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