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