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 | */ |
| 32 | #include <linux/list.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 33 | #include <linux/slab.h> |
Paul Gortmaker | 2d1a8a4 | 2011-08-30 18:16:33 -0400 | [diff] [blame] | 34 | #include <linux/export.h> |
David Howells | 760285e | 2012-10-02 18:01:07 +0100 | [diff] [blame] | 35 | #include <drm/drmP.h> |
| 36 | #include <drm/drm_crtc.h> |
| 37 | #include <drm/drm_edid.h> |
| 38 | #include <drm/drm_fourcc.h> |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 39 | |
Daniel Vetter | 8484990 | 2012-12-02 00:28:11 +0100 | [diff] [blame] | 40 | /** |
| 41 | * drm_modeset_lock_all - take all modeset locks |
| 42 | * @dev: drm device |
| 43 | * |
| 44 | * This function takes all modeset locks, suitable where a more fine-grained |
| 45 | * scheme isn't (yet) implemented. |
| 46 | */ |
| 47 | void drm_modeset_lock_all(struct drm_device *dev) |
| 48 | { |
Daniel Vetter | 29494c1 | 2012-12-02 02:18:25 +0100 | [diff] [blame] | 49 | struct drm_crtc *crtc; |
| 50 | |
Daniel Vetter | 8484990 | 2012-12-02 00:28:11 +0100 | [diff] [blame] | 51 | mutex_lock(&dev->mode_config.mutex); |
Daniel Vetter | 29494c1 | 2012-12-02 02:18:25 +0100 | [diff] [blame] | 52 | |
| 53 | list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) |
| 54 | mutex_lock_nest_lock(&crtc->mutex, &dev->mode_config.mutex); |
Daniel Vetter | 8484990 | 2012-12-02 00:28:11 +0100 | [diff] [blame] | 55 | } |
| 56 | EXPORT_SYMBOL(drm_modeset_lock_all); |
| 57 | |
| 58 | /** |
| 59 | * drm_modeset_unlock_all - drop all modeset locks |
| 60 | * @dev: device |
| 61 | */ |
| 62 | void drm_modeset_unlock_all(struct drm_device *dev) |
| 63 | { |
Daniel Vetter | 29494c1 | 2012-12-02 02:18:25 +0100 | [diff] [blame] | 64 | struct drm_crtc *crtc; |
| 65 | |
| 66 | list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) |
| 67 | mutex_unlock(&crtc->mutex); |
| 68 | |
Daniel Vetter | 8484990 | 2012-12-02 00:28:11 +0100 | [diff] [blame] | 69 | mutex_unlock(&dev->mode_config.mutex); |
| 70 | } |
| 71 | EXPORT_SYMBOL(drm_modeset_unlock_all); |
| 72 | |
Daniel Vetter | 6aed8ec | 2013-01-20 17:32:21 +0100 | [diff] [blame] | 73 | /** |
| 74 | * drm_warn_on_modeset_not_all_locked - check that all modeset locks are locked |
| 75 | * @dev: device |
| 76 | */ |
| 77 | void drm_warn_on_modeset_not_all_locked(struct drm_device *dev) |
| 78 | { |
| 79 | struct drm_crtc *crtc; |
| 80 | |
| 81 | list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) |
| 82 | WARN_ON(!mutex_is_locked(&crtc->mutex)); |
| 83 | |
| 84 | WARN_ON(!mutex_is_locked(&dev->mode_config.mutex)); |
| 85 | } |
| 86 | EXPORT_SYMBOL(drm_warn_on_modeset_not_all_locked); |
| 87 | |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 88 | /* Avoid boilerplate. I'm tired of typing. */ |
| 89 | #define DRM_ENUM_NAME_FN(fnname, list) \ |
| 90 | char *fnname(int val) \ |
| 91 | { \ |
| 92 | int i; \ |
| 93 | for (i = 0; i < ARRAY_SIZE(list); i++) { \ |
| 94 | if (list[i].type == val) \ |
| 95 | return list[i].name; \ |
| 96 | } \ |
| 97 | return "(unknown)"; \ |
| 98 | } |
| 99 | |
| 100 | /* |
| 101 | * Global properties |
| 102 | */ |
| 103 | static struct drm_prop_enum_list drm_dpms_enum_list[] = |
| 104 | { { DRM_MODE_DPMS_ON, "On" }, |
| 105 | { DRM_MODE_DPMS_STANDBY, "Standby" }, |
| 106 | { DRM_MODE_DPMS_SUSPEND, "Suspend" }, |
| 107 | { DRM_MODE_DPMS_OFF, "Off" } |
| 108 | }; |
| 109 | |
| 110 | DRM_ENUM_NAME_FN(drm_get_dpms_name, drm_dpms_enum_list) |
| 111 | |
| 112 | /* |
| 113 | * Optional properties |
| 114 | */ |
| 115 | static struct drm_prop_enum_list drm_scaling_mode_enum_list[] = |
| 116 | { |
Jesse Barnes | 53bd838 | 2009-07-01 10:04:40 -0700 | [diff] [blame] | 117 | { DRM_MODE_SCALE_NONE, "None" }, |
| 118 | { DRM_MODE_SCALE_FULLSCREEN, "Full" }, |
| 119 | { DRM_MODE_SCALE_CENTER, "Center" }, |
| 120 | { DRM_MODE_SCALE_ASPECT, "Full aspect" }, |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 121 | }; |
| 122 | |
| 123 | static struct drm_prop_enum_list drm_dithering_mode_enum_list[] = |
| 124 | { |
| 125 | { DRM_MODE_DITHERING_OFF, "Off" }, |
| 126 | { DRM_MODE_DITHERING_ON, "On" }, |
Ben Skeggs | 92897b5 | 2010-07-16 15:09:17 +1000 | [diff] [blame] | 127 | { DRM_MODE_DITHERING_AUTO, "Automatic" }, |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 128 | }; |
| 129 | |
| 130 | /* |
| 131 | * Non-global properties, but "required" for certain connectors. |
| 132 | */ |
| 133 | static struct drm_prop_enum_list drm_dvi_i_select_enum_list[] = |
| 134 | { |
| 135 | { DRM_MODE_SUBCONNECTOR_Automatic, "Automatic" }, /* DVI-I and TV-out */ |
| 136 | { DRM_MODE_SUBCONNECTOR_DVID, "DVI-D" }, /* DVI-I */ |
| 137 | { DRM_MODE_SUBCONNECTOR_DVIA, "DVI-A" }, /* DVI-I */ |
| 138 | }; |
| 139 | |
| 140 | DRM_ENUM_NAME_FN(drm_get_dvi_i_select_name, drm_dvi_i_select_enum_list) |
| 141 | |
| 142 | static struct drm_prop_enum_list drm_dvi_i_subconnector_enum_list[] = |
| 143 | { |
| 144 | { DRM_MODE_SUBCONNECTOR_Unknown, "Unknown" }, /* DVI-I and TV-out */ |
| 145 | { DRM_MODE_SUBCONNECTOR_DVID, "DVI-D" }, /* DVI-I */ |
| 146 | { DRM_MODE_SUBCONNECTOR_DVIA, "DVI-A" }, /* DVI-I */ |
| 147 | }; |
| 148 | |
| 149 | DRM_ENUM_NAME_FN(drm_get_dvi_i_subconnector_name, |
| 150 | drm_dvi_i_subconnector_enum_list) |
| 151 | |
| 152 | static struct drm_prop_enum_list drm_tv_select_enum_list[] = |
| 153 | { |
| 154 | { DRM_MODE_SUBCONNECTOR_Automatic, "Automatic" }, /* DVI-I and TV-out */ |
| 155 | { DRM_MODE_SUBCONNECTOR_Composite, "Composite" }, /* TV-out */ |
| 156 | { DRM_MODE_SUBCONNECTOR_SVIDEO, "SVIDEO" }, /* TV-out */ |
| 157 | { DRM_MODE_SUBCONNECTOR_Component, "Component" }, /* TV-out */ |
Francisco Jerez | aeaa1ad | 2009-08-02 04:19:19 +0200 | [diff] [blame] | 158 | { DRM_MODE_SUBCONNECTOR_SCART, "SCART" }, /* TV-out */ |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 159 | }; |
| 160 | |
| 161 | DRM_ENUM_NAME_FN(drm_get_tv_select_name, drm_tv_select_enum_list) |
| 162 | |
| 163 | static struct drm_prop_enum_list drm_tv_subconnector_enum_list[] = |
| 164 | { |
| 165 | { DRM_MODE_SUBCONNECTOR_Unknown, "Unknown" }, /* DVI-I and TV-out */ |
| 166 | { DRM_MODE_SUBCONNECTOR_Composite, "Composite" }, /* TV-out */ |
| 167 | { DRM_MODE_SUBCONNECTOR_SVIDEO, "SVIDEO" }, /* TV-out */ |
| 168 | { DRM_MODE_SUBCONNECTOR_Component, "Component" }, /* TV-out */ |
Francisco Jerez | aeaa1ad | 2009-08-02 04:19:19 +0200 | [diff] [blame] | 169 | { DRM_MODE_SUBCONNECTOR_SCART, "SCART" }, /* TV-out */ |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 170 | }; |
| 171 | |
| 172 | DRM_ENUM_NAME_FN(drm_get_tv_subconnector_name, |
| 173 | drm_tv_subconnector_enum_list) |
| 174 | |
Jakob Bornecrantz | 884840a | 2009-12-03 23:25:47 +0000 | [diff] [blame] | 175 | static struct drm_prop_enum_list drm_dirty_info_enum_list[] = { |
| 176 | { DRM_MODE_DIRTY_OFF, "Off" }, |
| 177 | { DRM_MODE_DIRTY_ON, "On" }, |
| 178 | { DRM_MODE_DIRTY_ANNOTATE, "Annotate" }, |
| 179 | }; |
| 180 | |
| 181 | DRM_ENUM_NAME_FN(drm_get_dirty_info_name, |
| 182 | drm_dirty_info_enum_list) |
| 183 | |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 184 | struct drm_conn_prop_enum_list { |
| 185 | int type; |
| 186 | char *name; |
| 187 | int count; |
| 188 | }; |
| 189 | |
| 190 | /* |
| 191 | * Connector and encoder types. |
| 192 | */ |
| 193 | static struct drm_conn_prop_enum_list drm_connector_enum_list[] = |
| 194 | { { DRM_MODE_CONNECTOR_Unknown, "Unknown", 0 }, |
| 195 | { DRM_MODE_CONNECTOR_VGA, "VGA", 0 }, |
| 196 | { DRM_MODE_CONNECTOR_DVII, "DVI-I", 0 }, |
| 197 | { DRM_MODE_CONNECTOR_DVID, "DVI-D", 0 }, |
| 198 | { DRM_MODE_CONNECTOR_DVIA, "DVI-A", 0 }, |
| 199 | { DRM_MODE_CONNECTOR_Composite, "Composite", 0 }, |
| 200 | { DRM_MODE_CONNECTOR_SVIDEO, "SVIDEO", 0 }, |
| 201 | { DRM_MODE_CONNECTOR_LVDS, "LVDS", 0 }, |
| 202 | { DRM_MODE_CONNECTOR_Component, "Component", 0 }, |
Alex Deucher | e76116c | 2010-12-08 19:09:42 -0500 | [diff] [blame] | 203 | { DRM_MODE_CONNECTOR_9PinDIN, "DIN", 0 }, |
| 204 | { DRM_MODE_CONNECTOR_DisplayPort, "DP", 0 }, |
| 205 | { DRM_MODE_CONNECTOR_HDMIA, "HDMI-A", 0 }, |
| 206 | { DRM_MODE_CONNECTOR_HDMIB, "HDMI-B", 0 }, |
Francisco Jerez | 74bd3c2 | 2009-08-02 04:19:18 +0200 | [diff] [blame] | 207 | { DRM_MODE_CONNECTOR_TV, "TV", 0 }, |
Alex Deucher | e76116c | 2010-12-08 19:09:42 -0500 | [diff] [blame] | 208 | { DRM_MODE_CONNECTOR_eDP, "eDP", 0 }, |
Thomas Hellstrom | a7331e5 | 2011-10-22 10:36:19 +0200 | [diff] [blame] | 209 | { DRM_MODE_CONNECTOR_VIRTUAL, "Virtual", 0}, |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 210 | }; |
| 211 | |
| 212 | static struct drm_prop_enum_list drm_encoder_enum_list[] = |
| 213 | { { DRM_MODE_ENCODER_NONE, "None" }, |
| 214 | { DRM_MODE_ENCODER_DAC, "DAC" }, |
| 215 | { DRM_MODE_ENCODER_TMDS, "TMDS" }, |
| 216 | { DRM_MODE_ENCODER_LVDS, "LVDS" }, |
| 217 | { DRM_MODE_ENCODER_TVDAC, "TV" }, |
Thomas Hellstrom | a7331e5 | 2011-10-22 10:36:19 +0200 | [diff] [blame] | 218 | { DRM_MODE_ENCODER_VIRTUAL, "Virtual" }, |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 219 | }; |
| 220 | |
| 221 | char *drm_get_encoder_name(struct drm_encoder *encoder) |
| 222 | { |
| 223 | static char buf[32]; |
| 224 | |
| 225 | snprintf(buf, 32, "%s-%d", |
| 226 | drm_encoder_enum_list[encoder->encoder_type].name, |
| 227 | encoder->base.id); |
| 228 | return buf; |
| 229 | } |
Dave Airlie | 13a8195 | 2009-09-07 15:45:33 +1000 | [diff] [blame] | 230 | EXPORT_SYMBOL(drm_get_encoder_name); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 231 | |
| 232 | char *drm_get_connector_name(struct drm_connector *connector) |
| 233 | { |
| 234 | static char buf[32]; |
| 235 | |
| 236 | snprintf(buf, 32, "%s-%d", |
| 237 | drm_connector_enum_list[connector->connector_type].name, |
| 238 | connector->connector_type_id); |
| 239 | return buf; |
| 240 | } |
| 241 | EXPORT_SYMBOL(drm_get_connector_name); |
| 242 | |
| 243 | char *drm_get_connector_status_name(enum drm_connector_status status) |
| 244 | { |
| 245 | if (status == connector_status_connected) |
| 246 | return "connected"; |
| 247 | else if (status == connector_status_disconnected) |
| 248 | return "disconnected"; |
| 249 | else |
| 250 | return "unknown"; |
| 251 | } |
| 252 | |
| 253 | /** |
Daniel Vetter | 065a50ed | 2012-12-02 00:09:18 +0100 | [diff] [blame] | 254 | * drm_mode_object_get - allocate a new modeset identifier |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 255 | * @dev: DRM device |
Daniel Vetter | 065a50ed | 2012-12-02 00:09:18 +0100 | [diff] [blame] | 256 | * @obj: object pointer, used to generate unique ID |
| 257 | * @obj_type: object type |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 258 | * |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 259 | * Create a unique identifier based on @ptr in @dev's identifier space. Used |
| 260 | * for tracking modes, CRTCs and connectors. |
| 261 | * |
| 262 | * RETURNS: |
| 263 | * New unique (relative to other objects in @dev) integer identifier for the |
| 264 | * object. |
| 265 | */ |
| 266 | static int drm_mode_object_get(struct drm_device *dev, |
| 267 | struct drm_mode_object *obj, uint32_t obj_type) |
| 268 | { |
| 269 | int new_id = 0; |
| 270 | int ret; |
| 271 | |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 272 | again: |
| 273 | if (idr_pre_get(&dev->mode_config.crtc_idr, GFP_KERNEL) == 0) { |
| 274 | DRM_ERROR("Ran out memory getting a mode number\n"); |
Ville Syrjälä | f1ae126 | 2012-03-15 19:58:31 +0200 | [diff] [blame] | 275 | return -ENOMEM; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 276 | } |
| 277 | |
Jesse Barnes | ad2563c | 2009-01-19 17:21:45 +1000 | [diff] [blame] | 278 | mutex_lock(&dev->mode_config.idr_mutex); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 279 | ret = idr_get_new_above(&dev->mode_config.crtc_idr, obj, 1, &new_id); |
Daniel Vetter | 4b096ac | 2012-12-10 21:19:18 +0100 | [diff] [blame] | 280 | |
| 281 | if (!ret) { |
| 282 | /* |
| 283 | * Set up the object linking under the protection of the idr |
| 284 | * lock so that other users can't see inconsistent state. |
| 285 | */ |
| 286 | obj->id = new_id; |
| 287 | obj->type = obj_type; |
| 288 | } |
Jesse Barnes | ad2563c | 2009-01-19 17:21:45 +1000 | [diff] [blame] | 289 | mutex_unlock(&dev->mode_config.idr_mutex); |
Daniel Vetter | 4b096ac | 2012-12-10 21:19:18 +0100 | [diff] [blame] | 290 | |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 291 | if (ret == -EAGAIN) |
| 292 | goto again; |
| 293 | |
Daniel Vetter | 4b096ac | 2012-12-10 21:19:18 +0100 | [diff] [blame] | 294 | return ret; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 295 | } |
| 296 | |
| 297 | /** |
Daniel Vetter | 065a50ed | 2012-12-02 00:09:18 +0100 | [diff] [blame] | 298 | * drm_mode_object_put - free a modeset identifer |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 299 | * @dev: DRM device |
Daniel Vetter | 065a50ed | 2012-12-02 00:09:18 +0100 | [diff] [blame] | 300 | * @object: object to free |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 301 | * |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 302 | * Free @id from @dev's unique identifier pool. |
| 303 | */ |
| 304 | static void drm_mode_object_put(struct drm_device *dev, |
| 305 | struct drm_mode_object *object) |
| 306 | { |
Jesse Barnes | ad2563c | 2009-01-19 17:21:45 +1000 | [diff] [blame] | 307 | mutex_lock(&dev->mode_config.idr_mutex); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 308 | idr_remove(&dev->mode_config.crtc_idr, object->id); |
Jesse Barnes | ad2563c | 2009-01-19 17:21:45 +1000 | [diff] [blame] | 309 | mutex_unlock(&dev->mode_config.idr_mutex); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 310 | } |
| 311 | |
Daniel Vetter | 786b99e | 2012-12-02 21:53:40 +0100 | [diff] [blame] | 312 | /** |
| 313 | * drm_mode_object_find - look up a drm object with static lifetime |
| 314 | * @dev: drm device |
| 315 | * @id: id of the mode object |
| 316 | * @type: type of the mode object |
| 317 | * |
| 318 | * Note that framebuffers cannot be looked up with this functions - since those |
| 319 | * are reference counted, they need special treatment. |
| 320 | */ |
Daniel Vetter | 7a9c906 | 2009-09-15 22:57:31 +0200 | [diff] [blame] | 321 | struct drm_mode_object *drm_mode_object_find(struct drm_device *dev, |
| 322 | uint32_t id, uint32_t type) |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 323 | { |
Jesse Barnes | ad2563c | 2009-01-19 17:21:45 +1000 | [diff] [blame] | 324 | struct drm_mode_object *obj = NULL; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 325 | |
Daniel Vetter | 786b99e | 2012-12-02 21:53:40 +0100 | [diff] [blame] | 326 | /* Framebuffers are reference counted and need their own lookup |
| 327 | * function.*/ |
| 328 | WARN_ON(type == DRM_MODE_OBJECT_FB); |
| 329 | |
Jesse Barnes | ad2563c | 2009-01-19 17:21:45 +1000 | [diff] [blame] | 330 | mutex_lock(&dev->mode_config.idr_mutex); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 331 | obj = idr_find(&dev->mode_config.crtc_idr, id); |
| 332 | if (!obj || (obj->type != type) || (obj->id != id)) |
Jesse Barnes | ad2563c | 2009-01-19 17:21:45 +1000 | [diff] [blame] | 333 | obj = NULL; |
| 334 | mutex_unlock(&dev->mode_config.idr_mutex); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 335 | |
| 336 | return obj; |
| 337 | } |
| 338 | EXPORT_SYMBOL(drm_mode_object_find); |
| 339 | |
| 340 | /** |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 341 | * drm_framebuffer_init - initialize a framebuffer |
| 342 | * @dev: DRM device |
Daniel Vetter | 065a50ed | 2012-12-02 00:09:18 +0100 | [diff] [blame] | 343 | * @fb: framebuffer to be initialized |
| 344 | * @funcs: ... with these functions |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 345 | * |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 346 | * Allocates an ID for the framebuffer's parent mode object, sets its mode |
| 347 | * functions & device file and adds it to the master fd list. |
| 348 | * |
Daniel Vetter | 4b096ac | 2012-12-10 21:19:18 +0100 | [diff] [blame] | 349 | * IMPORTANT: |
| 350 | * This functions publishes the fb and makes it available for concurrent access |
| 351 | * by other users. Which means by this point the fb _must_ be fully set up - |
| 352 | * since all the fb attributes are invariant over its lifetime, no further |
| 353 | * locking but only correct reference counting is required. |
| 354 | * |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 355 | * RETURNS: |
André Goddard Rosa | af901ca | 2009-11-14 13:09:05 -0200 | [diff] [blame] | 356 | * Zero on success, error code on failure. |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 357 | */ |
| 358 | int drm_framebuffer_init(struct drm_device *dev, struct drm_framebuffer *fb, |
| 359 | const struct drm_framebuffer_funcs *funcs) |
| 360 | { |
| 361 | int ret; |
| 362 | |
Daniel Vetter | 4b096ac | 2012-12-10 21:19:18 +0100 | [diff] [blame] | 363 | mutex_lock(&dev->mode_config.fb_lock); |
Rob Clark | f7eff60 | 2012-09-05 21:48:38 +0000 | [diff] [blame] | 364 | kref_init(&fb->refcount); |
Daniel Vetter | 4b096ac | 2012-12-10 21:19:18 +0100 | [diff] [blame] | 365 | INIT_LIST_HEAD(&fb->filp_head); |
| 366 | fb->dev = dev; |
| 367 | fb->funcs = funcs; |
Rob Clark | f7eff60 | 2012-09-05 21:48:38 +0000 | [diff] [blame] | 368 | |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 369 | ret = drm_mode_object_get(dev, &fb->base, DRM_MODE_OBJECT_FB); |
Ville Syrjälä | 6bfc56a | 2012-03-13 12:35:48 +0200 | [diff] [blame] | 370 | if (ret) |
Daniel Vetter | 4b096ac | 2012-12-10 21:19:18 +0100 | [diff] [blame] | 371 | goto out; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 372 | |
Daniel Vetter | 2b677e8 | 2012-12-10 21:16:05 +0100 | [diff] [blame] | 373 | /* Grab the idr reference. */ |
| 374 | drm_framebuffer_reference(fb); |
| 375 | |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 376 | dev->mode_config.num_fb++; |
| 377 | list_add(&fb->head, &dev->mode_config.fb_list); |
Daniel Vetter | 4b096ac | 2012-12-10 21:19:18 +0100 | [diff] [blame] | 378 | out: |
| 379 | mutex_unlock(&dev->mode_config.fb_lock); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 380 | |
| 381 | return 0; |
| 382 | } |
| 383 | EXPORT_SYMBOL(drm_framebuffer_init); |
| 384 | |
Rob Clark | f7eff60 | 2012-09-05 21:48:38 +0000 | [diff] [blame] | 385 | static void drm_framebuffer_free(struct kref *kref) |
| 386 | { |
| 387 | struct drm_framebuffer *fb = |
| 388 | container_of(kref, struct drm_framebuffer, refcount); |
| 389 | fb->funcs->destroy(fb); |
| 390 | } |
| 391 | |
Daniel Vetter | 2b677e8 | 2012-12-10 21:16:05 +0100 | [diff] [blame] | 392 | static struct drm_framebuffer *__drm_framebuffer_lookup(struct drm_device *dev, |
| 393 | uint32_t id) |
| 394 | { |
| 395 | struct drm_mode_object *obj = NULL; |
| 396 | struct drm_framebuffer *fb; |
| 397 | |
| 398 | mutex_lock(&dev->mode_config.idr_mutex); |
| 399 | obj = idr_find(&dev->mode_config.crtc_idr, id); |
| 400 | if (!obj || (obj->type != DRM_MODE_OBJECT_FB) || (obj->id != id)) |
| 401 | fb = NULL; |
| 402 | else |
| 403 | fb = obj_to_fb(obj); |
| 404 | mutex_unlock(&dev->mode_config.idr_mutex); |
| 405 | |
| 406 | return fb; |
| 407 | } |
| 408 | |
Rob Clark | f7eff60 | 2012-09-05 21:48:38 +0000 | [diff] [blame] | 409 | /** |
Daniel Vetter | 786b99e | 2012-12-02 21:53:40 +0100 | [diff] [blame] | 410 | * drm_framebuffer_lookup - look up a drm framebuffer and grab a reference |
| 411 | * @dev: drm device |
| 412 | * @id: id of the fb object |
| 413 | * |
| 414 | * If successful, this grabs an additional reference to the framebuffer - |
| 415 | * callers need to make sure to eventually unreference the returned framebuffer |
| 416 | * again. |
| 417 | */ |
| 418 | struct drm_framebuffer *drm_framebuffer_lookup(struct drm_device *dev, |
| 419 | uint32_t id) |
| 420 | { |
Daniel Vetter | 786b99e | 2012-12-02 21:53:40 +0100 | [diff] [blame] | 421 | struct drm_framebuffer *fb; |
| 422 | |
| 423 | mutex_lock(&dev->mode_config.fb_lock); |
Daniel Vetter | 2b677e8 | 2012-12-10 21:16:05 +0100 | [diff] [blame] | 424 | fb = __drm_framebuffer_lookup(dev, id); |
Daniel Vetter | 786b99e | 2012-12-02 21:53:40 +0100 | [diff] [blame] | 425 | if (fb) |
| 426 | kref_get(&fb->refcount); |
Daniel Vetter | 786b99e | 2012-12-02 21:53:40 +0100 | [diff] [blame] | 427 | mutex_unlock(&dev->mode_config.fb_lock); |
| 428 | |
| 429 | return fb; |
| 430 | } |
| 431 | EXPORT_SYMBOL(drm_framebuffer_lookup); |
| 432 | |
| 433 | /** |
Rob Clark | f7eff60 | 2012-09-05 21:48:38 +0000 | [diff] [blame] | 434 | * drm_framebuffer_unreference - unref a framebuffer |
Daniel Vetter | 065a50ed | 2012-12-02 00:09:18 +0100 | [diff] [blame] | 435 | * @fb: framebuffer to unref |
| 436 | * |
| 437 | * This functions decrements the fb's refcount and frees it if it drops to zero. |
Rob Clark | f7eff60 | 2012-09-05 21:48:38 +0000 | [diff] [blame] | 438 | */ |
| 439 | void drm_framebuffer_unreference(struct drm_framebuffer *fb) |
| 440 | { |
Rob Clark | f7eff60 | 2012-09-05 21:48:38 +0000 | [diff] [blame] | 441 | DRM_DEBUG("FB ID: %d\n", fb->base.id); |
Rob Clark | f7eff60 | 2012-09-05 21:48:38 +0000 | [diff] [blame] | 442 | kref_put(&fb->refcount, drm_framebuffer_free); |
| 443 | } |
| 444 | EXPORT_SYMBOL(drm_framebuffer_unreference); |
| 445 | |
| 446 | /** |
| 447 | * drm_framebuffer_reference - incr the fb refcnt |
Daniel Vetter | 065a50ed | 2012-12-02 00:09:18 +0100 | [diff] [blame] | 448 | * @fb: framebuffer |
Rob Clark | f7eff60 | 2012-09-05 21:48:38 +0000 | [diff] [blame] | 449 | */ |
| 450 | void drm_framebuffer_reference(struct drm_framebuffer *fb) |
| 451 | { |
| 452 | DRM_DEBUG("FB ID: %d\n", fb->base.id); |
| 453 | kref_get(&fb->refcount); |
| 454 | } |
| 455 | EXPORT_SYMBOL(drm_framebuffer_reference); |
| 456 | |
Daniel Vetter | 2b677e8 | 2012-12-10 21:16:05 +0100 | [diff] [blame] | 457 | static void drm_framebuffer_free_bug(struct kref *kref) |
| 458 | { |
| 459 | BUG(); |
| 460 | } |
| 461 | |
Daniel Vetter | 6c2a753 | 2012-12-11 00:59:24 +0100 | [diff] [blame] | 462 | static void __drm_framebuffer_unreference(struct drm_framebuffer *fb) |
| 463 | { |
| 464 | DRM_DEBUG("FB ID: %d\n", fb->base.id); |
| 465 | kref_put(&fb->refcount, drm_framebuffer_free_bug); |
| 466 | } |
| 467 | |
Daniel Vetter | 2b677e8 | 2012-12-10 21:16:05 +0100 | [diff] [blame] | 468 | /* dev->mode_config.fb_lock must be held! */ |
| 469 | static void __drm_framebuffer_unregister(struct drm_device *dev, |
| 470 | struct drm_framebuffer *fb) |
| 471 | { |
| 472 | mutex_lock(&dev->mode_config.idr_mutex); |
| 473 | idr_remove(&dev->mode_config.crtc_idr, fb->base.id); |
| 474 | mutex_unlock(&dev->mode_config.idr_mutex); |
| 475 | |
| 476 | fb->base.id = 0; |
| 477 | |
Daniel Vetter | 6c2a753 | 2012-12-11 00:59:24 +0100 | [diff] [blame] | 478 | __drm_framebuffer_unreference(fb); |
Daniel Vetter | 2b677e8 | 2012-12-10 21:16:05 +0100 | [diff] [blame] | 479 | } |
| 480 | |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 481 | /** |
Daniel Vetter | 3620636 | 2012-12-10 20:42:17 +0100 | [diff] [blame] | 482 | * drm_framebuffer_unregister_private - unregister a private fb from the lookup idr |
| 483 | * @fb: fb to unregister |
| 484 | * |
| 485 | * Drivers need to call this when cleaning up driver-private framebuffers, e.g. |
| 486 | * those used for fbdev. Note that the caller must hold a reference of it's own, |
| 487 | * i.e. the object may not be destroyed through this call (since it'll lead to a |
| 488 | * locking inversion). |
| 489 | */ |
| 490 | void drm_framebuffer_unregister_private(struct drm_framebuffer *fb) |
| 491 | { |
Daniel Vetter | 2b677e8 | 2012-12-10 21:16:05 +0100 | [diff] [blame] | 492 | struct drm_device *dev = fb->dev; |
| 493 | |
| 494 | mutex_lock(&dev->mode_config.fb_lock); |
| 495 | /* Mark fb as reaped and drop idr ref. */ |
| 496 | __drm_framebuffer_unregister(dev, fb); |
| 497 | mutex_unlock(&dev->mode_config.fb_lock); |
Daniel Vetter | 3620636 | 2012-12-10 20:42:17 +0100 | [diff] [blame] | 498 | } |
| 499 | EXPORT_SYMBOL(drm_framebuffer_unregister_private); |
| 500 | |
| 501 | /** |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 502 | * drm_framebuffer_cleanup - remove a framebuffer object |
| 503 | * @fb: framebuffer to remove |
| 504 | * |
Daniel Vetter | 3620636 | 2012-12-10 20:42:17 +0100 | [diff] [blame] | 505 | * Cleanup references to a user-created framebuffer. This function is intended |
| 506 | * to be used from the drivers ->destroy callback. |
| 507 | * |
| 508 | * Note that this function does not remove the fb from active usuage - if it is |
| 509 | * still used anywhere, hilarity can ensue since userspace could call getfb on |
| 510 | * the id and get back -EINVAL. Obviously no concern at driver unload time. |
| 511 | * |
| 512 | * Also, the framebuffer will not be removed from the lookup idr - for |
| 513 | * user-created framebuffers this will happen in in the rmfb ioctl. For |
| 514 | * driver-private objects (e.g. for fbdev) drivers need to explicitly call |
| 515 | * drm_framebuffer_unregister_private. |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 516 | */ |
| 517 | void drm_framebuffer_cleanup(struct drm_framebuffer *fb) |
| 518 | { |
| 519 | struct drm_device *dev = fb->dev; |
Daniel Vetter | 8faf6b1 | 2012-12-01 23:43:11 +0100 | [diff] [blame] | 520 | |
Daniel Vetter | 4b096ac | 2012-12-10 21:19:18 +0100 | [diff] [blame] | 521 | mutex_lock(&dev->mode_config.fb_lock); |
Rob Clark | f7eff60 | 2012-09-05 21:48:38 +0000 | [diff] [blame] | 522 | list_del(&fb->head); |
| 523 | dev->mode_config.num_fb--; |
Daniel Vetter | 4b096ac | 2012-12-10 21:19:18 +0100 | [diff] [blame] | 524 | mutex_unlock(&dev->mode_config.fb_lock); |
Rob Clark | f7eff60 | 2012-09-05 21:48:38 +0000 | [diff] [blame] | 525 | } |
| 526 | EXPORT_SYMBOL(drm_framebuffer_cleanup); |
| 527 | |
| 528 | /** |
| 529 | * drm_framebuffer_remove - remove and unreference a framebuffer object |
| 530 | * @fb: framebuffer to remove |
| 531 | * |
Rob Clark | f7eff60 | 2012-09-05 21:48:38 +0000 | [diff] [blame] | 532 | * 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] | 533 | * 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] | 534 | * passed-in framebuffer. Might take the modeset locks. |
| 535 | * |
| 536 | * Note that this function optimizes the cleanup away if the caller holds the |
| 537 | * last reference to the framebuffer. It is also guaranteed to not take the |
| 538 | * modeset locks in this case. |
Rob Clark | f7eff60 | 2012-09-05 21:48:38 +0000 | [diff] [blame] | 539 | */ |
| 540 | void drm_framebuffer_remove(struct drm_framebuffer *fb) |
| 541 | { |
| 542 | struct drm_device *dev = fb->dev; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 543 | struct drm_crtc *crtc; |
Jesse Barnes | 8cf5c91 | 2011-11-14 14:51:27 -0800 | [diff] [blame] | 544 | struct drm_plane *plane; |
Dave Airlie | 5ef5f72 | 2009-08-17 13:11:23 +1000 | [diff] [blame] | 545 | struct drm_mode_set set; |
| 546 | int ret; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 547 | |
Daniel Vetter | 4b096ac | 2012-12-10 21:19:18 +0100 | [diff] [blame] | 548 | WARN_ON(!list_empty(&fb->filp_head)); |
Daniel Vetter | 8faf6b1 | 2012-12-01 23:43:11 +0100 | [diff] [blame] | 549 | |
Daniel Vetter | b62584e | 2012-12-11 16:51:35 +0100 | [diff] [blame] | 550 | /* |
| 551 | * drm ABI mandates that we remove any deleted framebuffers from active |
| 552 | * useage. But since most sane clients only remove framebuffers they no |
| 553 | * longer need, try to optimize this away. |
| 554 | * |
| 555 | * Since we're holding a reference ourselves, observing a refcount of 1 |
| 556 | * means that we're the last holder and can skip it. Also, the refcount |
| 557 | * can never increase from 1 again, so we don't need any barriers or |
| 558 | * locks. |
| 559 | * |
| 560 | * Note that userspace could try to race with use and instate a new |
| 561 | * usage _after_ we've cleared all current ones. End result will be an |
| 562 | * in-use fb with fb-id == 0. Userspace is allowed to shoot its own foot |
| 563 | * in this manner. |
| 564 | */ |
| 565 | if (atomic_read(&fb->refcount.refcount) > 1) { |
| 566 | drm_modeset_lock_all(dev); |
| 567 | /* remove from any CRTC */ |
| 568 | list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) { |
| 569 | if (crtc->fb == fb) { |
| 570 | /* should turn off the crtc */ |
| 571 | memset(&set, 0, sizeof(struct drm_mode_set)); |
| 572 | set.crtc = crtc; |
| 573 | set.fb = NULL; |
| 574 | ret = drm_mode_set_config_internal(&set); |
| 575 | if (ret) |
| 576 | DRM_ERROR("failed to reset crtc %p when fb was deleted\n", crtc); |
| 577 | } |
Dave Airlie | 5ef5f72 | 2009-08-17 13:11:23 +1000 | [diff] [blame] | 578 | } |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 579 | |
Daniel Vetter | b62584e | 2012-12-11 16:51:35 +0100 | [diff] [blame] | 580 | list_for_each_entry(plane, &dev->mode_config.plane_list, head) { |
| 581 | if (plane->fb == fb) { |
| 582 | /* should turn off the crtc */ |
| 583 | ret = plane->funcs->disable_plane(plane); |
| 584 | if (ret) |
| 585 | DRM_ERROR("failed to disable plane with busy fb\n"); |
| 586 | /* disconnect the plane from the fb and crtc: */ |
| 587 | __drm_framebuffer_unreference(plane->fb); |
| 588 | plane->fb = NULL; |
| 589 | plane->crtc = NULL; |
| 590 | } |
Jesse Barnes | 8cf5c91 | 2011-11-14 14:51:27 -0800 | [diff] [blame] | 591 | } |
Daniel Vetter | b62584e | 2012-12-11 16:51:35 +0100 | [diff] [blame] | 592 | drm_modeset_unlock_all(dev); |
Jesse Barnes | 8cf5c91 | 2011-11-14 14:51:27 -0800 | [diff] [blame] | 593 | } |
| 594 | |
Rob Clark | f7eff60 | 2012-09-05 21:48:38 +0000 | [diff] [blame] | 595 | drm_framebuffer_unreference(fb); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 596 | } |
Rob Clark | f7eff60 | 2012-09-05 21:48:38 +0000 | [diff] [blame] | 597 | EXPORT_SYMBOL(drm_framebuffer_remove); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 598 | |
| 599 | /** |
| 600 | * drm_crtc_init - Initialise a new CRTC object |
| 601 | * @dev: DRM device |
| 602 | * @crtc: CRTC object to init |
| 603 | * @funcs: callbacks for the new CRTC |
| 604 | * |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 605 | * Inits a new object created as base part of an driver crtc object. |
Ville Syrjälä | 6bfc56a | 2012-03-13 12:35:48 +0200 | [diff] [blame] | 606 | * |
| 607 | * RETURNS: |
| 608 | * Zero on success, error code on failure. |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 609 | */ |
Ville Syrjälä | 6bfc56a | 2012-03-13 12:35:48 +0200 | [diff] [blame] | 610 | int drm_crtc_init(struct drm_device *dev, struct drm_crtc *crtc, |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 611 | const struct drm_crtc_funcs *funcs) |
| 612 | { |
Ville Syrjälä | 6bfc56a | 2012-03-13 12:35:48 +0200 | [diff] [blame] | 613 | int ret; |
| 614 | |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 615 | crtc->dev = dev; |
| 616 | crtc->funcs = funcs; |
Rob Clark | 7c80e12 | 2012-09-04 16:35:56 +0000 | [diff] [blame] | 617 | crtc->invert_dimensions = false; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 618 | |
Daniel Vetter | 8484990 | 2012-12-02 00:28:11 +0100 | [diff] [blame] | 619 | drm_modeset_lock_all(dev); |
Daniel Vetter | 29494c1 | 2012-12-02 02:18:25 +0100 | [diff] [blame] | 620 | mutex_init(&crtc->mutex); |
| 621 | mutex_lock_nest_lock(&crtc->mutex, &dev->mode_config.mutex); |
Ville Syrjälä | 6bfc56a | 2012-03-13 12:35:48 +0200 | [diff] [blame] | 622 | |
| 623 | ret = drm_mode_object_get(dev, &crtc->base, DRM_MODE_OBJECT_CRTC); |
| 624 | if (ret) |
| 625 | goto out; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 626 | |
Paulo Zanoni | bffd9de0 | 2012-05-15 18:09:05 -0300 | [diff] [blame] | 627 | crtc->base.properties = &crtc->properties; |
| 628 | |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 629 | list_add_tail(&crtc->head, &dev->mode_config.crtc_list); |
| 630 | dev->mode_config.num_crtc++; |
Ville Syrjälä | 6bfc56a | 2012-03-13 12:35:48 +0200 | [diff] [blame] | 631 | |
| 632 | out: |
Daniel Vetter | 8484990 | 2012-12-02 00:28:11 +0100 | [diff] [blame] | 633 | drm_modeset_unlock_all(dev); |
Ville Syrjälä | 6bfc56a | 2012-03-13 12:35:48 +0200 | [diff] [blame] | 634 | |
| 635 | return ret; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 636 | } |
| 637 | EXPORT_SYMBOL(drm_crtc_init); |
| 638 | |
| 639 | /** |
| 640 | * drm_crtc_cleanup - Cleans up the core crtc usage. |
| 641 | * @crtc: CRTC to cleanup |
| 642 | * |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 643 | * Cleanup @crtc. Removes from drm modesetting space |
| 644 | * does NOT free object, caller does that. |
| 645 | */ |
| 646 | void drm_crtc_cleanup(struct drm_crtc *crtc) |
| 647 | { |
| 648 | struct drm_device *dev = crtc->dev; |
| 649 | |
Sachin Kamat | 9e1c156 | 2012-11-19 09:44:56 +0000 | [diff] [blame] | 650 | kfree(crtc->gamma_store); |
| 651 | crtc->gamma_store = NULL; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 652 | |
| 653 | drm_mode_object_put(dev, &crtc->base); |
| 654 | list_del(&crtc->head); |
| 655 | dev->mode_config.num_crtc--; |
| 656 | } |
| 657 | EXPORT_SYMBOL(drm_crtc_cleanup); |
| 658 | |
| 659 | /** |
| 660 | * drm_mode_probed_add - add a mode to a connector's probed mode list |
| 661 | * @connector: connector the new mode |
| 662 | * @mode: mode data |
| 663 | * |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 664 | * Add @mode to @connector's mode list for later use. |
| 665 | */ |
| 666 | void drm_mode_probed_add(struct drm_connector *connector, |
| 667 | struct drm_display_mode *mode) |
| 668 | { |
| 669 | list_add(&mode->head, &connector->probed_modes); |
| 670 | } |
| 671 | EXPORT_SYMBOL(drm_mode_probed_add); |
| 672 | |
| 673 | /** |
| 674 | * drm_mode_remove - remove and free a mode |
| 675 | * @connector: connector list to modify |
| 676 | * @mode: mode to remove |
| 677 | * |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 678 | * Remove @mode from @connector's mode list, then free it. |
| 679 | */ |
| 680 | void drm_mode_remove(struct drm_connector *connector, |
| 681 | struct drm_display_mode *mode) |
| 682 | { |
| 683 | list_del(&mode->head); |
Sascha Hauer | 554f1d7 | 2012-02-01 11:38:19 +0100 | [diff] [blame] | 684 | drm_mode_destroy(connector->dev, mode); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 685 | } |
| 686 | EXPORT_SYMBOL(drm_mode_remove); |
| 687 | |
| 688 | /** |
| 689 | * drm_connector_init - Init a preallocated connector |
| 690 | * @dev: DRM device |
| 691 | * @connector: the connector to init |
| 692 | * @funcs: callbacks for this connector |
Daniel Vetter | 065a50ed | 2012-12-02 00:09:18 +0100 | [diff] [blame] | 693 | * @connector_type: user visible type of the connector |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 694 | * |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 695 | * Initialises a preallocated connector. Connectors should be |
| 696 | * subclassed as part of driver connector objects. |
Ville Syrjälä | 6bfc56a | 2012-03-13 12:35:48 +0200 | [diff] [blame] | 697 | * |
| 698 | * RETURNS: |
| 699 | * Zero on success, error code on failure. |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 700 | */ |
Ville Syrjälä | 6bfc56a | 2012-03-13 12:35:48 +0200 | [diff] [blame] | 701 | int drm_connector_init(struct drm_device *dev, |
| 702 | struct drm_connector *connector, |
| 703 | const struct drm_connector_funcs *funcs, |
| 704 | int connector_type) |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 705 | { |
Ville Syrjälä | 6bfc56a | 2012-03-13 12:35:48 +0200 | [diff] [blame] | 706 | int ret; |
| 707 | |
Daniel Vetter | 8484990 | 2012-12-02 00:28:11 +0100 | [diff] [blame] | 708 | drm_modeset_lock_all(dev); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 709 | |
Ville Syrjälä | 6bfc56a | 2012-03-13 12:35:48 +0200 | [diff] [blame] | 710 | ret = drm_mode_object_get(dev, &connector->base, DRM_MODE_OBJECT_CONNECTOR); |
| 711 | if (ret) |
| 712 | goto out; |
| 713 | |
Paulo Zanoni | 7e3bdf4 | 2012-05-15 18:09:01 -0300 | [diff] [blame] | 714 | connector->base.properties = &connector->properties; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 715 | connector->dev = dev; |
| 716 | connector->funcs = funcs; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 717 | connector->connector_type = connector_type; |
| 718 | connector->connector_type_id = |
| 719 | ++drm_connector_enum_list[connector_type].count; /* TODO */ |
| 720 | INIT_LIST_HEAD(&connector->user_modes); |
| 721 | INIT_LIST_HEAD(&connector->probed_modes); |
| 722 | INIT_LIST_HEAD(&connector->modes); |
| 723 | connector->edid_blob_ptr = NULL; |
Daniel Vetter | 5e2cb2f | 2012-10-23 18:23:35 +0000 | [diff] [blame] | 724 | connector->status = connector_status_unknown; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 725 | |
| 726 | list_add_tail(&connector->head, &dev->mode_config.connector_list); |
| 727 | dev->mode_config.num_connector++; |
| 728 | |
Thomas Hellstrom | a7331e5 | 2011-10-22 10:36:19 +0200 | [diff] [blame] | 729 | if (connector_type != DRM_MODE_CONNECTOR_VIRTUAL) |
Rob Clark | 5849556 | 2012-10-11 20:50:56 -0500 | [diff] [blame] | 730 | drm_object_attach_property(&connector->base, |
Thomas Hellstrom | a7331e5 | 2011-10-22 10:36:19 +0200 | [diff] [blame] | 731 | dev->mode_config.edid_property, |
| 732 | 0); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 733 | |
Rob Clark | 5849556 | 2012-10-11 20:50:56 -0500 | [diff] [blame] | 734 | drm_object_attach_property(&connector->base, |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 735 | dev->mode_config.dpms_property, 0); |
| 736 | |
Ville Syrjälä | 6bfc56a | 2012-03-13 12:35:48 +0200 | [diff] [blame] | 737 | out: |
Daniel Vetter | 8484990 | 2012-12-02 00:28:11 +0100 | [diff] [blame] | 738 | drm_modeset_unlock_all(dev); |
Ville Syrjälä | 6bfc56a | 2012-03-13 12:35:48 +0200 | [diff] [blame] | 739 | |
| 740 | return ret; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 741 | } |
| 742 | EXPORT_SYMBOL(drm_connector_init); |
| 743 | |
| 744 | /** |
| 745 | * drm_connector_cleanup - cleans up an initialised connector |
| 746 | * @connector: connector to cleanup |
| 747 | * |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 748 | * Cleans up the connector but doesn't free the object. |
| 749 | */ |
| 750 | void drm_connector_cleanup(struct drm_connector *connector) |
| 751 | { |
| 752 | struct drm_device *dev = connector->dev; |
| 753 | struct drm_display_mode *mode, *t; |
| 754 | |
| 755 | list_for_each_entry_safe(mode, t, &connector->probed_modes, head) |
| 756 | drm_mode_remove(connector, mode); |
| 757 | |
| 758 | list_for_each_entry_safe(mode, t, &connector->modes, head) |
| 759 | drm_mode_remove(connector, mode); |
| 760 | |
| 761 | list_for_each_entry_safe(mode, t, &connector->user_modes, head) |
| 762 | drm_mode_remove(connector, mode); |
| 763 | |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 764 | drm_mode_object_put(dev, &connector->base); |
| 765 | list_del(&connector->head); |
Joonyoung Shim | 6380c50 | 2011-08-27 02:06:21 +0000 | [diff] [blame] | 766 | dev->mode_config.num_connector--; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 767 | } |
| 768 | EXPORT_SYMBOL(drm_connector_cleanup); |
| 769 | |
Dave Airlie | cbc7e22 | 2012-02-20 14:16:40 +0000 | [diff] [blame] | 770 | void drm_connector_unplug_all(struct drm_device *dev) |
| 771 | { |
| 772 | struct drm_connector *connector; |
| 773 | |
| 774 | /* taking the mode config mutex ends up in a clash with sysfs */ |
| 775 | list_for_each_entry(connector, &dev->mode_config.connector_list, head) |
| 776 | drm_sysfs_connector_remove(connector); |
| 777 | |
| 778 | } |
| 779 | EXPORT_SYMBOL(drm_connector_unplug_all); |
| 780 | |
Ville Syrjälä | 6bfc56a | 2012-03-13 12:35:48 +0200 | [diff] [blame] | 781 | int drm_encoder_init(struct drm_device *dev, |
Dave Airlie | cbc7e22 | 2012-02-20 14:16:40 +0000 | [diff] [blame] | 782 | struct drm_encoder *encoder, |
| 783 | const struct drm_encoder_funcs *funcs, |
| 784 | int encoder_type) |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 785 | { |
Ville Syrjälä | 6bfc56a | 2012-03-13 12:35:48 +0200 | [diff] [blame] | 786 | int ret; |
| 787 | |
Daniel Vetter | 8484990 | 2012-12-02 00:28:11 +0100 | [diff] [blame] | 788 | drm_modeset_lock_all(dev); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 789 | |
Ville Syrjälä | 6bfc56a | 2012-03-13 12:35:48 +0200 | [diff] [blame] | 790 | ret = drm_mode_object_get(dev, &encoder->base, DRM_MODE_OBJECT_ENCODER); |
| 791 | if (ret) |
| 792 | goto out; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 793 | |
Ville Syrjälä | 6bfc56a | 2012-03-13 12:35:48 +0200 | [diff] [blame] | 794 | encoder->dev = dev; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 795 | encoder->encoder_type = encoder_type; |
| 796 | encoder->funcs = funcs; |
| 797 | |
| 798 | list_add_tail(&encoder->head, &dev->mode_config.encoder_list); |
| 799 | dev->mode_config.num_encoder++; |
| 800 | |
Ville Syrjälä | 6bfc56a | 2012-03-13 12:35:48 +0200 | [diff] [blame] | 801 | out: |
Daniel Vetter | 8484990 | 2012-12-02 00:28:11 +0100 | [diff] [blame] | 802 | drm_modeset_unlock_all(dev); |
Ville Syrjälä | 6bfc56a | 2012-03-13 12:35:48 +0200 | [diff] [blame] | 803 | |
| 804 | return ret; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 805 | } |
| 806 | EXPORT_SYMBOL(drm_encoder_init); |
| 807 | |
| 808 | void drm_encoder_cleanup(struct drm_encoder *encoder) |
| 809 | { |
| 810 | struct drm_device *dev = encoder->dev; |
Daniel Vetter | 8484990 | 2012-12-02 00:28:11 +0100 | [diff] [blame] | 811 | drm_modeset_lock_all(dev); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 812 | drm_mode_object_put(dev, &encoder->base); |
| 813 | list_del(&encoder->head); |
Joonyoung Shim | 6380c50 | 2011-08-27 02:06:21 +0000 | [diff] [blame] | 814 | dev->mode_config.num_encoder--; |
Daniel Vetter | 8484990 | 2012-12-02 00:28:11 +0100 | [diff] [blame] | 815 | drm_modeset_unlock_all(dev); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 816 | } |
| 817 | EXPORT_SYMBOL(drm_encoder_cleanup); |
| 818 | |
Jesse Barnes | 8cf5c91 | 2011-11-14 14:51:27 -0800 | [diff] [blame] | 819 | int drm_plane_init(struct drm_device *dev, struct drm_plane *plane, |
| 820 | unsigned long possible_crtcs, |
| 821 | const struct drm_plane_funcs *funcs, |
Rob Clark | 0a7eb24 | 2011-12-13 20:19:36 -0600 | [diff] [blame] | 822 | const uint32_t *formats, uint32_t format_count, |
| 823 | bool priv) |
Jesse Barnes | 8cf5c91 | 2011-11-14 14:51:27 -0800 | [diff] [blame] | 824 | { |
Ville Syrjälä | 6bfc56a | 2012-03-13 12:35:48 +0200 | [diff] [blame] | 825 | int ret; |
| 826 | |
Daniel Vetter | 8484990 | 2012-12-02 00:28:11 +0100 | [diff] [blame] | 827 | drm_modeset_lock_all(dev); |
Jesse Barnes | 8cf5c91 | 2011-11-14 14:51:27 -0800 | [diff] [blame] | 828 | |
Ville Syrjälä | 6bfc56a | 2012-03-13 12:35:48 +0200 | [diff] [blame] | 829 | ret = drm_mode_object_get(dev, &plane->base, DRM_MODE_OBJECT_PLANE); |
| 830 | if (ret) |
| 831 | goto out; |
| 832 | |
Rob Clark | 4d93914 | 2012-05-17 02:23:27 -0600 | [diff] [blame] | 833 | plane->base.properties = &plane->properties; |
Jesse Barnes | 8cf5c91 | 2011-11-14 14:51:27 -0800 | [diff] [blame] | 834 | plane->dev = dev; |
Jesse Barnes | 8cf5c91 | 2011-11-14 14:51:27 -0800 | [diff] [blame] | 835 | plane->funcs = funcs; |
| 836 | plane->format_types = kmalloc(sizeof(uint32_t) * format_count, |
| 837 | GFP_KERNEL); |
| 838 | if (!plane->format_types) { |
| 839 | DRM_DEBUG_KMS("out of memory when allocating plane\n"); |
| 840 | drm_mode_object_put(dev, &plane->base); |
Ville Syrjälä | 6bfc56a | 2012-03-13 12:35:48 +0200 | [diff] [blame] | 841 | ret = -ENOMEM; |
| 842 | goto out; |
Jesse Barnes | 8cf5c91 | 2011-11-14 14:51:27 -0800 | [diff] [blame] | 843 | } |
| 844 | |
Jesse Barnes | 308e5bc | 2011-11-14 14:51:28 -0800 | [diff] [blame] | 845 | memcpy(plane->format_types, formats, format_count * sizeof(uint32_t)); |
Jesse Barnes | 8cf5c91 | 2011-11-14 14:51:27 -0800 | [diff] [blame] | 846 | plane->format_count = format_count; |
| 847 | plane->possible_crtcs = possible_crtcs; |
| 848 | |
Rob Clark | 0a7eb24 | 2011-12-13 20:19:36 -0600 | [diff] [blame] | 849 | /* private planes are not exposed to userspace, but depending on |
| 850 | * display hardware, might be convenient to allow sharing programming |
| 851 | * for the scanout engine with the crtc implementation. |
| 852 | */ |
| 853 | if (!priv) { |
| 854 | list_add_tail(&plane->head, &dev->mode_config.plane_list); |
| 855 | dev->mode_config.num_plane++; |
| 856 | } else { |
| 857 | INIT_LIST_HEAD(&plane->head); |
| 858 | } |
Jesse Barnes | 8cf5c91 | 2011-11-14 14:51:27 -0800 | [diff] [blame] | 859 | |
Ville Syrjälä | 6bfc56a | 2012-03-13 12:35:48 +0200 | [diff] [blame] | 860 | out: |
Daniel Vetter | 8484990 | 2012-12-02 00:28:11 +0100 | [diff] [blame] | 861 | drm_modeset_unlock_all(dev); |
Jesse Barnes | 8cf5c91 | 2011-11-14 14:51:27 -0800 | [diff] [blame] | 862 | |
Ville Syrjälä | 6bfc56a | 2012-03-13 12:35:48 +0200 | [diff] [blame] | 863 | return ret; |
Jesse Barnes | 8cf5c91 | 2011-11-14 14:51:27 -0800 | [diff] [blame] | 864 | } |
| 865 | EXPORT_SYMBOL(drm_plane_init); |
| 866 | |
| 867 | void drm_plane_cleanup(struct drm_plane *plane) |
| 868 | { |
| 869 | struct drm_device *dev = plane->dev; |
| 870 | |
Daniel Vetter | 8484990 | 2012-12-02 00:28:11 +0100 | [diff] [blame] | 871 | drm_modeset_lock_all(dev); |
Jesse Barnes | 8cf5c91 | 2011-11-14 14:51:27 -0800 | [diff] [blame] | 872 | kfree(plane->format_types); |
| 873 | drm_mode_object_put(dev, &plane->base); |
Rob Clark | 0a7eb24 | 2011-12-13 20:19:36 -0600 | [diff] [blame] | 874 | /* if not added to a list, it must be a private plane */ |
| 875 | if (!list_empty(&plane->head)) { |
| 876 | list_del(&plane->head); |
| 877 | dev->mode_config.num_plane--; |
| 878 | } |
Daniel Vetter | 8484990 | 2012-12-02 00:28:11 +0100 | [diff] [blame] | 879 | drm_modeset_unlock_all(dev); |
Jesse Barnes | 8cf5c91 | 2011-11-14 14:51:27 -0800 | [diff] [blame] | 880 | } |
| 881 | EXPORT_SYMBOL(drm_plane_cleanup); |
| 882 | |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 883 | /** |
| 884 | * drm_mode_create - create a new display mode |
| 885 | * @dev: DRM device |
| 886 | * |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 887 | * Create a new drm_display_mode, give it an ID, and return it. |
| 888 | * |
| 889 | * RETURNS: |
| 890 | * Pointer to new mode on success, NULL on error. |
| 891 | */ |
| 892 | struct drm_display_mode *drm_mode_create(struct drm_device *dev) |
| 893 | { |
| 894 | struct drm_display_mode *nmode; |
| 895 | |
| 896 | nmode = kzalloc(sizeof(struct drm_display_mode), GFP_KERNEL); |
| 897 | if (!nmode) |
| 898 | return NULL; |
| 899 | |
Ville Syrjälä | 6bfc56a | 2012-03-13 12:35:48 +0200 | [diff] [blame] | 900 | if (drm_mode_object_get(dev, &nmode->base, DRM_MODE_OBJECT_MODE)) { |
| 901 | kfree(nmode); |
| 902 | return NULL; |
| 903 | } |
| 904 | |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 905 | return nmode; |
| 906 | } |
| 907 | EXPORT_SYMBOL(drm_mode_create); |
| 908 | |
| 909 | /** |
| 910 | * drm_mode_destroy - remove a mode |
| 911 | * @dev: DRM device |
| 912 | * @mode: mode to remove |
| 913 | * |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 914 | * Free @mode's unique identifier, then free it. |
| 915 | */ |
| 916 | void drm_mode_destroy(struct drm_device *dev, struct drm_display_mode *mode) |
| 917 | { |
Ville Syrjälä | ee34ab5 | 2012-03-13 12:35:43 +0200 | [diff] [blame] | 918 | if (!mode) |
| 919 | return; |
| 920 | |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 921 | drm_mode_object_put(dev, &mode->base); |
| 922 | |
| 923 | kfree(mode); |
| 924 | } |
| 925 | EXPORT_SYMBOL(drm_mode_destroy); |
| 926 | |
| 927 | static int drm_mode_create_standard_connector_properties(struct drm_device *dev) |
| 928 | { |
| 929 | struct drm_property *edid; |
| 930 | struct drm_property *dpms; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 931 | |
| 932 | /* |
| 933 | * Standard properties (apply to all connectors) |
| 934 | */ |
| 935 | edid = drm_property_create(dev, DRM_MODE_PROP_BLOB | |
| 936 | DRM_MODE_PROP_IMMUTABLE, |
| 937 | "EDID", 0); |
| 938 | dev->mode_config.edid_property = edid; |
| 939 | |
Sascha Hauer | 4a67d39 | 2012-02-06 10:58:17 +0100 | [diff] [blame] | 940 | dpms = drm_property_create_enum(dev, 0, |
| 941 | "DPMS", drm_dpms_enum_list, |
| 942 | ARRAY_SIZE(drm_dpms_enum_list)); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 943 | dev->mode_config.dpms_property = dpms; |
| 944 | |
| 945 | return 0; |
| 946 | } |
| 947 | |
| 948 | /** |
| 949 | * drm_mode_create_dvi_i_properties - create DVI-I specific connector properties |
| 950 | * @dev: DRM device |
| 951 | * |
| 952 | * Called by a driver the first time a DVI-I connector is made. |
| 953 | */ |
| 954 | int drm_mode_create_dvi_i_properties(struct drm_device *dev) |
| 955 | { |
| 956 | struct drm_property *dvi_i_selector; |
| 957 | struct drm_property *dvi_i_subconnector; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 958 | |
| 959 | if (dev->mode_config.dvi_i_select_subconnector_property) |
| 960 | return 0; |
| 961 | |
| 962 | dvi_i_selector = |
Sascha Hauer | 4a67d39 | 2012-02-06 10:58:17 +0100 | [diff] [blame] | 963 | drm_property_create_enum(dev, 0, |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 964 | "select subconnector", |
Sascha Hauer | 4a67d39 | 2012-02-06 10:58:17 +0100 | [diff] [blame] | 965 | drm_dvi_i_select_enum_list, |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 966 | ARRAY_SIZE(drm_dvi_i_select_enum_list)); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 967 | dev->mode_config.dvi_i_select_subconnector_property = dvi_i_selector; |
| 968 | |
Sascha Hauer | 4a67d39 | 2012-02-06 10:58:17 +0100 | [diff] [blame] | 969 | dvi_i_subconnector = drm_property_create_enum(dev, DRM_MODE_PROP_IMMUTABLE, |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 970 | "subconnector", |
Sascha Hauer | 4a67d39 | 2012-02-06 10:58:17 +0100 | [diff] [blame] | 971 | drm_dvi_i_subconnector_enum_list, |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 972 | ARRAY_SIZE(drm_dvi_i_subconnector_enum_list)); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 973 | dev->mode_config.dvi_i_subconnector_property = dvi_i_subconnector; |
| 974 | |
| 975 | return 0; |
| 976 | } |
| 977 | EXPORT_SYMBOL(drm_mode_create_dvi_i_properties); |
| 978 | |
| 979 | /** |
| 980 | * drm_create_tv_properties - create TV specific connector properties |
| 981 | * @dev: DRM device |
| 982 | * @num_modes: number of different TV formats (modes) supported |
| 983 | * @modes: array of pointers to strings containing name of each format |
| 984 | * |
| 985 | * Called by a driver's TV initialization routine, this function creates |
| 986 | * the TV specific connector properties for a given device. Caller is |
| 987 | * responsible for allocating a list of format names and passing them to |
| 988 | * this routine. |
| 989 | */ |
| 990 | int drm_mode_create_tv_properties(struct drm_device *dev, int num_modes, |
| 991 | char *modes[]) |
| 992 | { |
| 993 | struct drm_property *tv_selector; |
| 994 | struct drm_property *tv_subconnector; |
| 995 | int i; |
| 996 | |
| 997 | if (dev->mode_config.tv_select_subconnector_property) |
| 998 | return 0; |
| 999 | |
| 1000 | /* |
| 1001 | * Basic connector properties |
| 1002 | */ |
Sascha Hauer | 4a67d39 | 2012-02-06 10:58:17 +0100 | [diff] [blame] | 1003 | tv_selector = drm_property_create_enum(dev, 0, |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 1004 | "select subconnector", |
Sascha Hauer | 4a67d39 | 2012-02-06 10:58:17 +0100 | [diff] [blame] | 1005 | drm_tv_select_enum_list, |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 1006 | ARRAY_SIZE(drm_tv_select_enum_list)); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 1007 | dev->mode_config.tv_select_subconnector_property = tv_selector; |
| 1008 | |
| 1009 | tv_subconnector = |
Sascha Hauer | 4a67d39 | 2012-02-06 10:58:17 +0100 | [diff] [blame] | 1010 | drm_property_create_enum(dev, DRM_MODE_PROP_IMMUTABLE, |
| 1011 | "subconnector", |
| 1012 | drm_tv_subconnector_enum_list, |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 1013 | ARRAY_SIZE(drm_tv_subconnector_enum_list)); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 1014 | dev->mode_config.tv_subconnector_property = tv_subconnector; |
| 1015 | |
| 1016 | /* |
| 1017 | * Other, TV specific properties: margins & TV modes. |
| 1018 | */ |
| 1019 | dev->mode_config.tv_left_margin_property = |
Sascha Hauer | d9bc3c0 | 2012-02-06 10:58:18 +0100 | [diff] [blame] | 1020 | drm_property_create_range(dev, 0, "left margin", 0, 100); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 1021 | |
| 1022 | dev->mode_config.tv_right_margin_property = |
Sascha Hauer | d9bc3c0 | 2012-02-06 10:58:18 +0100 | [diff] [blame] | 1023 | drm_property_create_range(dev, 0, "right margin", 0, 100); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 1024 | |
| 1025 | dev->mode_config.tv_top_margin_property = |
Sascha Hauer | d9bc3c0 | 2012-02-06 10:58:18 +0100 | [diff] [blame] | 1026 | drm_property_create_range(dev, 0, "top margin", 0, 100); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 1027 | |
| 1028 | dev->mode_config.tv_bottom_margin_property = |
Sascha Hauer | d9bc3c0 | 2012-02-06 10:58:18 +0100 | [diff] [blame] | 1029 | drm_property_create_range(dev, 0, "bottom margin", 0, 100); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 1030 | |
| 1031 | dev->mode_config.tv_mode_property = |
| 1032 | drm_property_create(dev, DRM_MODE_PROP_ENUM, |
| 1033 | "mode", num_modes); |
| 1034 | for (i = 0; i < num_modes; i++) |
| 1035 | drm_property_add_enum(dev->mode_config.tv_mode_property, i, |
| 1036 | i, modes[i]); |
| 1037 | |
Francisco Jerez | b6b7902 | 2009-08-02 04:19:20 +0200 | [diff] [blame] | 1038 | dev->mode_config.tv_brightness_property = |
Sascha Hauer | d9bc3c0 | 2012-02-06 10:58:18 +0100 | [diff] [blame] | 1039 | drm_property_create_range(dev, 0, "brightness", 0, 100); |
Francisco Jerez | b6b7902 | 2009-08-02 04:19:20 +0200 | [diff] [blame] | 1040 | |
| 1041 | dev->mode_config.tv_contrast_property = |
Sascha Hauer | d9bc3c0 | 2012-02-06 10:58:18 +0100 | [diff] [blame] | 1042 | drm_property_create_range(dev, 0, "contrast", 0, 100); |
Francisco Jerez | b6b7902 | 2009-08-02 04:19:20 +0200 | [diff] [blame] | 1043 | |
| 1044 | dev->mode_config.tv_flicker_reduction_property = |
Sascha Hauer | d9bc3c0 | 2012-02-06 10:58:18 +0100 | [diff] [blame] | 1045 | drm_property_create_range(dev, 0, "flicker reduction", 0, 100); |
Francisco Jerez | b6b7902 | 2009-08-02 04:19:20 +0200 | [diff] [blame] | 1046 | |
Francisco Jerez | a75f023 | 2009-08-12 02:30:10 +0200 | [diff] [blame] | 1047 | dev->mode_config.tv_overscan_property = |
Sascha Hauer | d9bc3c0 | 2012-02-06 10:58:18 +0100 | [diff] [blame] | 1048 | drm_property_create_range(dev, 0, "overscan", 0, 100); |
Francisco Jerez | a75f023 | 2009-08-12 02:30:10 +0200 | [diff] [blame] | 1049 | |
| 1050 | dev->mode_config.tv_saturation_property = |
Sascha Hauer | d9bc3c0 | 2012-02-06 10:58:18 +0100 | [diff] [blame] | 1051 | drm_property_create_range(dev, 0, "saturation", 0, 100); |
Francisco Jerez | a75f023 | 2009-08-12 02:30:10 +0200 | [diff] [blame] | 1052 | |
| 1053 | dev->mode_config.tv_hue_property = |
Sascha Hauer | d9bc3c0 | 2012-02-06 10:58:18 +0100 | [diff] [blame] | 1054 | drm_property_create_range(dev, 0, "hue", 0, 100); |
Francisco Jerez | a75f023 | 2009-08-12 02:30:10 +0200 | [diff] [blame] | 1055 | |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 1056 | return 0; |
| 1057 | } |
| 1058 | EXPORT_SYMBOL(drm_mode_create_tv_properties); |
| 1059 | |
| 1060 | /** |
| 1061 | * drm_mode_create_scaling_mode_property - create scaling mode property |
| 1062 | * @dev: DRM device |
| 1063 | * |
| 1064 | * Called by a driver the first time it's needed, must be attached to desired |
| 1065 | * connectors. |
| 1066 | */ |
| 1067 | int drm_mode_create_scaling_mode_property(struct drm_device *dev) |
| 1068 | { |
| 1069 | struct drm_property *scaling_mode; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 1070 | |
| 1071 | if (dev->mode_config.scaling_mode_property) |
| 1072 | return 0; |
| 1073 | |
| 1074 | scaling_mode = |
Sascha Hauer | 4a67d39 | 2012-02-06 10:58:17 +0100 | [diff] [blame] | 1075 | drm_property_create_enum(dev, 0, "scaling mode", |
| 1076 | drm_scaling_mode_enum_list, |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 1077 | ARRAY_SIZE(drm_scaling_mode_enum_list)); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 1078 | |
| 1079 | dev->mode_config.scaling_mode_property = scaling_mode; |
| 1080 | |
| 1081 | return 0; |
| 1082 | } |
| 1083 | EXPORT_SYMBOL(drm_mode_create_scaling_mode_property); |
| 1084 | |
| 1085 | /** |
| 1086 | * drm_mode_create_dithering_property - create dithering property |
| 1087 | * @dev: DRM device |
| 1088 | * |
| 1089 | * Called by a driver the first time it's needed, must be attached to desired |
| 1090 | * connectors. |
| 1091 | */ |
| 1092 | int drm_mode_create_dithering_property(struct drm_device *dev) |
| 1093 | { |
| 1094 | struct drm_property *dithering_mode; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 1095 | |
| 1096 | if (dev->mode_config.dithering_mode_property) |
| 1097 | return 0; |
| 1098 | |
| 1099 | dithering_mode = |
Sascha Hauer | 4a67d39 | 2012-02-06 10:58:17 +0100 | [diff] [blame] | 1100 | drm_property_create_enum(dev, 0, "dithering", |
| 1101 | drm_dithering_mode_enum_list, |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 1102 | ARRAY_SIZE(drm_dithering_mode_enum_list)); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 1103 | dev->mode_config.dithering_mode_property = dithering_mode; |
| 1104 | |
| 1105 | return 0; |
| 1106 | } |
| 1107 | EXPORT_SYMBOL(drm_mode_create_dithering_property); |
| 1108 | |
| 1109 | /** |
Jakob Bornecrantz | 884840a | 2009-12-03 23:25:47 +0000 | [diff] [blame] | 1110 | * drm_mode_create_dirty_property - create dirty property |
| 1111 | * @dev: DRM device |
| 1112 | * |
| 1113 | * Called by a driver the first time it's needed, must be attached to desired |
| 1114 | * connectors. |
| 1115 | */ |
| 1116 | int drm_mode_create_dirty_info_property(struct drm_device *dev) |
| 1117 | { |
| 1118 | struct drm_property *dirty_info; |
Jakob Bornecrantz | 884840a | 2009-12-03 23:25:47 +0000 | [diff] [blame] | 1119 | |
| 1120 | if (dev->mode_config.dirty_info_property) |
| 1121 | return 0; |
| 1122 | |
| 1123 | dirty_info = |
Sascha Hauer | 4a67d39 | 2012-02-06 10:58:17 +0100 | [diff] [blame] | 1124 | drm_property_create_enum(dev, DRM_MODE_PROP_IMMUTABLE, |
Jakob Bornecrantz | 884840a | 2009-12-03 23:25:47 +0000 | [diff] [blame] | 1125 | "dirty", |
Sascha Hauer | 4a67d39 | 2012-02-06 10:58:17 +0100 | [diff] [blame] | 1126 | drm_dirty_info_enum_list, |
Jakob Bornecrantz | 884840a | 2009-12-03 23:25:47 +0000 | [diff] [blame] | 1127 | ARRAY_SIZE(drm_dirty_info_enum_list)); |
Jakob Bornecrantz | 884840a | 2009-12-03 23:25:47 +0000 | [diff] [blame] | 1128 | dev->mode_config.dirty_info_property = dirty_info; |
| 1129 | |
| 1130 | return 0; |
| 1131 | } |
| 1132 | EXPORT_SYMBOL(drm_mode_create_dirty_info_property); |
| 1133 | |
| 1134 | /** |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 1135 | * drm_mode_config_init - initialize DRM mode_configuration structure |
| 1136 | * @dev: DRM device |
| 1137 | * |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 1138 | * Initialize @dev's mode_config structure, used for tracking the graphics |
| 1139 | * configuration of @dev. |
Daniel Vetter | 8faf6b1 | 2012-12-01 23:43:11 +0100 | [diff] [blame] | 1140 | * |
| 1141 | * Since this initializes the modeset locks, no locking is possible. Which is no |
| 1142 | * problem, since this should happen single threaded at init time. It is the |
| 1143 | * driver's problem to ensure this guarantee. |
| 1144 | * |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 1145 | */ |
| 1146 | void drm_mode_config_init(struct drm_device *dev) |
| 1147 | { |
| 1148 | mutex_init(&dev->mode_config.mutex); |
Jesse Barnes | ad2563c | 2009-01-19 17:21:45 +1000 | [diff] [blame] | 1149 | mutex_init(&dev->mode_config.idr_mutex); |
Daniel Vetter | 4b096ac | 2012-12-10 21:19:18 +0100 | [diff] [blame] | 1150 | mutex_init(&dev->mode_config.fb_lock); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 1151 | INIT_LIST_HEAD(&dev->mode_config.fb_list); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 1152 | INIT_LIST_HEAD(&dev->mode_config.crtc_list); |
| 1153 | INIT_LIST_HEAD(&dev->mode_config.connector_list); |
| 1154 | INIT_LIST_HEAD(&dev->mode_config.encoder_list); |
| 1155 | INIT_LIST_HEAD(&dev->mode_config.property_list); |
| 1156 | INIT_LIST_HEAD(&dev->mode_config.property_blob_list); |
Jesse Barnes | 8cf5c91 | 2011-11-14 14:51:27 -0800 | [diff] [blame] | 1157 | INIT_LIST_HEAD(&dev->mode_config.plane_list); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 1158 | idr_init(&dev->mode_config.crtc_idr); |
| 1159 | |
Daniel Vetter | 8484990 | 2012-12-02 00:28:11 +0100 | [diff] [blame] | 1160 | drm_modeset_lock_all(dev); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 1161 | drm_mode_create_standard_connector_properties(dev); |
Daniel Vetter | 8484990 | 2012-12-02 00:28:11 +0100 | [diff] [blame] | 1162 | drm_modeset_unlock_all(dev); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 1163 | |
| 1164 | /* Just to be sure */ |
| 1165 | dev->mode_config.num_fb = 0; |
| 1166 | dev->mode_config.num_connector = 0; |
| 1167 | dev->mode_config.num_crtc = 0; |
| 1168 | dev->mode_config.num_encoder = 0; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 1169 | } |
| 1170 | EXPORT_SYMBOL(drm_mode_config_init); |
| 1171 | |
| 1172 | int drm_mode_group_init(struct drm_device *dev, struct drm_mode_group *group) |
| 1173 | { |
| 1174 | uint32_t total_objects = 0; |
| 1175 | |
| 1176 | total_objects += dev->mode_config.num_crtc; |
| 1177 | total_objects += dev->mode_config.num_connector; |
| 1178 | total_objects += dev->mode_config.num_encoder; |
| 1179 | |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 1180 | group->id_list = kzalloc(total_objects * sizeof(uint32_t), GFP_KERNEL); |
| 1181 | if (!group->id_list) |
| 1182 | return -ENOMEM; |
| 1183 | |
| 1184 | group->num_crtcs = 0; |
| 1185 | group->num_connectors = 0; |
| 1186 | group->num_encoders = 0; |
| 1187 | return 0; |
| 1188 | } |
| 1189 | |
| 1190 | int drm_mode_group_init_legacy_group(struct drm_device *dev, |
| 1191 | struct drm_mode_group *group) |
| 1192 | { |
| 1193 | struct drm_crtc *crtc; |
| 1194 | struct drm_encoder *encoder; |
| 1195 | struct drm_connector *connector; |
| 1196 | int ret; |
| 1197 | |
| 1198 | if ((ret = drm_mode_group_init(dev, group))) |
| 1199 | return ret; |
| 1200 | |
| 1201 | list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) |
| 1202 | group->id_list[group->num_crtcs++] = crtc->base.id; |
| 1203 | |
| 1204 | list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) |
| 1205 | group->id_list[group->num_crtcs + group->num_encoders++] = |
| 1206 | encoder->base.id; |
| 1207 | |
| 1208 | list_for_each_entry(connector, &dev->mode_config.connector_list, head) |
| 1209 | group->id_list[group->num_crtcs + group->num_encoders + |
| 1210 | group->num_connectors++] = connector->base.id; |
| 1211 | |
| 1212 | return 0; |
| 1213 | } |
Dave Airlie | 9c1dfc5 | 2012-03-20 06:59:29 +0000 | [diff] [blame] | 1214 | EXPORT_SYMBOL(drm_mode_group_init_legacy_group); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 1215 | |
| 1216 | /** |
| 1217 | * drm_mode_config_cleanup - free up DRM mode_config info |
| 1218 | * @dev: DRM device |
| 1219 | * |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 1220 | * Free up all the connectors and CRTCs associated with this DRM device, then |
| 1221 | * free up the framebuffers and associated buffer objects. |
| 1222 | * |
Daniel Vetter | 8faf6b1 | 2012-12-01 23:43:11 +0100 | [diff] [blame] | 1223 | * Note that since this /should/ happen single-threaded at driver/device |
| 1224 | * teardown time, no locking is required. It's the driver's job to ensure that |
| 1225 | * this guarantee actually holds true. |
| 1226 | * |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 1227 | * FIXME: cleanup any dangling user buffer objects too |
| 1228 | */ |
| 1229 | void drm_mode_config_cleanup(struct drm_device *dev) |
| 1230 | { |
| 1231 | struct drm_connector *connector, *ot; |
| 1232 | struct drm_crtc *crtc, *ct; |
| 1233 | struct drm_encoder *encoder, *enct; |
| 1234 | struct drm_framebuffer *fb, *fbt; |
| 1235 | struct drm_property *property, *pt; |
Jesse Barnes | 8cf5c91 | 2011-11-14 14:51:27 -0800 | [diff] [blame] | 1236 | struct drm_plane *plane, *plt; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 1237 | |
| 1238 | list_for_each_entry_safe(encoder, enct, &dev->mode_config.encoder_list, |
| 1239 | head) { |
| 1240 | encoder->funcs->destroy(encoder); |
| 1241 | } |
| 1242 | |
| 1243 | list_for_each_entry_safe(connector, ot, |
| 1244 | &dev->mode_config.connector_list, head) { |
| 1245 | connector->funcs->destroy(connector); |
| 1246 | } |
| 1247 | |
| 1248 | list_for_each_entry_safe(property, pt, &dev->mode_config.property_list, |
| 1249 | head) { |
| 1250 | drm_property_destroy(dev, property); |
| 1251 | } |
| 1252 | |
Daniel Vetter | 2b677e8 | 2012-12-10 21:16:05 +0100 | [diff] [blame] | 1253 | /* |
| 1254 | * Single-threaded teardown context, so it's not required to grab the |
Daniel Vetter | 4b096ac | 2012-12-10 21:19:18 +0100 | [diff] [blame] | 1255 | * fb_lock to protect against concurrent fb_list access. Contrary, it |
Daniel Vetter | 2b677e8 | 2012-12-10 21:16:05 +0100 | [diff] [blame] | 1256 | * would actually deadlock with the drm_framebuffer_cleanup function. |
| 1257 | * |
| 1258 | * Also, if there are any framebuffers left, that's a driver leak now, |
| 1259 | * so politely WARN about this. |
| 1260 | */ |
| 1261 | WARN_ON(!list_empty(&dev->mode_config.fb_list)); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 1262 | list_for_each_entry_safe(fb, fbt, &dev->mode_config.fb_list, head) { |
Rob Clark | f7eff60 | 2012-09-05 21:48:38 +0000 | [diff] [blame] | 1263 | drm_framebuffer_remove(fb); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 1264 | } |
| 1265 | |
Jesse Barnes | 8cf5c91 | 2011-11-14 14:51:27 -0800 | [diff] [blame] | 1266 | list_for_each_entry_safe(plane, plt, &dev->mode_config.plane_list, |
| 1267 | head) { |
| 1268 | plane->funcs->destroy(plane); |
| 1269 | } |
Sascha Hauer | 59ce062 | 2012-02-01 11:38:20 +0100 | [diff] [blame] | 1270 | |
Chris Wilson | 3184009 | 2012-09-17 09:38:03 +0000 | [diff] [blame] | 1271 | list_for_each_entry_safe(crtc, ct, &dev->mode_config.crtc_list, head) { |
| 1272 | crtc->funcs->destroy(crtc); |
| 1273 | } |
| 1274 | |
Sascha Hauer | 59ce062 | 2012-02-01 11:38:20 +0100 | [diff] [blame] | 1275 | idr_remove_all(&dev->mode_config.crtc_idr); |
| 1276 | idr_destroy(&dev->mode_config.crtc_idr); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 1277 | } |
| 1278 | EXPORT_SYMBOL(drm_mode_config_cleanup); |
| 1279 | |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 1280 | /** |
| 1281 | * drm_crtc_convert_to_umode - convert a drm_display_mode into a modeinfo |
| 1282 | * @out: drm_mode_modeinfo struct to return to the user |
| 1283 | * @in: drm_display_mode to use |
| 1284 | * |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 1285 | * Convert a drm_display_mode into a drm_mode_modeinfo structure to return to |
| 1286 | * the user. |
| 1287 | */ |
Ville Syrjälä | 93bbf6d | 2012-03-13 12:35:47 +0200 | [diff] [blame] | 1288 | static void drm_crtc_convert_to_umode(struct drm_mode_modeinfo *out, |
| 1289 | const struct drm_display_mode *in) |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 1290 | { |
Ville Syrjälä | e36fae3 | 2012-03-13 12:35:40 +0200 | [diff] [blame] | 1291 | WARN(in->hdisplay > USHRT_MAX || in->hsync_start > USHRT_MAX || |
| 1292 | in->hsync_end > USHRT_MAX || in->htotal > USHRT_MAX || |
| 1293 | in->hskew > USHRT_MAX || in->vdisplay > USHRT_MAX || |
| 1294 | in->vsync_start > USHRT_MAX || in->vsync_end > USHRT_MAX || |
| 1295 | in->vtotal > USHRT_MAX || in->vscan > USHRT_MAX, |
| 1296 | "timing values too large for mode info\n"); |
| 1297 | |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 1298 | out->clock = in->clock; |
| 1299 | out->hdisplay = in->hdisplay; |
| 1300 | out->hsync_start = in->hsync_start; |
| 1301 | out->hsync_end = in->hsync_end; |
| 1302 | out->htotal = in->htotal; |
| 1303 | out->hskew = in->hskew; |
| 1304 | out->vdisplay = in->vdisplay; |
| 1305 | out->vsync_start = in->vsync_start; |
| 1306 | out->vsync_end = in->vsync_end; |
| 1307 | out->vtotal = in->vtotal; |
| 1308 | out->vscan = in->vscan; |
| 1309 | out->vrefresh = in->vrefresh; |
| 1310 | out->flags = in->flags; |
| 1311 | out->type = in->type; |
| 1312 | strncpy(out->name, in->name, DRM_DISPLAY_MODE_LEN); |
| 1313 | out->name[DRM_DISPLAY_MODE_LEN-1] = 0; |
| 1314 | } |
| 1315 | |
| 1316 | /** |
| 1317 | * drm_crtc_convert_to_umode - convert a modeinfo into a drm_display_mode |
| 1318 | * @out: drm_display_mode to return to the user |
| 1319 | * @in: drm_mode_modeinfo to use |
| 1320 | * |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 1321 | * Convert a drm_mode_modeinfo into a drm_display_mode structure to return to |
| 1322 | * the caller. |
Ville Syrjälä | 90367bf | 2012-03-13 12:35:44 +0200 | [diff] [blame] | 1323 | * |
| 1324 | * RETURNS: |
| 1325 | * Zero on success, errno on failure. |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 1326 | */ |
Ville Syrjälä | 93bbf6d | 2012-03-13 12:35:47 +0200 | [diff] [blame] | 1327 | static int drm_crtc_convert_umode(struct drm_display_mode *out, |
| 1328 | const struct drm_mode_modeinfo *in) |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 1329 | { |
Ville Syrjälä | 90367bf | 2012-03-13 12:35:44 +0200 | [diff] [blame] | 1330 | if (in->clock > INT_MAX || in->vrefresh > INT_MAX) |
| 1331 | return -ERANGE; |
| 1332 | |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 1333 | out->clock = in->clock; |
| 1334 | out->hdisplay = in->hdisplay; |
| 1335 | out->hsync_start = in->hsync_start; |
| 1336 | out->hsync_end = in->hsync_end; |
| 1337 | out->htotal = in->htotal; |
| 1338 | out->hskew = in->hskew; |
| 1339 | out->vdisplay = in->vdisplay; |
| 1340 | out->vsync_start = in->vsync_start; |
| 1341 | out->vsync_end = in->vsync_end; |
| 1342 | out->vtotal = in->vtotal; |
| 1343 | out->vscan = in->vscan; |
| 1344 | out->vrefresh = in->vrefresh; |
| 1345 | out->flags = in->flags; |
| 1346 | out->type = in->type; |
| 1347 | strncpy(out->name, in->name, DRM_DISPLAY_MODE_LEN); |
| 1348 | out->name[DRM_DISPLAY_MODE_LEN-1] = 0; |
Ville Syrjälä | 90367bf | 2012-03-13 12:35:44 +0200 | [diff] [blame] | 1349 | |
| 1350 | return 0; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 1351 | } |
| 1352 | |
| 1353 | /** |
| 1354 | * drm_mode_getresources - get graphics configuration |
Daniel Vetter | 065a50ed | 2012-12-02 00:09:18 +0100 | [diff] [blame] | 1355 | * @dev: drm device for the ioctl |
| 1356 | * @data: data pointer for the ioctl |
| 1357 | * @file_priv: drm file for the ioctl call |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 1358 | * |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 1359 | * Construct a set of configuration description structures and return |
| 1360 | * them to the user, including CRTC, connector and framebuffer configuration. |
| 1361 | * |
| 1362 | * Called by the user via ioctl. |
| 1363 | * |
| 1364 | * RETURNS: |
| 1365 | * Zero on success, errno on failure. |
| 1366 | */ |
| 1367 | int drm_mode_getresources(struct drm_device *dev, void *data, |
| 1368 | struct drm_file *file_priv) |
| 1369 | { |
| 1370 | struct drm_mode_card_res *card_res = data; |
| 1371 | struct list_head *lh; |
| 1372 | struct drm_framebuffer *fb; |
| 1373 | struct drm_connector *connector; |
| 1374 | struct drm_crtc *crtc; |
| 1375 | struct drm_encoder *encoder; |
| 1376 | int ret = 0; |
| 1377 | int connector_count = 0; |
| 1378 | int crtc_count = 0; |
| 1379 | int fb_count = 0; |
| 1380 | int encoder_count = 0; |
| 1381 | int copied = 0, i; |
| 1382 | uint32_t __user *fb_id; |
| 1383 | uint32_t __user *crtc_id; |
| 1384 | uint32_t __user *connector_id; |
| 1385 | uint32_t __user *encoder_id; |
| 1386 | struct drm_mode_group *mode_group; |
| 1387 | |
Dave Airlie | fb3b06c | 2011-02-08 13:55:21 +1000 | [diff] [blame] | 1388 | if (!drm_core_check_feature(dev, DRIVER_MODESET)) |
| 1389 | return -EINVAL; |
| 1390 | |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 1391 | |
Daniel Vetter | 4b096ac | 2012-12-10 21:19:18 +0100 | [diff] [blame] | 1392 | mutex_lock(&file_priv->fbs_lock); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 1393 | /* |
| 1394 | * For the non-control nodes we need to limit the list of resources |
| 1395 | * by IDs in the group list for this node |
| 1396 | */ |
| 1397 | list_for_each(lh, &file_priv->fbs) |
| 1398 | fb_count++; |
| 1399 | |
Daniel Vetter | 4b096ac | 2012-12-10 21:19:18 +0100 | [diff] [blame] | 1400 | /* handle this in 4 parts */ |
| 1401 | /* FBs */ |
| 1402 | if (card_res->count_fbs >= fb_count) { |
| 1403 | copied = 0; |
| 1404 | fb_id = (uint32_t __user *)(unsigned long)card_res->fb_id_ptr; |
| 1405 | list_for_each_entry(fb, &file_priv->fbs, filp_head) { |
| 1406 | if (put_user(fb->base.id, fb_id + copied)) { |
| 1407 | mutex_unlock(&file_priv->fbs_lock); |
| 1408 | return -EFAULT; |
| 1409 | } |
| 1410 | copied++; |
| 1411 | } |
| 1412 | } |
| 1413 | card_res->count_fbs = fb_count; |
| 1414 | mutex_unlock(&file_priv->fbs_lock); |
| 1415 | |
| 1416 | drm_modeset_lock_all(dev); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 1417 | mode_group = &file_priv->master->minor->mode_group; |
| 1418 | if (file_priv->master->minor->type == DRM_MINOR_CONTROL) { |
| 1419 | |
| 1420 | list_for_each(lh, &dev->mode_config.crtc_list) |
| 1421 | crtc_count++; |
| 1422 | |
| 1423 | list_for_each(lh, &dev->mode_config.connector_list) |
| 1424 | connector_count++; |
| 1425 | |
| 1426 | list_for_each(lh, &dev->mode_config.encoder_list) |
| 1427 | encoder_count++; |
| 1428 | } else { |
| 1429 | |
| 1430 | crtc_count = mode_group->num_crtcs; |
| 1431 | connector_count = mode_group->num_connectors; |
| 1432 | encoder_count = mode_group->num_encoders; |
| 1433 | } |
| 1434 | |
| 1435 | card_res->max_height = dev->mode_config.max_height; |
| 1436 | card_res->min_height = dev->mode_config.min_height; |
| 1437 | card_res->max_width = dev->mode_config.max_width; |
| 1438 | card_res->min_width = dev->mode_config.min_width; |
| 1439 | |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 1440 | /* CRTCs */ |
| 1441 | if (card_res->count_crtcs >= crtc_count) { |
| 1442 | copied = 0; |
| 1443 | crtc_id = (uint32_t __user *)(unsigned long)card_res->crtc_id_ptr; |
| 1444 | if (file_priv->master->minor->type == DRM_MINOR_CONTROL) { |
| 1445 | list_for_each_entry(crtc, &dev->mode_config.crtc_list, |
| 1446 | head) { |
Jerome Glisse | 9440106 | 2010-07-15 15:43:25 -0400 | [diff] [blame] | 1447 | DRM_DEBUG_KMS("[CRTC:%d]\n", crtc->base.id); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 1448 | if (put_user(crtc->base.id, crtc_id + copied)) { |
| 1449 | ret = -EFAULT; |
| 1450 | goto out; |
| 1451 | } |
| 1452 | copied++; |
| 1453 | } |
| 1454 | } else { |
| 1455 | for (i = 0; i < mode_group->num_crtcs; i++) { |
| 1456 | if (put_user(mode_group->id_list[i], |
| 1457 | crtc_id + copied)) { |
| 1458 | ret = -EFAULT; |
| 1459 | goto out; |
| 1460 | } |
| 1461 | copied++; |
| 1462 | } |
| 1463 | } |
| 1464 | } |
| 1465 | card_res->count_crtcs = crtc_count; |
| 1466 | |
| 1467 | /* Encoders */ |
| 1468 | if (card_res->count_encoders >= encoder_count) { |
| 1469 | copied = 0; |
| 1470 | encoder_id = (uint32_t __user *)(unsigned long)card_res->encoder_id_ptr; |
| 1471 | if (file_priv->master->minor->type == DRM_MINOR_CONTROL) { |
| 1472 | list_for_each_entry(encoder, |
| 1473 | &dev->mode_config.encoder_list, |
| 1474 | head) { |
Jerome Glisse | 9440106 | 2010-07-15 15:43:25 -0400 | [diff] [blame] | 1475 | DRM_DEBUG_KMS("[ENCODER:%d:%s]\n", encoder->base.id, |
| 1476 | drm_get_encoder_name(encoder)); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 1477 | if (put_user(encoder->base.id, encoder_id + |
| 1478 | copied)) { |
| 1479 | ret = -EFAULT; |
| 1480 | goto out; |
| 1481 | } |
| 1482 | copied++; |
| 1483 | } |
| 1484 | } else { |
| 1485 | for (i = mode_group->num_crtcs; i < mode_group->num_crtcs + mode_group->num_encoders; i++) { |
| 1486 | if (put_user(mode_group->id_list[i], |
| 1487 | encoder_id + copied)) { |
| 1488 | ret = -EFAULT; |
| 1489 | goto out; |
| 1490 | } |
| 1491 | copied++; |
| 1492 | } |
| 1493 | |
| 1494 | } |
| 1495 | } |
| 1496 | card_res->count_encoders = encoder_count; |
| 1497 | |
| 1498 | /* Connectors */ |
| 1499 | if (card_res->count_connectors >= connector_count) { |
| 1500 | copied = 0; |
| 1501 | connector_id = (uint32_t __user *)(unsigned long)card_res->connector_id_ptr; |
| 1502 | if (file_priv->master->minor->type == DRM_MINOR_CONTROL) { |
| 1503 | list_for_each_entry(connector, |
| 1504 | &dev->mode_config.connector_list, |
| 1505 | head) { |
Jerome Glisse | 9440106 | 2010-07-15 15:43:25 -0400 | [diff] [blame] | 1506 | DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n", |
| 1507 | connector->base.id, |
| 1508 | drm_get_connector_name(connector)); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 1509 | if (put_user(connector->base.id, |
| 1510 | connector_id + copied)) { |
| 1511 | ret = -EFAULT; |
| 1512 | goto out; |
| 1513 | } |
| 1514 | copied++; |
| 1515 | } |
| 1516 | } else { |
| 1517 | int start = mode_group->num_crtcs + |
| 1518 | mode_group->num_encoders; |
| 1519 | for (i = start; i < start + mode_group->num_connectors; i++) { |
| 1520 | if (put_user(mode_group->id_list[i], |
| 1521 | connector_id + copied)) { |
| 1522 | ret = -EFAULT; |
| 1523 | goto out; |
| 1524 | } |
| 1525 | copied++; |
| 1526 | } |
| 1527 | } |
| 1528 | } |
| 1529 | card_res->count_connectors = connector_count; |
| 1530 | |
Jerome Glisse | 9440106 | 2010-07-15 15:43:25 -0400 | [diff] [blame] | 1531 | 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] | 1532 | card_res->count_connectors, card_res->count_encoders); |
| 1533 | |
| 1534 | out: |
Daniel Vetter | 8484990 | 2012-12-02 00:28:11 +0100 | [diff] [blame] | 1535 | drm_modeset_unlock_all(dev); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 1536 | return ret; |
| 1537 | } |
| 1538 | |
| 1539 | /** |
| 1540 | * drm_mode_getcrtc - get CRTC configuration |
Daniel Vetter | 065a50ed | 2012-12-02 00:09:18 +0100 | [diff] [blame] | 1541 | * @dev: drm device for the ioctl |
| 1542 | * @data: data pointer for the ioctl |
| 1543 | * @file_priv: drm file for the ioctl call |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 1544 | * |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 1545 | * Construct a CRTC configuration structure to return to the user. |
| 1546 | * |
| 1547 | * Called by the user via ioctl. |
| 1548 | * |
| 1549 | * RETURNS: |
| 1550 | * Zero on success, errno on failure. |
| 1551 | */ |
| 1552 | int drm_mode_getcrtc(struct drm_device *dev, |
| 1553 | void *data, struct drm_file *file_priv) |
| 1554 | { |
| 1555 | struct drm_mode_crtc *crtc_resp = data; |
| 1556 | struct drm_crtc *crtc; |
| 1557 | struct drm_mode_object *obj; |
| 1558 | int ret = 0; |
| 1559 | |
Dave Airlie | fb3b06c | 2011-02-08 13:55:21 +1000 | [diff] [blame] | 1560 | if (!drm_core_check_feature(dev, DRIVER_MODESET)) |
| 1561 | return -EINVAL; |
| 1562 | |
Daniel Vetter | 8484990 | 2012-12-02 00:28:11 +0100 | [diff] [blame] | 1563 | drm_modeset_lock_all(dev); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 1564 | |
| 1565 | obj = drm_mode_object_find(dev, crtc_resp->crtc_id, |
| 1566 | DRM_MODE_OBJECT_CRTC); |
| 1567 | if (!obj) { |
| 1568 | ret = -EINVAL; |
| 1569 | goto out; |
| 1570 | } |
| 1571 | crtc = obj_to_crtc(obj); |
| 1572 | |
| 1573 | crtc_resp->x = crtc->x; |
| 1574 | crtc_resp->y = crtc->y; |
| 1575 | crtc_resp->gamma_size = crtc->gamma_size; |
| 1576 | if (crtc->fb) |
| 1577 | crtc_resp->fb_id = crtc->fb->base.id; |
| 1578 | else |
| 1579 | crtc_resp->fb_id = 0; |
| 1580 | |
| 1581 | if (crtc->enabled) { |
| 1582 | |
| 1583 | drm_crtc_convert_to_umode(&crtc_resp->mode, &crtc->mode); |
| 1584 | crtc_resp->mode_valid = 1; |
| 1585 | |
| 1586 | } else { |
| 1587 | crtc_resp->mode_valid = 0; |
| 1588 | } |
| 1589 | |
| 1590 | out: |
Daniel Vetter | 8484990 | 2012-12-02 00:28:11 +0100 | [diff] [blame] | 1591 | drm_modeset_unlock_all(dev); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 1592 | return ret; |
| 1593 | } |
| 1594 | |
| 1595 | /** |
| 1596 | * drm_mode_getconnector - get connector configuration |
Daniel Vetter | 065a50ed | 2012-12-02 00:09:18 +0100 | [diff] [blame] | 1597 | * @dev: drm device for the ioctl |
| 1598 | * @data: data pointer for the ioctl |
| 1599 | * @file_priv: drm file for the ioctl call |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 1600 | * |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 1601 | * Construct a connector configuration structure to return to the user. |
| 1602 | * |
| 1603 | * Called by the user via ioctl. |
| 1604 | * |
| 1605 | * RETURNS: |
| 1606 | * Zero on success, errno on failure. |
| 1607 | */ |
| 1608 | int drm_mode_getconnector(struct drm_device *dev, void *data, |
| 1609 | struct drm_file *file_priv) |
| 1610 | { |
| 1611 | struct drm_mode_get_connector *out_resp = data; |
| 1612 | struct drm_mode_object *obj; |
| 1613 | struct drm_connector *connector; |
| 1614 | struct drm_display_mode *mode; |
| 1615 | int mode_count = 0; |
| 1616 | int props_count = 0; |
| 1617 | int encoders_count = 0; |
| 1618 | int ret = 0; |
| 1619 | int copied = 0; |
| 1620 | int i; |
| 1621 | struct drm_mode_modeinfo u_mode; |
| 1622 | struct drm_mode_modeinfo __user *mode_ptr; |
| 1623 | uint32_t __user *prop_ptr; |
| 1624 | uint64_t __user *prop_values; |
| 1625 | uint32_t __user *encoder_ptr; |
| 1626 | |
Dave Airlie | fb3b06c | 2011-02-08 13:55:21 +1000 | [diff] [blame] | 1627 | if (!drm_core_check_feature(dev, DRIVER_MODESET)) |
| 1628 | return -EINVAL; |
| 1629 | |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 1630 | memset(&u_mode, 0, sizeof(struct drm_mode_modeinfo)); |
| 1631 | |
Jerome Glisse | 9440106 | 2010-07-15 15:43:25 -0400 | [diff] [blame] | 1632 | DRM_DEBUG_KMS("[CONNECTOR:%d:?]\n", out_resp->connector_id); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 1633 | |
Daniel Vetter | 7b24056 | 2012-12-12 00:35:33 +0100 | [diff] [blame] | 1634 | mutex_lock(&dev->mode_config.mutex); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 1635 | |
| 1636 | obj = drm_mode_object_find(dev, out_resp->connector_id, |
| 1637 | DRM_MODE_OBJECT_CONNECTOR); |
| 1638 | if (!obj) { |
| 1639 | ret = -EINVAL; |
| 1640 | goto out; |
| 1641 | } |
| 1642 | connector = obj_to_connector(obj); |
| 1643 | |
Paulo Zanoni | 7f88a9b | 2012-05-15 18:09:04 -0300 | [diff] [blame] | 1644 | props_count = connector->properties.count; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 1645 | |
| 1646 | for (i = 0; i < DRM_CONNECTOR_MAX_ENCODER; i++) { |
| 1647 | if (connector->encoder_ids[i] != 0) { |
| 1648 | encoders_count++; |
| 1649 | } |
| 1650 | } |
| 1651 | |
| 1652 | if (out_resp->count_modes == 0) { |
| 1653 | connector->funcs->fill_modes(connector, |
| 1654 | dev->mode_config.max_width, |
| 1655 | dev->mode_config.max_height); |
| 1656 | } |
| 1657 | |
| 1658 | /* delayed so we get modes regardless of pre-fill_modes state */ |
| 1659 | list_for_each_entry(mode, &connector->modes, head) |
| 1660 | mode_count++; |
| 1661 | |
| 1662 | out_resp->connector_id = connector->base.id; |
| 1663 | out_resp->connector_type = connector->connector_type; |
| 1664 | out_resp->connector_type_id = connector->connector_type_id; |
| 1665 | out_resp->mm_width = connector->display_info.width_mm; |
| 1666 | out_resp->mm_height = connector->display_info.height_mm; |
| 1667 | out_resp->subpixel = connector->display_info.subpixel_order; |
| 1668 | out_resp->connection = connector->status; |
| 1669 | if (connector->encoder) |
| 1670 | out_resp->encoder_id = connector->encoder->base.id; |
| 1671 | else |
| 1672 | out_resp->encoder_id = 0; |
| 1673 | |
| 1674 | /* |
| 1675 | * This ioctl is called twice, once to determine how much space is |
| 1676 | * needed, and the 2nd time to fill it. |
| 1677 | */ |
| 1678 | if ((out_resp->count_modes >= mode_count) && mode_count) { |
| 1679 | copied = 0; |
Ville Syrjälä | 81f6c7f | 2011-12-20 00:06:42 +0200 | [diff] [blame] | 1680 | 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] | 1681 | list_for_each_entry(mode, &connector->modes, head) { |
| 1682 | drm_crtc_convert_to_umode(&u_mode, mode); |
| 1683 | if (copy_to_user(mode_ptr + copied, |
| 1684 | &u_mode, sizeof(u_mode))) { |
| 1685 | ret = -EFAULT; |
| 1686 | goto out; |
| 1687 | } |
| 1688 | copied++; |
| 1689 | } |
| 1690 | } |
| 1691 | out_resp->count_modes = mode_count; |
| 1692 | |
| 1693 | if ((out_resp->count_props >= props_count) && props_count) { |
| 1694 | copied = 0; |
Ville Syrjälä | 81f6c7f | 2011-12-20 00:06:42 +0200 | [diff] [blame] | 1695 | prop_ptr = (uint32_t __user *)(unsigned long)(out_resp->props_ptr); |
| 1696 | prop_values = (uint64_t __user *)(unsigned long)(out_resp->prop_values_ptr); |
Paulo Zanoni | 7f88a9b | 2012-05-15 18:09:04 -0300 | [diff] [blame] | 1697 | for (i = 0; i < connector->properties.count; i++) { |
| 1698 | if (put_user(connector->properties.ids[i], |
| 1699 | prop_ptr + copied)) { |
| 1700 | ret = -EFAULT; |
| 1701 | goto out; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 1702 | } |
Paulo Zanoni | 7f88a9b | 2012-05-15 18:09:04 -0300 | [diff] [blame] | 1703 | |
| 1704 | if (put_user(connector->properties.values[i], |
| 1705 | prop_values + copied)) { |
| 1706 | ret = -EFAULT; |
| 1707 | goto out; |
| 1708 | } |
| 1709 | copied++; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 1710 | } |
| 1711 | } |
| 1712 | out_resp->count_props = props_count; |
| 1713 | |
| 1714 | if ((out_resp->count_encoders >= encoders_count) && encoders_count) { |
| 1715 | copied = 0; |
Ville Syrjälä | 81f6c7f | 2011-12-20 00:06:42 +0200 | [diff] [blame] | 1716 | encoder_ptr = (uint32_t __user *)(unsigned long)(out_resp->encoders_ptr); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 1717 | for (i = 0; i < DRM_CONNECTOR_MAX_ENCODER; i++) { |
| 1718 | if (connector->encoder_ids[i] != 0) { |
| 1719 | if (put_user(connector->encoder_ids[i], |
| 1720 | encoder_ptr + copied)) { |
| 1721 | ret = -EFAULT; |
| 1722 | goto out; |
| 1723 | } |
| 1724 | copied++; |
| 1725 | } |
| 1726 | } |
| 1727 | } |
| 1728 | out_resp->count_encoders = encoders_count; |
| 1729 | |
| 1730 | out: |
Daniel Vetter | 7b24056 | 2012-12-12 00:35:33 +0100 | [diff] [blame] | 1731 | mutex_unlock(&dev->mode_config.mutex); |
| 1732 | |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 1733 | return ret; |
| 1734 | } |
| 1735 | |
| 1736 | int drm_mode_getencoder(struct drm_device *dev, void *data, |
| 1737 | struct drm_file *file_priv) |
| 1738 | { |
| 1739 | struct drm_mode_get_encoder *enc_resp = data; |
| 1740 | struct drm_mode_object *obj; |
| 1741 | struct drm_encoder *encoder; |
| 1742 | int ret = 0; |
| 1743 | |
Dave Airlie | fb3b06c | 2011-02-08 13:55:21 +1000 | [diff] [blame] | 1744 | if (!drm_core_check_feature(dev, DRIVER_MODESET)) |
| 1745 | return -EINVAL; |
| 1746 | |
Daniel Vetter | 8484990 | 2012-12-02 00:28:11 +0100 | [diff] [blame] | 1747 | drm_modeset_lock_all(dev); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 1748 | obj = drm_mode_object_find(dev, enc_resp->encoder_id, |
| 1749 | DRM_MODE_OBJECT_ENCODER); |
| 1750 | if (!obj) { |
| 1751 | ret = -EINVAL; |
| 1752 | goto out; |
| 1753 | } |
| 1754 | encoder = obj_to_encoder(obj); |
| 1755 | |
| 1756 | if (encoder->crtc) |
| 1757 | enc_resp->crtc_id = encoder->crtc->base.id; |
| 1758 | else |
| 1759 | enc_resp->crtc_id = 0; |
| 1760 | enc_resp->encoder_type = encoder->encoder_type; |
| 1761 | enc_resp->encoder_id = encoder->base.id; |
| 1762 | enc_resp->possible_crtcs = encoder->possible_crtcs; |
| 1763 | enc_resp->possible_clones = encoder->possible_clones; |
| 1764 | |
| 1765 | out: |
Daniel Vetter | 8484990 | 2012-12-02 00:28:11 +0100 | [diff] [blame] | 1766 | drm_modeset_unlock_all(dev); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 1767 | return ret; |
| 1768 | } |
| 1769 | |
| 1770 | /** |
Jesse Barnes | 8cf5c91 | 2011-11-14 14:51:27 -0800 | [diff] [blame] | 1771 | * drm_mode_getplane_res - get plane info |
| 1772 | * @dev: DRM device |
| 1773 | * @data: ioctl data |
| 1774 | * @file_priv: DRM file info |
| 1775 | * |
| 1776 | * Return an plane count and set of IDs. |
| 1777 | */ |
| 1778 | int drm_mode_getplane_res(struct drm_device *dev, void *data, |
| 1779 | struct drm_file *file_priv) |
| 1780 | { |
| 1781 | struct drm_mode_get_plane_res *plane_resp = data; |
| 1782 | struct drm_mode_config *config; |
| 1783 | struct drm_plane *plane; |
| 1784 | uint32_t __user *plane_ptr; |
| 1785 | int copied = 0, ret = 0; |
| 1786 | |
| 1787 | if (!drm_core_check_feature(dev, DRIVER_MODESET)) |
| 1788 | return -EINVAL; |
| 1789 | |
Daniel Vetter | 8484990 | 2012-12-02 00:28:11 +0100 | [diff] [blame] | 1790 | drm_modeset_lock_all(dev); |
Jesse Barnes | 8cf5c91 | 2011-11-14 14:51:27 -0800 | [diff] [blame] | 1791 | config = &dev->mode_config; |
| 1792 | |
| 1793 | /* |
| 1794 | * This ioctl is called twice, once to determine how much space is |
| 1795 | * needed, and the 2nd time to fill it. |
| 1796 | */ |
| 1797 | if (config->num_plane && |
| 1798 | (plane_resp->count_planes >= config->num_plane)) { |
Ville Syrjälä | 81f6c7f | 2011-12-20 00:06:42 +0200 | [diff] [blame] | 1799 | plane_ptr = (uint32_t __user *)(unsigned long)plane_resp->plane_id_ptr; |
Jesse Barnes | 8cf5c91 | 2011-11-14 14:51:27 -0800 | [diff] [blame] | 1800 | |
| 1801 | list_for_each_entry(plane, &config->plane_list, head) { |
| 1802 | if (put_user(plane->base.id, plane_ptr + copied)) { |
| 1803 | ret = -EFAULT; |
| 1804 | goto out; |
| 1805 | } |
| 1806 | copied++; |
| 1807 | } |
| 1808 | } |
| 1809 | plane_resp->count_planes = config->num_plane; |
| 1810 | |
| 1811 | out: |
Daniel Vetter | 8484990 | 2012-12-02 00:28:11 +0100 | [diff] [blame] | 1812 | drm_modeset_unlock_all(dev); |
Jesse Barnes | 8cf5c91 | 2011-11-14 14:51:27 -0800 | [diff] [blame] | 1813 | return ret; |
| 1814 | } |
| 1815 | |
| 1816 | /** |
| 1817 | * drm_mode_getplane - get plane info |
| 1818 | * @dev: DRM device |
| 1819 | * @data: ioctl data |
| 1820 | * @file_priv: DRM file info |
| 1821 | * |
| 1822 | * Return plane info, including formats supported, gamma size, any |
| 1823 | * current fb, etc. |
| 1824 | */ |
| 1825 | int drm_mode_getplane(struct drm_device *dev, void *data, |
| 1826 | struct drm_file *file_priv) |
| 1827 | { |
| 1828 | struct drm_mode_get_plane *plane_resp = data; |
| 1829 | struct drm_mode_object *obj; |
| 1830 | struct drm_plane *plane; |
| 1831 | uint32_t __user *format_ptr; |
| 1832 | int ret = 0; |
| 1833 | |
| 1834 | if (!drm_core_check_feature(dev, DRIVER_MODESET)) |
| 1835 | return -EINVAL; |
| 1836 | |
Daniel Vetter | 8484990 | 2012-12-02 00:28:11 +0100 | [diff] [blame] | 1837 | drm_modeset_lock_all(dev); |
Jesse Barnes | 8cf5c91 | 2011-11-14 14:51:27 -0800 | [diff] [blame] | 1838 | obj = drm_mode_object_find(dev, plane_resp->plane_id, |
| 1839 | DRM_MODE_OBJECT_PLANE); |
| 1840 | if (!obj) { |
| 1841 | ret = -ENOENT; |
| 1842 | goto out; |
| 1843 | } |
| 1844 | plane = obj_to_plane(obj); |
| 1845 | |
| 1846 | if (plane->crtc) |
| 1847 | plane_resp->crtc_id = plane->crtc->base.id; |
| 1848 | else |
| 1849 | plane_resp->crtc_id = 0; |
| 1850 | |
| 1851 | if (plane->fb) |
| 1852 | plane_resp->fb_id = plane->fb->base.id; |
| 1853 | else |
| 1854 | plane_resp->fb_id = 0; |
| 1855 | |
| 1856 | plane_resp->plane_id = plane->base.id; |
| 1857 | plane_resp->possible_crtcs = plane->possible_crtcs; |
| 1858 | plane_resp->gamma_size = plane->gamma_size; |
| 1859 | |
| 1860 | /* |
| 1861 | * This ioctl is called twice, once to determine how much space is |
| 1862 | * needed, and the 2nd time to fill it. |
| 1863 | */ |
| 1864 | if (plane->format_count && |
| 1865 | (plane_resp->count_format_types >= plane->format_count)) { |
Ville Syrjälä | 81f6c7f | 2011-12-20 00:06:42 +0200 | [diff] [blame] | 1866 | format_ptr = (uint32_t __user *)(unsigned long)plane_resp->format_type_ptr; |
Jesse Barnes | 8cf5c91 | 2011-11-14 14:51:27 -0800 | [diff] [blame] | 1867 | if (copy_to_user(format_ptr, |
| 1868 | plane->format_types, |
| 1869 | sizeof(uint32_t) * plane->format_count)) { |
| 1870 | ret = -EFAULT; |
| 1871 | goto out; |
| 1872 | } |
| 1873 | } |
| 1874 | plane_resp->count_format_types = plane->format_count; |
| 1875 | |
| 1876 | out: |
Daniel Vetter | 8484990 | 2012-12-02 00:28:11 +0100 | [diff] [blame] | 1877 | drm_modeset_unlock_all(dev); |
Jesse Barnes | 8cf5c91 | 2011-11-14 14:51:27 -0800 | [diff] [blame] | 1878 | return ret; |
| 1879 | } |
| 1880 | |
| 1881 | /** |
| 1882 | * drm_mode_setplane - set up or tear down an plane |
| 1883 | * @dev: DRM device |
| 1884 | * @data: ioctl data* |
Daniel Vetter | 065a50ed | 2012-12-02 00:09:18 +0100 | [diff] [blame] | 1885 | * @file_priv: DRM file info |
Jesse Barnes | 8cf5c91 | 2011-11-14 14:51:27 -0800 | [diff] [blame] | 1886 | * |
| 1887 | * Set plane info, including placement, fb, scaling, and other factors. |
| 1888 | * Or pass a NULL fb to disable. |
| 1889 | */ |
| 1890 | int drm_mode_setplane(struct drm_device *dev, void *data, |
| 1891 | struct drm_file *file_priv) |
| 1892 | { |
| 1893 | struct drm_mode_set_plane *plane_req = data; |
| 1894 | struct drm_mode_object *obj; |
| 1895 | struct drm_plane *plane; |
| 1896 | struct drm_crtc *crtc; |
Daniel Vetter | 6c2a753 | 2012-12-11 00:59:24 +0100 | [diff] [blame] | 1897 | struct drm_framebuffer *fb = NULL, *old_fb = NULL; |
Jesse Barnes | 8cf5c91 | 2011-11-14 14:51:27 -0800 | [diff] [blame] | 1898 | int ret = 0; |
Ville Syrjälä | 42ef878 | 2011-12-20 00:06:44 +0200 | [diff] [blame] | 1899 | unsigned int fb_width, fb_height; |
Ville Syrjälä | 62443be | 2011-12-20 00:06:47 +0200 | [diff] [blame] | 1900 | int i; |
Jesse Barnes | 8cf5c91 | 2011-11-14 14:51:27 -0800 | [diff] [blame] | 1901 | |
| 1902 | if (!drm_core_check_feature(dev, DRIVER_MODESET)) |
| 1903 | return -EINVAL; |
| 1904 | |
Jesse Barnes | 8cf5c91 | 2011-11-14 14:51:27 -0800 | [diff] [blame] | 1905 | /* |
| 1906 | * First, find the plane, crtc, and fb objects. If not available, |
| 1907 | * we don't bother to call the driver. |
| 1908 | */ |
| 1909 | obj = drm_mode_object_find(dev, plane_req->plane_id, |
| 1910 | DRM_MODE_OBJECT_PLANE); |
| 1911 | if (!obj) { |
| 1912 | DRM_DEBUG_KMS("Unknown plane ID %d\n", |
| 1913 | plane_req->plane_id); |
Daniel Vetter | 6c2a753 | 2012-12-11 00:59:24 +0100 | [diff] [blame] | 1914 | return -ENOENT; |
Jesse Barnes | 8cf5c91 | 2011-11-14 14:51:27 -0800 | [diff] [blame] | 1915 | } |
| 1916 | plane = obj_to_plane(obj); |
| 1917 | |
| 1918 | /* No fb means shut it down */ |
| 1919 | if (!plane_req->fb_id) { |
Daniel Vetter | 6c2a753 | 2012-12-11 00:59:24 +0100 | [diff] [blame] | 1920 | drm_modeset_lock_all(dev); |
| 1921 | old_fb = plane->fb; |
Jesse Barnes | 8cf5c91 | 2011-11-14 14:51:27 -0800 | [diff] [blame] | 1922 | plane->funcs->disable_plane(plane); |
Ville Syrjälä | e5e3b44 | 2011-12-20 00:06:43 +0200 | [diff] [blame] | 1923 | plane->crtc = NULL; |
| 1924 | plane->fb = NULL; |
Daniel Vetter | 6c2a753 | 2012-12-11 00:59:24 +0100 | [diff] [blame] | 1925 | drm_modeset_unlock_all(dev); |
Jesse Barnes | 8cf5c91 | 2011-11-14 14:51:27 -0800 | [diff] [blame] | 1926 | goto out; |
| 1927 | } |
| 1928 | |
| 1929 | obj = drm_mode_object_find(dev, plane_req->crtc_id, |
| 1930 | DRM_MODE_OBJECT_CRTC); |
| 1931 | if (!obj) { |
| 1932 | DRM_DEBUG_KMS("Unknown crtc ID %d\n", |
| 1933 | plane_req->crtc_id); |
| 1934 | ret = -ENOENT; |
| 1935 | goto out; |
| 1936 | } |
| 1937 | crtc = obj_to_crtc(obj); |
| 1938 | |
Daniel Vetter | 786b99e | 2012-12-02 21:53:40 +0100 | [diff] [blame] | 1939 | fb = drm_framebuffer_lookup(dev, plane_req->fb_id); |
| 1940 | if (!fb) { |
Jesse Barnes | 8cf5c91 | 2011-11-14 14:51:27 -0800 | [diff] [blame] | 1941 | DRM_DEBUG_KMS("Unknown framebuffer ID %d\n", |
| 1942 | plane_req->fb_id); |
| 1943 | ret = -ENOENT; |
| 1944 | goto out; |
| 1945 | } |
Jesse Barnes | 8cf5c91 | 2011-11-14 14:51:27 -0800 | [diff] [blame] | 1946 | |
Ville Syrjälä | 62443be | 2011-12-20 00:06:47 +0200 | [diff] [blame] | 1947 | /* Check whether this plane supports the fb pixel format. */ |
| 1948 | for (i = 0; i < plane->format_count; i++) |
| 1949 | if (fb->pixel_format == plane->format_types[i]) |
| 1950 | break; |
| 1951 | if (i == plane->format_count) { |
| 1952 | DRM_DEBUG_KMS("Invalid pixel format 0x%08x\n", fb->pixel_format); |
| 1953 | ret = -EINVAL; |
| 1954 | goto out; |
| 1955 | } |
| 1956 | |
Ville Syrjälä | 42ef878 | 2011-12-20 00:06:44 +0200 | [diff] [blame] | 1957 | fb_width = fb->width << 16; |
| 1958 | fb_height = fb->height << 16; |
| 1959 | |
| 1960 | /* Make sure source coordinates are inside the fb. */ |
| 1961 | if (plane_req->src_w > fb_width || |
| 1962 | plane_req->src_x > fb_width - plane_req->src_w || |
| 1963 | plane_req->src_h > fb_height || |
| 1964 | plane_req->src_y > fb_height - plane_req->src_h) { |
| 1965 | DRM_DEBUG_KMS("Invalid source coordinates " |
| 1966 | "%u.%06ux%u.%06u+%u.%06u+%u.%06u\n", |
| 1967 | plane_req->src_w >> 16, |
| 1968 | ((plane_req->src_w & 0xffff) * 15625) >> 10, |
| 1969 | plane_req->src_h >> 16, |
| 1970 | ((plane_req->src_h & 0xffff) * 15625) >> 10, |
| 1971 | plane_req->src_x >> 16, |
| 1972 | ((plane_req->src_x & 0xffff) * 15625) >> 10, |
| 1973 | plane_req->src_y >> 16, |
| 1974 | ((plane_req->src_y & 0xffff) * 15625) >> 10); |
| 1975 | ret = -ENOSPC; |
| 1976 | goto out; |
| 1977 | } |
| 1978 | |
Ville Syrjälä | 687a040 | 2011-12-20 00:06:45 +0200 | [diff] [blame] | 1979 | /* Give drivers some help against integer overflows */ |
| 1980 | if (plane_req->crtc_w > INT_MAX || |
| 1981 | plane_req->crtc_x > INT_MAX - (int32_t) plane_req->crtc_w || |
| 1982 | plane_req->crtc_h > INT_MAX || |
| 1983 | plane_req->crtc_y > INT_MAX - (int32_t) plane_req->crtc_h) { |
| 1984 | DRM_DEBUG_KMS("Invalid CRTC coordinates %ux%u+%d+%d\n", |
| 1985 | plane_req->crtc_w, plane_req->crtc_h, |
| 1986 | plane_req->crtc_x, plane_req->crtc_y); |
| 1987 | ret = -ERANGE; |
| 1988 | goto out; |
| 1989 | } |
| 1990 | |
Daniel Vetter | 6c2a753 | 2012-12-11 00:59:24 +0100 | [diff] [blame] | 1991 | drm_modeset_lock_all(dev); |
Jesse Barnes | 8cf5c91 | 2011-11-14 14:51:27 -0800 | [diff] [blame] | 1992 | ret = plane->funcs->update_plane(plane, crtc, fb, |
| 1993 | plane_req->crtc_x, plane_req->crtc_y, |
| 1994 | plane_req->crtc_w, plane_req->crtc_h, |
| 1995 | plane_req->src_x, plane_req->src_y, |
| 1996 | plane_req->src_w, plane_req->src_h); |
| 1997 | if (!ret) { |
Daniel Vetter | 6c2a753 | 2012-12-11 00:59:24 +0100 | [diff] [blame] | 1998 | old_fb = plane->fb; |
Jesse Barnes | 8cf5c91 | 2011-11-14 14:51:27 -0800 | [diff] [blame] | 1999 | plane->crtc = crtc; |
| 2000 | plane->fb = fb; |
Daniel Vetter | 35f8bad | 2013-02-15 21:21:37 +0100 | [diff] [blame^] | 2001 | fb = NULL; |
Jesse Barnes | 8cf5c91 | 2011-11-14 14:51:27 -0800 | [diff] [blame] | 2002 | } |
Daniel Vetter | 6c2a753 | 2012-12-11 00:59:24 +0100 | [diff] [blame] | 2003 | drm_modeset_unlock_all(dev); |
Jesse Barnes | 8cf5c91 | 2011-11-14 14:51:27 -0800 | [diff] [blame] | 2004 | |
| 2005 | out: |
Daniel Vetter | 6c2a753 | 2012-12-11 00:59:24 +0100 | [diff] [blame] | 2006 | if (fb) |
| 2007 | drm_framebuffer_unreference(fb); |
| 2008 | if (old_fb) |
| 2009 | drm_framebuffer_unreference(old_fb); |
Jesse Barnes | 8cf5c91 | 2011-11-14 14:51:27 -0800 | [diff] [blame] | 2010 | |
| 2011 | return ret; |
| 2012 | } |
| 2013 | |
| 2014 | /** |
Daniel Vetter | 2d13b67 | 2012-12-11 13:47:23 +0100 | [diff] [blame] | 2015 | * drm_mode_set_config_internal - helper to call ->set_config |
| 2016 | * @set: modeset config to set |
| 2017 | * |
| 2018 | * This is a little helper to wrap internal calls to the ->set_config driver |
| 2019 | * interface. The only thing it adds is correct refcounting dance. |
| 2020 | */ |
| 2021 | int drm_mode_set_config_internal(struct drm_mode_set *set) |
| 2022 | { |
| 2023 | struct drm_crtc *crtc = set->crtc; |
Daniel Vetter | b0d1232 | 2012-12-11 01:07:12 +0100 | [diff] [blame] | 2024 | struct drm_framebuffer *fb, *old_fb; |
| 2025 | int ret; |
Daniel Vetter | 2d13b67 | 2012-12-11 13:47:23 +0100 | [diff] [blame] | 2026 | |
Daniel Vetter | b0d1232 | 2012-12-11 01:07:12 +0100 | [diff] [blame] | 2027 | old_fb = crtc->fb; |
| 2028 | fb = set->fb; |
| 2029 | |
| 2030 | ret = crtc->funcs->set_config(set); |
| 2031 | if (ret == 0) { |
| 2032 | if (old_fb) |
| 2033 | drm_framebuffer_unreference(old_fb); |
| 2034 | if (fb) |
| 2035 | drm_framebuffer_reference(fb); |
| 2036 | } |
| 2037 | |
| 2038 | return ret; |
Daniel Vetter | 2d13b67 | 2012-12-11 13:47:23 +0100 | [diff] [blame] | 2039 | } |
| 2040 | EXPORT_SYMBOL(drm_mode_set_config_internal); |
| 2041 | |
| 2042 | /** |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 2043 | * drm_mode_setcrtc - set CRTC configuration |
Daniel Vetter | 065a50ed | 2012-12-02 00:09:18 +0100 | [diff] [blame] | 2044 | * @dev: drm device for the ioctl |
| 2045 | * @data: data pointer for the ioctl |
| 2046 | * @file_priv: drm file for the ioctl call |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 2047 | * |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 2048 | * Build a new CRTC configuration based on user request. |
| 2049 | * |
| 2050 | * Called by the user via ioctl. |
| 2051 | * |
| 2052 | * RETURNS: |
| 2053 | * Zero on success, errno on failure. |
| 2054 | */ |
| 2055 | int drm_mode_setcrtc(struct drm_device *dev, void *data, |
| 2056 | struct drm_file *file_priv) |
| 2057 | { |
| 2058 | struct drm_mode_config *config = &dev->mode_config; |
| 2059 | struct drm_mode_crtc *crtc_req = data; |
| 2060 | struct drm_mode_object *obj; |
Ville Syrjälä | 6653cc8 | 2012-03-13 12:35:38 +0200 | [diff] [blame] | 2061 | struct drm_crtc *crtc; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 2062 | struct drm_connector **connector_set = NULL, *connector; |
| 2063 | struct drm_framebuffer *fb = NULL; |
| 2064 | struct drm_display_mode *mode = NULL; |
| 2065 | struct drm_mode_set set; |
| 2066 | uint32_t __user *set_connectors_ptr; |
Laurent Pinchart | 4a1b071 | 2012-05-17 13:27:21 +0200 | [diff] [blame] | 2067 | int ret; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 2068 | int i; |
| 2069 | |
Dave Airlie | fb3b06c | 2011-02-08 13:55:21 +1000 | [diff] [blame] | 2070 | if (!drm_core_check_feature(dev, DRIVER_MODESET)) |
| 2071 | return -EINVAL; |
| 2072 | |
Ville Syrjälä | 1d97e91 | 2012-03-13 12:35:41 +0200 | [diff] [blame] | 2073 | /* For some reason crtc x/y offsets are signed internally. */ |
| 2074 | if (crtc_req->x > INT_MAX || crtc_req->y > INT_MAX) |
| 2075 | return -ERANGE; |
| 2076 | |
Daniel Vetter | 8484990 | 2012-12-02 00:28:11 +0100 | [diff] [blame] | 2077 | drm_modeset_lock_all(dev); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 2078 | obj = drm_mode_object_find(dev, crtc_req->crtc_id, |
| 2079 | DRM_MODE_OBJECT_CRTC); |
| 2080 | if (!obj) { |
Zhao Yakui | 58367ed | 2009-07-20 13:48:07 +0800 | [diff] [blame] | 2081 | DRM_DEBUG_KMS("Unknown CRTC ID %d\n", crtc_req->crtc_id); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 2082 | ret = -EINVAL; |
| 2083 | goto out; |
| 2084 | } |
| 2085 | crtc = obj_to_crtc(obj); |
Jerome Glisse | 9440106 | 2010-07-15 15:43:25 -0400 | [diff] [blame] | 2086 | DRM_DEBUG_KMS("[CRTC:%d]\n", crtc->base.id); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 2087 | |
| 2088 | if (crtc_req->mode_valid) { |
Rob Clark | 7c80e12 | 2012-09-04 16:35:56 +0000 | [diff] [blame] | 2089 | int hdisplay, vdisplay; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 2090 | /* If we have a mode we need a framebuffer. */ |
| 2091 | /* If we pass -1, set the mode with the currently bound fb */ |
| 2092 | if (crtc_req->fb_id == -1) { |
Ville Syrjälä | 6653cc8 | 2012-03-13 12:35:38 +0200 | [diff] [blame] | 2093 | if (!crtc->fb) { |
| 2094 | DRM_DEBUG_KMS("CRTC doesn't have current FB\n"); |
| 2095 | ret = -EINVAL; |
| 2096 | goto out; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 2097 | } |
Ville Syrjälä | 6653cc8 | 2012-03-13 12:35:38 +0200 | [diff] [blame] | 2098 | fb = crtc->fb; |
Daniel Vetter | b0d1232 | 2012-12-11 01:07:12 +0100 | [diff] [blame] | 2099 | /* Make refcounting symmetric with the lookup path. */ |
| 2100 | drm_framebuffer_reference(fb); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 2101 | } else { |
Daniel Vetter | 786b99e | 2012-12-02 21:53:40 +0100 | [diff] [blame] | 2102 | fb = drm_framebuffer_lookup(dev, crtc_req->fb_id); |
| 2103 | if (!fb) { |
Zhao Yakui | 58367ed | 2009-07-20 13:48:07 +0800 | [diff] [blame] | 2104 | DRM_DEBUG_KMS("Unknown FB ID%d\n", |
| 2105 | crtc_req->fb_id); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 2106 | ret = -EINVAL; |
| 2107 | goto out; |
| 2108 | } |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 2109 | } |
| 2110 | |
| 2111 | mode = drm_mode_create(dev); |
Ville Syrjälä | ee34ab5 | 2012-03-13 12:35:43 +0200 | [diff] [blame] | 2112 | if (!mode) { |
| 2113 | ret = -ENOMEM; |
| 2114 | goto out; |
| 2115 | } |
| 2116 | |
Ville Syrjälä | 90367bf | 2012-03-13 12:35:44 +0200 | [diff] [blame] | 2117 | ret = drm_crtc_convert_umode(mode, &crtc_req->mode); |
| 2118 | if (ret) { |
| 2119 | DRM_DEBUG_KMS("Invalid mode\n"); |
| 2120 | goto out; |
| 2121 | } |
| 2122 | |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 2123 | drm_mode_set_crtcinfo(mode, CRTC_INTERLACE_HALVE_V); |
Ville Syrjälä | 5f61bb4 | 2012-03-13 12:35:45 +0200 | [diff] [blame] | 2124 | |
Rob Clark | 7c80e12 | 2012-09-04 16:35:56 +0000 | [diff] [blame] | 2125 | hdisplay = mode->hdisplay; |
| 2126 | vdisplay = mode->vdisplay; |
| 2127 | |
| 2128 | if (crtc->invert_dimensions) |
| 2129 | swap(hdisplay, vdisplay); |
| 2130 | |
| 2131 | if (hdisplay > fb->width || |
| 2132 | vdisplay > fb->height || |
| 2133 | crtc_req->x > fb->width - hdisplay || |
| 2134 | crtc_req->y > fb->height - vdisplay) { |
| 2135 | DRM_DEBUG_KMS("Invalid fb size %ux%u for CRTC viewport %ux%u+%d+%d%s.\n", |
| 2136 | fb->width, fb->height, |
| 2137 | hdisplay, vdisplay, crtc_req->x, crtc_req->y, |
| 2138 | crtc->invert_dimensions ? " (inverted)" : ""); |
Ville Syrjälä | 5f61bb4 | 2012-03-13 12:35:45 +0200 | [diff] [blame] | 2139 | ret = -ENOSPC; |
| 2140 | goto out; |
| 2141 | } |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 2142 | } |
| 2143 | |
| 2144 | if (crtc_req->count_connectors == 0 && mode) { |
Zhao Yakui | 58367ed | 2009-07-20 13:48:07 +0800 | [diff] [blame] | 2145 | DRM_DEBUG_KMS("Count connectors is 0 but mode set\n"); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 2146 | ret = -EINVAL; |
| 2147 | goto out; |
| 2148 | } |
| 2149 | |
Jakob Bornecrantz | 7781de7 | 2009-08-03 13:43:58 +0100 | [diff] [blame] | 2150 | if (crtc_req->count_connectors > 0 && (!mode || !fb)) { |
Zhao Yakui | 58367ed | 2009-07-20 13:48:07 +0800 | [diff] [blame] | 2151 | 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] | 2152 | crtc_req->count_connectors); |
| 2153 | ret = -EINVAL; |
| 2154 | goto out; |
| 2155 | } |
| 2156 | |
| 2157 | if (crtc_req->count_connectors > 0) { |
| 2158 | u32 out_id; |
| 2159 | |
| 2160 | /* Avoid unbounded kernel memory allocation */ |
| 2161 | if (crtc_req->count_connectors > config->num_connector) { |
| 2162 | ret = -EINVAL; |
| 2163 | goto out; |
| 2164 | } |
| 2165 | |
| 2166 | connector_set = kmalloc(crtc_req->count_connectors * |
| 2167 | sizeof(struct drm_connector *), |
| 2168 | GFP_KERNEL); |
| 2169 | if (!connector_set) { |
| 2170 | ret = -ENOMEM; |
| 2171 | goto out; |
| 2172 | } |
| 2173 | |
| 2174 | for (i = 0; i < crtc_req->count_connectors; i++) { |
Ville Syrjälä | 81f6c7f | 2011-12-20 00:06:42 +0200 | [diff] [blame] | 2175 | 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] | 2176 | if (get_user(out_id, &set_connectors_ptr[i])) { |
| 2177 | ret = -EFAULT; |
| 2178 | goto out; |
| 2179 | } |
| 2180 | |
| 2181 | obj = drm_mode_object_find(dev, out_id, |
| 2182 | DRM_MODE_OBJECT_CONNECTOR); |
| 2183 | if (!obj) { |
Zhao Yakui | 58367ed | 2009-07-20 13:48:07 +0800 | [diff] [blame] | 2184 | DRM_DEBUG_KMS("Connector id %d unknown\n", |
| 2185 | out_id); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 2186 | ret = -EINVAL; |
| 2187 | goto out; |
| 2188 | } |
| 2189 | connector = obj_to_connector(obj); |
Jerome Glisse | 9440106 | 2010-07-15 15:43:25 -0400 | [diff] [blame] | 2190 | DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n", |
| 2191 | connector->base.id, |
| 2192 | drm_get_connector_name(connector)); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 2193 | |
| 2194 | connector_set[i] = connector; |
| 2195 | } |
| 2196 | } |
| 2197 | |
| 2198 | set.crtc = crtc; |
| 2199 | set.x = crtc_req->x; |
| 2200 | set.y = crtc_req->y; |
| 2201 | set.mode = mode; |
| 2202 | set.connectors = connector_set; |
| 2203 | set.num_connectors = crtc_req->count_connectors; |
Dave Airlie | 5ef5f72 | 2009-08-17 13:11:23 +1000 | [diff] [blame] | 2204 | set.fb = fb; |
Daniel Vetter | 2d13b67 | 2012-12-11 13:47:23 +0100 | [diff] [blame] | 2205 | ret = drm_mode_set_config_internal(&set); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 2206 | |
| 2207 | out: |
Daniel Vetter | b0d1232 | 2012-12-11 01:07:12 +0100 | [diff] [blame] | 2208 | if (fb) |
| 2209 | drm_framebuffer_unreference(fb); |
| 2210 | |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 2211 | kfree(connector_set); |
Ville Syrjälä | ee34ab5 | 2012-03-13 12:35:43 +0200 | [diff] [blame] | 2212 | drm_mode_destroy(dev, mode); |
Daniel Vetter | 8484990 | 2012-12-02 00:28:11 +0100 | [diff] [blame] | 2213 | drm_modeset_unlock_all(dev); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 2214 | return ret; |
| 2215 | } |
| 2216 | |
| 2217 | int drm_mode_cursor_ioctl(struct drm_device *dev, |
| 2218 | void *data, struct drm_file *file_priv) |
| 2219 | { |
| 2220 | struct drm_mode_cursor *req = data; |
| 2221 | struct drm_mode_object *obj; |
| 2222 | struct drm_crtc *crtc; |
| 2223 | int ret = 0; |
| 2224 | |
Dave Airlie | fb3b06c | 2011-02-08 13:55:21 +1000 | [diff] [blame] | 2225 | if (!drm_core_check_feature(dev, DRIVER_MODESET)) |
| 2226 | return -EINVAL; |
| 2227 | |
Jakob Bornecrantz | 7c4eaca | 2012-08-16 08:29:03 +0000 | [diff] [blame] | 2228 | if (!req->flags || (~DRM_MODE_CURSOR_FLAGS & req->flags)) |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 2229 | return -EINVAL; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 2230 | |
Jakob Bornecrantz | e0c8463 | 2008-12-19 14:50:50 +1000 | [diff] [blame] | 2231 | obj = drm_mode_object_find(dev, req->crtc_id, DRM_MODE_OBJECT_CRTC); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 2232 | if (!obj) { |
Zhao Yakui | 58367ed | 2009-07-20 13:48:07 +0800 | [diff] [blame] | 2233 | DRM_DEBUG_KMS("Unknown CRTC ID %d\n", req->crtc_id); |
Daniel Vetter | dac3566 | 2012-12-02 15:24:10 +0100 | [diff] [blame] | 2234 | return -EINVAL; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 2235 | } |
| 2236 | crtc = obj_to_crtc(obj); |
| 2237 | |
Daniel Vetter | dac3566 | 2012-12-02 15:24:10 +0100 | [diff] [blame] | 2238 | mutex_lock(&crtc->mutex); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 2239 | if (req->flags & DRM_MODE_CURSOR_BO) { |
| 2240 | if (!crtc->funcs->cursor_set) { |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 2241 | ret = -ENXIO; |
| 2242 | goto out; |
| 2243 | } |
| 2244 | /* Turns off the cursor if handle is 0 */ |
| 2245 | ret = crtc->funcs->cursor_set(crtc, file_priv, req->handle, |
| 2246 | req->width, req->height); |
| 2247 | } |
| 2248 | |
| 2249 | if (req->flags & DRM_MODE_CURSOR_MOVE) { |
| 2250 | if (crtc->funcs->cursor_move) { |
| 2251 | ret = crtc->funcs->cursor_move(crtc, req->x, req->y); |
| 2252 | } else { |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 2253 | ret = -EFAULT; |
| 2254 | goto out; |
| 2255 | } |
| 2256 | } |
| 2257 | out: |
Daniel Vetter | dac3566 | 2012-12-02 15:24:10 +0100 | [diff] [blame] | 2258 | mutex_unlock(&crtc->mutex); |
| 2259 | |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 2260 | return ret; |
| 2261 | } |
| 2262 | |
Jesse Barnes | 308e5bc | 2011-11-14 14:51:28 -0800 | [diff] [blame] | 2263 | /* Original addfb only supported RGB formats, so figure out which one */ |
| 2264 | uint32_t drm_mode_legacy_fb_format(uint32_t bpp, uint32_t depth) |
| 2265 | { |
| 2266 | uint32_t fmt; |
| 2267 | |
| 2268 | switch (bpp) { |
| 2269 | case 8: |
Ville Syrjälä | 04b3924 | 2011-11-17 18:05:13 +0200 | [diff] [blame] | 2270 | fmt = DRM_FORMAT_RGB332; |
Jesse Barnes | 308e5bc | 2011-11-14 14:51:28 -0800 | [diff] [blame] | 2271 | break; |
| 2272 | case 16: |
| 2273 | if (depth == 15) |
Ville Syrjälä | 04b3924 | 2011-11-17 18:05:13 +0200 | [diff] [blame] | 2274 | fmt = DRM_FORMAT_XRGB1555; |
Jesse Barnes | 308e5bc | 2011-11-14 14:51:28 -0800 | [diff] [blame] | 2275 | else |
Ville Syrjälä | 04b3924 | 2011-11-17 18:05:13 +0200 | [diff] [blame] | 2276 | fmt = DRM_FORMAT_RGB565; |
Jesse Barnes | 308e5bc | 2011-11-14 14:51:28 -0800 | [diff] [blame] | 2277 | break; |
| 2278 | case 24: |
Ville Syrjälä | 04b3924 | 2011-11-17 18:05:13 +0200 | [diff] [blame] | 2279 | fmt = DRM_FORMAT_RGB888; |
Jesse Barnes | 308e5bc | 2011-11-14 14:51:28 -0800 | [diff] [blame] | 2280 | break; |
| 2281 | case 32: |
| 2282 | if (depth == 24) |
Ville Syrjälä | 04b3924 | 2011-11-17 18:05:13 +0200 | [diff] [blame] | 2283 | fmt = DRM_FORMAT_XRGB8888; |
Jesse Barnes | 308e5bc | 2011-11-14 14:51:28 -0800 | [diff] [blame] | 2284 | else if (depth == 30) |
Ville Syrjälä | 04b3924 | 2011-11-17 18:05:13 +0200 | [diff] [blame] | 2285 | fmt = DRM_FORMAT_XRGB2101010; |
Jesse Barnes | 308e5bc | 2011-11-14 14:51:28 -0800 | [diff] [blame] | 2286 | else |
Ville Syrjälä | 04b3924 | 2011-11-17 18:05:13 +0200 | [diff] [blame] | 2287 | fmt = DRM_FORMAT_ARGB8888; |
Jesse Barnes | 308e5bc | 2011-11-14 14:51:28 -0800 | [diff] [blame] | 2288 | break; |
| 2289 | default: |
Ville Syrjälä | 04b3924 | 2011-11-17 18:05:13 +0200 | [diff] [blame] | 2290 | DRM_ERROR("bad bpp, assuming x8r8g8b8 pixel format\n"); |
| 2291 | fmt = DRM_FORMAT_XRGB8888; |
Jesse Barnes | 308e5bc | 2011-11-14 14:51:28 -0800 | [diff] [blame] | 2292 | break; |
| 2293 | } |
| 2294 | |
| 2295 | return fmt; |
| 2296 | } |
| 2297 | EXPORT_SYMBOL(drm_mode_legacy_fb_format); |
| 2298 | |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 2299 | /** |
| 2300 | * drm_mode_addfb - add an FB to the graphics configuration |
Daniel Vetter | 065a50ed | 2012-12-02 00:09:18 +0100 | [diff] [blame] | 2301 | * @dev: drm device for the ioctl |
| 2302 | * @data: data pointer for the ioctl |
| 2303 | * @file_priv: drm file for the ioctl call |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 2304 | * |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 2305 | * Add a new FB to the specified CRTC, given a user request. |
| 2306 | * |
| 2307 | * Called by the user via ioctl. |
| 2308 | * |
| 2309 | * RETURNS: |
| 2310 | * Zero on success, errno on failure. |
| 2311 | */ |
| 2312 | int drm_mode_addfb(struct drm_device *dev, |
| 2313 | void *data, struct drm_file *file_priv) |
| 2314 | { |
Jesse Barnes | 308e5bc | 2011-11-14 14:51:28 -0800 | [diff] [blame] | 2315 | struct drm_mode_fb_cmd *or = data; |
| 2316 | struct drm_mode_fb_cmd2 r = {}; |
| 2317 | struct drm_mode_config *config = &dev->mode_config; |
| 2318 | struct drm_framebuffer *fb; |
| 2319 | int ret = 0; |
| 2320 | |
| 2321 | /* Use new struct with format internally */ |
| 2322 | r.fb_id = or->fb_id; |
| 2323 | r.width = or->width; |
| 2324 | r.height = or->height; |
| 2325 | r.pitches[0] = or->pitch; |
| 2326 | r.pixel_format = drm_mode_legacy_fb_format(or->bpp, or->depth); |
| 2327 | r.handles[0] = or->handle; |
| 2328 | |
| 2329 | if (!drm_core_check_feature(dev, DRIVER_MODESET)) |
| 2330 | return -EINVAL; |
| 2331 | |
Jesse Barnes | acb4b99 | 2011-11-07 12:03:23 -0800 | [diff] [blame] | 2332 | if ((config->min_width > r.width) || (r.width > config->max_width)) |
Jesse Barnes | 308e5bc | 2011-11-14 14:51:28 -0800 | [diff] [blame] | 2333 | return -EINVAL; |
Jesse Barnes | acb4b99 | 2011-11-07 12:03:23 -0800 | [diff] [blame] | 2334 | |
| 2335 | if ((config->min_height > r.height) || (r.height > config->max_height)) |
Jesse Barnes | 308e5bc | 2011-11-14 14:51:28 -0800 | [diff] [blame] | 2336 | return -EINVAL; |
Jesse Barnes | 308e5bc | 2011-11-14 14:51:28 -0800 | [diff] [blame] | 2337 | |
Jesse Barnes | 308e5bc | 2011-11-14 14:51:28 -0800 | [diff] [blame] | 2338 | fb = dev->mode_config.funcs->fb_create(dev, file_priv, &r); |
| 2339 | if (IS_ERR(fb)) { |
Dave Airlie | 1aa1b11 | 2012-05-01 17:38:35 +0100 | [diff] [blame] | 2340 | DRM_DEBUG_KMS("could not create framebuffer\n"); |
Daniel Vetter | 4b096ac | 2012-12-10 21:19:18 +0100 | [diff] [blame] | 2341 | drm_modeset_unlock_all(dev); |
| 2342 | return PTR_ERR(fb); |
Jesse Barnes | 308e5bc | 2011-11-14 14:51:28 -0800 | [diff] [blame] | 2343 | } |
| 2344 | |
Daniel Vetter | 4b096ac | 2012-12-10 21:19:18 +0100 | [diff] [blame] | 2345 | mutex_lock(&file_priv->fbs_lock); |
Jesse Barnes | 308e5bc | 2011-11-14 14:51:28 -0800 | [diff] [blame] | 2346 | or->fb_id = fb->base.id; |
| 2347 | list_add(&fb->filp_head, &file_priv->fbs); |
| 2348 | DRM_DEBUG_KMS("[FB:%d]\n", fb->base.id); |
Daniel Vetter | 4b096ac | 2012-12-10 21:19:18 +0100 | [diff] [blame] | 2349 | mutex_unlock(&file_priv->fbs_lock); |
Daniel Vetter | 4b096ac | 2012-12-10 21:19:18 +0100 | [diff] [blame] | 2350 | |
Jesse Barnes | 308e5bc | 2011-11-14 14:51:28 -0800 | [diff] [blame] | 2351 | return ret; |
| 2352 | } |
| 2353 | |
Ville Syrjälä | cff91b6 | 2012-05-24 20:54:00 +0300 | [diff] [blame] | 2354 | static int format_check(const struct drm_mode_fb_cmd2 *r) |
Ville Syrjälä | 935b597 | 2011-12-20 00:06:48 +0200 | [diff] [blame] | 2355 | { |
| 2356 | uint32_t format = r->pixel_format & ~DRM_FORMAT_BIG_ENDIAN; |
| 2357 | |
| 2358 | switch (format) { |
| 2359 | case DRM_FORMAT_C8: |
| 2360 | case DRM_FORMAT_RGB332: |
| 2361 | case DRM_FORMAT_BGR233: |
| 2362 | case DRM_FORMAT_XRGB4444: |
| 2363 | case DRM_FORMAT_XBGR4444: |
| 2364 | case DRM_FORMAT_RGBX4444: |
| 2365 | case DRM_FORMAT_BGRX4444: |
| 2366 | case DRM_FORMAT_ARGB4444: |
| 2367 | case DRM_FORMAT_ABGR4444: |
| 2368 | case DRM_FORMAT_RGBA4444: |
| 2369 | case DRM_FORMAT_BGRA4444: |
| 2370 | case DRM_FORMAT_XRGB1555: |
| 2371 | case DRM_FORMAT_XBGR1555: |
| 2372 | case DRM_FORMAT_RGBX5551: |
| 2373 | case DRM_FORMAT_BGRX5551: |
| 2374 | case DRM_FORMAT_ARGB1555: |
| 2375 | case DRM_FORMAT_ABGR1555: |
| 2376 | case DRM_FORMAT_RGBA5551: |
| 2377 | case DRM_FORMAT_BGRA5551: |
| 2378 | case DRM_FORMAT_RGB565: |
| 2379 | case DRM_FORMAT_BGR565: |
| 2380 | case DRM_FORMAT_RGB888: |
| 2381 | case DRM_FORMAT_BGR888: |
| 2382 | case DRM_FORMAT_XRGB8888: |
| 2383 | case DRM_FORMAT_XBGR8888: |
| 2384 | case DRM_FORMAT_RGBX8888: |
| 2385 | case DRM_FORMAT_BGRX8888: |
| 2386 | case DRM_FORMAT_ARGB8888: |
| 2387 | case DRM_FORMAT_ABGR8888: |
| 2388 | case DRM_FORMAT_RGBA8888: |
| 2389 | case DRM_FORMAT_BGRA8888: |
| 2390 | case DRM_FORMAT_XRGB2101010: |
| 2391 | case DRM_FORMAT_XBGR2101010: |
| 2392 | case DRM_FORMAT_RGBX1010102: |
| 2393 | case DRM_FORMAT_BGRX1010102: |
| 2394 | case DRM_FORMAT_ARGB2101010: |
| 2395 | case DRM_FORMAT_ABGR2101010: |
| 2396 | case DRM_FORMAT_RGBA1010102: |
| 2397 | case DRM_FORMAT_BGRA1010102: |
| 2398 | case DRM_FORMAT_YUYV: |
| 2399 | case DRM_FORMAT_YVYU: |
| 2400 | case DRM_FORMAT_UYVY: |
| 2401 | case DRM_FORMAT_VYUY: |
| 2402 | case DRM_FORMAT_AYUV: |
| 2403 | case DRM_FORMAT_NV12: |
| 2404 | case DRM_FORMAT_NV21: |
| 2405 | case DRM_FORMAT_NV16: |
| 2406 | case DRM_FORMAT_NV61: |
Laurent Pinchart | ba623f6 | 2012-05-18 23:47:40 +0200 | [diff] [blame] | 2407 | case DRM_FORMAT_NV24: |
| 2408 | case DRM_FORMAT_NV42: |
Ville Syrjälä | 935b597 | 2011-12-20 00:06:48 +0200 | [diff] [blame] | 2409 | case DRM_FORMAT_YUV410: |
| 2410 | case DRM_FORMAT_YVU410: |
| 2411 | case DRM_FORMAT_YUV411: |
| 2412 | case DRM_FORMAT_YVU411: |
| 2413 | case DRM_FORMAT_YUV420: |
| 2414 | case DRM_FORMAT_YVU420: |
| 2415 | case DRM_FORMAT_YUV422: |
| 2416 | case DRM_FORMAT_YVU422: |
| 2417 | case DRM_FORMAT_YUV444: |
| 2418 | case DRM_FORMAT_YVU444: |
| 2419 | return 0; |
| 2420 | default: |
| 2421 | return -EINVAL; |
| 2422 | } |
| 2423 | } |
| 2424 | |
Ville Syrjälä | cff91b6 | 2012-05-24 20:54:00 +0300 | [diff] [blame] | 2425 | static int framebuffer_check(const struct drm_mode_fb_cmd2 *r) |
Ville Syrjälä | d1b45d5 | 2012-04-05 21:35:18 +0300 | [diff] [blame] | 2426 | { |
| 2427 | int ret, hsub, vsub, num_planes, i; |
| 2428 | |
| 2429 | ret = format_check(r); |
| 2430 | if (ret) { |
Dave Airlie | 1aa1b11 | 2012-05-01 17:38:35 +0100 | [diff] [blame] | 2431 | DRM_DEBUG_KMS("bad framebuffer format 0x%08x\n", r->pixel_format); |
Ville Syrjälä | d1b45d5 | 2012-04-05 21:35:18 +0300 | [diff] [blame] | 2432 | return ret; |
| 2433 | } |
| 2434 | |
| 2435 | hsub = drm_format_horz_chroma_subsampling(r->pixel_format); |
| 2436 | vsub = drm_format_vert_chroma_subsampling(r->pixel_format); |
| 2437 | num_planes = drm_format_num_planes(r->pixel_format); |
| 2438 | |
| 2439 | if (r->width == 0 || r->width % hsub) { |
Dave Airlie | 1aa1b11 | 2012-05-01 17:38:35 +0100 | [diff] [blame] | 2440 | DRM_DEBUG_KMS("bad framebuffer width %u\n", r->height); |
Ville Syrjälä | d1b45d5 | 2012-04-05 21:35:18 +0300 | [diff] [blame] | 2441 | return -EINVAL; |
| 2442 | } |
| 2443 | |
| 2444 | if (r->height == 0 || r->height % vsub) { |
Dave Airlie | 1aa1b11 | 2012-05-01 17:38:35 +0100 | [diff] [blame] | 2445 | DRM_DEBUG_KMS("bad framebuffer height %u\n", r->height); |
Ville Syrjälä | d1b45d5 | 2012-04-05 21:35:18 +0300 | [diff] [blame] | 2446 | return -EINVAL; |
| 2447 | } |
| 2448 | |
| 2449 | for (i = 0; i < num_planes; i++) { |
| 2450 | unsigned int width = r->width / (i != 0 ? hsub : 1); |
Ville Syrjälä | b180b5d | 2012-10-25 18:05:04 +0000 | [diff] [blame] | 2451 | unsigned int height = r->height / (i != 0 ? vsub : 1); |
| 2452 | unsigned int cpp = drm_format_plane_cpp(r->pixel_format, i); |
Ville Syrjälä | d1b45d5 | 2012-04-05 21:35:18 +0300 | [diff] [blame] | 2453 | |
| 2454 | if (!r->handles[i]) { |
Dave Airlie | 1aa1b11 | 2012-05-01 17:38:35 +0100 | [diff] [blame] | 2455 | 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] | 2456 | return -EINVAL; |
| 2457 | } |
| 2458 | |
Ville Syrjälä | b180b5d | 2012-10-25 18:05:04 +0000 | [diff] [blame] | 2459 | if ((uint64_t) width * cpp > UINT_MAX) |
| 2460 | return -ERANGE; |
| 2461 | |
| 2462 | if ((uint64_t) height * r->pitches[i] + r->offsets[i] > UINT_MAX) |
| 2463 | return -ERANGE; |
| 2464 | |
| 2465 | if (r->pitches[i] < width * cpp) { |
Dave Airlie | 1aa1b11 | 2012-05-01 17:38:35 +0100 | [diff] [blame] | 2466 | 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] | 2467 | return -EINVAL; |
| 2468 | } |
| 2469 | } |
| 2470 | |
| 2471 | return 0; |
| 2472 | } |
| 2473 | |
Jesse Barnes | 308e5bc | 2011-11-14 14:51:28 -0800 | [diff] [blame] | 2474 | /** |
| 2475 | * drm_mode_addfb2 - add an FB to the graphics configuration |
Daniel Vetter | 065a50ed | 2012-12-02 00:09:18 +0100 | [diff] [blame] | 2476 | * @dev: drm device for the ioctl |
| 2477 | * @data: data pointer for the ioctl |
| 2478 | * @file_priv: drm file for the ioctl call |
Jesse Barnes | 308e5bc | 2011-11-14 14:51:28 -0800 | [diff] [blame] | 2479 | * |
Jesse Barnes | 308e5bc | 2011-11-14 14:51:28 -0800 | [diff] [blame] | 2480 | * Add a new FB to the specified CRTC, given a user request with format. |
| 2481 | * |
| 2482 | * Called by the user via ioctl. |
| 2483 | * |
| 2484 | * RETURNS: |
| 2485 | * Zero on success, errno on failure. |
| 2486 | */ |
| 2487 | int drm_mode_addfb2(struct drm_device *dev, |
| 2488 | void *data, struct drm_file *file_priv) |
| 2489 | { |
| 2490 | struct drm_mode_fb_cmd2 *r = data; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 2491 | struct drm_mode_config *config = &dev->mode_config; |
| 2492 | struct drm_framebuffer *fb; |
Laurent Pinchart | 4a1b071 | 2012-05-17 13:27:21 +0200 | [diff] [blame] | 2493 | int ret; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 2494 | |
Dave Airlie | fb3b06c | 2011-02-08 13:55:21 +1000 | [diff] [blame] | 2495 | if (!drm_core_check_feature(dev, DRIVER_MODESET)) |
| 2496 | return -EINVAL; |
| 2497 | |
Ville Syrjälä | e3cc352 | 2012-11-08 09:09:42 +0000 | [diff] [blame] | 2498 | if (r->flags & ~DRM_MODE_FB_INTERLACED) { |
| 2499 | DRM_DEBUG_KMS("bad framebuffer flags 0x%08x\n", r->flags); |
| 2500 | return -EINVAL; |
| 2501 | } |
| 2502 | |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 2503 | if ((config->min_width > r->width) || (r->width > config->max_width)) { |
Dave Airlie | 1aa1b11 | 2012-05-01 17:38:35 +0100 | [diff] [blame] | 2504 | DRM_DEBUG_KMS("bad framebuffer width %d, should be >= %d && <= %d\n", |
Jesse Barnes | 8cf5c91 | 2011-11-14 14:51:27 -0800 | [diff] [blame] | 2505 | r->width, config->min_width, config->max_width); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 2506 | return -EINVAL; |
| 2507 | } |
| 2508 | if ((config->min_height > r->height) || (r->height > config->max_height)) { |
Dave Airlie | 1aa1b11 | 2012-05-01 17:38:35 +0100 | [diff] [blame] | 2509 | DRM_DEBUG_KMS("bad framebuffer height %d, should be >= %d && <= %d\n", |
Jesse Barnes | 8cf5c91 | 2011-11-14 14:51:27 -0800 | [diff] [blame] | 2510 | r->height, config->min_height, config->max_height); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 2511 | return -EINVAL; |
| 2512 | } |
| 2513 | |
Ville Syrjälä | d1b45d5 | 2012-04-05 21:35:18 +0300 | [diff] [blame] | 2514 | ret = framebuffer_check(r); |
| 2515 | if (ret) |
Ville Syrjälä | 935b597 | 2011-12-20 00:06:48 +0200 | [diff] [blame] | 2516 | return ret; |
Ville Syrjälä | 935b597 | 2011-12-20 00:06:48 +0200 | [diff] [blame] | 2517 | |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 2518 | fb = dev->mode_config.funcs->fb_create(dev, file_priv, r); |
Chris Wilson | cce13ff | 2010-08-08 13:36:38 +0100 | [diff] [blame] | 2519 | if (IS_ERR(fb)) { |
Dave Airlie | 1aa1b11 | 2012-05-01 17:38:35 +0100 | [diff] [blame] | 2520 | DRM_DEBUG_KMS("could not create framebuffer\n"); |
Daniel Vetter | 4b096ac | 2012-12-10 21:19:18 +0100 | [diff] [blame] | 2521 | drm_modeset_unlock_all(dev); |
| 2522 | return PTR_ERR(fb); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 2523 | } |
| 2524 | |
Daniel Vetter | 4b096ac | 2012-12-10 21:19:18 +0100 | [diff] [blame] | 2525 | mutex_lock(&file_priv->fbs_lock); |
Jakob Bornecrantz | e0c8463 | 2008-12-19 14:50:50 +1000 | [diff] [blame] | 2526 | r->fb_id = fb->base.id; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 2527 | list_add(&fb->filp_head, &file_priv->fbs); |
Jerome Glisse | 9440106 | 2010-07-15 15:43:25 -0400 | [diff] [blame] | 2528 | DRM_DEBUG_KMS("[FB:%d]\n", fb->base.id); |
Daniel Vetter | 4b096ac | 2012-12-10 21:19:18 +0100 | [diff] [blame] | 2529 | mutex_unlock(&file_priv->fbs_lock); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 2530 | |
Daniel Vetter | 4b096ac | 2012-12-10 21:19:18 +0100 | [diff] [blame] | 2531 | |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 2532 | return ret; |
| 2533 | } |
| 2534 | |
| 2535 | /** |
| 2536 | * drm_mode_rmfb - remove an FB from the configuration |
Daniel Vetter | 065a50ed | 2012-12-02 00:09:18 +0100 | [diff] [blame] | 2537 | * @dev: drm device for the ioctl |
| 2538 | * @data: data pointer for the ioctl |
| 2539 | * @file_priv: drm file for the ioctl call |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 2540 | * |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 2541 | * Remove the FB specified by the user. |
| 2542 | * |
| 2543 | * Called by the user via ioctl. |
| 2544 | * |
| 2545 | * RETURNS: |
| 2546 | * Zero on success, errno on failure. |
| 2547 | */ |
| 2548 | int drm_mode_rmfb(struct drm_device *dev, |
| 2549 | void *data, struct drm_file *file_priv) |
| 2550 | { |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 2551 | struct drm_framebuffer *fb = NULL; |
| 2552 | struct drm_framebuffer *fbl = NULL; |
| 2553 | uint32_t *id = data; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 2554 | int found = 0; |
| 2555 | |
Dave Airlie | fb3b06c | 2011-02-08 13:55:21 +1000 | [diff] [blame] | 2556 | if (!drm_core_check_feature(dev, DRIVER_MODESET)) |
| 2557 | return -EINVAL; |
| 2558 | |
Daniel Vetter | 4b096ac | 2012-12-10 21:19:18 +0100 | [diff] [blame] | 2559 | mutex_lock(&file_priv->fbs_lock); |
Daniel Vetter | 2b677e8 | 2012-12-10 21:16:05 +0100 | [diff] [blame] | 2560 | mutex_lock(&dev->mode_config.fb_lock); |
| 2561 | fb = __drm_framebuffer_lookup(dev, *id); |
| 2562 | if (!fb) |
| 2563 | goto fail_lookup; |
| 2564 | |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 2565 | list_for_each_entry(fbl, &file_priv->fbs, filp_head) |
| 2566 | if (fb == fbl) |
| 2567 | found = 1; |
Daniel Vetter | 2b677e8 | 2012-12-10 21:16:05 +0100 | [diff] [blame] | 2568 | if (!found) |
| 2569 | goto fail_lookup; |
| 2570 | |
| 2571 | /* Mark fb as reaped, we still have a ref from fpriv->fbs. */ |
| 2572 | __drm_framebuffer_unregister(dev, fb); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 2573 | |
Daniel Vetter | 4b096ac | 2012-12-10 21:19:18 +0100 | [diff] [blame] | 2574 | list_del_init(&fb->filp_head); |
Daniel Vetter | 2b677e8 | 2012-12-10 21:16:05 +0100 | [diff] [blame] | 2575 | mutex_unlock(&dev->mode_config.fb_lock); |
Daniel Vetter | 4b096ac | 2012-12-10 21:19:18 +0100 | [diff] [blame] | 2576 | mutex_unlock(&file_priv->fbs_lock); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 2577 | |
Daniel Vetter | 4b096ac | 2012-12-10 21:19:18 +0100 | [diff] [blame] | 2578 | drm_framebuffer_remove(fb); |
Daniel Vetter | 4b096ac | 2012-12-10 21:19:18 +0100 | [diff] [blame] | 2579 | |
Daniel Vetter | 2b677e8 | 2012-12-10 21:16:05 +0100 | [diff] [blame] | 2580 | return 0; |
| 2581 | |
| 2582 | fail_lookup: |
| 2583 | mutex_unlock(&dev->mode_config.fb_lock); |
| 2584 | mutex_unlock(&file_priv->fbs_lock); |
| 2585 | |
| 2586 | return -EINVAL; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 2587 | } |
| 2588 | |
| 2589 | /** |
| 2590 | * drm_mode_getfb - get FB info |
Daniel Vetter | 065a50ed | 2012-12-02 00:09:18 +0100 | [diff] [blame] | 2591 | * @dev: drm device for the ioctl |
| 2592 | * @data: data pointer for the ioctl |
| 2593 | * @file_priv: drm file for the ioctl call |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 2594 | * |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 2595 | * Lookup the FB given its ID and return info about it. |
| 2596 | * |
| 2597 | * Called by the user via ioctl. |
| 2598 | * |
| 2599 | * RETURNS: |
| 2600 | * Zero on success, errno on failure. |
| 2601 | */ |
| 2602 | int drm_mode_getfb(struct drm_device *dev, |
| 2603 | void *data, struct drm_file *file_priv) |
| 2604 | { |
| 2605 | struct drm_mode_fb_cmd *r = data; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 2606 | struct drm_framebuffer *fb; |
Daniel Vetter | 58c0dca | 2012-12-13 23:06:08 +0100 | [diff] [blame] | 2607 | int ret; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 2608 | |
Dave Airlie | fb3b06c | 2011-02-08 13:55:21 +1000 | [diff] [blame] | 2609 | if (!drm_core_check_feature(dev, DRIVER_MODESET)) |
| 2610 | return -EINVAL; |
| 2611 | |
Daniel Vetter | 786b99e | 2012-12-02 21:53:40 +0100 | [diff] [blame] | 2612 | fb = drm_framebuffer_lookup(dev, r->fb_id); |
Daniel Vetter | 58c0dca | 2012-12-13 23:06:08 +0100 | [diff] [blame] | 2613 | if (!fb) |
| 2614 | return -EINVAL; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 2615 | |
| 2616 | r->height = fb->height; |
| 2617 | r->width = fb->width; |
| 2618 | r->depth = fb->depth; |
| 2619 | r->bpp = fb->bits_per_pixel; |
Ville Syrjälä | 01f2c77 | 2011-12-20 00:06:49 +0200 | [diff] [blame] | 2620 | r->pitch = fb->pitches[0]; |
Daniel Vetter | af26ef3 | 2012-12-13 23:07:50 +0100 | [diff] [blame] | 2621 | if (fb->funcs->create_handle) |
| 2622 | ret = fb->funcs->create_handle(fb, file_priv, &r->handle); |
| 2623 | else |
| 2624 | ret = -ENODEV; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 2625 | |
Daniel Vetter | 58c0dca | 2012-12-13 23:06:08 +0100 | [diff] [blame] | 2626 | drm_framebuffer_unreference(fb); |
| 2627 | |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 2628 | return ret; |
| 2629 | } |
| 2630 | |
Jakob Bornecrantz | 884840a | 2009-12-03 23:25:47 +0000 | [diff] [blame] | 2631 | int drm_mode_dirtyfb_ioctl(struct drm_device *dev, |
| 2632 | void *data, struct drm_file *file_priv) |
| 2633 | { |
| 2634 | struct drm_clip_rect __user *clips_ptr; |
| 2635 | struct drm_clip_rect *clips = NULL; |
| 2636 | struct drm_mode_fb_dirty_cmd *r = data; |
Jakob Bornecrantz | 884840a | 2009-12-03 23:25:47 +0000 | [diff] [blame] | 2637 | struct drm_framebuffer *fb; |
| 2638 | unsigned flags; |
| 2639 | int num_clips; |
Laurent Pinchart | 4a1b071 | 2012-05-17 13:27:21 +0200 | [diff] [blame] | 2640 | int ret; |
Jakob Bornecrantz | 884840a | 2009-12-03 23:25:47 +0000 | [diff] [blame] | 2641 | |
Dave Airlie | fb3b06c | 2011-02-08 13:55:21 +1000 | [diff] [blame] | 2642 | if (!drm_core_check_feature(dev, DRIVER_MODESET)) |
| 2643 | return -EINVAL; |
| 2644 | |
Daniel Vetter | 786b99e | 2012-12-02 21:53:40 +0100 | [diff] [blame] | 2645 | fb = drm_framebuffer_lookup(dev, r->fb_id); |
Daniel Vetter | 4ccf097 | 2012-12-11 00:38:18 +0100 | [diff] [blame] | 2646 | if (!fb) |
| 2647 | return -EINVAL; |
Jakob Bornecrantz | 884840a | 2009-12-03 23:25:47 +0000 | [diff] [blame] | 2648 | |
| 2649 | num_clips = r->num_clips; |
Ville Syrjälä | 81f6c7f | 2011-12-20 00:06:42 +0200 | [diff] [blame] | 2650 | clips_ptr = (struct drm_clip_rect __user *)(unsigned long)r->clips_ptr; |
Jakob Bornecrantz | 884840a | 2009-12-03 23:25:47 +0000 | [diff] [blame] | 2651 | |
| 2652 | if (!num_clips != !clips_ptr) { |
| 2653 | ret = -EINVAL; |
| 2654 | goto out_err1; |
| 2655 | } |
| 2656 | |
| 2657 | flags = DRM_MODE_FB_DIRTY_FLAGS & r->flags; |
| 2658 | |
| 2659 | /* If userspace annotates copy, clips must come in pairs */ |
| 2660 | if (flags & DRM_MODE_FB_DIRTY_ANNOTATE_COPY && (num_clips % 2)) { |
| 2661 | ret = -EINVAL; |
| 2662 | goto out_err1; |
| 2663 | } |
| 2664 | |
| 2665 | if (num_clips && clips_ptr) { |
Xi Wang | a5cd335 | 2011-11-23 01:12:01 -0500 | [diff] [blame] | 2666 | if (num_clips < 0 || num_clips > DRM_MODE_FB_DIRTY_MAX_CLIPS) { |
| 2667 | ret = -EINVAL; |
| 2668 | goto out_err1; |
| 2669 | } |
Jakob Bornecrantz | 884840a | 2009-12-03 23:25:47 +0000 | [diff] [blame] | 2670 | clips = kzalloc(num_clips * sizeof(*clips), GFP_KERNEL); |
| 2671 | if (!clips) { |
| 2672 | ret = -ENOMEM; |
| 2673 | goto out_err1; |
| 2674 | } |
| 2675 | |
| 2676 | ret = copy_from_user(clips, clips_ptr, |
| 2677 | num_clips * sizeof(*clips)); |
Dan Carpenter | e902a35 | 2010-06-04 12:23:21 +0200 | [diff] [blame] | 2678 | if (ret) { |
| 2679 | ret = -EFAULT; |
Jakob Bornecrantz | 884840a | 2009-12-03 23:25:47 +0000 | [diff] [blame] | 2680 | goto out_err2; |
Dan Carpenter | e902a35 | 2010-06-04 12:23:21 +0200 | [diff] [blame] | 2681 | } |
Jakob Bornecrantz | 884840a | 2009-12-03 23:25:47 +0000 | [diff] [blame] | 2682 | } |
| 2683 | |
| 2684 | if (fb->funcs->dirty) { |
Daniel Vetter | 4ccf097 | 2012-12-11 00:38:18 +0100 | [diff] [blame] | 2685 | drm_modeset_lock_all(dev); |
Thomas Hellstrom | 02b0016 | 2010-10-05 12:43:02 +0200 | [diff] [blame] | 2686 | ret = fb->funcs->dirty(fb, file_priv, flags, r->color, |
| 2687 | clips, num_clips); |
Daniel Vetter | 4ccf097 | 2012-12-11 00:38:18 +0100 | [diff] [blame] | 2688 | drm_modeset_unlock_all(dev); |
Jakob Bornecrantz | 884840a | 2009-12-03 23:25:47 +0000 | [diff] [blame] | 2689 | } else { |
| 2690 | ret = -ENOSYS; |
Jakob Bornecrantz | 884840a | 2009-12-03 23:25:47 +0000 | [diff] [blame] | 2691 | } |
| 2692 | |
| 2693 | out_err2: |
| 2694 | kfree(clips); |
| 2695 | out_err1: |
Daniel Vetter | 4ccf097 | 2012-12-11 00:38:18 +0100 | [diff] [blame] | 2696 | drm_framebuffer_unreference(fb); |
| 2697 | |
Jakob Bornecrantz | 884840a | 2009-12-03 23:25:47 +0000 | [diff] [blame] | 2698 | return ret; |
| 2699 | } |
| 2700 | |
| 2701 | |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 2702 | /** |
| 2703 | * drm_fb_release - remove and free the FBs on this file |
Daniel Vetter | 065a50ed | 2012-12-02 00:09:18 +0100 | [diff] [blame] | 2704 | * @priv: drm file for the ioctl |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 2705 | * |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 2706 | * Destroy all the FBs associated with @filp. |
| 2707 | * |
| 2708 | * Called by the user via ioctl. |
| 2709 | * |
| 2710 | * RETURNS: |
| 2711 | * Zero on success, errno on failure. |
| 2712 | */ |
Kristian Høgsberg | ea39f83 | 2009-02-12 14:37:56 -0500 | [diff] [blame] | 2713 | void drm_fb_release(struct drm_file *priv) |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 2714 | { |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 2715 | struct drm_device *dev = priv->minor->dev; |
| 2716 | struct drm_framebuffer *fb, *tfb; |
| 2717 | |
Daniel Vetter | 4b096ac | 2012-12-10 21:19:18 +0100 | [diff] [blame] | 2718 | mutex_lock(&priv->fbs_lock); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 2719 | list_for_each_entry_safe(fb, tfb, &priv->fbs, filp_head) { |
Daniel Vetter | 2b677e8 | 2012-12-10 21:16:05 +0100 | [diff] [blame] | 2720 | |
| 2721 | mutex_lock(&dev->mode_config.fb_lock); |
| 2722 | /* Mark fb as reaped, we still have a ref from fpriv->fbs. */ |
| 2723 | __drm_framebuffer_unregister(dev, fb); |
| 2724 | mutex_unlock(&dev->mode_config.fb_lock); |
| 2725 | |
Daniel Vetter | 4b096ac | 2012-12-10 21:19:18 +0100 | [diff] [blame] | 2726 | list_del_init(&fb->filp_head); |
Daniel Vetter | 2b677e8 | 2012-12-10 21:16:05 +0100 | [diff] [blame] | 2727 | |
| 2728 | /* This will also drop the fpriv->fbs reference. */ |
Rob Clark | f7eff60 | 2012-09-05 21:48:38 +0000 | [diff] [blame] | 2729 | drm_framebuffer_remove(fb); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 2730 | } |
Daniel Vetter | 4b096ac | 2012-12-10 21:19:18 +0100 | [diff] [blame] | 2731 | mutex_unlock(&priv->fbs_lock); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 2732 | } |
| 2733 | |
| 2734 | /** |
| 2735 | * drm_mode_attachmode - add a mode to the user mode list |
| 2736 | * @dev: DRM device |
| 2737 | * @connector: connector to add the mode to |
| 2738 | * @mode: mode to add |
| 2739 | * |
| 2740 | * Add @mode to @connector's user mode list. |
| 2741 | */ |
Ville Syrjälä | 1dd6c8b | 2012-03-13 12:35:42 +0200 | [diff] [blame] | 2742 | static void drm_mode_attachmode(struct drm_device *dev, |
| 2743 | struct drm_connector *connector, |
| 2744 | struct drm_display_mode *mode) |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 2745 | { |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 2746 | list_add_tail(&mode->head, &connector->user_modes); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 2747 | } |
| 2748 | |
| 2749 | int drm_mode_attachmode_crtc(struct drm_device *dev, struct drm_crtc *crtc, |
Ville Syrjälä | ac235da | 2012-03-13 12:35:46 +0200 | [diff] [blame] | 2750 | const struct drm_display_mode *mode) |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 2751 | { |
| 2752 | struct drm_connector *connector; |
Ville Syrjälä | ac235da | 2012-03-13 12:35:46 +0200 | [diff] [blame] | 2753 | int ret = 0; |
| 2754 | struct drm_display_mode *dup_mode, *next; |
| 2755 | LIST_HEAD(list); |
| 2756 | |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 2757 | list_for_each_entry(connector, &dev->mode_config.connector_list, head) { |
| 2758 | if (!connector->encoder) |
Ville Syrjälä | ac235da | 2012-03-13 12:35:46 +0200 | [diff] [blame] | 2759 | continue; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 2760 | if (connector->encoder->crtc == crtc) { |
Ville Syrjälä | ac235da | 2012-03-13 12:35:46 +0200 | [diff] [blame] | 2761 | dup_mode = drm_mode_duplicate(dev, mode); |
| 2762 | if (!dup_mode) { |
| 2763 | ret = -ENOMEM; |
| 2764 | goto out; |
| 2765 | } |
| 2766 | list_add_tail(&dup_mode->head, &list); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 2767 | } |
| 2768 | } |
Ville Syrjälä | ac235da | 2012-03-13 12:35:46 +0200 | [diff] [blame] | 2769 | |
| 2770 | list_for_each_entry(connector, &dev->mode_config.connector_list, head) { |
| 2771 | if (!connector->encoder) |
| 2772 | continue; |
| 2773 | if (connector->encoder->crtc == crtc) |
| 2774 | list_move_tail(list.next, &connector->user_modes); |
| 2775 | } |
| 2776 | |
| 2777 | WARN_ON(!list_empty(&list)); |
| 2778 | |
| 2779 | out: |
| 2780 | list_for_each_entry_safe(dup_mode, next, &list, head) |
| 2781 | drm_mode_destroy(dev, dup_mode); |
| 2782 | |
| 2783 | return ret; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 2784 | } |
| 2785 | EXPORT_SYMBOL(drm_mode_attachmode_crtc); |
| 2786 | |
| 2787 | static int drm_mode_detachmode(struct drm_device *dev, |
| 2788 | struct drm_connector *connector, |
| 2789 | struct drm_display_mode *mode) |
| 2790 | { |
| 2791 | int found = 0; |
| 2792 | int ret = 0; |
| 2793 | struct drm_display_mode *match_mode, *t; |
| 2794 | |
| 2795 | list_for_each_entry_safe(match_mode, t, &connector->user_modes, head) { |
| 2796 | if (drm_mode_equal(match_mode, mode)) { |
| 2797 | list_del(&match_mode->head); |
| 2798 | drm_mode_destroy(dev, match_mode); |
| 2799 | found = 1; |
| 2800 | break; |
| 2801 | } |
| 2802 | } |
| 2803 | |
| 2804 | if (!found) |
| 2805 | ret = -EINVAL; |
| 2806 | |
| 2807 | return ret; |
| 2808 | } |
| 2809 | |
| 2810 | int drm_mode_detachmode_crtc(struct drm_device *dev, struct drm_display_mode *mode) |
| 2811 | { |
| 2812 | struct drm_connector *connector; |
| 2813 | |
| 2814 | list_for_each_entry(connector, &dev->mode_config.connector_list, head) { |
| 2815 | drm_mode_detachmode(dev, connector, mode); |
| 2816 | } |
| 2817 | return 0; |
| 2818 | } |
| 2819 | EXPORT_SYMBOL(drm_mode_detachmode_crtc); |
| 2820 | |
| 2821 | /** |
| 2822 | * drm_fb_attachmode - Attach a user mode to an connector |
Daniel Vetter | 065a50ed | 2012-12-02 00:09:18 +0100 | [diff] [blame] | 2823 | * @dev: drm device for the ioctl |
| 2824 | * @data: data pointer for the ioctl |
| 2825 | * @file_priv: drm file for the ioctl call |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 2826 | * |
| 2827 | * This attaches a user specified mode to an connector. |
| 2828 | * Called by the user via ioctl. |
| 2829 | * |
| 2830 | * RETURNS: |
| 2831 | * Zero on success, errno on failure. |
| 2832 | */ |
| 2833 | int drm_mode_attachmode_ioctl(struct drm_device *dev, |
| 2834 | void *data, struct drm_file *file_priv) |
| 2835 | { |
| 2836 | struct drm_mode_mode_cmd *mode_cmd = data; |
| 2837 | struct drm_connector *connector; |
| 2838 | struct drm_display_mode *mode; |
| 2839 | struct drm_mode_object *obj; |
| 2840 | struct drm_mode_modeinfo *umode = &mode_cmd->mode; |
Laurent Pinchart | 4a1b071 | 2012-05-17 13:27:21 +0200 | [diff] [blame] | 2841 | int ret; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 2842 | |
Dave Airlie | fb3b06c | 2011-02-08 13:55:21 +1000 | [diff] [blame] | 2843 | if (!drm_core_check_feature(dev, DRIVER_MODESET)) |
| 2844 | return -EINVAL; |
| 2845 | |
Daniel Vetter | 8484990 | 2012-12-02 00:28:11 +0100 | [diff] [blame] | 2846 | drm_modeset_lock_all(dev); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 2847 | |
| 2848 | obj = drm_mode_object_find(dev, mode_cmd->connector_id, DRM_MODE_OBJECT_CONNECTOR); |
| 2849 | if (!obj) { |
| 2850 | ret = -EINVAL; |
| 2851 | goto out; |
| 2852 | } |
| 2853 | connector = obj_to_connector(obj); |
| 2854 | |
| 2855 | mode = drm_mode_create(dev); |
| 2856 | if (!mode) { |
| 2857 | ret = -ENOMEM; |
| 2858 | goto out; |
| 2859 | } |
| 2860 | |
Ville Syrjälä | 90367bf | 2012-03-13 12:35:44 +0200 | [diff] [blame] | 2861 | ret = drm_crtc_convert_umode(mode, umode); |
| 2862 | if (ret) { |
| 2863 | DRM_DEBUG_KMS("Invalid mode\n"); |
| 2864 | drm_mode_destroy(dev, mode); |
| 2865 | goto out; |
| 2866 | } |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 2867 | |
Ville Syrjälä | 1dd6c8b | 2012-03-13 12:35:42 +0200 | [diff] [blame] | 2868 | drm_mode_attachmode(dev, connector, mode); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 2869 | out: |
Daniel Vetter | 8484990 | 2012-12-02 00:28:11 +0100 | [diff] [blame] | 2870 | drm_modeset_unlock_all(dev); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 2871 | return ret; |
| 2872 | } |
| 2873 | |
| 2874 | |
| 2875 | /** |
| 2876 | * drm_fb_detachmode - Detach a user specified mode from an connector |
Daniel Vetter | 065a50ed | 2012-12-02 00:09:18 +0100 | [diff] [blame] | 2877 | * @dev: drm device for the ioctl |
| 2878 | * @data: data pointer for the ioctl |
| 2879 | * @file_priv: drm file for the ioctl call |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 2880 | * |
| 2881 | * Called by the user via ioctl. |
| 2882 | * |
| 2883 | * RETURNS: |
| 2884 | * Zero on success, errno on failure. |
| 2885 | */ |
| 2886 | int drm_mode_detachmode_ioctl(struct drm_device *dev, |
| 2887 | void *data, struct drm_file *file_priv) |
| 2888 | { |
| 2889 | struct drm_mode_object *obj; |
| 2890 | struct drm_mode_mode_cmd *mode_cmd = data; |
| 2891 | struct drm_connector *connector; |
| 2892 | struct drm_display_mode mode; |
| 2893 | struct drm_mode_modeinfo *umode = &mode_cmd->mode; |
Laurent Pinchart | 4a1b071 | 2012-05-17 13:27:21 +0200 | [diff] [blame] | 2894 | int ret; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 2895 | |
Dave Airlie | fb3b06c | 2011-02-08 13:55:21 +1000 | [diff] [blame] | 2896 | if (!drm_core_check_feature(dev, DRIVER_MODESET)) |
| 2897 | return -EINVAL; |
| 2898 | |
Daniel Vetter | 8484990 | 2012-12-02 00:28:11 +0100 | [diff] [blame] | 2899 | drm_modeset_lock_all(dev); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 2900 | |
| 2901 | obj = drm_mode_object_find(dev, mode_cmd->connector_id, DRM_MODE_OBJECT_CONNECTOR); |
| 2902 | if (!obj) { |
| 2903 | ret = -EINVAL; |
| 2904 | goto out; |
| 2905 | } |
| 2906 | connector = obj_to_connector(obj); |
| 2907 | |
Ville Syrjälä | 90367bf | 2012-03-13 12:35:44 +0200 | [diff] [blame] | 2908 | ret = drm_crtc_convert_umode(&mode, umode); |
| 2909 | if (ret) { |
| 2910 | DRM_DEBUG_KMS("Invalid mode\n"); |
| 2911 | goto out; |
| 2912 | } |
| 2913 | |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 2914 | ret = drm_mode_detachmode(dev, connector, &mode); |
| 2915 | out: |
Daniel Vetter | 8484990 | 2012-12-02 00:28:11 +0100 | [diff] [blame] | 2916 | drm_modeset_unlock_all(dev); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 2917 | return ret; |
| 2918 | } |
| 2919 | |
| 2920 | struct drm_property *drm_property_create(struct drm_device *dev, int flags, |
| 2921 | const char *name, int num_values) |
| 2922 | { |
| 2923 | struct drm_property *property = NULL; |
Ville Syrjälä | 6bfc56a | 2012-03-13 12:35:48 +0200 | [diff] [blame] | 2924 | int ret; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 2925 | |
| 2926 | property = kzalloc(sizeof(struct drm_property), GFP_KERNEL); |
| 2927 | if (!property) |
| 2928 | return NULL; |
| 2929 | |
| 2930 | if (num_values) { |
| 2931 | property->values = kzalloc(sizeof(uint64_t)*num_values, GFP_KERNEL); |
| 2932 | if (!property->values) |
| 2933 | goto fail; |
| 2934 | } |
| 2935 | |
Ville Syrjälä | 6bfc56a | 2012-03-13 12:35:48 +0200 | [diff] [blame] | 2936 | ret = drm_mode_object_get(dev, &property->base, DRM_MODE_OBJECT_PROPERTY); |
| 2937 | if (ret) |
| 2938 | goto fail; |
| 2939 | |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 2940 | property->flags = flags; |
| 2941 | property->num_values = num_values; |
| 2942 | INIT_LIST_HEAD(&property->enum_blob_list); |
| 2943 | |
Vinson Lee | 471dd2e | 2011-11-10 11:55:40 -0800 | [diff] [blame] | 2944 | if (name) { |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 2945 | strncpy(property->name, name, DRM_PROP_NAME_LEN); |
Vinson Lee | 471dd2e | 2011-11-10 11:55:40 -0800 | [diff] [blame] | 2946 | property->name[DRM_PROP_NAME_LEN-1] = '\0'; |
| 2947 | } |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 2948 | |
| 2949 | list_add_tail(&property->head, &dev->mode_config.property_list); |
| 2950 | return property; |
| 2951 | fail: |
Ville Syrjälä | 6bfc56a | 2012-03-13 12:35:48 +0200 | [diff] [blame] | 2952 | kfree(property->values); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 2953 | kfree(property); |
| 2954 | return NULL; |
| 2955 | } |
| 2956 | EXPORT_SYMBOL(drm_property_create); |
| 2957 | |
Sascha Hauer | 4a67d39 | 2012-02-06 10:58:17 +0100 | [diff] [blame] | 2958 | struct drm_property *drm_property_create_enum(struct drm_device *dev, int flags, |
| 2959 | const char *name, |
| 2960 | const struct drm_prop_enum_list *props, |
| 2961 | int num_values) |
| 2962 | { |
| 2963 | struct drm_property *property; |
| 2964 | int i, ret; |
| 2965 | |
| 2966 | flags |= DRM_MODE_PROP_ENUM; |
| 2967 | |
| 2968 | property = drm_property_create(dev, flags, name, num_values); |
| 2969 | if (!property) |
| 2970 | return NULL; |
| 2971 | |
| 2972 | for (i = 0; i < num_values; i++) { |
| 2973 | ret = drm_property_add_enum(property, i, |
| 2974 | props[i].type, |
| 2975 | props[i].name); |
| 2976 | if (ret) { |
| 2977 | drm_property_destroy(dev, property); |
| 2978 | return NULL; |
| 2979 | } |
| 2980 | } |
| 2981 | |
| 2982 | return property; |
| 2983 | } |
| 2984 | EXPORT_SYMBOL(drm_property_create_enum); |
| 2985 | |
Rob Clark | 49e2754 | 2012-05-17 02:23:26 -0600 | [diff] [blame] | 2986 | struct drm_property *drm_property_create_bitmask(struct drm_device *dev, |
| 2987 | int flags, const char *name, |
| 2988 | const struct drm_prop_enum_list *props, |
| 2989 | int num_values) |
| 2990 | { |
| 2991 | struct drm_property *property; |
| 2992 | int i, ret; |
| 2993 | |
| 2994 | flags |= DRM_MODE_PROP_BITMASK; |
| 2995 | |
| 2996 | property = drm_property_create(dev, flags, name, num_values); |
| 2997 | if (!property) |
| 2998 | return NULL; |
| 2999 | |
| 3000 | for (i = 0; i < num_values; i++) { |
| 3001 | ret = drm_property_add_enum(property, i, |
| 3002 | props[i].type, |
| 3003 | props[i].name); |
| 3004 | if (ret) { |
| 3005 | drm_property_destroy(dev, property); |
| 3006 | return NULL; |
| 3007 | } |
| 3008 | } |
| 3009 | |
| 3010 | return property; |
| 3011 | } |
| 3012 | EXPORT_SYMBOL(drm_property_create_bitmask); |
| 3013 | |
Sascha Hauer | d9bc3c0 | 2012-02-06 10:58:18 +0100 | [diff] [blame] | 3014 | struct drm_property *drm_property_create_range(struct drm_device *dev, int flags, |
| 3015 | const char *name, |
| 3016 | uint64_t min, uint64_t max) |
| 3017 | { |
| 3018 | struct drm_property *property; |
| 3019 | |
| 3020 | flags |= DRM_MODE_PROP_RANGE; |
| 3021 | |
| 3022 | property = drm_property_create(dev, flags, name, 2); |
| 3023 | if (!property) |
| 3024 | return NULL; |
| 3025 | |
| 3026 | property->values[0] = min; |
| 3027 | property->values[1] = max; |
| 3028 | |
| 3029 | return property; |
| 3030 | } |
| 3031 | EXPORT_SYMBOL(drm_property_create_range); |
| 3032 | |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 3033 | int drm_property_add_enum(struct drm_property *property, int index, |
| 3034 | uint64_t value, const char *name) |
| 3035 | { |
| 3036 | struct drm_property_enum *prop_enum; |
| 3037 | |
Rob Clark | 49e2754 | 2012-05-17 02:23:26 -0600 | [diff] [blame] | 3038 | if (!(property->flags & (DRM_MODE_PROP_ENUM | DRM_MODE_PROP_BITMASK))) |
| 3039 | return -EINVAL; |
| 3040 | |
| 3041 | /* |
| 3042 | * Bitmask enum properties have the additional constraint of values |
| 3043 | * from 0 to 63 |
| 3044 | */ |
| 3045 | if ((property->flags & DRM_MODE_PROP_BITMASK) && (value > 63)) |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 3046 | return -EINVAL; |
| 3047 | |
| 3048 | if (!list_empty(&property->enum_blob_list)) { |
| 3049 | list_for_each_entry(prop_enum, &property->enum_blob_list, head) { |
| 3050 | if (prop_enum->value == value) { |
| 3051 | strncpy(prop_enum->name, name, DRM_PROP_NAME_LEN); |
| 3052 | prop_enum->name[DRM_PROP_NAME_LEN-1] = '\0'; |
| 3053 | return 0; |
| 3054 | } |
| 3055 | } |
| 3056 | } |
| 3057 | |
| 3058 | prop_enum = kzalloc(sizeof(struct drm_property_enum), GFP_KERNEL); |
| 3059 | if (!prop_enum) |
| 3060 | return -ENOMEM; |
| 3061 | |
| 3062 | strncpy(prop_enum->name, name, DRM_PROP_NAME_LEN); |
| 3063 | prop_enum->name[DRM_PROP_NAME_LEN-1] = '\0'; |
| 3064 | prop_enum->value = value; |
| 3065 | |
| 3066 | property->values[index] = value; |
| 3067 | list_add_tail(&prop_enum->head, &property->enum_blob_list); |
| 3068 | return 0; |
| 3069 | } |
| 3070 | EXPORT_SYMBOL(drm_property_add_enum); |
| 3071 | |
| 3072 | void drm_property_destroy(struct drm_device *dev, struct drm_property *property) |
| 3073 | { |
| 3074 | struct drm_property_enum *prop_enum, *pt; |
| 3075 | |
| 3076 | list_for_each_entry_safe(prop_enum, pt, &property->enum_blob_list, head) { |
| 3077 | list_del(&prop_enum->head); |
| 3078 | kfree(prop_enum); |
| 3079 | } |
| 3080 | |
| 3081 | if (property->num_values) |
| 3082 | kfree(property->values); |
| 3083 | drm_mode_object_put(dev, &property->base); |
| 3084 | list_del(&property->head); |
| 3085 | kfree(property); |
| 3086 | } |
| 3087 | EXPORT_SYMBOL(drm_property_destroy); |
| 3088 | |
Paulo Zanoni | c543188 | 2012-05-15 18:09:02 -0300 | [diff] [blame] | 3089 | void drm_object_attach_property(struct drm_mode_object *obj, |
| 3090 | struct drm_property *property, |
| 3091 | uint64_t init_val) |
| 3092 | { |
Paulo Zanoni | 7f88a9b | 2012-05-15 18:09:04 -0300 | [diff] [blame] | 3093 | int count = obj->properties->count; |
Paulo Zanoni | c543188 | 2012-05-15 18:09:02 -0300 | [diff] [blame] | 3094 | |
Paulo Zanoni | 7f88a9b | 2012-05-15 18:09:04 -0300 | [diff] [blame] | 3095 | if (count == DRM_OBJECT_MAX_PROPERTY) { |
| 3096 | WARN(1, "Failed to attach object property (type: 0x%x). Please " |
| 3097 | "increase DRM_OBJECT_MAX_PROPERTY by 1 for each time " |
| 3098 | "you see this message on the same object type.\n", |
| 3099 | obj->type); |
| 3100 | return; |
Paulo Zanoni | c543188 | 2012-05-15 18:09:02 -0300 | [diff] [blame] | 3101 | } |
| 3102 | |
Paulo Zanoni | 7f88a9b | 2012-05-15 18:09:04 -0300 | [diff] [blame] | 3103 | obj->properties->ids[count] = property->base.id; |
| 3104 | obj->properties->values[count] = init_val; |
| 3105 | obj->properties->count++; |
Paulo Zanoni | c543188 | 2012-05-15 18:09:02 -0300 | [diff] [blame] | 3106 | } |
| 3107 | EXPORT_SYMBOL(drm_object_attach_property); |
| 3108 | |
| 3109 | int drm_object_property_set_value(struct drm_mode_object *obj, |
| 3110 | struct drm_property *property, uint64_t val) |
| 3111 | { |
| 3112 | int i; |
| 3113 | |
Paulo Zanoni | 7f88a9b | 2012-05-15 18:09:04 -0300 | [diff] [blame] | 3114 | for (i = 0; i < obj->properties->count; i++) { |
Paulo Zanoni | c543188 | 2012-05-15 18:09:02 -0300 | [diff] [blame] | 3115 | if (obj->properties->ids[i] == property->base.id) { |
| 3116 | obj->properties->values[i] = val; |
| 3117 | return 0; |
| 3118 | } |
| 3119 | } |
| 3120 | |
| 3121 | return -EINVAL; |
| 3122 | } |
| 3123 | EXPORT_SYMBOL(drm_object_property_set_value); |
| 3124 | |
| 3125 | int drm_object_property_get_value(struct drm_mode_object *obj, |
| 3126 | struct drm_property *property, uint64_t *val) |
| 3127 | { |
| 3128 | int i; |
| 3129 | |
Paulo Zanoni | 7f88a9b | 2012-05-15 18:09:04 -0300 | [diff] [blame] | 3130 | for (i = 0; i < obj->properties->count; i++) { |
Paulo Zanoni | c543188 | 2012-05-15 18:09:02 -0300 | [diff] [blame] | 3131 | if (obj->properties->ids[i] == property->base.id) { |
| 3132 | *val = obj->properties->values[i]; |
| 3133 | return 0; |
| 3134 | } |
| 3135 | } |
| 3136 | |
| 3137 | return -EINVAL; |
| 3138 | } |
| 3139 | EXPORT_SYMBOL(drm_object_property_get_value); |
| 3140 | |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 3141 | int drm_mode_getproperty_ioctl(struct drm_device *dev, |
| 3142 | void *data, struct drm_file *file_priv) |
| 3143 | { |
| 3144 | struct drm_mode_object *obj; |
| 3145 | struct drm_mode_get_property *out_resp = data; |
| 3146 | struct drm_property *property; |
| 3147 | int enum_count = 0; |
| 3148 | int blob_count = 0; |
| 3149 | int value_count = 0; |
| 3150 | int ret = 0, i; |
| 3151 | int copied; |
| 3152 | struct drm_property_enum *prop_enum; |
| 3153 | struct drm_mode_property_enum __user *enum_ptr; |
| 3154 | struct drm_property_blob *prop_blob; |
Ville Syrjälä | 81f6c7f | 2011-12-20 00:06:42 +0200 | [diff] [blame] | 3155 | uint32_t __user *blob_id_ptr; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 3156 | uint64_t __user *values_ptr; |
| 3157 | uint32_t __user *blob_length_ptr; |
| 3158 | |
Dave Airlie | fb3b06c | 2011-02-08 13:55:21 +1000 | [diff] [blame] | 3159 | if (!drm_core_check_feature(dev, DRIVER_MODESET)) |
| 3160 | return -EINVAL; |
| 3161 | |
Daniel Vetter | 8484990 | 2012-12-02 00:28:11 +0100 | [diff] [blame] | 3162 | drm_modeset_lock_all(dev); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 3163 | obj = drm_mode_object_find(dev, out_resp->prop_id, DRM_MODE_OBJECT_PROPERTY); |
| 3164 | if (!obj) { |
| 3165 | ret = -EINVAL; |
| 3166 | goto done; |
| 3167 | } |
| 3168 | property = obj_to_property(obj); |
| 3169 | |
Rob Clark | 49e2754 | 2012-05-17 02:23:26 -0600 | [diff] [blame] | 3170 | if (property->flags & (DRM_MODE_PROP_ENUM | DRM_MODE_PROP_BITMASK)) { |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 3171 | list_for_each_entry(prop_enum, &property->enum_blob_list, head) |
| 3172 | enum_count++; |
| 3173 | } else if (property->flags & DRM_MODE_PROP_BLOB) { |
| 3174 | list_for_each_entry(prop_blob, &property->enum_blob_list, head) |
| 3175 | blob_count++; |
| 3176 | } |
| 3177 | |
| 3178 | value_count = property->num_values; |
| 3179 | |
| 3180 | strncpy(out_resp->name, property->name, DRM_PROP_NAME_LEN); |
| 3181 | out_resp->name[DRM_PROP_NAME_LEN-1] = 0; |
| 3182 | out_resp->flags = property->flags; |
| 3183 | |
| 3184 | if ((out_resp->count_values >= value_count) && value_count) { |
Ville Syrjälä | 81f6c7f | 2011-12-20 00:06:42 +0200 | [diff] [blame] | 3185 | values_ptr = (uint64_t __user *)(unsigned long)out_resp->values_ptr; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 3186 | for (i = 0; i < value_count; i++) { |
| 3187 | if (copy_to_user(values_ptr + i, &property->values[i], sizeof(uint64_t))) { |
| 3188 | ret = -EFAULT; |
| 3189 | goto done; |
| 3190 | } |
| 3191 | } |
| 3192 | } |
| 3193 | out_resp->count_values = value_count; |
| 3194 | |
Rob Clark | 49e2754 | 2012-05-17 02:23:26 -0600 | [diff] [blame] | 3195 | if (property->flags & (DRM_MODE_PROP_ENUM | DRM_MODE_PROP_BITMASK)) { |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 3196 | if ((out_resp->count_enum_blobs >= enum_count) && enum_count) { |
| 3197 | copied = 0; |
Ville Syrjälä | 81f6c7f | 2011-12-20 00:06:42 +0200 | [diff] [blame] | 3198 | enum_ptr = (struct drm_mode_property_enum __user *)(unsigned long)out_resp->enum_blob_ptr; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 3199 | list_for_each_entry(prop_enum, &property->enum_blob_list, head) { |
| 3200 | |
| 3201 | if (copy_to_user(&enum_ptr[copied].value, &prop_enum->value, sizeof(uint64_t))) { |
| 3202 | ret = -EFAULT; |
| 3203 | goto done; |
| 3204 | } |
| 3205 | |
| 3206 | if (copy_to_user(&enum_ptr[copied].name, |
| 3207 | &prop_enum->name, DRM_PROP_NAME_LEN)) { |
| 3208 | ret = -EFAULT; |
| 3209 | goto done; |
| 3210 | } |
| 3211 | copied++; |
| 3212 | } |
| 3213 | } |
| 3214 | out_resp->count_enum_blobs = enum_count; |
| 3215 | } |
| 3216 | |
| 3217 | if (property->flags & DRM_MODE_PROP_BLOB) { |
| 3218 | if ((out_resp->count_enum_blobs >= blob_count) && blob_count) { |
| 3219 | copied = 0; |
Ville Syrjälä | 81f6c7f | 2011-12-20 00:06:42 +0200 | [diff] [blame] | 3220 | blob_id_ptr = (uint32_t __user *)(unsigned long)out_resp->enum_blob_ptr; |
| 3221 | blob_length_ptr = (uint32_t __user *)(unsigned long)out_resp->values_ptr; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 3222 | |
| 3223 | list_for_each_entry(prop_blob, &property->enum_blob_list, head) { |
| 3224 | if (put_user(prop_blob->base.id, blob_id_ptr + copied)) { |
| 3225 | ret = -EFAULT; |
| 3226 | goto done; |
| 3227 | } |
| 3228 | |
| 3229 | if (put_user(prop_blob->length, blob_length_ptr + copied)) { |
| 3230 | ret = -EFAULT; |
| 3231 | goto done; |
| 3232 | } |
| 3233 | |
| 3234 | copied++; |
| 3235 | } |
| 3236 | } |
| 3237 | out_resp->count_enum_blobs = blob_count; |
| 3238 | } |
| 3239 | done: |
Daniel Vetter | 8484990 | 2012-12-02 00:28:11 +0100 | [diff] [blame] | 3240 | drm_modeset_unlock_all(dev); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 3241 | return ret; |
| 3242 | } |
| 3243 | |
| 3244 | static struct drm_property_blob *drm_property_create_blob(struct drm_device *dev, int length, |
| 3245 | void *data) |
| 3246 | { |
| 3247 | struct drm_property_blob *blob; |
Ville Syrjälä | 6bfc56a | 2012-03-13 12:35:48 +0200 | [diff] [blame] | 3248 | int ret; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 3249 | |
| 3250 | if (!length || !data) |
| 3251 | return NULL; |
| 3252 | |
| 3253 | blob = kzalloc(sizeof(struct drm_property_blob)+length, GFP_KERNEL); |
| 3254 | if (!blob) |
| 3255 | return NULL; |
| 3256 | |
Ville Syrjälä | 6bfc56a | 2012-03-13 12:35:48 +0200 | [diff] [blame] | 3257 | ret = drm_mode_object_get(dev, &blob->base, DRM_MODE_OBJECT_BLOB); |
| 3258 | if (ret) { |
| 3259 | kfree(blob); |
| 3260 | return NULL; |
| 3261 | } |
| 3262 | |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 3263 | blob->length = length; |
| 3264 | |
| 3265 | memcpy(blob->data, data, length); |
| 3266 | |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 3267 | list_add_tail(&blob->head, &dev->mode_config.property_blob_list); |
| 3268 | return blob; |
| 3269 | } |
| 3270 | |
| 3271 | static void drm_property_destroy_blob(struct drm_device *dev, |
| 3272 | struct drm_property_blob *blob) |
| 3273 | { |
| 3274 | drm_mode_object_put(dev, &blob->base); |
| 3275 | list_del(&blob->head); |
| 3276 | kfree(blob); |
| 3277 | } |
| 3278 | |
| 3279 | int drm_mode_getblob_ioctl(struct drm_device *dev, |
| 3280 | void *data, struct drm_file *file_priv) |
| 3281 | { |
| 3282 | struct drm_mode_object *obj; |
| 3283 | struct drm_mode_get_blob *out_resp = data; |
| 3284 | struct drm_property_blob *blob; |
| 3285 | int ret = 0; |
Ville Syrjälä | 81f6c7f | 2011-12-20 00:06:42 +0200 | [diff] [blame] | 3286 | void __user *blob_ptr; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 3287 | |
Dave Airlie | fb3b06c | 2011-02-08 13:55:21 +1000 | [diff] [blame] | 3288 | if (!drm_core_check_feature(dev, DRIVER_MODESET)) |
| 3289 | return -EINVAL; |
| 3290 | |
Daniel Vetter | 8484990 | 2012-12-02 00:28:11 +0100 | [diff] [blame] | 3291 | drm_modeset_lock_all(dev); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 3292 | obj = drm_mode_object_find(dev, out_resp->blob_id, DRM_MODE_OBJECT_BLOB); |
| 3293 | if (!obj) { |
| 3294 | ret = -EINVAL; |
| 3295 | goto done; |
| 3296 | } |
| 3297 | blob = obj_to_blob(obj); |
| 3298 | |
| 3299 | if (out_resp->length == blob->length) { |
Ville Syrjälä | 81f6c7f | 2011-12-20 00:06:42 +0200 | [diff] [blame] | 3300 | blob_ptr = (void __user *)(unsigned long)out_resp->data; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 3301 | if (copy_to_user(blob_ptr, blob->data, blob->length)){ |
| 3302 | ret = -EFAULT; |
| 3303 | goto done; |
| 3304 | } |
| 3305 | } |
| 3306 | out_resp->length = blob->length; |
| 3307 | |
| 3308 | done: |
Daniel Vetter | 8484990 | 2012-12-02 00:28:11 +0100 | [diff] [blame] | 3309 | drm_modeset_unlock_all(dev); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 3310 | return ret; |
| 3311 | } |
| 3312 | |
| 3313 | int drm_mode_connector_update_edid_property(struct drm_connector *connector, |
| 3314 | struct edid *edid) |
| 3315 | { |
| 3316 | struct drm_device *dev = connector->dev; |
Laurent Pinchart | 4a1b071 | 2012-05-17 13:27:21 +0200 | [diff] [blame] | 3317 | int ret, size; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 3318 | |
| 3319 | if (connector->edid_blob_ptr) |
| 3320 | drm_property_destroy_blob(dev, connector->edid_blob_ptr); |
| 3321 | |
| 3322 | /* Delete edid, when there is none. */ |
| 3323 | if (!edid) { |
| 3324 | connector->edid_blob_ptr = NULL; |
Rob Clark | 5849556 | 2012-10-11 20:50:56 -0500 | [diff] [blame] | 3325 | ret = drm_object_property_set_value(&connector->base, dev->mode_config.edid_property, 0); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 3326 | return ret; |
| 3327 | } |
| 3328 | |
Adam Jackson | 7466f4c | 2010-03-29 21:43:23 +0000 | [diff] [blame] | 3329 | size = EDID_LENGTH * (1 + edid->extensions); |
| 3330 | connector->edid_blob_ptr = drm_property_create_blob(connector->dev, |
| 3331 | size, edid); |
Sachin Kamat | e655d12 | 2012-11-19 09:44:57 +0000 | [diff] [blame] | 3332 | if (!connector->edid_blob_ptr) |
| 3333 | return -EINVAL; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 3334 | |
Rob Clark | 5849556 | 2012-10-11 20:50:56 -0500 | [diff] [blame] | 3335 | ret = drm_object_property_set_value(&connector->base, |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 3336 | dev->mode_config.edid_property, |
| 3337 | connector->edid_blob_ptr->base.id); |
| 3338 | |
| 3339 | return ret; |
| 3340 | } |
| 3341 | EXPORT_SYMBOL(drm_mode_connector_update_edid_property); |
| 3342 | |
Paulo Zanoni | 26a3481 | 2012-05-15 18:08:59 -0300 | [diff] [blame] | 3343 | static bool drm_property_change_is_valid(struct drm_property *property, |
Ville Syrjälä | 592c20e | 2012-05-24 20:53:58 +0300 | [diff] [blame] | 3344 | uint64_t value) |
Paulo Zanoni | 26a3481 | 2012-05-15 18:08:59 -0300 | [diff] [blame] | 3345 | { |
| 3346 | if (property->flags & DRM_MODE_PROP_IMMUTABLE) |
| 3347 | return false; |
| 3348 | if (property->flags & DRM_MODE_PROP_RANGE) { |
| 3349 | if (value < property->values[0] || value > property->values[1]) |
| 3350 | return false; |
| 3351 | return true; |
Rob Clark | 49e2754 | 2012-05-17 02:23:26 -0600 | [diff] [blame] | 3352 | } else if (property->flags & DRM_MODE_PROP_BITMASK) { |
| 3353 | int i; |
Ville Syrjälä | 592c20e | 2012-05-24 20:53:58 +0300 | [diff] [blame] | 3354 | uint64_t valid_mask = 0; |
Rob Clark | 49e2754 | 2012-05-17 02:23:26 -0600 | [diff] [blame] | 3355 | for (i = 0; i < property->num_values; i++) |
| 3356 | valid_mask |= (1ULL << property->values[i]); |
| 3357 | return !(value & ~valid_mask); |
Ville Syrjälä | c4a5675 | 2012-10-25 18:05:06 +0000 | [diff] [blame] | 3358 | } else if (property->flags & DRM_MODE_PROP_BLOB) { |
| 3359 | /* Only the driver knows */ |
| 3360 | return true; |
Paulo Zanoni | 26a3481 | 2012-05-15 18:08:59 -0300 | [diff] [blame] | 3361 | } else { |
| 3362 | int i; |
| 3363 | for (i = 0; i < property->num_values; i++) |
| 3364 | if (property->values[i] == value) |
| 3365 | return true; |
| 3366 | return false; |
| 3367 | } |
| 3368 | } |
| 3369 | |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 3370 | int drm_mode_connector_property_set_ioctl(struct drm_device *dev, |
| 3371 | void *data, struct drm_file *file_priv) |
| 3372 | { |
Paulo Zanoni | 0057d8d | 2012-05-15 18:09:03 -0300 | [diff] [blame] | 3373 | struct drm_mode_connector_set_property *conn_set_prop = data; |
| 3374 | struct drm_mode_obj_set_property obj_set_prop = { |
| 3375 | .value = conn_set_prop->value, |
| 3376 | .prop_id = conn_set_prop->prop_id, |
| 3377 | .obj_id = conn_set_prop->connector_id, |
| 3378 | .obj_type = DRM_MODE_OBJECT_CONNECTOR |
| 3379 | }; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 3380 | |
Paulo Zanoni | 0057d8d | 2012-05-15 18:09:03 -0300 | [diff] [blame] | 3381 | /* It does all the locking and checking we need */ |
| 3382 | 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] | 3383 | } |
| 3384 | |
Paulo Zanoni | c543188 | 2012-05-15 18:09:02 -0300 | [diff] [blame] | 3385 | static int drm_mode_connector_set_obj_prop(struct drm_mode_object *obj, |
| 3386 | struct drm_property *property, |
| 3387 | uint64_t value) |
| 3388 | { |
| 3389 | int ret = -EINVAL; |
| 3390 | struct drm_connector *connector = obj_to_connector(obj); |
| 3391 | |
| 3392 | /* Do DPMS ourselves */ |
| 3393 | if (property == connector->dev->mode_config.dpms_property) { |
| 3394 | if (connector->funcs->dpms) |
| 3395 | (*connector->funcs->dpms)(connector, (int)value); |
| 3396 | ret = 0; |
| 3397 | } else if (connector->funcs->set_property) |
| 3398 | ret = connector->funcs->set_property(connector, property, value); |
| 3399 | |
| 3400 | /* store the property value if successful */ |
| 3401 | if (!ret) |
Rob Clark | 5849556 | 2012-10-11 20:50:56 -0500 | [diff] [blame] | 3402 | drm_object_property_set_value(&connector->base, property, value); |
Paulo Zanoni | c543188 | 2012-05-15 18:09:02 -0300 | [diff] [blame] | 3403 | return ret; |
| 3404 | } |
| 3405 | |
Paulo Zanoni | bffd9de0 | 2012-05-15 18:09:05 -0300 | [diff] [blame] | 3406 | static int drm_mode_crtc_set_obj_prop(struct drm_mode_object *obj, |
| 3407 | struct drm_property *property, |
| 3408 | uint64_t value) |
| 3409 | { |
| 3410 | int ret = -EINVAL; |
| 3411 | struct drm_crtc *crtc = obj_to_crtc(obj); |
| 3412 | |
| 3413 | if (crtc->funcs->set_property) |
| 3414 | ret = crtc->funcs->set_property(crtc, property, value); |
| 3415 | if (!ret) |
| 3416 | drm_object_property_set_value(obj, property, value); |
| 3417 | |
| 3418 | return ret; |
| 3419 | } |
| 3420 | |
Rob Clark | 4d93914 | 2012-05-17 02:23:27 -0600 | [diff] [blame] | 3421 | static int drm_mode_plane_set_obj_prop(struct drm_mode_object *obj, |
| 3422 | struct drm_property *property, |
| 3423 | uint64_t value) |
| 3424 | { |
| 3425 | int ret = -EINVAL; |
| 3426 | struct drm_plane *plane = obj_to_plane(obj); |
| 3427 | |
| 3428 | if (plane->funcs->set_property) |
| 3429 | ret = plane->funcs->set_property(plane, property, value); |
| 3430 | if (!ret) |
| 3431 | drm_object_property_set_value(obj, property, value); |
| 3432 | |
| 3433 | return ret; |
| 3434 | } |
| 3435 | |
Paulo Zanoni | c543188 | 2012-05-15 18:09:02 -0300 | [diff] [blame] | 3436 | int drm_mode_obj_get_properties_ioctl(struct drm_device *dev, void *data, |
| 3437 | struct drm_file *file_priv) |
| 3438 | { |
| 3439 | struct drm_mode_obj_get_properties *arg = data; |
| 3440 | struct drm_mode_object *obj; |
| 3441 | int ret = 0; |
| 3442 | int i; |
| 3443 | int copied = 0; |
| 3444 | int props_count = 0; |
| 3445 | uint32_t __user *props_ptr; |
| 3446 | uint64_t __user *prop_values_ptr; |
| 3447 | |
| 3448 | if (!drm_core_check_feature(dev, DRIVER_MODESET)) |
| 3449 | return -EINVAL; |
| 3450 | |
Daniel Vetter | 8484990 | 2012-12-02 00:28:11 +0100 | [diff] [blame] | 3451 | drm_modeset_lock_all(dev); |
Paulo Zanoni | c543188 | 2012-05-15 18:09:02 -0300 | [diff] [blame] | 3452 | |
| 3453 | obj = drm_mode_object_find(dev, arg->obj_id, arg->obj_type); |
| 3454 | if (!obj) { |
| 3455 | ret = -EINVAL; |
| 3456 | goto out; |
| 3457 | } |
| 3458 | if (!obj->properties) { |
| 3459 | ret = -EINVAL; |
| 3460 | goto out; |
| 3461 | } |
| 3462 | |
Paulo Zanoni | 7f88a9b | 2012-05-15 18:09:04 -0300 | [diff] [blame] | 3463 | props_count = obj->properties->count; |
Paulo Zanoni | c543188 | 2012-05-15 18:09:02 -0300 | [diff] [blame] | 3464 | |
| 3465 | /* This ioctl is called twice, once to determine how much space is |
| 3466 | * needed, and the 2nd time to fill it. */ |
| 3467 | if ((arg->count_props >= props_count) && props_count) { |
| 3468 | copied = 0; |
| 3469 | props_ptr = (uint32_t __user *)(unsigned long)(arg->props_ptr); |
| 3470 | prop_values_ptr = (uint64_t __user *)(unsigned long) |
| 3471 | (arg->prop_values_ptr); |
| 3472 | for (i = 0; i < props_count; i++) { |
| 3473 | if (put_user(obj->properties->ids[i], |
| 3474 | props_ptr + copied)) { |
| 3475 | ret = -EFAULT; |
| 3476 | goto out; |
| 3477 | } |
| 3478 | if (put_user(obj->properties->values[i], |
| 3479 | prop_values_ptr + copied)) { |
| 3480 | ret = -EFAULT; |
| 3481 | goto out; |
| 3482 | } |
| 3483 | copied++; |
| 3484 | } |
| 3485 | } |
| 3486 | arg->count_props = props_count; |
| 3487 | out: |
Daniel Vetter | 8484990 | 2012-12-02 00:28:11 +0100 | [diff] [blame] | 3488 | drm_modeset_unlock_all(dev); |
Paulo Zanoni | c543188 | 2012-05-15 18:09:02 -0300 | [diff] [blame] | 3489 | return ret; |
| 3490 | } |
| 3491 | |
| 3492 | int drm_mode_obj_set_property_ioctl(struct drm_device *dev, void *data, |
| 3493 | struct drm_file *file_priv) |
| 3494 | { |
| 3495 | struct drm_mode_obj_set_property *arg = data; |
| 3496 | struct drm_mode_object *arg_obj; |
| 3497 | struct drm_mode_object *prop_obj; |
| 3498 | struct drm_property *property; |
| 3499 | int ret = -EINVAL; |
| 3500 | int i; |
| 3501 | |
| 3502 | if (!drm_core_check_feature(dev, DRIVER_MODESET)) |
| 3503 | return -EINVAL; |
| 3504 | |
Daniel Vetter | 8484990 | 2012-12-02 00:28:11 +0100 | [diff] [blame] | 3505 | drm_modeset_lock_all(dev); |
Paulo Zanoni | c543188 | 2012-05-15 18:09:02 -0300 | [diff] [blame] | 3506 | |
| 3507 | arg_obj = drm_mode_object_find(dev, arg->obj_id, arg->obj_type); |
| 3508 | if (!arg_obj) |
| 3509 | goto out; |
| 3510 | if (!arg_obj->properties) |
| 3511 | goto out; |
| 3512 | |
Paulo Zanoni | 7f88a9b | 2012-05-15 18:09:04 -0300 | [diff] [blame] | 3513 | for (i = 0; i < arg_obj->properties->count; i++) |
Paulo Zanoni | c543188 | 2012-05-15 18:09:02 -0300 | [diff] [blame] | 3514 | if (arg_obj->properties->ids[i] == arg->prop_id) |
| 3515 | break; |
| 3516 | |
Paulo Zanoni | 7f88a9b | 2012-05-15 18:09:04 -0300 | [diff] [blame] | 3517 | if (i == arg_obj->properties->count) |
Paulo Zanoni | c543188 | 2012-05-15 18:09:02 -0300 | [diff] [blame] | 3518 | goto out; |
| 3519 | |
| 3520 | prop_obj = drm_mode_object_find(dev, arg->prop_id, |
| 3521 | DRM_MODE_OBJECT_PROPERTY); |
| 3522 | if (!prop_obj) |
| 3523 | goto out; |
| 3524 | property = obj_to_property(prop_obj); |
| 3525 | |
| 3526 | if (!drm_property_change_is_valid(property, arg->value)) |
| 3527 | goto out; |
| 3528 | |
| 3529 | switch (arg_obj->type) { |
| 3530 | case DRM_MODE_OBJECT_CONNECTOR: |
| 3531 | ret = drm_mode_connector_set_obj_prop(arg_obj, property, |
| 3532 | arg->value); |
| 3533 | break; |
Paulo Zanoni | bffd9de0 | 2012-05-15 18:09:05 -0300 | [diff] [blame] | 3534 | case DRM_MODE_OBJECT_CRTC: |
| 3535 | ret = drm_mode_crtc_set_obj_prop(arg_obj, property, arg->value); |
| 3536 | break; |
Rob Clark | 4d93914 | 2012-05-17 02:23:27 -0600 | [diff] [blame] | 3537 | case DRM_MODE_OBJECT_PLANE: |
| 3538 | ret = drm_mode_plane_set_obj_prop(arg_obj, property, arg->value); |
| 3539 | break; |
Paulo Zanoni | c543188 | 2012-05-15 18:09:02 -0300 | [diff] [blame] | 3540 | } |
| 3541 | |
| 3542 | out: |
Daniel Vetter | 8484990 | 2012-12-02 00:28:11 +0100 | [diff] [blame] | 3543 | drm_modeset_unlock_all(dev); |
Paulo Zanoni | c543188 | 2012-05-15 18:09:02 -0300 | [diff] [blame] | 3544 | return ret; |
| 3545 | } |
| 3546 | |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 3547 | int drm_mode_connector_attach_encoder(struct drm_connector *connector, |
| 3548 | struct drm_encoder *encoder) |
| 3549 | { |
| 3550 | int i; |
| 3551 | |
| 3552 | for (i = 0; i < DRM_CONNECTOR_MAX_ENCODER; i++) { |
| 3553 | if (connector->encoder_ids[i] == 0) { |
| 3554 | connector->encoder_ids[i] = encoder->base.id; |
| 3555 | return 0; |
| 3556 | } |
| 3557 | } |
| 3558 | return -ENOMEM; |
| 3559 | } |
| 3560 | EXPORT_SYMBOL(drm_mode_connector_attach_encoder); |
| 3561 | |
| 3562 | void drm_mode_connector_detach_encoder(struct drm_connector *connector, |
| 3563 | struct drm_encoder *encoder) |
| 3564 | { |
| 3565 | int i; |
| 3566 | for (i = 0; i < DRM_CONNECTOR_MAX_ENCODER; i++) { |
| 3567 | if (connector->encoder_ids[i] == encoder->base.id) { |
| 3568 | connector->encoder_ids[i] = 0; |
| 3569 | if (connector->encoder == encoder) |
| 3570 | connector->encoder = NULL; |
| 3571 | break; |
| 3572 | } |
| 3573 | } |
| 3574 | } |
| 3575 | EXPORT_SYMBOL(drm_mode_connector_detach_encoder); |
| 3576 | |
Sascha Hauer | 4cae5b8 | 2012-02-01 11:38:23 +0100 | [diff] [blame] | 3577 | int drm_mode_crtc_set_gamma_size(struct drm_crtc *crtc, |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 3578 | int gamma_size) |
| 3579 | { |
| 3580 | crtc->gamma_size = gamma_size; |
| 3581 | |
| 3582 | crtc->gamma_store = kzalloc(gamma_size * sizeof(uint16_t) * 3, GFP_KERNEL); |
| 3583 | if (!crtc->gamma_store) { |
| 3584 | crtc->gamma_size = 0; |
Sascha Hauer | 4cae5b8 | 2012-02-01 11:38:23 +0100 | [diff] [blame] | 3585 | return -ENOMEM; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 3586 | } |
| 3587 | |
Sascha Hauer | 4cae5b8 | 2012-02-01 11:38:23 +0100 | [diff] [blame] | 3588 | return 0; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 3589 | } |
| 3590 | EXPORT_SYMBOL(drm_mode_crtc_set_gamma_size); |
| 3591 | |
| 3592 | int drm_mode_gamma_set_ioctl(struct drm_device *dev, |
| 3593 | void *data, struct drm_file *file_priv) |
| 3594 | { |
| 3595 | struct drm_mode_crtc_lut *crtc_lut = data; |
| 3596 | struct drm_mode_object *obj; |
| 3597 | struct drm_crtc *crtc; |
| 3598 | void *r_base, *g_base, *b_base; |
| 3599 | int size; |
| 3600 | int ret = 0; |
| 3601 | |
Dave Airlie | fb3b06c | 2011-02-08 13:55:21 +1000 | [diff] [blame] | 3602 | if (!drm_core_check_feature(dev, DRIVER_MODESET)) |
| 3603 | return -EINVAL; |
| 3604 | |
Daniel Vetter | 8484990 | 2012-12-02 00:28:11 +0100 | [diff] [blame] | 3605 | drm_modeset_lock_all(dev); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 3606 | obj = drm_mode_object_find(dev, crtc_lut->crtc_id, DRM_MODE_OBJECT_CRTC); |
| 3607 | if (!obj) { |
| 3608 | ret = -EINVAL; |
| 3609 | goto out; |
| 3610 | } |
| 3611 | crtc = obj_to_crtc(obj); |
| 3612 | |
Laurent Pinchart | ebe0f24 | 2012-05-17 13:27:24 +0200 | [diff] [blame] | 3613 | if (crtc->funcs->gamma_set == NULL) { |
| 3614 | ret = -ENOSYS; |
| 3615 | goto out; |
| 3616 | } |
| 3617 | |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 3618 | /* memcpy into gamma store */ |
| 3619 | if (crtc_lut->gamma_size != crtc->gamma_size) { |
| 3620 | ret = -EINVAL; |
| 3621 | goto out; |
| 3622 | } |
| 3623 | |
| 3624 | size = crtc_lut->gamma_size * (sizeof(uint16_t)); |
| 3625 | r_base = crtc->gamma_store; |
| 3626 | if (copy_from_user(r_base, (void __user *)(unsigned long)crtc_lut->red, size)) { |
| 3627 | ret = -EFAULT; |
| 3628 | goto out; |
| 3629 | } |
| 3630 | |
| 3631 | g_base = r_base + size; |
| 3632 | if (copy_from_user(g_base, (void __user *)(unsigned long)crtc_lut->green, size)) { |
| 3633 | ret = -EFAULT; |
| 3634 | goto out; |
| 3635 | } |
| 3636 | |
| 3637 | b_base = g_base + size; |
| 3638 | if (copy_from_user(b_base, (void __user *)(unsigned long)crtc_lut->blue, size)) { |
| 3639 | ret = -EFAULT; |
| 3640 | goto out; |
| 3641 | } |
| 3642 | |
James Simmons | 7203425 | 2010-08-03 01:33:19 +0100 | [diff] [blame] | 3643 | 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] | 3644 | |
| 3645 | out: |
Daniel Vetter | 8484990 | 2012-12-02 00:28:11 +0100 | [diff] [blame] | 3646 | drm_modeset_unlock_all(dev); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 3647 | return ret; |
| 3648 | |
| 3649 | } |
| 3650 | |
| 3651 | int drm_mode_gamma_get_ioctl(struct drm_device *dev, |
| 3652 | void *data, struct drm_file *file_priv) |
| 3653 | { |
| 3654 | struct drm_mode_crtc_lut *crtc_lut = data; |
| 3655 | struct drm_mode_object *obj; |
| 3656 | struct drm_crtc *crtc; |
| 3657 | void *r_base, *g_base, *b_base; |
| 3658 | int size; |
| 3659 | int ret = 0; |
| 3660 | |
Dave Airlie | fb3b06c | 2011-02-08 13:55:21 +1000 | [diff] [blame] | 3661 | if (!drm_core_check_feature(dev, DRIVER_MODESET)) |
| 3662 | return -EINVAL; |
| 3663 | |
Daniel Vetter | 8484990 | 2012-12-02 00:28:11 +0100 | [diff] [blame] | 3664 | drm_modeset_lock_all(dev); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 3665 | obj = drm_mode_object_find(dev, crtc_lut->crtc_id, DRM_MODE_OBJECT_CRTC); |
| 3666 | if (!obj) { |
| 3667 | ret = -EINVAL; |
| 3668 | goto out; |
| 3669 | } |
| 3670 | crtc = obj_to_crtc(obj); |
| 3671 | |
| 3672 | /* memcpy into gamma store */ |
| 3673 | if (crtc_lut->gamma_size != crtc->gamma_size) { |
| 3674 | ret = -EINVAL; |
| 3675 | goto out; |
| 3676 | } |
| 3677 | |
| 3678 | size = crtc_lut->gamma_size * (sizeof(uint16_t)); |
| 3679 | r_base = crtc->gamma_store; |
| 3680 | if (copy_to_user((void __user *)(unsigned long)crtc_lut->red, r_base, size)) { |
| 3681 | ret = -EFAULT; |
| 3682 | goto out; |
| 3683 | } |
| 3684 | |
| 3685 | g_base = r_base + size; |
| 3686 | if (copy_to_user((void __user *)(unsigned long)crtc_lut->green, g_base, size)) { |
| 3687 | ret = -EFAULT; |
| 3688 | goto out; |
| 3689 | } |
| 3690 | |
| 3691 | b_base = g_base + size; |
| 3692 | if (copy_to_user((void __user *)(unsigned long)crtc_lut->blue, b_base, size)) { |
| 3693 | ret = -EFAULT; |
| 3694 | goto out; |
| 3695 | } |
| 3696 | out: |
Daniel Vetter | 8484990 | 2012-12-02 00:28:11 +0100 | [diff] [blame] | 3697 | drm_modeset_unlock_all(dev); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 3698 | return ret; |
| 3699 | } |
Kristian Høgsberg | d91d8a3 | 2009-11-17 12:43:55 -0500 | [diff] [blame] | 3700 | |
| 3701 | int drm_mode_page_flip_ioctl(struct drm_device *dev, |
| 3702 | void *data, struct drm_file *file_priv) |
| 3703 | { |
| 3704 | struct drm_mode_crtc_page_flip *page_flip = data; |
| 3705 | struct drm_mode_object *obj; |
| 3706 | struct drm_crtc *crtc; |
Daniel Vetter | b0d1232 | 2012-12-11 01:07:12 +0100 | [diff] [blame] | 3707 | struct drm_framebuffer *fb = NULL, *old_fb = NULL; |
Kristian Høgsberg | d91d8a3 | 2009-11-17 12:43:55 -0500 | [diff] [blame] | 3708 | struct drm_pending_vblank_event *e = NULL; |
| 3709 | unsigned long flags; |
Rob Clark | 7c80e12 | 2012-09-04 16:35:56 +0000 | [diff] [blame] | 3710 | int hdisplay, vdisplay; |
Kristian Høgsberg | d91d8a3 | 2009-11-17 12:43:55 -0500 | [diff] [blame] | 3711 | int ret = -EINVAL; |
| 3712 | |
| 3713 | if (page_flip->flags & ~DRM_MODE_PAGE_FLIP_FLAGS || |
| 3714 | page_flip->reserved != 0) |
| 3715 | return -EINVAL; |
| 3716 | |
Kristian Høgsberg | d91d8a3 | 2009-11-17 12:43:55 -0500 | [diff] [blame] | 3717 | obj = drm_mode_object_find(dev, page_flip->crtc_id, DRM_MODE_OBJECT_CRTC); |
| 3718 | if (!obj) |
Daniel Vetter | b4d5e7d | 2012-12-11 16:59:31 +0100 | [diff] [blame] | 3719 | return -EINVAL; |
Kristian Høgsberg | d91d8a3 | 2009-11-17 12:43:55 -0500 | [diff] [blame] | 3720 | crtc = obj_to_crtc(obj); |
| 3721 | |
Daniel Vetter | b4d5e7d | 2012-12-11 16:59:31 +0100 | [diff] [blame] | 3722 | mutex_lock(&crtc->mutex); |
Chris Wilson | 90c1efd | 2010-07-17 20:23:26 +0100 | [diff] [blame] | 3723 | if (crtc->fb == NULL) { |
| 3724 | /* The framebuffer is currently unbound, presumably |
| 3725 | * due to a hotplug event, that userspace has not |
| 3726 | * yet discovered. |
| 3727 | */ |
| 3728 | ret = -EBUSY; |
| 3729 | goto out; |
| 3730 | } |
| 3731 | |
Kristian Høgsberg | d91d8a3 | 2009-11-17 12:43:55 -0500 | [diff] [blame] | 3732 | if (crtc->funcs->page_flip == NULL) |
| 3733 | goto out; |
| 3734 | |
Daniel Vetter | 786b99e | 2012-12-02 21:53:40 +0100 | [diff] [blame] | 3735 | fb = drm_framebuffer_lookup(dev, page_flip->fb_id); |
| 3736 | if (!fb) |
Kristian Høgsberg | d91d8a3 | 2009-11-17 12:43:55 -0500 | [diff] [blame] | 3737 | goto out; |
Kristian Høgsberg | d91d8a3 | 2009-11-17 12:43:55 -0500 | [diff] [blame] | 3738 | |
Rob Clark | 7c80e12 | 2012-09-04 16:35:56 +0000 | [diff] [blame] | 3739 | hdisplay = crtc->mode.hdisplay; |
| 3740 | vdisplay = crtc->mode.vdisplay; |
| 3741 | |
| 3742 | if (crtc->invert_dimensions) |
| 3743 | swap(hdisplay, vdisplay); |
| 3744 | |
| 3745 | if (hdisplay > fb->width || |
| 3746 | vdisplay > fb->height || |
| 3747 | crtc->x > fb->width - hdisplay || |
| 3748 | crtc->y > fb->height - vdisplay) { |
| 3749 | DRM_DEBUG_KMS("Invalid fb size %ux%u for CRTC viewport %ux%u+%d+%d%s.\n", |
| 3750 | fb->width, fb->height, hdisplay, vdisplay, crtc->x, crtc->y, |
| 3751 | crtc->invert_dimensions ? " (inverted)" : ""); |
Ville Syrjälä | 5f61bb4 | 2012-03-13 12:35:45 +0200 | [diff] [blame] | 3752 | ret = -ENOSPC; |
| 3753 | goto out; |
| 3754 | } |
| 3755 | |
Kristian Høgsberg | d91d8a3 | 2009-11-17 12:43:55 -0500 | [diff] [blame] | 3756 | if (page_flip->flags & DRM_MODE_PAGE_FLIP_EVENT) { |
| 3757 | ret = -ENOMEM; |
| 3758 | spin_lock_irqsave(&dev->event_lock, flags); |
| 3759 | if (file_priv->event_space < sizeof e->event) { |
| 3760 | spin_unlock_irqrestore(&dev->event_lock, flags); |
| 3761 | goto out; |
| 3762 | } |
| 3763 | file_priv->event_space -= sizeof e->event; |
| 3764 | spin_unlock_irqrestore(&dev->event_lock, flags); |
| 3765 | |
| 3766 | e = kzalloc(sizeof *e, GFP_KERNEL); |
| 3767 | if (e == NULL) { |
| 3768 | spin_lock_irqsave(&dev->event_lock, flags); |
| 3769 | file_priv->event_space += sizeof e->event; |
| 3770 | spin_unlock_irqrestore(&dev->event_lock, flags); |
| 3771 | goto out; |
| 3772 | } |
| 3773 | |
Jesse Barnes | 7bd4d7b | 2009-11-19 10:50:22 -0800 | [diff] [blame] | 3774 | e->event.base.type = DRM_EVENT_FLIP_COMPLETE; |
Kristian Høgsberg | d91d8a3 | 2009-11-17 12:43:55 -0500 | [diff] [blame] | 3775 | e->event.base.length = sizeof e->event; |
| 3776 | e->event.user_data = page_flip->user_data; |
| 3777 | e->base.event = &e->event.base; |
| 3778 | e->base.file_priv = file_priv; |
| 3779 | e->base.destroy = |
| 3780 | (void (*) (struct drm_pending_event *)) kfree; |
| 3781 | } |
| 3782 | |
Daniel Vetter | b0d1232 | 2012-12-11 01:07:12 +0100 | [diff] [blame] | 3783 | old_fb = crtc->fb; |
Kristian Høgsberg | d91d8a3 | 2009-11-17 12:43:55 -0500 | [diff] [blame] | 3784 | ret = crtc->funcs->page_flip(crtc, fb, e); |
| 3785 | if (ret) { |
Joonyoung Shim | aef6a7e | 2012-04-18 13:47:02 +0900 | [diff] [blame] | 3786 | if (page_flip->flags & DRM_MODE_PAGE_FLIP_EVENT) { |
| 3787 | spin_lock_irqsave(&dev->event_lock, flags); |
| 3788 | file_priv->event_space += sizeof e->event; |
| 3789 | spin_unlock_irqrestore(&dev->event_lock, flags); |
| 3790 | kfree(e); |
| 3791 | } |
Daniel Vetter | b0d1232 | 2012-12-11 01:07:12 +0100 | [diff] [blame] | 3792 | /* Keep the old fb, don't unref it. */ |
| 3793 | old_fb = NULL; |
| 3794 | } else { |
| 3795 | /* Unref only the old framebuffer. */ |
| 3796 | fb = NULL; |
Kristian Høgsberg | d91d8a3 | 2009-11-17 12:43:55 -0500 | [diff] [blame] | 3797 | } |
| 3798 | |
| 3799 | out: |
Daniel Vetter | b0d1232 | 2012-12-11 01:07:12 +0100 | [diff] [blame] | 3800 | if (fb) |
| 3801 | drm_framebuffer_unreference(fb); |
| 3802 | if (old_fb) |
| 3803 | drm_framebuffer_unreference(old_fb); |
Daniel Vetter | b4d5e7d | 2012-12-11 16:59:31 +0100 | [diff] [blame] | 3804 | mutex_unlock(&crtc->mutex); |
| 3805 | |
Kristian Høgsberg | d91d8a3 | 2009-11-17 12:43:55 -0500 | [diff] [blame] | 3806 | return ret; |
| 3807 | } |
Chris Wilson | eb03355 | 2011-01-24 15:11:08 +0000 | [diff] [blame] | 3808 | |
| 3809 | void drm_mode_config_reset(struct drm_device *dev) |
| 3810 | { |
| 3811 | struct drm_crtc *crtc; |
| 3812 | struct drm_encoder *encoder; |
| 3813 | struct drm_connector *connector; |
| 3814 | |
| 3815 | list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) |
| 3816 | if (crtc->funcs->reset) |
| 3817 | crtc->funcs->reset(crtc); |
| 3818 | |
| 3819 | list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) |
| 3820 | if (encoder->funcs->reset) |
| 3821 | encoder->funcs->reset(encoder); |
| 3822 | |
Daniel Vetter | 5e2cb2f | 2012-10-23 18:23:35 +0000 | [diff] [blame] | 3823 | list_for_each_entry(connector, &dev->mode_config.connector_list, head) { |
| 3824 | connector->status = connector_status_unknown; |
| 3825 | |
Chris Wilson | eb03355 | 2011-01-24 15:11:08 +0000 | [diff] [blame] | 3826 | if (connector->funcs->reset) |
| 3827 | connector->funcs->reset(connector); |
Daniel Vetter | 5e2cb2f | 2012-10-23 18:23:35 +0000 | [diff] [blame] | 3828 | } |
Chris Wilson | eb03355 | 2011-01-24 15:11:08 +0000 | [diff] [blame] | 3829 | } |
| 3830 | EXPORT_SYMBOL(drm_mode_config_reset); |
Dave Airlie | ff72145b | 2011-02-07 12:16:14 +1000 | [diff] [blame] | 3831 | |
| 3832 | int drm_mode_create_dumb_ioctl(struct drm_device *dev, |
| 3833 | void *data, struct drm_file *file_priv) |
| 3834 | { |
| 3835 | struct drm_mode_create_dumb *args = data; |
| 3836 | |
| 3837 | if (!dev->driver->dumb_create) |
| 3838 | return -ENOSYS; |
| 3839 | return dev->driver->dumb_create(file_priv, dev, args); |
| 3840 | } |
| 3841 | |
| 3842 | int drm_mode_mmap_dumb_ioctl(struct drm_device *dev, |
| 3843 | void *data, struct drm_file *file_priv) |
| 3844 | { |
| 3845 | struct drm_mode_map_dumb *args = data; |
| 3846 | |
| 3847 | /* call driver ioctl to get mmap offset */ |
| 3848 | if (!dev->driver->dumb_map_offset) |
| 3849 | return -ENOSYS; |
| 3850 | |
| 3851 | return dev->driver->dumb_map_offset(file_priv, dev, args->handle, &args->offset); |
| 3852 | } |
| 3853 | |
| 3854 | int drm_mode_destroy_dumb_ioctl(struct drm_device *dev, |
| 3855 | void *data, struct drm_file *file_priv) |
| 3856 | { |
| 3857 | struct drm_mode_destroy_dumb *args = data; |
| 3858 | |
| 3859 | if (!dev->driver->dumb_destroy) |
| 3860 | return -ENOSYS; |
| 3861 | |
| 3862 | return dev->driver->dumb_destroy(file_priv, dev, args->handle); |
| 3863 | } |
Dave Airlie | 248dbc2 | 2011-11-29 20:02:54 +0000 | [diff] [blame] | 3864 | |
| 3865 | /* |
| 3866 | * Just need to support RGB formats here for compat with code that doesn't |
| 3867 | * use pixel formats directly yet. |
| 3868 | */ |
| 3869 | void drm_fb_get_bpp_depth(uint32_t format, unsigned int *depth, |
| 3870 | int *bpp) |
| 3871 | { |
| 3872 | switch (format) { |
Ville Syrjälä | 04b3924 | 2011-11-17 18:05:13 +0200 | [diff] [blame] | 3873 | case DRM_FORMAT_RGB332: |
| 3874 | case DRM_FORMAT_BGR233: |
Dave Airlie | 248dbc2 | 2011-11-29 20:02:54 +0000 | [diff] [blame] | 3875 | *depth = 8; |
| 3876 | *bpp = 8; |
| 3877 | break; |
Ville Syrjälä | 04b3924 | 2011-11-17 18:05:13 +0200 | [diff] [blame] | 3878 | case DRM_FORMAT_XRGB1555: |
| 3879 | case DRM_FORMAT_XBGR1555: |
| 3880 | case DRM_FORMAT_RGBX5551: |
| 3881 | case DRM_FORMAT_BGRX5551: |
| 3882 | case DRM_FORMAT_ARGB1555: |
| 3883 | case DRM_FORMAT_ABGR1555: |
| 3884 | case DRM_FORMAT_RGBA5551: |
| 3885 | case DRM_FORMAT_BGRA5551: |
Dave Airlie | 248dbc2 | 2011-11-29 20:02:54 +0000 | [diff] [blame] | 3886 | *depth = 15; |
| 3887 | *bpp = 16; |
| 3888 | break; |
Ville Syrjälä | 04b3924 | 2011-11-17 18:05:13 +0200 | [diff] [blame] | 3889 | case DRM_FORMAT_RGB565: |
| 3890 | case DRM_FORMAT_BGR565: |
Dave Airlie | 248dbc2 | 2011-11-29 20:02:54 +0000 | [diff] [blame] | 3891 | *depth = 16; |
| 3892 | *bpp = 16; |
| 3893 | break; |
Ville Syrjälä | 04b3924 | 2011-11-17 18:05:13 +0200 | [diff] [blame] | 3894 | case DRM_FORMAT_RGB888: |
| 3895 | case DRM_FORMAT_BGR888: |
| 3896 | *depth = 24; |
| 3897 | *bpp = 24; |
| 3898 | break; |
| 3899 | case DRM_FORMAT_XRGB8888: |
| 3900 | case DRM_FORMAT_XBGR8888: |
| 3901 | case DRM_FORMAT_RGBX8888: |
| 3902 | case DRM_FORMAT_BGRX8888: |
Dave Airlie | 248dbc2 | 2011-11-29 20:02:54 +0000 | [diff] [blame] | 3903 | *depth = 24; |
| 3904 | *bpp = 32; |
| 3905 | break; |
Ville Syrjälä | 04b3924 | 2011-11-17 18:05:13 +0200 | [diff] [blame] | 3906 | case DRM_FORMAT_XRGB2101010: |
| 3907 | case DRM_FORMAT_XBGR2101010: |
| 3908 | case DRM_FORMAT_RGBX1010102: |
| 3909 | case DRM_FORMAT_BGRX1010102: |
| 3910 | case DRM_FORMAT_ARGB2101010: |
| 3911 | case DRM_FORMAT_ABGR2101010: |
| 3912 | case DRM_FORMAT_RGBA1010102: |
| 3913 | case DRM_FORMAT_BGRA1010102: |
Dave Airlie | 248dbc2 | 2011-11-29 20:02:54 +0000 | [diff] [blame] | 3914 | *depth = 30; |
| 3915 | *bpp = 32; |
| 3916 | break; |
Ville Syrjälä | 04b3924 | 2011-11-17 18:05:13 +0200 | [diff] [blame] | 3917 | case DRM_FORMAT_ARGB8888: |
| 3918 | case DRM_FORMAT_ABGR8888: |
| 3919 | case DRM_FORMAT_RGBA8888: |
| 3920 | case DRM_FORMAT_BGRA8888: |
Dave Airlie | 248dbc2 | 2011-11-29 20:02:54 +0000 | [diff] [blame] | 3921 | *depth = 32; |
| 3922 | *bpp = 32; |
| 3923 | break; |
| 3924 | default: |
| 3925 | DRM_DEBUG_KMS("unsupported pixel format\n"); |
| 3926 | *depth = 0; |
| 3927 | *bpp = 0; |
| 3928 | break; |
| 3929 | } |
| 3930 | } |
| 3931 | EXPORT_SYMBOL(drm_fb_get_bpp_depth); |
Ville Syrjälä | 141670e | 2012-04-05 21:35:15 +0300 | [diff] [blame] | 3932 | |
| 3933 | /** |
| 3934 | * drm_format_num_planes - get the number of planes for format |
| 3935 | * @format: pixel format (DRM_FORMAT_*) |
| 3936 | * |
| 3937 | * RETURNS: |
| 3938 | * The number of planes used by the specified pixel format. |
| 3939 | */ |
| 3940 | int drm_format_num_planes(uint32_t format) |
| 3941 | { |
| 3942 | switch (format) { |
| 3943 | case DRM_FORMAT_YUV410: |
| 3944 | case DRM_FORMAT_YVU410: |
| 3945 | case DRM_FORMAT_YUV411: |
| 3946 | case DRM_FORMAT_YVU411: |
| 3947 | case DRM_FORMAT_YUV420: |
| 3948 | case DRM_FORMAT_YVU420: |
| 3949 | case DRM_FORMAT_YUV422: |
| 3950 | case DRM_FORMAT_YVU422: |
| 3951 | case DRM_FORMAT_YUV444: |
| 3952 | case DRM_FORMAT_YVU444: |
| 3953 | return 3; |
| 3954 | case DRM_FORMAT_NV12: |
| 3955 | case DRM_FORMAT_NV21: |
| 3956 | case DRM_FORMAT_NV16: |
| 3957 | case DRM_FORMAT_NV61: |
Laurent Pinchart | ba623f6 | 2012-05-18 23:47:40 +0200 | [diff] [blame] | 3958 | case DRM_FORMAT_NV24: |
| 3959 | case DRM_FORMAT_NV42: |
Ville Syrjälä | 141670e | 2012-04-05 21:35:15 +0300 | [diff] [blame] | 3960 | return 2; |
| 3961 | default: |
| 3962 | return 1; |
| 3963 | } |
| 3964 | } |
| 3965 | EXPORT_SYMBOL(drm_format_num_planes); |
Ville Syrjälä | 5a86bd5 | 2012-04-05 21:35:16 +0300 | [diff] [blame] | 3966 | |
| 3967 | /** |
| 3968 | * drm_format_plane_cpp - determine the bytes per pixel value |
| 3969 | * @format: pixel format (DRM_FORMAT_*) |
| 3970 | * @plane: plane index |
| 3971 | * |
| 3972 | * RETURNS: |
| 3973 | * The bytes per pixel value for the specified plane. |
| 3974 | */ |
| 3975 | int drm_format_plane_cpp(uint32_t format, int plane) |
| 3976 | { |
| 3977 | unsigned int depth; |
| 3978 | int bpp; |
| 3979 | |
| 3980 | if (plane >= drm_format_num_planes(format)) |
| 3981 | return 0; |
| 3982 | |
| 3983 | switch (format) { |
| 3984 | case DRM_FORMAT_YUYV: |
| 3985 | case DRM_FORMAT_YVYU: |
| 3986 | case DRM_FORMAT_UYVY: |
| 3987 | case DRM_FORMAT_VYUY: |
| 3988 | return 2; |
| 3989 | case DRM_FORMAT_NV12: |
| 3990 | case DRM_FORMAT_NV21: |
| 3991 | case DRM_FORMAT_NV16: |
| 3992 | case DRM_FORMAT_NV61: |
Laurent Pinchart | ba623f6 | 2012-05-18 23:47:40 +0200 | [diff] [blame] | 3993 | case DRM_FORMAT_NV24: |
| 3994 | case DRM_FORMAT_NV42: |
Ville Syrjälä | 5a86bd5 | 2012-04-05 21:35:16 +0300 | [diff] [blame] | 3995 | return plane ? 2 : 1; |
| 3996 | case DRM_FORMAT_YUV410: |
| 3997 | case DRM_FORMAT_YVU410: |
| 3998 | case DRM_FORMAT_YUV411: |
| 3999 | case DRM_FORMAT_YVU411: |
| 4000 | case DRM_FORMAT_YUV420: |
| 4001 | case DRM_FORMAT_YVU420: |
| 4002 | case DRM_FORMAT_YUV422: |
| 4003 | case DRM_FORMAT_YVU422: |
| 4004 | case DRM_FORMAT_YUV444: |
| 4005 | case DRM_FORMAT_YVU444: |
| 4006 | return 1; |
| 4007 | default: |
| 4008 | drm_fb_get_bpp_depth(format, &depth, &bpp); |
| 4009 | return bpp >> 3; |
| 4010 | } |
| 4011 | } |
| 4012 | EXPORT_SYMBOL(drm_format_plane_cpp); |
Ville Syrjälä | 01b68b0 | 2012-04-05 21:35:17 +0300 | [diff] [blame] | 4013 | |
| 4014 | /** |
| 4015 | * drm_format_horz_chroma_subsampling - get the horizontal chroma subsampling factor |
| 4016 | * @format: pixel format (DRM_FORMAT_*) |
| 4017 | * |
| 4018 | * RETURNS: |
| 4019 | * The horizontal chroma subsampling factor for the |
| 4020 | * specified pixel format. |
| 4021 | */ |
| 4022 | int drm_format_horz_chroma_subsampling(uint32_t format) |
| 4023 | { |
| 4024 | switch (format) { |
| 4025 | case DRM_FORMAT_YUV411: |
| 4026 | case DRM_FORMAT_YVU411: |
| 4027 | case DRM_FORMAT_YUV410: |
| 4028 | case DRM_FORMAT_YVU410: |
| 4029 | return 4; |
| 4030 | case DRM_FORMAT_YUYV: |
| 4031 | case DRM_FORMAT_YVYU: |
| 4032 | case DRM_FORMAT_UYVY: |
| 4033 | case DRM_FORMAT_VYUY: |
| 4034 | case DRM_FORMAT_NV12: |
| 4035 | case DRM_FORMAT_NV21: |
| 4036 | case DRM_FORMAT_NV16: |
| 4037 | case DRM_FORMAT_NV61: |
| 4038 | case DRM_FORMAT_YUV422: |
| 4039 | case DRM_FORMAT_YVU422: |
| 4040 | case DRM_FORMAT_YUV420: |
| 4041 | case DRM_FORMAT_YVU420: |
| 4042 | return 2; |
| 4043 | default: |
| 4044 | return 1; |
| 4045 | } |
| 4046 | } |
| 4047 | EXPORT_SYMBOL(drm_format_horz_chroma_subsampling); |
| 4048 | |
| 4049 | /** |
| 4050 | * drm_format_vert_chroma_subsampling - get the vertical chroma subsampling factor |
| 4051 | * @format: pixel format (DRM_FORMAT_*) |
| 4052 | * |
| 4053 | * RETURNS: |
| 4054 | * The vertical chroma subsampling factor for the |
| 4055 | * specified pixel format. |
| 4056 | */ |
| 4057 | int drm_format_vert_chroma_subsampling(uint32_t format) |
| 4058 | { |
| 4059 | switch (format) { |
| 4060 | case DRM_FORMAT_YUV410: |
| 4061 | case DRM_FORMAT_YVU410: |
| 4062 | return 4; |
| 4063 | case DRM_FORMAT_YUV420: |
| 4064 | case DRM_FORMAT_YVU420: |
| 4065 | case DRM_FORMAT_NV12: |
| 4066 | case DRM_FORMAT_NV21: |
| 4067 | return 2; |
| 4068 | default: |
| 4069 | return 1; |
| 4070 | } |
| 4071 | } |
| 4072 | EXPORT_SYMBOL(drm_format_vert_chroma_subsampling); |