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