blob: d2e09d98691a043eacac4c3472da7368c2a73faf [file] [log] [blame]
Dave Airlief453ba02008-11-07 14:05:41 -08001/*
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 Heo5a0e3ad2010-03-24 17:04:11 +090033#include <linux/slab.h>
Paul Gortmaker2d1a8a42011-08-30 18:16:33 -040034#include <linux/export.h>
Dave Airlief453ba02008-11-07 14:05:41 -080035#include "drm.h"
36#include "drmP.h"
37#include "drm_crtc.h"
Adam Jackson7466f4c2010-03-29 21:43:23 +000038#include "drm_edid.h"
Jesse Barnes308e5bc2011-11-14 14:51:28 -080039#include "drm_fourcc.h"
Dave Airlief453ba02008-11-07 14:05:41 -080040
Dave Airlief453ba02008-11-07 14:05:41 -080041/* 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 */
56static 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
63DRM_ENUM_NAME_FN(drm_get_dpms_name, drm_dpms_enum_list)
64
65/*
66 * Optional properties
67 */
68static struct drm_prop_enum_list drm_scaling_mode_enum_list[] =
69{
Jesse Barnes53bd8382009-07-01 10:04:40 -070070 { 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 Airlief453ba02008-11-07 14:05:41 -080074};
75
76static struct drm_prop_enum_list drm_dithering_mode_enum_list[] =
77{
78 { DRM_MODE_DITHERING_OFF, "Off" },
79 { DRM_MODE_DITHERING_ON, "On" },
Ben Skeggs92897b52010-07-16 15:09:17 +100080 { DRM_MODE_DITHERING_AUTO, "Automatic" },
Dave Airlief453ba02008-11-07 14:05:41 -080081};
82
83/*
84 * Non-global properties, but "required" for certain connectors.
85 */
86static 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
93DRM_ENUM_NAME_FN(drm_get_dvi_i_select_name, drm_dvi_i_select_enum_list)
94
95static 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
102DRM_ENUM_NAME_FN(drm_get_dvi_i_subconnector_name,
103 drm_dvi_i_subconnector_enum_list)
104
105static 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 Jerezaeaa1ad2009-08-02 04:19:19 +0200111 { DRM_MODE_SUBCONNECTOR_SCART, "SCART" }, /* TV-out */
Dave Airlief453ba02008-11-07 14:05:41 -0800112};
113
114DRM_ENUM_NAME_FN(drm_get_tv_select_name, drm_tv_select_enum_list)
115
116static 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 Jerezaeaa1ad2009-08-02 04:19:19 +0200122 { DRM_MODE_SUBCONNECTOR_SCART, "SCART" }, /* TV-out */
Dave Airlief453ba02008-11-07 14:05:41 -0800123};
124
125DRM_ENUM_NAME_FN(drm_get_tv_subconnector_name,
126 drm_tv_subconnector_enum_list)
127
Jakob Bornecrantz884840a2009-12-03 23:25:47 +0000128static 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
134DRM_ENUM_NAME_FN(drm_get_dirty_info_name,
135 drm_dirty_info_enum_list)
136
Dave Airlief453ba02008-11-07 14:05:41 -0800137struct drm_conn_prop_enum_list {
138 int type;
139 char *name;
140 int count;
141};
142
143/*
144 * Connector and encoder types.
145 */
146static 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 Deuchere76116c2010-12-08 19:09:42 -0500156 { 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 Jerez74bd3c22009-08-02 04:19:18 +0200160 { DRM_MODE_CONNECTOR_TV, "TV", 0 },
Alex Deuchere76116c2010-12-08 19:09:42 -0500161 { DRM_MODE_CONNECTOR_eDP, "eDP", 0 },
Thomas Hellstroma7331e52011-10-22 10:36:19 +0200162 { DRM_MODE_CONNECTOR_VIRTUAL, "Virtual", 0},
Dave Airlief453ba02008-11-07 14:05:41 -0800163};
164
165static 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 Hellstroma7331e52011-10-22 10:36:19 +0200171 { DRM_MODE_ENCODER_VIRTUAL, "Virtual" },
Dave Airlief453ba02008-11-07 14:05:41 -0800172};
173
174char *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 Airlie13a81952009-09-07 15:45:33 +1000183EXPORT_SYMBOL(drm_get_encoder_name);
Dave Airlief453ba02008-11-07 14:05:41 -0800184
185char *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}
194EXPORT_SYMBOL(drm_get_connector_name);
195
196char *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 Airlief453ba02008-11-07 14:05:41 -0800213 *
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 */
221static 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 Airlief453ba02008-11-07 14:05:41 -0800227again:
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 Barnesad2563c2009-01-19 17:21:45 +1000233 mutex_lock(&dev->mode_config.idr_mutex);
Dave Airlief453ba02008-11-07 14:05:41 -0800234 ret = idr_get_new_above(&dev->mode_config.crtc_idr, obj, 1, &new_id);
Jesse Barnesad2563c2009-01-19 17:21:45 +1000235 mutex_unlock(&dev->mode_config.idr_mutex);
Dave Airlief453ba02008-11-07 14:05:41 -0800236 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 */
254static void drm_mode_object_put(struct drm_device *dev,
255 struct drm_mode_object *object)
256{
Jesse Barnesad2563c2009-01-19 17:21:45 +1000257 mutex_lock(&dev->mode_config.idr_mutex);
Dave Airlief453ba02008-11-07 14:05:41 -0800258 idr_remove(&dev->mode_config.crtc_idr, object->id);
Jesse Barnesad2563c2009-01-19 17:21:45 +1000259 mutex_unlock(&dev->mode_config.idr_mutex);
Dave Airlief453ba02008-11-07 14:05:41 -0800260}
261
Daniel Vetter7a9c9062009-09-15 22:57:31 +0200262struct drm_mode_object *drm_mode_object_find(struct drm_device *dev,
263 uint32_t id, uint32_t type)
Dave Airlief453ba02008-11-07 14:05:41 -0800264{
Jesse Barnesad2563c2009-01-19 17:21:45 +1000265 struct drm_mode_object *obj = NULL;
Dave Airlief453ba02008-11-07 14:05:41 -0800266
Jesse Barnesad2563c2009-01-19 17:21:45 +1000267 mutex_lock(&dev->mode_config.idr_mutex);
Dave Airlief453ba02008-11-07 14:05:41 -0800268 obj = idr_find(&dev->mode_config.crtc_idr, id);
269 if (!obj || (obj->type != type) || (obj->id != id))
Jesse Barnesad2563c2009-01-19 17:21:45 +1000270 obj = NULL;
271 mutex_unlock(&dev->mode_config.idr_mutex);
Dave Airlief453ba02008-11-07 14:05:41 -0800272
273 return obj;
274}
275EXPORT_SYMBOL(drm_mode_object_find);
276
277/**
Dave Airlief453ba02008-11-07 14:05:41 -0800278 * 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 Rosaaf901ca2009-11-14 13:09:05 -0200288 * Zero on success, error code on failure.
Dave Airlief453ba02008-11-07 14:05:41 -0800289 */
290int 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}
307EXPORT_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 */
319void drm_framebuffer_cleanup(struct drm_framebuffer *fb)
320{
321 struct drm_device *dev = fb->dev;
322 struct drm_crtc *crtc;
Jesse Barnes8cf5c912011-11-14 14:51:27 -0800323 struct drm_plane *plane;
Dave Airlie5ef5f722009-08-17 13:11:23 +1000324 struct drm_mode_set set;
325 int ret;
Dave Airlief453ba02008-11-07 14:05:41 -0800326
327 /* remove from any CRTC */
328 list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) {
Dave Airlie5ef5f722009-08-17 13:11:23 +1000329 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 Airlief453ba02008-11-07 14:05:41 -0800338 }
339
Jesse Barnes8cf5c912011-11-14 14:51:27 -0800340 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 Clarka9971152011-12-13 20:19:35 -0600346 /* disconnect the plane from the fb and crtc: */
347 plane->fb = NULL;
348 plane->crtc = NULL;
Jesse Barnes8cf5c912011-11-14 14:51:27 -0800349 }
350 }
351
Dave Airlief453ba02008-11-07 14:05:41 -0800352 drm_mode_object_put(dev, &fb->base);
353 list_del(&fb->head);
354 dev->mode_config.num_fb--;
355}
356EXPORT_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 */
369void 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}
382EXPORT_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 */
394void 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}
407EXPORT_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 */
419void drm_mode_probed_add(struct drm_connector *connector,
420 struct drm_display_mode *mode)
421{
422 list_add(&mode->head, &connector->probed_modes);
423}
424EXPORT_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 */
436void drm_mode_remove(struct drm_connector *connector,
437 struct drm_display_mode *mode)
438{
439 list_del(&mode->head);
Sascha Hauer554f1d72012-02-01 11:38:19 +0100440 drm_mode_destroy(connector->dev, mode);
Dave Airlief453ba02008-11-07 14:05:41 -0800441}
442EXPORT_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 Hauerb20f3862012-02-01 11:38:31 +0100452 * Takes mode config lock.
Dave Airlief453ba02008-11-07 14:05:41 -0800453 *
454 * Initialises a preallocated connector. Connectors should be
455 * subclassed as part of driver connector objects.
456 */
457void 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 Hellstroma7331e52011-10-22 10:36:19 +0200478 if (connector_type != DRM_MODE_CONNECTOR_VIRTUAL)
479 drm_connector_attach_property(connector,
480 dev->mode_config.edid_property,
481 0);
Dave Airlief453ba02008-11-07 14:05:41 -0800482
483 drm_connector_attach_property(connector,
484 dev->mode_config.dpms_property, 0);
485
486 mutex_unlock(&dev->mode_config.mutex);
487}
488EXPORT_SYMBOL(drm_connector_init);
489
490/**
491 * drm_connector_cleanup - cleans up an initialised connector
492 * @connector: connector to cleanup
493 *
494 * LOCKING:
Sascha Hauerb20f3862012-02-01 11:38:31 +0100495 * Takes mode config lock.
Dave Airlief453ba02008-11-07 14:05:41 -0800496 *
497 * Cleans up the connector but doesn't free the object.
498 */
499void 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 Shim6380c502011-08-27 02:06:21 +0000516 dev->mode_config.num_connector--;
Dave Airlief453ba02008-11-07 14:05:41 -0800517 mutex_unlock(&dev->mode_config.mutex);
518}
519EXPORT_SYMBOL(drm_connector_cleanup);
520
521void 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}
539EXPORT_SYMBOL(drm_encoder_init);
540
541void 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 Shim6380c502011-08-27 02:06:21 +0000547 dev->mode_config.num_encoder--;
Dave Airlief453ba02008-11-07 14:05:41 -0800548 mutex_unlock(&dev->mode_config.mutex);
549}
550EXPORT_SYMBOL(drm_encoder_cleanup);
551
Jesse Barnes8cf5c912011-11-14 14:51:27 -0800552int drm_plane_init(struct drm_device *dev, struct drm_plane *plane,
553 unsigned long possible_crtcs,
554 const struct drm_plane_funcs *funcs,
Rob Clark0a7eb242011-12-13 20:19:36 -0600555 const uint32_t *formats, uint32_t format_count,
556 bool priv)
Jesse Barnes8cf5c912011-11-14 14:51:27 -0800557{
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ä10bf5732011-12-20 00:06:41 +0200568 mutex_unlock(&dev->mode_config.mutex);
Jesse Barnes8cf5c912011-11-14 14:51:27 -0800569 return -ENOMEM;
570 }
571
Jesse Barnes308e5bc2011-11-14 14:51:28 -0800572 memcpy(plane->format_types, formats, format_count * sizeof(uint32_t));
Jesse Barnes8cf5c912011-11-14 14:51:27 -0800573 plane->format_count = format_count;
574 plane->possible_crtcs = possible_crtcs;
575
Rob Clark0a7eb242011-12-13 20:19:36 -0600576 /* 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 Barnes8cf5c912011-11-14 14:51:27 -0800586
587 mutex_unlock(&dev->mode_config.mutex);
588
589 return 0;
590}
591EXPORT_SYMBOL(drm_plane_init);
592
593void 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 Clark0a7eb242011-12-13 20:19:36 -0600600 /* 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 Barnes8cf5c912011-11-14 14:51:27 -0800605 mutex_unlock(&dev->mode_config.mutex);
606}
607EXPORT_SYMBOL(drm_plane_cleanup);
608
Dave Airlief453ba02008-11-07 14:05:41 -0800609/**
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 */
621struct 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}
632EXPORT_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 */
644void drm_mode_destroy(struct drm_device *dev, struct drm_display_mode *mode)
645{
646 drm_mode_object_put(dev, &mode->base);
647
648 kfree(mode);
649}
650EXPORT_SYMBOL(drm_mode_destroy);
651
652static int drm_mode_create_standard_connector_properties(struct drm_device *dev)
653{
654 struct drm_property *edid;
655 struct drm_property *dpms;
Dave Airlief453ba02008-11-07 14:05:41 -0800656
657 /*
658 * Standard properties (apply to all connectors)
659 */
660 edid = drm_property_create(dev, DRM_MODE_PROP_BLOB |
661 DRM_MODE_PROP_IMMUTABLE,
662 "EDID", 0);
663 dev->mode_config.edid_property = edid;
664
Sascha Hauer4a67d392012-02-06 10:58:17 +0100665 dpms = drm_property_create_enum(dev, 0,
666 "DPMS", drm_dpms_enum_list,
667 ARRAY_SIZE(drm_dpms_enum_list));
Dave Airlief453ba02008-11-07 14:05:41 -0800668 dev->mode_config.dpms_property = dpms;
669
670 return 0;
671}
672
673/**
674 * drm_mode_create_dvi_i_properties - create DVI-I specific connector properties
675 * @dev: DRM device
676 *
677 * Called by a driver the first time a DVI-I connector is made.
678 */
679int drm_mode_create_dvi_i_properties(struct drm_device *dev)
680{
681 struct drm_property *dvi_i_selector;
682 struct drm_property *dvi_i_subconnector;
Dave Airlief453ba02008-11-07 14:05:41 -0800683
684 if (dev->mode_config.dvi_i_select_subconnector_property)
685 return 0;
686
687 dvi_i_selector =
Sascha Hauer4a67d392012-02-06 10:58:17 +0100688 drm_property_create_enum(dev, 0,
Dave Airlief453ba02008-11-07 14:05:41 -0800689 "select subconnector",
Sascha Hauer4a67d392012-02-06 10:58:17 +0100690 drm_dvi_i_select_enum_list,
Dave Airlief453ba02008-11-07 14:05:41 -0800691 ARRAY_SIZE(drm_dvi_i_select_enum_list));
Dave Airlief453ba02008-11-07 14:05:41 -0800692 dev->mode_config.dvi_i_select_subconnector_property = dvi_i_selector;
693
Sascha Hauer4a67d392012-02-06 10:58:17 +0100694 dvi_i_subconnector = drm_property_create_enum(dev, DRM_MODE_PROP_IMMUTABLE,
Dave Airlief453ba02008-11-07 14:05:41 -0800695 "subconnector",
Sascha Hauer4a67d392012-02-06 10:58:17 +0100696 drm_dvi_i_subconnector_enum_list,
Dave Airlief453ba02008-11-07 14:05:41 -0800697 ARRAY_SIZE(drm_dvi_i_subconnector_enum_list));
Dave Airlief453ba02008-11-07 14:05:41 -0800698 dev->mode_config.dvi_i_subconnector_property = dvi_i_subconnector;
699
700 return 0;
701}
702EXPORT_SYMBOL(drm_mode_create_dvi_i_properties);
703
704/**
705 * drm_create_tv_properties - create TV specific connector properties
706 * @dev: DRM device
707 * @num_modes: number of different TV formats (modes) supported
708 * @modes: array of pointers to strings containing name of each format
709 *
710 * Called by a driver's TV initialization routine, this function creates
711 * the TV specific connector properties for a given device. Caller is
712 * responsible for allocating a list of format names and passing them to
713 * this routine.
714 */
715int drm_mode_create_tv_properties(struct drm_device *dev, int num_modes,
716 char *modes[])
717{
718 struct drm_property *tv_selector;
719 struct drm_property *tv_subconnector;
720 int i;
721
722 if (dev->mode_config.tv_select_subconnector_property)
723 return 0;
724
725 /*
726 * Basic connector properties
727 */
Sascha Hauer4a67d392012-02-06 10:58:17 +0100728 tv_selector = drm_property_create_enum(dev, 0,
Dave Airlief453ba02008-11-07 14:05:41 -0800729 "select subconnector",
Sascha Hauer4a67d392012-02-06 10:58:17 +0100730 drm_tv_select_enum_list,
Dave Airlief453ba02008-11-07 14:05:41 -0800731 ARRAY_SIZE(drm_tv_select_enum_list));
Dave Airlief453ba02008-11-07 14:05:41 -0800732 dev->mode_config.tv_select_subconnector_property = tv_selector;
733
734 tv_subconnector =
Sascha Hauer4a67d392012-02-06 10:58:17 +0100735 drm_property_create_enum(dev, DRM_MODE_PROP_IMMUTABLE,
736 "subconnector",
737 drm_tv_subconnector_enum_list,
Dave Airlief453ba02008-11-07 14:05:41 -0800738 ARRAY_SIZE(drm_tv_subconnector_enum_list));
Dave Airlief453ba02008-11-07 14:05:41 -0800739 dev->mode_config.tv_subconnector_property = tv_subconnector;
740
741 /*
742 * Other, TV specific properties: margins & TV modes.
743 */
744 dev->mode_config.tv_left_margin_property =
Sascha Hauerd9bc3c02012-02-06 10:58:18 +0100745 drm_property_create_range(dev, 0, "left margin", 0, 100);
Dave Airlief453ba02008-11-07 14:05:41 -0800746
747 dev->mode_config.tv_right_margin_property =
Sascha Hauerd9bc3c02012-02-06 10:58:18 +0100748 drm_property_create_range(dev, 0, "right margin", 0, 100);
Dave Airlief453ba02008-11-07 14:05:41 -0800749
750 dev->mode_config.tv_top_margin_property =
Sascha Hauerd9bc3c02012-02-06 10:58:18 +0100751 drm_property_create_range(dev, 0, "top margin", 0, 100);
Dave Airlief453ba02008-11-07 14:05:41 -0800752
753 dev->mode_config.tv_bottom_margin_property =
Sascha Hauerd9bc3c02012-02-06 10:58:18 +0100754 drm_property_create_range(dev, 0, "bottom margin", 0, 100);
Dave Airlief453ba02008-11-07 14:05:41 -0800755
756 dev->mode_config.tv_mode_property =
757 drm_property_create(dev, DRM_MODE_PROP_ENUM,
758 "mode", num_modes);
759 for (i = 0; i < num_modes; i++)
760 drm_property_add_enum(dev->mode_config.tv_mode_property, i,
761 i, modes[i]);
762
Francisco Jerezb6b79022009-08-02 04:19:20 +0200763 dev->mode_config.tv_brightness_property =
Sascha Hauerd9bc3c02012-02-06 10:58:18 +0100764 drm_property_create_range(dev, 0, "brightness", 0, 100);
Francisco Jerezb6b79022009-08-02 04:19:20 +0200765
766 dev->mode_config.tv_contrast_property =
Sascha Hauerd9bc3c02012-02-06 10:58:18 +0100767 drm_property_create_range(dev, 0, "contrast", 0, 100);
Francisco Jerezb6b79022009-08-02 04:19:20 +0200768
769 dev->mode_config.tv_flicker_reduction_property =
Sascha Hauerd9bc3c02012-02-06 10:58:18 +0100770 drm_property_create_range(dev, 0, "flicker reduction", 0, 100);
Francisco Jerezb6b79022009-08-02 04:19:20 +0200771
Francisco Jereza75f0232009-08-12 02:30:10 +0200772 dev->mode_config.tv_overscan_property =
Sascha Hauerd9bc3c02012-02-06 10:58:18 +0100773 drm_property_create_range(dev, 0, "overscan", 0, 100);
Francisco Jereza75f0232009-08-12 02:30:10 +0200774
775 dev->mode_config.tv_saturation_property =
Sascha Hauerd9bc3c02012-02-06 10:58:18 +0100776 drm_property_create_range(dev, 0, "saturation", 0, 100);
Francisco Jereza75f0232009-08-12 02:30:10 +0200777
778 dev->mode_config.tv_hue_property =
Sascha Hauerd9bc3c02012-02-06 10:58:18 +0100779 drm_property_create_range(dev, 0, "hue", 0, 100);
Francisco Jereza75f0232009-08-12 02:30:10 +0200780
Dave Airlief453ba02008-11-07 14:05:41 -0800781 return 0;
782}
783EXPORT_SYMBOL(drm_mode_create_tv_properties);
784
785/**
786 * drm_mode_create_scaling_mode_property - create scaling mode property
787 * @dev: DRM device
788 *
789 * Called by a driver the first time it's needed, must be attached to desired
790 * connectors.
791 */
792int drm_mode_create_scaling_mode_property(struct drm_device *dev)
793{
794 struct drm_property *scaling_mode;
Dave Airlief453ba02008-11-07 14:05:41 -0800795
796 if (dev->mode_config.scaling_mode_property)
797 return 0;
798
799 scaling_mode =
Sascha Hauer4a67d392012-02-06 10:58:17 +0100800 drm_property_create_enum(dev, 0, "scaling mode",
801 drm_scaling_mode_enum_list,
Dave Airlief453ba02008-11-07 14:05:41 -0800802 ARRAY_SIZE(drm_scaling_mode_enum_list));
Dave Airlief453ba02008-11-07 14:05:41 -0800803
804 dev->mode_config.scaling_mode_property = scaling_mode;
805
806 return 0;
807}
808EXPORT_SYMBOL(drm_mode_create_scaling_mode_property);
809
810/**
811 * drm_mode_create_dithering_property - create dithering property
812 * @dev: DRM device
813 *
814 * Called by a driver the first time it's needed, must be attached to desired
815 * connectors.
816 */
817int drm_mode_create_dithering_property(struct drm_device *dev)
818{
819 struct drm_property *dithering_mode;
Dave Airlief453ba02008-11-07 14:05:41 -0800820
821 if (dev->mode_config.dithering_mode_property)
822 return 0;
823
824 dithering_mode =
Sascha Hauer4a67d392012-02-06 10:58:17 +0100825 drm_property_create_enum(dev, 0, "dithering",
826 drm_dithering_mode_enum_list,
Dave Airlief453ba02008-11-07 14:05:41 -0800827 ARRAY_SIZE(drm_dithering_mode_enum_list));
Dave Airlief453ba02008-11-07 14:05:41 -0800828 dev->mode_config.dithering_mode_property = dithering_mode;
829
830 return 0;
831}
832EXPORT_SYMBOL(drm_mode_create_dithering_property);
833
834/**
Jakob Bornecrantz884840a2009-12-03 23:25:47 +0000835 * drm_mode_create_dirty_property - create dirty property
836 * @dev: DRM device
837 *
838 * Called by a driver the first time it's needed, must be attached to desired
839 * connectors.
840 */
841int drm_mode_create_dirty_info_property(struct drm_device *dev)
842{
843 struct drm_property *dirty_info;
Jakob Bornecrantz884840a2009-12-03 23:25:47 +0000844
845 if (dev->mode_config.dirty_info_property)
846 return 0;
847
848 dirty_info =
Sascha Hauer4a67d392012-02-06 10:58:17 +0100849 drm_property_create_enum(dev, DRM_MODE_PROP_IMMUTABLE,
Jakob Bornecrantz884840a2009-12-03 23:25:47 +0000850 "dirty",
Sascha Hauer4a67d392012-02-06 10:58:17 +0100851 drm_dirty_info_enum_list,
Jakob Bornecrantz884840a2009-12-03 23:25:47 +0000852 ARRAY_SIZE(drm_dirty_info_enum_list));
Jakob Bornecrantz884840a2009-12-03 23:25:47 +0000853 dev->mode_config.dirty_info_property = dirty_info;
854
855 return 0;
856}
857EXPORT_SYMBOL(drm_mode_create_dirty_info_property);
858
859/**
Dave Airlief453ba02008-11-07 14:05:41 -0800860 * drm_mode_config_init - initialize DRM mode_configuration structure
861 * @dev: DRM device
862 *
863 * LOCKING:
864 * None, should happen single threaded at init time.
865 *
866 * Initialize @dev's mode_config structure, used for tracking the graphics
867 * configuration of @dev.
868 */
869void drm_mode_config_init(struct drm_device *dev)
870{
871 mutex_init(&dev->mode_config.mutex);
Jesse Barnesad2563c2009-01-19 17:21:45 +1000872 mutex_init(&dev->mode_config.idr_mutex);
Dave Airlief453ba02008-11-07 14:05:41 -0800873 INIT_LIST_HEAD(&dev->mode_config.fb_list);
Dave Airlief453ba02008-11-07 14:05:41 -0800874 INIT_LIST_HEAD(&dev->mode_config.crtc_list);
875 INIT_LIST_HEAD(&dev->mode_config.connector_list);
876 INIT_LIST_HEAD(&dev->mode_config.encoder_list);
877 INIT_LIST_HEAD(&dev->mode_config.property_list);
878 INIT_LIST_HEAD(&dev->mode_config.property_blob_list);
Jesse Barnes8cf5c912011-11-14 14:51:27 -0800879 INIT_LIST_HEAD(&dev->mode_config.plane_list);
Dave Airlief453ba02008-11-07 14:05:41 -0800880 idr_init(&dev->mode_config.crtc_idr);
881
882 mutex_lock(&dev->mode_config.mutex);
883 drm_mode_create_standard_connector_properties(dev);
884 mutex_unlock(&dev->mode_config.mutex);
885
886 /* Just to be sure */
887 dev->mode_config.num_fb = 0;
888 dev->mode_config.num_connector = 0;
889 dev->mode_config.num_crtc = 0;
890 dev->mode_config.num_encoder = 0;
Dave Airlief453ba02008-11-07 14:05:41 -0800891}
892EXPORT_SYMBOL(drm_mode_config_init);
893
894int drm_mode_group_init(struct drm_device *dev, struct drm_mode_group *group)
895{
896 uint32_t total_objects = 0;
897
898 total_objects += dev->mode_config.num_crtc;
899 total_objects += dev->mode_config.num_connector;
900 total_objects += dev->mode_config.num_encoder;
901
Dave Airlief453ba02008-11-07 14:05:41 -0800902 group->id_list = kzalloc(total_objects * sizeof(uint32_t), GFP_KERNEL);
903 if (!group->id_list)
904 return -ENOMEM;
905
906 group->num_crtcs = 0;
907 group->num_connectors = 0;
908 group->num_encoders = 0;
909 return 0;
910}
911
912int drm_mode_group_init_legacy_group(struct drm_device *dev,
913 struct drm_mode_group *group)
914{
915 struct drm_crtc *crtc;
916 struct drm_encoder *encoder;
917 struct drm_connector *connector;
918 int ret;
919
920 if ((ret = drm_mode_group_init(dev, group)))
921 return ret;
922
923 list_for_each_entry(crtc, &dev->mode_config.crtc_list, head)
924 group->id_list[group->num_crtcs++] = crtc->base.id;
925
926 list_for_each_entry(encoder, &dev->mode_config.encoder_list, head)
927 group->id_list[group->num_crtcs + group->num_encoders++] =
928 encoder->base.id;
929
930 list_for_each_entry(connector, &dev->mode_config.connector_list, head)
931 group->id_list[group->num_crtcs + group->num_encoders +
932 group->num_connectors++] = connector->base.id;
933
934 return 0;
935}
936
937/**
938 * drm_mode_config_cleanup - free up DRM mode_config info
939 * @dev: DRM device
940 *
941 * LOCKING:
942 * Caller must hold mode config lock.
943 *
944 * Free up all the connectors and CRTCs associated with this DRM device, then
945 * free up the framebuffers and associated buffer objects.
946 *
947 * FIXME: cleanup any dangling user buffer objects too
948 */
949void drm_mode_config_cleanup(struct drm_device *dev)
950{
951 struct drm_connector *connector, *ot;
952 struct drm_crtc *crtc, *ct;
953 struct drm_encoder *encoder, *enct;
954 struct drm_framebuffer *fb, *fbt;
955 struct drm_property *property, *pt;
Jesse Barnes8cf5c912011-11-14 14:51:27 -0800956 struct drm_plane *plane, *plt;
Dave Airlief453ba02008-11-07 14:05:41 -0800957
958 list_for_each_entry_safe(encoder, enct, &dev->mode_config.encoder_list,
959 head) {
960 encoder->funcs->destroy(encoder);
961 }
962
963 list_for_each_entry_safe(connector, ot,
964 &dev->mode_config.connector_list, head) {
965 connector->funcs->destroy(connector);
966 }
967
968 list_for_each_entry_safe(property, pt, &dev->mode_config.property_list,
969 head) {
970 drm_property_destroy(dev, property);
971 }
972
973 list_for_each_entry_safe(fb, fbt, &dev->mode_config.fb_list, head) {
974 fb->funcs->destroy(fb);
975 }
976
977 list_for_each_entry_safe(crtc, ct, &dev->mode_config.crtc_list, head) {
978 crtc->funcs->destroy(crtc);
979 }
980
Jesse Barnes8cf5c912011-11-14 14:51:27 -0800981 list_for_each_entry_safe(plane, plt, &dev->mode_config.plane_list,
982 head) {
983 plane->funcs->destroy(plane);
984 }
Sascha Hauer59ce0622012-02-01 11:38:20 +0100985
986 idr_remove_all(&dev->mode_config.crtc_idr);
987 idr_destroy(&dev->mode_config.crtc_idr);
Dave Airlief453ba02008-11-07 14:05:41 -0800988}
989EXPORT_SYMBOL(drm_mode_config_cleanup);
990
Dave Airlief453ba02008-11-07 14:05:41 -0800991/**
992 * drm_crtc_convert_to_umode - convert a drm_display_mode into a modeinfo
993 * @out: drm_mode_modeinfo struct to return to the user
994 * @in: drm_display_mode to use
995 *
996 * LOCKING:
997 * None.
998 *
999 * Convert a drm_display_mode into a drm_mode_modeinfo structure to return to
1000 * the user.
1001 */
1002void drm_crtc_convert_to_umode(struct drm_mode_modeinfo *out,
1003 struct drm_display_mode *in)
1004{
Ville Syrjäläe36fae32012-03-13 12:35:40 +02001005 WARN(in->hdisplay > USHRT_MAX || in->hsync_start > USHRT_MAX ||
1006 in->hsync_end > USHRT_MAX || in->htotal > USHRT_MAX ||
1007 in->hskew > USHRT_MAX || in->vdisplay > USHRT_MAX ||
1008 in->vsync_start > USHRT_MAX || in->vsync_end > USHRT_MAX ||
1009 in->vtotal > USHRT_MAX || in->vscan > USHRT_MAX,
1010 "timing values too large for mode info\n");
1011
Dave Airlief453ba02008-11-07 14:05:41 -08001012 out->clock = in->clock;
1013 out->hdisplay = in->hdisplay;
1014 out->hsync_start = in->hsync_start;
1015 out->hsync_end = in->hsync_end;
1016 out->htotal = in->htotal;
1017 out->hskew = in->hskew;
1018 out->vdisplay = in->vdisplay;
1019 out->vsync_start = in->vsync_start;
1020 out->vsync_end = in->vsync_end;
1021 out->vtotal = in->vtotal;
1022 out->vscan = in->vscan;
1023 out->vrefresh = in->vrefresh;
1024 out->flags = in->flags;
1025 out->type = in->type;
1026 strncpy(out->name, in->name, DRM_DISPLAY_MODE_LEN);
1027 out->name[DRM_DISPLAY_MODE_LEN-1] = 0;
1028}
1029
1030/**
1031 * drm_crtc_convert_to_umode - convert a modeinfo into a drm_display_mode
1032 * @out: drm_display_mode to return to the user
1033 * @in: drm_mode_modeinfo to use
1034 *
1035 * LOCKING:
1036 * None.
1037 *
1038 * Convert a drm_mode_modeinfo into a drm_display_mode structure to return to
1039 * the caller.
1040 */
1041void drm_crtc_convert_umode(struct drm_display_mode *out,
1042 struct drm_mode_modeinfo *in)
1043{
1044 out->clock = in->clock;
1045 out->hdisplay = in->hdisplay;
1046 out->hsync_start = in->hsync_start;
1047 out->hsync_end = in->hsync_end;
1048 out->htotal = in->htotal;
1049 out->hskew = in->hskew;
1050 out->vdisplay = in->vdisplay;
1051 out->vsync_start = in->vsync_start;
1052 out->vsync_end = in->vsync_end;
1053 out->vtotal = in->vtotal;
1054 out->vscan = in->vscan;
1055 out->vrefresh = in->vrefresh;
1056 out->flags = in->flags;
1057 out->type = in->type;
1058 strncpy(out->name, in->name, DRM_DISPLAY_MODE_LEN);
1059 out->name[DRM_DISPLAY_MODE_LEN-1] = 0;
1060}
1061
1062/**
1063 * drm_mode_getresources - get graphics configuration
1064 * @inode: inode from the ioctl
1065 * @filp: file * from the ioctl
1066 * @cmd: cmd from ioctl
1067 * @arg: arg from ioctl
1068 *
1069 * LOCKING:
1070 * Takes mode config lock.
1071 *
1072 * Construct a set of configuration description structures and return
1073 * them to the user, including CRTC, connector and framebuffer configuration.
1074 *
1075 * Called by the user via ioctl.
1076 *
1077 * RETURNS:
1078 * Zero on success, errno on failure.
1079 */
1080int drm_mode_getresources(struct drm_device *dev, void *data,
1081 struct drm_file *file_priv)
1082{
1083 struct drm_mode_card_res *card_res = data;
1084 struct list_head *lh;
1085 struct drm_framebuffer *fb;
1086 struct drm_connector *connector;
1087 struct drm_crtc *crtc;
1088 struct drm_encoder *encoder;
1089 int ret = 0;
1090 int connector_count = 0;
1091 int crtc_count = 0;
1092 int fb_count = 0;
1093 int encoder_count = 0;
1094 int copied = 0, i;
1095 uint32_t __user *fb_id;
1096 uint32_t __user *crtc_id;
1097 uint32_t __user *connector_id;
1098 uint32_t __user *encoder_id;
1099 struct drm_mode_group *mode_group;
1100
Dave Airliefb3b06c2011-02-08 13:55:21 +10001101 if (!drm_core_check_feature(dev, DRIVER_MODESET))
1102 return -EINVAL;
1103
Dave Airlief453ba02008-11-07 14:05:41 -08001104 mutex_lock(&dev->mode_config.mutex);
1105
1106 /*
1107 * For the non-control nodes we need to limit the list of resources
1108 * by IDs in the group list for this node
1109 */
1110 list_for_each(lh, &file_priv->fbs)
1111 fb_count++;
1112
1113 mode_group = &file_priv->master->minor->mode_group;
1114 if (file_priv->master->minor->type == DRM_MINOR_CONTROL) {
1115
1116 list_for_each(lh, &dev->mode_config.crtc_list)
1117 crtc_count++;
1118
1119 list_for_each(lh, &dev->mode_config.connector_list)
1120 connector_count++;
1121
1122 list_for_each(lh, &dev->mode_config.encoder_list)
1123 encoder_count++;
1124 } else {
1125
1126 crtc_count = mode_group->num_crtcs;
1127 connector_count = mode_group->num_connectors;
1128 encoder_count = mode_group->num_encoders;
1129 }
1130
1131 card_res->max_height = dev->mode_config.max_height;
1132 card_res->min_height = dev->mode_config.min_height;
1133 card_res->max_width = dev->mode_config.max_width;
1134 card_res->min_width = dev->mode_config.min_width;
1135
1136 /* handle this in 4 parts */
1137 /* FBs */
1138 if (card_res->count_fbs >= fb_count) {
1139 copied = 0;
1140 fb_id = (uint32_t __user *)(unsigned long)card_res->fb_id_ptr;
Sascha Hauer618c75e2011-06-03 12:54:14 +02001141 list_for_each_entry(fb, &file_priv->fbs, filp_head) {
Dave Airlief453ba02008-11-07 14:05:41 -08001142 if (put_user(fb->base.id, fb_id + copied)) {
1143 ret = -EFAULT;
1144 goto out;
1145 }
1146 copied++;
1147 }
1148 }
1149 card_res->count_fbs = fb_count;
1150
1151 /* CRTCs */
1152 if (card_res->count_crtcs >= crtc_count) {
1153 copied = 0;
1154 crtc_id = (uint32_t __user *)(unsigned long)card_res->crtc_id_ptr;
1155 if (file_priv->master->minor->type == DRM_MINOR_CONTROL) {
1156 list_for_each_entry(crtc, &dev->mode_config.crtc_list,
1157 head) {
Jerome Glisse94401062010-07-15 15:43:25 -04001158 DRM_DEBUG_KMS("[CRTC:%d]\n", crtc->base.id);
Dave Airlief453ba02008-11-07 14:05:41 -08001159 if (put_user(crtc->base.id, crtc_id + copied)) {
1160 ret = -EFAULT;
1161 goto out;
1162 }
1163 copied++;
1164 }
1165 } else {
1166 for (i = 0; i < mode_group->num_crtcs; i++) {
1167 if (put_user(mode_group->id_list[i],
1168 crtc_id + copied)) {
1169 ret = -EFAULT;
1170 goto out;
1171 }
1172 copied++;
1173 }
1174 }
1175 }
1176 card_res->count_crtcs = crtc_count;
1177
1178 /* Encoders */
1179 if (card_res->count_encoders >= encoder_count) {
1180 copied = 0;
1181 encoder_id = (uint32_t __user *)(unsigned long)card_res->encoder_id_ptr;
1182 if (file_priv->master->minor->type == DRM_MINOR_CONTROL) {
1183 list_for_each_entry(encoder,
1184 &dev->mode_config.encoder_list,
1185 head) {
Jerome Glisse94401062010-07-15 15:43:25 -04001186 DRM_DEBUG_KMS("[ENCODER:%d:%s]\n", encoder->base.id,
1187 drm_get_encoder_name(encoder));
Dave Airlief453ba02008-11-07 14:05:41 -08001188 if (put_user(encoder->base.id, encoder_id +
1189 copied)) {
1190 ret = -EFAULT;
1191 goto out;
1192 }
1193 copied++;
1194 }
1195 } else {
1196 for (i = mode_group->num_crtcs; i < mode_group->num_crtcs + mode_group->num_encoders; i++) {
1197 if (put_user(mode_group->id_list[i],
1198 encoder_id + copied)) {
1199 ret = -EFAULT;
1200 goto out;
1201 }
1202 copied++;
1203 }
1204
1205 }
1206 }
1207 card_res->count_encoders = encoder_count;
1208
1209 /* Connectors */
1210 if (card_res->count_connectors >= connector_count) {
1211 copied = 0;
1212 connector_id = (uint32_t __user *)(unsigned long)card_res->connector_id_ptr;
1213 if (file_priv->master->minor->type == DRM_MINOR_CONTROL) {
1214 list_for_each_entry(connector,
1215 &dev->mode_config.connector_list,
1216 head) {
Jerome Glisse94401062010-07-15 15:43:25 -04001217 DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n",
1218 connector->base.id,
1219 drm_get_connector_name(connector));
Dave Airlief453ba02008-11-07 14:05:41 -08001220 if (put_user(connector->base.id,
1221 connector_id + copied)) {
1222 ret = -EFAULT;
1223 goto out;
1224 }
1225 copied++;
1226 }
1227 } else {
1228 int start = mode_group->num_crtcs +
1229 mode_group->num_encoders;
1230 for (i = start; i < start + mode_group->num_connectors; i++) {
1231 if (put_user(mode_group->id_list[i],
1232 connector_id + copied)) {
1233 ret = -EFAULT;
1234 goto out;
1235 }
1236 copied++;
1237 }
1238 }
1239 }
1240 card_res->count_connectors = connector_count;
1241
Jerome Glisse94401062010-07-15 15:43:25 -04001242 DRM_DEBUG_KMS("CRTC[%d] CONNECTORS[%d] ENCODERS[%d]\n", card_res->count_crtcs,
Dave Airlief453ba02008-11-07 14:05:41 -08001243 card_res->count_connectors, card_res->count_encoders);
1244
1245out:
1246 mutex_unlock(&dev->mode_config.mutex);
1247 return ret;
1248}
1249
1250/**
1251 * drm_mode_getcrtc - get CRTC configuration
1252 * @inode: inode from the ioctl
1253 * @filp: file * from the ioctl
1254 * @cmd: cmd from ioctl
1255 * @arg: arg from ioctl
1256 *
1257 * LOCKING:
Sascha Hauerb20f3862012-02-01 11:38:31 +01001258 * Takes mode config lock.
Dave Airlief453ba02008-11-07 14:05:41 -08001259 *
1260 * Construct a CRTC configuration structure to return to the user.
1261 *
1262 * Called by the user via ioctl.
1263 *
1264 * RETURNS:
1265 * Zero on success, errno on failure.
1266 */
1267int drm_mode_getcrtc(struct drm_device *dev,
1268 void *data, struct drm_file *file_priv)
1269{
1270 struct drm_mode_crtc *crtc_resp = data;
1271 struct drm_crtc *crtc;
1272 struct drm_mode_object *obj;
1273 int ret = 0;
1274
Dave Airliefb3b06c2011-02-08 13:55:21 +10001275 if (!drm_core_check_feature(dev, DRIVER_MODESET))
1276 return -EINVAL;
1277
Dave Airlief453ba02008-11-07 14:05:41 -08001278 mutex_lock(&dev->mode_config.mutex);
1279
1280 obj = drm_mode_object_find(dev, crtc_resp->crtc_id,
1281 DRM_MODE_OBJECT_CRTC);
1282 if (!obj) {
1283 ret = -EINVAL;
1284 goto out;
1285 }
1286 crtc = obj_to_crtc(obj);
1287
1288 crtc_resp->x = crtc->x;
1289 crtc_resp->y = crtc->y;
1290 crtc_resp->gamma_size = crtc->gamma_size;
1291 if (crtc->fb)
1292 crtc_resp->fb_id = crtc->fb->base.id;
1293 else
1294 crtc_resp->fb_id = 0;
1295
1296 if (crtc->enabled) {
1297
1298 drm_crtc_convert_to_umode(&crtc_resp->mode, &crtc->mode);
1299 crtc_resp->mode_valid = 1;
1300
1301 } else {
1302 crtc_resp->mode_valid = 0;
1303 }
1304
1305out:
1306 mutex_unlock(&dev->mode_config.mutex);
1307 return ret;
1308}
1309
1310/**
1311 * drm_mode_getconnector - get connector configuration
1312 * @inode: inode from the ioctl
1313 * @filp: file * from the ioctl
1314 * @cmd: cmd from ioctl
1315 * @arg: arg from ioctl
1316 *
1317 * LOCKING:
Sascha Hauerb20f3862012-02-01 11:38:31 +01001318 * Takes mode config lock.
Dave Airlief453ba02008-11-07 14:05:41 -08001319 *
1320 * Construct a connector configuration structure to return to the user.
1321 *
1322 * Called by the user via ioctl.
1323 *
1324 * RETURNS:
1325 * Zero on success, errno on failure.
1326 */
1327int drm_mode_getconnector(struct drm_device *dev, void *data,
1328 struct drm_file *file_priv)
1329{
1330 struct drm_mode_get_connector *out_resp = data;
1331 struct drm_mode_object *obj;
1332 struct drm_connector *connector;
1333 struct drm_display_mode *mode;
1334 int mode_count = 0;
1335 int props_count = 0;
1336 int encoders_count = 0;
1337 int ret = 0;
1338 int copied = 0;
1339 int i;
1340 struct drm_mode_modeinfo u_mode;
1341 struct drm_mode_modeinfo __user *mode_ptr;
1342 uint32_t __user *prop_ptr;
1343 uint64_t __user *prop_values;
1344 uint32_t __user *encoder_ptr;
1345
Dave Airliefb3b06c2011-02-08 13:55:21 +10001346 if (!drm_core_check_feature(dev, DRIVER_MODESET))
1347 return -EINVAL;
1348
Dave Airlief453ba02008-11-07 14:05:41 -08001349 memset(&u_mode, 0, sizeof(struct drm_mode_modeinfo));
1350
Jerome Glisse94401062010-07-15 15:43:25 -04001351 DRM_DEBUG_KMS("[CONNECTOR:%d:?]\n", out_resp->connector_id);
Dave Airlief453ba02008-11-07 14:05:41 -08001352
1353 mutex_lock(&dev->mode_config.mutex);
1354
1355 obj = drm_mode_object_find(dev, out_resp->connector_id,
1356 DRM_MODE_OBJECT_CONNECTOR);
1357 if (!obj) {
1358 ret = -EINVAL;
1359 goto out;
1360 }
1361 connector = obj_to_connector(obj);
1362
1363 for (i = 0; i < DRM_CONNECTOR_MAX_PROPERTY; i++) {
1364 if (connector->property_ids[i] != 0) {
1365 props_count++;
1366 }
1367 }
1368
1369 for (i = 0; i < DRM_CONNECTOR_MAX_ENCODER; i++) {
1370 if (connector->encoder_ids[i] != 0) {
1371 encoders_count++;
1372 }
1373 }
1374
1375 if (out_resp->count_modes == 0) {
1376 connector->funcs->fill_modes(connector,
1377 dev->mode_config.max_width,
1378 dev->mode_config.max_height);
1379 }
1380
1381 /* delayed so we get modes regardless of pre-fill_modes state */
1382 list_for_each_entry(mode, &connector->modes, head)
1383 mode_count++;
1384
1385 out_resp->connector_id = connector->base.id;
1386 out_resp->connector_type = connector->connector_type;
1387 out_resp->connector_type_id = connector->connector_type_id;
1388 out_resp->mm_width = connector->display_info.width_mm;
1389 out_resp->mm_height = connector->display_info.height_mm;
1390 out_resp->subpixel = connector->display_info.subpixel_order;
1391 out_resp->connection = connector->status;
1392 if (connector->encoder)
1393 out_resp->encoder_id = connector->encoder->base.id;
1394 else
1395 out_resp->encoder_id = 0;
1396
1397 /*
1398 * This ioctl is called twice, once to determine how much space is
1399 * needed, and the 2nd time to fill it.
1400 */
1401 if ((out_resp->count_modes >= mode_count) && mode_count) {
1402 copied = 0;
Ville Syrjälä81f6c7f2011-12-20 00:06:42 +02001403 mode_ptr = (struct drm_mode_modeinfo __user *)(unsigned long)out_resp->modes_ptr;
Dave Airlief453ba02008-11-07 14:05:41 -08001404 list_for_each_entry(mode, &connector->modes, head) {
1405 drm_crtc_convert_to_umode(&u_mode, mode);
1406 if (copy_to_user(mode_ptr + copied,
1407 &u_mode, sizeof(u_mode))) {
1408 ret = -EFAULT;
1409 goto out;
1410 }
1411 copied++;
1412 }
1413 }
1414 out_resp->count_modes = mode_count;
1415
1416 if ((out_resp->count_props >= props_count) && props_count) {
1417 copied = 0;
Ville Syrjälä81f6c7f2011-12-20 00:06:42 +02001418 prop_ptr = (uint32_t __user *)(unsigned long)(out_resp->props_ptr);
1419 prop_values = (uint64_t __user *)(unsigned long)(out_resp->prop_values_ptr);
Dave Airlief453ba02008-11-07 14:05:41 -08001420 for (i = 0; i < DRM_CONNECTOR_MAX_PROPERTY; i++) {
1421 if (connector->property_ids[i] != 0) {
1422 if (put_user(connector->property_ids[i],
1423 prop_ptr + copied)) {
1424 ret = -EFAULT;
1425 goto out;
1426 }
1427
1428 if (put_user(connector->property_values[i],
1429 prop_values + copied)) {
1430 ret = -EFAULT;
1431 goto out;
1432 }
1433 copied++;
1434 }
1435 }
1436 }
1437 out_resp->count_props = props_count;
1438
1439 if ((out_resp->count_encoders >= encoders_count) && encoders_count) {
1440 copied = 0;
Ville Syrjälä81f6c7f2011-12-20 00:06:42 +02001441 encoder_ptr = (uint32_t __user *)(unsigned long)(out_resp->encoders_ptr);
Dave Airlief453ba02008-11-07 14:05:41 -08001442 for (i = 0; i < DRM_CONNECTOR_MAX_ENCODER; i++) {
1443 if (connector->encoder_ids[i] != 0) {
1444 if (put_user(connector->encoder_ids[i],
1445 encoder_ptr + copied)) {
1446 ret = -EFAULT;
1447 goto out;
1448 }
1449 copied++;
1450 }
1451 }
1452 }
1453 out_resp->count_encoders = encoders_count;
1454
1455out:
1456 mutex_unlock(&dev->mode_config.mutex);
1457 return ret;
1458}
1459
1460int drm_mode_getencoder(struct drm_device *dev, void *data,
1461 struct drm_file *file_priv)
1462{
1463 struct drm_mode_get_encoder *enc_resp = data;
1464 struct drm_mode_object *obj;
1465 struct drm_encoder *encoder;
1466 int ret = 0;
1467
Dave Airliefb3b06c2011-02-08 13:55:21 +10001468 if (!drm_core_check_feature(dev, DRIVER_MODESET))
1469 return -EINVAL;
1470
Dave Airlief453ba02008-11-07 14:05:41 -08001471 mutex_lock(&dev->mode_config.mutex);
1472 obj = drm_mode_object_find(dev, enc_resp->encoder_id,
1473 DRM_MODE_OBJECT_ENCODER);
1474 if (!obj) {
1475 ret = -EINVAL;
1476 goto out;
1477 }
1478 encoder = obj_to_encoder(obj);
1479
1480 if (encoder->crtc)
1481 enc_resp->crtc_id = encoder->crtc->base.id;
1482 else
1483 enc_resp->crtc_id = 0;
1484 enc_resp->encoder_type = encoder->encoder_type;
1485 enc_resp->encoder_id = encoder->base.id;
1486 enc_resp->possible_crtcs = encoder->possible_crtcs;
1487 enc_resp->possible_clones = encoder->possible_clones;
1488
1489out:
1490 mutex_unlock(&dev->mode_config.mutex);
1491 return ret;
1492}
1493
1494/**
Jesse Barnes8cf5c912011-11-14 14:51:27 -08001495 * drm_mode_getplane_res - get plane info
1496 * @dev: DRM device
1497 * @data: ioctl data
1498 * @file_priv: DRM file info
1499 *
Sascha Hauerb20f3862012-02-01 11:38:31 +01001500 * LOCKING:
1501 * Takes mode config lock.
1502 *
Jesse Barnes8cf5c912011-11-14 14:51:27 -08001503 * Return an plane count and set of IDs.
1504 */
1505int drm_mode_getplane_res(struct drm_device *dev, void *data,
1506 struct drm_file *file_priv)
1507{
1508 struct drm_mode_get_plane_res *plane_resp = data;
1509 struct drm_mode_config *config;
1510 struct drm_plane *plane;
1511 uint32_t __user *plane_ptr;
1512 int copied = 0, ret = 0;
1513
1514 if (!drm_core_check_feature(dev, DRIVER_MODESET))
1515 return -EINVAL;
1516
1517 mutex_lock(&dev->mode_config.mutex);
1518 config = &dev->mode_config;
1519
1520 /*
1521 * This ioctl is called twice, once to determine how much space is
1522 * needed, and the 2nd time to fill it.
1523 */
1524 if (config->num_plane &&
1525 (plane_resp->count_planes >= config->num_plane)) {
Ville Syrjälä81f6c7f2011-12-20 00:06:42 +02001526 plane_ptr = (uint32_t __user *)(unsigned long)plane_resp->plane_id_ptr;
Jesse Barnes8cf5c912011-11-14 14:51:27 -08001527
1528 list_for_each_entry(plane, &config->plane_list, head) {
1529 if (put_user(plane->base.id, plane_ptr + copied)) {
1530 ret = -EFAULT;
1531 goto out;
1532 }
1533 copied++;
1534 }
1535 }
1536 plane_resp->count_planes = config->num_plane;
1537
1538out:
1539 mutex_unlock(&dev->mode_config.mutex);
1540 return ret;
1541}
1542
1543/**
1544 * drm_mode_getplane - get plane info
1545 * @dev: DRM device
1546 * @data: ioctl data
1547 * @file_priv: DRM file info
1548 *
Sascha Hauerb20f3862012-02-01 11:38:31 +01001549 * LOCKING:
1550 * Takes mode config lock.
1551 *
Jesse Barnes8cf5c912011-11-14 14:51:27 -08001552 * Return plane info, including formats supported, gamma size, any
1553 * current fb, etc.
1554 */
1555int drm_mode_getplane(struct drm_device *dev, void *data,
1556 struct drm_file *file_priv)
1557{
1558 struct drm_mode_get_plane *plane_resp = data;
1559 struct drm_mode_object *obj;
1560 struct drm_plane *plane;
1561 uint32_t __user *format_ptr;
1562 int ret = 0;
1563
1564 if (!drm_core_check_feature(dev, DRIVER_MODESET))
1565 return -EINVAL;
1566
1567 mutex_lock(&dev->mode_config.mutex);
1568 obj = drm_mode_object_find(dev, plane_resp->plane_id,
1569 DRM_MODE_OBJECT_PLANE);
1570 if (!obj) {
1571 ret = -ENOENT;
1572 goto out;
1573 }
1574 plane = obj_to_plane(obj);
1575
1576 if (plane->crtc)
1577 plane_resp->crtc_id = plane->crtc->base.id;
1578 else
1579 plane_resp->crtc_id = 0;
1580
1581 if (plane->fb)
1582 plane_resp->fb_id = plane->fb->base.id;
1583 else
1584 plane_resp->fb_id = 0;
1585
1586 plane_resp->plane_id = plane->base.id;
1587 plane_resp->possible_crtcs = plane->possible_crtcs;
1588 plane_resp->gamma_size = plane->gamma_size;
1589
1590 /*
1591 * This ioctl is called twice, once to determine how much space is
1592 * needed, and the 2nd time to fill it.
1593 */
1594 if (plane->format_count &&
1595 (plane_resp->count_format_types >= plane->format_count)) {
Ville Syrjälä81f6c7f2011-12-20 00:06:42 +02001596 format_ptr = (uint32_t __user *)(unsigned long)plane_resp->format_type_ptr;
Jesse Barnes8cf5c912011-11-14 14:51:27 -08001597 if (copy_to_user(format_ptr,
1598 plane->format_types,
1599 sizeof(uint32_t) * plane->format_count)) {
1600 ret = -EFAULT;
1601 goto out;
1602 }
1603 }
1604 plane_resp->count_format_types = plane->format_count;
1605
1606out:
1607 mutex_unlock(&dev->mode_config.mutex);
1608 return ret;
1609}
1610
1611/**
1612 * drm_mode_setplane - set up or tear down an plane
1613 * @dev: DRM device
1614 * @data: ioctl data*
1615 * @file_prive: DRM file info
1616 *
Sascha Hauerb20f3862012-02-01 11:38:31 +01001617 * LOCKING:
1618 * Takes mode config lock.
1619 *
Jesse Barnes8cf5c912011-11-14 14:51:27 -08001620 * Set plane info, including placement, fb, scaling, and other factors.
1621 * Or pass a NULL fb to disable.
1622 */
1623int drm_mode_setplane(struct drm_device *dev, void *data,
1624 struct drm_file *file_priv)
1625{
1626 struct drm_mode_set_plane *plane_req = data;
1627 struct drm_mode_object *obj;
1628 struct drm_plane *plane;
1629 struct drm_crtc *crtc;
1630 struct drm_framebuffer *fb;
1631 int ret = 0;
Ville Syrjälä42ef8782011-12-20 00:06:44 +02001632 unsigned int fb_width, fb_height;
Ville Syrjälä62443be2011-12-20 00:06:47 +02001633 int i;
Jesse Barnes8cf5c912011-11-14 14:51:27 -08001634
1635 if (!drm_core_check_feature(dev, DRIVER_MODESET))
1636 return -EINVAL;
1637
1638 mutex_lock(&dev->mode_config.mutex);
1639
1640 /*
1641 * First, find the plane, crtc, and fb objects. If not available,
1642 * we don't bother to call the driver.
1643 */
1644 obj = drm_mode_object_find(dev, plane_req->plane_id,
1645 DRM_MODE_OBJECT_PLANE);
1646 if (!obj) {
1647 DRM_DEBUG_KMS("Unknown plane ID %d\n",
1648 plane_req->plane_id);
1649 ret = -ENOENT;
1650 goto out;
1651 }
1652 plane = obj_to_plane(obj);
1653
1654 /* No fb means shut it down */
1655 if (!plane_req->fb_id) {
1656 plane->funcs->disable_plane(plane);
Ville Syrjäläe5e3b442011-12-20 00:06:43 +02001657 plane->crtc = NULL;
1658 plane->fb = NULL;
Jesse Barnes8cf5c912011-11-14 14:51:27 -08001659 goto out;
1660 }
1661
1662 obj = drm_mode_object_find(dev, plane_req->crtc_id,
1663 DRM_MODE_OBJECT_CRTC);
1664 if (!obj) {
1665 DRM_DEBUG_KMS("Unknown crtc ID %d\n",
1666 plane_req->crtc_id);
1667 ret = -ENOENT;
1668 goto out;
1669 }
1670 crtc = obj_to_crtc(obj);
1671
1672 obj = drm_mode_object_find(dev, plane_req->fb_id,
1673 DRM_MODE_OBJECT_FB);
1674 if (!obj) {
1675 DRM_DEBUG_KMS("Unknown framebuffer ID %d\n",
1676 plane_req->fb_id);
1677 ret = -ENOENT;
1678 goto out;
1679 }
1680 fb = obj_to_fb(obj);
1681
Ville Syrjälä62443be2011-12-20 00:06:47 +02001682 /* Check whether this plane supports the fb pixel format. */
1683 for (i = 0; i < plane->format_count; i++)
1684 if (fb->pixel_format == plane->format_types[i])
1685 break;
1686 if (i == plane->format_count) {
1687 DRM_DEBUG_KMS("Invalid pixel format 0x%08x\n", fb->pixel_format);
1688 ret = -EINVAL;
1689 goto out;
1690 }
1691
Ville Syrjälä42ef8782011-12-20 00:06:44 +02001692 fb_width = fb->width << 16;
1693 fb_height = fb->height << 16;
1694
1695 /* Make sure source coordinates are inside the fb. */
1696 if (plane_req->src_w > fb_width ||
1697 plane_req->src_x > fb_width - plane_req->src_w ||
1698 plane_req->src_h > fb_height ||
1699 plane_req->src_y > fb_height - plane_req->src_h) {
1700 DRM_DEBUG_KMS("Invalid source coordinates "
1701 "%u.%06ux%u.%06u+%u.%06u+%u.%06u\n",
1702 plane_req->src_w >> 16,
1703 ((plane_req->src_w & 0xffff) * 15625) >> 10,
1704 plane_req->src_h >> 16,
1705 ((plane_req->src_h & 0xffff) * 15625) >> 10,
1706 plane_req->src_x >> 16,
1707 ((plane_req->src_x & 0xffff) * 15625) >> 10,
1708 plane_req->src_y >> 16,
1709 ((plane_req->src_y & 0xffff) * 15625) >> 10);
1710 ret = -ENOSPC;
1711 goto out;
1712 }
1713
Ville Syrjälä687a0402011-12-20 00:06:45 +02001714 /* Give drivers some help against integer overflows */
1715 if (plane_req->crtc_w > INT_MAX ||
1716 plane_req->crtc_x > INT_MAX - (int32_t) plane_req->crtc_w ||
1717 plane_req->crtc_h > INT_MAX ||
1718 plane_req->crtc_y > INT_MAX - (int32_t) plane_req->crtc_h) {
1719 DRM_DEBUG_KMS("Invalid CRTC coordinates %ux%u+%d+%d\n",
1720 plane_req->crtc_w, plane_req->crtc_h,
1721 plane_req->crtc_x, plane_req->crtc_y);
1722 ret = -ERANGE;
1723 goto out;
1724 }
1725
Jesse Barnes8cf5c912011-11-14 14:51:27 -08001726 ret = plane->funcs->update_plane(plane, crtc, fb,
1727 plane_req->crtc_x, plane_req->crtc_y,
1728 plane_req->crtc_w, plane_req->crtc_h,
1729 plane_req->src_x, plane_req->src_y,
1730 plane_req->src_w, plane_req->src_h);
1731 if (!ret) {
1732 plane->crtc = crtc;
1733 plane->fb = fb;
1734 }
1735
1736out:
1737 mutex_unlock(&dev->mode_config.mutex);
1738
1739 return ret;
1740}
1741
1742/**
Dave Airlief453ba02008-11-07 14:05:41 -08001743 * drm_mode_setcrtc - set CRTC configuration
1744 * @inode: inode from the ioctl
1745 * @filp: file * from the ioctl
1746 * @cmd: cmd from ioctl
1747 * @arg: arg from ioctl
1748 *
1749 * LOCKING:
Sascha Hauerb20f3862012-02-01 11:38:31 +01001750 * Takes mode config lock.
Dave Airlief453ba02008-11-07 14:05:41 -08001751 *
1752 * Build a new CRTC configuration based on user request.
1753 *
1754 * Called by the user via ioctl.
1755 *
1756 * RETURNS:
1757 * Zero on success, errno on failure.
1758 */
1759int drm_mode_setcrtc(struct drm_device *dev, void *data,
1760 struct drm_file *file_priv)
1761{
1762 struct drm_mode_config *config = &dev->mode_config;
1763 struct drm_mode_crtc *crtc_req = data;
1764 struct drm_mode_object *obj;
Ville Syrjälä6653cc82012-03-13 12:35:38 +02001765 struct drm_crtc *crtc;
Dave Airlief453ba02008-11-07 14:05:41 -08001766 struct drm_connector **connector_set = NULL, *connector;
1767 struct drm_framebuffer *fb = NULL;
1768 struct drm_display_mode *mode = NULL;
1769 struct drm_mode_set set;
1770 uint32_t __user *set_connectors_ptr;
1771 int ret = 0;
1772 int i;
1773
Dave Airliefb3b06c2011-02-08 13:55:21 +10001774 if (!drm_core_check_feature(dev, DRIVER_MODESET))
1775 return -EINVAL;
1776
Ville Syrjälä1d97e912012-03-13 12:35:41 +02001777 /* For some reason crtc x/y offsets are signed internally. */
1778 if (crtc_req->x > INT_MAX || crtc_req->y > INT_MAX)
1779 return -ERANGE;
1780
Dave Airlief453ba02008-11-07 14:05:41 -08001781 mutex_lock(&dev->mode_config.mutex);
1782 obj = drm_mode_object_find(dev, crtc_req->crtc_id,
1783 DRM_MODE_OBJECT_CRTC);
1784 if (!obj) {
Zhao Yakui58367ed2009-07-20 13:48:07 +08001785 DRM_DEBUG_KMS("Unknown CRTC ID %d\n", crtc_req->crtc_id);
Dave Airlief453ba02008-11-07 14:05:41 -08001786 ret = -EINVAL;
1787 goto out;
1788 }
1789 crtc = obj_to_crtc(obj);
Jerome Glisse94401062010-07-15 15:43:25 -04001790 DRM_DEBUG_KMS("[CRTC:%d]\n", crtc->base.id);
Dave Airlief453ba02008-11-07 14:05:41 -08001791
1792 if (crtc_req->mode_valid) {
1793 /* If we have a mode we need a framebuffer. */
1794 /* If we pass -1, set the mode with the currently bound fb */
1795 if (crtc_req->fb_id == -1) {
Ville Syrjälä6653cc82012-03-13 12:35:38 +02001796 if (!crtc->fb) {
1797 DRM_DEBUG_KMS("CRTC doesn't have current FB\n");
1798 ret = -EINVAL;
1799 goto out;
Dave Airlief453ba02008-11-07 14:05:41 -08001800 }
Ville Syrjälä6653cc82012-03-13 12:35:38 +02001801 fb = crtc->fb;
Dave Airlief453ba02008-11-07 14:05:41 -08001802 } else {
1803 obj = drm_mode_object_find(dev, crtc_req->fb_id,
1804 DRM_MODE_OBJECT_FB);
1805 if (!obj) {
Zhao Yakui58367ed2009-07-20 13:48:07 +08001806 DRM_DEBUG_KMS("Unknown FB ID%d\n",
1807 crtc_req->fb_id);
Dave Airlief453ba02008-11-07 14:05:41 -08001808 ret = -EINVAL;
1809 goto out;
1810 }
1811 fb = obj_to_fb(obj);
1812 }
1813
1814 mode = drm_mode_create(dev);
1815 drm_crtc_convert_umode(mode, &crtc_req->mode);
1816 drm_mode_set_crtcinfo(mode, CRTC_INTERLACE_HALVE_V);
1817 }
1818
1819 if (crtc_req->count_connectors == 0 && mode) {
Zhao Yakui58367ed2009-07-20 13:48:07 +08001820 DRM_DEBUG_KMS("Count connectors is 0 but mode set\n");
Dave Airlief453ba02008-11-07 14:05:41 -08001821 ret = -EINVAL;
1822 goto out;
1823 }
1824
Jakob Bornecrantz7781de72009-08-03 13:43:58 +01001825 if (crtc_req->count_connectors > 0 && (!mode || !fb)) {
Zhao Yakui58367ed2009-07-20 13:48:07 +08001826 DRM_DEBUG_KMS("Count connectors is %d but no mode or fb set\n",
Dave Airlief453ba02008-11-07 14:05:41 -08001827 crtc_req->count_connectors);
1828 ret = -EINVAL;
1829 goto out;
1830 }
1831
1832 if (crtc_req->count_connectors > 0) {
1833 u32 out_id;
1834
1835 /* Avoid unbounded kernel memory allocation */
1836 if (crtc_req->count_connectors > config->num_connector) {
1837 ret = -EINVAL;
1838 goto out;
1839 }
1840
1841 connector_set = kmalloc(crtc_req->count_connectors *
1842 sizeof(struct drm_connector *),
1843 GFP_KERNEL);
1844 if (!connector_set) {
1845 ret = -ENOMEM;
1846 goto out;
1847 }
1848
1849 for (i = 0; i < crtc_req->count_connectors; i++) {
Ville Syrjälä81f6c7f2011-12-20 00:06:42 +02001850 set_connectors_ptr = (uint32_t __user *)(unsigned long)crtc_req->set_connectors_ptr;
Dave Airlief453ba02008-11-07 14:05:41 -08001851 if (get_user(out_id, &set_connectors_ptr[i])) {
1852 ret = -EFAULT;
1853 goto out;
1854 }
1855
1856 obj = drm_mode_object_find(dev, out_id,
1857 DRM_MODE_OBJECT_CONNECTOR);
1858 if (!obj) {
Zhao Yakui58367ed2009-07-20 13:48:07 +08001859 DRM_DEBUG_KMS("Connector id %d unknown\n",
1860 out_id);
Dave Airlief453ba02008-11-07 14:05:41 -08001861 ret = -EINVAL;
1862 goto out;
1863 }
1864 connector = obj_to_connector(obj);
Jerome Glisse94401062010-07-15 15:43:25 -04001865 DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n",
1866 connector->base.id,
1867 drm_get_connector_name(connector));
Dave Airlief453ba02008-11-07 14:05:41 -08001868
1869 connector_set[i] = connector;
1870 }
1871 }
1872
1873 set.crtc = crtc;
1874 set.x = crtc_req->x;
1875 set.y = crtc_req->y;
1876 set.mode = mode;
1877 set.connectors = connector_set;
1878 set.num_connectors = crtc_req->count_connectors;
Dave Airlie5ef5f722009-08-17 13:11:23 +10001879 set.fb = fb;
Dave Airlief453ba02008-11-07 14:05:41 -08001880 ret = crtc->funcs->set_config(&set);
1881
1882out:
1883 kfree(connector_set);
1884 mutex_unlock(&dev->mode_config.mutex);
1885 return ret;
1886}
1887
1888int drm_mode_cursor_ioctl(struct drm_device *dev,
1889 void *data, struct drm_file *file_priv)
1890{
1891 struct drm_mode_cursor *req = data;
1892 struct drm_mode_object *obj;
1893 struct drm_crtc *crtc;
1894 int ret = 0;
1895
Dave Airliefb3b06c2011-02-08 13:55:21 +10001896 if (!drm_core_check_feature(dev, DRIVER_MODESET))
1897 return -EINVAL;
1898
Jesse Barnesacb4b992011-11-07 12:03:23 -08001899 if (!req->flags)
Dave Airlief453ba02008-11-07 14:05:41 -08001900 return -EINVAL;
Dave Airlief453ba02008-11-07 14:05:41 -08001901
1902 mutex_lock(&dev->mode_config.mutex);
Jakob Bornecrantze0c84632008-12-19 14:50:50 +10001903 obj = drm_mode_object_find(dev, req->crtc_id, DRM_MODE_OBJECT_CRTC);
Dave Airlief453ba02008-11-07 14:05:41 -08001904 if (!obj) {
Zhao Yakui58367ed2009-07-20 13:48:07 +08001905 DRM_DEBUG_KMS("Unknown CRTC ID %d\n", req->crtc_id);
Dave Airlief453ba02008-11-07 14:05:41 -08001906 ret = -EINVAL;
1907 goto out;
1908 }
1909 crtc = obj_to_crtc(obj);
1910
1911 if (req->flags & DRM_MODE_CURSOR_BO) {
1912 if (!crtc->funcs->cursor_set) {
Dave Airlief453ba02008-11-07 14:05:41 -08001913 ret = -ENXIO;
1914 goto out;
1915 }
1916 /* Turns off the cursor if handle is 0 */
1917 ret = crtc->funcs->cursor_set(crtc, file_priv, req->handle,
1918 req->width, req->height);
1919 }
1920
1921 if (req->flags & DRM_MODE_CURSOR_MOVE) {
1922 if (crtc->funcs->cursor_move) {
1923 ret = crtc->funcs->cursor_move(crtc, req->x, req->y);
1924 } else {
Dave Airlief453ba02008-11-07 14:05:41 -08001925 ret = -EFAULT;
1926 goto out;
1927 }
1928 }
1929out:
1930 mutex_unlock(&dev->mode_config.mutex);
1931 return ret;
1932}
1933
Jesse Barnes308e5bc2011-11-14 14:51:28 -08001934/* Original addfb only supported RGB formats, so figure out which one */
1935uint32_t drm_mode_legacy_fb_format(uint32_t bpp, uint32_t depth)
1936{
1937 uint32_t fmt;
1938
1939 switch (bpp) {
1940 case 8:
Ville Syrjälä04b39242011-11-17 18:05:13 +02001941 fmt = DRM_FORMAT_RGB332;
Jesse Barnes308e5bc2011-11-14 14:51:28 -08001942 break;
1943 case 16:
1944 if (depth == 15)
Ville Syrjälä04b39242011-11-17 18:05:13 +02001945 fmt = DRM_FORMAT_XRGB1555;
Jesse Barnes308e5bc2011-11-14 14:51:28 -08001946 else
Ville Syrjälä04b39242011-11-17 18:05:13 +02001947 fmt = DRM_FORMAT_RGB565;
Jesse Barnes308e5bc2011-11-14 14:51:28 -08001948 break;
1949 case 24:
Ville Syrjälä04b39242011-11-17 18:05:13 +02001950 fmt = DRM_FORMAT_RGB888;
Jesse Barnes308e5bc2011-11-14 14:51:28 -08001951 break;
1952 case 32:
1953 if (depth == 24)
Ville Syrjälä04b39242011-11-17 18:05:13 +02001954 fmt = DRM_FORMAT_XRGB8888;
Jesse Barnes308e5bc2011-11-14 14:51:28 -08001955 else if (depth == 30)
Ville Syrjälä04b39242011-11-17 18:05:13 +02001956 fmt = DRM_FORMAT_XRGB2101010;
Jesse Barnes308e5bc2011-11-14 14:51:28 -08001957 else
Ville Syrjälä04b39242011-11-17 18:05:13 +02001958 fmt = DRM_FORMAT_ARGB8888;
Jesse Barnes308e5bc2011-11-14 14:51:28 -08001959 break;
1960 default:
Ville Syrjälä04b39242011-11-17 18:05:13 +02001961 DRM_ERROR("bad bpp, assuming x8r8g8b8 pixel format\n");
1962 fmt = DRM_FORMAT_XRGB8888;
Jesse Barnes308e5bc2011-11-14 14:51:28 -08001963 break;
1964 }
1965
1966 return fmt;
1967}
1968EXPORT_SYMBOL(drm_mode_legacy_fb_format);
1969
Dave Airlief453ba02008-11-07 14:05:41 -08001970/**
1971 * drm_mode_addfb - add an FB to the graphics configuration
1972 * @inode: inode from the ioctl
1973 * @filp: file * from the ioctl
1974 * @cmd: cmd from ioctl
1975 * @arg: arg from ioctl
1976 *
1977 * LOCKING:
1978 * Takes mode config lock.
1979 *
1980 * Add a new FB to the specified CRTC, given a user request.
1981 *
1982 * Called by the user via ioctl.
1983 *
1984 * RETURNS:
1985 * Zero on success, errno on failure.
1986 */
1987int drm_mode_addfb(struct drm_device *dev,
1988 void *data, struct drm_file *file_priv)
1989{
Jesse Barnes308e5bc2011-11-14 14:51:28 -08001990 struct drm_mode_fb_cmd *or = data;
1991 struct drm_mode_fb_cmd2 r = {};
1992 struct drm_mode_config *config = &dev->mode_config;
1993 struct drm_framebuffer *fb;
1994 int ret = 0;
1995
1996 /* Use new struct with format internally */
1997 r.fb_id = or->fb_id;
1998 r.width = or->width;
1999 r.height = or->height;
2000 r.pitches[0] = or->pitch;
2001 r.pixel_format = drm_mode_legacy_fb_format(or->bpp, or->depth);
2002 r.handles[0] = or->handle;
2003
2004 if (!drm_core_check_feature(dev, DRIVER_MODESET))
2005 return -EINVAL;
2006
Jesse Barnesacb4b992011-11-07 12:03:23 -08002007 if ((config->min_width > r.width) || (r.width > config->max_width))
Jesse Barnes308e5bc2011-11-14 14:51:28 -08002008 return -EINVAL;
Jesse Barnesacb4b992011-11-07 12:03:23 -08002009
2010 if ((config->min_height > r.height) || (r.height > config->max_height))
Jesse Barnes308e5bc2011-11-14 14:51:28 -08002011 return -EINVAL;
Jesse Barnes308e5bc2011-11-14 14:51:28 -08002012
2013 mutex_lock(&dev->mode_config.mutex);
2014
2015 /* TODO check buffer is sufficiently large */
2016 /* TODO setup destructor callback */
2017
2018 fb = dev->mode_config.funcs->fb_create(dev, file_priv, &r);
2019 if (IS_ERR(fb)) {
2020 DRM_ERROR("could not create framebuffer\n");
2021 ret = PTR_ERR(fb);
2022 goto out;
2023 }
2024
2025 or->fb_id = fb->base.id;
2026 list_add(&fb->filp_head, &file_priv->fbs);
2027 DRM_DEBUG_KMS("[FB:%d]\n", fb->base.id);
2028
2029out:
2030 mutex_unlock(&dev->mode_config.mutex);
2031 return ret;
2032}
2033
Ville Syrjälä935b5972011-12-20 00:06:48 +02002034static int format_check(struct drm_mode_fb_cmd2 *r)
2035{
2036 uint32_t format = r->pixel_format & ~DRM_FORMAT_BIG_ENDIAN;
2037
2038 switch (format) {
2039 case DRM_FORMAT_C8:
2040 case DRM_FORMAT_RGB332:
2041 case DRM_FORMAT_BGR233:
2042 case DRM_FORMAT_XRGB4444:
2043 case DRM_FORMAT_XBGR4444:
2044 case DRM_FORMAT_RGBX4444:
2045 case DRM_FORMAT_BGRX4444:
2046 case DRM_FORMAT_ARGB4444:
2047 case DRM_FORMAT_ABGR4444:
2048 case DRM_FORMAT_RGBA4444:
2049 case DRM_FORMAT_BGRA4444:
2050 case DRM_FORMAT_XRGB1555:
2051 case DRM_FORMAT_XBGR1555:
2052 case DRM_FORMAT_RGBX5551:
2053 case DRM_FORMAT_BGRX5551:
2054 case DRM_FORMAT_ARGB1555:
2055 case DRM_FORMAT_ABGR1555:
2056 case DRM_FORMAT_RGBA5551:
2057 case DRM_FORMAT_BGRA5551:
2058 case DRM_FORMAT_RGB565:
2059 case DRM_FORMAT_BGR565:
2060 case DRM_FORMAT_RGB888:
2061 case DRM_FORMAT_BGR888:
2062 case DRM_FORMAT_XRGB8888:
2063 case DRM_FORMAT_XBGR8888:
2064 case DRM_FORMAT_RGBX8888:
2065 case DRM_FORMAT_BGRX8888:
2066 case DRM_FORMAT_ARGB8888:
2067 case DRM_FORMAT_ABGR8888:
2068 case DRM_FORMAT_RGBA8888:
2069 case DRM_FORMAT_BGRA8888:
2070 case DRM_FORMAT_XRGB2101010:
2071 case DRM_FORMAT_XBGR2101010:
2072 case DRM_FORMAT_RGBX1010102:
2073 case DRM_FORMAT_BGRX1010102:
2074 case DRM_FORMAT_ARGB2101010:
2075 case DRM_FORMAT_ABGR2101010:
2076 case DRM_FORMAT_RGBA1010102:
2077 case DRM_FORMAT_BGRA1010102:
2078 case DRM_FORMAT_YUYV:
2079 case DRM_FORMAT_YVYU:
2080 case DRM_FORMAT_UYVY:
2081 case DRM_FORMAT_VYUY:
2082 case DRM_FORMAT_AYUV:
2083 case DRM_FORMAT_NV12:
2084 case DRM_FORMAT_NV21:
2085 case DRM_FORMAT_NV16:
2086 case DRM_FORMAT_NV61:
2087 case DRM_FORMAT_YUV410:
2088 case DRM_FORMAT_YVU410:
2089 case DRM_FORMAT_YUV411:
2090 case DRM_FORMAT_YVU411:
2091 case DRM_FORMAT_YUV420:
2092 case DRM_FORMAT_YVU420:
2093 case DRM_FORMAT_YUV422:
2094 case DRM_FORMAT_YVU422:
2095 case DRM_FORMAT_YUV444:
2096 case DRM_FORMAT_YVU444:
2097 return 0;
2098 default:
2099 return -EINVAL;
2100 }
2101}
2102
Jesse Barnes308e5bc2011-11-14 14:51:28 -08002103/**
2104 * drm_mode_addfb2 - add an FB to the graphics configuration
2105 * @inode: inode from the ioctl
2106 * @filp: file * from the ioctl
2107 * @cmd: cmd from ioctl
2108 * @arg: arg from ioctl
2109 *
2110 * LOCKING:
2111 * Takes mode config lock.
2112 *
2113 * Add a new FB to the specified CRTC, given a user request with format.
2114 *
2115 * Called by the user via ioctl.
2116 *
2117 * RETURNS:
2118 * Zero on success, errno on failure.
2119 */
2120int drm_mode_addfb2(struct drm_device *dev,
2121 void *data, struct drm_file *file_priv)
2122{
2123 struct drm_mode_fb_cmd2 *r = data;
Dave Airlief453ba02008-11-07 14:05:41 -08002124 struct drm_mode_config *config = &dev->mode_config;
2125 struct drm_framebuffer *fb;
2126 int ret = 0;
2127
Dave Airliefb3b06c2011-02-08 13:55:21 +10002128 if (!drm_core_check_feature(dev, DRIVER_MODESET))
2129 return -EINVAL;
2130
Dave Airlief453ba02008-11-07 14:05:41 -08002131 if ((config->min_width > r->width) || (r->width > config->max_width)) {
Jesse Barnes8cf5c912011-11-14 14:51:27 -08002132 DRM_ERROR("bad framebuffer width %d, should be >= %d && <= %d\n",
2133 r->width, config->min_width, config->max_width);
Dave Airlief453ba02008-11-07 14:05:41 -08002134 return -EINVAL;
2135 }
2136 if ((config->min_height > r->height) || (r->height > config->max_height)) {
Jesse Barnes8cf5c912011-11-14 14:51:27 -08002137 DRM_ERROR("bad framebuffer height %d, should be >= %d && <= %d\n",
2138 r->height, config->min_height, config->max_height);
Dave Airlief453ba02008-11-07 14:05:41 -08002139 return -EINVAL;
2140 }
2141
Ville Syrjälä935b5972011-12-20 00:06:48 +02002142 ret = format_check(r);
2143 if (ret) {
2144 DRM_ERROR("bad framebuffer format 0x%08x\n", r->pixel_format);
2145 return ret;
2146 }
2147
Dave Airlief453ba02008-11-07 14:05:41 -08002148 mutex_lock(&dev->mode_config.mutex);
2149
Dave Airlief453ba02008-11-07 14:05:41 -08002150 fb = dev->mode_config.funcs->fb_create(dev, file_priv, r);
Chris Wilsoncce13ff2010-08-08 13:36:38 +01002151 if (IS_ERR(fb)) {
Dave Airlief453ba02008-11-07 14:05:41 -08002152 DRM_ERROR("could not create framebuffer\n");
Chris Wilsoncce13ff2010-08-08 13:36:38 +01002153 ret = PTR_ERR(fb);
Dave Airlief453ba02008-11-07 14:05:41 -08002154 goto out;
2155 }
2156
Jakob Bornecrantze0c84632008-12-19 14:50:50 +10002157 r->fb_id = fb->base.id;
Dave Airlief453ba02008-11-07 14:05:41 -08002158 list_add(&fb->filp_head, &file_priv->fbs);
Jerome Glisse94401062010-07-15 15:43:25 -04002159 DRM_DEBUG_KMS("[FB:%d]\n", fb->base.id);
Dave Airlief453ba02008-11-07 14:05:41 -08002160
2161out:
2162 mutex_unlock(&dev->mode_config.mutex);
2163 return ret;
2164}
2165
2166/**
2167 * drm_mode_rmfb - remove an FB from the configuration
2168 * @inode: inode from the ioctl
2169 * @filp: file * from the ioctl
2170 * @cmd: cmd from ioctl
2171 * @arg: arg from ioctl
2172 *
2173 * LOCKING:
2174 * Takes mode config lock.
2175 *
2176 * Remove the FB specified by the user.
2177 *
2178 * Called by the user via ioctl.
2179 *
2180 * RETURNS:
2181 * Zero on success, errno on failure.
2182 */
2183int drm_mode_rmfb(struct drm_device *dev,
2184 void *data, struct drm_file *file_priv)
2185{
2186 struct drm_mode_object *obj;
2187 struct drm_framebuffer *fb = NULL;
2188 struct drm_framebuffer *fbl = NULL;
2189 uint32_t *id = data;
2190 int ret = 0;
2191 int found = 0;
2192
Dave Airliefb3b06c2011-02-08 13:55:21 +10002193 if (!drm_core_check_feature(dev, DRIVER_MODESET))
2194 return -EINVAL;
2195
Dave Airlief453ba02008-11-07 14:05:41 -08002196 mutex_lock(&dev->mode_config.mutex);
2197 obj = drm_mode_object_find(dev, *id, DRM_MODE_OBJECT_FB);
Lucas De Marchi25985ed2011-03-30 22:57:33 -03002198 /* TODO check that we really get a framebuffer back. */
Dave Airlief453ba02008-11-07 14:05:41 -08002199 if (!obj) {
Dave Airlief453ba02008-11-07 14:05:41 -08002200 ret = -EINVAL;
2201 goto out;
2202 }
2203 fb = obj_to_fb(obj);
2204
2205 list_for_each_entry(fbl, &file_priv->fbs, filp_head)
2206 if (fb == fbl)
2207 found = 1;
2208
2209 if (!found) {
Dave Airlief453ba02008-11-07 14:05:41 -08002210 ret = -EINVAL;
2211 goto out;
2212 }
2213
2214 /* TODO release all crtc connected to the framebuffer */
2215 /* TODO unhock the destructor from the buffer object */
2216
2217 list_del(&fb->filp_head);
2218 fb->funcs->destroy(fb);
2219
2220out:
2221 mutex_unlock(&dev->mode_config.mutex);
2222 return ret;
2223}
2224
2225/**
2226 * drm_mode_getfb - get FB info
2227 * @inode: inode from the ioctl
2228 * @filp: file * from the ioctl
2229 * @cmd: cmd from ioctl
2230 * @arg: arg from ioctl
2231 *
2232 * LOCKING:
Sascha Hauerb20f3862012-02-01 11:38:31 +01002233 * Takes mode config lock.
Dave Airlief453ba02008-11-07 14:05:41 -08002234 *
2235 * Lookup the FB given its ID and return info about it.
2236 *
2237 * Called by the user via ioctl.
2238 *
2239 * RETURNS:
2240 * Zero on success, errno on failure.
2241 */
2242int drm_mode_getfb(struct drm_device *dev,
2243 void *data, struct drm_file *file_priv)
2244{
2245 struct drm_mode_fb_cmd *r = data;
2246 struct drm_mode_object *obj;
2247 struct drm_framebuffer *fb;
2248 int ret = 0;
2249
Dave Airliefb3b06c2011-02-08 13:55:21 +10002250 if (!drm_core_check_feature(dev, DRIVER_MODESET))
2251 return -EINVAL;
2252
Dave Airlief453ba02008-11-07 14:05:41 -08002253 mutex_lock(&dev->mode_config.mutex);
Jakob Bornecrantze0c84632008-12-19 14:50:50 +10002254 obj = drm_mode_object_find(dev, r->fb_id, DRM_MODE_OBJECT_FB);
Dave Airlief453ba02008-11-07 14:05:41 -08002255 if (!obj) {
Dave Airlief453ba02008-11-07 14:05:41 -08002256 ret = -EINVAL;
2257 goto out;
2258 }
2259 fb = obj_to_fb(obj);
2260
2261 r->height = fb->height;
2262 r->width = fb->width;
2263 r->depth = fb->depth;
2264 r->bpp = fb->bits_per_pixel;
Ville Syrjälä01f2c772011-12-20 00:06:49 +02002265 r->pitch = fb->pitches[0];
Dave Airlief453ba02008-11-07 14:05:41 -08002266 fb->funcs->create_handle(fb, file_priv, &r->handle);
2267
2268out:
2269 mutex_unlock(&dev->mode_config.mutex);
2270 return ret;
2271}
2272
Jakob Bornecrantz884840a2009-12-03 23:25:47 +00002273int drm_mode_dirtyfb_ioctl(struct drm_device *dev,
2274 void *data, struct drm_file *file_priv)
2275{
2276 struct drm_clip_rect __user *clips_ptr;
2277 struct drm_clip_rect *clips = NULL;
2278 struct drm_mode_fb_dirty_cmd *r = data;
2279 struct drm_mode_object *obj;
2280 struct drm_framebuffer *fb;
2281 unsigned flags;
2282 int num_clips;
2283 int ret = 0;
2284
Dave Airliefb3b06c2011-02-08 13:55:21 +10002285 if (!drm_core_check_feature(dev, DRIVER_MODESET))
2286 return -EINVAL;
2287
Jakob Bornecrantz884840a2009-12-03 23:25:47 +00002288 mutex_lock(&dev->mode_config.mutex);
2289 obj = drm_mode_object_find(dev, r->fb_id, DRM_MODE_OBJECT_FB);
2290 if (!obj) {
Jakob Bornecrantz884840a2009-12-03 23:25:47 +00002291 ret = -EINVAL;
2292 goto out_err1;
2293 }
2294 fb = obj_to_fb(obj);
2295
2296 num_clips = r->num_clips;
Ville Syrjälä81f6c7f2011-12-20 00:06:42 +02002297 clips_ptr = (struct drm_clip_rect __user *)(unsigned long)r->clips_ptr;
Jakob Bornecrantz884840a2009-12-03 23:25:47 +00002298
2299 if (!num_clips != !clips_ptr) {
2300 ret = -EINVAL;
2301 goto out_err1;
2302 }
2303
2304 flags = DRM_MODE_FB_DIRTY_FLAGS & r->flags;
2305
2306 /* If userspace annotates copy, clips must come in pairs */
2307 if (flags & DRM_MODE_FB_DIRTY_ANNOTATE_COPY && (num_clips % 2)) {
2308 ret = -EINVAL;
2309 goto out_err1;
2310 }
2311
2312 if (num_clips && clips_ptr) {
Xi Wanga5cd3352011-11-23 01:12:01 -05002313 if (num_clips < 0 || num_clips > DRM_MODE_FB_DIRTY_MAX_CLIPS) {
2314 ret = -EINVAL;
2315 goto out_err1;
2316 }
Jakob Bornecrantz884840a2009-12-03 23:25:47 +00002317 clips = kzalloc(num_clips * sizeof(*clips), GFP_KERNEL);
2318 if (!clips) {
2319 ret = -ENOMEM;
2320 goto out_err1;
2321 }
2322
2323 ret = copy_from_user(clips, clips_ptr,
2324 num_clips * sizeof(*clips));
Dan Carpentere902a352010-06-04 12:23:21 +02002325 if (ret) {
2326 ret = -EFAULT;
Jakob Bornecrantz884840a2009-12-03 23:25:47 +00002327 goto out_err2;
Dan Carpentere902a352010-06-04 12:23:21 +02002328 }
Jakob Bornecrantz884840a2009-12-03 23:25:47 +00002329 }
2330
2331 if (fb->funcs->dirty) {
Thomas Hellstrom02b00162010-10-05 12:43:02 +02002332 ret = fb->funcs->dirty(fb, file_priv, flags, r->color,
2333 clips, num_clips);
Jakob Bornecrantz884840a2009-12-03 23:25:47 +00002334 } else {
2335 ret = -ENOSYS;
2336 goto out_err2;
2337 }
2338
2339out_err2:
2340 kfree(clips);
2341out_err1:
2342 mutex_unlock(&dev->mode_config.mutex);
2343 return ret;
2344}
2345
2346
Dave Airlief453ba02008-11-07 14:05:41 -08002347/**
2348 * drm_fb_release - remove and free the FBs on this file
2349 * @filp: file * from the ioctl
2350 *
2351 * LOCKING:
2352 * Takes mode config lock.
2353 *
2354 * Destroy all the FBs associated with @filp.
2355 *
2356 * Called by the user via ioctl.
2357 *
2358 * RETURNS:
2359 * Zero on success, errno on failure.
2360 */
Kristian Høgsbergea39f832009-02-12 14:37:56 -05002361void drm_fb_release(struct drm_file *priv)
Dave Airlief453ba02008-11-07 14:05:41 -08002362{
Dave Airlief453ba02008-11-07 14:05:41 -08002363 struct drm_device *dev = priv->minor->dev;
2364 struct drm_framebuffer *fb, *tfb;
2365
2366 mutex_lock(&dev->mode_config.mutex);
2367 list_for_each_entry_safe(fb, tfb, &priv->fbs, filp_head) {
2368 list_del(&fb->filp_head);
2369 fb->funcs->destroy(fb);
2370 }
2371 mutex_unlock(&dev->mode_config.mutex);
2372}
2373
2374/**
2375 * drm_mode_attachmode - add a mode to the user mode list
2376 * @dev: DRM device
2377 * @connector: connector to add the mode to
2378 * @mode: mode to add
2379 *
2380 * Add @mode to @connector's user mode list.
2381 */
Ville Syrjälä1dd6c8b2012-03-13 12:35:42 +02002382static void drm_mode_attachmode(struct drm_device *dev,
2383 struct drm_connector *connector,
2384 struct drm_display_mode *mode)
Dave Airlief453ba02008-11-07 14:05:41 -08002385{
Dave Airlief453ba02008-11-07 14:05:41 -08002386 list_add_tail(&mode->head, &connector->user_modes);
Dave Airlief453ba02008-11-07 14:05:41 -08002387}
2388
2389int drm_mode_attachmode_crtc(struct drm_device *dev, struct drm_crtc *crtc,
2390 struct drm_display_mode *mode)
2391{
2392 struct drm_connector *connector;
Dave Airlief453ba02008-11-07 14:05:41 -08002393 struct drm_display_mode *dup_mode;
2394 int need_dup = 0;
2395 list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
2396 if (!connector->encoder)
2397 break;
2398 if (connector->encoder->crtc == crtc) {
2399 if (need_dup)
2400 dup_mode = drm_mode_duplicate(dev, mode);
2401 else
2402 dup_mode = mode;
Ville Syrjälä1dd6c8b2012-03-13 12:35:42 +02002403 drm_mode_attachmode(dev, connector, dup_mode);
Dave Airlief453ba02008-11-07 14:05:41 -08002404 need_dup = 1;
2405 }
2406 }
2407 return 0;
2408}
2409EXPORT_SYMBOL(drm_mode_attachmode_crtc);
2410
2411static int drm_mode_detachmode(struct drm_device *dev,
2412 struct drm_connector *connector,
2413 struct drm_display_mode *mode)
2414{
2415 int found = 0;
2416 int ret = 0;
2417 struct drm_display_mode *match_mode, *t;
2418
2419 list_for_each_entry_safe(match_mode, t, &connector->user_modes, head) {
2420 if (drm_mode_equal(match_mode, mode)) {
2421 list_del(&match_mode->head);
2422 drm_mode_destroy(dev, match_mode);
2423 found = 1;
2424 break;
2425 }
2426 }
2427
2428 if (!found)
2429 ret = -EINVAL;
2430
2431 return ret;
2432}
2433
2434int drm_mode_detachmode_crtc(struct drm_device *dev, struct drm_display_mode *mode)
2435{
2436 struct drm_connector *connector;
2437
2438 list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
2439 drm_mode_detachmode(dev, connector, mode);
2440 }
2441 return 0;
2442}
2443EXPORT_SYMBOL(drm_mode_detachmode_crtc);
2444
2445/**
2446 * drm_fb_attachmode - Attach a user mode to an connector
2447 * @inode: inode from the ioctl
2448 * @filp: file * from the ioctl
2449 * @cmd: cmd from ioctl
2450 * @arg: arg from ioctl
2451 *
2452 * This attaches a user specified mode to an connector.
2453 * Called by the user via ioctl.
2454 *
2455 * RETURNS:
2456 * Zero on success, errno on failure.
2457 */
2458int drm_mode_attachmode_ioctl(struct drm_device *dev,
2459 void *data, struct drm_file *file_priv)
2460{
2461 struct drm_mode_mode_cmd *mode_cmd = data;
2462 struct drm_connector *connector;
2463 struct drm_display_mode *mode;
2464 struct drm_mode_object *obj;
2465 struct drm_mode_modeinfo *umode = &mode_cmd->mode;
2466 int ret = 0;
2467
Dave Airliefb3b06c2011-02-08 13:55:21 +10002468 if (!drm_core_check_feature(dev, DRIVER_MODESET))
2469 return -EINVAL;
2470
Dave Airlief453ba02008-11-07 14:05:41 -08002471 mutex_lock(&dev->mode_config.mutex);
2472
2473 obj = drm_mode_object_find(dev, mode_cmd->connector_id, DRM_MODE_OBJECT_CONNECTOR);
2474 if (!obj) {
2475 ret = -EINVAL;
2476 goto out;
2477 }
2478 connector = obj_to_connector(obj);
2479
2480 mode = drm_mode_create(dev);
2481 if (!mode) {
2482 ret = -ENOMEM;
2483 goto out;
2484 }
2485
2486 drm_crtc_convert_umode(mode, umode);
2487
Ville Syrjälä1dd6c8b2012-03-13 12:35:42 +02002488 drm_mode_attachmode(dev, connector, mode);
Dave Airlief453ba02008-11-07 14:05:41 -08002489out:
2490 mutex_unlock(&dev->mode_config.mutex);
2491 return ret;
2492}
2493
2494
2495/**
2496 * drm_fb_detachmode - Detach a user specified mode from 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 * Called by the user via ioctl.
2503 *
2504 * RETURNS:
2505 * Zero on success, errno on failure.
2506 */
2507int drm_mode_detachmode_ioctl(struct drm_device *dev,
2508 void *data, struct drm_file *file_priv)
2509{
2510 struct drm_mode_object *obj;
2511 struct drm_mode_mode_cmd *mode_cmd = data;
2512 struct drm_connector *connector;
2513 struct drm_display_mode mode;
2514 struct drm_mode_modeinfo *umode = &mode_cmd->mode;
2515 int ret = 0;
2516
Dave Airliefb3b06c2011-02-08 13:55:21 +10002517 if (!drm_core_check_feature(dev, DRIVER_MODESET))
2518 return -EINVAL;
2519
Dave Airlief453ba02008-11-07 14:05:41 -08002520 mutex_lock(&dev->mode_config.mutex);
2521
2522 obj = drm_mode_object_find(dev, mode_cmd->connector_id, DRM_MODE_OBJECT_CONNECTOR);
2523 if (!obj) {
2524 ret = -EINVAL;
2525 goto out;
2526 }
2527 connector = obj_to_connector(obj);
2528
2529 drm_crtc_convert_umode(&mode, umode);
2530 ret = drm_mode_detachmode(dev, connector, &mode);
2531out:
2532 mutex_unlock(&dev->mode_config.mutex);
2533 return ret;
2534}
2535
2536struct drm_property *drm_property_create(struct drm_device *dev, int flags,
2537 const char *name, int num_values)
2538{
2539 struct drm_property *property = NULL;
2540
2541 property = kzalloc(sizeof(struct drm_property), GFP_KERNEL);
2542 if (!property)
2543 return NULL;
2544
2545 if (num_values) {
2546 property->values = kzalloc(sizeof(uint64_t)*num_values, GFP_KERNEL);
2547 if (!property->values)
2548 goto fail;
2549 }
2550
2551 drm_mode_object_get(dev, &property->base, DRM_MODE_OBJECT_PROPERTY);
2552 property->flags = flags;
2553 property->num_values = num_values;
2554 INIT_LIST_HEAD(&property->enum_blob_list);
2555
Vinson Lee471dd2e2011-11-10 11:55:40 -08002556 if (name) {
Dave Airlief453ba02008-11-07 14:05:41 -08002557 strncpy(property->name, name, DRM_PROP_NAME_LEN);
Vinson Lee471dd2e2011-11-10 11:55:40 -08002558 property->name[DRM_PROP_NAME_LEN-1] = '\0';
2559 }
Dave Airlief453ba02008-11-07 14:05:41 -08002560
2561 list_add_tail(&property->head, &dev->mode_config.property_list);
2562 return property;
2563fail:
2564 kfree(property);
2565 return NULL;
2566}
2567EXPORT_SYMBOL(drm_property_create);
2568
Sascha Hauer4a67d392012-02-06 10:58:17 +01002569struct drm_property *drm_property_create_enum(struct drm_device *dev, int flags,
2570 const char *name,
2571 const struct drm_prop_enum_list *props,
2572 int num_values)
2573{
2574 struct drm_property *property;
2575 int i, ret;
2576
2577 flags |= DRM_MODE_PROP_ENUM;
2578
2579 property = drm_property_create(dev, flags, name, num_values);
2580 if (!property)
2581 return NULL;
2582
2583 for (i = 0; i < num_values; i++) {
2584 ret = drm_property_add_enum(property, i,
2585 props[i].type,
2586 props[i].name);
2587 if (ret) {
2588 drm_property_destroy(dev, property);
2589 return NULL;
2590 }
2591 }
2592
2593 return property;
2594}
2595EXPORT_SYMBOL(drm_property_create_enum);
2596
Sascha Hauerd9bc3c02012-02-06 10:58:18 +01002597struct drm_property *drm_property_create_range(struct drm_device *dev, int flags,
2598 const char *name,
2599 uint64_t min, uint64_t max)
2600{
2601 struct drm_property *property;
2602
2603 flags |= DRM_MODE_PROP_RANGE;
2604
2605 property = drm_property_create(dev, flags, name, 2);
2606 if (!property)
2607 return NULL;
2608
2609 property->values[0] = min;
2610 property->values[1] = max;
2611
2612 return property;
2613}
2614EXPORT_SYMBOL(drm_property_create_range);
2615
Dave Airlief453ba02008-11-07 14:05:41 -08002616int drm_property_add_enum(struct drm_property *property, int index,
2617 uint64_t value, const char *name)
2618{
2619 struct drm_property_enum *prop_enum;
2620
2621 if (!(property->flags & DRM_MODE_PROP_ENUM))
2622 return -EINVAL;
2623
2624 if (!list_empty(&property->enum_blob_list)) {
2625 list_for_each_entry(prop_enum, &property->enum_blob_list, head) {
2626 if (prop_enum->value == value) {
2627 strncpy(prop_enum->name, name, DRM_PROP_NAME_LEN);
2628 prop_enum->name[DRM_PROP_NAME_LEN-1] = '\0';
2629 return 0;
2630 }
2631 }
2632 }
2633
2634 prop_enum = kzalloc(sizeof(struct drm_property_enum), GFP_KERNEL);
2635 if (!prop_enum)
2636 return -ENOMEM;
2637
2638 strncpy(prop_enum->name, name, DRM_PROP_NAME_LEN);
2639 prop_enum->name[DRM_PROP_NAME_LEN-1] = '\0';
2640 prop_enum->value = value;
2641
2642 property->values[index] = value;
2643 list_add_tail(&prop_enum->head, &property->enum_blob_list);
2644 return 0;
2645}
2646EXPORT_SYMBOL(drm_property_add_enum);
2647
2648void drm_property_destroy(struct drm_device *dev, struct drm_property *property)
2649{
2650 struct drm_property_enum *prop_enum, *pt;
2651
2652 list_for_each_entry_safe(prop_enum, pt, &property->enum_blob_list, head) {
2653 list_del(&prop_enum->head);
2654 kfree(prop_enum);
2655 }
2656
2657 if (property->num_values)
2658 kfree(property->values);
2659 drm_mode_object_put(dev, &property->base);
2660 list_del(&property->head);
2661 kfree(property);
2662}
2663EXPORT_SYMBOL(drm_property_destroy);
2664
2665int drm_connector_attach_property(struct drm_connector *connector,
2666 struct drm_property *property, uint64_t init_val)
2667{
2668 int i;
2669
2670 for (i = 0; i < DRM_CONNECTOR_MAX_PROPERTY; i++) {
2671 if (connector->property_ids[i] == 0) {
2672 connector->property_ids[i] = property->base.id;
2673 connector->property_values[i] = init_val;
2674 break;
2675 }
2676 }
2677
2678 if (i == DRM_CONNECTOR_MAX_PROPERTY)
2679 return -EINVAL;
2680 return 0;
2681}
2682EXPORT_SYMBOL(drm_connector_attach_property);
2683
2684int drm_connector_property_set_value(struct drm_connector *connector,
2685 struct drm_property *property, uint64_t value)
2686{
2687 int i;
2688
2689 for (i = 0; i < DRM_CONNECTOR_MAX_PROPERTY; i++) {
2690 if (connector->property_ids[i] == property->base.id) {
2691 connector->property_values[i] = value;
2692 break;
2693 }
2694 }
2695
2696 if (i == DRM_CONNECTOR_MAX_PROPERTY)
2697 return -EINVAL;
2698 return 0;
2699}
2700EXPORT_SYMBOL(drm_connector_property_set_value);
2701
2702int drm_connector_property_get_value(struct drm_connector *connector,
2703 struct drm_property *property, uint64_t *val)
2704{
2705 int i;
2706
2707 for (i = 0; i < DRM_CONNECTOR_MAX_PROPERTY; i++) {
2708 if (connector->property_ids[i] == property->base.id) {
2709 *val = connector->property_values[i];
2710 break;
2711 }
2712 }
2713
2714 if (i == DRM_CONNECTOR_MAX_PROPERTY)
2715 return -EINVAL;
2716 return 0;
2717}
2718EXPORT_SYMBOL(drm_connector_property_get_value);
2719
2720int drm_mode_getproperty_ioctl(struct drm_device *dev,
2721 void *data, struct drm_file *file_priv)
2722{
2723 struct drm_mode_object *obj;
2724 struct drm_mode_get_property *out_resp = data;
2725 struct drm_property *property;
2726 int enum_count = 0;
2727 int blob_count = 0;
2728 int value_count = 0;
2729 int ret = 0, i;
2730 int copied;
2731 struct drm_property_enum *prop_enum;
2732 struct drm_mode_property_enum __user *enum_ptr;
2733 struct drm_property_blob *prop_blob;
Ville Syrjälä81f6c7f2011-12-20 00:06:42 +02002734 uint32_t __user *blob_id_ptr;
Dave Airlief453ba02008-11-07 14:05:41 -08002735 uint64_t __user *values_ptr;
2736 uint32_t __user *blob_length_ptr;
2737
Dave Airliefb3b06c2011-02-08 13:55:21 +10002738 if (!drm_core_check_feature(dev, DRIVER_MODESET))
2739 return -EINVAL;
2740
Dave Airlief453ba02008-11-07 14:05:41 -08002741 mutex_lock(&dev->mode_config.mutex);
2742 obj = drm_mode_object_find(dev, out_resp->prop_id, DRM_MODE_OBJECT_PROPERTY);
2743 if (!obj) {
2744 ret = -EINVAL;
2745 goto done;
2746 }
2747 property = obj_to_property(obj);
2748
2749 if (property->flags & DRM_MODE_PROP_ENUM) {
2750 list_for_each_entry(prop_enum, &property->enum_blob_list, head)
2751 enum_count++;
2752 } else if (property->flags & DRM_MODE_PROP_BLOB) {
2753 list_for_each_entry(prop_blob, &property->enum_blob_list, head)
2754 blob_count++;
2755 }
2756
2757 value_count = property->num_values;
2758
2759 strncpy(out_resp->name, property->name, DRM_PROP_NAME_LEN);
2760 out_resp->name[DRM_PROP_NAME_LEN-1] = 0;
2761 out_resp->flags = property->flags;
2762
2763 if ((out_resp->count_values >= value_count) && value_count) {
Ville Syrjälä81f6c7f2011-12-20 00:06:42 +02002764 values_ptr = (uint64_t __user *)(unsigned long)out_resp->values_ptr;
Dave Airlief453ba02008-11-07 14:05:41 -08002765 for (i = 0; i < value_count; i++) {
2766 if (copy_to_user(values_ptr + i, &property->values[i], sizeof(uint64_t))) {
2767 ret = -EFAULT;
2768 goto done;
2769 }
2770 }
2771 }
2772 out_resp->count_values = value_count;
2773
2774 if (property->flags & DRM_MODE_PROP_ENUM) {
2775 if ((out_resp->count_enum_blobs >= enum_count) && enum_count) {
2776 copied = 0;
Ville Syrjälä81f6c7f2011-12-20 00:06:42 +02002777 enum_ptr = (struct drm_mode_property_enum __user *)(unsigned long)out_resp->enum_blob_ptr;
Dave Airlief453ba02008-11-07 14:05:41 -08002778 list_for_each_entry(prop_enum, &property->enum_blob_list, head) {
2779
2780 if (copy_to_user(&enum_ptr[copied].value, &prop_enum->value, sizeof(uint64_t))) {
2781 ret = -EFAULT;
2782 goto done;
2783 }
2784
2785 if (copy_to_user(&enum_ptr[copied].name,
2786 &prop_enum->name, DRM_PROP_NAME_LEN)) {
2787 ret = -EFAULT;
2788 goto done;
2789 }
2790 copied++;
2791 }
2792 }
2793 out_resp->count_enum_blobs = enum_count;
2794 }
2795
2796 if (property->flags & DRM_MODE_PROP_BLOB) {
2797 if ((out_resp->count_enum_blobs >= blob_count) && blob_count) {
2798 copied = 0;
Ville Syrjälä81f6c7f2011-12-20 00:06:42 +02002799 blob_id_ptr = (uint32_t __user *)(unsigned long)out_resp->enum_blob_ptr;
2800 blob_length_ptr = (uint32_t __user *)(unsigned long)out_resp->values_ptr;
Dave Airlief453ba02008-11-07 14:05:41 -08002801
2802 list_for_each_entry(prop_blob, &property->enum_blob_list, head) {
2803 if (put_user(prop_blob->base.id, blob_id_ptr + copied)) {
2804 ret = -EFAULT;
2805 goto done;
2806 }
2807
2808 if (put_user(prop_blob->length, blob_length_ptr + copied)) {
2809 ret = -EFAULT;
2810 goto done;
2811 }
2812
2813 copied++;
2814 }
2815 }
2816 out_resp->count_enum_blobs = blob_count;
2817 }
2818done:
2819 mutex_unlock(&dev->mode_config.mutex);
2820 return ret;
2821}
2822
2823static struct drm_property_blob *drm_property_create_blob(struct drm_device *dev, int length,
2824 void *data)
2825{
2826 struct drm_property_blob *blob;
2827
2828 if (!length || !data)
2829 return NULL;
2830
2831 blob = kzalloc(sizeof(struct drm_property_blob)+length, GFP_KERNEL);
2832 if (!blob)
2833 return NULL;
2834
2835 blob->data = (void *)((char *)blob + sizeof(struct drm_property_blob));
2836 blob->length = length;
2837
2838 memcpy(blob->data, data, length);
2839
2840 drm_mode_object_get(dev, &blob->base, DRM_MODE_OBJECT_BLOB);
2841
2842 list_add_tail(&blob->head, &dev->mode_config.property_blob_list);
2843 return blob;
2844}
2845
2846static void drm_property_destroy_blob(struct drm_device *dev,
2847 struct drm_property_blob *blob)
2848{
2849 drm_mode_object_put(dev, &blob->base);
2850 list_del(&blob->head);
2851 kfree(blob);
2852}
2853
2854int drm_mode_getblob_ioctl(struct drm_device *dev,
2855 void *data, struct drm_file *file_priv)
2856{
2857 struct drm_mode_object *obj;
2858 struct drm_mode_get_blob *out_resp = data;
2859 struct drm_property_blob *blob;
2860 int ret = 0;
Ville Syrjälä81f6c7f2011-12-20 00:06:42 +02002861 void __user *blob_ptr;
Dave Airlief453ba02008-11-07 14:05:41 -08002862
Dave Airliefb3b06c2011-02-08 13:55:21 +10002863 if (!drm_core_check_feature(dev, DRIVER_MODESET))
2864 return -EINVAL;
2865
Dave Airlief453ba02008-11-07 14:05:41 -08002866 mutex_lock(&dev->mode_config.mutex);
2867 obj = drm_mode_object_find(dev, out_resp->blob_id, DRM_MODE_OBJECT_BLOB);
2868 if (!obj) {
2869 ret = -EINVAL;
2870 goto done;
2871 }
2872 blob = obj_to_blob(obj);
2873
2874 if (out_resp->length == blob->length) {
Ville Syrjälä81f6c7f2011-12-20 00:06:42 +02002875 blob_ptr = (void __user *)(unsigned long)out_resp->data;
Dave Airlief453ba02008-11-07 14:05:41 -08002876 if (copy_to_user(blob_ptr, blob->data, blob->length)){
2877 ret = -EFAULT;
2878 goto done;
2879 }
2880 }
2881 out_resp->length = blob->length;
2882
2883done:
2884 mutex_unlock(&dev->mode_config.mutex);
2885 return ret;
2886}
2887
2888int drm_mode_connector_update_edid_property(struct drm_connector *connector,
2889 struct edid *edid)
2890{
2891 struct drm_device *dev = connector->dev;
Adam Jackson7466f4c2010-03-29 21:43:23 +00002892 int ret = 0, size;
Dave Airlief453ba02008-11-07 14:05:41 -08002893
2894 if (connector->edid_blob_ptr)
2895 drm_property_destroy_blob(dev, connector->edid_blob_ptr);
2896
2897 /* Delete edid, when there is none. */
2898 if (!edid) {
2899 connector->edid_blob_ptr = NULL;
2900 ret = drm_connector_property_set_value(connector, dev->mode_config.edid_property, 0);
2901 return ret;
2902 }
2903
Adam Jackson7466f4c2010-03-29 21:43:23 +00002904 size = EDID_LENGTH * (1 + edid->extensions);
2905 connector->edid_blob_ptr = drm_property_create_blob(connector->dev,
2906 size, edid);
Dave Airlief453ba02008-11-07 14:05:41 -08002907
2908 ret = drm_connector_property_set_value(connector,
2909 dev->mode_config.edid_property,
2910 connector->edid_blob_ptr->base.id);
2911
2912 return ret;
2913}
2914EXPORT_SYMBOL(drm_mode_connector_update_edid_property);
2915
2916int drm_mode_connector_property_set_ioctl(struct drm_device *dev,
2917 void *data, struct drm_file *file_priv)
2918{
2919 struct drm_mode_connector_set_property *out_resp = data;
2920 struct drm_mode_object *obj;
2921 struct drm_property *property;
2922 struct drm_connector *connector;
2923 int ret = -EINVAL;
2924 int i;
2925
Dave Airliefb3b06c2011-02-08 13:55:21 +10002926 if (!drm_core_check_feature(dev, DRIVER_MODESET))
2927 return -EINVAL;
2928
Dave Airlief453ba02008-11-07 14:05:41 -08002929 mutex_lock(&dev->mode_config.mutex);
2930
2931 obj = drm_mode_object_find(dev, out_resp->connector_id, DRM_MODE_OBJECT_CONNECTOR);
2932 if (!obj) {
2933 goto out;
2934 }
2935 connector = obj_to_connector(obj);
2936
2937 for (i = 0; i < DRM_CONNECTOR_MAX_PROPERTY; i++) {
2938 if (connector->property_ids[i] == out_resp->prop_id)
2939 break;
2940 }
2941
2942 if (i == DRM_CONNECTOR_MAX_PROPERTY) {
2943 goto out;
2944 }
2945
2946 obj = drm_mode_object_find(dev, out_resp->prop_id, DRM_MODE_OBJECT_PROPERTY);
2947 if (!obj) {
2948 goto out;
2949 }
2950 property = obj_to_property(obj);
2951
2952 if (property->flags & DRM_MODE_PROP_IMMUTABLE)
2953 goto out;
2954
2955 if (property->flags & DRM_MODE_PROP_RANGE) {
2956 if (out_resp->value < property->values[0])
2957 goto out;
2958
2959 if (out_resp->value > property->values[1])
2960 goto out;
2961 } else {
2962 int found = 0;
2963 for (i = 0; i < property->num_values; i++) {
2964 if (property->values[i] == out_resp->value) {
2965 found = 1;
2966 break;
2967 }
2968 }
2969 if (!found) {
2970 goto out;
2971 }
2972 }
2973
Keith Packardc9fb15f2009-05-30 20:42:28 -07002974 /* Do DPMS ourselves */
2975 if (property == connector->dev->mode_config.dpms_property) {
2976 if (connector->funcs->dpms)
2977 (*connector->funcs->dpms)(connector, (int) out_resp->value);
2978 ret = 0;
2979 } else if (connector->funcs->set_property)
Dave Airlief453ba02008-11-07 14:05:41 -08002980 ret = connector->funcs->set_property(connector, property, out_resp->value);
2981
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02002982 /* store the property value if successful */
Dave Airlief453ba02008-11-07 14:05:41 -08002983 if (!ret)
2984 drm_connector_property_set_value(connector, property, out_resp->value);
2985out:
2986 mutex_unlock(&dev->mode_config.mutex);
2987 return ret;
2988}
2989
Dave Airlief453ba02008-11-07 14:05:41 -08002990int drm_mode_connector_attach_encoder(struct drm_connector *connector,
2991 struct drm_encoder *encoder)
2992{
2993 int i;
2994
2995 for (i = 0; i < DRM_CONNECTOR_MAX_ENCODER; i++) {
2996 if (connector->encoder_ids[i] == 0) {
2997 connector->encoder_ids[i] = encoder->base.id;
2998 return 0;
2999 }
3000 }
3001 return -ENOMEM;
3002}
3003EXPORT_SYMBOL(drm_mode_connector_attach_encoder);
3004
3005void drm_mode_connector_detach_encoder(struct drm_connector *connector,
3006 struct drm_encoder *encoder)
3007{
3008 int i;
3009 for (i = 0; i < DRM_CONNECTOR_MAX_ENCODER; i++) {
3010 if (connector->encoder_ids[i] == encoder->base.id) {
3011 connector->encoder_ids[i] = 0;
3012 if (connector->encoder == encoder)
3013 connector->encoder = NULL;
3014 break;
3015 }
3016 }
3017}
3018EXPORT_SYMBOL(drm_mode_connector_detach_encoder);
3019
Sascha Hauer4cae5b82012-02-01 11:38:23 +01003020int drm_mode_crtc_set_gamma_size(struct drm_crtc *crtc,
Dave Airlief453ba02008-11-07 14:05:41 -08003021 int gamma_size)
3022{
3023 crtc->gamma_size = gamma_size;
3024
3025 crtc->gamma_store = kzalloc(gamma_size * sizeof(uint16_t) * 3, GFP_KERNEL);
3026 if (!crtc->gamma_store) {
3027 crtc->gamma_size = 0;
Sascha Hauer4cae5b82012-02-01 11:38:23 +01003028 return -ENOMEM;
Dave Airlief453ba02008-11-07 14:05:41 -08003029 }
3030
Sascha Hauer4cae5b82012-02-01 11:38:23 +01003031 return 0;
Dave Airlief453ba02008-11-07 14:05:41 -08003032}
3033EXPORT_SYMBOL(drm_mode_crtc_set_gamma_size);
3034
3035int drm_mode_gamma_set_ioctl(struct drm_device *dev,
3036 void *data, struct drm_file *file_priv)
3037{
3038 struct drm_mode_crtc_lut *crtc_lut = data;
3039 struct drm_mode_object *obj;
3040 struct drm_crtc *crtc;
3041 void *r_base, *g_base, *b_base;
3042 int size;
3043 int ret = 0;
3044
Dave Airliefb3b06c2011-02-08 13:55:21 +10003045 if (!drm_core_check_feature(dev, DRIVER_MODESET))
3046 return -EINVAL;
3047
Dave Airlief453ba02008-11-07 14:05:41 -08003048 mutex_lock(&dev->mode_config.mutex);
3049 obj = drm_mode_object_find(dev, crtc_lut->crtc_id, DRM_MODE_OBJECT_CRTC);
3050 if (!obj) {
3051 ret = -EINVAL;
3052 goto out;
3053 }
3054 crtc = obj_to_crtc(obj);
3055
3056 /* memcpy into gamma store */
3057 if (crtc_lut->gamma_size != crtc->gamma_size) {
3058 ret = -EINVAL;
3059 goto out;
3060 }
3061
3062 size = crtc_lut->gamma_size * (sizeof(uint16_t));
3063 r_base = crtc->gamma_store;
3064 if (copy_from_user(r_base, (void __user *)(unsigned long)crtc_lut->red, size)) {
3065 ret = -EFAULT;
3066 goto out;
3067 }
3068
3069 g_base = r_base + size;
3070 if (copy_from_user(g_base, (void __user *)(unsigned long)crtc_lut->green, size)) {
3071 ret = -EFAULT;
3072 goto out;
3073 }
3074
3075 b_base = g_base + size;
3076 if (copy_from_user(b_base, (void __user *)(unsigned long)crtc_lut->blue, size)) {
3077 ret = -EFAULT;
3078 goto out;
3079 }
3080
James Simmons72034252010-08-03 01:33:19 +01003081 crtc->funcs->gamma_set(crtc, r_base, g_base, b_base, 0, crtc->gamma_size);
Dave Airlief453ba02008-11-07 14:05:41 -08003082
3083out:
3084 mutex_unlock(&dev->mode_config.mutex);
3085 return ret;
3086
3087}
3088
3089int drm_mode_gamma_get_ioctl(struct drm_device *dev,
3090 void *data, struct drm_file *file_priv)
3091{
3092 struct drm_mode_crtc_lut *crtc_lut = data;
3093 struct drm_mode_object *obj;
3094 struct drm_crtc *crtc;
3095 void *r_base, *g_base, *b_base;
3096 int size;
3097 int ret = 0;
3098
Dave Airliefb3b06c2011-02-08 13:55:21 +10003099 if (!drm_core_check_feature(dev, DRIVER_MODESET))
3100 return -EINVAL;
3101
Dave Airlief453ba02008-11-07 14:05:41 -08003102 mutex_lock(&dev->mode_config.mutex);
3103 obj = drm_mode_object_find(dev, crtc_lut->crtc_id, DRM_MODE_OBJECT_CRTC);
3104 if (!obj) {
3105 ret = -EINVAL;
3106 goto out;
3107 }
3108 crtc = obj_to_crtc(obj);
3109
3110 /* memcpy into gamma store */
3111 if (crtc_lut->gamma_size != crtc->gamma_size) {
3112 ret = -EINVAL;
3113 goto out;
3114 }
3115
3116 size = crtc_lut->gamma_size * (sizeof(uint16_t));
3117 r_base = crtc->gamma_store;
3118 if (copy_to_user((void __user *)(unsigned long)crtc_lut->red, r_base, size)) {
3119 ret = -EFAULT;
3120 goto out;
3121 }
3122
3123 g_base = r_base + size;
3124 if (copy_to_user((void __user *)(unsigned long)crtc_lut->green, g_base, size)) {
3125 ret = -EFAULT;
3126 goto out;
3127 }
3128
3129 b_base = g_base + size;
3130 if (copy_to_user((void __user *)(unsigned long)crtc_lut->blue, b_base, size)) {
3131 ret = -EFAULT;
3132 goto out;
3133 }
3134out:
3135 mutex_unlock(&dev->mode_config.mutex);
3136 return ret;
3137}
Kristian Høgsbergd91d8a32009-11-17 12:43:55 -05003138
3139int drm_mode_page_flip_ioctl(struct drm_device *dev,
3140 void *data, struct drm_file *file_priv)
3141{
3142 struct drm_mode_crtc_page_flip *page_flip = data;
3143 struct drm_mode_object *obj;
3144 struct drm_crtc *crtc;
3145 struct drm_framebuffer *fb;
3146 struct drm_pending_vblank_event *e = NULL;
3147 unsigned long flags;
3148 int ret = -EINVAL;
3149
3150 if (page_flip->flags & ~DRM_MODE_PAGE_FLIP_FLAGS ||
3151 page_flip->reserved != 0)
3152 return -EINVAL;
3153
3154 mutex_lock(&dev->mode_config.mutex);
3155 obj = drm_mode_object_find(dev, page_flip->crtc_id, DRM_MODE_OBJECT_CRTC);
3156 if (!obj)
3157 goto out;
3158 crtc = obj_to_crtc(obj);
3159
Chris Wilson90c1efd2010-07-17 20:23:26 +01003160 if (crtc->fb == NULL) {
3161 /* The framebuffer is currently unbound, presumably
3162 * due to a hotplug event, that userspace has not
3163 * yet discovered.
3164 */
3165 ret = -EBUSY;
3166 goto out;
3167 }
3168
Kristian Høgsbergd91d8a32009-11-17 12:43:55 -05003169 if (crtc->funcs->page_flip == NULL)
3170 goto out;
3171
3172 obj = drm_mode_object_find(dev, page_flip->fb_id, DRM_MODE_OBJECT_FB);
3173 if (!obj)
3174 goto out;
3175 fb = obj_to_fb(obj);
3176
3177 if (page_flip->flags & DRM_MODE_PAGE_FLIP_EVENT) {
3178 ret = -ENOMEM;
3179 spin_lock_irqsave(&dev->event_lock, flags);
3180 if (file_priv->event_space < sizeof e->event) {
3181 spin_unlock_irqrestore(&dev->event_lock, flags);
3182 goto out;
3183 }
3184 file_priv->event_space -= sizeof e->event;
3185 spin_unlock_irqrestore(&dev->event_lock, flags);
3186
3187 e = kzalloc(sizeof *e, GFP_KERNEL);
3188 if (e == NULL) {
3189 spin_lock_irqsave(&dev->event_lock, flags);
3190 file_priv->event_space += sizeof e->event;
3191 spin_unlock_irqrestore(&dev->event_lock, flags);
3192 goto out;
3193 }
3194
Jesse Barnes7bd4d7b2009-11-19 10:50:22 -08003195 e->event.base.type = DRM_EVENT_FLIP_COMPLETE;
Kristian Høgsbergd91d8a32009-11-17 12:43:55 -05003196 e->event.base.length = sizeof e->event;
3197 e->event.user_data = page_flip->user_data;
3198 e->base.event = &e->event.base;
3199 e->base.file_priv = file_priv;
3200 e->base.destroy =
3201 (void (*) (struct drm_pending_event *)) kfree;
3202 }
3203
3204 ret = crtc->funcs->page_flip(crtc, fb, e);
3205 if (ret) {
3206 spin_lock_irqsave(&dev->event_lock, flags);
3207 file_priv->event_space += sizeof e->event;
3208 spin_unlock_irqrestore(&dev->event_lock, flags);
3209 kfree(e);
3210 }
3211
3212out:
3213 mutex_unlock(&dev->mode_config.mutex);
3214 return ret;
3215}
Chris Wilsoneb033552011-01-24 15:11:08 +00003216
3217void drm_mode_config_reset(struct drm_device *dev)
3218{
3219 struct drm_crtc *crtc;
3220 struct drm_encoder *encoder;
3221 struct drm_connector *connector;
3222
3223 list_for_each_entry(crtc, &dev->mode_config.crtc_list, head)
3224 if (crtc->funcs->reset)
3225 crtc->funcs->reset(crtc);
3226
3227 list_for_each_entry(encoder, &dev->mode_config.encoder_list, head)
3228 if (encoder->funcs->reset)
3229 encoder->funcs->reset(encoder);
3230
3231 list_for_each_entry(connector, &dev->mode_config.connector_list, head)
3232 if (connector->funcs->reset)
3233 connector->funcs->reset(connector);
3234}
3235EXPORT_SYMBOL(drm_mode_config_reset);
Dave Airlieff72145b2011-02-07 12:16:14 +10003236
3237int drm_mode_create_dumb_ioctl(struct drm_device *dev,
3238 void *data, struct drm_file *file_priv)
3239{
3240 struct drm_mode_create_dumb *args = data;
3241
3242 if (!dev->driver->dumb_create)
3243 return -ENOSYS;
3244 return dev->driver->dumb_create(file_priv, dev, args);
3245}
3246
3247int drm_mode_mmap_dumb_ioctl(struct drm_device *dev,
3248 void *data, struct drm_file *file_priv)
3249{
3250 struct drm_mode_map_dumb *args = data;
3251
3252 /* call driver ioctl to get mmap offset */
3253 if (!dev->driver->dumb_map_offset)
3254 return -ENOSYS;
3255
3256 return dev->driver->dumb_map_offset(file_priv, dev, args->handle, &args->offset);
3257}
3258
3259int drm_mode_destroy_dumb_ioctl(struct drm_device *dev,
3260 void *data, struct drm_file *file_priv)
3261{
3262 struct drm_mode_destroy_dumb *args = data;
3263
3264 if (!dev->driver->dumb_destroy)
3265 return -ENOSYS;
3266
3267 return dev->driver->dumb_destroy(file_priv, dev, args->handle);
3268}
Dave Airlie248dbc22011-11-29 20:02:54 +00003269
3270/*
3271 * Just need to support RGB formats here for compat with code that doesn't
3272 * use pixel formats directly yet.
3273 */
3274void drm_fb_get_bpp_depth(uint32_t format, unsigned int *depth,
3275 int *bpp)
3276{
3277 switch (format) {
Ville Syrjälä04b39242011-11-17 18:05:13 +02003278 case DRM_FORMAT_RGB332:
3279 case DRM_FORMAT_BGR233:
Dave Airlie248dbc22011-11-29 20:02:54 +00003280 *depth = 8;
3281 *bpp = 8;
3282 break;
Ville Syrjälä04b39242011-11-17 18:05:13 +02003283 case DRM_FORMAT_XRGB1555:
3284 case DRM_FORMAT_XBGR1555:
3285 case DRM_FORMAT_RGBX5551:
3286 case DRM_FORMAT_BGRX5551:
3287 case DRM_FORMAT_ARGB1555:
3288 case DRM_FORMAT_ABGR1555:
3289 case DRM_FORMAT_RGBA5551:
3290 case DRM_FORMAT_BGRA5551:
Dave Airlie248dbc22011-11-29 20:02:54 +00003291 *depth = 15;
3292 *bpp = 16;
3293 break;
Ville Syrjälä04b39242011-11-17 18:05:13 +02003294 case DRM_FORMAT_RGB565:
3295 case DRM_FORMAT_BGR565:
Dave Airlie248dbc22011-11-29 20:02:54 +00003296 *depth = 16;
3297 *bpp = 16;
3298 break;
Ville Syrjälä04b39242011-11-17 18:05:13 +02003299 case DRM_FORMAT_RGB888:
3300 case DRM_FORMAT_BGR888:
3301 *depth = 24;
3302 *bpp = 24;
3303 break;
3304 case DRM_FORMAT_XRGB8888:
3305 case DRM_FORMAT_XBGR8888:
3306 case DRM_FORMAT_RGBX8888:
3307 case DRM_FORMAT_BGRX8888:
Dave Airlie248dbc22011-11-29 20:02:54 +00003308 *depth = 24;
3309 *bpp = 32;
3310 break;
Ville Syrjälä04b39242011-11-17 18:05:13 +02003311 case DRM_FORMAT_XRGB2101010:
3312 case DRM_FORMAT_XBGR2101010:
3313 case DRM_FORMAT_RGBX1010102:
3314 case DRM_FORMAT_BGRX1010102:
3315 case DRM_FORMAT_ARGB2101010:
3316 case DRM_FORMAT_ABGR2101010:
3317 case DRM_FORMAT_RGBA1010102:
3318 case DRM_FORMAT_BGRA1010102:
Dave Airlie248dbc22011-11-29 20:02:54 +00003319 *depth = 30;
3320 *bpp = 32;
3321 break;
Ville Syrjälä04b39242011-11-17 18:05:13 +02003322 case DRM_FORMAT_ARGB8888:
3323 case DRM_FORMAT_ABGR8888:
3324 case DRM_FORMAT_RGBA8888:
3325 case DRM_FORMAT_BGRA8888:
Dave Airlie248dbc22011-11-29 20:02:54 +00003326 *depth = 32;
3327 *bpp = 32;
3328 break;
3329 default:
3330 DRM_DEBUG_KMS("unsupported pixel format\n");
3331 *depth = 0;
3332 *bpp = 0;
3333 break;
3334 }
3335}
3336EXPORT_SYMBOL(drm_fb_get_bpp_depth);