2 * Copyright (c) 2006-2008 Intel Corporation
3 * Copyright (c) 2007 Dave Airlie <airlied@linux.ie>
4 * Copyright (c) 2008 Red Hat Inc.
6 * DRM core CRTC related functions
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.
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
28 * Eric Anholt <eric@anholt.net>
29 * Dave Airlie <airlied@linux.ie>
30 * Jesse Barnes <jesse.barnes@intel.com>
32 #include <linux/list.h>
33 #include <linux/slab.h>
34 #include <linux/export.h>
39 #include "drm_fourcc.h"
41 struct drm_prop_enum_list
{
46 /* Avoid boilerplate. I'm tired of typing. */
47 #define DRM_ENUM_NAME_FN(fnname, list) \
48 char *fnname(int val) \
51 for (i = 0; i < ARRAY_SIZE(list); i++) { \
52 if (list[i].type == val) \
53 return list[i].name; \
61 static struct drm_prop_enum_list drm_dpms_enum_list
[] =
62 { { DRM_MODE_DPMS_ON
, "On" },
63 { DRM_MODE_DPMS_STANDBY
, "Standby" },
64 { DRM_MODE_DPMS_SUSPEND
, "Suspend" },
65 { DRM_MODE_DPMS_OFF
, "Off" }
68 DRM_ENUM_NAME_FN(drm_get_dpms_name
, drm_dpms_enum_list
)
73 static struct drm_prop_enum_list drm_scaling_mode_enum_list
[] =
75 { DRM_MODE_SCALE_NONE
, "None" },
76 { DRM_MODE_SCALE_FULLSCREEN
, "Full" },
77 { DRM_MODE_SCALE_CENTER
, "Center" },
78 { DRM_MODE_SCALE_ASPECT
, "Full aspect" },
81 static struct drm_prop_enum_list drm_dithering_mode_enum_list
[] =
83 { DRM_MODE_DITHERING_OFF
, "Off" },
84 { DRM_MODE_DITHERING_ON
, "On" },
85 { DRM_MODE_DITHERING_AUTO
, "Automatic" },
89 * Non-global properties, but "required" for certain connectors.
91 static struct drm_prop_enum_list drm_dvi_i_select_enum_list
[] =
93 { DRM_MODE_SUBCONNECTOR_Automatic
, "Automatic" }, /* DVI-I and TV-out */
94 { DRM_MODE_SUBCONNECTOR_DVID
, "DVI-D" }, /* DVI-I */
95 { DRM_MODE_SUBCONNECTOR_DVIA
, "DVI-A" }, /* DVI-I */
98 DRM_ENUM_NAME_FN(drm_get_dvi_i_select_name
, drm_dvi_i_select_enum_list
)
100 static struct drm_prop_enum_list drm_dvi_i_subconnector_enum_list
[] =
102 { DRM_MODE_SUBCONNECTOR_Unknown
, "Unknown" }, /* DVI-I and TV-out */
103 { DRM_MODE_SUBCONNECTOR_DVID
, "DVI-D" }, /* DVI-I */
104 { DRM_MODE_SUBCONNECTOR_DVIA
, "DVI-A" }, /* DVI-I */
107 DRM_ENUM_NAME_FN(drm_get_dvi_i_subconnector_name
,
108 drm_dvi_i_subconnector_enum_list
)
110 static struct drm_prop_enum_list drm_tv_select_enum_list
[] =
112 { DRM_MODE_SUBCONNECTOR_Automatic
, "Automatic" }, /* DVI-I and TV-out */
113 { DRM_MODE_SUBCONNECTOR_Composite
, "Composite" }, /* TV-out */
114 { DRM_MODE_SUBCONNECTOR_SVIDEO
, "SVIDEO" }, /* TV-out */
115 { DRM_MODE_SUBCONNECTOR_Component
, "Component" }, /* TV-out */
116 { DRM_MODE_SUBCONNECTOR_SCART
, "SCART" }, /* TV-out */
119 DRM_ENUM_NAME_FN(drm_get_tv_select_name
, drm_tv_select_enum_list
)
121 static struct drm_prop_enum_list drm_tv_subconnector_enum_list
[] =
123 { DRM_MODE_SUBCONNECTOR_Unknown
, "Unknown" }, /* DVI-I and TV-out */
124 { DRM_MODE_SUBCONNECTOR_Composite
, "Composite" }, /* TV-out */
125 { DRM_MODE_SUBCONNECTOR_SVIDEO
, "SVIDEO" }, /* TV-out */
126 { DRM_MODE_SUBCONNECTOR_Component
, "Component" }, /* TV-out */
127 { DRM_MODE_SUBCONNECTOR_SCART
, "SCART" }, /* TV-out */
130 DRM_ENUM_NAME_FN(drm_get_tv_subconnector_name
,
131 drm_tv_subconnector_enum_list
)
133 static struct drm_prop_enum_list drm_dirty_info_enum_list
[] = {
134 { DRM_MODE_DIRTY_OFF
, "Off" },
135 { DRM_MODE_DIRTY_ON
, "On" },
136 { DRM_MODE_DIRTY_ANNOTATE
, "Annotate" },
139 DRM_ENUM_NAME_FN(drm_get_dirty_info_name
,
140 drm_dirty_info_enum_list
)
142 struct drm_conn_prop_enum_list
{
149 * Connector and encoder types.
151 static struct drm_conn_prop_enum_list drm_connector_enum_list
[] =
152 { { DRM_MODE_CONNECTOR_Unknown
, "Unknown", 0 },
153 { DRM_MODE_CONNECTOR_VGA
, "VGA", 0 },
154 { DRM_MODE_CONNECTOR_DVII
, "DVI-I", 0 },
155 { DRM_MODE_CONNECTOR_DVID
, "DVI-D", 0 },
156 { DRM_MODE_CONNECTOR_DVIA
, "DVI-A", 0 },
157 { DRM_MODE_CONNECTOR_Composite
, "Composite", 0 },
158 { DRM_MODE_CONNECTOR_SVIDEO
, "SVIDEO", 0 },
159 { DRM_MODE_CONNECTOR_LVDS
, "LVDS", 0 },
160 { DRM_MODE_CONNECTOR_Component
, "Component", 0 },
161 { DRM_MODE_CONNECTOR_9PinDIN
, "DIN", 0 },
162 { DRM_MODE_CONNECTOR_DisplayPort
, "DP", 0 },
163 { DRM_MODE_CONNECTOR_HDMIA
, "HDMI-A", 0 },
164 { DRM_MODE_CONNECTOR_HDMIB
, "HDMI-B", 0 },
165 { DRM_MODE_CONNECTOR_TV
, "TV", 0 },
166 { DRM_MODE_CONNECTOR_eDP
, "eDP", 0 },
167 { DRM_MODE_CONNECTOR_VIRTUAL
, "Virtual", 0},
170 static struct drm_prop_enum_list drm_encoder_enum_list
[] =
171 { { DRM_MODE_ENCODER_NONE
, "None" },
172 { DRM_MODE_ENCODER_DAC
, "DAC" },
173 { DRM_MODE_ENCODER_TMDS
, "TMDS" },
174 { DRM_MODE_ENCODER_LVDS
, "LVDS" },
175 { DRM_MODE_ENCODER_TVDAC
, "TV" },
176 { DRM_MODE_ENCODER_VIRTUAL
, "Virtual" },
179 char *drm_get_encoder_name(struct drm_encoder
*encoder
)
183 snprintf(buf
, 32, "%s-%d",
184 drm_encoder_enum_list
[encoder
->encoder_type
].name
,
188 EXPORT_SYMBOL(drm_get_encoder_name
);
190 char *drm_get_connector_name(struct drm_connector
*connector
)
194 snprintf(buf
, 32, "%s-%d",
195 drm_connector_enum_list
[connector
->connector_type
].name
,
196 connector
->connector_type_id
);
199 EXPORT_SYMBOL(drm_get_connector_name
);
201 char *drm_get_connector_status_name(enum drm_connector_status status
)
203 if (status
== connector_status_connected
)
205 else if (status
== connector_status_disconnected
)
206 return "disconnected";
212 * drm_mode_object_get - allocate a new identifier
214 * @ptr: object pointer, used to generate unique ID
219 * Create a unique identifier based on @ptr in @dev's identifier space. Used
220 * for tracking modes, CRTCs and connectors.
223 * New unique (relative to other objects in @dev) integer identifier for the
226 static int drm_mode_object_get(struct drm_device
*dev
,
227 struct drm_mode_object
*obj
, uint32_t obj_type
)
233 if (idr_pre_get(&dev
->mode_config
.crtc_idr
, GFP_KERNEL
) == 0) {
234 DRM_ERROR("Ran out memory getting a mode number\n");
238 mutex_lock(&dev
->mode_config
.idr_mutex
);
239 ret
= idr_get_new_above(&dev
->mode_config
.crtc_idr
, obj
, 1, &new_id
);
240 mutex_unlock(&dev
->mode_config
.idr_mutex
);
245 obj
->type
= obj_type
;
250 * drm_mode_object_put - free an identifer
255 * Caller must hold DRM mode_config lock.
257 * Free @id from @dev's unique identifier pool.
259 static void drm_mode_object_put(struct drm_device
*dev
,
260 struct drm_mode_object
*object
)
262 mutex_lock(&dev
->mode_config
.idr_mutex
);
263 idr_remove(&dev
->mode_config
.crtc_idr
, object
->id
);
264 mutex_unlock(&dev
->mode_config
.idr_mutex
);
267 struct drm_mode_object
*drm_mode_object_find(struct drm_device
*dev
,
268 uint32_t id
, uint32_t type
)
270 struct drm_mode_object
*obj
= NULL
;
272 mutex_lock(&dev
->mode_config
.idr_mutex
);
273 obj
= idr_find(&dev
->mode_config
.crtc_idr
, id
);
274 if (!obj
|| (obj
->type
!= type
) || (obj
->id
!= id
))
276 mutex_unlock(&dev
->mode_config
.idr_mutex
);
280 EXPORT_SYMBOL(drm_mode_object_find
);
283 * drm_framebuffer_init - initialize a framebuffer
287 * Caller must hold mode config lock.
289 * Allocates an ID for the framebuffer's parent mode object, sets its mode
290 * functions & device file and adds it to the master fd list.
293 * Zero on success, error code on failure.
295 int drm_framebuffer_init(struct drm_device
*dev
, struct drm_framebuffer
*fb
,
296 const struct drm_framebuffer_funcs
*funcs
)
300 ret
= drm_mode_object_get(dev
, &fb
->base
, DRM_MODE_OBJECT_FB
);
307 dev
->mode_config
.num_fb
++;
308 list_add(&fb
->head
, &dev
->mode_config
.fb_list
);
312 EXPORT_SYMBOL(drm_framebuffer_init
);
315 * drm_framebuffer_cleanup - remove a framebuffer object
316 * @fb: framebuffer to remove
319 * Caller must hold mode config lock.
321 * Scans all the CRTCs in @dev's mode_config. If they're using @fb, removes
322 * it, setting it to NULL.
324 void drm_framebuffer_cleanup(struct drm_framebuffer
*fb
)
326 struct drm_device
*dev
= fb
->dev
;
327 struct drm_crtc
*crtc
;
328 struct drm_plane
*plane
;
329 struct drm_mode_set set
;
332 /* remove from any CRTC */
333 list_for_each_entry(crtc
, &dev
->mode_config
.crtc_list
, head
) {
334 if (crtc
->fb
== fb
) {
335 /* should turn off the crtc */
336 memset(&set
, 0, sizeof(struct drm_mode_set
));
339 ret
= crtc
->funcs
->set_config(&set
);
341 DRM_ERROR("failed to reset crtc %p when fb was deleted\n", crtc
);
345 list_for_each_entry(plane
, &dev
->mode_config
.plane_list
, head
) {
346 if (plane
->fb
== fb
) {
347 /* should turn off the crtc */
348 ret
= plane
->funcs
->disable_plane(plane
);
350 DRM_ERROR("failed to disable plane with busy fb\n");
351 /* disconnect the plane from the fb and crtc: */
357 drm_mode_object_put(dev
, &fb
->base
);
359 dev
->mode_config
.num_fb
--;
361 EXPORT_SYMBOL(drm_framebuffer_cleanup
);
364 * drm_crtc_init - Initialise a new CRTC object
366 * @crtc: CRTC object to init
367 * @funcs: callbacks for the new CRTC
370 * Caller must hold mode config lock.
372 * Inits a new object created as base part of an driver crtc object.
374 void drm_crtc_init(struct drm_device
*dev
, struct drm_crtc
*crtc
,
375 const struct drm_crtc_funcs
*funcs
)
380 mutex_lock(&dev
->mode_config
.mutex
);
381 drm_mode_object_get(dev
, &crtc
->base
, DRM_MODE_OBJECT_CRTC
);
383 list_add_tail(&crtc
->head
, &dev
->mode_config
.crtc_list
);
384 dev
->mode_config
.num_crtc
++;
385 mutex_unlock(&dev
->mode_config
.mutex
);
387 EXPORT_SYMBOL(drm_crtc_init
);
390 * drm_crtc_cleanup - Cleans up the core crtc usage.
391 * @crtc: CRTC to cleanup
394 * Caller must hold mode config lock.
396 * Cleanup @crtc. Removes from drm modesetting space
397 * does NOT free object, caller does that.
399 void drm_crtc_cleanup(struct drm_crtc
*crtc
)
401 struct drm_device
*dev
= crtc
->dev
;
403 if (crtc
->gamma_store
) {
404 kfree(crtc
->gamma_store
);
405 crtc
->gamma_store
= NULL
;
408 drm_mode_object_put(dev
, &crtc
->base
);
409 list_del(&crtc
->head
);
410 dev
->mode_config
.num_crtc
--;
412 EXPORT_SYMBOL(drm_crtc_cleanup
);
415 * drm_mode_probed_add - add a mode to a connector's probed mode list
416 * @connector: connector the new mode
420 * Caller must hold mode config lock.
422 * Add @mode to @connector's mode list for later use.
424 void drm_mode_probed_add(struct drm_connector
*connector
,
425 struct drm_display_mode
*mode
)
427 list_add(&mode
->head
, &connector
->probed_modes
);
429 EXPORT_SYMBOL(drm_mode_probed_add
);
432 * drm_mode_remove - remove and free a mode
433 * @connector: connector list to modify
434 * @mode: mode to remove
437 * Caller must hold mode config lock.
439 * Remove @mode from @connector's mode list, then free it.
441 void drm_mode_remove(struct drm_connector
*connector
,
442 struct drm_display_mode
*mode
)
444 list_del(&mode
->head
);
445 drm_mode_destroy(connector
->dev
, mode
);
447 EXPORT_SYMBOL(drm_mode_remove
);
450 * drm_connector_init - Init a preallocated connector
452 * @connector: the connector to init
453 * @funcs: callbacks for this connector
454 * @name: user visible name of the connector
457 * Caller must hold @dev's mode_config lock.
459 * Initialises a preallocated connector. Connectors should be
460 * subclassed as part of driver connector objects.
462 void drm_connector_init(struct drm_device
*dev
,
463 struct drm_connector
*connector
,
464 const struct drm_connector_funcs
*funcs
,
467 mutex_lock(&dev
->mode_config
.mutex
);
469 connector
->dev
= dev
;
470 connector
->funcs
= funcs
;
471 drm_mode_object_get(dev
, &connector
->base
, DRM_MODE_OBJECT_CONNECTOR
);
472 connector
->connector_type
= connector_type
;
473 connector
->connector_type_id
=
474 ++drm_connector_enum_list
[connector_type
].count
; /* TODO */
475 INIT_LIST_HEAD(&connector
->user_modes
);
476 INIT_LIST_HEAD(&connector
->probed_modes
);
477 INIT_LIST_HEAD(&connector
->modes
);
478 connector
->edid_blob_ptr
= NULL
;
480 list_add_tail(&connector
->head
, &dev
->mode_config
.connector_list
);
481 dev
->mode_config
.num_connector
++;
483 if (connector_type
!= DRM_MODE_CONNECTOR_VIRTUAL
)
484 drm_connector_attach_property(connector
,
485 dev
->mode_config
.edid_property
,
488 drm_connector_attach_property(connector
,
489 dev
->mode_config
.dpms_property
, 0);
491 mutex_unlock(&dev
->mode_config
.mutex
);
493 EXPORT_SYMBOL(drm_connector_init
);
496 * drm_connector_cleanup - cleans up an initialised connector
497 * @connector: connector to cleanup
500 * Caller must hold @dev's mode_config lock.
502 * Cleans up the connector but doesn't free the object.
504 void drm_connector_cleanup(struct drm_connector
*connector
)
506 struct drm_device
*dev
= connector
->dev
;
507 struct drm_display_mode
*mode
, *t
;
509 list_for_each_entry_safe(mode
, t
, &connector
->probed_modes
, head
)
510 drm_mode_remove(connector
, mode
);
512 list_for_each_entry_safe(mode
, t
, &connector
->modes
, head
)
513 drm_mode_remove(connector
, mode
);
515 list_for_each_entry_safe(mode
, t
, &connector
->user_modes
, head
)
516 drm_mode_remove(connector
, mode
);
518 mutex_lock(&dev
->mode_config
.mutex
);
519 drm_mode_object_put(dev
, &connector
->base
);
520 list_del(&connector
->head
);
521 dev
->mode_config
.num_connector
--;
522 mutex_unlock(&dev
->mode_config
.mutex
);
524 EXPORT_SYMBOL(drm_connector_cleanup
);
526 void drm_encoder_init(struct drm_device
*dev
,
527 struct drm_encoder
*encoder
,
528 const struct drm_encoder_funcs
*funcs
,
531 mutex_lock(&dev
->mode_config
.mutex
);
535 drm_mode_object_get(dev
, &encoder
->base
, DRM_MODE_OBJECT_ENCODER
);
536 encoder
->encoder_type
= encoder_type
;
537 encoder
->funcs
= funcs
;
539 list_add_tail(&encoder
->head
, &dev
->mode_config
.encoder_list
);
540 dev
->mode_config
.num_encoder
++;
542 mutex_unlock(&dev
->mode_config
.mutex
);
544 EXPORT_SYMBOL(drm_encoder_init
);
546 void drm_encoder_cleanup(struct drm_encoder
*encoder
)
548 struct drm_device
*dev
= encoder
->dev
;
549 mutex_lock(&dev
->mode_config
.mutex
);
550 drm_mode_object_put(dev
, &encoder
->base
);
551 list_del(&encoder
->head
);
552 dev
->mode_config
.num_encoder
--;
553 mutex_unlock(&dev
->mode_config
.mutex
);
555 EXPORT_SYMBOL(drm_encoder_cleanup
);
557 int drm_plane_init(struct drm_device
*dev
, struct drm_plane
*plane
,
558 unsigned long possible_crtcs
,
559 const struct drm_plane_funcs
*funcs
,
560 const uint32_t *formats
, uint32_t format_count
,
563 mutex_lock(&dev
->mode_config
.mutex
);
566 drm_mode_object_get(dev
, &plane
->base
, DRM_MODE_OBJECT_PLANE
);
567 plane
->funcs
= funcs
;
568 plane
->format_types
= kmalloc(sizeof(uint32_t) * format_count
,
570 if (!plane
->format_types
) {
571 DRM_DEBUG_KMS("out of memory when allocating plane\n");
572 drm_mode_object_put(dev
, &plane
->base
);
573 mutex_unlock(&dev
->mode_config
.mutex
);
577 memcpy(plane
->format_types
, formats
, format_count
* sizeof(uint32_t));
578 plane
->format_count
= format_count
;
579 plane
->possible_crtcs
= possible_crtcs
;
581 /* private planes are not exposed to userspace, but depending on
582 * display hardware, might be convenient to allow sharing programming
583 * for the scanout engine with the crtc implementation.
586 list_add_tail(&plane
->head
, &dev
->mode_config
.plane_list
);
587 dev
->mode_config
.num_plane
++;
589 INIT_LIST_HEAD(&plane
->head
);
592 mutex_unlock(&dev
->mode_config
.mutex
);
596 EXPORT_SYMBOL(drm_plane_init
);
598 void drm_plane_cleanup(struct drm_plane
*plane
)
600 struct drm_device
*dev
= plane
->dev
;
602 mutex_lock(&dev
->mode_config
.mutex
);
603 kfree(plane
->format_types
);
604 drm_mode_object_put(dev
, &plane
->base
);
605 /* if not added to a list, it must be a private plane */
606 if (!list_empty(&plane
->head
)) {
607 list_del(&plane
->head
);
608 dev
->mode_config
.num_plane
--;
610 mutex_unlock(&dev
->mode_config
.mutex
);
612 EXPORT_SYMBOL(drm_plane_cleanup
);
615 * drm_mode_create - create a new display mode
619 * Caller must hold DRM mode_config lock.
621 * Create a new drm_display_mode, give it an ID, and return it.
624 * Pointer to new mode on success, NULL on error.
626 struct drm_display_mode
*drm_mode_create(struct drm_device
*dev
)
628 struct drm_display_mode
*nmode
;
630 nmode
= kzalloc(sizeof(struct drm_display_mode
), GFP_KERNEL
);
634 drm_mode_object_get(dev
, &nmode
->base
, DRM_MODE_OBJECT_MODE
);
637 EXPORT_SYMBOL(drm_mode_create
);
640 * drm_mode_destroy - remove a mode
642 * @mode: mode to remove
645 * Caller must hold mode config lock.
647 * Free @mode's unique identifier, then free it.
649 void drm_mode_destroy(struct drm_device
*dev
, struct drm_display_mode
*mode
)
651 drm_mode_object_put(dev
, &mode
->base
);
655 EXPORT_SYMBOL(drm_mode_destroy
);
657 static int drm_mode_create_standard_connector_properties(struct drm_device
*dev
)
659 struct drm_property
*edid
;
660 struct drm_property
*dpms
;
664 * Standard properties (apply to all connectors)
666 edid
= drm_property_create(dev
, DRM_MODE_PROP_BLOB
|
667 DRM_MODE_PROP_IMMUTABLE
,
669 dev
->mode_config
.edid_property
= edid
;
671 dpms
= drm_property_create(dev
, DRM_MODE_PROP_ENUM
,
672 "DPMS", ARRAY_SIZE(drm_dpms_enum_list
));
673 for (i
= 0; i
< ARRAY_SIZE(drm_dpms_enum_list
); i
++)
674 drm_property_add_enum(dpms
, i
, drm_dpms_enum_list
[i
].type
,
675 drm_dpms_enum_list
[i
].name
);
676 dev
->mode_config
.dpms_property
= dpms
;
682 * drm_mode_create_dvi_i_properties - create DVI-I specific connector properties
685 * Called by a driver the first time a DVI-I connector is made.
687 int drm_mode_create_dvi_i_properties(struct drm_device
*dev
)
689 struct drm_property
*dvi_i_selector
;
690 struct drm_property
*dvi_i_subconnector
;
693 if (dev
->mode_config
.dvi_i_select_subconnector_property
)
697 drm_property_create(dev
, DRM_MODE_PROP_ENUM
,
698 "select subconnector",
699 ARRAY_SIZE(drm_dvi_i_select_enum_list
));
700 for (i
= 0; i
< ARRAY_SIZE(drm_dvi_i_select_enum_list
); i
++)
701 drm_property_add_enum(dvi_i_selector
, i
,
702 drm_dvi_i_select_enum_list
[i
].type
,
703 drm_dvi_i_select_enum_list
[i
].name
);
704 dev
->mode_config
.dvi_i_select_subconnector_property
= dvi_i_selector
;
707 drm_property_create(dev
, DRM_MODE_PROP_ENUM
|
708 DRM_MODE_PROP_IMMUTABLE
,
710 ARRAY_SIZE(drm_dvi_i_subconnector_enum_list
));
711 for (i
= 0; i
< ARRAY_SIZE(drm_dvi_i_subconnector_enum_list
); i
++)
712 drm_property_add_enum(dvi_i_subconnector
, i
,
713 drm_dvi_i_subconnector_enum_list
[i
].type
,
714 drm_dvi_i_subconnector_enum_list
[i
].name
);
715 dev
->mode_config
.dvi_i_subconnector_property
= dvi_i_subconnector
;
719 EXPORT_SYMBOL(drm_mode_create_dvi_i_properties
);
722 * drm_create_tv_properties - create TV specific connector properties
724 * @num_modes: number of different TV formats (modes) supported
725 * @modes: array of pointers to strings containing name of each format
727 * Called by a driver's TV initialization routine, this function creates
728 * the TV specific connector properties for a given device. Caller is
729 * responsible for allocating a list of format names and passing them to
732 int drm_mode_create_tv_properties(struct drm_device
*dev
, int num_modes
,
735 struct drm_property
*tv_selector
;
736 struct drm_property
*tv_subconnector
;
739 if (dev
->mode_config
.tv_select_subconnector_property
)
743 * Basic connector properties
745 tv_selector
= drm_property_create(dev
, DRM_MODE_PROP_ENUM
,
746 "select subconnector",
747 ARRAY_SIZE(drm_tv_select_enum_list
));
748 for (i
= 0; i
< ARRAY_SIZE(drm_tv_select_enum_list
); i
++)
749 drm_property_add_enum(tv_selector
, i
,
750 drm_tv_select_enum_list
[i
].type
,
751 drm_tv_select_enum_list
[i
].name
);
752 dev
->mode_config
.tv_select_subconnector_property
= tv_selector
;
755 drm_property_create(dev
, DRM_MODE_PROP_ENUM
|
756 DRM_MODE_PROP_IMMUTABLE
, "subconnector",
757 ARRAY_SIZE(drm_tv_subconnector_enum_list
));
758 for (i
= 0; i
< ARRAY_SIZE(drm_tv_subconnector_enum_list
); i
++)
759 drm_property_add_enum(tv_subconnector
, i
,
760 drm_tv_subconnector_enum_list
[i
].type
,
761 drm_tv_subconnector_enum_list
[i
].name
);
762 dev
->mode_config
.tv_subconnector_property
= tv_subconnector
;
765 * Other, TV specific properties: margins & TV modes.
767 dev
->mode_config
.tv_left_margin_property
=
768 drm_property_create(dev
, DRM_MODE_PROP_RANGE
,
770 dev
->mode_config
.tv_left_margin_property
->values
[0] = 0;
771 dev
->mode_config
.tv_left_margin_property
->values
[1] = 100;
773 dev
->mode_config
.tv_right_margin_property
=
774 drm_property_create(dev
, DRM_MODE_PROP_RANGE
,
776 dev
->mode_config
.tv_right_margin_property
->values
[0] = 0;
777 dev
->mode_config
.tv_right_margin_property
->values
[1] = 100;
779 dev
->mode_config
.tv_top_margin_property
=
780 drm_property_create(dev
, DRM_MODE_PROP_RANGE
,
782 dev
->mode_config
.tv_top_margin_property
->values
[0] = 0;
783 dev
->mode_config
.tv_top_margin_property
->values
[1] = 100;
785 dev
->mode_config
.tv_bottom_margin_property
=
786 drm_property_create(dev
, DRM_MODE_PROP_RANGE
,
788 dev
->mode_config
.tv_bottom_margin_property
->values
[0] = 0;
789 dev
->mode_config
.tv_bottom_margin_property
->values
[1] = 100;
791 dev
->mode_config
.tv_mode_property
=
792 drm_property_create(dev
, DRM_MODE_PROP_ENUM
,
794 for (i
= 0; i
< num_modes
; i
++)
795 drm_property_add_enum(dev
->mode_config
.tv_mode_property
, i
,
798 dev
->mode_config
.tv_brightness_property
=
799 drm_property_create(dev
, DRM_MODE_PROP_RANGE
,
801 dev
->mode_config
.tv_brightness_property
->values
[0] = 0;
802 dev
->mode_config
.tv_brightness_property
->values
[1] = 100;
804 dev
->mode_config
.tv_contrast_property
=
805 drm_property_create(dev
, DRM_MODE_PROP_RANGE
,
807 dev
->mode_config
.tv_contrast_property
->values
[0] = 0;
808 dev
->mode_config
.tv_contrast_property
->values
[1] = 100;
810 dev
->mode_config
.tv_flicker_reduction_property
=
811 drm_property_create(dev
, DRM_MODE_PROP_RANGE
,
812 "flicker reduction", 2);
813 dev
->mode_config
.tv_flicker_reduction_property
->values
[0] = 0;
814 dev
->mode_config
.tv_flicker_reduction_property
->values
[1] = 100;
816 dev
->mode_config
.tv_overscan_property
=
817 drm_property_create(dev
, DRM_MODE_PROP_RANGE
,
819 dev
->mode_config
.tv_overscan_property
->values
[0] = 0;
820 dev
->mode_config
.tv_overscan_property
->values
[1] = 100;
822 dev
->mode_config
.tv_saturation_property
=
823 drm_property_create(dev
, DRM_MODE_PROP_RANGE
,
825 dev
->mode_config
.tv_saturation_property
->values
[0] = 0;
826 dev
->mode_config
.tv_saturation_property
->values
[1] = 100;
828 dev
->mode_config
.tv_hue_property
=
829 drm_property_create(dev
, DRM_MODE_PROP_RANGE
,
831 dev
->mode_config
.tv_hue_property
->values
[0] = 0;
832 dev
->mode_config
.tv_hue_property
->values
[1] = 100;
836 EXPORT_SYMBOL(drm_mode_create_tv_properties
);
839 * drm_mode_create_scaling_mode_property - create scaling mode property
842 * Called by a driver the first time it's needed, must be attached to desired
845 int drm_mode_create_scaling_mode_property(struct drm_device
*dev
)
847 struct drm_property
*scaling_mode
;
850 if (dev
->mode_config
.scaling_mode_property
)
854 drm_property_create(dev
, DRM_MODE_PROP_ENUM
, "scaling mode",
855 ARRAY_SIZE(drm_scaling_mode_enum_list
));
856 for (i
= 0; i
< ARRAY_SIZE(drm_scaling_mode_enum_list
); i
++)
857 drm_property_add_enum(scaling_mode
, i
,
858 drm_scaling_mode_enum_list
[i
].type
,
859 drm_scaling_mode_enum_list
[i
].name
);
861 dev
->mode_config
.scaling_mode_property
= scaling_mode
;
865 EXPORT_SYMBOL(drm_mode_create_scaling_mode_property
);
868 * drm_mode_create_dithering_property - create dithering property
871 * Called by a driver the first time it's needed, must be attached to desired
874 int drm_mode_create_dithering_property(struct drm_device
*dev
)
876 struct drm_property
*dithering_mode
;
879 if (dev
->mode_config
.dithering_mode_property
)
883 drm_property_create(dev
, DRM_MODE_PROP_ENUM
, "dithering",
884 ARRAY_SIZE(drm_dithering_mode_enum_list
));
885 for (i
= 0; i
< ARRAY_SIZE(drm_dithering_mode_enum_list
); i
++)
886 drm_property_add_enum(dithering_mode
, i
,
887 drm_dithering_mode_enum_list
[i
].type
,
888 drm_dithering_mode_enum_list
[i
].name
);
889 dev
->mode_config
.dithering_mode_property
= dithering_mode
;
893 EXPORT_SYMBOL(drm_mode_create_dithering_property
);
896 * drm_mode_create_dirty_property - create dirty property
899 * Called by a driver the first time it's needed, must be attached to desired
902 int drm_mode_create_dirty_info_property(struct drm_device
*dev
)
904 struct drm_property
*dirty_info
;
907 if (dev
->mode_config
.dirty_info_property
)
911 drm_property_create(dev
, DRM_MODE_PROP_ENUM
|
912 DRM_MODE_PROP_IMMUTABLE
,
914 ARRAY_SIZE(drm_dirty_info_enum_list
));
915 for (i
= 0; i
< ARRAY_SIZE(drm_dirty_info_enum_list
); i
++)
916 drm_property_add_enum(dirty_info
, i
,
917 drm_dirty_info_enum_list
[i
].type
,
918 drm_dirty_info_enum_list
[i
].name
);
919 dev
->mode_config
.dirty_info_property
= dirty_info
;
923 EXPORT_SYMBOL(drm_mode_create_dirty_info_property
);
926 * drm_mode_config_init - initialize DRM mode_configuration structure
930 * None, should happen single threaded at init time.
932 * Initialize @dev's mode_config structure, used for tracking the graphics
933 * configuration of @dev.
935 void drm_mode_config_init(struct drm_device
*dev
)
937 mutex_init(&dev
->mode_config
.mutex
);
938 mutex_init(&dev
->mode_config
.idr_mutex
);
939 INIT_LIST_HEAD(&dev
->mode_config
.fb_list
);
940 INIT_LIST_HEAD(&dev
->mode_config
.crtc_list
);
941 INIT_LIST_HEAD(&dev
->mode_config
.connector_list
);
942 INIT_LIST_HEAD(&dev
->mode_config
.encoder_list
);
943 INIT_LIST_HEAD(&dev
->mode_config
.property_list
);
944 INIT_LIST_HEAD(&dev
->mode_config
.property_blob_list
);
945 INIT_LIST_HEAD(&dev
->mode_config
.plane_list
);
946 idr_init(&dev
->mode_config
.crtc_idr
);
948 mutex_lock(&dev
->mode_config
.mutex
);
949 drm_mode_create_standard_connector_properties(dev
);
950 mutex_unlock(&dev
->mode_config
.mutex
);
952 /* Just to be sure */
953 dev
->mode_config
.num_fb
= 0;
954 dev
->mode_config
.num_connector
= 0;
955 dev
->mode_config
.num_crtc
= 0;
956 dev
->mode_config
.num_encoder
= 0;
958 EXPORT_SYMBOL(drm_mode_config_init
);
960 int drm_mode_group_init(struct drm_device
*dev
, struct drm_mode_group
*group
)
962 uint32_t total_objects
= 0;
964 total_objects
+= dev
->mode_config
.num_crtc
;
965 total_objects
+= dev
->mode_config
.num_connector
;
966 total_objects
+= dev
->mode_config
.num_encoder
;
968 group
->id_list
= kzalloc(total_objects
* sizeof(uint32_t), GFP_KERNEL
);
972 group
->num_crtcs
= 0;
973 group
->num_connectors
= 0;
974 group
->num_encoders
= 0;
978 int drm_mode_group_init_legacy_group(struct drm_device
*dev
,
979 struct drm_mode_group
*group
)
981 struct drm_crtc
*crtc
;
982 struct drm_encoder
*encoder
;
983 struct drm_connector
*connector
;
986 if ((ret
= drm_mode_group_init(dev
, group
)))
989 list_for_each_entry(crtc
, &dev
->mode_config
.crtc_list
, head
)
990 group
->id_list
[group
->num_crtcs
++] = crtc
->base
.id
;
992 list_for_each_entry(encoder
, &dev
->mode_config
.encoder_list
, head
)
993 group
->id_list
[group
->num_crtcs
+ group
->num_encoders
++] =
996 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
, head
)
997 group
->id_list
[group
->num_crtcs
+ group
->num_encoders
+
998 group
->num_connectors
++] = connector
->base
.id
;
1004 * drm_mode_config_cleanup - free up DRM mode_config info
1008 * Caller must hold mode config lock.
1010 * Free up all the connectors and CRTCs associated with this DRM device, then
1011 * free up the framebuffers and associated buffer objects.
1013 * FIXME: cleanup any dangling user buffer objects too
1015 void drm_mode_config_cleanup(struct drm_device
*dev
)
1017 struct drm_connector
*connector
, *ot
;
1018 struct drm_crtc
*crtc
, *ct
;
1019 struct drm_encoder
*encoder
, *enct
;
1020 struct drm_framebuffer
*fb
, *fbt
;
1021 struct drm_property
*property
, *pt
;
1022 struct drm_plane
*plane
, *plt
;
1024 list_for_each_entry_safe(encoder
, enct
, &dev
->mode_config
.encoder_list
,
1026 encoder
->funcs
->destroy(encoder
);
1029 list_for_each_entry_safe(connector
, ot
,
1030 &dev
->mode_config
.connector_list
, head
) {
1031 connector
->funcs
->destroy(connector
);
1034 list_for_each_entry_safe(property
, pt
, &dev
->mode_config
.property_list
,
1036 drm_property_destroy(dev
, property
);
1039 list_for_each_entry_safe(fb
, fbt
, &dev
->mode_config
.fb_list
, head
) {
1040 fb
->funcs
->destroy(fb
);
1043 list_for_each_entry_safe(crtc
, ct
, &dev
->mode_config
.crtc_list
, head
) {
1044 crtc
->funcs
->destroy(crtc
);
1047 list_for_each_entry_safe(plane
, plt
, &dev
->mode_config
.plane_list
,
1049 plane
->funcs
->destroy(plane
);
1052 idr_remove_all(&dev
->mode_config
.crtc_idr
);
1053 idr_destroy(&dev
->mode_config
.crtc_idr
);
1055 EXPORT_SYMBOL(drm_mode_config_cleanup
);
1058 * drm_crtc_convert_to_umode - convert a drm_display_mode into a modeinfo
1059 * @out: drm_mode_modeinfo struct to return to the user
1060 * @in: drm_display_mode to use
1065 * Convert a drm_display_mode into a drm_mode_modeinfo structure to return to
1068 void drm_crtc_convert_to_umode(struct drm_mode_modeinfo
*out
,
1069 struct drm_display_mode
*in
)
1071 out
->clock
= in
->clock
;
1072 out
->hdisplay
= in
->hdisplay
;
1073 out
->hsync_start
= in
->hsync_start
;
1074 out
->hsync_end
= in
->hsync_end
;
1075 out
->htotal
= in
->htotal
;
1076 out
->hskew
= in
->hskew
;
1077 out
->vdisplay
= in
->vdisplay
;
1078 out
->vsync_start
= in
->vsync_start
;
1079 out
->vsync_end
= in
->vsync_end
;
1080 out
->vtotal
= in
->vtotal
;
1081 out
->vscan
= in
->vscan
;
1082 out
->vrefresh
= in
->vrefresh
;
1083 out
->flags
= in
->flags
;
1084 out
->type
= in
->type
;
1085 strncpy(out
->name
, in
->name
, DRM_DISPLAY_MODE_LEN
);
1086 out
->name
[DRM_DISPLAY_MODE_LEN
-1] = 0;
1090 * drm_crtc_convert_to_umode - convert a modeinfo into a drm_display_mode
1091 * @out: drm_display_mode to return to the user
1092 * @in: drm_mode_modeinfo to use
1097 * Convert a drm_mode_modeinfo into a drm_display_mode structure to return to
1100 void drm_crtc_convert_umode(struct drm_display_mode
*out
,
1101 struct drm_mode_modeinfo
*in
)
1103 out
->clock
= in
->clock
;
1104 out
->hdisplay
= in
->hdisplay
;
1105 out
->hsync_start
= in
->hsync_start
;
1106 out
->hsync_end
= in
->hsync_end
;
1107 out
->htotal
= in
->htotal
;
1108 out
->hskew
= in
->hskew
;
1109 out
->vdisplay
= in
->vdisplay
;
1110 out
->vsync_start
= in
->vsync_start
;
1111 out
->vsync_end
= in
->vsync_end
;
1112 out
->vtotal
= in
->vtotal
;
1113 out
->vscan
= in
->vscan
;
1114 out
->vrefresh
= in
->vrefresh
;
1115 out
->flags
= in
->flags
;
1116 out
->type
= in
->type
;
1117 strncpy(out
->name
, in
->name
, DRM_DISPLAY_MODE_LEN
);
1118 out
->name
[DRM_DISPLAY_MODE_LEN
-1] = 0;
1122 * drm_mode_getresources - get graphics configuration
1123 * @inode: inode from the ioctl
1124 * @filp: file * from the ioctl
1125 * @cmd: cmd from ioctl
1126 * @arg: arg from ioctl
1129 * Takes mode config lock.
1131 * Construct a set of configuration description structures and return
1132 * them to the user, including CRTC, connector and framebuffer configuration.
1134 * Called by the user via ioctl.
1137 * Zero on success, errno on failure.
1139 int drm_mode_getresources(struct drm_device
*dev
, void *data
,
1140 struct drm_file
*file_priv
)
1142 struct drm_mode_card_res
*card_res
= data
;
1143 struct list_head
*lh
;
1144 struct drm_framebuffer
*fb
;
1145 struct drm_connector
*connector
;
1146 struct drm_crtc
*crtc
;
1147 struct drm_encoder
*encoder
;
1149 int connector_count
= 0;
1152 int encoder_count
= 0;
1154 uint32_t __user
*fb_id
;
1155 uint32_t __user
*crtc_id
;
1156 uint32_t __user
*connector_id
;
1157 uint32_t __user
*encoder_id
;
1158 struct drm_mode_group
*mode_group
;
1160 if (!drm_core_check_feature(dev
, DRIVER_MODESET
))
1163 mutex_lock(&dev
->mode_config
.mutex
);
1166 * For the non-control nodes we need to limit the list of resources
1167 * by IDs in the group list for this node
1169 list_for_each(lh
, &file_priv
->fbs
)
1172 mode_group
= &file_priv
->master
->minor
->mode_group
;
1173 if (file_priv
->master
->minor
->type
== DRM_MINOR_CONTROL
) {
1175 list_for_each(lh
, &dev
->mode_config
.crtc_list
)
1178 list_for_each(lh
, &dev
->mode_config
.connector_list
)
1181 list_for_each(lh
, &dev
->mode_config
.encoder_list
)
1185 crtc_count
= mode_group
->num_crtcs
;
1186 connector_count
= mode_group
->num_connectors
;
1187 encoder_count
= mode_group
->num_encoders
;
1190 card_res
->max_height
= dev
->mode_config
.max_height
;
1191 card_res
->min_height
= dev
->mode_config
.min_height
;
1192 card_res
->max_width
= dev
->mode_config
.max_width
;
1193 card_res
->min_width
= dev
->mode_config
.min_width
;
1195 /* handle this in 4 parts */
1197 if (card_res
->count_fbs
>= fb_count
) {
1199 fb_id
= (uint32_t __user
*)(unsigned long)card_res
->fb_id_ptr
;
1200 list_for_each_entry(fb
, &file_priv
->fbs
, filp_head
) {
1201 if (put_user(fb
->base
.id
, fb_id
+ copied
)) {
1208 card_res
->count_fbs
= fb_count
;
1211 if (card_res
->count_crtcs
>= crtc_count
) {
1213 crtc_id
= (uint32_t __user
*)(unsigned long)card_res
->crtc_id_ptr
;
1214 if (file_priv
->master
->minor
->type
== DRM_MINOR_CONTROL
) {
1215 list_for_each_entry(crtc
, &dev
->mode_config
.crtc_list
,
1217 DRM_DEBUG_KMS("[CRTC:%d]\n", crtc
->base
.id
);
1218 if (put_user(crtc
->base
.id
, crtc_id
+ copied
)) {
1225 for (i
= 0; i
< mode_group
->num_crtcs
; i
++) {
1226 if (put_user(mode_group
->id_list
[i
],
1227 crtc_id
+ copied
)) {
1235 card_res
->count_crtcs
= crtc_count
;
1238 if (card_res
->count_encoders
>= encoder_count
) {
1240 encoder_id
= (uint32_t __user
*)(unsigned long)card_res
->encoder_id_ptr
;
1241 if (file_priv
->master
->minor
->type
== DRM_MINOR_CONTROL
) {
1242 list_for_each_entry(encoder
,
1243 &dev
->mode_config
.encoder_list
,
1245 DRM_DEBUG_KMS("[ENCODER:%d:%s]\n", encoder
->base
.id
,
1246 drm_get_encoder_name(encoder
));
1247 if (put_user(encoder
->base
.id
, encoder_id
+
1255 for (i
= mode_group
->num_crtcs
; i
< mode_group
->num_crtcs
+ mode_group
->num_encoders
; i
++) {
1256 if (put_user(mode_group
->id_list
[i
],
1257 encoder_id
+ copied
)) {
1266 card_res
->count_encoders
= encoder_count
;
1269 if (card_res
->count_connectors
>= connector_count
) {
1271 connector_id
= (uint32_t __user
*)(unsigned long)card_res
->connector_id_ptr
;
1272 if (file_priv
->master
->minor
->type
== DRM_MINOR_CONTROL
) {
1273 list_for_each_entry(connector
,
1274 &dev
->mode_config
.connector_list
,
1276 DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n",
1278 drm_get_connector_name(connector
));
1279 if (put_user(connector
->base
.id
,
1280 connector_id
+ copied
)) {
1287 int start
= mode_group
->num_crtcs
+
1288 mode_group
->num_encoders
;
1289 for (i
= start
; i
< start
+ mode_group
->num_connectors
; i
++) {
1290 if (put_user(mode_group
->id_list
[i
],
1291 connector_id
+ copied
)) {
1299 card_res
->count_connectors
= connector_count
;
1301 DRM_DEBUG_KMS("CRTC[%d] CONNECTORS[%d] ENCODERS[%d]\n", card_res
->count_crtcs
,
1302 card_res
->count_connectors
, card_res
->count_encoders
);
1305 mutex_unlock(&dev
->mode_config
.mutex
);
1310 * drm_mode_getcrtc - get CRTC configuration
1311 * @inode: inode from the ioctl
1312 * @filp: file * from the ioctl
1313 * @cmd: cmd from ioctl
1314 * @arg: arg from ioctl
1319 * Construct a CRTC configuration structure to return to the user.
1321 * Called by the user via ioctl.
1324 * Zero on success, errno on failure.
1326 int drm_mode_getcrtc(struct drm_device
*dev
,
1327 void *data
, struct drm_file
*file_priv
)
1329 struct drm_mode_crtc
*crtc_resp
= data
;
1330 struct drm_crtc
*crtc
;
1331 struct drm_mode_object
*obj
;
1334 if (!drm_core_check_feature(dev
, DRIVER_MODESET
))
1337 mutex_lock(&dev
->mode_config
.mutex
);
1339 obj
= drm_mode_object_find(dev
, crtc_resp
->crtc_id
,
1340 DRM_MODE_OBJECT_CRTC
);
1345 crtc
= obj_to_crtc(obj
);
1347 crtc_resp
->x
= crtc
->x
;
1348 crtc_resp
->y
= crtc
->y
;
1349 crtc_resp
->gamma_size
= crtc
->gamma_size
;
1351 crtc_resp
->fb_id
= crtc
->fb
->base
.id
;
1353 crtc_resp
->fb_id
= 0;
1355 if (crtc
->enabled
) {
1357 drm_crtc_convert_to_umode(&crtc_resp
->mode
, &crtc
->mode
);
1358 crtc_resp
->mode_valid
= 1;
1361 crtc_resp
->mode_valid
= 0;
1365 mutex_unlock(&dev
->mode_config
.mutex
);
1370 * drm_mode_getconnector - get connector configuration
1371 * @inode: inode from the ioctl
1372 * @filp: file * from the ioctl
1373 * @cmd: cmd from ioctl
1374 * @arg: arg from ioctl
1379 * Construct a connector configuration structure to return to the user.
1381 * Called by the user via ioctl.
1384 * Zero on success, errno on failure.
1386 int drm_mode_getconnector(struct drm_device
*dev
, void *data
,
1387 struct drm_file
*file_priv
)
1389 struct drm_mode_get_connector
*out_resp
= data
;
1390 struct drm_mode_object
*obj
;
1391 struct drm_connector
*connector
;
1392 struct drm_display_mode
*mode
;
1394 int props_count
= 0;
1395 int encoders_count
= 0;
1399 struct drm_mode_modeinfo u_mode
;
1400 struct drm_mode_modeinfo __user
*mode_ptr
;
1401 uint32_t __user
*prop_ptr
;
1402 uint64_t __user
*prop_values
;
1403 uint32_t __user
*encoder_ptr
;
1405 if (!drm_core_check_feature(dev
, DRIVER_MODESET
))
1408 memset(&u_mode
, 0, sizeof(struct drm_mode_modeinfo
));
1410 DRM_DEBUG_KMS("[CONNECTOR:%d:?]\n", out_resp
->connector_id
);
1412 mutex_lock(&dev
->mode_config
.mutex
);
1414 obj
= drm_mode_object_find(dev
, out_resp
->connector_id
,
1415 DRM_MODE_OBJECT_CONNECTOR
);
1420 connector
= obj_to_connector(obj
);
1422 for (i
= 0; i
< DRM_CONNECTOR_MAX_PROPERTY
; i
++) {
1423 if (connector
->property_ids
[i
] != 0) {
1428 for (i
= 0; i
< DRM_CONNECTOR_MAX_ENCODER
; i
++) {
1429 if (connector
->encoder_ids
[i
] != 0) {
1434 if (out_resp
->count_modes
== 0) {
1435 connector
->funcs
->fill_modes(connector
,
1436 dev
->mode_config
.max_width
,
1437 dev
->mode_config
.max_height
);
1440 /* delayed so we get modes regardless of pre-fill_modes state */
1441 list_for_each_entry(mode
, &connector
->modes
, head
)
1444 out_resp
->connector_id
= connector
->base
.id
;
1445 out_resp
->connector_type
= connector
->connector_type
;
1446 out_resp
->connector_type_id
= connector
->connector_type_id
;
1447 out_resp
->mm_width
= connector
->display_info
.width_mm
;
1448 out_resp
->mm_height
= connector
->display_info
.height_mm
;
1449 out_resp
->subpixel
= connector
->display_info
.subpixel_order
;
1450 out_resp
->connection
= connector
->status
;
1451 if (connector
->encoder
)
1452 out_resp
->encoder_id
= connector
->encoder
->base
.id
;
1454 out_resp
->encoder_id
= 0;
1457 * This ioctl is called twice, once to determine how much space is
1458 * needed, and the 2nd time to fill it.
1460 if ((out_resp
->count_modes
>= mode_count
) && mode_count
) {
1462 mode_ptr
= (struct drm_mode_modeinfo __user
*)(unsigned long)out_resp
->modes_ptr
;
1463 list_for_each_entry(mode
, &connector
->modes
, head
) {
1464 drm_crtc_convert_to_umode(&u_mode
, mode
);
1465 if (copy_to_user(mode_ptr
+ copied
,
1466 &u_mode
, sizeof(u_mode
))) {
1473 out_resp
->count_modes
= mode_count
;
1475 if ((out_resp
->count_props
>= props_count
) && props_count
) {
1477 prop_ptr
= (uint32_t __user
*)(unsigned long)(out_resp
->props_ptr
);
1478 prop_values
= (uint64_t __user
*)(unsigned long)(out_resp
->prop_values_ptr
);
1479 for (i
= 0; i
< DRM_CONNECTOR_MAX_PROPERTY
; i
++) {
1480 if (connector
->property_ids
[i
] != 0) {
1481 if (put_user(connector
->property_ids
[i
],
1482 prop_ptr
+ copied
)) {
1487 if (put_user(connector
->property_values
[i
],
1488 prop_values
+ copied
)) {
1496 out_resp
->count_props
= props_count
;
1498 if ((out_resp
->count_encoders
>= encoders_count
) && encoders_count
) {
1500 encoder_ptr
= (uint32_t __user
*)(unsigned long)(out_resp
->encoders_ptr
);
1501 for (i
= 0; i
< DRM_CONNECTOR_MAX_ENCODER
; i
++) {
1502 if (connector
->encoder_ids
[i
] != 0) {
1503 if (put_user(connector
->encoder_ids
[i
],
1504 encoder_ptr
+ copied
)) {
1512 out_resp
->count_encoders
= encoders_count
;
1515 mutex_unlock(&dev
->mode_config
.mutex
);
1519 int drm_mode_getencoder(struct drm_device
*dev
, void *data
,
1520 struct drm_file
*file_priv
)
1522 struct drm_mode_get_encoder
*enc_resp
= data
;
1523 struct drm_mode_object
*obj
;
1524 struct drm_encoder
*encoder
;
1527 if (!drm_core_check_feature(dev
, DRIVER_MODESET
))
1530 mutex_lock(&dev
->mode_config
.mutex
);
1531 obj
= drm_mode_object_find(dev
, enc_resp
->encoder_id
,
1532 DRM_MODE_OBJECT_ENCODER
);
1537 encoder
= obj_to_encoder(obj
);
1540 enc_resp
->crtc_id
= encoder
->crtc
->base
.id
;
1542 enc_resp
->crtc_id
= 0;
1543 enc_resp
->encoder_type
= encoder
->encoder_type
;
1544 enc_resp
->encoder_id
= encoder
->base
.id
;
1545 enc_resp
->possible_crtcs
= encoder
->possible_crtcs
;
1546 enc_resp
->possible_clones
= encoder
->possible_clones
;
1549 mutex_unlock(&dev
->mode_config
.mutex
);
1554 * drm_mode_getplane_res - get plane info
1557 * @file_priv: DRM file info
1559 * Return an plane count and set of IDs.
1561 int drm_mode_getplane_res(struct drm_device
*dev
, void *data
,
1562 struct drm_file
*file_priv
)
1564 struct drm_mode_get_plane_res
*plane_resp
= data
;
1565 struct drm_mode_config
*config
;
1566 struct drm_plane
*plane
;
1567 uint32_t __user
*plane_ptr
;
1568 int copied
= 0, ret
= 0;
1570 if (!drm_core_check_feature(dev
, DRIVER_MODESET
))
1573 mutex_lock(&dev
->mode_config
.mutex
);
1574 config
= &dev
->mode_config
;
1577 * This ioctl is called twice, once to determine how much space is
1578 * needed, and the 2nd time to fill it.
1580 if (config
->num_plane
&&
1581 (plane_resp
->count_planes
>= config
->num_plane
)) {
1582 plane_ptr
= (uint32_t __user
*)(unsigned long)plane_resp
->plane_id_ptr
;
1584 list_for_each_entry(plane
, &config
->plane_list
, head
) {
1585 if (put_user(plane
->base
.id
, plane_ptr
+ copied
)) {
1592 plane_resp
->count_planes
= config
->num_plane
;
1595 mutex_unlock(&dev
->mode_config
.mutex
);
1600 * drm_mode_getplane - get plane info
1603 * @file_priv: DRM file info
1605 * Return plane info, including formats supported, gamma size, any
1608 int drm_mode_getplane(struct drm_device
*dev
, void *data
,
1609 struct drm_file
*file_priv
)
1611 struct drm_mode_get_plane
*plane_resp
= data
;
1612 struct drm_mode_object
*obj
;
1613 struct drm_plane
*plane
;
1614 uint32_t __user
*format_ptr
;
1617 if (!drm_core_check_feature(dev
, DRIVER_MODESET
))
1620 mutex_lock(&dev
->mode_config
.mutex
);
1621 obj
= drm_mode_object_find(dev
, plane_resp
->plane_id
,
1622 DRM_MODE_OBJECT_PLANE
);
1627 plane
= obj_to_plane(obj
);
1630 plane_resp
->crtc_id
= plane
->crtc
->base
.id
;
1632 plane_resp
->crtc_id
= 0;
1635 plane_resp
->fb_id
= plane
->fb
->base
.id
;
1637 plane_resp
->fb_id
= 0;
1639 plane_resp
->plane_id
= plane
->base
.id
;
1640 plane_resp
->possible_crtcs
= plane
->possible_crtcs
;
1641 plane_resp
->gamma_size
= plane
->gamma_size
;
1644 * This ioctl is called twice, once to determine how much space is
1645 * needed, and the 2nd time to fill it.
1647 if (plane
->format_count
&&
1648 (plane_resp
->count_format_types
>= plane
->format_count
)) {
1649 format_ptr
= (uint32_t __user
*)(unsigned long)plane_resp
->format_type_ptr
;
1650 if (copy_to_user(format_ptr
,
1651 plane
->format_types
,
1652 sizeof(uint32_t) * plane
->format_count
)) {
1657 plane_resp
->count_format_types
= plane
->format_count
;
1660 mutex_unlock(&dev
->mode_config
.mutex
);
1665 * drm_mode_setplane - set up or tear down an plane
1667 * @data: ioctl data*
1668 * @file_prive: DRM file info
1670 * Set plane info, including placement, fb, scaling, and other factors.
1671 * Or pass a NULL fb to disable.
1673 int drm_mode_setplane(struct drm_device
*dev
, void *data
,
1674 struct drm_file
*file_priv
)
1676 struct drm_mode_set_plane
*plane_req
= data
;
1677 struct drm_mode_object
*obj
;
1678 struct drm_plane
*plane
;
1679 struct drm_crtc
*crtc
;
1680 struct drm_framebuffer
*fb
;
1682 unsigned int fb_width
, fb_height
;
1685 if (!drm_core_check_feature(dev
, DRIVER_MODESET
))
1688 mutex_lock(&dev
->mode_config
.mutex
);
1691 * First, find the plane, crtc, and fb objects. If not available,
1692 * we don't bother to call the driver.
1694 obj
= drm_mode_object_find(dev
, plane_req
->plane_id
,
1695 DRM_MODE_OBJECT_PLANE
);
1697 DRM_DEBUG_KMS("Unknown plane ID %d\n",
1698 plane_req
->plane_id
);
1702 plane
= obj_to_plane(obj
);
1704 /* No fb means shut it down */
1705 if (!plane_req
->fb_id
) {
1706 plane
->funcs
->disable_plane(plane
);
1712 obj
= drm_mode_object_find(dev
, plane_req
->crtc_id
,
1713 DRM_MODE_OBJECT_CRTC
);
1715 DRM_DEBUG_KMS("Unknown crtc ID %d\n",
1716 plane_req
->crtc_id
);
1720 crtc
= obj_to_crtc(obj
);
1722 obj
= drm_mode_object_find(dev
, plane_req
->fb_id
,
1723 DRM_MODE_OBJECT_FB
);
1725 DRM_DEBUG_KMS("Unknown framebuffer ID %d\n",
1730 fb
= obj_to_fb(obj
);
1732 /* Check whether this plane supports the fb pixel format. */
1733 for (i
= 0; i
< plane
->format_count
; i
++)
1734 if (fb
->pixel_format
== plane
->format_types
[i
])
1736 if (i
== plane
->format_count
) {
1737 DRM_DEBUG_KMS("Invalid pixel format 0x%08x\n", fb
->pixel_format
);
1742 fb_width
= fb
->width
<< 16;
1743 fb_height
= fb
->height
<< 16;
1745 /* Make sure source coordinates are inside the fb. */
1746 if (plane_req
->src_w
> fb_width
||
1747 plane_req
->src_x
> fb_width
- plane_req
->src_w
||
1748 plane_req
->src_h
> fb_height
||
1749 plane_req
->src_y
> fb_height
- plane_req
->src_h
) {
1750 DRM_DEBUG_KMS("Invalid source coordinates "
1751 "%u.%06ux%u.%06u+%u.%06u+%u.%06u\n",
1752 plane_req
->src_w
>> 16,
1753 ((plane_req
->src_w
& 0xffff) * 15625) >> 10,
1754 plane_req
->src_h
>> 16,
1755 ((plane_req
->src_h
& 0xffff) * 15625) >> 10,
1756 plane_req
->src_x
>> 16,
1757 ((plane_req
->src_x
& 0xffff) * 15625) >> 10,
1758 plane_req
->src_y
>> 16,
1759 ((plane_req
->src_y
& 0xffff) * 15625) >> 10);
1764 /* Give drivers some help against integer overflows */
1765 if (plane_req
->crtc_w
> INT_MAX
||
1766 plane_req
->crtc_x
> INT_MAX
- (int32_t) plane_req
->crtc_w
||
1767 plane_req
->crtc_h
> INT_MAX
||
1768 plane_req
->crtc_y
> INT_MAX
- (int32_t) plane_req
->crtc_h
) {
1769 DRM_DEBUG_KMS("Invalid CRTC coordinates %ux%u+%d+%d\n",
1770 plane_req
->crtc_w
, plane_req
->crtc_h
,
1771 plane_req
->crtc_x
, plane_req
->crtc_y
);
1776 ret
= plane
->funcs
->update_plane(plane
, crtc
, fb
,
1777 plane_req
->crtc_x
, plane_req
->crtc_y
,
1778 plane_req
->crtc_w
, plane_req
->crtc_h
,
1779 plane_req
->src_x
, plane_req
->src_y
,
1780 plane_req
->src_w
, plane_req
->src_h
);
1787 mutex_unlock(&dev
->mode_config
.mutex
);
1793 * drm_mode_setcrtc - set CRTC configuration
1794 * @inode: inode from the ioctl
1795 * @filp: file * from the ioctl
1796 * @cmd: cmd from ioctl
1797 * @arg: arg from ioctl
1802 * Build a new CRTC configuration based on user request.
1804 * Called by the user via ioctl.
1807 * Zero on success, errno on failure.
1809 int drm_mode_setcrtc(struct drm_device
*dev
, void *data
,
1810 struct drm_file
*file_priv
)
1812 struct drm_mode_config
*config
= &dev
->mode_config
;
1813 struct drm_mode_crtc
*crtc_req
= data
;
1814 struct drm_mode_object
*obj
;
1815 struct drm_crtc
*crtc
, *crtcfb
;
1816 struct drm_connector
**connector_set
= NULL
, *connector
;
1817 struct drm_framebuffer
*fb
= NULL
;
1818 struct drm_display_mode
*mode
= NULL
;
1819 struct drm_mode_set set
;
1820 uint32_t __user
*set_connectors_ptr
;
1824 if (!drm_core_check_feature(dev
, DRIVER_MODESET
))
1827 mutex_lock(&dev
->mode_config
.mutex
);
1828 obj
= drm_mode_object_find(dev
, crtc_req
->crtc_id
,
1829 DRM_MODE_OBJECT_CRTC
);
1831 DRM_DEBUG_KMS("Unknown CRTC ID %d\n", crtc_req
->crtc_id
);
1835 crtc
= obj_to_crtc(obj
);
1836 DRM_DEBUG_KMS("[CRTC:%d]\n", crtc
->base
.id
);
1838 if (crtc_req
->mode_valid
) {
1839 /* If we have a mode we need a framebuffer. */
1840 /* If we pass -1, set the mode with the currently bound fb */
1841 if (crtc_req
->fb_id
== -1) {
1842 list_for_each_entry(crtcfb
,
1843 &dev
->mode_config
.crtc_list
, head
) {
1844 if (crtcfb
== crtc
) {
1845 DRM_DEBUG_KMS("Using current fb for "
1851 obj
= drm_mode_object_find(dev
, crtc_req
->fb_id
,
1852 DRM_MODE_OBJECT_FB
);
1854 DRM_DEBUG_KMS("Unknown FB ID%d\n",
1859 fb
= obj_to_fb(obj
);
1862 mode
= drm_mode_create(dev
);
1863 drm_crtc_convert_umode(mode
, &crtc_req
->mode
);
1864 drm_mode_set_crtcinfo(mode
, CRTC_INTERLACE_HALVE_V
);
1867 if (crtc_req
->count_connectors
== 0 && mode
) {
1868 DRM_DEBUG_KMS("Count connectors is 0 but mode set\n");
1873 if (crtc_req
->count_connectors
> 0 && (!mode
|| !fb
)) {
1874 DRM_DEBUG_KMS("Count connectors is %d but no mode or fb set\n",
1875 crtc_req
->count_connectors
);
1880 if (crtc_req
->count_connectors
> 0) {
1883 /* Avoid unbounded kernel memory allocation */
1884 if (crtc_req
->count_connectors
> config
->num_connector
) {
1889 connector_set
= kmalloc(crtc_req
->count_connectors
*
1890 sizeof(struct drm_connector
*),
1892 if (!connector_set
) {
1897 for (i
= 0; i
< crtc_req
->count_connectors
; i
++) {
1898 set_connectors_ptr
= (uint32_t __user
*)(unsigned long)crtc_req
->set_connectors_ptr
;
1899 if (get_user(out_id
, &set_connectors_ptr
[i
])) {
1904 obj
= drm_mode_object_find(dev
, out_id
,
1905 DRM_MODE_OBJECT_CONNECTOR
);
1907 DRM_DEBUG_KMS("Connector id %d unknown\n",
1912 connector
= obj_to_connector(obj
);
1913 DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n",
1915 drm_get_connector_name(connector
));
1917 connector_set
[i
] = connector
;
1922 set
.x
= crtc_req
->x
;
1923 set
.y
= crtc_req
->y
;
1925 set
.connectors
= connector_set
;
1926 set
.num_connectors
= crtc_req
->count_connectors
;
1928 ret
= crtc
->funcs
->set_config(&set
);
1931 kfree(connector_set
);
1932 mutex_unlock(&dev
->mode_config
.mutex
);
1936 int drm_mode_cursor_ioctl(struct drm_device
*dev
,
1937 void *data
, struct drm_file
*file_priv
)
1939 struct drm_mode_cursor
*req
= data
;
1940 struct drm_mode_object
*obj
;
1941 struct drm_crtc
*crtc
;
1944 if (!drm_core_check_feature(dev
, DRIVER_MODESET
))
1950 mutex_lock(&dev
->mode_config
.mutex
);
1951 obj
= drm_mode_object_find(dev
, req
->crtc_id
, DRM_MODE_OBJECT_CRTC
);
1953 DRM_DEBUG_KMS("Unknown CRTC ID %d\n", req
->crtc_id
);
1957 crtc
= obj_to_crtc(obj
);
1959 if (req
->flags
& DRM_MODE_CURSOR_BO
) {
1960 if (!crtc
->funcs
->cursor_set
) {
1964 /* Turns off the cursor if handle is 0 */
1965 ret
= crtc
->funcs
->cursor_set(crtc
, file_priv
, req
->handle
,
1966 req
->width
, req
->height
);
1969 if (req
->flags
& DRM_MODE_CURSOR_MOVE
) {
1970 if (crtc
->funcs
->cursor_move
) {
1971 ret
= crtc
->funcs
->cursor_move(crtc
, req
->x
, req
->y
);
1978 mutex_unlock(&dev
->mode_config
.mutex
);
1982 /* Original addfb only supported RGB formats, so figure out which one */
1983 uint32_t drm_mode_legacy_fb_format(uint32_t bpp
, uint32_t depth
)
1989 fmt
= DRM_FORMAT_RGB332
;
1993 fmt
= DRM_FORMAT_XRGB1555
;
1995 fmt
= DRM_FORMAT_RGB565
;
1998 fmt
= DRM_FORMAT_RGB888
;
2002 fmt
= DRM_FORMAT_XRGB8888
;
2003 else if (depth
== 30)
2004 fmt
= DRM_FORMAT_XRGB2101010
;
2006 fmt
= DRM_FORMAT_ARGB8888
;
2009 DRM_ERROR("bad bpp, assuming x8r8g8b8 pixel format\n");
2010 fmt
= DRM_FORMAT_XRGB8888
;
2016 EXPORT_SYMBOL(drm_mode_legacy_fb_format
);
2019 * drm_mode_addfb - add an FB to the graphics configuration
2020 * @inode: inode from the ioctl
2021 * @filp: file * from the ioctl
2022 * @cmd: cmd from ioctl
2023 * @arg: arg from ioctl
2026 * Takes mode config lock.
2028 * Add a new FB to the specified CRTC, given a user request.
2030 * Called by the user via ioctl.
2033 * Zero on success, errno on failure.
2035 int drm_mode_addfb(struct drm_device
*dev
,
2036 void *data
, struct drm_file
*file_priv
)
2038 struct drm_mode_fb_cmd
*or = data
;
2039 struct drm_mode_fb_cmd2 r
= {};
2040 struct drm_mode_config
*config
= &dev
->mode_config
;
2041 struct drm_framebuffer
*fb
;
2044 /* Use new struct with format internally */
2045 r
.fb_id
= or->fb_id
;
2046 r
.width
= or->width
;
2047 r
.height
= or->height
;
2048 r
.pitches
[0] = or->pitch
;
2049 r
.pixel_format
= drm_mode_legacy_fb_format(or->bpp
, or->depth
);
2050 r
.handles
[0] = or->handle
;
2052 if (!drm_core_check_feature(dev
, DRIVER_MODESET
))
2055 if ((config
->min_width
> r
.width
) || (r
.width
> config
->max_width
))
2058 if ((config
->min_height
> r
.height
) || (r
.height
> config
->max_height
))
2061 mutex_lock(&dev
->mode_config
.mutex
);
2063 /* TODO check buffer is sufficiently large */
2064 /* TODO setup destructor callback */
2066 fb
= dev
->mode_config
.funcs
->fb_create(dev
, file_priv
, &r
);
2068 DRM_ERROR("could not create framebuffer\n");
2073 or->fb_id
= fb
->base
.id
;
2074 list_add(&fb
->filp_head
, &file_priv
->fbs
);
2075 DRM_DEBUG_KMS("[FB:%d]\n", fb
->base
.id
);
2078 mutex_unlock(&dev
->mode_config
.mutex
);
2082 static int format_check(struct drm_mode_fb_cmd2
*r
)
2084 uint32_t format
= r
->pixel_format
& ~DRM_FORMAT_BIG_ENDIAN
;
2088 case DRM_FORMAT_RGB332
:
2089 case DRM_FORMAT_BGR233
:
2090 case DRM_FORMAT_XRGB4444
:
2091 case DRM_FORMAT_XBGR4444
:
2092 case DRM_FORMAT_RGBX4444
:
2093 case DRM_FORMAT_BGRX4444
:
2094 case DRM_FORMAT_ARGB4444
:
2095 case DRM_FORMAT_ABGR4444
:
2096 case DRM_FORMAT_RGBA4444
:
2097 case DRM_FORMAT_BGRA4444
:
2098 case DRM_FORMAT_XRGB1555
:
2099 case DRM_FORMAT_XBGR1555
:
2100 case DRM_FORMAT_RGBX5551
:
2101 case DRM_FORMAT_BGRX5551
:
2102 case DRM_FORMAT_ARGB1555
:
2103 case DRM_FORMAT_ABGR1555
:
2104 case DRM_FORMAT_RGBA5551
:
2105 case DRM_FORMAT_BGRA5551
:
2106 case DRM_FORMAT_RGB565
:
2107 case DRM_FORMAT_BGR565
:
2108 case DRM_FORMAT_RGB888
:
2109 case DRM_FORMAT_BGR888
:
2110 case DRM_FORMAT_XRGB8888
:
2111 case DRM_FORMAT_XBGR8888
:
2112 case DRM_FORMAT_RGBX8888
:
2113 case DRM_FORMAT_BGRX8888
:
2114 case DRM_FORMAT_ARGB8888
:
2115 case DRM_FORMAT_ABGR8888
:
2116 case DRM_FORMAT_RGBA8888
:
2117 case DRM_FORMAT_BGRA8888
:
2118 case DRM_FORMAT_XRGB2101010
:
2119 case DRM_FORMAT_XBGR2101010
:
2120 case DRM_FORMAT_RGBX1010102
:
2121 case DRM_FORMAT_BGRX1010102
:
2122 case DRM_FORMAT_ARGB2101010
:
2123 case DRM_FORMAT_ABGR2101010
:
2124 case DRM_FORMAT_RGBA1010102
:
2125 case DRM_FORMAT_BGRA1010102
:
2126 case DRM_FORMAT_YUYV
:
2127 case DRM_FORMAT_YVYU
:
2128 case DRM_FORMAT_UYVY
:
2129 case DRM_FORMAT_VYUY
:
2130 case DRM_FORMAT_AYUV
:
2131 case DRM_FORMAT_NV12
:
2132 case DRM_FORMAT_NV21
:
2133 case DRM_FORMAT_NV16
:
2134 case DRM_FORMAT_NV61
:
2135 case DRM_FORMAT_YUV410
:
2136 case DRM_FORMAT_YVU410
:
2137 case DRM_FORMAT_YUV411
:
2138 case DRM_FORMAT_YVU411
:
2139 case DRM_FORMAT_YUV420
:
2140 case DRM_FORMAT_YVU420
:
2141 case DRM_FORMAT_YUV422
:
2142 case DRM_FORMAT_YVU422
:
2143 case DRM_FORMAT_YUV444
:
2144 case DRM_FORMAT_YVU444
:
2152 * drm_mode_addfb2 - add an FB to the graphics configuration
2153 * @inode: inode from the ioctl
2154 * @filp: file * from the ioctl
2155 * @cmd: cmd from ioctl
2156 * @arg: arg from ioctl
2159 * Takes mode config lock.
2161 * Add a new FB to the specified CRTC, given a user request with format.
2163 * Called by the user via ioctl.
2166 * Zero on success, errno on failure.
2168 int drm_mode_addfb2(struct drm_device
*dev
,
2169 void *data
, struct drm_file
*file_priv
)
2171 struct drm_mode_fb_cmd2
*r
= data
;
2172 struct drm_mode_config
*config
= &dev
->mode_config
;
2173 struct drm_framebuffer
*fb
;
2176 if (!drm_core_check_feature(dev
, DRIVER_MODESET
))
2179 if ((config
->min_width
> r
->width
) || (r
->width
> config
->max_width
)) {
2180 DRM_ERROR("bad framebuffer width %d, should be >= %d && <= %d\n",
2181 r
->width
, config
->min_width
, config
->max_width
);
2184 if ((config
->min_height
> r
->height
) || (r
->height
> config
->max_height
)) {
2185 DRM_ERROR("bad framebuffer height %d, should be >= %d && <= %d\n",
2186 r
->height
, config
->min_height
, config
->max_height
);
2190 ret
= format_check(r
);
2192 DRM_ERROR("bad framebuffer format 0x%08x\n", r
->pixel_format
);
2196 mutex_lock(&dev
->mode_config
.mutex
);
2198 fb
= dev
->mode_config
.funcs
->fb_create(dev
, file_priv
, r
);
2200 DRM_ERROR("could not create framebuffer\n");
2205 r
->fb_id
= fb
->base
.id
;
2206 list_add(&fb
->filp_head
, &file_priv
->fbs
);
2207 DRM_DEBUG_KMS("[FB:%d]\n", fb
->base
.id
);
2210 mutex_unlock(&dev
->mode_config
.mutex
);
2215 * drm_mode_rmfb - remove an FB from the configuration
2216 * @inode: inode from the ioctl
2217 * @filp: file * from the ioctl
2218 * @cmd: cmd from ioctl
2219 * @arg: arg from ioctl
2222 * Takes mode config lock.
2224 * Remove the FB specified by the user.
2226 * Called by the user via ioctl.
2229 * Zero on success, errno on failure.
2231 int drm_mode_rmfb(struct drm_device
*dev
,
2232 void *data
, struct drm_file
*file_priv
)
2234 struct drm_mode_object
*obj
;
2235 struct drm_framebuffer
*fb
= NULL
;
2236 struct drm_framebuffer
*fbl
= NULL
;
2237 uint32_t *id
= data
;
2241 if (!drm_core_check_feature(dev
, DRIVER_MODESET
))
2244 mutex_lock(&dev
->mode_config
.mutex
);
2245 obj
= drm_mode_object_find(dev
, *id
, DRM_MODE_OBJECT_FB
);
2246 /* TODO check that we really get a framebuffer back. */
2251 fb
= obj_to_fb(obj
);
2253 list_for_each_entry(fbl
, &file_priv
->fbs
, filp_head
)
2262 /* TODO release all crtc connected to the framebuffer */
2263 /* TODO unhock the destructor from the buffer object */
2265 list_del(&fb
->filp_head
);
2266 fb
->funcs
->destroy(fb
);
2269 mutex_unlock(&dev
->mode_config
.mutex
);
2274 * drm_mode_getfb - get FB info
2275 * @inode: inode from the ioctl
2276 * @filp: file * from the ioctl
2277 * @cmd: cmd from ioctl
2278 * @arg: arg from ioctl
2283 * Lookup the FB given its ID and return info about it.
2285 * Called by the user via ioctl.
2288 * Zero on success, errno on failure.
2290 int drm_mode_getfb(struct drm_device
*dev
,
2291 void *data
, struct drm_file
*file_priv
)
2293 struct drm_mode_fb_cmd
*r
= data
;
2294 struct drm_mode_object
*obj
;
2295 struct drm_framebuffer
*fb
;
2298 if (!drm_core_check_feature(dev
, DRIVER_MODESET
))
2301 mutex_lock(&dev
->mode_config
.mutex
);
2302 obj
= drm_mode_object_find(dev
, r
->fb_id
, DRM_MODE_OBJECT_FB
);
2307 fb
= obj_to_fb(obj
);
2309 r
->height
= fb
->height
;
2310 r
->width
= fb
->width
;
2311 r
->depth
= fb
->depth
;
2312 r
->bpp
= fb
->bits_per_pixel
;
2313 r
->pitch
= fb
->pitches
[0];
2314 fb
->funcs
->create_handle(fb
, file_priv
, &r
->handle
);
2317 mutex_unlock(&dev
->mode_config
.mutex
);
2321 int drm_mode_dirtyfb_ioctl(struct drm_device
*dev
,
2322 void *data
, struct drm_file
*file_priv
)
2324 struct drm_clip_rect __user
*clips_ptr
;
2325 struct drm_clip_rect
*clips
= NULL
;
2326 struct drm_mode_fb_dirty_cmd
*r
= data
;
2327 struct drm_mode_object
*obj
;
2328 struct drm_framebuffer
*fb
;
2333 if (!drm_core_check_feature(dev
, DRIVER_MODESET
))
2336 mutex_lock(&dev
->mode_config
.mutex
);
2337 obj
= drm_mode_object_find(dev
, r
->fb_id
, DRM_MODE_OBJECT_FB
);
2342 fb
= obj_to_fb(obj
);
2344 num_clips
= r
->num_clips
;
2345 clips_ptr
= (struct drm_clip_rect __user
*)(unsigned long)r
->clips_ptr
;
2347 if (!num_clips
!= !clips_ptr
) {
2352 flags
= DRM_MODE_FB_DIRTY_FLAGS
& r
->flags
;
2354 /* If userspace annotates copy, clips must come in pairs */
2355 if (flags
& DRM_MODE_FB_DIRTY_ANNOTATE_COPY
&& (num_clips
% 2)) {
2360 if (num_clips
&& clips_ptr
) {
2361 if (num_clips
< 0 || num_clips
> DRM_MODE_FB_DIRTY_MAX_CLIPS
) {
2365 clips
= kzalloc(num_clips
* sizeof(*clips
), GFP_KERNEL
);
2371 ret
= copy_from_user(clips
, clips_ptr
,
2372 num_clips
* sizeof(*clips
));
2379 if (fb
->funcs
->dirty
) {
2380 ret
= fb
->funcs
->dirty(fb
, file_priv
, flags
, r
->color
,
2390 mutex_unlock(&dev
->mode_config
.mutex
);
2396 * drm_fb_release - remove and free the FBs on this file
2397 * @filp: file * from the ioctl
2400 * Takes mode config lock.
2402 * Destroy all the FBs associated with @filp.
2404 * Called by the user via ioctl.
2407 * Zero on success, errno on failure.
2409 void drm_fb_release(struct drm_file
*priv
)
2411 struct drm_device
*dev
= priv
->minor
->dev
;
2412 struct drm_framebuffer
*fb
, *tfb
;
2414 mutex_lock(&dev
->mode_config
.mutex
);
2415 list_for_each_entry_safe(fb
, tfb
, &priv
->fbs
, filp_head
) {
2416 list_del(&fb
->filp_head
);
2417 fb
->funcs
->destroy(fb
);
2419 mutex_unlock(&dev
->mode_config
.mutex
);
2423 * drm_mode_attachmode - add a mode to the user mode list
2425 * @connector: connector to add the mode to
2426 * @mode: mode to add
2428 * Add @mode to @connector's user mode list.
2430 static int drm_mode_attachmode(struct drm_device
*dev
,
2431 struct drm_connector
*connector
,
2432 struct drm_display_mode
*mode
)
2436 list_add_tail(&mode
->head
, &connector
->user_modes
);
2440 int drm_mode_attachmode_crtc(struct drm_device
*dev
, struct drm_crtc
*crtc
,
2441 struct drm_display_mode
*mode
)
2443 struct drm_connector
*connector
;
2445 struct drm_display_mode
*dup_mode
;
2447 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
, head
) {
2448 if (!connector
->encoder
)
2450 if (connector
->encoder
->crtc
== crtc
) {
2452 dup_mode
= drm_mode_duplicate(dev
, mode
);
2455 ret
= drm_mode_attachmode(dev
, connector
, dup_mode
);
2463 EXPORT_SYMBOL(drm_mode_attachmode_crtc
);
2465 static int drm_mode_detachmode(struct drm_device
*dev
,
2466 struct drm_connector
*connector
,
2467 struct drm_display_mode
*mode
)
2471 struct drm_display_mode
*match_mode
, *t
;
2473 list_for_each_entry_safe(match_mode
, t
, &connector
->user_modes
, head
) {
2474 if (drm_mode_equal(match_mode
, mode
)) {
2475 list_del(&match_mode
->head
);
2476 drm_mode_destroy(dev
, match_mode
);
2488 int drm_mode_detachmode_crtc(struct drm_device
*dev
, struct drm_display_mode
*mode
)
2490 struct drm_connector
*connector
;
2492 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
, head
) {
2493 drm_mode_detachmode(dev
, connector
, mode
);
2497 EXPORT_SYMBOL(drm_mode_detachmode_crtc
);
2500 * drm_fb_attachmode - Attach a user mode to an connector
2501 * @inode: inode from the ioctl
2502 * @filp: file * from the ioctl
2503 * @cmd: cmd from ioctl
2504 * @arg: arg from ioctl
2506 * This attaches a user specified mode to an connector.
2507 * Called by the user via ioctl.
2510 * Zero on success, errno on failure.
2512 int drm_mode_attachmode_ioctl(struct drm_device
*dev
,
2513 void *data
, struct drm_file
*file_priv
)
2515 struct drm_mode_mode_cmd
*mode_cmd
= data
;
2516 struct drm_connector
*connector
;
2517 struct drm_display_mode
*mode
;
2518 struct drm_mode_object
*obj
;
2519 struct drm_mode_modeinfo
*umode
= &mode_cmd
->mode
;
2522 if (!drm_core_check_feature(dev
, DRIVER_MODESET
))
2525 mutex_lock(&dev
->mode_config
.mutex
);
2527 obj
= drm_mode_object_find(dev
, mode_cmd
->connector_id
, DRM_MODE_OBJECT_CONNECTOR
);
2532 connector
= obj_to_connector(obj
);
2534 mode
= drm_mode_create(dev
);
2540 drm_crtc_convert_umode(mode
, umode
);
2542 ret
= drm_mode_attachmode(dev
, connector
, mode
);
2544 mutex_unlock(&dev
->mode_config
.mutex
);
2550 * drm_fb_detachmode - Detach a user specified mode from an connector
2551 * @inode: inode from the ioctl
2552 * @filp: file * from the ioctl
2553 * @cmd: cmd from ioctl
2554 * @arg: arg from ioctl
2556 * Called by the user via ioctl.
2559 * Zero on success, errno on failure.
2561 int drm_mode_detachmode_ioctl(struct drm_device
*dev
,
2562 void *data
, struct drm_file
*file_priv
)
2564 struct drm_mode_object
*obj
;
2565 struct drm_mode_mode_cmd
*mode_cmd
= data
;
2566 struct drm_connector
*connector
;
2567 struct drm_display_mode mode
;
2568 struct drm_mode_modeinfo
*umode
= &mode_cmd
->mode
;
2571 if (!drm_core_check_feature(dev
, DRIVER_MODESET
))
2574 mutex_lock(&dev
->mode_config
.mutex
);
2576 obj
= drm_mode_object_find(dev
, mode_cmd
->connector_id
, DRM_MODE_OBJECT_CONNECTOR
);
2581 connector
= obj_to_connector(obj
);
2583 drm_crtc_convert_umode(&mode
, umode
);
2584 ret
= drm_mode_detachmode(dev
, connector
, &mode
);
2586 mutex_unlock(&dev
->mode_config
.mutex
);
2590 struct drm_property
*drm_property_create(struct drm_device
*dev
, int flags
,
2591 const char *name
, int num_values
)
2593 struct drm_property
*property
= NULL
;
2595 property
= kzalloc(sizeof(struct drm_property
), GFP_KERNEL
);
2600 property
->values
= kzalloc(sizeof(uint64_t)*num_values
, GFP_KERNEL
);
2601 if (!property
->values
)
2605 drm_mode_object_get(dev
, &property
->base
, DRM_MODE_OBJECT_PROPERTY
);
2606 property
->flags
= flags
;
2607 property
->num_values
= num_values
;
2608 INIT_LIST_HEAD(&property
->enum_blob_list
);
2611 strncpy(property
->name
, name
, DRM_PROP_NAME_LEN
);
2612 property
->name
[DRM_PROP_NAME_LEN
-1] = '\0';
2615 list_add_tail(&property
->head
, &dev
->mode_config
.property_list
);
2621 EXPORT_SYMBOL(drm_property_create
);
2623 int drm_property_add_enum(struct drm_property
*property
, int index
,
2624 uint64_t value
, const char *name
)
2626 struct drm_property_enum
*prop_enum
;
2628 if (!(property
->flags
& DRM_MODE_PROP_ENUM
))
2631 if (!list_empty(&property
->enum_blob_list
)) {
2632 list_for_each_entry(prop_enum
, &property
->enum_blob_list
, head
) {
2633 if (prop_enum
->value
== value
) {
2634 strncpy(prop_enum
->name
, name
, DRM_PROP_NAME_LEN
);
2635 prop_enum
->name
[DRM_PROP_NAME_LEN
-1] = '\0';
2641 prop_enum
= kzalloc(sizeof(struct drm_property_enum
), GFP_KERNEL
);
2645 strncpy(prop_enum
->name
, name
, DRM_PROP_NAME_LEN
);
2646 prop_enum
->name
[DRM_PROP_NAME_LEN
-1] = '\0';
2647 prop_enum
->value
= value
;
2649 property
->values
[index
] = value
;
2650 list_add_tail(&prop_enum
->head
, &property
->enum_blob_list
);
2653 EXPORT_SYMBOL(drm_property_add_enum
);
2655 void drm_property_destroy(struct drm_device
*dev
, struct drm_property
*property
)
2657 struct drm_property_enum
*prop_enum
, *pt
;
2659 list_for_each_entry_safe(prop_enum
, pt
, &property
->enum_blob_list
, head
) {
2660 list_del(&prop_enum
->head
);
2664 if (property
->num_values
)
2665 kfree(property
->values
);
2666 drm_mode_object_put(dev
, &property
->base
);
2667 list_del(&property
->head
);
2670 EXPORT_SYMBOL(drm_property_destroy
);
2672 int drm_connector_attach_property(struct drm_connector
*connector
,
2673 struct drm_property
*property
, uint64_t init_val
)
2677 for (i
= 0; i
< DRM_CONNECTOR_MAX_PROPERTY
; i
++) {
2678 if (connector
->property_ids
[i
] == 0) {
2679 connector
->property_ids
[i
] = property
->base
.id
;
2680 connector
->property_values
[i
] = init_val
;
2685 if (i
== DRM_CONNECTOR_MAX_PROPERTY
)
2689 EXPORT_SYMBOL(drm_connector_attach_property
);
2691 int drm_connector_property_set_value(struct drm_connector
*connector
,
2692 struct drm_property
*property
, uint64_t value
)
2696 for (i
= 0; i
< DRM_CONNECTOR_MAX_PROPERTY
; i
++) {
2697 if (connector
->property_ids
[i
] == property
->base
.id
) {
2698 connector
->property_values
[i
] = value
;
2703 if (i
== DRM_CONNECTOR_MAX_PROPERTY
)
2707 EXPORT_SYMBOL(drm_connector_property_set_value
);
2709 int drm_connector_property_get_value(struct drm_connector
*connector
,
2710 struct drm_property
*property
, uint64_t *val
)
2714 for (i
= 0; i
< DRM_CONNECTOR_MAX_PROPERTY
; i
++) {
2715 if (connector
->property_ids
[i
] == property
->base
.id
) {
2716 *val
= connector
->property_values
[i
];
2721 if (i
== DRM_CONNECTOR_MAX_PROPERTY
)
2725 EXPORT_SYMBOL(drm_connector_property_get_value
);
2727 int drm_mode_getproperty_ioctl(struct drm_device
*dev
,
2728 void *data
, struct drm_file
*file_priv
)
2730 struct drm_mode_object
*obj
;
2731 struct drm_mode_get_property
*out_resp
= data
;
2732 struct drm_property
*property
;
2735 int value_count
= 0;
2738 struct drm_property_enum
*prop_enum
;
2739 struct drm_mode_property_enum __user
*enum_ptr
;
2740 struct drm_property_blob
*prop_blob
;
2741 uint32_t __user
*blob_id_ptr
;
2742 uint64_t __user
*values_ptr
;
2743 uint32_t __user
*blob_length_ptr
;
2745 if (!drm_core_check_feature(dev
, DRIVER_MODESET
))
2748 mutex_lock(&dev
->mode_config
.mutex
);
2749 obj
= drm_mode_object_find(dev
, out_resp
->prop_id
, DRM_MODE_OBJECT_PROPERTY
);
2754 property
= obj_to_property(obj
);
2756 if (property
->flags
& DRM_MODE_PROP_ENUM
) {
2757 list_for_each_entry(prop_enum
, &property
->enum_blob_list
, head
)
2759 } else if (property
->flags
& DRM_MODE_PROP_BLOB
) {
2760 list_for_each_entry(prop_blob
, &property
->enum_blob_list
, head
)
2764 value_count
= property
->num_values
;
2766 strncpy(out_resp
->name
, property
->name
, DRM_PROP_NAME_LEN
);
2767 out_resp
->name
[DRM_PROP_NAME_LEN
-1] = 0;
2768 out_resp
->flags
= property
->flags
;
2770 if ((out_resp
->count_values
>= value_count
) && value_count
) {
2771 values_ptr
= (uint64_t __user
*)(unsigned long)out_resp
->values_ptr
;
2772 for (i
= 0; i
< value_count
; i
++) {
2773 if (copy_to_user(values_ptr
+ i
, &property
->values
[i
], sizeof(uint64_t))) {
2779 out_resp
->count_values
= value_count
;
2781 if (property
->flags
& DRM_MODE_PROP_ENUM
) {
2782 if ((out_resp
->count_enum_blobs
>= enum_count
) && enum_count
) {
2784 enum_ptr
= (struct drm_mode_property_enum __user
*)(unsigned long)out_resp
->enum_blob_ptr
;
2785 list_for_each_entry(prop_enum
, &property
->enum_blob_list
, head
) {
2787 if (copy_to_user(&enum_ptr
[copied
].value
, &prop_enum
->value
, sizeof(uint64_t))) {
2792 if (copy_to_user(&enum_ptr
[copied
].name
,
2793 &prop_enum
->name
, DRM_PROP_NAME_LEN
)) {
2800 out_resp
->count_enum_blobs
= enum_count
;
2803 if (property
->flags
& DRM_MODE_PROP_BLOB
) {
2804 if ((out_resp
->count_enum_blobs
>= blob_count
) && blob_count
) {
2806 blob_id_ptr
= (uint32_t __user
*)(unsigned long)out_resp
->enum_blob_ptr
;
2807 blob_length_ptr
= (uint32_t __user
*)(unsigned long)out_resp
->values_ptr
;
2809 list_for_each_entry(prop_blob
, &property
->enum_blob_list
, head
) {
2810 if (put_user(prop_blob
->base
.id
, blob_id_ptr
+ copied
)) {
2815 if (put_user(prop_blob
->length
, blob_length_ptr
+ copied
)) {
2823 out_resp
->count_enum_blobs
= blob_count
;
2826 mutex_unlock(&dev
->mode_config
.mutex
);
2830 static struct drm_property_blob
*drm_property_create_blob(struct drm_device
*dev
, int length
,
2833 struct drm_property_blob
*blob
;
2835 if (!length
|| !data
)
2838 blob
= kzalloc(sizeof(struct drm_property_blob
)+length
, GFP_KERNEL
);
2842 blob
->data
= (void *)((char *)blob
+ sizeof(struct drm_property_blob
));
2843 blob
->length
= length
;
2845 memcpy(blob
->data
, data
, length
);
2847 drm_mode_object_get(dev
, &blob
->base
, DRM_MODE_OBJECT_BLOB
);
2849 list_add_tail(&blob
->head
, &dev
->mode_config
.property_blob_list
);
2853 static void drm_property_destroy_blob(struct drm_device
*dev
,
2854 struct drm_property_blob
*blob
)
2856 drm_mode_object_put(dev
, &blob
->base
);
2857 list_del(&blob
->head
);
2861 int drm_mode_getblob_ioctl(struct drm_device
*dev
,
2862 void *data
, struct drm_file
*file_priv
)
2864 struct drm_mode_object
*obj
;
2865 struct drm_mode_get_blob
*out_resp
= data
;
2866 struct drm_property_blob
*blob
;
2868 void __user
*blob_ptr
;
2870 if (!drm_core_check_feature(dev
, DRIVER_MODESET
))
2873 mutex_lock(&dev
->mode_config
.mutex
);
2874 obj
= drm_mode_object_find(dev
, out_resp
->blob_id
, DRM_MODE_OBJECT_BLOB
);
2879 blob
= obj_to_blob(obj
);
2881 if (out_resp
->length
== blob
->length
) {
2882 blob_ptr
= (void __user
*)(unsigned long)out_resp
->data
;
2883 if (copy_to_user(blob_ptr
, blob
->data
, blob
->length
)){
2888 out_resp
->length
= blob
->length
;
2891 mutex_unlock(&dev
->mode_config
.mutex
);
2895 int drm_mode_connector_update_edid_property(struct drm_connector
*connector
,
2898 struct drm_device
*dev
= connector
->dev
;
2901 if (connector
->edid_blob_ptr
)
2902 drm_property_destroy_blob(dev
, connector
->edid_blob_ptr
);
2904 /* Delete edid, when there is none. */
2906 connector
->edid_blob_ptr
= NULL
;
2907 ret
= drm_connector_property_set_value(connector
, dev
->mode_config
.edid_property
, 0);
2911 size
= EDID_LENGTH
* (1 + edid
->extensions
);
2912 connector
->edid_blob_ptr
= drm_property_create_blob(connector
->dev
,
2915 ret
= drm_connector_property_set_value(connector
,
2916 dev
->mode_config
.edid_property
,
2917 connector
->edid_blob_ptr
->base
.id
);
2921 EXPORT_SYMBOL(drm_mode_connector_update_edid_property
);
2923 int drm_mode_connector_property_set_ioctl(struct drm_device
*dev
,
2924 void *data
, struct drm_file
*file_priv
)
2926 struct drm_mode_connector_set_property
*out_resp
= data
;
2927 struct drm_mode_object
*obj
;
2928 struct drm_property
*property
;
2929 struct drm_connector
*connector
;
2933 if (!drm_core_check_feature(dev
, DRIVER_MODESET
))
2936 mutex_lock(&dev
->mode_config
.mutex
);
2938 obj
= drm_mode_object_find(dev
, out_resp
->connector_id
, DRM_MODE_OBJECT_CONNECTOR
);
2942 connector
= obj_to_connector(obj
);
2944 for (i
= 0; i
< DRM_CONNECTOR_MAX_PROPERTY
; i
++) {
2945 if (connector
->property_ids
[i
] == out_resp
->prop_id
)
2949 if (i
== DRM_CONNECTOR_MAX_PROPERTY
) {
2953 obj
= drm_mode_object_find(dev
, out_resp
->prop_id
, DRM_MODE_OBJECT_PROPERTY
);
2957 property
= obj_to_property(obj
);
2959 if (property
->flags
& DRM_MODE_PROP_IMMUTABLE
)
2962 if (property
->flags
& DRM_MODE_PROP_RANGE
) {
2963 if (out_resp
->value
< property
->values
[0])
2966 if (out_resp
->value
> property
->values
[1])
2970 for (i
= 0; i
< property
->num_values
; i
++) {
2971 if (property
->values
[i
] == out_resp
->value
) {
2981 /* Do DPMS ourselves */
2982 if (property
== connector
->dev
->mode_config
.dpms_property
) {
2983 if (connector
->funcs
->dpms
)
2984 (*connector
->funcs
->dpms
)(connector
, (int) out_resp
->value
);
2986 } else if (connector
->funcs
->set_property
)
2987 ret
= connector
->funcs
->set_property(connector
, property
, out_resp
->value
);
2989 /* store the property value if successful */
2991 drm_connector_property_set_value(connector
, property
, out_resp
->value
);
2993 mutex_unlock(&dev
->mode_config
.mutex
);
2997 int drm_mode_connector_attach_encoder(struct drm_connector
*connector
,
2998 struct drm_encoder
*encoder
)
3002 for (i
= 0; i
< DRM_CONNECTOR_MAX_ENCODER
; i
++) {
3003 if (connector
->encoder_ids
[i
] == 0) {
3004 connector
->encoder_ids
[i
] = encoder
->base
.id
;
3010 EXPORT_SYMBOL(drm_mode_connector_attach_encoder
);
3012 void drm_mode_connector_detach_encoder(struct drm_connector
*connector
,
3013 struct drm_encoder
*encoder
)
3016 for (i
= 0; i
< DRM_CONNECTOR_MAX_ENCODER
; i
++) {
3017 if (connector
->encoder_ids
[i
] == encoder
->base
.id
) {
3018 connector
->encoder_ids
[i
] = 0;
3019 if (connector
->encoder
== encoder
)
3020 connector
->encoder
= NULL
;
3025 EXPORT_SYMBOL(drm_mode_connector_detach_encoder
);
3027 int drm_mode_crtc_set_gamma_size(struct drm_crtc
*crtc
,
3030 crtc
->gamma_size
= gamma_size
;
3032 crtc
->gamma_store
= kzalloc(gamma_size
* sizeof(uint16_t) * 3, GFP_KERNEL
);
3033 if (!crtc
->gamma_store
) {
3034 crtc
->gamma_size
= 0;
3040 EXPORT_SYMBOL(drm_mode_crtc_set_gamma_size
);
3042 int drm_mode_gamma_set_ioctl(struct drm_device
*dev
,
3043 void *data
, struct drm_file
*file_priv
)
3045 struct drm_mode_crtc_lut
*crtc_lut
= data
;
3046 struct drm_mode_object
*obj
;
3047 struct drm_crtc
*crtc
;
3048 void *r_base
, *g_base
, *b_base
;
3052 if (!drm_core_check_feature(dev
, DRIVER_MODESET
))
3055 mutex_lock(&dev
->mode_config
.mutex
);
3056 obj
= drm_mode_object_find(dev
, crtc_lut
->crtc_id
, DRM_MODE_OBJECT_CRTC
);
3061 crtc
= obj_to_crtc(obj
);
3063 /* memcpy into gamma store */
3064 if (crtc_lut
->gamma_size
!= crtc
->gamma_size
) {
3069 size
= crtc_lut
->gamma_size
* (sizeof(uint16_t));
3070 r_base
= crtc
->gamma_store
;
3071 if (copy_from_user(r_base
, (void __user
*)(unsigned long)crtc_lut
->red
, size
)) {
3076 g_base
= r_base
+ size
;
3077 if (copy_from_user(g_base
, (void __user
*)(unsigned long)crtc_lut
->green
, size
)) {
3082 b_base
= g_base
+ size
;
3083 if (copy_from_user(b_base
, (void __user
*)(unsigned long)crtc_lut
->blue
, size
)) {
3088 crtc
->funcs
->gamma_set(crtc
, r_base
, g_base
, b_base
, 0, crtc
->gamma_size
);
3091 mutex_unlock(&dev
->mode_config
.mutex
);
3096 int drm_mode_gamma_get_ioctl(struct drm_device
*dev
,
3097 void *data
, struct drm_file
*file_priv
)
3099 struct drm_mode_crtc_lut
*crtc_lut
= data
;
3100 struct drm_mode_object
*obj
;
3101 struct drm_crtc
*crtc
;
3102 void *r_base
, *g_base
, *b_base
;
3106 if (!drm_core_check_feature(dev
, DRIVER_MODESET
))
3109 mutex_lock(&dev
->mode_config
.mutex
);
3110 obj
= drm_mode_object_find(dev
, crtc_lut
->crtc_id
, DRM_MODE_OBJECT_CRTC
);
3115 crtc
= obj_to_crtc(obj
);
3117 /* memcpy into gamma store */
3118 if (crtc_lut
->gamma_size
!= crtc
->gamma_size
) {
3123 size
= crtc_lut
->gamma_size
* (sizeof(uint16_t));
3124 r_base
= crtc
->gamma_store
;
3125 if (copy_to_user((void __user
*)(unsigned long)crtc_lut
->red
, r_base
, size
)) {
3130 g_base
= r_base
+ size
;
3131 if (copy_to_user((void __user
*)(unsigned long)crtc_lut
->green
, g_base
, size
)) {
3136 b_base
= g_base
+ size
;
3137 if (copy_to_user((void __user
*)(unsigned long)crtc_lut
->blue
, b_base
, size
)) {
3142 mutex_unlock(&dev
->mode_config
.mutex
);
3146 int drm_mode_page_flip_ioctl(struct drm_device
*dev
,
3147 void *data
, struct drm_file
*file_priv
)
3149 struct drm_mode_crtc_page_flip
*page_flip
= data
;
3150 struct drm_mode_object
*obj
;
3151 struct drm_crtc
*crtc
;
3152 struct drm_framebuffer
*fb
;
3153 struct drm_pending_vblank_event
*e
= NULL
;
3154 unsigned long flags
;
3157 if (page_flip
->flags
& ~DRM_MODE_PAGE_FLIP_FLAGS
||
3158 page_flip
->reserved
!= 0)
3161 mutex_lock(&dev
->mode_config
.mutex
);
3162 obj
= drm_mode_object_find(dev
, page_flip
->crtc_id
, DRM_MODE_OBJECT_CRTC
);
3165 crtc
= obj_to_crtc(obj
);
3167 if (crtc
->fb
== NULL
) {
3168 /* The framebuffer is currently unbound, presumably
3169 * due to a hotplug event, that userspace has not
3176 if (crtc
->funcs
->page_flip
== NULL
)
3179 obj
= drm_mode_object_find(dev
, page_flip
->fb_id
, DRM_MODE_OBJECT_FB
);
3182 fb
= obj_to_fb(obj
);
3184 if (page_flip
->flags
& DRM_MODE_PAGE_FLIP_EVENT
) {
3186 spin_lock_irqsave(&dev
->event_lock
, flags
);
3187 if (file_priv
->event_space
< sizeof e
->event
) {
3188 spin_unlock_irqrestore(&dev
->event_lock
, flags
);
3191 file_priv
->event_space
-= sizeof e
->event
;
3192 spin_unlock_irqrestore(&dev
->event_lock
, flags
);
3194 e
= kzalloc(sizeof *e
, GFP_KERNEL
);
3196 spin_lock_irqsave(&dev
->event_lock
, flags
);
3197 file_priv
->event_space
+= sizeof e
->event
;
3198 spin_unlock_irqrestore(&dev
->event_lock
, flags
);
3202 e
->event
.base
.type
= DRM_EVENT_FLIP_COMPLETE
;
3203 e
->event
.base
.length
= sizeof e
->event
;
3204 e
->event
.user_data
= page_flip
->user_data
;
3205 e
->base
.event
= &e
->event
.base
;
3206 e
->base
.file_priv
= file_priv
;
3208 (void (*) (struct drm_pending_event
*)) kfree
;
3211 ret
= crtc
->funcs
->page_flip(crtc
, fb
, e
);
3213 spin_lock_irqsave(&dev
->event_lock
, flags
);
3214 file_priv
->event_space
+= sizeof e
->event
;
3215 spin_unlock_irqrestore(&dev
->event_lock
, flags
);
3220 mutex_unlock(&dev
->mode_config
.mutex
);
3224 void drm_mode_config_reset(struct drm_device
*dev
)
3226 struct drm_crtc
*crtc
;
3227 struct drm_encoder
*encoder
;
3228 struct drm_connector
*connector
;
3230 list_for_each_entry(crtc
, &dev
->mode_config
.crtc_list
, head
)
3231 if (crtc
->funcs
->reset
)
3232 crtc
->funcs
->reset(crtc
);
3234 list_for_each_entry(encoder
, &dev
->mode_config
.encoder_list
, head
)
3235 if (encoder
->funcs
->reset
)
3236 encoder
->funcs
->reset(encoder
);
3238 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
, head
)
3239 if (connector
->funcs
->reset
)
3240 connector
->funcs
->reset(connector
);
3242 EXPORT_SYMBOL(drm_mode_config_reset
);
3244 int drm_mode_create_dumb_ioctl(struct drm_device
*dev
,
3245 void *data
, struct drm_file
*file_priv
)
3247 struct drm_mode_create_dumb
*args
= data
;
3249 if (!dev
->driver
->dumb_create
)
3251 return dev
->driver
->dumb_create(file_priv
, dev
, args
);
3254 int drm_mode_mmap_dumb_ioctl(struct drm_device
*dev
,
3255 void *data
, struct drm_file
*file_priv
)
3257 struct drm_mode_map_dumb
*args
= data
;
3259 /* call driver ioctl to get mmap offset */
3260 if (!dev
->driver
->dumb_map_offset
)
3263 return dev
->driver
->dumb_map_offset(file_priv
, dev
, args
->handle
, &args
->offset
);
3266 int drm_mode_destroy_dumb_ioctl(struct drm_device
*dev
,
3267 void *data
, struct drm_file
*file_priv
)
3269 struct drm_mode_destroy_dumb
*args
= data
;
3271 if (!dev
->driver
->dumb_destroy
)
3274 return dev
->driver
->dumb_destroy(file_priv
, dev
, args
->handle
);
3278 * Just need to support RGB formats here for compat with code that doesn't
3279 * use pixel formats directly yet.
3281 void drm_fb_get_bpp_depth(uint32_t format
, unsigned int *depth
,
3285 case DRM_FORMAT_RGB332
:
3286 case DRM_FORMAT_BGR233
:
3290 case DRM_FORMAT_XRGB1555
:
3291 case DRM_FORMAT_XBGR1555
:
3292 case DRM_FORMAT_RGBX5551
:
3293 case DRM_FORMAT_BGRX5551
:
3294 case DRM_FORMAT_ARGB1555
:
3295 case DRM_FORMAT_ABGR1555
:
3296 case DRM_FORMAT_RGBA5551
:
3297 case DRM_FORMAT_BGRA5551
:
3301 case DRM_FORMAT_RGB565
:
3302 case DRM_FORMAT_BGR565
:
3306 case DRM_FORMAT_RGB888
:
3307 case DRM_FORMAT_BGR888
:
3311 case DRM_FORMAT_XRGB8888
:
3312 case DRM_FORMAT_XBGR8888
:
3313 case DRM_FORMAT_RGBX8888
:
3314 case DRM_FORMAT_BGRX8888
:
3318 case DRM_FORMAT_XRGB2101010
:
3319 case DRM_FORMAT_XBGR2101010
:
3320 case DRM_FORMAT_RGBX1010102
:
3321 case DRM_FORMAT_BGRX1010102
:
3322 case DRM_FORMAT_ARGB2101010
:
3323 case DRM_FORMAT_ABGR2101010
:
3324 case DRM_FORMAT_RGBA1010102
:
3325 case DRM_FORMAT_BGRA1010102
:
3329 case DRM_FORMAT_ARGB8888
:
3330 case DRM_FORMAT_ABGR8888
:
3331 case DRM_FORMAT_RGBA8888
:
3332 case DRM_FORMAT_BGRA8888
:
3337 DRM_DEBUG_KMS("unsupported pixel format\n");
3343 EXPORT_SYMBOL(drm_fb_get_bpp_depth
);