Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2006-2008 Intel Corporation |
| 3 | * Copyright (c) 2007 Dave Airlie <airlied@linux.ie> |
| 4 | * Copyright (c) 2008 Red Hat Inc. |
| 5 | * |
| 6 | * DRM core CRTC related functions |
| 7 | * |
| 8 | * Permission to use, copy, modify, distribute, and sell this software and its |
| 9 | * documentation for any purpose is hereby granted without fee, provided that |
| 10 | * the above copyright notice appear in all copies and that both that copyright |
| 11 | * notice and this permission notice appear in supporting documentation, and |
| 12 | * that the name of the copyright holders not be used in advertising or |
| 13 | * publicity pertaining to distribution of the software without specific, |
| 14 | * written prior permission. The copyright holders make no representations |
| 15 | * about the suitability of this software for any purpose. It is provided "as |
| 16 | * is" without express or implied warranty. |
| 17 | * |
| 18 | * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, |
| 19 | * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO |
| 20 | * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR |
| 21 | * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, |
| 22 | * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER |
| 23 | * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE |
| 24 | * OF THIS SOFTWARE. |
| 25 | * |
| 26 | * Authors: |
| 27 | * Keith Packard |
| 28 | * Eric Anholt <eric@anholt.net> |
| 29 | * Dave Airlie <airlied@linux.ie> |
| 30 | * Jesse Barnes <jesse.barnes@intel.com> |
| 31 | */ |
Ville Syrjälä | 6ba6d03 | 2013-06-10 11:15:10 +0300 | [diff] [blame] | 32 | #include <linux/ctype.h> |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 33 | #include <linux/list.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 34 | #include <linux/slab.h> |
Paul Gortmaker | 2d1a8a4 | 2011-08-30 18:16:33 -0400 | [diff] [blame] | 35 | #include <linux/export.h> |
David Howells | 760285e | 2012-10-02 18:01:07 +0100 | [diff] [blame] | 36 | #include <drm/drmP.h> |
| 37 | #include <drm/drm_crtc.h> |
| 38 | #include <drm/drm_edid.h> |
| 39 | #include <drm/drm_fourcc.h> |
Rob Clark | 51fd371 | 2013-11-19 12:10:12 -0500 | [diff] [blame] | 40 | #include <drm/drm_modeset_lock.h> |
Rob Clark | 88a48e2 | 2014-12-18 16:01:50 -0500 | [diff] [blame] | 41 | #include <drm/drm_atomic.h> |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 42 | |
Daniel Vetter | 8bd441b | 2014-01-23 15:35:24 +0100 | [diff] [blame] | 43 | #include "drm_crtc_internal.h" |
Daniel Vetter | 67d0ec4 | 2014-09-10 12:43:53 +0200 | [diff] [blame] | 44 | #include "drm_internal.h" |
Daniel Vetter | 8bd441b | 2014-01-23 15:35:24 +0100 | [diff] [blame] | 45 | |
Chris Wilson | 9a6f513 | 2015-02-25 13:45:26 +0000 | [diff] [blame] | 46 | static struct drm_framebuffer * |
| 47 | internal_framebuffer_create(struct drm_device *dev, |
Ville Syrjälä | 1eb83451 | 2015-11-11 19:11:29 +0200 | [diff] [blame] | 48 | const struct drm_mode_fb_cmd2 *r, |
Chris Wilson | 9a6f513 | 2015-02-25 13:45:26 +0000 | [diff] [blame] | 49 | struct drm_file *file_priv); |
Matt Roper | c394c2b | 2014-06-10 08:28:08 -0700 | [diff] [blame] | 50 | |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 51 | /* Avoid boilerplate. I'm tired of typing. */ |
| 52 | #define DRM_ENUM_NAME_FN(fnname, list) \ |
Ville Syrjälä | d20d317 | 2013-06-07 15:43:07 +0000 | [diff] [blame] | 53 | const char *fnname(int val) \ |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 54 | { \ |
| 55 | int i; \ |
| 56 | for (i = 0; i < ARRAY_SIZE(list); i++) { \ |
| 57 | if (list[i].type == val) \ |
| 58 | return list[i].name; \ |
| 59 | } \ |
| 60 | return "(unknown)"; \ |
| 61 | } |
| 62 | |
| 63 | /* |
| 64 | * Global properties |
| 65 | */ |
Thierry Reding | 4dfd909 | 2014-12-10 13:03:34 +0100 | [diff] [blame] | 66 | static const struct drm_prop_enum_list drm_dpms_enum_list[] = { |
| 67 | { DRM_MODE_DPMS_ON, "On" }, |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 68 | { DRM_MODE_DPMS_STANDBY, "Standby" }, |
| 69 | { DRM_MODE_DPMS_SUSPEND, "Suspend" }, |
| 70 | { DRM_MODE_DPMS_OFF, "Off" } |
| 71 | }; |
| 72 | |
| 73 | DRM_ENUM_NAME_FN(drm_get_dpms_name, drm_dpms_enum_list) |
| 74 | |
Thierry Reding | 4dfd909 | 2014-12-10 13:03:34 +0100 | [diff] [blame] | 75 | static const struct drm_prop_enum_list drm_plane_type_enum_list[] = { |
Rob Clark | 9922ab5 | 2014-04-01 20:16:57 -0400 | [diff] [blame] | 76 | { DRM_PLANE_TYPE_OVERLAY, "Overlay" }, |
| 77 | { DRM_PLANE_TYPE_PRIMARY, "Primary" }, |
| 78 | { DRM_PLANE_TYPE_CURSOR, "Cursor" }, |
| 79 | }; |
| 80 | |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 81 | /* |
| 82 | * Optional properties |
| 83 | */ |
Thierry Reding | 4dfd909 | 2014-12-10 13:03:34 +0100 | [diff] [blame] | 84 | static const struct drm_prop_enum_list drm_scaling_mode_enum_list[] = { |
Jesse Barnes | 53bd838 | 2009-07-01 10:04:40 -0700 | [diff] [blame] | 85 | { DRM_MODE_SCALE_NONE, "None" }, |
| 86 | { DRM_MODE_SCALE_FULLSCREEN, "Full" }, |
| 87 | { DRM_MODE_SCALE_CENTER, "Center" }, |
| 88 | { DRM_MODE_SCALE_ASPECT, "Full aspect" }, |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 89 | }; |
| 90 | |
Vandana Kannan | ff587e4 | 2014-06-11 10:46:48 +0530 | [diff] [blame] | 91 | static const struct drm_prop_enum_list drm_aspect_ratio_enum_list[] = { |
| 92 | { DRM_MODE_PICTURE_ASPECT_NONE, "Automatic" }, |
| 93 | { DRM_MODE_PICTURE_ASPECT_4_3, "4:3" }, |
| 94 | { DRM_MODE_PICTURE_ASPECT_16_9, "16:9" }, |
| 95 | }; |
| 96 | |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 97 | /* |
| 98 | * Non-global properties, but "required" for certain connectors. |
| 99 | */ |
Thierry Reding | 4dfd909 | 2014-12-10 13:03:34 +0100 | [diff] [blame] | 100 | 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] | 101 | { DRM_MODE_SUBCONNECTOR_Automatic, "Automatic" }, /* DVI-I and TV-out */ |
| 102 | { DRM_MODE_SUBCONNECTOR_DVID, "DVI-D" }, /* DVI-I */ |
| 103 | { DRM_MODE_SUBCONNECTOR_DVIA, "DVI-A" }, /* DVI-I */ |
| 104 | }; |
| 105 | |
| 106 | DRM_ENUM_NAME_FN(drm_get_dvi_i_select_name, drm_dvi_i_select_enum_list) |
| 107 | |
Thierry Reding | 4dfd909 | 2014-12-10 13:03:34 +0100 | [diff] [blame] | 108 | 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] | 109 | { DRM_MODE_SUBCONNECTOR_Unknown, "Unknown" }, /* DVI-I and TV-out */ |
| 110 | { DRM_MODE_SUBCONNECTOR_DVID, "DVI-D" }, /* DVI-I */ |
| 111 | { DRM_MODE_SUBCONNECTOR_DVIA, "DVI-A" }, /* DVI-I */ |
| 112 | }; |
| 113 | |
| 114 | DRM_ENUM_NAME_FN(drm_get_dvi_i_subconnector_name, |
| 115 | drm_dvi_i_subconnector_enum_list) |
| 116 | |
Thierry Reding | 4dfd909 | 2014-12-10 13:03:34 +0100 | [diff] [blame] | 117 | static const struct drm_prop_enum_list drm_tv_select_enum_list[] = { |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 118 | { DRM_MODE_SUBCONNECTOR_Automatic, "Automatic" }, /* DVI-I and TV-out */ |
| 119 | { DRM_MODE_SUBCONNECTOR_Composite, "Composite" }, /* TV-out */ |
| 120 | { DRM_MODE_SUBCONNECTOR_SVIDEO, "SVIDEO" }, /* TV-out */ |
| 121 | { DRM_MODE_SUBCONNECTOR_Component, "Component" }, /* TV-out */ |
Francisco Jerez | aeaa1ad | 2009-08-02 04:19:19 +0200 | [diff] [blame] | 122 | { DRM_MODE_SUBCONNECTOR_SCART, "SCART" }, /* TV-out */ |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 123 | }; |
| 124 | |
| 125 | DRM_ENUM_NAME_FN(drm_get_tv_select_name, drm_tv_select_enum_list) |
| 126 | |
Thierry Reding | 4dfd909 | 2014-12-10 13:03:34 +0100 | [diff] [blame] | 127 | static const struct drm_prop_enum_list drm_tv_subconnector_enum_list[] = { |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 128 | { DRM_MODE_SUBCONNECTOR_Unknown, "Unknown" }, /* DVI-I and TV-out */ |
| 129 | { DRM_MODE_SUBCONNECTOR_Composite, "Composite" }, /* TV-out */ |
| 130 | { DRM_MODE_SUBCONNECTOR_SVIDEO, "SVIDEO" }, /* TV-out */ |
| 131 | { DRM_MODE_SUBCONNECTOR_Component, "Component" }, /* TV-out */ |
Francisco Jerez | aeaa1ad | 2009-08-02 04:19:19 +0200 | [diff] [blame] | 132 | { DRM_MODE_SUBCONNECTOR_SCART, "SCART" }, /* TV-out */ |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 133 | }; |
| 134 | |
| 135 | DRM_ENUM_NAME_FN(drm_get_tv_subconnector_name, |
| 136 | drm_tv_subconnector_enum_list) |
| 137 | |
Ville Syrjälä | d20d317 | 2013-06-07 15:43:07 +0000 | [diff] [blame] | 138 | static const struct drm_prop_enum_list drm_dirty_info_enum_list[] = { |
Jakob Bornecrantz | 884840a | 2009-12-03 23:25:47 +0000 | [diff] [blame] | 139 | { DRM_MODE_DIRTY_OFF, "Off" }, |
| 140 | { DRM_MODE_DIRTY_ON, "On" }, |
| 141 | { DRM_MODE_DIRTY_ANNOTATE, "Annotate" }, |
| 142 | }; |
| 143 | |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 144 | struct drm_conn_prop_enum_list { |
| 145 | int type; |
Ville Syrjälä | d20d317 | 2013-06-07 15:43:07 +0000 | [diff] [blame] | 146 | const char *name; |
Ilia Mirkin | b21e3af | 2013-08-07 22:34:48 -0400 | [diff] [blame] | 147 | struct ida ida; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 148 | }; |
| 149 | |
| 150 | /* |
| 151 | * Connector and encoder types. |
| 152 | */ |
Thierry Reding | 4dfd909 | 2014-12-10 13:03:34 +0100 | [diff] [blame] | 153 | static struct drm_conn_prop_enum_list drm_connector_enum_list[] = { |
| 154 | { DRM_MODE_CONNECTOR_Unknown, "Unknown" }, |
Ilia Mirkin | b21e3af | 2013-08-07 22:34:48 -0400 | [diff] [blame] | 155 | { DRM_MODE_CONNECTOR_VGA, "VGA" }, |
| 156 | { DRM_MODE_CONNECTOR_DVII, "DVI-I" }, |
| 157 | { DRM_MODE_CONNECTOR_DVID, "DVI-D" }, |
| 158 | { DRM_MODE_CONNECTOR_DVIA, "DVI-A" }, |
| 159 | { DRM_MODE_CONNECTOR_Composite, "Composite" }, |
| 160 | { DRM_MODE_CONNECTOR_SVIDEO, "SVIDEO" }, |
| 161 | { DRM_MODE_CONNECTOR_LVDS, "LVDS" }, |
| 162 | { DRM_MODE_CONNECTOR_Component, "Component" }, |
| 163 | { DRM_MODE_CONNECTOR_9PinDIN, "DIN" }, |
| 164 | { DRM_MODE_CONNECTOR_DisplayPort, "DP" }, |
| 165 | { DRM_MODE_CONNECTOR_HDMIA, "HDMI-A" }, |
| 166 | { DRM_MODE_CONNECTOR_HDMIB, "HDMI-B" }, |
| 167 | { DRM_MODE_CONNECTOR_TV, "TV" }, |
| 168 | { DRM_MODE_CONNECTOR_eDP, "eDP" }, |
| 169 | { DRM_MODE_CONNECTOR_VIRTUAL, "Virtual" }, |
Shobhit Kumar | b892327 | 2013-08-27 15:12:13 +0300 | [diff] [blame] | 170 | { DRM_MODE_CONNECTOR_DSI, "DSI" }, |
Eric Anholt | 0b27c02 | 2016-03-18 12:34:59 -0700 | [diff] [blame] | 171 | { DRM_MODE_CONNECTOR_DPI, "DPI" }, |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 172 | }; |
| 173 | |
Thierry Reding | 4dfd909 | 2014-12-10 13:03:34 +0100 | [diff] [blame] | 174 | static const struct drm_prop_enum_list drm_encoder_enum_list[] = { |
| 175 | { DRM_MODE_ENCODER_NONE, "None" }, |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 176 | { DRM_MODE_ENCODER_DAC, "DAC" }, |
| 177 | { DRM_MODE_ENCODER_TMDS, "TMDS" }, |
| 178 | { DRM_MODE_ENCODER_LVDS, "LVDS" }, |
| 179 | { DRM_MODE_ENCODER_TVDAC, "TV" }, |
Thomas Hellstrom | a7331e5 | 2011-10-22 10:36:19 +0200 | [diff] [blame] | 180 | { DRM_MODE_ENCODER_VIRTUAL, "Virtual" }, |
Shobhit Kumar | b892327 | 2013-08-27 15:12:13 +0300 | [diff] [blame] | 181 | { DRM_MODE_ENCODER_DSI, "DSI" }, |
Dave Airlie | 182407a | 2014-05-02 11:09:54 +1000 | [diff] [blame] | 182 | { DRM_MODE_ENCODER_DPMST, "DP MST" }, |
Eric Anholt | 0b27c02 | 2016-03-18 12:34:59 -0700 | [diff] [blame] | 183 | { DRM_MODE_ENCODER_DPI, "DPI" }, |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 184 | }; |
| 185 | |
Thierry Reding | 4dfd909 | 2014-12-10 13:03:34 +0100 | [diff] [blame] | 186 | static const struct drm_prop_enum_list drm_subpixel_enum_list[] = { |
Jesse Barnes | ac1bb36 | 2014-02-10 15:32:44 -0800 | [diff] [blame] | 187 | { SubPixelUnknown, "Unknown" }, |
| 188 | { SubPixelHorizontalRGB, "Horizontal RGB" }, |
| 189 | { SubPixelHorizontalBGR, "Horizontal BGR" }, |
| 190 | { SubPixelVerticalRGB, "Vertical RGB" }, |
| 191 | { SubPixelVerticalBGR, "Vertical BGR" }, |
| 192 | { SubPixelNone, "None" }, |
| 193 | }; |
| 194 | |
Ilia Mirkin | b21e3af | 2013-08-07 22:34:48 -0400 | [diff] [blame] | 195 | void drm_connector_ida_init(void) |
| 196 | { |
| 197 | int i; |
| 198 | |
| 199 | for (i = 0; i < ARRAY_SIZE(drm_connector_enum_list); i++) |
| 200 | ida_init(&drm_connector_enum_list[i].ida); |
| 201 | } |
| 202 | |
| 203 | void drm_connector_ida_destroy(void) |
| 204 | { |
| 205 | int i; |
| 206 | |
| 207 | for (i = 0; i < ARRAY_SIZE(drm_connector_enum_list); i++) |
| 208 | ida_destroy(&drm_connector_enum_list[i].ida); |
| 209 | } |
| 210 | |
Daniel Vetter | c8e32cc | 2014-03-10 21:33:02 +0100 | [diff] [blame] | 211 | /** |
Daniel Vetter | c8e32cc | 2014-03-10 21:33:02 +0100 | [diff] [blame] | 212 | * drm_get_connector_status_name - return a string for connector status |
| 213 | * @status: connector status to compute name of |
| 214 | * |
| 215 | * In contrast to the other drm_get_*_name functions this one here returns a |
| 216 | * const pointer and hence is threadsafe. |
| 217 | */ |
Ville Syrjälä | d20d317 | 2013-06-07 15:43:07 +0000 | [diff] [blame] | 218 | const char *drm_get_connector_status_name(enum drm_connector_status status) |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 219 | { |
| 220 | if (status == connector_status_connected) |
| 221 | return "connected"; |
| 222 | else if (status == connector_status_disconnected) |
| 223 | return "disconnected"; |
| 224 | else |
| 225 | return "unknown"; |
| 226 | } |
Lespiau, Damien | ed7951d | 2013-05-10 12:36:42 +0000 | [diff] [blame] | 227 | EXPORT_SYMBOL(drm_get_connector_status_name); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 228 | |
Jesse Barnes | ac1bb36 | 2014-02-10 15:32:44 -0800 | [diff] [blame] | 229 | /** |
| 230 | * drm_get_subpixel_order_name - return a string for a given subpixel enum |
| 231 | * @order: enum of subpixel_order |
| 232 | * |
| 233 | * Note you could abuse this and return something out of bounds, but that |
| 234 | * would be a caller error. No unscrubbed user data should make it here. |
| 235 | */ |
| 236 | const char *drm_get_subpixel_order_name(enum subpixel_order order) |
| 237 | { |
| 238 | return drm_subpixel_enum_list[order].name; |
| 239 | } |
| 240 | EXPORT_SYMBOL(drm_get_subpixel_order_name); |
| 241 | |
Dave Airlie | 2ee3945 | 2014-07-24 11:53:45 +1000 | [diff] [blame] | 242 | /* |
| 243 | * Internal function to assign a slot in the object idr and optionally |
| 244 | * register the object into the idr. |
| 245 | */ |
| 246 | static int drm_mode_object_get_reg(struct drm_device *dev, |
| 247 | struct drm_mode_object *obj, |
| 248 | uint32_t obj_type, |
Dave Airlie | d0f37cf | 2016-04-15 15:10:36 +1000 | [diff] [blame] | 249 | bool register_obj, |
| 250 | void (*obj_free_cb)(struct kref *kref)) |
Dave Airlie | 2ee3945 | 2014-07-24 11:53:45 +1000 | [diff] [blame] | 251 | { |
| 252 | int ret; |
| 253 | |
| 254 | mutex_lock(&dev->mode_config.idr_mutex); |
| 255 | ret = idr_alloc(&dev->mode_config.crtc_idr, register_obj ? obj : NULL, 1, 0, GFP_KERNEL); |
| 256 | if (ret >= 0) { |
| 257 | /* |
| 258 | * Set up the object linking under the protection of the idr |
| 259 | * lock so that other users can't see inconsistent state. |
| 260 | */ |
| 261 | obj->id = ret; |
| 262 | obj->type = obj_type; |
Dave Airlie | d0f37cf | 2016-04-15 15:10:36 +1000 | [diff] [blame] | 263 | if (obj_free_cb) { |
| 264 | obj->free_cb = obj_free_cb; |
| 265 | kref_init(&obj->refcount); |
| 266 | } |
Dave Airlie | 2ee3945 | 2014-07-24 11:53:45 +1000 | [diff] [blame] | 267 | } |
| 268 | mutex_unlock(&dev->mode_config.idr_mutex); |
| 269 | |
| 270 | return ret < 0 ? ret : 0; |
| 271 | } |
| 272 | |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 273 | /** |
Daniel Vetter | 065a50ed | 2012-12-02 00:09:18 +0100 | [diff] [blame] | 274 | * drm_mode_object_get - allocate a new modeset identifier |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 275 | * @dev: DRM device |
Daniel Vetter | 065a50ed | 2012-12-02 00:09:18 +0100 | [diff] [blame] | 276 | * @obj: object pointer, used to generate unique ID |
| 277 | * @obj_type: object type |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 278 | * |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 279 | * 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] | 280 | * for tracking modes, CRTCs and connectors. Note that despite the _get postfix |
| 281 | * modeset identifiers are _not_ reference counted. Hence don't use this for |
| 282 | * reference counted modeset objects like framebuffers. |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 283 | * |
Daniel Vetter | c8e32cc | 2014-03-10 21:33:02 +0100 | [diff] [blame] | 284 | * Returns: |
Lukas Wunner | 3c67d83 | 2015-10-15 11:56:56 +0200 | [diff] [blame] | 285 | * Zero on success, error code on failure. |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 286 | */ |
Daniel Vetter | 8bd441b | 2014-01-23 15:35:24 +0100 | [diff] [blame] | 287 | int drm_mode_object_get(struct drm_device *dev, |
| 288 | struct drm_mode_object *obj, uint32_t obj_type) |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 289 | { |
Dave Airlie | d0f37cf | 2016-04-15 15:10:36 +1000 | [diff] [blame] | 290 | return drm_mode_object_get_reg(dev, obj, obj_type, true, NULL); |
Dave Airlie | 2ee3945 | 2014-07-24 11:53:45 +1000 | [diff] [blame] | 291 | } |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 292 | |
Dave Airlie | 2ee3945 | 2014-07-24 11:53:45 +1000 | [diff] [blame] | 293 | static void drm_mode_object_register(struct drm_device *dev, |
| 294 | struct drm_mode_object *obj) |
| 295 | { |
Jesse Barnes | ad2563c | 2009-01-19 17:21:45 +1000 | [diff] [blame] | 296 | mutex_lock(&dev->mode_config.idr_mutex); |
Dave Airlie | 2ee3945 | 2014-07-24 11:53:45 +1000 | [diff] [blame] | 297 | idr_replace(&dev->mode_config.crtc_idr, obj, obj->id); |
Jesse Barnes | ad2563c | 2009-01-19 17:21:45 +1000 | [diff] [blame] | 298 | mutex_unlock(&dev->mode_config.idr_mutex); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 299 | } |
| 300 | |
| 301 | /** |
Dave Airlie | 7c8f6d2 | 2016-04-15 15:10:32 +1000 | [diff] [blame] | 302 | * drm_mode_object_unregister - free a modeset identifer |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 303 | * @dev: DRM device |
Daniel Vetter | 065a50ed | 2012-12-02 00:09:18 +0100 | [diff] [blame] | 304 | * @object: object to free |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 305 | * |
Dave Airlie | 7c8f6d2 | 2016-04-15 15:10:32 +1000 | [diff] [blame] | 306 | * Free @id from @dev's unique identifier pool. |
| 307 | * This function can be called multiple times, and guards against |
| 308 | * multiple removals. |
| 309 | * These modeset identifiers are _not_ reference counted. Hence don't use this |
Daniel Vetter | c8e32cc | 2014-03-10 21:33:02 +0100 | [diff] [blame] | 310 | * for reference counted modeset objects like framebuffers. |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 311 | */ |
Dave Airlie | 7c8f6d2 | 2016-04-15 15:10:32 +1000 | [diff] [blame] | 312 | void drm_mode_object_unregister(struct drm_device *dev, |
Daniel Vetter | 8bd441b | 2014-01-23 15:35:24 +0100 | [diff] [blame] | 313 | struct drm_mode_object *object) |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 314 | { |
Jesse Barnes | ad2563c | 2009-01-19 17:21:45 +1000 | [diff] [blame] | 315 | mutex_lock(&dev->mode_config.idr_mutex); |
Dave Airlie | 7c8f6d2 | 2016-04-15 15:10:32 +1000 | [diff] [blame] | 316 | if (object->id) { |
| 317 | idr_remove(&dev->mode_config.crtc_idr, object->id); |
| 318 | object->id = 0; |
| 319 | } |
Jesse Barnes | ad2563c | 2009-01-19 17:21:45 +1000 | [diff] [blame] | 320 | mutex_unlock(&dev->mode_config.idr_mutex); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 321 | } |
| 322 | |
Rob Clark | 98f75de | 2014-05-30 11:37:03 -0400 | [diff] [blame] | 323 | static struct drm_mode_object *_object_find(struct drm_device *dev, |
| 324 | uint32_t id, uint32_t type) |
| 325 | { |
| 326 | struct drm_mode_object *obj = NULL; |
| 327 | |
| 328 | mutex_lock(&dev->mode_config.idr_mutex); |
| 329 | obj = idr_find(&dev->mode_config.crtc_idr, id); |
Daniel Vetter | 168c02e | 2014-07-24 12:12:45 +0200 | [diff] [blame] | 330 | if (obj && type != DRM_MODE_OBJECT_ANY && obj->type != type) |
| 331 | obj = NULL; |
| 332 | if (obj && obj->id != id) |
| 333 | obj = NULL; |
Dave Airlie | 72fe90b | 2016-04-15 15:10:40 +1000 | [diff] [blame] | 334 | |
| 335 | if (obj && obj->free_cb) { |
| 336 | if (!kref_get_unless_zero(&obj->refcount)) |
| 337 | obj = NULL; |
| 338 | } |
Rob Clark | 98f75de | 2014-05-30 11:37:03 -0400 | [diff] [blame] | 339 | mutex_unlock(&dev->mode_config.idr_mutex); |
| 340 | |
| 341 | return obj; |
| 342 | } |
| 343 | |
Daniel Vetter | 786b99e | 2012-12-02 21:53:40 +0100 | [diff] [blame] | 344 | /** |
| 345 | * drm_mode_object_find - look up a drm object with static lifetime |
| 346 | * @dev: drm device |
| 347 | * @id: id of the mode object |
| 348 | * @type: type of the mode object |
| 349 | * |
Daniel Vetter | 05981422 | 2016-04-22 22:10:27 +0200 | [diff] [blame] | 350 | * This function is used to look up a modeset object. It will acquire a |
| 351 | * reference for reference counted objects. This reference must be dropped again |
| 352 | * by callind drm_mode_object_unreference(). |
Daniel Vetter | 786b99e | 2012-12-02 21:53:40 +0100 | [diff] [blame] | 353 | */ |
Daniel Vetter | 7a9c906 | 2009-09-15 22:57:31 +0200 | [diff] [blame] | 354 | struct drm_mode_object *drm_mode_object_find(struct drm_device *dev, |
| 355 | uint32_t id, uint32_t type) |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 356 | { |
Jesse Barnes | ad2563c | 2009-01-19 17:21:45 +1000 | [diff] [blame] | 357 | struct drm_mode_object *obj = NULL; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 358 | |
Rob Clark | 98f75de | 2014-05-30 11:37:03 -0400 | [diff] [blame] | 359 | obj = _object_find(dev, id, type); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 360 | return obj; |
| 361 | } |
| 362 | EXPORT_SYMBOL(drm_mode_object_find); |
| 363 | |
Daniel Vetter | 05981422 | 2016-04-22 22:10:27 +0200 | [diff] [blame] | 364 | /** |
| 365 | * drm_mode_object_unreference - decr the object refcnt |
| 366 | * @obj: mode_object |
| 367 | * |
| 368 | * This functions decrements the object's refcount if it is a refcounted modeset |
| 369 | * object. It is a no-op on any other object. This is used to drop references |
| 370 | * acquired with drm_mode_object_reference(). |
| 371 | */ |
Dave Airlie | d0f37cf | 2016-04-15 15:10:36 +1000 | [diff] [blame] | 372 | void drm_mode_object_unreference(struct drm_mode_object *obj) |
| 373 | { |
| 374 | if (obj->free_cb) { |
| 375 | DRM_DEBUG("OBJ ID: %d (%d)\n", obj->id, atomic_read(&obj->refcount.refcount)); |
| 376 | kref_put(&obj->refcount, obj->free_cb); |
| 377 | } |
| 378 | } |
| 379 | EXPORT_SYMBOL(drm_mode_object_unreference); |
| 380 | |
| 381 | /** |
Daniel Vetter | 05981422 | 2016-04-22 22:10:27 +0200 | [diff] [blame] | 382 | * drm_mode_object_reference - incr the object refcnt |
Dave Airlie | d0f37cf | 2016-04-15 15:10:36 +1000 | [diff] [blame] | 383 | * @obj: mode_object |
| 384 | * |
Daniel Vetter | 05981422 | 2016-04-22 22:10:27 +0200 | [diff] [blame] | 385 | * This functions increments the object's refcount if it is a refcounted modeset |
| 386 | * object. It is a no-op on any other object. References should be dropped again |
| 387 | * by calling drm_mode_object_unreference(). |
Dave Airlie | d0f37cf | 2016-04-15 15:10:36 +1000 | [diff] [blame] | 388 | */ |
| 389 | void drm_mode_object_reference(struct drm_mode_object *obj) |
| 390 | { |
| 391 | if (obj->free_cb) { |
| 392 | DRM_DEBUG("OBJ ID: %d (%d)\n", obj->id, atomic_read(&obj->refcount.refcount)); |
| 393 | kref_get(&obj->refcount); |
| 394 | } |
| 395 | } |
| 396 | EXPORT_SYMBOL(drm_mode_object_reference); |
| 397 | |
Dave Airlie | f55f1f9 | 2016-04-15 15:10:33 +1000 | [diff] [blame] | 398 | static void drm_framebuffer_free(struct kref *kref) |
| 399 | { |
| 400 | struct drm_framebuffer *fb = |
Dave Airlie | d0f37cf | 2016-04-15 15:10:36 +1000 | [diff] [blame] | 401 | container_of(kref, struct drm_framebuffer, base.refcount); |
Dave Airlie | f55f1f9 | 2016-04-15 15:10:33 +1000 | [diff] [blame] | 402 | struct drm_device *dev = fb->dev; |
| 403 | |
| 404 | /* |
| 405 | * The lookup idr holds a weak reference, which has not necessarily been |
| 406 | * removed at this point. Check for that. |
| 407 | */ |
Dave Airlie | 19ab3f8 | 2016-04-15 15:10:34 +1000 | [diff] [blame] | 408 | drm_mode_object_unregister(dev, &fb->base); |
Dave Airlie | f55f1f9 | 2016-04-15 15:10:33 +1000 | [diff] [blame] | 409 | |
| 410 | fb->funcs->destroy(fb); |
| 411 | } |
| 412 | |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 413 | /** |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 414 | * drm_framebuffer_init - initialize a framebuffer |
| 415 | * @dev: DRM device |
Daniel Vetter | 065a50ed | 2012-12-02 00:09:18 +0100 | [diff] [blame] | 416 | * @fb: framebuffer to be initialized |
| 417 | * @funcs: ... with these functions |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 418 | * |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 419 | * Allocates an ID for the framebuffer's parent mode object, sets its mode |
| 420 | * functions & device file and adds it to the master fd list. |
| 421 | * |
Daniel Vetter | 4b096ac | 2012-12-10 21:19:18 +0100 | [diff] [blame] | 422 | * IMPORTANT: |
| 423 | * This functions publishes the fb and makes it available for concurrent access |
| 424 | * by other users. Which means by this point the fb _must_ be fully set up - |
| 425 | * since all the fb attributes are invariant over its lifetime, no further |
| 426 | * locking but only correct reference counting is required. |
| 427 | * |
Daniel Vetter | c8e32cc | 2014-03-10 21:33:02 +0100 | [diff] [blame] | 428 | * Returns: |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 429 | * Zero on success, error code on failure. |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 430 | */ |
| 431 | int drm_framebuffer_init(struct drm_device *dev, struct drm_framebuffer *fb, |
| 432 | const struct drm_framebuffer_funcs *funcs) |
| 433 | { |
| 434 | int ret; |
| 435 | |
Daniel Vetter | 4b096ac | 2012-12-10 21:19:18 +0100 | [diff] [blame] | 436 | INIT_LIST_HEAD(&fb->filp_head); |
| 437 | fb->dev = dev; |
| 438 | fb->funcs = funcs; |
Rob Clark | f7eff60 | 2012-09-05 21:48:38 +0000 | [diff] [blame] | 439 | |
Dave Airlie | d0f37cf | 2016-04-15 15:10:36 +1000 | [diff] [blame] | 440 | ret = drm_mode_object_get_reg(dev, &fb->base, DRM_MODE_OBJECT_FB, |
Dave Airlie | 9cd4742 | 2016-04-15 15:10:38 +1000 | [diff] [blame] | 441 | false, drm_framebuffer_free); |
Ville Syrjälä | 6bfc56a | 2012-03-13 12:35:48 +0200 | [diff] [blame] | 442 | if (ret) |
Daniel Vetter | 4b096ac | 2012-12-10 21:19:18 +0100 | [diff] [blame] | 443 | goto out; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 444 | |
Dave Airlie | 9cd4742 | 2016-04-15 15:10:38 +1000 | [diff] [blame] | 445 | mutex_lock(&dev->mode_config.fb_lock); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 446 | dev->mode_config.num_fb++; |
| 447 | list_add(&fb->head, &dev->mode_config.fb_list); |
Dave Airlie | 2ddea3f | 2016-04-15 15:10:41 +1000 | [diff] [blame] | 448 | mutex_unlock(&dev->mode_config.fb_lock); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 449 | |
Dave Airlie | 9cd4742 | 2016-04-15 15:10:38 +1000 | [diff] [blame] | 450 | drm_mode_object_register(dev, &fb->base); |
Dave Airlie | 9cd4742 | 2016-04-15 15:10:38 +1000 | [diff] [blame] | 451 | out: |
Lukas Wunner | 3c67d83 | 2015-10-15 11:56:56 +0200 | [diff] [blame] | 452 | return ret; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 453 | } |
| 454 | EXPORT_SYMBOL(drm_framebuffer_init); |
| 455 | |
Rob Clark | f7eff60 | 2012-09-05 21:48:38 +0000 | [diff] [blame] | 456 | /** |
Daniel Vetter | 786b99e | 2012-12-02 21:53:40 +0100 | [diff] [blame] | 457 | * drm_framebuffer_lookup - look up a drm framebuffer and grab a reference |
| 458 | * @dev: drm device |
| 459 | * @id: id of the fb object |
| 460 | * |
| 461 | * If successful, this grabs an additional reference to the framebuffer - |
| 462 | * callers need to make sure to eventually unreference the returned framebuffer |
Daniel Vetter | c8e32cc | 2014-03-10 21:33:02 +0100 | [diff] [blame] | 463 | * again, using @drm_framebuffer_unreference. |
Daniel Vetter | 786b99e | 2012-12-02 21:53:40 +0100 | [diff] [blame] | 464 | */ |
| 465 | struct drm_framebuffer *drm_framebuffer_lookup(struct drm_device *dev, |
| 466 | uint32_t id) |
| 467 | { |
Dave Airlie | cee26ac | 2016-04-15 15:10:37 +1000 | [diff] [blame] | 468 | struct drm_mode_object *obj; |
| 469 | struct drm_framebuffer *fb = NULL; |
Daniel Vetter | 786b99e | 2012-12-02 21:53:40 +0100 | [diff] [blame] | 470 | |
Dave Airlie | cee26ac | 2016-04-15 15:10:37 +1000 | [diff] [blame] | 471 | obj = _object_find(dev, id, DRM_MODE_OBJECT_FB); |
Dave Airlie | 72fe90b | 2016-04-15 15:10:40 +1000 | [diff] [blame] | 472 | if (obj) |
Dave Airlie | cee26ac | 2016-04-15 15:10:37 +1000 | [diff] [blame] | 473 | fb = obj_to_fb(obj); |
Daniel Vetter | 786b99e | 2012-12-02 21:53:40 +0100 | [diff] [blame] | 474 | return fb; |
| 475 | } |
| 476 | EXPORT_SYMBOL(drm_framebuffer_lookup); |
| 477 | |
| 478 | /** |
Daniel Vetter | 3620636 | 2012-12-10 20:42:17 +0100 | [diff] [blame] | 479 | * drm_framebuffer_unregister_private - unregister a private fb from the lookup idr |
| 480 | * @fb: fb to unregister |
| 481 | * |
| 482 | * Drivers need to call this when cleaning up driver-private framebuffers, e.g. |
| 483 | * those used for fbdev. Note that the caller must hold a reference of it's own, |
| 484 | * i.e. the object may not be destroyed through this call (since it'll lead to a |
| 485 | * locking inversion). |
| 486 | */ |
| 487 | void drm_framebuffer_unregister_private(struct drm_framebuffer *fb) |
| 488 | { |
Daniel Vetter | a39a357 | 2015-08-25 15:45:11 +0200 | [diff] [blame] | 489 | struct drm_device *dev; |
| 490 | |
| 491 | if (!fb) |
| 492 | return; |
| 493 | |
| 494 | dev = fb->dev; |
Daniel Vetter | 2b677e8 | 2012-12-10 21:16:05 +0100 | [diff] [blame] | 495 | |
Daniel Vetter | 2b677e8 | 2012-12-10 21:16:05 +0100 | [diff] [blame] | 496 | /* Mark fb as reaped and drop idr ref. */ |
Dave Airlie | 19ab3f8 | 2016-04-15 15:10:34 +1000 | [diff] [blame] | 497 | drm_mode_object_unregister(dev, &fb->base); |
Daniel Vetter | 3620636 | 2012-12-10 20:42:17 +0100 | [diff] [blame] | 498 | } |
| 499 | EXPORT_SYMBOL(drm_framebuffer_unregister_private); |
| 500 | |
| 501 | /** |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 502 | * drm_framebuffer_cleanup - remove a framebuffer object |
| 503 | * @fb: framebuffer to remove |
| 504 | * |
Daniel Vetter | c8e32cc | 2014-03-10 21:33:02 +0100 | [diff] [blame] | 505 | * Cleanup framebuffer. This function is intended to be used from the drivers |
| 506 | * ->destroy callback. It can also be used to clean up driver private |
Daniel Vetter | 2e7a570 | 2016-06-01 23:40:36 +0200 | [diff] [blame] | 507 | * framebuffers embedded into a larger structure. |
Daniel Vetter | 3620636 | 2012-12-10 20:42:17 +0100 | [diff] [blame] | 508 | * |
| 509 | * Note that this function does not remove the fb from active usuage - if it is |
| 510 | * still used anywhere, hilarity can ensue since userspace could call getfb on |
| 511 | * the id and get back -EINVAL. Obviously no concern at driver unload time. |
| 512 | * |
| 513 | * Also, the framebuffer will not be removed from the lookup idr - for |
| 514 | * user-created framebuffers this will happen in in the rmfb ioctl. For |
| 515 | * driver-private objects (e.g. for fbdev) drivers need to explicitly call |
| 516 | * drm_framebuffer_unregister_private. |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 517 | */ |
| 518 | void drm_framebuffer_cleanup(struct drm_framebuffer *fb) |
| 519 | { |
| 520 | struct drm_device *dev = fb->dev; |
Daniel Vetter | 8faf6b1 | 2012-12-01 23:43:11 +0100 | [diff] [blame] | 521 | |
Daniel Vetter | 4b096ac | 2012-12-10 21:19:18 +0100 | [diff] [blame] | 522 | mutex_lock(&dev->mode_config.fb_lock); |
Rob Clark | f7eff60 | 2012-09-05 21:48:38 +0000 | [diff] [blame] | 523 | list_del(&fb->head); |
| 524 | dev->mode_config.num_fb--; |
Daniel Vetter | 4b096ac | 2012-12-10 21:19:18 +0100 | [diff] [blame] | 525 | mutex_unlock(&dev->mode_config.fb_lock); |
Rob Clark | f7eff60 | 2012-09-05 21:48:38 +0000 | [diff] [blame] | 526 | } |
| 527 | EXPORT_SYMBOL(drm_framebuffer_cleanup); |
| 528 | |
| 529 | /** |
| 530 | * drm_framebuffer_remove - remove and unreference a framebuffer object |
| 531 | * @fb: framebuffer to remove |
| 532 | * |
Rob Clark | f7eff60 | 2012-09-05 21:48:38 +0000 | [diff] [blame] | 533 | * 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] | 534 | * 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] | 535 | * passed-in framebuffer. Might take the modeset locks. |
| 536 | * |
| 537 | * Note that this function optimizes the cleanup away if the caller holds the |
| 538 | * last reference to the framebuffer. It is also guaranteed to not take the |
| 539 | * modeset locks in this case. |
Rob Clark | f7eff60 | 2012-09-05 21:48:38 +0000 | [diff] [blame] | 540 | */ |
| 541 | void drm_framebuffer_remove(struct drm_framebuffer *fb) |
| 542 | { |
Daniel Vetter | a39a357 | 2015-08-25 15:45:11 +0200 | [diff] [blame] | 543 | struct drm_device *dev; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 544 | struct drm_crtc *crtc; |
Jesse Barnes | 8cf5c91 | 2011-11-14 14:51:27 -0800 | [diff] [blame] | 545 | struct drm_plane *plane; |
Dave Airlie | 5ef5f72 | 2009-08-17 13:11:23 +1000 | [diff] [blame] | 546 | struct drm_mode_set set; |
| 547 | int ret; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 548 | |
Daniel Vetter | a39a357 | 2015-08-25 15:45:11 +0200 | [diff] [blame] | 549 | if (!fb) |
| 550 | return; |
| 551 | |
| 552 | dev = fb->dev; |
| 553 | |
Daniel Vetter | 4b096ac | 2012-12-10 21:19:18 +0100 | [diff] [blame] | 554 | WARN_ON(!list_empty(&fb->filp_head)); |
Daniel Vetter | 8faf6b1 | 2012-12-01 23:43:11 +0100 | [diff] [blame] | 555 | |
Daniel Vetter | b62584e | 2012-12-11 16:51:35 +0100 | [diff] [blame] | 556 | /* |
| 557 | * drm ABI mandates that we remove any deleted framebuffers from active |
| 558 | * useage. But since most sane clients only remove framebuffers they no |
| 559 | * longer need, try to optimize this away. |
| 560 | * |
| 561 | * Since we're holding a reference ourselves, observing a refcount of 1 |
| 562 | * means that we're the last holder and can skip it. Also, the refcount |
| 563 | * can never increase from 1 again, so we don't need any barriers or |
| 564 | * locks. |
| 565 | * |
| 566 | * Note that userspace could try to race with use and instate a new |
| 567 | * usage _after_ we've cleared all current ones. End result will be an |
| 568 | * in-use fb with fb-id == 0. Userspace is allowed to shoot its own foot |
| 569 | * in this manner. |
| 570 | */ |
Dave Airlie | 747a598 | 2016-04-15 15:10:35 +1000 | [diff] [blame] | 571 | if (drm_framebuffer_read_refcount(fb) > 1) { |
Daniel Vetter | b62584e | 2012-12-11 16:51:35 +0100 | [diff] [blame] | 572 | drm_modeset_lock_all(dev); |
| 573 | /* remove from any CRTC */ |
Daniel Vetter | 6295d60 | 2015-07-09 23:44:25 +0200 | [diff] [blame] | 574 | drm_for_each_crtc(crtc, dev) { |
Matt Roper | f4510a2 | 2014-04-01 15:22:40 -0700 | [diff] [blame] | 575 | if (crtc->primary->fb == fb) { |
Daniel Vetter | b62584e | 2012-12-11 16:51:35 +0100 | [diff] [blame] | 576 | /* should turn off the crtc */ |
| 577 | memset(&set, 0, sizeof(struct drm_mode_set)); |
| 578 | set.crtc = crtc; |
| 579 | set.fb = NULL; |
| 580 | ret = drm_mode_set_config_internal(&set); |
| 581 | if (ret) |
| 582 | DRM_ERROR("failed to reset crtc %p when fb was deleted\n", crtc); |
| 583 | } |
Dave Airlie | 5ef5f72 | 2009-08-17 13:11:23 +1000 | [diff] [blame] | 584 | } |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 585 | |
Daniel Vetter | 6295d60 | 2015-07-09 23:44:25 +0200 | [diff] [blame] | 586 | drm_for_each_plane(plane, dev) { |
Ville Syrjälä | 9125e61 | 2013-06-03 16:10:40 +0300 | [diff] [blame] | 587 | if (plane->fb == fb) |
| 588 | drm_plane_force_disable(plane); |
Jesse Barnes | 8cf5c91 | 2011-11-14 14:51:27 -0800 | [diff] [blame] | 589 | } |
Daniel Vetter | b62584e | 2012-12-11 16:51:35 +0100 | [diff] [blame] | 590 | drm_modeset_unlock_all(dev); |
Jesse Barnes | 8cf5c91 | 2011-11-14 14:51:27 -0800 | [diff] [blame] | 591 | } |
| 592 | |
Rob Clark | f7eff60 | 2012-09-05 21:48:38 +0000 | [diff] [blame] | 593 | drm_framebuffer_unreference(fb); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 594 | } |
Rob Clark | f7eff60 | 2012-09-05 21:48:38 +0000 | [diff] [blame] | 595 | EXPORT_SYMBOL(drm_framebuffer_remove); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 596 | |
Rob Clark | 51fd371 | 2013-11-19 12:10:12 -0500 | [diff] [blame] | 597 | DEFINE_WW_CLASS(crtc_ww_class); |
| 598 | |
Ville Syrjälä | fa3ab4c | 2015-12-08 18:41:53 +0200 | [diff] [blame] | 599 | static unsigned int drm_num_crtcs(struct drm_device *dev) |
| 600 | { |
| 601 | unsigned int num = 0; |
| 602 | struct drm_crtc *tmp; |
| 603 | |
| 604 | drm_for_each_crtc(tmp, dev) { |
| 605 | num++; |
| 606 | } |
| 607 | |
| 608 | return num; |
| 609 | } |
| 610 | |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 611 | /** |
Matt Roper | e13161a | 2014-04-01 15:22:38 -0700 | [diff] [blame] | 612 | * drm_crtc_init_with_planes - Initialise a new CRTC object with |
| 613 | * specified primary and cursor planes. |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 614 | * @dev: DRM device |
| 615 | * @crtc: CRTC object to init |
Matt Roper | e13161a | 2014-04-01 15:22:38 -0700 | [diff] [blame] | 616 | * @primary: Primary plane for CRTC |
| 617 | * @cursor: Cursor plane for CRTC |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 618 | * @funcs: callbacks for the new CRTC |
Ville Syrjälä | f988287 | 2015-12-09 16:19:31 +0200 | [diff] [blame] | 619 | * @name: printf style format string for the CRTC name, or NULL for default name |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 620 | * |
Ville Syrjälä | ad6f5c3 | 2013-06-05 12:39:55 +0000 | [diff] [blame] | 621 | * 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] | 622 | * |
Daniel Vetter | c8e32cc | 2014-03-10 21:33:02 +0100 | [diff] [blame] | 623 | * Returns: |
Ville Syrjälä | 6bfc56a | 2012-03-13 12:35:48 +0200 | [diff] [blame] | 624 | * Zero on success, error code on failure. |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 625 | */ |
Matt Roper | e13161a | 2014-04-01 15:22:38 -0700 | [diff] [blame] | 626 | int drm_crtc_init_with_planes(struct drm_device *dev, struct drm_crtc *crtc, |
| 627 | struct drm_plane *primary, |
Matt Roper | fc1d3e4 | 2014-06-10 08:28:11 -0700 | [diff] [blame] | 628 | struct drm_plane *cursor, |
Ville Syrjälä | f988287 | 2015-12-09 16:19:31 +0200 | [diff] [blame] | 629 | const struct drm_crtc_funcs *funcs, |
| 630 | const char *name, ...) |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 631 | { |
Rob Clark | 51fd371 | 2013-11-19 12:10:12 -0500 | [diff] [blame] | 632 | struct drm_mode_config *config = &dev->mode_config; |
Ville Syrjälä | 6bfc56a | 2012-03-13 12:35:48 +0200 | [diff] [blame] | 633 | int ret; |
| 634 | |
Benjamin Gaignard | 522cf91 | 2015-03-17 12:05:29 +0100 | [diff] [blame] | 635 | WARN_ON(primary && primary->type != DRM_PLANE_TYPE_PRIMARY); |
| 636 | WARN_ON(cursor && cursor->type != DRM_PLANE_TYPE_CURSOR); |
| 637 | |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 638 | crtc->dev = dev; |
| 639 | crtc->funcs = funcs; |
| 640 | |
Daniel Vetter | 3b24f7d | 2016-06-08 14:19:00 +0200 | [diff] [blame^] | 641 | INIT_LIST_HEAD(&crtc->commit_list); |
| 642 | spin_lock_init(&crtc->commit_lock); |
| 643 | |
Rob Clark | 51fd371 | 2013-11-19 12:10:12 -0500 | [diff] [blame] | 644 | drm_modeset_lock_init(&crtc->mutex); |
Ville Syrjälä | 6bfc56a | 2012-03-13 12:35:48 +0200 | [diff] [blame] | 645 | ret = drm_mode_object_get(dev, &crtc->base, DRM_MODE_OBJECT_CRTC); |
| 646 | if (ret) |
Daniel Vetter | baf698b | 2014-11-12 11:59:47 +0100 | [diff] [blame] | 647 | return ret; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 648 | |
Ville Syrjälä | fa3ab4c | 2015-12-08 18:41:53 +0200 | [diff] [blame] | 649 | if (name) { |
| 650 | va_list ap; |
| 651 | |
| 652 | va_start(ap, name); |
| 653 | crtc->name = kvasprintf(GFP_KERNEL, name, ap); |
| 654 | va_end(ap); |
| 655 | } else { |
| 656 | crtc->name = kasprintf(GFP_KERNEL, "crtc-%d", |
| 657 | drm_num_crtcs(dev)); |
| 658 | } |
| 659 | if (!crtc->name) { |
Dave Airlie | 7c8f6d2 | 2016-04-15 15:10:32 +1000 | [diff] [blame] | 660 | drm_mode_object_unregister(dev, &crtc->base); |
Ville Syrjälä | fa3ab4c | 2015-12-08 18:41:53 +0200 | [diff] [blame] | 661 | return -ENOMEM; |
| 662 | } |
| 663 | |
Paulo Zanoni | bffd9de0 | 2012-05-15 18:09:05 -0300 | [diff] [blame] | 664 | crtc->base.properties = &crtc->properties; |
| 665 | |
Rob Clark | 51fd371 | 2013-11-19 12:10:12 -0500 | [diff] [blame] | 666 | list_add_tail(&crtc->head, &config->crtc_list); |
Chris Wilson | 490d3d1 | 2016-05-27 20:05:00 +0100 | [diff] [blame] | 667 | crtc->index = config->num_crtc++; |
Ville Syrjälä | 6bfc56a | 2012-03-13 12:35:48 +0200 | [diff] [blame] | 668 | |
Matt Roper | e13161a | 2014-04-01 15:22:38 -0700 | [diff] [blame] | 669 | crtc->primary = primary; |
Matt Roper | fc1d3e4 | 2014-06-10 08:28:11 -0700 | [diff] [blame] | 670 | crtc->cursor = cursor; |
Matt Roper | e13161a | 2014-04-01 15:22:38 -0700 | [diff] [blame] | 671 | if (primary) |
| 672 | primary->possible_crtcs = 1 << drm_crtc_index(crtc); |
Matt Roper | fc1d3e4 | 2014-06-10 08:28:11 -0700 | [diff] [blame] | 673 | if (cursor) |
| 674 | cursor->possible_crtcs = 1 << drm_crtc_index(crtc); |
Matt Roper | e13161a | 2014-04-01 15:22:38 -0700 | [diff] [blame] | 675 | |
Daniel Vetter | eab3bbe | 2015-01-22 16:36:21 +0100 | [diff] [blame] | 676 | if (drm_core_check_feature(dev, DRIVER_ATOMIC)) { |
| 677 | drm_object_attach_property(&crtc->base, config->prop_active, 0); |
Daniel Stone | 955f3c3 | 2015-05-25 19:11:52 +0100 | [diff] [blame] | 678 | drm_object_attach_property(&crtc->base, config->prop_mode_id, 0); |
Daniel Vetter | eab3bbe | 2015-01-22 16:36:21 +0100 | [diff] [blame] | 679 | } |
| 680 | |
Daniel Vetter | baf698b | 2014-11-12 11:59:47 +0100 | [diff] [blame] | 681 | return 0; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 682 | } |
Matt Roper | e13161a | 2014-04-01 15:22:38 -0700 | [diff] [blame] | 683 | EXPORT_SYMBOL(drm_crtc_init_with_planes); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 684 | |
| 685 | /** |
Ville Syrjälä | ad6f5c3 | 2013-06-05 12:39:55 +0000 | [diff] [blame] | 686 | * drm_crtc_cleanup - Clean up the core crtc usage |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 687 | * @crtc: CRTC to cleanup |
| 688 | * |
Ville Syrjälä | ad6f5c3 | 2013-06-05 12:39:55 +0000 | [diff] [blame] | 689 | * This function cleans up @crtc and removes it from the DRM mode setting |
| 690 | * core. Note that the function does *not* free the crtc structure itself, |
| 691 | * this is the responsibility of the caller. |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 692 | */ |
| 693 | void drm_crtc_cleanup(struct drm_crtc *crtc) |
| 694 | { |
| 695 | struct drm_device *dev = crtc->dev; |
| 696 | |
Chris Wilson | 490d3d1 | 2016-05-27 20:05:00 +0100 | [diff] [blame] | 697 | /* Note that the crtc_list is considered to be static; should we |
| 698 | * remove the drm_crtc at runtime we would have to decrement all |
| 699 | * the indices on the drm_crtc after us in the crtc_list. |
| 700 | */ |
| 701 | |
Sachin Kamat | 9e1c156 | 2012-11-19 09:44:56 +0000 | [diff] [blame] | 702 | kfree(crtc->gamma_store); |
| 703 | crtc->gamma_store = NULL; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 704 | |
Rob Clark | 51fd371 | 2013-11-19 12:10:12 -0500 | [diff] [blame] | 705 | drm_modeset_lock_fini(&crtc->mutex); |
| 706 | |
Dave Airlie | 7c8f6d2 | 2016-04-15 15:10:32 +1000 | [diff] [blame] | 707 | drm_mode_object_unregister(dev, &crtc->base); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 708 | list_del(&crtc->head); |
| 709 | dev->mode_config.num_crtc--; |
Thierry Reding | 3009c03 | 2014-11-25 12:09:49 +0100 | [diff] [blame] | 710 | |
| 711 | WARN_ON(crtc->state && !crtc->funcs->atomic_destroy_state); |
| 712 | if (crtc->state && crtc->funcs->atomic_destroy_state) |
| 713 | crtc->funcs->atomic_destroy_state(crtc, crtc->state); |
Thierry Reding | a18c0af | 2014-12-10 11:38:49 +0100 | [diff] [blame] | 714 | |
Ville Syrjälä | fa3ab4c | 2015-12-08 18:41:53 +0200 | [diff] [blame] | 715 | kfree(crtc->name); |
| 716 | |
Thierry Reding | a18c0af | 2014-12-10 11:38:49 +0100 | [diff] [blame] | 717 | memset(crtc, 0, sizeof(*crtc)); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 718 | } |
| 719 | EXPORT_SYMBOL(drm_crtc_cleanup); |
| 720 | |
Lespiau, Damien | 86f422d | 2013-08-20 00:53:06 +0100 | [diff] [blame] | 721 | /* |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 722 | * drm_mode_remove - remove and free a mode |
| 723 | * @connector: connector list to modify |
| 724 | * @mode: mode to remove |
| 725 | * |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 726 | * Remove @mode from @connector's mode list, then free it. |
| 727 | */ |
Lespiau, Damien | 86f422d | 2013-08-20 00:53:06 +0100 | [diff] [blame] | 728 | static void drm_mode_remove(struct drm_connector *connector, |
| 729 | struct drm_display_mode *mode) |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 730 | { |
| 731 | list_del(&mode->head); |
Sascha Hauer | 554f1d7 | 2012-02-01 11:38:19 +0100 | [diff] [blame] | 732 | drm_mode_destroy(connector->dev, mode); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 733 | } |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 734 | |
| 735 | /** |
Boris Brezillon | b5571e9 | 2014-07-22 12:09:10 +0200 | [diff] [blame] | 736 | * drm_display_info_set_bus_formats - set the supported bus formats |
| 737 | * @info: display info to store bus formats in |
Boris Brezillon | e37bfa1 | 2015-01-23 21:09:30 +0100 | [diff] [blame] | 738 | * @formats: array containing the supported bus formats |
| 739 | * @num_formats: the number of entries in the fmts array |
Boris Brezillon | b5571e9 | 2014-07-22 12:09:10 +0200 | [diff] [blame] | 740 | * |
| 741 | * Store the supported bus formats in display info structure. |
| 742 | * See MEDIA_BUS_FMT_* definitions in include/uapi/linux/media-bus-format.h for |
| 743 | * a full list of available formats. |
| 744 | */ |
| 745 | int drm_display_info_set_bus_formats(struct drm_display_info *info, |
| 746 | const u32 *formats, |
| 747 | unsigned int num_formats) |
| 748 | { |
| 749 | u32 *fmts = NULL; |
| 750 | |
| 751 | if (!formats && num_formats) |
| 752 | return -EINVAL; |
| 753 | |
| 754 | if (formats && num_formats) { |
| 755 | fmts = kmemdup(formats, sizeof(*formats) * num_formats, |
| 756 | GFP_KERNEL); |
Dan Carpenter | 944579c | 2015-01-28 09:43:35 +0300 | [diff] [blame] | 757 | if (!fmts) |
Boris Brezillon | b5571e9 | 2014-07-22 12:09:10 +0200 | [diff] [blame] | 758 | return -ENOMEM; |
| 759 | } |
| 760 | |
| 761 | kfree(info->bus_formats); |
| 762 | info->bus_formats = fmts; |
| 763 | info->num_bus_formats = num_formats; |
| 764 | |
| 765 | return 0; |
| 766 | } |
| 767 | EXPORT_SYMBOL(drm_display_info_set_bus_formats); |
| 768 | |
| 769 | /** |
Chris Wilson | eaf99c7 | 2014-08-06 10:08:32 +0200 | [diff] [blame] | 770 | * drm_connector_get_cmdline_mode - reads the user's cmdline mode |
| 771 | * @connector: connector to quwery |
Chris Wilson | eaf99c7 | 2014-08-06 10:08:32 +0200 | [diff] [blame] | 772 | * |
| 773 | * The kernel supports per-connector configration of its consoles through |
| 774 | * use of the video= parameter. This function parses that option and |
| 775 | * extracts the user's specified mode (or enable/disable status) for a |
| 776 | * particular connector. This is typically only used during the early fbdev |
| 777 | * setup. |
| 778 | */ |
| 779 | static void drm_connector_get_cmdline_mode(struct drm_connector *connector) |
| 780 | { |
| 781 | struct drm_cmdline_mode *mode = &connector->cmdline_mode; |
| 782 | char *option = NULL; |
| 783 | |
| 784 | if (fb_get_options(connector->name, &option)) |
| 785 | return; |
| 786 | |
| 787 | if (!drm_mode_parse_command_line_for_connector(option, |
| 788 | connector, |
| 789 | mode)) |
| 790 | return; |
| 791 | |
| 792 | if (mode->force) { |
| 793 | const char *s; |
| 794 | |
| 795 | switch (mode->force) { |
| 796 | case DRM_FORCE_OFF: |
| 797 | s = "OFF"; |
| 798 | break; |
| 799 | case DRM_FORCE_ON_DIGITAL: |
| 800 | s = "ON - dig"; |
| 801 | break; |
| 802 | default: |
| 803 | case DRM_FORCE_ON: |
| 804 | s = "ON"; |
| 805 | break; |
| 806 | } |
| 807 | |
| 808 | DRM_INFO("forcing %s connector %s\n", connector->name, s); |
| 809 | connector->force = mode->force; |
| 810 | } |
| 811 | |
| 812 | DRM_DEBUG_KMS("cmdline mode for connector %s %dx%d@%dHz%s%s%s\n", |
| 813 | connector->name, |
| 814 | mode->xres, mode->yres, |
| 815 | mode->refresh_specified ? mode->refresh : 60, |
| 816 | mode->rb ? " reduced blanking" : "", |
| 817 | mode->margins ? " with margins" : "", |
| 818 | mode->interlace ? " interlaced" : ""); |
| 819 | } |
| 820 | |
Dave Airlie | b164d31 | 2016-04-27 11:10:09 +1000 | [diff] [blame] | 821 | static void drm_connector_free(struct kref *kref) |
| 822 | { |
| 823 | struct drm_connector *connector = |
| 824 | container_of(kref, struct drm_connector, base.refcount); |
| 825 | struct drm_device *dev = connector->dev; |
| 826 | |
| 827 | drm_mode_object_unregister(dev, &connector->base); |
| 828 | connector->funcs->destroy(connector); |
| 829 | } |
| 830 | |
Chris Wilson | eaf99c7 | 2014-08-06 10:08:32 +0200 | [diff] [blame] | 831 | /** |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 832 | * drm_connector_init - Init a preallocated connector |
| 833 | * @dev: DRM device |
| 834 | * @connector: the connector to init |
| 835 | * @funcs: callbacks for this connector |
Daniel Vetter | 065a50ed | 2012-12-02 00:09:18 +0100 | [diff] [blame] | 836 | * @connector_type: user visible type of the connector |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 837 | * |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 838 | * Initialises a preallocated connector. Connectors should be |
| 839 | * subclassed as part of driver connector objects. |
Ville Syrjälä | 6bfc56a | 2012-03-13 12:35:48 +0200 | [diff] [blame] | 840 | * |
Daniel Vetter | c8e32cc | 2014-03-10 21:33:02 +0100 | [diff] [blame] | 841 | * Returns: |
Ville Syrjälä | 6bfc56a | 2012-03-13 12:35:48 +0200 | [diff] [blame] | 842 | * Zero on success, error code on failure. |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 843 | */ |
Ville Syrjälä | 6bfc56a | 2012-03-13 12:35:48 +0200 | [diff] [blame] | 844 | int drm_connector_init(struct drm_device *dev, |
| 845 | struct drm_connector *connector, |
| 846 | const struct drm_connector_funcs *funcs, |
| 847 | int connector_type) |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 848 | { |
Rob Clark | ae16c59 | 2014-12-18 16:01:54 -0500 | [diff] [blame] | 849 | struct drm_mode_config *config = &dev->mode_config; |
Ville Syrjälä | 6bfc56a | 2012-03-13 12:35:48 +0200 | [diff] [blame] | 850 | int ret; |
Ilia Mirkin | b21e3af | 2013-08-07 22:34:48 -0400 | [diff] [blame] | 851 | struct ida *connector_ida = |
| 852 | &drm_connector_enum_list[connector_type].ida; |
Ville Syrjälä | 6bfc56a | 2012-03-13 12:35:48 +0200 | [diff] [blame] | 853 | |
Daniel Vetter | 8484990 | 2012-12-02 00:28:11 +0100 | [diff] [blame] | 854 | drm_modeset_lock_all(dev); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 855 | |
Dave Airlie | b164d31 | 2016-04-27 11:10:09 +1000 | [diff] [blame] | 856 | ret = drm_mode_object_get_reg(dev, &connector->base, |
| 857 | DRM_MODE_OBJECT_CONNECTOR, |
| 858 | false, drm_connector_free); |
Ville Syrjälä | 6bfc56a | 2012-03-13 12:35:48 +0200 | [diff] [blame] | 859 | if (ret) |
Jani Nikula | 2abdd31 | 2014-05-14 16:58:19 +0300 | [diff] [blame] | 860 | goto out_unlock; |
Ville Syrjälä | 6bfc56a | 2012-03-13 12:35:48 +0200 | [diff] [blame] | 861 | |
Paulo Zanoni | 7e3bdf4 | 2012-05-15 18:09:01 -0300 | [diff] [blame] | 862 | connector->base.properties = &connector->properties; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 863 | connector->dev = dev; |
| 864 | connector->funcs = funcs; |
Maarten Lankhorst | 5fff80b | 2016-02-17 08:32:05 +0100 | [diff] [blame] | 865 | |
| 866 | connector->connector_id = ida_simple_get(&config->connector_ida, 0, 0, GFP_KERNEL); |
| 867 | if (connector->connector_id < 0) { |
| 868 | ret = connector->connector_id; |
| 869 | goto out_put; |
| 870 | } |
| 871 | |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 872 | connector->connector_type = connector_type; |
| 873 | connector->connector_type_id = |
Ilia Mirkin | b21e3af | 2013-08-07 22:34:48 -0400 | [diff] [blame] | 874 | ida_simple_get(connector_ida, 1, 0, GFP_KERNEL); |
| 875 | if (connector->connector_type_id < 0) { |
| 876 | ret = connector->connector_type_id; |
Maarten Lankhorst | 5fff80b | 2016-02-17 08:32:05 +0100 | [diff] [blame] | 877 | goto out_put_id; |
Ilia Mirkin | b21e3af | 2013-08-07 22:34:48 -0400 | [diff] [blame] | 878 | } |
Jani Nikula | 2abdd31 | 2014-05-14 16:58:19 +0300 | [diff] [blame] | 879 | connector->name = |
| 880 | kasprintf(GFP_KERNEL, "%s-%d", |
| 881 | drm_connector_enum_list[connector_type].name, |
| 882 | connector->connector_type_id); |
| 883 | if (!connector->name) { |
| 884 | ret = -ENOMEM; |
Maarten Lankhorst | 5fff80b | 2016-02-17 08:32:05 +0100 | [diff] [blame] | 885 | goto out_put_type_id; |
Jani Nikula | 2abdd31 | 2014-05-14 16:58:19 +0300 | [diff] [blame] | 886 | } |
| 887 | |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 888 | INIT_LIST_HEAD(&connector->probed_modes); |
| 889 | INIT_LIST_HEAD(&connector->modes); |
| 890 | connector->edid_blob_ptr = NULL; |
Daniel Vetter | 5e2cb2f | 2012-10-23 18:23:35 +0000 | [diff] [blame] | 891 | connector->status = connector_status_unknown; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 892 | |
Chris Wilson | eaf99c7 | 2014-08-06 10:08:32 +0200 | [diff] [blame] | 893 | drm_connector_get_cmdline_mode(connector); |
| 894 | |
Daniel Vetter | c7eb76f | 2014-11-19 18:38:06 +0100 | [diff] [blame] | 895 | /* We should add connectors at the end to avoid upsetting the connector |
| 896 | * index too much. */ |
Rob Clark | ae16c59 | 2014-12-18 16:01:54 -0500 | [diff] [blame] | 897 | list_add_tail(&connector->head, &config->connector_list); |
| 898 | config->num_connector++; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 899 | |
Thomas Hellstrom | a7331e5 | 2011-10-22 10:36:19 +0200 | [diff] [blame] | 900 | if (connector_type != DRM_MODE_CONNECTOR_VIRTUAL) |
Rob Clark | 5849556 | 2012-10-11 20:50:56 -0500 | [diff] [blame] | 901 | drm_object_attach_property(&connector->base, |
Rob Clark | ae16c59 | 2014-12-18 16:01:54 -0500 | [diff] [blame] | 902 | config->edid_property, |
Thomas Hellstrom | a7331e5 | 2011-10-22 10:36:19 +0200 | [diff] [blame] | 903 | 0); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 904 | |
Rob Clark | 5849556 | 2012-10-11 20:50:56 -0500 | [diff] [blame] | 905 | drm_object_attach_property(&connector->base, |
Rob Clark | ae16c59 | 2014-12-18 16:01:54 -0500 | [diff] [blame] | 906 | config->dpms_property, 0); |
| 907 | |
| 908 | if (drm_core_check_feature(dev, DRIVER_ATOMIC)) { |
| 909 | drm_object_attach_property(&connector->base, config->prop_crtc_id, 0); |
| 910 | } |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 911 | |
Thomas Wood | 30f6570 | 2014-06-18 17:52:32 +0100 | [diff] [blame] | 912 | connector->debugfs_entry = NULL; |
Maarten Lankhorst | 5fff80b | 2016-02-17 08:32:05 +0100 | [diff] [blame] | 913 | out_put_type_id: |
| 914 | if (ret) |
| 915 | ida_remove(connector_ida, connector->connector_type_id); |
| 916 | out_put_id: |
| 917 | if (ret) |
| 918 | ida_remove(&config->connector_ida, connector->connector_id); |
Jani Nikula | 2abdd31 | 2014-05-14 16:58:19 +0300 | [diff] [blame] | 919 | out_put: |
| 920 | if (ret) |
Dave Airlie | 7c8f6d2 | 2016-04-15 15:10:32 +1000 | [diff] [blame] | 921 | drm_mode_object_unregister(dev, &connector->base); |
Jani Nikula | 2abdd31 | 2014-05-14 16:58:19 +0300 | [diff] [blame] | 922 | |
| 923 | out_unlock: |
Daniel Vetter | 8484990 | 2012-12-02 00:28:11 +0100 | [diff] [blame] | 924 | drm_modeset_unlock_all(dev); |
Ville Syrjälä | 6bfc56a | 2012-03-13 12:35:48 +0200 | [diff] [blame] | 925 | |
| 926 | return ret; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 927 | } |
| 928 | EXPORT_SYMBOL(drm_connector_init); |
| 929 | |
| 930 | /** |
| 931 | * drm_connector_cleanup - cleans up an initialised connector |
| 932 | * @connector: connector to cleanup |
| 933 | * |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 934 | * Cleans up the connector but doesn't free the object. |
| 935 | */ |
| 936 | void drm_connector_cleanup(struct drm_connector *connector) |
| 937 | { |
| 938 | struct drm_device *dev = connector->dev; |
| 939 | struct drm_display_mode *mode, *t; |
| 940 | |
Dave Airlie | 40d9b04 | 2014-10-20 16:29:33 +1000 | [diff] [blame] | 941 | if (connector->tile_group) { |
| 942 | drm_mode_put_tile_group(dev, connector->tile_group); |
| 943 | connector->tile_group = NULL; |
| 944 | } |
| 945 | |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 946 | list_for_each_entry_safe(mode, t, &connector->probed_modes, head) |
| 947 | drm_mode_remove(connector, mode); |
| 948 | |
| 949 | list_for_each_entry_safe(mode, t, &connector->modes, head) |
| 950 | drm_mode_remove(connector, mode); |
| 951 | |
Ilia Mirkin | b21e3af | 2013-08-07 22:34:48 -0400 | [diff] [blame] | 952 | ida_remove(&drm_connector_enum_list[connector->connector_type].ida, |
| 953 | connector->connector_type_id); |
| 954 | |
Maarten Lankhorst | 5fff80b | 2016-02-17 08:32:05 +0100 | [diff] [blame] | 955 | ida_remove(&dev->mode_config.connector_ida, |
| 956 | connector->connector_id); |
| 957 | |
Boris Brezillon | b5571e9 | 2014-07-22 12:09:10 +0200 | [diff] [blame] | 958 | kfree(connector->display_info.bus_formats); |
Dave Airlie | 7c8f6d2 | 2016-04-15 15:10:32 +1000 | [diff] [blame] | 959 | drm_mode_object_unregister(dev, &connector->base); |
Jani Nikula | 2abdd31 | 2014-05-14 16:58:19 +0300 | [diff] [blame] | 960 | kfree(connector->name); |
| 961 | connector->name = NULL; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 962 | list_del(&connector->head); |
Joonyoung Shim | 6380c50 | 2011-08-27 02:06:21 +0000 | [diff] [blame] | 963 | dev->mode_config.num_connector--; |
Thierry Reding | 3009c03 | 2014-11-25 12:09:49 +0100 | [diff] [blame] | 964 | |
| 965 | WARN_ON(connector->state && !connector->funcs->atomic_destroy_state); |
| 966 | if (connector->state && connector->funcs->atomic_destroy_state) |
| 967 | connector->funcs->atomic_destroy_state(connector, |
| 968 | connector->state); |
Thierry Reding | a18c0af | 2014-12-10 11:38:49 +0100 | [diff] [blame] | 969 | |
| 970 | memset(connector, 0, sizeof(*connector)); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 971 | } |
| 972 | EXPORT_SYMBOL(drm_connector_cleanup); |
| 973 | |
Daniel Vetter | c8e32cc | 2014-03-10 21:33:02 +0100 | [diff] [blame] | 974 | /** |
Thomas Wood | 34ea3d3 | 2014-05-29 16:57:41 +0100 | [diff] [blame] | 975 | * drm_connector_register - register a connector |
| 976 | * @connector: the connector to register |
| 977 | * |
| 978 | * Register userspace interfaces for a connector |
| 979 | * |
| 980 | * Returns: |
| 981 | * Zero on success, error code on failure. |
| 982 | */ |
| 983 | int drm_connector_register(struct drm_connector *connector) |
| 984 | { |
Thomas Wood | 30f6570 | 2014-06-18 17:52:32 +0100 | [diff] [blame] | 985 | int ret; |
| 986 | |
| 987 | ret = drm_sysfs_connector_add(connector); |
| 988 | if (ret) |
| 989 | return ret; |
| 990 | |
| 991 | ret = drm_debugfs_connector_add(connector); |
| 992 | if (ret) { |
| 993 | drm_sysfs_connector_remove(connector); |
| 994 | return ret; |
| 995 | } |
| 996 | |
Daniel Vetter | fdf2c85 | 2016-05-06 14:55:02 +0200 | [diff] [blame] | 997 | drm_mode_object_register(connector->dev, &connector->base); |
| 998 | |
Thomas Wood | 30f6570 | 2014-06-18 17:52:32 +0100 | [diff] [blame] | 999 | return 0; |
Thomas Wood | 34ea3d3 | 2014-05-29 16:57:41 +0100 | [diff] [blame] | 1000 | } |
| 1001 | EXPORT_SYMBOL(drm_connector_register); |
| 1002 | |
| 1003 | /** |
| 1004 | * drm_connector_unregister - unregister a connector |
| 1005 | * @connector: the connector to unregister |
| 1006 | * |
| 1007 | * Unregister userspace interfaces for a connector |
| 1008 | */ |
| 1009 | void drm_connector_unregister(struct drm_connector *connector) |
| 1010 | { |
| 1011 | drm_sysfs_connector_remove(connector); |
Thomas Wood | 30f6570 | 2014-06-18 17:52:32 +0100 | [diff] [blame] | 1012 | drm_debugfs_connector_remove(connector); |
Thomas Wood | 34ea3d3 | 2014-05-29 16:57:41 +0100 | [diff] [blame] | 1013 | } |
| 1014 | EXPORT_SYMBOL(drm_connector_unregister); |
| 1015 | |
Thomas Wood | 34ea3d3 | 2014-05-29 16:57:41 +0100 | [diff] [blame] | 1016 | /** |
Alexey Brodkin | 54d2c2d | 2016-04-19 15:24:51 +0300 | [diff] [blame] | 1017 | * drm_connector_register_all - register all connectors |
| 1018 | * @dev: drm device |
| 1019 | * |
| 1020 | * This function registers all connectors in sysfs and other places so that |
| 1021 | * userspace can start to access them. Drivers can call it after calling |
| 1022 | * drm_dev_register() to complete the device registration, if they don't call |
| 1023 | * drm_connector_register() on each connector individually. |
| 1024 | * |
| 1025 | * When a device is unplugged and should be removed from userspace access, |
| 1026 | * call drm_connector_unregister_all(), which is the inverse of this |
| 1027 | * function. |
| 1028 | * |
| 1029 | * Returns: |
| 1030 | * Zero on success, error code on failure. |
| 1031 | */ |
| 1032 | int drm_connector_register_all(struct drm_device *dev) |
| 1033 | { |
| 1034 | struct drm_connector *connector; |
| 1035 | int ret; |
| 1036 | |
| 1037 | mutex_lock(&dev->mode_config.mutex); |
| 1038 | |
| 1039 | drm_for_each_connector(connector, dev) { |
| 1040 | ret = drm_connector_register(connector); |
| 1041 | if (ret) |
| 1042 | goto err; |
| 1043 | } |
| 1044 | |
| 1045 | mutex_unlock(&dev->mode_config.mutex); |
| 1046 | |
| 1047 | return 0; |
| 1048 | |
| 1049 | err: |
| 1050 | mutex_unlock(&dev->mode_config.mutex); |
| 1051 | drm_connector_unregister_all(dev); |
| 1052 | return ret; |
| 1053 | } |
| 1054 | EXPORT_SYMBOL(drm_connector_register_all); |
| 1055 | |
| 1056 | /** |
Alexey Brodkin | 6c87e5c | 2016-03-23 11:42:54 +0300 | [diff] [blame] | 1057 | * drm_connector_unregister_all - unregister connector userspace interfaces |
Daniel Vetter | c8e32cc | 2014-03-10 21:33:02 +0100 | [diff] [blame] | 1058 | * @dev: drm device |
| 1059 | * |
Alexey Brodkin | 6c87e5c | 2016-03-23 11:42:54 +0300 | [diff] [blame] | 1060 | * This functions unregisters all connectors from sysfs and other places so |
| 1061 | * that userspace can no longer access them. Drivers should call this as the |
| 1062 | * first step tearing down the device instace, or when the underlying |
| 1063 | * physical device disappeared (e.g. USB unplug), right before calling |
| 1064 | * drm_dev_unregister(). |
Daniel Vetter | c8e32cc | 2014-03-10 21:33:02 +0100 | [diff] [blame] | 1065 | */ |
Alexey Brodkin | 6c87e5c | 2016-03-23 11:42:54 +0300 | [diff] [blame] | 1066 | void drm_connector_unregister_all(struct drm_device *dev) |
Dave Airlie | cbc7e22 | 2012-02-20 14:16:40 +0000 | [diff] [blame] | 1067 | { |
| 1068 | struct drm_connector *connector; |
| 1069 | |
Daniel Vetter | 9a9f5ce | 2015-07-09 23:44:34 +0200 | [diff] [blame] | 1070 | /* FIXME: taking the mode config mutex ends up in a clash with sysfs */ |
Laurent Pinchart | 14ba003 | 2016-04-21 01:21:14 +0300 | [diff] [blame] | 1071 | list_for_each_entry(connector, &dev->mode_config.connector_list, head) |
Thomas Wood | 34ea3d3 | 2014-05-29 16:57:41 +0100 | [diff] [blame] | 1072 | drm_connector_unregister(connector); |
Dave Airlie | cbc7e22 | 2012-02-20 14:16:40 +0000 | [diff] [blame] | 1073 | } |
Alexey Brodkin | 6c87e5c | 2016-03-23 11:42:54 +0300 | [diff] [blame] | 1074 | EXPORT_SYMBOL(drm_connector_unregister_all); |
Dave Airlie | cbc7e22 | 2012-02-20 14:16:40 +0000 | [diff] [blame] | 1075 | |
Daniel Vetter | c8e32cc | 2014-03-10 21:33:02 +0100 | [diff] [blame] | 1076 | /** |
Daniel Vetter | c8e32cc | 2014-03-10 21:33:02 +0100 | [diff] [blame] | 1077 | * drm_encoder_init - Init a preallocated encoder |
| 1078 | * @dev: drm device |
| 1079 | * @encoder: the encoder to init |
| 1080 | * @funcs: callbacks for this encoder |
| 1081 | * @encoder_type: user visible type of the encoder |
Ville Syrjälä | 13a3d91 | 2015-12-09 16:20:18 +0200 | [diff] [blame] | 1082 | * @name: printf style format string for the encoder name, or NULL for default name |
Daniel Vetter | c8e32cc | 2014-03-10 21:33:02 +0100 | [diff] [blame] | 1083 | * |
| 1084 | * Initialises a preallocated encoder. Encoder should be |
| 1085 | * subclassed as part of driver encoder objects. |
| 1086 | * |
| 1087 | * Returns: |
| 1088 | * Zero on success, error code on failure. |
| 1089 | */ |
Ville Syrjälä | 6bfc56a | 2012-03-13 12:35:48 +0200 | [diff] [blame] | 1090 | int drm_encoder_init(struct drm_device *dev, |
Dave Airlie | cbc7e22 | 2012-02-20 14:16:40 +0000 | [diff] [blame] | 1091 | struct drm_encoder *encoder, |
| 1092 | const struct drm_encoder_funcs *funcs, |
Ville Syrjälä | 13a3d91 | 2015-12-09 16:20:18 +0200 | [diff] [blame] | 1093 | int encoder_type, const char *name, ...) |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 1094 | { |
Ville Syrjälä | 6bfc56a | 2012-03-13 12:35:48 +0200 | [diff] [blame] | 1095 | int ret; |
| 1096 | |
Daniel Vetter | 8484990 | 2012-12-02 00:28:11 +0100 | [diff] [blame] | 1097 | drm_modeset_lock_all(dev); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 1098 | |
Ville Syrjälä | 6bfc56a | 2012-03-13 12:35:48 +0200 | [diff] [blame] | 1099 | ret = drm_mode_object_get(dev, &encoder->base, DRM_MODE_OBJECT_ENCODER); |
| 1100 | if (ret) |
Jani Nikula | e574894 | 2014-05-14 16:58:20 +0300 | [diff] [blame] | 1101 | goto out_unlock; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 1102 | |
Ville Syrjälä | 6bfc56a | 2012-03-13 12:35:48 +0200 | [diff] [blame] | 1103 | encoder->dev = dev; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 1104 | encoder->encoder_type = encoder_type; |
| 1105 | encoder->funcs = funcs; |
Ville Syrjälä | 86bf546 | 2015-12-08 18:41:52 +0200 | [diff] [blame] | 1106 | if (name) { |
| 1107 | va_list ap; |
| 1108 | |
| 1109 | va_start(ap, name); |
| 1110 | encoder->name = kvasprintf(GFP_KERNEL, name, ap); |
| 1111 | va_end(ap); |
| 1112 | } else { |
| 1113 | encoder->name = kasprintf(GFP_KERNEL, "%s-%d", |
| 1114 | drm_encoder_enum_list[encoder_type].name, |
| 1115 | encoder->base.id); |
| 1116 | } |
Jani Nikula | e574894 | 2014-05-14 16:58:20 +0300 | [diff] [blame] | 1117 | if (!encoder->name) { |
| 1118 | ret = -ENOMEM; |
| 1119 | goto out_put; |
| 1120 | } |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 1121 | |
| 1122 | list_add_tail(&encoder->head, &dev->mode_config.encoder_list); |
Chris Wilson | 490d3d1 | 2016-05-27 20:05:00 +0100 | [diff] [blame] | 1123 | encoder->index = dev->mode_config.num_encoder++; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 1124 | |
Jani Nikula | e574894 | 2014-05-14 16:58:20 +0300 | [diff] [blame] | 1125 | out_put: |
| 1126 | if (ret) |
Dave Airlie | 7c8f6d2 | 2016-04-15 15:10:32 +1000 | [diff] [blame] | 1127 | drm_mode_object_unregister(dev, &encoder->base); |
Jani Nikula | e574894 | 2014-05-14 16:58:20 +0300 | [diff] [blame] | 1128 | |
| 1129 | out_unlock: |
Daniel Vetter | 8484990 | 2012-12-02 00:28:11 +0100 | [diff] [blame] | 1130 | drm_modeset_unlock_all(dev); |
Ville Syrjälä | 6bfc56a | 2012-03-13 12:35:48 +0200 | [diff] [blame] | 1131 | |
| 1132 | return ret; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 1133 | } |
| 1134 | EXPORT_SYMBOL(drm_encoder_init); |
| 1135 | |
Daniel Vetter | c8e32cc | 2014-03-10 21:33:02 +0100 | [diff] [blame] | 1136 | /** |
| 1137 | * drm_encoder_cleanup - cleans up an initialised encoder |
| 1138 | * @encoder: encoder to cleanup |
| 1139 | * |
| 1140 | * Cleans up the encoder but doesn't free the object. |
| 1141 | */ |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 1142 | void drm_encoder_cleanup(struct drm_encoder *encoder) |
| 1143 | { |
| 1144 | struct drm_device *dev = encoder->dev; |
Thierry Reding | 4dfd909 | 2014-12-10 13:03:34 +0100 | [diff] [blame] | 1145 | |
Chris Wilson | 490d3d1 | 2016-05-27 20:05:00 +0100 | [diff] [blame] | 1146 | /* Note that the encoder_list is considered to be static; should we |
| 1147 | * remove the drm_encoder at runtime we would have to decrement all |
| 1148 | * the indices on the drm_encoder after us in the encoder_list. |
| 1149 | */ |
| 1150 | |
Daniel Vetter | 8484990 | 2012-12-02 00:28:11 +0100 | [diff] [blame] | 1151 | drm_modeset_lock_all(dev); |
Dave Airlie | 7c8f6d2 | 2016-04-15 15:10:32 +1000 | [diff] [blame] | 1152 | drm_mode_object_unregister(dev, &encoder->base); |
Jani Nikula | e574894 | 2014-05-14 16:58:20 +0300 | [diff] [blame] | 1153 | kfree(encoder->name); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 1154 | list_del(&encoder->head); |
Joonyoung Shim | 6380c50 | 2011-08-27 02:06:21 +0000 | [diff] [blame] | 1155 | dev->mode_config.num_encoder--; |
Daniel Vetter | 8484990 | 2012-12-02 00:28:11 +0100 | [diff] [blame] | 1156 | drm_modeset_unlock_all(dev); |
Thierry Reding | a18c0af | 2014-12-10 11:38:49 +0100 | [diff] [blame] | 1157 | |
| 1158 | memset(encoder, 0, sizeof(*encoder)); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 1159 | } |
| 1160 | EXPORT_SYMBOL(drm_encoder_cleanup); |
| 1161 | |
Ville Syrjälä | 9f4c97a | 2015-12-08 18:41:54 +0200 | [diff] [blame] | 1162 | static unsigned int drm_num_planes(struct drm_device *dev) |
| 1163 | { |
| 1164 | unsigned int num = 0; |
| 1165 | struct drm_plane *tmp; |
| 1166 | |
| 1167 | drm_for_each_plane(tmp, dev) { |
| 1168 | num++; |
| 1169 | } |
| 1170 | |
| 1171 | return num; |
| 1172 | } |
| 1173 | |
Ville Syrjälä | 35f2c3a | 2013-06-05 15:39:56 +0300 | [diff] [blame] | 1174 | /** |
Matt Roper | dc415ff | 2014-04-01 15:22:36 -0700 | [diff] [blame] | 1175 | * drm_universal_plane_init - Initialize a new universal plane object |
Ville Syrjälä | 35f2c3a | 2013-06-05 15:39:56 +0300 | [diff] [blame] | 1176 | * @dev: DRM device |
| 1177 | * @plane: plane object to init |
| 1178 | * @possible_crtcs: bitmask of possible CRTCs |
| 1179 | * @funcs: callbacks for the new plane |
| 1180 | * @formats: array of supported formats (%DRM_FORMAT_*) |
| 1181 | * @format_count: number of elements in @formats |
Matt Roper | dc415ff | 2014-04-01 15:22:36 -0700 | [diff] [blame] | 1182 | * @type: type of plane (overlay, primary, cursor) |
Ville Syrjälä | b0b3b79 | 2015-12-09 16:19:55 +0200 | [diff] [blame] | 1183 | * @name: printf style format string for the plane name, or NULL for default name |
Ville Syrjälä | 35f2c3a | 2013-06-05 15:39:56 +0300 | [diff] [blame] | 1184 | * |
Matt Roper | dc415ff | 2014-04-01 15:22:36 -0700 | [diff] [blame] | 1185 | * Initializes a plane object of type @type. |
Ville Syrjälä | 35f2c3a | 2013-06-05 15:39:56 +0300 | [diff] [blame] | 1186 | * |
Daniel Vetter | c8e32cc | 2014-03-10 21:33:02 +0100 | [diff] [blame] | 1187 | * Returns: |
Ville Syrjälä | 35f2c3a | 2013-06-05 15:39:56 +0300 | [diff] [blame] | 1188 | * Zero on success, error code on failure. |
| 1189 | */ |
Matt Roper | dc415ff | 2014-04-01 15:22:36 -0700 | [diff] [blame] | 1190 | int drm_universal_plane_init(struct drm_device *dev, struct drm_plane *plane, |
| 1191 | unsigned long possible_crtcs, |
| 1192 | const struct drm_plane_funcs *funcs, |
Thierry Reding | 45e3743 | 2015-08-12 16:54:28 +0200 | [diff] [blame] | 1193 | const uint32_t *formats, unsigned int format_count, |
Ville Syrjälä | b0b3b79 | 2015-12-09 16:19:55 +0200 | [diff] [blame] | 1194 | enum drm_plane_type type, |
| 1195 | const char *name, ...) |
Jesse Barnes | 8cf5c91 | 2011-11-14 14:51:27 -0800 | [diff] [blame] | 1196 | { |
Rob Clark | 6b4959f | 2014-12-18 16:01:53 -0500 | [diff] [blame] | 1197 | struct drm_mode_config *config = &dev->mode_config; |
Ville Syrjälä | 6bfc56a | 2012-03-13 12:35:48 +0200 | [diff] [blame] | 1198 | int ret; |
| 1199 | |
Ville Syrjälä | 6bfc56a | 2012-03-13 12:35:48 +0200 | [diff] [blame] | 1200 | ret = drm_mode_object_get(dev, &plane->base, DRM_MODE_OBJECT_PLANE); |
| 1201 | if (ret) |
Daniel Vetter | baf698b | 2014-11-12 11:59:47 +0100 | [diff] [blame] | 1202 | return ret; |
Ville Syrjälä | 6bfc56a | 2012-03-13 12:35:48 +0200 | [diff] [blame] | 1203 | |
Daniel Vetter | 4d02e2d | 2014-11-11 10:12:00 +0100 | [diff] [blame] | 1204 | drm_modeset_lock_init(&plane->mutex); |
| 1205 | |
Rob Clark | 4d93914 | 2012-05-17 02:23:27 -0600 | [diff] [blame] | 1206 | plane->base.properties = &plane->properties; |
Jesse Barnes | 8cf5c91 | 2011-11-14 14:51:27 -0800 | [diff] [blame] | 1207 | plane->dev = dev; |
Jesse Barnes | 8cf5c91 | 2011-11-14 14:51:27 -0800 | [diff] [blame] | 1208 | plane->funcs = funcs; |
Thierry Reding | 2f6c538 | 2014-12-10 13:03:36 +0100 | [diff] [blame] | 1209 | plane->format_types = kmalloc_array(format_count, sizeof(uint32_t), |
| 1210 | GFP_KERNEL); |
Jesse Barnes | 8cf5c91 | 2011-11-14 14:51:27 -0800 | [diff] [blame] | 1211 | if (!plane->format_types) { |
| 1212 | DRM_DEBUG_KMS("out of memory when allocating plane\n"); |
Dave Airlie | 7c8f6d2 | 2016-04-15 15:10:32 +1000 | [diff] [blame] | 1213 | drm_mode_object_unregister(dev, &plane->base); |
Daniel Vetter | baf698b | 2014-11-12 11:59:47 +0100 | [diff] [blame] | 1214 | return -ENOMEM; |
Jesse Barnes | 8cf5c91 | 2011-11-14 14:51:27 -0800 | [diff] [blame] | 1215 | } |
| 1216 | |
Ville Syrjälä | 9f4c97a | 2015-12-08 18:41:54 +0200 | [diff] [blame] | 1217 | if (name) { |
| 1218 | va_list ap; |
| 1219 | |
| 1220 | va_start(ap, name); |
| 1221 | plane->name = kvasprintf(GFP_KERNEL, name, ap); |
| 1222 | va_end(ap); |
| 1223 | } else { |
| 1224 | plane->name = kasprintf(GFP_KERNEL, "plane-%d", |
| 1225 | drm_num_planes(dev)); |
| 1226 | } |
| 1227 | if (!plane->name) { |
| 1228 | kfree(plane->format_types); |
Dave Airlie | 7c8f6d2 | 2016-04-15 15:10:32 +1000 | [diff] [blame] | 1229 | drm_mode_object_unregister(dev, &plane->base); |
Ville Syrjälä | 9f4c97a | 2015-12-08 18:41:54 +0200 | [diff] [blame] | 1230 | return -ENOMEM; |
| 1231 | } |
| 1232 | |
Jesse Barnes | 308e5bc | 2011-11-14 14:51:28 -0800 | [diff] [blame] | 1233 | memcpy(plane->format_types, formats, format_count * sizeof(uint32_t)); |
Jesse Barnes | 8cf5c91 | 2011-11-14 14:51:27 -0800 | [diff] [blame] | 1234 | plane->format_count = format_count; |
| 1235 | plane->possible_crtcs = possible_crtcs; |
Matt Roper | dc415ff | 2014-04-01 15:22:36 -0700 | [diff] [blame] | 1236 | plane->type = type; |
Jesse Barnes | 8cf5c91 | 2011-11-14 14:51:27 -0800 | [diff] [blame] | 1237 | |
Rob Clark | 6b4959f | 2014-12-18 16:01:53 -0500 | [diff] [blame] | 1238 | list_add_tail(&plane->head, &config->plane_list); |
Chris Wilson | 490d3d1 | 2016-05-27 20:05:00 +0100 | [diff] [blame] | 1239 | plane->index = config->num_total_plane++; |
Matt Roper | dc415ff | 2014-04-01 15:22:36 -0700 | [diff] [blame] | 1240 | if (plane->type == DRM_PLANE_TYPE_OVERLAY) |
Rob Clark | 6b4959f | 2014-12-18 16:01:53 -0500 | [diff] [blame] | 1241 | config->num_overlay_plane++; |
Jesse Barnes | 8cf5c91 | 2011-11-14 14:51:27 -0800 | [diff] [blame] | 1242 | |
Rob Clark | 9922ab5 | 2014-04-01 20:16:57 -0400 | [diff] [blame] | 1243 | drm_object_attach_property(&plane->base, |
Rob Clark | 6b4959f | 2014-12-18 16:01:53 -0500 | [diff] [blame] | 1244 | config->plane_type_property, |
Rob Clark | 9922ab5 | 2014-04-01 20:16:57 -0400 | [diff] [blame] | 1245 | plane->type); |
| 1246 | |
Rob Clark | 6b4959f | 2014-12-18 16:01:53 -0500 | [diff] [blame] | 1247 | if (drm_core_check_feature(dev, DRIVER_ATOMIC)) { |
| 1248 | drm_object_attach_property(&plane->base, config->prop_fb_id, 0); |
| 1249 | drm_object_attach_property(&plane->base, config->prop_crtc_id, 0); |
| 1250 | drm_object_attach_property(&plane->base, config->prop_crtc_x, 0); |
| 1251 | drm_object_attach_property(&plane->base, config->prop_crtc_y, 0); |
| 1252 | drm_object_attach_property(&plane->base, config->prop_crtc_w, 0); |
| 1253 | drm_object_attach_property(&plane->base, config->prop_crtc_h, 0); |
| 1254 | drm_object_attach_property(&plane->base, config->prop_src_x, 0); |
| 1255 | drm_object_attach_property(&plane->base, config->prop_src_y, 0); |
| 1256 | drm_object_attach_property(&plane->base, config->prop_src_w, 0); |
| 1257 | drm_object_attach_property(&plane->base, config->prop_src_h, 0); |
| 1258 | } |
| 1259 | |
Daniel Vetter | baf698b | 2014-11-12 11:59:47 +0100 | [diff] [blame] | 1260 | return 0; |
Jesse Barnes | 8cf5c91 | 2011-11-14 14:51:27 -0800 | [diff] [blame] | 1261 | } |
Matt Roper | dc415ff | 2014-04-01 15:22:36 -0700 | [diff] [blame] | 1262 | EXPORT_SYMBOL(drm_universal_plane_init); |
| 1263 | |
| 1264 | /** |
| 1265 | * drm_plane_init - Initialize a legacy plane |
| 1266 | * @dev: DRM device |
| 1267 | * @plane: plane object to init |
| 1268 | * @possible_crtcs: bitmask of possible CRTCs |
| 1269 | * @funcs: callbacks for the new plane |
| 1270 | * @formats: array of supported formats (%DRM_FORMAT_*) |
| 1271 | * @format_count: number of elements in @formats |
| 1272 | * @is_primary: plane type (primary vs overlay) |
| 1273 | * |
| 1274 | * Legacy API to initialize a DRM plane. |
| 1275 | * |
| 1276 | * New drivers should call drm_universal_plane_init() instead. |
| 1277 | * |
| 1278 | * Returns: |
| 1279 | * Zero on success, error code on failure. |
| 1280 | */ |
| 1281 | int drm_plane_init(struct drm_device *dev, struct drm_plane *plane, |
| 1282 | unsigned long possible_crtcs, |
| 1283 | const struct drm_plane_funcs *funcs, |
Thierry Reding | 45e3743 | 2015-08-12 16:54:28 +0200 | [diff] [blame] | 1284 | const uint32_t *formats, unsigned int format_count, |
Matt Roper | dc415ff | 2014-04-01 15:22:36 -0700 | [diff] [blame] | 1285 | bool is_primary) |
| 1286 | { |
| 1287 | enum drm_plane_type type; |
| 1288 | |
| 1289 | type = is_primary ? DRM_PLANE_TYPE_PRIMARY : DRM_PLANE_TYPE_OVERLAY; |
| 1290 | return drm_universal_plane_init(dev, plane, possible_crtcs, funcs, |
Ville Syrjälä | b0b3b79 | 2015-12-09 16:19:55 +0200 | [diff] [blame] | 1291 | formats, format_count, type, NULL); |
Matt Roper | dc415ff | 2014-04-01 15:22:36 -0700 | [diff] [blame] | 1292 | } |
Jesse Barnes | 8cf5c91 | 2011-11-14 14:51:27 -0800 | [diff] [blame] | 1293 | EXPORT_SYMBOL(drm_plane_init); |
| 1294 | |
Ville Syrjälä | 35f2c3a | 2013-06-05 15:39:56 +0300 | [diff] [blame] | 1295 | /** |
| 1296 | * drm_plane_cleanup - Clean up the core plane usage |
| 1297 | * @plane: plane to cleanup |
| 1298 | * |
| 1299 | * This function cleans up @plane and removes it from the DRM mode setting |
| 1300 | * core. Note that the function does *not* free the plane structure itself, |
| 1301 | * this is the responsibility of the caller. |
| 1302 | */ |
Jesse Barnes | 8cf5c91 | 2011-11-14 14:51:27 -0800 | [diff] [blame] | 1303 | void drm_plane_cleanup(struct drm_plane *plane) |
| 1304 | { |
| 1305 | struct drm_device *dev = plane->dev; |
| 1306 | |
Daniel Vetter | 8484990 | 2012-12-02 00:28:11 +0100 | [diff] [blame] | 1307 | drm_modeset_lock_all(dev); |
Jesse Barnes | 8cf5c91 | 2011-11-14 14:51:27 -0800 | [diff] [blame] | 1308 | kfree(plane->format_types); |
Dave Airlie | 7c8f6d2 | 2016-04-15 15:10:32 +1000 | [diff] [blame] | 1309 | drm_mode_object_unregister(dev, &plane->base); |
Matt Roper | dc415ff | 2014-04-01 15:22:36 -0700 | [diff] [blame] | 1310 | |
| 1311 | BUG_ON(list_empty(&plane->head)); |
| 1312 | |
Chris Wilson | 490d3d1 | 2016-05-27 20:05:00 +0100 | [diff] [blame] | 1313 | /* Note that the plane_list is considered to be static; should we |
| 1314 | * remove the drm_plane at runtime we would have to decrement all |
| 1315 | * the indices on the drm_plane after us in the plane_list. |
| 1316 | */ |
| 1317 | |
Matt Roper | dc415ff | 2014-04-01 15:22:36 -0700 | [diff] [blame] | 1318 | list_del(&plane->head); |
| 1319 | dev->mode_config.num_total_plane--; |
| 1320 | if (plane->type == DRM_PLANE_TYPE_OVERLAY) |
| 1321 | dev->mode_config.num_overlay_plane--; |
Daniel Vetter | 8484990 | 2012-12-02 00:28:11 +0100 | [diff] [blame] | 1322 | drm_modeset_unlock_all(dev); |
Thierry Reding | 3009c03 | 2014-11-25 12:09:49 +0100 | [diff] [blame] | 1323 | |
| 1324 | WARN_ON(plane->state && !plane->funcs->atomic_destroy_state); |
| 1325 | if (plane->state && plane->funcs->atomic_destroy_state) |
| 1326 | plane->funcs->atomic_destroy_state(plane, plane->state); |
Thierry Reding | a18c0af | 2014-12-10 11:38:49 +0100 | [diff] [blame] | 1327 | |
Ville Syrjälä | 9f4c97a | 2015-12-08 18:41:54 +0200 | [diff] [blame] | 1328 | kfree(plane->name); |
| 1329 | |
Thierry Reding | a18c0af | 2014-12-10 11:38:49 +0100 | [diff] [blame] | 1330 | memset(plane, 0, sizeof(*plane)); |
Jesse Barnes | 8cf5c91 | 2011-11-14 14:51:27 -0800 | [diff] [blame] | 1331 | } |
| 1332 | EXPORT_SYMBOL(drm_plane_cleanup); |
| 1333 | |
Ville Syrjälä | 35f2c3a | 2013-06-05 15:39:56 +0300 | [diff] [blame] | 1334 | /** |
Chandra Konduru | f81338a | 2015-04-09 17:36:21 -0700 | [diff] [blame] | 1335 | * drm_plane_from_index - find the registered plane at an index |
| 1336 | * @dev: DRM device |
| 1337 | * @idx: index of registered plane to find for |
| 1338 | * |
| 1339 | * Given a plane index, return the registered plane from DRM device's |
| 1340 | * list of planes with matching index. |
| 1341 | */ |
| 1342 | struct drm_plane * |
| 1343 | drm_plane_from_index(struct drm_device *dev, int idx) |
| 1344 | { |
| 1345 | struct drm_plane *plane; |
Chandra Konduru | f81338a | 2015-04-09 17:36:21 -0700 | [diff] [blame] | 1346 | |
Chris Wilson | 490d3d1 | 2016-05-27 20:05:00 +0100 | [diff] [blame] | 1347 | drm_for_each_plane(plane, dev) |
| 1348 | if (idx == plane->index) |
Chandra Konduru | f81338a | 2015-04-09 17:36:21 -0700 | [diff] [blame] | 1349 | return plane; |
Chris Wilson | 490d3d1 | 2016-05-27 20:05:00 +0100 | [diff] [blame] | 1350 | |
Chandra Konduru | f81338a | 2015-04-09 17:36:21 -0700 | [diff] [blame] | 1351 | return NULL; |
| 1352 | } |
| 1353 | EXPORT_SYMBOL(drm_plane_from_index); |
| 1354 | |
| 1355 | /** |
Ville Syrjälä | 35f2c3a | 2013-06-05 15:39:56 +0300 | [diff] [blame] | 1356 | * drm_plane_force_disable - Forcibly disable a plane |
| 1357 | * @plane: plane to disable |
| 1358 | * |
| 1359 | * Forces the plane to be disabled. |
| 1360 | * |
| 1361 | * Used when the plane's current framebuffer is destroyed, |
| 1362 | * and when restoring fbdev mode. |
| 1363 | */ |
Ville Syrjälä | 9125e61 | 2013-06-03 16:10:40 +0300 | [diff] [blame] | 1364 | void drm_plane_force_disable(struct drm_plane *plane) |
| 1365 | { |
| 1366 | int ret; |
| 1367 | |
Daniel Vetter | 3d30a59 | 2014-07-27 13:42:42 +0200 | [diff] [blame] | 1368 | if (!plane->fb) |
Ville Syrjälä | 9125e61 | 2013-06-03 16:10:40 +0300 | [diff] [blame] | 1369 | return; |
| 1370 | |
Daniel Vetter | 3d30a59 | 2014-07-27 13:42:42 +0200 | [diff] [blame] | 1371 | plane->old_fb = plane->fb; |
Ville Syrjälä | 9125e61 | 2013-06-03 16:10:40 +0300 | [diff] [blame] | 1372 | ret = plane->funcs->disable_plane(plane); |
Daniel Vetter | 731cce4 | 2014-04-23 10:24:11 +0200 | [diff] [blame] | 1373 | if (ret) { |
Ville Syrjälä | 9125e61 | 2013-06-03 16:10:40 +0300 | [diff] [blame] | 1374 | DRM_ERROR("failed to disable plane with busy fb\n"); |
Daniel Vetter | 3d30a59 | 2014-07-27 13:42:42 +0200 | [diff] [blame] | 1375 | plane->old_fb = NULL; |
Daniel Vetter | 731cce4 | 2014-04-23 10:24:11 +0200 | [diff] [blame] | 1376 | return; |
| 1377 | } |
Ville Syrjälä | 9125e61 | 2013-06-03 16:10:40 +0300 | [diff] [blame] | 1378 | /* disconnect the plane from the fb and crtc: */ |
Daniel Vetter | 220dd2b | 2015-02-27 12:58:13 +0100 | [diff] [blame] | 1379 | drm_framebuffer_unreference(plane->old_fb); |
Daniel Vetter | 3d30a59 | 2014-07-27 13:42:42 +0200 | [diff] [blame] | 1380 | plane->old_fb = NULL; |
Ville Syrjälä | 9125e61 | 2013-06-03 16:10:40 +0300 | [diff] [blame] | 1381 | plane->fb = NULL; |
| 1382 | plane->crtc = NULL; |
| 1383 | } |
| 1384 | EXPORT_SYMBOL(drm_plane_force_disable); |
| 1385 | |
Rob Clark | 6b4959f | 2014-12-18 16:01:53 -0500 | [diff] [blame] | 1386 | static int drm_mode_create_standard_properties(struct drm_device *dev) |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 1387 | { |
Rob Clark | 356af0e | 2014-12-18 16:01:52 -0500 | [diff] [blame] | 1388 | struct drm_property *prop; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 1389 | |
| 1390 | /* |
| 1391 | * Standard properties (apply to all connectors) |
| 1392 | */ |
Rob Clark | 356af0e | 2014-12-18 16:01:52 -0500 | [diff] [blame] | 1393 | prop = drm_property_create(dev, DRM_MODE_PROP_BLOB | |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 1394 | DRM_MODE_PROP_IMMUTABLE, |
| 1395 | "EDID", 0); |
Rob Clark | 356af0e | 2014-12-18 16:01:52 -0500 | [diff] [blame] | 1396 | if (!prop) |
| 1397 | return -ENOMEM; |
| 1398 | dev->mode_config.edid_property = prop; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 1399 | |
Rob Clark | 356af0e | 2014-12-18 16:01:52 -0500 | [diff] [blame] | 1400 | prop = drm_property_create_enum(dev, 0, |
Sascha Hauer | 4a67d39 | 2012-02-06 10:58:17 +0100 | [diff] [blame] | 1401 | "DPMS", drm_dpms_enum_list, |
| 1402 | ARRAY_SIZE(drm_dpms_enum_list)); |
Rob Clark | 356af0e | 2014-12-18 16:01:52 -0500 | [diff] [blame] | 1403 | if (!prop) |
| 1404 | return -ENOMEM; |
| 1405 | dev->mode_config.dpms_property = prop; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 1406 | |
Rob Clark | 356af0e | 2014-12-18 16:01:52 -0500 | [diff] [blame] | 1407 | prop = drm_property_create(dev, |
| 1408 | DRM_MODE_PROP_BLOB | |
| 1409 | DRM_MODE_PROP_IMMUTABLE, |
| 1410 | "PATH", 0); |
| 1411 | if (!prop) |
| 1412 | return -ENOMEM; |
| 1413 | dev->mode_config.path_property = prop; |
Dave Airlie | 43aba7e | 2014-06-05 14:01:31 +1000 | [diff] [blame] | 1414 | |
Rob Clark | 356af0e | 2014-12-18 16:01:52 -0500 | [diff] [blame] | 1415 | prop = drm_property_create(dev, |
| 1416 | DRM_MODE_PROP_BLOB | |
| 1417 | DRM_MODE_PROP_IMMUTABLE, |
| 1418 | "TILE", 0); |
| 1419 | if (!prop) |
| 1420 | return -ENOMEM; |
| 1421 | dev->mode_config.tile_property = prop; |
Dave Airlie | 6f134d7 | 2014-10-20 16:30:50 +1000 | [diff] [blame] | 1422 | |
Rob Clark | 6b4959f | 2014-12-18 16:01:53 -0500 | [diff] [blame] | 1423 | prop = drm_property_create_enum(dev, DRM_MODE_PROP_IMMUTABLE, |
Rob Clark | 9922ab5 | 2014-04-01 20:16:57 -0400 | [diff] [blame] | 1424 | "type", drm_plane_type_enum_list, |
| 1425 | ARRAY_SIZE(drm_plane_type_enum_list)); |
Rob Clark | 6b4959f | 2014-12-18 16:01:53 -0500 | [diff] [blame] | 1426 | if (!prop) |
| 1427 | return -ENOMEM; |
| 1428 | dev->mode_config.plane_type_property = prop; |
| 1429 | |
| 1430 | prop = drm_property_create_range(dev, DRM_MODE_PROP_ATOMIC, |
| 1431 | "SRC_X", 0, UINT_MAX); |
| 1432 | if (!prop) |
| 1433 | return -ENOMEM; |
| 1434 | dev->mode_config.prop_src_x = prop; |
| 1435 | |
| 1436 | prop = drm_property_create_range(dev, DRM_MODE_PROP_ATOMIC, |
| 1437 | "SRC_Y", 0, UINT_MAX); |
| 1438 | if (!prop) |
| 1439 | return -ENOMEM; |
| 1440 | dev->mode_config.prop_src_y = prop; |
| 1441 | |
| 1442 | prop = drm_property_create_range(dev, DRM_MODE_PROP_ATOMIC, |
| 1443 | "SRC_W", 0, UINT_MAX); |
| 1444 | if (!prop) |
| 1445 | return -ENOMEM; |
| 1446 | dev->mode_config.prop_src_w = prop; |
| 1447 | |
| 1448 | prop = drm_property_create_range(dev, DRM_MODE_PROP_ATOMIC, |
| 1449 | "SRC_H", 0, UINT_MAX); |
| 1450 | if (!prop) |
| 1451 | return -ENOMEM; |
| 1452 | dev->mode_config.prop_src_h = prop; |
| 1453 | |
| 1454 | prop = drm_property_create_signed_range(dev, DRM_MODE_PROP_ATOMIC, |
| 1455 | "CRTC_X", INT_MIN, INT_MAX); |
| 1456 | if (!prop) |
| 1457 | return -ENOMEM; |
| 1458 | dev->mode_config.prop_crtc_x = prop; |
| 1459 | |
| 1460 | prop = drm_property_create_signed_range(dev, DRM_MODE_PROP_ATOMIC, |
| 1461 | "CRTC_Y", INT_MIN, INT_MAX); |
| 1462 | if (!prop) |
| 1463 | return -ENOMEM; |
| 1464 | dev->mode_config.prop_crtc_y = prop; |
| 1465 | |
| 1466 | prop = drm_property_create_range(dev, DRM_MODE_PROP_ATOMIC, |
| 1467 | "CRTC_W", 0, INT_MAX); |
| 1468 | if (!prop) |
| 1469 | return -ENOMEM; |
| 1470 | dev->mode_config.prop_crtc_w = prop; |
| 1471 | |
| 1472 | prop = drm_property_create_range(dev, DRM_MODE_PROP_ATOMIC, |
| 1473 | "CRTC_H", 0, INT_MAX); |
| 1474 | if (!prop) |
| 1475 | return -ENOMEM; |
| 1476 | dev->mode_config.prop_crtc_h = prop; |
| 1477 | |
| 1478 | prop = drm_property_create_object(dev, DRM_MODE_PROP_ATOMIC, |
| 1479 | "FB_ID", DRM_MODE_OBJECT_FB); |
| 1480 | if (!prop) |
| 1481 | return -ENOMEM; |
| 1482 | dev->mode_config.prop_fb_id = prop; |
| 1483 | |
| 1484 | prop = drm_property_create_object(dev, DRM_MODE_PROP_ATOMIC, |
| 1485 | "CRTC_ID", DRM_MODE_OBJECT_CRTC); |
| 1486 | if (!prop) |
| 1487 | return -ENOMEM; |
| 1488 | dev->mode_config.prop_crtc_id = prop; |
Rob Clark | 9922ab5 | 2014-04-01 20:16:57 -0400 | [diff] [blame] | 1489 | |
Daniel Vetter | eab3bbe | 2015-01-22 16:36:21 +0100 | [diff] [blame] | 1490 | prop = drm_property_create_bool(dev, DRM_MODE_PROP_ATOMIC, |
| 1491 | "ACTIVE"); |
| 1492 | if (!prop) |
| 1493 | return -ENOMEM; |
| 1494 | dev->mode_config.prop_active = prop; |
| 1495 | |
Daniel Stone | 955f3c3 | 2015-05-25 19:11:52 +0100 | [diff] [blame] | 1496 | prop = drm_property_create(dev, |
| 1497 | DRM_MODE_PROP_ATOMIC | DRM_MODE_PROP_BLOB, |
| 1498 | "MODE_ID", 0); |
| 1499 | if (!prop) |
| 1500 | return -ENOMEM; |
| 1501 | dev->mode_config.prop_mode_id = prop; |
| 1502 | |
Lionel Landwerlin | 5488dc1 | 2016-02-26 17:05:00 +0000 | [diff] [blame] | 1503 | prop = drm_property_create(dev, |
| 1504 | DRM_MODE_PROP_BLOB, |
| 1505 | "DEGAMMA_LUT", 0); |
| 1506 | if (!prop) |
| 1507 | return -ENOMEM; |
| 1508 | dev->mode_config.degamma_lut_property = prop; |
| 1509 | |
| 1510 | prop = drm_property_create_range(dev, |
| 1511 | DRM_MODE_PROP_IMMUTABLE, |
| 1512 | "DEGAMMA_LUT_SIZE", 0, UINT_MAX); |
| 1513 | if (!prop) |
| 1514 | return -ENOMEM; |
| 1515 | dev->mode_config.degamma_lut_size_property = prop; |
| 1516 | |
| 1517 | prop = drm_property_create(dev, |
| 1518 | DRM_MODE_PROP_BLOB, |
| 1519 | "CTM", 0); |
| 1520 | if (!prop) |
| 1521 | return -ENOMEM; |
| 1522 | dev->mode_config.ctm_property = prop; |
| 1523 | |
| 1524 | prop = drm_property_create(dev, |
| 1525 | DRM_MODE_PROP_BLOB, |
| 1526 | "GAMMA_LUT", 0); |
| 1527 | if (!prop) |
| 1528 | return -ENOMEM; |
| 1529 | dev->mode_config.gamma_lut_property = prop; |
| 1530 | |
| 1531 | prop = drm_property_create_range(dev, |
| 1532 | DRM_MODE_PROP_IMMUTABLE, |
| 1533 | "GAMMA_LUT_SIZE", 0, UINT_MAX); |
| 1534 | if (!prop) |
| 1535 | return -ENOMEM; |
| 1536 | dev->mode_config.gamma_lut_size_property = prop; |
| 1537 | |
Rob Clark | 9922ab5 | 2014-04-01 20:16:57 -0400 | [diff] [blame] | 1538 | return 0; |
| 1539 | } |
| 1540 | |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 1541 | /** |
| 1542 | * drm_mode_create_dvi_i_properties - create DVI-I specific connector properties |
| 1543 | * @dev: DRM device |
| 1544 | * |
| 1545 | * Called by a driver the first time a DVI-I connector is made. |
| 1546 | */ |
| 1547 | int drm_mode_create_dvi_i_properties(struct drm_device *dev) |
| 1548 | { |
| 1549 | struct drm_property *dvi_i_selector; |
| 1550 | struct drm_property *dvi_i_subconnector; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 1551 | |
| 1552 | if (dev->mode_config.dvi_i_select_subconnector_property) |
| 1553 | return 0; |
| 1554 | |
| 1555 | dvi_i_selector = |
Sascha Hauer | 4a67d39 | 2012-02-06 10:58:17 +0100 | [diff] [blame] | 1556 | drm_property_create_enum(dev, 0, |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 1557 | "select subconnector", |
Sascha Hauer | 4a67d39 | 2012-02-06 10:58:17 +0100 | [diff] [blame] | 1558 | drm_dvi_i_select_enum_list, |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 1559 | ARRAY_SIZE(drm_dvi_i_select_enum_list)); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 1560 | dev->mode_config.dvi_i_select_subconnector_property = dvi_i_selector; |
| 1561 | |
Sascha Hauer | 4a67d39 | 2012-02-06 10:58:17 +0100 | [diff] [blame] | 1562 | dvi_i_subconnector = drm_property_create_enum(dev, DRM_MODE_PROP_IMMUTABLE, |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 1563 | "subconnector", |
Sascha Hauer | 4a67d39 | 2012-02-06 10:58:17 +0100 | [diff] [blame] | 1564 | drm_dvi_i_subconnector_enum_list, |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 1565 | ARRAY_SIZE(drm_dvi_i_subconnector_enum_list)); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 1566 | dev->mode_config.dvi_i_subconnector_property = dvi_i_subconnector; |
| 1567 | |
| 1568 | return 0; |
| 1569 | } |
| 1570 | EXPORT_SYMBOL(drm_mode_create_dvi_i_properties); |
| 1571 | |
| 1572 | /** |
| 1573 | * drm_create_tv_properties - create TV specific connector properties |
| 1574 | * @dev: DRM device |
| 1575 | * @num_modes: number of different TV formats (modes) supported |
| 1576 | * @modes: array of pointers to strings containing name of each format |
| 1577 | * |
| 1578 | * Called by a driver's TV initialization routine, this function creates |
| 1579 | * the TV specific connector properties for a given device. Caller is |
| 1580 | * responsible for allocating a list of format names and passing them to |
| 1581 | * this routine. |
| 1582 | */ |
Thierry Reding | 2f76331 | 2014-10-13 12:45:57 +0200 | [diff] [blame] | 1583 | int drm_mode_create_tv_properties(struct drm_device *dev, |
| 1584 | unsigned int num_modes, |
Ville Syrjälä | b7c914b | 2015-08-31 15:09:26 +0300 | [diff] [blame] | 1585 | const char * const modes[]) |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 1586 | { |
| 1587 | struct drm_property *tv_selector; |
| 1588 | struct drm_property *tv_subconnector; |
Thierry Reding | 2f76331 | 2014-10-13 12:45:57 +0200 | [diff] [blame] | 1589 | unsigned int i; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 1590 | |
| 1591 | if (dev->mode_config.tv_select_subconnector_property) |
| 1592 | return 0; |
| 1593 | |
| 1594 | /* |
| 1595 | * Basic connector properties |
| 1596 | */ |
Sascha Hauer | 4a67d39 | 2012-02-06 10:58:17 +0100 | [diff] [blame] | 1597 | tv_selector = drm_property_create_enum(dev, 0, |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 1598 | "select subconnector", |
Sascha Hauer | 4a67d39 | 2012-02-06 10:58:17 +0100 | [diff] [blame] | 1599 | drm_tv_select_enum_list, |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 1600 | ARRAY_SIZE(drm_tv_select_enum_list)); |
Insu Yun | 48aa1e7 | 2015-10-19 16:33:30 +0000 | [diff] [blame] | 1601 | if (!tv_selector) |
| 1602 | goto nomem; |
| 1603 | |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 1604 | dev->mode_config.tv_select_subconnector_property = tv_selector; |
| 1605 | |
| 1606 | tv_subconnector = |
Sascha Hauer | 4a67d39 | 2012-02-06 10:58:17 +0100 | [diff] [blame] | 1607 | drm_property_create_enum(dev, DRM_MODE_PROP_IMMUTABLE, |
| 1608 | "subconnector", |
| 1609 | drm_tv_subconnector_enum_list, |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 1610 | ARRAY_SIZE(drm_tv_subconnector_enum_list)); |
Insu Yun | 48aa1e7 | 2015-10-19 16:33:30 +0000 | [diff] [blame] | 1611 | if (!tv_subconnector) |
| 1612 | goto nomem; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 1613 | dev->mode_config.tv_subconnector_property = tv_subconnector; |
| 1614 | |
| 1615 | /* |
| 1616 | * Other, TV specific properties: margins & TV modes. |
| 1617 | */ |
| 1618 | dev->mode_config.tv_left_margin_property = |
Sascha Hauer | d9bc3c0 | 2012-02-06 10:58:18 +0100 | [diff] [blame] | 1619 | drm_property_create_range(dev, 0, "left margin", 0, 100); |
Insu Yun | 48aa1e7 | 2015-10-19 16:33:30 +0000 | [diff] [blame] | 1620 | if (!dev->mode_config.tv_left_margin_property) |
| 1621 | goto nomem; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 1622 | |
| 1623 | dev->mode_config.tv_right_margin_property = |
Sascha Hauer | d9bc3c0 | 2012-02-06 10:58:18 +0100 | [diff] [blame] | 1624 | drm_property_create_range(dev, 0, "right margin", 0, 100); |
Insu Yun | 48aa1e7 | 2015-10-19 16:33:30 +0000 | [diff] [blame] | 1625 | if (!dev->mode_config.tv_right_margin_property) |
| 1626 | goto nomem; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 1627 | |
| 1628 | dev->mode_config.tv_top_margin_property = |
Sascha Hauer | d9bc3c0 | 2012-02-06 10:58:18 +0100 | [diff] [blame] | 1629 | drm_property_create_range(dev, 0, "top margin", 0, 100); |
Insu Yun | 48aa1e7 | 2015-10-19 16:33:30 +0000 | [diff] [blame] | 1630 | if (!dev->mode_config.tv_top_margin_property) |
| 1631 | goto nomem; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 1632 | |
| 1633 | dev->mode_config.tv_bottom_margin_property = |
Sascha Hauer | d9bc3c0 | 2012-02-06 10:58:18 +0100 | [diff] [blame] | 1634 | drm_property_create_range(dev, 0, "bottom margin", 0, 100); |
Insu Yun | 48aa1e7 | 2015-10-19 16:33:30 +0000 | [diff] [blame] | 1635 | if (!dev->mode_config.tv_bottom_margin_property) |
| 1636 | goto nomem; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 1637 | |
| 1638 | dev->mode_config.tv_mode_property = |
| 1639 | drm_property_create(dev, DRM_MODE_PROP_ENUM, |
| 1640 | "mode", num_modes); |
Insu Yun | 48aa1e7 | 2015-10-19 16:33:30 +0000 | [diff] [blame] | 1641 | if (!dev->mode_config.tv_mode_property) |
| 1642 | goto nomem; |
| 1643 | |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 1644 | for (i = 0; i < num_modes; i++) |
| 1645 | drm_property_add_enum(dev->mode_config.tv_mode_property, i, |
| 1646 | i, modes[i]); |
| 1647 | |
Francisco Jerez | b6b7902 | 2009-08-02 04:19:20 +0200 | [diff] [blame] | 1648 | dev->mode_config.tv_brightness_property = |
Sascha Hauer | d9bc3c0 | 2012-02-06 10:58:18 +0100 | [diff] [blame] | 1649 | drm_property_create_range(dev, 0, "brightness", 0, 100); |
Insu Yun | 48aa1e7 | 2015-10-19 16:33:30 +0000 | [diff] [blame] | 1650 | if (!dev->mode_config.tv_brightness_property) |
| 1651 | goto nomem; |
Francisco Jerez | b6b7902 | 2009-08-02 04:19:20 +0200 | [diff] [blame] | 1652 | |
| 1653 | dev->mode_config.tv_contrast_property = |
Sascha Hauer | d9bc3c0 | 2012-02-06 10:58:18 +0100 | [diff] [blame] | 1654 | drm_property_create_range(dev, 0, "contrast", 0, 100); |
Insu Yun | 48aa1e7 | 2015-10-19 16:33:30 +0000 | [diff] [blame] | 1655 | if (!dev->mode_config.tv_contrast_property) |
| 1656 | goto nomem; |
Francisco Jerez | b6b7902 | 2009-08-02 04:19:20 +0200 | [diff] [blame] | 1657 | |
| 1658 | dev->mode_config.tv_flicker_reduction_property = |
Sascha Hauer | d9bc3c0 | 2012-02-06 10:58:18 +0100 | [diff] [blame] | 1659 | drm_property_create_range(dev, 0, "flicker reduction", 0, 100); |
Insu Yun | 48aa1e7 | 2015-10-19 16:33:30 +0000 | [diff] [blame] | 1660 | if (!dev->mode_config.tv_flicker_reduction_property) |
| 1661 | goto nomem; |
Francisco Jerez | b6b7902 | 2009-08-02 04:19:20 +0200 | [diff] [blame] | 1662 | |
Francisco Jerez | a75f023 | 2009-08-12 02:30:10 +0200 | [diff] [blame] | 1663 | dev->mode_config.tv_overscan_property = |
Sascha Hauer | d9bc3c0 | 2012-02-06 10:58:18 +0100 | [diff] [blame] | 1664 | drm_property_create_range(dev, 0, "overscan", 0, 100); |
Insu Yun | 48aa1e7 | 2015-10-19 16:33:30 +0000 | [diff] [blame] | 1665 | if (!dev->mode_config.tv_overscan_property) |
| 1666 | goto nomem; |
Francisco Jerez | a75f023 | 2009-08-12 02:30:10 +0200 | [diff] [blame] | 1667 | |
| 1668 | dev->mode_config.tv_saturation_property = |
Sascha Hauer | d9bc3c0 | 2012-02-06 10:58:18 +0100 | [diff] [blame] | 1669 | drm_property_create_range(dev, 0, "saturation", 0, 100); |
Insu Yun | 48aa1e7 | 2015-10-19 16:33:30 +0000 | [diff] [blame] | 1670 | if (!dev->mode_config.tv_saturation_property) |
| 1671 | goto nomem; |
Francisco Jerez | a75f023 | 2009-08-12 02:30:10 +0200 | [diff] [blame] | 1672 | |
| 1673 | dev->mode_config.tv_hue_property = |
Sascha Hauer | d9bc3c0 | 2012-02-06 10:58:18 +0100 | [diff] [blame] | 1674 | drm_property_create_range(dev, 0, "hue", 0, 100); |
Insu Yun | 48aa1e7 | 2015-10-19 16:33:30 +0000 | [diff] [blame] | 1675 | if (!dev->mode_config.tv_hue_property) |
| 1676 | goto nomem; |
Francisco Jerez | a75f023 | 2009-08-12 02:30:10 +0200 | [diff] [blame] | 1677 | |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 1678 | return 0; |
Insu Yun | 48aa1e7 | 2015-10-19 16:33:30 +0000 | [diff] [blame] | 1679 | nomem: |
| 1680 | return -ENOMEM; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 1681 | } |
| 1682 | EXPORT_SYMBOL(drm_mode_create_tv_properties); |
| 1683 | |
| 1684 | /** |
| 1685 | * drm_mode_create_scaling_mode_property - create scaling mode property |
| 1686 | * @dev: DRM device |
| 1687 | * |
| 1688 | * Called by a driver the first time it's needed, must be attached to desired |
| 1689 | * connectors. |
| 1690 | */ |
| 1691 | int drm_mode_create_scaling_mode_property(struct drm_device *dev) |
| 1692 | { |
| 1693 | struct drm_property *scaling_mode; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 1694 | |
| 1695 | if (dev->mode_config.scaling_mode_property) |
| 1696 | return 0; |
| 1697 | |
| 1698 | scaling_mode = |
Sascha Hauer | 4a67d39 | 2012-02-06 10:58:17 +0100 | [diff] [blame] | 1699 | drm_property_create_enum(dev, 0, "scaling mode", |
| 1700 | drm_scaling_mode_enum_list, |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 1701 | ARRAY_SIZE(drm_scaling_mode_enum_list)); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 1702 | |
| 1703 | dev->mode_config.scaling_mode_property = scaling_mode; |
| 1704 | |
| 1705 | return 0; |
| 1706 | } |
| 1707 | EXPORT_SYMBOL(drm_mode_create_scaling_mode_property); |
| 1708 | |
| 1709 | /** |
Vandana Kannan | ff587e4 | 2014-06-11 10:46:48 +0530 | [diff] [blame] | 1710 | * drm_mode_create_aspect_ratio_property - create aspect ratio property |
| 1711 | * @dev: DRM device |
| 1712 | * |
| 1713 | * Called by a driver the first time it's needed, must be attached to desired |
| 1714 | * connectors. |
| 1715 | * |
| 1716 | * Returns: |
Daniel Vetter | 1a49863 | 2014-11-19 18:38:09 +0100 | [diff] [blame] | 1717 | * Zero on success, negative errno on failure. |
Vandana Kannan | ff587e4 | 2014-06-11 10:46:48 +0530 | [diff] [blame] | 1718 | */ |
| 1719 | int drm_mode_create_aspect_ratio_property(struct drm_device *dev) |
| 1720 | { |
| 1721 | if (dev->mode_config.aspect_ratio_property) |
| 1722 | return 0; |
| 1723 | |
| 1724 | dev->mode_config.aspect_ratio_property = |
| 1725 | drm_property_create_enum(dev, 0, "aspect ratio", |
| 1726 | drm_aspect_ratio_enum_list, |
| 1727 | ARRAY_SIZE(drm_aspect_ratio_enum_list)); |
| 1728 | |
| 1729 | if (dev->mode_config.aspect_ratio_property == NULL) |
| 1730 | return -ENOMEM; |
| 1731 | |
| 1732 | return 0; |
| 1733 | } |
| 1734 | EXPORT_SYMBOL(drm_mode_create_aspect_ratio_property); |
| 1735 | |
| 1736 | /** |
Jakob Bornecrantz | 884840a | 2009-12-03 23:25:47 +0000 | [diff] [blame] | 1737 | * drm_mode_create_dirty_property - create dirty property |
| 1738 | * @dev: DRM device |
| 1739 | * |
| 1740 | * Called by a driver the first time it's needed, must be attached to desired |
| 1741 | * connectors. |
| 1742 | */ |
| 1743 | int drm_mode_create_dirty_info_property(struct drm_device *dev) |
| 1744 | { |
| 1745 | struct drm_property *dirty_info; |
Jakob Bornecrantz | 884840a | 2009-12-03 23:25:47 +0000 | [diff] [blame] | 1746 | |
| 1747 | if (dev->mode_config.dirty_info_property) |
| 1748 | return 0; |
| 1749 | |
| 1750 | dirty_info = |
Sascha Hauer | 4a67d39 | 2012-02-06 10:58:17 +0100 | [diff] [blame] | 1751 | drm_property_create_enum(dev, DRM_MODE_PROP_IMMUTABLE, |
Jakob Bornecrantz | 884840a | 2009-12-03 23:25:47 +0000 | [diff] [blame] | 1752 | "dirty", |
Sascha Hauer | 4a67d39 | 2012-02-06 10:58:17 +0100 | [diff] [blame] | 1753 | drm_dirty_info_enum_list, |
Jakob Bornecrantz | 884840a | 2009-12-03 23:25:47 +0000 | [diff] [blame] | 1754 | ARRAY_SIZE(drm_dirty_info_enum_list)); |
Jakob Bornecrantz | 884840a | 2009-12-03 23:25:47 +0000 | [diff] [blame] | 1755 | dev->mode_config.dirty_info_property = dirty_info; |
| 1756 | |
| 1757 | return 0; |
| 1758 | } |
| 1759 | EXPORT_SYMBOL(drm_mode_create_dirty_info_property); |
| 1760 | |
Dave Airlie | 5bb2bbf | 2014-11-10 10:18:15 +1000 | [diff] [blame] | 1761 | /** |
| 1762 | * drm_mode_create_suggested_offset_properties - create suggests offset properties |
| 1763 | * @dev: DRM device |
| 1764 | * |
| 1765 | * Create the the suggested x/y offset property for connectors. |
| 1766 | */ |
| 1767 | int drm_mode_create_suggested_offset_properties(struct drm_device *dev) |
| 1768 | { |
| 1769 | if (dev->mode_config.suggested_x_property && dev->mode_config.suggested_y_property) |
| 1770 | return 0; |
| 1771 | |
| 1772 | dev->mode_config.suggested_x_property = |
| 1773 | drm_property_create_range(dev, DRM_MODE_PROP_IMMUTABLE, "suggested X", 0, 0xffffffff); |
| 1774 | |
| 1775 | dev->mode_config.suggested_y_property = |
| 1776 | drm_property_create_range(dev, DRM_MODE_PROP_IMMUTABLE, "suggested Y", 0, 0xffffffff); |
| 1777 | |
| 1778 | if (dev->mode_config.suggested_x_property == NULL || |
| 1779 | dev->mode_config.suggested_y_property == NULL) |
| 1780 | return -ENOMEM; |
| 1781 | return 0; |
| 1782 | } |
| 1783 | EXPORT_SYMBOL(drm_mode_create_suggested_offset_properties); |
| 1784 | |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 1785 | /** |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 1786 | * drm_mode_getresources - get graphics configuration |
Daniel Vetter | 065a50ed | 2012-12-02 00:09:18 +0100 | [diff] [blame] | 1787 | * @dev: drm device for the ioctl |
| 1788 | * @data: data pointer for the ioctl |
| 1789 | * @file_priv: drm file for the ioctl call |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 1790 | * |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 1791 | * Construct a set of configuration description structures and return |
| 1792 | * them to the user, including CRTC, connector and framebuffer configuration. |
| 1793 | * |
| 1794 | * Called by the user via ioctl. |
| 1795 | * |
Daniel Vetter | c8e32cc | 2014-03-10 21:33:02 +0100 | [diff] [blame] | 1796 | * Returns: |
Daniel Vetter | 1a49863 | 2014-11-19 18:38:09 +0100 | [diff] [blame] | 1797 | * Zero on success, negative errno on failure. |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 1798 | */ |
| 1799 | int drm_mode_getresources(struct drm_device *dev, void *data, |
| 1800 | struct drm_file *file_priv) |
| 1801 | { |
| 1802 | struct drm_mode_card_res *card_res = data; |
| 1803 | struct list_head *lh; |
| 1804 | struct drm_framebuffer *fb; |
| 1805 | struct drm_connector *connector; |
| 1806 | struct drm_crtc *crtc; |
| 1807 | struct drm_encoder *encoder; |
| 1808 | int ret = 0; |
| 1809 | int connector_count = 0; |
| 1810 | int crtc_count = 0; |
| 1811 | int fb_count = 0; |
| 1812 | int encoder_count = 0; |
Daniel Vetter | 9c7060f | 2015-07-09 23:44:36 +0200 | [diff] [blame] | 1813 | int copied = 0; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 1814 | uint32_t __user *fb_id; |
| 1815 | uint32_t __user *crtc_id; |
| 1816 | uint32_t __user *connector_id; |
| 1817 | uint32_t __user *encoder_id; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 1818 | |
Dave Airlie | fb3b06c | 2011-02-08 13:55:21 +1000 | [diff] [blame] | 1819 | if (!drm_core_check_feature(dev, DRIVER_MODESET)) |
| 1820 | return -EINVAL; |
| 1821 | |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 1822 | |
Daniel Vetter | 4b096ac | 2012-12-10 21:19:18 +0100 | [diff] [blame] | 1823 | mutex_lock(&file_priv->fbs_lock); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 1824 | /* |
| 1825 | * For the non-control nodes we need to limit the list of resources |
| 1826 | * by IDs in the group list for this node |
| 1827 | */ |
| 1828 | list_for_each(lh, &file_priv->fbs) |
| 1829 | fb_count++; |
| 1830 | |
Daniel Vetter | 4b096ac | 2012-12-10 21:19:18 +0100 | [diff] [blame] | 1831 | /* handle this in 4 parts */ |
| 1832 | /* FBs */ |
| 1833 | if (card_res->count_fbs >= fb_count) { |
| 1834 | copied = 0; |
| 1835 | fb_id = (uint32_t __user *)(unsigned long)card_res->fb_id_ptr; |
| 1836 | list_for_each_entry(fb, &file_priv->fbs, filp_head) { |
| 1837 | if (put_user(fb->base.id, fb_id + copied)) { |
| 1838 | mutex_unlock(&file_priv->fbs_lock); |
| 1839 | return -EFAULT; |
| 1840 | } |
| 1841 | copied++; |
| 1842 | } |
| 1843 | } |
| 1844 | card_res->count_fbs = fb_count; |
| 1845 | mutex_unlock(&file_priv->fbs_lock); |
| 1846 | |
Daniel Vetter | fcf93f6 | 2014-11-12 08:45:01 +0100 | [diff] [blame] | 1847 | /* mode_config.mutex protects the connector list against e.g. DP MST |
| 1848 | * connector hot-adding. CRTC/Plane lists are invariant. */ |
| 1849 | mutex_lock(&dev->mode_config.mutex); |
Daniel Vetter | 9c7060f | 2015-07-09 23:44:36 +0200 | [diff] [blame] | 1850 | drm_for_each_crtc(crtc, dev) |
| 1851 | crtc_count++; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 1852 | |
Daniel Vetter | 9c7060f | 2015-07-09 23:44:36 +0200 | [diff] [blame] | 1853 | drm_for_each_connector(connector, dev) |
| 1854 | connector_count++; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 1855 | |
Daniel Vetter | 9c7060f | 2015-07-09 23:44:36 +0200 | [diff] [blame] | 1856 | drm_for_each_encoder(encoder, dev) |
| 1857 | encoder_count++; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 1858 | |
| 1859 | card_res->max_height = dev->mode_config.max_height; |
| 1860 | card_res->min_height = dev->mode_config.min_height; |
| 1861 | card_res->max_width = dev->mode_config.max_width; |
| 1862 | card_res->min_width = dev->mode_config.min_width; |
| 1863 | |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 1864 | /* CRTCs */ |
| 1865 | if (card_res->count_crtcs >= crtc_count) { |
| 1866 | copied = 0; |
| 1867 | crtc_id = (uint32_t __user *)(unsigned long)card_res->crtc_id_ptr; |
Daniel Vetter | 9c7060f | 2015-07-09 23:44:36 +0200 | [diff] [blame] | 1868 | drm_for_each_crtc(crtc, dev) { |
Daniel Vetter | 9c7060f | 2015-07-09 23:44:36 +0200 | [diff] [blame] | 1869 | if (put_user(crtc->base.id, crtc_id + copied)) { |
| 1870 | ret = -EFAULT; |
| 1871 | goto out; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 1872 | } |
Daniel Vetter | 9c7060f | 2015-07-09 23:44:36 +0200 | [diff] [blame] | 1873 | copied++; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 1874 | } |
| 1875 | } |
| 1876 | card_res->count_crtcs = crtc_count; |
| 1877 | |
| 1878 | /* Encoders */ |
| 1879 | if (card_res->count_encoders >= encoder_count) { |
| 1880 | copied = 0; |
| 1881 | encoder_id = (uint32_t __user *)(unsigned long)card_res->encoder_id_ptr; |
Daniel Vetter | 9c7060f | 2015-07-09 23:44:36 +0200 | [diff] [blame] | 1882 | drm_for_each_encoder(encoder, dev) { |
Daniel Vetter | 9c7060f | 2015-07-09 23:44:36 +0200 | [diff] [blame] | 1883 | if (put_user(encoder->base.id, encoder_id + |
| 1884 | copied)) { |
| 1885 | ret = -EFAULT; |
| 1886 | goto out; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 1887 | } |
Daniel Vetter | 9c7060f | 2015-07-09 23:44:36 +0200 | [diff] [blame] | 1888 | copied++; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 1889 | } |
| 1890 | } |
| 1891 | card_res->count_encoders = encoder_count; |
| 1892 | |
| 1893 | /* Connectors */ |
| 1894 | if (card_res->count_connectors >= connector_count) { |
| 1895 | copied = 0; |
| 1896 | connector_id = (uint32_t __user *)(unsigned long)card_res->connector_id_ptr; |
Daniel Vetter | 9c7060f | 2015-07-09 23:44:36 +0200 | [diff] [blame] | 1897 | drm_for_each_connector(connector, dev) { |
Daniel Vetter | 9c7060f | 2015-07-09 23:44:36 +0200 | [diff] [blame] | 1898 | if (put_user(connector->base.id, |
| 1899 | connector_id + copied)) { |
| 1900 | ret = -EFAULT; |
| 1901 | goto out; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 1902 | } |
Daniel Vetter | 9c7060f | 2015-07-09 23:44:36 +0200 | [diff] [blame] | 1903 | copied++; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 1904 | } |
| 1905 | } |
| 1906 | card_res->count_connectors = connector_count; |
| 1907 | |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 1908 | out: |
Daniel Vetter | fcf93f6 | 2014-11-12 08:45:01 +0100 | [diff] [blame] | 1909 | mutex_unlock(&dev->mode_config.mutex); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 1910 | return ret; |
| 1911 | } |
| 1912 | |
| 1913 | /** |
| 1914 | * drm_mode_getcrtc - get CRTC configuration |
Daniel Vetter | 065a50ed | 2012-12-02 00:09:18 +0100 | [diff] [blame] | 1915 | * @dev: drm device for the ioctl |
| 1916 | * @data: data pointer for the ioctl |
| 1917 | * @file_priv: drm file for the ioctl call |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 1918 | * |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 1919 | * Construct a CRTC configuration structure to return to the user. |
| 1920 | * |
| 1921 | * Called by the user via ioctl. |
| 1922 | * |
Daniel Vetter | c8e32cc | 2014-03-10 21:33:02 +0100 | [diff] [blame] | 1923 | * Returns: |
Daniel Vetter | 1a49863 | 2014-11-19 18:38:09 +0100 | [diff] [blame] | 1924 | * Zero on success, negative errno on failure. |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 1925 | */ |
| 1926 | int drm_mode_getcrtc(struct drm_device *dev, |
| 1927 | void *data, struct drm_file *file_priv) |
| 1928 | { |
| 1929 | struct drm_mode_crtc *crtc_resp = data; |
| 1930 | struct drm_crtc *crtc; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 1931 | |
Dave Airlie | fb3b06c | 2011-02-08 13:55:21 +1000 | [diff] [blame] | 1932 | if (!drm_core_check_feature(dev, DRIVER_MODESET)) |
| 1933 | return -EINVAL; |
| 1934 | |
Rob Clark | a2b34e2 | 2013-10-05 16:36:52 -0400 | [diff] [blame] | 1935 | crtc = drm_crtc_find(dev, crtc_resp->crtc_id); |
Daniel Vetter | fcf93f6 | 2014-11-12 08:45:01 +0100 | [diff] [blame] | 1936 | if (!crtc) |
| 1937 | return -ENOENT; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 1938 | |
Daniel Vetter | fcf93f6 | 2014-11-12 08:45:01 +0100 | [diff] [blame] | 1939 | drm_modeset_lock_crtc(crtc, crtc->primary); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 1940 | crtc_resp->gamma_size = crtc->gamma_size; |
Matt Roper | f4510a2 | 2014-04-01 15:22:40 -0700 | [diff] [blame] | 1941 | if (crtc->primary->fb) |
| 1942 | crtc_resp->fb_id = crtc->primary->fb->base.id; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 1943 | else |
| 1944 | crtc_resp->fb_id = 0; |
| 1945 | |
Daniel Vetter | 31c946e | 2015-02-22 12:24:17 +0100 | [diff] [blame] | 1946 | if (crtc->state) { |
| 1947 | crtc_resp->x = crtc->primary->state->src_x >> 16; |
| 1948 | crtc_resp->y = crtc->primary->state->src_y >> 16; |
| 1949 | if (crtc->state->enable) { |
Daniel Stone | 934a8a8 | 2015-05-22 13:34:48 +0100 | [diff] [blame] | 1950 | drm_mode_convert_to_umode(&crtc_resp->mode, &crtc->state->mode); |
Daniel Vetter | 31c946e | 2015-02-22 12:24:17 +0100 | [diff] [blame] | 1951 | crtc_resp->mode_valid = 1; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 1952 | |
Daniel Vetter | 31c946e | 2015-02-22 12:24:17 +0100 | [diff] [blame] | 1953 | } else { |
| 1954 | crtc_resp->mode_valid = 0; |
| 1955 | } |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 1956 | } else { |
Daniel Vetter | 31c946e | 2015-02-22 12:24:17 +0100 | [diff] [blame] | 1957 | crtc_resp->x = crtc->x; |
| 1958 | crtc_resp->y = crtc->y; |
| 1959 | if (crtc->enabled) { |
Daniel Stone | 934a8a8 | 2015-05-22 13:34:48 +0100 | [diff] [blame] | 1960 | drm_mode_convert_to_umode(&crtc_resp->mode, &crtc->mode); |
Daniel Vetter | 31c946e | 2015-02-22 12:24:17 +0100 | [diff] [blame] | 1961 | crtc_resp->mode_valid = 1; |
| 1962 | |
| 1963 | } else { |
| 1964 | crtc_resp->mode_valid = 0; |
| 1965 | } |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 1966 | } |
Daniel Vetter | fcf93f6 | 2014-11-12 08:45:01 +0100 | [diff] [blame] | 1967 | drm_modeset_unlock_crtc(crtc); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 1968 | |
Daniel Vetter | baf698b | 2014-11-12 11:59:47 +0100 | [diff] [blame] | 1969 | return 0; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 1970 | } |
| 1971 | |
Damien Lespiau | 61d8e32 | 2013-09-25 16:45:22 +0100 | [diff] [blame] | 1972 | static bool drm_mode_expose_to_userspace(const struct drm_display_mode *mode, |
| 1973 | const struct drm_file *file_priv) |
| 1974 | { |
| 1975 | /* |
| 1976 | * If user-space hasn't configured the driver to expose the stereo 3D |
| 1977 | * modes, don't expose them. |
| 1978 | */ |
| 1979 | if (!file_priv->stereo_allowed && drm_mode_is_stereo(mode)) |
| 1980 | return false; |
| 1981 | |
| 1982 | return true; |
| 1983 | } |
| 1984 | |
Daniel Vetter | abd69c5 | 2014-11-25 23:50:05 +0100 | [diff] [blame] | 1985 | static struct drm_encoder *drm_connector_get_encoder(struct drm_connector *connector) |
| 1986 | { |
| 1987 | /* For atomic drivers only state objects are synchronously updated and |
| 1988 | * protected by modeset locks, so check those first. */ |
| 1989 | if (connector->state) |
| 1990 | return connector->state->best_encoder; |
| 1991 | return connector->encoder; |
| 1992 | } |
| 1993 | |
Rob Clark | 95cbf11 | 2014-12-18 16:01:49 -0500 | [diff] [blame] | 1994 | /* helper for getconnector and getproperties ioctls */ |
Rob Clark | 88a48e2 | 2014-12-18 16:01:50 -0500 | [diff] [blame] | 1995 | static int get_properties(struct drm_mode_object *obj, bool atomic, |
Rob Clark | 95cbf11 | 2014-12-18 16:01:49 -0500 | [diff] [blame] | 1996 | uint32_t __user *prop_ptr, uint64_t __user *prop_values, |
| 1997 | uint32_t *arg_count_props) |
| 1998 | { |
Rob Clark | 88a48e2 | 2014-12-18 16:01:50 -0500 | [diff] [blame] | 1999 | int props_count; |
| 2000 | int i, ret, copied; |
| 2001 | |
| 2002 | props_count = obj->properties->count; |
| 2003 | if (!atomic) |
| 2004 | props_count -= obj->properties->atomic_count; |
Rob Clark | 95cbf11 | 2014-12-18 16:01:49 -0500 | [diff] [blame] | 2005 | |
| 2006 | if ((*arg_count_props >= props_count) && props_count) { |
Rob Clark | 88a48e2 | 2014-12-18 16:01:50 -0500 | [diff] [blame] | 2007 | for (i = 0, copied = 0; copied < props_count; i++) { |
Rob Clark | 95cbf11 | 2014-12-18 16:01:49 -0500 | [diff] [blame] | 2008 | struct drm_property *prop = obj->properties->properties[i]; |
| 2009 | uint64_t val; |
| 2010 | |
Rob Clark | 88a48e2 | 2014-12-18 16:01:50 -0500 | [diff] [blame] | 2011 | if ((prop->flags & DRM_MODE_PROP_ATOMIC) && !atomic) |
| 2012 | continue; |
| 2013 | |
Rob Clark | 95cbf11 | 2014-12-18 16:01:49 -0500 | [diff] [blame] | 2014 | ret = drm_object_property_get_value(obj, prop, &val); |
| 2015 | if (ret) |
| 2016 | return ret; |
| 2017 | |
| 2018 | if (put_user(prop->base.id, prop_ptr + copied)) |
| 2019 | return -EFAULT; |
| 2020 | |
| 2021 | if (put_user(val, prop_values + copied)) |
| 2022 | return -EFAULT; |
| 2023 | |
| 2024 | copied++; |
| 2025 | } |
| 2026 | } |
| 2027 | *arg_count_props = props_count; |
| 2028 | |
| 2029 | return 0; |
| 2030 | } |
| 2031 | |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 2032 | /** |
| 2033 | * drm_mode_getconnector - get connector configuration |
Daniel Vetter | 065a50ed | 2012-12-02 00:09:18 +0100 | [diff] [blame] | 2034 | * @dev: drm device for the ioctl |
| 2035 | * @data: data pointer for the ioctl |
| 2036 | * @file_priv: drm file for the ioctl call |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 2037 | * |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 2038 | * Construct a connector configuration structure to return to the user. |
| 2039 | * |
| 2040 | * Called by the user via ioctl. |
| 2041 | * |
Daniel Vetter | c8e32cc | 2014-03-10 21:33:02 +0100 | [diff] [blame] | 2042 | * Returns: |
Daniel Vetter | 1a49863 | 2014-11-19 18:38:09 +0100 | [diff] [blame] | 2043 | * Zero on success, negative errno on failure. |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 2044 | */ |
| 2045 | int drm_mode_getconnector(struct drm_device *dev, void *data, |
| 2046 | struct drm_file *file_priv) |
| 2047 | { |
| 2048 | struct drm_mode_get_connector *out_resp = data; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 2049 | struct drm_connector *connector; |
Daniel Vetter | abd69c5 | 2014-11-25 23:50:05 +0100 | [diff] [blame] | 2050 | struct drm_encoder *encoder; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 2051 | struct drm_display_mode *mode; |
| 2052 | int mode_count = 0; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 2053 | int encoders_count = 0; |
| 2054 | int ret = 0; |
| 2055 | int copied = 0; |
| 2056 | int i; |
| 2057 | struct drm_mode_modeinfo u_mode; |
| 2058 | struct drm_mode_modeinfo __user *mode_ptr; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 2059 | uint32_t __user *encoder_ptr; |
| 2060 | |
Dave Airlie | fb3b06c | 2011-02-08 13:55:21 +1000 | [diff] [blame] | 2061 | if (!drm_core_check_feature(dev, DRIVER_MODESET)) |
| 2062 | return -EINVAL; |
| 2063 | |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 2064 | memset(&u_mode, 0, sizeof(struct drm_mode_modeinfo)); |
| 2065 | |
Daniel Vetter | 7b24056 | 2012-12-12 00:35:33 +0100 | [diff] [blame] | 2066 | mutex_lock(&dev->mode_config.mutex); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 2067 | |
Dave Airlie | b164d31 | 2016-04-27 11:10:09 +1000 | [diff] [blame] | 2068 | connector = drm_connector_lookup(dev, out_resp->connector_id); |
Rob Clark | a2b34e2 | 2013-10-05 16:36:52 -0400 | [diff] [blame] | 2069 | if (!connector) { |
Ville Syrjälä | f27657f | 2013-10-17 13:35:00 +0300 | [diff] [blame] | 2070 | ret = -ENOENT; |
Tommi Rantala | 04bdf44 | 2015-04-03 10:45:29 +0300 | [diff] [blame] | 2071 | goto out_unlock; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 2072 | } |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 2073 | |
Thierry Reding | 01073b0 | 2014-12-10 13:03:38 +0100 | [diff] [blame] | 2074 | for (i = 0; i < DRM_CONNECTOR_MAX_ENCODER; i++) |
| 2075 | if (connector->encoder_ids[i] != 0) |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 2076 | encoders_count++; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 2077 | |
| 2078 | if (out_resp->count_modes == 0) { |
| 2079 | connector->funcs->fill_modes(connector, |
| 2080 | dev->mode_config.max_width, |
| 2081 | dev->mode_config.max_height); |
| 2082 | } |
| 2083 | |
| 2084 | /* delayed so we get modes regardless of pre-fill_modes state */ |
| 2085 | list_for_each_entry(mode, &connector->modes, head) |
Damien Lespiau | 61d8e32 | 2013-09-25 16:45:22 +0100 | [diff] [blame] | 2086 | if (drm_mode_expose_to_userspace(mode, file_priv)) |
| 2087 | mode_count++; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 2088 | |
| 2089 | out_resp->connector_id = connector->base.id; |
| 2090 | out_resp->connector_type = connector->connector_type; |
| 2091 | out_resp->connector_type_id = connector->connector_type_id; |
| 2092 | out_resp->mm_width = connector->display_info.width_mm; |
| 2093 | out_resp->mm_height = connector->display_info.height_mm; |
| 2094 | out_resp->subpixel = connector->display_info.subpixel_order; |
| 2095 | out_resp->connection = connector->status; |
Daniel Vetter | 2caa80e | 2015-02-22 11:38:36 +0100 | [diff] [blame] | 2096 | |
| 2097 | drm_modeset_lock(&dev->mode_config.connection_mutex, NULL); |
Daniel Vetter | abd69c5 | 2014-11-25 23:50:05 +0100 | [diff] [blame] | 2098 | encoder = drm_connector_get_encoder(connector); |
| 2099 | if (encoder) |
| 2100 | out_resp->encoder_id = encoder->base.id; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 2101 | else |
| 2102 | out_resp->encoder_id = 0; |
| 2103 | |
| 2104 | /* |
| 2105 | * This ioctl is called twice, once to determine how much space is |
| 2106 | * needed, and the 2nd time to fill it. |
| 2107 | */ |
| 2108 | if ((out_resp->count_modes >= mode_count) && mode_count) { |
| 2109 | copied = 0; |
Ville Syrjälä | 81f6c7f | 2011-12-20 00:06:42 +0200 | [diff] [blame] | 2110 | 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] | 2111 | list_for_each_entry(mode, &connector->modes, head) { |
Damien Lespiau | 61d8e32 | 2013-09-25 16:45:22 +0100 | [diff] [blame] | 2112 | if (!drm_mode_expose_to_userspace(mode, file_priv)) |
| 2113 | continue; |
| 2114 | |
Daniel Stone | 934a8a8 | 2015-05-22 13:34:48 +0100 | [diff] [blame] | 2115 | drm_mode_convert_to_umode(&u_mode, mode); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 2116 | if (copy_to_user(mode_ptr + copied, |
| 2117 | &u_mode, sizeof(u_mode))) { |
| 2118 | ret = -EFAULT; |
| 2119 | goto out; |
| 2120 | } |
| 2121 | copied++; |
| 2122 | } |
| 2123 | } |
| 2124 | out_resp->count_modes = mode_count; |
| 2125 | |
Rob Clark | 88a48e2 | 2014-12-18 16:01:50 -0500 | [diff] [blame] | 2126 | ret = get_properties(&connector->base, file_priv->atomic, |
Rob Clark | 95cbf11 | 2014-12-18 16:01:49 -0500 | [diff] [blame] | 2127 | (uint32_t __user *)(unsigned long)(out_resp->props_ptr), |
| 2128 | (uint64_t __user *)(unsigned long)(out_resp->prop_values_ptr), |
| 2129 | &out_resp->count_props); |
| 2130 | if (ret) |
| 2131 | goto out; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 2132 | |
| 2133 | if ((out_resp->count_encoders >= encoders_count) && encoders_count) { |
| 2134 | copied = 0; |
Ville Syrjälä | 81f6c7f | 2011-12-20 00:06:42 +0200 | [diff] [blame] | 2135 | encoder_ptr = (uint32_t __user *)(unsigned long)(out_resp->encoders_ptr); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 2136 | for (i = 0; i < DRM_CONNECTOR_MAX_ENCODER; i++) { |
| 2137 | if (connector->encoder_ids[i] != 0) { |
| 2138 | if (put_user(connector->encoder_ids[i], |
| 2139 | encoder_ptr + copied)) { |
| 2140 | ret = -EFAULT; |
| 2141 | goto out; |
| 2142 | } |
| 2143 | copied++; |
| 2144 | } |
| 2145 | } |
| 2146 | } |
| 2147 | out_resp->count_encoders = encoders_count; |
| 2148 | |
| 2149 | out: |
Rob Clark | ccfc086 | 2014-12-18 16:01:48 -0500 | [diff] [blame] | 2150 | drm_modeset_unlock(&dev->mode_config.connection_mutex); |
Tommi Rantala | 04bdf44 | 2015-04-03 10:45:29 +0300 | [diff] [blame] | 2151 | |
Dave Airlie | b164d31 | 2016-04-27 11:10:09 +1000 | [diff] [blame] | 2152 | drm_connector_unreference(connector); |
Tommi Rantala | 04bdf44 | 2015-04-03 10:45:29 +0300 | [diff] [blame] | 2153 | out_unlock: |
Daniel Vetter | 7b24056 | 2012-12-12 00:35:33 +0100 | [diff] [blame] | 2154 | mutex_unlock(&dev->mode_config.mutex); |
| 2155 | |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 2156 | return ret; |
| 2157 | } |
| 2158 | |
Daniel Vetter | abd69c5 | 2014-11-25 23:50:05 +0100 | [diff] [blame] | 2159 | static struct drm_crtc *drm_encoder_get_crtc(struct drm_encoder *encoder) |
| 2160 | { |
| 2161 | struct drm_connector *connector; |
| 2162 | struct drm_device *dev = encoder->dev; |
| 2163 | bool uses_atomic = false; |
| 2164 | |
| 2165 | /* For atomic drivers only state objects are synchronously updated and |
| 2166 | * protected by modeset locks, so check those first. */ |
Daniel Vetter | 6295d60 | 2015-07-09 23:44:25 +0200 | [diff] [blame] | 2167 | drm_for_each_connector(connector, dev) { |
Daniel Vetter | abd69c5 | 2014-11-25 23:50:05 +0100 | [diff] [blame] | 2168 | if (!connector->state) |
| 2169 | continue; |
| 2170 | |
| 2171 | uses_atomic = true; |
| 2172 | |
| 2173 | if (connector->state->best_encoder != encoder) |
| 2174 | continue; |
| 2175 | |
| 2176 | return connector->state->crtc; |
| 2177 | } |
| 2178 | |
| 2179 | /* Don't return stale data (e.g. pending async disable). */ |
| 2180 | if (uses_atomic) |
| 2181 | return NULL; |
| 2182 | |
| 2183 | return encoder->crtc; |
| 2184 | } |
| 2185 | |
Daniel Vetter | c8e32cc | 2014-03-10 21:33:02 +0100 | [diff] [blame] | 2186 | /** |
| 2187 | * drm_mode_getencoder - get encoder configuration |
| 2188 | * @dev: drm device for the ioctl |
| 2189 | * @data: data pointer for the ioctl |
| 2190 | * @file_priv: drm file for the ioctl call |
| 2191 | * |
| 2192 | * Construct a encoder configuration structure to return to the user. |
| 2193 | * |
| 2194 | * Called by the user via ioctl. |
| 2195 | * |
| 2196 | * Returns: |
Daniel Vetter | 1a49863 | 2014-11-19 18:38:09 +0100 | [diff] [blame] | 2197 | * Zero on success, negative errno on failure. |
Daniel Vetter | c8e32cc | 2014-03-10 21:33:02 +0100 | [diff] [blame] | 2198 | */ |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 2199 | int drm_mode_getencoder(struct drm_device *dev, void *data, |
| 2200 | struct drm_file *file_priv) |
| 2201 | { |
| 2202 | struct drm_mode_get_encoder *enc_resp = data; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 2203 | struct drm_encoder *encoder; |
Daniel Vetter | abd69c5 | 2014-11-25 23:50:05 +0100 | [diff] [blame] | 2204 | struct drm_crtc *crtc; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 2205 | |
Dave Airlie | fb3b06c | 2011-02-08 13:55:21 +1000 | [diff] [blame] | 2206 | if (!drm_core_check_feature(dev, DRIVER_MODESET)) |
| 2207 | return -EINVAL; |
| 2208 | |
Rob Clark | a2b34e2 | 2013-10-05 16:36:52 -0400 | [diff] [blame] | 2209 | encoder = drm_encoder_find(dev, enc_resp->encoder_id); |
Daniel Vetter | fcf93f6 | 2014-11-12 08:45:01 +0100 | [diff] [blame] | 2210 | if (!encoder) |
| 2211 | return -ENOENT; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 2212 | |
Daniel Vetter | fcf93f6 | 2014-11-12 08:45:01 +0100 | [diff] [blame] | 2213 | drm_modeset_lock(&dev->mode_config.connection_mutex, NULL); |
Daniel Vetter | abd69c5 | 2014-11-25 23:50:05 +0100 | [diff] [blame] | 2214 | crtc = drm_encoder_get_crtc(encoder); |
| 2215 | if (crtc) |
| 2216 | enc_resp->crtc_id = crtc->base.id; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 2217 | else |
| 2218 | enc_resp->crtc_id = 0; |
Daniel Vetter | fcf93f6 | 2014-11-12 08:45:01 +0100 | [diff] [blame] | 2219 | drm_modeset_unlock(&dev->mode_config.connection_mutex); |
| 2220 | |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 2221 | enc_resp->encoder_type = encoder->encoder_type; |
| 2222 | enc_resp->encoder_id = encoder->base.id; |
| 2223 | enc_resp->possible_crtcs = encoder->possible_crtcs; |
| 2224 | enc_resp->possible_clones = encoder->possible_clones; |
| 2225 | |
Daniel Vetter | baf698b | 2014-11-12 11:59:47 +0100 | [diff] [blame] | 2226 | return 0; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 2227 | } |
| 2228 | |
| 2229 | /** |
Daniel Vetter | c8e32cc | 2014-03-10 21:33:02 +0100 | [diff] [blame] | 2230 | * drm_mode_getplane_res - enumerate all plane resources |
Jesse Barnes | 8cf5c91 | 2011-11-14 14:51:27 -0800 | [diff] [blame] | 2231 | * @dev: DRM device |
| 2232 | * @data: ioctl data |
| 2233 | * @file_priv: DRM file info |
| 2234 | * |
Daniel Vetter | c8e32cc | 2014-03-10 21:33:02 +0100 | [diff] [blame] | 2235 | * Construct a list of plane ids to return to the user. |
| 2236 | * |
| 2237 | * Called by the user via ioctl. |
| 2238 | * |
| 2239 | * Returns: |
Daniel Vetter | 1a49863 | 2014-11-19 18:38:09 +0100 | [diff] [blame] | 2240 | * Zero on success, negative errno on failure. |
Jesse Barnes | 8cf5c91 | 2011-11-14 14:51:27 -0800 | [diff] [blame] | 2241 | */ |
| 2242 | int drm_mode_getplane_res(struct drm_device *dev, void *data, |
Daniel Vetter | c8e32cc | 2014-03-10 21:33:02 +0100 | [diff] [blame] | 2243 | struct drm_file *file_priv) |
Jesse Barnes | 8cf5c91 | 2011-11-14 14:51:27 -0800 | [diff] [blame] | 2244 | { |
| 2245 | struct drm_mode_get_plane_res *plane_resp = data; |
| 2246 | struct drm_mode_config *config; |
| 2247 | struct drm_plane *plane; |
| 2248 | uint32_t __user *plane_ptr; |
Daniel Vetter | fcf93f6 | 2014-11-12 08:45:01 +0100 | [diff] [blame] | 2249 | int copied = 0; |
Matt Roper | 681e7ec | 2014-04-01 15:22:42 -0700 | [diff] [blame] | 2250 | unsigned num_planes; |
Jesse Barnes | 8cf5c91 | 2011-11-14 14:51:27 -0800 | [diff] [blame] | 2251 | |
| 2252 | if (!drm_core_check_feature(dev, DRIVER_MODESET)) |
| 2253 | return -EINVAL; |
| 2254 | |
Jesse Barnes | 8cf5c91 | 2011-11-14 14:51:27 -0800 | [diff] [blame] | 2255 | config = &dev->mode_config; |
| 2256 | |
Matt Roper | 681e7ec | 2014-04-01 15:22:42 -0700 | [diff] [blame] | 2257 | if (file_priv->universal_planes) |
| 2258 | num_planes = config->num_total_plane; |
| 2259 | else |
| 2260 | num_planes = config->num_overlay_plane; |
| 2261 | |
Jesse Barnes | 8cf5c91 | 2011-11-14 14:51:27 -0800 | [diff] [blame] | 2262 | /* |
| 2263 | * This ioctl is called twice, once to determine how much space is |
| 2264 | * needed, and the 2nd time to fill it. |
| 2265 | */ |
Matt Roper | 681e7ec | 2014-04-01 15:22:42 -0700 | [diff] [blame] | 2266 | if (num_planes && |
| 2267 | (plane_resp->count_planes >= num_planes)) { |
Ville Syrjälä | 81f6c7f | 2011-12-20 00:06:42 +0200 | [diff] [blame] | 2268 | plane_ptr = (uint32_t __user *)(unsigned long)plane_resp->plane_id_ptr; |
Jesse Barnes | 8cf5c91 | 2011-11-14 14:51:27 -0800 | [diff] [blame] | 2269 | |
Daniel Vetter | fcf93f6 | 2014-11-12 08:45:01 +0100 | [diff] [blame] | 2270 | /* Plane lists are invariant, no locking needed. */ |
Daniel Vetter | e4f6254 | 2015-07-09 23:44:35 +0200 | [diff] [blame] | 2271 | drm_for_each_plane(plane, dev) { |
Matt Roper | 681e7ec | 2014-04-01 15:22:42 -0700 | [diff] [blame] | 2272 | /* |
| 2273 | * Unless userspace set the 'universal planes' |
| 2274 | * capability bit, only advertise overlays. |
| 2275 | */ |
| 2276 | if (plane->type != DRM_PLANE_TYPE_OVERLAY && |
| 2277 | !file_priv->universal_planes) |
Matt Roper | e27dde3 | 2014-04-01 15:22:30 -0700 | [diff] [blame] | 2278 | continue; |
| 2279 | |
Daniel Vetter | fcf93f6 | 2014-11-12 08:45:01 +0100 | [diff] [blame] | 2280 | if (put_user(plane->base.id, plane_ptr + copied)) |
| 2281 | return -EFAULT; |
Jesse Barnes | 8cf5c91 | 2011-11-14 14:51:27 -0800 | [diff] [blame] | 2282 | copied++; |
| 2283 | } |
| 2284 | } |
Matt Roper | 681e7ec | 2014-04-01 15:22:42 -0700 | [diff] [blame] | 2285 | plane_resp->count_planes = num_planes; |
Jesse Barnes | 8cf5c91 | 2011-11-14 14:51:27 -0800 | [diff] [blame] | 2286 | |
Daniel Vetter | fcf93f6 | 2014-11-12 08:45:01 +0100 | [diff] [blame] | 2287 | return 0; |
Jesse Barnes | 8cf5c91 | 2011-11-14 14:51:27 -0800 | [diff] [blame] | 2288 | } |
| 2289 | |
| 2290 | /** |
Daniel Vetter | c8e32cc | 2014-03-10 21:33:02 +0100 | [diff] [blame] | 2291 | * drm_mode_getplane - get plane configuration |
Jesse Barnes | 8cf5c91 | 2011-11-14 14:51:27 -0800 | [diff] [blame] | 2292 | * @dev: DRM device |
| 2293 | * @data: ioctl data |
| 2294 | * @file_priv: DRM file info |
| 2295 | * |
Daniel Vetter | c8e32cc | 2014-03-10 21:33:02 +0100 | [diff] [blame] | 2296 | * Construct a plane configuration structure to return to the user. |
| 2297 | * |
| 2298 | * Called by the user via ioctl. |
| 2299 | * |
| 2300 | * Returns: |
Daniel Vetter | 1a49863 | 2014-11-19 18:38:09 +0100 | [diff] [blame] | 2301 | * Zero on success, negative errno on failure. |
Jesse Barnes | 8cf5c91 | 2011-11-14 14:51:27 -0800 | [diff] [blame] | 2302 | */ |
| 2303 | int drm_mode_getplane(struct drm_device *dev, void *data, |
Daniel Vetter | c8e32cc | 2014-03-10 21:33:02 +0100 | [diff] [blame] | 2304 | struct drm_file *file_priv) |
Jesse Barnes | 8cf5c91 | 2011-11-14 14:51:27 -0800 | [diff] [blame] | 2305 | { |
| 2306 | struct drm_mode_get_plane *plane_resp = data; |
Jesse Barnes | 8cf5c91 | 2011-11-14 14:51:27 -0800 | [diff] [blame] | 2307 | struct drm_plane *plane; |
| 2308 | uint32_t __user *format_ptr; |
Jesse Barnes | 8cf5c91 | 2011-11-14 14:51:27 -0800 | [diff] [blame] | 2309 | |
| 2310 | if (!drm_core_check_feature(dev, DRIVER_MODESET)) |
| 2311 | return -EINVAL; |
| 2312 | |
Rob Clark | a2b34e2 | 2013-10-05 16:36:52 -0400 | [diff] [blame] | 2313 | plane = drm_plane_find(dev, plane_resp->plane_id); |
Daniel Vetter | fcf93f6 | 2014-11-12 08:45:01 +0100 | [diff] [blame] | 2314 | if (!plane) |
| 2315 | return -ENOENT; |
Jesse Barnes | 8cf5c91 | 2011-11-14 14:51:27 -0800 | [diff] [blame] | 2316 | |
Daniel Vetter | fcf93f6 | 2014-11-12 08:45:01 +0100 | [diff] [blame] | 2317 | drm_modeset_lock(&plane->mutex, NULL); |
Jesse Barnes | 8cf5c91 | 2011-11-14 14:51:27 -0800 | [diff] [blame] | 2318 | if (plane->crtc) |
| 2319 | plane_resp->crtc_id = plane->crtc->base.id; |
| 2320 | else |
| 2321 | plane_resp->crtc_id = 0; |
| 2322 | |
| 2323 | if (plane->fb) |
| 2324 | plane_resp->fb_id = plane->fb->base.id; |
| 2325 | else |
| 2326 | plane_resp->fb_id = 0; |
Daniel Vetter | fcf93f6 | 2014-11-12 08:45:01 +0100 | [diff] [blame] | 2327 | drm_modeset_unlock(&plane->mutex); |
Jesse Barnes | 8cf5c91 | 2011-11-14 14:51:27 -0800 | [diff] [blame] | 2328 | |
| 2329 | plane_resp->plane_id = plane->base.id; |
| 2330 | plane_resp->possible_crtcs = plane->possible_crtcs; |
Ville Syrjälä | 778ad90 | 2013-06-03 16:11:42 +0300 | [diff] [blame] | 2331 | plane_resp->gamma_size = 0; |
Jesse Barnes | 8cf5c91 | 2011-11-14 14:51:27 -0800 | [diff] [blame] | 2332 | |
| 2333 | /* |
| 2334 | * This ioctl is called twice, once to determine how much space is |
| 2335 | * needed, and the 2nd time to fill it. |
| 2336 | */ |
| 2337 | if (plane->format_count && |
| 2338 | (plane_resp->count_format_types >= plane->format_count)) { |
Ville Syrjälä | 81f6c7f | 2011-12-20 00:06:42 +0200 | [diff] [blame] | 2339 | format_ptr = (uint32_t __user *)(unsigned long)plane_resp->format_type_ptr; |
Jesse Barnes | 8cf5c91 | 2011-11-14 14:51:27 -0800 | [diff] [blame] | 2340 | if (copy_to_user(format_ptr, |
| 2341 | plane->format_types, |
| 2342 | sizeof(uint32_t) * plane->format_count)) { |
Daniel Vetter | fcf93f6 | 2014-11-12 08:45:01 +0100 | [diff] [blame] | 2343 | return -EFAULT; |
Jesse Barnes | 8cf5c91 | 2011-11-14 14:51:27 -0800 | [diff] [blame] | 2344 | } |
| 2345 | } |
| 2346 | plane_resp->count_format_types = plane->format_count; |
| 2347 | |
Daniel Vetter | baf698b | 2014-11-12 11:59:47 +0100 | [diff] [blame] | 2348 | return 0; |
Jesse Barnes | 8cf5c91 | 2011-11-14 14:51:27 -0800 | [diff] [blame] | 2349 | } |
| 2350 | |
Laurent Pinchart | ead8610 | 2015-03-05 02:25:43 +0200 | [diff] [blame] | 2351 | /** |
| 2352 | * drm_plane_check_pixel_format - Check if the plane supports the pixel format |
| 2353 | * @plane: plane to check for format support |
| 2354 | * @format: the pixel format |
| 2355 | * |
| 2356 | * Returns: |
| 2357 | * Zero of @plane has @format in its list of supported pixel formats, -EINVAL |
| 2358 | * otherwise. |
| 2359 | */ |
| 2360 | int drm_plane_check_pixel_format(const struct drm_plane *plane, u32 format) |
| 2361 | { |
| 2362 | unsigned int i; |
| 2363 | |
| 2364 | for (i = 0; i < plane->format_count; i++) { |
| 2365 | if (format == plane->format_types[i]) |
| 2366 | return 0; |
| 2367 | } |
| 2368 | |
| 2369 | return -EINVAL; |
| 2370 | } |
| 2371 | |
Ville Syrjälä | ce8d9ec | 2015-10-15 20:40:00 +0300 | [diff] [blame] | 2372 | static int check_src_coords(uint32_t src_x, uint32_t src_y, |
| 2373 | uint32_t src_w, uint32_t src_h, |
| 2374 | const struct drm_framebuffer *fb) |
| 2375 | { |
| 2376 | unsigned int fb_width, fb_height; |
| 2377 | |
| 2378 | fb_width = fb->width << 16; |
| 2379 | fb_height = fb->height << 16; |
| 2380 | |
| 2381 | /* Make sure source coordinates are inside the fb. */ |
| 2382 | if (src_w > fb_width || |
| 2383 | src_x > fb_width - src_w || |
| 2384 | src_h > fb_height || |
| 2385 | src_y > fb_height - src_h) { |
| 2386 | DRM_DEBUG_KMS("Invalid source coordinates " |
| 2387 | "%u.%06ux%u.%06u+%u.%06u+%u.%06u\n", |
| 2388 | src_w >> 16, ((src_w & 0xffff) * 15625) >> 10, |
| 2389 | src_h >> 16, ((src_h & 0xffff) * 15625) >> 10, |
| 2390 | src_x >> 16, ((src_x & 0xffff) * 15625) >> 10, |
| 2391 | src_y >> 16, ((src_y & 0xffff) * 15625) >> 10); |
| 2392 | return -ENOSPC; |
| 2393 | } |
| 2394 | |
| 2395 | return 0; |
| 2396 | } |
| 2397 | |
Matt Roper | b36552b | 2014-06-10 08:28:09 -0700 | [diff] [blame] | 2398 | /* |
| 2399 | * setplane_internal - setplane handler for internal callers |
Jesse Barnes | 8cf5c91 | 2011-11-14 14:51:27 -0800 | [diff] [blame] | 2400 | * |
Matt Roper | b36552b | 2014-06-10 08:28:09 -0700 | [diff] [blame] | 2401 | * Note that we assume an extra reference has already been taken on fb. If the |
| 2402 | * update fails, this reference will be dropped before return; if it succeeds, |
| 2403 | * the previous framebuffer (if any) will be unreferenced instead. |
Daniel Vetter | c8e32cc | 2014-03-10 21:33:02 +0100 | [diff] [blame] | 2404 | * |
Matt Roper | b36552b | 2014-06-10 08:28:09 -0700 | [diff] [blame] | 2405 | * src_{x,y,w,h} are provided in 16.16 fixed point format |
Jesse Barnes | 8cf5c91 | 2011-11-14 14:51:27 -0800 | [diff] [blame] | 2406 | */ |
Daniel Vetter | f2b50c1 | 2014-09-12 17:07:32 +0200 | [diff] [blame] | 2407 | static int __setplane_internal(struct drm_plane *plane, |
| 2408 | struct drm_crtc *crtc, |
| 2409 | struct drm_framebuffer *fb, |
| 2410 | int32_t crtc_x, int32_t crtc_y, |
| 2411 | uint32_t crtc_w, uint32_t crtc_h, |
| 2412 | /* src_{x,y,w,h} values are 16.16 fixed point */ |
| 2413 | uint32_t src_x, uint32_t src_y, |
| 2414 | uint32_t src_w, uint32_t src_h) |
Jesse Barnes | 8cf5c91 | 2011-11-14 14:51:27 -0800 | [diff] [blame] | 2415 | { |
Jesse Barnes | 8cf5c91 | 2011-11-14 14:51:27 -0800 | [diff] [blame] | 2416 | int ret = 0; |
| 2417 | |
Jesse Barnes | 8cf5c91 | 2011-11-14 14:51:27 -0800 | [diff] [blame] | 2418 | /* No fb means shut it down */ |
Matt Roper | b36552b | 2014-06-10 08:28:09 -0700 | [diff] [blame] | 2419 | if (!fb) { |
Daniel Vetter | 3d30a59 | 2014-07-27 13:42:42 +0200 | [diff] [blame] | 2420 | plane->old_fb = plane->fb; |
Daniel Vetter | 731cce4 | 2014-04-23 10:24:11 +0200 | [diff] [blame] | 2421 | ret = plane->funcs->disable_plane(plane); |
| 2422 | if (!ret) { |
| 2423 | plane->crtc = NULL; |
| 2424 | plane->fb = NULL; |
| 2425 | } else { |
Daniel Vetter | 3d30a59 | 2014-07-27 13:42:42 +0200 | [diff] [blame] | 2426 | plane->old_fb = NULL; |
Daniel Vetter | 731cce4 | 2014-04-23 10:24:11 +0200 | [diff] [blame] | 2427 | } |
Jesse Barnes | 8cf5c91 | 2011-11-14 14:51:27 -0800 | [diff] [blame] | 2428 | goto out; |
| 2429 | } |
| 2430 | |
Matt Roper | 7f994f3 | 2014-05-29 08:06:51 -0700 | [diff] [blame] | 2431 | /* Check whether this plane is usable on this CRTC */ |
| 2432 | if (!(plane->possible_crtcs & drm_crtc_mask(crtc))) { |
| 2433 | DRM_DEBUG_KMS("Invalid crtc for plane\n"); |
| 2434 | ret = -EINVAL; |
| 2435 | goto out; |
| 2436 | } |
| 2437 | |
Ville Syrjälä | 62443be | 2011-12-20 00:06:47 +0200 | [diff] [blame] | 2438 | /* Check whether this plane supports the fb pixel format. */ |
Laurent Pinchart | ead8610 | 2015-03-05 02:25:43 +0200 | [diff] [blame] | 2439 | ret = drm_plane_check_pixel_format(plane, fb->pixel_format); |
| 2440 | if (ret) { |
Ville Syrjälä | 6ba6d03 | 2013-06-10 11:15:10 +0300 | [diff] [blame] | 2441 | DRM_DEBUG_KMS("Invalid pixel format %s\n", |
| 2442 | drm_get_format_name(fb->pixel_format)); |
Ville Syrjälä | 62443be | 2011-12-20 00:06:47 +0200 | [diff] [blame] | 2443 | goto out; |
| 2444 | } |
| 2445 | |
Matt Roper | 3968be9 | 2015-04-13 11:06:13 -0700 | [diff] [blame] | 2446 | /* Give drivers some help against integer overflows */ |
| 2447 | if (crtc_w > INT_MAX || |
| 2448 | crtc_x > INT_MAX - (int32_t) crtc_w || |
| 2449 | crtc_h > INT_MAX || |
| 2450 | crtc_y > INT_MAX - (int32_t) crtc_h) { |
| 2451 | DRM_DEBUG_KMS("Invalid CRTC coordinates %ux%u+%d+%d\n", |
| 2452 | crtc_w, crtc_h, crtc_x, crtc_y); |
Ville Syrjälä | c390eed | 2015-10-15 20:39:58 +0300 | [diff] [blame] | 2453 | ret = -ERANGE; |
Ville Syrjälä | 42ef878 | 2011-12-20 00:06:44 +0200 | [diff] [blame] | 2454 | goto out; |
| 2455 | } |
| 2456 | |
Ville Syrjälä | ce8d9ec | 2015-10-15 20:40:00 +0300 | [diff] [blame] | 2457 | ret = check_src_coords(src_x, src_y, src_w, src_h, fb); |
| 2458 | if (ret) |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 2459 | goto out; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 2460 | |
Daniel Vetter | 3d30a59 | 2014-07-27 13:42:42 +0200 | [diff] [blame] | 2461 | plane->old_fb = plane->fb; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 2462 | ret = plane->funcs->update_plane(plane, crtc, fb, |
Matt Roper | b36552b | 2014-06-10 08:28:09 -0700 | [diff] [blame] | 2463 | crtc_x, crtc_y, crtc_w, crtc_h, |
| 2464 | src_x, src_y, src_w, src_h); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 2465 | if (!ret) { |
| 2466 | plane->crtc = crtc; |
| 2467 | plane->fb = fb; |
Daniel Vetter | 35f8bad | 2013-02-15 21:21:37 +0100 | [diff] [blame] | 2468 | fb = NULL; |
Daniel Vetter | 0fe27f0 | 2014-04-23 17:34:06 +0200 | [diff] [blame] | 2469 | } else { |
Daniel Vetter | 3d30a59 | 2014-07-27 13:42:42 +0200 | [diff] [blame] | 2470 | plane->old_fb = NULL; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 2471 | } |
| 2472 | |
| 2473 | out: |
Daniel Vetter | 6c2a753 | 2012-12-11 00:59:24 +0100 | [diff] [blame] | 2474 | if (fb) |
| 2475 | drm_framebuffer_unreference(fb); |
Daniel Vetter | 3d30a59 | 2014-07-27 13:42:42 +0200 | [diff] [blame] | 2476 | if (plane->old_fb) |
| 2477 | drm_framebuffer_unreference(plane->old_fb); |
| 2478 | plane->old_fb = NULL; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 2479 | |
| 2480 | return ret; |
Daniel Vetter | f2b50c1 | 2014-09-12 17:07:32 +0200 | [diff] [blame] | 2481 | } |
Matt Roper | b36552b | 2014-06-10 08:28:09 -0700 | [diff] [blame] | 2482 | |
Daniel Vetter | f2b50c1 | 2014-09-12 17:07:32 +0200 | [diff] [blame] | 2483 | static int setplane_internal(struct drm_plane *plane, |
| 2484 | struct drm_crtc *crtc, |
| 2485 | struct drm_framebuffer *fb, |
| 2486 | int32_t crtc_x, int32_t crtc_y, |
| 2487 | uint32_t crtc_w, uint32_t crtc_h, |
| 2488 | /* src_{x,y,w,h} values are 16.16 fixed point */ |
| 2489 | uint32_t src_x, uint32_t src_y, |
| 2490 | uint32_t src_w, uint32_t src_h) |
| 2491 | { |
| 2492 | int ret; |
| 2493 | |
| 2494 | drm_modeset_lock_all(plane->dev); |
| 2495 | ret = __setplane_internal(plane, crtc, fb, |
| 2496 | crtc_x, crtc_y, crtc_w, crtc_h, |
| 2497 | src_x, src_y, src_w, src_h); |
| 2498 | drm_modeset_unlock_all(plane->dev); |
| 2499 | |
| 2500 | return ret; |
Matt Roper | b36552b | 2014-06-10 08:28:09 -0700 | [diff] [blame] | 2501 | } |
| 2502 | |
| 2503 | /** |
| 2504 | * drm_mode_setplane - configure a plane's configuration |
| 2505 | * @dev: DRM device |
| 2506 | * @data: ioctl data* |
| 2507 | * @file_priv: DRM file info |
| 2508 | * |
| 2509 | * Set plane configuration, including placement, fb, scaling, and other factors. |
| 2510 | * Or pass a NULL fb to disable (planes may be disabled without providing a |
| 2511 | * valid crtc). |
| 2512 | * |
| 2513 | * Returns: |
Daniel Vetter | 1a49863 | 2014-11-19 18:38:09 +0100 | [diff] [blame] | 2514 | * Zero on success, negative errno on failure. |
Matt Roper | b36552b | 2014-06-10 08:28:09 -0700 | [diff] [blame] | 2515 | */ |
| 2516 | int drm_mode_setplane(struct drm_device *dev, void *data, |
| 2517 | struct drm_file *file_priv) |
| 2518 | { |
| 2519 | struct drm_mode_set_plane *plane_req = data; |
Matt Roper | b36552b | 2014-06-10 08:28:09 -0700 | [diff] [blame] | 2520 | struct drm_plane *plane; |
| 2521 | struct drm_crtc *crtc = NULL; |
| 2522 | struct drm_framebuffer *fb = NULL; |
| 2523 | |
| 2524 | if (!drm_core_check_feature(dev, DRIVER_MODESET)) |
| 2525 | return -EINVAL; |
| 2526 | |
Matt Roper | b36552b | 2014-06-10 08:28:09 -0700 | [diff] [blame] | 2527 | /* |
| 2528 | * First, find the plane, crtc, and fb objects. If not available, |
| 2529 | * we don't bother to call the driver. |
| 2530 | */ |
Rob Clark | 933f622 | 2014-11-25 20:33:11 -0500 | [diff] [blame] | 2531 | plane = drm_plane_find(dev, plane_req->plane_id); |
| 2532 | if (!plane) { |
Matt Roper | b36552b | 2014-06-10 08:28:09 -0700 | [diff] [blame] | 2533 | DRM_DEBUG_KMS("Unknown plane ID %d\n", |
| 2534 | plane_req->plane_id); |
| 2535 | return -ENOENT; |
| 2536 | } |
Matt Roper | b36552b | 2014-06-10 08:28:09 -0700 | [diff] [blame] | 2537 | |
| 2538 | if (plane_req->fb_id) { |
| 2539 | fb = drm_framebuffer_lookup(dev, plane_req->fb_id); |
| 2540 | if (!fb) { |
| 2541 | DRM_DEBUG_KMS("Unknown framebuffer ID %d\n", |
| 2542 | plane_req->fb_id); |
| 2543 | return -ENOENT; |
| 2544 | } |
| 2545 | |
Rob Clark | 933f622 | 2014-11-25 20:33:11 -0500 | [diff] [blame] | 2546 | crtc = drm_crtc_find(dev, plane_req->crtc_id); |
| 2547 | if (!crtc) { |
Matt Roper | b36552b | 2014-06-10 08:28:09 -0700 | [diff] [blame] | 2548 | DRM_DEBUG_KMS("Unknown crtc ID %d\n", |
| 2549 | plane_req->crtc_id); |
| 2550 | return -ENOENT; |
| 2551 | } |
Matt Roper | b36552b | 2014-06-10 08:28:09 -0700 | [diff] [blame] | 2552 | } |
| 2553 | |
Matt Roper | 161d0dc | 2014-06-10 08:28:10 -0700 | [diff] [blame] | 2554 | /* |
| 2555 | * setplane_internal will take care of deref'ing either the old or new |
| 2556 | * framebuffer depending on success. |
| 2557 | */ |
Chris Wilson | 17cfd91 | 2014-06-13 15:22:28 +0100 | [diff] [blame] | 2558 | return setplane_internal(plane, crtc, fb, |
Matt Roper | b36552b | 2014-06-10 08:28:09 -0700 | [diff] [blame] | 2559 | plane_req->crtc_x, plane_req->crtc_y, |
| 2560 | plane_req->crtc_w, plane_req->crtc_h, |
| 2561 | plane_req->src_x, plane_req->src_y, |
| 2562 | plane_req->src_w, plane_req->src_h); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 2563 | } |
| 2564 | |
| 2565 | /** |
Daniel Vetter | 2d13b67 | 2012-12-11 13:47:23 +0100 | [diff] [blame] | 2566 | * drm_mode_set_config_internal - helper to call ->set_config |
| 2567 | * @set: modeset config to set |
| 2568 | * |
| 2569 | * This is a little helper to wrap internal calls to the ->set_config driver |
| 2570 | * interface. The only thing it adds is correct refcounting dance. |
Thierry Reding | 4dfd909 | 2014-12-10 13:03:34 +0100 | [diff] [blame] | 2571 | * |
Daniel Vetter | c8e32cc | 2014-03-10 21:33:02 +0100 | [diff] [blame] | 2572 | * Returns: |
Daniel Vetter | 1a49863 | 2014-11-19 18:38:09 +0100 | [diff] [blame] | 2573 | * Zero on success, negative errno on failure. |
Daniel Vetter | 2d13b67 | 2012-12-11 13:47:23 +0100 | [diff] [blame] | 2574 | */ |
| 2575 | int drm_mode_set_config_internal(struct drm_mode_set *set) |
| 2576 | { |
| 2577 | struct drm_crtc *crtc = set->crtc; |
Daniel Vetter | 5cef29a | 2013-06-15 00:13:16 +0200 | [diff] [blame] | 2578 | struct drm_framebuffer *fb; |
| 2579 | struct drm_crtc *tmp; |
Daniel Vetter | b0d1232 | 2012-12-11 01:07:12 +0100 | [diff] [blame] | 2580 | int ret; |
Daniel Vetter | 2d13b67 | 2012-12-11 13:47:23 +0100 | [diff] [blame] | 2581 | |
Daniel Vetter | 5cef29a | 2013-06-15 00:13:16 +0200 | [diff] [blame] | 2582 | /* |
| 2583 | * NOTE: ->set_config can also disable other crtcs (if we steal all |
| 2584 | * connectors from it), hence we need to refcount the fbs across all |
| 2585 | * crtcs. Atomic modeset will have saner semantics ... |
| 2586 | */ |
Daniel Vetter | e4f6254 | 2015-07-09 23:44:35 +0200 | [diff] [blame] | 2587 | drm_for_each_crtc(tmp, crtc->dev) |
Daniel Vetter | 3d30a59 | 2014-07-27 13:42:42 +0200 | [diff] [blame] | 2588 | tmp->primary->old_fb = tmp->primary->fb; |
Daniel Vetter | 5cef29a | 2013-06-15 00:13:16 +0200 | [diff] [blame] | 2589 | |
Daniel Vetter | b0d1232 | 2012-12-11 01:07:12 +0100 | [diff] [blame] | 2590 | fb = set->fb; |
| 2591 | |
| 2592 | ret = crtc->funcs->set_config(set); |
| 2593 | if (ret == 0) { |
Matt Roper | e13161a | 2014-04-01 15:22:38 -0700 | [diff] [blame] | 2594 | crtc->primary->crtc = crtc; |
Daniel Vetter | 0fe27f0 | 2014-04-23 17:34:06 +0200 | [diff] [blame] | 2595 | crtc->primary->fb = fb; |
Daniel Vetter | 5cef29a | 2013-06-15 00:13:16 +0200 | [diff] [blame] | 2596 | } |
Daniel Vetter | cc85e12 | 2013-06-15 00:13:15 +0200 | [diff] [blame] | 2597 | |
Daniel Vetter | e4f6254 | 2015-07-09 23:44:35 +0200 | [diff] [blame] | 2598 | drm_for_each_crtc(tmp, crtc->dev) { |
Matt Roper | f4510a2 | 2014-04-01 15:22:40 -0700 | [diff] [blame] | 2599 | if (tmp->primary->fb) |
| 2600 | drm_framebuffer_reference(tmp->primary->fb); |
Daniel Vetter | 3d30a59 | 2014-07-27 13:42:42 +0200 | [diff] [blame] | 2601 | if (tmp->primary->old_fb) |
| 2602 | drm_framebuffer_unreference(tmp->primary->old_fb); |
| 2603 | tmp->primary->old_fb = NULL; |
Daniel Vetter | b0d1232 | 2012-12-11 01:07:12 +0100 | [diff] [blame] | 2604 | } |
| 2605 | |
| 2606 | return ret; |
Daniel Vetter | 2d13b67 | 2012-12-11 13:47:23 +0100 | [diff] [blame] | 2607 | } |
| 2608 | EXPORT_SYMBOL(drm_mode_set_config_internal); |
| 2609 | |
Matt Roper | af93629 | 2014-04-01 15:22:34 -0700 | [diff] [blame] | 2610 | /** |
Gustavo Padovan | ecb7e16 | 2014-12-01 15:40:09 -0800 | [diff] [blame] | 2611 | * drm_crtc_get_hv_timing - Fetches hdisplay/vdisplay for given mode |
| 2612 | * @mode: mode to query |
| 2613 | * @hdisplay: hdisplay value to fill in |
| 2614 | * @vdisplay: vdisplay value to fill in |
| 2615 | * |
| 2616 | * The vdisplay value will be doubled if the specified mode is a stereo mode of |
| 2617 | * the appropriate layout. |
| 2618 | */ |
| 2619 | void drm_crtc_get_hv_timing(const struct drm_display_mode *mode, |
| 2620 | int *hdisplay, int *vdisplay) |
| 2621 | { |
| 2622 | struct drm_display_mode adjusted; |
| 2623 | |
| 2624 | drm_mode_copy(&adjusted, mode); |
| 2625 | drm_mode_set_crtcinfo(&adjusted, CRTC_STEREO_DOUBLE_ONLY); |
| 2626 | *hdisplay = adjusted.crtc_hdisplay; |
| 2627 | *vdisplay = adjusted.crtc_vdisplay; |
| 2628 | } |
| 2629 | EXPORT_SYMBOL(drm_crtc_get_hv_timing); |
| 2630 | |
| 2631 | /** |
Matt Roper | af93629 | 2014-04-01 15:22:34 -0700 | [diff] [blame] | 2632 | * drm_crtc_check_viewport - Checks that a framebuffer is big enough for the |
| 2633 | * CRTC viewport |
| 2634 | * @crtc: CRTC that framebuffer will be displayed on |
| 2635 | * @x: x panning |
| 2636 | * @y: y panning |
| 2637 | * @mode: mode that framebuffer will be displayed under |
| 2638 | * @fb: framebuffer to check size of |
Damien Lespiau | c11e928 | 2013-09-25 16:45:30 +0100 | [diff] [blame] | 2639 | */ |
Matt Roper | af93629 | 2014-04-01 15:22:34 -0700 | [diff] [blame] | 2640 | int drm_crtc_check_viewport(const struct drm_crtc *crtc, |
| 2641 | int x, int y, |
| 2642 | const struct drm_display_mode *mode, |
| 2643 | const struct drm_framebuffer *fb) |
Damien Lespiau | c11e928 | 2013-09-25 16:45:30 +0100 | [diff] [blame] | 2644 | |
| 2645 | { |
| 2646 | int hdisplay, vdisplay; |
| 2647 | |
Gustavo Padovan | ecb7e16 | 2014-12-01 15:40:09 -0800 | [diff] [blame] | 2648 | drm_crtc_get_hv_timing(mode, &hdisplay, &vdisplay); |
Damien Lespiau | a0c1bbb | 2013-09-25 16:45:31 +0100 | [diff] [blame] | 2649 | |
Ville Syrjälä | 33e0be6 | 2015-10-16 18:38:39 +0300 | [diff] [blame] | 2650 | if (crtc->state && |
| 2651 | crtc->primary->state->rotation & (BIT(DRM_ROTATE_90) | |
| 2652 | BIT(DRM_ROTATE_270))) |
Damien Lespiau | c11e928 | 2013-09-25 16:45:30 +0100 | [diff] [blame] | 2653 | swap(hdisplay, vdisplay); |
| 2654 | |
Ville Syrjälä | ce8d9ec | 2015-10-15 20:40:00 +0300 | [diff] [blame] | 2655 | return check_src_coords(x << 16, y << 16, |
| 2656 | hdisplay << 16, vdisplay << 16, fb); |
Damien Lespiau | c11e928 | 2013-09-25 16:45:30 +0100 | [diff] [blame] | 2657 | } |
Matt Roper | af93629 | 2014-04-01 15:22:34 -0700 | [diff] [blame] | 2658 | EXPORT_SYMBOL(drm_crtc_check_viewport); |
Damien Lespiau | c11e928 | 2013-09-25 16:45:30 +0100 | [diff] [blame] | 2659 | |
Daniel Vetter | 2d13b67 | 2012-12-11 13:47:23 +0100 | [diff] [blame] | 2660 | /** |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 2661 | * drm_mode_setcrtc - set CRTC configuration |
Daniel Vetter | 065a50ed | 2012-12-02 00:09:18 +0100 | [diff] [blame] | 2662 | * @dev: drm device for the ioctl |
| 2663 | * @data: data pointer for the ioctl |
| 2664 | * @file_priv: drm file for the ioctl call |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 2665 | * |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 2666 | * Build a new CRTC configuration based on user request. |
| 2667 | * |
| 2668 | * Called by the user via ioctl. |
| 2669 | * |
Daniel Vetter | c8e32cc | 2014-03-10 21:33:02 +0100 | [diff] [blame] | 2670 | * Returns: |
Daniel Vetter | 1a49863 | 2014-11-19 18:38:09 +0100 | [diff] [blame] | 2671 | * Zero on success, negative errno on failure. |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 2672 | */ |
| 2673 | int drm_mode_setcrtc(struct drm_device *dev, void *data, |
| 2674 | struct drm_file *file_priv) |
| 2675 | { |
| 2676 | struct drm_mode_config *config = &dev->mode_config; |
| 2677 | struct drm_mode_crtc *crtc_req = data; |
Ville Syrjälä | 6653cc8 | 2012-03-13 12:35:38 +0200 | [diff] [blame] | 2678 | struct drm_crtc *crtc; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 2679 | struct drm_connector **connector_set = NULL, *connector; |
| 2680 | struct drm_framebuffer *fb = NULL; |
| 2681 | struct drm_display_mode *mode = NULL; |
| 2682 | struct drm_mode_set set; |
| 2683 | uint32_t __user *set_connectors_ptr; |
Laurent Pinchart | 4a1b071 | 2012-05-17 13:27:21 +0200 | [diff] [blame] | 2684 | int ret; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 2685 | int i; |
| 2686 | |
Dave Airlie | fb3b06c | 2011-02-08 13:55:21 +1000 | [diff] [blame] | 2687 | if (!drm_core_check_feature(dev, DRIVER_MODESET)) |
| 2688 | return -EINVAL; |
| 2689 | |
Zhao Junwang | 01447e9 | 2015-07-07 17:08:35 +0800 | [diff] [blame] | 2690 | /* |
| 2691 | * Universal plane src offsets are only 16.16, prevent havoc for |
| 2692 | * drivers using universal plane code internally. |
| 2693 | */ |
| 2694 | if (crtc_req->x & 0xffff0000 || crtc_req->y & 0xffff0000) |
Ville Syrjälä | 1d97e91 | 2012-03-13 12:35:41 +0200 | [diff] [blame] | 2695 | return -ERANGE; |
| 2696 | |
Daniel Vetter | 8484990 | 2012-12-02 00:28:11 +0100 | [diff] [blame] | 2697 | drm_modeset_lock_all(dev); |
Rob Clark | a2b34e2 | 2013-10-05 16:36:52 -0400 | [diff] [blame] | 2698 | crtc = drm_crtc_find(dev, crtc_req->crtc_id); |
| 2699 | if (!crtc) { |
Zhao Yakui | 58367ed | 2009-07-20 13:48:07 +0800 | [diff] [blame] | 2700 | 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] | 2701 | ret = -ENOENT; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 2702 | goto out; |
| 2703 | } |
Ville Syrjälä | fa3ab4c | 2015-12-08 18:41:53 +0200 | [diff] [blame] | 2704 | DRM_DEBUG_KMS("[CRTC:%d:%s]\n", crtc->base.id, crtc->name); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 2705 | |
| 2706 | if (crtc_req->mode_valid) { |
| 2707 | /* If we have a mode we need a framebuffer. */ |
| 2708 | /* If we pass -1, set the mode with the currently bound fb */ |
| 2709 | if (crtc_req->fb_id == -1) { |
Matt Roper | f4510a2 | 2014-04-01 15:22:40 -0700 | [diff] [blame] | 2710 | if (!crtc->primary->fb) { |
Ville Syrjälä | 6653cc8 | 2012-03-13 12:35:38 +0200 | [diff] [blame] | 2711 | DRM_DEBUG_KMS("CRTC doesn't have current FB\n"); |
| 2712 | ret = -EINVAL; |
| 2713 | goto out; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 2714 | } |
Matt Roper | f4510a2 | 2014-04-01 15:22:40 -0700 | [diff] [blame] | 2715 | fb = crtc->primary->fb; |
Daniel Vetter | b0d1232 | 2012-12-11 01:07:12 +0100 | [diff] [blame] | 2716 | /* Make refcounting symmetric with the lookup path. */ |
| 2717 | drm_framebuffer_reference(fb); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 2718 | } else { |
Daniel Vetter | 786b99e | 2012-12-02 21:53:40 +0100 | [diff] [blame] | 2719 | fb = drm_framebuffer_lookup(dev, crtc_req->fb_id); |
| 2720 | if (!fb) { |
Zhao Yakui | 58367ed | 2009-07-20 13:48:07 +0800 | [diff] [blame] | 2721 | DRM_DEBUG_KMS("Unknown FB ID%d\n", |
| 2722 | crtc_req->fb_id); |
Ville Syrjälä | 37c4e70 | 2013-10-17 13:35:01 +0300 | [diff] [blame] | 2723 | ret = -ENOENT; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 2724 | goto out; |
| 2725 | } |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 2726 | } |
| 2727 | |
| 2728 | mode = drm_mode_create(dev); |
Ville Syrjälä | ee34ab5 | 2012-03-13 12:35:43 +0200 | [diff] [blame] | 2729 | if (!mode) { |
| 2730 | ret = -ENOMEM; |
| 2731 | goto out; |
| 2732 | } |
| 2733 | |
Daniel Stone | 934a8a8 | 2015-05-22 13:34:48 +0100 | [diff] [blame] | 2734 | ret = drm_mode_convert_umode(mode, &crtc_req->mode); |
Ville Syrjälä | 90367bf | 2012-03-13 12:35:44 +0200 | [diff] [blame] | 2735 | if (ret) { |
| 2736 | DRM_DEBUG_KMS("Invalid mode\n"); |
| 2737 | goto out; |
| 2738 | } |
| 2739 | |
Laurent Pinchart | 7eb5f30 | 2015-03-09 10:41:07 +0200 | [diff] [blame] | 2740 | /* |
| 2741 | * Check whether the primary plane supports the fb pixel format. |
| 2742 | * Drivers not implementing the universal planes API use a |
| 2743 | * default formats list provided by the DRM core which doesn't |
| 2744 | * match real hardware capabilities. Skip the check in that |
| 2745 | * case. |
| 2746 | */ |
| 2747 | if (!crtc->primary->format_default) { |
| 2748 | ret = drm_plane_check_pixel_format(crtc->primary, |
| 2749 | fb->pixel_format); |
| 2750 | if (ret) { |
| 2751 | DRM_DEBUG_KMS("Invalid pixel format %s\n", |
| 2752 | drm_get_format_name(fb->pixel_format)); |
| 2753 | goto out; |
| 2754 | } |
| 2755 | } |
| 2756 | |
Damien Lespiau | c11e928 | 2013-09-25 16:45:30 +0100 | [diff] [blame] | 2757 | ret = drm_crtc_check_viewport(crtc, crtc_req->x, crtc_req->y, |
| 2758 | mode, fb); |
| 2759 | if (ret) |
Ville Syrjälä | 5f61bb4 | 2012-03-13 12:35:45 +0200 | [diff] [blame] | 2760 | goto out; |
Damien Lespiau | c11e928 | 2013-09-25 16:45:30 +0100 | [diff] [blame] | 2761 | |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 2762 | } |
| 2763 | |
| 2764 | if (crtc_req->count_connectors == 0 && mode) { |
Zhao Yakui | 58367ed | 2009-07-20 13:48:07 +0800 | [diff] [blame] | 2765 | DRM_DEBUG_KMS("Count connectors is 0 but mode set\n"); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 2766 | ret = -EINVAL; |
| 2767 | goto out; |
| 2768 | } |
| 2769 | |
Jakob Bornecrantz | 7781de7 | 2009-08-03 13:43:58 +0100 | [diff] [blame] | 2770 | if (crtc_req->count_connectors > 0 && (!mode || !fb)) { |
Zhao Yakui | 58367ed | 2009-07-20 13:48:07 +0800 | [diff] [blame] | 2771 | 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] | 2772 | crtc_req->count_connectors); |
| 2773 | ret = -EINVAL; |
| 2774 | goto out; |
| 2775 | } |
| 2776 | |
| 2777 | if (crtc_req->count_connectors > 0) { |
| 2778 | u32 out_id; |
| 2779 | |
| 2780 | /* Avoid unbounded kernel memory allocation */ |
| 2781 | if (crtc_req->count_connectors > config->num_connector) { |
| 2782 | ret = -EINVAL; |
| 2783 | goto out; |
| 2784 | } |
| 2785 | |
Thierry Reding | 2f6c538 | 2014-12-10 13:03:36 +0100 | [diff] [blame] | 2786 | connector_set = kmalloc_array(crtc_req->count_connectors, |
| 2787 | sizeof(struct drm_connector *), |
| 2788 | GFP_KERNEL); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 2789 | if (!connector_set) { |
| 2790 | ret = -ENOMEM; |
| 2791 | goto out; |
| 2792 | } |
| 2793 | |
| 2794 | for (i = 0; i < crtc_req->count_connectors; i++) { |
Dave Airlie | b164d31 | 2016-04-27 11:10:09 +1000 | [diff] [blame] | 2795 | connector_set[i] = NULL; |
Ville Syrjälä | 81f6c7f | 2011-12-20 00:06:42 +0200 | [diff] [blame] | 2796 | 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] | 2797 | if (get_user(out_id, &set_connectors_ptr[i])) { |
| 2798 | ret = -EFAULT; |
| 2799 | goto out; |
| 2800 | } |
| 2801 | |
Dave Airlie | b164d31 | 2016-04-27 11:10:09 +1000 | [diff] [blame] | 2802 | connector = drm_connector_lookup(dev, out_id); |
Rob Clark | a2b34e2 | 2013-10-05 16:36:52 -0400 | [diff] [blame] | 2803 | if (!connector) { |
Zhao Yakui | 58367ed | 2009-07-20 13:48:07 +0800 | [diff] [blame] | 2804 | DRM_DEBUG_KMS("Connector id %d unknown\n", |
| 2805 | out_id); |
Ville Syrjälä | f27657f | 2013-10-17 13:35:00 +0300 | [diff] [blame] | 2806 | ret = -ENOENT; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 2807 | goto out; |
| 2808 | } |
Jerome Glisse | 9440106 | 2010-07-15 15:43:25 -0400 | [diff] [blame] | 2809 | DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n", |
| 2810 | connector->base.id, |
Jani Nikula | 2593382 | 2014-06-03 14:56:20 +0300 | [diff] [blame] | 2811 | connector->name); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 2812 | |
| 2813 | connector_set[i] = connector; |
| 2814 | } |
| 2815 | } |
| 2816 | |
| 2817 | set.crtc = crtc; |
| 2818 | set.x = crtc_req->x; |
| 2819 | set.y = crtc_req->y; |
| 2820 | set.mode = mode; |
| 2821 | set.connectors = connector_set; |
| 2822 | set.num_connectors = crtc_req->count_connectors; |
Dave Airlie | 5ef5f72 | 2009-08-17 13:11:23 +1000 | [diff] [blame] | 2823 | set.fb = fb; |
Daniel Vetter | 2d13b67 | 2012-12-11 13:47:23 +0100 | [diff] [blame] | 2824 | ret = drm_mode_set_config_internal(&set); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 2825 | |
| 2826 | out: |
Daniel Vetter | b0d1232 | 2012-12-11 01:07:12 +0100 | [diff] [blame] | 2827 | if (fb) |
| 2828 | drm_framebuffer_unreference(fb); |
| 2829 | |
Dave Airlie | b164d31 | 2016-04-27 11:10:09 +1000 | [diff] [blame] | 2830 | if (connector_set) { |
| 2831 | for (i = 0; i < crtc_req->count_connectors; i++) { |
| 2832 | if (connector_set[i]) |
| 2833 | drm_connector_unreference(connector_set[i]); |
| 2834 | } |
| 2835 | } |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 2836 | kfree(connector_set); |
Ville Syrjälä | ee34ab5 | 2012-03-13 12:35:43 +0200 | [diff] [blame] | 2837 | drm_mode_destroy(dev, mode); |
Daniel Vetter | 8484990 | 2012-12-02 00:28:11 +0100 | [diff] [blame] | 2838 | drm_modeset_unlock_all(dev); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 2839 | return ret; |
| 2840 | } |
| 2841 | |
Matt Roper | 161d0dc | 2014-06-10 08:28:10 -0700 | [diff] [blame] | 2842 | /** |
| 2843 | * drm_mode_cursor_universal - translate legacy cursor ioctl call into a |
| 2844 | * universal plane handler call |
| 2845 | * @crtc: crtc to update cursor for |
| 2846 | * @req: data pointer for the ioctl |
| 2847 | * @file_priv: drm file for the ioctl call |
| 2848 | * |
| 2849 | * Legacy cursor ioctl's work directly with driver buffer handles. To |
| 2850 | * translate legacy ioctl calls into universal plane handler calls, we need to |
| 2851 | * wrap the native buffer handle in a drm_framebuffer. |
| 2852 | * |
| 2853 | * Note that we assume any handle passed to the legacy ioctls was a 32-bit ARGB |
| 2854 | * buffer with a pitch of 4*width; the universal plane interface should be used |
| 2855 | * directly in cases where the hardware can support other buffer settings and |
| 2856 | * userspace wants to make use of these capabilities. |
| 2857 | * |
| 2858 | * Returns: |
Daniel Vetter | 1a49863 | 2014-11-19 18:38:09 +0100 | [diff] [blame] | 2859 | * Zero on success, negative errno on failure. |
Matt Roper | 161d0dc | 2014-06-10 08:28:10 -0700 | [diff] [blame] | 2860 | */ |
| 2861 | static int drm_mode_cursor_universal(struct drm_crtc *crtc, |
| 2862 | struct drm_mode_cursor2 *req, |
| 2863 | struct drm_file *file_priv) |
| 2864 | { |
| 2865 | struct drm_device *dev = crtc->dev; |
| 2866 | struct drm_framebuffer *fb = NULL; |
| 2867 | struct drm_mode_fb_cmd2 fbreq = { |
| 2868 | .width = req->width, |
| 2869 | .height = req->height, |
| 2870 | .pixel_format = DRM_FORMAT_ARGB8888, |
| 2871 | .pitches = { req->width * 4 }, |
| 2872 | .handles = { req->handle }, |
| 2873 | }; |
| 2874 | int32_t crtc_x, crtc_y; |
| 2875 | uint32_t crtc_w = 0, crtc_h = 0; |
| 2876 | uint32_t src_w = 0, src_h = 0; |
| 2877 | int ret = 0; |
| 2878 | |
| 2879 | BUG_ON(!crtc->cursor); |
Daniel Vetter | f2b50c1 | 2014-09-12 17:07:32 +0200 | [diff] [blame] | 2880 | WARN_ON(crtc->cursor->crtc != crtc && crtc->cursor->crtc != NULL); |
Matt Roper | 161d0dc | 2014-06-10 08:28:10 -0700 | [diff] [blame] | 2881 | |
| 2882 | /* |
| 2883 | * Obtain fb we'll be using (either new or existing) and take an extra |
| 2884 | * reference to it if fb != null. setplane will take care of dropping |
| 2885 | * the reference if the plane update fails. |
| 2886 | */ |
| 2887 | if (req->flags & DRM_MODE_CURSOR_BO) { |
| 2888 | if (req->handle) { |
Chris Wilson | 9a6f513 | 2015-02-25 13:45:26 +0000 | [diff] [blame] | 2889 | fb = internal_framebuffer_create(dev, &fbreq, file_priv); |
Matt Roper | 161d0dc | 2014-06-10 08:28:10 -0700 | [diff] [blame] | 2890 | if (IS_ERR(fb)) { |
| 2891 | DRM_DEBUG_KMS("failed to wrap cursor buffer in drm framebuffer\n"); |
| 2892 | return PTR_ERR(fb); |
| 2893 | } |
Gerd Hoffmann | dd54659 | 2016-05-31 08:54:52 +0200 | [diff] [blame] | 2894 | fb->hot_x = req->hot_x; |
| 2895 | fb->hot_y = req->hot_y; |
Matt Roper | 161d0dc | 2014-06-10 08:28:10 -0700 | [diff] [blame] | 2896 | } else { |
| 2897 | fb = NULL; |
| 2898 | } |
| 2899 | } else { |
Matt Roper | 161d0dc | 2014-06-10 08:28:10 -0700 | [diff] [blame] | 2900 | fb = crtc->cursor->fb; |
| 2901 | if (fb) |
| 2902 | drm_framebuffer_reference(fb); |
Matt Roper | 161d0dc | 2014-06-10 08:28:10 -0700 | [diff] [blame] | 2903 | } |
| 2904 | |
| 2905 | if (req->flags & DRM_MODE_CURSOR_MOVE) { |
| 2906 | crtc_x = req->x; |
| 2907 | crtc_y = req->y; |
| 2908 | } else { |
| 2909 | crtc_x = crtc->cursor_x; |
| 2910 | crtc_y = crtc->cursor_y; |
| 2911 | } |
| 2912 | |
| 2913 | if (fb) { |
| 2914 | crtc_w = fb->width; |
| 2915 | crtc_h = fb->height; |
| 2916 | src_w = fb->width << 16; |
| 2917 | src_h = fb->height << 16; |
| 2918 | } |
| 2919 | |
| 2920 | /* |
| 2921 | * setplane_internal will take care of deref'ing either the old or new |
| 2922 | * framebuffer depending on success. |
| 2923 | */ |
Daniel Vetter | f2b50c1 | 2014-09-12 17:07:32 +0200 | [diff] [blame] | 2924 | ret = __setplane_internal(crtc->cursor, crtc, fb, |
Matt Roper | 161d0dc | 2014-06-10 08:28:10 -0700 | [diff] [blame] | 2925 | crtc_x, crtc_y, crtc_w, crtc_h, |
| 2926 | 0, 0, src_w, src_h); |
| 2927 | |
| 2928 | /* Update successful; save new cursor position, if necessary */ |
| 2929 | if (ret == 0 && req->flags & DRM_MODE_CURSOR_MOVE) { |
| 2930 | crtc->cursor_x = req->x; |
| 2931 | crtc->cursor_y = req->y; |
| 2932 | } |
| 2933 | |
| 2934 | return ret; |
| 2935 | } |
| 2936 | |
Dave Airlie | 4c813d4 | 2013-06-20 11:48:52 +1000 | [diff] [blame] | 2937 | static int drm_mode_cursor_common(struct drm_device *dev, |
| 2938 | struct drm_mode_cursor2 *req, |
| 2939 | struct drm_file *file_priv) |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 2940 | { |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 2941 | struct drm_crtc *crtc; |
| 2942 | int ret = 0; |
| 2943 | |
Dave Airlie | fb3b06c | 2011-02-08 13:55:21 +1000 | [diff] [blame] | 2944 | if (!drm_core_check_feature(dev, DRIVER_MODESET)) |
| 2945 | return -EINVAL; |
| 2946 | |
Jakob Bornecrantz | 7c4eaca | 2012-08-16 08:29:03 +0000 | [diff] [blame] | 2947 | if (!req->flags || (~DRM_MODE_CURSOR_FLAGS & req->flags)) |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 2948 | return -EINVAL; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 2949 | |
Rob Clark | a2b34e2 | 2013-10-05 16:36:52 -0400 | [diff] [blame] | 2950 | crtc = drm_crtc_find(dev, req->crtc_id); |
| 2951 | if (!crtc) { |
Zhao Yakui | 58367ed | 2009-07-20 13:48:07 +0800 | [diff] [blame] | 2952 | DRM_DEBUG_KMS("Unknown CRTC ID %d\n", req->crtc_id); |
Ville Syrjälä | f27657f | 2013-10-17 13:35:00 +0300 | [diff] [blame] | 2953 | return -ENOENT; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 2954 | } |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 2955 | |
Matt Roper | 161d0dc | 2014-06-10 08:28:10 -0700 | [diff] [blame] | 2956 | /* |
| 2957 | * If this crtc has a universal cursor plane, call that plane's update |
| 2958 | * handler rather than using legacy cursor handlers. |
| 2959 | */ |
Daniel Vetter | 4d02e2d | 2014-11-11 10:12:00 +0100 | [diff] [blame] | 2960 | drm_modeset_lock_crtc(crtc, crtc->cursor); |
Daniel Vetter | f2b50c1 | 2014-09-12 17:07:32 +0200 | [diff] [blame] | 2961 | if (crtc->cursor) { |
| 2962 | ret = drm_mode_cursor_universal(crtc, req, file_priv); |
| 2963 | goto out; |
| 2964 | } |
| 2965 | |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 2966 | if (req->flags & DRM_MODE_CURSOR_BO) { |
Dave Airlie | 4c813d4 | 2013-06-20 11:48:52 +1000 | [diff] [blame] | 2967 | if (!crtc->funcs->cursor_set && !crtc->funcs->cursor_set2) { |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 2968 | ret = -ENXIO; |
| 2969 | goto out; |
| 2970 | } |
| 2971 | /* Turns off the cursor if handle is 0 */ |
Dave Airlie | 4c813d4 | 2013-06-20 11:48:52 +1000 | [diff] [blame] | 2972 | if (crtc->funcs->cursor_set2) |
| 2973 | ret = crtc->funcs->cursor_set2(crtc, file_priv, req->handle, |
| 2974 | req->width, req->height, req->hot_x, req->hot_y); |
| 2975 | else |
| 2976 | ret = crtc->funcs->cursor_set(crtc, file_priv, req->handle, |
| 2977 | req->width, req->height); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 2978 | } |
| 2979 | |
| 2980 | if (req->flags & DRM_MODE_CURSOR_MOVE) { |
| 2981 | if (crtc->funcs->cursor_move) { |
| 2982 | ret = crtc->funcs->cursor_move(crtc, req->x, req->y); |
| 2983 | } else { |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 2984 | ret = -EFAULT; |
| 2985 | goto out; |
| 2986 | } |
| 2987 | } |
| 2988 | out: |
Daniel Vetter | d059f65 | 2014-07-25 18:07:40 +0200 | [diff] [blame] | 2989 | drm_modeset_unlock_crtc(crtc); |
Daniel Vetter | dac3566 | 2012-12-02 15:24:10 +0100 | [diff] [blame] | 2990 | |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 2991 | return ret; |
Dave Airlie | 4c813d4 | 2013-06-20 11:48:52 +1000 | [diff] [blame] | 2992 | |
| 2993 | } |
Daniel Vetter | c8e32cc | 2014-03-10 21:33:02 +0100 | [diff] [blame] | 2994 | |
| 2995 | |
| 2996 | /** |
| 2997 | * drm_mode_cursor_ioctl - set CRTC's cursor configuration |
| 2998 | * @dev: drm device for the ioctl |
| 2999 | * @data: data pointer for the ioctl |
| 3000 | * @file_priv: drm file for the ioctl call |
| 3001 | * |
| 3002 | * Set the cursor configuration based on user request. |
| 3003 | * |
| 3004 | * Called by the user via ioctl. |
| 3005 | * |
| 3006 | * Returns: |
Daniel Vetter | 1a49863 | 2014-11-19 18:38:09 +0100 | [diff] [blame] | 3007 | * Zero on success, negative errno on failure. |
Daniel Vetter | c8e32cc | 2014-03-10 21:33:02 +0100 | [diff] [blame] | 3008 | */ |
Dave Airlie | 4c813d4 | 2013-06-20 11:48:52 +1000 | [diff] [blame] | 3009 | int drm_mode_cursor_ioctl(struct drm_device *dev, |
Daniel Vetter | c8e32cc | 2014-03-10 21:33:02 +0100 | [diff] [blame] | 3010 | void *data, struct drm_file *file_priv) |
Dave Airlie | 4c813d4 | 2013-06-20 11:48:52 +1000 | [diff] [blame] | 3011 | { |
| 3012 | struct drm_mode_cursor *req = data; |
| 3013 | struct drm_mode_cursor2 new_req; |
| 3014 | |
| 3015 | memcpy(&new_req, req, sizeof(struct drm_mode_cursor)); |
| 3016 | new_req.hot_x = new_req.hot_y = 0; |
| 3017 | |
| 3018 | return drm_mode_cursor_common(dev, &new_req, file_priv); |
| 3019 | } |
| 3020 | |
Daniel Vetter | c8e32cc | 2014-03-10 21:33:02 +0100 | [diff] [blame] | 3021 | /** |
| 3022 | * drm_mode_cursor2_ioctl - set CRTC's cursor configuration |
| 3023 | * @dev: drm device for the ioctl |
| 3024 | * @data: data pointer for the ioctl |
| 3025 | * @file_priv: drm file for the ioctl call |
| 3026 | * |
| 3027 | * Set the cursor configuration based on user request. This implements the 2nd |
| 3028 | * version of the cursor ioctl, which allows userspace to additionally specify |
| 3029 | * the hotspot of the pointer. |
| 3030 | * |
| 3031 | * Called by the user via ioctl. |
| 3032 | * |
| 3033 | * Returns: |
Daniel Vetter | 1a49863 | 2014-11-19 18:38:09 +0100 | [diff] [blame] | 3034 | * Zero on success, negative errno on failure. |
Daniel Vetter | c8e32cc | 2014-03-10 21:33:02 +0100 | [diff] [blame] | 3035 | */ |
Dave Airlie | 4c813d4 | 2013-06-20 11:48:52 +1000 | [diff] [blame] | 3036 | int drm_mode_cursor2_ioctl(struct drm_device *dev, |
| 3037 | void *data, struct drm_file *file_priv) |
| 3038 | { |
| 3039 | struct drm_mode_cursor2 *req = data; |
Thierry Reding | 4dfd909 | 2014-12-10 13:03:34 +0100 | [diff] [blame] | 3040 | |
Dave Airlie | 4c813d4 | 2013-06-20 11:48:52 +1000 | [diff] [blame] | 3041 | return drm_mode_cursor_common(dev, req, file_priv); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 3042 | } |
| 3043 | |
Daniel Vetter | c8e32cc | 2014-03-10 21:33:02 +0100 | [diff] [blame] | 3044 | /** |
| 3045 | * drm_mode_legacy_fb_format - compute drm fourcc code from legacy description |
| 3046 | * @bpp: bits per pixels |
| 3047 | * @depth: bit depth per pixel |
| 3048 | * |
| 3049 | * Computes a drm fourcc pixel format code for the given @bpp/@depth values. |
| 3050 | * Useful in fbdev emulation code, since that deals in those values. |
| 3051 | */ |
Jesse Barnes | 308e5bc | 2011-11-14 14:51:28 -0800 | [diff] [blame] | 3052 | uint32_t drm_mode_legacy_fb_format(uint32_t bpp, uint32_t depth) |
| 3053 | { |
| 3054 | uint32_t fmt; |
| 3055 | |
| 3056 | switch (bpp) { |
| 3057 | case 8: |
Ville Syrjälä | d84f031 | 2013-01-31 19:43:38 +0200 | [diff] [blame] | 3058 | fmt = DRM_FORMAT_C8; |
Jesse Barnes | 308e5bc | 2011-11-14 14:51:28 -0800 | [diff] [blame] | 3059 | break; |
| 3060 | case 16: |
| 3061 | if (depth == 15) |
Ville Syrjälä | 04b3924 | 2011-11-17 18:05:13 +0200 | [diff] [blame] | 3062 | fmt = DRM_FORMAT_XRGB1555; |
Jesse Barnes | 308e5bc | 2011-11-14 14:51:28 -0800 | [diff] [blame] | 3063 | else |
Ville Syrjälä | 04b3924 | 2011-11-17 18:05:13 +0200 | [diff] [blame] | 3064 | fmt = DRM_FORMAT_RGB565; |
Jesse Barnes | 308e5bc | 2011-11-14 14:51:28 -0800 | [diff] [blame] | 3065 | break; |
| 3066 | case 24: |
Ville Syrjälä | 04b3924 | 2011-11-17 18:05:13 +0200 | [diff] [blame] | 3067 | fmt = DRM_FORMAT_RGB888; |
Jesse Barnes | 308e5bc | 2011-11-14 14:51:28 -0800 | [diff] [blame] | 3068 | break; |
| 3069 | case 32: |
| 3070 | if (depth == 24) |
Ville Syrjälä | 04b3924 | 2011-11-17 18:05:13 +0200 | [diff] [blame] | 3071 | fmt = DRM_FORMAT_XRGB8888; |
Jesse Barnes | 308e5bc | 2011-11-14 14:51:28 -0800 | [diff] [blame] | 3072 | else if (depth == 30) |
Ville Syrjälä | 04b3924 | 2011-11-17 18:05:13 +0200 | [diff] [blame] | 3073 | fmt = DRM_FORMAT_XRGB2101010; |
Jesse Barnes | 308e5bc | 2011-11-14 14:51:28 -0800 | [diff] [blame] | 3074 | else |
Ville Syrjälä | 04b3924 | 2011-11-17 18:05:13 +0200 | [diff] [blame] | 3075 | fmt = DRM_FORMAT_ARGB8888; |
Jesse Barnes | 308e5bc | 2011-11-14 14:51:28 -0800 | [diff] [blame] | 3076 | break; |
| 3077 | default: |
Ville Syrjälä | 04b3924 | 2011-11-17 18:05:13 +0200 | [diff] [blame] | 3078 | DRM_ERROR("bad bpp, assuming x8r8g8b8 pixel format\n"); |
| 3079 | fmt = DRM_FORMAT_XRGB8888; |
Jesse Barnes | 308e5bc | 2011-11-14 14:51:28 -0800 | [diff] [blame] | 3080 | break; |
| 3081 | } |
| 3082 | |
| 3083 | return fmt; |
| 3084 | } |
| 3085 | EXPORT_SYMBOL(drm_mode_legacy_fb_format); |
| 3086 | |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 3087 | /** |
| 3088 | * drm_mode_addfb - add an FB to the graphics configuration |
Daniel Vetter | 065a50ed | 2012-12-02 00:09:18 +0100 | [diff] [blame] | 3089 | * @dev: drm device for the ioctl |
| 3090 | * @data: data pointer for the ioctl |
| 3091 | * @file_priv: drm file for the ioctl call |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 3092 | * |
Daniel Vetter | c8e32cc | 2014-03-10 21:33:02 +0100 | [diff] [blame] | 3093 | * Add a new FB to the specified CRTC, given a user request. This is the |
Chuck Ebbert | 209f552 | 2014-10-08 11:37:20 -0500 | [diff] [blame] | 3094 | * original addfb ioctl which only supported RGB formats. |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 3095 | * |
| 3096 | * Called by the user via ioctl. |
| 3097 | * |
Daniel Vetter | c8e32cc | 2014-03-10 21:33:02 +0100 | [diff] [blame] | 3098 | * Returns: |
Daniel Vetter | 1a49863 | 2014-11-19 18:38:09 +0100 | [diff] [blame] | 3099 | * Zero on success, negative errno on failure. |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 3100 | */ |
| 3101 | int drm_mode_addfb(struct drm_device *dev, |
| 3102 | void *data, struct drm_file *file_priv) |
| 3103 | { |
Jesse Barnes | 308e5bc | 2011-11-14 14:51:28 -0800 | [diff] [blame] | 3104 | struct drm_mode_fb_cmd *or = data; |
| 3105 | struct drm_mode_fb_cmd2 r = {}; |
Chuck Ebbert | 228f2cb | 2014-10-08 11:40:34 -0500 | [diff] [blame] | 3106 | int ret; |
Jesse Barnes | 308e5bc | 2011-11-14 14:51:28 -0800 | [diff] [blame] | 3107 | |
Chuck Ebbert | 228f2cb | 2014-10-08 11:40:34 -0500 | [diff] [blame] | 3108 | /* convert to new format and call new ioctl */ |
Jesse Barnes | 308e5bc | 2011-11-14 14:51:28 -0800 | [diff] [blame] | 3109 | r.fb_id = or->fb_id; |
| 3110 | r.width = or->width; |
| 3111 | r.height = or->height; |
| 3112 | r.pitches[0] = or->pitch; |
| 3113 | r.pixel_format = drm_mode_legacy_fb_format(or->bpp, or->depth); |
| 3114 | r.handles[0] = or->handle; |
| 3115 | |
Chuck Ebbert | 228f2cb | 2014-10-08 11:40:34 -0500 | [diff] [blame] | 3116 | ret = drm_mode_addfb2(dev, &r, file_priv); |
| 3117 | if (ret) |
| 3118 | return ret; |
Jesse Barnes | 308e5bc | 2011-11-14 14:51:28 -0800 | [diff] [blame] | 3119 | |
Chuck Ebbert | 228f2cb | 2014-10-08 11:40:34 -0500 | [diff] [blame] | 3120 | or->fb_id = r.fb_id; |
Daniel Vetter | 4b096ac | 2012-12-10 21:19:18 +0100 | [diff] [blame] | 3121 | |
Daniel Vetter | baf698b | 2014-11-12 11:59:47 +0100 | [diff] [blame] | 3122 | return 0; |
Jesse Barnes | 308e5bc | 2011-11-14 14:51:28 -0800 | [diff] [blame] | 3123 | } |
| 3124 | |
Ville Syrjälä | cff91b6 | 2012-05-24 20:54:00 +0300 | [diff] [blame] | 3125 | static int format_check(const struct drm_mode_fb_cmd2 *r) |
Ville Syrjälä | 935b597 | 2011-12-20 00:06:48 +0200 | [diff] [blame] | 3126 | { |
| 3127 | uint32_t format = r->pixel_format & ~DRM_FORMAT_BIG_ENDIAN; |
| 3128 | |
| 3129 | switch (format) { |
| 3130 | case DRM_FORMAT_C8: |
| 3131 | case DRM_FORMAT_RGB332: |
| 3132 | case DRM_FORMAT_BGR233: |
| 3133 | case DRM_FORMAT_XRGB4444: |
| 3134 | case DRM_FORMAT_XBGR4444: |
| 3135 | case DRM_FORMAT_RGBX4444: |
| 3136 | case DRM_FORMAT_BGRX4444: |
| 3137 | case DRM_FORMAT_ARGB4444: |
| 3138 | case DRM_FORMAT_ABGR4444: |
| 3139 | case DRM_FORMAT_RGBA4444: |
| 3140 | case DRM_FORMAT_BGRA4444: |
| 3141 | case DRM_FORMAT_XRGB1555: |
| 3142 | case DRM_FORMAT_XBGR1555: |
| 3143 | case DRM_FORMAT_RGBX5551: |
| 3144 | case DRM_FORMAT_BGRX5551: |
| 3145 | case DRM_FORMAT_ARGB1555: |
| 3146 | case DRM_FORMAT_ABGR1555: |
| 3147 | case DRM_FORMAT_RGBA5551: |
| 3148 | case DRM_FORMAT_BGRA5551: |
| 3149 | case DRM_FORMAT_RGB565: |
| 3150 | case DRM_FORMAT_BGR565: |
| 3151 | case DRM_FORMAT_RGB888: |
| 3152 | case DRM_FORMAT_BGR888: |
| 3153 | case DRM_FORMAT_XRGB8888: |
| 3154 | case DRM_FORMAT_XBGR8888: |
| 3155 | case DRM_FORMAT_RGBX8888: |
| 3156 | case DRM_FORMAT_BGRX8888: |
| 3157 | case DRM_FORMAT_ARGB8888: |
| 3158 | case DRM_FORMAT_ABGR8888: |
| 3159 | case DRM_FORMAT_RGBA8888: |
| 3160 | case DRM_FORMAT_BGRA8888: |
| 3161 | case DRM_FORMAT_XRGB2101010: |
| 3162 | case DRM_FORMAT_XBGR2101010: |
| 3163 | case DRM_FORMAT_RGBX1010102: |
| 3164 | case DRM_FORMAT_BGRX1010102: |
| 3165 | case DRM_FORMAT_ARGB2101010: |
| 3166 | case DRM_FORMAT_ABGR2101010: |
| 3167 | case DRM_FORMAT_RGBA1010102: |
| 3168 | case DRM_FORMAT_BGRA1010102: |
| 3169 | case DRM_FORMAT_YUYV: |
| 3170 | case DRM_FORMAT_YVYU: |
| 3171 | case DRM_FORMAT_UYVY: |
| 3172 | case DRM_FORMAT_VYUY: |
| 3173 | case DRM_FORMAT_AYUV: |
| 3174 | case DRM_FORMAT_NV12: |
| 3175 | case DRM_FORMAT_NV21: |
| 3176 | case DRM_FORMAT_NV16: |
| 3177 | case DRM_FORMAT_NV61: |
Laurent Pinchart | ba623f6 | 2012-05-18 23:47:40 +0200 | [diff] [blame] | 3178 | case DRM_FORMAT_NV24: |
| 3179 | case DRM_FORMAT_NV42: |
Ville Syrjälä | 935b597 | 2011-12-20 00:06:48 +0200 | [diff] [blame] | 3180 | case DRM_FORMAT_YUV410: |
| 3181 | case DRM_FORMAT_YVU410: |
| 3182 | case DRM_FORMAT_YUV411: |
| 3183 | case DRM_FORMAT_YVU411: |
| 3184 | case DRM_FORMAT_YUV420: |
| 3185 | case DRM_FORMAT_YVU420: |
| 3186 | case DRM_FORMAT_YUV422: |
| 3187 | case DRM_FORMAT_YVU422: |
| 3188 | case DRM_FORMAT_YUV444: |
| 3189 | case DRM_FORMAT_YVU444: |
| 3190 | return 0; |
| 3191 | default: |
Ville Syrjälä | 23c453a | 2013-10-15 21:06:51 +0300 | [diff] [blame] | 3192 | DRM_DEBUG_KMS("invalid pixel format %s\n", |
| 3193 | drm_get_format_name(r->pixel_format)); |
Ville Syrjälä | 935b597 | 2011-12-20 00:06:48 +0200 | [diff] [blame] | 3194 | return -EINVAL; |
| 3195 | } |
| 3196 | } |
| 3197 | |
Ville Syrjälä | cff91b6 | 2012-05-24 20:54:00 +0300 | [diff] [blame] | 3198 | static int framebuffer_check(const struct drm_mode_fb_cmd2 *r) |
Ville Syrjälä | d1b45d5 | 2012-04-05 21:35:18 +0300 | [diff] [blame] | 3199 | { |
| 3200 | int ret, hsub, vsub, num_planes, i; |
| 3201 | |
| 3202 | ret = format_check(r); |
| 3203 | if (ret) { |
Ville Syrjälä | 6ba6d03 | 2013-06-10 11:15:10 +0300 | [diff] [blame] | 3204 | DRM_DEBUG_KMS("bad framebuffer format %s\n", |
| 3205 | drm_get_format_name(r->pixel_format)); |
Ville Syrjälä | d1b45d5 | 2012-04-05 21:35:18 +0300 | [diff] [blame] | 3206 | return ret; |
| 3207 | } |
| 3208 | |
| 3209 | hsub = drm_format_horz_chroma_subsampling(r->pixel_format); |
| 3210 | vsub = drm_format_vert_chroma_subsampling(r->pixel_format); |
| 3211 | num_planes = drm_format_num_planes(r->pixel_format); |
| 3212 | |
| 3213 | if (r->width == 0 || r->width % hsub) { |
Chuck Ebbert | 209f552 | 2014-10-08 11:37:20 -0500 | [diff] [blame] | 3214 | DRM_DEBUG_KMS("bad framebuffer width %u\n", r->width); |
Ville Syrjälä | d1b45d5 | 2012-04-05 21:35:18 +0300 | [diff] [blame] | 3215 | return -EINVAL; |
| 3216 | } |
| 3217 | |
| 3218 | if (r->height == 0 || r->height % vsub) { |
Dave Airlie | 1aa1b11 | 2012-05-01 17:38:35 +0100 | [diff] [blame] | 3219 | DRM_DEBUG_KMS("bad framebuffer height %u\n", r->height); |
Ville Syrjälä | d1b45d5 | 2012-04-05 21:35:18 +0300 | [diff] [blame] | 3220 | return -EINVAL; |
| 3221 | } |
| 3222 | |
| 3223 | for (i = 0; i < num_planes; i++) { |
| 3224 | unsigned int width = r->width / (i != 0 ? hsub : 1); |
Ville Syrjälä | b180b5d | 2012-10-25 18:05:04 +0000 | [diff] [blame] | 3225 | unsigned int height = r->height / (i != 0 ? vsub : 1); |
| 3226 | unsigned int cpp = drm_format_plane_cpp(r->pixel_format, i); |
Ville Syrjälä | d1b45d5 | 2012-04-05 21:35:18 +0300 | [diff] [blame] | 3227 | |
| 3228 | if (!r->handles[i]) { |
Dave Airlie | 1aa1b11 | 2012-05-01 17:38:35 +0100 | [diff] [blame] | 3229 | 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] | 3230 | return -EINVAL; |
| 3231 | } |
| 3232 | |
Ville Syrjälä | b180b5d | 2012-10-25 18:05:04 +0000 | [diff] [blame] | 3233 | if ((uint64_t) width * cpp > UINT_MAX) |
| 3234 | return -ERANGE; |
| 3235 | |
| 3236 | if ((uint64_t) height * r->pitches[i] + r->offsets[i] > UINT_MAX) |
| 3237 | return -ERANGE; |
| 3238 | |
| 3239 | if (r->pitches[i] < width * cpp) { |
Dave Airlie | 1aa1b11 | 2012-05-01 17:38:35 +0100 | [diff] [blame] | 3240 | 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] | 3241 | return -EINVAL; |
| 3242 | } |
Rob Clark | e3eb325 | 2015-02-05 14:41:52 +0000 | [diff] [blame] | 3243 | |
| 3244 | if (r->modifier[i] && !(r->flags & DRM_MODE_FB_MODIFIERS)) { |
| 3245 | DRM_DEBUG_KMS("bad fb modifier %llu for plane %d\n", |
| 3246 | r->modifier[i], i); |
| 3247 | return -EINVAL; |
| 3248 | } |
Rob Clark | 570655b | 2015-01-30 20:18:11 +0530 | [diff] [blame] | 3249 | |
| 3250 | /* modifier specific checks: */ |
| 3251 | switch (r->modifier[i]) { |
| 3252 | case DRM_FORMAT_MOD_SAMSUNG_64_32_TILE: |
| 3253 | /* NOTE: the pitch restriction may be lifted later if it turns |
| 3254 | * out that no hw has this restriction: |
| 3255 | */ |
| 3256 | if (r->pixel_format != DRM_FORMAT_NV12 || |
| 3257 | width % 128 || height % 32 || |
| 3258 | r->pitches[i] % 128) { |
| 3259 | DRM_DEBUG_KMS("bad modifier data for plane %d\n", i); |
| 3260 | return -EINVAL; |
| 3261 | } |
| 3262 | break; |
| 3263 | |
| 3264 | default: |
| 3265 | break; |
| 3266 | } |
Ville Syrjälä | d1b45d5 | 2012-04-05 21:35:18 +0300 | [diff] [blame] | 3267 | } |
| 3268 | |
Daniel Vetter | bbe16a4 | 2015-05-20 16:53:53 +0200 | [diff] [blame] | 3269 | for (i = num_planes; i < 4; i++) { |
| 3270 | if (r->modifier[i]) { |
| 3271 | DRM_DEBUG_KMS("non-zero modifier for unused plane %d\n", i); |
| 3272 | return -EINVAL; |
| 3273 | } |
| 3274 | |
| 3275 | /* Pre-FB_MODIFIERS userspace didn't clear the structs properly. */ |
| 3276 | if (!(r->flags & DRM_MODE_FB_MODIFIERS)) |
| 3277 | continue; |
| 3278 | |
| 3279 | if (r->handles[i]) { |
| 3280 | DRM_DEBUG_KMS("buffer object handle for unused plane %d\n", i); |
| 3281 | return -EINVAL; |
| 3282 | } |
| 3283 | |
| 3284 | if (r->pitches[i]) { |
| 3285 | DRM_DEBUG_KMS("non-zero pitch for unused plane %d\n", i); |
| 3286 | return -EINVAL; |
| 3287 | } |
| 3288 | |
| 3289 | if (r->offsets[i]) { |
| 3290 | DRM_DEBUG_KMS("non-zero offset for unused plane %d\n", i); |
| 3291 | return -EINVAL; |
| 3292 | } |
| 3293 | } |
| 3294 | |
Ville Syrjälä | d1b45d5 | 2012-04-05 21:35:18 +0300 | [diff] [blame] | 3295 | return 0; |
| 3296 | } |
| 3297 | |
Chris Wilson | 9a6f513 | 2015-02-25 13:45:26 +0000 | [diff] [blame] | 3298 | static struct drm_framebuffer * |
| 3299 | internal_framebuffer_create(struct drm_device *dev, |
Ville Syrjälä | 1eb83451 | 2015-11-11 19:11:29 +0200 | [diff] [blame] | 3300 | const struct drm_mode_fb_cmd2 *r, |
Chris Wilson | 9a6f513 | 2015-02-25 13:45:26 +0000 | [diff] [blame] | 3301 | struct drm_file *file_priv) |
Matt Roper | c394c2b | 2014-06-10 08:28:08 -0700 | [diff] [blame] | 3302 | { |
| 3303 | struct drm_mode_config *config = &dev->mode_config; |
| 3304 | struct drm_framebuffer *fb; |
| 3305 | int ret; |
| 3306 | |
Rob Clark | e3eb325 | 2015-02-05 14:41:52 +0000 | [diff] [blame] | 3307 | if (r->flags & ~(DRM_MODE_FB_INTERLACED | DRM_MODE_FB_MODIFIERS)) { |
Matt Roper | c394c2b | 2014-06-10 08:28:08 -0700 | [diff] [blame] | 3308 | DRM_DEBUG_KMS("bad framebuffer flags 0x%08x\n", r->flags); |
| 3309 | return ERR_PTR(-EINVAL); |
| 3310 | } |
| 3311 | |
| 3312 | if ((config->min_width > r->width) || (r->width > config->max_width)) { |
| 3313 | DRM_DEBUG_KMS("bad framebuffer width %d, should be >= %d && <= %d\n", |
| 3314 | r->width, config->min_width, config->max_width); |
| 3315 | return ERR_PTR(-EINVAL); |
| 3316 | } |
| 3317 | if ((config->min_height > r->height) || (r->height > config->max_height)) { |
| 3318 | DRM_DEBUG_KMS("bad framebuffer height %d, should be >= %d && <= %d\n", |
| 3319 | r->height, config->min_height, config->max_height); |
| 3320 | return ERR_PTR(-EINVAL); |
| 3321 | } |
| 3322 | |
Rob Clark | e3eb325 | 2015-02-05 14:41:52 +0000 | [diff] [blame] | 3323 | if (r->flags & DRM_MODE_FB_MODIFIERS && |
| 3324 | !dev->mode_config.allow_fb_modifiers) { |
| 3325 | DRM_DEBUG_KMS("driver does not support fb modifiers\n"); |
| 3326 | return ERR_PTR(-EINVAL); |
| 3327 | } |
| 3328 | |
Matt Roper | c394c2b | 2014-06-10 08:28:08 -0700 | [diff] [blame] | 3329 | ret = framebuffer_check(r); |
| 3330 | if (ret) |
| 3331 | return ERR_PTR(ret); |
| 3332 | |
| 3333 | fb = dev->mode_config.funcs->fb_create(dev, file_priv, r); |
| 3334 | if (IS_ERR(fb)) { |
| 3335 | DRM_DEBUG_KMS("could not create framebuffer\n"); |
| 3336 | return fb; |
| 3337 | } |
| 3338 | |
Matt Roper | c394c2b | 2014-06-10 08:28:08 -0700 | [diff] [blame] | 3339 | return fb; |
| 3340 | } |
| 3341 | |
Jesse Barnes | 308e5bc | 2011-11-14 14:51:28 -0800 | [diff] [blame] | 3342 | /** |
| 3343 | * drm_mode_addfb2 - add an FB to the graphics configuration |
Daniel Vetter | 065a50ed | 2012-12-02 00:09:18 +0100 | [diff] [blame] | 3344 | * @dev: drm device for the ioctl |
| 3345 | * @data: data pointer for the ioctl |
| 3346 | * @file_priv: drm file for the ioctl call |
Jesse Barnes | 308e5bc | 2011-11-14 14:51:28 -0800 | [diff] [blame] | 3347 | * |
Daniel Vetter | c8e32cc | 2014-03-10 21:33:02 +0100 | [diff] [blame] | 3348 | * Add a new FB to the specified CRTC, given a user request with format. This is |
| 3349 | * the 2nd version of the addfb ioctl, which supports multi-planar framebuffers |
| 3350 | * and uses fourcc codes as pixel format specifiers. |
Jesse Barnes | 308e5bc | 2011-11-14 14:51:28 -0800 | [diff] [blame] | 3351 | * |
| 3352 | * Called by the user via ioctl. |
| 3353 | * |
Daniel Vetter | c8e32cc | 2014-03-10 21:33:02 +0100 | [diff] [blame] | 3354 | * Returns: |
Daniel Vetter | 1a49863 | 2014-11-19 18:38:09 +0100 | [diff] [blame] | 3355 | * Zero on success, negative errno on failure. |
Jesse Barnes | 308e5bc | 2011-11-14 14:51:28 -0800 | [diff] [blame] | 3356 | */ |
| 3357 | int drm_mode_addfb2(struct drm_device *dev, |
| 3358 | void *data, struct drm_file *file_priv) |
| 3359 | { |
Chris Wilson | 9a6f513 | 2015-02-25 13:45:26 +0000 | [diff] [blame] | 3360 | struct drm_mode_fb_cmd2 *r = data; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 3361 | struct drm_framebuffer *fb; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 3362 | |
Dave Airlie | fb3b06c | 2011-02-08 13:55:21 +1000 | [diff] [blame] | 3363 | if (!drm_core_check_feature(dev, DRIVER_MODESET)) |
| 3364 | return -EINVAL; |
| 3365 | |
Chris Wilson | 9a6f513 | 2015-02-25 13:45:26 +0000 | [diff] [blame] | 3366 | fb = internal_framebuffer_create(dev, r, file_priv); |
Matt Roper | c394c2b | 2014-06-10 08:28:08 -0700 | [diff] [blame] | 3367 | if (IS_ERR(fb)) |
Daniel Vetter | 4b096ac | 2012-12-10 21:19:18 +0100 | [diff] [blame] | 3368 | return PTR_ERR(fb); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 3369 | |
Chris Wilson | 9a6f513 | 2015-02-25 13:45:26 +0000 | [diff] [blame] | 3370 | DRM_DEBUG_KMS("[FB:%d]\n", fb->base.id); |
Chris Wilson | 9a6f513 | 2015-02-25 13:45:26 +0000 | [diff] [blame] | 3371 | r->fb_id = fb->base.id; |
Dave Airlie | c7e1c59 | 2016-04-15 15:10:39 +1000 | [diff] [blame] | 3372 | |
| 3373 | /* Transfer ownership to the filp for reaping on close */ |
| 3374 | mutex_lock(&file_priv->fbs_lock); |
Chris Wilson | 9a6f513 | 2015-02-25 13:45:26 +0000 | [diff] [blame] | 3375 | list_add(&fb->filp_head, &file_priv->fbs); |
| 3376 | mutex_unlock(&file_priv->fbs_lock); |
| 3377 | |
Matt Roper | c394c2b | 2014-06-10 08:28:08 -0700 | [diff] [blame] | 3378 | return 0; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 3379 | } |
| 3380 | |
Maarten Lankhorst | f2d580b | 2016-05-04 14:38:26 +0200 | [diff] [blame] | 3381 | struct drm_mode_rmfb_work { |
| 3382 | struct work_struct work; |
| 3383 | struct list_head fbs; |
| 3384 | }; |
| 3385 | |
| 3386 | static void drm_mode_rmfb_work_fn(struct work_struct *w) |
| 3387 | { |
| 3388 | struct drm_mode_rmfb_work *arg = container_of(w, typeof(*arg), work); |
| 3389 | |
| 3390 | while (!list_empty(&arg->fbs)) { |
| 3391 | struct drm_framebuffer *fb = |
| 3392 | list_first_entry(&arg->fbs, typeof(*fb), filp_head); |
| 3393 | |
| 3394 | list_del_init(&fb->filp_head); |
| 3395 | drm_framebuffer_remove(fb); |
| 3396 | } |
| 3397 | } |
| 3398 | |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 3399 | /** |
| 3400 | * drm_mode_rmfb - remove an FB from the configuration |
Daniel Vetter | 065a50ed | 2012-12-02 00:09:18 +0100 | [diff] [blame] | 3401 | * @dev: drm device for the ioctl |
| 3402 | * @data: data pointer for the ioctl |
| 3403 | * @file_priv: drm file for the ioctl call |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 3404 | * |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 3405 | * Remove the FB specified by the user. |
| 3406 | * |
| 3407 | * Called by the user via ioctl. |
| 3408 | * |
Daniel Vetter | c8e32cc | 2014-03-10 21:33:02 +0100 | [diff] [blame] | 3409 | * Returns: |
Daniel Vetter | 1a49863 | 2014-11-19 18:38:09 +0100 | [diff] [blame] | 3410 | * Zero on success, negative errno on failure. |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 3411 | */ |
| 3412 | int drm_mode_rmfb(struct drm_device *dev, |
| 3413 | void *data, struct drm_file *file_priv) |
| 3414 | { |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 3415 | struct drm_framebuffer *fb = NULL; |
| 3416 | struct drm_framebuffer *fbl = NULL; |
| 3417 | uint32_t *id = data; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 3418 | int found = 0; |
| 3419 | |
Dave Airlie | fb3b06c | 2011-02-08 13:55:21 +1000 | [diff] [blame] | 3420 | if (!drm_core_check_feature(dev, DRIVER_MODESET)) |
| 3421 | return -EINVAL; |
| 3422 | |
Dave Airlie | 72fe90b | 2016-04-15 15:10:40 +1000 | [diff] [blame] | 3423 | fb = drm_framebuffer_lookup(dev, *id); |
| 3424 | if (!fb) |
| 3425 | return -ENOENT; |
| 3426 | |
Daniel Vetter | 4b096ac | 2012-12-10 21:19:18 +0100 | [diff] [blame] | 3427 | mutex_lock(&file_priv->fbs_lock); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 3428 | list_for_each_entry(fbl, &file_priv->fbs, filp_head) |
| 3429 | if (fb == fbl) |
| 3430 | found = 1; |
Dave Airlie | 72fe90b | 2016-04-15 15:10:40 +1000 | [diff] [blame] | 3431 | if (!found) { |
| 3432 | mutex_unlock(&file_priv->fbs_lock); |
| 3433 | goto fail_unref; |
| 3434 | } |
Daniel Vetter | 2b677e8 | 2012-12-10 21:16:05 +0100 | [diff] [blame] | 3435 | |
Daniel Vetter | 4b096ac | 2012-12-10 21:19:18 +0100 | [diff] [blame] | 3436 | list_del_init(&fb->filp_head); |
| 3437 | mutex_unlock(&file_priv->fbs_lock); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 3438 | |
Dave Airlie | 72fe90b | 2016-04-15 15:10:40 +1000 | [diff] [blame] | 3439 | /* drop the reference we picked up in framebuffer lookup */ |
Maarten Lankhorst | 1380313 | 2015-09-09 16:40:56 +0200 | [diff] [blame] | 3440 | drm_framebuffer_unreference(fb); |
Daniel Vetter | 4b096ac | 2012-12-10 21:19:18 +0100 | [diff] [blame] | 3441 | |
Maarten Lankhorst | f2d580b | 2016-05-04 14:38:26 +0200 | [diff] [blame] | 3442 | /* |
| 3443 | * we now own the reference that was stored in the fbs list |
| 3444 | * |
| 3445 | * drm_framebuffer_remove may fail with -EINTR on pending signals, |
| 3446 | * so run this in a separate stack as there's no way to correctly |
| 3447 | * handle this after the fb is already removed from the lookup table. |
| 3448 | */ |
| 3449 | if (drm_framebuffer_read_refcount(fb) > 1) { |
| 3450 | struct drm_mode_rmfb_work arg; |
| 3451 | |
| 3452 | INIT_WORK_ONSTACK(&arg.work, drm_mode_rmfb_work_fn); |
| 3453 | INIT_LIST_HEAD(&arg.fbs); |
| 3454 | list_add_tail(&fb->filp_head, &arg.fbs); |
| 3455 | |
| 3456 | schedule_work(&arg.work); |
| 3457 | flush_work(&arg.work); |
| 3458 | destroy_work_on_stack(&arg.work); |
| 3459 | } else |
| 3460 | drm_framebuffer_unreference(fb); |
| 3461 | |
Daniel Vetter | 2b677e8 | 2012-12-10 21:16:05 +0100 | [diff] [blame] | 3462 | return 0; |
| 3463 | |
Dave Airlie | 72fe90b | 2016-04-15 15:10:40 +1000 | [diff] [blame] | 3464 | fail_unref: |
| 3465 | drm_framebuffer_unreference(fb); |
Ville Syrjälä | 37c4e70 | 2013-10-17 13:35:01 +0300 | [diff] [blame] | 3466 | return -ENOENT; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 3467 | } |
| 3468 | |
| 3469 | /** |
| 3470 | * drm_mode_getfb - get FB info |
Daniel Vetter | 065a50ed | 2012-12-02 00:09:18 +0100 | [diff] [blame] | 3471 | * @dev: drm device for the ioctl |
| 3472 | * @data: data pointer for the ioctl |
| 3473 | * @file_priv: drm file for the ioctl call |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 3474 | * |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 3475 | * Lookup the FB given its ID and return info about it. |
| 3476 | * |
| 3477 | * Called by the user via ioctl. |
| 3478 | * |
Daniel Vetter | c8e32cc | 2014-03-10 21:33:02 +0100 | [diff] [blame] | 3479 | * Returns: |
Daniel Vetter | 1a49863 | 2014-11-19 18:38:09 +0100 | [diff] [blame] | 3480 | * Zero on success, negative errno on failure. |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 3481 | */ |
| 3482 | int drm_mode_getfb(struct drm_device *dev, |
| 3483 | void *data, struct drm_file *file_priv) |
| 3484 | { |
| 3485 | struct drm_mode_fb_cmd *r = data; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 3486 | struct drm_framebuffer *fb; |
Daniel Vetter | 58c0dca | 2012-12-13 23:06:08 +0100 | [diff] [blame] | 3487 | int ret; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 3488 | |
Dave Airlie | fb3b06c | 2011-02-08 13:55:21 +1000 | [diff] [blame] | 3489 | if (!drm_core_check_feature(dev, DRIVER_MODESET)) |
| 3490 | return -EINVAL; |
| 3491 | |
Daniel Vetter | 786b99e | 2012-12-02 21:53:40 +0100 | [diff] [blame] | 3492 | fb = drm_framebuffer_lookup(dev, r->fb_id); |
Daniel Vetter | 58c0dca | 2012-12-13 23:06:08 +0100 | [diff] [blame] | 3493 | if (!fb) |
Ville Syrjälä | 37c4e70 | 2013-10-17 13:35:01 +0300 | [diff] [blame] | 3494 | return -ENOENT; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 3495 | |
| 3496 | r->height = fb->height; |
| 3497 | r->width = fb->width; |
| 3498 | r->depth = fb->depth; |
| 3499 | r->bpp = fb->bits_per_pixel; |
Ville Syrjälä | 01f2c77 | 2011-12-20 00:06:49 +0200 | [diff] [blame] | 3500 | r->pitch = fb->pitches[0]; |
David Herrmann | 101b96f | 2013-08-26 15:16:49 +0200 | [diff] [blame] | 3501 | if (fb->funcs->create_handle) { |
Thomas Hellstrom | 09f308f | 2014-03-13 10:00:42 +0100 | [diff] [blame] | 3502 | if (file_priv->is_master || capable(CAP_SYS_ADMIN) || |
Thomas Hellstrom | 4368305 | 2014-03-13 11:07:44 +0100 | [diff] [blame] | 3503 | drm_is_control_client(file_priv)) { |
David Herrmann | 101b96f | 2013-08-26 15:16:49 +0200 | [diff] [blame] | 3504 | ret = fb->funcs->create_handle(fb, file_priv, |
| 3505 | &r->handle); |
| 3506 | } else { |
| 3507 | /* GET_FB() is an unprivileged ioctl so we must not |
| 3508 | * return a buffer-handle to non-master processes! For |
| 3509 | * backwards-compatibility reasons, we cannot make |
| 3510 | * GET_FB() privileged, so just return an invalid handle |
| 3511 | * for non-masters. */ |
| 3512 | r->handle = 0; |
| 3513 | ret = 0; |
| 3514 | } |
| 3515 | } else { |
Daniel Vetter | af26ef3 | 2012-12-13 23:07:50 +0100 | [diff] [blame] | 3516 | ret = -ENODEV; |
David Herrmann | 101b96f | 2013-08-26 15:16:49 +0200 | [diff] [blame] | 3517 | } |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 3518 | |
Daniel Vetter | 58c0dca | 2012-12-13 23:06:08 +0100 | [diff] [blame] | 3519 | drm_framebuffer_unreference(fb); |
| 3520 | |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 3521 | return ret; |
| 3522 | } |
| 3523 | |
Daniel Vetter | c8e32cc | 2014-03-10 21:33:02 +0100 | [diff] [blame] | 3524 | /** |
| 3525 | * drm_mode_dirtyfb_ioctl - flush frontbuffer rendering on an FB |
| 3526 | * @dev: drm device for the ioctl |
| 3527 | * @data: data pointer for the ioctl |
| 3528 | * @file_priv: drm file for the ioctl call |
| 3529 | * |
| 3530 | * Lookup the FB and flush out the damaged area supplied by userspace as a clip |
| 3531 | * rectangle list. Generic userspace which does frontbuffer rendering must call |
| 3532 | * this ioctl to flush out the changes on manual-update display outputs, e.g. |
| 3533 | * usb display-link, mipi manual update panels or edp panel self refresh modes. |
| 3534 | * |
| 3535 | * Modesetting drivers which always update the frontbuffer do not need to |
| 3536 | * implement the corresponding ->dirty framebuffer callback. |
| 3537 | * |
| 3538 | * Called by the user via ioctl. |
| 3539 | * |
| 3540 | * Returns: |
Daniel Vetter | 1a49863 | 2014-11-19 18:38:09 +0100 | [diff] [blame] | 3541 | * Zero on success, negative errno on failure. |
Daniel Vetter | c8e32cc | 2014-03-10 21:33:02 +0100 | [diff] [blame] | 3542 | */ |
Jakob Bornecrantz | 884840a | 2009-12-03 23:25:47 +0000 | [diff] [blame] | 3543 | int drm_mode_dirtyfb_ioctl(struct drm_device *dev, |
| 3544 | void *data, struct drm_file *file_priv) |
| 3545 | { |
| 3546 | struct drm_clip_rect __user *clips_ptr; |
| 3547 | struct drm_clip_rect *clips = NULL; |
| 3548 | struct drm_mode_fb_dirty_cmd *r = data; |
Jakob Bornecrantz | 884840a | 2009-12-03 23:25:47 +0000 | [diff] [blame] | 3549 | struct drm_framebuffer *fb; |
| 3550 | unsigned flags; |
| 3551 | int num_clips; |
Laurent Pinchart | 4a1b071 | 2012-05-17 13:27:21 +0200 | [diff] [blame] | 3552 | int ret; |
Jakob Bornecrantz | 884840a | 2009-12-03 23:25:47 +0000 | [diff] [blame] | 3553 | |
Dave Airlie | fb3b06c | 2011-02-08 13:55:21 +1000 | [diff] [blame] | 3554 | if (!drm_core_check_feature(dev, DRIVER_MODESET)) |
| 3555 | return -EINVAL; |
| 3556 | |
Daniel Vetter | 786b99e | 2012-12-02 21:53:40 +0100 | [diff] [blame] | 3557 | fb = drm_framebuffer_lookup(dev, r->fb_id); |
Daniel Vetter | 4ccf097 | 2012-12-11 00:38:18 +0100 | [diff] [blame] | 3558 | if (!fb) |
Ville Syrjälä | 37c4e70 | 2013-10-17 13:35:01 +0300 | [diff] [blame] | 3559 | return -ENOENT; |
Jakob Bornecrantz | 884840a | 2009-12-03 23:25:47 +0000 | [diff] [blame] | 3560 | |
| 3561 | num_clips = r->num_clips; |
Ville Syrjälä | 81f6c7f | 2011-12-20 00:06:42 +0200 | [diff] [blame] | 3562 | clips_ptr = (struct drm_clip_rect __user *)(unsigned long)r->clips_ptr; |
Jakob Bornecrantz | 884840a | 2009-12-03 23:25:47 +0000 | [diff] [blame] | 3563 | |
| 3564 | if (!num_clips != !clips_ptr) { |
| 3565 | ret = -EINVAL; |
| 3566 | goto out_err1; |
| 3567 | } |
| 3568 | |
| 3569 | flags = DRM_MODE_FB_DIRTY_FLAGS & r->flags; |
| 3570 | |
| 3571 | /* If userspace annotates copy, clips must come in pairs */ |
| 3572 | if (flags & DRM_MODE_FB_DIRTY_ANNOTATE_COPY && (num_clips % 2)) { |
| 3573 | ret = -EINVAL; |
| 3574 | goto out_err1; |
| 3575 | } |
| 3576 | |
| 3577 | if (num_clips && clips_ptr) { |
Xi Wang | a5cd335 | 2011-11-23 01:12:01 -0500 | [diff] [blame] | 3578 | if (num_clips < 0 || num_clips > DRM_MODE_FB_DIRTY_MAX_CLIPS) { |
| 3579 | ret = -EINVAL; |
| 3580 | goto out_err1; |
| 3581 | } |
Thierry Reding | bd3f0ff | 2014-12-10 13:03:35 +0100 | [diff] [blame] | 3582 | clips = kcalloc(num_clips, sizeof(*clips), GFP_KERNEL); |
Jakob Bornecrantz | 884840a | 2009-12-03 23:25:47 +0000 | [diff] [blame] | 3583 | if (!clips) { |
| 3584 | ret = -ENOMEM; |
| 3585 | goto out_err1; |
| 3586 | } |
| 3587 | |
| 3588 | ret = copy_from_user(clips, clips_ptr, |
| 3589 | num_clips * sizeof(*clips)); |
Dan Carpenter | e902a35 | 2010-06-04 12:23:21 +0200 | [diff] [blame] | 3590 | if (ret) { |
| 3591 | ret = -EFAULT; |
Jakob Bornecrantz | 884840a | 2009-12-03 23:25:47 +0000 | [diff] [blame] | 3592 | goto out_err2; |
Dan Carpenter | e902a35 | 2010-06-04 12:23:21 +0200 | [diff] [blame] | 3593 | } |
Jakob Bornecrantz | 884840a | 2009-12-03 23:25:47 +0000 | [diff] [blame] | 3594 | } |
| 3595 | |
| 3596 | if (fb->funcs->dirty) { |
Thomas Hellstrom | 02b0016 | 2010-10-05 12:43:02 +0200 | [diff] [blame] | 3597 | ret = fb->funcs->dirty(fb, file_priv, flags, r->color, |
| 3598 | clips, num_clips); |
Jakob Bornecrantz | 884840a | 2009-12-03 23:25:47 +0000 | [diff] [blame] | 3599 | } else { |
| 3600 | ret = -ENOSYS; |
Jakob Bornecrantz | 884840a | 2009-12-03 23:25:47 +0000 | [diff] [blame] | 3601 | } |
| 3602 | |
| 3603 | out_err2: |
| 3604 | kfree(clips); |
| 3605 | out_err1: |
Daniel Vetter | 4ccf097 | 2012-12-11 00:38:18 +0100 | [diff] [blame] | 3606 | drm_framebuffer_unreference(fb); |
| 3607 | |
Jakob Bornecrantz | 884840a | 2009-12-03 23:25:47 +0000 | [diff] [blame] | 3608 | return ret; |
| 3609 | } |
| 3610 | |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 3611 | /** |
| 3612 | * drm_fb_release - remove and free the FBs on this file |
Daniel Vetter | 065a50ed | 2012-12-02 00:09:18 +0100 | [diff] [blame] | 3613 | * @priv: drm file for the ioctl |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 3614 | * |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 3615 | * Destroy all the FBs associated with @filp. |
| 3616 | * |
| 3617 | * Called by the user via ioctl. |
| 3618 | * |
Daniel Vetter | c8e32cc | 2014-03-10 21:33:02 +0100 | [diff] [blame] | 3619 | * Returns: |
Daniel Vetter | 1a49863 | 2014-11-19 18:38:09 +0100 | [diff] [blame] | 3620 | * Zero on success, negative errno on failure. |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 3621 | */ |
Kristian Høgsberg | ea39f83 | 2009-02-12 14:37:56 -0500 | [diff] [blame] | 3622 | void drm_fb_release(struct drm_file *priv) |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 3623 | { |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 3624 | struct drm_framebuffer *fb, *tfb; |
Maarten Lankhorst | f2d580b | 2016-05-04 14:38:26 +0200 | [diff] [blame] | 3625 | struct drm_mode_rmfb_work arg; |
| 3626 | |
| 3627 | INIT_LIST_HEAD(&arg.fbs); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 3628 | |
Daniel Vetter | 1b11629 | 2014-09-24 21:51:06 +0200 | [diff] [blame] | 3629 | /* |
| 3630 | * When the file gets released that means no one else can access the fb |
Martin Peres | e2db726 | 2014-12-09 07:24:04 +0100 | [diff] [blame] | 3631 | * list any more, so no need to grab fpriv->fbs_lock. And we need to |
Daniel Vetter | 1b11629 | 2014-09-24 21:51:06 +0200 | [diff] [blame] | 3632 | * avoid upsetting lockdep since the universal cursor code adds a |
| 3633 | * framebuffer while holding mutex locks. |
| 3634 | * |
| 3635 | * Note that a real deadlock between fpriv->fbs_lock and the modeset |
| 3636 | * locks is impossible here since no one else but this function can get |
| 3637 | * at it any more. |
| 3638 | */ |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 3639 | list_for_each_entry_safe(fb, tfb, &priv->fbs, filp_head) { |
Maarten Lankhorst | f2d580b | 2016-05-04 14:38:26 +0200 | [diff] [blame] | 3640 | if (drm_framebuffer_read_refcount(fb) > 1) { |
| 3641 | list_move_tail(&fb->filp_head, &arg.fbs); |
| 3642 | } else { |
| 3643 | list_del_init(&fb->filp_head); |
Daniel Vetter | 2b677e8 | 2012-12-10 21:16:05 +0100 | [diff] [blame] | 3644 | |
Maarten Lankhorst | f2d580b | 2016-05-04 14:38:26 +0200 | [diff] [blame] | 3645 | /* This drops the fpriv->fbs reference. */ |
| 3646 | drm_framebuffer_unreference(fb); |
| 3647 | } |
| 3648 | } |
| 3649 | |
| 3650 | if (!list_empty(&arg.fbs)) { |
| 3651 | INIT_WORK_ONSTACK(&arg.work, drm_mode_rmfb_work_fn); |
| 3652 | |
| 3653 | schedule_work(&arg.work); |
| 3654 | flush_work(&arg.work); |
| 3655 | destroy_work_on_stack(&arg.work); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 3656 | } |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 3657 | } |
| 3658 | |
Daniel Vetter | c8e32cc | 2014-03-10 21:33:02 +0100 | [diff] [blame] | 3659 | /** |
| 3660 | * drm_property_create - create a new property type |
| 3661 | * @dev: drm device |
| 3662 | * @flags: flags specifying the property type |
| 3663 | * @name: name of the property |
| 3664 | * @num_values: number of pre-defined values |
| 3665 | * |
| 3666 | * This creates a new generic drm property which can then be attached to a drm |
| 3667 | * object with drm_object_attach_property. The returned property object must be |
| 3668 | * freed with drm_property_destroy. |
| 3669 | * |
Damien Lespiau | 3b5b993 | 2014-10-31 14:39:11 +0000 | [diff] [blame] | 3670 | * Note that the DRM core keeps a per-device list of properties and that, if |
| 3671 | * drm_mode_config_cleanup() is called, it will destroy all properties created |
| 3672 | * by the driver. |
| 3673 | * |
Daniel Vetter | c8e32cc | 2014-03-10 21:33:02 +0100 | [diff] [blame] | 3674 | * Returns: |
| 3675 | * A pointer to the newly created property on success, NULL on failure. |
| 3676 | */ |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 3677 | struct drm_property *drm_property_create(struct drm_device *dev, int flags, |
| 3678 | const char *name, int num_values) |
| 3679 | { |
| 3680 | struct drm_property *property = NULL; |
Ville Syrjälä | 6bfc56a | 2012-03-13 12:35:48 +0200 | [diff] [blame] | 3681 | int ret; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 3682 | |
| 3683 | property = kzalloc(sizeof(struct drm_property), GFP_KERNEL); |
| 3684 | if (!property) |
| 3685 | return NULL; |
| 3686 | |
Rob Clark | 98f75de | 2014-05-30 11:37:03 -0400 | [diff] [blame] | 3687 | property->dev = dev; |
| 3688 | |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 3689 | if (num_values) { |
Thierry Reding | bd3f0ff | 2014-12-10 13:03:35 +0100 | [diff] [blame] | 3690 | property->values = kcalloc(num_values, sizeof(uint64_t), |
| 3691 | GFP_KERNEL); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 3692 | if (!property->values) |
| 3693 | goto fail; |
| 3694 | } |
| 3695 | |
Ville Syrjälä | 6bfc56a | 2012-03-13 12:35:48 +0200 | [diff] [blame] | 3696 | ret = drm_mode_object_get(dev, &property->base, DRM_MODE_OBJECT_PROPERTY); |
| 3697 | if (ret) |
| 3698 | goto fail; |
| 3699 | |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 3700 | property->flags = flags; |
| 3701 | property->num_values = num_values; |
Daniel Vetter | 3758b34 | 2014-11-19 18:38:10 +0100 | [diff] [blame] | 3702 | INIT_LIST_HEAD(&property->enum_list); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 3703 | |
Vinson Lee | 471dd2e | 2011-11-10 11:55:40 -0800 | [diff] [blame] | 3704 | if (name) { |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 3705 | strncpy(property->name, name, DRM_PROP_NAME_LEN); |
Vinson Lee | 471dd2e | 2011-11-10 11:55:40 -0800 | [diff] [blame] | 3706 | property->name[DRM_PROP_NAME_LEN-1] = '\0'; |
| 3707 | } |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 3708 | |
| 3709 | list_add_tail(&property->head, &dev->mode_config.property_list); |
Rob Clark | 5ea22f2 | 2014-05-30 11:34:01 -0400 | [diff] [blame] | 3710 | |
| 3711 | WARN_ON(!drm_property_type_valid(property)); |
| 3712 | |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 3713 | return property; |
| 3714 | fail: |
Ville Syrjälä | 6bfc56a | 2012-03-13 12:35:48 +0200 | [diff] [blame] | 3715 | kfree(property->values); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 3716 | kfree(property); |
| 3717 | return NULL; |
| 3718 | } |
| 3719 | EXPORT_SYMBOL(drm_property_create); |
| 3720 | |
Daniel Vetter | c8e32cc | 2014-03-10 21:33:02 +0100 | [diff] [blame] | 3721 | /** |
Thierry Reding | 2aa9d2b | 2014-06-26 21:37:20 +0200 | [diff] [blame] | 3722 | * drm_property_create_enum - create a new enumeration property type |
Daniel Vetter | c8e32cc | 2014-03-10 21:33:02 +0100 | [diff] [blame] | 3723 | * @dev: drm device |
| 3724 | * @flags: flags specifying the property type |
| 3725 | * @name: name of the property |
| 3726 | * @props: enumeration lists with property values |
| 3727 | * @num_values: number of pre-defined values |
| 3728 | * |
| 3729 | * This creates a new generic drm property which can then be attached to a drm |
| 3730 | * object with drm_object_attach_property. The returned property object must be |
| 3731 | * freed with drm_property_destroy. |
| 3732 | * |
| 3733 | * Userspace is only allowed to set one of the predefined values for enumeration |
| 3734 | * properties. |
| 3735 | * |
| 3736 | * Returns: |
| 3737 | * A pointer to the newly created property on success, NULL on failure. |
| 3738 | */ |
Sascha Hauer | 4a67d39 | 2012-02-06 10:58:17 +0100 | [diff] [blame] | 3739 | struct drm_property *drm_property_create_enum(struct drm_device *dev, int flags, |
| 3740 | const char *name, |
| 3741 | const struct drm_prop_enum_list *props, |
| 3742 | int num_values) |
| 3743 | { |
| 3744 | struct drm_property *property; |
| 3745 | int i, ret; |
| 3746 | |
| 3747 | flags |= DRM_MODE_PROP_ENUM; |
| 3748 | |
| 3749 | property = drm_property_create(dev, flags, name, num_values); |
| 3750 | if (!property) |
| 3751 | return NULL; |
| 3752 | |
| 3753 | for (i = 0; i < num_values; i++) { |
| 3754 | ret = drm_property_add_enum(property, i, |
| 3755 | props[i].type, |
| 3756 | props[i].name); |
| 3757 | if (ret) { |
| 3758 | drm_property_destroy(dev, property); |
| 3759 | return NULL; |
| 3760 | } |
| 3761 | } |
| 3762 | |
| 3763 | return property; |
| 3764 | } |
| 3765 | EXPORT_SYMBOL(drm_property_create_enum); |
| 3766 | |
Daniel Vetter | c8e32cc | 2014-03-10 21:33:02 +0100 | [diff] [blame] | 3767 | /** |
Thierry Reding | 2aa9d2b | 2014-06-26 21:37:20 +0200 | [diff] [blame] | 3768 | * drm_property_create_bitmask - create a new bitmask property type |
Daniel Vetter | c8e32cc | 2014-03-10 21:33:02 +0100 | [diff] [blame] | 3769 | * @dev: drm device |
| 3770 | * @flags: flags specifying the property type |
| 3771 | * @name: name of the property |
| 3772 | * @props: enumeration lists with property bitflags |
Daniel Vetter | 295ee85 | 2014-07-30 14:23:44 +0200 | [diff] [blame] | 3773 | * @num_props: size of the @props array |
| 3774 | * @supported_bits: bitmask of all supported enumeration values |
Daniel Vetter | c8e32cc | 2014-03-10 21:33:02 +0100 | [diff] [blame] | 3775 | * |
Daniel Vetter | 295ee85 | 2014-07-30 14:23:44 +0200 | [diff] [blame] | 3776 | * This creates a new bitmask drm property which can then be attached to a drm |
Daniel Vetter | c8e32cc | 2014-03-10 21:33:02 +0100 | [diff] [blame] | 3777 | * object with drm_object_attach_property. The returned property object must be |
| 3778 | * freed with drm_property_destroy. |
| 3779 | * |
| 3780 | * Compared to plain enumeration properties userspace is allowed to set any |
| 3781 | * or'ed together combination of the predefined property bitflag values |
| 3782 | * |
| 3783 | * Returns: |
| 3784 | * A pointer to the newly created property on success, NULL on failure. |
| 3785 | */ |
Rob Clark | 49e2754 | 2012-05-17 02:23:26 -0600 | [diff] [blame] | 3786 | struct drm_property *drm_property_create_bitmask(struct drm_device *dev, |
| 3787 | int flags, const char *name, |
| 3788 | const struct drm_prop_enum_list *props, |
Ville Syrjälä | 7689ffb | 2014-07-08 10:31:52 +0530 | [diff] [blame] | 3789 | int num_props, |
| 3790 | uint64_t supported_bits) |
Rob Clark | 49e2754 | 2012-05-17 02:23:26 -0600 | [diff] [blame] | 3791 | { |
| 3792 | struct drm_property *property; |
Ville Syrjälä | 7689ffb | 2014-07-08 10:31:52 +0530 | [diff] [blame] | 3793 | int i, ret, index = 0; |
| 3794 | int num_values = hweight64(supported_bits); |
Rob Clark | 49e2754 | 2012-05-17 02:23:26 -0600 | [diff] [blame] | 3795 | |
| 3796 | flags |= DRM_MODE_PROP_BITMASK; |
| 3797 | |
| 3798 | property = drm_property_create(dev, flags, name, num_values); |
| 3799 | if (!property) |
| 3800 | return NULL; |
Ville Syrjälä | 7689ffb | 2014-07-08 10:31:52 +0530 | [diff] [blame] | 3801 | for (i = 0; i < num_props; i++) { |
| 3802 | if (!(supported_bits & (1ULL << props[i].type))) |
| 3803 | continue; |
Rob Clark | 49e2754 | 2012-05-17 02:23:26 -0600 | [diff] [blame] | 3804 | |
Ville Syrjälä | 7689ffb | 2014-07-08 10:31:52 +0530 | [diff] [blame] | 3805 | if (WARN_ON(index >= num_values)) { |
| 3806 | drm_property_destroy(dev, property); |
| 3807 | return NULL; |
| 3808 | } |
| 3809 | |
| 3810 | ret = drm_property_add_enum(property, index++, |
Rob Clark | 49e2754 | 2012-05-17 02:23:26 -0600 | [diff] [blame] | 3811 | props[i].type, |
| 3812 | props[i].name); |
| 3813 | if (ret) { |
| 3814 | drm_property_destroy(dev, property); |
| 3815 | return NULL; |
| 3816 | } |
| 3817 | } |
| 3818 | |
| 3819 | return property; |
| 3820 | } |
| 3821 | EXPORT_SYMBOL(drm_property_create_bitmask); |
| 3822 | |
Rob Clark | ebc44cf | 2012-09-12 22:22:31 -0500 | [diff] [blame] | 3823 | static struct drm_property *property_create_range(struct drm_device *dev, |
| 3824 | int flags, const char *name, |
| 3825 | uint64_t min, uint64_t max) |
| 3826 | { |
| 3827 | struct drm_property *property; |
| 3828 | |
| 3829 | property = drm_property_create(dev, flags, name, 2); |
| 3830 | if (!property) |
| 3831 | return NULL; |
| 3832 | |
| 3833 | property->values[0] = min; |
| 3834 | property->values[1] = max; |
| 3835 | |
| 3836 | return property; |
| 3837 | } |
| 3838 | |
Daniel Vetter | c8e32cc | 2014-03-10 21:33:02 +0100 | [diff] [blame] | 3839 | /** |
Daniel Vetter | 960cd9d | 2015-01-21 08:47:38 +0100 | [diff] [blame] | 3840 | * drm_property_create_range - create a new unsigned ranged property type |
Daniel Vetter | c8e32cc | 2014-03-10 21:33:02 +0100 | [diff] [blame] | 3841 | * @dev: drm device |
| 3842 | * @flags: flags specifying the property type |
| 3843 | * @name: name of the property |
| 3844 | * @min: minimum value of the property |
| 3845 | * @max: maximum value of the property |
| 3846 | * |
| 3847 | * This creates a new generic drm property which can then be attached to a drm |
| 3848 | * object with drm_object_attach_property. The returned property object must be |
| 3849 | * freed with drm_property_destroy. |
| 3850 | * |
Daniel Vetter | 960cd9d | 2015-01-21 08:47:38 +0100 | [diff] [blame] | 3851 | * Userspace is allowed to set any unsigned integer value in the (min, max) |
| 3852 | * range inclusive. |
Daniel Vetter | c8e32cc | 2014-03-10 21:33:02 +0100 | [diff] [blame] | 3853 | * |
| 3854 | * Returns: |
| 3855 | * A pointer to the newly created property on success, NULL on failure. |
| 3856 | */ |
Sascha Hauer | d9bc3c0 | 2012-02-06 10:58:18 +0100 | [diff] [blame] | 3857 | struct drm_property *drm_property_create_range(struct drm_device *dev, int flags, |
| 3858 | const char *name, |
| 3859 | uint64_t min, uint64_t max) |
| 3860 | { |
Rob Clark | ebc44cf | 2012-09-12 22:22:31 -0500 | [diff] [blame] | 3861 | return property_create_range(dev, DRM_MODE_PROP_RANGE | flags, |
| 3862 | name, min, max); |
Sascha Hauer | d9bc3c0 | 2012-02-06 10:58:18 +0100 | [diff] [blame] | 3863 | } |
| 3864 | EXPORT_SYMBOL(drm_property_create_range); |
| 3865 | |
Daniel Vetter | 960cd9d | 2015-01-21 08:47:38 +0100 | [diff] [blame] | 3866 | /** |
| 3867 | * drm_property_create_signed_range - create a new signed ranged property type |
| 3868 | * @dev: drm device |
| 3869 | * @flags: flags specifying the property type |
| 3870 | * @name: name of the property |
| 3871 | * @min: minimum value of the property |
| 3872 | * @max: maximum value of the property |
| 3873 | * |
| 3874 | * This creates a new generic drm property which can then be attached to a drm |
| 3875 | * object with drm_object_attach_property. The returned property object must be |
| 3876 | * freed with drm_property_destroy. |
| 3877 | * |
| 3878 | * Userspace is allowed to set any signed integer value in the (min, max) |
| 3879 | * range inclusive. |
| 3880 | * |
| 3881 | * Returns: |
| 3882 | * A pointer to the newly created property on success, NULL on failure. |
| 3883 | */ |
Rob Clark | ebc44cf | 2012-09-12 22:22:31 -0500 | [diff] [blame] | 3884 | struct drm_property *drm_property_create_signed_range(struct drm_device *dev, |
| 3885 | int flags, const char *name, |
| 3886 | int64_t min, int64_t max) |
| 3887 | { |
| 3888 | return property_create_range(dev, DRM_MODE_PROP_SIGNED_RANGE | flags, |
| 3889 | name, I642U64(min), I642U64(max)); |
| 3890 | } |
| 3891 | EXPORT_SYMBOL(drm_property_create_signed_range); |
| 3892 | |
Daniel Vetter | 960cd9d | 2015-01-21 08:47:38 +0100 | [diff] [blame] | 3893 | /** |
| 3894 | * drm_property_create_object - create a new object property type |
| 3895 | * @dev: drm device |
| 3896 | * @flags: flags specifying the property type |
| 3897 | * @name: name of the property |
| 3898 | * @type: object type from DRM_MODE_OBJECT_* defines |
| 3899 | * |
| 3900 | * This creates a new generic drm property which can then be attached to a drm |
| 3901 | * object with drm_object_attach_property. The returned property object must be |
| 3902 | * freed with drm_property_destroy. |
| 3903 | * |
| 3904 | * Userspace is only allowed to set this to any property value of the given |
| 3905 | * @type. Only useful for atomic properties, which is enforced. |
| 3906 | * |
| 3907 | * Returns: |
| 3908 | * A pointer to the newly created property on success, NULL on failure. |
| 3909 | */ |
Rob Clark | 98f75de | 2014-05-30 11:37:03 -0400 | [diff] [blame] | 3910 | struct drm_property *drm_property_create_object(struct drm_device *dev, |
| 3911 | int flags, const char *name, uint32_t type) |
| 3912 | { |
| 3913 | struct drm_property *property; |
| 3914 | |
| 3915 | flags |= DRM_MODE_PROP_OBJECT; |
| 3916 | |
Daniel Vetter | 960cd9d | 2015-01-21 08:47:38 +0100 | [diff] [blame] | 3917 | if (WARN_ON(!(flags & DRM_MODE_PROP_ATOMIC))) |
| 3918 | return NULL; |
| 3919 | |
Rob Clark | 98f75de | 2014-05-30 11:37:03 -0400 | [diff] [blame] | 3920 | property = drm_property_create(dev, flags, name, 1); |
| 3921 | if (!property) |
| 3922 | return NULL; |
| 3923 | |
| 3924 | property->values[0] = type; |
| 3925 | |
| 3926 | return property; |
| 3927 | } |
| 3928 | EXPORT_SYMBOL(drm_property_create_object); |
| 3929 | |
Daniel Vetter | c8e32cc | 2014-03-10 21:33:02 +0100 | [diff] [blame] | 3930 | /** |
Daniel Vetter | 960cd9d | 2015-01-21 08:47:38 +0100 | [diff] [blame] | 3931 | * drm_property_create_bool - create a new boolean property type |
| 3932 | * @dev: drm device |
| 3933 | * @flags: flags specifying the property type |
| 3934 | * @name: name of the property |
| 3935 | * |
| 3936 | * This creates a new generic drm property which can then be attached to a drm |
| 3937 | * object with drm_object_attach_property. The returned property object must be |
| 3938 | * freed with drm_property_destroy. |
| 3939 | * |
| 3940 | * This is implemented as a ranged property with only {0, 1} as valid values. |
| 3941 | * |
| 3942 | * Returns: |
| 3943 | * A pointer to the newly created property on success, NULL on failure. |
| 3944 | */ |
| 3945 | struct drm_property *drm_property_create_bool(struct drm_device *dev, int flags, |
| 3946 | const char *name) |
| 3947 | { |
| 3948 | return drm_property_create_range(dev, flags, name, 0, 1); |
| 3949 | } |
| 3950 | EXPORT_SYMBOL(drm_property_create_bool); |
| 3951 | |
| 3952 | /** |
Daniel Vetter | c8e32cc | 2014-03-10 21:33:02 +0100 | [diff] [blame] | 3953 | * drm_property_add_enum - add a possible value to an enumeration property |
| 3954 | * @property: enumeration property to change |
| 3955 | * @index: index of the new enumeration |
| 3956 | * @value: value of the new enumeration |
| 3957 | * @name: symbolic name of the new enumeration |
| 3958 | * |
| 3959 | * This functions adds enumerations to a property. |
| 3960 | * |
| 3961 | * It's use is deprecated, drivers should use one of the more specific helpers |
| 3962 | * to directly create the property with all enumerations already attached. |
| 3963 | * |
| 3964 | * Returns: |
| 3965 | * Zero on success, error code on failure. |
| 3966 | */ |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 3967 | int drm_property_add_enum(struct drm_property *property, int index, |
| 3968 | uint64_t value, const char *name) |
| 3969 | { |
| 3970 | struct drm_property_enum *prop_enum; |
| 3971 | |
Rob Clark | 5ea22f2 | 2014-05-30 11:34:01 -0400 | [diff] [blame] | 3972 | if (!(drm_property_type_is(property, DRM_MODE_PROP_ENUM) || |
| 3973 | drm_property_type_is(property, DRM_MODE_PROP_BITMASK))) |
Rob Clark | 49e2754 | 2012-05-17 02:23:26 -0600 | [diff] [blame] | 3974 | return -EINVAL; |
| 3975 | |
| 3976 | /* |
| 3977 | * Bitmask enum properties have the additional constraint of values |
| 3978 | * from 0 to 63 |
| 3979 | */ |
Rob Clark | 5ea22f2 | 2014-05-30 11:34:01 -0400 | [diff] [blame] | 3980 | if (drm_property_type_is(property, DRM_MODE_PROP_BITMASK) && |
| 3981 | (value > 63)) |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 3982 | return -EINVAL; |
| 3983 | |
Daniel Vetter | 3758b34 | 2014-11-19 18:38:10 +0100 | [diff] [blame] | 3984 | if (!list_empty(&property->enum_list)) { |
| 3985 | list_for_each_entry(prop_enum, &property->enum_list, head) { |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 3986 | if (prop_enum->value == value) { |
| 3987 | strncpy(prop_enum->name, name, DRM_PROP_NAME_LEN); |
| 3988 | prop_enum->name[DRM_PROP_NAME_LEN-1] = '\0'; |
| 3989 | return 0; |
| 3990 | } |
| 3991 | } |
| 3992 | } |
| 3993 | |
| 3994 | prop_enum = kzalloc(sizeof(struct drm_property_enum), GFP_KERNEL); |
| 3995 | if (!prop_enum) |
| 3996 | return -ENOMEM; |
| 3997 | |
| 3998 | strncpy(prop_enum->name, name, DRM_PROP_NAME_LEN); |
| 3999 | prop_enum->name[DRM_PROP_NAME_LEN-1] = '\0'; |
| 4000 | prop_enum->value = value; |
| 4001 | |
| 4002 | property->values[index] = value; |
Daniel Vetter | 3758b34 | 2014-11-19 18:38:10 +0100 | [diff] [blame] | 4003 | list_add_tail(&prop_enum->head, &property->enum_list); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 4004 | return 0; |
| 4005 | } |
| 4006 | EXPORT_SYMBOL(drm_property_add_enum); |
| 4007 | |
Daniel Vetter | c8e32cc | 2014-03-10 21:33:02 +0100 | [diff] [blame] | 4008 | /** |
| 4009 | * drm_property_destroy - destroy a drm property |
| 4010 | * @dev: drm device |
| 4011 | * @property: property to destry |
| 4012 | * |
| 4013 | * This function frees a property including any attached resources like |
| 4014 | * enumeration values. |
| 4015 | */ |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 4016 | void drm_property_destroy(struct drm_device *dev, struct drm_property *property) |
| 4017 | { |
| 4018 | struct drm_property_enum *prop_enum, *pt; |
| 4019 | |
Daniel Vetter | 3758b34 | 2014-11-19 18:38:10 +0100 | [diff] [blame] | 4020 | list_for_each_entry_safe(prop_enum, pt, &property->enum_list, head) { |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 4021 | list_del(&prop_enum->head); |
| 4022 | kfree(prop_enum); |
| 4023 | } |
| 4024 | |
| 4025 | if (property->num_values) |
| 4026 | kfree(property->values); |
Dave Airlie | 7c8f6d2 | 2016-04-15 15:10:32 +1000 | [diff] [blame] | 4027 | drm_mode_object_unregister(dev, &property->base); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 4028 | list_del(&property->head); |
| 4029 | kfree(property); |
| 4030 | } |
| 4031 | EXPORT_SYMBOL(drm_property_destroy); |
| 4032 | |
Daniel Vetter | c8e32cc | 2014-03-10 21:33:02 +0100 | [diff] [blame] | 4033 | /** |
| 4034 | * drm_object_attach_property - attach a property to a modeset object |
| 4035 | * @obj: drm modeset object |
| 4036 | * @property: property to attach |
| 4037 | * @init_val: initial value of the property |
| 4038 | * |
| 4039 | * This attaches the given property to the modeset object with the given initial |
| 4040 | * value. Currently this function cannot fail since the properties are stored in |
| 4041 | * a statically sized array. |
| 4042 | */ |
Paulo Zanoni | c543188 | 2012-05-15 18:09:02 -0300 | [diff] [blame] | 4043 | void drm_object_attach_property(struct drm_mode_object *obj, |
| 4044 | struct drm_property *property, |
| 4045 | uint64_t init_val) |
| 4046 | { |
Paulo Zanoni | 7f88a9b | 2012-05-15 18:09:04 -0300 | [diff] [blame] | 4047 | int count = obj->properties->count; |
Paulo Zanoni | c543188 | 2012-05-15 18:09:02 -0300 | [diff] [blame] | 4048 | |
Paulo Zanoni | 7f88a9b | 2012-05-15 18:09:04 -0300 | [diff] [blame] | 4049 | if (count == DRM_OBJECT_MAX_PROPERTY) { |
| 4050 | WARN(1, "Failed to attach object property (type: 0x%x). Please " |
| 4051 | "increase DRM_OBJECT_MAX_PROPERTY by 1 for each time " |
| 4052 | "you see this message on the same object type.\n", |
| 4053 | obj->type); |
| 4054 | return; |
Paulo Zanoni | c543188 | 2012-05-15 18:09:02 -0300 | [diff] [blame] | 4055 | } |
| 4056 | |
Rob Clark | b17cd75 | 2014-12-16 18:05:30 -0500 | [diff] [blame] | 4057 | obj->properties->properties[count] = property; |
Paulo Zanoni | 7f88a9b | 2012-05-15 18:09:04 -0300 | [diff] [blame] | 4058 | obj->properties->values[count] = init_val; |
| 4059 | obj->properties->count++; |
Rob Clark | 88a48e2 | 2014-12-18 16:01:50 -0500 | [diff] [blame] | 4060 | if (property->flags & DRM_MODE_PROP_ATOMIC) |
| 4061 | obj->properties->atomic_count++; |
Paulo Zanoni | c543188 | 2012-05-15 18:09:02 -0300 | [diff] [blame] | 4062 | } |
| 4063 | EXPORT_SYMBOL(drm_object_attach_property); |
| 4064 | |
Daniel Vetter | c8e32cc | 2014-03-10 21:33:02 +0100 | [diff] [blame] | 4065 | /** |
| 4066 | * drm_object_property_set_value - set the value of a property |
| 4067 | * @obj: drm mode object to set property value for |
| 4068 | * @property: property to set |
| 4069 | * @val: value the property should be set to |
| 4070 | * |
| 4071 | * This functions sets a given property on a given object. This function only |
| 4072 | * changes the software state of the property, it does not call into the |
| 4073 | * driver's ->set_property callback. |
| 4074 | * |
| 4075 | * Returns: |
| 4076 | * Zero on success, error code on failure. |
| 4077 | */ |
Paulo Zanoni | c543188 | 2012-05-15 18:09:02 -0300 | [diff] [blame] | 4078 | int drm_object_property_set_value(struct drm_mode_object *obj, |
| 4079 | struct drm_property *property, uint64_t val) |
| 4080 | { |
| 4081 | int i; |
| 4082 | |
Paulo Zanoni | 7f88a9b | 2012-05-15 18:09:04 -0300 | [diff] [blame] | 4083 | for (i = 0; i < obj->properties->count; i++) { |
Rob Clark | b17cd75 | 2014-12-16 18:05:30 -0500 | [diff] [blame] | 4084 | if (obj->properties->properties[i] == property) { |
Paulo Zanoni | c543188 | 2012-05-15 18:09:02 -0300 | [diff] [blame] | 4085 | obj->properties->values[i] = val; |
| 4086 | return 0; |
| 4087 | } |
| 4088 | } |
| 4089 | |
| 4090 | return -EINVAL; |
| 4091 | } |
| 4092 | EXPORT_SYMBOL(drm_object_property_set_value); |
| 4093 | |
Daniel Vetter | c8e32cc | 2014-03-10 21:33:02 +0100 | [diff] [blame] | 4094 | /** |
| 4095 | * drm_object_property_get_value - retrieve the value of a property |
| 4096 | * @obj: drm mode object to get property value from |
| 4097 | * @property: property to retrieve |
| 4098 | * @val: storage for the property value |
| 4099 | * |
| 4100 | * This function retrieves the softare state of the given property for the given |
| 4101 | * property. Since there is no driver callback to retrieve the current property |
| 4102 | * value this might be out of sync with the hardware, depending upon the driver |
| 4103 | * and property. |
| 4104 | * |
| 4105 | * Returns: |
| 4106 | * Zero on success, error code on failure. |
| 4107 | */ |
Paulo Zanoni | c543188 | 2012-05-15 18:09:02 -0300 | [diff] [blame] | 4108 | int drm_object_property_get_value(struct drm_mode_object *obj, |
| 4109 | struct drm_property *property, uint64_t *val) |
| 4110 | { |
| 4111 | int i; |
| 4112 | |
Rob Clark | 88a48e2 | 2014-12-18 16:01:50 -0500 | [diff] [blame] | 4113 | /* read-only properties bypass atomic mechanism and still store |
| 4114 | * their value in obj->properties->values[].. mostly to avoid |
| 4115 | * having to deal w/ EDID and similar props in atomic paths: |
| 4116 | */ |
| 4117 | if (drm_core_check_feature(property->dev, DRIVER_ATOMIC) && |
| 4118 | !(property->flags & DRM_MODE_PROP_IMMUTABLE)) |
| 4119 | return drm_atomic_get_property(obj, property, val); |
| 4120 | |
Paulo Zanoni | 7f88a9b | 2012-05-15 18:09:04 -0300 | [diff] [blame] | 4121 | for (i = 0; i < obj->properties->count; i++) { |
Rob Clark | b17cd75 | 2014-12-16 18:05:30 -0500 | [diff] [blame] | 4122 | if (obj->properties->properties[i] == property) { |
Paulo Zanoni | c543188 | 2012-05-15 18:09:02 -0300 | [diff] [blame] | 4123 | *val = obj->properties->values[i]; |
| 4124 | return 0; |
| 4125 | } |
| 4126 | } |
| 4127 | |
| 4128 | return -EINVAL; |
| 4129 | } |
| 4130 | EXPORT_SYMBOL(drm_object_property_get_value); |
| 4131 | |
Daniel Vetter | c8e32cc | 2014-03-10 21:33:02 +0100 | [diff] [blame] | 4132 | /** |
Daniel Vetter | 1a49863 | 2014-11-19 18:38:09 +0100 | [diff] [blame] | 4133 | * drm_mode_getproperty_ioctl - get the property metadata |
Daniel Vetter | c8e32cc | 2014-03-10 21:33:02 +0100 | [diff] [blame] | 4134 | * @dev: DRM device |
| 4135 | * @data: ioctl data |
| 4136 | * @file_priv: DRM file info |
| 4137 | * |
Daniel Vetter | 1a49863 | 2014-11-19 18:38:09 +0100 | [diff] [blame] | 4138 | * This function retrieves the metadata for a given property, like the different |
| 4139 | * possible values for an enum property or the limits for a range property. |
| 4140 | * |
| 4141 | * Blob properties are special |
Daniel Vetter | c8e32cc | 2014-03-10 21:33:02 +0100 | [diff] [blame] | 4142 | * |
| 4143 | * Called by the user via ioctl. |
| 4144 | * |
| 4145 | * Returns: |
Daniel Vetter | 1a49863 | 2014-11-19 18:38:09 +0100 | [diff] [blame] | 4146 | * Zero on success, negative errno on failure. |
Daniel Vetter | c8e32cc | 2014-03-10 21:33:02 +0100 | [diff] [blame] | 4147 | */ |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 4148 | int drm_mode_getproperty_ioctl(struct drm_device *dev, |
| 4149 | void *data, struct drm_file *file_priv) |
| 4150 | { |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 4151 | struct drm_mode_get_property *out_resp = data; |
| 4152 | struct drm_property *property; |
| 4153 | int enum_count = 0; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 4154 | int value_count = 0; |
| 4155 | int ret = 0, i; |
| 4156 | int copied; |
| 4157 | struct drm_property_enum *prop_enum; |
| 4158 | struct drm_mode_property_enum __user *enum_ptr; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 4159 | uint64_t __user *values_ptr; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 4160 | |
Dave Airlie | fb3b06c | 2011-02-08 13:55:21 +1000 | [diff] [blame] | 4161 | if (!drm_core_check_feature(dev, DRIVER_MODESET)) |
| 4162 | return -EINVAL; |
| 4163 | |
Daniel Vetter | 8484990 | 2012-12-02 00:28:11 +0100 | [diff] [blame] | 4164 | drm_modeset_lock_all(dev); |
Rob Clark | a2b34e2 | 2013-10-05 16:36:52 -0400 | [diff] [blame] | 4165 | property = drm_property_find(dev, out_resp->prop_id); |
| 4166 | if (!property) { |
Ville Syrjälä | f27657f | 2013-10-17 13:35:00 +0300 | [diff] [blame] | 4167 | ret = -ENOENT; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 4168 | goto done; |
| 4169 | } |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 4170 | |
Rob Clark | 5ea22f2 | 2014-05-30 11:34:01 -0400 | [diff] [blame] | 4171 | if (drm_property_type_is(property, DRM_MODE_PROP_ENUM) || |
| 4172 | drm_property_type_is(property, DRM_MODE_PROP_BITMASK)) { |
Daniel Vetter | 3758b34 | 2014-11-19 18:38:10 +0100 | [diff] [blame] | 4173 | list_for_each_entry(prop_enum, &property->enum_list, head) |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 4174 | enum_count++; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 4175 | } |
| 4176 | |
| 4177 | value_count = property->num_values; |
| 4178 | |
| 4179 | strncpy(out_resp->name, property->name, DRM_PROP_NAME_LEN); |
| 4180 | out_resp->name[DRM_PROP_NAME_LEN-1] = 0; |
| 4181 | out_resp->flags = property->flags; |
| 4182 | |
| 4183 | if ((out_resp->count_values >= value_count) && value_count) { |
Ville Syrjälä | 81f6c7f | 2011-12-20 00:06:42 +0200 | [diff] [blame] | 4184 | values_ptr = (uint64_t __user *)(unsigned long)out_resp->values_ptr; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 4185 | for (i = 0; i < value_count; i++) { |
| 4186 | if (copy_to_user(values_ptr + i, &property->values[i], sizeof(uint64_t))) { |
| 4187 | ret = -EFAULT; |
| 4188 | goto done; |
| 4189 | } |
| 4190 | } |
| 4191 | } |
| 4192 | out_resp->count_values = value_count; |
| 4193 | |
Rob Clark | 5ea22f2 | 2014-05-30 11:34:01 -0400 | [diff] [blame] | 4194 | if (drm_property_type_is(property, DRM_MODE_PROP_ENUM) || |
| 4195 | drm_property_type_is(property, DRM_MODE_PROP_BITMASK)) { |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 4196 | if ((out_resp->count_enum_blobs >= enum_count) && enum_count) { |
| 4197 | copied = 0; |
Ville Syrjälä | 81f6c7f | 2011-12-20 00:06:42 +0200 | [diff] [blame] | 4198 | enum_ptr = (struct drm_mode_property_enum __user *)(unsigned long)out_resp->enum_blob_ptr; |
Daniel Vetter | 3758b34 | 2014-11-19 18:38:10 +0100 | [diff] [blame] | 4199 | list_for_each_entry(prop_enum, &property->enum_list, head) { |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 4200 | |
| 4201 | if (copy_to_user(&enum_ptr[copied].value, &prop_enum->value, sizeof(uint64_t))) { |
| 4202 | ret = -EFAULT; |
| 4203 | goto done; |
| 4204 | } |
| 4205 | |
| 4206 | if (copy_to_user(&enum_ptr[copied].name, |
| 4207 | &prop_enum->name, DRM_PROP_NAME_LEN)) { |
| 4208 | ret = -EFAULT; |
| 4209 | goto done; |
| 4210 | } |
| 4211 | copied++; |
| 4212 | } |
| 4213 | } |
| 4214 | out_resp->count_enum_blobs = enum_count; |
| 4215 | } |
| 4216 | |
Daniel Vetter | 3758b34 | 2014-11-19 18:38:10 +0100 | [diff] [blame] | 4217 | /* |
| 4218 | * NOTE: The idea seems to have been to use this to read all the blob |
| 4219 | * property values. But nothing ever added them to the corresponding |
| 4220 | * list, userspace always used the special-purpose get_blob ioctl to |
| 4221 | * read the value for a blob property. It also doesn't make a lot of |
| 4222 | * sense to return values here when everything else is just metadata for |
| 4223 | * the property itself. |
| 4224 | */ |
| 4225 | if (drm_property_type_is(property, DRM_MODE_PROP_BLOB)) |
| 4226 | out_resp->count_enum_blobs = 0; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 4227 | done: |
Daniel Vetter | 8484990 | 2012-12-02 00:28:11 +0100 | [diff] [blame] | 4228 | drm_modeset_unlock_all(dev); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 4229 | return ret; |
| 4230 | } |
| 4231 | |
Daniel Vetter | 152ef5f | 2016-04-22 22:10:30 +0200 | [diff] [blame] | 4232 | static void drm_property_free_blob(struct kref *kref) |
| 4233 | { |
| 4234 | struct drm_property_blob *blob = |
| 4235 | container_of(kref, struct drm_property_blob, base.refcount); |
| 4236 | |
| 4237 | mutex_lock(&blob->dev->mode_config.blob_lock); |
| 4238 | list_del(&blob->head_global); |
| 4239 | mutex_unlock(&blob->dev->mode_config.blob_lock); |
| 4240 | |
| 4241 | drm_mode_object_unregister(blob->dev, &blob->base); |
| 4242 | |
| 4243 | kfree(blob); |
| 4244 | } |
| 4245 | |
Daniel Stone | 99531d9 | 2015-05-22 13:34:49 +0100 | [diff] [blame] | 4246 | /** |
| 4247 | * drm_property_create_blob - Create new blob property |
| 4248 | * |
| 4249 | * Creates a new blob property for a specified DRM device, optionally |
| 4250 | * copying data. |
| 4251 | * |
| 4252 | * @dev: DRM device to create property for |
| 4253 | * @length: Length to allocate for blob data |
| 4254 | * @data: If specified, copies data into blob |
Daniel Stone | 10e8cb7 | 2015-05-22 13:34:50 +0100 | [diff] [blame] | 4255 | * |
| 4256 | * Returns: |
| 4257 | * New blob property with a single reference on success, or an ERR_PTR |
| 4258 | * value on failure. |
Daniel Stone | 99531d9 | 2015-05-22 13:34:49 +0100 | [diff] [blame] | 4259 | */ |
Daniel Stone | 6bcacf5 | 2015-04-20 19:22:55 +0100 | [diff] [blame] | 4260 | struct drm_property_blob * |
Thierry Reding | ecbbe59 | 2014-05-13 11:36:13 +0200 | [diff] [blame] | 4261 | drm_property_create_blob(struct drm_device *dev, size_t length, |
Thierry Reding | 12e6cec | 2014-05-13 11:38:36 +0200 | [diff] [blame] | 4262 | const void *data) |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 4263 | { |
| 4264 | struct drm_property_blob *blob; |
Ville Syrjälä | 6bfc56a | 2012-03-13 12:35:48 +0200 | [diff] [blame] | 4265 | int ret; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 4266 | |
Dan Carpenter | 9ac0934 | 2015-10-29 16:37:54 +0300 | [diff] [blame] | 4267 | if (!length || length > ULONG_MAX - sizeof(struct drm_property_blob)) |
Daniel Stone | 10e8cb7 | 2015-05-22 13:34:50 +0100 | [diff] [blame] | 4268 | return ERR_PTR(-EINVAL); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 4269 | |
| 4270 | blob = kzalloc(sizeof(struct drm_property_blob)+length, GFP_KERNEL); |
| 4271 | if (!blob) |
Daniel Stone | 10e8cb7 | 2015-05-22 13:34:50 +0100 | [diff] [blame] | 4272 | return ERR_PTR(-ENOMEM); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 4273 | |
Daniel Stone | e2f5d2e | 2015-05-22 13:34:51 +0100 | [diff] [blame] | 4274 | /* This must be explicitly initialised, so we can safely call list_del |
| 4275 | * on it in the removal handler, even if it isn't in a file list. */ |
| 4276 | INIT_LIST_HEAD(&blob->head_file); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 4277 | blob->length = length; |
Daniel Stone | 6bcacf5 | 2015-04-20 19:22:55 +0100 | [diff] [blame] | 4278 | blob->dev = dev; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 4279 | |
Daniel Stone | 99531d9 | 2015-05-22 13:34:49 +0100 | [diff] [blame] | 4280 | if (data) |
| 4281 | memcpy(blob->data, data, length); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 4282 | |
Daniel Vetter | 152ef5f | 2016-04-22 22:10:30 +0200 | [diff] [blame] | 4283 | ret = drm_mode_object_get_reg(dev, &blob->base, DRM_MODE_OBJECT_BLOB, |
| 4284 | true, drm_property_free_blob); |
Daniel Stone | 8fb6e7a | 2015-04-20 19:22:54 +0100 | [diff] [blame] | 4285 | if (ret) { |
| 4286 | kfree(blob); |
Daniel Stone | 10e8cb7 | 2015-05-22 13:34:50 +0100 | [diff] [blame] | 4287 | return ERR_PTR(-EINVAL); |
Daniel Stone | 8fb6e7a | 2015-04-20 19:22:54 +0100 | [diff] [blame] | 4288 | } |
| 4289 | |
Daniel Vetter | 152ef5f | 2016-04-22 22:10:30 +0200 | [diff] [blame] | 4290 | mutex_lock(&dev->mode_config.blob_lock); |
Daniel Stone | e2f5d2e | 2015-05-22 13:34:51 +0100 | [diff] [blame] | 4291 | list_add_tail(&blob->head_global, |
| 4292 | &dev->mode_config.property_blob_list); |
Daniel Stone | 8fb6e7a | 2015-04-20 19:22:54 +0100 | [diff] [blame] | 4293 | mutex_unlock(&dev->mode_config.blob_lock); |
| 4294 | |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 4295 | return blob; |
| 4296 | } |
Daniel Stone | 6bcacf5 | 2015-04-20 19:22:55 +0100 | [diff] [blame] | 4297 | EXPORT_SYMBOL(drm_property_create_blob); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 4298 | |
Daniel Stone | 6bcacf5 | 2015-04-20 19:22:55 +0100 | [diff] [blame] | 4299 | /** |
Daniel Stone | 6bcacf5 | 2015-04-20 19:22:55 +0100 | [diff] [blame] | 4300 | * drm_property_unreference_blob - Unreference a blob property |
| 4301 | * |
| 4302 | * Drop a reference on a blob property. May free the object. |
| 4303 | * |
Daniel Stone | f102c16 | 2015-05-22 13:34:44 +0100 | [diff] [blame] | 4304 | * @blob: Pointer to blob property |
Daniel Stone | 6bcacf5 | 2015-04-20 19:22:55 +0100 | [diff] [blame] | 4305 | */ |
| 4306 | void drm_property_unreference_blob(struct drm_property_blob *blob) |
| 4307 | { |
Daniel Stone | 6bcacf5 | 2015-04-20 19:22:55 +0100 | [diff] [blame] | 4308 | if (!blob) |
| 4309 | return; |
| 4310 | |
Daniel Vetter | 152ef5f | 2016-04-22 22:10:30 +0200 | [diff] [blame] | 4311 | drm_mode_object_unreference(&blob->base); |
Daniel Stone | 6bcacf5 | 2015-04-20 19:22:55 +0100 | [diff] [blame] | 4312 | } |
| 4313 | EXPORT_SYMBOL(drm_property_unreference_blob); |
| 4314 | |
| 4315 | /** |
Daniel Stone | e2f5d2e | 2015-05-22 13:34:51 +0100 | [diff] [blame] | 4316 | * drm_property_destroy_user_blobs - destroy all blobs created by this client |
| 4317 | * @dev: DRM device |
| 4318 | * @file_priv: destroy all blobs owned by this file handle |
| 4319 | */ |
| 4320 | void drm_property_destroy_user_blobs(struct drm_device *dev, |
| 4321 | struct drm_file *file_priv) |
| 4322 | { |
| 4323 | struct drm_property_blob *blob, *bt; |
| 4324 | |
Daniel Vetter | 152ef5f | 2016-04-22 22:10:30 +0200 | [diff] [blame] | 4325 | /* |
| 4326 | * When the file gets released that means no one else can access the |
| 4327 | * blob list any more, so no need to grab dev->blob_lock. |
| 4328 | */ |
Daniel Stone | e2f5d2e | 2015-05-22 13:34:51 +0100 | [diff] [blame] | 4329 | list_for_each_entry_safe(blob, bt, &file_priv->blobs, head_file) { |
| 4330 | list_del_init(&blob->head_file); |
Daniel Vetter | 152ef5f | 2016-04-22 22:10:30 +0200 | [diff] [blame] | 4331 | drm_property_unreference_blob(blob); |
Daniel Stone | e2f5d2e | 2015-05-22 13:34:51 +0100 | [diff] [blame] | 4332 | } |
Daniel Stone | e2f5d2e | 2015-05-22 13:34:51 +0100 | [diff] [blame] | 4333 | } |
| 4334 | |
| 4335 | /** |
Daniel Stone | 6bcacf5 | 2015-04-20 19:22:55 +0100 | [diff] [blame] | 4336 | * drm_property_reference_blob - Take a reference on an existing property |
| 4337 | * |
| 4338 | * Take a new reference on an existing blob property. |
| 4339 | * |
Daniel Stone | f102c16 | 2015-05-22 13:34:44 +0100 | [diff] [blame] | 4340 | * @blob: Pointer to blob property |
Daniel Stone | 6bcacf5 | 2015-04-20 19:22:55 +0100 | [diff] [blame] | 4341 | */ |
| 4342 | struct drm_property_blob *drm_property_reference_blob(struct drm_property_blob *blob) |
| 4343 | { |
Daniel Vetter | 152ef5f | 2016-04-22 22:10:30 +0200 | [diff] [blame] | 4344 | drm_mode_object_reference(&blob->base); |
Daniel Stone | 6bcacf5 | 2015-04-20 19:22:55 +0100 | [diff] [blame] | 4345 | return blob; |
| 4346 | } |
| 4347 | EXPORT_SYMBOL(drm_property_reference_blob); |
| 4348 | |
Daniel Stone | 6bcacf5 | 2015-04-20 19:22:55 +0100 | [diff] [blame] | 4349 | /** |
| 4350 | * drm_property_lookup_blob - look up a blob property and take a reference |
| 4351 | * @dev: drm device |
| 4352 | * @id: id of the blob property |
| 4353 | * |
| 4354 | * If successful, this takes an additional reference to the blob property. |
| 4355 | * callers need to make sure to eventually unreference the returned property |
| 4356 | * again, using @drm_property_unreference_blob. |
| 4357 | */ |
| 4358 | struct drm_property_blob *drm_property_lookup_blob(struct drm_device *dev, |
| 4359 | uint32_t id) |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 4360 | { |
Daniel Vetter | 152ef5f | 2016-04-22 22:10:30 +0200 | [diff] [blame] | 4361 | struct drm_mode_object *obj; |
| 4362 | struct drm_property_blob *blob = NULL; |
Daniel Stone | 6bcacf5 | 2015-04-20 19:22:55 +0100 | [diff] [blame] | 4363 | |
Daniel Vetter | 152ef5f | 2016-04-22 22:10:30 +0200 | [diff] [blame] | 4364 | obj = _object_find(dev, id, DRM_MODE_OBJECT_BLOB); |
| 4365 | if (obj) |
| 4366 | blob = obj_to_blob(obj); |
Daniel Stone | 6bcacf5 | 2015-04-20 19:22:55 +0100 | [diff] [blame] | 4367 | return blob; |
| 4368 | } |
| 4369 | EXPORT_SYMBOL(drm_property_lookup_blob); |
| 4370 | |
| 4371 | /** |
Daniel Stone | d2ed343 | 2015-04-20 19:22:53 +0100 | [diff] [blame] | 4372 | * drm_property_replace_global_blob - atomically replace existing blob property |
| 4373 | * @dev: drm device |
| 4374 | * @replace: location of blob property pointer to be replaced |
| 4375 | * @length: length of data for new blob, or 0 for no data |
| 4376 | * @data: content for new blob, or NULL for no data |
| 4377 | * @obj_holds_id: optional object for property holding blob ID |
| 4378 | * @prop_holds_id: optional property holding blob ID |
| 4379 | * @return 0 on success or error on failure |
| 4380 | * |
| 4381 | * This function will atomically replace a global property in the blob list, |
| 4382 | * optionally updating a property which holds the ID of that property. It is |
| 4383 | * guaranteed to be atomic: no caller will be allowed to see intermediate |
| 4384 | * results, and either the entire operation will succeed and clean up the |
| 4385 | * previous property, or it will fail and the state will be unchanged. |
| 4386 | * |
| 4387 | * If length is 0 or data is NULL, no new blob will be created, and the holding |
| 4388 | * property, if specified, will be set to 0. |
| 4389 | * |
| 4390 | * Access to the replace pointer is assumed to be protected by the caller, e.g. |
| 4391 | * by holding the relevant modesetting object lock for its parent. |
| 4392 | * |
| 4393 | * For example, a drm_connector has a 'PATH' property, which contains the ID |
| 4394 | * of a blob property with the value of the MST path information. Calling this |
| 4395 | * function with replace pointing to the connector's path_blob_ptr, length and |
| 4396 | * data set for the new path information, obj_holds_id set to the connector's |
| 4397 | * base object, and prop_holds_id set to the path property name, will perform |
| 4398 | * a completely atomic update. The access to path_blob_ptr is protected by the |
| 4399 | * caller holding a lock on the connector. |
| 4400 | */ |
| 4401 | static int drm_property_replace_global_blob(struct drm_device *dev, |
| 4402 | struct drm_property_blob **replace, |
| 4403 | size_t length, |
| 4404 | const void *data, |
| 4405 | struct drm_mode_object *obj_holds_id, |
| 4406 | struct drm_property *prop_holds_id) |
| 4407 | { |
| 4408 | struct drm_property_blob *new_blob = NULL; |
| 4409 | struct drm_property_blob *old_blob = NULL; |
| 4410 | int ret; |
| 4411 | |
| 4412 | WARN_ON(replace == NULL); |
| 4413 | |
| 4414 | old_blob = *replace; |
| 4415 | |
| 4416 | if (length && data) { |
| 4417 | new_blob = drm_property_create_blob(dev, length, data); |
Daniel Stone | 10e8cb7 | 2015-05-22 13:34:50 +0100 | [diff] [blame] | 4418 | if (IS_ERR(new_blob)) |
| 4419 | return PTR_ERR(new_blob); |
Daniel Stone | d2ed343 | 2015-04-20 19:22:53 +0100 | [diff] [blame] | 4420 | } |
| 4421 | |
| 4422 | /* This does not need to be synchronised with blob_lock, as the |
| 4423 | * get_properties ioctl locks all modesetting objects, and |
| 4424 | * obj_holds_id must be locked before calling here, so we cannot |
| 4425 | * have its value out of sync with the list membership modified |
| 4426 | * below under blob_lock. */ |
| 4427 | if (obj_holds_id) { |
| 4428 | ret = drm_object_property_set_value(obj_holds_id, |
| 4429 | prop_holds_id, |
| 4430 | new_blob ? |
| 4431 | new_blob->base.id : 0); |
| 4432 | if (ret != 0) |
| 4433 | goto err_created; |
| 4434 | } |
| 4435 | |
Markus Elfring | ec53082 | 2015-07-05 21:55:10 +0200 | [diff] [blame] | 4436 | drm_property_unreference_blob(old_blob); |
Daniel Stone | d2ed343 | 2015-04-20 19:22:53 +0100 | [diff] [blame] | 4437 | *replace = new_blob; |
| 4438 | |
| 4439 | return 0; |
| 4440 | |
| 4441 | err_created: |
Daniel Stone | 6bcacf5 | 2015-04-20 19:22:55 +0100 | [diff] [blame] | 4442 | drm_property_unreference_blob(new_blob); |
Daniel Stone | d2ed343 | 2015-04-20 19:22:53 +0100 | [diff] [blame] | 4443 | return ret; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 4444 | } |
| 4445 | |
Daniel Vetter | c8e32cc | 2014-03-10 21:33:02 +0100 | [diff] [blame] | 4446 | /** |
| 4447 | * drm_mode_getblob_ioctl - get the contents of a blob property value |
| 4448 | * @dev: DRM device |
| 4449 | * @data: ioctl data |
| 4450 | * @file_priv: DRM file info |
| 4451 | * |
| 4452 | * This function retrieves the contents of a blob property. The value stored in |
| 4453 | * an object's blob property is just a normal modeset object id. |
| 4454 | * |
| 4455 | * Called by the user via ioctl. |
| 4456 | * |
| 4457 | * Returns: |
Daniel Vetter | 1a49863 | 2014-11-19 18:38:09 +0100 | [diff] [blame] | 4458 | * Zero on success, negative errno on failure. |
Daniel Vetter | c8e32cc | 2014-03-10 21:33:02 +0100 | [diff] [blame] | 4459 | */ |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 4460 | int drm_mode_getblob_ioctl(struct drm_device *dev, |
| 4461 | void *data, struct drm_file *file_priv) |
| 4462 | { |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 4463 | struct drm_mode_get_blob *out_resp = data; |
| 4464 | struct drm_property_blob *blob; |
| 4465 | int ret = 0; |
Ville Syrjälä | 81f6c7f | 2011-12-20 00:06:42 +0200 | [diff] [blame] | 4466 | void __user *blob_ptr; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 4467 | |
Dave Airlie | fb3b06c | 2011-02-08 13:55:21 +1000 | [diff] [blame] | 4468 | if (!drm_core_check_feature(dev, DRIVER_MODESET)) |
| 4469 | return -EINVAL; |
| 4470 | |
Daniel Vetter | 152ef5f | 2016-04-22 22:10:30 +0200 | [diff] [blame] | 4471 | blob = drm_property_lookup_blob(dev, out_resp->blob_id); |
| 4472 | if (!blob) |
| 4473 | return -ENOENT; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 4474 | |
| 4475 | if (out_resp->length == blob->length) { |
Ville Syrjälä | 81f6c7f | 2011-12-20 00:06:42 +0200 | [diff] [blame] | 4476 | blob_ptr = (void __user *)(unsigned long)out_resp->data; |
Thierry Reding | 4dfd909 | 2014-12-10 13:03:34 +0100 | [diff] [blame] | 4477 | if (copy_to_user(blob_ptr, blob->data, blob->length)) { |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 4478 | ret = -EFAULT; |
Daniel Vetter | 152ef5f | 2016-04-22 22:10:30 +0200 | [diff] [blame] | 4479 | goto unref; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 4480 | } |
| 4481 | } |
| 4482 | out_resp->length = blob->length; |
Daniel Vetter | 152ef5f | 2016-04-22 22:10:30 +0200 | [diff] [blame] | 4483 | unref: |
| 4484 | drm_property_unreference_blob(blob); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 4485 | |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 4486 | return ret; |
| 4487 | } |
| 4488 | |
Dave Airlie | cc7096f | 2014-10-22 12:03:04 +1000 | [diff] [blame] | 4489 | /** |
Daniel Stone | e2f5d2e | 2015-05-22 13:34:51 +0100 | [diff] [blame] | 4490 | * drm_mode_createblob_ioctl - create a new blob property |
| 4491 | * @dev: DRM device |
| 4492 | * @data: ioctl data |
| 4493 | * @file_priv: DRM file info |
| 4494 | * |
| 4495 | * This function creates a new blob property with user-defined values. In order |
| 4496 | * to give us sensible validation and checking when creating, rather than at |
| 4497 | * every potential use, we also require a type to be provided upfront. |
| 4498 | * |
| 4499 | * Called by the user via ioctl. |
| 4500 | * |
| 4501 | * Returns: |
| 4502 | * Zero on success, negative errno on failure. |
| 4503 | */ |
| 4504 | int drm_mode_createblob_ioctl(struct drm_device *dev, |
| 4505 | void *data, struct drm_file *file_priv) |
| 4506 | { |
| 4507 | struct drm_mode_create_blob *out_resp = data; |
| 4508 | struct drm_property_blob *blob; |
| 4509 | void __user *blob_ptr; |
| 4510 | int ret = 0; |
| 4511 | |
| 4512 | if (!drm_core_check_feature(dev, DRIVER_MODESET)) |
| 4513 | return -EINVAL; |
| 4514 | |
| 4515 | blob = drm_property_create_blob(dev, out_resp->length, NULL); |
| 4516 | if (IS_ERR(blob)) |
| 4517 | return PTR_ERR(blob); |
| 4518 | |
| 4519 | blob_ptr = (void __user *)(unsigned long)out_resp->data; |
| 4520 | if (copy_from_user(blob->data, blob_ptr, out_resp->length)) { |
| 4521 | ret = -EFAULT; |
| 4522 | goto out_blob; |
| 4523 | } |
| 4524 | |
| 4525 | /* Dropping the lock between create_blob and our access here is safe |
| 4526 | * as only the same file_priv can remove the blob; at this point, it is |
| 4527 | * not associated with any file_priv. */ |
| 4528 | mutex_lock(&dev->mode_config.blob_lock); |
| 4529 | out_resp->blob_id = blob->base.id; |
Maneet Singh | 8731b26 | 2015-10-08 10:10:24 -0400 | [diff] [blame] | 4530 | list_add_tail(&blob->head_file, &file_priv->blobs); |
Daniel Stone | e2f5d2e | 2015-05-22 13:34:51 +0100 | [diff] [blame] | 4531 | mutex_unlock(&dev->mode_config.blob_lock); |
| 4532 | |
| 4533 | return 0; |
| 4534 | |
| 4535 | out_blob: |
| 4536 | drm_property_unreference_blob(blob); |
| 4537 | return ret; |
| 4538 | } |
| 4539 | |
| 4540 | /** |
| 4541 | * drm_mode_destroyblob_ioctl - destroy a user blob property |
| 4542 | * @dev: DRM device |
| 4543 | * @data: ioctl data |
| 4544 | * @file_priv: DRM file info |
| 4545 | * |
| 4546 | * Destroy an existing user-defined blob property. |
| 4547 | * |
| 4548 | * Called by the user via ioctl. |
| 4549 | * |
| 4550 | * Returns: |
| 4551 | * Zero on success, negative errno on failure. |
| 4552 | */ |
| 4553 | int drm_mode_destroyblob_ioctl(struct drm_device *dev, |
| 4554 | void *data, struct drm_file *file_priv) |
| 4555 | { |
| 4556 | struct drm_mode_destroy_blob *out_resp = data; |
| 4557 | struct drm_property_blob *blob = NULL, *bt; |
| 4558 | bool found = false; |
| 4559 | int ret = 0; |
| 4560 | |
| 4561 | if (!drm_core_check_feature(dev, DRIVER_MODESET)) |
| 4562 | return -EINVAL; |
| 4563 | |
Daniel Vetter | 152ef5f | 2016-04-22 22:10:30 +0200 | [diff] [blame] | 4564 | blob = drm_property_lookup_blob(dev, out_resp->blob_id); |
| 4565 | if (!blob) |
| 4566 | return -ENOENT; |
Daniel Stone | e2f5d2e | 2015-05-22 13:34:51 +0100 | [diff] [blame] | 4567 | |
Daniel Vetter | 152ef5f | 2016-04-22 22:10:30 +0200 | [diff] [blame] | 4568 | mutex_lock(&dev->mode_config.blob_lock); |
Daniel Stone | e2f5d2e | 2015-05-22 13:34:51 +0100 | [diff] [blame] | 4569 | /* Ensure the property was actually created by this user. */ |
| 4570 | list_for_each_entry(bt, &file_priv->blobs, head_file) { |
| 4571 | if (bt == blob) { |
| 4572 | found = true; |
| 4573 | break; |
| 4574 | } |
| 4575 | } |
| 4576 | |
| 4577 | if (!found) { |
| 4578 | ret = -EPERM; |
| 4579 | goto err; |
| 4580 | } |
| 4581 | |
| 4582 | /* We must drop head_file here, because we may not be the last |
| 4583 | * reference on the blob. */ |
| 4584 | list_del_init(&blob->head_file); |
Daniel Stone | e2f5d2e | 2015-05-22 13:34:51 +0100 | [diff] [blame] | 4585 | mutex_unlock(&dev->mode_config.blob_lock); |
| 4586 | |
Daniel Vetter | 152ef5f | 2016-04-22 22:10:30 +0200 | [diff] [blame] | 4587 | /* One reference from lookup, and one from the filp. */ |
| 4588 | drm_property_unreference_blob(blob); |
| 4589 | drm_property_unreference_blob(blob); |
| 4590 | |
Daniel Stone | e2f5d2e | 2015-05-22 13:34:51 +0100 | [diff] [blame] | 4591 | return 0; |
| 4592 | |
| 4593 | err: |
| 4594 | mutex_unlock(&dev->mode_config.blob_lock); |
Daniel Vetter | 152ef5f | 2016-04-22 22:10:30 +0200 | [diff] [blame] | 4595 | drm_property_unreference_blob(blob); |
| 4596 | |
Daniel Stone | e2f5d2e | 2015-05-22 13:34:51 +0100 | [diff] [blame] | 4597 | return ret; |
| 4598 | } |
| 4599 | |
| 4600 | /** |
Dave Airlie | cc7096f | 2014-10-22 12:03:04 +1000 | [diff] [blame] | 4601 | * drm_mode_connector_set_path_property - set tile property on connector |
| 4602 | * @connector: connector to set property on. |
Daniel Stone | d2ed343 | 2015-04-20 19:22:53 +0100 | [diff] [blame] | 4603 | * @path: path to use for property; must not be NULL. |
Dave Airlie | cc7096f | 2014-10-22 12:03:04 +1000 | [diff] [blame] | 4604 | * |
| 4605 | * This creates a property to expose to userspace to specify a |
| 4606 | * connector path. This is mainly used for DisplayPort MST where |
| 4607 | * connectors have a topology and we want to allow userspace to give |
| 4608 | * them more meaningful names. |
| 4609 | * |
| 4610 | * Returns: |
Daniel Vetter | 1a49863 | 2014-11-19 18:38:09 +0100 | [diff] [blame] | 4611 | * Zero on success, negative errno on failure. |
Dave Airlie | cc7096f | 2014-10-22 12:03:04 +1000 | [diff] [blame] | 4612 | */ |
Dave Airlie | 43aba7e | 2014-06-05 14:01:31 +1000 | [diff] [blame] | 4613 | int drm_mode_connector_set_path_property(struct drm_connector *connector, |
Thierry Reding | 12e6cec | 2014-05-13 11:38:36 +0200 | [diff] [blame] | 4614 | const char *path) |
Dave Airlie | 43aba7e | 2014-06-05 14:01:31 +1000 | [diff] [blame] | 4615 | { |
| 4616 | struct drm_device *dev = connector->dev; |
Thierry Reding | ecbbe59 | 2014-05-13 11:36:13 +0200 | [diff] [blame] | 4617 | int ret; |
Dave Airlie | 43aba7e | 2014-06-05 14:01:31 +1000 | [diff] [blame] | 4618 | |
Daniel Stone | d2ed343 | 2015-04-20 19:22:53 +0100 | [diff] [blame] | 4619 | ret = drm_property_replace_global_blob(dev, |
| 4620 | &connector->path_blob_ptr, |
| 4621 | strlen(path) + 1, |
| 4622 | path, |
| 4623 | &connector->base, |
| 4624 | dev->mode_config.path_property); |
Dave Airlie | 43aba7e | 2014-06-05 14:01:31 +1000 | [diff] [blame] | 4625 | return ret; |
| 4626 | } |
| 4627 | EXPORT_SYMBOL(drm_mode_connector_set_path_property); |
| 4628 | |
Daniel Vetter | c8e32cc | 2014-03-10 21:33:02 +0100 | [diff] [blame] | 4629 | /** |
Dave Airlie | 6f134d7 | 2014-10-20 16:30:50 +1000 | [diff] [blame] | 4630 | * drm_mode_connector_set_tile_property - set tile property on connector |
| 4631 | * @connector: connector to set property on. |
| 4632 | * |
| 4633 | * This looks up the tile information for a connector, and creates a |
| 4634 | * property for userspace to parse if it exists. The property is of |
| 4635 | * the form of 8 integers using ':' as a separator. |
| 4636 | * |
| 4637 | * Returns: |
| 4638 | * Zero on success, errno on failure. |
| 4639 | */ |
| 4640 | int drm_mode_connector_set_tile_property(struct drm_connector *connector) |
| 4641 | { |
| 4642 | struct drm_device *dev = connector->dev; |
Dave Airlie | 6f134d7 | 2014-10-20 16:30:50 +1000 | [diff] [blame] | 4643 | char tile[256]; |
Daniel Stone | d2ed343 | 2015-04-20 19:22:53 +0100 | [diff] [blame] | 4644 | int ret; |
Dave Airlie | 6f134d7 | 2014-10-20 16:30:50 +1000 | [diff] [blame] | 4645 | |
| 4646 | if (!connector->has_tile) { |
Daniel Stone | d2ed343 | 2015-04-20 19:22:53 +0100 | [diff] [blame] | 4647 | ret = drm_property_replace_global_blob(dev, |
| 4648 | &connector->tile_blob_ptr, |
| 4649 | 0, |
| 4650 | NULL, |
| 4651 | &connector->base, |
| 4652 | dev->mode_config.tile_property); |
Dave Airlie | 6f134d7 | 2014-10-20 16:30:50 +1000 | [diff] [blame] | 4653 | return ret; |
| 4654 | } |
| 4655 | |
| 4656 | snprintf(tile, 256, "%d:%d:%d:%d:%d:%d:%d:%d", |
| 4657 | connector->tile_group->id, connector->tile_is_single_monitor, |
| 4658 | connector->num_h_tile, connector->num_v_tile, |
| 4659 | connector->tile_h_loc, connector->tile_v_loc, |
| 4660 | connector->tile_h_size, connector->tile_v_size); |
Dave Airlie | 6f134d7 | 2014-10-20 16:30:50 +1000 | [diff] [blame] | 4661 | |
Daniel Stone | d2ed343 | 2015-04-20 19:22:53 +0100 | [diff] [blame] | 4662 | ret = drm_property_replace_global_blob(dev, |
| 4663 | &connector->tile_blob_ptr, |
| 4664 | strlen(tile) + 1, |
| 4665 | tile, |
| 4666 | &connector->base, |
| 4667 | dev->mode_config.tile_property); |
Dave Airlie | 6f134d7 | 2014-10-20 16:30:50 +1000 | [diff] [blame] | 4668 | return ret; |
| 4669 | } |
| 4670 | EXPORT_SYMBOL(drm_mode_connector_set_tile_property); |
| 4671 | |
| 4672 | /** |
Daniel Vetter | c8e32cc | 2014-03-10 21:33:02 +0100 | [diff] [blame] | 4673 | * drm_mode_connector_update_edid_property - update the edid property of a connector |
| 4674 | * @connector: drm connector |
| 4675 | * @edid: new value of the edid property |
| 4676 | * |
| 4677 | * This function creates a new blob modeset object and assigns its id to the |
| 4678 | * connector's edid property. |
| 4679 | * |
| 4680 | * Returns: |
Daniel Vetter | 1a49863 | 2014-11-19 18:38:09 +0100 | [diff] [blame] | 4681 | * Zero on success, negative errno on failure. |
Daniel Vetter | c8e32cc | 2014-03-10 21:33:02 +0100 | [diff] [blame] | 4682 | */ |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 4683 | int drm_mode_connector_update_edid_property(struct drm_connector *connector, |
Thierry Reding | 12e6cec | 2014-05-13 11:38:36 +0200 | [diff] [blame] | 4684 | const struct edid *edid) |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 4685 | { |
| 4686 | struct drm_device *dev = connector->dev; |
Daniel Stone | d2ed343 | 2015-04-20 19:22:53 +0100 | [diff] [blame] | 4687 | size_t size = 0; |
Thierry Reding | ecbbe59 | 2014-05-13 11:36:13 +0200 | [diff] [blame] | 4688 | int ret; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 4689 | |
Thomas Wood | 4cf2b28 | 2014-06-18 17:52:33 +0100 | [diff] [blame] | 4690 | /* ignore requests to set edid when overridden */ |
| 4691 | if (connector->override_edid) |
| 4692 | return 0; |
| 4693 | |
Daniel Stone | d2ed343 | 2015-04-20 19:22:53 +0100 | [diff] [blame] | 4694 | if (edid) |
Shixin Zeng | e24ff46 | 2015-07-03 08:46:50 +0200 | [diff] [blame] | 4695 | size = EDID_LENGTH * (1 + edid->extensions); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 4696 | |
Daniel Stone | d2ed343 | 2015-04-20 19:22:53 +0100 | [diff] [blame] | 4697 | ret = drm_property_replace_global_blob(dev, |
| 4698 | &connector->edid_blob_ptr, |
| 4699 | size, |
| 4700 | edid, |
| 4701 | &connector->base, |
| 4702 | dev->mode_config.edid_property); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 4703 | return ret; |
| 4704 | } |
| 4705 | EXPORT_SYMBOL(drm_mode_connector_update_edid_property); |
| 4706 | |
Rob Clark | 3843e71 | 2014-12-16 18:05:29 -0500 | [diff] [blame] | 4707 | /* Some properties could refer to dynamic refcnt'd objects, or things that |
| 4708 | * need special locking to handle lifetime issues (ie. to ensure the prop |
| 4709 | * value doesn't become invalid part way through the property update due to |
| 4710 | * race). The value returned by reference via 'obj' should be passed back |
| 4711 | * to drm_property_change_valid_put() after the property is set (and the |
| 4712 | * object to which the property is attached has a chance to take it's own |
| 4713 | * reference). |
| 4714 | */ |
Rob Clark | d34f20d | 2014-12-18 16:01:56 -0500 | [diff] [blame] | 4715 | bool drm_property_change_valid_get(struct drm_property *property, |
Rob Clark | 3843e71 | 2014-12-16 18:05:29 -0500 | [diff] [blame] | 4716 | uint64_t value, struct drm_mode_object **ref) |
Paulo Zanoni | 26a3481 | 2012-05-15 18:08:59 -0300 | [diff] [blame] | 4717 | { |
Thierry Reding | 2ca651d | 2014-12-10 13:03:39 +0100 | [diff] [blame] | 4718 | int i; |
| 4719 | |
Paulo Zanoni | 26a3481 | 2012-05-15 18:08:59 -0300 | [diff] [blame] | 4720 | if (property->flags & DRM_MODE_PROP_IMMUTABLE) |
| 4721 | return false; |
Rob Clark | 5ea22f2 | 2014-05-30 11:34:01 -0400 | [diff] [blame] | 4722 | |
Rob Clark | 3843e71 | 2014-12-16 18:05:29 -0500 | [diff] [blame] | 4723 | *ref = NULL; |
| 4724 | |
Rob Clark | 5ea22f2 | 2014-05-30 11:34:01 -0400 | [diff] [blame] | 4725 | if (drm_property_type_is(property, DRM_MODE_PROP_RANGE)) { |
Paulo Zanoni | 26a3481 | 2012-05-15 18:08:59 -0300 | [diff] [blame] | 4726 | if (value < property->values[0] || value > property->values[1]) |
| 4727 | return false; |
| 4728 | return true; |
Rob Clark | ebc44cf | 2012-09-12 22:22:31 -0500 | [diff] [blame] | 4729 | } else if (drm_property_type_is(property, DRM_MODE_PROP_SIGNED_RANGE)) { |
| 4730 | int64_t svalue = U642I64(value); |
Thierry Reding | 4dfd909 | 2014-12-10 13:03:34 +0100 | [diff] [blame] | 4731 | |
Rob Clark | ebc44cf | 2012-09-12 22:22:31 -0500 | [diff] [blame] | 4732 | if (svalue < U642I64(property->values[0]) || |
| 4733 | svalue > U642I64(property->values[1])) |
| 4734 | return false; |
| 4735 | return true; |
Rob Clark | 5ea22f2 | 2014-05-30 11:34:01 -0400 | [diff] [blame] | 4736 | } else if (drm_property_type_is(property, DRM_MODE_PROP_BITMASK)) { |
Ville Syrjälä | 592c20e | 2012-05-24 20:53:58 +0300 | [diff] [blame] | 4737 | uint64_t valid_mask = 0; |
Thierry Reding | 4dfd909 | 2014-12-10 13:03:34 +0100 | [diff] [blame] | 4738 | |
Rob Clark | 49e2754 | 2012-05-17 02:23:26 -0600 | [diff] [blame] | 4739 | for (i = 0; i < property->num_values; i++) |
| 4740 | valid_mask |= (1ULL << property->values[i]); |
| 4741 | return !(value & ~valid_mask); |
Rob Clark | 5ea22f2 | 2014-05-30 11:34:01 -0400 | [diff] [blame] | 4742 | } else if (drm_property_type_is(property, DRM_MODE_PROP_BLOB)) { |
Daniel Stone | 6bcacf5 | 2015-04-20 19:22:55 +0100 | [diff] [blame] | 4743 | struct drm_property_blob *blob; |
| 4744 | |
| 4745 | if (value == 0) |
| 4746 | return true; |
| 4747 | |
| 4748 | blob = drm_property_lookup_blob(property->dev, value); |
| 4749 | if (blob) { |
| 4750 | *ref = &blob->base; |
| 4751 | return true; |
| 4752 | } else { |
| 4753 | return false; |
| 4754 | } |
Rob Clark | 98f75de | 2014-05-30 11:37:03 -0400 | [diff] [blame] | 4755 | } else if (drm_property_type_is(property, DRM_MODE_PROP_OBJECT)) { |
Rob Clark | 98f75de | 2014-05-30 11:37:03 -0400 | [diff] [blame] | 4756 | /* a zero value for an object property translates to null: */ |
| 4757 | if (value == 0) |
| 4758 | return true; |
Rob Clark | 3843e71 | 2014-12-16 18:05:29 -0500 | [diff] [blame] | 4759 | |
Tomi Valkeinen | 1e8985a | 2016-05-31 15:03:18 +0300 | [diff] [blame] | 4760 | *ref = _object_find(property->dev, value, property->values[0]); |
| 4761 | return *ref != NULL; |
Paulo Zanoni | 26a3481 | 2012-05-15 18:08:59 -0300 | [diff] [blame] | 4762 | } |
Thierry Reding | 2ca651d | 2014-12-10 13:03:39 +0100 | [diff] [blame] | 4763 | |
| 4764 | for (i = 0; i < property->num_values; i++) |
| 4765 | if (property->values[i] == value) |
| 4766 | return true; |
| 4767 | return false; |
Paulo Zanoni | 26a3481 | 2012-05-15 18:08:59 -0300 | [diff] [blame] | 4768 | } |
| 4769 | |
Rob Clark | d34f20d | 2014-12-18 16:01:56 -0500 | [diff] [blame] | 4770 | void drm_property_change_valid_put(struct drm_property *property, |
Rob Clark | 3843e71 | 2014-12-16 18:05:29 -0500 | [diff] [blame] | 4771 | struct drm_mode_object *ref) |
| 4772 | { |
| 4773 | if (!ref) |
| 4774 | return; |
| 4775 | |
| 4776 | if (drm_property_type_is(property, DRM_MODE_PROP_OBJECT)) { |
Dave Airlie | 027b3f8b | 2016-04-15 15:10:42 +1000 | [diff] [blame] | 4777 | drm_mode_object_unreference(ref); |
Daniel Stone | da9b2a3 | 2015-05-25 19:11:49 +0100 | [diff] [blame] | 4778 | } else if (drm_property_type_is(property, DRM_MODE_PROP_BLOB)) |
| 4779 | drm_property_unreference_blob(obj_to_blob(ref)); |
Rob Clark | 3843e71 | 2014-12-16 18:05:29 -0500 | [diff] [blame] | 4780 | } |
| 4781 | |
Daniel Vetter | c8e32cc | 2014-03-10 21:33:02 +0100 | [diff] [blame] | 4782 | /** |
| 4783 | * drm_mode_connector_property_set_ioctl - set the current value of a connector property |
| 4784 | * @dev: DRM device |
| 4785 | * @data: ioctl data |
| 4786 | * @file_priv: DRM file info |
| 4787 | * |
| 4788 | * This function sets the current value for a connectors's property. It also |
| 4789 | * calls into a driver's ->set_property callback to update the hardware state |
| 4790 | * |
| 4791 | * Called by the user via ioctl. |
| 4792 | * |
| 4793 | * Returns: |
Daniel Vetter | 1a49863 | 2014-11-19 18:38:09 +0100 | [diff] [blame] | 4794 | * Zero on success, negative errno on failure. |
Daniel Vetter | c8e32cc | 2014-03-10 21:33:02 +0100 | [diff] [blame] | 4795 | */ |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 4796 | int drm_mode_connector_property_set_ioctl(struct drm_device *dev, |
| 4797 | void *data, struct drm_file *file_priv) |
| 4798 | { |
Paulo Zanoni | 0057d8d | 2012-05-15 18:09:03 -0300 | [diff] [blame] | 4799 | struct drm_mode_connector_set_property *conn_set_prop = data; |
| 4800 | struct drm_mode_obj_set_property obj_set_prop = { |
| 4801 | .value = conn_set_prop->value, |
| 4802 | .prop_id = conn_set_prop->prop_id, |
| 4803 | .obj_id = conn_set_prop->connector_id, |
| 4804 | .obj_type = DRM_MODE_OBJECT_CONNECTOR |
| 4805 | }; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 4806 | |
Paulo Zanoni | 0057d8d | 2012-05-15 18:09:03 -0300 | [diff] [blame] | 4807 | /* It does all the locking and checking we need */ |
| 4808 | 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] | 4809 | } |
| 4810 | |
Paulo Zanoni | c543188 | 2012-05-15 18:09:02 -0300 | [diff] [blame] | 4811 | static int drm_mode_connector_set_obj_prop(struct drm_mode_object *obj, |
| 4812 | struct drm_property *property, |
| 4813 | uint64_t value) |
| 4814 | { |
| 4815 | int ret = -EINVAL; |
| 4816 | struct drm_connector *connector = obj_to_connector(obj); |
| 4817 | |
| 4818 | /* Do DPMS ourselves */ |
| 4819 | if (property == connector->dev->mode_config.dpms_property) { |
Daniel Vetter | 3558c11 | 2015-12-04 09:45:59 +0100 | [diff] [blame] | 4820 | ret = (*connector->funcs->dpms)(connector, (int)value); |
Paulo Zanoni | c543188 | 2012-05-15 18:09:02 -0300 | [diff] [blame] | 4821 | } else if (connector->funcs->set_property) |
| 4822 | ret = connector->funcs->set_property(connector, property, value); |
| 4823 | |
| 4824 | /* store the property value if successful */ |
| 4825 | if (!ret) |
Rob Clark | 5849556 | 2012-10-11 20:50:56 -0500 | [diff] [blame] | 4826 | drm_object_property_set_value(&connector->base, property, value); |
Paulo Zanoni | c543188 | 2012-05-15 18:09:02 -0300 | [diff] [blame] | 4827 | return ret; |
| 4828 | } |
| 4829 | |
Paulo Zanoni | bffd9de0 | 2012-05-15 18:09:05 -0300 | [diff] [blame] | 4830 | static int drm_mode_crtc_set_obj_prop(struct drm_mode_object *obj, |
| 4831 | struct drm_property *property, |
| 4832 | uint64_t value) |
| 4833 | { |
| 4834 | int ret = -EINVAL; |
| 4835 | struct drm_crtc *crtc = obj_to_crtc(obj); |
| 4836 | |
| 4837 | if (crtc->funcs->set_property) |
| 4838 | ret = crtc->funcs->set_property(crtc, property, value); |
| 4839 | if (!ret) |
| 4840 | drm_object_property_set_value(obj, property, value); |
| 4841 | |
| 4842 | return ret; |
| 4843 | } |
| 4844 | |
Thomas Wood | 3a5f87c | 2014-08-20 14:45:00 +0100 | [diff] [blame] | 4845 | /** |
| 4846 | * drm_mode_plane_set_obj_prop - set the value of a property |
| 4847 | * @plane: drm plane object to set property value for |
| 4848 | * @property: property to set |
| 4849 | * @value: value the property should be set to |
| 4850 | * |
| 4851 | * This functions sets a given property on a given plane object. This function |
| 4852 | * calls the driver's ->set_property callback and changes the software state of |
| 4853 | * the property if the callback succeeds. |
| 4854 | * |
| 4855 | * Returns: |
| 4856 | * Zero on success, error code on failure. |
| 4857 | */ |
| 4858 | int drm_mode_plane_set_obj_prop(struct drm_plane *plane, |
| 4859 | struct drm_property *property, |
| 4860 | uint64_t value) |
Rob Clark | 4d93914 | 2012-05-17 02:23:27 -0600 | [diff] [blame] | 4861 | { |
| 4862 | int ret = -EINVAL; |
Thomas Wood | 3a5f87c | 2014-08-20 14:45:00 +0100 | [diff] [blame] | 4863 | struct drm_mode_object *obj = &plane->base; |
Rob Clark | 4d93914 | 2012-05-17 02:23:27 -0600 | [diff] [blame] | 4864 | |
| 4865 | if (plane->funcs->set_property) |
| 4866 | ret = plane->funcs->set_property(plane, property, value); |
| 4867 | if (!ret) |
| 4868 | drm_object_property_set_value(obj, property, value); |
| 4869 | |
| 4870 | return ret; |
| 4871 | } |
Thomas Wood | 3a5f87c | 2014-08-20 14:45:00 +0100 | [diff] [blame] | 4872 | EXPORT_SYMBOL(drm_mode_plane_set_obj_prop); |
Rob Clark | 4d93914 | 2012-05-17 02:23:27 -0600 | [diff] [blame] | 4873 | |
Daniel Vetter | c8e32cc | 2014-03-10 21:33:02 +0100 | [diff] [blame] | 4874 | /** |
Daniel Vetter | 1a49863 | 2014-11-19 18:38:09 +0100 | [diff] [blame] | 4875 | * drm_mode_obj_get_properties_ioctl - get the current value of a object's property |
Daniel Vetter | c8e32cc | 2014-03-10 21:33:02 +0100 | [diff] [blame] | 4876 | * @dev: DRM device |
| 4877 | * @data: ioctl data |
| 4878 | * @file_priv: DRM file info |
| 4879 | * |
| 4880 | * This function retrieves the current value for an object's property. Compared |
| 4881 | * to the connector specific ioctl this one is extended to also work on crtc and |
| 4882 | * plane objects. |
| 4883 | * |
| 4884 | * Called by the user via ioctl. |
| 4885 | * |
| 4886 | * Returns: |
Daniel Vetter | 1a49863 | 2014-11-19 18:38:09 +0100 | [diff] [blame] | 4887 | * Zero on success, negative errno on failure. |
Daniel Vetter | c8e32cc | 2014-03-10 21:33:02 +0100 | [diff] [blame] | 4888 | */ |
Paulo Zanoni | c543188 | 2012-05-15 18:09:02 -0300 | [diff] [blame] | 4889 | int drm_mode_obj_get_properties_ioctl(struct drm_device *dev, void *data, |
| 4890 | struct drm_file *file_priv) |
| 4891 | { |
| 4892 | struct drm_mode_obj_get_properties *arg = data; |
| 4893 | struct drm_mode_object *obj; |
| 4894 | int ret = 0; |
Paulo Zanoni | c543188 | 2012-05-15 18:09:02 -0300 | [diff] [blame] | 4895 | |
| 4896 | if (!drm_core_check_feature(dev, DRIVER_MODESET)) |
| 4897 | return -EINVAL; |
| 4898 | |
Daniel Vetter | 8484990 | 2012-12-02 00:28:11 +0100 | [diff] [blame] | 4899 | drm_modeset_lock_all(dev); |
Paulo Zanoni | c543188 | 2012-05-15 18:09:02 -0300 | [diff] [blame] | 4900 | |
| 4901 | obj = drm_mode_object_find(dev, arg->obj_id, arg->obj_type); |
| 4902 | if (!obj) { |
Ville Syrjälä | f27657f | 2013-10-17 13:35:00 +0300 | [diff] [blame] | 4903 | ret = -ENOENT; |
Paulo Zanoni | c543188 | 2012-05-15 18:09:02 -0300 | [diff] [blame] | 4904 | goto out; |
| 4905 | } |
| 4906 | if (!obj->properties) { |
| 4907 | ret = -EINVAL; |
Daniel Vetter | 1649c33 | 2016-04-22 22:10:28 +0200 | [diff] [blame] | 4908 | goto out_unref; |
Paulo Zanoni | c543188 | 2012-05-15 18:09:02 -0300 | [diff] [blame] | 4909 | } |
| 4910 | |
Rob Clark | 88a48e2 | 2014-12-18 16:01:50 -0500 | [diff] [blame] | 4911 | ret = get_properties(obj, file_priv->atomic, |
Rob Clark | 95cbf11 | 2014-12-18 16:01:49 -0500 | [diff] [blame] | 4912 | (uint32_t __user *)(unsigned long)(arg->props_ptr), |
| 4913 | (uint64_t __user *)(unsigned long)(arg->prop_values_ptr), |
| 4914 | &arg->count_props); |
Paulo Zanoni | c543188 | 2012-05-15 18:09:02 -0300 | [diff] [blame] | 4915 | |
Daniel Vetter | 1649c33 | 2016-04-22 22:10:28 +0200 | [diff] [blame] | 4916 | out_unref: |
| 4917 | drm_mode_object_unreference(obj); |
Paulo Zanoni | c543188 | 2012-05-15 18:09:02 -0300 | [diff] [blame] | 4918 | out: |
Daniel Vetter | 8484990 | 2012-12-02 00:28:11 +0100 | [diff] [blame] | 4919 | drm_modeset_unlock_all(dev); |
Paulo Zanoni | c543188 | 2012-05-15 18:09:02 -0300 | [diff] [blame] | 4920 | return ret; |
| 4921 | } |
| 4922 | |
Daniel Vetter | c8e32cc | 2014-03-10 21:33:02 +0100 | [diff] [blame] | 4923 | /** |
| 4924 | * drm_mode_obj_set_property_ioctl - set the current value of an object's property |
| 4925 | * @dev: DRM device |
| 4926 | * @data: ioctl data |
| 4927 | * @file_priv: DRM file info |
| 4928 | * |
| 4929 | * This function sets the current value for an object's property. It also calls |
| 4930 | * into a driver's ->set_property callback to update the hardware state. |
| 4931 | * Compared to the connector specific ioctl this one is extended to also work on |
| 4932 | * crtc and plane objects. |
| 4933 | * |
| 4934 | * Called by the user via ioctl. |
| 4935 | * |
| 4936 | * Returns: |
Daniel Vetter | 1a49863 | 2014-11-19 18:38:09 +0100 | [diff] [blame] | 4937 | * Zero on success, negative errno on failure. |
Daniel Vetter | c8e32cc | 2014-03-10 21:33:02 +0100 | [diff] [blame] | 4938 | */ |
Paulo Zanoni | c543188 | 2012-05-15 18:09:02 -0300 | [diff] [blame] | 4939 | int drm_mode_obj_set_property_ioctl(struct drm_device *dev, void *data, |
| 4940 | struct drm_file *file_priv) |
| 4941 | { |
| 4942 | struct drm_mode_obj_set_property *arg = data; |
| 4943 | struct drm_mode_object *arg_obj; |
| 4944 | struct drm_mode_object *prop_obj; |
| 4945 | struct drm_property *property; |
Rob Clark | 3843e71 | 2014-12-16 18:05:29 -0500 | [diff] [blame] | 4946 | int i, ret = -EINVAL; |
| 4947 | struct drm_mode_object *ref; |
Paulo Zanoni | c543188 | 2012-05-15 18:09:02 -0300 | [diff] [blame] | 4948 | |
| 4949 | if (!drm_core_check_feature(dev, DRIVER_MODESET)) |
| 4950 | return -EINVAL; |
| 4951 | |
Daniel Vetter | 8484990 | 2012-12-02 00:28:11 +0100 | [diff] [blame] | 4952 | drm_modeset_lock_all(dev); |
Paulo Zanoni | c543188 | 2012-05-15 18:09:02 -0300 | [diff] [blame] | 4953 | |
| 4954 | 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] | 4955 | if (!arg_obj) { |
| 4956 | ret = -ENOENT; |
Paulo Zanoni | c543188 | 2012-05-15 18:09:02 -0300 | [diff] [blame] | 4957 | goto out; |
Ville Syrjälä | f27657f | 2013-10-17 13:35:00 +0300 | [diff] [blame] | 4958 | } |
Paulo Zanoni | c543188 | 2012-05-15 18:09:02 -0300 | [diff] [blame] | 4959 | if (!arg_obj->properties) |
Daniel Vetter | 1649c33 | 2016-04-22 22:10:28 +0200 | [diff] [blame] | 4960 | goto out_unref; |
Paulo Zanoni | c543188 | 2012-05-15 18:09:02 -0300 | [diff] [blame] | 4961 | |
Paulo Zanoni | 7f88a9b | 2012-05-15 18:09:04 -0300 | [diff] [blame] | 4962 | for (i = 0; i < arg_obj->properties->count; i++) |
Rob Clark | b17cd75 | 2014-12-16 18:05:30 -0500 | [diff] [blame] | 4963 | if (arg_obj->properties->properties[i]->base.id == arg->prop_id) |
Paulo Zanoni | c543188 | 2012-05-15 18:09:02 -0300 | [diff] [blame] | 4964 | break; |
| 4965 | |
Paulo Zanoni | 7f88a9b | 2012-05-15 18:09:04 -0300 | [diff] [blame] | 4966 | if (i == arg_obj->properties->count) |
Daniel Vetter | 1649c33 | 2016-04-22 22:10:28 +0200 | [diff] [blame] | 4967 | goto out_unref; |
Paulo Zanoni | c543188 | 2012-05-15 18:09:02 -0300 | [diff] [blame] | 4968 | |
| 4969 | prop_obj = drm_mode_object_find(dev, arg->prop_id, |
| 4970 | DRM_MODE_OBJECT_PROPERTY); |
Ville Syrjälä | f27657f | 2013-10-17 13:35:00 +0300 | [diff] [blame] | 4971 | if (!prop_obj) { |
| 4972 | ret = -ENOENT; |
Daniel Vetter | 1649c33 | 2016-04-22 22:10:28 +0200 | [diff] [blame] | 4973 | goto out_unref; |
Ville Syrjälä | f27657f | 2013-10-17 13:35:00 +0300 | [diff] [blame] | 4974 | } |
Paulo Zanoni | c543188 | 2012-05-15 18:09:02 -0300 | [diff] [blame] | 4975 | property = obj_to_property(prop_obj); |
| 4976 | |
Rob Clark | 3843e71 | 2014-12-16 18:05:29 -0500 | [diff] [blame] | 4977 | if (!drm_property_change_valid_get(property, arg->value, &ref)) |
Dave Airlie | b164d31 | 2016-04-27 11:10:09 +1000 | [diff] [blame] | 4978 | goto out_unref; |
Paulo Zanoni | c543188 | 2012-05-15 18:09:02 -0300 | [diff] [blame] | 4979 | |
| 4980 | switch (arg_obj->type) { |
| 4981 | case DRM_MODE_OBJECT_CONNECTOR: |
| 4982 | ret = drm_mode_connector_set_obj_prop(arg_obj, property, |
| 4983 | arg->value); |
| 4984 | break; |
Paulo Zanoni | bffd9de0 | 2012-05-15 18:09:05 -0300 | [diff] [blame] | 4985 | case DRM_MODE_OBJECT_CRTC: |
| 4986 | ret = drm_mode_crtc_set_obj_prop(arg_obj, property, arg->value); |
| 4987 | break; |
Rob Clark | 4d93914 | 2012-05-17 02:23:27 -0600 | [diff] [blame] | 4988 | case DRM_MODE_OBJECT_PLANE: |
Thomas Wood | 3a5f87c | 2014-08-20 14:45:00 +0100 | [diff] [blame] | 4989 | ret = drm_mode_plane_set_obj_prop(obj_to_plane(arg_obj), |
| 4990 | property, arg->value); |
Rob Clark | 4d93914 | 2012-05-17 02:23:27 -0600 | [diff] [blame] | 4991 | break; |
Paulo Zanoni | c543188 | 2012-05-15 18:09:02 -0300 | [diff] [blame] | 4992 | } |
| 4993 | |
Rob Clark | 3843e71 | 2014-12-16 18:05:29 -0500 | [diff] [blame] | 4994 | drm_property_change_valid_put(property, ref); |
| 4995 | |
Daniel Vetter | 1649c33 | 2016-04-22 22:10:28 +0200 | [diff] [blame] | 4996 | out_unref: |
| 4997 | drm_mode_object_unreference(arg_obj); |
Paulo Zanoni | c543188 | 2012-05-15 18:09:02 -0300 | [diff] [blame] | 4998 | out: |
Daniel Vetter | 8484990 | 2012-12-02 00:28:11 +0100 | [diff] [blame] | 4999 | drm_modeset_unlock_all(dev); |
Paulo Zanoni | c543188 | 2012-05-15 18:09:02 -0300 | [diff] [blame] | 5000 | return ret; |
| 5001 | } |
| 5002 | |
Daniel Vetter | c8e32cc | 2014-03-10 21:33:02 +0100 | [diff] [blame] | 5003 | /** |
| 5004 | * drm_mode_connector_attach_encoder - attach a connector to an encoder |
| 5005 | * @connector: connector to attach |
| 5006 | * @encoder: encoder to attach @connector to |
| 5007 | * |
| 5008 | * This function links up a connector to an encoder. Note that the routing |
| 5009 | * restrictions between encoders and crtcs are exposed to userspace through the |
| 5010 | * possible_clones and possible_crtcs bitmasks. |
| 5011 | * |
| 5012 | * Returns: |
Daniel Vetter | 1a49863 | 2014-11-19 18:38:09 +0100 | [diff] [blame] | 5013 | * Zero on success, negative errno on failure. |
Daniel Vetter | c8e32cc | 2014-03-10 21:33:02 +0100 | [diff] [blame] | 5014 | */ |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 5015 | int drm_mode_connector_attach_encoder(struct drm_connector *connector, |
| 5016 | struct drm_encoder *encoder) |
| 5017 | { |
| 5018 | int i; |
| 5019 | |
Thierry Reding | eb47fe8 | 2015-11-16 18:19:53 +0100 | [diff] [blame] | 5020 | /* |
| 5021 | * In the past, drivers have attempted to model the static association |
| 5022 | * of connector to encoder in simple connector/encoder devices using a |
| 5023 | * direct assignment of connector->encoder = encoder. This connection |
| 5024 | * is a logical one and the responsibility of the core, so drivers are |
| 5025 | * expected not to mess with this. |
| 5026 | * |
| 5027 | * Note that the error return should've been enough here, but a large |
| 5028 | * majority of drivers ignores the return value, so add in a big WARN |
| 5029 | * to get people's attention. |
| 5030 | */ |
| 5031 | if (WARN_ON(connector->encoder)) |
| 5032 | return -EINVAL; |
| 5033 | |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 5034 | for (i = 0; i < DRM_CONNECTOR_MAX_ENCODER; i++) { |
| 5035 | if (connector->encoder_ids[i] == 0) { |
| 5036 | connector->encoder_ids[i] = encoder->base.id; |
| 5037 | return 0; |
| 5038 | } |
| 5039 | } |
| 5040 | return -ENOMEM; |
| 5041 | } |
| 5042 | EXPORT_SYMBOL(drm_mode_connector_attach_encoder); |
| 5043 | |
Daniel Vetter | c8e32cc | 2014-03-10 21:33:02 +0100 | [diff] [blame] | 5044 | /** |
| 5045 | * drm_mode_crtc_set_gamma_size - set the gamma table size |
| 5046 | * @crtc: CRTC to set the gamma table size for |
| 5047 | * @gamma_size: size of the gamma table |
| 5048 | * |
| 5049 | * Drivers which support gamma tables should set this to the supported gamma |
| 5050 | * table size when initializing the CRTC. Currently the drm core only supports a |
| 5051 | * fixed gamma table size. |
| 5052 | * |
| 5053 | * Returns: |
Daniel Vetter | 1a49863 | 2014-11-19 18:38:09 +0100 | [diff] [blame] | 5054 | * Zero on success, negative errno on failure. |
Daniel Vetter | c8e32cc | 2014-03-10 21:33:02 +0100 | [diff] [blame] | 5055 | */ |
Sascha Hauer | 4cae5b8 | 2012-02-01 11:38:23 +0100 | [diff] [blame] | 5056 | int drm_mode_crtc_set_gamma_size(struct drm_crtc *crtc, |
Daniel Vetter | c8e32cc | 2014-03-10 21:33:02 +0100 | [diff] [blame] | 5057 | int gamma_size) |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 5058 | { |
Daniel Vetter | cf48e29 | 2016-03-30 11:51:16 +0200 | [diff] [blame] | 5059 | uint16_t *r_base, *g_base, *b_base; |
| 5060 | int i; |
| 5061 | |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 5062 | crtc->gamma_size = gamma_size; |
| 5063 | |
Thierry Reding | bd3f0ff | 2014-12-10 13:03:35 +0100 | [diff] [blame] | 5064 | crtc->gamma_store = kcalloc(gamma_size, sizeof(uint16_t) * 3, |
| 5065 | GFP_KERNEL); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 5066 | if (!crtc->gamma_store) { |
| 5067 | crtc->gamma_size = 0; |
Sascha Hauer | 4cae5b8 | 2012-02-01 11:38:23 +0100 | [diff] [blame] | 5068 | return -ENOMEM; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 5069 | } |
| 5070 | |
Daniel Vetter | cf48e29 | 2016-03-30 11:51:16 +0200 | [diff] [blame] | 5071 | r_base = crtc->gamma_store; |
| 5072 | g_base = r_base + gamma_size; |
| 5073 | b_base = g_base + gamma_size; |
| 5074 | for (i = 0; i < gamma_size; i++) { |
| 5075 | r_base[i] = i << 8; |
| 5076 | g_base[i] = i << 8; |
| 5077 | b_base[i] = i << 8; |
| 5078 | } |
| 5079 | |
| 5080 | |
Sascha Hauer | 4cae5b8 | 2012-02-01 11:38:23 +0100 | [diff] [blame] | 5081 | return 0; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 5082 | } |
| 5083 | EXPORT_SYMBOL(drm_mode_crtc_set_gamma_size); |
| 5084 | |
Daniel Vetter | c8e32cc | 2014-03-10 21:33:02 +0100 | [diff] [blame] | 5085 | /** |
| 5086 | * drm_mode_gamma_set_ioctl - set the gamma table |
| 5087 | * @dev: DRM device |
| 5088 | * @data: ioctl data |
| 5089 | * @file_priv: DRM file info |
| 5090 | * |
| 5091 | * Set the gamma table of a CRTC to the one passed in by the user. Userspace can |
| 5092 | * inquire the required gamma table size through drm_mode_gamma_get_ioctl. |
| 5093 | * |
| 5094 | * Called by the user via ioctl. |
| 5095 | * |
| 5096 | * Returns: |
Daniel Vetter | 1a49863 | 2014-11-19 18:38:09 +0100 | [diff] [blame] | 5097 | * Zero on success, negative errno on failure. |
Daniel Vetter | c8e32cc | 2014-03-10 21:33:02 +0100 | [diff] [blame] | 5098 | */ |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 5099 | int drm_mode_gamma_set_ioctl(struct drm_device *dev, |
| 5100 | void *data, struct drm_file *file_priv) |
| 5101 | { |
| 5102 | struct drm_mode_crtc_lut *crtc_lut = data; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 5103 | struct drm_crtc *crtc; |
| 5104 | void *r_base, *g_base, *b_base; |
| 5105 | int size; |
| 5106 | int ret = 0; |
| 5107 | |
Dave Airlie | fb3b06c | 2011-02-08 13:55:21 +1000 | [diff] [blame] | 5108 | if (!drm_core_check_feature(dev, DRIVER_MODESET)) |
| 5109 | return -EINVAL; |
| 5110 | |
Daniel Vetter | 8484990 | 2012-12-02 00:28:11 +0100 | [diff] [blame] | 5111 | drm_modeset_lock_all(dev); |
Rob Clark | a2b34e2 | 2013-10-05 16:36:52 -0400 | [diff] [blame] | 5112 | crtc = drm_crtc_find(dev, crtc_lut->crtc_id); |
| 5113 | if (!crtc) { |
Ville Syrjälä | f27657f | 2013-10-17 13:35:00 +0300 | [diff] [blame] | 5114 | ret = -ENOENT; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 5115 | goto out; |
| 5116 | } |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 5117 | |
Laurent Pinchart | ebe0f24 | 2012-05-17 13:27:24 +0200 | [diff] [blame] | 5118 | if (crtc->funcs->gamma_set == NULL) { |
| 5119 | ret = -ENOSYS; |
| 5120 | goto out; |
| 5121 | } |
| 5122 | |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 5123 | /* memcpy into gamma store */ |
| 5124 | if (crtc_lut->gamma_size != crtc->gamma_size) { |
| 5125 | ret = -EINVAL; |
| 5126 | goto out; |
| 5127 | } |
| 5128 | |
| 5129 | size = crtc_lut->gamma_size * (sizeof(uint16_t)); |
| 5130 | r_base = crtc->gamma_store; |
| 5131 | if (copy_from_user(r_base, (void __user *)(unsigned long)crtc_lut->red, size)) { |
| 5132 | ret = -EFAULT; |
| 5133 | goto out; |
| 5134 | } |
| 5135 | |
| 5136 | g_base = r_base + size; |
| 5137 | if (copy_from_user(g_base, (void __user *)(unsigned long)crtc_lut->green, size)) { |
| 5138 | ret = -EFAULT; |
| 5139 | goto out; |
| 5140 | } |
| 5141 | |
| 5142 | b_base = g_base + size; |
| 5143 | if (copy_from_user(b_base, (void __user *)(unsigned long)crtc_lut->blue, size)) { |
| 5144 | ret = -EFAULT; |
| 5145 | goto out; |
| 5146 | } |
| 5147 | |
Maarten Lankhorst | 7ea7728 | 2016-06-07 12:49:30 +0200 | [diff] [blame] | 5148 | ret = crtc->funcs->gamma_set(crtc, r_base, g_base, b_base, crtc->gamma_size); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 5149 | |
| 5150 | out: |
Daniel Vetter | 8484990 | 2012-12-02 00:28:11 +0100 | [diff] [blame] | 5151 | drm_modeset_unlock_all(dev); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 5152 | return ret; |
| 5153 | |
| 5154 | } |
| 5155 | |
Daniel Vetter | c8e32cc | 2014-03-10 21:33:02 +0100 | [diff] [blame] | 5156 | /** |
| 5157 | * drm_mode_gamma_get_ioctl - get the gamma table |
| 5158 | * @dev: DRM device |
| 5159 | * @data: ioctl data |
| 5160 | * @file_priv: DRM file info |
| 5161 | * |
| 5162 | * Copy the current gamma table into the storage provided. This also provides |
| 5163 | * the gamma table size the driver expects, which can be used to size the |
| 5164 | * allocated storage. |
| 5165 | * |
| 5166 | * Called by the user via ioctl. |
| 5167 | * |
| 5168 | * Returns: |
Daniel Vetter | 1a49863 | 2014-11-19 18:38:09 +0100 | [diff] [blame] | 5169 | * Zero on success, negative errno on failure. |
Daniel Vetter | c8e32cc | 2014-03-10 21:33:02 +0100 | [diff] [blame] | 5170 | */ |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 5171 | int drm_mode_gamma_get_ioctl(struct drm_device *dev, |
| 5172 | void *data, struct drm_file *file_priv) |
| 5173 | { |
| 5174 | struct drm_mode_crtc_lut *crtc_lut = data; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 5175 | struct drm_crtc *crtc; |
| 5176 | void *r_base, *g_base, *b_base; |
| 5177 | int size; |
| 5178 | int ret = 0; |
| 5179 | |
Dave Airlie | fb3b06c | 2011-02-08 13:55:21 +1000 | [diff] [blame] | 5180 | if (!drm_core_check_feature(dev, DRIVER_MODESET)) |
| 5181 | return -EINVAL; |
| 5182 | |
Daniel Vetter | 8484990 | 2012-12-02 00:28:11 +0100 | [diff] [blame] | 5183 | drm_modeset_lock_all(dev); |
Rob Clark | a2b34e2 | 2013-10-05 16:36:52 -0400 | [diff] [blame] | 5184 | crtc = drm_crtc_find(dev, crtc_lut->crtc_id); |
| 5185 | if (!crtc) { |
Ville Syrjälä | f27657f | 2013-10-17 13:35:00 +0300 | [diff] [blame] | 5186 | ret = -ENOENT; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 5187 | goto out; |
| 5188 | } |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 5189 | |
| 5190 | /* memcpy into gamma store */ |
| 5191 | if (crtc_lut->gamma_size != crtc->gamma_size) { |
| 5192 | ret = -EINVAL; |
| 5193 | goto out; |
| 5194 | } |
| 5195 | |
| 5196 | size = crtc_lut->gamma_size * (sizeof(uint16_t)); |
| 5197 | r_base = crtc->gamma_store; |
| 5198 | if (copy_to_user((void __user *)(unsigned long)crtc_lut->red, r_base, size)) { |
| 5199 | ret = -EFAULT; |
| 5200 | goto out; |
| 5201 | } |
| 5202 | |
| 5203 | g_base = r_base + size; |
| 5204 | if (copy_to_user((void __user *)(unsigned long)crtc_lut->green, g_base, size)) { |
| 5205 | ret = -EFAULT; |
| 5206 | goto out; |
| 5207 | } |
| 5208 | |
| 5209 | b_base = g_base + size; |
| 5210 | if (copy_to_user((void __user *)(unsigned long)crtc_lut->blue, b_base, size)) { |
| 5211 | ret = -EFAULT; |
| 5212 | goto out; |
| 5213 | } |
| 5214 | out: |
Daniel Vetter | 8484990 | 2012-12-02 00:28:11 +0100 | [diff] [blame] | 5215 | drm_modeset_unlock_all(dev); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 5216 | return ret; |
| 5217 | } |
Kristian Høgsberg | d91d8a3 | 2009-11-17 12:43:55 -0500 | [diff] [blame] | 5218 | |
Daniel Vetter | c8e32cc | 2014-03-10 21:33:02 +0100 | [diff] [blame] | 5219 | /** |
| 5220 | * drm_mode_page_flip_ioctl - schedule an asynchronous fb update |
| 5221 | * @dev: DRM device |
| 5222 | * @data: ioctl data |
| 5223 | * @file_priv: DRM file info |
| 5224 | * |
| 5225 | * This schedules an asynchronous update on a given CRTC, called page flip. |
| 5226 | * Optionally a drm event is generated to signal the completion of the event. |
| 5227 | * Generic drivers cannot assume that a pageflip with changed framebuffer |
| 5228 | * properties (including driver specific metadata like tiling layout) will work, |
| 5229 | * but some drivers support e.g. pixel format changes through the pageflip |
| 5230 | * ioctl. |
| 5231 | * |
| 5232 | * Called by the user via ioctl. |
| 5233 | * |
| 5234 | * Returns: |
Daniel Vetter | 1a49863 | 2014-11-19 18:38:09 +0100 | [diff] [blame] | 5235 | * Zero on success, negative errno on failure. |
Daniel Vetter | c8e32cc | 2014-03-10 21:33:02 +0100 | [diff] [blame] | 5236 | */ |
Kristian Høgsberg | d91d8a3 | 2009-11-17 12:43:55 -0500 | [diff] [blame] | 5237 | int drm_mode_page_flip_ioctl(struct drm_device *dev, |
| 5238 | void *data, struct drm_file *file_priv) |
| 5239 | { |
| 5240 | struct drm_mode_crtc_page_flip *page_flip = data; |
Kristian Høgsberg | d91d8a3 | 2009-11-17 12:43:55 -0500 | [diff] [blame] | 5241 | struct drm_crtc *crtc; |
Daniel Vetter | 3d30a59 | 2014-07-27 13:42:42 +0200 | [diff] [blame] | 5242 | struct drm_framebuffer *fb = NULL; |
Kristian Høgsberg | d91d8a3 | 2009-11-17 12:43:55 -0500 | [diff] [blame] | 5243 | struct drm_pending_vblank_event *e = NULL; |
Kristian Høgsberg | d91d8a3 | 2009-11-17 12:43:55 -0500 | [diff] [blame] | 5244 | int ret = -EINVAL; |
| 5245 | |
| 5246 | if (page_flip->flags & ~DRM_MODE_PAGE_FLIP_FLAGS || |
| 5247 | page_flip->reserved != 0) |
| 5248 | return -EINVAL; |
| 5249 | |
Keith Packard | 62f2104 | 2013-07-22 18:50:00 -0700 | [diff] [blame] | 5250 | if ((page_flip->flags & DRM_MODE_PAGE_FLIP_ASYNC) && !dev->mode_config.async_page_flip) |
| 5251 | return -EINVAL; |
| 5252 | |
Rob Clark | a2b34e2 | 2013-10-05 16:36:52 -0400 | [diff] [blame] | 5253 | crtc = drm_crtc_find(dev, page_flip->crtc_id); |
| 5254 | if (!crtc) |
Ville Syrjälä | f27657f | 2013-10-17 13:35:00 +0300 | [diff] [blame] | 5255 | return -ENOENT; |
Kristian Høgsberg | d91d8a3 | 2009-11-17 12:43:55 -0500 | [diff] [blame] | 5256 | |
Daniel Vetter | 4d02e2d | 2014-11-11 10:12:00 +0100 | [diff] [blame] | 5257 | drm_modeset_lock_crtc(crtc, crtc->primary); |
Matt Roper | f4510a2 | 2014-04-01 15:22:40 -0700 | [diff] [blame] | 5258 | if (crtc->primary->fb == NULL) { |
Chris Wilson | 90c1efd | 2010-07-17 20:23:26 +0100 | [diff] [blame] | 5259 | /* The framebuffer is currently unbound, presumably |
| 5260 | * due to a hotplug event, that userspace has not |
| 5261 | * yet discovered. |
| 5262 | */ |
| 5263 | ret = -EBUSY; |
| 5264 | goto out; |
| 5265 | } |
| 5266 | |
Kristian Høgsberg | d91d8a3 | 2009-11-17 12:43:55 -0500 | [diff] [blame] | 5267 | if (crtc->funcs->page_flip == NULL) |
| 5268 | goto out; |
| 5269 | |
Daniel Vetter | 786b99e | 2012-12-02 21:53:40 +0100 | [diff] [blame] | 5270 | fb = drm_framebuffer_lookup(dev, page_flip->fb_id); |
Ville Syrjälä | 37c4e70 | 2013-10-17 13:35:01 +0300 | [diff] [blame] | 5271 | if (!fb) { |
| 5272 | ret = -ENOENT; |
Kristian Høgsberg | d91d8a3 | 2009-11-17 12:43:55 -0500 | [diff] [blame] | 5273 | goto out; |
Ville Syrjälä | 37c4e70 | 2013-10-17 13:35:01 +0300 | [diff] [blame] | 5274 | } |
Kristian Høgsberg | d91d8a3 | 2009-11-17 12:43:55 -0500 | [diff] [blame] | 5275 | |
Ville Syrjälä | 2afa701d | 2015-10-15 20:40:02 +0300 | [diff] [blame] | 5276 | if (crtc->state) { |
| 5277 | const struct drm_plane_state *state = crtc->primary->state; |
| 5278 | |
| 5279 | ret = check_src_coords(state->src_x, state->src_y, |
| 5280 | state->src_w, state->src_h, fb); |
| 5281 | } else { |
| 5282 | ret = drm_crtc_check_viewport(crtc, crtc->x, crtc->y, &crtc->mode, fb); |
| 5283 | } |
Damien Lespiau | c11e928 | 2013-09-25 16:45:30 +0100 | [diff] [blame] | 5284 | if (ret) |
Ville Syrjälä | 5f61bb4 | 2012-03-13 12:35:45 +0200 | [diff] [blame] | 5285 | goto out; |
Ville Syrjälä | 5f61bb4 | 2012-03-13 12:35:45 +0200 | [diff] [blame] | 5286 | |
Matt Roper | f4510a2 | 2014-04-01 15:22:40 -0700 | [diff] [blame] | 5287 | if (crtc->primary->fb->pixel_format != fb->pixel_format) { |
Laurent Pinchart | 909d9cd | 2013-04-22 01:38:46 +0200 | [diff] [blame] | 5288 | DRM_DEBUG_KMS("Page flip is not allowed to change frame buffer format.\n"); |
| 5289 | ret = -EINVAL; |
| 5290 | goto out; |
| 5291 | } |
| 5292 | |
Kristian Høgsberg | d91d8a3 | 2009-11-17 12:43:55 -0500 | [diff] [blame] | 5293 | if (page_flip->flags & DRM_MODE_PAGE_FLIP_EVENT) { |
Daniel Vetter | 2dd500f | 2016-01-11 22:40:56 +0100 | [diff] [blame] | 5294 | e = kzalloc(sizeof *e, GFP_KERNEL); |
| 5295 | if (!e) { |
| 5296 | ret = -ENOMEM; |
Kristian Høgsberg | d91d8a3 | 2009-11-17 12:43:55 -0500 | [diff] [blame] | 5297 | goto out; |
| 5298 | } |
Jesse Barnes | 7bd4d7b | 2009-11-19 10:50:22 -0800 | [diff] [blame] | 5299 | e->event.base.type = DRM_EVENT_FLIP_COMPLETE; |
Thierry Reding | f76511b | 2014-12-10 13:03:40 +0100 | [diff] [blame] | 5300 | e->event.base.length = sizeof(e->event); |
Kristian Høgsberg | d91d8a3 | 2009-11-17 12:43:55 -0500 | [diff] [blame] | 5301 | e->event.user_data = page_flip->user_data; |
Daniel Vetter | 2dd500f | 2016-01-11 22:40:56 +0100 | [diff] [blame] | 5302 | ret = drm_event_reserve_init(dev, file_priv, &e->base, &e->event.base); |
| 5303 | if (ret) { |
| 5304 | kfree(e); |
| 5305 | goto out; |
| 5306 | } |
Kristian Høgsberg | d91d8a3 | 2009-11-17 12:43:55 -0500 | [diff] [blame] | 5307 | } |
| 5308 | |
Daniel Vetter | 3d30a59 | 2014-07-27 13:42:42 +0200 | [diff] [blame] | 5309 | crtc->primary->old_fb = crtc->primary->fb; |
Keith Packard | ed8d197 | 2013-07-22 18:49:58 -0700 | [diff] [blame] | 5310 | ret = crtc->funcs->page_flip(crtc, fb, e, page_flip->flags); |
Kristian Høgsberg | d91d8a3 | 2009-11-17 12:43:55 -0500 | [diff] [blame] | 5311 | if (ret) { |
Daniel Vetter | 2dd500f | 2016-01-11 22:40:56 +0100 | [diff] [blame] | 5312 | if (page_flip->flags & DRM_MODE_PAGE_FLIP_EVENT) |
| 5313 | drm_event_cancel_free(dev, &e->base); |
Daniel Vetter | b0d1232 | 2012-12-11 01:07:12 +0100 | [diff] [blame] | 5314 | /* Keep the old fb, don't unref it. */ |
Daniel Vetter | 3d30a59 | 2014-07-27 13:42:42 +0200 | [diff] [blame] | 5315 | crtc->primary->old_fb = NULL; |
Daniel Vetter | b0d1232 | 2012-12-11 01:07:12 +0100 | [diff] [blame] | 5316 | } else { |
Daniel Vetter | 3cb43cc | 2015-07-07 08:43:03 +0200 | [diff] [blame] | 5317 | crtc->primary->fb = fb; |
Daniel Vetter | b0d1232 | 2012-12-11 01:07:12 +0100 | [diff] [blame] | 5318 | /* Unref only the old framebuffer. */ |
| 5319 | fb = NULL; |
Kristian Høgsberg | d91d8a3 | 2009-11-17 12:43:55 -0500 | [diff] [blame] | 5320 | } |
| 5321 | |
| 5322 | out: |
Daniel Vetter | b0d1232 | 2012-12-11 01:07:12 +0100 | [diff] [blame] | 5323 | if (fb) |
| 5324 | drm_framebuffer_unreference(fb); |
Daniel Vetter | 3d30a59 | 2014-07-27 13:42:42 +0200 | [diff] [blame] | 5325 | if (crtc->primary->old_fb) |
| 5326 | drm_framebuffer_unreference(crtc->primary->old_fb); |
| 5327 | crtc->primary->old_fb = NULL; |
Daniel Vetter | d059f65 | 2014-07-25 18:07:40 +0200 | [diff] [blame] | 5328 | drm_modeset_unlock_crtc(crtc); |
Daniel Vetter | b4d5e7d | 2012-12-11 16:59:31 +0100 | [diff] [blame] | 5329 | |
Kristian Høgsberg | d91d8a3 | 2009-11-17 12:43:55 -0500 | [diff] [blame] | 5330 | return ret; |
| 5331 | } |
Chris Wilson | eb03355 | 2011-01-24 15:11:08 +0000 | [diff] [blame] | 5332 | |
Daniel Vetter | c8e32cc | 2014-03-10 21:33:02 +0100 | [diff] [blame] | 5333 | /** |
| 5334 | * drm_mode_config_reset - call ->reset callbacks |
| 5335 | * @dev: drm device |
| 5336 | * |
| 5337 | * This functions calls all the crtc's, encoder's and connector's ->reset |
| 5338 | * callback. Drivers can use this in e.g. their driver load or resume code to |
| 5339 | * reset hardware and software state. |
| 5340 | */ |
Chris Wilson | eb03355 | 2011-01-24 15:11:08 +0000 | [diff] [blame] | 5341 | void drm_mode_config_reset(struct drm_device *dev) |
| 5342 | { |
| 5343 | struct drm_crtc *crtc; |
Daniel Vetter | 2a0d7cf | 2014-07-29 15:32:37 +0200 | [diff] [blame] | 5344 | struct drm_plane *plane; |
Chris Wilson | eb03355 | 2011-01-24 15:11:08 +0000 | [diff] [blame] | 5345 | struct drm_encoder *encoder; |
| 5346 | struct drm_connector *connector; |
| 5347 | |
Daniel Vetter | e4f6254 | 2015-07-09 23:44:35 +0200 | [diff] [blame] | 5348 | drm_for_each_plane(plane, dev) |
Daniel Vetter | 2a0d7cf | 2014-07-29 15:32:37 +0200 | [diff] [blame] | 5349 | if (plane->funcs->reset) |
| 5350 | plane->funcs->reset(plane); |
| 5351 | |
Daniel Vetter | e4f6254 | 2015-07-09 23:44:35 +0200 | [diff] [blame] | 5352 | drm_for_each_crtc(crtc, dev) |
Chris Wilson | eb03355 | 2011-01-24 15:11:08 +0000 | [diff] [blame] | 5353 | if (crtc->funcs->reset) |
| 5354 | crtc->funcs->reset(crtc); |
| 5355 | |
Daniel Vetter | e4f6254 | 2015-07-09 23:44:35 +0200 | [diff] [blame] | 5356 | drm_for_each_encoder(encoder, dev) |
Chris Wilson | eb03355 | 2011-01-24 15:11:08 +0000 | [diff] [blame] | 5357 | if (encoder->funcs->reset) |
| 5358 | encoder->funcs->reset(encoder); |
| 5359 | |
Daniel Vetter | f8c2ba3 | 2015-07-29 08:32:43 +0200 | [diff] [blame] | 5360 | mutex_lock(&dev->mode_config.mutex); |
Dave Airlie | 4eebf60 | 2015-08-17 14:13:53 +1000 | [diff] [blame] | 5361 | drm_for_each_connector(connector, dev) |
Chris Wilson | eb03355 | 2011-01-24 15:11:08 +0000 | [diff] [blame] | 5362 | if (connector->funcs->reset) |
| 5363 | connector->funcs->reset(connector); |
Daniel Vetter | f8c2ba3 | 2015-07-29 08:32:43 +0200 | [diff] [blame] | 5364 | mutex_unlock(&dev->mode_config.mutex); |
Chris Wilson | eb03355 | 2011-01-24 15:11:08 +0000 | [diff] [blame] | 5365 | } |
| 5366 | EXPORT_SYMBOL(drm_mode_config_reset); |
Dave Airlie | ff72145b | 2011-02-07 12:16:14 +1000 | [diff] [blame] | 5367 | |
Daniel Vetter | c8e32cc | 2014-03-10 21:33:02 +0100 | [diff] [blame] | 5368 | /** |
| 5369 | * drm_mode_create_dumb_ioctl - create a dumb backing storage buffer |
| 5370 | * @dev: DRM device |
| 5371 | * @data: ioctl data |
| 5372 | * @file_priv: DRM file info |
| 5373 | * |
| 5374 | * This creates a new dumb buffer in the driver's backing storage manager (GEM, |
| 5375 | * TTM or something else entirely) and returns the resulting buffer handle. This |
| 5376 | * handle can then be wrapped up into a framebuffer modeset object. |
| 5377 | * |
| 5378 | * Note that userspace is not allowed to use such objects for render |
| 5379 | * acceleration - drivers must create their own private ioctls for such a use |
| 5380 | * case. |
| 5381 | * |
| 5382 | * Called by the user via ioctl. |
| 5383 | * |
| 5384 | * Returns: |
Daniel Vetter | 1a49863 | 2014-11-19 18:38:09 +0100 | [diff] [blame] | 5385 | * Zero on success, negative errno on failure. |
Daniel Vetter | c8e32cc | 2014-03-10 21:33:02 +0100 | [diff] [blame] | 5386 | */ |
Dave Airlie | ff72145b | 2011-02-07 12:16:14 +1000 | [diff] [blame] | 5387 | int drm_mode_create_dumb_ioctl(struct drm_device *dev, |
| 5388 | void *data, struct drm_file *file_priv) |
| 5389 | { |
| 5390 | struct drm_mode_create_dumb *args = data; |
David Herrmann | b28cd41 | 2014-01-20 20:09:55 +0100 | [diff] [blame] | 5391 | u32 cpp, stride, size; |
Dave Airlie | ff72145b | 2011-02-07 12:16:14 +1000 | [diff] [blame] | 5392 | |
| 5393 | if (!dev->driver->dumb_create) |
| 5394 | return -ENOSYS; |
David Herrmann | b28cd41 | 2014-01-20 20:09:55 +0100 | [diff] [blame] | 5395 | if (!args->width || !args->height || !args->bpp) |
| 5396 | return -EINVAL; |
| 5397 | |
| 5398 | /* overflow checks for 32bit size calculations */ |
David Herrmann | 00e7208 | 2014-08-24 19:23:26 +0200 | [diff] [blame] | 5399 | /* NOTE: DIV_ROUND_UP() can overflow */ |
David Herrmann | b28cd41 | 2014-01-20 20:09:55 +0100 | [diff] [blame] | 5400 | cpp = DIV_ROUND_UP(args->bpp, 8); |
David Herrmann | 00e7208 | 2014-08-24 19:23:26 +0200 | [diff] [blame] | 5401 | if (!cpp || cpp > 0xffffffffU / args->width) |
David Herrmann | b28cd41 | 2014-01-20 20:09:55 +0100 | [diff] [blame] | 5402 | return -EINVAL; |
| 5403 | stride = cpp * args->width; |
| 5404 | if (args->height > 0xffffffffU / stride) |
| 5405 | return -EINVAL; |
| 5406 | |
| 5407 | /* test for wrap-around */ |
| 5408 | size = args->height * stride; |
| 5409 | if (PAGE_ALIGN(size) == 0) |
| 5410 | return -EINVAL; |
| 5411 | |
Thierry Reding | f608595 | 2014-11-03 11:14:14 +0100 | [diff] [blame] | 5412 | /* |
| 5413 | * handle, pitch and size are output parameters. Zero them out to |
| 5414 | * prevent drivers from accidentally using uninitialized data. Since |
| 5415 | * not all existing userspace is clearing these fields properly we |
| 5416 | * cannot reject IOCTL with garbage in them. |
| 5417 | */ |
| 5418 | args->handle = 0; |
| 5419 | args->pitch = 0; |
| 5420 | args->size = 0; |
| 5421 | |
Dave Airlie | ff72145b | 2011-02-07 12:16:14 +1000 | [diff] [blame] | 5422 | return dev->driver->dumb_create(file_priv, dev, args); |
| 5423 | } |
| 5424 | |
Daniel Vetter | c8e32cc | 2014-03-10 21:33:02 +0100 | [diff] [blame] | 5425 | /** |
| 5426 | * drm_mode_mmap_dumb_ioctl - create an mmap offset for a dumb backing storage buffer |
| 5427 | * @dev: DRM device |
| 5428 | * @data: ioctl data |
| 5429 | * @file_priv: DRM file info |
| 5430 | * |
| 5431 | * Allocate an offset in the drm device node's address space to be able to |
| 5432 | * memory map a dumb buffer. |
| 5433 | * |
| 5434 | * Called by the user via ioctl. |
| 5435 | * |
| 5436 | * Returns: |
Daniel Vetter | 1a49863 | 2014-11-19 18:38:09 +0100 | [diff] [blame] | 5437 | * Zero on success, negative errno on failure. |
Daniel Vetter | c8e32cc | 2014-03-10 21:33:02 +0100 | [diff] [blame] | 5438 | */ |
Dave Airlie | ff72145b | 2011-02-07 12:16:14 +1000 | [diff] [blame] | 5439 | int drm_mode_mmap_dumb_ioctl(struct drm_device *dev, |
| 5440 | void *data, struct drm_file *file_priv) |
| 5441 | { |
| 5442 | struct drm_mode_map_dumb *args = data; |
| 5443 | |
| 5444 | /* call driver ioctl to get mmap offset */ |
| 5445 | if (!dev->driver->dumb_map_offset) |
| 5446 | return -ENOSYS; |
| 5447 | |
| 5448 | return dev->driver->dumb_map_offset(file_priv, dev, args->handle, &args->offset); |
| 5449 | } |
| 5450 | |
Daniel Vetter | c8e32cc | 2014-03-10 21:33:02 +0100 | [diff] [blame] | 5451 | /** |
| 5452 | * drm_mode_destroy_dumb_ioctl - destroy a dumb backing strage buffer |
| 5453 | * @dev: DRM device |
| 5454 | * @data: ioctl data |
| 5455 | * @file_priv: DRM file info |
| 5456 | * |
| 5457 | * This destroys the userspace handle for the given dumb backing storage buffer. |
| 5458 | * Since buffer objects must be reference counted in the kernel a buffer object |
| 5459 | * won't be immediately freed if a framebuffer modeset object still uses it. |
| 5460 | * |
| 5461 | * Called by the user via ioctl. |
| 5462 | * |
| 5463 | * Returns: |
Daniel Vetter | 1a49863 | 2014-11-19 18:38:09 +0100 | [diff] [blame] | 5464 | * Zero on success, negative errno on failure. |
Daniel Vetter | c8e32cc | 2014-03-10 21:33:02 +0100 | [diff] [blame] | 5465 | */ |
Dave Airlie | ff72145b | 2011-02-07 12:16:14 +1000 | [diff] [blame] | 5466 | int drm_mode_destroy_dumb_ioctl(struct drm_device *dev, |
| 5467 | void *data, struct drm_file *file_priv) |
| 5468 | { |
| 5469 | struct drm_mode_destroy_dumb *args = data; |
| 5470 | |
| 5471 | if (!dev->driver->dumb_destroy) |
| 5472 | return -ENOSYS; |
| 5473 | |
| 5474 | return dev->driver->dumb_destroy(file_priv, dev, args->handle); |
| 5475 | } |
Dave Airlie | 248dbc2 | 2011-11-29 20:02:54 +0000 | [diff] [blame] | 5476 | |
Daniel Vetter | c8e32cc | 2014-03-10 21:33:02 +0100 | [diff] [blame] | 5477 | /** |
Ville Syrjälä | 3c9855f | 2014-07-08 10:31:56 +0530 | [diff] [blame] | 5478 | * drm_rotation_simplify() - Try to simplify the rotation |
| 5479 | * @rotation: Rotation to be simplified |
| 5480 | * @supported_rotations: Supported rotations |
| 5481 | * |
| 5482 | * Attempt to simplify the rotation to a form that is supported. |
| 5483 | * Eg. if the hardware supports everything except DRM_REFLECT_X |
| 5484 | * one could call this function like this: |
| 5485 | * |
| 5486 | * drm_rotation_simplify(rotation, BIT(DRM_ROTATE_0) | |
| 5487 | * BIT(DRM_ROTATE_90) | BIT(DRM_ROTATE_180) | |
| 5488 | * BIT(DRM_ROTATE_270) | BIT(DRM_REFLECT_Y)); |
| 5489 | * |
| 5490 | * to eliminate the DRM_ROTATE_X flag. Depending on what kind of |
| 5491 | * transforms the hardware supports, this function may not |
| 5492 | * be able to produce a supported transform, so the caller should |
| 5493 | * check the result afterwards. |
| 5494 | */ |
| 5495 | unsigned int drm_rotation_simplify(unsigned int rotation, |
| 5496 | unsigned int supported_rotations) |
| 5497 | { |
| 5498 | if (rotation & ~supported_rotations) { |
| 5499 | rotation ^= BIT(DRM_REFLECT_X) | BIT(DRM_REFLECT_Y); |
Joonas Lahtinen | 14152c8 | 2015-10-01 10:00:58 +0300 | [diff] [blame] | 5500 | rotation = (rotation & DRM_REFLECT_MASK) | |
| 5501 | BIT((ffs(rotation & DRM_ROTATE_MASK) + 1) % 4); |
Ville Syrjälä | 3c9855f | 2014-07-08 10:31:56 +0530 | [diff] [blame] | 5502 | } |
| 5503 | |
| 5504 | return rotation; |
| 5505 | } |
| 5506 | EXPORT_SYMBOL(drm_rotation_simplify); |
| 5507 | |
| 5508 | /** |
Laurent Pinchart | 87d24fc | 2013-04-15 15:37:16 +0200 | [diff] [blame] | 5509 | * drm_mode_config_init - initialize DRM mode_configuration structure |
| 5510 | * @dev: DRM device |
| 5511 | * |
| 5512 | * Initialize @dev's mode_config structure, used for tracking the graphics |
| 5513 | * configuration of @dev. |
| 5514 | * |
| 5515 | * Since this initializes the modeset locks, no locking is possible. Which is no |
| 5516 | * problem, since this should happen single threaded at init time. It is the |
| 5517 | * driver's problem to ensure this guarantee. |
| 5518 | * |
| 5519 | */ |
| 5520 | void drm_mode_config_init(struct drm_device *dev) |
| 5521 | { |
| 5522 | mutex_init(&dev->mode_config.mutex); |
Rob Clark | 51fd371 | 2013-11-19 12:10:12 -0500 | [diff] [blame] | 5523 | drm_modeset_lock_init(&dev->mode_config.connection_mutex); |
Laurent Pinchart | 87d24fc | 2013-04-15 15:37:16 +0200 | [diff] [blame] | 5524 | mutex_init(&dev->mode_config.idr_mutex); |
| 5525 | mutex_init(&dev->mode_config.fb_lock); |
Daniel Stone | 8fb6e7a | 2015-04-20 19:22:54 +0100 | [diff] [blame] | 5526 | mutex_init(&dev->mode_config.blob_lock); |
Laurent Pinchart | 87d24fc | 2013-04-15 15:37:16 +0200 | [diff] [blame] | 5527 | INIT_LIST_HEAD(&dev->mode_config.fb_list); |
| 5528 | INIT_LIST_HEAD(&dev->mode_config.crtc_list); |
| 5529 | INIT_LIST_HEAD(&dev->mode_config.connector_list); |
| 5530 | INIT_LIST_HEAD(&dev->mode_config.encoder_list); |
| 5531 | INIT_LIST_HEAD(&dev->mode_config.property_list); |
| 5532 | INIT_LIST_HEAD(&dev->mode_config.property_blob_list); |
| 5533 | INIT_LIST_HEAD(&dev->mode_config.plane_list); |
| 5534 | idr_init(&dev->mode_config.crtc_idr); |
Dave Airlie | 138f9eb | 2014-10-20 16:17:17 +1000 | [diff] [blame] | 5535 | idr_init(&dev->mode_config.tile_idr); |
Maarten Lankhorst | 5fff80b | 2016-02-17 08:32:05 +0100 | [diff] [blame] | 5536 | ida_init(&dev->mode_config.connector_ida); |
Laurent Pinchart | 87d24fc | 2013-04-15 15:37:16 +0200 | [diff] [blame] | 5537 | |
| 5538 | drm_modeset_lock_all(dev); |
Rob Clark | 6b4959f | 2014-12-18 16:01:53 -0500 | [diff] [blame] | 5539 | drm_mode_create_standard_properties(dev); |
Laurent Pinchart | 87d24fc | 2013-04-15 15:37:16 +0200 | [diff] [blame] | 5540 | drm_modeset_unlock_all(dev); |
| 5541 | |
| 5542 | /* Just to be sure */ |
| 5543 | dev->mode_config.num_fb = 0; |
| 5544 | dev->mode_config.num_connector = 0; |
| 5545 | dev->mode_config.num_crtc = 0; |
| 5546 | dev->mode_config.num_encoder = 0; |
Matt Roper | e27dde3 | 2014-04-01 15:22:30 -0700 | [diff] [blame] | 5547 | dev->mode_config.num_overlay_plane = 0; |
| 5548 | dev->mode_config.num_total_plane = 0; |
Laurent Pinchart | 87d24fc | 2013-04-15 15:37:16 +0200 | [diff] [blame] | 5549 | } |
| 5550 | EXPORT_SYMBOL(drm_mode_config_init); |
| 5551 | |
| 5552 | /** |
| 5553 | * drm_mode_config_cleanup - free up DRM mode_config info |
| 5554 | * @dev: DRM device |
| 5555 | * |
| 5556 | * Free up all the connectors and CRTCs associated with this DRM device, then |
| 5557 | * free up the framebuffers and associated buffer objects. |
| 5558 | * |
| 5559 | * Note that since this /should/ happen single-threaded at driver/device |
| 5560 | * teardown time, no locking is required. It's the driver's job to ensure that |
| 5561 | * this guarantee actually holds true. |
| 5562 | * |
| 5563 | * FIXME: cleanup any dangling user buffer objects too |
| 5564 | */ |
| 5565 | void drm_mode_config_cleanup(struct drm_device *dev) |
| 5566 | { |
| 5567 | struct drm_connector *connector, *ot; |
| 5568 | struct drm_crtc *crtc, *ct; |
| 5569 | struct drm_encoder *encoder, *enct; |
| 5570 | struct drm_framebuffer *fb, *fbt; |
| 5571 | struct drm_property *property, *pt; |
| 5572 | struct drm_property_blob *blob, *bt; |
| 5573 | struct drm_plane *plane, *plt; |
| 5574 | |
| 5575 | list_for_each_entry_safe(encoder, enct, &dev->mode_config.encoder_list, |
| 5576 | head) { |
| 5577 | encoder->funcs->destroy(encoder); |
| 5578 | } |
| 5579 | |
| 5580 | list_for_each_entry_safe(connector, ot, |
| 5581 | &dev->mode_config.connector_list, head) { |
| 5582 | connector->funcs->destroy(connector); |
| 5583 | } |
| 5584 | |
| 5585 | list_for_each_entry_safe(property, pt, &dev->mode_config.property_list, |
| 5586 | head) { |
| 5587 | drm_property_destroy(dev, property); |
| 5588 | } |
| 5589 | |
Maarten Lankhorst | f35034f | 2016-03-22 15:42:14 +0100 | [diff] [blame] | 5590 | list_for_each_entry_safe(plane, plt, &dev->mode_config.plane_list, |
| 5591 | head) { |
| 5592 | plane->funcs->destroy(plane); |
| 5593 | } |
| 5594 | |
| 5595 | list_for_each_entry_safe(crtc, ct, &dev->mode_config.crtc_list, head) { |
| 5596 | crtc->funcs->destroy(crtc); |
| 5597 | } |
| 5598 | |
Laurent Pinchart | 87d24fc | 2013-04-15 15:37:16 +0200 | [diff] [blame] | 5599 | list_for_each_entry_safe(blob, bt, &dev->mode_config.property_blob_list, |
Daniel Stone | e2f5d2e | 2015-05-22 13:34:51 +0100 | [diff] [blame] | 5600 | head_global) { |
Daniel Stone | 6bcacf5 | 2015-04-20 19:22:55 +0100 | [diff] [blame] | 5601 | drm_property_unreference_blob(blob); |
Laurent Pinchart | 87d24fc | 2013-04-15 15:37:16 +0200 | [diff] [blame] | 5602 | } |
| 5603 | |
| 5604 | /* |
| 5605 | * Single-threaded teardown context, so it's not required to grab the |
| 5606 | * fb_lock to protect against concurrent fb_list access. Contrary, it |
| 5607 | * would actually deadlock with the drm_framebuffer_cleanup function. |
| 5608 | * |
| 5609 | * Also, if there are any framebuffers left, that's a driver leak now, |
| 5610 | * so politely WARN about this. |
| 5611 | */ |
| 5612 | WARN_ON(!list_empty(&dev->mode_config.fb_list)); |
| 5613 | list_for_each_entry_safe(fb, fbt, &dev->mode_config.fb_list, head) { |
Dave Airlie | d0f37cf | 2016-04-15 15:10:36 +1000 | [diff] [blame] | 5614 | drm_framebuffer_free(&fb->base.refcount); |
Laurent Pinchart | 87d24fc | 2013-04-15 15:37:16 +0200 | [diff] [blame] | 5615 | } |
| 5616 | |
Maarten Lankhorst | 5fff80b | 2016-02-17 08:32:05 +0100 | [diff] [blame] | 5617 | ida_destroy(&dev->mode_config.connector_ida); |
Dave Airlie | 138f9eb | 2014-10-20 16:17:17 +1000 | [diff] [blame] | 5618 | idr_destroy(&dev->mode_config.tile_idr); |
Laurent Pinchart | 87d24fc | 2013-04-15 15:37:16 +0200 | [diff] [blame] | 5619 | idr_destroy(&dev->mode_config.crtc_idr); |
Rob Clark | 51fd371 | 2013-11-19 12:10:12 -0500 | [diff] [blame] | 5620 | drm_modeset_lock_fini(&dev->mode_config.connection_mutex); |
Laurent Pinchart | 87d24fc | 2013-04-15 15:37:16 +0200 | [diff] [blame] | 5621 | } |
| 5622 | EXPORT_SYMBOL(drm_mode_config_cleanup); |
Ville Syrjälä | c1df5f3 | 2014-07-08 10:31:53 +0530 | [diff] [blame] | 5623 | |
| 5624 | struct drm_property *drm_mode_create_rotation_property(struct drm_device *dev, |
| 5625 | unsigned int supported_rotations) |
| 5626 | { |
| 5627 | static const struct drm_prop_enum_list props[] = { |
| 5628 | { DRM_ROTATE_0, "rotate-0" }, |
| 5629 | { DRM_ROTATE_90, "rotate-90" }, |
| 5630 | { DRM_ROTATE_180, "rotate-180" }, |
| 5631 | { DRM_ROTATE_270, "rotate-270" }, |
| 5632 | { DRM_REFLECT_X, "reflect-x" }, |
| 5633 | { DRM_REFLECT_Y, "reflect-y" }, |
| 5634 | }; |
| 5635 | |
| 5636 | return drm_property_create_bitmask(dev, 0, "rotation", |
| 5637 | props, ARRAY_SIZE(props), |
| 5638 | supported_rotations); |
| 5639 | } |
| 5640 | EXPORT_SYMBOL(drm_mode_create_rotation_property); |
Dave Airlie | 138f9eb | 2014-10-20 16:17:17 +1000 | [diff] [blame] | 5641 | |
| 5642 | /** |
| 5643 | * DOC: Tile group |
| 5644 | * |
| 5645 | * Tile groups are used to represent tiled monitors with a unique |
| 5646 | * integer identifier. Tiled monitors using DisplayID v1.3 have |
| 5647 | * a unique 8-byte handle, we store this in a tile group, so we |
| 5648 | * have a common identifier for all tiles in a monitor group. |
| 5649 | */ |
| 5650 | static void drm_tile_group_free(struct kref *kref) |
| 5651 | { |
| 5652 | struct drm_tile_group *tg = container_of(kref, struct drm_tile_group, refcount); |
| 5653 | struct drm_device *dev = tg->dev; |
| 5654 | mutex_lock(&dev->mode_config.idr_mutex); |
| 5655 | idr_remove(&dev->mode_config.tile_idr, tg->id); |
| 5656 | mutex_unlock(&dev->mode_config.idr_mutex); |
| 5657 | kfree(tg); |
| 5658 | } |
| 5659 | |
| 5660 | /** |
| 5661 | * drm_mode_put_tile_group - drop a reference to a tile group. |
| 5662 | * @dev: DRM device |
| 5663 | * @tg: tile group to drop reference to. |
| 5664 | * |
| 5665 | * drop reference to tile group and free if 0. |
| 5666 | */ |
| 5667 | void drm_mode_put_tile_group(struct drm_device *dev, |
| 5668 | struct drm_tile_group *tg) |
| 5669 | { |
| 5670 | kref_put(&tg->refcount, drm_tile_group_free); |
| 5671 | } |
| 5672 | |
| 5673 | /** |
| 5674 | * drm_mode_get_tile_group - get a reference to an existing tile group |
| 5675 | * @dev: DRM device |
| 5676 | * @topology: 8-bytes unique per monitor. |
| 5677 | * |
| 5678 | * Use the unique bytes to get a reference to an existing tile group. |
| 5679 | * |
| 5680 | * RETURNS: |
| 5681 | * tile group or NULL if not found. |
| 5682 | */ |
| 5683 | struct drm_tile_group *drm_mode_get_tile_group(struct drm_device *dev, |
| 5684 | char topology[8]) |
| 5685 | { |
| 5686 | struct drm_tile_group *tg; |
| 5687 | int id; |
| 5688 | mutex_lock(&dev->mode_config.idr_mutex); |
| 5689 | idr_for_each_entry(&dev->mode_config.tile_idr, tg, id) { |
| 5690 | if (!memcmp(tg->group_data, topology, 8)) { |
| 5691 | if (!kref_get_unless_zero(&tg->refcount)) |
| 5692 | tg = NULL; |
| 5693 | mutex_unlock(&dev->mode_config.idr_mutex); |
| 5694 | return tg; |
| 5695 | } |
| 5696 | } |
| 5697 | mutex_unlock(&dev->mode_config.idr_mutex); |
| 5698 | return NULL; |
| 5699 | } |
Rob Clark | 81ddd1b | 2015-03-27 13:01:52 -0400 | [diff] [blame] | 5700 | EXPORT_SYMBOL(drm_mode_get_tile_group); |
Dave Airlie | 138f9eb | 2014-10-20 16:17:17 +1000 | [diff] [blame] | 5701 | |
| 5702 | /** |
| 5703 | * drm_mode_create_tile_group - create a tile group from a displayid description |
| 5704 | * @dev: DRM device |
| 5705 | * @topology: 8-bytes unique per monitor. |
| 5706 | * |
| 5707 | * Create a tile group for the unique monitor, and get a unique |
| 5708 | * identifier for the tile group. |
| 5709 | * |
| 5710 | * RETURNS: |
| 5711 | * new tile group or error. |
| 5712 | */ |
| 5713 | struct drm_tile_group *drm_mode_create_tile_group(struct drm_device *dev, |
| 5714 | char topology[8]) |
| 5715 | { |
| 5716 | struct drm_tile_group *tg; |
| 5717 | int ret; |
| 5718 | |
| 5719 | tg = kzalloc(sizeof(*tg), GFP_KERNEL); |
| 5720 | if (!tg) |
| 5721 | return ERR_PTR(-ENOMEM); |
| 5722 | |
| 5723 | kref_init(&tg->refcount); |
| 5724 | memcpy(tg->group_data, topology, 8); |
| 5725 | tg->dev = dev; |
| 5726 | |
| 5727 | mutex_lock(&dev->mode_config.idr_mutex); |
| 5728 | ret = idr_alloc(&dev->mode_config.tile_idr, tg, 1, 0, GFP_KERNEL); |
| 5729 | if (ret >= 0) { |
| 5730 | tg->id = ret; |
| 5731 | } else { |
| 5732 | kfree(tg); |
| 5733 | tg = ERR_PTR(ret); |
| 5734 | } |
| 5735 | |
| 5736 | mutex_unlock(&dev->mode_config.idr_mutex); |
| 5737 | return tg; |
| 5738 | } |
Rob Clark | 81ddd1b | 2015-03-27 13:01:52 -0400 | [diff] [blame] | 5739 | EXPORT_SYMBOL(drm_mode_create_tile_group); |
Jyri Sarha | f8ed34a | 2016-06-07 15:09:14 +0300 | [diff] [blame] | 5740 | |
| 5741 | /** |
| 5742 | * drm_crtc_enable_color_mgmt - enable color management properties |
| 5743 | * @crtc: DRM CRTC |
| 5744 | * @degamma_lut_size: the size of the degamma lut (before CSC) |
| 5745 | * @has_ctm: whether to attach ctm_property for CSC matrix |
| 5746 | * @gamma_lut_size: the size of the gamma lut (after CSC) |
| 5747 | * |
| 5748 | * This function lets the driver enable the color correction |
| 5749 | * properties on a CRTC. This includes 3 degamma, csc and gamma |
| 5750 | * properties that userspace can set and 2 size properties to inform |
| 5751 | * the userspace of the lut sizes. Each of the properties are |
| 5752 | * optional. The gamma and degamma properties are only attached if |
| 5753 | * their size is not 0 and ctm_property is only attached if has_ctm is |
| 5754 | * true. |
| 5755 | */ |
| 5756 | void drm_crtc_enable_color_mgmt(struct drm_crtc *crtc, |
| 5757 | uint degamma_lut_size, |
| 5758 | bool has_ctm, |
| 5759 | uint gamma_lut_size) |
| 5760 | { |
| 5761 | struct drm_device *dev = crtc->dev; |
| 5762 | struct drm_mode_config *config = &dev->mode_config; |
| 5763 | |
| 5764 | if (degamma_lut_size) { |
| 5765 | drm_object_attach_property(&crtc->base, |
| 5766 | config->degamma_lut_property, 0); |
| 5767 | drm_object_attach_property(&crtc->base, |
| 5768 | config->degamma_lut_size_property, |
| 5769 | degamma_lut_size); |
| 5770 | } |
| 5771 | |
| 5772 | if (has_ctm) |
| 5773 | drm_object_attach_property(&crtc->base, |
| 5774 | config->ctm_property, 0); |
| 5775 | |
| 5776 | if (gamma_lut_size) { |
| 5777 | drm_object_attach_property(&crtc->base, |
| 5778 | config->gamma_lut_property, 0); |
| 5779 | drm_object_attach_property(&crtc->base, |
| 5780 | config->gamma_lut_size_property, |
| 5781 | gamma_lut_size); |
| 5782 | } |
| 5783 | } |
| 5784 | EXPORT_SYMBOL(drm_crtc_enable_color_mgmt); |