Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2006-2008 Intel Corporation |
| 3 | * Copyright (c) 2007 Dave Airlie <airlied@linux.ie> |
| 4 | * Copyright (c) 2008 Red Hat Inc. |
| 5 | * |
| 6 | * DRM core CRTC related functions |
| 7 | * |
| 8 | * Permission to use, copy, modify, distribute, and sell this software and its |
| 9 | * documentation for any purpose is hereby granted without fee, provided that |
| 10 | * the above copyright notice appear in all copies and that both that copyright |
| 11 | * notice and this permission notice appear in supporting documentation, and |
| 12 | * that the name of the copyright holders not be used in advertising or |
| 13 | * publicity pertaining to distribution of the software without specific, |
| 14 | * written prior permission. The copyright holders make no representations |
| 15 | * about the suitability of this software for any purpose. It is provided "as |
| 16 | * is" without express or implied warranty. |
| 17 | * |
| 18 | * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, |
| 19 | * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO |
| 20 | * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR |
| 21 | * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, |
| 22 | * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER |
| 23 | * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE |
| 24 | * OF THIS SOFTWARE. |
| 25 | * |
| 26 | * Authors: |
| 27 | * Keith Packard |
| 28 | * Eric Anholt <eric@anholt.net> |
| 29 | * Dave Airlie <airlied@linux.ie> |
| 30 | * Jesse Barnes <jesse.barnes@intel.com> |
| 31 | */ |
Ville Syrjälä | 6ba6d03 | 2013-06-10 11:15:10 +0300 | [diff] [blame] | 32 | #include <linux/ctype.h> |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 33 | #include <linux/list.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 34 | #include <linux/slab.h> |
Paul Gortmaker | 2d1a8a4 | 2011-08-30 18:16:33 -0400 | [diff] [blame] | 35 | #include <linux/export.h> |
David Howells | 760285e | 2012-10-02 18:01:07 +0100 | [diff] [blame] | 36 | #include <drm/drmP.h> |
| 37 | #include <drm/drm_crtc.h> |
| 38 | #include <drm/drm_edid.h> |
| 39 | #include <drm/drm_fourcc.h> |
Rob Clark | 51fd371 | 2013-11-19 12:10:12 -0500 | [diff] [blame] | 40 | #include <drm/drm_modeset_lock.h> |
Rob Clark | 88a48e2 | 2014-12-18 16:01:50 -0500 | [diff] [blame] | 41 | #include <drm/drm_atomic.h> |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 42 | |
Daniel Vetter | 8bd441b | 2014-01-23 15:35:24 +0100 | [diff] [blame] | 43 | #include "drm_crtc_internal.h" |
Daniel Vetter | 67d0ec4 | 2014-09-10 12:43:53 +0200 | [diff] [blame] | 44 | #include "drm_internal.h" |
Daniel Vetter | 8bd441b | 2014-01-23 15:35:24 +0100 | [diff] [blame] | 45 | |
Chris Wilson | 9a6f513 | 2015-02-25 13:45:26 +0000 | [diff] [blame] | 46 | static struct drm_framebuffer * |
| 47 | internal_framebuffer_create(struct drm_device *dev, |
Ville Syrjälä | 1eb83451 | 2015-11-11 19:11:29 +0200 | [diff] [blame] | 48 | const struct drm_mode_fb_cmd2 *r, |
Chris Wilson | 9a6f513 | 2015-02-25 13:45:26 +0000 | [diff] [blame] | 49 | struct drm_file *file_priv); |
Matt Roper | c394c2b | 2014-06-10 08:28:08 -0700 | [diff] [blame] | 50 | |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 51 | /* Avoid boilerplate. I'm tired of typing. */ |
| 52 | #define DRM_ENUM_NAME_FN(fnname, list) \ |
Ville Syrjälä | d20d317 | 2013-06-07 15:43:07 +0000 | [diff] [blame] | 53 | const char *fnname(int val) \ |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 54 | { \ |
| 55 | int i; \ |
| 56 | for (i = 0; i < ARRAY_SIZE(list); i++) { \ |
| 57 | if (list[i].type == val) \ |
| 58 | return list[i].name; \ |
| 59 | } \ |
| 60 | return "(unknown)"; \ |
| 61 | } |
| 62 | |
| 63 | /* |
| 64 | * Global properties |
| 65 | */ |
Thierry Reding | 4dfd909 | 2014-12-10 13:03:34 +0100 | [diff] [blame] | 66 | static const struct drm_prop_enum_list drm_dpms_enum_list[] = { |
| 67 | { DRM_MODE_DPMS_ON, "On" }, |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 68 | { DRM_MODE_DPMS_STANDBY, "Standby" }, |
| 69 | { DRM_MODE_DPMS_SUSPEND, "Suspend" }, |
| 70 | { DRM_MODE_DPMS_OFF, "Off" } |
| 71 | }; |
| 72 | |
| 73 | DRM_ENUM_NAME_FN(drm_get_dpms_name, drm_dpms_enum_list) |
| 74 | |
Thierry Reding | 4dfd909 | 2014-12-10 13:03:34 +0100 | [diff] [blame] | 75 | static const struct drm_prop_enum_list drm_plane_type_enum_list[] = { |
Rob Clark | 9922ab5 | 2014-04-01 20:16:57 -0400 | [diff] [blame] | 76 | { DRM_PLANE_TYPE_OVERLAY, "Overlay" }, |
| 77 | { DRM_PLANE_TYPE_PRIMARY, "Primary" }, |
| 78 | { DRM_PLANE_TYPE_CURSOR, "Cursor" }, |
| 79 | }; |
| 80 | |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 81 | /* |
| 82 | * Optional properties |
| 83 | */ |
Thierry Reding | 4dfd909 | 2014-12-10 13:03:34 +0100 | [diff] [blame] | 84 | static const struct drm_prop_enum_list drm_scaling_mode_enum_list[] = { |
Jesse Barnes | 53bd838 | 2009-07-01 10:04:40 -0700 | [diff] [blame] | 85 | { DRM_MODE_SCALE_NONE, "None" }, |
| 86 | { DRM_MODE_SCALE_FULLSCREEN, "Full" }, |
| 87 | { DRM_MODE_SCALE_CENTER, "Center" }, |
| 88 | { DRM_MODE_SCALE_ASPECT, "Full aspect" }, |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 89 | }; |
| 90 | |
Vandana Kannan | ff587e4 | 2014-06-11 10:46:48 +0530 | [diff] [blame] | 91 | static const struct drm_prop_enum_list drm_aspect_ratio_enum_list[] = { |
| 92 | { DRM_MODE_PICTURE_ASPECT_NONE, "Automatic" }, |
| 93 | { DRM_MODE_PICTURE_ASPECT_4_3, "4:3" }, |
| 94 | { DRM_MODE_PICTURE_ASPECT_16_9, "16:9" }, |
| 95 | }; |
| 96 | |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 97 | /* |
| 98 | * Non-global properties, but "required" for certain connectors. |
| 99 | */ |
Thierry Reding | 4dfd909 | 2014-12-10 13:03:34 +0100 | [diff] [blame] | 100 | static const struct drm_prop_enum_list drm_dvi_i_select_enum_list[] = { |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 101 | { DRM_MODE_SUBCONNECTOR_Automatic, "Automatic" }, /* DVI-I and TV-out */ |
| 102 | { DRM_MODE_SUBCONNECTOR_DVID, "DVI-D" }, /* DVI-I */ |
| 103 | { DRM_MODE_SUBCONNECTOR_DVIA, "DVI-A" }, /* DVI-I */ |
| 104 | }; |
| 105 | |
| 106 | DRM_ENUM_NAME_FN(drm_get_dvi_i_select_name, drm_dvi_i_select_enum_list) |
| 107 | |
Thierry Reding | 4dfd909 | 2014-12-10 13:03:34 +0100 | [diff] [blame] | 108 | static const struct drm_prop_enum_list drm_dvi_i_subconnector_enum_list[] = { |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 109 | { DRM_MODE_SUBCONNECTOR_Unknown, "Unknown" }, /* DVI-I and TV-out */ |
| 110 | { DRM_MODE_SUBCONNECTOR_DVID, "DVI-D" }, /* DVI-I */ |
| 111 | { DRM_MODE_SUBCONNECTOR_DVIA, "DVI-A" }, /* DVI-I */ |
| 112 | }; |
| 113 | |
| 114 | DRM_ENUM_NAME_FN(drm_get_dvi_i_subconnector_name, |
| 115 | drm_dvi_i_subconnector_enum_list) |
| 116 | |
Thierry Reding | 4dfd909 | 2014-12-10 13:03:34 +0100 | [diff] [blame] | 117 | static const struct drm_prop_enum_list drm_tv_select_enum_list[] = { |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 118 | { DRM_MODE_SUBCONNECTOR_Automatic, "Automatic" }, /* DVI-I and TV-out */ |
| 119 | { DRM_MODE_SUBCONNECTOR_Composite, "Composite" }, /* TV-out */ |
| 120 | { DRM_MODE_SUBCONNECTOR_SVIDEO, "SVIDEO" }, /* TV-out */ |
| 121 | { DRM_MODE_SUBCONNECTOR_Component, "Component" }, /* TV-out */ |
Francisco Jerez | aeaa1ad | 2009-08-02 04:19:19 +0200 | [diff] [blame] | 122 | { DRM_MODE_SUBCONNECTOR_SCART, "SCART" }, /* TV-out */ |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 123 | }; |
| 124 | |
| 125 | DRM_ENUM_NAME_FN(drm_get_tv_select_name, drm_tv_select_enum_list) |
| 126 | |
Thierry Reding | 4dfd909 | 2014-12-10 13:03:34 +0100 | [diff] [blame] | 127 | static const struct drm_prop_enum_list drm_tv_subconnector_enum_list[] = { |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 128 | { DRM_MODE_SUBCONNECTOR_Unknown, "Unknown" }, /* DVI-I and TV-out */ |
| 129 | { DRM_MODE_SUBCONNECTOR_Composite, "Composite" }, /* TV-out */ |
| 130 | { DRM_MODE_SUBCONNECTOR_SVIDEO, "SVIDEO" }, /* TV-out */ |
| 131 | { DRM_MODE_SUBCONNECTOR_Component, "Component" }, /* TV-out */ |
Francisco Jerez | aeaa1ad | 2009-08-02 04:19:19 +0200 | [diff] [blame] | 132 | { DRM_MODE_SUBCONNECTOR_SCART, "SCART" }, /* TV-out */ |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 133 | }; |
| 134 | |
| 135 | DRM_ENUM_NAME_FN(drm_get_tv_subconnector_name, |
| 136 | drm_tv_subconnector_enum_list) |
| 137 | |
Ville Syrjälä | d20d317 | 2013-06-07 15:43:07 +0000 | [diff] [blame] | 138 | static const struct drm_prop_enum_list drm_dirty_info_enum_list[] = { |
Jakob Bornecrantz | 884840a | 2009-12-03 23:25:47 +0000 | [diff] [blame] | 139 | { DRM_MODE_DIRTY_OFF, "Off" }, |
| 140 | { DRM_MODE_DIRTY_ON, "On" }, |
| 141 | { DRM_MODE_DIRTY_ANNOTATE, "Annotate" }, |
| 142 | }; |
| 143 | |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 144 | struct drm_conn_prop_enum_list { |
| 145 | int type; |
Ville Syrjälä | d20d317 | 2013-06-07 15:43:07 +0000 | [diff] [blame] | 146 | const char *name; |
Ilia Mirkin | b21e3af | 2013-08-07 22:34:48 -0400 | [diff] [blame] | 147 | struct ida ida; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 148 | }; |
| 149 | |
| 150 | /* |
| 151 | * Connector and encoder types. |
| 152 | */ |
Thierry Reding | 4dfd909 | 2014-12-10 13:03:34 +0100 | [diff] [blame] | 153 | static struct drm_conn_prop_enum_list drm_connector_enum_list[] = { |
| 154 | { DRM_MODE_CONNECTOR_Unknown, "Unknown" }, |
Ilia Mirkin | b21e3af | 2013-08-07 22:34:48 -0400 | [diff] [blame] | 155 | { DRM_MODE_CONNECTOR_VGA, "VGA" }, |
| 156 | { DRM_MODE_CONNECTOR_DVII, "DVI-I" }, |
| 157 | { DRM_MODE_CONNECTOR_DVID, "DVI-D" }, |
| 158 | { DRM_MODE_CONNECTOR_DVIA, "DVI-A" }, |
| 159 | { DRM_MODE_CONNECTOR_Composite, "Composite" }, |
| 160 | { DRM_MODE_CONNECTOR_SVIDEO, "SVIDEO" }, |
| 161 | { DRM_MODE_CONNECTOR_LVDS, "LVDS" }, |
| 162 | { DRM_MODE_CONNECTOR_Component, "Component" }, |
| 163 | { DRM_MODE_CONNECTOR_9PinDIN, "DIN" }, |
| 164 | { DRM_MODE_CONNECTOR_DisplayPort, "DP" }, |
| 165 | { DRM_MODE_CONNECTOR_HDMIA, "HDMI-A" }, |
| 166 | { DRM_MODE_CONNECTOR_HDMIB, "HDMI-B" }, |
| 167 | { DRM_MODE_CONNECTOR_TV, "TV" }, |
| 168 | { DRM_MODE_CONNECTOR_eDP, "eDP" }, |
| 169 | { DRM_MODE_CONNECTOR_VIRTUAL, "Virtual" }, |
Shobhit Kumar | b892327 | 2013-08-27 15:12:13 +0300 | [diff] [blame] | 170 | { DRM_MODE_CONNECTOR_DSI, "DSI" }, |
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, |
Dave Airlie | d0f37cf | 2016-04-15 15:10:36 +1000 | [diff] [blame] | 278 | bool register_obj, |
| 279 | void (*obj_free_cb)(struct kref *kref)) |
Dave Airlie | 2ee3945 | 2014-07-24 11:53:45 +1000 | [diff] [blame] | 280 | { |
| 281 | int ret; |
| 282 | |
| 283 | mutex_lock(&dev->mode_config.idr_mutex); |
| 284 | ret = idr_alloc(&dev->mode_config.crtc_idr, register_obj ? obj : NULL, 1, 0, GFP_KERNEL); |
| 285 | if (ret >= 0) { |
| 286 | /* |
| 287 | * Set up the object linking under the protection of the idr |
| 288 | * lock so that other users can't see inconsistent state. |
| 289 | */ |
| 290 | obj->id = ret; |
| 291 | obj->type = obj_type; |
Dave Airlie | d0f37cf | 2016-04-15 15:10:36 +1000 | [diff] [blame] | 292 | if (obj_free_cb) { |
| 293 | obj->free_cb = obj_free_cb; |
| 294 | kref_init(&obj->refcount); |
| 295 | } |
Dave Airlie | 2ee3945 | 2014-07-24 11:53:45 +1000 | [diff] [blame] | 296 | } |
| 297 | mutex_unlock(&dev->mode_config.idr_mutex); |
| 298 | |
| 299 | return ret < 0 ? ret : 0; |
| 300 | } |
| 301 | |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 302 | /** |
Daniel Vetter | 065a50ed | 2012-12-02 00:09:18 +0100 | [diff] [blame] | 303 | * drm_mode_object_get - allocate a new modeset identifier |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 304 | * @dev: DRM device |
Daniel Vetter | 065a50ed | 2012-12-02 00:09:18 +0100 | [diff] [blame] | 305 | * @obj: object pointer, used to generate unique ID |
| 306 | * @obj_type: object type |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 307 | * |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 308 | * 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] | 309 | * for tracking modes, CRTCs and connectors. Note that despite the _get postfix |
| 310 | * modeset identifiers are _not_ reference counted. Hence don't use this for |
| 311 | * reference counted modeset objects like framebuffers. |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 312 | * |
Daniel Vetter | c8e32cc | 2014-03-10 21:33:02 +0100 | [diff] [blame] | 313 | * Returns: |
Lukas Wunner | 3c67d83 | 2015-10-15 11:56:56 +0200 | [diff] [blame] | 314 | * Zero on success, error code on failure. |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 315 | */ |
Daniel Vetter | 8bd441b | 2014-01-23 15:35:24 +0100 | [diff] [blame] | 316 | int drm_mode_object_get(struct drm_device *dev, |
| 317 | struct drm_mode_object *obj, uint32_t obj_type) |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 318 | { |
Dave Airlie | d0f37cf | 2016-04-15 15:10:36 +1000 | [diff] [blame] | 319 | return drm_mode_object_get_reg(dev, obj, obj_type, true, NULL); |
Dave Airlie | 2ee3945 | 2014-07-24 11:53:45 +1000 | [diff] [blame] | 320 | } |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 321 | |
Dave Airlie | 2ee3945 | 2014-07-24 11:53:45 +1000 | [diff] [blame] | 322 | static void drm_mode_object_register(struct drm_device *dev, |
| 323 | struct drm_mode_object *obj) |
| 324 | { |
Jesse Barnes | ad2563c | 2009-01-19 17:21:45 +1000 | [diff] [blame] | 325 | mutex_lock(&dev->mode_config.idr_mutex); |
Dave Airlie | 2ee3945 | 2014-07-24 11:53:45 +1000 | [diff] [blame] | 326 | idr_replace(&dev->mode_config.crtc_idr, obj, obj->id); |
Jesse Barnes | ad2563c | 2009-01-19 17:21:45 +1000 | [diff] [blame] | 327 | mutex_unlock(&dev->mode_config.idr_mutex); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 328 | } |
| 329 | |
| 330 | /** |
Dave Airlie | 7c8f6d2 | 2016-04-15 15:10:32 +1000 | [diff] [blame] | 331 | * drm_mode_object_unregister - free a modeset identifer |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 332 | * @dev: DRM device |
Daniel Vetter | 065a50ed | 2012-12-02 00:09:18 +0100 | [diff] [blame] | 333 | * @object: object to free |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 334 | * |
Dave Airlie | 7c8f6d2 | 2016-04-15 15:10:32 +1000 | [diff] [blame] | 335 | * Free @id from @dev's unique identifier pool. |
| 336 | * This function can be called multiple times, and guards against |
| 337 | * multiple removals. |
| 338 | * These modeset identifiers are _not_ reference counted. Hence don't use this |
Daniel Vetter | c8e32cc | 2014-03-10 21:33:02 +0100 | [diff] [blame] | 339 | * for reference counted modeset objects like framebuffers. |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 340 | */ |
Dave Airlie | 7c8f6d2 | 2016-04-15 15:10:32 +1000 | [diff] [blame] | 341 | void drm_mode_object_unregister(struct drm_device *dev, |
Daniel Vetter | 8bd441b | 2014-01-23 15:35:24 +0100 | [diff] [blame] | 342 | struct drm_mode_object *object) |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 343 | { |
Jesse Barnes | ad2563c | 2009-01-19 17:21:45 +1000 | [diff] [blame] | 344 | mutex_lock(&dev->mode_config.idr_mutex); |
Dave Airlie | 7c8f6d2 | 2016-04-15 15:10:32 +1000 | [diff] [blame] | 345 | if (object->id) { |
| 346 | idr_remove(&dev->mode_config.crtc_idr, object->id); |
| 347 | object->id = 0; |
| 348 | } |
Jesse Barnes | ad2563c | 2009-01-19 17:21:45 +1000 | [diff] [blame] | 349 | mutex_unlock(&dev->mode_config.idr_mutex); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 350 | } |
| 351 | |
Rob Clark | 98f75de | 2014-05-30 11:37:03 -0400 | [diff] [blame] | 352 | static struct drm_mode_object *_object_find(struct drm_device *dev, |
| 353 | uint32_t id, uint32_t type) |
| 354 | { |
| 355 | struct drm_mode_object *obj = NULL; |
| 356 | |
| 357 | mutex_lock(&dev->mode_config.idr_mutex); |
| 358 | obj = idr_find(&dev->mode_config.crtc_idr, id); |
Daniel Vetter | 168c02e | 2014-07-24 12:12:45 +0200 | [diff] [blame] | 359 | if (obj && type != DRM_MODE_OBJECT_ANY && obj->type != type) |
| 360 | obj = NULL; |
| 361 | if (obj && obj->id != id) |
| 362 | obj = NULL; |
| 363 | /* don't leak out unref'd fb's */ |
Daniel Stone | 6bcacf5 | 2015-04-20 19:22:55 +0100 | [diff] [blame] | 364 | if (obj && |
Dave Airlie | cee26ac | 2016-04-15 15:10:37 +1000 | [diff] [blame] | 365 | obj->type == DRM_MODE_OBJECT_BLOB) |
Rob Clark | 98f75de | 2014-05-30 11:37:03 -0400 | [diff] [blame] | 366 | obj = NULL; |
Dave Airlie | 72fe90b | 2016-04-15 15:10:40 +1000 | [diff] [blame] | 367 | |
| 368 | if (obj && obj->free_cb) { |
| 369 | if (!kref_get_unless_zero(&obj->refcount)) |
| 370 | obj = NULL; |
| 371 | } |
Rob Clark | 98f75de | 2014-05-30 11:37:03 -0400 | [diff] [blame] | 372 | mutex_unlock(&dev->mode_config.idr_mutex); |
| 373 | |
| 374 | return obj; |
| 375 | } |
| 376 | |
Daniel Vetter | 786b99e | 2012-12-02 21:53:40 +0100 | [diff] [blame] | 377 | /** |
| 378 | * drm_mode_object_find - look up a drm object with static lifetime |
| 379 | * @dev: drm device |
| 380 | * @id: id of the mode object |
| 381 | * @type: type of the mode object |
| 382 | * |
Daniel Vetter | 05981422 | 2016-04-22 22:10:27 +0200 | [diff] [blame^] | 383 | * This function is used to look up a modeset object. It will acquire a |
| 384 | * reference for reference counted objects. This reference must be dropped again |
| 385 | * by callind drm_mode_object_unreference(). |
Daniel Vetter | 786b99e | 2012-12-02 21:53:40 +0100 | [diff] [blame] | 386 | */ |
Daniel Vetter | 7a9c906 | 2009-09-15 22:57:31 +0200 | [diff] [blame] | 387 | struct drm_mode_object *drm_mode_object_find(struct drm_device *dev, |
| 388 | uint32_t id, uint32_t type) |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 389 | { |
Jesse Barnes | ad2563c | 2009-01-19 17:21:45 +1000 | [diff] [blame] | 390 | struct drm_mode_object *obj = NULL; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 391 | |
Daniel Vetter | 786b99e | 2012-12-02 21:53:40 +0100 | [diff] [blame] | 392 | /* Framebuffers are reference counted and need their own lookup |
| 393 | * function.*/ |
Daniel Stone | 6bcacf5 | 2015-04-20 19:22:55 +0100 | [diff] [blame] | 394 | WARN_ON(type == DRM_MODE_OBJECT_FB || type == DRM_MODE_OBJECT_BLOB); |
Rob Clark | 98f75de | 2014-05-30 11:37:03 -0400 | [diff] [blame] | 395 | obj = _object_find(dev, id, type); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 396 | return obj; |
| 397 | } |
| 398 | EXPORT_SYMBOL(drm_mode_object_find); |
| 399 | |
Daniel Vetter | 05981422 | 2016-04-22 22:10:27 +0200 | [diff] [blame^] | 400 | /** |
| 401 | * drm_mode_object_unreference - decr the object refcnt |
| 402 | * @obj: mode_object |
| 403 | * |
| 404 | * This functions decrements the object's refcount if it is a refcounted modeset |
| 405 | * object. It is a no-op on any other object. This is used to drop references |
| 406 | * acquired with drm_mode_object_reference(). |
| 407 | */ |
Dave Airlie | d0f37cf | 2016-04-15 15:10:36 +1000 | [diff] [blame] | 408 | void drm_mode_object_unreference(struct drm_mode_object *obj) |
| 409 | { |
| 410 | if (obj->free_cb) { |
| 411 | DRM_DEBUG("OBJ ID: %d (%d)\n", obj->id, atomic_read(&obj->refcount.refcount)); |
| 412 | kref_put(&obj->refcount, obj->free_cb); |
| 413 | } |
| 414 | } |
| 415 | EXPORT_SYMBOL(drm_mode_object_unreference); |
| 416 | |
| 417 | /** |
Daniel Vetter | 05981422 | 2016-04-22 22:10:27 +0200 | [diff] [blame^] | 418 | * drm_mode_object_reference - incr the object refcnt |
Dave Airlie | d0f37cf | 2016-04-15 15:10:36 +1000 | [diff] [blame] | 419 | * @obj: mode_object |
| 420 | * |
Daniel Vetter | 05981422 | 2016-04-22 22:10:27 +0200 | [diff] [blame^] | 421 | * This functions increments the object's refcount if it is a refcounted modeset |
| 422 | * object. It is a no-op on any other object. References should be dropped again |
| 423 | * by calling drm_mode_object_unreference(). |
Dave Airlie | d0f37cf | 2016-04-15 15:10:36 +1000 | [diff] [blame] | 424 | */ |
| 425 | void drm_mode_object_reference(struct drm_mode_object *obj) |
| 426 | { |
| 427 | if (obj->free_cb) { |
| 428 | DRM_DEBUG("OBJ ID: %d (%d)\n", obj->id, atomic_read(&obj->refcount.refcount)); |
| 429 | kref_get(&obj->refcount); |
| 430 | } |
| 431 | } |
| 432 | EXPORT_SYMBOL(drm_mode_object_reference); |
| 433 | |
Dave Airlie | f55f1f9 | 2016-04-15 15:10:33 +1000 | [diff] [blame] | 434 | static void drm_framebuffer_free(struct kref *kref) |
| 435 | { |
| 436 | struct drm_framebuffer *fb = |
Dave Airlie | d0f37cf | 2016-04-15 15:10:36 +1000 | [diff] [blame] | 437 | container_of(kref, struct drm_framebuffer, base.refcount); |
Dave Airlie | f55f1f9 | 2016-04-15 15:10:33 +1000 | [diff] [blame] | 438 | struct drm_device *dev = fb->dev; |
| 439 | |
| 440 | /* |
| 441 | * The lookup idr holds a weak reference, which has not necessarily been |
| 442 | * removed at this point. Check for that. |
| 443 | */ |
Dave Airlie | 19ab3f8 | 2016-04-15 15:10:34 +1000 | [diff] [blame] | 444 | drm_mode_object_unregister(dev, &fb->base); |
Dave Airlie | f55f1f9 | 2016-04-15 15:10:33 +1000 | [diff] [blame] | 445 | |
| 446 | fb->funcs->destroy(fb); |
| 447 | } |
| 448 | |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 449 | /** |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 450 | * drm_framebuffer_init - initialize a framebuffer |
| 451 | * @dev: DRM device |
Daniel Vetter | 065a50ed | 2012-12-02 00:09:18 +0100 | [diff] [blame] | 452 | * @fb: framebuffer to be initialized |
| 453 | * @funcs: ... with these functions |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 454 | * |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 455 | * Allocates an ID for the framebuffer's parent mode object, sets its mode |
| 456 | * functions & device file and adds it to the master fd list. |
| 457 | * |
Daniel Vetter | 4b096ac | 2012-12-10 21:19:18 +0100 | [diff] [blame] | 458 | * IMPORTANT: |
| 459 | * This functions publishes the fb and makes it available for concurrent access |
| 460 | * by other users. Which means by this point the fb _must_ be fully set up - |
| 461 | * since all the fb attributes are invariant over its lifetime, no further |
| 462 | * locking but only correct reference counting is required. |
| 463 | * |
Daniel Vetter | c8e32cc | 2014-03-10 21:33:02 +0100 | [diff] [blame] | 464 | * Returns: |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 465 | * Zero on success, error code on failure. |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 466 | */ |
| 467 | int drm_framebuffer_init(struct drm_device *dev, struct drm_framebuffer *fb, |
| 468 | const struct drm_framebuffer_funcs *funcs) |
| 469 | { |
| 470 | int ret; |
| 471 | |
Daniel Vetter | 4b096ac | 2012-12-10 21:19:18 +0100 | [diff] [blame] | 472 | INIT_LIST_HEAD(&fb->filp_head); |
| 473 | fb->dev = dev; |
| 474 | fb->funcs = funcs; |
Rob Clark | f7eff60 | 2012-09-05 21:48:38 +0000 | [diff] [blame] | 475 | |
Dave Airlie | d0f37cf | 2016-04-15 15:10:36 +1000 | [diff] [blame] | 476 | ret = drm_mode_object_get_reg(dev, &fb->base, DRM_MODE_OBJECT_FB, |
Dave Airlie | 9cd4742 | 2016-04-15 15:10:38 +1000 | [diff] [blame] | 477 | false, drm_framebuffer_free); |
Ville Syrjälä | 6bfc56a | 2012-03-13 12:35:48 +0200 | [diff] [blame] | 478 | if (ret) |
Daniel Vetter | 4b096ac | 2012-12-10 21:19:18 +0100 | [diff] [blame] | 479 | goto out; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 480 | |
Dave Airlie | 9cd4742 | 2016-04-15 15:10:38 +1000 | [diff] [blame] | 481 | mutex_lock(&dev->mode_config.fb_lock); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 482 | dev->mode_config.num_fb++; |
| 483 | list_add(&fb->head, &dev->mode_config.fb_list); |
Dave Airlie | 2ddea3f | 2016-04-15 15:10:41 +1000 | [diff] [blame] | 484 | mutex_unlock(&dev->mode_config.fb_lock); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 485 | |
Dave Airlie | 9cd4742 | 2016-04-15 15:10:38 +1000 | [diff] [blame] | 486 | drm_mode_object_register(dev, &fb->base); |
Dave Airlie | 9cd4742 | 2016-04-15 15:10:38 +1000 | [diff] [blame] | 487 | out: |
Lukas Wunner | 3c67d83 | 2015-10-15 11:56:56 +0200 | [diff] [blame] | 488 | return ret; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 489 | } |
| 490 | EXPORT_SYMBOL(drm_framebuffer_init); |
| 491 | |
Rob Clark | f7eff60 | 2012-09-05 21:48:38 +0000 | [diff] [blame] | 492 | /** |
Daniel Vetter | 786b99e | 2012-12-02 21:53:40 +0100 | [diff] [blame] | 493 | * drm_framebuffer_lookup - look up a drm framebuffer and grab a reference |
| 494 | * @dev: drm device |
| 495 | * @id: id of the fb object |
| 496 | * |
| 497 | * If successful, this grabs an additional reference to the framebuffer - |
| 498 | * callers need to make sure to eventually unreference the returned framebuffer |
Daniel Vetter | c8e32cc | 2014-03-10 21:33:02 +0100 | [diff] [blame] | 499 | * again, using @drm_framebuffer_unreference. |
Daniel Vetter | 786b99e | 2012-12-02 21:53:40 +0100 | [diff] [blame] | 500 | */ |
| 501 | struct drm_framebuffer *drm_framebuffer_lookup(struct drm_device *dev, |
| 502 | uint32_t id) |
| 503 | { |
Dave Airlie | cee26ac | 2016-04-15 15:10:37 +1000 | [diff] [blame] | 504 | struct drm_mode_object *obj; |
| 505 | struct drm_framebuffer *fb = NULL; |
Daniel Vetter | 786b99e | 2012-12-02 21:53:40 +0100 | [diff] [blame] | 506 | |
Dave Airlie | cee26ac | 2016-04-15 15:10:37 +1000 | [diff] [blame] | 507 | obj = _object_find(dev, id, DRM_MODE_OBJECT_FB); |
Dave Airlie | 72fe90b | 2016-04-15 15:10:40 +1000 | [diff] [blame] | 508 | if (obj) |
Dave Airlie | cee26ac | 2016-04-15 15:10:37 +1000 | [diff] [blame] | 509 | fb = obj_to_fb(obj); |
Daniel Vetter | 786b99e | 2012-12-02 21:53:40 +0100 | [diff] [blame] | 510 | return fb; |
| 511 | } |
| 512 | EXPORT_SYMBOL(drm_framebuffer_lookup); |
| 513 | |
| 514 | /** |
Daniel Vetter | 3620636 | 2012-12-10 20:42:17 +0100 | [diff] [blame] | 515 | * drm_framebuffer_unregister_private - unregister a private fb from the lookup idr |
| 516 | * @fb: fb to unregister |
| 517 | * |
| 518 | * Drivers need to call this when cleaning up driver-private framebuffers, e.g. |
| 519 | * those used for fbdev. Note that the caller must hold a reference of it's own, |
| 520 | * i.e. the object may not be destroyed through this call (since it'll lead to a |
| 521 | * locking inversion). |
| 522 | */ |
| 523 | void drm_framebuffer_unregister_private(struct drm_framebuffer *fb) |
| 524 | { |
Daniel Vetter | a39a357 | 2015-08-25 15:45:11 +0200 | [diff] [blame] | 525 | struct drm_device *dev; |
| 526 | |
| 527 | if (!fb) |
| 528 | return; |
| 529 | |
| 530 | dev = fb->dev; |
Daniel Vetter | 2b677e8 | 2012-12-10 21:16:05 +0100 | [diff] [blame] | 531 | |
Daniel Vetter | 2b677e8 | 2012-12-10 21:16:05 +0100 | [diff] [blame] | 532 | /* Mark fb as reaped and drop idr ref. */ |
Dave Airlie | 19ab3f8 | 2016-04-15 15:10:34 +1000 | [diff] [blame] | 533 | drm_mode_object_unregister(dev, &fb->base); |
Daniel Vetter | 3620636 | 2012-12-10 20:42:17 +0100 | [diff] [blame] | 534 | } |
| 535 | EXPORT_SYMBOL(drm_framebuffer_unregister_private); |
| 536 | |
| 537 | /** |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 538 | * drm_framebuffer_cleanup - remove a framebuffer object |
| 539 | * @fb: framebuffer to remove |
| 540 | * |
Daniel Vetter | c8e32cc | 2014-03-10 21:33:02 +0100 | [diff] [blame] | 541 | * Cleanup framebuffer. This function is intended to be used from the drivers |
| 542 | * ->destroy callback. It can also be used to clean up driver private |
| 543 | * framebuffers embedded into a larger structure. |
Daniel Vetter | 3620636 | 2012-12-10 20:42:17 +0100 | [diff] [blame] | 544 | * |
| 545 | * Note that this function does not remove the fb from active usuage - if it is |
| 546 | * still used anywhere, hilarity can ensue since userspace could call getfb on |
| 547 | * the id and get back -EINVAL. Obviously no concern at driver unload time. |
| 548 | * |
| 549 | * Also, the framebuffer will not be removed from the lookup idr - for |
| 550 | * user-created framebuffers this will happen in in the rmfb ioctl. For |
| 551 | * driver-private objects (e.g. for fbdev) drivers need to explicitly call |
| 552 | * drm_framebuffer_unregister_private. |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 553 | */ |
| 554 | void drm_framebuffer_cleanup(struct drm_framebuffer *fb) |
| 555 | { |
| 556 | struct drm_device *dev = fb->dev; |
Daniel Vetter | 8faf6b1 | 2012-12-01 23:43:11 +0100 | [diff] [blame] | 557 | |
Daniel Vetter | 4b096ac | 2012-12-10 21:19:18 +0100 | [diff] [blame] | 558 | mutex_lock(&dev->mode_config.fb_lock); |
Rob Clark | f7eff60 | 2012-09-05 21:48:38 +0000 | [diff] [blame] | 559 | list_del(&fb->head); |
| 560 | dev->mode_config.num_fb--; |
Daniel Vetter | 4b096ac | 2012-12-10 21:19:18 +0100 | [diff] [blame] | 561 | mutex_unlock(&dev->mode_config.fb_lock); |
Rob Clark | f7eff60 | 2012-09-05 21:48:38 +0000 | [diff] [blame] | 562 | } |
| 563 | EXPORT_SYMBOL(drm_framebuffer_cleanup); |
| 564 | |
| 565 | /** |
| 566 | * drm_framebuffer_remove - remove and unreference a framebuffer object |
| 567 | * @fb: framebuffer to remove |
| 568 | * |
Rob Clark | f7eff60 | 2012-09-05 21:48:38 +0000 | [diff] [blame] | 569 | * 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] | 570 | * 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] | 571 | * passed-in framebuffer. Might take the modeset locks. |
| 572 | * |
| 573 | * Note that this function optimizes the cleanup away if the caller holds the |
| 574 | * last reference to the framebuffer. It is also guaranteed to not take the |
| 575 | * modeset locks in this case. |
Rob Clark | f7eff60 | 2012-09-05 21:48:38 +0000 | [diff] [blame] | 576 | */ |
| 577 | void drm_framebuffer_remove(struct drm_framebuffer *fb) |
| 578 | { |
Daniel Vetter | a39a357 | 2015-08-25 15:45:11 +0200 | [diff] [blame] | 579 | struct drm_device *dev; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 580 | struct drm_crtc *crtc; |
Jesse Barnes | 8cf5c91 | 2011-11-14 14:51:27 -0800 | [diff] [blame] | 581 | struct drm_plane *plane; |
Dave Airlie | 5ef5f72 | 2009-08-17 13:11:23 +1000 | [diff] [blame] | 582 | struct drm_mode_set set; |
| 583 | int ret; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 584 | |
Daniel Vetter | a39a357 | 2015-08-25 15:45:11 +0200 | [diff] [blame] | 585 | if (!fb) |
| 586 | return; |
| 587 | |
| 588 | dev = fb->dev; |
| 589 | |
Daniel Vetter | 4b096ac | 2012-12-10 21:19:18 +0100 | [diff] [blame] | 590 | WARN_ON(!list_empty(&fb->filp_head)); |
Daniel Vetter | 8faf6b1 | 2012-12-01 23:43:11 +0100 | [diff] [blame] | 591 | |
Daniel Vetter | b62584e | 2012-12-11 16:51:35 +0100 | [diff] [blame] | 592 | /* |
| 593 | * drm ABI mandates that we remove any deleted framebuffers from active |
| 594 | * useage. But since most sane clients only remove framebuffers they no |
| 595 | * longer need, try to optimize this away. |
| 596 | * |
| 597 | * Since we're holding a reference ourselves, observing a refcount of 1 |
| 598 | * means that we're the last holder and can skip it. Also, the refcount |
| 599 | * can never increase from 1 again, so we don't need any barriers or |
| 600 | * locks. |
| 601 | * |
| 602 | * Note that userspace could try to race with use and instate a new |
| 603 | * usage _after_ we've cleared all current ones. End result will be an |
| 604 | * in-use fb with fb-id == 0. Userspace is allowed to shoot its own foot |
| 605 | * in this manner. |
| 606 | */ |
Dave Airlie | 747a598 | 2016-04-15 15:10:35 +1000 | [diff] [blame] | 607 | if (drm_framebuffer_read_refcount(fb) > 1) { |
Daniel Vetter | b62584e | 2012-12-11 16:51:35 +0100 | [diff] [blame] | 608 | drm_modeset_lock_all(dev); |
| 609 | /* remove from any CRTC */ |
Daniel Vetter | 6295d60 | 2015-07-09 23:44:25 +0200 | [diff] [blame] | 610 | drm_for_each_crtc(crtc, dev) { |
Matt Roper | f4510a2 | 2014-04-01 15:22:40 -0700 | [diff] [blame] | 611 | if (crtc->primary->fb == fb) { |
Daniel Vetter | b62584e | 2012-12-11 16:51:35 +0100 | [diff] [blame] | 612 | /* should turn off the crtc */ |
| 613 | memset(&set, 0, sizeof(struct drm_mode_set)); |
| 614 | set.crtc = crtc; |
| 615 | set.fb = NULL; |
| 616 | ret = drm_mode_set_config_internal(&set); |
| 617 | if (ret) |
| 618 | DRM_ERROR("failed to reset crtc %p when fb was deleted\n", crtc); |
| 619 | } |
Dave Airlie | 5ef5f72 | 2009-08-17 13:11:23 +1000 | [diff] [blame] | 620 | } |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 621 | |
Daniel Vetter | 6295d60 | 2015-07-09 23:44:25 +0200 | [diff] [blame] | 622 | drm_for_each_plane(plane, dev) { |
Ville Syrjälä | 9125e61 | 2013-06-03 16:10:40 +0300 | [diff] [blame] | 623 | if (plane->fb == fb) |
| 624 | drm_plane_force_disable(plane); |
Jesse Barnes | 8cf5c91 | 2011-11-14 14:51:27 -0800 | [diff] [blame] | 625 | } |
Daniel Vetter | b62584e | 2012-12-11 16:51:35 +0100 | [diff] [blame] | 626 | drm_modeset_unlock_all(dev); |
Jesse Barnes | 8cf5c91 | 2011-11-14 14:51:27 -0800 | [diff] [blame] | 627 | } |
| 628 | |
Rob Clark | f7eff60 | 2012-09-05 21:48:38 +0000 | [diff] [blame] | 629 | drm_framebuffer_unreference(fb); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 630 | } |
Rob Clark | f7eff60 | 2012-09-05 21:48:38 +0000 | [diff] [blame] | 631 | EXPORT_SYMBOL(drm_framebuffer_remove); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 632 | |
Rob Clark | 51fd371 | 2013-11-19 12:10:12 -0500 | [diff] [blame] | 633 | DEFINE_WW_CLASS(crtc_ww_class); |
| 634 | |
Ville Syrjälä | fa3ab4c | 2015-12-08 18:41:53 +0200 | [diff] [blame] | 635 | static unsigned int drm_num_crtcs(struct drm_device *dev) |
| 636 | { |
| 637 | unsigned int num = 0; |
| 638 | struct drm_crtc *tmp; |
| 639 | |
| 640 | drm_for_each_crtc(tmp, dev) { |
| 641 | num++; |
| 642 | } |
| 643 | |
| 644 | return num; |
| 645 | } |
| 646 | |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 647 | /** |
Matt Roper | e13161a | 2014-04-01 15:22:38 -0700 | [diff] [blame] | 648 | * drm_crtc_init_with_planes - Initialise a new CRTC object with |
| 649 | * specified primary and cursor planes. |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 650 | * @dev: DRM device |
| 651 | * @crtc: CRTC object to init |
Matt Roper | e13161a | 2014-04-01 15:22:38 -0700 | [diff] [blame] | 652 | * @primary: Primary plane for CRTC |
| 653 | * @cursor: Cursor plane for CRTC |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 654 | * @funcs: callbacks for the new CRTC |
Ville Syrjälä | f988287 | 2015-12-09 16:19:31 +0200 | [diff] [blame] | 655 | * @name: printf style format string for the CRTC name, or NULL for default name |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 656 | * |
Ville Syrjälä | ad6f5c3 | 2013-06-05 12:39:55 +0000 | [diff] [blame] | 657 | * 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] | 658 | * |
Daniel Vetter | c8e32cc | 2014-03-10 21:33:02 +0100 | [diff] [blame] | 659 | * Returns: |
Ville Syrjälä | 6bfc56a | 2012-03-13 12:35:48 +0200 | [diff] [blame] | 660 | * Zero on success, error code on failure. |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 661 | */ |
Matt Roper | e13161a | 2014-04-01 15:22:38 -0700 | [diff] [blame] | 662 | int drm_crtc_init_with_planes(struct drm_device *dev, struct drm_crtc *crtc, |
| 663 | struct drm_plane *primary, |
Matt Roper | fc1d3e4 | 2014-06-10 08:28:11 -0700 | [diff] [blame] | 664 | struct drm_plane *cursor, |
Ville Syrjälä | f988287 | 2015-12-09 16:19:31 +0200 | [diff] [blame] | 665 | const struct drm_crtc_funcs *funcs, |
| 666 | const char *name, ...) |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 667 | { |
Rob Clark | 51fd371 | 2013-11-19 12:10:12 -0500 | [diff] [blame] | 668 | struct drm_mode_config *config = &dev->mode_config; |
Ville Syrjälä | 6bfc56a | 2012-03-13 12:35:48 +0200 | [diff] [blame] | 669 | int ret; |
| 670 | |
Benjamin Gaignard | 522cf91 | 2015-03-17 12:05:29 +0100 | [diff] [blame] | 671 | WARN_ON(primary && primary->type != DRM_PLANE_TYPE_PRIMARY); |
| 672 | WARN_ON(cursor && cursor->type != DRM_PLANE_TYPE_CURSOR); |
| 673 | |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 674 | crtc->dev = dev; |
| 675 | crtc->funcs = funcs; |
| 676 | |
Rob Clark | 51fd371 | 2013-11-19 12:10:12 -0500 | [diff] [blame] | 677 | drm_modeset_lock_init(&crtc->mutex); |
Ville Syrjälä | 6bfc56a | 2012-03-13 12:35:48 +0200 | [diff] [blame] | 678 | ret = drm_mode_object_get(dev, &crtc->base, DRM_MODE_OBJECT_CRTC); |
| 679 | if (ret) |
Daniel Vetter | baf698b | 2014-11-12 11:59:47 +0100 | [diff] [blame] | 680 | return ret; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 681 | |
Ville Syrjälä | fa3ab4c | 2015-12-08 18:41:53 +0200 | [diff] [blame] | 682 | if (name) { |
| 683 | va_list ap; |
| 684 | |
| 685 | va_start(ap, name); |
| 686 | crtc->name = kvasprintf(GFP_KERNEL, name, ap); |
| 687 | va_end(ap); |
| 688 | } else { |
| 689 | crtc->name = kasprintf(GFP_KERNEL, "crtc-%d", |
| 690 | drm_num_crtcs(dev)); |
| 691 | } |
| 692 | if (!crtc->name) { |
Dave Airlie | 7c8f6d2 | 2016-04-15 15:10:32 +1000 | [diff] [blame] | 693 | drm_mode_object_unregister(dev, &crtc->base); |
Ville Syrjälä | fa3ab4c | 2015-12-08 18:41:53 +0200 | [diff] [blame] | 694 | return -ENOMEM; |
| 695 | } |
| 696 | |
Paulo Zanoni | bffd9de0 | 2012-05-15 18:09:05 -0300 | [diff] [blame] | 697 | crtc->base.properties = &crtc->properties; |
| 698 | |
Rob Clark | 51fd371 | 2013-11-19 12:10:12 -0500 | [diff] [blame] | 699 | list_add_tail(&crtc->head, &config->crtc_list); |
| 700 | config->num_crtc++; |
Ville Syrjälä | 6bfc56a | 2012-03-13 12:35:48 +0200 | [diff] [blame] | 701 | |
Matt Roper | e13161a | 2014-04-01 15:22:38 -0700 | [diff] [blame] | 702 | crtc->primary = primary; |
Matt Roper | fc1d3e4 | 2014-06-10 08:28:11 -0700 | [diff] [blame] | 703 | crtc->cursor = cursor; |
Matt Roper | e13161a | 2014-04-01 15:22:38 -0700 | [diff] [blame] | 704 | if (primary) |
| 705 | primary->possible_crtcs = 1 << drm_crtc_index(crtc); |
Matt Roper | fc1d3e4 | 2014-06-10 08:28:11 -0700 | [diff] [blame] | 706 | if (cursor) |
| 707 | cursor->possible_crtcs = 1 << drm_crtc_index(crtc); |
Matt Roper | e13161a | 2014-04-01 15:22:38 -0700 | [diff] [blame] | 708 | |
Daniel Vetter | eab3bbe | 2015-01-22 16:36:21 +0100 | [diff] [blame] | 709 | if (drm_core_check_feature(dev, DRIVER_ATOMIC)) { |
| 710 | drm_object_attach_property(&crtc->base, config->prop_active, 0); |
Daniel Stone | 955f3c3 | 2015-05-25 19:11:52 +0100 | [diff] [blame] | 711 | drm_object_attach_property(&crtc->base, config->prop_mode_id, 0); |
Daniel Vetter | eab3bbe | 2015-01-22 16:36:21 +0100 | [diff] [blame] | 712 | } |
| 713 | |
Daniel Vetter | baf698b | 2014-11-12 11:59:47 +0100 | [diff] [blame] | 714 | return 0; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 715 | } |
Matt Roper | e13161a | 2014-04-01 15:22:38 -0700 | [diff] [blame] | 716 | EXPORT_SYMBOL(drm_crtc_init_with_planes); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 717 | |
| 718 | /** |
Ville Syrjälä | ad6f5c3 | 2013-06-05 12:39:55 +0000 | [diff] [blame] | 719 | * drm_crtc_cleanup - Clean up the core crtc usage |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 720 | * @crtc: CRTC to cleanup |
| 721 | * |
Ville Syrjälä | ad6f5c3 | 2013-06-05 12:39:55 +0000 | [diff] [blame] | 722 | * This function cleans up @crtc and removes it from the DRM mode setting |
| 723 | * core. Note that the function does *not* free the crtc structure itself, |
| 724 | * this is the responsibility of the caller. |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 725 | */ |
| 726 | void drm_crtc_cleanup(struct drm_crtc *crtc) |
| 727 | { |
| 728 | struct drm_device *dev = crtc->dev; |
| 729 | |
Sachin Kamat | 9e1c156 | 2012-11-19 09:44:56 +0000 | [diff] [blame] | 730 | kfree(crtc->gamma_store); |
| 731 | crtc->gamma_store = NULL; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 732 | |
Rob Clark | 51fd371 | 2013-11-19 12:10:12 -0500 | [diff] [blame] | 733 | drm_modeset_lock_fini(&crtc->mutex); |
| 734 | |
Dave Airlie | 7c8f6d2 | 2016-04-15 15:10:32 +1000 | [diff] [blame] | 735 | drm_mode_object_unregister(dev, &crtc->base); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 736 | list_del(&crtc->head); |
| 737 | dev->mode_config.num_crtc--; |
Thierry Reding | 3009c03 | 2014-11-25 12:09:49 +0100 | [diff] [blame] | 738 | |
| 739 | WARN_ON(crtc->state && !crtc->funcs->atomic_destroy_state); |
| 740 | if (crtc->state && crtc->funcs->atomic_destroy_state) |
| 741 | crtc->funcs->atomic_destroy_state(crtc, crtc->state); |
Thierry Reding | a18c0af | 2014-12-10 11:38:49 +0100 | [diff] [blame] | 742 | |
Ville Syrjälä | fa3ab4c | 2015-12-08 18:41:53 +0200 | [diff] [blame] | 743 | kfree(crtc->name); |
| 744 | |
Thierry Reding | a18c0af | 2014-12-10 11:38:49 +0100 | [diff] [blame] | 745 | memset(crtc, 0, sizeof(*crtc)); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 746 | } |
| 747 | EXPORT_SYMBOL(drm_crtc_cleanup); |
| 748 | |
| 749 | /** |
Russell King | db5f7a6 | 2014-01-02 21:27:33 +0000 | [diff] [blame] | 750 | * drm_crtc_index - find the index of a registered CRTC |
| 751 | * @crtc: CRTC to find index for |
| 752 | * |
| 753 | * Given a registered CRTC, return the index of that CRTC within a DRM |
| 754 | * device's list of CRTCs. |
| 755 | */ |
| 756 | unsigned int drm_crtc_index(struct drm_crtc *crtc) |
| 757 | { |
| 758 | unsigned int index = 0; |
| 759 | struct drm_crtc *tmp; |
| 760 | |
Daniel Vetter | e4f6254 | 2015-07-09 23:44:35 +0200 | [diff] [blame] | 761 | drm_for_each_crtc(tmp, crtc->dev) { |
Russell King | db5f7a6 | 2014-01-02 21:27:33 +0000 | [diff] [blame] | 762 | if (tmp == crtc) |
| 763 | return index; |
| 764 | |
| 765 | index++; |
| 766 | } |
| 767 | |
| 768 | BUG(); |
| 769 | } |
| 770 | EXPORT_SYMBOL(drm_crtc_index); |
| 771 | |
Lespiau, Damien | 86f422d | 2013-08-20 00:53:06 +0100 | [diff] [blame] | 772 | /* |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 773 | * drm_mode_remove - remove and free a mode |
| 774 | * @connector: connector list to modify |
| 775 | * @mode: mode to remove |
| 776 | * |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 777 | * Remove @mode from @connector's mode list, then free it. |
| 778 | */ |
Lespiau, Damien | 86f422d | 2013-08-20 00:53:06 +0100 | [diff] [blame] | 779 | static void drm_mode_remove(struct drm_connector *connector, |
| 780 | struct drm_display_mode *mode) |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 781 | { |
| 782 | list_del(&mode->head); |
Sascha Hauer | 554f1d7 | 2012-02-01 11:38:19 +0100 | [diff] [blame] | 783 | drm_mode_destroy(connector->dev, mode); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 784 | } |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 785 | |
| 786 | /** |
Boris Brezillon | b5571e9 | 2014-07-22 12:09:10 +0200 | [diff] [blame] | 787 | * drm_display_info_set_bus_formats - set the supported bus formats |
| 788 | * @info: display info to store bus formats in |
Boris Brezillon | e37bfa1 | 2015-01-23 21:09:30 +0100 | [diff] [blame] | 789 | * @formats: array containing the supported bus formats |
| 790 | * @num_formats: the number of entries in the fmts array |
Boris Brezillon | b5571e9 | 2014-07-22 12:09:10 +0200 | [diff] [blame] | 791 | * |
| 792 | * Store the supported bus formats in display info structure. |
| 793 | * See MEDIA_BUS_FMT_* definitions in include/uapi/linux/media-bus-format.h for |
| 794 | * a full list of available formats. |
| 795 | */ |
| 796 | int drm_display_info_set_bus_formats(struct drm_display_info *info, |
| 797 | const u32 *formats, |
| 798 | unsigned int num_formats) |
| 799 | { |
| 800 | u32 *fmts = NULL; |
| 801 | |
| 802 | if (!formats && num_formats) |
| 803 | return -EINVAL; |
| 804 | |
| 805 | if (formats && num_formats) { |
| 806 | fmts = kmemdup(formats, sizeof(*formats) * num_formats, |
| 807 | GFP_KERNEL); |
Dan Carpenter | 944579c | 2015-01-28 09:43:35 +0300 | [diff] [blame] | 808 | if (!fmts) |
Boris Brezillon | b5571e9 | 2014-07-22 12:09:10 +0200 | [diff] [blame] | 809 | return -ENOMEM; |
| 810 | } |
| 811 | |
| 812 | kfree(info->bus_formats); |
| 813 | info->bus_formats = fmts; |
| 814 | info->num_bus_formats = num_formats; |
| 815 | |
| 816 | return 0; |
| 817 | } |
| 818 | EXPORT_SYMBOL(drm_display_info_set_bus_formats); |
| 819 | |
| 820 | /** |
Chris Wilson | eaf99c7 | 2014-08-06 10:08:32 +0200 | [diff] [blame] | 821 | * drm_connector_get_cmdline_mode - reads the user's cmdline mode |
| 822 | * @connector: connector to quwery |
Chris Wilson | eaf99c7 | 2014-08-06 10:08:32 +0200 | [diff] [blame] | 823 | * |
| 824 | * The kernel supports per-connector configration of its consoles through |
| 825 | * use of the video= parameter. This function parses that option and |
| 826 | * extracts the user's specified mode (or enable/disable status) for a |
| 827 | * particular connector. This is typically only used during the early fbdev |
| 828 | * setup. |
| 829 | */ |
| 830 | static void drm_connector_get_cmdline_mode(struct drm_connector *connector) |
| 831 | { |
| 832 | struct drm_cmdline_mode *mode = &connector->cmdline_mode; |
| 833 | char *option = NULL; |
| 834 | |
| 835 | if (fb_get_options(connector->name, &option)) |
| 836 | return; |
| 837 | |
| 838 | if (!drm_mode_parse_command_line_for_connector(option, |
| 839 | connector, |
| 840 | mode)) |
| 841 | return; |
| 842 | |
| 843 | if (mode->force) { |
| 844 | const char *s; |
| 845 | |
| 846 | switch (mode->force) { |
| 847 | case DRM_FORCE_OFF: |
| 848 | s = "OFF"; |
| 849 | break; |
| 850 | case DRM_FORCE_ON_DIGITAL: |
| 851 | s = "ON - dig"; |
| 852 | break; |
| 853 | default: |
| 854 | case DRM_FORCE_ON: |
| 855 | s = "ON"; |
| 856 | break; |
| 857 | } |
| 858 | |
| 859 | DRM_INFO("forcing %s connector %s\n", connector->name, s); |
| 860 | connector->force = mode->force; |
| 861 | } |
| 862 | |
| 863 | DRM_DEBUG_KMS("cmdline mode for connector %s %dx%d@%dHz%s%s%s\n", |
| 864 | connector->name, |
| 865 | mode->xres, mode->yres, |
| 866 | mode->refresh_specified ? mode->refresh : 60, |
| 867 | mode->rb ? " reduced blanking" : "", |
| 868 | mode->margins ? " with margins" : "", |
| 869 | mode->interlace ? " interlaced" : ""); |
| 870 | } |
| 871 | |
| 872 | /** |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 873 | * drm_connector_init - Init a preallocated connector |
| 874 | * @dev: DRM device |
| 875 | * @connector: the connector to init |
| 876 | * @funcs: callbacks for this connector |
Daniel Vetter | 065a50ed | 2012-12-02 00:09:18 +0100 | [diff] [blame] | 877 | * @connector_type: user visible type of the connector |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 878 | * |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 879 | * Initialises a preallocated connector. Connectors should be |
| 880 | * subclassed as part of driver connector objects. |
Ville Syrjälä | 6bfc56a | 2012-03-13 12:35:48 +0200 | [diff] [blame] | 881 | * |
Daniel Vetter | c8e32cc | 2014-03-10 21:33:02 +0100 | [diff] [blame] | 882 | * Returns: |
Ville Syrjälä | 6bfc56a | 2012-03-13 12:35:48 +0200 | [diff] [blame] | 883 | * Zero on success, error code on failure. |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 884 | */ |
Ville Syrjälä | 6bfc56a | 2012-03-13 12:35:48 +0200 | [diff] [blame] | 885 | int drm_connector_init(struct drm_device *dev, |
| 886 | struct drm_connector *connector, |
| 887 | const struct drm_connector_funcs *funcs, |
| 888 | int connector_type) |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 889 | { |
Rob Clark | ae16c59 | 2014-12-18 16:01:54 -0500 | [diff] [blame] | 890 | struct drm_mode_config *config = &dev->mode_config; |
Ville Syrjälä | 6bfc56a | 2012-03-13 12:35:48 +0200 | [diff] [blame] | 891 | int ret; |
Ilia Mirkin | b21e3af | 2013-08-07 22:34:48 -0400 | [diff] [blame] | 892 | struct ida *connector_ida = |
| 893 | &drm_connector_enum_list[connector_type].ida; |
Ville Syrjälä | 6bfc56a | 2012-03-13 12:35:48 +0200 | [diff] [blame] | 894 | |
Daniel Vetter | 8484990 | 2012-12-02 00:28:11 +0100 | [diff] [blame] | 895 | drm_modeset_lock_all(dev); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 896 | |
Dave Airlie | d0f37cf | 2016-04-15 15:10:36 +1000 | [diff] [blame] | 897 | ret = drm_mode_object_get_reg(dev, &connector->base, DRM_MODE_OBJECT_CONNECTOR, false, NULL); |
Ville Syrjälä | 6bfc56a | 2012-03-13 12:35:48 +0200 | [diff] [blame] | 898 | if (ret) |
Jani Nikula | 2abdd31 | 2014-05-14 16:58:19 +0300 | [diff] [blame] | 899 | goto out_unlock; |
Ville Syrjälä | 6bfc56a | 2012-03-13 12:35:48 +0200 | [diff] [blame] | 900 | |
Paulo Zanoni | 7e3bdf4 | 2012-05-15 18:09:01 -0300 | [diff] [blame] | 901 | connector->base.properties = &connector->properties; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 902 | connector->dev = dev; |
| 903 | connector->funcs = funcs; |
Maarten Lankhorst | 5fff80b | 2016-02-17 08:32:05 +0100 | [diff] [blame] | 904 | |
| 905 | connector->connector_id = ida_simple_get(&config->connector_ida, 0, 0, GFP_KERNEL); |
| 906 | if (connector->connector_id < 0) { |
| 907 | ret = connector->connector_id; |
| 908 | goto out_put; |
| 909 | } |
| 910 | |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 911 | connector->connector_type = connector_type; |
| 912 | connector->connector_type_id = |
Ilia Mirkin | b21e3af | 2013-08-07 22:34:48 -0400 | [diff] [blame] | 913 | ida_simple_get(connector_ida, 1, 0, GFP_KERNEL); |
| 914 | if (connector->connector_type_id < 0) { |
| 915 | ret = connector->connector_type_id; |
Maarten Lankhorst | 5fff80b | 2016-02-17 08:32:05 +0100 | [diff] [blame] | 916 | goto out_put_id; |
Ilia Mirkin | b21e3af | 2013-08-07 22:34:48 -0400 | [diff] [blame] | 917 | } |
Jani Nikula | 2abdd31 | 2014-05-14 16:58:19 +0300 | [diff] [blame] | 918 | connector->name = |
| 919 | kasprintf(GFP_KERNEL, "%s-%d", |
| 920 | drm_connector_enum_list[connector_type].name, |
| 921 | connector->connector_type_id); |
| 922 | if (!connector->name) { |
| 923 | ret = -ENOMEM; |
Maarten Lankhorst | 5fff80b | 2016-02-17 08:32:05 +0100 | [diff] [blame] | 924 | goto out_put_type_id; |
Jani Nikula | 2abdd31 | 2014-05-14 16:58:19 +0300 | [diff] [blame] | 925 | } |
| 926 | |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 927 | INIT_LIST_HEAD(&connector->probed_modes); |
| 928 | INIT_LIST_HEAD(&connector->modes); |
| 929 | connector->edid_blob_ptr = NULL; |
Daniel Vetter | 5e2cb2f | 2012-10-23 18:23:35 +0000 | [diff] [blame] | 930 | connector->status = connector_status_unknown; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 931 | |
Chris Wilson | eaf99c7 | 2014-08-06 10:08:32 +0200 | [diff] [blame] | 932 | drm_connector_get_cmdline_mode(connector); |
| 933 | |
Daniel Vetter | c7eb76f | 2014-11-19 18:38:06 +0100 | [diff] [blame] | 934 | /* We should add connectors at the end to avoid upsetting the connector |
| 935 | * index too much. */ |
Rob Clark | ae16c59 | 2014-12-18 16:01:54 -0500 | [diff] [blame] | 936 | list_add_tail(&connector->head, &config->connector_list); |
| 937 | config->num_connector++; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 938 | |
Thomas Hellstrom | a7331e5 | 2011-10-22 10:36:19 +0200 | [diff] [blame] | 939 | if (connector_type != DRM_MODE_CONNECTOR_VIRTUAL) |
Rob Clark | 5849556 | 2012-10-11 20:50:56 -0500 | [diff] [blame] | 940 | drm_object_attach_property(&connector->base, |
Rob Clark | ae16c59 | 2014-12-18 16:01:54 -0500 | [diff] [blame] | 941 | config->edid_property, |
Thomas Hellstrom | a7331e5 | 2011-10-22 10:36:19 +0200 | [diff] [blame] | 942 | 0); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 943 | |
Rob Clark | 5849556 | 2012-10-11 20:50:56 -0500 | [diff] [blame] | 944 | drm_object_attach_property(&connector->base, |
Rob Clark | ae16c59 | 2014-12-18 16:01:54 -0500 | [diff] [blame] | 945 | config->dpms_property, 0); |
| 946 | |
| 947 | if (drm_core_check_feature(dev, DRIVER_ATOMIC)) { |
| 948 | drm_object_attach_property(&connector->base, config->prop_crtc_id, 0); |
| 949 | } |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 950 | |
Thomas Wood | 30f6570 | 2014-06-18 17:52:32 +0100 | [diff] [blame] | 951 | connector->debugfs_entry = NULL; |
Maarten Lankhorst | 5fff80b | 2016-02-17 08:32:05 +0100 | [diff] [blame] | 952 | out_put_type_id: |
| 953 | if (ret) |
| 954 | ida_remove(connector_ida, connector->connector_type_id); |
| 955 | out_put_id: |
| 956 | if (ret) |
| 957 | ida_remove(&config->connector_ida, connector->connector_id); |
Jani Nikula | 2abdd31 | 2014-05-14 16:58:19 +0300 | [diff] [blame] | 958 | out_put: |
| 959 | if (ret) |
Dave Airlie | 7c8f6d2 | 2016-04-15 15:10:32 +1000 | [diff] [blame] | 960 | drm_mode_object_unregister(dev, &connector->base); |
Jani Nikula | 2abdd31 | 2014-05-14 16:58:19 +0300 | [diff] [blame] | 961 | |
| 962 | out_unlock: |
Daniel Vetter | 8484990 | 2012-12-02 00:28:11 +0100 | [diff] [blame] | 963 | drm_modeset_unlock_all(dev); |
Ville Syrjälä | 6bfc56a | 2012-03-13 12:35:48 +0200 | [diff] [blame] | 964 | |
| 965 | return ret; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 966 | } |
| 967 | EXPORT_SYMBOL(drm_connector_init); |
| 968 | |
| 969 | /** |
| 970 | * drm_connector_cleanup - cleans up an initialised connector |
| 971 | * @connector: connector to cleanup |
| 972 | * |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 973 | * Cleans up the connector but doesn't free the object. |
| 974 | */ |
| 975 | void drm_connector_cleanup(struct drm_connector *connector) |
| 976 | { |
| 977 | struct drm_device *dev = connector->dev; |
| 978 | struct drm_display_mode *mode, *t; |
| 979 | |
Dave Airlie | 40d9b04 | 2014-10-20 16:29:33 +1000 | [diff] [blame] | 980 | if (connector->tile_group) { |
| 981 | drm_mode_put_tile_group(dev, connector->tile_group); |
| 982 | connector->tile_group = NULL; |
| 983 | } |
| 984 | |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 985 | list_for_each_entry_safe(mode, t, &connector->probed_modes, head) |
| 986 | drm_mode_remove(connector, mode); |
| 987 | |
| 988 | list_for_each_entry_safe(mode, t, &connector->modes, head) |
| 989 | drm_mode_remove(connector, mode); |
| 990 | |
Ilia Mirkin | b21e3af | 2013-08-07 22:34:48 -0400 | [diff] [blame] | 991 | ida_remove(&drm_connector_enum_list[connector->connector_type].ida, |
| 992 | connector->connector_type_id); |
| 993 | |
Maarten Lankhorst | 5fff80b | 2016-02-17 08:32:05 +0100 | [diff] [blame] | 994 | ida_remove(&dev->mode_config.connector_ida, |
| 995 | connector->connector_id); |
| 996 | |
Boris Brezillon | b5571e9 | 2014-07-22 12:09:10 +0200 | [diff] [blame] | 997 | kfree(connector->display_info.bus_formats); |
Dave Airlie | 7c8f6d2 | 2016-04-15 15:10:32 +1000 | [diff] [blame] | 998 | drm_mode_object_unregister(dev, &connector->base); |
Jani Nikula | 2abdd31 | 2014-05-14 16:58:19 +0300 | [diff] [blame] | 999 | kfree(connector->name); |
| 1000 | connector->name = NULL; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 1001 | list_del(&connector->head); |
Joonyoung Shim | 6380c50 | 2011-08-27 02:06:21 +0000 | [diff] [blame] | 1002 | dev->mode_config.num_connector--; |
Thierry Reding | 3009c03 | 2014-11-25 12:09:49 +0100 | [diff] [blame] | 1003 | |
| 1004 | WARN_ON(connector->state && !connector->funcs->atomic_destroy_state); |
| 1005 | if (connector->state && connector->funcs->atomic_destroy_state) |
| 1006 | connector->funcs->atomic_destroy_state(connector, |
| 1007 | connector->state); |
Thierry Reding | a18c0af | 2014-12-10 11:38:49 +0100 | [diff] [blame] | 1008 | |
| 1009 | memset(connector, 0, sizeof(*connector)); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 1010 | } |
| 1011 | EXPORT_SYMBOL(drm_connector_cleanup); |
| 1012 | |
Daniel Vetter | c8e32cc | 2014-03-10 21:33:02 +0100 | [diff] [blame] | 1013 | /** |
Thomas Wood | 34ea3d3 | 2014-05-29 16:57:41 +0100 | [diff] [blame] | 1014 | * drm_connector_register - register a connector |
| 1015 | * @connector: the connector to register |
| 1016 | * |
| 1017 | * Register userspace interfaces for a connector |
| 1018 | * |
| 1019 | * Returns: |
| 1020 | * Zero on success, error code on failure. |
| 1021 | */ |
| 1022 | int drm_connector_register(struct drm_connector *connector) |
| 1023 | { |
Thomas Wood | 30f6570 | 2014-06-18 17:52:32 +0100 | [diff] [blame] | 1024 | int ret; |
| 1025 | |
Dave Airlie | 2ee3945 | 2014-07-24 11:53:45 +1000 | [diff] [blame] | 1026 | drm_mode_object_register(connector->dev, &connector->base); |
| 1027 | |
Thomas Wood | 30f6570 | 2014-06-18 17:52:32 +0100 | [diff] [blame] | 1028 | ret = drm_sysfs_connector_add(connector); |
| 1029 | if (ret) |
| 1030 | return ret; |
| 1031 | |
| 1032 | ret = drm_debugfs_connector_add(connector); |
| 1033 | if (ret) { |
| 1034 | drm_sysfs_connector_remove(connector); |
| 1035 | return ret; |
| 1036 | } |
| 1037 | |
| 1038 | return 0; |
Thomas Wood | 34ea3d3 | 2014-05-29 16:57:41 +0100 | [diff] [blame] | 1039 | } |
| 1040 | EXPORT_SYMBOL(drm_connector_register); |
| 1041 | |
| 1042 | /** |
| 1043 | * drm_connector_unregister - unregister a connector |
| 1044 | * @connector: the connector to unregister |
| 1045 | * |
| 1046 | * Unregister userspace interfaces for a connector |
| 1047 | */ |
| 1048 | void drm_connector_unregister(struct drm_connector *connector) |
| 1049 | { |
| 1050 | drm_sysfs_connector_remove(connector); |
Thomas Wood | 30f6570 | 2014-06-18 17:52:32 +0100 | [diff] [blame] | 1051 | drm_debugfs_connector_remove(connector); |
Thomas Wood | 34ea3d3 | 2014-05-29 16:57:41 +0100 | [diff] [blame] | 1052 | } |
| 1053 | EXPORT_SYMBOL(drm_connector_unregister); |
| 1054 | |
Thomas Wood | 34ea3d3 | 2014-05-29 16:57:41 +0100 | [diff] [blame] | 1055 | /** |
Alexey Brodkin | 54d2c2d | 2016-04-19 15:24:51 +0300 | [diff] [blame] | 1056 | * drm_connector_register_all - register all connectors |
| 1057 | * @dev: drm device |
| 1058 | * |
| 1059 | * This function registers all connectors in sysfs and other places so that |
| 1060 | * userspace can start to access them. Drivers can call it after calling |
| 1061 | * drm_dev_register() to complete the device registration, if they don't call |
| 1062 | * drm_connector_register() on each connector individually. |
| 1063 | * |
| 1064 | * When a device is unplugged and should be removed from userspace access, |
| 1065 | * call drm_connector_unregister_all(), which is the inverse of this |
| 1066 | * function. |
| 1067 | * |
| 1068 | * Returns: |
| 1069 | * Zero on success, error code on failure. |
| 1070 | */ |
| 1071 | int drm_connector_register_all(struct drm_device *dev) |
| 1072 | { |
| 1073 | struct drm_connector *connector; |
| 1074 | int ret; |
| 1075 | |
| 1076 | mutex_lock(&dev->mode_config.mutex); |
| 1077 | |
| 1078 | drm_for_each_connector(connector, dev) { |
| 1079 | ret = drm_connector_register(connector); |
| 1080 | if (ret) |
| 1081 | goto err; |
| 1082 | } |
| 1083 | |
| 1084 | mutex_unlock(&dev->mode_config.mutex); |
| 1085 | |
| 1086 | return 0; |
| 1087 | |
| 1088 | err: |
| 1089 | mutex_unlock(&dev->mode_config.mutex); |
| 1090 | drm_connector_unregister_all(dev); |
| 1091 | return ret; |
| 1092 | } |
| 1093 | EXPORT_SYMBOL(drm_connector_register_all); |
| 1094 | |
| 1095 | /** |
Alexey Brodkin | 6c87e5c | 2016-03-23 11:42:54 +0300 | [diff] [blame] | 1096 | * drm_connector_unregister_all - unregister connector userspace interfaces |
Daniel Vetter | c8e32cc | 2014-03-10 21:33:02 +0100 | [diff] [blame] | 1097 | * @dev: drm device |
| 1098 | * |
Alexey Brodkin | 6c87e5c | 2016-03-23 11:42:54 +0300 | [diff] [blame] | 1099 | * This functions unregisters all connectors from sysfs and other places so |
| 1100 | * that userspace can no longer access them. Drivers should call this as the |
| 1101 | * first step tearing down the device instace, or when the underlying |
| 1102 | * physical device disappeared (e.g. USB unplug), right before calling |
| 1103 | * drm_dev_unregister(). |
Daniel Vetter | c8e32cc | 2014-03-10 21:33:02 +0100 | [diff] [blame] | 1104 | */ |
Alexey Brodkin | 6c87e5c | 2016-03-23 11:42:54 +0300 | [diff] [blame] | 1105 | void drm_connector_unregister_all(struct drm_device *dev) |
Dave Airlie | cbc7e22 | 2012-02-20 14:16:40 +0000 | [diff] [blame] | 1106 | { |
| 1107 | struct drm_connector *connector; |
| 1108 | |
Daniel Vetter | 9a9f5ce | 2015-07-09 23:44:34 +0200 | [diff] [blame] | 1109 | /* FIXME: taking the mode config mutex ends up in a clash with sysfs */ |
Laurent Pinchart | 14ba003 | 2016-04-21 01:21:14 +0300 | [diff] [blame] | 1110 | list_for_each_entry(connector, &dev->mode_config.connector_list, head) |
Thomas Wood | 34ea3d3 | 2014-05-29 16:57:41 +0100 | [diff] [blame] | 1111 | drm_connector_unregister(connector); |
Dave Airlie | cbc7e22 | 2012-02-20 14:16:40 +0000 | [diff] [blame] | 1112 | } |
Alexey Brodkin | 6c87e5c | 2016-03-23 11:42:54 +0300 | [diff] [blame] | 1113 | EXPORT_SYMBOL(drm_connector_unregister_all); |
Dave Airlie | cbc7e22 | 2012-02-20 14:16:40 +0000 | [diff] [blame] | 1114 | |
Daniel Vetter | c8e32cc | 2014-03-10 21:33:02 +0100 | [diff] [blame] | 1115 | /** |
Daniel Vetter | c8e32cc | 2014-03-10 21:33:02 +0100 | [diff] [blame] | 1116 | * drm_encoder_init - Init a preallocated encoder |
| 1117 | * @dev: drm device |
| 1118 | * @encoder: the encoder to init |
| 1119 | * @funcs: callbacks for this encoder |
| 1120 | * @encoder_type: user visible type of the encoder |
Ville Syrjälä | 13a3d91 | 2015-12-09 16:20:18 +0200 | [diff] [blame] | 1121 | * @name: printf style format string for the encoder name, or NULL for default name |
Daniel Vetter | c8e32cc | 2014-03-10 21:33:02 +0100 | [diff] [blame] | 1122 | * |
| 1123 | * Initialises a preallocated encoder. Encoder should be |
| 1124 | * subclassed as part of driver encoder objects. |
| 1125 | * |
| 1126 | * Returns: |
| 1127 | * Zero on success, error code on failure. |
| 1128 | */ |
Ville Syrjälä | 6bfc56a | 2012-03-13 12:35:48 +0200 | [diff] [blame] | 1129 | int drm_encoder_init(struct drm_device *dev, |
Dave Airlie | cbc7e22 | 2012-02-20 14:16:40 +0000 | [diff] [blame] | 1130 | struct drm_encoder *encoder, |
| 1131 | const struct drm_encoder_funcs *funcs, |
Ville Syrjälä | 13a3d91 | 2015-12-09 16:20:18 +0200 | [diff] [blame] | 1132 | int encoder_type, const char *name, ...) |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 1133 | { |
Ville Syrjälä | 6bfc56a | 2012-03-13 12:35:48 +0200 | [diff] [blame] | 1134 | int ret; |
| 1135 | |
Daniel Vetter | 8484990 | 2012-12-02 00:28:11 +0100 | [diff] [blame] | 1136 | drm_modeset_lock_all(dev); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 1137 | |
Ville Syrjälä | 6bfc56a | 2012-03-13 12:35:48 +0200 | [diff] [blame] | 1138 | ret = drm_mode_object_get(dev, &encoder->base, DRM_MODE_OBJECT_ENCODER); |
| 1139 | if (ret) |
Jani Nikula | e574894 | 2014-05-14 16:58:20 +0300 | [diff] [blame] | 1140 | goto out_unlock; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 1141 | |
Ville Syrjälä | 6bfc56a | 2012-03-13 12:35:48 +0200 | [diff] [blame] | 1142 | encoder->dev = dev; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 1143 | encoder->encoder_type = encoder_type; |
| 1144 | encoder->funcs = funcs; |
Ville Syrjälä | 86bf546 | 2015-12-08 18:41:52 +0200 | [diff] [blame] | 1145 | if (name) { |
| 1146 | va_list ap; |
| 1147 | |
| 1148 | va_start(ap, name); |
| 1149 | encoder->name = kvasprintf(GFP_KERNEL, name, ap); |
| 1150 | va_end(ap); |
| 1151 | } else { |
| 1152 | encoder->name = kasprintf(GFP_KERNEL, "%s-%d", |
| 1153 | drm_encoder_enum_list[encoder_type].name, |
| 1154 | encoder->base.id); |
| 1155 | } |
Jani Nikula | e574894 | 2014-05-14 16:58:20 +0300 | [diff] [blame] | 1156 | if (!encoder->name) { |
| 1157 | ret = -ENOMEM; |
| 1158 | goto out_put; |
| 1159 | } |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 1160 | |
| 1161 | list_add_tail(&encoder->head, &dev->mode_config.encoder_list); |
| 1162 | dev->mode_config.num_encoder++; |
| 1163 | |
Jani Nikula | e574894 | 2014-05-14 16:58:20 +0300 | [diff] [blame] | 1164 | out_put: |
| 1165 | if (ret) |
Dave Airlie | 7c8f6d2 | 2016-04-15 15:10:32 +1000 | [diff] [blame] | 1166 | drm_mode_object_unregister(dev, &encoder->base); |
Jani Nikula | e574894 | 2014-05-14 16:58:20 +0300 | [diff] [blame] | 1167 | |
| 1168 | out_unlock: |
Daniel Vetter | 8484990 | 2012-12-02 00:28:11 +0100 | [diff] [blame] | 1169 | drm_modeset_unlock_all(dev); |
Ville Syrjälä | 6bfc56a | 2012-03-13 12:35:48 +0200 | [diff] [blame] | 1170 | |
| 1171 | return ret; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 1172 | } |
| 1173 | EXPORT_SYMBOL(drm_encoder_init); |
| 1174 | |
Daniel Vetter | c8e32cc | 2014-03-10 21:33:02 +0100 | [diff] [blame] | 1175 | /** |
Maarten Lankhorst | 47d7777 | 2016-01-07 10:59:18 +0100 | [diff] [blame] | 1176 | * drm_encoder_index - find the index of a registered encoder |
| 1177 | * @encoder: encoder to find index for |
| 1178 | * |
| 1179 | * Given a registered encoder, return the index of that encoder within a DRM |
| 1180 | * device's list of encoders. |
| 1181 | */ |
| 1182 | unsigned int drm_encoder_index(struct drm_encoder *encoder) |
| 1183 | { |
| 1184 | unsigned int index = 0; |
| 1185 | struct drm_encoder *tmp; |
| 1186 | |
| 1187 | drm_for_each_encoder(tmp, encoder->dev) { |
| 1188 | if (tmp == encoder) |
| 1189 | return index; |
| 1190 | |
| 1191 | index++; |
| 1192 | } |
| 1193 | |
| 1194 | BUG(); |
| 1195 | } |
| 1196 | EXPORT_SYMBOL(drm_encoder_index); |
| 1197 | |
| 1198 | /** |
Daniel Vetter | c8e32cc | 2014-03-10 21:33:02 +0100 | [diff] [blame] | 1199 | * drm_encoder_cleanup - cleans up an initialised encoder |
| 1200 | * @encoder: encoder to cleanup |
| 1201 | * |
| 1202 | * Cleans up the encoder but doesn't free the object. |
| 1203 | */ |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 1204 | void drm_encoder_cleanup(struct drm_encoder *encoder) |
| 1205 | { |
| 1206 | struct drm_device *dev = encoder->dev; |
Thierry Reding | 4dfd909 | 2014-12-10 13:03:34 +0100 | [diff] [blame] | 1207 | |
Daniel Vetter | 8484990 | 2012-12-02 00:28:11 +0100 | [diff] [blame] | 1208 | drm_modeset_lock_all(dev); |
Dave Airlie | 7c8f6d2 | 2016-04-15 15:10:32 +1000 | [diff] [blame] | 1209 | drm_mode_object_unregister(dev, &encoder->base); |
Jani Nikula | e574894 | 2014-05-14 16:58:20 +0300 | [diff] [blame] | 1210 | kfree(encoder->name); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 1211 | list_del(&encoder->head); |
Joonyoung Shim | 6380c50 | 2011-08-27 02:06:21 +0000 | [diff] [blame] | 1212 | dev->mode_config.num_encoder--; |
Daniel Vetter | 8484990 | 2012-12-02 00:28:11 +0100 | [diff] [blame] | 1213 | drm_modeset_unlock_all(dev); |
Thierry Reding | a18c0af | 2014-12-10 11:38:49 +0100 | [diff] [blame] | 1214 | |
| 1215 | memset(encoder, 0, sizeof(*encoder)); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 1216 | } |
| 1217 | EXPORT_SYMBOL(drm_encoder_cleanup); |
| 1218 | |
Ville Syrjälä | 9f4c97a | 2015-12-08 18:41:54 +0200 | [diff] [blame] | 1219 | static unsigned int drm_num_planes(struct drm_device *dev) |
| 1220 | { |
| 1221 | unsigned int num = 0; |
| 1222 | struct drm_plane *tmp; |
| 1223 | |
| 1224 | drm_for_each_plane(tmp, dev) { |
| 1225 | num++; |
| 1226 | } |
| 1227 | |
| 1228 | return num; |
| 1229 | } |
| 1230 | |
Ville Syrjälä | 35f2c3a | 2013-06-05 15:39:56 +0300 | [diff] [blame] | 1231 | /** |
Matt Roper | dc415ff | 2014-04-01 15:22:36 -0700 | [diff] [blame] | 1232 | * drm_universal_plane_init - Initialize a new universal plane object |
Ville Syrjälä | 35f2c3a | 2013-06-05 15:39:56 +0300 | [diff] [blame] | 1233 | * @dev: DRM device |
| 1234 | * @plane: plane object to init |
| 1235 | * @possible_crtcs: bitmask of possible CRTCs |
| 1236 | * @funcs: callbacks for the new plane |
| 1237 | * @formats: array of supported formats (%DRM_FORMAT_*) |
| 1238 | * @format_count: number of elements in @formats |
Matt Roper | dc415ff | 2014-04-01 15:22:36 -0700 | [diff] [blame] | 1239 | * @type: type of plane (overlay, primary, cursor) |
Ville Syrjälä | b0b3b79 | 2015-12-09 16:19:55 +0200 | [diff] [blame] | 1240 | * @name: printf style format string for the plane name, or NULL for default name |
Ville Syrjälä | 35f2c3a | 2013-06-05 15:39:56 +0300 | [diff] [blame] | 1241 | * |
Matt Roper | dc415ff | 2014-04-01 15:22:36 -0700 | [diff] [blame] | 1242 | * Initializes a plane object of type @type. |
Ville Syrjälä | 35f2c3a | 2013-06-05 15:39:56 +0300 | [diff] [blame] | 1243 | * |
Daniel Vetter | c8e32cc | 2014-03-10 21:33:02 +0100 | [diff] [blame] | 1244 | * Returns: |
Ville Syrjälä | 35f2c3a | 2013-06-05 15:39:56 +0300 | [diff] [blame] | 1245 | * Zero on success, error code on failure. |
| 1246 | */ |
Matt Roper | dc415ff | 2014-04-01 15:22:36 -0700 | [diff] [blame] | 1247 | int drm_universal_plane_init(struct drm_device *dev, struct drm_plane *plane, |
| 1248 | unsigned long possible_crtcs, |
| 1249 | const struct drm_plane_funcs *funcs, |
Thierry Reding | 45e3743 | 2015-08-12 16:54:28 +0200 | [diff] [blame] | 1250 | const uint32_t *formats, unsigned int format_count, |
Ville Syrjälä | b0b3b79 | 2015-12-09 16:19:55 +0200 | [diff] [blame] | 1251 | enum drm_plane_type type, |
| 1252 | const char *name, ...) |
Jesse Barnes | 8cf5c91 | 2011-11-14 14:51:27 -0800 | [diff] [blame] | 1253 | { |
Rob Clark | 6b4959f | 2014-12-18 16:01:53 -0500 | [diff] [blame] | 1254 | struct drm_mode_config *config = &dev->mode_config; |
Ville Syrjälä | 6bfc56a | 2012-03-13 12:35:48 +0200 | [diff] [blame] | 1255 | int ret; |
| 1256 | |
Ville Syrjälä | 6bfc56a | 2012-03-13 12:35:48 +0200 | [diff] [blame] | 1257 | ret = drm_mode_object_get(dev, &plane->base, DRM_MODE_OBJECT_PLANE); |
| 1258 | if (ret) |
Daniel Vetter | baf698b | 2014-11-12 11:59:47 +0100 | [diff] [blame] | 1259 | return ret; |
Ville Syrjälä | 6bfc56a | 2012-03-13 12:35:48 +0200 | [diff] [blame] | 1260 | |
Daniel Vetter | 4d02e2d | 2014-11-11 10:12:00 +0100 | [diff] [blame] | 1261 | drm_modeset_lock_init(&plane->mutex); |
| 1262 | |
Rob Clark | 4d93914 | 2012-05-17 02:23:27 -0600 | [diff] [blame] | 1263 | plane->base.properties = &plane->properties; |
Jesse Barnes | 8cf5c91 | 2011-11-14 14:51:27 -0800 | [diff] [blame] | 1264 | plane->dev = dev; |
Jesse Barnes | 8cf5c91 | 2011-11-14 14:51:27 -0800 | [diff] [blame] | 1265 | plane->funcs = funcs; |
Thierry Reding | 2f6c538 | 2014-12-10 13:03:36 +0100 | [diff] [blame] | 1266 | plane->format_types = kmalloc_array(format_count, sizeof(uint32_t), |
| 1267 | GFP_KERNEL); |
Jesse Barnes | 8cf5c91 | 2011-11-14 14:51:27 -0800 | [diff] [blame] | 1268 | if (!plane->format_types) { |
| 1269 | DRM_DEBUG_KMS("out of memory when allocating plane\n"); |
Dave Airlie | 7c8f6d2 | 2016-04-15 15:10:32 +1000 | [diff] [blame] | 1270 | drm_mode_object_unregister(dev, &plane->base); |
Daniel Vetter | baf698b | 2014-11-12 11:59:47 +0100 | [diff] [blame] | 1271 | return -ENOMEM; |
Jesse Barnes | 8cf5c91 | 2011-11-14 14:51:27 -0800 | [diff] [blame] | 1272 | } |
| 1273 | |
Ville Syrjälä | 9f4c97a | 2015-12-08 18:41:54 +0200 | [diff] [blame] | 1274 | if (name) { |
| 1275 | va_list ap; |
| 1276 | |
| 1277 | va_start(ap, name); |
| 1278 | plane->name = kvasprintf(GFP_KERNEL, name, ap); |
| 1279 | va_end(ap); |
| 1280 | } else { |
| 1281 | plane->name = kasprintf(GFP_KERNEL, "plane-%d", |
| 1282 | drm_num_planes(dev)); |
| 1283 | } |
| 1284 | if (!plane->name) { |
| 1285 | kfree(plane->format_types); |
Dave Airlie | 7c8f6d2 | 2016-04-15 15:10:32 +1000 | [diff] [blame] | 1286 | drm_mode_object_unregister(dev, &plane->base); |
Ville Syrjälä | 9f4c97a | 2015-12-08 18:41:54 +0200 | [diff] [blame] | 1287 | return -ENOMEM; |
| 1288 | } |
| 1289 | |
Jesse Barnes | 308e5bc | 2011-11-14 14:51:28 -0800 | [diff] [blame] | 1290 | memcpy(plane->format_types, formats, format_count * sizeof(uint32_t)); |
Jesse Barnes | 8cf5c91 | 2011-11-14 14:51:27 -0800 | [diff] [blame] | 1291 | plane->format_count = format_count; |
| 1292 | plane->possible_crtcs = possible_crtcs; |
Matt Roper | dc415ff | 2014-04-01 15:22:36 -0700 | [diff] [blame] | 1293 | plane->type = type; |
Jesse Barnes | 8cf5c91 | 2011-11-14 14:51:27 -0800 | [diff] [blame] | 1294 | |
Rob Clark | 6b4959f | 2014-12-18 16:01:53 -0500 | [diff] [blame] | 1295 | list_add_tail(&plane->head, &config->plane_list); |
| 1296 | config->num_total_plane++; |
Matt Roper | dc415ff | 2014-04-01 15:22:36 -0700 | [diff] [blame] | 1297 | if (plane->type == DRM_PLANE_TYPE_OVERLAY) |
Rob Clark | 6b4959f | 2014-12-18 16:01:53 -0500 | [diff] [blame] | 1298 | config->num_overlay_plane++; |
Jesse Barnes | 8cf5c91 | 2011-11-14 14:51:27 -0800 | [diff] [blame] | 1299 | |
Rob Clark | 9922ab5 | 2014-04-01 20:16:57 -0400 | [diff] [blame] | 1300 | drm_object_attach_property(&plane->base, |
Rob Clark | 6b4959f | 2014-12-18 16:01:53 -0500 | [diff] [blame] | 1301 | config->plane_type_property, |
Rob Clark | 9922ab5 | 2014-04-01 20:16:57 -0400 | [diff] [blame] | 1302 | plane->type); |
| 1303 | |
Rob Clark | 6b4959f | 2014-12-18 16:01:53 -0500 | [diff] [blame] | 1304 | if (drm_core_check_feature(dev, DRIVER_ATOMIC)) { |
| 1305 | drm_object_attach_property(&plane->base, config->prop_fb_id, 0); |
| 1306 | drm_object_attach_property(&plane->base, config->prop_crtc_id, 0); |
| 1307 | drm_object_attach_property(&plane->base, config->prop_crtc_x, 0); |
| 1308 | drm_object_attach_property(&plane->base, config->prop_crtc_y, 0); |
| 1309 | drm_object_attach_property(&plane->base, config->prop_crtc_w, 0); |
| 1310 | drm_object_attach_property(&plane->base, config->prop_crtc_h, 0); |
| 1311 | drm_object_attach_property(&plane->base, config->prop_src_x, 0); |
| 1312 | drm_object_attach_property(&plane->base, config->prop_src_y, 0); |
| 1313 | drm_object_attach_property(&plane->base, config->prop_src_w, 0); |
| 1314 | drm_object_attach_property(&plane->base, config->prop_src_h, 0); |
| 1315 | } |
| 1316 | |
Daniel Vetter | baf698b | 2014-11-12 11:59:47 +0100 | [diff] [blame] | 1317 | return 0; |
Jesse Barnes | 8cf5c91 | 2011-11-14 14:51:27 -0800 | [diff] [blame] | 1318 | } |
Matt Roper | dc415ff | 2014-04-01 15:22:36 -0700 | [diff] [blame] | 1319 | EXPORT_SYMBOL(drm_universal_plane_init); |
| 1320 | |
| 1321 | /** |
| 1322 | * drm_plane_init - Initialize a legacy plane |
| 1323 | * @dev: DRM device |
| 1324 | * @plane: plane object to init |
| 1325 | * @possible_crtcs: bitmask of possible CRTCs |
| 1326 | * @funcs: callbacks for the new plane |
| 1327 | * @formats: array of supported formats (%DRM_FORMAT_*) |
| 1328 | * @format_count: number of elements in @formats |
| 1329 | * @is_primary: plane type (primary vs overlay) |
| 1330 | * |
| 1331 | * Legacy API to initialize a DRM plane. |
| 1332 | * |
| 1333 | * New drivers should call drm_universal_plane_init() instead. |
| 1334 | * |
| 1335 | * Returns: |
| 1336 | * Zero on success, error code on failure. |
| 1337 | */ |
| 1338 | int drm_plane_init(struct drm_device *dev, struct drm_plane *plane, |
| 1339 | unsigned long possible_crtcs, |
| 1340 | const struct drm_plane_funcs *funcs, |
Thierry Reding | 45e3743 | 2015-08-12 16:54:28 +0200 | [diff] [blame] | 1341 | const uint32_t *formats, unsigned int format_count, |
Matt Roper | dc415ff | 2014-04-01 15:22:36 -0700 | [diff] [blame] | 1342 | bool is_primary) |
| 1343 | { |
| 1344 | enum drm_plane_type type; |
| 1345 | |
| 1346 | type = is_primary ? DRM_PLANE_TYPE_PRIMARY : DRM_PLANE_TYPE_OVERLAY; |
| 1347 | return drm_universal_plane_init(dev, plane, possible_crtcs, funcs, |
Ville Syrjälä | b0b3b79 | 2015-12-09 16:19:55 +0200 | [diff] [blame] | 1348 | formats, format_count, type, NULL); |
Matt Roper | dc415ff | 2014-04-01 15:22:36 -0700 | [diff] [blame] | 1349 | } |
Jesse Barnes | 8cf5c91 | 2011-11-14 14:51:27 -0800 | [diff] [blame] | 1350 | EXPORT_SYMBOL(drm_plane_init); |
| 1351 | |
Ville Syrjälä | 35f2c3a | 2013-06-05 15:39:56 +0300 | [diff] [blame] | 1352 | /** |
| 1353 | * drm_plane_cleanup - Clean up the core plane usage |
| 1354 | * @plane: plane to cleanup |
| 1355 | * |
| 1356 | * This function cleans up @plane and removes it from the DRM mode setting |
| 1357 | * core. Note that the function does *not* free the plane structure itself, |
| 1358 | * this is the responsibility of the caller. |
| 1359 | */ |
Jesse Barnes | 8cf5c91 | 2011-11-14 14:51:27 -0800 | [diff] [blame] | 1360 | void drm_plane_cleanup(struct drm_plane *plane) |
| 1361 | { |
| 1362 | struct drm_device *dev = plane->dev; |
| 1363 | |
Daniel Vetter | 8484990 | 2012-12-02 00:28:11 +0100 | [diff] [blame] | 1364 | drm_modeset_lock_all(dev); |
Jesse Barnes | 8cf5c91 | 2011-11-14 14:51:27 -0800 | [diff] [blame] | 1365 | kfree(plane->format_types); |
Dave Airlie | 7c8f6d2 | 2016-04-15 15:10:32 +1000 | [diff] [blame] | 1366 | drm_mode_object_unregister(dev, &plane->base); |
Matt Roper | dc415ff | 2014-04-01 15:22:36 -0700 | [diff] [blame] | 1367 | |
| 1368 | BUG_ON(list_empty(&plane->head)); |
| 1369 | |
| 1370 | list_del(&plane->head); |
| 1371 | dev->mode_config.num_total_plane--; |
| 1372 | if (plane->type == DRM_PLANE_TYPE_OVERLAY) |
| 1373 | dev->mode_config.num_overlay_plane--; |
Daniel Vetter | 8484990 | 2012-12-02 00:28:11 +0100 | [diff] [blame] | 1374 | drm_modeset_unlock_all(dev); |
Thierry Reding | 3009c03 | 2014-11-25 12:09:49 +0100 | [diff] [blame] | 1375 | |
| 1376 | WARN_ON(plane->state && !plane->funcs->atomic_destroy_state); |
| 1377 | if (plane->state && plane->funcs->atomic_destroy_state) |
| 1378 | plane->funcs->atomic_destroy_state(plane, plane->state); |
Thierry Reding | a18c0af | 2014-12-10 11:38:49 +0100 | [diff] [blame] | 1379 | |
Ville Syrjälä | 9f4c97a | 2015-12-08 18:41:54 +0200 | [diff] [blame] | 1380 | kfree(plane->name); |
| 1381 | |
Thierry Reding | a18c0af | 2014-12-10 11:38:49 +0100 | [diff] [blame] | 1382 | memset(plane, 0, sizeof(*plane)); |
Jesse Barnes | 8cf5c91 | 2011-11-14 14:51:27 -0800 | [diff] [blame] | 1383 | } |
| 1384 | EXPORT_SYMBOL(drm_plane_cleanup); |
| 1385 | |
Ville Syrjälä | 35f2c3a | 2013-06-05 15:39:56 +0300 | [diff] [blame] | 1386 | /** |
Daniel Vetter | 10f637b | 2014-07-29 13:47:11 +0200 | [diff] [blame] | 1387 | * drm_plane_index - find the index of a registered plane |
| 1388 | * @plane: plane to find index for |
| 1389 | * |
| 1390 | * Given a registered plane, return the index of that CRTC within a DRM |
| 1391 | * device's list of planes. |
| 1392 | */ |
| 1393 | unsigned int drm_plane_index(struct drm_plane *plane) |
| 1394 | { |
| 1395 | unsigned int index = 0; |
| 1396 | struct drm_plane *tmp; |
| 1397 | |
Daniel Vetter | e4f6254 | 2015-07-09 23:44:35 +0200 | [diff] [blame] | 1398 | drm_for_each_plane(tmp, plane->dev) { |
Daniel Vetter | 10f637b | 2014-07-29 13:47:11 +0200 | [diff] [blame] | 1399 | if (tmp == plane) |
| 1400 | return index; |
| 1401 | |
| 1402 | index++; |
| 1403 | } |
| 1404 | |
| 1405 | BUG(); |
| 1406 | } |
| 1407 | EXPORT_SYMBOL(drm_plane_index); |
| 1408 | |
| 1409 | /** |
Chandra Konduru | f81338a | 2015-04-09 17:36:21 -0700 | [diff] [blame] | 1410 | * drm_plane_from_index - find the registered plane at an index |
| 1411 | * @dev: DRM device |
| 1412 | * @idx: index of registered plane to find for |
| 1413 | * |
| 1414 | * Given a plane index, return the registered plane from DRM device's |
| 1415 | * list of planes with matching index. |
| 1416 | */ |
| 1417 | struct drm_plane * |
| 1418 | drm_plane_from_index(struct drm_device *dev, int idx) |
| 1419 | { |
| 1420 | struct drm_plane *plane; |
| 1421 | unsigned int i = 0; |
| 1422 | |
Daniel Vetter | 6295d60 | 2015-07-09 23:44:25 +0200 | [diff] [blame] | 1423 | drm_for_each_plane(plane, dev) { |
Chandra Konduru | f81338a | 2015-04-09 17:36:21 -0700 | [diff] [blame] | 1424 | if (i == idx) |
| 1425 | return plane; |
| 1426 | i++; |
| 1427 | } |
| 1428 | return NULL; |
| 1429 | } |
| 1430 | EXPORT_SYMBOL(drm_plane_from_index); |
| 1431 | |
| 1432 | /** |
Ville Syrjälä | 35f2c3a | 2013-06-05 15:39:56 +0300 | [diff] [blame] | 1433 | * drm_plane_force_disable - Forcibly disable a plane |
| 1434 | * @plane: plane to disable |
| 1435 | * |
| 1436 | * Forces the plane to be disabled. |
| 1437 | * |
| 1438 | * Used when the plane's current framebuffer is destroyed, |
| 1439 | * and when restoring fbdev mode. |
| 1440 | */ |
Ville Syrjälä | 9125e61 | 2013-06-03 16:10:40 +0300 | [diff] [blame] | 1441 | void drm_plane_force_disable(struct drm_plane *plane) |
| 1442 | { |
| 1443 | int ret; |
| 1444 | |
Daniel Vetter | 3d30a59 | 2014-07-27 13:42:42 +0200 | [diff] [blame] | 1445 | if (!plane->fb) |
Ville Syrjälä | 9125e61 | 2013-06-03 16:10:40 +0300 | [diff] [blame] | 1446 | return; |
| 1447 | |
Daniel Vetter | 3d30a59 | 2014-07-27 13:42:42 +0200 | [diff] [blame] | 1448 | plane->old_fb = plane->fb; |
Ville Syrjälä | 9125e61 | 2013-06-03 16:10:40 +0300 | [diff] [blame] | 1449 | ret = plane->funcs->disable_plane(plane); |
Daniel Vetter | 731cce4 | 2014-04-23 10:24:11 +0200 | [diff] [blame] | 1450 | if (ret) { |
Ville Syrjälä | 9125e61 | 2013-06-03 16:10:40 +0300 | [diff] [blame] | 1451 | DRM_ERROR("failed to disable plane with busy fb\n"); |
Daniel Vetter | 3d30a59 | 2014-07-27 13:42:42 +0200 | [diff] [blame] | 1452 | plane->old_fb = NULL; |
Daniel Vetter | 731cce4 | 2014-04-23 10:24:11 +0200 | [diff] [blame] | 1453 | return; |
| 1454 | } |
Ville Syrjälä | 9125e61 | 2013-06-03 16:10:40 +0300 | [diff] [blame] | 1455 | /* disconnect the plane from the fb and crtc: */ |
Daniel Vetter | 220dd2b | 2015-02-27 12:58:13 +0100 | [diff] [blame] | 1456 | drm_framebuffer_unreference(plane->old_fb); |
Daniel Vetter | 3d30a59 | 2014-07-27 13:42:42 +0200 | [diff] [blame] | 1457 | plane->old_fb = NULL; |
Ville Syrjälä | 9125e61 | 2013-06-03 16:10:40 +0300 | [diff] [blame] | 1458 | plane->fb = NULL; |
| 1459 | plane->crtc = NULL; |
| 1460 | } |
| 1461 | EXPORT_SYMBOL(drm_plane_force_disable); |
| 1462 | |
Rob Clark | 6b4959f | 2014-12-18 16:01:53 -0500 | [diff] [blame] | 1463 | static int drm_mode_create_standard_properties(struct drm_device *dev) |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 1464 | { |
Rob Clark | 356af0e | 2014-12-18 16:01:52 -0500 | [diff] [blame] | 1465 | struct drm_property *prop; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 1466 | |
| 1467 | /* |
| 1468 | * Standard properties (apply to all connectors) |
| 1469 | */ |
Rob Clark | 356af0e | 2014-12-18 16:01:52 -0500 | [diff] [blame] | 1470 | prop = drm_property_create(dev, DRM_MODE_PROP_BLOB | |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 1471 | DRM_MODE_PROP_IMMUTABLE, |
| 1472 | "EDID", 0); |
Rob Clark | 356af0e | 2014-12-18 16:01:52 -0500 | [diff] [blame] | 1473 | if (!prop) |
| 1474 | return -ENOMEM; |
| 1475 | dev->mode_config.edid_property = prop; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 1476 | |
Rob Clark | 356af0e | 2014-12-18 16:01:52 -0500 | [diff] [blame] | 1477 | prop = drm_property_create_enum(dev, 0, |
Sascha Hauer | 4a67d39 | 2012-02-06 10:58:17 +0100 | [diff] [blame] | 1478 | "DPMS", drm_dpms_enum_list, |
| 1479 | ARRAY_SIZE(drm_dpms_enum_list)); |
Rob Clark | 356af0e | 2014-12-18 16:01:52 -0500 | [diff] [blame] | 1480 | if (!prop) |
| 1481 | return -ENOMEM; |
| 1482 | dev->mode_config.dpms_property = prop; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 1483 | |
Rob Clark | 356af0e | 2014-12-18 16:01:52 -0500 | [diff] [blame] | 1484 | prop = drm_property_create(dev, |
| 1485 | DRM_MODE_PROP_BLOB | |
| 1486 | DRM_MODE_PROP_IMMUTABLE, |
| 1487 | "PATH", 0); |
| 1488 | if (!prop) |
| 1489 | return -ENOMEM; |
| 1490 | dev->mode_config.path_property = prop; |
Dave Airlie | 43aba7e | 2014-06-05 14:01:31 +1000 | [diff] [blame] | 1491 | |
Rob Clark | 356af0e | 2014-12-18 16:01:52 -0500 | [diff] [blame] | 1492 | prop = drm_property_create(dev, |
| 1493 | DRM_MODE_PROP_BLOB | |
| 1494 | DRM_MODE_PROP_IMMUTABLE, |
| 1495 | "TILE", 0); |
| 1496 | if (!prop) |
| 1497 | return -ENOMEM; |
| 1498 | dev->mode_config.tile_property = prop; |
Dave Airlie | 6f134d7 | 2014-10-20 16:30:50 +1000 | [diff] [blame] | 1499 | |
Rob Clark | 6b4959f | 2014-12-18 16:01:53 -0500 | [diff] [blame] | 1500 | prop = drm_property_create_enum(dev, DRM_MODE_PROP_IMMUTABLE, |
Rob Clark | 9922ab5 | 2014-04-01 20:16:57 -0400 | [diff] [blame] | 1501 | "type", drm_plane_type_enum_list, |
| 1502 | ARRAY_SIZE(drm_plane_type_enum_list)); |
Rob Clark | 6b4959f | 2014-12-18 16:01:53 -0500 | [diff] [blame] | 1503 | if (!prop) |
| 1504 | return -ENOMEM; |
| 1505 | dev->mode_config.plane_type_property = prop; |
| 1506 | |
| 1507 | prop = drm_property_create_range(dev, DRM_MODE_PROP_ATOMIC, |
| 1508 | "SRC_X", 0, UINT_MAX); |
| 1509 | if (!prop) |
| 1510 | return -ENOMEM; |
| 1511 | dev->mode_config.prop_src_x = prop; |
| 1512 | |
| 1513 | prop = drm_property_create_range(dev, DRM_MODE_PROP_ATOMIC, |
| 1514 | "SRC_Y", 0, UINT_MAX); |
| 1515 | if (!prop) |
| 1516 | return -ENOMEM; |
| 1517 | dev->mode_config.prop_src_y = prop; |
| 1518 | |
| 1519 | prop = drm_property_create_range(dev, DRM_MODE_PROP_ATOMIC, |
| 1520 | "SRC_W", 0, UINT_MAX); |
| 1521 | if (!prop) |
| 1522 | return -ENOMEM; |
| 1523 | dev->mode_config.prop_src_w = prop; |
| 1524 | |
| 1525 | prop = drm_property_create_range(dev, DRM_MODE_PROP_ATOMIC, |
| 1526 | "SRC_H", 0, UINT_MAX); |
| 1527 | if (!prop) |
| 1528 | return -ENOMEM; |
| 1529 | dev->mode_config.prop_src_h = prop; |
| 1530 | |
| 1531 | prop = drm_property_create_signed_range(dev, DRM_MODE_PROP_ATOMIC, |
| 1532 | "CRTC_X", INT_MIN, INT_MAX); |
| 1533 | if (!prop) |
| 1534 | return -ENOMEM; |
| 1535 | dev->mode_config.prop_crtc_x = prop; |
| 1536 | |
| 1537 | prop = drm_property_create_signed_range(dev, DRM_MODE_PROP_ATOMIC, |
| 1538 | "CRTC_Y", INT_MIN, INT_MAX); |
| 1539 | if (!prop) |
| 1540 | return -ENOMEM; |
| 1541 | dev->mode_config.prop_crtc_y = prop; |
| 1542 | |
| 1543 | prop = drm_property_create_range(dev, DRM_MODE_PROP_ATOMIC, |
| 1544 | "CRTC_W", 0, INT_MAX); |
| 1545 | if (!prop) |
| 1546 | return -ENOMEM; |
| 1547 | dev->mode_config.prop_crtc_w = prop; |
| 1548 | |
| 1549 | prop = drm_property_create_range(dev, DRM_MODE_PROP_ATOMIC, |
| 1550 | "CRTC_H", 0, INT_MAX); |
| 1551 | if (!prop) |
| 1552 | return -ENOMEM; |
| 1553 | dev->mode_config.prop_crtc_h = prop; |
| 1554 | |
| 1555 | prop = drm_property_create_object(dev, DRM_MODE_PROP_ATOMIC, |
| 1556 | "FB_ID", DRM_MODE_OBJECT_FB); |
| 1557 | if (!prop) |
| 1558 | return -ENOMEM; |
| 1559 | dev->mode_config.prop_fb_id = prop; |
| 1560 | |
| 1561 | prop = drm_property_create_object(dev, DRM_MODE_PROP_ATOMIC, |
| 1562 | "CRTC_ID", DRM_MODE_OBJECT_CRTC); |
| 1563 | if (!prop) |
| 1564 | return -ENOMEM; |
| 1565 | dev->mode_config.prop_crtc_id = prop; |
Rob Clark | 9922ab5 | 2014-04-01 20:16:57 -0400 | [diff] [blame] | 1566 | |
Daniel Vetter | eab3bbe | 2015-01-22 16:36:21 +0100 | [diff] [blame] | 1567 | prop = drm_property_create_bool(dev, DRM_MODE_PROP_ATOMIC, |
| 1568 | "ACTIVE"); |
| 1569 | if (!prop) |
| 1570 | return -ENOMEM; |
| 1571 | dev->mode_config.prop_active = prop; |
| 1572 | |
Daniel Stone | 955f3c3 | 2015-05-25 19:11:52 +0100 | [diff] [blame] | 1573 | prop = drm_property_create(dev, |
| 1574 | DRM_MODE_PROP_ATOMIC | DRM_MODE_PROP_BLOB, |
| 1575 | "MODE_ID", 0); |
| 1576 | if (!prop) |
| 1577 | return -ENOMEM; |
| 1578 | dev->mode_config.prop_mode_id = prop; |
| 1579 | |
Lionel Landwerlin | 5488dc1 | 2016-02-26 17:05:00 +0000 | [diff] [blame] | 1580 | prop = drm_property_create(dev, |
| 1581 | DRM_MODE_PROP_BLOB, |
| 1582 | "DEGAMMA_LUT", 0); |
| 1583 | if (!prop) |
| 1584 | return -ENOMEM; |
| 1585 | dev->mode_config.degamma_lut_property = prop; |
| 1586 | |
| 1587 | prop = drm_property_create_range(dev, |
| 1588 | DRM_MODE_PROP_IMMUTABLE, |
| 1589 | "DEGAMMA_LUT_SIZE", 0, UINT_MAX); |
| 1590 | if (!prop) |
| 1591 | return -ENOMEM; |
| 1592 | dev->mode_config.degamma_lut_size_property = prop; |
| 1593 | |
| 1594 | prop = drm_property_create(dev, |
| 1595 | DRM_MODE_PROP_BLOB, |
| 1596 | "CTM", 0); |
| 1597 | if (!prop) |
| 1598 | return -ENOMEM; |
| 1599 | dev->mode_config.ctm_property = prop; |
| 1600 | |
| 1601 | prop = drm_property_create(dev, |
| 1602 | DRM_MODE_PROP_BLOB, |
| 1603 | "GAMMA_LUT", 0); |
| 1604 | if (!prop) |
| 1605 | return -ENOMEM; |
| 1606 | dev->mode_config.gamma_lut_property = prop; |
| 1607 | |
| 1608 | prop = drm_property_create_range(dev, |
| 1609 | DRM_MODE_PROP_IMMUTABLE, |
| 1610 | "GAMMA_LUT_SIZE", 0, UINT_MAX); |
| 1611 | if (!prop) |
| 1612 | return -ENOMEM; |
| 1613 | dev->mode_config.gamma_lut_size_property = prop; |
| 1614 | |
Rob Clark | 9922ab5 | 2014-04-01 20:16:57 -0400 | [diff] [blame] | 1615 | return 0; |
| 1616 | } |
| 1617 | |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 1618 | /** |
| 1619 | * drm_mode_create_dvi_i_properties - create DVI-I specific connector properties |
| 1620 | * @dev: DRM device |
| 1621 | * |
| 1622 | * Called by a driver the first time a DVI-I connector is made. |
| 1623 | */ |
| 1624 | int drm_mode_create_dvi_i_properties(struct drm_device *dev) |
| 1625 | { |
| 1626 | struct drm_property *dvi_i_selector; |
| 1627 | struct drm_property *dvi_i_subconnector; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 1628 | |
| 1629 | if (dev->mode_config.dvi_i_select_subconnector_property) |
| 1630 | return 0; |
| 1631 | |
| 1632 | dvi_i_selector = |
Sascha Hauer | 4a67d39 | 2012-02-06 10:58:17 +0100 | [diff] [blame] | 1633 | drm_property_create_enum(dev, 0, |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 1634 | "select subconnector", |
Sascha Hauer | 4a67d39 | 2012-02-06 10:58:17 +0100 | [diff] [blame] | 1635 | drm_dvi_i_select_enum_list, |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 1636 | ARRAY_SIZE(drm_dvi_i_select_enum_list)); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 1637 | dev->mode_config.dvi_i_select_subconnector_property = dvi_i_selector; |
| 1638 | |
Sascha Hauer | 4a67d39 | 2012-02-06 10:58:17 +0100 | [diff] [blame] | 1639 | dvi_i_subconnector = drm_property_create_enum(dev, DRM_MODE_PROP_IMMUTABLE, |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 1640 | "subconnector", |
Sascha Hauer | 4a67d39 | 2012-02-06 10:58:17 +0100 | [diff] [blame] | 1641 | drm_dvi_i_subconnector_enum_list, |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 1642 | ARRAY_SIZE(drm_dvi_i_subconnector_enum_list)); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 1643 | dev->mode_config.dvi_i_subconnector_property = dvi_i_subconnector; |
| 1644 | |
| 1645 | return 0; |
| 1646 | } |
| 1647 | EXPORT_SYMBOL(drm_mode_create_dvi_i_properties); |
| 1648 | |
| 1649 | /** |
| 1650 | * drm_create_tv_properties - create TV specific connector properties |
| 1651 | * @dev: DRM device |
| 1652 | * @num_modes: number of different TV formats (modes) supported |
| 1653 | * @modes: array of pointers to strings containing name of each format |
| 1654 | * |
| 1655 | * Called by a driver's TV initialization routine, this function creates |
| 1656 | * the TV specific connector properties for a given device. Caller is |
| 1657 | * responsible for allocating a list of format names and passing them to |
| 1658 | * this routine. |
| 1659 | */ |
Thierry Reding | 2f76331 | 2014-10-13 12:45:57 +0200 | [diff] [blame] | 1660 | int drm_mode_create_tv_properties(struct drm_device *dev, |
| 1661 | unsigned int num_modes, |
Ville Syrjälä | b7c914b | 2015-08-31 15:09:26 +0300 | [diff] [blame] | 1662 | const char * const modes[]) |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 1663 | { |
| 1664 | struct drm_property *tv_selector; |
| 1665 | struct drm_property *tv_subconnector; |
Thierry Reding | 2f76331 | 2014-10-13 12:45:57 +0200 | [diff] [blame] | 1666 | unsigned int i; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 1667 | |
| 1668 | if (dev->mode_config.tv_select_subconnector_property) |
| 1669 | return 0; |
| 1670 | |
| 1671 | /* |
| 1672 | * Basic connector properties |
| 1673 | */ |
Sascha Hauer | 4a67d39 | 2012-02-06 10:58:17 +0100 | [diff] [blame] | 1674 | tv_selector = drm_property_create_enum(dev, 0, |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 1675 | "select subconnector", |
Sascha Hauer | 4a67d39 | 2012-02-06 10:58:17 +0100 | [diff] [blame] | 1676 | drm_tv_select_enum_list, |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 1677 | ARRAY_SIZE(drm_tv_select_enum_list)); |
Insu Yun | 48aa1e7 | 2015-10-19 16:33:30 +0000 | [diff] [blame] | 1678 | if (!tv_selector) |
| 1679 | goto nomem; |
| 1680 | |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 1681 | dev->mode_config.tv_select_subconnector_property = tv_selector; |
| 1682 | |
| 1683 | tv_subconnector = |
Sascha Hauer | 4a67d39 | 2012-02-06 10:58:17 +0100 | [diff] [blame] | 1684 | drm_property_create_enum(dev, DRM_MODE_PROP_IMMUTABLE, |
| 1685 | "subconnector", |
| 1686 | drm_tv_subconnector_enum_list, |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 1687 | ARRAY_SIZE(drm_tv_subconnector_enum_list)); |
Insu Yun | 48aa1e7 | 2015-10-19 16:33:30 +0000 | [diff] [blame] | 1688 | if (!tv_subconnector) |
| 1689 | goto nomem; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 1690 | dev->mode_config.tv_subconnector_property = tv_subconnector; |
| 1691 | |
| 1692 | /* |
| 1693 | * Other, TV specific properties: margins & TV modes. |
| 1694 | */ |
| 1695 | dev->mode_config.tv_left_margin_property = |
Sascha Hauer | d9bc3c0 | 2012-02-06 10:58:18 +0100 | [diff] [blame] | 1696 | drm_property_create_range(dev, 0, "left margin", 0, 100); |
Insu Yun | 48aa1e7 | 2015-10-19 16:33:30 +0000 | [diff] [blame] | 1697 | if (!dev->mode_config.tv_left_margin_property) |
| 1698 | goto nomem; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 1699 | |
| 1700 | dev->mode_config.tv_right_margin_property = |
Sascha Hauer | d9bc3c0 | 2012-02-06 10:58:18 +0100 | [diff] [blame] | 1701 | drm_property_create_range(dev, 0, "right margin", 0, 100); |
Insu Yun | 48aa1e7 | 2015-10-19 16:33:30 +0000 | [diff] [blame] | 1702 | if (!dev->mode_config.tv_right_margin_property) |
| 1703 | goto nomem; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 1704 | |
| 1705 | dev->mode_config.tv_top_margin_property = |
Sascha Hauer | d9bc3c0 | 2012-02-06 10:58:18 +0100 | [diff] [blame] | 1706 | drm_property_create_range(dev, 0, "top margin", 0, 100); |
Insu Yun | 48aa1e7 | 2015-10-19 16:33:30 +0000 | [diff] [blame] | 1707 | if (!dev->mode_config.tv_top_margin_property) |
| 1708 | goto nomem; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 1709 | |
| 1710 | dev->mode_config.tv_bottom_margin_property = |
Sascha Hauer | d9bc3c0 | 2012-02-06 10:58:18 +0100 | [diff] [blame] | 1711 | drm_property_create_range(dev, 0, "bottom margin", 0, 100); |
Insu Yun | 48aa1e7 | 2015-10-19 16:33:30 +0000 | [diff] [blame] | 1712 | if (!dev->mode_config.tv_bottom_margin_property) |
| 1713 | goto nomem; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 1714 | |
| 1715 | dev->mode_config.tv_mode_property = |
| 1716 | drm_property_create(dev, DRM_MODE_PROP_ENUM, |
| 1717 | "mode", num_modes); |
Insu Yun | 48aa1e7 | 2015-10-19 16:33:30 +0000 | [diff] [blame] | 1718 | if (!dev->mode_config.tv_mode_property) |
| 1719 | goto nomem; |
| 1720 | |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 1721 | for (i = 0; i < num_modes; i++) |
| 1722 | drm_property_add_enum(dev->mode_config.tv_mode_property, i, |
| 1723 | i, modes[i]); |
| 1724 | |
Francisco Jerez | b6b7902 | 2009-08-02 04:19:20 +0200 | [diff] [blame] | 1725 | dev->mode_config.tv_brightness_property = |
Sascha Hauer | d9bc3c0 | 2012-02-06 10:58:18 +0100 | [diff] [blame] | 1726 | drm_property_create_range(dev, 0, "brightness", 0, 100); |
Insu Yun | 48aa1e7 | 2015-10-19 16:33:30 +0000 | [diff] [blame] | 1727 | if (!dev->mode_config.tv_brightness_property) |
| 1728 | goto nomem; |
Francisco Jerez | b6b7902 | 2009-08-02 04:19:20 +0200 | [diff] [blame] | 1729 | |
| 1730 | dev->mode_config.tv_contrast_property = |
Sascha Hauer | d9bc3c0 | 2012-02-06 10:58:18 +0100 | [diff] [blame] | 1731 | drm_property_create_range(dev, 0, "contrast", 0, 100); |
Insu Yun | 48aa1e7 | 2015-10-19 16:33:30 +0000 | [diff] [blame] | 1732 | if (!dev->mode_config.tv_contrast_property) |
| 1733 | goto nomem; |
Francisco Jerez | b6b7902 | 2009-08-02 04:19:20 +0200 | [diff] [blame] | 1734 | |
| 1735 | dev->mode_config.tv_flicker_reduction_property = |
Sascha Hauer | d9bc3c0 | 2012-02-06 10:58:18 +0100 | [diff] [blame] | 1736 | drm_property_create_range(dev, 0, "flicker reduction", 0, 100); |
Insu Yun | 48aa1e7 | 2015-10-19 16:33:30 +0000 | [diff] [blame] | 1737 | if (!dev->mode_config.tv_flicker_reduction_property) |
| 1738 | goto nomem; |
Francisco Jerez | b6b7902 | 2009-08-02 04:19:20 +0200 | [diff] [blame] | 1739 | |
Francisco Jerez | a75f023 | 2009-08-12 02:30:10 +0200 | [diff] [blame] | 1740 | dev->mode_config.tv_overscan_property = |
Sascha Hauer | d9bc3c0 | 2012-02-06 10:58:18 +0100 | [diff] [blame] | 1741 | drm_property_create_range(dev, 0, "overscan", 0, 100); |
Insu Yun | 48aa1e7 | 2015-10-19 16:33:30 +0000 | [diff] [blame] | 1742 | if (!dev->mode_config.tv_overscan_property) |
| 1743 | goto nomem; |
Francisco Jerez | a75f023 | 2009-08-12 02:30:10 +0200 | [diff] [blame] | 1744 | |
| 1745 | dev->mode_config.tv_saturation_property = |
Sascha Hauer | d9bc3c0 | 2012-02-06 10:58:18 +0100 | [diff] [blame] | 1746 | drm_property_create_range(dev, 0, "saturation", 0, 100); |
Insu Yun | 48aa1e7 | 2015-10-19 16:33:30 +0000 | [diff] [blame] | 1747 | if (!dev->mode_config.tv_saturation_property) |
| 1748 | goto nomem; |
Francisco Jerez | a75f023 | 2009-08-12 02:30:10 +0200 | [diff] [blame] | 1749 | |
| 1750 | dev->mode_config.tv_hue_property = |
Sascha Hauer | d9bc3c0 | 2012-02-06 10:58:18 +0100 | [diff] [blame] | 1751 | drm_property_create_range(dev, 0, "hue", 0, 100); |
Insu Yun | 48aa1e7 | 2015-10-19 16:33:30 +0000 | [diff] [blame] | 1752 | if (!dev->mode_config.tv_hue_property) |
| 1753 | goto nomem; |
Francisco Jerez | a75f023 | 2009-08-12 02:30:10 +0200 | [diff] [blame] | 1754 | |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 1755 | return 0; |
Insu Yun | 48aa1e7 | 2015-10-19 16:33:30 +0000 | [diff] [blame] | 1756 | nomem: |
| 1757 | return -ENOMEM; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 1758 | } |
| 1759 | EXPORT_SYMBOL(drm_mode_create_tv_properties); |
| 1760 | |
| 1761 | /** |
| 1762 | * drm_mode_create_scaling_mode_property - create scaling mode property |
| 1763 | * @dev: DRM device |
| 1764 | * |
| 1765 | * Called by a driver the first time it's needed, must be attached to desired |
| 1766 | * connectors. |
| 1767 | */ |
| 1768 | int drm_mode_create_scaling_mode_property(struct drm_device *dev) |
| 1769 | { |
| 1770 | struct drm_property *scaling_mode; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 1771 | |
| 1772 | if (dev->mode_config.scaling_mode_property) |
| 1773 | return 0; |
| 1774 | |
| 1775 | scaling_mode = |
Sascha Hauer | 4a67d39 | 2012-02-06 10:58:17 +0100 | [diff] [blame] | 1776 | drm_property_create_enum(dev, 0, "scaling mode", |
| 1777 | drm_scaling_mode_enum_list, |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 1778 | ARRAY_SIZE(drm_scaling_mode_enum_list)); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 1779 | |
| 1780 | dev->mode_config.scaling_mode_property = scaling_mode; |
| 1781 | |
| 1782 | return 0; |
| 1783 | } |
| 1784 | EXPORT_SYMBOL(drm_mode_create_scaling_mode_property); |
| 1785 | |
| 1786 | /** |
Vandana Kannan | ff587e4 | 2014-06-11 10:46:48 +0530 | [diff] [blame] | 1787 | * drm_mode_create_aspect_ratio_property - create aspect ratio property |
| 1788 | * @dev: DRM device |
| 1789 | * |
| 1790 | * Called by a driver the first time it's needed, must be attached to desired |
| 1791 | * connectors. |
| 1792 | * |
| 1793 | * Returns: |
Daniel Vetter | 1a49863 | 2014-11-19 18:38:09 +0100 | [diff] [blame] | 1794 | * Zero on success, negative errno on failure. |
Vandana Kannan | ff587e4 | 2014-06-11 10:46:48 +0530 | [diff] [blame] | 1795 | */ |
| 1796 | int drm_mode_create_aspect_ratio_property(struct drm_device *dev) |
| 1797 | { |
| 1798 | if (dev->mode_config.aspect_ratio_property) |
| 1799 | return 0; |
| 1800 | |
| 1801 | dev->mode_config.aspect_ratio_property = |
| 1802 | drm_property_create_enum(dev, 0, "aspect ratio", |
| 1803 | drm_aspect_ratio_enum_list, |
| 1804 | ARRAY_SIZE(drm_aspect_ratio_enum_list)); |
| 1805 | |
| 1806 | if (dev->mode_config.aspect_ratio_property == NULL) |
| 1807 | return -ENOMEM; |
| 1808 | |
| 1809 | return 0; |
| 1810 | } |
| 1811 | EXPORT_SYMBOL(drm_mode_create_aspect_ratio_property); |
| 1812 | |
| 1813 | /** |
Jakob Bornecrantz | 884840a | 2009-12-03 23:25:47 +0000 | [diff] [blame] | 1814 | * drm_mode_create_dirty_property - create dirty property |
| 1815 | * @dev: DRM device |
| 1816 | * |
| 1817 | * Called by a driver the first time it's needed, must be attached to desired |
| 1818 | * connectors. |
| 1819 | */ |
| 1820 | int drm_mode_create_dirty_info_property(struct drm_device *dev) |
| 1821 | { |
| 1822 | struct drm_property *dirty_info; |
Jakob Bornecrantz | 884840a | 2009-12-03 23:25:47 +0000 | [diff] [blame] | 1823 | |
| 1824 | if (dev->mode_config.dirty_info_property) |
| 1825 | return 0; |
| 1826 | |
| 1827 | dirty_info = |
Sascha Hauer | 4a67d39 | 2012-02-06 10:58:17 +0100 | [diff] [blame] | 1828 | drm_property_create_enum(dev, DRM_MODE_PROP_IMMUTABLE, |
Jakob Bornecrantz | 884840a | 2009-12-03 23:25:47 +0000 | [diff] [blame] | 1829 | "dirty", |
Sascha Hauer | 4a67d39 | 2012-02-06 10:58:17 +0100 | [diff] [blame] | 1830 | drm_dirty_info_enum_list, |
Jakob Bornecrantz | 884840a | 2009-12-03 23:25:47 +0000 | [diff] [blame] | 1831 | ARRAY_SIZE(drm_dirty_info_enum_list)); |
Jakob Bornecrantz | 884840a | 2009-12-03 23:25:47 +0000 | [diff] [blame] | 1832 | dev->mode_config.dirty_info_property = dirty_info; |
| 1833 | |
| 1834 | return 0; |
| 1835 | } |
| 1836 | EXPORT_SYMBOL(drm_mode_create_dirty_info_property); |
| 1837 | |
Dave Airlie | 5bb2bbf | 2014-11-10 10:18:15 +1000 | [diff] [blame] | 1838 | /** |
| 1839 | * drm_mode_create_suggested_offset_properties - create suggests offset properties |
| 1840 | * @dev: DRM device |
| 1841 | * |
| 1842 | * Create the the suggested x/y offset property for connectors. |
| 1843 | */ |
| 1844 | int drm_mode_create_suggested_offset_properties(struct drm_device *dev) |
| 1845 | { |
| 1846 | if (dev->mode_config.suggested_x_property && dev->mode_config.suggested_y_property) |
| 1847 | return 0; |
| 1848 | |
| 1849 | dev->mode_config.suggested_x_property = |
| 1850 | drm_property_create_range(dev, DRM_MODE_PROP_IMMUTABLE, "suggested X", 0, 0xffffffff); |
| 1851 | |
| 1852 | dev->mode_config.suggested_y_property = |
| 1853 | drm_property_create_range(dev, DRM_MODE_PROP_IMMUTABLE, "suggested Y", 0, 0xffffffff); |
| 1854 | |
| 1855 | if (dev->mode_config.suggested_x_property == NULL || |
| 1856 | dev->mode_config.suggested_y_property == NULL) |
| 1857 | return -ENOMEM; |
| 1858 | return 0; |
| 1859 | } |
| 1860 | EXPORT_SYMBOL(drm_mode_create_suggested_offset_properties); |
| 1861 | |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 1862 | /** |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 1863 | * drm_mode_getresources - get graphics configuration |
Daniel Vetter | 065a50ed | 2012-12-02 00:09:18 +0100 | [diff] [blame] | 1864 | * @dev: drm device for the ioctl |
| 1865 | * @data: data pointer for the ioctl |
| 1866 | * @file_priv: drm file for the ioctl call |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 1867 | * |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 1868 | * Construct a set of configuration description structures and return |
| 1869 | * them to the user, including CRTC, connector and framebuffer configuration. |
| 1870 | * |
| 1871 | * Called by the user via ioctl. |
| 1872 | * |
Daniel Vetter | c8e32cc | 2014-03-10 21:33:02 +0100 | [diff] [blame] | 1873 | * Returns: |
Daniel Vetter | 1a49863 | 2014-11-19 18:38:09 +0100 | [diff] [blame] | 1874 | * Zero on success, negative errno on failure. |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 1875 | */ |
| 1876 | int drm_mode_getresources(struct drm_device *dev, void *data, |
| 1877 | struct drm_file *file_priv) |
| 1878 | { |
| 1879 | struct drm_mode_card_res *card_res = data; |
| 1880 | struct list_head *lh; |
| 1881 | struct drm_framebuffer *fb; |
| 1882 | struct drm_connector *connector; |
| 1883 | struct drm_crtc *crtc; |
| 1884 | struct drm_encoder *encoder; |
| 1885 | int ret = 0; |
| 1886 | int connector_count = 0; |
| 1887 | int crtc_count = 0; |
| 1888 | int fb_count = 0; |
| 1889 | int encoder_count = 0; |
Daniel Vetter | 9c7060f | 2015-07-09 23:44:36 +0200 | [diff] [blame] | 1890 | int copied = 0; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 1891 | uint32_t __user *fb_id; |
| 1892 | uint32_t __user *crtc_id; |
| 1893 | uint32_t __user *connector_id; |
| 1894 | uint32_t __user *encoder_id; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 1895 | |
Dave Airlie | fb3b06c | 2011-02-08 13:55:21 +1000 | [diff] [blame] | 1896 | if (!drm_core_check_feature(dev, DRIVER_MODESET)) |
| 1897 | return -EINVAL; |
| 1898 | |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 1899 | |
Daniel Vetter | 4b096ac | 2012-12-10 21:19:18 +0100 | [diff] [blame] | 1900 | mutex_lock(&file_priv->fbs_lock); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 1901 | /* |
| 1902 | * For the non-control nodes we need to limit the list of resources |
| 1903 | * by IDs in the group list for this node |
| 1904 | */ |
| 1905 | list_for_each(lh, &file_priv->fbs) |
| 1906 | fb_count++; |
| 1907 | |
Daniel Vetter | 4b096ac | 2012-12-10 21:19:18 +0100 | [diff] [blame] | 1908 | /* handle this in 4 parts */ |
| 1909 | /* FBs */ |
| 1910 | if (card_res->count_fbs >= fb_count) { |
| 1911 | copied = 0; |
| 1912 | fb_id = (uint32_t __user *)(unsigned long)card_res->fb_id_ptr; |
| 1913 | list_for_each_entry(fb, &file_priv->fbs, filp_head) { |
| 1914 | if (put_user(fb->base.id, fb_id + copied)) { |
| 1915 | mutex_unlock(&file_priv->fbs_lock); |
| 1916 | return -EFAULT; |
| 1917 | } |
| 1918 | copied++; |
| 1919 | } |
| 1920 | } |
| 1921 | card_res->count_fbs = fb_count; |
| 1922 | mutex_unlock(&file_priv->fbs_lock); |
| 1923 | |
Daniel Vetter | fcf93f6 | 2014-11-12 08:45:01 +0100 | [diff] [blame] | 1924 | /* mode_config.mutex protects the connector list against e.g. DP MST |
| 1925 | * connector hot-adding. CRTC/Plane lists are invariant. */ |
| 1926 | mutex_lock(&dev->mode_config.mutex); |
Daniel Vetter | 9c7060f | 2015-07-09 23:44:36 +0200 | [diff] [blame] | 1927 | drm_for_each_crtc(crtc, dev) |
| 1928 | crtc_count++; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 1929 | |
Daniel Vetter | 9c7060f | 2015-07-09 23:44:36 +0200 | [diff] [blame] | 1930 | drm_for_each_connector(connector, dev) |
| 1931 | connector_count++; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 1932 | |
Daniel Vetter | 9c7060f | 2015-07-09 23:44:36 +0200 | [diff] [blame] | 1933 | drm_for_each_encoder(encoder, dev) |
| 1934 | encoder_count++; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 1935 | |
| 1936 | card_res->max_height = dev->mode_config.max_height; |
| 1937 | card_res->min_height = dev->mode_config.min_height; |
| 1938 | card_res->max_width = dev->mode_config.max_width; |
| 1939 | card_res->min_width = dev->mode_config.min_width; |
| 1940 | |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 1941 | /* CRTCs */ |
| 1942 | if (card_res->count_crtcs >= crtc_count) { |
| 1943 | copied = 0; |
| 1944 | crtc_id = (uint32_t __user *)(unsigned long)card_res->crtc_id_ptr; |
Daniel Vetter | 9c7060f | 2015-07-09 23:44:36 +0200 | [diff] [blame] | 1945 | drm_for_each_crtc(crtc, dev) { |
Ville Syrjälä | fa3ab4c | 2015-12-08 18:41:53 +0200 | [diff] [blame] | 1946 | DRM_DEBUG_KMS("[CRTC:%d:%s]\n", |
| 1947 | crtc->base.id, crtc->name); |
Daniel Vetter | 9c7060f | 2015-07-09 23:44:36 +0200 | [diff] [blame] | 1948 | if (put_user(crtc->base.id, crtc_id + copied)) { |
| 1949 | ret = -EFAULT; |
| 1950 | goto out; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 1951 | } |
Daniel Vetter | 9c7060f | 2015-07-09 23:44:36 +0200 | [diff] [blame] | 1952 | copied++; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 1953 | } |
| 1954 | } |
| 1955 | card_res->count_crtcs = crtc_count; |
| 1956 | |
| 1957 | /* Encoders */ |
| 1958 | if (card_res->count_encoders >= encoder_count) { |
| 1959 | copied = 0; |
| 1960 | encoder_id = (uint32_t __user *)(unsigned long)card_res->encoder_id_ptr; |
Daniel Vetter | 9c7060f | 2015-07-09 23:44:36 +0200 | [diff] [blame] | 1961 | drm_for_each_encoder(encoder, dev) { |
| 1962 | DRM_DEBUG_KMS("[ENCODER:%d:%s]\n", encoder->base.id, |
| 1963 | encoder->name); |
| 1964 | if (put_user(encoder->base.id, encoder_id + |
| 1965 | copied)) { |
| 1966 | ret = -EFAULT; |
| 1967 | goto out; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 1968 | } |
Daniel Vetter | 9c7060f | 2015-07-09 23:44:36 +0200 | [diff] [blame] | 1969 | copied++; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 1970 | } |
| 1971 | } |
| 1972 | card_res->count_encoders = encoder_count; |
| 1973 | |
| 1974 | /* Connectors */ |
| 1975 | if (card_res->count_connectors >= connector_count) { |
| 1976 | copied = 0; |
| 1977 | connector_id = (uint32_t __user *)(unsigned long)card_res->connector_id_ptr; |
Daniel Vetter | 9c7060f | 2015-07-09 23:44:36 +0200 | [diff] [blame] | 1978 | drm_for_each_connector(connector, dev) { |
| 1979 | DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n", |
| 1980 | connector->base.id, |
| 1981 | connector->name); |
| 1982 | if (put_user(connector->base.id, |
| 1983 | connector_id + copied)) { |
| 1984 | ret = -EFAULT; |
| 1985 | goto out; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 1986 | } |
Daniel Vetter | 9c7060f | 2015-07-09 23:44:36 +0200 | [diff] [blame] | 1987 | copied++; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 1988 | } |
| 1989 | } |
| 1990 | card_res->count_connectors = connector_count; |
| 1991 | |
Jerome Glisse | 9440106 | 2010-07-15 15:43:25 -0400 | [diff] [blame] | 1992 | 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] | 1993 | card_res->count_connectors, card_res->count_encoders); |
| 1994 | |
| 1995 | out: |
Daniel Vetter | fcf93f6 | 2014-11-12 08:45:01 +0100 | [diff] [blame] | 1996 | mutex_unlock(&dev->mode_config.mutex); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 1997 | return ret; |
| 1998 | } |
| 1999 | |
| 2000 | /** |
| 2001 | * drm_mode_getcrtc - get CRTC configuration |
Daniel Vetter | 065a50ed | 2012-12-02 00:09:18 +0100 | [diff] [blame] | 2002 | * @dev: drm device for the ioctl |
| 2003 | * @data: data pointer for the ioctl |
| 2004 | * @file_priv: drm file for the ioctl call |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 2005 | * |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 2006 | * Construct a CRTC configuration structure to return to the user. |
| 2007 | * |
| 2008 | * Called by the user via ioctl. |
| 2009 | * |
Daniel Vetter | c8e32cc | 2014-03-10 21:33:02 +0100 | [diff] [blame] | 2010 | * Returns: |
Daniel Vetter | 1a49863 | 2014-11-19 18:38:09 +0100 | [diff] [blame] | 2011 | * Zero on success, negative errno on failure. |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 2012 | */ |
| 2013 | int drm_mode_getcrtc(struct drm_device *dev, |
| 2014 | void *data, struct drm_file *file_priv) |
| 2015 | { |
| 2016 | struct drm_mode_crtc *crtc_resp = data; |
| 2017 | struct drm_crtc *crtc; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 2018 | |
Dave Airlie | fb3b06c | 2011-02-08 13:55:21 +1000 | [diff] [blame] | 2019 | if (!drm_core_check_feature(dev, DRIVER_MODESET)) |
| 2020 | return -EINVAL; |
| 2021 | |
Rob Clark | a2b34e2 | 2013-10-05 16:36:52 -0400 | [diff] [blame] | 2022 | crtc = drm_crtc_find(dev, crtc_resp->crtc_id); |
Daniel Vetter | fcf93f6 | 2014-11-12 08:45:01 +0100 | [diff] [blame] | 2023 | if (!crtc) |
| 2024 | return -ENOENT; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 2025 | |
Daniel Vetter | fcf93f6 | 2014-11-12 08:45:01 +0100 | [diff] [blame] | 2026 | drm_modeset_lock_crtc(crtc, crtc->primary); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 2027 | crtc_resp->gamma_size = crtc->gamma_size; |
Matt Roper | f4510a2 | 2014-04-01 15:22:40 -0700 | [diff] [blame] | 2028 | if (crtc->primary->fb) |
| 2029 | crtc_resp->fb_id = crtc->primary->fb->base.id; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 2030 | else |
| 2031 | crtc_resp->fb_id = 0; |
| 2032 | |
Daniel Vetter | 31c946e | 2015-02-22 12:24:17 +0100 | [diff] [blame] | 2033 | if (crtc->state) { |
| 2034 | crtc_resp->x = crtc->primary->state->src_x >> 16; |
| 2035 | crtc_resp->y = crtc->primary->state->src_y >> 16; |
| 2036 | if (crtc->state->enable) { |
Daniel Stone | 934a8a8 | 2015-05-22 13:34:48 +0100 | [diff] [blame] | 2037 | drm_mode_convert_to_umode(&crtc_resp->mode, &crtc->state->mode); |
Daniel Vetter | 31c946e | 2015-02-22 12:24:17 +0100 | [diff] [blame] | 2038 | crtc_resp->mode_valid = 1; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 2039 | |
Daniel Vetter | 31c946e | 2015-02-22 12:24:17 +0100 | [diff] [blame] | 2040 | } else { |
| 2041 | crtc_resp->mode_valid = 0; |
| 2042 | } |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 2043 | } else { |
Daniel Vetter | 31c946e | 2015-02-22 12:24:17 +0100 | [diff] [blame] | 2044 | crtc_resp->x = crtc->x; |
| 2045 | crtc_resp->y = crtc->y; |
| 2046 | if (crtc->enabled) { |
Daniel Stone | 934a8a8 | 2015-05-22 13:34:48 +0100 | [diff] [blame] | 2047 | drm_mode_convert_to_umode(&crtc_resp->mode, &crtc->mode); |
Daniel Vetter | 31c946e | 2015-02-22 12:24:17 +0100 | [diff] [blame] | 2048 | crtc_resp->mode_valid = 1; |
| 2049 | |
| 2050 | } else { |
| 2051 | crtc_resp->mode_valid = 0; |
| 2052 | } |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 2053 | } |
Daniel Vetter | fcf93f6 | 2014-11-12 08:45:01 +0100 | [diff] [blame] | 2054 | drm_modeset_unlock_crtc(crtc); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 2055 | |
Daniel Vetter | baf698b | 2014-11-12 11:59:47 +0100 | [diff] [blame] | 2056 | return 0; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 2057 | } |
| 2058 | |
Damien Lespiau | 61d8e32 | 2013-09-25 16:45:22 +0100 | [diff] [blame] | 2059 | static bool drm_mode_expose_to_userspace(const struct drm_display_mode *mode, |
| 2060 | const struct drm_file *file_priv) |
| 2061 | { |
| 2062 | /* |
| 2063 | * If user-space hasn't configured the driver to expose the stereo 3D |
| 2064 | * modes, don't expose them. |
| 2065 | */ |
| 2066 | if (!file_priv->stereo_allowed && drm_mode_is_stereo(mode)) |
| 2067 | return false; |
| 2068 | |
| 2069 | return true; |
| 2070 | } |
| 2071 | |
Daniel Vetter | abd69c5 | 2014-11-25 23:50:05 +0100 | [diff] [blame] | 2072 | static struct drm_encoder *drm_connector_get_encoder(struct drm_connector *connector) |
| 2073 | { |
| 2074 | /* For atomic drivers only state objects are synchronously updated and |
| 2075 | * protected by modeset locks, so check those first. */ |
| 2076 | if (connector->state) |
| 2077 | return connector->state->best_encoder; |
| 2078 | return connector->encoder; |
| 2079 | } |
| 2080 | |
Rob Clark | 95cbf11 | 2014-12-18 16:01:49 -0500 | [diff] [blame] | 2081 | /* helper for getconnector and getproperties ioctls */ |
Rob Clark | 88a48e2 | 2014-12-18 16:01:50 -0500 | [diff] [blame] | 2082 | static int get_properties(struct drm_mode_object *obj, bool atomic, |
Rob Clark | 95cbf11 | 2014-12-18 16:01:49 -0500 | [diff] [blame] | 2083 | uint32_t __user *prop_ptr, uint64_t __user *prop_values, |
| 2084 | uint32_t *arg_count_props) |
| 2085 | { |
Rob Clark | 88a48e2 | 2014-12-18 16:01:50 -0500 | [diff] [blame] | 2086 | int props_count; |
| 2087 | int i, ret, copied; |
| 2088 | |
| 2089 | props_count = obj->properties->count; |
| 2090 | if (!atomic) |
| 2091 | props_count -= obj->properties->atomic_count; |
Rob Clark | 95cbf11 | 2014-12-18 16:01:49 -0500 | [diff] [blame] | 2092 | |
| 2093 | if ((*arg_count_props >= props_count) && props_count) { |
Rob Clark | 88a48e2 | 2014-12-18 16:01:50 -0500 | [diff] [blame] | 2094 | for (i = 0, copied = 0; copied < props_count; i++) { |
Rob Clark | 95cbf11 | 2014-12-18 16:01:49 -0500 | [diff] [blame] | 2095 | struct drm_property *prop = obj->properties->properties[i]; |
| 2096 | uint64_t val; |
| 2097 | |
Rob Clark | 88a48e2 | 2014-12-18 16:01:50 -0500 | [diff] [blame] | 2098 | if ((prop->flags & DRM_MODE_PROP_ATOMIC) && !atomic) |
| 2099 | continue; |
| 2100 | |
Rob Clark | 95cbf11 | 2014-12-18 16:01:49 -0500 | [diff] [blame] | 2101 | ret = drm_object_property_get_value(obj, prop, &val); |
| 2102 | if (ret) |
| 2103 | return ret; |
| 2104 | |
| 2105 | if (put_user(prop->base.id, prop_ptr + copied)) |
| 2106 | return -EFAULT; |
| 2107 | |
| 2108 | if (put_user(val, prop_values + copied)) |
| 2109 | return -EFAULT; |
| 2110 | |
| 2111 | copied++; |
| 2112 | } |
| 2113 | } |
| 2114 | *arg_count_props = props_count; |
| 2115 | |
| 2116 | return 0; |
| 2117 | } |
| 2118 | |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 2119 | /** |
| 2120 | * drm_mode_getconnector - get connector configuration |
Daniel Vetter | 065a50ed | 2012-12-02 00:09:18 +0100 | [diff] [blame] | 2121 | * @dev: drm device for the ioctl |
| 2122 | * @data: data pointer for the ioctl |
| 2123 | * @file_priv: drm file for the ioctl call |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 2124 | * |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 2125 | * Construct a connector configuration structure to return to the user. |
| 2126 | * |
| 2127 | * Called by the user via ioctl. |
| 2128 | * |
Daniel Vetter | c8e32cc | 2014-03-10 21:33:02 +0100 | [diff] [blame] | 2129 | * Returns: |
Daniel Vetter | 1a49863 | 2014-11-19 18:38:09 +0100 | [diff] [blame] | 2130 | * Zero on success, negative errno on failure. |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 2131 | */ |
| 2132 | int drm_mode_getconnector(struct drm_device *dev, void *data, |
| 2133 | struct drm_file *file_priv) |
| 2134 | { |
| 2135 | struct drm_mode_get_connector *out_resp = data; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 2136 | struct drm_connector *connector; |
Daniel Vetter | abd69c5 | 2014-11-25 23:50:05 +0100 | [diff] [blame] | 2137 | struct drm_encoder *encoder; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 2138 | struct drm_display_mode *mode; |
| 2139 | int mode_count = 0; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 2140 | int encoders_count = 0; |
| 2141 | int ret = 0; |
| 2142 | int copied = 0; |
| 2143 | int i; |
| 2144 | struct drm_mode_modeinfo u_mode; |
| 2145 | struct drm_mode_modeinfo __user *mode_ptr; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 2146 | uint32_t __user *encoder_ptr; |
| 2147 | |
Dave Airlie | fb3b06c | 2011-02-08 13:55:21 +1000 | [diff] [blame] | 2148 | if (!drm_core_check_feature(dev, DRIVER_MODESET)) |
| 2149 | return -EINVAL; |
| 2150 | |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 2151 | memset(&u_mode, 0, sizeof(struct drm_mode_modeinfo)); |
| 2152 | |
Jerome Glisse | 9440106 | 2010-07-15 15:43:25 -0400 | [diff] [blame] | 2153 | DRM_DEBUG_KMS("[CONNECTOR:%d:?]\n", out_resp->connector_id); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 2154 | |
Daniel Vetter | 7b24056 | 2012-12-12 00:35:33 +0100 | [diff] [blame] | 2155 | mutex_lock(&dev->mode_config.mutex); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 2156 | |
Rob Clark | a2b34e2 | 2013-10-05 16:36:52 -0400 | [diff] [blame] | 2157 | connector = drm_connector_find(dev, out_resp->connector_id); |
| 2158 | if (!connector) { |
Ville Syrjälä | f27657f | 2013-10-17 13:35:00 +0300 | [diff] [blame] | 2159 | ret = -ENOENT; |
Tommi Rantala | 04bdf44 | 2015-04-03 10:45:29 +0300 | [diff] [blame] | 2160 | goto out_unlock; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 2161 | } |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 2162 | |
Thierry Reding | 01073b0 | 2014-12-10 13:03:38 +0100 | [diff] [blame] | 2163 | for (i = 0; i < DRM_CONNECTOR_MAX_ENCODER; i++) |
| 2164 | if (connector->encoder_ids[i] != 0) |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 2165 | encoders_count++; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 2166 | |
| 2167 | if (out_resp->count_modes == 0) { |
| 2168 | connector->funcs->fill_modes(connector, |
| 2169 | dev->mode_config.max_width, |
| 2170 | dev->mode_config.max_height); |
| 2171 | } |
| 2172 | |
| 2173 | /* delayed so we get modes regardless of pre-fill_modes state */ |
| 2174 | list_for_each_entry(mode, &connector->modes, head) |
Damien Lespiau | 61d8e32 | 2013-09-25 16:45:22 +0100 | [diff] [blame] | 2175 | if (drm_mode_expose_to_userspace(mode, file_priv)) |
| 2176 | mode_count++; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 2177 | |
| 2178 | out_resp->connector_id = connector->base.id; |
| 2179 | out_resp->connector_type = connector->connector_type; |
| 2180 | out_resp->connector_type_id = connector->connector_type_id; |
| 2181 | out_resp->mm_width = connector->display_info.width_mm; |
| 2182 | out_resp->mm_height = connector->display_info.height_mm; |
| 2183 | out_resp->subpixel = connector->display_info.subpixel_order; |
| 2184 | out_resp->connection = connector->status; |
Daniel Vetter | 2caa80e | 2015-02-22 11:38:36 +0100 | [diff] [blame] | 2185 | |
| 2186 | drm_modeset_lock(&dev->mode_config.connection_mutex, NULL); |
Daniel Vetter | abd69c5 | 2014-11-25 23:50:05 +0100 | [diff] [blame] | 2187 | encoder = drm_connector_get_encoder(connector); |
| 2188 | if (encoder) |
| 2189 | out_resp->encoder_id = encoder->base.id; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 2190 | else |
| 2191 | out_resp->encoder_id = 0; |
| 2192 | |
| 2193 | /* |
| 2194 | * This ioctl is called twice, once to determine how much space is |
| 2195 | * needed, and the 2nd time to fill it. |
| 2196 | */ |
| 2197 | if ((out_resp->count_modes >= mode_count) && mode_count) { |
| 2198 | copied = 0; |
Ville Syrjälä | 81f6c7f | 2011-12-20 00:06:42 +0200 | [diff] [blame] | 2199 | 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] | 2200 | list_for_each_entry(mode, &connector->modes, head) { |
Damien Lespiau | 61d8e32 | 2013-09-25 16:45:22 +0100 | [diff] [blame] | 2201 | if (!drm_mode_expose_to_userspace(mode, file_priv)) |
| 2202 | continue; |
| 2203 | |
Daniel Stone | 934a8a8 | 2015-05-22 13:34:48 +0100 | [diff] [blame] | 2204 | drm_mode_convert_to_umode(&u_mode, mode); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 2205 | if (copy_to_user(mode_ptr + copied, |
| 2206 | &u_mode, sizeof(u_mode))) { |
| 2207 | ret = -EFAULT; |
| 2208 | goto out; |
| 2209 | } |
| 2210 | copied++; |
| 2211 | } |
| 2212 | } |
| 2213 | out_resp->count_modes = mode_count; |
| 2214 | |
Rob Clark | 88a48e2 | 2014-12-18 16:01:50 -0500 | [diff] [blame] | 2215 | ret = get_properties(&connector->base, file_priv->atomic, |
Rob Clark | 95cbf11 | 2014-12-18 16:01:49 -0500 | [diff] [blame] | 2216 | (uint32_t __user *)(unsigned long)(out_resp->props_ptr), |
| 2217 | (uint64_t __user *)(unsigned long)(out_resp->prop_values_ptr), |
| 2218 | &out_resp->count_props); |
| 2219 | if (ret) |
| 2220 | goto out; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 2221 | |
| 2222 | if ((out_resp->count_encoders >= encoders_count) && encoders_count) { |
| 2223 | copied = 0; |
Ville Syrjälä | 81f6c7f | 2011-12-20 00:06:42 +0200 | [diff] [blame] | 2224 | encoder_ptr = (uint32_t __user *)(unsigned long)(out_resp->encoders_ptr); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 2225 | for (i = 0; i < DRM_CONNECTOR_MAX_ENCODER; i++) { |
| 2226 | if (connector->encoder_ids[i] != 0) { |
| 2227 | if (put_user(connector->encoder_ids[i], |
| 2228 | encoder_ptr + copied)) { |
| 2229 | ret = -EFAULT; |
| 2230 | goto out; |
| 2231 | } |
| 2232 | copied++; |
| 2233 | } |
| 2234 | } |
| 2235 | } |
| 2236 | out_resp->count_encoders = encoders_count; |
| 2237 | |
| 2238 | out: |
Rob Clark | ccfc086 | 2014-12-18 16:01:48 -0500 | [diff] [blame] | 2239 | drm_modeset_unlock(&dev->mode_config.connection_mutex); |
Tommi Rantala | 04bdf44 | 2015-04-03 10:45:29 +0300 | [diff] [blame] | 2240 | |
| 2241 | out_unlock: |
Daniel Vetter | 7b24056 | 2012-12-12 00:35:33 +0100 | [diff] [blame] | 2242 | mutex_unlock(&dev->mode_config.mutex); |
| 2243 | |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 2244 | return ret; |
| 2245 | } |
| 2246 | |
Daniel Vetter | abd69c5 | 2014-11-25 23:50:05 +0100 | [diff] [blame] | 2247 | static struct drm_crtc *drm_encoder_get_crtc(struct drm_encoder *encoder) |
| 2248 | { |
| 2249 | struct drm_connector *connector; |
| 2250 | struct drm_device *dev = encoder->dev; |
| 2251 | bool uses_atomic = false; |
| 2252 | |
| 2253 | /* For atomic drivers only state objects are synchronously updated and |
| 2254 | * protected by modeset locks, so check those first. */ |
Daniel Vetter | 6295d60 | 2015-07-09 23:44:25 +0200 | [diff] [blame] | 2255 | drm_for_each_connector(connector, dev) { |
Daniel Vetter | abd69c5 | 2014-11-25 23:50:05 +0100 | [diff] [blame] | 2256 | if (!connector->state) |
| 2257 | continue; |
| 2258 | |
| 2259 | uses_atomic = true; |
| 2260 | |
| 2261 | if (connector->state->best_encoder != encoder) |
| 2262 | continue; |
| 2263 | |
| 2264 | return connector->state->crtc; |
| 2265 | } |
| 2266 | |
| 2267 | /* Don't return stale data (e.g. pending async disable). */ |
| 2268 | if (uses_atomic) |
| 2269 | return NULL; |
| 2270 | |
| 2271 | return encoder->crtc; |
| 2272 | } |
| 2273 | |
Daniel Vetter | c8e32cc | 2014-03-10 21:33:02 +0100 | [diff] [blame] | 2274 | /** |
| 2275 | * drm_mode_getencoder - get encoder configuration |
| 2276 | * @dev: drm device for the ioctl |
| 2277 | * @data: data pointer for the ioctl |
| 2278 | * @file_priv: drm file for the ioctl call |
| 2279 | * |
| 2280 | * Construct a encoder configuration structure to return to the user. |
| 2281 | * |
| 2282 | * Called by the user via ioctl. |
| 2283 | * |
| 2284 | * Returns: |
Daniel Vetter | 1a49863 | 2014-11-19 18:38:09 +0100 | [diff] [blame] | 2285 | * Zero on success, negative errno on failure. |
Daniel Vetter | c8e32cc | 2014-03-10 21:33:02 +0100 | [diff] [blame] | 2286 | */ |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 2287 | int drm_mode_getencoder(struct drm_device *dev, void *data, |
| 2288 | struct drm_file *file_priv) |
| 2289 | { |
| 2290 | struct drm_mode_get_encoder *enc_resp = data; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 2291 | struct drm_encoder *encoder; |
Daniel Vetter | abd69c5 | 2014-11-25 23:50:05 +0100 | [diff] [blame] | 2292 | struct drm_crtc *crtc; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 2293 | |
Dave Airlie | fb3b06c | 2011-02-08 13:55:21 +1000 | [diff] [blame] | 2294 | if (!drm_core_check_feature(dev, DRIVER_MODESET)) |
| 2295 | return -EINVAL; |
| 2296 | |
Rob Clark | a2b34e2 | 2013-10-05 16:36:52 -0400 | [diff] [blame] | 2297 | encoder = drm_encoder_find(dev, enc_resp->encoder_id); |
Daniel Vetter | fcf93f6 | 2014-11-12 08:45:01 +0100 | [diff] [blame] | 2298 | if (!encoder) |
| 2299 | return -ENOENT; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 2300 | |
Daniel Vetter | fcf93f6 | 2014-11-12 08:45:01 +0100 | [diff] [blame] | 2301 | drm_modeset_lock(&dev->mode_config.connection_mutex, NULL); |
Daniel Vetter | abd69c5 | 2014-11-25 23:50:05 +0100 | [diff] [blame] | 2302 | crtc = drm_encoder_get_crtc(encoder); |
| 2303 | if (crtc) |
| 2304 | enc_resp->crtc_id = crtc->base.id; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 2305 | else |
| 2306 | enc_resp->crtc_id = 0; |
Daniel Vetter | fcf93f6 | 2014-11-12 08:45:01 +0100 | [diff] [blame] | 2307 | drm_modeset_unlock(&dev->mode_config.connection_mutex); |
| 2308 | |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 2309 | enc_resp->encoder_type = encoder->encoder_type; |
| 2310 | enc_resp->encoder_id = encoder->base.id; |
| 2311 | enc_resp->possible_crtcs = encoder->possible_crtcs; |
| 2312 | enc_resp->possible_clones = encoder->possible_clones; |
| 2313 | |
Daniel Vetter | baf698b | 2014-11-12 11:59:47 +0100 | [diff] [blame] | 2314 | return 0; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 2315 | } |
| 2316 | |
| 2317 | /** |
Daniel Vetter | c8e32cc | 2014-03-10 21:33:02 +0100 | [diff] [blame] | 2318 | * drm_mode_getplane_res - enumerate all plane resources |
Jesse Barnes | 8cf5c91 | 2011-11-14 14:51:27 -0800 | [diff] [blame] | 2319 | * @dev: DRM device |
| 2320 | * @data: ioctl data |
| 2321 | * @file_priv: DRM file info |
| 2322 | * |
Daniel Vetter | c8e32cc | 2014-03-10 21:33:02 +0100 | [diff] [blame] | 2323 | * Construct a list of plane ids to return to the user. |
| 2324 | * |
| 2325 | * Called by the user via ioctl. |
| 2326 | * |
| 2327 | * Returns: |
Daniel Vetter | 1a49863 | 2014-11-19 18:38:09 +0100 | [diff] [blame] | 2328 | * Zero on success, negative errno on failure. |
Jesse Barnes | 8cf5c91 | 2011-11-14 14:51:27 -0800 | [diff] [blame] | 2329 | */ |
| 2330 | int drm_mode_getplane_res(struct drm_device *dev, void *data, |
Daniel Vetter | c8e32cc | 2014-03-10 21:33:02 +0100 | [diff] [blame] | 2331 | struct drm_file *file_priv) |
Jesse Barnes | 8cf5c91 | 2011-11-14 14:51:27 -0800 | [diff] [blame] | 2332 | { |
| 2333 | struct drm_mode_get_plane_res *plane_resp = data; |
| 2334 | struct drm_mode_config *config; |
| 2335 | struct drm_plane *plane; |
| 2336 | uint32_t __user *plane_ptr; |
Daniel Vetter | fcf93f6 | 2014-11-12 08:45:01 +0100 | [diff] [blame] | 2337 | int copied = 0; |
Matt Roper | 681e7ec | 2014-04-01 15:22:42 -0700 | [diff] [blame] | 2338 | unsigned num_planes; |
Jesse Barnes | 8cf5c91 | 2011-11-14 14:51:27 -0800 | [diff] [blame] | 2339 | |
| 2340 | if (!drm_core_check_feature(dev, DRIVER_MODESET)) |
| 2341 | return -EINVAL; |
| 2342 | |
Jesse Barnes | 8cf5c91 | 2011-11-14 14:51:27 -0800 | [diff] [blame] | 2343 | config = &dev->mode_config; |
| 2344 | |
Matt Roper | 681e7ec | 2014-04-01 15:22:42 -0700 | [diff] [blame] | 2345 | if (file_priv->universal_planes) |
| 2346 | num_planes = config->num_total_plane; |
| 2347 | else |
| 2348 | num_planes = config->num_overlay_plane; |
| 2349 | |
Jesse Barnes | 8cf5c91 | 2011-11-14 14:51:27 -0800 | [diff] [blame] | 2350 | /* |
| 2351 | * This ioctl is called twice, once to determine how much space is |
| 2352 | * needed, and the 2nd time to fill it. |
| 2353 | */ |
Matt Roper | 681e7ec | 2014-04-01 15:22:42 -0700 | [diff] [blame] | 2354 | if (num_planes && |
| 2355 | (plane_resp->count_planes >= num_planes)) { |
Ville Syrjälä | 81f6c7f | 2011-12-20 00:06:42 +0200 | [diff] [blame] | 2356 | plane_ptr = (uint32_t __user *)(unsigned long)plane_resp->plane_id_ptr; |
Jesse Barnes | 8cf5c91 | 2011-11-14 14:51:27 -0800 | [diff] [blame] | 2357 | |
Daniel Vetter | fcf93f6 | 2014-11-12 08:45:01 +0100 | [diff] [blame] | 2358 | /* Plane lists are invariant, no locking needed. */ |
Daniel Vetter | e4f6254 | 2015-07-09 23:44:35 +0200 | [diff] [blame] | 2359 | drm_for_each_plane(plane, dev) { |
Matt Roper | 681e7ec | 2014-04-01 15:22:42 -0700 | [diff] [blame] | 2360 | /* |
| 2361 | * Unless userspace set the 'universal planes' |
| 2362 | * capability bit, only advertise overlays. |
| 2363 | */ |
| 2364 | if (plane->type != DRM_PLANE_TYPE_OVERLAY && |
| 2365 | !file_priv->universal_planes) |
Matt Roper | e27dde3 | 2014-04-01 15:22:30 -0700 | [diff] [blame] | 2366 | continue; |
| 2367 | |
Daniel Vetter | fcf93f6 | 2014-11-12 08:45:01 +0100 | [diff] [blame] | 2368 | if (put_user(plane->base.id, plane_ptr + copied)) |
| 2369 | return -EFAULT; |
Jesse Barnes | 8cf5c91 | 2011-11-14 14:51:27 -0800 | [diff] [blame] | 2370 | copied++; |
| 2371 | } |
| 2372 | } |
Matt Roper | 681e7ec | 2014-04-01 15:22:42 -0700 | [diff] [blame] | 2373 | plane_resp->count_planes = num_planes; |
Jesse Barnes | 8cf5c91 | 2011-11-14 14:51:27 -0800 | [diff] [blame] | 2374 | |
Daniel Vetter | fcf93f6 | 2014-11-12 08:45:01 +0100 | [diff] [blame] | 2375 | return 0; |
Jesse Barnes | 8cf5c91 | 2011-11-14 14:51:27 -0800 | [diff] [blame] | 2376 | } |
| 2377 | |
| 2378 | /** |
Daniel Vetter | c8e32cc | 2014-03-10 21:33:02 +0100 | [diff] [blame] | 2379 | * drm_mode_getplane - get plane configuration |
Jesse Barnes | 8cf5c91 | 2011-11-14 14:51:27 -0800 | [diff] [blame] | 2380 | * @dev: DRM device |
| 2381 | * @data: ioctl data |
| 2382 | * @file_priv: DRM file info |
| 2383 | * |
Daniel Vetter | c8e32cc | 2014-03-10 21:33:02 +0100 | [diff] [blame] | 2384 | * Construct a plane configuration structure to return to the user. |
| 2385 | * |
| 2386 | * Called by the user via ioctl. |
| 2387 | * |
| 2388 | * Returns: |
Daniel Vetter | 1a49863 | 2014-11-19 18:38:09 +0100 | [diff] [blame] | 2389 | * Zero on success, negative errno on failure. |
Jesse Barnes | 8cf5c91 | 2011-11-14 14:51:27 -0800 | [diff] [blame] | 2390 | */ |
| 2391 | int drm_mode_getplane(struct drm_device *dev, void *data, |
Daniel Vetter | c8e32cc | 2014-03-10 21:33:02 +0100 | [diff] [blame] | 2392 | struct drm_file *file_priv) |
Jesse Barnes | 8cf5c91 | 2011-11-14 14:51:27 -0800 | [diff] [blame] | 2393 | { |
| 2394 | struct drm_mode_get_plane *plane_resp = data; |
Jesse Barnes | 8cf5c91 | 2011-11-14 14:51:27 -0800 | [diff] [blame] | 2395 | struct drm_plane *plane; |
| 2396 | uint32_t __user *format_ptr; |
Jesse Barnes | 8cf5c91 | 2011-11-14 14:51:27 -0800 | [diff] [blame] | 2397 | |
| 2398 | if (!drm_core_check_feature(dev, DRIVER_MODESET)) |
| 2399 | return -EINVAL; |
| 2400 | |
Rob Clark | a2b34e2 | 2013-10-05 16:36:52 -0400 | [diff] [blame] | 2401 | plane = drm_plane_find(dev, plane_resp->plane_id); |
Daniel Vetter | fcf93f6 | 2014-11-12 08:45:01 +0100 | [diff] [blame] | 2402 | if (!plane) |
| 2403 | return -ENOENT; |
Jesse Barnes | 8cf5c91 | 2011-11-14 14:51:27 -0800 | [diff] [blame] | 2404 | |
Daniel Vetter | fcf93f6 | 2014-11-12 08:45:01 +0100 | [diff] [blame] | 2405 | drm_modeset_lock(&plane->mutex, NULL); |
Jesse Barnes | 8cf5c91 | 2011-11-14 14:51:27 -0800 | [diff] [blame] | 2406 | if (plane->crtc) |
| 2407 | plane_resp->crtc_id = plane->crtc->base.id; |
| 2408 | else |
| 2409 | plane_resp->crtc_id = 0; |
| 2410 | |
| 2411 | if (plane->fb) |
| 2412 | plane_resp->fb_id = plane->fb->base.id; |
| 2413 | else |
| 2414 | plane_resp->fb_id = 0; |
Daniel Vetter | fcf93f6 | 2014-11-12 08:45:01 +0100 | [diff] [blame] | 2415 | drm_modeset_unlock(&plane->mutex); |
Jesse Barnes | 8cf5c91 | 2011-11-14 14:51:27 -0800 | [diff] [blame] | 2416 | |
| 2417 | plane_resp->plane_id = plane->base.id; |
| 2418 | plane_resp->possible_crtcs = plane->possible_crtcs; |
Ville Syrjälä | 778ad90 | 2013-06-03 16:11:42 +0300 | [diff] [blame] | 2419 | plane_resp->gamma_size = 0; |
Jesse Barnes | 8cf5c91 | 2011-11-14 14:51:27 -0800 | [diff] [blame] | 2420 | |
| 2421 | /* |
| 2422 | * This ioctl is called twice, once to determine how much space is |
| 2423 | * needed, and the 2nd time to fill it. |
| 2424 | */ |
| 2425 | if (plane->format_count && |
| 2426 | (plane_resp->count_format_types >= plane->format_count)) { |
Ville Syrjälä | 81f6c7f | 2011-12-20 00:06:42 +0200 | [diff] [blame] | 2427 | format_ptr = (uint32_t __user *)(unsigned long)plane_resp->format_type_ptr; |
Jesse Barnes | 8cf5c91 | 2011-11-14 14:51:27 -0800 | [diff] [blame] | 2428 | if (copy_to_user(format_ptr, |
| 2429 | plane->format_types, |
| 2430 | sizeof(uint32_t) * plane->format_count)) { |
Daniel Vetter | fcf93f6 | 2014-11-12 08:45:01 +0100 | [diff] [blame] | 2431 | return -EFAULT; |
Jesse Barnes | 8cf5c91 | 2011-11-14 14:51:27 -0800 | [diff] [blame] | 2432 | } |
| 2433 | } |
| 2434 | plane_resp->count_format_types = plane->format_count; |
| 2435 | |
Daniel Vetter | baf698b | 2014-11-12 11:59:47 +0100 | [diff] [blame] | 2436 | return 0; |
Jesse Barnes | 8cf5c91 | 2011-11-14 14:51:27 -0800 | [diff] [blame] | 2437 | } |
| 2438 | |
Laurent Pinchart | ead8610 | 2015-03-05 02:25:43 +0200 | [diff] [blame] | 2439 | /** |
| 2440 | * drm_plane_check_pixel_format - Check if the plane supports the pixel format |
| 2441 | * @plane: plane to check for format support |
| 2442 | * @format: the pixel format |
| 2443 | * |
| 2444 | * Returns: |
| 2445 | * Zero of @plane has @format in its list of supported pixel formats, -EINVAL |
| 2446 | * otherwise. |
| 2447 | */ |
| 2448 | int drm_plane_check_pixel_format(const struct drm_plane *plane, u32 format) |
| 2449 | { |
| 2450 | unsigned int i; |
| 2451 | |
| 2452 | for (i = 0; i < plane->format_count; i++) { |
| 2453 | if (format == plane->format_types[i]) |
| 2454 | return 0; |
| 2455 | } |
| 2456 | |
| 2457 | return -EINVAL; |
| 2458 | } |
| 2459 | |
Ville Syrjälä | ce8d9ec | 2015-10-15 20:40:00 +0300 | [diff] [blame] | 2460 | static int check_src_coords(uint32_t src_x, uint32_t src_y, |
| 2461 | uint32_t src_w, uint32_t src_h, |
| 2462 | const struct drm_framebuffer *fb) |
| 2463 | { |
| 2464 | unsigned int fb_width, fb_height; |
| 2465 | |
| 2466 | fb_width = fb->width << 16; |
| 2467 | fb_height = fb->height << 16; |
| 2468 | |
| 2469 | /* Make sure source coordinates are inside the fb. */ |
| 2470 | if (src_w > fb_width || |
| 2471 | src_x > fb_width - src_w || |
| 2472 | src_h > fb_height || |
| 2473 | src_y > fb_height - src_h) { |
| 2474 | DRM_DEBUG_KMS("Invalid source coordinates " |
| 2475 | "%u.%06ux%u.%06u+%u.%06u+%u.%06u\n", |
| 2476 | src_w >> 16, ((src_w & 0xffff) * 15625) >> 10, |
| 2477 | src_h >> 16, ((src_h & 0xffff) * 15625) >> 10, |
| 2478 | src_x >> 16, ((src_x & 0xffff) * 15625) >> 10, |
| 2479 | src_y >> 16, ((src_y & 0xffff) * 15625) >> 10); |
| 2480 | return -ENOSPC; |
| 2481 | } |
| 2482 | |
| 2483 | return 0; |
| 2484 | } |
| 2485 | |
Matt Roper | b36552b | 2014-06-10 08:28:09 -0700 | [diff] [blame] | 2486 | /* |
| 2487 | * setplane_internal - setplane handler for internal callers |
Jesse Barnes | 8cf5c91 | 2011-11-14 14:51:27 -0800 | [diff] [blame] | 2488 | * |
Matt Roper | b36552b | 2014-06-10 08:28:09 -0700 | [diff] [blame] | 2489 | * Note that we assume an extra reference has already been taken on fb. If the |
| 2490 | * update fails, this reference will be dropped before return; if it succeeds, |
| 2491 | * the previous framebuffer (if any) will be unreferenced instead. |
Daniel Vetter | c8e32cc | 2014-03-10 21:33:02 +0100 | [diff] [blame] | 2492 | * |
Matt Roper | b36552b | 2014-06-10 08:28:09 -0700 | [diff] [blame] | 2493 | * 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] | 2494 | */ |
Daniel Vetter | f2b50c1 | 2014-09-12 17:07:32 +0200 | [diff] [blame] | 2495 | static int __setplane_internal(struct drm_plane *plane, |
| 2496 | struct drm_crtc *crtc, |
| 2497 | struct drm_framebuffer *fb, |
| 2498 | int32_t crtc_x, int32_t crtc_y, |
| 2499 | uint32_t crtc_w, uint32_t crtc_h, |
| 2500 | /* src_{x,y,w,h} values are 16.16 fixed point */ |
| 2501 | uint32_t src_x, uint32_t src_y, |
| 2502 | uint32_t src_w, uint32_t src_h) |
Jesse Barnes | 8cf5c91 | 2011-11-14 14:51:27 -0800 | [diff] [blame] | 2503 | { |
Jesse Barnes | 8cf5c91 | 2011-11-14 14:51:27 -0800 | [diff] [blame] | 2504 | int ret = 0; |
| 2505 | |
Jesse Barnes | 8cf5c91 | 2011-11-14 14:51:27 -0800 | [diff] [blame] | 2506 | /* No fb means shut it down */ |
Matt Roper | b36552b | 2014-06-10 08:28:09 -0700 | [diff] [blame] | 2507 | if (!fb) { |
Daniel Vetter | 3d30a59 | 2014-07-27 13:42:42 +0200 | [diff] [blame] | 2508 | plane->old_fb = plane->fb; |
Daniel Vetter | 731cce4 | 2014-04-23 10:24:11 +0200 | [diff] [blame] | 2509 | ret = plane->funcs->disable_plane(plane); |
| 2510 | if (!ret) { |
| 2511 | plane->crtc = NULL; |
| 2512 | plane->fb = NULL; |
| 2513 | } else { |
Daniel Vetter | 3d30a59 | 2014-07-27 13:42:42 +0200 | [diff] [blame] | 2514 | plane->old_fb = NULL; |
Daniel Vetter | 731cce4 | 2014-04-23 10:24:11 +0200 | [diff] [blame] | 2515 | } |
Jesse Barnes | 8cf5c91 | 2011-11-14 14:51:27 -0800 | [diff] [blame] | 2516 | goto out; |
| 2517 | } |
| 2518 | |
Matt Roper | 7f994f3 | 2014-05-29 08:06:51 -0700 | [diff] [blame] | 2519 | /* Check whether this plane is usable on this CRTC */ |
| 2520 | if (!(plane->possible_crtcs & drm_crtc_mask(crtc))) { |
| 2521 | DRM_DEBUG_KMS("Invalid crtc for plane\n"); |
| 2522 | ret = -EINVAL; |
| 2523 | goto out; |
| 2524 | } |
| 2525 | |
Ville Syrjälä | 62443be | 2011-12-20 00:06:47 +0200 | [diff] [blame] | 2526 | /* Check whether this plane supports the fb pixel format. */ |
Laurent Pinchart | ead8610 | 2015-03-05 02:25:43 +0200 | [diff] [blame] | 2527 | ret = drm_plane_check_pixel_format(plane, fb->pixel_format); |
| 2528 | if (ret) { |
Ville Syrjälä | 6ba6d03 | 2013-06-10 11:15:10 +0300 | [diff] [blame] | 2529 | DRM_DEBUG_KMS("Invalid pixel format %s\n", |
| 2530 | drm_get_format_name(fb->pixel_format)); |
Ville Syrjälä | 62443be | 2011-12-20 00:06:47 +0200 | [diff] [blame] | 2531 | goto out; |
| 2532 | } |
| 2533 | |
Matt Roper | 3968be9 | 2015-04-13 11:06:13 -0700 | [diff] [blame] | 2534 | /* Give drivers some help against integer overflows */ |
| 2535 | if (crtc_w > INT_MAX || |
| 2536 | crtc_x > INT_MAX - (int32_t) crtc_w || |
| 2537 | crtc_h > INT_MAX || |
| 2538 | crtc_y > INT_MAX - (int32_t) crtc_h) { |
| 2539 | DRM_DEBUG_KMS("Invalid CRTC coordinates %ux%u+%d+%d\n", |
| 2540 | crtc_w, crtc_h, crtc_x, crtc_y); |
Ville Syrjälä | c390eed | 2015-10-15 20:39:58 +0300 | [diff] [blame] | 2541 | ret = -ERANGE; |
Ville Syrjälä | 42ef878 | 2011-12-20 00:06:44 +0200 | [diff] [blame] | 2542 | goto out; |
| 2543 | } |
| 2544 | |
Ville Syrjälä | ce8d9ec | 2015-10-15 20:40:00 +0300 | [diff] [blame] | 2545 | ret = check_src_coords(src_x, src_y, src_w, src_h, fb); |
| 2546 | if (ret) |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 2547 | goto out; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 2548 | |
Daniel Vetter | 3d30a59 | 2014-07-27 13:42:42 +0200 | [diff] [blame] | 2549 | plane->old_fb = plane->fb; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 2550 | ret = plane->funcs->update_plane(plane, crtc, fb, |
Matt Roper | b36552b | 2014-06-10 08:28:09 -0700 | [diff] [blame] | 2551 | crtc_x, crtc_y, crtc_w, crtc_h, |
| 2552 | src_x, src_y, src_w, src_h); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 2553 | if (!ret) { |
| 2554 | plane->crtc = crtc; |
| 2555 | plane->fb = fb; |
Daniel Vetter | 35f8bad | 2013-02-15 21:21:37 +0100 | [diff] [blame] | 2556 | fb = NULL; |
Daniel Vetter | 0fe27f0 | 2014-04-23 17:34:06 +0200 | [diff] [blame] | 2557 | } else { |
Daniel Vetter | 3d30a59 | 2014-07-27 13:42:42 +0200 | [diff] [blame] | 2558 | plane->old_fb = NULL; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 2559 | } |
| 2560 | |
| 2561 | out: |
Daniel Vetter | 6c2a753 | 2012-12-11 00:59:24 +0100 | [diff] [blame] | 2562 | if (fb) |
| 2563 | drm_framebuffer_unreference(fb); |
Daniel Vetter | 3d30a59 | 2014-07-27 13:42:42 +0200 | [diff] [blame] | 2564 | if (plane->old_fb) |
| 2565 | drm_framebuffer_unreference(plane->old_fb); |
| 2566 | plane->old_fb = NULL; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 2567 | |
| 2568 | return ret; |
Daniel Vetter | f2b50c1 | 2014-09-12 17:07:32 +0200 | [diff] [blame] | 2569 | } |
Matt Roper | b36552b | 2014-06-10 08:28:09 -0700 | [diff] [blame] | 2570 | |
Daniel Vetter | f2b50c1 | 2014-09-12 17:07:32 +0200 | [diff] [blame] | 2571 | static int setplane_internal(struct drm_plane *plane, |
| 2572 | struct drm_crtc *crtc, |
| 2573 | struct drm_framebuffer *fb, |
| 2574 | int32_t crtc_x, int32_t crtc_y, |
| 2575 | uint32_t crtc_w, uint32_t crtc_h, |
| 2576 | /* src_{x,y,w,h} values are 16.16 fixed point */ |
| 2577 | uint32_t src_x, uint32_t src_y, |
| 2578 | uint32_t src_w, uint32_t src_h) |
| 2579 | { |
| 2580 | int ret; |
| 2581 | |
| 2582 | drm_modeset_lock_all(plane->dev); |
| 2583 | ret = __setplane_internal(plane, crtc, fb, |
| 2584 | crtc_x, crtc_y, crtc_w, crtc_h, |
| 2585 | src_x, src_y, src_w, src_h); |
| 2586 | drm_modeset_unlock_all(plane->dev); |
| 2587 | |
| 2588 | return ret; |
Matt Roper | b36552b | 2014-06-10 08:28:09 -0700 | [diff] [blame] | 2589 | } |
| 2590 | |
| 2591 | /** |
| 2592 | * drm_mode_setplane - configure a plane's configuration |
| 2593 | * @dev: DRM device |
| 2594 | * @data: ioctl data* |
| 2595 | * @file_priv: DRM file info |
| 2596 | * |
| 2597 | * Set plane configuration, including placement, fb, scaling, and other factors. |
| 2598 | * Or pass a NULL fb to disable (planes may be disabled without providing a |
| 2599 | * valid crtc). |
| 2600 | * |
| 2601 | * Returns: |
Daniel Vetter | 1a49863 | 2014-11-19 18:38:09 +0100 | [diff] [blame] | 2602 | * Zero on success, negative errno on failure. |
Matt Roper | b36552b | 2014-06-10 08:28:09 -0700 | [diff] [blame] | 2603 | */ |
| 2604 | int drm_mode_setplane(struct drm_device *dev, void *data, |
| 2605 | struct drm_file *file_priv) |
| 2606 | { |
| 2607 | struct drm_mode_set_plane *plane_req = data; |
Matt Roper | b36552b | 2014-06-10 08:28:09 -0700 | [diff] [blame] | 2608 | struct drm_plane *plane; |
| 2609 | struct drm_crtc *crtc = NULL; |
| 2610 | struct drm_framebuffer *fb = NULL; |
| 2611 | |
| 2612 | if (!drm_core_check_feature(dev, DRIVER_MODESET)) |
| 2613 | return -EINVAL; |
| 2614 | |
Matt Roper | b36552b | 2014-06-10 08:28:09 -0700 | [diff] [blame] | 2615 | /* |
| 2616 | * First, find the plane, crtc, and fb objects. If not available, |
| 2617 | * we don't bother to call the driver. |
| 2618 | */ |
Rob Clark | 933f622 | 2014-11-25 20:33:11 -0500 | [diff] [blame] | 2619 | plane = drm_plane_find(dev, plane_req->plane_id); |
| 2620 | if (!plane) { |
Matt Roper | b36552b | 2014-06-10 08:28:09 -0700 | [diff] [blame] | 2621 | DRM_DEBUG_KMS("Unknown plane ID %d\n", |
| 2622 | plane_req->plane_id); |
| 2623 | return -ENOENT; |
| 2624 | } |
Matt Roper | b36552b | 2014-06-10 08:28:09 -0700 | [diff] [blame] | 2625 | |
| 2626 | if (plane_req->fb_id) { |
| 2627 | fb = drm_framebuffer_lookup(dev, plane_req->fb_id); |
| 2628 | if (!fb) { |
| 2629 | DRM_DEBUG_KMS("Unknown framebuffer ID %d\n", |
| 2630 | plane_req->fb_id); |
| 2631 | return -ENOENT; |
| 2632 | } |
| 2633 | |
Rob Clark | 933f622 | 2014-11-25 20:33:11 -0500 | [diff] [blame] | 2634 | crtc = drm_crtc_find(dev, plane_req->crtc_id); |
| 2635 | if (!crtc) { |
Matt Roper | b36552b | 2014-06-10 08:28:09 -0700 | [diff] [blame] | 2636 | DRM_DEBUG_KMS("Unknown crtc ID %d\n", |
| 2637 | plane_req->crtc_id); |
| 2638 | return -ENOENT; |
| 2639 | } |
Matt Roper | b36552b | 2014-06-10 08:28:09 -0700 | [diff] [blame] | 2640 | } |
| 2641 | |
Matt Roper | 161d0dc | 2014-06-10 08:28:10 -0700 | [diff] [blame] | 2642 | /* |
| 2643 | * setplane_internal will take care of deref'ing either the old or new |
| 2644 | * framebuffer depending on success. |
| 2645 | */ |
Chris Wilson | 17cfd91 | 2014-06-13 15:22:28 +0100 | [diff] [blame] | 2646 | return setplane_internal(plane, crtc, fb, |
Matt Roper | b36552b | 2014-06-10 08:28:09 -0700 | [diff] [blame] | 2647 | plane_req->crtc_x, plane_req->crtc_y, |
| 2648 | plane_req->crtc_w, plane_req->crtc_h, |
| 2649 | plane_req->src_x, plane_req->src_y, |
| 2650 | plane_req->src_w, plane_req->src_h); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 2651 | } |
| 2652 | |
| 2653 | /** |
Daniel Vetter | 2d13b67 | 2012-12-11 13:47:23 +0100 | [diff] [blame] | 2654 | * drm_mode_set_config_internal - helper to call ->set_config |
| 2655 | * @set: modeset config to set |
| 2656 | * |
| 2657 | * This is a little helper to wrap internal calls to the ->set_config driver |
| 2658 | * interface. The only thing it adds is correct refcounting dance. |
Thierry Reding | 4dfd909 | 2014-12-10 13:03:34 +0100 | [diff] [blame] | 2659 | * |
Daniel Vetter | c8e32cc | 2014-03-10 21:33:02 +0100 | [diff] [blame] | 2660 | * Returns: |
Daniel Vetter | 1a49863 | 2014-11-19 18:38:09 +0100 | [diff] [blame] | 2661 | * Zero on success, negative errno on failure. |
Daniel Vetter | 2d13b67 | 2012-12-11 13:47:23 +0100 | [diff] [blame] | 2662 | */ |
| 2663 | int drm_mode_set_config_internal(struct drm_mode_set *set) |
| 2664 | { |
| 2665 | struct drm_crtc *crtc = set->crtc; |
Daniel Vetter | 5cef29a | 2013-06-15 00:13:16 +0200 | [diff] [blame] | 2666 | struct drm_framebuffer *fb; |
| 2667 | struct drm_crtc *tmp; |
Daniel Vetter | b0d1232 | 2012-12-11 01:07:12 +0100 | [diff] [blame] | 2668 | int ret; |
Daniel Vetter | 2d13b67 | 2012-12-11 13:47:23 +0100 | [diff] [blame] | 2669 | |
Daniel Vetter | 5cef29a | 2013-06-15 00:13:16 +0200 | [diff] [blame] | 2670 | /* |
| 2671 | * NOTE: ->set_config can also disable other crtcs (if we steal all |
| 2672 | * connectors from it), hence we need to refcount the fbs across all |
| 2673 | * crtcs. Atomic modeset will have saner semantics ... |
| 2674 | */ |
Daniel Vetter | e4f6254 | 2015-07-09 23:44:35 +0200 | [diff] [blame] | 2675 | drm_for_each_crtc(tmp, crtc->dev) |
Daniel Vetter | 3d30a59 | 2014-07-27 13:42:42 +0200 | [diff] [blame] | 2676 | tmp->primary->old_fb = tmp->primary->fb; |
Daniel Vetter | 5cef29a | 2013-06-15 00:13:16 +0200 | [diff] [blame] | 2677 | |
Daniel Vetter | b0d1232 | 2012-12-11 01:07:12 +0100 | [diff] [blame] | 2678 | fb = set->fb; |
| 2679 | |
| 2680 | ret = crtc->funcs->set_config(set); |
| 2681 | if (ret == 0) { |
Matt Roper | e13161a | 2014-04-01 15:22:38 -0700 | [diff] [blame] | 2682 | crtc->primary->crtc = crtc; |
Daniel Vetter | 0fe27f0 | 2014-04-23 17:34:06 +0200 | [diff] [blame] | 2683 | crtc->primary->fb = fb; |
Daniel Vetter | 5cef29a | 2013-06-15 00:13:16 +0200 | [diff] [blame] | 2684 | } |
Daniel Vetter | cc85e12 | 2013-06-15 00:13:15 +0200 | [diff] [blame] | 2685 | |
Daniel Vetter | e4f6254 | 2015-07-09 23:44:35 +0200 | [diff] [blame] | 2686 | drm_for_each_crtc(tmp, crtc->dev) { |
Matt Roper | f4510a2 | 2014-04-01 15:22:40 -0700 | [diff] [blame] | 2687 | if (tmp->primary->fb) |
| 2688 | drm_framebuffer_reference(tmp->primary->fb); |
Daniel Vetter | 3d30a59 | 2014-07-27 13:42:42 +0200 | [diff] [blame] | 2689 | if (tmp->primary->old_fb) |
| 2690 | drm_framebuffer_unreference(tmp->primary->old_fb); |
| 2691 | tmp->primary->old_fb = NULL; |
Daniel Vetter | b0d1232 | 2012-12-11 01:07:12 +0100 | [diff] [blame] | 2692 | } |
| 2693 | |
| 2694 | return ret; |
Daniel Vetter | 2d13b67 | 2012-12-11 13:47:23 +0100 | [diff] [blame] | 2695 | } |
| 2696 | EXPORT_SYMBOL(drm_mode_set_config_internal); |
| 2697 | |
Matt Roper | af93629 | 2014-04-01 15:22:34 -0700 | [diff] [blame] | 2698 | /** |
Gustavo Padovan | ecb7e16 | 2014-12-01 15:40:09 -0800 | [diff] [blame] | 2699 | * drm_crtc_get_hv_timing - Fetches hdisplay/vdisplay for given mode |
| 2700 | * @mode: mode to query |
| 2701 | * @hdisplay: hdisplay value to fill in |
| 2702 | * @vdisplay: vdisplay value to fill in |
| 2703 | * |
| 2704 | * The vdisplay value will be doubled if the specified mode is a stereo mode of |
| 2705 | * the appropriate layout. |
| 2706 | */ |
| 2707 | void drm_crtc_get_hv_timing(const struct drm_display_mode *mode, |
| 2708 | int *hdisplay, int *vdisplay) |
| 2709 | { |
| 2710 | struct drm_display_mode adjusted; |
| 2711 | |
| 2712 | drm_mode_copy(&adjusted, mode); |
| 2713 | drm_mode_set_crtcinfo(&adjusted, CRTC_STEREO_DOUBLE_ONLY); |
| 2714 | *hdisplay = adjusted.crtc_hdisplay; |
| 2715 | *vdisplay = adjusted.crtc_vdisplay; |
| 2716 | } |
| 2717 | EXPORT_SYMBOL(drm_crtc_get_hv_timing); |
| 2718 | |
| 2719 | /** |
Matt Roper | af93629 | 2014-04-01 15:22:34 -0700 | [diff] [blame] | 2720 | * drm_crtc_check_viewport - Checks that a framebuffer is big enough for the |
| 2721 | * CRTC viewport |
| 2722 | * @crtc: CRTC that framebuffer will be displayed on |
| 2723 | * @x: x panning |
| 2724 | * @y: y panning |
| 2725 | * @mode: mode that framebuffer will be displayed under |
| 2726 | * @fb: framebuffer to check size of |
Damien Lespiau | c11e928 | 2013-09-25 16:45:30 +0100 | [diff] [blame] | 2727 | */ |
Matt Roper | af93629 | 2014-04-01 15:22:34 -0700 | [diff] [blame] | 2728 | int drm_crtc_check_viewport(const struct drm_crtc *crtc, |
| 2729 | int x, int y, |
| 2730 | const struct drm_display_mode *mode, |
| 2731 | const struct drm_framebuffer *fb) |
Damien Lespiau | c11e928 | 2013-09-25 16:45:30 +0100 | [diff] [blame] | 2732 | |
| 2733 | { |
| 2734 | int hdisplay, vdisplay; |
| 2735 | |
Gustavo Padovan | ecb7e16 | 2014-12-01 15:40:09 -0800 | [diff] [blame] | 2736 | drm_crtc_get_hv_timing(mode, &hdisplay, &vdisplay); |
Damien Lespiau | a0c1bbb | 2013-09-25 16:45:31 +0100 | [diff] [blame] | 2737 | |
Ville Syrjälä | 33e0be6 | 2015-10-16 18:38:39 +0300 | [diff] [blame] | 2738 | if (crtc->state && |
| 2739 | crtc->primary->state->rotation & (BIT(DRM_ROTATE_90) | |
| 2740 | BIT(DRM_ROTATE_270))) |
Damien Lespiau | c11e928 | 2013-09-25 16:45:30 +0100 | [diff] [blame] | 2741 | swap(hdisplay, vdisplay); |
| 2742 | |
Ville Syrjälä | ce8d9ec | 2015-10-15 20:40:00 +0300 | [diff] [blame] | 2743 | return check_src_coords(x << 16, y << 16, |
| 2744 | hdisplay << 16, vdisplay << 16, fb); |
Damien Lespiau | c11e928 | 2013-09-25 16:45:30 +0100 | [diff] [blame] | 2745 | } |
Matt Roper | af93629 | 2014-04-01 15:22:34 -0700 | [diff] [blame] | 2746 | EXPORT_SYMBOL(drm_crtc_check_viewport); |
Damien Lespiau | c11e928 | 2013-09-25 16:45:30 +0100 | [diff] [blame] | 2747 | |
Daniel Vetter | 2d13b67 | 2012-12-11 13:47:23 +0100 | [diff] [blame] | 2748 | /** |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 2749 | * drm_mode_setcrtc - set CRTC configuration |
Daniel Vetter | 065a50ed | 2012-12-02 00:09:18 +0100 | [diff] [blame] | 2750 | * @dev: drm device for the ioctl |
| 2751 | * @data: data pointer for the ioctl |
| 2752 | * @file_priv: drm file for the ioctl call |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 2753 | * |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 2754 | * Build a new CRTC configuration based on user request. |
| 2755 | * |
| 2756 | * Called by the user via ioctl. |
| 2757 | * |
Daniel Vetter | c8e32cc | 2014-03-10 21:33:02 +0100 | [diff] [blame] | 2758 | * Returns: |
Daniel Vetter | 1a49863 | 2014-11-19 18:38:09 +0100 | [diff] [blame] | 2759 | * Zero on success, negative errno on failure. |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 2760 | */ |
| 2761 | int drm_mode_setcrtc(struct drm_device *dev, void *data, |
| 2762 | struct drm_file *file_priv) |
| 2763 | { |
| 2764 | struct drm_mode_config *config = &dev->mode_config; |
| 2765 | struct drm_mode_crtc *crtc_req = data; |
Ville Syrjälä | 6653cc8 | 2012-03-13 12:35:38 +0200 | [diff] [blame] | 2766 | struct drm_crtc *crtc; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 2767 | struct drm_connector **connector_set = NULL, *connector; |
| 2768 | struct drm_framebuffer *fb = NULL; |
| 2769 | struct drm_display_mode *mode = NULL; |
| 2770 | struct drm_mode_set set; |
| 2771 | uint32_t __user *set_connectors_ptr; |
Laurent Pinchart | 4a1b071 | 2012-05-17 13:27:21 +0200 | [diff] [blame] | 2772 | int ret; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 2773 | int i; |
| 2774 | |
Dave Airlie | fb3b06c | 2011-02-08 13:55:21 +1000 | [diff] [blame] | 2775 | if (!drm_core_check_feature(dev, DRIVER_MODESET)) |
| 2776 | return -EINVAL; |
| 2777 | |
Zhao Junwang | 01447e9 | 2015-07-07 17:08:35 +0800 | [diff] [blame] | 2778 | /* |
| 2779 | * Universal plane src offsets are only 16.16, prevent havoc for |
| 2780 | * drivers using universal plane code internally. |
| 2781 | */ |
| 2782 | if (crtc_req->x & 0xffff0000 || crtc_req->y & 0xffff0000) |
Ville Syrjälä | 1d97e91 | 2012-03-13 12:35:41 +0200 | [diff] [blame] | 2783 | return -ERANGE; |
| 2784 | |
Daniel Vetter | 8484990 | 2012-12-02 00:28:11 +0100 | [diff] [blame] | 2785 | drm_modeset_lock_all(dev); |
Rob Clark | a2b34e2 | 2013-10-05 16:36:52 -0400 | [diff] [blame] | 2786 | crtc = drm_crtc_find(dev, crtc_req->crtc_id); |
| 2787 | if (!crtc) { |
Zhao Yakui | 58367ed | 2009-07-20 13:48:07 +0800 | [diff] [blame] | 2788 | 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] | 2789 | ret = -ENOENT; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 2790 | goto out; |
| 2791 | } |
Ville Syrjälä | fa3ab4c | 2015-12-08 18:41:53 +0200 | [diff] [blame] | 2792 | DRM_DEBUG_KMS("[CRTC:%d:%s]\n", crtc->base.id, crtc->name); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 2793 | |
| 2794 | if (crtc_req->mode_valid) { |
| 2795 | /* If we have a mode we need a framebuffer. */ |
| 2796 | /* If we pass -1, set the mode with the currently bound fb */ |
| 2797 | if (crtc_req->fb_id == -1) { |
Matt Roper | f4510a2 | 2014-04-01 15:22:40 -0700 | [diff] [blame] | 2798 | if (!crtc->primary->fb) { |
Ville Syrjälä | 6653cc8 | 2012-03-13 12:35:38 +0200 | [diff] [blame] | 2799 | DRM_DEBUG_KMS("CRTC doesn't have current FB\n"); |
| 2800 | ret = -EINVAL; |
| 2801 | goto out; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 2802 | } |
Matt Roper | f4510a2 | 2014-04-01 15:22:40 -0700 | [diff] [blame] | 2803 | fb = crtc->primary->fb; |
Daniel Vetter | b0d1232 | 2012-12-11 01:07:12 +0100 | [diff] [blame] | 2804 | /* Make refcounting symmetric with the lookup path. */ |
| 2805 | drm_framebuffer_reference(fb); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 2806 | } else { |
Daniel Vetter | 786b99e | 2012-12-02 21:53:40 +0100 | [diff] [blame] | 2807 | fb = drm_framebuffer_lookup(dev, crtc_req->fb_id); |
| 2808 | if (!fb) { |
Zhao Yakui | 58367ed | 2009-07-20 13:48:07 +0800 | [diff] [blame] | 2809 | DRM_DEBUG_KMS("Unknown FB ID%d\n", |
| 2810 | crtc_req->fb_id); |
Ville Syrjälä | 37c4e70 | 2013-10-17 13:35:01 +0300 | [diff] [blame] | 2811 | ret = -ENOENT; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 2812 | goto out; |
| 2813 | } |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 2814 | } |
| 2815 | |
| 2816 | mode = drm_mode_create(dev); |
Ville Syrjälä | ee34ab5 | 2012-03-13 12:35:43 +0200 | [diff] [blame] | 2817 | if (!mode) { |
| 2818 | ret = -ENOMEM; |
| 2819 | goto out; |
| 2820 | } |
| 2821 | |
Daniel Stone | 934a8a8 | 2015-05-22 13:34:48 +0100 | [diff] [blame] | 2822 | ret = drm_mode_convert_umode(mode, &crtc_req->mode); |
Ville Syrjälä | 90367bf | 2012-03-13 12:35:44 +0200 | [diff] [blame] | 2823 | if (ret) { |
| 2824 | DRM_DEBUG_KMS("Invalid mode\n"); |
| 2825 | goto out; |
| 2826 | } |
| 2827 | |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 2828 | drm_mode_set_crtcinfo(mode, CRTC_INTERLACE_HALVE_V); |
Ville Syrjälä | 5f61bb4 | 2012-03-13 12:35:45 +0200 | [diff] [blame] | 2829 | |
Laurent Pinchart | 7eb5f30 | 2015-03-09 10:41:07 +0200 | [diff] [blame] | 2830 | /* |
| 2831 | * Check whether the primary plane supports the fb pixel format. |
| 2832 | * Drivers not implementing the universal planes API use a |
| 2833 | * default formats list provided by the DRM core which doesn't |
| 2834 | * match real hardware capabilities. Skip the check in that |
| 2835 | * case. |
| 2836 | */ |
| 2837 | if (!crtc->primary->format_default) { |
| 2838 | ret = drm_plane_check_pixel_format(crtc->primary, |
| 2839 | fb->pixel_format); |
| 2840 | if (ret) { |
| 2841 | DRM_DEBUG_KMS("Invalid pixel format %s\n", |
| 2842 | drm_get_format_name(fb->pixel_format)); |
| 2843 | goto out; |
| 2844 | } |
| 2845 | } |
| 2846 | |
Damien Lespiau | c11e928 | 2013-09-25 16:45:30 +0100 | [diff] [blame] | 2847 | ret = drm_crtc_check_viewport(crtc, crtc_req->x, crtc_req->y, |
| 2848 | mode, fb); |
| 2849 | if (ret) |
Ville Syrjälä | 5f61bb4 | 2012-03-13 12:35:45 +0200 | [diff] [blame] | 2850 | goto out; |
Damien Lespiau | c11e928 | 2013-09-25 16:45:30 +0100 | [diff] [blame] | 2851 | |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 2852 | } |
| 2853 | |
| 2854 | if (crtc_req->count_connectors == 0 && mode) { |
Zhao Yakui | 58367ed | 2009-07-20 13:48:07 +0800 | [diff] [blame] | 2855 | DRM_DEBUG_KMS("Count connectors is 0 but mode set\n"); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 2856 | ret = -EINVAL; |
| 2857 | goto out; |
| 2858 | } |
| 2859 | |
Jakob Bornecrantz | 7781de7 | 2009-08-03 13:43:58 +0100 | [diff] [blame] | 2860 | if (crtc_req->count_connectors > 0 && (!mode || !fb)) { |
Zhao Yakui | 58367ed | 2009-07-20 13:48:07 +0800 | [diff] [blame] | 2861 | 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] | 2862 | crtc_req->count_connectors); |
| 2863 | ret = -EINVAL; |
| 2864 | goto out; |
| 2865 | } |
| 2866 | |
| 2867 | if (crtc_req->count_connectors > 0) { |
| 2868 | u32 out_id; |
| 2869 | |
| 2870 | /* Avoid unbounded kernel memory allocation */ |
| 2871 | if (crtc_req->count_connectors > config->num_connector) { |
| 2872 | ret = -EINVAL; |
| 2873 | goto out; |
| 2874 | } |
| 2875 | |
Thierry Reding | 2f6c538 | 2014-12-10 13:03:36 +0100 | [diff] [blame] | 2876 | connector_set = kmalloc_array(crtc_req->count_connectors, |
| 2877 | sizeof(struct drm_connector *), |
| 2878 | GFP_KERNEL); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 2879 | if (!connector_set) { |
| 2880 | ret = -ENOMEM; |
| 2881 | goto out; |
| 2882 | } |
| 2883 | |
| 2884 | for (i = 0; i < crtc_req->count_connectors; i++) { |
Ville Syrjälä | 81f6c7f | 2011-12-20 00:06:42 +0200 | [diff] [blame] | 2885 | 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] | 2886 | if (get_user(out_id, &set_connectors_ptr[i])) { |
| 2887 | ret = -EFAULT; |
| 2888 | goto out; |
| 2889 | } |
| 2890 | |
Rob Clark | a2b34e2 | 2013-10-05 16:36:52 -0400 | [diff] [blame] | 2891 | connector = drm_connector_find(dev, out_id); |
| 2892 | if (!connector) { |
Zhao Yakui | 58367ed | 2009-07-20 13:48:07 +0800 | [diff] [blame] | 2893 | DRM_DEBUG_KMS("Connector id %d unknown\n", |
| 2894 | out_id); |
Ville Syrjälä | f27657f | 2013-10-17 13:35:00 +0300 | [diff] [blame] | 2895 | ret = -ENOENT; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 2896 | goto out; |
| 2897 | } |
Jerome Glisse | 9440106 | 2010-07-15 15:43:25 -0400 | [diff] [blame] | 2898 | DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n", |
| 2899 | connector->base.id, |
Jani Nikula | 2593382 | 2014-06-03 14:56:20 +0300 | [diff] [blame] | 2900 | connector->name); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 2901 | |
| 2902 | connector_set[i] = connector; |
| 2903 | } |
| 2904 | } |
| 2905 | |
| 2906 | set.crtc = crtc; |
| 2907 | set.x = crtc_req->x; |
| 2908 | set.y = crtc_req->y; |
| 2909 | set.mode = mode; |
| 2910 | set.connectors = connector_set; |
| 2911 | set.num_connectors = crtc_req->count_connectors; |
Dave Airlie | 5ef5f72 | 2009-08-17 13:11:23 +1000 | [diff] [blame] | 2912 | set.fb = fb; |
Daniel Vetter | 2d13b67 | 2012-12-11 13:47:23 +0100 | [diff] [blame] | 2913 | ret = drm_mode_set_config_internal(&set); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 2914 | |
| 2915 | out: |
Daniel Vetter | b0d1232 | 2012-12-11 01:07:12 +0100 | [diff] [blame] | 2916 | if (fb) |
| 2917 | drm_framebuffer_unreference(fb); |
| 2918 | |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 2919 | kfree(connector_set); |
Ville Syrjälä | ee34ab5 | 2012-03-13 12:35:43 +0200 | [diff] [blame] | 2920 | drm_mode_destroy(dev, mode); |
Daniel Vetter | 8484990 | 2012-12-02 00:28:11 +0100 | [diff] [blame] | 2921 | drm_modeset_unlock_all(dev); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 2922 | return ret; |
| 2923 | } |
| 2924 | |
Matt Roper | 161d0dc | 2014-06-10 08:28:10 -0700 | [diff] [blame] | 2925 | /** |
| 2926 | * drm_mode_cursor_universal - translate legacy cursor ioctl call into a |
| 2927 | * universal plane handler call |
| 2928 | * @crtc: crtc to update cursor for |
| 2929 | * @req: data pointer for the ioctl |
| 2930 | * @file_priv: drm file for the ioctl call |
| 2931 | * |
| 2932 | * Legacy cursor ioctl's work directly with driver buffer handles. To |
| 2933 | * translate legacy ioctl calls into universal plane handler calls, we need to |
| 2934 | * wrap the native buffer handle in a drm_framebuffer. |
| 2935 | * |
| 2936 | * Note that we assume any handle passed to the legacy ioctls was a 32-bit ARGB |
| 2937 | * buffer with a pitch of 4*width; the universal plane interface should be used |
| 2938 | * directly in cases where the hardware can support other buffer settings and |
| 2939 | * userspace wants to make use of these capabilities. |
| 2940 | * |
| 2941 | * Returns: |
Daniel Vetter | 1a49863 | 2014-11-19 18:38:09 +0100 | [diff] [blame] | 2942 | * Zero on success, negative errno on failure. |
Matt Roper | 161d0dc | 2014-06-10 08:28:10 -0700 | [diff] [blame] | 2943 | */ |
| 2944 | static int drm_mode_cursor_universal(struct drm_crtc *crtc, |
| 2945 | struct drm_mode_cursor2 *req, |
| 2946 | struct drm_file *file_priv) |
| 2947 | { |
| 2948 | struct drm_device *dev = crtc->dev; |
| 2949 | struct drm_framebuffer *fb = NULL; |
| 2950 | struct drm_mode_fb_cmd2 fbreq = { |
| 2951 | .width = req->width, |
| 2952 | .height = req->height, |
| 2953 | .pixel_format = DRM_FORMAT_ARGB8888, |
| 2954 | .pitches = { req->width * 4 }, |
| 2955 | .handles = { req->handle }, |
| 2956 | }; |
| 2957 | int32_t crtc_x, crtc_y; |
| 2958 | uint32_t crtc_w = 0, crtc_h = 0; |
| 2959 | uint32_t src_w = 0, src_h = 0; |
| 2960 | int ret = 0; |
| 2961 | |
| 2962 | BUG_ON(!crtc->cursor); |
Daniel Vetter | f2b50c1 | 2014-09-12 17:07:32 +0200 | [diff] [blame] | 2963 | WARN_ON(crtc->cursor->crtc != crtc && crtc->cursor->crtc != NULL); |
Matt Roper | 161d0dc | 2014-06-10 08:28:10 -0700 | [diff] [blame] | 2964 | |
| 2965 | /* |
| 2966 | * Obtain fb we'll be using (either new or existing) and take an extra |
| 2967 | * reference to it if fb != null. setplane will take care of dropping |
| 2968 | * the reference if the plane update fails. |
| 2969 | */ |
| 2970 | if (req->flags & DRM_MODE_CURSOR_BO) { |
| 2971 | if (req->handle) { |
Chris Wilson | 9a6f513 | 2015-02-25 13:45:26 +0000 | [diff] [blame] | 2972 | fb = internal_framebuffer_create(dev, &fbreq, file_priv); |
Matt Roper | 161d0dc | 2014-06-10 08:28:10 -0700 | [diff] [blame] | 2973 | if (IS_ERR(fb)) { |
| 2974 | DRM_DEBUG_KMS("failed to wrap cursor buffer in drm framebuffer\n"); |
| 2975 | return PTR_ERR(fb); |
| 2976 | } |
Matt Roper | 161d0dc | 2014-06-10 08:28:10 -0700 | [diff] [blame] | 2977 | } else { |
| 2978 | fb = NULL; |
| 2979 | } |
| 2980 | } else { |
Matt Roper | 161d0dc | 2014-06-10 08:28:10 -0700 | [diff] [blame] | 2981 | fb = crtc->cursor->fb; |
| 2982 | if (fb) |
| 2983 | drm_framebuffer_reference(fb); |
Matt Roper | 161d0dc | 2014-06-10 08:28:10 -0700 | [diff] [blame] | 2984 | } |
| 2985 | |
| 2986 | if (req->flags & DRM_MODE_CURSOR_MOVE) { |
| 2987 | crtc_x = req->x; |
| 2988 | crtc_y = req->y; |
| 2989 | } else { |
| 2990 | crtc_x = crtc->cursor_x; |
| 2991 | crtc_y = crtc->cursor_y; |
| 2992 | } |
| 2993 | |
| 2994 | if (fb) { |
| 2995 | crtc_w = fb->width; |
| 2996 | crtc_h = fb->height; |
| 2997 | src_w = fb->width << 16; |
| 2998 | src_h = fb->height << 16; |
| 2999 | } |
| 3000 | |
| 3001 | /* |
| 3002 | * setplane_internal will take care of deref'ing either the old or new |
| 3003 | * framebuffer depending on success. |
| 3004 | */ |
Daniel Vetter | f2b50c1 | 2014-09-12 17:07:32 +0200 | [diff] [blame] | 3005 | ret = __setplane_internal(crtc->cursor, crtc, fb, |
Matt Roper | 161d0dc | 2014-06-10 08:28:10 -0700 | [diff] [blame] | 3006 | crtc_x, crtc_y, crtc_w, crtc_h, |
| 3007 | 0, 0, src_w, src_h); |
| 3008 | |
| 3009 | /* Update successful; save new cursor position, if necessary */ |
| 3010 | if (ret == 0 && req->flags & DRM_MODE_CURSOR_MOVE) { |
| 3011 | crtc->cursor_x = req->x; |
| 3012 | crtc->cursor_y = req->y; |
| 3013 | } |
| 3014 | |
| 3015 | return ret; |
| 3016 | } |
| 3017 | |
Dave Airlie | 4c813d4 | 2013-06-20 11:48:52 +1000 | [diff] [blame] | 3018 | static int drm_mode_cursor_common(struct drm_device *dev, |
| 3019 | struct drm_mode_cursor2 *req, |
| 3020 | struct drm_file *file_priv) |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 3021 | { |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 3022 | struct drm_crtc *crtc; |
| 3023 | int ret = 0; |
| 3024 | |
Dave Airlie | fb3b06c | 2011-02-08 13:55:21 +1000 | [diff] [blame] | 3025 | if (!drm_core_check_feature(dev, DRIVER_MODESET)) |
| 3026 | return -EINVAL; |
| 3027 | |
Jakob Bornecrantz | 7c4eaca | 2012-08-16 08:29:03 +0000 | [diff] [blame] | 3028 | if (!req->flags || (~DRM_MODE_CURSOR_FLAGS & req->flags)) |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 3029 | return -EINVAL; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 3030 | |
Rob Clark | a2b34e2 | 2013-10-05 16:36:52 -0400 | [diff] [blame] | 3031 | crtc = drm_crtc_find(dev, req->crtc_id); |
| 3032 | if (!crtc) { |
Zhao Yakui | 58367ed | 2009-07-20 13:48:07 +0800 | [diff] [blame] | 3033 | DRM_DEBUG_KMS("Unknown CRTC ID %d\n", req->crtc_id); |
Ville Syrjälä | f27657f | 2013-10-17 13:35:00 +0300 | [diff] [blame] | 3034 | return -ENOENT; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 3035 | } |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 3036 | |
Matt Roper | 161d0dc | 2014-06-10 08:28:10 -0700 | [diff] [blame] | 3037 | /* |
| 3038 | * If this crtc has a universal cursor plane, call that plane's update |
| 3039 | * handler rather than using legacy cursor handlers. |
| 3040 | */ |
Daniel Vetter | 4d02e2d | 2014-11-11 10:12:00 +0100 | [diff] [blame] | 3041 | drm_modeset_lock_crtc(crtc, crtc->cursor); |
Daniel Vetter | f2b50c1 | 2014-09-12 17:07:32 +0200 | [diff] [blame] | 3042 | if (crtc->cursor) { |
| 3043 | ret = drm_mode_cursor_universal(crtc, req, file_priv); |
| 3044 | goto out; |
| 3045 | } |
| 3046 | |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 3047 | if (req->flags & DRM_MODE_CURSOR_BO) { |
Dave Airlie | 4c813d4 | 2013-06-20 11:48:52 +1000 | [diff] [blame] | 3048 | if (!crtc->funcs->cursor_set && !crtc->funcs->cursor_set2) { |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 3049 | ret = -ENXIO; |
| 3050 | goto out; |
| 3051 | } |
| 3052 | /* Turns off the cursor if handle is 0 */ |
Dave Airlie | 4c813d4 | 2013-06-20 11:48:52 +1000 | [diff] [blame] | 3053 | if (crtc->funcs->cursor_set2) |
| 3054 | ret = crtc->funcs->cursor_set2(crtc, file_priv, req->handle, |
| 3055 | req->width, req->height, req->hot_x, req->hot_y); |
| 3056 | else |
| 3057 | ret = crtc->funcs->cursor_set(crtc, file_priv, req->handle, |
| 3058 | req->width, req->height); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 3059 | } |
| 3060 | |
| 3061 | if (req->flags & DRM_MODE_CURSOR_MOVE) { |
| 3062 | if (crtc->funcs->cursor_move) { |
| 3063 | ret = crtc->funcs->cursor_move(crtc, req->x, req->y); |
| 3064 | } else { |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 3065 | ret = -EFAULT; |
| 3066 | goto out; |
| 3067 | } |
| 3068 | } |
| 3069 | out: |
Daniel Vetter | d059f65 | 2014-07-25 18:07:40 +0200 | [diff] [blame] | 3070 | drm_modeset_unlock_crtc(crtc); |
Daniel Vetter | dac3566 | 2012-12-02 15:24:10 +0100 | [diff] [blame] | 3071 | |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 3072 | return ret; |
Dave Airlie | 4c813d4 | 2013-06-20 11:48:52 +1000 | [diff] [blame] | 3073 | |
| 3074 | } |
Daniel Vetter | c8e32cc | 2014-03-10 21:33:02 +0100 | [diff] [blame] | 3075 | |
| 3076 | |
| 3077 | /** |
| 3078 | * drm_mode_cursor_ioctl - set CRTC's cursor configuration |
| 3079 | * @dev: drm device for the ioctl |
| 3080 | * @data: data pointer for the ioctl |
| 3081 | * @file_priv: drm file for the ioctl call |
| 3082 | * |
| 3083 | * Set the cursor configuration based on user request. |
| 3084 | * |
| 3085 | * Called by the user via ioctl. |
| 3086 | * |
| 3087 | * Returns: |
Daniel Vetter | 1a49863 | 2014-11-19 18:38:09 +0100 | [diff] [blame] | 3088 | * Zero on success, negative errno on failure. |
Daniel Vetter | c8e32cc | 2014-03-10 21:33:02 +0100 | [diff] [blame] | 3089 | */ |
Dave Airlie | 4c813d4 | 2013-06-20 11:48:52 +1000 | [diff] [blame] | 3090 | int drm_mode_cursor_ioctl(struct drm_device *dev, |
Daniel Vetter | c8e32cc | 2014-03-10 21:33:02 +0100 | [diff] [blame] | 3091 | void *data, struct drm_file *file_priv) |
Dave Airlie | 4c813d4 | 2013-06-20 11:48:52 +1000 | [diff] [blame] | 3092 | { |
| 3093 | struct drm_mode_cursor *req = data; |
| 3094 | struct drm_mode_cursor2 new_req; |
| 3095 | |
| 3096 | memcpy(&new_req, req, sizeof(struct drm_mode_cursor)); |
| 3097 | new_req.hot_x = new_req.hot_y = 0; |
| 3098 | |
| 3099 | return drm_mode_cursor_common(dev, &new_req, file_priv); |
| 3100 | } |
| 3101 | |
Daniel Vetter | c8e32cc | 2014-03-10 21:33:02 +0100 | [diff] [blame] | 3102 | /** |
| 3103 | * drm_mode_cursor2_ioctl - set CRTC's cursor configuration |
| 3104 | * @dev: drm device for the ioctl |
| 3105 | * @data: data pointer for the ioctl |
| 3106 | * @file_priv: drm file for the ioctl call |
| 3107 | * |
| 3108 | * Set the cursor configuration based on user request. This implements the 2nd |
| 3109 | * version of the cursor ioctl, which allows userspace to additionally specify |
| 3110 | * the hotspot of the pointer. |
| 3111 | * |
| 3112 | * Called by the user via ioctl. |
| 3113 | * |
| 3114 | * Returns: |
Daniel Vetter | 1a49863 | 2014-11-19 18:38:09 +0100 | [diff] [blame] | 3115 | * Zero on success, negative errno on failure. |
Daniel Vetter | c8e32cc | 2014-03-10 21:33:02 +0100 | [diff] [blame] | 3116 | */ |
Dave Airlie | 4c813d4 | 2013-06-20 11:48:52 +1000 | [diff] [blame] | 3117 | int drm_mode_cursor2_ioctl(struct drm_device *dev, |
| 3118 | void *data, struct drm_file *file_priv) |
| 3119 | { |
| 3120 | struct drm_mode_cursor2 *req = data; |
Thierry Reding | 4dfd909 | 2014-12-10 13:03:34 +0100 | [diff] [blame] | 3121 | |
Dave Airlie | 4c813d4 | 2013-06-20 11:48:52 +1000 | [diff] [blame] | 3122 | return drm_mode_cursor_common(dev, req, file_priv); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 3123 | } |
| 3124 | |
Daniel Vetter | c8e32cc | 2014-03-10 21:33:02 +0100 | [diff] [blame] | 3125 | /** |
| 3126 | * drm_mode_legacy_fb_format - compute drm fourcc code from legacy description |
| 3127 | * @bpp: bits per pixels |
| 3128 | * @depth: bit depth per pixel |
| 3129 | * |
| 3130 | * Computes a drm fourcc pixel format code for the given @bpp/@depth values. |
| 3131 | * Useful in fbdev emulation code, since that deals in those values. |
| 3132 | */ |
Jesse Barnes | 308e5bc | 2011-11-14 14:51:28 -0800 | [diff] [blame] | 3133 | uint32_t drm_mode_legacy_fb_format(uint32_t bpp, uint32_t depth) |
| 3134 | { |
| 3135 | uint32_t fmt; |
| 3136 | |
| 3137 | switch (bpp) { |
| 3138 | case 8: |
Ville Syrjälä | d84f031 | 2013-01-31 19:43:38 +0200 | [diff] [blame] | 3139 | fmt = DRM_FORMAT_C8; |
Jesse Barnes | 308e5bc | 2011-11-14 14:51:28 -0800 | [diff] [blame] | 3140 | break; |
| 3141 | case 16: |
| 3142 | if (depth == 15) |
Ville Syrjälä | 04b3924 | 2011-11-17 18:05:13 +0200 | [diff] [blame] | 3143 | fmt = DRM_FORMAT_XRGB1555; |
Jesse Barnes | 308e5bc | 2011-11-14 14:51:28 -0800 | [diff] [blame] | 3144 | else |
Ville Syrjälä | 04b3924 | 2011-11-17 18:05:13 +0200 | [diff] [blame] | 3145 | fmt = DRM_FORMAT_RGB565; |
Jesse Barnes | 308e5bc | 2011-11-14 14:51:28 -0800 | [diff] [blame] | 3146 | break; |
| 3147 | case 24: |
Ville Syrjälä | 04b3924 | 2011-11-17 18:05:13 +0200 | [diff] [blame] | 3148 | fmt = DRM_FORMAT_RGB888; |
Jesse Barnes | 308e5bc | 2011-11-14 14:51:28 -0800 | [diff] [blame] | 3149 | break; |
| 3150 | case 32: |
| 3151 | if (depth == 24) |
Ville Syrjälä | 04b3924 | 2011-11-17 18:05:13 +0200 | [diff] [blame] | 3152 | fmt = DRM_FORMAT_XRGB8888; |
Jesse Barnes | 308e5bc | 2011-11-14 14:51:28 -0800 | [diff] [blame] | 3153 | else if (depth == 30) |
Ville Syrjälä | 04b3924 | 2011-11-17 18:05:13 +0200 | [diff] [blame] | 3154 | fmt = DRM_FORMAT_XRGB2101010; |
Jesse Barnes | 308e5bc | 2011-11-14 14:51:28 -0800 | [diff] [blame] | 3155 | else |
Ville Syrjälä | 04b3924 | 2011-11-17 18:05:13 +0200 | [diff] [blame] | 3156 | fmt = DRM_FORMAT_ARGB8888; |
Jesse Barnes | 308e5bc | 2011-11-14 14:51:28 -0800 | [diff] [blame] | 3157 | break; |
| 3158 | default: |
Ville Syrjälä | 04b3924 | 2011-11-17 18:05:13 +0200 | [diff] [blame] | 3159 | DRM_ERROR("bad bpp, assuming x8r8g8b8 pixel format\n"); |
| 3160 | fmt = DRM_FORMAT_XRGB8888; |
Jesse Barnes | 308e5bc | 2011-11-14 14:51:28 -0800 | [diff] [blame] | 3161 | break; |
| 3162 | } |
| 3163 | |
| 3164 | return fmt; |
| 3165 | } |
| 3166 | EXPORT_SYMBOL(drm_mode_legacy_fb_format); |
| 3167 | |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 3168 | /** |
| 3169 | * drm_mode_addfb - add an FB to the graphics configuration |
Daniel Vetter | 065a50ed | 2012-12-02 00:09:18 +0100 | [diff] [blame] | 3170 | * @dev: drm device for the ioctl |
| 3171 | * @data: data pointer for the ioctl |
| 3172 | * @file_priv: drm file for the ioctl call |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 3173 | * |
Daniel Vetter | c8e32cc | 2014-03-10 21:33:02 +0100 | [diff] [blame] | 3174 | * 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] | 3175 | * original addfb ioctl which only supported RGB formats. |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 3176 | * |
| 3177 | * Called by the user via ioctl. |
| 3178 | * |
Daniel Vetter | c8e32cc | 2014-03-10 21:33:02 +0100 | [diff] [blame] | 3179 | * Returns: |
Daniel Vetter | 1a49863 | 2014-11-19 18:38:09 +0100 | [diff] [blame] | 3180 | * Zero on success, negative errno on failure. |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 3181 | */ |
| 3182 | int drm_mode_addfb(struct drm_device *dev, |
| 3183 | void *data, struct drm_file *file_priv) |
| 3184 | { |
Jesse Barnes | 308e5bc | 2011-11-14 14:51:28 -0800 | [diff] [blame] | 3185 | struct drm_mode_fb_cmd *or = data; |
| 3186 | struct drm_mode_fb_cmd2 r = {}; |
Chuck Ebbert | 228f2cb | 2014-10-08 11:40:34 -0500 | [diff] [blame] | 3187 | int ret; |
Jesse Barnes | 308e5bc | 2011-11-14 14:51:28 -0800 | [diff] [blame] | 3188 | |
Chuck Ebbert | 228f2cb | 2014-10-08 11:40:34 -0500 | [diff] [blame] | 3189 | /* convert to new format and call new ioctl */ |
Jesse Barnes | 308e5bc | 2011-11-14 14:51:28 -0800 | [diff] [blame] | 3190 | r.fb_id = or->fb_id; |
| 3191 | r.width = or->width; |
| 3192 | r.height = or->height; |
| 3193 | r.pitches[0] = or->pitch; |
| 3194 | r.pixel_format = drm_mode_legacy_fb_format(or->bpp, or->depth); |
| 3195 | r.handles[0] = or->handle; |
| 3196 | |
Chuck Ebbert | 228f2cb | 2014-10-08 11:40:34 -0500 | [diff] [blame] | 3197 | ret = drm_mode_addfb2(dev, &r, file_priv); |
| 3198 | if (ret) |
| 3199 | return ret; |
Jesse Barnes | 308e5bc | 2011-11-14 14:51:28 -0800 | [diff] [blame] | 3200 | |
Chuck Ebbert | 228f2cb | 2014-10-08 11:40:34 -0500 | [diff] [blame] | 3201 | or->fb_id = r.fb_id; |
Daniel Vetter | 4b096ac | 2012-12-10 21:19:18 +0100 | [diff] [blame] | 3202 | |
Daniel Vetter | baf698b | 2014-11-12 11:59:47 +0100 | [diff] [blame] | 3203 | return 0; |
Jesse Barnes | 308e5bc | 2011-11-14 14:51:28 -0800 | [diff] [blame] | 3204 | } |
| 3205 | |
Ville Syrjälä | cff91b6 | 2012-05-24 20:54:00 +0300 | [diff] [blame] | 3206 | static int format_check(const struct drm_mode_fb_cmd2 *r) |
Ville Syrjälä | 935b597 | 2011-12-20 00:06:48 +0200 | [diff] [blame] | 3207 | { |
| 3208 | uint32_t format = r->pixel_format & ~DRM_FORMAT_BIG_ENDIAN; |
| 3209 | |
| 3210 | switch (format) { |
| 3211 | case DRM_FORMAT_C8: |
| 3212 | case DRM_FORMAT_RGB332: |
| 3213 | case DRM_FORMAT_BGR233: |
| 3214 | case DRM_FORMAT_XRGB4444: |
| 3215 | case DRM_FORMAT_XBGR4444: |
| 3216 | case DRM_FORMAT_RGBX4444: |
| 3217 | case DRM_FORMAT_BGRX4444: |
| 3218 | case DRM_FORMAT_ARGB4444: |
| 3219 | case DRM_FORMAT_ABGR4444: |
| 3220 | case DRM_FORMAT_RGBA4444: |
| 3221 | case DRM_FORMAT_BGRA4444: |
| 3222 | case DRM_FORMAT_XRGB1555: |
| 3223 | case DRM_FORMAT_XBGR1555: |
| 3224 | case DRM_FORMAT_RGBX5551: |
| 3225 | case DRM_FORMAT_BGRX5551: |
| 3226 | case DRM_FORMAT_ARGB1555: |
| 3227 | case DRM_FORMAT_ABGR1555: |
| 3228 | case DRM_FORMAT_RGBA5551: |
| 3229 | case DRM_FORMAT_BGRA5551: |
| 3230 | case DRM_FORMAT_RGB565: |
| 3231 | case DRM_FORMAT_BGR565: |
| 3232 | case DRM_FORMAT_RGB888: |
| 3233 | case DRM_FORMAT_BGR888: |
| 3234 | case DRM_FORMAT_XRGB8888: |
| 3235 | case DRM_FORMAT_XBGR8888: |
| 3236 | case DRM_FORMAT_RGBX8888: |
| 3237 | case DRM_FORMAT_BGRX8888: |
| 3238 | case DRM_FORMAT_ARGB8888: |
| 3239 | case DRM_FORMAT_ABGR8888: |
| 3240 | case DRM_FORMAT_RGBA8888: |
| 3241 | case DRM_FORMAT_BGRA8888: |
| 3242 | case DRM_FORMAT_XRGB2101010: |
| 3243 | case DRM_FORMAT_XBGR2101010: |
| 3244 | case DRM_FORMAT_RGBX1010102: |
| 3245 | case DRM_FORMAT_BGRX1010102: |
| 3246 | case DRM_FORMAT_ARGB2101010: |
| 3247 | case DRM_FORMAT_ABGR2101010: |
| 3248 | case DRM_FORMAT_RGBA1010102: |
| 3249 | case DRM_FORMAT_BGRA1010102: |
| 3250 | case DRM_FORMAT_YUYV: |
| 3251 | case DRM_FORMAT_YVYU: |
| 3252 | case DRM_FORMAT_UYVY: |
| 3253 | case DRM_FORMAT_VYUY: |
| 3254 | case DRM_FORMAT_AYUV: |
| 3255 | case DRM_FORMAT_NV12: |
| 3256 | case DRM_FORMAT_NV21: |
| 3257 | case DRM_FORMAT_NV16: |
| 3258 | case DRM_FORMAT_NV61: |
Laurent Pinchart | ba623f6 | 2012-05-18 23:47:40 +0200 | [diff] [blame] | 3259 | case DRM_FORMAT_NV24: |
| 3260 | case DRM_FORMAT_NV42: |
Ville Syrjälä | 935b597 | 2011-12-20 00:06:48 +0200 | [diff] [blame] | 3261 | case DRM_FORMAT_YUV410: |
| 3262 | case DRM_FORMAT_YVU410: |
| 3263 | case DRM_FORMAT_YUV411: |
| 3264 | case DRM_FORMAT_YVU411: |
| 3265 | case DRM_FORMAT_YUV420: |
| 3266 | case DRM_FORMAT_YVU420: |
| 3267 | case DRM_FORMAT_YUV422: |
| 3268 | case DRM_FORMAT_YVU422: |
| 3269 | case DRM_FORMAT_YUV444: |
| 3270 | case DRM_FORMAT_YVU444: |
| 3271 | return 0; |
| 3272 | default: |
Ville Syrjälä | 23c453a | 2013-10-15 21:06:51 +0300 | [diff] [blame] | 3273 | DRM_DEBUG_KMS("invalid pixel format %s\n", |
| 3274 | drm_get_format_name(r->pixel_format)); |
Ville Syrjälä | 935b597 | 2011-12-20 00:06:48 +0200 | [diff] [blame] | 3275 | return -EINVAL; |
| 3276 | } |
| 3277 | } |
| 3278 | |
Ville Syrjälä | cff91b6 | 2012-05-24 20:54:00 +0300 | [diff] [blame] | 3279 | static int framebuffer_check(const struct drm_mode_fb_cmd2 *r) |
Ville Syrjälä | d1b45d5 | 2012-04-05 21:35:18 +0300 | [diff] [blame] | 3280 | { |
| 3281 | int ret, hsub, vsub, num_planes, i; |
| 3282 | |
| 3283 | ret = format_check(r); |
| 3284 | if (ret) { |
Ville Syrjälä | 6ba6d03 | 2013-06-10 11:15:10 +0300 | [diff] [blame] | 3285 | DRM_DEBUG_KMS("bad framebuffer format %s\n", |
| 3286 | drm_get_format_name(r->pixel_format)); |
Ville Syrjälä | d1b45d5 | 2012-04-05 21:35:18 +0300 | [diff] [blame] | 3287 | return ret; |
| 3288 | } |
| 3289 | |
| 3290 | hsub = drm_format_horz_chroma_subsampling(r->pixel_format); |
| 3291 | vsub = drm_format_vert_chroma_subsampling(r->pixel_format); |
| 3292 | num_planes = drm_format_num_planes(r->pixel_format); |
| 3293 | |
| 3294 | if (r->width == 0 || r->width % hsub) { |
Chuck Ebbert | 209f552 | 2014-10-08 11:37:20 -0500 | [diff] [blame] | 3295 | DRM_DEBUG_KMS("bad framebuffer width %u\n", r->width); |
Ville Syrjälä | d1b45d5 | 2012-04-05 21:35:18 +0300 | [diff] [blame] | 3296 | return -EINVAL; |
| 3297 | } |
| 3298 | |
| 3299 | if (r->height == 0 || r->height % vsub) { |
Dave Airlie | 1aa1b11 | 2012-05-01 17:38:35 +0100 | [diff] [blame] | 3300 | DRM_DEBUG_KMS("bad framebuffer height %u\n", r->height); |
Ville Syrjälä | d1b45d5 | 2012-04-05 21:35:18 +0300 | [diff] [blame] | 3301 | return -EINVAL; |
| 3302 | } |
| 3303 | |
| 3304 | for (i = 0; i < num_planes; i++) { |
| 3305 | unsigned int width = r->width / (i != 0 ? hsub : 1); |
Ville Syrjälä | b180b5d | 2012-10-25 18:05:04 +0000 | [diff] [blame] | 3306 | unsigned int height = r->height / (i != 0 ? vsub : 1); |
| 3307 | unsigned int cpp = drm_format_plane_cpp(r->pixel_format, i); |
Ville Syrjälä | d1b45d5 | 2012-04-05 21:35:18 +0300 | [diff] [blame] | 3308 | |
| 3309 | if (!r->handles[i]) { |
Dave Airlie | 1aa1b11 | 2012-05-01 17:38:35 +0100 | [diff] [blame] | 3310 | 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] | 3311 | return -EINVAL; |
| 3312 | } |
| 3313 | |
Ville Syrjälä | b180b5d | 2012-10-25 18:05:04 +0000 | [diff] [blame] | 3314 | if ((uint64_t) width * cpp > UINT_MAX) |
| 3315 | return -ERANGE; |
| 3316 | |
| 3317 | if ((uint64_t) height * r->pitches[i] + r->offsets[i] > UINT_MAX) |
| 3318 | return -ERANGE; |
| 3319 | |
| 3320 | if (r->pitches[i] < width * cpp) { |
Dave Airlie | 1aa1b11 | 2012-05-01 17:38:35 +0100 | [diff] [blame] | 3321 | 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] | 3322 | return -EINVAL; |
| 3323 | } |
Rob Clark | e3eb325 | 2015-02-05 14:41:52 +0000 | [diff] [blame] | 3324 | |
| 3325 | if (r->modifier[i] && !(r->flags & DRM_MODE_FB_MODIFIERS)) { |
| 3326 | DRM_DEBUG_KMS("bad fb modifier %llu for plane %d\n", |
| 3327 | r->modifier[i], i); |
| 3328 | return -EINVAL; |
| 3329 | } |
Rob Clark | 570655b | 2015-01-30 20:18:11 +0530 | [diff] [blame] | 3330 | |
| 3331 | /* modifier specific checks: */ |
| 3332 | switch (r->modifier[i]) { |
| 3333 | case DRM_FORMAT_MOD_SAMSUNG_64_32_TILE: |
| 3334 | /* NOTE: the pitch restriction may be lifted later if it turns |
| 3335 | * out that no hw has this restriction: |
| 3336 | */ |
| 3337 | if (r->pixel_format != DRM_FORMAT_NV12 || |
| 3338 | width % 128 || height % 32 || |
| 3339 | r->pitches[i] % 128) { |
| 3340 | DRM_DEBUG_KMS("bad modifier data for plane %d\n", i); |
| 3341 | return -EINVAL; |
| 3342 | } |
| 3343 | break; |
| 3344 | |
| 3345 | default: |
| 3346 | break; |
| 3347 | } |
Ville Syrjälä | d1b45d5 | 2012-04-05 21:35:18 +0300 | [diff] [blame] | 3348 | } |
| 3349 | |
Daniel Vetter | bbe16a4 | 2015-05-20 16:53:53 +0200 | [diff] [blame] | 3350 | for (i = num_planes; i < 4; i++) { |
| 3351 | if (r->modifier[i]) { |
| 3352 | DRM_DEBUG_KMS("non-zero modifier for unused plane %d\n", i); |
| 3353 | return -EINVAL; |
| 3354 | } |
| 3355 | |
| 3356 | /* Pre-FB_MODIFIERS userspace didn't clear the structs properly. */ |
| 3357 | if (!(r->flags & DRM_MODE_FB_MODIFIERS)) |
| 3358 | continue; |
| 3359 | |
| 3360 | if (r->handles[i]) { |
| 3361 | DRM_DEBUG_KMS("buffer object handle for unused plane %d\n", i); |
| 3362 | return -EINVAL; |
| 3363 | } |
| 3364 | |
| 3365 | if (r->pitches[i]) { |
| 3366 | DRM_DEBUG_KMS("non-zero pitch for unused plane %d\n", i); |
| 3367 | return -EINVAL; |
| 3368 | } |
| 3369 | |
| 3370 | if (r->offsets[i]) { |
| 3371 | DRM_DEBUG_KMS("non-zero offset for unused plane %d\n", i); |
| 3372 | return -EINVAL; |
| 3373 | } |
| 3374 | } |
| 3375 | |
Ville Syrjälä | d1b45d5 | 2012-04-05 21:35:18 +0300 | [diff] [blame] | 3376 | return 0; |
| 3377 | } |
| 3378 | |
Chris Wilson | 9a6f513 | 2015-02-25 13:45:26 +0000 | [diff] [blame] | 3379 | static struct drm_framebuffer * |
| 3380 | internal_framebuffer_create(struct drm_device *dev, |
Ville Syrjälä | 1eb83451 | 2015-11-11 19:11:29 +0200 | [diff] [blame] | 3381 | const struct drm_mode_fb_cmd2 *r, |
Chris Wilson | 9a6f513 | 2015-02-25 13:45:26 +0000 | [diff] [blame] | 3382 | struct drm_file *file_priv) |
Matt Roper | c394c2b | 2014-06-10 08:28:08 -0700 | [diff] [blame] | 3383 | { |
| 3384 | struct drm_mode_config *config = &dev->mode_config; |
| 3385 | struct drm_framebuffer *fb; |
| 3386 | int ret; |
| 3387 | |
Rob Clark | e3eb325 | 2015-02-05 14:41:52 +0000 | [diff] [blame] | 3388 | if (r->flags & ~(DRM_MODE_FB_INTERLACED | DRM_MODE_FB_MODIFIERS)) { |
Matt Roper | c394c2b | 2014-06-10 08:28:08 -0700 | [diff] [blame] | 3389 | DRM_DEBUG_KMS("bad framebuffer flags 0x%08x\n", r->flags); |
| 3390 | return ERR_PTR(-EINVAL); |
| 3391 | } |
| 3392 | |
| 3393 | if ((config->min_width > r->width) || (r->width > config->max_width)) { |
| 3394 | DRM_DEBUG_KMS("bad framebuffer width %d, should be >= %d && <= %d\n", |
| 3395 | r->width, config->min_width, config->max_width); |
| 3396 | return ERR_PTR(-EINVAL); |
| 3397 | } |
| 3398 | if ((config->min_height > r->height) || (r->height > config->max_height)) { |
| 3399 | DRM_DEBUG_KMS("bad framebuffer height %d, should be >= %d && <= %d\n", |
| 3400 | r->height, config->min_height, config->max_height); |
| 3401 | return ERR_PTR(-EINVAL); |
| 3402 | } |
| 3403 | |
Rob Clark | e3eb325 | 2015-02-05 14:41:52 +0000 | [diff] [blame] | 3404 | if (r->flags & DRM_MODE_FB_MODIFIERS && |
| 3405 | !dev->mode_config.allow_fb_modifiers) { |
| 3406 | DRM_DEBUG_KMS("driver does not support fb modifiers\n"); |
| 3407 | return ERR_PTR(-EINVAL); |
| 3408 | } |
| 3409 | |
Matt Roper | c394c2b | 2014-06-10 08:28:08 -0700 | [diff] [blame] | 3410 | ret = framebuffer_check(r); |
| 3411 | if (ret) |
| 3412 | return ERR_PTR(ret); |
| 3413 | |
| 3414 | fb = dev->mode_config.funcs->fb_create(dev, file_priv, r); |
| 3415 | if (IS_ERR(fb)) { |
| 3416 | DRM_DEBUG_KMS("could not create framebuffer\n"); |
| 3417 | return fb; |
| 3418 | } |
| 3419 | |
Matt Roper | c394c2b | 2014-06-10 08:28:08 -0700 | [diff] [blame] | 3420 | return fb; |
| 3421 | } |
| 3422 | |
Jesse Barnes | 308e5bc | 2011-11-14 14:51:28 -0800 | [diff] [blame] | 3423 | /** |
| 3424 | * drm_mode_addfb2 - add an FB to the graphics configuration |
Daniel Vetter | 065a50ed | 2012-12-02 00:09:18 +0100 | [diff] [blame] | 3425 | * @dev: drm device for the ioctl |
| 3426 | * @data: data pointer for the ioctl |
| 3427 | * @file_priv: drm file for the ioctl call |
Jesse Barnes | 308e5bc | 2011-11-14 14:51:28 -0800 | [diff] [blame] | 3428 | * |
Daniel Vetter | c8e32cc | 2014-03-10 21:33:02 +0100 | [diff] [blame] | 3429 | * Add a new FB to the specified CRTC, given a user request with format. This is |
| 3430 | * the 2nd version of the addfb ioctl, which supports multi-planar framebuffers |
| 3431 | * and uses fourcc codes as pixel format specifiers. |
Jesse Barnes | 308e5bc | 2011-11-14 14:51:28 -0800 | [diff] [blame] | 3432 | * |
| 3433 | * Called by the user via ioctl. |
| 3434 | * |
Daniel Vetter | c8e32cc | 2014-03-10 21:33:02 +0100 | [diff] [blame] | 3435 | * Returns: |
Daniel Vetter | 1a49863 | 2014-11-19 18:38:09 +0100 | [diff] [blame] | 3436 | * Zero on success, negative errno on failure. |
Jesse Barnes | 308e5bc | 2011-11-14 14:51:28 -0800 | [diff] [blame] | 3437 | */ |
| 3438 | int drm_mode_addfb2(struct drm_device *dev, |
| 3439 | void *data, struct drm_file *file_priv) |
| 3440 | { |
Chris Wilson | 9a6f513 | 2015-02-25 13:45:26 +0000 | [diff] [blame] | 3441 | struct drm_mode_fb_cmd2 *r = data; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 3442 | struct drm_framebuffer *fb; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 3443 | |
Dave Airlie | fb3b06c | 2011-02-08 13:55:21 +1000 | [diff] [blame] | 3444 | if (!drm_core_check_feature(dev, DRIVER_MODESET)) |
| 3445 | return -EINVAL; |
| 3446 | |
Chris Wilson | 9a6f513 | 2015-02-25 13:45:26 +0000 | [diff] [blame] | 3447 | fb = internal_framebuffer_create(dev, r, file_priv); |
Matt Roper | c394c2b | 2014-06-10 08:28:08 -0700 | [diff] [blame] | 3448 | if (IS_ERR(fb)) |
Daniel Vetter | 4b096ac | 2012-12-10 21:19:18 +0100 | [diff] [blame] | 3449 | return PTR_ERR(fb); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 3450 | |
Chris Wilson | 9a6f513 | 2015-02-25 13:45:26 +0000 | [diff] [blame] | 3451 | DRM_DEBUG_KMS("[FB:%d]\n", fb->base.id); |
Chris Wilson | 9a6f513 | 2015-02-25 13:45:26 +0000 | [diff] [blame] | 3452 | r->fb_id = fb->base.id; |
Dave Airlie | c7e1c59 | 2016-04-15 15:10:39 +1000 | [diff] [blame] | 3453 | |
| 3454 | /* Transfer ownership to the filp for reaping on close */ |
| 3455 | mutex_lock(&file_priv->fbs_lock); |
Chris Wilson | 9a6f513 | 2015-02-25 13:45:26 +0000 | [diff] [blame] | 3456 | list_add(&fb->filp_head, &file_priv->fbs); |
| 3457 | mutex_unlock(&file_priv->fbs_lock); |
| 3458 | |
Matt Roper | c394c2b | 2014-06-10 08:28:08 -0700 | [diff] [blame] | 3459 | return 0; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 3460 | } |
| 3461 | |
| 3462 | /** |
| 3463 | * drm_mode_rmfb - remove an FB from the configuration |
Daniel Vetter | 065a50ed | 2012-12-02 00:09:18 +0100 | [diff] [blame] | 3464 | * @dev: drm device for the ioctl |
| 3465 | * @data: data pointer for the ioctl |
| 3466 | * @file_priv: drm file for the ioctl call |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 3467 | * |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 3468 | * Remove the FB specified by the user. |
| 3469 | * |
| 3470 | * Called by the user via ioctl. |
| 3471 | * |
Daniel Vetter | c8e32cc | 2014-03-10 21:33:02 +0100 | [diff] [blame] | 3472 | * Returns: |
Daniel Vetter | 1a49863 | 2014-11-19 18:38:09 +0100 | [diff] [blame] | 3473 | * Zero on success, negative errno on failure. |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 3474 | */ |
| 3475 | int drm_mode_rmfb(struct drm_device *dev, |
| 3476 | void *data, struct drm_file *file_priv) |
| 3477 | { |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 3478 | struct drm_framebuffer *fb = NULL; |
| 3479 | struct drm_framebuffer *fbl = NULL; |
| 3480 | uint32_t *id = data; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 3481 | int found = 0; |
| 3482 | |
Dave Airlie | fb3b06c | 2011-02-08 13:55:21 +1000 | [diff] [blame] | 3483 | if (!drm_core_check_feature(dev, DRIVER_MODESET)) |
| 3484 | return -EINVAL; |
| 3485 | |
Dave Airlie | 72fe90b | 2016-04-15 15:10:40 +1000 | [diff] [blame] | 3486 | fb = drm_framebuffer_lookup(dev, *id); |
| 3487 | if (!fb) |
| 3488 | return -ENOENT; |
| 3489 | |
Daniel Vetter | 4b096ac | 2012-12-10 21:19:18 +0100 | [diff] [blame] | 3490 | mutex_lock(&file_priv->fbs_lock); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 3491 | list_for_each_entry(fbl, &file_priv->fbs, filp_head) |
| 3492 | if (fb == fbl) |
| 3493 | found = 1; |
Dave Airlie | 72fe90b | 2016-04-15 15:10:40 +1000 | [diff] [blame] | 3494 | if (!found) { |
| 3495 | mutex_unlock(&file_priv->fbs_lock); |
| 3496 | goto fail_unref; |
| 3497 | } |
Daniel Vetter | 2b677e8 | 2012-12-10 21:16:05 +0100 | [diff] [blame] | 3498 | |
Daniel Vetter | 4b096ac | 2012-12-10 21:19:18 +0100 | [diff] [blame] | 3499 | list_del_init(&fb->filp_head); |
| 3500 | mutex_unlock(&file_priv->fbs_lock); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 3501 | |
Dave Airlie | 72fe90b | 2016-04-15 15:10:40 +1000 | [diff] [blame] | 3502 | /* we now own the reference that was stored in the fbs list */ |
| 3503 | drm_framebuffer_unreference(fb); |
| 3504 | |
| 3505 | /* drop the reference we picked up in framebuffer lookup */ |
Maarten Lankhorst | 1380313 | 2015-09-09 16:40:56 +0200 | [diff] [blame] | 3506 | drm_framebuffer_unreference(fb); |
Daniel Vetter | 4b096ac | 2012-12-10 21:19:18 +0100 | [diff] [blame] | 3507 | |
Daniel Vetter | 2b677e8 | 2012-12-10 21:16:05 +0100 | [diff] [blame] | 3508 | return 0; |
| 3509 | |
Dave Airlie | 72fe90b | 2016-04-15 15:10:40 +1000 | [diff] [blame] | 3510 | fail_unref: |
| 3511 | drm_framebuffer_unreference(fb); |
Ville Syrjälä | 37c4e70 | 2013-10-17 13:35:01 +0300 | [diff] [blame] | 3512 | return -ENOENT; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 3513 | } |
| 3514 | |
| 3515 | /** |
| 3516 | * drm_mode_getfb - get FB info |
Daniel Vetter | 065a50ed | 2012-12-02 00:09:18 +0100 | [diff] [blame] | 3517 | * @dev: drm device for the ioctl |
| 3518 | * @data: data pointer for the ioctl |
| 3519 | * @file_priv: drm file for the ioctl call |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 3520 | * |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 3521 | * Lookup the FB given its ID and return info about it. |
| 3522 | * |
| 3523 | * Called by the user via ioctl. |
| 3524 | * |
Daniel Vetter | c8e32cc | 2014-03-10 21:33:02 +0100 | [diff] [blame] | 3525 | * Returns: |
Daniel Vetter | 1a49863 | 2014-11-19 18:38:09 +0100 | [diff] [blame] | 3526 | * Zero on success, negative errno on failure. |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 3527 | */ |
| 3528 | int drm_mode_getfb(struct drm_device *dev, |
| 3529 | void *data, struct drm_file *file_priv) |
| 3530 | { |
| 3531 | struct drm_mode_fb_cmd *r = data; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 3532 | struct drm_framebuffer *fb; |
Daniel Vetter | 58c0dca | 2012-12-13 23:06:08 +0100 | [diff] [blame] | 3533 | int ret; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 3534 | |
Dave Airlie | fb3b06c | 2011-02-08 13:55:21 +1000 | [diff] [blame] | 3535 | if (!drm_core_check_feature(dev, DRIVER_MODESET)) |
| 3536 | return -EINVAL; |
| 3537 | |
Daniel Vetter | 786b99e | 2012-12-02 21:53:40 +0100 | [diff] [blame] | 3538 | fb = drm_framebuffer_lookup(dev, r->fb_id); |
Daniel Vetter | 58c0dca | 2012-12-13 23:06:08 +0100 | [diff] [blame] | 3539 | if (!fb) |
Ville Syrjälä | 37c4e70 | 2013-10-17 13:35:01 +0300 | [diff] [blame] | 3540 | return -ENOENT; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 3541 | |
| 3542 | r->height = fb->height; |
| 3543 | r->width = fb->width; |
| 3544 | r->depth = fb->depth; |
| 3545 | r->bpp = fb->bits_per_pixel; |
Ville Syrjälä | 01f2c77 | 2011-12-20 00:06:49 +0200 | [diff] [blame] | 3546 | r->pitch = fb->pitches[0]; |
David Herrmann | 101b96f | 2013-08-26 15:16:49 +0200 | [diff] [blame] | 3547 | if (fb->funcs->create_handle) { |
Thomas Hellstrom | 09f308f | 2014-03-13 10:00:42 +0100 | [diff] [blame] | 3548 | if (file_priv->is_master || capable(CAP_SYS_ADMIN) || |
Thomas Hellstrom | 4368305 | 2014-03-13 11:07:44 +0100 | [diff] [blame] | 3549 | drm_is_control_client(file_priv)) { |
David Herrmann | 101b96f | 2013-08-26 15:16:49 +0200 | [diff] [blame] | 3550 | ret = fb->funcs->create_handle(fb, file_priv, |
| 3551 | &r->handle); |
| 3552 | } else { |
| 3553 | /* GET_FB() is an unprivileged ioctl so we must not |
| 3554 | * return a buffer-handle to non-master processes! For |
| 3555 | * backwards-compatibility reasons, we cannot make |
| 3556 | * GET_FB() privileged, so just return an invalid handle |
| 3557 | * for non-masters. */ |
| 3558 | r->handle = 0; |
| 3559 | ret = 0; |
| 3560 | } |
| 3561 | } else { |
Daniel Vetter | af26ef3 | 2012-12-13 23:07:50 +0100 | [diff] [blame] | 3562 | ret = -ENODEV; |
David Herrmann | 101b96f | 2013-08-26 15:16:49 +0200 | [diff] [blame] | 3563 | } |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 3564 | |
Daniel Vetter | 58c0dca | 2012-12-13 23:06:08 +0100 | [diff] [blame] | 3565 | drm_framebuffer_unreference(fb); |
| 3566 | |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 3567 | return ret; |
| 3568 | } |
| 3569 | |
Daniel Vetter | c8e32cc | 2014-03-10 21:33:02 +0100 | [diff] [blame] | 3570 | /** |
| 3571 | * drm_mode_dirtyfb_ioctl - flush frontbuffer rendering on an FB |
| 3572 | * @dev: drm device for the ioctl |
| 3573 | * @data: data pointer for the ioctl |
| 3574 | * @file_priv: drm file for the ioctl call |
| 3575 | * |
| 3576 | * Lookup the FB and flush out the damaged area supplied by userspace as a clip |
| 3577 | * rectangle list. Generic userspace which does frontbuffer rendering must call |
| 3578 | * this ioctl to flush out the changes on manual-update display outputs, e.g. |
| 3579 | * usb display-link, mipi manual update panels or edp panel self refresh modes. |
| 3580 | * |
| 3581 | * Modesetting drivers which always update the frontbuffer do not need to |
| 3582 | * implement the corresponding ->dirty framebuffer callback. |
| 3583 | * |
| 3584 | * Called by the user via ioctl. |
| 3585 | * |
| 3586 | * Returns: |
Daniel Vetter | 1a49863 | 2014-11-19 18:38:09 +0100 | [diff] [blame] | 3587 | * Zero on success, negative errno on failure. |
Daniel Vetter | c8e32cc | 2014-03-10 21:33:02 +0100 | [diff] [blame] | 3588 | */ |
Jakob Bornecrantz | 884840a | 2009-12-03 23:25:47 +0000 | [diff] [blame] | 3589 | int drm_mode_dirtyfb_ioctl(struct drm_device *dev, |
| 3590 | void *data, struct drm_file *file_priv) |
| 3591 | { |
| 3592 | struct drm_clip_rect __user *clips_ptr; |
| 3593 | struct drm_clip_rect *clips = NULL; |
| 3594 | struct drm_mode_fb_dirty_cmd *r = data; |
Jakob Bornecrantz | 884840a | 2009-12-03 23:25:47 +0000 | [diff] [blame] | 3595 | struct drm_framebuffer *fb; |
| 3596 | unsigned flags; |
| 3597 | int num_clips; |
Laurent Pinchart | 4a1b071 | 2012-05-17 13:27:21 +0200 | [diff] [blame] | 3598 | int ret; |
Jakob Bornecrantz | 884840a | 2009-12-03 23:25:47 +0000 | [diff] [blame] | 3599 | |
Dave Airlie | fb3b06c | 2011-02-08 13:55:21 +1000 | [diff] [blame] | 3600 | if (!drm_core_check_feature(dev, DRIVER_MODESET)) |
| 3601 | return -EINVAL; |
| 3602 | |
Daniel Vetter | 786b99e | 2012-12-02 21:53:40 +0100 | [diff] [blame] | 3603 | fb = drm_framebuffer_lookup(dev, r->fb_id); |
Daniel Vetter | 4ccf097 | 2012-12-11 00:38:18 +0100 | [diff] [blame] | 3604 | if (!fb) |
Ville Syrjälä | 37c4e70 | 2013-10-17 13:35:01 +0300 | [diff] [blame] | 3605 | return -ENOENT; |
Jakob Bornecrantz | 884840a | 2009-12-03 23:25:47 +0000 | [diff] [blame] | 3606 | |
| 3607 | num_clips = r->num_clips; |
Ville Syrjälä | 81f6c7f | 2011-12-20 00:06:42 +0200 | [diff] [blame] | 3608 | clips_ptr = (struct drm_clip_rect __user *)(unsigned long)r->clips_ptr; |
Jakob Bornecrantz | 884840a | 2009-12-03 23:25:47 +0000 | [diff] [blame] | 3609 | |
| 3610 | if (!num_clips != !clips_ptr) { |
| 3611 | ret = -EINVAL; |
| 3612 | goto out_err1; |
| 3613 | } |
| 3614 | |
| 3615 | flags = DRM_MODE_FB_DIRTY_FLAGS & r->flags; |
| 3616 | |
| 3617 | /* If userspace annotates copy, clips must come in pairs */ |
| 3618 | if (flags & DRM_MODE_FB_DIRTY_ANNOTATE_COPY && (num_clips % 2)) { |
| 3619 | ret = -EINVAL; |
| 3620 | goto out_err1; |
| 3621 | } |
| 3622 | |
| 3623 | if (num_clips && clips_ptr) { |
Xi Wang | a5cd335 | 2011-11-23 01:12:01 -0500 | [diff] [blame] | 3624 | if (num_clips < 0 || num_clips > DRM_MODE_FB_DIRTY_MAX_CLIPS) { |
| 3625 | ret = -EINVAL; |
| 3626 | goto out_err1; |
| 3627 | } |
Thierry Reding | bd3f0ff | 2014-12-10 13:03:35 +0100 | [diff] [blame] | 3628 | clips = kcalloc(num_clips, sizeof(*clips), GFP_KERNEL); |
Jakob Bornecrantz | 884840a | 2009-12-03 23:25:47 +0000 | [diff] [blame] | 3629 | if (!clips) { |
| 3630 | ret = -ENOMEM; |
| 3631 | goto out_err1; |
| 3632 | } |
| 3633 | |
| 3634 | ret = copy_from_user(clips, clips_ptr, |
| 3635 | num_clips * sizeof(*clips)); |
Dan Carpenter | e902a35 | 2010-06-04 12:23:21 +0200 | [diff] [blame] | 3636 | if (ret) { |
| 3637 | ret = -EFAULT; |
Jakob Bornecrantz | 884840a | 2009-12-03 23:25:47 +0000 | [diff] [blame] | 3638 | goto out_err2; |
Dan Carpenter | e902a35 | 2010-06-04 12:23:21 +0200 | [diff] [blame] | 3639 | } |
Jakob Bornecrantz | 884840a | 2009-12-03 23:25:47 +0000 | [diff] [blame] | 3640 | } |
| 3641 | |
| 3642 | if (fb->funcs->dirty) { |
Thomas Hellstrom | 02b0016 | 2010-10-05 12:43:02 +0200 | [diff] [blame] | 3643 | ret = fb->funcs->dirty(fb, file_priv, flags, r->color, |
| 3644 | clips, num_clips); |
Jakob Bornecrantz | 884840a | 2009-12-03 23:25:47 +0000 | [diff] [blame] | 3645 | } else { |
| 3646 | ret = -ENOSYS; |
Jakob Bornecrantz | 884840a | 2009-12-03 23:25:47 +0000 | [diff] [blame] | 3647 | } |
| 3648 | |
| 3649 | out_err2: |
| 3650 | kfree(clips); |
| 3651 | out_err1: |
Daniel Vetter | 4ccf097 | 2012-12-11 00:38:18 +0100 | [diff] [blame] | 3652 | drm_framebuffer_unreference(fb); |
| 3653 | |
Jakob Bornecrantz | 884840a | 2009-12-03 23:25:47 +0000 | [diff] [blame] | 3654 | return ret; |
| 3655 | } |
| 3656 | |
| 3657 | |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 3658 | /** |
| 3659 | * drm_fb_release - remove and free the FBs on this file |
Daniel Vetter | 065a50ed | 2012-12-02 00:09:18 +0100 | [diff] [blame] | 3660 | * @priv: drm file for the ioctl |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 3661 | * |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 3662 | * Destroy all the FBs associated with @filp. |
| 3663 | * |
| 3664 | * Called by the user via ioctl. |
| 3665 | * |
Daniel Vetter | c8e32cc | 2014-03-10 21:33:02 +0100 | [diff] [blame] | 3666 | * Returns: |
Daniel Vetter | 1a49863 | 2014-11-19 18:38:09 +0100 | [diff] [blame] | 3667 | * Zero on success, negative errno on failure. |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 3668 | */ |
Kristian Høgsberg | ea39f83 | 2009-02-12 14:37:56 -0500 | [diff] [blame] | 3669 | void drm_fb_release(struct drm_file *priv) |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 3670 | { |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 3671 | struct drm_framebuffer *fb, *tfb; |
| 3672 | |
Daniel Vetter | 1b11629 | 2014-09-24 21:51:06 +0200 | [diff] [blame] | 3673 | /* |
| 3674 | * 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] | 3675 | * 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] | 3676 | * avoid upsetting lockdep since the universal cursor code adds a |
| 3677 | * framebuffer while holding mutex locks. |
| 3678 | * |
| 3679 | * Note that a real deadlock between fpriv->fbs_lock and the modeset |
| 3680 | * locks is impossible here since no one else but this function can get |
| 3681 | * at it any more. |
| 3682 | */ |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 3683 | list_for_each_entry_safe(fb, tfb, &priv->fbs, filp_head) { |
Daniel Vetter | 4b096ac | 2012-12-10 21:19:18 +0100 | [diff] [blame] | 3684 | list_del_init(&fb->filp_head); |
Daniel Vetter | 2b677e8 | 2012-12-10 21:16:05 +0100 | [diff] [blame] | 3685 | |
Maarten Lankhorst | 73f7570 | 2015-09-09 16:40:57 +0200 | [diff] [blame] | 3686 | /* This drops the fpriv->fbs reference. */ |
Maarten Lankhorst | 1380313 | 2015-09-09 16:40:56 +0200 | [diff] [blame] | 3687 | drm_framebuffer_unreference(fb); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 3688 | } |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 3689 | } |
| 3690 | |
Daniel Vetter | c8e32cc | 2014-03-10 21:33:02 +0100 | [diff] [blame] | 3691 | /** |
| 3692 | * drm_property_create - create a new property type |
| 3693 | * @dev: drm device |
| 3694 | * @flags: flags specifying the property type |
| 3695 | * @name: name of the property |
| 3696 | * @num_values: number of pre-defined values |
| 3697 | * |
| 3698 | * This creates a new generic drm property which can then be attached to a drm |
| 3699 | * object with drm_object_attach_property. The returned property object must be |
| 3700 | * freed with drm_property_destroy. |
| 3701 | * |
Damien Lespiau | 3b5b993 | 2014-10-31 14:39:11 +0000 | [diff] [blame] | 3702 | * Note that the DRM core keeps a per-device list of properties and that, if |
| 3703 | * drm_mode_config_cleanup() is called, it will destroy all properties created |
| 3704 | * by the driver. |
| 3705 | * |
Daniel Vetter | c8e32cc | 2014-03-10 21:33:02 +0100 | [diff] [blame] | 3706 | * Returns: |
| 3707 | * A pointer to the newly created property on success, NULL on failure. |
| 3708 | */ |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 3709 | struct drm_property *drm_property_create(struct drm_device *dev, int flags, |
| 3710 | const char *name, int num_values) |
| 3711 | { |
| 3712 | struct drm_property *property = NULL; |
Ville Syrjälä | 6bfc56a | 2012-03-13 12:35:48 +0200 | [diff] [blame] | 3713 | int ret; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 3714 | |
| 3715 | property = kzalloc(sizeof(struct drm_property), GFP_KERNEL); |
| 3716 | if (!property) |
| 3717 | return NULL; |
| 3718 | |
Rob Clark | 98f75de | 2014-05-30 11:37:03 -0400 | [diff] [blame] | 3719 | property->dev = dev; |
| 3720 | |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 3721 | if (num_values) { |
Thierry Reding | bd3f0ff | 2014-12-10 13:03:35 +0100 | [diff] [blame] | 3722 | property->values = kcalloc(num_values, sizeof(uint64_t), |
| 3723 | GFP_KERNEL); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 3724 | if (!property->values) |
| 3725 | goto fail; |
| 3726 | } |
| 3727 | |
Ville Syrjälä | 6bfc56a | 2012-03-13 12:35:48 +0200 | [diff] [blame] | 3728 | ret = drm_mode_object_get(dev, &property->base, DRM_MODE_OBJECT_PROPERTY); |
| 3729 | if (ret) |
| 3730 | goto fail; |
| 3731 | |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 3732 | property->flags = flags; |
| 3733 | property->num_values = num_values; |
Daniel Vetter | 3758b34 | 2014-11-19 18:38:10 +0100 | [diff] [blame] | 3734 | INIT_LIST_HEAD(&property->enum_list); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 3735 | |
Vinson Lee | 471dd2e | 2011-11-10 11:55:40 -0800 | [diff] [blame] | 3736 | if (name) { |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 3737 | strncpy(property->name, name, DRM_PROP_NAME_LEN); |
Vinson Lee | 471dd2e | 2011-11-10 11:55:40 -0800 | [diff] [blame] | 3738 | property->name[DRM_PROP_NAME_LEN-1] = '\0'; |
| 3739 | } |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 3740 | |
| 3741 | list_add_tail(&property->head, &dev->mode_config.property_list); |
Rob Clark | 5ea22f2 | 2014-05-30 11:34:01 -0400 | [diff] [blame] | 3742 | |
| 3743 | WARN_ON(!drm_property_type_valid(property)); |
| 3744 | |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 3745 | return property; |
| 3746 | fail: |
Ville Syrjälä | 6bfc56a | 2012-03-13 12:35:48 +0200 | [diff] [blame] | 3747 | kfree(property->values); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 3748 | kfree(property); |
| 3749 | return NULL; |
| 3750 | } |
| 3751 | EXPORT_SYMBOL(drm_property_create); |
| 3752 | |
Daniel Vetter | c8e32cc | 2014-03-10 21:33:02 +0100 | [diff] [blame] | 3753 | /** |
Thierry Reding | 2aa9d2b | 2014-06-26 21:37:20 +0200 | [diff] [blame] | 3754 | * drm_property_create_enum - create a new enumeration property type |
Daniel Vetter | c8e32cc | 2014-03-10 21:33:02 +0100 | [diff] [blame] | 3755 | * @dev: drm device |
| 3756 | * @flags: flags specifying the property type |
| 3757 | * @name: name of the property |
| 3758 | * @props: enumeration lists with property values |
| 3759 | * @num_values: number of pre-defined values |
| 3760 | * |
| 3761 | * This creates a new generic drm property which can then be attached to a drm |
| 3762 | * object with drm_object_attach_property. The returned property object must be |
| 3763 | * freed with drm_property_destroy. |
| 3764 | * |
| 3765 | * Userspace is only allowed to set one of the predefined values for enumeration |
| 3766 | * properties. |
| 3767 | * |
| 3768 | * Returns: |
| 3769 | * A pointer to the newly created property on success, NULL on failure. |
| 3770 | */ |
Sascha Hauer | 4a67d39 | 2012-02-06 10:58:17 +0100 | [diff] [blame] | 3771 | struct drm_property *drm_property_create_enum(struct drm_device *dev, int flags, |
| 3772 | const char *name, |
| 3773 | const struct drm_prop_enum_list *props, |
| 3774 | int num_values) |
| 3775 | { |
| 3776 | struct drm_property *property; |
| 3777 | int i, ret; |
| 3778 | |
| 3779 | flags |= DRM_MODE_PROP_ENUM; |
| 3780 | |
| 3781 | property = drm_property_create(dev, flags, name, num_values); |
| 3782 | if (!property) |
| 3783 | return NULL; |
| 3784 | |
| 3785 | for (i = 0; i < num_values; i++) { |
| 3786 | ret = drm_property_add_enum(property, i, |
| 3787 | props[i].type, |
| 3788 | props[i].name); |
| 3789 | if (ret) { |
| 3790 | drm_property_destroy(dev, property); |
| 3791 | return NULL; |
| 3792 | } |
| 3793 | } |
| 3794 | |
| 3795 | return property; |
| 3796 | } |
| 3797 | EXPORT_SYMBOL(drm_property_create_enum); |
| 3798 | |
Daniel Vetter | c8e32cc | 2014-03-10 21:33:02 +0100 | [diff] [blame] | 3799 | /** |
Thierry Reding | 2aa9d2b | 2014-06-26 21:37:20 +0200 | [diff] [blame] | 3800 | * drm_property_create_bitmask - create a new bitmask property type |
Daniel Vetter | c8e32cc | 2014-03-10 21:33:02 +0100 | [diff] [blame] | 3801 | * @dev: drm device |
| 3802 | * @flags: flags specifying the property type |
| 3803 | * @name: name of the property |
| 3804 | * @props: enumeration lists with property bitflags |
Daniel Vetter | 295ee85 | 2014-07-30 14:23:44 +0200 | [diff] [blame] | 3805 | * @num_props: size of the @props array |
| 3806 | * @supported_bits: bitmask of all supported enumeration values |
Daniel Vetter | c8e32cc | 2014-03-10 21:33:02 +0100 | [diff] [blame] | 3807 | * |
Daniel Vetter | 295ee85 | 2014-07-30 14:23:44 +0200 | [diff] [blame] | 3808 | * 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] | 3809 | * object with drm_object_attach_property. The returned property object must be |
| 3810 | * freed with drm_property_destroy. |
| 3811 | * |
| 3812 | * Compared to plain enumeration properties userspace is allowed to set any |
| 3813 | * or'ed together combination of the predefined property bitflag values |
| 3814 | * |
| 3815 | * Returns: |
| 3816 | * A pointer to the newly created property on success, NULL on failure. |
| 3817 | */ |
Rob Clark | 49e2754 | 2012-05-17 02:23:26 -0600 | [diff] [blame] | 3818 | struct drm_property *drm_property_create_bitmask(struct drm_device *dev, |
| 3819 | int flags, const char *name, |
| 3820 | const struct drm_prop_enum_list *props, |
Ville Syrjälä | 7689ffb | 2014-07-08 10:31:52 +0530 | [diff] [blame] | 3821 | int num_props, |
| 3822 | uint64_t supported_bits) |
Rob Clark | 49e2754 | 2012-05-17 02:23:26 -0600 | [diff] [blame] | 3823 | { |
| 3824 | struct drm_property *property; |
Ville Syrjälä | 7689ffb | 2014-07-08 10:31:52 +0530 | [diff] [blame] | 3825 | int i, ret, index = 0; |
| 3826 | int num_values = hweight64(supported_bits); |
Rob Clark | 49e2754 | 2012-05-17 02:23:26 -0600 | [diff] [blame] | 3827 | |
| 3828 | flags |= DRM_MODE_PROP_BITMASK; |
| 3829 | |
| 3830 | property = drm_property_create(dev, flags, name, num_values); |
| 3831 | if (!property) |
| 3832 | return NULL; |
Ville Syrjälä | 7689ffb | 2014-07-08 10:31:52 +0530 | [diff] [blame] | 3833 | for (i = 0; i < num_props; i++) { |
| 3834 | if (!(supported_bits & (1ULL << props[i].type))) |
| 3835 | continue; |
Rob Clark | 49e2754 | 2012-05-17 02:23:26 -0600 | [diff] [blame] | 3836 | |
Ville Syrjälä | 7689ffb | 2014-07-08 10:31:52 +0530 | [diff] [blame] | 3837 | if (WARN_ON(index >= num_values)) { |
| 3838 | drm_property_destroy(dev, property); |
| 3839 | return NULL; |
| 3840 | } |
| 3841 | |
| 3842 | ret = drm_property_add_enum(property, index++, |
Rob Clark | 49e2754 | 2012-05-17 02:23:26 -0600 | [diff] [blame] | 3843 | props[i].type, |
| 3844 | props[i].name); |
| 3845 | if (ret) { |
| 3846 | drm_property_destroy(dev, property); |
| 3847 | return NULL; |
| 3848 | } |
| 3849 | } |
| 3850 | |
| 3851 | return property; |
| 3852 | } |
| 3853 | EXPORT_SYMBOL(drm_property_create_bitmask); |
| 3854 | |
Rob Clark | ebc44cf | 2012-09-12 22:22:31 -0500 | [diff] [blame] | 3855 | static struct drm_property *property_create_range(struct drm_device *dev, |
| 3856 | int flags, const char *name, |
| 3857 | uint64_t min, uint64_t max) |
| 3858 | { |
| 3859 | struct drm_property *property; |
| 3860 | |
| 3861 | property = drm_property_create(dev, flags, name, 2); |
| 3862 | if (!property) |
| 3863 | return NULL; |
| 3864 | |
| 3865 | property->values[0] = min; |
| 3866 | property->values[1] = max; |
| 3867 | |
| 3868 | return property; |
| 3869 | } |
| 3870 | |
Daniel Vetter | c8e32cc | 2014-03-10 21:33:02 +0100 | [diff] [blame] | 3871 | /** |
Daniel Vetter | 960cd9d | 2015-01-21 08:47:38 +0100 | [diff] [blame] | 3872 | * drm_property_create_range - create a new unsigned ranged property type |
Daniel Vetter | c8e32cc | 2014-03-10 21:33:02 +0100 | [diff] [blame] | 3873 | * @dev: drm device |
| 3874 | * @flags: flags specifying the property type |
| 3875 | * @name: name of the property |
| 3876 | * @min: minimum value of the property |
| 3877 | * @max: maximum value of the property |
| 3878 | * |
| 3879 | * This creates a new generic drm property which can then be attached to a drm |
| 3880 | * object with drm_object_attach_property. The returned property object must be |
| 3881 | * freed with drm_property_destroy. |
| 3882 | * |
Daniel Vetter | 960cd9d | 2015-01-21 08:47:38 +0100 | [diff] [blame] | 3883 | * Userspace is allowed to set any unsigned integer value in the (min, max) |
| 3884 | * range inclusive. |
Daniel Vetter | c8e32cc | 2014-03-10 21:33:02 +0100 | [diff] [blame] | 3885 | * |
| 3886 | * Returns: |
| 3887 | * A pointer to the newly created property on success, NULL on failure. |
| 3888 | */ |
Sascha Hauer | d9bc3c0 | 2012-02-06 10:58:18 +0100 | [diff] [blame] | 3889 | struct drm_property *drm_property_create_range(struct drm_device *dev, int flags, |
| 3890 | const char *name, |
| 3891 | uint64_t min, uint64_t max) |
| 3892 | { |
Rob Clark | ebc44cf | 2012-09-12 22:22:31 -0500 | [diff] [blame] | 3893 | return property_create_range(dev, DRM_MODE_PROP_RANGE | flags, |
| 3894 | name, min, max); |
Sascha Hauer | d9bc3c0 | 2012-02-06 10:58:18 +0100 | [diff] [blame] | 3895 | } |
| 3896 | EXPORT_SYMBOL(drm_property_create_range); |
| 3897 | |
Daniel Vetter | 960cd9d | 2015-01-21 08:47:38 +0100 | [diff] [blame] | 3898 | /** |
| 3899 | * drm_property_create_signed_range - create a new signed ranged property type |
| 3900 | * @dev: drm device |
| 3901 | * @flags: flags specifying the property type |
| 3902 | * @name: name of the property |
| 3903 | * @min: minimum value of the property |
| 3904 | * @max: maximum value of the property |
| 3905 | * |
| 3906 | * This creates a new generic drm property which can then be attached to a drm |
| 3907 | * object with drm_object_attach_property. The returned property object must be |
| 3908 | * freed with drm_property_destroy. |
| 3909 | * |
| 3910 | * Userspace is allowed to set any signed integer value in the (min, max) |
| 3911 | * range inclusive. |
| 3912 | * |
| 3913 | * Returns: |
| 3914 | * A pointer to the newly created property on success, NULL on failure. |
| 3915 | */ |
Rob Clark | ebc44cf | 2012-09-12 22:22:31 -0500 | [diff] [blame] | 3916 | struct drm_property *drm_property_create_signed_range(struct drm_device *dev, |
| 3917 | int flags, const char *name, |
| 3918 | int64_t min, int64_t max) |
| 3919 | { |
| 3920 | return property_create_range(dev, DRM_MODE_PROP_SIGNED_RANGE | flags, |
| 3921 | name, I642U64(min), I642U64(max)); |
| 3922 | } |
| 3923 | EXPORT_SYMBOL(drm_property_create_signed_range); |
| 3924 | |
Daniel Vetter | 960cd9d | 2015-01-21 08:47:38 +0100 | [diff] [blame] | 3925 | /** |
| 3926 | * drm_property_create_object - create a new object property type |
| 3927 | * @dev: drm device |
| 3928 | * @flags: flags specifying the property type |
| 3929 | * @name: name of the property |
| 3930 | * @type: object type from DRM_MODE_OBJECT_* defines |
| 3931 | * |
| 3932 | * This creates a new generic drm property which can then be attached to a drm |
| 3933 | * object with drm_object_attach_property. The returned property object must be |
| 3934 | * freed with drm_property_destroy. |
| 3935 | * |
| 3936 | * Userspace is only allowed to set this to any property value of the given |
| 3937 | * @type. Only useful for atomic properties, which is enforced. |
| 3938 | * |
| 3939 | * Returns: |
| 3940 | * A pointer to the newly created property on success, NULL on failure. |
| 3941 | */ |
Rob Clark | 98f75de | 2014-05-30 11:37:03 -0400 | [diff] [blame] | 3942 | struct drm_property *drm_property_create_object(struct drm_device *dev, |
| 3943 | int flags, const char *name, uint32_t type) |
| 3944 | { |
| 3945 | struct drm_property *property; |
| 3946 | |
| 3947 | flags |= DRM_MODE_PROP_OBJECT; |
| 3948 | |
Daniel Vetter | 960cd9d | 2015-01-21 08:47:38 +0100 | [diff] [blame] | 3949 | if (WARN_ON(!(flags & DRM_MODE_PROP_ATOMIC))) |
| 3950 | return NULL; |
| 3951 | |
Rob Clark | 98f75de | 2014-05-30 11:37:03 -0400 | [diff] [blame] | 3952 | property = drm_property_create(dev, flags, name, 1); |
| 3953 | if (!property) |
| 3954 | return NULL; |
| 3955 | |
| 3956 | property->values[0] = type; |
| 3957 | |
| 3958 | return property; |
| 3959 | } |
| 3960 | EXPORT_SYMBOL(drm_property_create_object); |
| 3961 | |
Daniel Vetter | c8e32cc | 2014-03-10 21:33:02 +0100 | [diff] [blame] | 3962 | /** |
Daniel Vetter | 960cd9d | 2015-01-21 08:47:38 +0100 | [diff] [blame] | 3963 | * drm_property_create_bool - create a new boolean property type |
| 3964 | * @dev: drm device |
| 3965 | * @flags: flags specifying the property type |
| 3966 | * @name: name of the property |
| 3967 | * |
| 3968 | * This creates a new generic drm property which can then be attached to a drm |
| 3969 | * object with drm_object_attach_property. The returned property object must be |
| 3970 | * freed with drm_property_destroy. |
| 3971 | * |
| 3972 | * This is implemented as a ranged property with only {0, 1} as valid values. |
| 3973 | * |
| 3974 | * Returns: |
| 3975 | * A pointer to the newly created property on success, NULL on failure. |
| 3976 | */ |
| 3977 | struct drm_property *drm_property_create_bool(struct drm_device *dev, int flags, |
| 3978 | const char *name) |
| 3979 | { |
| 3980 | return drm_property_create_range(dev, flags, name, 0, 1); |
| 3981 | } |
| 3982 | EXPORT_SYMBOL(drm_property_create_bool); |
| 3983 | |
| 3984 | /** |
Daniel Vetter | c8e32cc | 2014-03-10 21:33:02 +0100 | [diff] [blame] | 3985 | * drm_property_add_enum - add a possible value to an enumeration property |
| 3986 | * @property: enumeration property to change |
| 3987 | * @index: index of the new enumeration |
| 3988 | * @value: value of the new enumeration |
| 3989 | * @name: symbolic name of the new enumeration |
| 3990 | * |
| 3991 | * This functions adds enumerations to a property. |
| 3992 | * |
| 3993 | * It's use is deprecated, drivers should use one of the more specific helpers |
| 3994 | * to directly create the property with all enumerations already attached. |
| 3995 | * |
| 3996 | * Returns: |
| 3997 | * Zero on success, error code on failure. |
| 3998 | */ |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 3999 | int drm_property_add_enum(struct drm_property *property, int index, |
| 4000 | uint64_t value, const char *name) |
| 4001 | { |
| 4002 | struct drm_property_enum *prop_enum; |
| 4003 | |
Rob Clark | 5ea22f2 | 2014-05-30 11:34:01 -0400 | [diff] [blame] | 4004 | if (!(drm_property_type_is(property, DRM_MODE_PROP_ENUM) || |
| 4005 | drm_property_type_is(property, DRM_MODE_PROP_BITMASK))) |
Rob Clark | 49e2754 | 2012-05-17 02:23:26 -0600 | [diff] [blame] | 4006 | return -EINVAL; |
| 4007 | |
| 4008 | /* |
| 4009 | * Bitmask enum properties have the additional constraint of values |
| 4010 | * from 0 to 63 |
| 4011 | */ |
Rob Clark | 5ea22f2 | 2014-05-30 11:34:01 -0400 | [diff] [blame] | 4012 | if (drm_property_type_is(property, DRM_MODE_PROP_BITMASK) && |
| 4013 | (value > 63)) |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 4014 | return -EINVAL; |
| 4015 | |
Daniel Vetter | 3758b34 | 2014-11-19 18:38:10 +0100 | [diff] [blame] | 4016 | if (!list_empty(&property->enum_list)) { |
| 4017 | list_for_each_entry(prop_enum, &property->enum_list, head) { |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 4018 | if (prop_enum->value == value) { |
| 4019 | strncpy(prop_enum->name, name, DRM_PROP_NAME_LEN); |
| 4020 | prop_enum->name[DRM_PROP_NAME_LEN-1] = '\0'; |
| 4021 | return 0; |
| 4022 | } |
| 4023 | } |
| 4024 | } |
| 4025 | |
| 4026 | prop_enum = kzalloc(sizeof(struct drm_property_enum), GFP_KERNEL); |
| 4027 | if (!prop_enum) |
| 4028 | return -ENOMEM; |
| 4029 | |
| 4030 | strncpy(prop_enum->name, name, DRM_PROP_NAME_LEN); |
| 4031 | prop_enum->name[DRM_PROP_NAME_LEN-1] = '\0'; |
| 4032 | prop_enum->value = value; |
| 4033 | |
| 4034 | property->values[index] = value; |
Daniel Vetter | 3758b34 | 2014-11-19 18:38:10 +0100 | [diff] [blame] | 4035 | list_add_tail(&prop_enum->head, &property->enum_list); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 4036 | return 0; |
| 4037 | } |
| 4038 | EXPORT_SYMBOL(drm_property_add_enum); |
| 4039 | |
Daniel Vetter | c8e32cc | 2014-03-10 21:33:02 +0100 | [diff] [blame] | 4040 | /** |
| 4041 | * drm_property_destroy - destroy a drm property |
| 4042 | * @dev: drm device |
| 4043 | * @property: property to destry |
| 4044 | * |
| 4045 | * This function frees a property including any attached resources like |
| 4046 | * enumeration values. |
| 4047 | */ |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 4048 | void drm_property_destroy(struct drm_device *dev, struct drm_property *property) |
| 4049 | { |
| 4050 | struct drm_property_enum *prop_enum, *pt; |
| 4051 | |
Daniel Vetter | 3758b34 | 2014-11-19 18:38:10 +0100 | [diff] [blame] | 4052 | list_for_each_entry_safe(prop_enum, pt, &property->enum_list, head) { |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 4053 | list_del(&prop_enum->head); |
| 4054 | kfree(prop_enum); |
| 4055 | } |
| 4056 | |
| 4057 | if (property->num_values) |
| 4058 | kfree(property->values); |
Dave Airlie | 7c8f6d2 | 2016-04-15 15:10:32 +1000 | [diff] [blame] | 4059 | drm_mode_object_unregister(dev, &property->base); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 4060 | list_del(&property->head); |
| 4061 | kfree(property); |
| 4062 | } |
| 4063 | EXPORT_SYMBOL(drm_property_destroy); |
| 4064 | |
Daniel Vetter | c8e32cc | 2014-03-10 21:33:02 +0100 | [diff] [blame] | 4065 | /** |
| 4066 | * drm_object_attach_property - attach a property to a modeset object |
| 4067 | * @obj: drm modeset object |
| 4068 | * @property: property to attach |
| 4069 | * @init_val: initial value of the property |
| 4070 | * |
| 4071 | * This attaches the given property to the modeset object with the given initial |
| 4072 | * value. Currently this function cannot fail since the properties are stored in |
| 4073 | * a statically sized array. |
| 4074 | */ |
Paulo Zanoni | c543188 | 2012-05-15 18:09:02 -0300 | [diff] [blame] | 4075 | void drm_object_attach_property(struct drm_mode_object *obj, |
| 4076 | struct drm_property *property, |
| 4077 | uint64_t init_val) |
| 4078 | { |
Paulo Zanoni | 7f88a9b | 2012-05-15 18:09:04 -0300 | [diff] [blame] | 4079 | int count = obj->properties->count; |
Paulo Zanoni | c543188 | 2012-05-15 18:09:02 -0300 | [diff] [blame] | 4080 | |
Paulo Zanoni | 7f88a9b | 2012-05-15 18:09:04 -0300 | [diff] [blame] | 4081 | if (count == DRM_OBJECT_MAX_PROPERTY) { |
| 4082 | WARN(1, "Failed to attach object property (type: 0x%x). Please " |
| 4083 | "increase DRM_OBJECT_MAX_PROPERTY by 1 for each time " |
| 4084 | "you see this message on the same object type.\n", |
| 4085 | obj->type); |
| 4086 | return; |
Paulo Zanoni | c543188 | 2012-05-15 18:09:02 -0300 | [diff] [blame] | 4087 | } |
| 4088 | |
Rob Clark | b17cd75 | 2014-12-16 18:05:30 -0500 | [diff] [blame] | 4089 | obj->properties->properties[count] = property; |
Paulo Zanoni | 7f88a9b | 2012-05-15 18:09:04 -0300 | [diff] [blame] | 4090 | obj->properties->values[count] = init_val; |
| 4091 | obj->properties->count++; |
Rob Clark | 88a48e2 | 2014-12-18 16:01:50 -0500 | [diff] [blame] | 4092 | if (property->flags & DRM_MODE_PROP_ATOMIC) |
| 4093 | obj->properties->atomic_count++; |
Paulo Zanoni | c543188 | 2012-05-15 18:09:02 -0300 | [diff] [blame] | 4094 | } |
| 4095 | EXPORT_SYMBOL(drm_object_attach_property); |
| 4096 | |
Daniel Vetter | c8e32cc | 2014-03-10 21:33:02 +0100 | [diff] [blame] | 4097 | /** |
| 4098 | * drm_object_property_set_value - set the value of a property |
| 4099 | * @obj: drm mode object to set property value for |
| 4100 | * @property: property to set |
| 4101 | * @val: value the property should be set to |
| 4102 | * |
| 4103 | * This functions sets a given property on a given object. This function only |
| 4104 | * changes the software state of the property, it does not call into the |
| 4105 | * driver's ->set_property callback. |
| 4106 | * |
| 4107 | * Returns: |
| 4108 | * Zero on success, error code on failure. |
| 4109 | */ |
Paulo Zanoni | c543188 | 2012-05-15 18:09:02 -0300 | [diff] [blame] | 4110 | int drm_object_property_set_value(struct drm_mode_object *obj, |
| 4111 | struct drm_property *property, uint64_t val) |
| 4112 | { |
| 4113 | int i; |
| 4114 | |
Paulo Zanoni | 7f88a9b | 2012-05-15 18:09:04 -0300 | [diff] [blame] | 4115 | for (i = 0; i < obj->properties->count; i++) { |
Rob Clark | b17cd75 | 2014-12-16 18:05:30 -0500 | [diff] [blame] | 4116 | if (obj->properties->properties[i] == property) { |
Paulo Zanoni | c543188 | 2012-05-15 18:09:02 -0300 | [diff] [blame] | 4117 | obj->properties->values[i] = val; |
| 4118 | return 0; |
| 4119 | } |
| 4120 | } |
| 4121 | |
| 4122 | return -EINVAL; |
| 4123 | } |
| 4124 | EXPORT_SYMBOL(drm_object_property_set_value); |
| 4125 | |
Daniel Vetter | c8e32cc | 2014-03-10 21:33:02 +0100 | [diff] [blame] | 4126 | /** |
| 4127 | * drm_object_property_get_value - retrieve the value of a property |
| 4128 | * @obj: drm mode object to get property value from |
| 4129 | * @property: property to retrieve |
| 4130 | * @val: storage for the property value |
| 4131 | * |
| 4132 | * This function retrieves the softare state of the given property for the given |
| 4133 | * property. Since there is no driver callback to retrieve the current property |
| 4134 | * value this might be out of sync with the hardware, depending upon the driver |
| 4135 | * and property. |
| 4136 | * |
| 4137 | * Returns: |
| 4138 | * Zero on success, error code on failure. |
| 4139 | */ |
Paulo Zanoni | c543188 | 2012-05-15 18:09:02 -0300 | [diff] [blame] | 4140 | int drm_object_property_get_value(struct drm_mode_object *obj, |
| 4141 | struct drm_property *property, uint64_t *val) |
| 4142 | { |
| 4143 | int i; |
| 4144 | |
Rob Clark | 88a48e2 | 2014-12-18 16:01:50 -0500 | [diff] [blame] | 4145 | /* read-only properties bypass atomic mechanism and still store |
| 4146 | * their value in obj->properties->values[].. mostly to avoid |
| 4147 | * having to deal w/ EDID and similar props in atomic paths: |
| 4148 | */ |
| 4149 | if (drm_core_check_feature(property->dev, DRIVER_ATOMIC) && |
| 4150 | !(property->flags & DRM_MODE_PROP_IMMUTABLE)) |
| 4151 | return drm_atomic_get_property(obj, property, val); |
| 4152 | |
Paulo Zanoni | 7f88a9b | 2012-05-15 18:09:04 -0300 | [diff] [blame] | 4153 | for (i = 0; i < obj->properties->count; i++) { |
Rob Clark | b17cd75 | 2014-12-16 18:05:30 -0500 | [diff] [blame] | 4154 | if (obj->properties->properties[i] == property) { |
Paulo Zanoni | c543188 | 2012-05-15 18:09:02 -0300 | [diff] [blame] | 4155 | *val = obj->properties->values[i]; |
| 4156 | return 0; |
| 4157 | } |
| 4158 | } |
| 4159 | |
| 4160 | return -EINVAL; |
| 4161 | } |
| 4162 | EXPORT_SYMBOL(drm_object_property_get_value); |
| 4163 | |
Daniel Vetter | c8e32cc | 2014-03-10 21:33:02 +0100 | [diff] [blame] | 4164 | /** |
Daniel Vetter | 1a49863 | 2014-11-19 18:38:09 +0100 | [diff] [blame] | 4165 | * drm_mode_getproperty_ioctl - get the property metadata |
Daniel Vetter | c8e32cc | 2014-03-10 21:33:02 +0100 | [diff] [blame] | 4166 | * @dev: DRM device |
| 4167 | * @data: ioctl data |
| 4168 | * @file_priv: DRM file info |
| 4169 | * |
Daniel Vetter | 1a49863 | 2014-11-19 18:38:09 +0100 | [diff] [blame] | 4170 | * This function retrieves the metadata for a given property, like the different |
| 4171 | * possible values for an enum property or the limits for a range property. |
| 4172 | * |
| 4173 | * Blob properties are special |
Daniel Vetter | c8e32cc | 2014-03-10 21:33:02 +0100 | [diff] [blame] | 4174 | * |
| 4175 | * Called by the user via ioctl. |
| 4176 | * |
| 4177 | * Returns: |
Daniel Vetter | 1a49863 | 2014-11-19 18:38:09 +0100 | [diff] [blame] | 4178 | * Zero on success, negative errno on failure. |
Daniel Vetter | c8e32cc | 2014-03-10 21:33:02 +0100 | [diff] [blame] | 4179 | */ |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 4180 | int drm_mode_getproperty_ioctl(struct drm_device *dev, |
| 4181 | void *data, struct drm_file *file_priv) |
| 4182 | { |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 4183 | struct drm_mode_get_property *out_resp = data; |
| 4184 | struct drm_property *property; |
| 4185 | int enum_count = 0; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 4186 | int value_count = 0; |
| 4187 | int ret = 0, i; |
| 4188 | int copied; |
| 4189 | struct drm_property_enum *prop_enum; |
| 4190 | struct drm_mode_property_enum __user *enum_ptr; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 4191 | uint64_t __user *values_ptr; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 4192 | |
Dave Airlie | fb3b06c | 2011-02-08 13:55:21 +1000 | [diff] [blame] | 4193 | if (!drm_core_check_feature(dev, DRIVER_MODESET)) |
| 4194 | return -EINVAL; |
| 4195 | |
Daniel Vetter | 8484990 | 2012-12-02 00:28:11 +0100 | [diff] [blame] | 4196 | drm_modeset_lock_all(dev); |
Rob Clark | a2b34e2 | 2013-10-05 16:36:52 -0400 | [diff] [blame] | 4197 | property = drm_property_find(dev, out_resp->prop_id); |
| 4198 | if (!property) { |
Ville Syrjälä | f27657f | 2013-10-17 13:35:00 +0300 | [diff] [blame] | 4199 | ret = -ENOENT; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 4200 | goto done; |
| 4201 | } |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 4202 | |
Rob Clark | 5ea22f2 | 2014-05-30 11:34:01 -0400 | [diff] [blame] | 4203 | if (drm_property_type_is(property, DRM_MODE_PROP_ENUM) || |
| 4204 | drm_property_type_is(property, DRM_MODE_PROP_BITMASK)) { |
Daniel Vetter | 3758b34 | 2014-11-19 18:38:10 +0100 | [diff] [blame] | 4205 | list_for_each_entry(prop_enum, &property->enum_list, head) |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 4206 | enum_count++; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 4207 | } |
| 4208 | |
| 4209 | value_count = property->num_values; |
| 4210 | |
| 4211 | strncpy(out_resp->name, property->name, DRM_PROP_NAME_LEN); |
| 4212 | out_resp->name[DRM_PROP_NAME_LEN-1] = 0; |
| 4213 | out_resp->flags = property->flags; |
| 4214 | |
| 4215 | if ((out_resp->count_values >= value_count) && value_count) { |
Ville Syrjälä | 81f6c7f | 2011-12-20 00:06:42 +0200 | [diff] [blame] | 4216 | values_ptr = (uint64_t __user *)(unsigned long)out_resp->values_ptr; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 4217 | for (i = 0; i < value_count; i++) { |
| 4218 | if (copy_to_user(values_ptr + i, &property->values[i], sizeof(uint64_t))) { |
| 4219 | ret = -EFAULT; |
| 4220 | goto done; |
| 4221 | } |
| 4222 | } |
| 4223 | } |
| 4224 | out_resp->count_values = value_count; |
| 4225 | |
Rob Clark | 5ea22f2 | 2014-05-30 11:34:01 -0400 | [diff] [blame] | 4226 | if (drm_property_type_is(property, DRM_MODE_PROP_ENUM) || |
| 4227 | drm_property_type_is(property, DRM_MODE_PROP_BITMASK)) { |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 4228 | if ((out_resp->count_enum_blobs >= enum_count) && enum_count) { |
| 4229 | copied = 0; |
Ville Syrjälä | 81f6c7f | 2011-12-20 00:06:42 +0200 | [diff] [blame] | 4230 | 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] | 4231 | list_for_each_entry(prop_enum, &property->enum_list, head) { |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 4232 | |
| 4233 | if (copy_to_user(&enum_ptr[copied].value, &prop_enum->value, sizeof(uint64_t))) { |
| 4234 | ret = -EFAULT; |
| 4235 | goto done; |
| 4236 | } |
| 4237 | |
| 4238 | if (copy_to_user(&enum_ptr[copied].name, |
| 4239 | &prop_enum->name, DRM_PROP_NAME_LEN)) { |
| 4240 | ret = -EFAULT; |
| 4241 | goto done; |
| 4242 | } |
| 4243 | copied++; |
| 4244 | } |
| 4245 | } |
| 4246 | out_resp->count_enum_blobs = enum_count; |
| 4247 | } |
| 4248 | |
Daniel Vetter | 3758b34 | 2014-11-19 18:38:10 +0100 | [diff] [blame] | 4249 | /* |
| 4250 | * NOTE: The idea seems to have been to use this to read all the blob |
| 4251 | * property values. But nothing ever added them to the corresponding |
| 4252 | * list, userspace always used the special-purpose get_blob ioctl to |
| 4253 | * read the value for a blob property. It also doesn't make a lot of |
| 4254 | * sense to return values here when everything else is just metadata for |
| 4255 | * the property itself. |
| 4256 | */ |
| 4257 | if (drm_property_type_is(property, DRM_MODE_PROP_BLOB)) |
| 4258 | out_resp->count_enum_blobs = 0; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 4259 | done: |
Daniel Vetter | 8484990 | 2012-12-02 00:28:11 +0100 | [diff] [blame] | 4260 | drm_modeset_unlock_all(dev); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 4261 | return ret; |
| 4262 | } |
| 4263 | |
Daniel Stone | 99531d9 | 2015-05-22 13:34:49 +0100 | [diff] [blame] | 4264 | /** |
| 4265 | * drm_property_create_blob - Create new blob property |
| 4266 | * |
| 4267 | * Creates a new blob property for a specified DRM device, optionally |
| 4268 | * copying data. |
| 4269 | * |
| 4270 | * @dev: DRM device to create property for |
| 4271 | * @length: Length to allocate for blob data |
| 4272 | * @data: If specified, copies data into blob |
Daniel Stone | 10e8cb7 | 2015-05-22 13:34:50 +0100 | [diff] [blame] | 4273 | * |
| 4274 | * Returns: |
| 4275 | * New blob property with a single reference on success, or an ERR_PTR |
| 4276 | * value on failure. |
Daniel Stone | 99531d9 | 2015-05-22 13:34:49 +0100 | [diff] [blame] | 4277 | */ |
Daniel Stone | 6bcacf5 | 2015-04-20 19:22:55 +0100 | [diff] [blame] | 4278 | struct drm_property_blob * |
Thierry Reding | ecbbe59 | 2014-05-13 11:36:13 +0200 | [diff] [blame] | 4279 | drm_property_create_blob(struct drm_device *dev, size_t length, |
Thierry Reding | 12e6cec | 2014-05-13 11:38:36 +0200 | [diff] [blame] | 4280 | const void *data) |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 4281 | { |
| 4282 | struct drm_property_blob *blob; |
Ville Syrjälä | 6bfc56a | 2012-03-13 12:35:48 +0200 | [diff] [blame] | 4283 | int ret; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 4284 | |
Dan Carpenter | 9ac0934 | 2015-10-29 16:37:54 +0300 | [diff] [blame] | 4285 | if (!length || length > ULONG_MAX - sizeof(struct drm_property_blob)) |
Daniel Stone | 10e8cb7 | 2015-05-22 13:34:50 +0100 | [diff] [blame] | 4286 | return ERR_PTR(-EINVAL); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 4287 | |
| 4288 | blob = kzalloc(sizeof(struct drm_property_blob)+length, GFP_KERNEL); |
| 4289 | if (!blob) |
Daniel Stone | 10e8cb7 | 2015-05-22 13:34:50 +0100 | [diff] [blame] | 4290 | return ERR_PTR(-ENOMEM); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 4291 | |
Daniel Stone | e2f5d2e | 2015-05-22 13:34:51 +0100 | [diff] [blame] | 4292 | /* This must be explicitly initialised, so we can safely call list_del |
| 4293 | * on it in the removal handler, even if it isn't in a file list. */ |
| 4294 | INIT_LIST_HEAD(&blob->head_file); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 4295 | blob->length = length; |
Daniel Stone | 6bcacf5 | 2015-04-20 19:22:55 +0100 | [diff] [blame] | 4296 | blob->dev = dev; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 4297 | |
Daniel Stone | 99531d9 | 2015-05-22 13:34:49 +0100 | [diff] [blame] | 4298 | if (data) |
| 4299 | memcpy(blob->data, data, length); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 4300 | |
Daniel Stone | 8fb6e7a | 2015-04-20 19:22:54 +0100 | [diff] [blame] | 4301 | mutex_lock(&dev->mode_config.blob_lock); |
| 4302 | |
| 4303 | ret = drm_mode_object_get(dev, &blob->base, DRM_MODE_OBJECT_BLOB); |
| 4304 | if (ret) { |
| 4305 | kfree(blob); |
| 4306 | mutex_unlock(&dev->mode_config.blob_lock); |
Daniel Stone | 10e8cb7 | 2015-05-22 13:34:50 +0100 | [diff] [blame] | 4307 | return ERR_PTR(-EINVAL); |
Daniel Stone | 8fb6e7a | 2015-04-20 19:22:54 +0100 | [diff] [blame] | 4308 | } |
| 4309 | |
Daniel Stone | 6bcacf5 | 2015-04-20 19:22:55 +0100 | [diff] [blame] | 4310 | kref_init(&blob->refcount); |
| 4311 | |
Daniel Stone | e2f5d2e | 2015-05-22 13:34:51 +0100 | [diff] [blame] | 4312 | list_add_tail(&blob->head_global, |
| 4313 | &dev->mode_config.property_blob_list); |
Daniel Stone | 8fb6e7a | 2015-04-20 19:22:54 +0100 | [diff] [blame] | 4314 | |
| 4315 | mutex_unlock(&dev->mode_config.blob_lock); |
| 4316 | |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 4317 | return blob; |
| 4318 | } |
Daniel Stone | 6bcacf5 | 2015-04-20 19:22:55 +0100 | [diff] [blame] | 4319 | EXPORT_SYMBOL(drm_property_create_blob); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 4320 | |
Daniel Stone | 6bcacf5 | 2015-04-20 19:22:55 +0100 | [diff] [blame] | 4321 | /** |
| 4322 | * drm_property_free_blob - Blob property destructor |
| 4323 | * |
| 4324 | * Internal free function for blob properties; must not be used directly. |
| 4325 | * |
Daniel Stone | f102c16 | 2015-05-22 13:34:44 +0100 | [diff] [blame] | 4326 | * @kref: Reference |
Daniel Stone | 6bcacf5 | 2015-04-20 19:22:55 +0100 | [diff] [blame] | 4327 | */ |
| 4328 | static void drm_property_free_blob(struct kref *kref) |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 4329 | { |
Daniel Stone | 6bcacf5 | 2015-04-20 19:22:55 +0100 | [diff] [blame] | 4330 | struct drm_property_blob *blob = |
| 4331 | container_of(kref, struct drm_property_blob, refcount); |
| 4332 | |
| 4333 | WARN_ON(!mutex_is_locked(&blob->dev->mode_config.blob_lock)); |
| 4334 | |
Daniel Stone | e2f5d2e | 2015-05-22 13:34:51 +0100 | [diff] [blame] | 4335 | list_del(&blob->head_global); |
| 4336 | list_del(&blob->head_file); |
Dave Airlie | 7c8f6d2 | 2016-04-15 15:10:32 +1000 | [diff] [blame] | 4337 | drm_mode_object_unregister(blob->dev, &blob->base); |
Daniel Stone | 8fb6e7a | 2015-04-20 19:22:54 +0100 | [diff] [blame] | 4338 | |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 4339 | kfree(blob); |
| 4340 | } |
| 4341 | |
Daniel Vetter | c8e32cc | 2014-03-10 21:33:02 +0100 | [diff] [blame] | 4342 | /** |
Daniel Stone | 6bcacf5 | 2015-04-20 19:22:55 +0100 | [diff] [blame] | 4343 | * drm_property_unreference_blob - Unreference a blob property |
| 4344 | * |
| 4345 | * Drop a reference on a blob property. May free the object. |
| 4346 | * |
Daniel Stone | f102c16 | 2015-05-22 13:34:44 +0100 | [diff] [blame] | 4347 | * @blob: Pointer to blob property |
Daniel Stone | 6bcacf5 | 2015-04-20 19:22:55 +0100 | [diff] [blame] | 4348 | */ |
| 4349 | void drm_property_unreference_blob(struct drm_property_blob *blob) |
| 4350 | { |
| 4351 | struct drm_device *dev; |
| 4352 | |
| 4353 | if (!blob) |
| 4354 | return; |
| 4355 | |
| 4356 | dev = blob->dev; |
| 4357 | |
| 4358 | DRM_DEBUG("%p: blob ID: %d (%d)\n", blob, blob->base.id, atomic_read(&blob->refcount.refcount)); |
| 4359 | |
| 4360 | if (kref_put_mutex(&blob->refcount, drm_property_free_blob, |
| 4361 | &dev->mode_config.blob_lock)) |
| 4362 | mutex_unlock(&dev->mode_config.blob_lock); |
| 4363 | else |
| 4364 | might_lock(&dev->mode_config.blob_lock); |
Daniel Stone | 6bcacf5 | 2015-04-20 19:22:55 +0100 | [diff] [blame] | 4365 | } |
| 4366 | EXPORT_SYMBOL(drm_property_unreference_blob); |
| 4367 | |
| 4368 | /** |
| 4369 | * drm_property_unreference_blob_locked - Unreference a blob property with blob_lock held |
| 4370 | * |
| 4371 | * Drop a reference on a blob property. May free the object. This must be |
| 4372 | * called with blob_lock held. |
| 4373 | * |
Daniel Stone | f102c16 | 2015-05-22 13:34:44 +0100 | [diff] [blame] | 4374 | * @blob: Pointer to blob property |
Daniel Stone | 6bcacf5 | 2015-04-20 19:22:55 +0100 | [diff] [blame] | 4375 | */ |
| 4376 | static void drm_property_unreference_blob_locked(struct drm_property_blob *blob) |
| 4377 | { |
| 4378 | if (!blob) |
| 4379 | return; |
| 4380 | |
| 4381 | DRM_DEBUG("%p: blob ID: %d (%d)\n", blob, blob->base.id, atomic_read(&blob->refcount.refcount)); |
| 4382 | |
| 4383 | kref_put(&blob->refcount, drm_property_free_blob); |
| 4384 | } |
| 4385 | |
| 4386 | /** |
Daniel Stone | e2f5d2e | 2015-05-22 13:34:51 +0100 | [diff] [blame] | 4387 | * drm_property_destroy_user_blobs - destroy all blobs created by this client |
| 4388 | * @dev: DRM device |
| 4389 | * @file_priv: destroy all blobs owned by this file handle |
| 4390 | */ |
| 4391 | void drm_property_destroy_user_blobs(struct drm_device *dev, |
| 4392 | struct drm_file *file_priv) |
| 4393 | { |
| 4394 | struct drm_property_blob *blob, *bt; |
| 4395 | |
| 4396 | mutex_lock(&dev->mode_config.blob_lock); |
| 4397 | |
| 4398 | list_for_each_entry_safe(blob, bt, &file_priv->blobs, head_file) { |
| 4399 | list_del_init(&blob->head_file); |
| 4400 | drm_property_unreference_blob_locked(blob); |
| 4401 | } |
| 4402 | |
| 4403 | mutex_unlock(&dev->mode_config.blob_lock); |
| 4404 | } |
| 4405 | |
| 4406 | /** |
Daniel Stone | 6bcacf5 | 2015-04-20 19:22:55 +0100 | [diff] [blame] | 4407 | * drm_property_reference_blob - Take a reference on an existing property |
| 4408 | * |
| 4409 | * Take a new reference on an existing blob property. |
| 4410 | * |
Daniel Stone | f102c16 | 2015-05-22 13:34:44 +0100 | [diff] [blame] | 4411 | * @blob: Pointer to blob property |
Daniel Stone | 6bcacf5 | 2015-04-20 19:22:55 +0100 | [diff] [blame] | 4412 | */ |
| 4413 | struct drm_property_blob *drm_property_reference_blob(struct drm_property_blob *blob) |
| 4414 | { |
| 4415 | DRM_DEBUG("%p: blob ID: %d (%d)\n", blob, blob->base.id, atomic_read(&blob->refcount.refcount)); |
| 4416 | kref_get(&blob->refcount); |
| 4417 | return blob; |
| 4418 | } |
| 4419 | EXPORT_SYMBOL(drm_property_reference_blob); |
| 4420 | |
| 4421 | /* |
| 4422 | * Like drm_property_lookup_blob, but does not return an additional reference. |
| 4423 | * Must be called with blob_lock held. |
| 4424 | */ |
| 4425 | static struct drm_property_blob *__drm_property_lookup_blob(struct drm_device *dev, |
| 4426 | uint32_t id) |
| 4427 | { |
| 4428 | struct drm_mode_object *obj = NULL; |
| 4429 | struct drm_property_blob *blob; |
| 4430 | |
| 4431 | WARN_ON(!mutex_is_locked(&dev->mode_config.blob_lock)); |
| 4432 | |
| 4433 | mutex_lock(&dev->mode_config.idr_mutex); |
| 4434 | obj = idr_find(&dev->mode_config.crtc_idr, id); |
| 4435 | if (!obj || (obj->type != DRM_MODE_OBJECT_BLOB) || (obj->id != id)) |
| 4436 | blob = NULL; |
| 4437 | else |
| 4438 | blob = obj_to_blob(obj); |
| 4439 | mutex_unlock(&dev->mode_config.idr_mutex); |
| 4440 | |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 4441 | return blob; |
| 4442 | } |
| 4443 | |
Daniel Stone | 6bcacf5 | 2015-04-20 19:22:55 +0100 | [diff] [blame] | 4444 | /** |
| 4445 | * drm_property_lookup_blob - look up a blob property and take a reference |
| 4446 | * @dev: drm device |
| 4447 | * @id: id of the blob property |
| 4448 | * |
| 4449 | * If successful, this takes an additional reference to the blob property. |
| 4450 | * callers need to make sure to eventually unreference the returned property |
| 4451 | * again, using @drm_property_unreference_blob. |
| 4452 | */ |
| 4453 | struct drm_property_blob *drm_property_lookup_blob(struct drm_device *dev, |
| 4454 | uint32_t id) |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 4455 | { |
Daniel Stone | 6bcacf5 | 2015-04-20 19:22:55 +0100 | [diff] [blame] | 4456 | struct drm_property_blob *blob; |
| 4457 | |
| 4458 | mutex_lock(&dev->mode_config.blob_lock); |
| 4459 | blob = __drm_property_lookup_blob(dev, id); |
| 4460 | if (blob) { |
| 4461 | if (!kref_get_unless_zero(&blob->refcount)) |
| 4462 | blob = NULL; |
| 4463 | } |
| 4464 | mutex_unlock(&dev->mode_config.blob_lock); |
| 4465 | |
| 4466 | return blob; |
| 4467 | } |
| 4468 | EXPORT_SYMBOL(drm_property_lookup_blob); |
| 4469 | |
| 4470 | /** |
Daniel Stone | d2ed343 | 2015-04-20 19:22:53 +0100 | [diff] [blame] | 4471 | * drm_property_replace_global_blob - atomically replace existing blob property |
| 4472 | * @dev: drm device |
| 4473 | * @replace: location of blob property pointer to be replaced |
| 4474 | * @length: length of data for new blob, or 0 for no data |
| 4475 | * @data: content for new blob, or NULL for no data |
| 4476 | * @obj_holds_id: optional object for property holding blob ID |
| 4477 | * @prop_holds_id: optional property holding blob ID |
| 4478 | * @return 0 on success or error on failure |
| 4479 | * |
| 4480 | * This function will atomically replace a global property in the blob list, |
| 4481 | * optionally updating a property which holds the ID of that property. It is |
| 4482 | * guaranteed to be atomic: no caller will be allowed to see intermediate |
| 4483 | * results, and either the entire operation will succeed and clean up the |
| 4484 | * previous property, or it will fail and the state will be unchanged. |
| 4485 | * |
| 4486 | * If length is 0 or data is NULL, no new blob will be created, and the holding |
| 4487 | * property, if specified, will be set to 0. |
| 4488 | * |
| 4489 | * Access to the replace pointer is assumed to be protected by the caller, e.g. |
| 4490 | * by holding the relevant modesetting object lock for its parent. |
| 4491 | * |
| 4492 | * For example, a drm_connector has a 'PATH' property, which contains the ID |
| 4493 | * of a blob property with the value of the MST path information. Calling this |
| 4494 | * function with replace pointing to the connector's path_blob_ptr, length and |
| 4495 | * data set for the new path information, obj_holds_id set to the connector's |
| 4496 | * base object, and prop_holds_id set to the path property name, will perform |
| 4497 | * a completely atomic update. The access to path_blob_ptr is protected by the |
| 4498 | * caller holding a lock on the connector. |
| 4499 | */ |
| 4500 | static int drm_property_replace_global_blob(struct drm_device *dev, |
| 4501 | struct drm_property_blob **replace, |
| 4502 | size_t length, |
| 4503 | const void *data, |
| 4504 | struct drm_mode_object *obj_holds_id, |
| 4505 | struct drm_property *prop_holds_id) |
| 4506 | { |
| 4507 | struct drm_property_blob *new_blob = NULL; |
| 4508 | struct drm_property_blob *old_blob = NULL; |
| 4509 | int ret; |
| 4510 | |
| 4511 | WARN_ON(replace == NULL); |
| 4512 | |
| 4513 | old_blob = *replace; |
| 4514 | |
| 4515 | if (length && data) { |
| 4516 | new_blob = drm_property_create_blob(dev, length, data); |
Daniel Stone | 10e8cb7 | 2015-05-22 13:34:50 +0100 | [diff] [blame] | 4517 | if (IS_ERR(new_blob)) |
| 4518 | return PTR_ERR(new_blob); |
Daniel Stone | d2ed343 | 2015-04-20 19:22:53 +0100 | [diff] [blame] | 4519 | } |
| 4520 | |
| 4521 | /* This does not need to be synchronised with blob_lock, as the |
| 4522 | * get_properties ioctl locks all modesetting objects, and |
| 4523 | * obj_holds_id must be locked before calling here, so we cannot |
| 4524 | * have its value out of sync with the list membership modified |
| 4525 | * below under blob_lock. */ |
| 4526 | if (obj_holds_id) { |
| 4527 | ret = drm_object_property_set_value(obj_holds_id, |
| 4528 | prop_holds_id, |
| 4529 | new_blob ? |
| 4530 | new_blob->base.id : 0); |
| 4531 | if (ret != 0) |
| 4532 | goto err_created; |
| 4533 | } |
| 4534 | |
Markus Elfring | ec53082 | 2015-07-05 21:55:10 +0200 | [diff] [blame] | 4535 | drm_property_unreference_blob(old_blob); |
Daniel Stone | d2ed343 | 2015-04-20 19:22:53 +0100 | [diff] [blame] | 4536 | *replace = new_blob; |
| 4537 | |
| 4538 | return 0; |
| 4539 | |
| 4540 | err_created: |
Daniel Stone | 6bcacf5 | 2015-04-20 19:22:55 +0100 | [diff] [blame] | 4541 | drm_property_unreference_blob(new_blob); |
Daniel Stone | d2ed343 | 2015-04-20 19:22:53 +0100 | [diff] [blame] | 4542 | return ret; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 4543 | } |
| 4544 | |
Daniel Vetter | c8e32cc | 2014-03-10 21:33:02 +0100 | [diff] [blame] | 4545 | /** |
| 4546 | * drm_mode_getblob_ioctl - get the contents of a blob property value |
| 4547 | * @dev: DRM device |
| 4548 | * @data: ioctl data |
| 4549 | * @file_priv: DRM file info |
| 4550 | * |
| 4551 | * This function retrieves the contents of a blob property. The value stored in |
| 4552 | * an object's blob property is just a normal modeset object id. |
| 4553 | * |
| 4554 | * Called by the user via ioctl. |
| 4555 | * |
| 4556 | * Returns: |
Daniel Vetter | 1a49863 | 2014-11-19 18:38:09 +0100 | [diff] [blame] | 4557 | * Zero on success, negative errno on failure. |
Daniel Vetter | c8e32cc | 2014-03-10 21:33:02 +0100 | [diff] [blame] | 4558 | */ |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 4559 | int drm_mode_getblob_ioctl(struct drm_device *dev, |
| 4560 | void *data, struct drm_file *file_priv) |
| 4561 | { |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 4562 | struct drm_mode_get_blob *out_resp = data; |
| 4563 | struct drm_property_blob *blob; |
| 4564 | int ret = 0; |
Ville Syrjälä | 81f6c7f | 2011-12-20 00:06:42 +0200 | [diff] [blame] | 4565 | void __user *blob_ptr; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 4566 | |
Dave Airlie | fb3b06c | 2011-02-08 13:55:21 +1000 | [diff] [blame] | 4567 | if (!drm_core_check_feature(dev, DRIVER_MODESET)) |
| 4568 | return -EINVAL; |
| 4569 | |
Daniel Vetter | 8484990 | 2012-12-02 00:28:11 +0100 | [diff] [blame] | 4570 | drm_modeset_lock_all(dev); |
Daniel Stone | 8fb6e7a | 2015-04-20 19:22:54 +0100 | [diff] [blame] | 4571 | mutex_lock(&dev->mode_config.blob_lock); |
Daniel Stone | 6bcacf5 | 2015-04-20 19:22:55 +0100 | [diff] [blame] | 4572 | blob = __drm_property_lookup_blob(dev, out_resp->blob_id); |
Rob Clark | a2b34e2 | 2013-10-05 16:36:52 -0400 | [diff] [blame] | 4573 | if (!blob) { |
Ville Syrjälä | f27657f | 2013-10-17 13:35:00 +0300 | [diff] [blame] | 4574 | ret = -ENOENT; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 4575 | goto done; |
| 4576 | } |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 4577 | |
| 4578 | if (out_resp->length == blob->length) { |
Ville Syrjälä | 81f6c7f | 2011-12-20 00:06:42 +0200 | [diff] [blame] | 4579 | blob_ptr = (void __user *)(unsigned long)out_resp->data; |
Thierry Reding | 4dfd909 | 2014-12-10 13:03:34 +0100 | [diff] [blame] | 4580 | if (copy_to_user(blob_ptr, blob->data, blob->length)) { |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 4581 | ret = -EFAULT; |
| 4582 | goto done; |
| 4583 | } |
| 4584 | } |
| 4585 | out_resp->length = blob->length; |
| 4586 | |
| 4587 | done: |
Daniel Stone | 8fb6e7a | 2015-04-20 19:22:54 +0100 | [diff] [blame] | 4588 | mutex_unlock(&dev->mode_config.blob_lock); |
Daniel Vetter | 8484990 | 2012-12-02 00:28:11 +0100 | [diff] [blame] | 4589 | drm_modeset_unlock_all(dev); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 4590 | return ret; |
| 4591 | } |
| 4592 | |
Dave Airlie | cc7096f | 2014-10-22 12:03:04 +1000 | [diff] [blame] | 4593 | /** |
Daniel Stone | e2f5d2e | 2015-05-22 13:34:51 +0100 | [diff] [blame] | 4594 | * drm_mode_createblob_ioctl - create a new blob property |
| 4595 | * @dev: DRM device |
| 4596 | * @data: ioctl data |
| 4597 | * @file_priv: DRM file info |
| 4598 | * |
| 4599 | * This function creates a new blob property with user-defined values. In order |
| 4600 | * to give us sensible validation and checking when creating, rather than at |
| 4601 | * every potential use, we also require a type to be provided upfront. |
| 4602 | * |
| 4603 | * Called by the user via ioctl. |
| 4604 | * |
| 4605 | * Returns: |
| 4606 | * Zero on success, negative errno on failure. |
| 4607 | */ |
| 4608 | int drm_mode_createblob_ioctl(struct drm_device *dev, |
| 4609 | void *data, struct drm_file *file_priv) |
| 4610 | { |
| 4611 | struct drm_mode_create_blob *out_resp = data; |
| 4612 | struct drm_property_blob *blob; |
| 4613 | void __user *blob_ptr; |
| 4614 | int ret = 0; |
| 4615 | |
| 4616 | if (!drm_core_check_feature(dev, DRIVER_MODESET)) |
| 4617 | return -EINVAL; |
| 4618 | |
| 4619 | blob = drm_property_create_blob(dev, out_resp->length, NULL); |
| 4620 | if (IS_ERR(blob)) |
| 4621 | return PTR_ERR(blob); |
| 4622 | |
| 4623 | blob_ptr = (void __user *)(unsigned long)out_resp->data; |
| 4624 | if (copy_from_user(blob->data, blob_ptr, out_resp->length)) { |
| 4625 | ret = -EFAULT; |
| 4626 | goto out_blob; |
| 4627 | } |
| 4628 | |
| 4629 | /* Dropping the lock between create_blob and our access here is safe |
| 4630 | * as only the same file_priv can remove the blob; at this point, it is |
| 4631 | * not associated with any file_priv. */ |
| 4632 | mutex_lock(&dev->mode_config.blob_lock); |
| 4633 | out_resp->blob_id = blob->base.id; |
Maneet Singh | 8731b26 | 2015-10-08 10:10:24 -0400 | [diff] [blame] | 4634 | list_add_tail(&blob->head_file, &file_priv->blobs); |
Daniel Stone | e2f5d2e | 2015-05-22 13:34:51 +0100 | [diff] [blame] | 4635 | mutex_unlock(&dev->mode_config.blob_lock); |
| 4636 | |
| 4637 | return 0; |
| 4638 | |
| 4639 | out_blob: |
| 4640 | drm_property_unreference_blob(blob); |
| 4641 | return ret; |
| 4642 | } |
| 4643 | |
| 4644 | /** |
| 4645 | * drm_mode_destroyblob_ioctl - destroy a user blob property |
| 4646 | * @dev: DRM device |
| 4647 | * @data: ioctl data |
| 4648 | * @file_priv: DRM file info |
| 4649 | * |
| 4650 | * Destroy an existing user-defined blob property. |
| 4651 | * |
| 4652 | * Called by the user via ioctl. |
| 4653 | * |
| 4654 | * Returns: |
| 4655 | * Zero on success, negative errno on failure. |
| 4656 | */ |
| 4657 | int drm_mode_destroyblob_ioctl(struct drm_device *dev, |
| 4658 | void *data, struct drm_file *file_priv) |
| 4659 | { |
| 4660 | struct drm_mode_destroy_blob *out_resp = data; |
| 4661 | struct drm_property_blob *blob = NULL, *bt; |
| 4662 | bool found = false; |
| 4663 | int ret = 0; |
| 4664 | |
| 4665 | if (!drm_core_check_feature(dev, DRIVER_MODESET)) |
| 4666 | return -EINVAL; |
| 4667 | |
| 4668 | mutex_lock(&dev->mode_config.blob_lock); |
| 4669 | blob = __drm_property_lookup_blob(dev, out_resp->blob_id); |
| 4670 | if (!blob) { |
| 4671 | ret = -ENOENT; |
| 4672 | goto err; |
| 4673 | } |
| 4674 | |
| 4675 | /* Ensure the property was actually created by this user. */ |
| 4676 | list_for_each_entry(bt, &file_priv->blobs, head_file) { |
| 4677 | if (bt == blob) { |
| 4678 | found = true; |
| 4679 | break; |
| 4680 | } |
| 4681 | } |
| 4682 | |
| 4683 | if (!found) { |
| 4684 | ret = -EPERM; |
| 4685 | goto err; |
| 4686 | } |
| 4687 | |
| 4688 | /* We must drop head_file here, because we may not be the last |
| 4689 | * reference on the blob. */ |
| 4690 | list_del_init(&blob->head_file); |
| 4691 | drm_property_unreference_blob_locked(blob); |
| 4692 | mutex_unlock(&dev->mode_config.blob_lock); |
| 4693 | |
| 4694 | return 0; |
| 4695 | |
| 4696 | err: |
| 4697 | mutex_unlock(&dev->mode_config.blob_lock); |
| 4698 | return ret; |
| 4699 | } |
| 4700 | |
| 4701 | /** |
Dave Airlie | cc7096f | 2014-10-22 12:03:04 +1000 | [diff] [blame] | 4702 | * drm_mode_connector_set_path_property - set tile property on connector |
| 4703 | * @connector: connector to set property on. |
Daniel Stone | d2ed343 | 2015-04-20 19:22:53 +0100 | [diff] [blame] | 4704 | * @path: path to use for property; must not be NULL. |
Dave Airlie | cc7096f | 2014-10-22 12:03:04 +1000 | [diff] [blame] | 4705 | * |
| 4706 | * This creates a property to expose to userspace to specify a |
| 4707 | * connector path. This is mainly used for DisplayPort MST where |
| 4708 | * connectors have a topology and we want to allow userspace to give |
| 4709 | * them more meaningful names. |
| 4710 | * |
| 4711 | * Returns: |
Daniel Vetter | 1a49863 | 2014-11-19 18:38:09 +0100 | [diff] [blame] | 4712 | * Zero on success, negative errno on failure. |
Dave Airlie | cc7096f | 2014-10-22 12:03:04 +1000 | [diff] [blame] | 4713 | */ |
Dave Airlie | 43aba7e | 2014-06-05 14:01:31 +1000 | [diff] [blame] | 4714 | int drm_mode_connector_set_path_property(struct drm_connector *connector, |
Thierry Reding | 12e6cec | 2014-05-13 11:38:36 +0200 | [diff] [blame] | 4715 | const char *path) |
Dave Airlie | 43aba7e | 2014-06-05 14:01:31 +1000 | [diff] [blame] | 4716 | { |
| 4717 | struct drm_device *dev = connector->dev; |
Thierry Reding | ecbbe59 | 2014-05-13 11:36:13 +0200 | [diff] [blame] | 4718 | int ret; |
Dave Airlie | 43aba7e | 2014-06-05 14:01:31 +1000 | [diff] [blame] | 4719 | |
Daniel Stone | d2ed343 | 2015-04-20 19:22:53 +0100 | [diff] [blame] | 4720 | ret = drm_property_replace_global_blob(dev, |
| 4721 | &connector->path_blob_ptr, |
| 4722 | strlen(path) + 1, |
| 4723 | path, |
| 4724 | &connector->base, |
| 4725 | dev->mode_config.path_property); |
Dave Airlie | 43aba7e | 2014-06-05 14:01:31 +1000 | [diff] [blame] | 4726 | return ret; |
| 4727 | } |
| 4728 | EXPORT_SYMBOL(drm_mode_connector_set_path_property); |
| 4729 | |
Daniel Vetter | c8e32cc | 2014-03-10 21:33:02 +0100 | [diff] [blame] | 4730 | /** |
Dave Airlie | 6f134d7 | 2014-10-20 16:30:50 +1000 | [diff] [blame] | 4731 | * drm_mode_connector_set_tile_property - set tile property on connector |
| 4732 | * @connector: connector to set property on. |
| 4733 | * |
| 4734 | * This looks up the tile information for a connector, and creates a |
| 4735 | * property for userspace to parse if it exists. The property is of |
| 4736 | * the form of 8 integers using ':' as a separator. |
| 4737 | * |
| 4738 | * Returns: |
| 4739 | * Zero on success, errno on failure. |
| 4740 | */ |
| 4741 | int drm_mode_connector_set_tile_property(struct drm_connector *connector) |
| 4742 | { |
| 4743 | struct drm_device *dev = connector->dev; |
Dave Airlie | 6f134d7 | 2014-10-20 16:30:50 +1000 | [diff] [blame] | 4744 | char tile[256]; |
Daniel Stone | d2ed343 | 2015-04-20 19:22:53 +0100 | [diff] [blame] | 4745 | int ret; |
Dave Airlie | 6f134d7 | 2014-10-20 16:30:50 +1000 | [diff] [blame] | 4746 | |
| 4747 | if (!connector->has_tile) { |
Daniel Stone | d2ed343 | 2015-04-20 19:22:53 +0100 | [diff] [blame] | 4748 | ret = drm_property_replace_global_blob(dev, |
| 4749 | &connector->tile_blob_ptr, |
| 4750 | 0, |
| 4751 | NULL, |
| 4752 | &connector->base, |
| 4753 | dev->mode_config.tile_property); |
Dave Airlie | 6f134d7 | 2014-10-20 16:30:50 +1000 | [diff] [blame] | 4754 | return ret; |
| 4755 | } |
| 4756 | |
| 4757 | snprintf(tile, 256, "%d:%d:%d:%d:%d:%d:%d:%d", |
| 4758 | connector->tile_group->id, connector->tile_is_single_monitor, |
| 4759 | connector->num_h_tile, connector->num_v_tile, |
| 4760 | connector->tile_h_loc, connector->tile_v_loc, |
| 4761 | connector->tile_h_size, connector->tile_v_size); |
Dave Airlie | 6f134d7 | 2014-10-20 16:30:50 +1000 | [diff] [blame] | 4762 | |
Daniel Stone | d2ed343 | 2015-04-20 19:22:53 +0100 | [diff] [blame] | 4763 | ret = drm_property_replace_global_blob(dev, |
| 4764 | &connector->tile_blob_ptr, |
| 4765 | strlen(tile) + 1, |
| 4766 | tile, |
| 4767 | &connector->base, |
| 4768 | dev->mode_config.tile_property); |
Dave Airlie | 6f134d7 | 2014-10-20 16:30:50 +1000 | [diff] [blame] | 4769 | return ret; |
| 4770 | } |
| 4771 | EXPORT_SYMBOL(drm_mode_connector_set_tile_property); |
| 4772 | |
| 4773 | /** |
Daniel Vetter | c8e32cc | 2014-03-10 21:33:02 +0100 | [diff] [blame] | 4774 | * drm_mode_connector_update_edid_property - update the edid property of a connector |
| 4775 | * @connector: drm connector |
| 4776 | * @edid: new value of the edid property |
| 4777 | * |
| 4778 | * This function creates a new blob modeset object and assigns its id to the |
| 4779 | * connector's edid property. |
| 4780 | * |
| 4781 | * Returns: |
Daniel Vetter | 1a49863 | 2014-11-19 18:38:09 +0100 | [diff] [blame] | 4782 | * Zero on success, negative errno on failure. |
Daniel Vetter | c8e32cc | 2014-03-10 21:33:02 +0100 | [diff] [blame] | 4783 | */ |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 4784 | int drm_mode_connector_update_edid_property(struct drm_connector *connector, |
Thierry Reding | 12e6cec | 2014-05-13 11:38:36 +0200 | [diff] [blame] | 4785 | const struct edid *edid) |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 4786 | { |
| 4787 | struct drm_device *dev = connector->dev; |
Daniel Stone | d2ed343 | 2015-04-20 19:22:53 +0100 | [diff] [blame] | 4788 | size_t size = 0; |
Thierry Reding | ecbbe59 | 2014-05-13 11:36:13 +0200 | [diff] [blame] | 4789 | int ret; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 4790 | |
Thomas Wood | 4cf2b28 | 2014-06-18 17:52:33 +0100 | [diff] [blame] | 4791 | /* ignore requests to set edid when overridden */ |
| 4792 | if (connector->override_edid) |
| 4793 | return 0; |
| 4794 | |
Daniel Stone | d2ed343 | 2015-04-20 19:22:53 +0100 | [diff] [blame] | 4795 | if (edid) |
Shixin Zeng | e24ff46 | 2015-07-03 08:46:50 +0200 | [diff] [blame] | 4796 | size = EDID_LENGTH * (1 + edid->extensions); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 4797 | |
Daniel Stone | d2ed343 | 2015-04-20 19:22:53 +0100 | [diff] [blame] | 4798 | ret = drm_property_replace_global_blob(dev, |
| 4799 | &connector->edid_blob_ptr, |
| 4800 | size, |
| 4801 | edid, |
| 4802 | &connector->base, |
| 4803 | dev->mode_config.edid_property); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 4804 | return ret; |
| 4805 | } |
| 4806 | EXPORT_SYMBOL(drm_mode_connector_update_edid_property); |
| 4807 | |
Rob Clark | 3843e71 | 2014-12-16 18:05:29 -0500 | [diff] [blame] | 4808 | /* Some properties could refer to dynamic refcnt'd objects, or things that |
| 4809 | * need special locking to handle lifetime issues (ie. to ensure the prop |
| 4810 | * value doesn't become invalid part way through the property update due to |
| 4811 | * race). The value returned by reference via 'obj' should be passed back |
| 4812 | * to drm_property_change_valid_put() after the property is set (and the |
| 4813 | * object to which the property is attached has a chance to take it's own |
| 4814 | * reference). |
| 4815 | */ |
Rob Clark | d34f20d | 2014-12-18 16:01:56 -0500 | [diff] [blame] | 4816 | bool drm_property_change_valid_get(struct drm_property *property, |
Rob Clark | 3843e71 | 2014-12-16 18:05:29 -0500 | [diff] [blame] | 4817 | uint64_t value, struct drm_mode_object **ref) |
Paulo Zanoni | 26a3481 | 2012-05-15 18:08:59 -0300 | [diff] [blame] | 4818 | { |
Thierry Reding | 2ca651d | 2014-12-10 13:03:39 +0100 | [diff] [blame] | 4819 | int i; |
| 4820 | |
Paulo Zanoni | 26a3481 | 2012-05-15 18:08:59 -0300 | [diff] [blame] | 4821 | if (property->flags & DRM_MODE_PROP_IMMUTABLE) |
| 4822 | return false; |
Rob Clark | 5ea22f2 | 2014-05-30 11:34:01 -0400 | [diff] [blame] | 4823 | |
Rob Clark | 3843e71 | 2014-12-16 18:05:29 -0500 | [diff] [blame] | 4824 | *ref = NULL; |
| 4825 | |
Rob Clark | 5ea22f2 | 2014-05-30 11:34:01 -0400 | [diff] [blame] | 4826 | if (drm_property_type_is(property, DRM_MODE_PROP_RANGE)) { |
Paulo Zanoni | 26a3481 | 2012-05-15 18:08:59 -0300 | [diff] [blame] | 4827 | if (value < property->values[0] || value > property->values[1]) |
| 4828 | return false; |
| 4829 | return true; |
Rob Clark | ebc44cf | 2012-09-12 22:22:31 -0500 | [diff] [blame] | 4830 | } else if (drm_property_type_is(property, DRM_MODE_PROP_SIGNED_RANGE)) { |
| 4831 | int64_t svalue = U642I64(value); |
Thierry Reding | 4dfd909 | 2014-12-10 13:03:34 +0100 | [diff] [blame] | 4832 | |
Rob Clark | ebc44cf | 2012-09-12 22:22:31 -0500 | [diff] [blame] | 4833 | if (svalue < U642I64(property->values[0]) || |
| 4834 | svalue > U642I64(property->values[1])) |
| 4835 | return false; |
| 4836 | return true; |
Rob Clark | 5ea22f2 | 2014-05-30 11:34:01 -0400 | [diff] [blame] | 4837 | } else if (drm_property_type_is(property, DRM_MODE_PROP_BITMASK)) { |
Ville Syrjälä | 592c20e | 2012-05-24 20:53:58 +0300 | [diff] [blame] | 4838 | uint64_t valid_mask = 0; |
Thierry Reding | 4dfd909 | 2014-12-10 13:03:34 +0100 | [diff] [blame] | 4839 | |
Rob Clark | 49e2754 | 2012-05-17 02:23:26 -0600 | [diff] [blame] | 4840 | for (i = 0; i < property->num_values; i++) |
| 4841 | valid_mask |= (1ULL << property->values[i]); |
| 4842 | return !(value & ~valid_mask); |
Rob Clark | 5ea22f2 | 2014-05-30 11:34:01 -0400 | [diff] [blame] | 4843 | } else if (drm_property_type_is(property, DRM_MODE_PROP_BLOB)) { |
Daniel Stone | 6bcacf5 | 2015-04-20 19:22:55 +0100 | [diff] [blame] | 4844 | struct drm_property_blob *blob; |
| 4845 | |
| 4846 | if (value == 0) |
| 4847 | return true; |
| 4848 | |
| 4849 | blob = drm_property_lookup_blob(property->dev, value); |
| 4850 | if (blob) { |
| 4851 | *ref = &blob->base; |
| 4852 | return true; |
| 4853 | } else { |
| 4854 | return false; |
| 4855 | } |
Rob Clark | 98f75de | 2014-05-30 11:37:03 -0400 | [diff] [blame] | 4856 | } else if (drm_property_type_is(property, DRM_MODE_PROP_OBJECT)) { |
Rob Clark | 98f75de | 2014-05-30 11:37:03 -0400 | [diff] [blame] | 4857 | /* a zero value for an object property translates to null: */ |
| 4858 | if (value == 0) |
| 4859 | return true; |
Rob Clark | 3843e71 | 2014-12-16 18:05:29 -0500 | [diff] [blame] | 4860 | |
Dave Airlie | 027b3f8b | 2016-04-15 15:10:42 +1000 | [diff] [blame] | 4861 | return _object_find(property->dev, value, property->values[0]) != NULL; |
Paulo Zanoni | 26a3481 | 2012-05-15 18:08:59 -0300 | [diff] [blame] | 4862 | } |
Thierry Reding | 2ca651d | 2014-12-10 13:03:39 +0100 | [diff] [blame] | 4863 | |
| 4864 | for (i = 0; i < property->num_values; i++) |
| 4865 | if (property->values[i] == value) |
| 4866 | return true; |
| 4867 | return false; |
Paulo Zanoni | 26a3481 | 2012-05-15 18:08:59 -0300 | [diff] [blame] | 4868 | } |
| 4869 | |
Rob Clark | d34f20d | 2014-12-18 16:01:56 -0500 | [diff] [blame] | 4870 | void drm_property_change_valid_put(struct drm_property *property, |
Rob Clark | 3843e71 | 2014-12-16 18:05:29 -0500 | [diff] [blame] | 4871 | struct drm_mode_object *ref) |
| 4872 | { |
| 4873 | if (!ref) |
| 4874 | return; |
| 4875 | |
| 4876 | if (drm_property_type_is(property, DRM_MODE_PROP_OBJECT)) { |
Dave Airlie | 027b3f8b | 2016-04-15 15:10:42 +1000 | [diff] [blame] | 4877 | drm_mode_object_unreference(ref); |
Daniel Stone | da9b2a3 | 2015-05-25 19:11:49 +0100 | [diff] [blame] | 4878 | } else if (drm_property_type_is(property, DRM_MODE_PROP_BLOB)) |
| 4879 | drm_property_unreference_blob(obj_to_blob(ref)); |
Rob Clark | 3843e71 | 2014-12-16 18:05:29 -0500 | [diff] [blame] | 4880 | } |
| 4881 | |
Daniel Vetter | c8e32cc | 2014-03-10 21:33:02 +0100 | [diff] [blame] | 4882 | /** |
| 4883 | * drm_mode_connector_property_set_ioctl - set the current value of a connector property |
| 4884 | * @dev: DRM device |
| 4885 | * @data: ioctl data |
| 4886 | * @file_priv: DRM file info |
| 4887 | * |
| 4888 | * This function sets the current value for a connectors's property. It also |
| 4889 | * calls into a driver's ->set_property callback to update the hardware state |
| 4890 | * |
| 4891 | * Called by the user via ioctl. |
| 4892 | * |
| 4893 | * Returns: |
Daniel Vetter | 1a49863 | 2014-11-19 18:38:09 +0100 | [diff] [blame] | 4894 | * Zero on success, negative errno on failure. |
Daniel Vetter | c8e32cc | 2014-03-10 21:33:02 +0100 | [diff] [blame] | 4895 | */ |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 4896 | int drm_mode_connector_property_set_ioctl(struct drm_device *dev, |
| 4897 | void *data, struct drm_file *file_priv) |
| 4898 | { |
Paulo Zanoni | 0057d8d | 2012-05-15 18:09:03 -0300 | [diff] [blame] | 4899 | struct drm_mode_connector_set_property *conn_set_prop = data; |
| 4900 | struct drm_mode_obj_set_property obj_set_prop = { |
| 4901 | .value = conn_set_prop->value, |
| 4902 | .prop_id = conn_set_prop->prop_id, |
| 4903 | .obj_id = conn_set_prop->connector_id, |
| 4904 | .obj_type = DRM_MODE_OBJECT_CONNECTOR |
| 4905 | }; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 4906 | |
Paulo Zanoni | 0057d8d | 2012-05-15 18:09:03 -0300 | [diff] [blame] | 4907 | /* It does all the locking and checking we need */ |
| 4908 | 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] | 4909 | } |
| 4910 | |
Paulo Zanoni | c543188 | 2012-05-15 18:09:02 -0300 | [diff] [blame] | 4911 | static int drm_mode_connector_set_obj_prop(struct drm_mode_object *obj, |
| 4912 | struct drm_property *property, |
| 4913 | uint64_t value) |
| 4914 | { |
| 4915 | int ret = -EINVAL; |
| 4916 | struct drm_connector *connector = obj_to_connector(obj); |
| 4917 | |
| 4918 | /* Do DPMS ourselves */ |
| 4919 | if (property == connector->dev->mode_config.dpms_property) { |
Daniel Vetter | 3558c11 | 2015-12-04 09:45:59 +0100 | [diff] [blame] | 4920 | ret = (*connector->funcs->dpms)(connector, (int)value); |
Paulo Zanoni | c543188 | 2012-05-15 18:09:02 -0300 | [diff] [blame] | 4921 | } else if (connector->funcs->set_property) |
| 4922 | ret = connector->funcs->set_property(connector, property, value); |
| 4923 | |
| 4924 | /* store the property value if successful */ |
| 4925 | if (!ret) |
Rob Clark | 5849556 | 2012-10-11 20:50:56 -0500 | [diff] [blame] | 4926 | drm_object_property_set_value(&connector->base, property, value); |
Paulo Zanoni | c543188 | 2012-05-15 18:09:02 -0300 | [diff] [blame] | 4927 | return ret; |
| 4928 | } |
| 4929 | |
Paulo Zanoni | bffd9de0 | 2012-05-15 18:09:05 -0300 | [diff] [blame] | 4930 | static int drm_mode_crtc_set_obj_prop(struct drm_mode_object *obj, |
| 4931 | struct drm_property *property, |
| 4932 | uint64_t value) |
| 4933 | { |
| 4934 | int ret = -EINVAL; |
| 4935 | struct drm_crtc *crtc = obj_to_crtc(obj); |
| 4936 | |
| 4937 | if (crtc->funcs->set_property) |
| 4938 | ret = crtc->funcs->set_property(crtc, property, value); |
| 4939 | if (!ret) |
| 4940 | drm_object_property_set_value(obj, property, value); |
| 4941 | |
| 4942 | return ret; |
| 4943 | } |
| 4944 | |
Thomas Wood | 3a5f87c | 2014-08-20 14:45:00 +0100 | [diff] [blame] | 4945 | /** |
| 4946 | * drm_mode_plane_set_obj_prop - set the value of a property |
| 4947 | * @plane: drm plane object to set property value for |
| 4948 | * @property: property to set |
| 4949 | * @value: value the property should be set to |
| 4950 | * |
| 4951 | * This functions sets a given property on a given plane object. This function |
| 4952 | * calls the driver's ->set_property callback and changes the software state of |
| 4953 | * the property if the callback succeeds. |
| 4954 | * |
| 4955 | * Returns: |
| 4956 | * Zero on success, error code on failure. |
| 4957 | */ |
| 4958 | int drm_mode_plane_set_obj_prop(struct drm_plane *plane, |
| 4959 | struct drm_property *property, |
| 4960 | uint64_t value) |
Rob Clark | 4d93914 | 2012-05-17 02:23:27 -0600 | [diff] [blame] | 4961 | { |
| 4962 | int ret = -EINVAL; |
Thomas Wood | 3a5f87c | 2014-08-20 14:45:00 +0100 | [diff] [blame] | 4963 | struct drm_mode_object *obj = &plane->base; |
Rob Clark | 4d93914 | 2012-05-17 02:23:27 -0600 | [diff] [blame] | 4964 | |
| 4965 | if (plane->funcs->set_property) |
| 4966 | ret = plane->funcs->set_property(plane, property, value); |
| 4967 | if (!ret) |
| 4968 | drm_object_property_set_value(obj, property, value); |
| 4969 | |
| 4970 | return ret; |
| 4971 | } |
Thomas Wood | 3a5f87c | 2014-08-20 14:45:00 +0100 | [diff] [blame] | 4972 | EXPORT_SYMBOL(drm_mode_plane_set_obj_prop); |
Rob Clark | 4d93914 | 2012-05-17 02:23:27 -0600 | [diff] [blame] | 4973 | |
Daniel Vetter | c8e32cc | 2014-03-10 21:33:02 +0100 | [diff] [blame] | 4974 | /** |
Daniel Vetter | 1a49863 | 2014-11-19 18:38:09 +0100 | [diff] [blame] | 4975 | * 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] | 4976 | * @dev: DRM device |
| 4977 | * @data: ioctl data |
| 4978 | * @file_priv: DRM file info |
| 4979 | * |
| 4980 | * This function retrieves the current value for an object's property. Compared |
| 4981 | * to the connector specific ioctl this one is extended to also work on crtc and |
| 4982 | * plane objects. |
| 4983 | * |
| 4984 | * Called by the user via ioctl. |
| 4985 | * |
| 4986 | * Returns: |
Daniel Vetter | 1a49863 | 2014-11-19 18:38:09 +0100 | [diff] [blame] | 4987 | * Zero on success, negative errno on failure. |
Daniel Vetter | c8e32cc | 2014-03-10 21:33:02 +0100 | [diff] [blame] | 4988 | */ |
Paulo Zanoni | c543188 | 2012-05-15 18:09:02 -0300 | [diff] [blame] | 4989 | int drm_mode_obj_get_properties_ioctl(struct drm_device *dev, void *data, |
| 4990 | struct drm_file *file_priv) |
| 4991 | { |
| 4992 | struct drm_mode_obj_get_properties *arg = data; |
| 4993 | struct drm_mode_object *obj; |
| 4994 | int ret = 0; |
Paulo Zanoni | c543188 | 2012-05-15 18:09:02 -0300 | [diff] [blame] | 4995 | |
| 4996 | if (!drm_core_check_feature(dev, DRIVER_MODESET)) |
| 4997 | return -EINVAL; |
| 4998 | |
Daniel Vetter | 8484990 | 2012-12-02 00:28:11 +0100 | [diff] [blame] | 4999 | drm_modeset_lock_all(dev); |
Paulo Zanoni | c543188 | 2012-05-15 18:09:02 -0300 | [diff] [blame] | 5000 | |
| 5001 | obj = drm_mode_object_find(dev, arg->obj_id, arg->obj_type); |
| 5002 | if (!obj) { |
Ville Syrjälä | f27657f | 2013-10-17 13:35:00 +0300 | [diff] [blame] | 5003 | ret = -ENOENT; |
Paulo Zanoni | c543188 | 2012-05-15 18:09:02 -0300 | [diff] [blame] | 5004 | goto out; |
| 5005 | } |
| 5006 | if (!obj->properties) { |
| 5007 | ret = -EINVAL; |
| 5008 | goto out; |
| 5009 | } |
| 5010 | |
Rob Clark | 88a48e2 | 2014-12-18 16:01:50 -0500 | [diff] [blame] | 5011 | ret = get_properties(obj, file_priv->atomic, |
Rob Clark | 95cbf11 | 2014-12-18 16:01:49 -0500 | [diff] [blame] | 5012 | (uint32_t __user *)(unsigned long)(arg->props_ptr), |
| 5013 | (uint64_t __user *)(unsigned long)(arg->prop_values_ptr), |
| 5014 | &arg->count_props); |
Paulo Zanoni | c543188 | 2012-05-15 18:09:02 -0300 | [diff] [blame] | 5015 | |
Paulo Zanoni | c543188 | 2012-05-15 18:09:02 -0300 | [diff] [blame] | 5016 | out: |
Daniel Vetter | 8484990 | 2012-12-02 00:28:11 +0100 | [diff] [blame] | 5017 | drm_modeset_unlock_all(dev); |
Paulo Zanoni | c543188 | 2012-05-15 18:09:02 -0300 | [diff] [blame] | 5018 | return ret; |
| 5019 | } |
| 5020 | |
Daniel Vetter | c8e32cc | 2014-03-10 21:33:02 +0100 | [diff] [blame] | 5021 | /** |
| 5022 | * drm_mode_obj_set_property_ioctl - set the current value of an object's property |
| 5023 | * @dev: DRM device |
| 5024 | * @data: ioctl data |
| 5025 | * @file_priv: DRM file info |
| 5026 | * |
| 5027 | * This function sets the current value for an object's property. It also calls |
| 5028 | * into a driver's ->set_property callback to update the hardware state. |
| 5029 | * Compared to the connector specific ioctl this one is extended to also work on |
| 5030 | * crtc and plane objects. |
| 5031 | * |
| 5032 | * Called by the user via ioctl. |
| 5033 | * |
| 5034 | * Returns: |
Daniel Vetter | 1a49863 | 2014-11-19 18:38:09 +0100 | [diff] [blame] | 5035 | * Zero on success, negative errno on failure. |
Daniel Vetter | c8e32cc | 2014-03-10 21:33:02 +0100 | [diff] [blame] | 5036 | */ |
Paulo Zanoni | c543188 | 2012-05-15 18:09:02 -0300 | [diff] [blame] | 5037 | int drm_mode_obj_set_property_ioctl(struct drm_device *dev, void *data, |
| 5038 | struct drm_file *file_priv) |
| 5039 | { |
| 5040 | struct drm_mode_obj_set_property *arg = data; |
| 5041 | struct drm_mode_object *arg_obj; |
| 5042 | struct drm_mode_object *prop_obj; |
| 5043 | struct drm_property *property; |
Rob Clark | 3843e71 | 2014-12-16 18:05:29 -0500 | [diff] [blame] | 5044 | int i, ret = -EINVAL; |
| 5045 | struct drm_mode_object *ref; |
Paulo Zanoni | c543188 | 2012-05-15 18:09:02 -0300 | [diff] [blame] | 5046 | |
| 5047 | if (!drm_core_check_feature(dev, DRIVER_MODESET)) |
| 5048 | return -EINVAL; |
| 5049 | |
Daniel Vetter | 8484990 | 2012-12-02 00:28:11 +0100 | [diff] [blame] | 5050 | drm_modeset_lock_all(dev); |
Paulo Zanoni | c543188 | 2012-05-15 18:09:02 -0300 | [diff] [blame] | 5051 | |
| 5052 | 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] | 5053 | if (!arg_obj) { |
| 5054 | ret = -ENOENT; |
Paulo Zanoni | c543188 | 2012-05-15 18:09:02 -0300 | [diff] [blame] | 5055 | goto out; |
Ville Syrjälä | f27657f | 2013-10-17 13:35:00 +0300 | [diff] [blame] | 5056 | } |
Paulo Zanoni | c543188 | 2012-05-15 18:09:02 -0300 | [diff] [blame] | 5057 | if (!arg_obj->properties) |
| 5058 | goto out; |
| 5059 | |
Paulo Zanoni | 7f88a9b | 2012-05-15 18:09:04 -0300 | [diff] [blame] | 5060 | for (i = 0; i < arg_obj->properties->count; i++) |
Rob Clark | b17cd75 | 2014-12-16 18:05:30 -0500 | [diff] [blame] | 5061 | if (arg_obj->properties->properties[i]->base.id == arg->prop_id) |
Paulo Zanoni | c543188 | 2012-05-15 18:09:02 -0300 | [diff] [blame] | 5062 | break; |
| 5063 | |
Paulo Zanoni | 7f88a9b | 2012-05-15 18:09:04 -0300 | [diff] [blame] | 5064 | if (i == arg_obj->properties->count) |
Paulo Zanoni | c543188 | 2012-05-15 18:09:02 -0300 | [diff] [blame] | 5065 | goto out; |
| 5066 | |
| 5067 | prop_obj = drm_mode_object_find(dev, arg->prop_id, |
| 5068 | DRM_MODE_OBJECT_PROPERTY); |
Ville Syrjälä | f27657f | 2013-10-17 13:35:00 +0300 | [diff] [blame] | 5069 | if (!prop_obj) { |
| 5070 | ret = -ENOENT; |
Paulo Zanoni | c543188 | 2012-05-15 18:09:02 -0300 | [diff] [blame] | 5071 | goto out; |
Ville Syrjälä | f27657f | 2013-10-17 13:35:00 +0300 | [diff] [blame] | 5072 | } |
Paulo Zanoni | c543188 | 2012-05-15 18:09:02 -0300 | [diff] [blame] | 5073 | property = obj_to_property(prop_obj); |
| 5074 | |
Rob Clark | 3843e71 | 2014-12-16 18:05:29 -0500 | [diff] [blame] | 5075 | if (!drm_property_change_valid_get(property, arg->value, &ref)) |
Paulo Zanoni | c543188 | 2012-05-15 18:09:02 -0300 | [diff] [blame] | 5076 | goto out; |
| 5077 | |
| 5078 | switch (arg_obj->type) { |
| 5079 | case DRM_MODE_OBJECT_CONNECTOR: |
| 5080 | ret = drm_mode_connector_set_obj_prop(arg_obj, property, |
| 5081 | arg->value); |
| 5082 | break; |
Paulo Zanoni | bffd9de0 | 2012-05-15 18:09:05 -0300 | [diff] [blame] | 5083 | case DRM_MODE_OBJECT_CRTC: |
| 5084 | ret = drm_mode_crtc_set_obj_prop(arg_obj, property, arg->value); |
| 5085 | break; |
Rob Clark | 4d93914 | 2012-05-17 02:23:27 -0600 | [diff] [blame] | 5086 | case DRM_MODE_OBJECT_PLANE: |
Thomas Wood | 3a5f87c | 2014-08-20 14:45:00 +0100 | [diff] [blame] | 5087 | ret = drm_mode_plane_set_obj_prop(obj_to_plane(arg_obj), |
| 5088 | property, arg->value); |
Rob Clark | 4d93914 | 2012-05-17 02:23:27 -0600 | [diff] [blame] | 5089 | break; |
Paulo Zanoni | c543188 | 2012-05-15 18:09:02 -0300 | [diff] [blame] | 5090 | } |
| 5091 | |
Rob Clark | 3843e71 | 2014-12-16 18:05:29 -0500 | [diff] [blame] | 5092 | drm_property_change_valid_put(property, ref); |
| 5093 | |
Paulo Zanoni | c543188 | 2012-05-15 18:09:02 -0300 | [diff] [blame] | 5094 | out: |
Daniel Vetter | 8484990 | 2012-12-02 00:28:11 +0100 | [diff] [blame] | 5095 | drm_modeset_unlock_all(dev); |
Paulo Zanoni | c543188 | 2012-05-15 18:09:02 -0300 | [diff] [blame] | 5096 | return ret; |
| 5097 | } |
| 5098 | |
Daniel Vetter | c8e32cc | 2014-03-10 21:33:02 +0100 | [diff] [blame] | 5099 | /** |
| 5100 | * drm_mode_connector_attach_encoder - attach a connector to an encoder |
| 5101 | * @connector: connector to attach |
| 5102 | * @encoder: encoder to attach @connector to |
| 5103 | * |
| 5104 | * This function links up a connector to an encoder. Note that the routing |
| 5105 | * restrictions between encoders and crtcs are exposed to userspace through the |
| 5106 | * possible_clones and possible_crtcs bitmasks. |
| 5107 | * |
| 5108 | * Returns: |
Daniel Vetter | 1a49863 | 2014-11-19 18:38:09 +0100 | [diff] [blame] | 5109 | * Zero on success, negative errno on failure. |
Daniel Vetter | c8e32cc | 2014-03-10 21:33:02 +0100 | [diff] [blame] | 5110 | */ |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 5111 | int drm_mode_connector_attach_encoder(struct drm_connector *connector, |
| 5112 | struct drm_encoder *encoder) |
| 5113 | { |
| 5114 | int i; |
| 5115 | |
Thierry Reding | eb47fe8 | 2015-11-16 18:19:53 +0100 | [diff] [blame] | 5116 | /* |
| 5117 | * In the past, drivers have attempted to model the static association |
| 5118 | * of connector to encoder in simple connector/encoder devices using a |
| 5119 | * direct assignment of connector->encoder = encoder. This connection |
| 5120 | * is a logical one and the responsibility of the core, so drivers are |
| 5121 | * expected not to mess with this. |
| 5122 | * |
| 5123 | * Note that the error return should've been enough here, but a large |
| 5124 | * majority of drivers ignores the return value, so add in a big WARN |
| 5125 | * to get people's attention. |
| 5126 | */ |
| 5127 | if (WARN_ON(connector->encoder)) |
| 5128 | return -EINVAL; |
| 5129 | |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 5130 | for (i = 0; i < DRM_CONNECTOR_MAX_ENCODER; i++) { |
| 5131 | if (connector->encoder_ids[i] == 0) { |
| 5132 | connector->encoder_ids[i] = encoder->base.id; |
| 5133 | return 0; |
| 5134 | } |
| 5135 | } |
| 5136 | return -ENOMEM; |
| 5137 | } |
| 5138 | EXPORT_SYMBOL(drm_mode_connector_attach_encoder); |
| 5139 | |
Daniel Vetter | c8e32cc | 2014-03-10 21:33:02 +0100 | [diff] [blame] | 5140 | /** |
| 5141 | * drm_mode_crtc_set_gamma_size - set the gamma table size |
| 5142 | * @crtc: CRTC to set the gamma table size for |
| 5143 | * @gamma_size: size of the gamma table |
| 5144 | * |
| 5145 | * Drivers which support gamma tables should set this to the supported gamma |
| 5146 | * table size when initializing the CRTC. Currently the drm core only supports a |
| 5147 | * fixed gamma table size. |
| 5148 | * |
| 5149 | * Returns: |
Daniel Vetter | 1a49863 | 2014-11-19 18:38:09 +0100 | [diff] [blame] | 5150 | * Zero on success, negative errno on failure. |
Daniel Vetter | c8e32cc | 2014-03-10 21:33:02 +0100 | [diff] [blame] | 5151 | */ |
Sascha Hauer | 4cae5b8 | 2012-02-01 11:38:23 +0100 | [diff] [blame] | 5152 | int drm_mode_crtc_set_gamma_size(struct drm_crtc *crtc, |
Daniel Vetter | c8e32cc | 2014-03-10 21:33:02 +0100 | [diff] [blame] | 5153 | int gamma_size) |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 5154 | { |
| 5155 | crtc->gamma_size = gamma_size; |
| 5156 | |
Thierry Reding | bd3f0ff | 2014-12-10 13:03:35 +0100 | [diff] [blame] | 5157 | crtc->gamma_store = kcalloc(gamma_size, sizeof(uint16_t) * 3, |
| 5158 | GFP_KERNEL); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 5159 | if (!crtc->gamma_store) { |
| 5160 | crtc->gamma_size = 0; |
Sascha Hauer | 4cae5b8 | 2012-02-01 11:38:23 +0100 | [diff] [blame] | 5161 | return -ENOMEM; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 5162 | } |
| 5163 | |
Sascha Hauer | 4cae5b8 | 2012-02-01 11:38:23 +0100 | [diff] [blame] | 5164 | return 0; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 5165 | } |
| 5166 | EXPORT_SYMBOL(drm_mode_crtc_set_gamma_size); |
| 5167 | |
Daniel Vetter | c8e32cc | 2014-03-10 21:33:02 +0100 | [diff] [blame] | 5168 | /** |
| 5169 | * drm_mode_gamma_set_ioctl - set the gamma table |
| 5170 | * @dev: DRM device |
| 5171 | * @data: ioctl data |
| 5172 | * @file_priv: DRM file info |
| 5173 | * |
| 5174 | * Set the gamma table of a CRTC to the one passed in by the user. Userspace can |
| 5175 | * inquire the required gamma table size through drm_mode_gamma_get_ioctl. |
| 5176 | * |
| 5177 | * Called by the user via ioctl. |
| 5178 | * |
| 5179 | * Returns: |
Daniel Vetter | 1a49863 | 2014-11-19 18:38:09 +0100 | [diff] [blame] | 5180 | * Zero on success, negative errno on failure. |
Daniel Vetter | c8e32cc | 2014-03-10 21:33:02 +0100 | [diff] [blame] | 5181 | */ |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 5182 | int drm_mode_gamma_set_ioctl(struct drm_device *dev, |
| 5183 | void *data, struct drm_file *file_priv) |
| 5184 | { |
| 5185 | struct drm_mode_crtc_lut *crtc_lut = data; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 5186 | struct drm_crtc *crtc; |
| 5187 | void *r_base, *g_base, *b_base; |
| 5188 | int size; |
| 5189 | int ret = 0; |
| 5190 | |
Dave Airlie | fb3b06c | 2011-02-08 13:55:21 +1000 | [diff] [blame] | 5191 | if (!drm_core_check_feature(dev, DRIVER_MODESET)) |
| 5192 | return -EINVAL; |
| 5193 | |
Daniel Vetter | 8484990 | 2012-12-02 00:28:11 +0100 | [diff] [blame] | 5194 | drm_modeset_lock_all(dev); |
Rob Clark | a2b34e2 | 2013-10-05 16:36:52 -0400 | [diff] [blame] | 5195 | crtc = drm_crtc_find(dev, crtc_lut->crtc_id); |
| 5196 | if (!crtc) { |
Ville Syrjälä | f27657f | 2013-10-17 13:35:00 +0300 | [diff] [blame] | 5197 | ret = -ENOENT; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 5198 | goto out; |
| 5199 | } |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 5200 | |
Laurent Pinchart | ebe0f24 | 2012-05-17 13:27:24 +0200 | [diff] [blame] | 5201 | if (crtc->funcs->gamma_set == NULL) { |
| 5202 | ret = -ENOSYS; |
| 5203 | goto out; |
| 5204 | } |
| 5205 | |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 5206 | /* memcpy into gamma store */ |
| 5207 | if (crtc_lut->gamma_size != crtc->gamma_size) { |
| 5208 | ret = -EINVAL; |
| 5209 | goto out; |
| 5210 | } |
| 5211 | |
| 5212 | size = crtc_lut->gamma_size * (sizeof(uint16_t)); |
| 5213 | r_base = crtc->gamma_store; |
| 5214 | if (copy_from_user(r_base, (void __user *)(unsigned long)crtc_lut->red, size)) { |
| 5215 | ret = -EFAULT; |
| 5216 | goto out; |
| 5217 | } |
| 5218 | |
| 5219 | g_base = r_base + size; |
| 5220 | if (copy_from_user(g_base, (void __user *)(unsigned long)crtc_lut->green, size)) { |
| 5221 | ret = -EFAULT; |
| 5222 | goto out; |
| 5223 | } |
| 5224 | |
| 5225 | b_base = g_base + size; |
| 5226 | if (copy_from_user(b_base, (void __user *)(unsigned long)crtc_lut->blue, size)) { |
| 5227 | ret = -EFAULT; |
| 5228 | goto out; |
| 5229 | } |
| 5230 | |
James Simmons | 7203425 | 2010-08-03 01:33:19 +0100 | [diff] [blame] | 5231 | 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] | 5232 | |
| 5233 | out: |
Daniel Vetter | 8484990 | 2012-12-02 00:28:11 +0100 | [diff] [blame] | 5234 | drm_modeset_unlock_all(dev); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 5235 | return ret; |
| 5236 | |
| 5237 | } |
| 5238 | |
Daniel Vetter | c8e32cc | 2014-03-10 21:33:02 +0100 | [diff] [blame] | 5239 | /** |
| 5240 | * drm_mode_gamma_get_ioctl - get the gamma table |
| 5241 | * @dev: DRM device |
| 5242 | * @data: ioctl data |
| 5243 | * @file_priv: DRM file info |
| 5244 | * |
| 5245 | * Copy the current gamma table into the storage provided. This also provides |
| 5246 | * the gamma table size the driver expects, which can be used to size the |
| 5247 | * allocated storage. |
| 5248 | * |
| 5249 | * Called by the user via ioctl. |
| 5250 | * |
| 5251 | * Returns: |
Daniel Vetter | 1a49863 | 2014-11-19 18:38:09 +0100 | [diff] [blame] | 5252 | * Zero on success, negative errno on failure. |
Daniel Vetter | c8e32cc | 2014-03-10 21:33:02 +0100 | [diff] [blame] | 5253 | */ |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 5254 | int drm_mode_gamma_get_ioctl(struct drm_device *dev, |
| 5255 | void *data, struct drm_file *file_priv) |
| 5256 | { |
| 5257 | struct drm_mode_crtc_lut *crtc_lut = data; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 5258 | struct drm_crtc *crtc; |
| 5259 | void *r_base, *g_base, *b_base; |
| 5260 | int size; |
| 5261 | int ret = 0; |
| 5262 | |
Dave Airlie | fb3b06c | 2011-02-08 13:55:21 +1000 | [diff] [blame] | 5263 | if (!drm_core_check_feature(dev, DRIVER_MODESET)) |
| 5264 | return -EINVAL; |
| 5265 | |
Daniel Vetter | 8484990 | 2012-12-02 00:28:11 +0100 | [diff] [blame] | 5266 | drm_modeset_lock_all(dev); |
Rob Clark | a2b34e2 | 2013-10-05 16:36:52 -0400 | [diff] [blame] | 5267 | crtc = drm_crtc_find(dev, crtc_lut->crtc_id); |
| 5268 | if (!crtc) { |
Ville Syrjälä | f27657f | 2013-10-17 13:35:00 +0300 | [diff] [blame] | 5269 | ret = -ENOENT; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 5270 | goto out; |
| 5271 | } |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 5272 | |
| 5273 | /* memcpy into gamma store */ |
| 5274 | if (crtc_lut->gamma_size != crtc->gamma_size) { |
| 5275 | ret = -EINVAL; |
| 5276 | goto out; |
| 5277 | } |
| 5278 | |
| 5279 | size = crtc_lut->gamma_size * (sizeof(uint16_t)); |
| 5280 | r_base = crtc->gamma_store; |
| 5281 | if (copy_to_user((void __user *)(unsigned long)crtc_lut->red, r_base, size)) { |
| 5282 | ret = -EFAULT; |
| 5283 | goto out; |
| 5284 | } |
| 5285 | |
| 5286 | g_base = r_base + size; |
| 5287 | if (copy_to_user((void __user *)(unsigned long)crtc_lut->green, g_base, size)) { |
| 5288 | ret = -EFAULT; |
| 5289 | goto out; |
| 5290 | } |
| 5291 | |
| 5292 | b_base = g_base + size; |
| 5293 | if (copy_to_user((void __user *)(unsigned long)crtc_lut->blue, b_base, size)) { |
| 5294 | ret = -EFAULT; |
| 5295 | goto out; |
| 5296 | } |
| 5297 | out: |
Daniel Vetter | 8484990 | 2012-12-02 00:28:11 +0100 | [diff] [blame] | 5298 | drm_modeset_unlock_all(dev); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 5299 | return ret; |
| 5300 | } |
Kristian Høgsberg | d91d8a3 | 2009-11-17 12:43:55 -0500 | [diff] [blame] | 5301 | |
Daniel Vetter | c8e32cc | 2014-03-10 21:33:02 +0100 | [diff] [blame] | 5302 | /** |
| 5303 | * drm_mode_page_flip_ioctl - schedule an asynchronous fb update |
| 5304 | * @dev: DRM device |
| 5305 | * @data: ioctl data |
| 5306 | * @file_priv: DRM file info |
| 5307 | * |
| 5308 | * This schedules an asynchronous update on a given CRTC, called page flip. |
| 5309 | * Optionally a drm event is generated to signal the completion of the event. |
| 5310 | * Generic drivers cannot assume that a pageflip with changed framebuffer |
| 5311 | * properties (including driver specific metadata like tiling layout) will work, |
| 5312 | * but some drivers support e.g. pixel format changes through the pageflip |
| 5313 | * ioctl. |
| 5314 | * |
| 5315 | * Called by the user via ioctl. |
| 5316 | * |
| 5317 | * Returns: |
Daniel Vetter | 1a49863 | 2014-11-19 18:38:09 +0100 | [diff] [blame] | 5318 | * Zero on success, negative errno on failure. |
Daniel Vetter | c8e32cc | 2014-03-10 21:33:02 +0100 | [diff] [blame] | 5319 | */ |
Kristian Høgsberg | d91d8a3 | 2009-11-17 12:43:55 -0500 | [diff] [blame] | 5320 | int drm_mode_page_flip_ioctl(struct drm_device *dev, |
| 5321 | void *data, struct drm_file *file_priv) |
| 5322 | { |
| 5323 | struct drm_mode_crtc_page_flip *page_flip = data; |
Kristian Høgsberg | d91d8a3 | 2009-11-17 12:43:55 -0500 | [diff] [blame] | 5324 | struct drm_crtc *crtc; |
Daniel Vetter | 3d30a59 | 2014-07-27 13:42:42 +0200 | [diff] [blame] | 5325 | struct drm_framebuffer *fb = NULL; |
Kristian Høgsberg | d91d8a3 | 2009-11-17 12:43:55 -0500 | [diff] [blame] | 5326 | struct drm_pending_vblank_event *e = NULL; |
Kristian Høgsberg | d91d8a3 | 2009-11-17 12:43:55 -0500 | [diff] [blame] | 5327 | int ret = -EINVAL; |
| 5328 | |
| 5329 | if (page_flip->flags & ~DRM_MODE_PAGE_FLIP_FLAGS || |
| 5330 | page_flip->reserved != 0) |
| 5331 | return -EINVAL; |
| 5332 | |
Keith Packard | 62f2104 | 2013-07-22 18:50:00 -0700 | [diff] [blame] | 5333 | if ((page_flip->flags & DRM_MODE_PAGE_FLIP_ASYNC) && !dev->mode_config.async_page_flip) |
| 5334 | return -EINVAL; |
| 5335 | |
Rob Clark | a2b34e2 | 2013-10-05 16:36:52 -0400 | [diff] [blame] | 5336 | crtc = drm_crtc_find(dev, page_flip->crtc_id); |
| 5337 | if (!crtc) |
Ville Syrjälä | f27657f | 2013-10-17 13:35:00 +0300 | [diff] [blame] | 5338 | return -ENOENT; |
Kristian Høgsberg | d91d8a3 | 2009-11-17 12:43:55 -0500 | [diff] [blame] | 5339 | |
Daniel Vetter | 4d02e2d | 2014-11-11 10:12:00 +0100 | [diff] [blame] | 5340 | drm_modeset_lock_crtc(crtc, crtc->primary); |
Matt Roper | f4510a2 | 2014-04-01 15:22:40 -0700 | [diff] [blame] | 5341 | if (crtc->primary->fb == NULL) { |
Chris Wilson | 90c1efd | 2010-07-17 20:23:26 +0100 | [diff] [blame] | 5342 | /* The framebuffer is currently unbound, presumably |
| 5343 | * due to a hotplug event, that userspace has not |
| 5344 | * yet discovered. |
| 5345 | */ |
| 5346 | ret = -EBUSY; |
| 5347 | goto out; |
| 5348 | } |
| 5349 | |
Kristian Høgsberg | d91d8a3 | 2009-11-17 12:43:55 -0500 | [diff] [blame] | 5350 | if (crtc->funcs->page_flip == NULL) |
| 5351 | goto out; |
| 5352 | |
Daniel Vetter | 786b99e | 2012-12-02 21:53:40 +0100 | [diff] [blame] | 5353 | fb = drm_framebuffer_lookup(dev, page_flip->fb_id); |
Ville Syrjälä | 37c4e70 | 2013-10-17 13:35:01 +0300 | [diff] [blame] | 5354 | if (!fb) { |
| 5355 | ret = -ENOENT; |
Kristian Høgsberg | d91d8a3 | 2009-11-17 12:43:55 -0500 | [diff] [blame] | 5356 | goto out; |
Ville Syrjälä | 37c4e70 | 2013-10-17 13:35:01 +0300 | [diff] [blame] | 5357 | } |
Kristian Høgsberg | d91d8a3 | 2009-11-17 12:43:55 -0500 | [diff] [blame] | 5358 | |
Ville Syrjälä | 2afa701d | 2015-10-15 20:40:02 +0300 | [diff] [blame] | 5359 | if (crtc->state) { |
| 5360 | const struct drm_plane_state *state = crtc->primary->state; |
| 5361 | |
| 5362 | ret = check_src_coords(state->src_x, state->src_y, |
| 5363 | state->src_w, state->src_h, fb); |
| 5364 | } else { |
| 5365 | ret = drm_crtc_check_viewport(crtc, crtc->x, crtc->y, &crtc->mode, fb); |
| 5366 | } |
Damien Lespiau | c11e928 | 2013-09-25 16:45:30 +0100 | [diff] [blame] | 5367 | if (ret) |
Ville Syrjälä | 5f61bb4 | 2012-03-13 12:35:45 +0200 | [diff] [blame] | 5368 | goto out; |
Ville Syrjälä | 5f61bb4 | 2012-03-13 12:35:45 +0200 | [diff] [blame] | 5369 | |
Matt Roper | f4510a2 | 2014-04-01 15:22:40 -0700 | [diff] [blame] | 5370 | if (crtc->primary->fb->pixel_format != fb->pixel_format) { |
Laurent Pinchart | 909d9cd | 2013-04-22 01:38:46 +0200 | [diff] [blame] | 5371 | DRM_DEBUG_KMS("Page flip is not allowed to change frame buffer format.\n"); |
| 5372 | ret = -EINVAL; |
| 5373 | goto out; |
| 5374 | } |
| 5375 | |
Kristian Høgsberg | d91d8a3 | 2009-11-17 12:43:55 -0500 | [diff] [blame] | 5376 | if (page_flip->flags & DRM_MODE_PAGE_FLIP_EVENT) { |
Daniel Vetter | 2dd500f | 2016-01-11 22:40:56 +0100 | [diff] [blame] | 5377 | e = kzalloc(sizeof *e, GFP_KERNEL); |
| 5378 | if (!e) { |
| 5379 | ret = -ENOMEM; |
Kristian Høgsberg | d91d8a3 | 2009-11-17 12:43:55 -0500 | [diff] [blame] | 5380 | goto out; |
| 5381 | } |
Jesse Barnes | 7bd4d7b | 2009-11-19 10:50:22 -0800 | [diff] [blame] | 5382 | e->event.base.type = DRM_EVENT_FLIP_COMPLETE; |
Thierry Reding | f76511b | 2014-12-10 13:03:40 +0100 | [diff] [blame] | 5383 | e->event.base.length = sizeof(e->event); |
Kristian Høgsberg | d91d8a3 | 2009-11-17 12:43:55 -0500 | [diff] [blame] | 5384 | e->event.user_data = page_flip->user_data; |
Daniel Vetter | 2dd500f | 2016-01-11 22:40:56 +0100 | [diff] [blame] | 5385 | ret = drm_event_reserve_init(dev, file_priv, &e->base, &e->event.base); |
| 5386 | if (ret) { |
| 5387 | kfree(e); |
| 5388 | goto out; |
| 5389 | } |
Kristian Høgsberg | d91d8a3 | 2009-11-17 12:43:55 -0500 | [diff] [blame] | 5390 | } |
| 5391 | |
Daniel Vetter | 3d30a59 | 2014-07-27 13:42:42 +0200 | [diff] [blame] | 5392 | crtc->primary->old_fb = crtc->primary->fb; |
Keith Packard | ed8d197 | 2013-07-22 18:49:58 -0700 | [diff] [blame] | 5393 | ret = crtc->funcs->page_flip(crtc, fb, e, page_flip->flags); |
Kristian Høgsberg | d91d8a3 | 2009-11-17 12:43:55 -0500 | [diff] [blame] | 5394 | if (ret) { |
Daniel Vetter | 2dd500f | 2016-01-11 22:40:56 +0100 | [diff] [blame] | 5395 | if (page_flip->flags & DRM_MODE_PAGE_FLIP_EVENT) |
| 5396 | drm_event_cancel_free(dev, &e->base); |
Daniel Vetter | b0d1232 | 2012-12-11 01:07:12 +0100 | [diff] [blame] | 5397 | /* Keep the old fb, don't unref it. */ |
Daniel Vetter | 3d30a59 | 2014-07-27 13:42:42 +0200 | [diff] [blame] | 5398 | crtc->primary->old_fb = NULL; |
Daniel Vetter | b0d1232 | 2012-12-11 01:07:12 +0100 | [diff] [blame] | 5399 | } else { |
Daniel Vetter | 3cb43cc | 2015-07-07 08:43:03 +0200 | [diff] [blame] | 5400 | crtc->primary->fb = fb; |
Daniel Vetter | b0d1232 | 2012-12-11 01:07:12 +0100 | [diff] [blame] | 5401 | /* Unref only the old framebuffer. */ |
| 5402 | fb = NULL; |
Kristian Høgsberg | d91d8a3 | 2009-11-17 12:43:55 -0500 | [diff] [blame] | 5403 | } |
| 5404 | |
| 5405 | out: |
Daniel Vetter | b0d1232 | 2012-12-11 01:07:12 +0100 | [diff] [blame] | 5406 | if (fb) |
| 5407 | drm_framebuffer_unreference(fb); |
Daniel Vetter | 3d30a59 | 2014-07-27 13:42:42 +0200 | [diff] [blame] | 5408 | if (crtc->primary->old_fb) |
| 5409 | drm_framebuffer_unreference(crtc->primary->old_fb); |
| 5410 | crtc->primary->old_fb = NULL; |
Daniel Vetter | d059f65 | 2014-07-25 18:07:40 +0200 | [diff] [blame] | 5411 | drm_modeset_unlock_crtc(crtc); |
Daniel Vetter | b4d5e7d | 2012-12-11 16:59:31 +0100 | [diff] [blame] | 5412 | |
Kristian Høgsberg | d91d8a3 | 2009-11-17 12:43:55 -0500 | [diff] [blame] | 5413 | return ret; |
| 5414 | } |
Chris Wilson | eb03355 | 2011-01-24 15:11:08 +0000 | [diff] [blame] | 5415 | |
Daniel Vetter | c8e32cc | 2014-03-10 21:33:02 +0100 | [diff] [blame] | 5416 | /** |
| 5417 | * drm_mode_config_reset - call ->reset callbacks |
| 5418 | * @dev: drm device |
| 5419 | * |
| 5420 | * This functions calls all the crtc's, encoder's and connector's ->reset |
| 5421 | * callback. Drivers can use this in e.g. their driver load or resume code to |
| 5422 | * reset hardware and software state. |
| 5423 | */ |
Chris Wilson | eb03355 | 2011-01-24 15:11:08 +0000 | [diff] [blame] | 5424 | void drm_mode_config_reset(struct drm_device *dev) |
| 5425 | { |
| 5426 | struct drm_crtc *crtc; |
Daniel Vetter | 2a0d7cf | 2014-07-29 15:32:37 +0200 | [diff] [blame] | 5427 | struct drm_plane *plane; |
Chris Wilson | eb03355 | 2011-01-24 15:11:08 +0000 | [diff] [blame] | 5428 | struct drm_encoder *encoder; |
| 5429 | struct drm_connector *connector; |
| 5430 | |
Daniel Vetter | e4f6254 | 2015-07-09 23:44:35 +0200 | [diff] [blame] | 5431 | drm_for_each_plane(plane, dev) |
Daniel Vetter | 2a0d7cf | 2014-07-29 15:32:37 +0200 | [diff] [blame] | 5432 | if (plane->funcs->reset) |
| 5433 | plane->funcs->reset(plane); |
| 5434 | |
Daniel Vetter | e4f6254 | 2015-07-09 23:44:35 +0200 | [diff] [blame] | 5435 | drm_for_each_crtc(crtc, dev) |
Chris Wilson | eb03355 | 2011-01-24 15:11:08 +0000 | [diff] [blame] | 5436 | if (crtc->funcs->reset) |
| 5437 | crtc->funcs->reset(crtc); |
| 5438 | |
Daniel Vetter | e4f6254 | 2015-07-09 23:44:35 +0200 | [diff] [blame] | 5439 | drm_for_each_encoder(encoder, dev) |
Chris Wilson | eb03355 | 2011-01-24 15:11:08 +0000 | [diff] [blame] | 5440 | if (encoder->funcs->reset) |
| 5441 | encoder->funcs->reset(encoder); |
| 5442 | |
Daniel Vetter | f8c2ba3 | 2015-07-29 08:32:43 +0200 | [diff] [blame] | 5443 | mutex_lock(&dev->mode_config.mutex); |
Dave Airlie | 4eebf60 | 2015-08-17 14:13:53 +1000 | [diff] [blame] | 5444 | drm_for_each_connector(connector, dev) |
Chris Wilson | eb03355 | 2011-01-24 15:11:08 +0000 | [diff] [blame] | 5445 | if (connector->funcs->reset) |
| 5446 | connector->funcs->reset(connector); |
Daniel Vetter | f8c2ba3 | 2015-07-29 08:32:43 +0200 | [diff] [blame] | 5447 | mutex_unlock(&dev->mode_config.mutex); |
Chris Wilson | eb03355 | 2011-01-24 15:11:08 +0000 | [diff] [blame] | 5448 | } |
| 5449 | EXPORT_SYMBOL(drm_mode_config_reset); |
Dave Airlie | ff72145b | 2011-02-07 12:16:14 +1000 | [diff] [blame] | 5450 | |
Daniel Vetter | c8e32cc | 2014-03-10 21:33:02 +0100 | [diff] [blame] | 5451 | /** |
| 5452 | * drm_mode_create_dumb_ioctl - create a dumb backing storage buffer |
| 5453 | * @dev: DRM device |
| 5454 | * @data: ioctl data |
| 5455 | * @file_priv: DRM file info |
| 5456 | * |
| 5457 | * This creates a new dumb buffer in the driver's backing storage manager (GEM, |
| 5458 | * TTM or something else entirely) and returns the resulting buffer handle. This |
| 5459 | * handle can then be wrapped up into a framebuffer modeset object. |
| 5460 | * |
| 5461 | * Note that userspace is not allowed to use such objects for render |
| 5462 | * acceleration - drivers must create their own private ioctls for such a use |
| 5463 | * case. |
| 5464 | * |
| 5465 | * Called by the user via ioctl. |
| 5466 | * |
| 5467 | * Returns: |
Daniel Vetter | 1a49863 | 2014-11-19 18:38:09 +0100 | [diff] [blame] | 5468 | * Zero on success, negative errno on failure. |
Daniel Vetter | c8e32cc | 2014-03-10 21:33:02 +0100 | [diff] [blame] | 5469 | */ |
Dave Airlie | ff72145b | 2011-02-07 12:16:14 +1000 | [diff] [blame] | 5470 | int drm_mode_create_dumb_ioctl(struct drm_device *dev, |
| 5471 | void *data, struct drm_file *file_priv) |
| 5472 | { |
| 5473 | struct drm_mode_create_dumb *args = data; |
David Herrmann | b28cd41 | 2014-01-20 20:09:55 +0100 | [diff] [blame] | 5474 | u32 cpp, stride, size; |
Dave Airlie | ff72145b | 2011-02-07 12:16:14 +1000 | [diff] [blame] | 5475 | |
| 5476 | if (!dev->driver->dumb_create) |
| 5477 | return -ENOSYS; |
David Herrmann | b28cd41 | 2014-01-20 20:09:55 +0100 | [diff] [blame] | 5478 | if (!args->width || !args->height || !args->bpp) |
| 5479 | return -EINVAL; |
| 5480 | |
| 5481 | /* overflow checks for 32bit size calculations */ |
David Herrmann | 00e7208 | 2014-08-24 19:23:26 +0200 | [diff] [blame] | 5482 | /* NOTE: DIV_ROUND_UP() can overflow */ |
David Herrmann | b28cd41 | 2014-01-20 20:09:55 +0100 | [diff] [blame] | 5483 | cpp = DIV_ROUND_UP(args->bpp, 8); |
David Herrmann | 00e7208 | 2014-08-24 19:23:26 +0200 | [diff] [blame] | 5484 | if (!cpp || cpp > 0xffffffffU / args->width) |
David Herrmann | b28cd41 | 2014-01-20 20:09:55 +0100 | [diff] [blame] | 5485 | return -EINVAL; |
| 5486 | stride = cpp * args->width; |
| 5487 | if (args->height > 0xffffffffU / stride) |
| 5488 | return -EINVAL; |
| 5489 | |
| 5490 | /* test for wrap-around */ |
| 5491 | size = args->height * stride; |
| 5492 | if (PAGE_ALIGN(size) == 0) |
| 5493 | return -EINVAL; |
| 5494 | |
Thierry Reding | f608595 | 2014-11-03 11:14:14 +0100 | [diff] [blame] | 5495 | /* |
| 5496 | * handle, pitch and size are output parameters. Zero them out to |
| 5497 | * prevent drivers from accidentally using uninitialized data. Since |
| 5498 | * not all existing userspace is clearing these fields properly we |
| 5499 | * cannot reject IOCTL with garbage in them. |
| 5500 | */ |
| 5501 | args->handle = 0; |
| 5502 | args->pitch = 0; |
| 5503 | args->size = 0; |
| 5504 | |
Dave Airlie | ff72145b | 2011-02-07 12:16:14 +1000 | [diff] [blame] | 5505 | return dev->driver->dumb_create(file_priv, dev, args); |
| 5506 | } |
| 5507 | |
Daniel Vetter | c8e32cc | 2014-03-10 21:33:02 +0100 | [diff] [blame] | 5508 | /** |
| 5509 | * drm_mode_mmap_dumb_ioctl - create an mmap offset for a dumb backing storage buffer |
| 5510 | * @dev: DRM device |
| 5511 | * @data: ioctl data |
| 5512 | * @file_priv: DRM file info |
| 5513 | * |
| 5514 | * Allocate an offset in the drm device node's address space to be able to |
| 5515 | * memory map a dumb buffer. |
| 5516 | * |
| 5517 | * Called by the user via ioctl. |
| 5518 | * |
| 5519 | * Returns: |
Daniel Vetter | 1a49863 | 2014-11-19 18:38:09 +0100 | [diff] [blame] | 5520 | * Zero on success, negative errno on failure. |
Daniel Vetter | c8e32cc | 2014-03-10 21:33:02 +0100 | [diff] [blame] | 5521 | */ |
Dave Airlie | ff72145b | 2011-02-07 12:16:14 +1000 | [diff] [blame] | 5522 | int drm_mode_mmap_dumb_ioctl(struct drm_device *dev, |
| 5523 | void *data, struct drm_file *file_priv) |
| 5524 | { |
| 5525 | struct drm_mode_map_dumb *args = data; |
| 5526 | |
| 5527 | /* call driver ioctl to get mmap offset */ |
| 5528 | if (!dev->driver->dumb_map_offset) |
| 5529 | return -ENOSYS; |
| 5530 | |
| 5531 | return dev->driver->dumb_map_offset(file_priv, dev, args->handle, &args->offset); |
| 5532 | } |
| 5533 | |
Daniel Vetter | c8e32cc | 2014-03-10 21:33:02 +0100 | [diff] [blame] | 5534 | /** |
| 5535 | * drm_mode_destroy_dumb_ioctl - destroy a dumb backing strage buffer |
| 5536 | * @dev: DRM device |
| 5537 | * @data: ioctl data |
| 5538 | * @file_priv: DRM file info |
| 5539 | * |
| 5540 | * This destroys the userspace handle for the given dumb backing storage buffer. |
| 5541 | * Since buffer objects must be reference counted in the kernel a buffer object |
| 5542 | * won't be immediately freed if a framebuffer modeset object still uses it. |
| 5543 | * |
| 5544 | * Called by the user via ioctl. |
| 5545 | * |
| 5546 | * Returns: |
Daniel Vetter | 1a49863 | 2014-11-19 18:38:09 +0100 | [diff] [blame] | 5547 | * Zero on success, negative errno on failure. |
Daniel Vetter | c8e32cc | 2014-03-10 21:33:02 +0100 | [diff] [blame] | 5548 | */ |
Dave Airlie | ff72145b | 2011-02-07 12:16:14 +1000 | [diff] [blame] | 5549 | int drm_mode_destroy_dumb_ioctl(struct drm_device *dev, |
| 5550 | void *data, struct drm_file *file_priv) |
| 5551 | { |
| 5552 | struct drm_mode_destroy_dumb *args = data; |
| 5553 | |
| 5554 | if (!dev->driver->dumb_destroy) |
| 5555 | return -ENOSYS; |
| 5556 | |
| 5557 | return dev->driver->dumb_destroy(file_priv, dev, args->handle); |
| 5558 | } |
Dave Airlie | 248dbc2 | 2011-11-29 20:02:54 +0000 | [diff] [blame] | 5559 | |
Daniel Vetter | c8e32cc | 2014-03-10 21:33:02 +0100 | [diff] [blame] | 5560 | /** |
| 5561 | * drm_fb_get_bpp_depth - get the bpp/depth values for format |
| 5562 | * @format: pixel format (DRM_FORMAT_*) |
| 5563 | * @depth: storage for the depth value |
| 5564 | * @bpp: storage for the bpp value |
| 5565 | * |
| 5566 | * This only supports RGB formats here for compat with code that doesn't use |
| 5567 | * pixel formats directly yet. |
Dave Airlie | 248dbc2 | 2011-11-29 20:02:54 +0000 | [diff] [blame] | 5568 | */ |
| 5569 | void drm_fb_get_bpp_depth(uint32_t format, unsigned int *depth, |
| 5570 | int *bpp) |
| 5571 | { |
| 5572 | switch (format) { |
Ville Syrjälä | c51a6bc | 2013-01-31 19:43:37 +0200 | [diff] [blame] | 5573 | case DRM_FORMAT_C8: |
Ville Syrjälä | 04b3924 | 2011-11-17 18:05:13 +0200 | [diff] [blame] | 5574 | case DRM_FORMAT_RGB332: |
| 5575 | case DRM_FORMAT_BGR233: |
Dave Airlie | 248dbc2 | 2011-11-29 20:02:54 +0000 | [diff] [blame] | 5576 | *depth = 8; |
| 5577 | *bpp = 8; |
| 5578 | break; |
Ville Syrjälä | 04b3924 | 2011-11-17 18:05:13 +0200 | [diff] [blame] | 5579 | case DRM_FORMAT_XRGB1555: |
| 5580 | case DRM_FORMAT_XBGR1555: |
| 5581 | case DRM_FORMAT_RGBX5551: |
| 5582 | case DRM_FORMAT_BGRX5551: |
| 5583 | case DRM_FORMAT_ARGB1555: |
| 5584 | case DRM_FORMAT_ABGR1555: |
| 5585 | case DRM_FORMAT_RGBA5551: |
| 5586 | case DRM_FORMAT_BGRA5551: |
Dave Airlie | 248dbc2 | 2011-11-29 20:02:54 +0000 | [diff] [blame] | 5587 | *depth = 15; |
| 5588 | *bpp = 16; |
| 5589 | break; |
Ville Syrjälä | 04b3924 | 2011-11-17 18:05:13 +0200 | [diff] [blame] | 5590 | case DRM_FORMAT_RGB565: |
| 5591 | case DRM_FORMAT_BGR565: |
Dave Airlie | 248dbc2 | 2011-11-29 20:02:54 +0000 | [diff] [blame] | 5592 | *depth = 16; |
| 5593 | *bpp = 16; |
| 5594 | break; |
Ville Syrjälä | 04b3924 | 2011-11-17 18:05:13 +0200 | [diff] [blame] | 5595 | case DRM_FORMAT_RGB888: |
| 5596 | case DRM_FORMAT_BGR888: |
| 5597 | *depth = 24; |
| 5598 | *bpp = 24; |
| 5599 | break; |
| 5600 | case DRM_FORMAT_XRGB8888: |
| 5601 | case DRM_FORMAT_XBGR8888: |
| 5602 | case DRM_FORMAT_RGBX8888: |
| 5603 | case DRM_FORMAT_BGRX8888: |
Dave Airlie | 248dbc2 | 2011-11-29 20:02:54 +0000 | [diff] [blame] | 5604 | *depth = 24; |
| 5605 | *bpp = 32; |
| 5606 | break; |
Ville Syrjälä | 04b3924 | 2011-11-17 18:05:13 +0200 | [diff] [blame] | 5607 | case DRM_FORMAT_XRGB2101010: |
| 5608 | case DRM_FORMAT_XBGR2101010: |
| 5609 | case DRM_FORMAT_RGBX1010102: |
| 5610 | case DRM_FORMAT_BGRX1010102: |
| 5611 | case DRM_FORMAT_ARGB2101010: |
| 5612 | case DRM_FORMAT_ABGR2101010: |
| 5613 | case DRM_FORMAT_RGBA1010102: |
| 5614 | case DRM_FORMAT_BGRA1010102: |
Dave Airlie | 248dbc2 | 2011-11-29 20:02:54 +0000 | [diff] [blame] | 5615 | *depth = 30; |
| 5616 | *bpp = 32; |
| 5617 | break; |
Ville Syrjälä | 04b3924 | 2011-11-17 18:05:13 +0200 | [diff] [blame] | 5618 | case DRM_FORMAT_ARGB8888: |
| 5619 | case DRM_FORMAT_ABGR8888: |
| 5620 | case DRM_FORMAT_RGBA8888: |
| 5621 | case DRM_FORMAT_BGRA8888: |
Dave Airlie | 248dbc2 | 2011-11-29 20:02:54 +0000 | [diff] [blame] | 5622 | *depth = 32; |
| 5623 | *bpp = 32; |
| 5624 | break; |
| 5625 | default: |
Ville Syrjälä | 23c453a | 2013-10-15 21:06:51 +0300 | [diff] [blame] | 5626 | DRM_DEBUG_KMS("unsupported pixel format %s\n", |
| 5627 | drm_get_format_name(format)); |
Dave Airlie | 248dbc2 | 2011-11-29 20:02:54 +0000 | [diff] [blame] | 5628 | *depth = 0; |
| 5629 | *bpp = 0; |
| 5630 | break; |
| 5631 | } |
| 5632 | } |
| 5633 | EXPORT_SYMBOL(drm_fb_get_bpp_depth); |
Ville Syrjälä | 141670e | 2012-04-05 21:35:15 +0300 | [diff] [blame] | 5634 | |
| 5635 | /** |
| 5636 | * drm_format_num_planes - get the number of planes for format |
| 5637 | * @format: pixel format (DRM_FORMAT_*) |
| 5638 | * |
Daniel Vetter | c8e32cc | 2014-03-10 21:33:02 +0100 | [diff] [blame] | 5639 | * Returns: |
Ville Syrjälä | 141670e | 2012-04-05 21:35:15 +0300 | [diff] [blame] | 5640 | * The number of planes used by the specified pixel format. |
| 5641 | */ |
| 5642 | int drm_format_num_planes(uint32_t format) |
| 5643 | { |
| 5644 | switch (format) { |
| 5645 | case DRM_FORMAT_YUV410: |
| 5646 | case DRM_FORMAT_YVU410: |
| 5647 | case DRM_FORMAT_YUV411: |
| 5648 | case DRM_FORMAT_YVU411: |
| 5649 | case DRM_FORMAT_YUV420: |
| 5650 | case DRM_FORMAT_YVU420: |
| 5651 | case DRM_FORMAT_YUV422: |
| 5652 | case DRM_FORMAT_YVU422: |
| 5653 | case DRM_FORMAT_YUV444: |
| 5654 | case DRM_FORMAT_YVU444: |
| 5655 | return 3; |
| 5656 | case DRM_FORMAT_NV12: |
| 5657 | case DRM_FORMAT_NV21: |
| 5658 | case DRM_FORMAT_NV16: |
| 5659 | case DRM_FORMAT_NV61: |
Laurent Pinchart | ba623f6 | 2012-05-18 23:47:40 +0200 | [diff] [blame] | 5660 | case DRM_FORMAT_NV24: |
| 5661 | case DRM_FORMAT_NV42: |
Ville Syrjälä | 141670e | 2012-04-05 21:35:15 +0300 | [diff] [blame] | 5662 | return 2; |
| 5663 | default: |
| 5664 | return 1; |
| 5665 | } |
| 5666 | } |
| 5667 | EXPORT_SYMBOL(drm_format_num_planes); |
Ville Syrjälä | 5a86bd5 | 2012-04-05 21:35:16 +0300 | [diff] [blame] | 5668 | |
| 5669 | /** |
| 5670 | * drm_format_plane_cpp - determine the bytes per pixel value |
| 5671 | * @format: pixel format (DRM_FORMAT_*) |
| 5672 | * @plane: plane index |
| 5673 | * |
Daniel Vetter | c8e32cc | 2014-03-10 21:33:02 +0100 | [diff] [blame] | 5674 | * Returns: |
Ville Syrjälä | 5a86bd5 | 2012-04-05 21:35:16 +0300 | [diff] [blame] | 5675 | * The bytes per pixel value for the specified plane. |
| 5676 | */ |
| 5677 | int drm_format_plane_cpp(uint32_t format, int plane) |
| 5678 | { |
| 5679 | unsigned int depth; |
| 5680 | int bpp; |
| 5681 | |
| 5682 | if (plane >= drm_format_num_planes(format)) |
| 5683 | return 0; |
| 5684 | |
| 5685 | switch (format) { |
| 5686 | case DRM_FORMAT_YUYV: |
| 5687 | case DRM_FORMAT_YVYU: |
| 5688 | case DRM_FORMAT_UYVY: |
| 5689 | case DRM_FORMAT_VYUY: |
| 5690 | return 2; |
| 5691 | case DRM_FORMAT_NV12: |
| 5692 | case DRM_FORMAT_NV21: |
| 5693 | case DRM_FORMAT_NV16: |
| 5694 | case DRM_FORMAT_NV61: |
Laurent Pinchart | ba623f6 | 2012-05-18 23:47:40 +0200 | [diff] [blame] | 5695 | case DRM_FORMAT_NV24: |
| 5696 | case DRM_FORMAT_NV42: |
Ville Syrjälä | 5a86bd5 | 2012-04-05 21:35:16 +0300 | [diff] [blame] | 5697 | return plane ? 2 : 1; |
| 5698 | case DRM_FORMAT_YUV410: |
| 5699 | case DRM_FORMAT_YVU410: |
| 5700 | case DRM_FORMAT_YUV411: |
| 5701 | case DRM_FORMAT_YVU411: |
| 5702 | case DRM_FORMAT_YUV420: |
| 5703 | case DRM_FORMAT_YVU420: |
| 5704 | case DRM_FORMAT_YUV422: |
| 5705 | case DRM_FORMAT_YVU422: |
| 5706 | case DRM_FORMAT_YUV444: |
| 5707 | case DRM_FORMAT_YVU444: |
| 5708 | return 1; |
| 5709 | default: |
| 5710 | drm_fb_get_bpp_depth(format, &depth, &bpp); |
| 5711 | return bpp >> 3; |
| 5712 | } |
| 5713 | } |
| 5714 | EXPORT_SYMBOL(drm_format_plane_cpp); |
Ville Syrjälä | 01b68b0 | 2012-04-05 21:35:17 +0300 | [diff] [blame] | 5715 | |
| 5716 | /** |
| 5717 | * drm_format_horz_chroma_subsampling - get the horizontal chroma subsampling factor |
| 5718 | * @format: pixel format (DRM_FORMAT_*) |
| 5719 | * |
Daniel Vetter | c8e32cc | 2014-03-10 21:33:02 +0100 | [diff] [blame] | 5720 | * Returns: |
Ville Syrjälä | 01b68b0 | 2012-04-05 21:35:17 +0300 | [diff] [blame] | 5721 | * The horizontal chroma subsampling factor for the |
| 5722 | * specified pixel format. |
| 5723 | */ |
| 5724 | int drm_format_horz_chroma_subsampling(uint32_t format) |
| 5725 | { |
| 5726 | switch (format) { |
| 5727 | case DRM_FORMAT_YUV411: |
| 5728 | case DRM_FORMAT_YVU411: |
| 5729 | case DRM_FORMAT_YUV410: |
| 5730 | case DRM_FORMAT_YVU410: |
| 5731 | return 4; |
| 5732 | case DRM_FORMAT_YUYV: |
| 5733 | case DRM_FORMAT_YVYU: |
| 5734 | case DRM_FORMAT_UYVY: |
| 5735 | case DRM_FORMAT_VYUY: |
| 5736 | case DRM_FORMAT_NV12: |
| 5737 | case DRM_FORMAT_NV21: |
| 5738 | case DRM_FORMAT_NV16: |
| 5739 | case DRM_FORMAT_NV61: |
| 5740 | case DRM_FORMAT_YUV422: |
| 5741 | case DRM_FORMAT_YVU422: |
| 5742 | case DRM_FORMAT_YUV420: |
| 5743 | case DRM_FORMAT_YVU420: |
| 5744 | return 2; |
| 5745 | default: |
| 5746 | return 1; |
| 5747 | } |
| 5748 | } |
| 5749 | EXPORT_SYMBOL(drm_format_horz_chroma_subsampling); |
| 5750 | |
| 5751 | /** |
| 5752 | * drm_format_vert_chroma_subsampling - get the vertical chroma subsampling factor |
| 5753 | * @format: pixel format (DRM_FORMAT_*) |
| 5754 | * |
Daniel Vetter | c8e32cc | 2014-03-10 21:33:02 +0100 | [diff] [blame] | 5755 | * Returns: |
Ville Syrjälä | 01b68b0 | 2012-04-05 21:35:17 +0300 | [diff] [blame] | 5756 | * The vertical chroma subsampling factor for the |
| 5757 | * specified pixel format. |
| 5758 | */ |
| 5759 | int drm_format_vert_chroma_subsampling(uint32_t format) |
| 5760 | { |
| 5761 | switch (format) { |
| 5762 | case DRM_FORMAT_YUV410: |
| 5763 | case DRM_FORMAT_YVU410: |
| 5764 | return 4; |
| 5765 | case DRM_FORMAT_YUV420: |
| 5766 | case DRM_FORMAT_YVU420: |
| 5767 | case DRM_FORMAT_NV12: |
| 5768 | case DRM_FORMAT_NV21: |
| 5769 | return 2; |
| 5770 | default: |
| 5771 | return 1; |
| 5772 | } |
| 5773 | } |
| 5774 | EXPORT_SYMBOL(drm_format_vert_chroma_subsampling); |
Laurent Pinchart | 87d24fc | 2013-04-15 15:37:16 +0200 | [diff] [blame] | 5775 | |
| 5776 | /** |
Ville Syrjälä | 4c61716 | 2016-02-09 17:29:44 +0200 | [diff] [blame] | 5777 | * drm_format_plane_width - width of the plane given the first plane |
| 5778 | * @width: width of the first plane |
| 5779 | * @format: pixel format |
| 5780 | * @plane: plane index |
| 5781 | * |
| 5782 | * Returns: |
| 5783 | * The width of @plane, given that the width of the first plane is @width. |
| 5784 | */ |
| 5785 | int drm_format_plane_width(int width, uint32_t format, int plane) |
| 5786 | { |
| 5787 | if (plane >= drm_format_num_planes(format)) |
| 5788 | return 0; |
| 5789 | |
| 5790 | if (plane == 0) |
| 5791 | return width; |
| 5792 | |
| 5793 | return width / drm_format_horz_chroma_subsampling(format); |
| 5794 | } |
| 5795 | EXPORT_SYMBOL(drm_format_plane_width); |
| 5796 | |
| 5797 | /** |
| 5798 | * drm_format_plane_height - height of the plane given the first plane |
| 5799 | * @height: height of the first plane |
| 5800 | * @format: pixel format |
| 5801 | * @plane: plane index |
| 5802 | * |
| 5803 | * Returns: |
| 5804 | * The height of @plane, given that the height of the first plane is @height. |
| 5805 | */ |
| 5806 | int drm_format_plane_height(int height, uint32_t format, int plane) |
| 5807 | { |
| 5808 | if (plane >= drm_format_num_planes(format)) |
| 5809 | return 0; |
| 5810 | |
| 5811 | if (plane == 0) |
| 5812 | return height; |
| 5813 | |
| 5814 | return height / drm_format_vert_chroma_subsampling(format); |
| 5815 | } |
| 5816 | EXPORT_SYMBOL(drm_format_plane_height); |
| 5817 | |
| 5818 | /** |
Ville Syrjälä | 3c9855f | 2014-07-08 10:31:56 +0530 | [diff] [blame] | 5819 | * drm_rotation_simplify() - Try to simplify the rotation |
| 5820 | * @rotation: Rotation to be simplified |
| 5821 | * @supported_rotations: Supported rotations |
| 5822 | * |
| 5823 | * Attempt to simplify the rotation to a form that is supported. |
| 5824 | * Eg. if the hardware supports everything except DRM_REFLECT_X |
| 5825 | * one could call this function like this: |
| 5826 | * |
| 5827 | * drm_rotation_simplify(rotation, BIT(DRM_ROTATE_0) | |
| 5828 | * BIT(DRM_ROTATE_90) | BIT(DRM_ROTATE_180) | |
| 5829 | * BIT(DRM_ROTATE_270) | BIT(DRM_REFLECT_Y)); |
| 5830 | * |
| 5831 | * to eliminate the DRM_ROTATE_X flag. Depending on what kind of |
| 5832 | * transforms the hardware supports, this function may not |
| 5833 | * be able to produce a supported transform, so the caller should |
| 5834 | * check the result afterwards. |
| 5835 | */ |
| 5836 | unsigned int drm_rotation_simplify(unsigned int rotation, |
| 5837 | unsigned int supported_rotations) |
| 5838 | { |
| 5839 | if (rotation & ~supported_rotations) { |
| 5840 | rotation ^= BIT(DRM_REFLECT_X) | BIT(DRM_REFLECT_Y); |
Joonas Lahtinen | 14152c8 | 2015-10-01 10:00:58 +0300 | [diff] [blame] | 5841 | rotation = (rotation & DRM_REFLECT_MASK) | |
| 5842 | BIT((ffs(rotation & DRM_ROTATE_MASK) + 1) % 4); |
Ville Syrjälä | 3c9855f | 2014-07-08 10:31:56 +0530 | [diff] [blame] | 5843 | } |
| 5844 | |
| 5845 | return rotation; |
| 5846 | } |
| 5847 | EXPORT_SYMBOL(drm_rotation_simplify); |
| 5848 | |
| 5849 | /** |
Laurent Pinchart | 87d24fc | 2013-04-15 15:37:16 +0200 | [diff] [blame] | 5850 | * drm_mode_config_init - initialize DRM mode_configuration structure |
| 5851 | * @dev: DRM device |
| 5852 | * |
| 5853 | * Initialize @dev's mode_config structure, used for tracking the graphics |
| 5854 | * configuration of @dev. |
| 5855 | * |
| 5856 | * Since this initializes the modeset locks, no locking is possible. Which is no |
| 5857 | * problem, since this should happen single threaded at init time. It is the |
| 5858 | * driver's problem to ensure this guarantee. |
| 5859 | * |
| 5860 | */ |
| 5861 | void drm_mode_config_init(struct drm_device *dev) |
| 5862 | { |
| 5863 | mutex_init(&dev->mode_config.mutex); |
Rob Clark | 51fd371 | 2013-11-19 12:10:12 -0500 | [diff] [blame] | 5864 | drm_modeset_lock_init(&dev->mode_config.connection_mutex); |
Laurent Pinchart | 87d24fc | 2013-04-15 15:37:16 +0200 | [diff] [blame] | 5865 | mutex_init(&dev->mode_config.idr_mutex); |
| 5866 | mutex_init(&dev->mode_config.fb_lock); |
Daniel Stone | 8fb6e7a | 2015-04-20 19:22:54 +0100 | [diff] [blame] | 5867 | mutex_init(&dev->mode_config.blob_lock); |
Laurent Pinchart | 87d24fc | 2013-04-15 15:37:16 +0200 | [diff] [blame] | 5868 | INIT_LIST_HEAD(&dev->mode_config.fb_list); |
| 5869 | INIT_LIST_HEAD(&dev->mode_config.crtc_list); |
| 5870 | INIT_LIST_HEAD(&dev->mode_config.connector_list); |
| 5871 | INIT_LIST_HEAD(&dev->mode_config.encoder_list); |
| 5872 | INIT_LIST_HEAD(&dev->mode_config.property_list); |
| 5873 | INIT_LIST_HEAD(&dev->mode_config.property_blob_list); |
| 5874 | INIT_LIST_HEAD(&dev->mode_config.plane_list); |
| 5875 | idr_init(&dev->mode_config.crtc_idr); |
Dave Airlie | 138f9eb | 2014-10-20 16:17:17 +1000 | [diff] [blame] | 5876 | idr_init(&dev->mode_config.tile_idr); |
Maarten Lankhorst | 5fff80b | 2016-02-17 08:32:05 +0100 | [diff] [blame] | 5877 | ida_init(&dev->mode_config.connector_ida); |
Laurent Pinchart | 87d24fc | 2013-04-15 15:37:16 +0200 | [diff] [blame] | 5878 | |
| 5879 | drm_modeset_lock_all(dev); |
Rob Clark | 6b4959f | 2014-12-18 16:01:53 -0500 | [diff] [blame] | 5880 | drm_mode_create_standard_properties(dev); |
Laurent Pinchart | 87d24fc | 2013-04-15 15:37:16 +0200 | [diff] [blame] | 5881 | drm_modeset_unlock_all(dev); |
| 5882 | |
| 5883 | /* Just to be sure */ |
| 5884 | dev->mode_config.num_fb = 0; |
| 5885 | dev->mode_config.num_connector = 0; |
| 5886 | dev->mode_config.num_crtc = 0; |
| 5887 | dev->mode_config.num_encoder = 0; |
Matt Roper | e27dde3 | 2014-04-01 15:22:30 -0700 | [diff] [blame] | 5888 | dev->mode_config.num_overlay_plane = 0; |
| 5889 | dev->mode_config.num_total_plane = 0; |
Laurent Pinchart | 87d24fc | 2013-04-15 15:37:16 +0200 | [diff] [blame] | 5890 | } |
| 5891 | EXPORT_SYMBOL(drm_mode_config_init); |
| 5892 | |
| 5893 | /** |
| 5894 | * drm_mode_config_cleanup - free up DRM mode_config info |
| 5895 | * @dev: DRM device |
| 5896 | * |
| 5897 | * Free up all the connectors and CRTCs associated with this DRM device, then |
| 5898 | * free up the framebuffers and associated buffer objects. |
| 5899 | * |
| 5900 | * Note that since this /should/ happen single-threaded at driver/device |
| 5901 | * teardown time, no locking is required. It's the driver's job to ensure that |
| 5902 | * this guarantee actually holds true. |
| 5903 | * |
| 5904 | * FIXME: cleanup any dangling user buffer objects too |
| 5905 | */ |
| 5906 | void drm_mode_config_cleanup(struct drm_device *dev) |
| 5907 | { |
| 5908 | struct drm_connector *connector, *ot; |
| 5909 | struct drm_crtc *crtc, *ct; |
| 5910 | struct drm_encoder *encoder, *enct; |
| 5911 | struct drm_framebuffer *fb, *fbt; |
| 5912 | struct drm_property *property, *pt; |
| 5913 | struct drm_property_blob *blob, *bt; |
| 5914 | struct drm_plane *plane, *plt; |
| 5915 | |
| 5916 | list_for_each_entry_safe(encoder, enct, &dev->mode_config.encoder_list, |
| 5917 | head) { |
| 5918 | encoder->funcs->destroy(encoder); |
| 5919 | } |
| 5920 | |
| 5921 | list_for_each_entry_safe(connector, ot, |
| 5922 | &dev->mode_config.connector_list, head) { |
| 5923 | connector->funcs->destroy(connector); |
| 5924 | } |
| 5925 | |
| 5926 | list_for_each_entry_safe(property, pt, &dev->mode_config.property_list, |
| 5927 | head) { |
| 5928 | drm_property_destroy(dev, property); |
| 5929 | } |
| 5930 | |
Maarten Lankhorst | f35034f | 2016-03-22 15:42:14 +0100 | [diff] [blame] | 5931 | list_for_each_entry_safe(plane, plt, &dev->mode_config.plane_list, |
| 5932 | head) { |
| 5933 | plane->funcs->destroy(plane); |
| 5934 | } |
| 5935 | |
| 5936 | list_for_each_entry_safe(crtc, ct, &dev->mode_config.crtc_list, head) { |
| 5937 | crtc->funcs->destroy(crtc); |
| 5938 | } |
| 5939 | |
Laurent Pinchart | 87d24fc | 2013-04-15 15:37:16 +0200 | [diff] [blame] | 5940 | list_for_each_entry_safe(blob, bt, &dev->mode_config.property_blob_list, |
Daniel Stone | e2f5d2e | 2015-05-22 13:34:51 +0100 | [diff] [blame] | 5941 | head_global) { |
Daniel Stone | 6bcacf5 | 2015-04-20 19:22:55 +0100 | [diff] [blame] | 5942 | drm_property_unreference_blob(blob); |
Laurent Pinchart | 87d24fc | 2013-04-15 15:37:16 +0200 | [diff] [blame] | 5943 | } |
| 5944 | |
| 5945 | /* |
| 5946 | * Single-threaded teardown context, so it's not required to grab the |
| 5947 | * fb_lock to protect against concurrent fb_list access. Contrary, it |
| 5948 | * would actually deadlock with the drm_framebuffer_cleanup function. |
| 5949 | * |
| 5950 | * Also, if there are any framebuffers left, that's a driver leak now, |
| 5951 | * so politely WARN about this. |
| 5952 | */ |
| 5953 | WARN_ON(!list_empty(&dev->mode_config.fb_list)); |
| 5954 | list_for_each_entry_safe(fb, fbt, &dev->mode_config.fb_list, head) { |
Dave Airlie | d0f37cf | 2016-04-15 15:10:36 +1000 | [diff] [blame] | 5955 | drm_framebuffer_free(&fb->base.refcount); |
Laurent Pinchart | 87d24fc | 2013-04-15 15:37:16 +0200 | [diff] [blame] | 5956 | } |
| 5957 | |
Maarten Lankhorst | 5fff80b | 2016-02-17 08:32:05 +0100 | [diff] [blame] | 5958 | ida_destroy(&dev->mode_config.connector_ida); |
Dave Airlie | 138f9eb | 2014-10-20 16:17:17 +1000 | [diff] [blame] | 5959 | idr_destroy(&dev->mode_config.tile_idr); |
Laurent Pinchart | 87d24fc | 2013-04-15 15:37:16 +0200 | [diff] [blame] | 5960 | idr_destroy(&dev->mode_config.crtc_idr); |
Rob Clark | 51fd371 | 2013-11-19 12:10:12 -0500 | [diff] [blame] | 5961 | drm_modeset_lock_fini(&dev->mode_config.connection_mutex); |
Laurent Pinchart | 87d24fc | 2013-04-15 15:37:16 +0200 | [diff] [blame] | 5962 | } |
| 5963 | EXPORT_SYMBOL(drm_mode_config_cleanup); |
Ville Syrjälä | c1df5f3 | 2014-07-08 10:31:53 +0530 | [diff] [blame] | 5964 | |
| 5965 | struct drm_property *drm_mode_create_rotation_property(struct drm_device *dev, |
| 5966 | unsigned int supported_rotations) |
| 5967 | { |
| 5968 | static const struct drm_prop_enum_list props[] = { |
| 5969 | { DRM_ROTATE_0, "rotate-0" }, |
| 5970 | { DRM_ROTATE_90, "rotate-90" }, |
| 5971 | { DRM_ROTATE_180, "rotate-180" }, |
| 5972 | { DRM_ROTATE_270, "rotate-270" }, |
| 5973 | { DRM_REFLECT_X, "reflect-x" }, |
| 5974 | { DRM_REFLECT_Y, "reflect-y" }, |
| 5975 | }; |
| 5976 | |
| 5977 | return drm_property_create_bitmask(dev, 0, "rotation", |
| 5978 | props, ARRAY_SIZE(props), |
| 5979 | supported_rotations); |
| 5980 | } |
| 5981 | EXPORT_SYMBOL(drm_mode_create_rotation_property); |
Dave Airlie | 138f9eb | 2014-10-20 16:17:17 +1000 | [diff] [blame] | 5982 | |
| 5983 | /** |
| 5984 | * DOC: Tile group |
| 5985 | * |
| 5986 | * Tile groups are used to represent tiled monitors with a unique |
| 5987 | * integer identifier. Tiled monitors using DisplayID v1.3 have |
| 5988 | * a unique 8-byte handle, we store this in a tile group, so we |
| 5989 | * have a common identifier for all tiles in a monitor group. |
| 5990 | */ |
| 5991 | static void drm_tile_group_free(struct kref *kref) |
| 5992 | { |
| 5993 | struct drm_tile_group *tg = container_of(kref, struct drm_tile_group, refcount); |
| 5994 | struct drm_device *dev = tg->dev; |
| 5995 | mutex_lock(&dev->mode_config.idr_mutex); |
| 5996 | idr_remove(&dev->mode_config.tile_idr, tg->id); |
| 5997 | mutex_unlock(&dev->mode_config.idr_mutex); |
| 5998 | kfree(tg); |
| 5999 | } |
| 6000 | |
| 6001 | /** |
| 6002 | * drm_mode_put_tile_group - drop a reference to a tile group. |
| 6003 | * @dev: DRM device |
| 6004 | * @tg: tile group to drop reference to. |
| 6005 | * |
| 6006 | * drop reference to tile group and free if 0. |
| 6007 | */ |
| 6008 | void drm_mode_put_tile_group(struct drm_device *dev, |
| 6009 | struct drm_tile_group *tg) |
| 6010 | { |
| 6011 | kref_put(&tg->refcount, drm_tile_group_free); |
| 6012 | } |
| 6013 | |
| 6014 | /** |
| 6015 | * drm_mode_get_tile_group - get a reference to an existing tile group |
| 6016 | * @dev: DRM device |
| 6017 | * @topology: 8-bytes unique per monitor. |
| 6018 | * |
| 6019 | * Use the unique bytes to get a reference to an existing tile group. |
| 6020 | * |
| 6021 | * RETURNS: |
| 6022 | * tile group or NULL if not found. |
| 6023 | */ |
| 6024 | struct drm_tile_group *drm_mode_get_tile_group(struct drm_device *dev, |
| 6025 | char topology[8]) |
| 6026 | { |
| 6027 | struct drm_tile_group *tg; |
| 6028 | int id; |
| 6029 | mutex_lock(&dev->mode_config.idr_mutex); |
| 6030 | idr_for_each_entry(&dev->mode_config.tile_idr, tg, id) { |
| 6031 | if (!memcmp(tg->group_data, topology, 8)) { |
| 6032 | if (!kref_get_unless_zero(&tg->refcount)) |
| 6033 | tg = NULL; |
| 6034 | mutex_unlock(&dev->mode_config.idr_mutex); |
| 6035 | return tg; |
| 6036 | } |
| 6037 | } |
| 6038 | mutex_unlock(&dev->mode_config.idr_mutex); |
| 6039 | return NULL; |
| 6040 | } |
Rob Clark | 81ddd1b | 2015-03-27 13:01:52 -0400 | [diff] [blame] | 6041 | EXPORT_SYMBOL(drm_mode_get_tile_group); |
Dave Airlie | 138f9eb | 2014-10-20 16:17:17 +1000 | [diff] [blame] | 6042 | |
| 6043 | /** |
| 6044 | * drm_mode_create_tile_group - create a tile group from a displayid description |
| 6045 | * @dev: DRM device |
| 6046 | * @topology: 8-bytes unique per monitor. |
| 6047 | * |
| 6048 | * Create a tile group for the unique monitor, and get a unique |
| 6049 | * identifier for the tile group. |
| 6050 | * |
| 6051 | * RETURNS: |
| 6052 | * new tile group or error. |
| 6053 | */ |
| 6054 | struct drm_tile_group *drm_mode_create_tile_group(struct drm_device *dev, |
| 6055 | char topology[8]) |
| 6056 | { |
| 6057 | struct drm_tile_group *tg; |
| 6058 | int ret; |
| 6059 | |
| 6060 | tg = kzalloc(sizeof(*tg), GFP_KERNEL); |
| 6061 | if (!tg) |
| 6062 | return ERR_PTR(-ENOMEM); |
| 6063 | |
| 6064 | kref_init(&tg->refcount); |
| 6065 | memcpy(tg->group_data, topology, 8); |
| 6066 | tg->dev = dev; |
| 6067 | |
| 6068 | mutex_lock(&dev->mode_config.idr_mutex); |
| 6069 | ret = idr_alloc(&dev->mode_config.tile_idr, tg, 1, 0, GFP_KERNEL); |
| 6070 | if (ret >= 0) { |
| 6071 | tg->id = ret; |
| 6072 | } else { |
| 6073 | kfree(tg); |
| 6074 | tg = ERR_PTR(ret); |
| 6075 | } |
| 6076 | |
| 6077 | mutex_unlock(&dev->mode_config.idr_mutex); |
| 6078 | return tg; |
| 6079 | } |
Rob Clark | 81ddd1b | 2015-03-27 13:01:52 -0400 | [diff] [blame] | 6080 | EXPORT_SYMBOL(drm_mode_create_tile_group); |