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