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