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