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 /* Avoid boilerplate. I'm tired of typing. */
42 #define DRM_ENUM_NAME_FN(fnname, list) \
43 char *fnname(int val) \
46 for (i = 0; i < ARRAY_SIZE(list); i++) { \
47 if (list[i].type == val) \
48 return list[i].name; \
56 static struct drm_prop_enum_list drm_dpms_enum_list
[] =
57 { { DRM_MODE_DPMS_ON
, "On" },
58 { DRM_MODE_DPMS_STANDBY
, "Standby" },
59 { DRM_MODE_DPMS_SUSPEND
, "Suspend" },
60 { DRM_MODE_DPMS_OFF
, "Off" }
63 DRM_ENUM_NAME_FN(drm_get_dpms_name
, drm_dpms_enum_list
)
68 static struct drm_prop_enum_list drm_scaling_mode_enum_list
[] =
70 { DRM_MODE_SCALE_NONE
, "None" },
71 { DRM_MODE_SCALE_FULLSCREEN
, "Full" },
72 { DRM_MODE_SCALE_CENTER
, "Center" },
73 { DRM_MODE_SCALE_ASPECT
, "Full aspect" },
76 static struct drm_prop_enum_list drm_dithering_mode_enum_list
[] =
78 { DRM_MODE_DITHERING_OFF
, "Off" },
79 { DRM_MODE_DITHERING_ON
, "On" },
80 { DRM_MODE_DITHERING_AUTO
, "Automatic" },
84 * Non-global properties, but "required" for certain connectors.
86 static struct drm_prop_enum_list drm_dvi_i_select_enum_list
[] =
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 */
93 DRM_ENUM_NAME_FN(drm_get_dvi_i_select_name
, drm_dvi_i_select_enum_list
)
95 static struct drm_prop_enum_list drm_dvi_i_subconnector_enum_list
[] =
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 */
102 DRM_ENUM_NAME_FN(drm_get_dvi_i_subconnector_name
,
103 drm_dvi_i_subconnector_enum_list
)
105 static struct drm_prop_enum_list drm_tv_select_enum_list
[] =
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 */
111 { DRM_MODE_SUBCONNECTOR_SCART
, "SCART" }, /* TV-out */
114 DRM_ENUM_NAME_FN(drm_get_tv_select_name
, drm_tv_select_enum_list
)
116 static struct drm_prop_enum_list drm_tv_subconnector_enum_list
[] =
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 */
122 { DRM_MODE_SUBCONNECTOR_SCART
, "SCART" }, /* TV-out */
125 DRM_ENUM_NAME_FN(drm_get_tv_subconnector_name
,
126 drm_tv_subconnector_enum_list
)
128 static struct drm_prop_enum_list drm_dirty_info_enum_list
[] = {
129 { DRM_MODE_DIRTY_OFF
, "Off" },
130 { DRM_MODE_DIRTY_ON
, "On" },
131 { DRM_MODE_DIRTY_ANNOTATE
, "Annotate" },
134 DRM_ENUM_NAME_FN(drm_get_dirty_info_name
,
135 drm_dirty_info_enum_list
)
137 struct drm_conn_prop_enum_list
{
144 * Connector and encoder types.
146 static struct drm_conn_prop_enum_list drm_connector_enum_list
[] =
147 { { DRM_MODE_CONNECTOR_Unknown
, "Unknown", 0 },
148 { DRM_MODE_CONNECTOR_VGA
, "VGA", 0 },
149 { DRM_MODE_CONNECTOR_DVII
, "DVI-I", 0 },
150 { DRM_MODE_CONNECTOR_DVID
, "DVI-D", 0 },
151 { DRM_MODE_CONNECTOR_DVIA
, "DVI-A", 0 },
152 { DRM_MODE_CONNECTOR_Composite
, "Composite", 0 },
153 { DRM_MODE_CONNECTOR_SVIDEO
, "SVIDEO", 0 },
154 { DRM_MODE_CONNECTOR_LVDS
, "LVDS", 0 },
155 { DRM_MODE_CONNECTOR_Component
, "Component", 0 },
156 { DRM_MODE_CONNECTOR_9PinDIN
, "DIN", 0 },
157 { DRM_MODE_CONNECTOR_DisplayPort
, "DP", 0 },
158 { DRM_MODE_CONNECTOR_HDMIA
, "HDMI-A", 0 },
159 { DRM_MODE_CONNECTOR_HDMIB
, "HDMI-B", 0 },
160 { DRM_MODE_CONNECTOR_TV
, "TV", 0 },
161 { DRM_MODE_CONNECTOR_eDP
, "eDP", 0 },
162 { DRM_MODE_CONNECTOR_VIRTUAL
, "Virtual", 0},
165 static struct drm_prop_enum_list drm_encoder_enum_list
[] =
166 { { DRM_MODE_ENCODER_NONE
, "None" },
167 { DRM_MODE_ENCODER_DAC
, "DAC" },
168 { DRM_MODE_ENCODER_TMDS
, "TMDS" },
169 { DRM_MODE_ENCODER_LVDS
, "LVDS" },
170 { DRM_MODE_ENCODER_TVDAC
, "TV" },
171 { DRM_MODE_ENCODER_VIRTUAL
, "Virtual" },
174 char *drm_get_encoder_name(struct drm_encoder
*encoder
)
178 snprintf(buf
, 32, "%s-%d",
179 drm_encoder_enum_list
[encoder
->encoder_type
].name
,
183 EXPORT_SYMBOL(drm_get_encoder_name
);
185 char *drm_get_connector_name(struct drm_connector
*connector
)
189 snprintf(buf
, 32, "%s-%d",
190 drm_connector_enum_list
[connector
->connector_type
].name
,
191 connector
->connector_type_id
);
194 EXPORT_SYMBOL(drm_get_connector_name
);
196 char *drm_get_connector_status_name(enum drm_connector_status status
)
198 if (status
== connector_status_connected
)
200 else if (status
== connector_status_disconnected
)
201 return "disconnected";
207 * drm_mode_object_get - allocate a new identifier
209 * @ptr: object pointer, used to generate unique ID
214 * Create a unique identifier based on @ptr in @dev's identifier space. Used
215 * for tracking modes, CRTCs and connectors.
218 * New unique (relative to other objects in @dev) integer identifier for the
221 static int drm_mode_object_get(struct drm_device
*dev
,
222 struct drm_mode_object
*obj
, uint32_t obj_type
)
228 if (idr_pre_get(&dev
->mode_config
.crtc_idr
, GFP_KERNEL
) == 0) {
229 DRM_ERROR("Ran out memory getting a mode number\n");
233 mutex_lock(&dev
->mode_config
.idr_mutex
);
234 ret
= idr_get_new_above(&dev
->mode_config
.crtc_idr
, obj
, 1, &new_id
);
235 mutex_unlock(&dev
->mode_config
.idr_mutex
);
240 obj
->type
= obj_type
;
245 * drm_mode_object_put - free an identifer
250 * Caller must hold DRM mode_config lock.
252 * Free @id from @dev's unique identifier pool.
254 static void drm_mode_object_put(struct drm_device
*dev
,
255 struct drm_mode_object
*object
)
257 mutex_lock(&dev
->mode_config
.idr_mutex
);
258 idr_remove(&dev
->mode_config
.crtc_idr
, object
->id
);
259 mutex_unlock(&dev
->mode_config
.idr_mutex
);
262 struct drm_mode_object
*drm_mode_object_find(struct drm_device
*dev
,
263 uint32_t id
, uint32_t type
)
265 struct drm_mode_object
*obj
= NULL
;
267 mutex_lock(&dev
->mode_config
.idr_mutex
);
268 obj
= idr_find(&dev
->mode_config
.crtc_idr
, id
);
269 if (!obj
|| (obj
->type
!= type
) || (obj
->id
!= id
))
271 mutex_unlock(&dev
->mode_config
.idr_mutex
);
275 EXPORT_SYMBOL(drm_mode_object_find
);
278 * drm_framebuffer_init - initialize a framebuffer
282 * Caller must hold mode config lock.
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.
288 * Zero on success, error code on failure.
290 int drm_framebuffer_init(struct drm_device
*dev
, struct drm_framebuffer
*fb
,
291 const struct drm_framebuffer_funcs
*funcs
)
295 ret
= drm_mode_object_get(dev
, &fb
->base
, DRM_MODE_OBJECT_FB
);
301 dev
->mode_config
.num_fb
++;
302 list_add(&fb
->head
, &dev
->mode_config
.fb_list
);
306 EXPORT_SYMBOL(drm_framebuffer_init
);
309 * drm_framebuffer_cleanup - remove a framebuffer object
310 * @fb: framebuffer to remove
313 * Caller must hold mode config lock.
315 * Scans all the CRTCs in @dev's mode_config. If they're using @fb, removes
316 * it, setting it to NULL.
318 void drm_framebuffer_cleanup(struct drm_framebuffer
*fb
)
320 struct drm_device
*dev
= fb
->dev
;
321 struct drm_crtc
*crtc
;
322 struct drm_plane
*plane
;
323 struct drm_mode_set set
;
326 /* remove from any CRTC */
327 list_for_each_entry(crtc
, &dev
->mode_config
.crtc_list
, head
) {
328 if (crtc
->fb
== fb
) {
329 /* should turn off the crtc */
330 memset(&set
, 0, sizeof(struct drm_mode_set
));
333 ret
= crtc
->funcs
->set_config(&set
);
335 DRM_ERROR("failed to reset crtc %p when fb was deleted\n", crtc
);
339 list_for_each_entry(plane
, &dev
->mode_config
.plane_list
, head
) {
340 if (plane
->fb
== fb
) {
341 /* should turn off the crtc */
342 ret
= plane
->funcs
->disable_plane(plane
);
344 DRM_ERROR("failed to disable plane with busy fb\n");
345 /* disconnect the plane from the fb and crtc: */
351 drm_mode_object_put(dev
, &fb
->base
);
353 dev
->mode_config
.num_fb
--;
355 EXPORT_SYMBOL(drm_framebuffer_cleanup
);
358 * drm_crtc_init - Initialise a new CRTC object
360 * @crtc: CRTC object to init
361 * @funcs: callbacks for the new CRTC
364 * Caller must hold mode config lock.
366 * Inits a new object created as base part of an driver crtc object.
369 * Zero on success, error code on failure.
371 int drm_crtc_init(struct drm_device
*dev
, struct drm_crtc
*crtc
,
372 const struct drm_crtc_funcs
*funcs
)
379 mutex_lock(&dev
->mode_config
.mutex
);
381 ret
= drm_mode_object_get(dev
, &crtc
->base
, DRM_MODE_OBJECT_CRTC
);
385 list_add_tail(&crtc
->head
, &dev
->mode_config
.crtc_list
);
386 dev
->mode_config
.num_crtc
++;
389 mutex_unlock(&dev
->mode_config
.mutex
);
393 EXPORT_SYMBOL(drm_crtc_init
);
396 * drm_crtc_cleanup - Cleans up the core crtc usage.
397 * @crtc: CRTC to cleanup
400 * Caller must hold mode config lock.
402 * Cleanup @crtc. Removes from drm modesetting space
403 * does NOT free object, caller does that.
405 void drm_crtc_cleanup(struct drm_crtc
*crtc
)
407 struct drm_device
*dev
= crtc
->dev
;
409 if (crtc
->gamma_store
) {
410 kfree(crtc
->gamma_store
);
411 crtc
->gamma_store
= NULL
;
414 drm_mode_object_put(dev
, &crtc
->base
);
415 list_del(&crtc
->head
);
416 dev
->mode_config
.num_crtc
--;
418 EXPORT_SYMBOL(drm_crtc_cleanup
);
421 * drm_mode_probed_add - add a mode to a connector's probed mode list
422 * @connector: connector the new mode
426 * Caller must hold mode config lock.
428 * Add @mode to @connector's mode list for later use.
430 void drm_mode_probed_add(struct drm_connector
*connector
,
431 struct drm_display_mode
*mode
)
433 list_add(&mode
->head
, &connector
->probed_modes
);
435 EXPORT_SYMBOL(drm_mode_probed_add
);
438 * drm_mode_remove - remove and free a mode
439 * @connector: connector list to modify
440 * @mode: mode to remove
443 * Caller must hold mode config lock.
445 * Remove @mode from @connector's mode list, then free it.
447 void drm_mode_remove(struct drm_connector
*connector
,
448 struct drm_display_mode
*mode
)
450 list_del(&mode
->head
);
451 drm_mode_destroy(connector
->dev
, mode
);
453 EXPORT_SYMBOL(drm_mode_remove
);
456 * drm_connector_init - Init a preallocated connector
458 * @connector: the connector to init
459 * @funcs: callbacks for this connector
460 * @name: user visible name of the connector
463 * Takes mode config lock.
465 * Initialises a preallocated connector. Connectors should be
466 * subclassed as part of driver connector objects.
469 * Zero on success, error code on failure.
471 int drm_connector_init(struct drm_device
*dev
,
472 struct drm_connector
*connector
,
473 const struct drm_connector_funcs
*funcs
,
478 mutex_lock(&dev
->mode_config
.mutex
);
480 ret
= drm_mode_object_get(dev
, &connector
->base
, DRM_MODE_OBJECT_CONNECTOR
);
484 connector
->dev
= dev
;
485 connector
->funcs
= funcs
;
486 connector
->connector_type
= connector_type
;
487 connector
->connector_type_id
=
488 ++drm_connector_enum_list
[connector_type
].count
; /* TODO */
489 INIT_LIST_HEAD(&connector
->user_modes
);
490 INIT_LIST_HEAD(&connector
->probed_modes
);
491 INIT_LIST_HEAD(&connector
->modes
);
492 connector
->edid_blob_ptr
= NULL
;
494 list_add_tail(&connector
->head
, &dev
->mode_config
.connector_list
);
495 dev
->mode_config
.num_connector
++;
497 if (connector_type
!= DRM_MODE_CONNECTOR_VIRTUAL
)
498 drm_connector_attach_property(connector
,
499 dev
->mode_config
.edid_property
,
502 drm_connector_attach_property(connector
,
503 dev
->mode_config
.dpms_property
, 0);
506 mutex_unlock(&dev
->mode_config
.mutex
);
510 EXPORT_SYMBOL(drm_connector_init
);
513 * drm_connector_cleanup - cleans up an initialised connector
514 * @connector: connector to cleanup
517 * Takes mode config lock.
519 * Cleans up the connector but doesn't free the object.
521 void drm_connector_cleanup(struct drm_connector
*connector
)
523 struct drm_device
*dev
= connector
->dev
;
524 struct drm_display_mode
*mode
, *t
;
526 list_for_each_entry_safe(mode
, t
, &connector
->probed_modes
, head
)
527 drm_mode_remove(connector
, mode
);
529 list_for_each_entry_safe(mode
, t
, &connector
->modes
, head
)
530 drm_mode_remove(connector
, mode
);
532 list_for_each_entry_safe(mode
, t
, &connector
->user_modes
, head
)
533 drm_mode_remove(connector
, mode
);
535 mutex_lock(&dev
->mode_config
.mutex
);
536 drm_mode_object_put(dev
, &connector
->base
);
537 list_del(&connector
->head
);
538 dev
->mode_config
.num_connector
--;
539 mutex_unlock(&dev
->mode_config
.mutex
);
541 EXPORT_SYMBOL(drm_connector_cleanup
);
543 void drm_connector_unplug_all(struct drm_device
*dev
)
545 struct drm_connector
*connector
;
547 /* taking the mode config mutex ends up in a clash with sysfs */
548 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
, head
)
549 drm_sysfs_connector_remove(connector
);
552 EXPORT_SYMBOL(drm_connector_unplug_all
);
554 int drm_encoder_init(struct drm_device
*dev
,
555 struct drm_encoder
*encoder
,
556 const struct drm_encoder_funcs
*funcs
,
561 mutex_lock(&dev
->mode_config
.mutex
);
563 ret
= drm_mode_object_get(dev
, &encoder
->base
, DRM_MODE_OBJECT_ENCODER
);
568 encoder
->encoder_type
= encoder_type
;
569 encoder
->funcs
= funcs
;
571 list_add_tail(&encoder
->head
, &dev
->mode_config
.encoder_list
);
572 dev
->mode_config
.num_encoder
++;
575 mutex_unlock(&dev
->mode_config
.mutex
);
579 EXPORT_SYMBOL(drm_encoder_init
);
581 void drm_encoder_cleanup(struct drm_encoder
*encoder
)
583 struct drm_device
*dev
= encoder
->dev
;
584 mutex_lock(&dev
->mode_config
.mutex
);
585 drm_mode_object_put(dev
, &encoder
->base
);
586 list_del(&encoder
->head
);
587 dev
->mode_config
.num_encoder
--;
588 mutex_unlock(&dev
->mode_config
.mutex
);
590 EXPORT_SYMBOL(drm_encoder_cleanup
);
592 int drm_plane_init(struct drm_device
*dev
, struct drm_plane
*plane
,
593 unsigned long possible_crtcs
,
594 const struct drm_plane_funcs
*funcs
,
595 const uint32_t *formats
, uint32_t format_count
,
600 mutex_lock(&dev
->mode_config
.mutex
);
602 ret
= drm_mode_object_get(dev
, &plane
->base
, DRM_MODE_OBJECT_PLANE
);
607 plane
->funcs
= funcs
;
608 plane
->format_types
= kmalloc(sizeof(uint32_t) * format_count
,
610 if (!plane
->format_types
) {
611 DRM_DEBUG_KMS("out of memory when allocating plane\n");
612 drm_mode_object_put(dev
, &plane
->base
);
617 memcpy(plane
->format_types
, formats
, format_count
* sizeof(uint32_t));
618 plane
->format_count
= format_count
;
619 plane
->possible_crtcs
= possible_crtcs
;
621 /* private planes are not exposed to userspace, but depending on
622 * display hardware, might be convenient to allow sharing programming
623 * for the scanout engine with the crtc implementation.
626 list_add_tail(&plane
->head
, &dev
->mode_config
.plane_list
);
627 dev
->mode_config
.num_plane
++;
629 INIT_LIST_HEAD(&plane
->head
);
633 mutex_unlock(&dev
->mode_config
.mutex
);
637 EXPORT_SYMBOL(drm_plane_init
);
639 void drm_plane_cleanup(struct drm_plane
*plane
)
641 struct drm_device
*dev
= plane
->dev
;
643 mutex_lock(&dev
->mode_config
.mutex
);
644 kfree(plane
->format_types
);
645 drm_mode_object_put(dev
, &plane
->base
);
646 /* if not added to a list, it must be a private plane */
647 if (!list_empty(&plane
->head
)) {
648 list_del(&plane
->head
);
649 dev
->mode_config
.num_plane
--;
651 mutex_unlock(&dev
->mode_config
.mutex
);
653 EXPORT_SYMBOL(drm_plane_cleanup
);
656 * drm_mode_create - create a new display mode
660 * Caller must hold DRM mode_config lock.
662 * Create a new drm_display_mode, give it an ID, and return it.
665 * Pointer to new mode on success, NULL on error.
667 struct drm_display_mode
*drm_mode_create(struct drm_device
*dev
)
669 struct drm_display_mode
*nmode
;
671 nmode
= kzalloc(sizeof(struct drm_display_mode
), GFP_KERNEL
);
675 if (drm_mode_object_get(dev
, &nmode
->base
, DRM_MODE_OBJECT_MODE
)) {
682 EXPORT_SYMBOL(drm_mode_create
);
685 * drm_mode_destroy - remove a mode
687 * @mode: mode to remove
690 * Caller must hold mode config lock.
692 * Free @mode's unique identifier, then free it.
694 void drm_mode_destroy(struct drm_device
*dev
, struct drm_display_mode
*mode
)
699 drm_mode_object_put(dev
, &mode
->base
);
703 EXPORT_SYMBOL(drm_mode_destroy
);
705 static int drm_mode_create_standard_connector_properties(struct drm_device
*dev
)
707 struct drm_property
*edid
;
708 struct drm_property
*dpms
;
711 * Standard properties (apply to all connectors)
713 edid
= drm_property_create(dev
, DRM_MODE_PROP_BLOB
|
714 DRM_MODE_PROP_IMMUTABLE
,
716 dev
->mode_config
.edid_property
= edid
;
718 dpms
= drm_property_create_enum(dev
, 0,
719 "DPMS", drm_dpms_enum_list
,
720 ARRAY_SIZE(drm_dpms_enum_list
));
721 dev
->mode_config
.dpms_property
= dpms
;
727 * drm_mode_create_dvi_i_properties - create DVI-I specific connector properties
730 * Called by a driver the first time a DVI-I connector is made.
732 int drm_mode_create_dvi_i_properties(struct drm_device
*dev
)
734 struct drm_property
*dvi_i_selector
;
735 struct drm_property
*dvi_i_subconnector
;
737 if (dev
->mode_config
.dvi_i_select_subconnector_property
)
741 drm_property_create_enum(dev
, 0,
742 "select subconnector",
743 drm_dvi_i_select_enum_list
,
744 ARRAY_SIZE(drm_dvi_i_select_enum_list
));
745 dev
->mode_config
.dvi_i_select_subconnector_property
= dvi_i_selector
;
747 dvi_i_subconnector
= drm_property_create_enum(dev
, DRM_MODE_PROP_IMMUTABLE
,
749 drm_dvi_i_subconnector_enum_list
,
750 ARRAY_SIZE(drm_dvi_i_subconnector_enum_list
));
751 dev
->mode_config
.dvi_i_subconnector_property
= dvi_i_subconnector
;
755 EXPORT_SYMBOL(drm_mode_create_dvi_i_properties
);
758 * drm_create_tv_properties - create TV specific connector properties
760 * @num_modes: number of different TV formats (modes) supported
761 * @modes: array of pointers to strings containing name of each format
763 * Called by a driver's TV initialization routine, this function creates
764 * the TV specific connector properties for a given device. Caller is
765 * responsible for allocating a list of format names and passing them to
768 int drm_mode_create_tv_properties(struct drm_device
*dev
, int num_modes
,
771 struct drm_property
*tv_selector
;
772 struct drm_property
*tv_subconnector
;
775 if (dev
->mode_config
.tv_select_subconnector_property
)
779 * Basic connector properties
781 tv_selector
= drm_property_create_enum(dev
, 0,
782 "select subconnector",
783 drm_tv_select_enum_list
,
784 ARRAY_SIZE(drm_tv_select_enum_list
));
785 dev
->mode_config
.tv_select_subconnector_property
= tv_selector
;
788 drm_property_create_enum(dev
, DRM_MODE_PROP_IMMUTABLE
,
790 drm_tv_subconnector_enum_list
,
791 ARRAY_SIZE(drm_tv_subconnector_enum_list
));
792 dev
->mode_config
.tv_subconnector_property
= tv_subconnector
;
795 * Other, TV specific properties: margins & TV modes.
797 dev
->mode_config
.tv_left_margin_property
=
798 drm_property_create_range(dev
, 0, "left margin", 0, 100);
800 dev
->mode_config
.tv_right_margin_property
=
801 drm_property_create_range(dev
, 0, "right margin", 0, 100);
803 dev
->mode_config
.tv_top_margin_property
=
804 drm_property_create_range(dev
, 0, "top margin", 0, 100);
806 dev
->mode_config
.tv_bottom_margin_property
=
807 drm_property_create_range(dev
, 0, "bottom margin", 0, 100);
809 dev
->mode_config
.tv_mode_property
=
810 drm_property_create(dev
, DRM_MODE_PROP_ENUM
,
812 for (i
= 0; i
< num_modes
; i
++)
813 drm_property_add_enum(dev
->mode_config
.tv_mode_property
, i
,
816 dev
->mode_config
.tv_brightness_property
=
817 drm_property_create_range(dev
, 0, "brightness", 0, 100);
819 dev
->mode_config
.tv_contrast_property
=
820 drm_property_create_range(dev
, 0, "contrast", 0, 100);
822 dev
->mode_config
.tv_flicker_reduction_property
=
823 drm_property_create_range(dev
, 0, "flicker reduction", 0, 100);
825 dev
->mode_config
.tv_overscan_property
=
826 drm_property_create_range(dev
, 0, "overscan", 0, 100);
828 dev
->mode_config
.tv_saturation_property
=
829 drm_property_create_range(dev
, 0, "saturation", 0, 100);
831 dev
->mode_config
.tv_hue_property
=
832 drm_property_create_range(dev
, 0, "hue", 0, 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
;
849 if (dev
->mode_config
.scaling_mode_property
)
853 drm_property_create_enum(dev
, 0, "scaling mode",
854 drm_scaling_mode_enum_list
,
855 ARRAY_SIZE(drm_scaling_mode_enum_list
));
857 dev
->mode_config
.scaling_mode_property
= scaling_mode
;
861 EXPORT_SYMBOL(drm_mode_create_scaling_mode_property
);
864 * drm_mode_create_dithering_property - create dithering property
867 * Called by a driver the first time it's needed, must be attached to desired
870 int drm_mode_create_dithering_property(struct drm_device
*dev
)
872 struct drm_property
*dithering_mode
;
874 if (dev
->mode_config
.dithering_mode_property
)
878 drm_property_create_enum(dev
, 0, "dithering",
879 drm_dithering_mode_enum_list
,
880 ARRAY_SIZE(drm_dithering_mode_enum_list
));
881 dev
->mode_config
.dithering_mode_property
= dithering_mode
;
885 EXPORT_SYMBOL(drm_mode_create_dithering_property
);
888 * drm_mode_create_dirty_property - create dirty property
891 * Called by a driver the first time it's needed, must be attached to desired
894 int drm_mode_create_dirty_info_property(struct drm_device
*dev
)
896 struct drm_property
*dirty_info
;
898 if (dev
->mode_config
.dirty_info_property
)
902 drm_property_create_enum(dev
, DRM_MODE_PROP_IMMUTABLE
,
904 drm_dirty_info_enum_list
,
905 ARRAY_SIZE(drm_dirty_info_enum_list
));
906 dev
->mode_config
.dirty_info_property
= dirty_info
;
910 EXPORT_SYMBOL(drm_mode_create_dirty_info_property
);
913 * drm_mode_config_init - initialize DRM mode_configuration structure
917 * None, should happen single threaded at init time.
919 * Initialize @dev's mode_config structure, used for tracking the graphics
920 * configuration of @dev.
922 void drm_mode_config_init(struct drm_device
*dev
)
924 mutex_init(&dev
->mode_config
.mutex
);
925 mutex_init(&dev
->mode_config
.idr_mutex
);
926 INIT_LIST_HEAD(&dev
->mode_config
.fb_list
);
927 INIT_LIST_HEAD(&dev
->mode_config
.crtc_list
);
928 INIT_LIST_HEAD(&dev
->mode_config
.connector_list
);
929 INIT_LIST_HEAD(&dev
->mode_config
.encoder_list
);
930 INIT_LIST_HEAD(&dev
->mode_config
.property_list
);
931 INIT_LIST_HEAD(&dev
->mode_config
.property_blob_list
);
932 INIT_LIST_HEAD(&dev
->mode_config
.plane_list
);
933 idr_init(&dev
->mode_config
.crtc_idr
);
935 mutex_lock(&dev
->mode_config
.mutex
);
936 drm_mode_create_standard_connector_properties(dev
);
937 mutex_unlock(&dev
->mode_config
.mutex
);
939 /* Just to be sure */
940 dev
->mode_config
.num_fb
= 0;
941 dev
->mode_config
.num_connector
= 0;
942 dev
->mode_config
.num_crtc
= 0;
943 dev
->mode_config
.num_encoder
= 0;
945 EXPORT_SYMBOL(drm_mode_config_init
);
947 int drm_mode_group_init(struct drm_device
*dev
, struct drm_mode_group
*group
)
949 uint32_t total_objects
= 0;
951 total_objects
+= dev
->mode_config
.num_crtc
;
952 total_objects
+= dev
->mode_config
.num_connector
;
953 total_objects
+= dev
->mode_config
.num_encoder
;
955 group
->id_list
= kzalloc(total_objects
* sizeof(uint32_t), GFP_KERNEL
);
959 group
->num_crtcs
= 0;
960 group
->num_connectors
= 0;
961 group
->num_encoders
= 0;
965 int drm_mode_group_init_legacy_group(struct drm_device
*dev
,
966 struct drm_mode_group
*group
)
968 struct drm_crtc
*crtc
;
969 struct drm_encoder
*encoder
;
970 struct drm_connector
*connector
;
973 if ((ret
= drm_mode_group_init(dev
, group
)))
976 list_for_each_entry(crtc
, &dev
->mode_config
.crtc_list
, head
)
977 group
->id_list
[group
->num_crtcs
++] = crtc
->base
.id
;
979 list_for_each_entry(encoder
, &dev
->mode_config
.encoder_list
, head
)
980 group
->id_list
[group
->num_crtcs
+ group
->num_encoders
++] =
983 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
, head
)
984 group
->id_list
[group
->num_crtcs
+ group
->num_encoders
+
985 group
->num_connectors
++] = connector
->base
.id
;
991 * drm_mode_config_cleanup - free up DRM mode_config info
995 * Caller must hold mode config lock.
997 * Free up all the connectors and CRTCs associated with this DRM device, then
998 * free up the framebuffers and associated buffer objects.
1000 * FIXME: cleanup any dangling user buffer objects too
1002 void drm_mode_config_cleanup(struct drm_device
*dev
)
1004 struct drm_connector
*connector
, *ot
;
1005 struct drm_crtc
*crtc
, *ct
;
1006 struct drm_encoder
*encoder
, *enct
;
1007 struct drm_framebuffer
*fb
, *fbt
;
1008 struct drm_property
*property
, *pt
;
1009 struct drm_plane
*plane
, *plt
;
1011 list_for_each_entry_safe(encoder
, enct
, &dev
->mode_config
.encoder_list
,
1013 encoder
->funcs
->destroy(encoder
);
1016 list_for_each_entry_safe(connector
, ot
,
1017 &dev
->mode_config
.connector_list
, head
) {
1018 connector
->funcs
->destroy(connector
);
1021 list_for_each_entry_safe(property
, pt
, &dev
->mode_config
.property_list
,
1023 drm_property_destroy(dev
, property
);
1026 list_for_each_entry_safe(fb
, fbt
, &dev
->mode_config
.fb_list
, head
) {
1027 fb
->funcs
->destroy(fb
);
1030 list_for_each_entry_safe(crtc
, ct
, &dev
->mode_config
.crtc_list
, head
) {
1031 crtc
->funcs
->destroy(crtc
);
1034 list_for_each_entry_safe(plane
, plt
, &dev
->mode_config
.plane_list
,
1036 plane
->funcs
->destroy(plane
);
1039 idr_remove_all(&dev
->mode_config
.crtc_idr
);
1040 idr_destroy(&dev
->mode_config
.crtc_idr
);
1042 EXPORT_SYMBOL(drm_mode_config_cleanup
);
1045 * drm_crtc_convert_to_umode - convert a drm_display_mode into a modeinfo
1046 * @out: drm_mode_modeinfo struct to return to the user
1047 * @in: drm_display_mode to use
1052 * Convert a drm_display_mode into a drm_mode_modeinfo structure to return to
1055 static void drm_crtc_convert_to_umode(struct drm_mode_modeinfo
*out
,
1056 const struct drm_display_mode
*in
)
1058 WARN(in
->hdisplay
> USHRT_MAX
|| in
->hsync_start
> USHRT_MAX
||
1059 in
->hsync_end
> USHRT_MAX
|| in
->htotal
> USHRT_MAX
||
1060 in
->hskew
> USHRT_MAX
|| in
->vdisplay
> USHRT_MAX
||
1061 in
->vsync_start
> USHRT_MAX
|| in
->vsync_end
> USHRT_MAX
||
1062 in
->vtotal
> USHRT_MAX
|| in
->vscan
> USHRT_MAX
,
1063 "timing values too large for mode info\n");
1065 out
->clock
= in
->clock
;
1066 out
->hdisplay
= in
->hdisplay
;
1067 out
->hsync_start
= in
->hsync_start
;
1068 out
->hsync_end
= in
->hsync_end
;
1069 out
->htotal
= in
->htotal
;
1070 out
->hskew
= in
->hskew
;
1071 out
->vdisplay
= in
->vdisplay
;
1072 out
->vsync_start
= in
->vsync_start
;
1073 out
->vsync_end
= in
->vsync_end
;
1074 out
->vtotal
= in
->vtotal
;
1075 out
->vscan
= in
->vscan
;
1076 out
->vrefresh
= in
->vrefresh
;
1077 out
->flags
= in
->flags
;
1078 out
->type
= in
->type
;
1079 strncpy(out
->name
, in
->name
, DRM_DISPLAY_MODE_LEN
);
1080 out
->name
[DRM_DISPLAY_MODE_LEN
-1] = 0;
1084 * drm_crtc_convert_to_umode - convert a modeinfo into a drm_display_mode
1085 * @out: drm_display_mode to return to the user
1086 * @in: drm_mode_modeinfo to use
1091 * Convert a drm_mode_modeinfo into a drm_display_mode structure to return to
1095 * Zero on success, errno on failure.
1097 static int drm_crtc_convert_umode(struct drm_display_mode
*out
,
1098 const struct drm_mode_modeinfo
*in
)
1100 if (in
->clock
> INT_MAX
|| in
->vrefresh
> INT_MAX
)
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;
1124 * drm_mode_getresources - get graphics configuration
1125 * @inode: inode from the ioctl
1126 * @filp: file * from the ioctl
1127 * @cmd: cmd from ioctl
1128 * @arg: arg from ioctl
1131 * Takes mode config lock.
1133 * Construct a set of configuration description structures and return
1134 * them to the user, including CRTC, connector and framebuffer configuration.
1136 * Called by the user via ioctl.
1139 * Zero on success, errno on failure.
1141 int drm_mode_getresources(struct drm_device
*dev
, void *data
,
1142 struct drm_file
*file_priv
)
1144 struct drm_mode_card_res
*card_res
= data
;
1145 struct list_head
*lh
;
1146 struct drm_framebuffer
*fb
;
1147 struct drm_connector
*connector
;
1148 struct drm_crtc
*crtc
;
1149 struct drm_encoder
*encoder
;
1151 int connector_count
= 0;
1154 int encoder_count
= 0;
1156 uint32_t __user
*fb_id
;
1157 uint32_t __user
*crtc_id
;
1158 uint32_t __user
*connector_id
;
1159 uint32_t __user
*encoder_id
;
1160 struct drm_mode_group
*mode_group
;
1162 if (!drm_core_check_feature(dev
, DRIVER_MODESET
))
1165 mutex_lock(&dev
->mode_config
.mutex
);
1168 * For the non-control nodes we need to limit the list of resources
1169 * by IDs in the group list for this node
1171 list_for_each(lh
, &file_priv
->fbs
)
1174 mode_group
= &file_priv
->master
->minor
->mode_group
;
1175 if (file_priv
->master
->minor
->type
== DRM_MINOR_CONTROL
) {
1177 list_for_each(lh
, &dev
->mode_config
.crtc_list
)
1180 list_for_each(lh
, &dev
->mode_config
.connector_list
)
1183 list_for_each(lh
, &dev
->mode_config
.encoder_list
)
1187 crtc_count
= mode_group
->num_crtcs
;
1188 connector_count
= mode_group
->num_connectors
;
1189 encoder_count
= mode_group
->num_encoders
;
1192 card_res
->max_height
= dev
->mode_config
.max_height
;
1193 card_res
->min_height
= dev
->mode_config
.min_height
;
1194 card_res
->max_width
= dev
->mode_config
.max_width
;
1195 card_res
->min_width
= dev
->mode_config
.min_width
;
1197 /* handle this in 4 parts */
1199 if (card_res
->count_fbs
>= fb_count
) {
1201 fb_id
= (uint32_t __user
*)(unsigned long)card_res
->fb_id_ptr
;
1202 list_for_each_entry(fb
, &file_priv
->fbs
, filp_head
) {
1203 if (put_user(fb
->base
.id
, fb_id
+ copied
)) {
1210 card_res
->count_fbs
= fb_count
;
1213 if (card_res
->count_crtcs
>= crtc_count
) {
1215 crtc_id
= (uint32_t __user
*)(unsigned long)card_res
->crtc_id_ptr
;
1216 if (file_priv
->master
->minor
->type
== DRM_MINOR_CONTROL
) {
1217 list_for_each_entry(crtc
, &dev
->mode_config
.crtc_list
,
1219 DRM_DEBUG_KMS("[CRTC:%d]\n", crtc
->base
.id
);
1220 if (put_user(crtc
->base
.id
, crtc_id
+ copied
)) {
1227 for (i
= 0; i
< mode_group
->num_crtcs
; i
++) {
1228 if (put_user(mode_group
->id_list
[i
],
1229 crtc_id
+ copied
)) {
1237 card_res
->count_crtcs
= crtc_count
;
1240 if (card_res
->count_encoders
>= encoder_count
) {
1242 encoder_id
= (uint32_t __user
*)(unsigned long)card_res
->encoder_id_ptr
;
1243 if (file_priv
->master
->minor
->type
== DRM_MINOR_CONTROL
) {
1244 list_for_each_entry(encoder
,
1245 &dev
->mode_config
.encoder_list
,
1247 DRM_DEBUG_KMS("[ENCODER:%d:%s]\n", encoder
->base
.id
,
1248 drm_get_encoder_name(encoder
));
1249 if (put_user(encoder
->base
.id
, encoder_id
+
1257 for (i
= mode_group
->num_crtcs
; i
< mode_group
->num_crtcs
+ mode_group
->num_encoders
; i
++) {
1258 if (put_user(mode_group
->id_list
[i
],
1259 encoder_id
+ copied
)) {
1268 card_res
->count_encoders
= encoder_count
;
1271 if (card_res
->count_connectors
>= connector_count
) {
1273 connector_id
= (uint32_t __user
*)(unsigned long)card_res
->connector_id_ptr
;
1274 if (file_priv
->master
->minor
->type
== DRM_MINOR_CONTROL
) {
1275 list_for_each_entry(connector
,
1276 &dev
->mode_config
.connector_list
,
1278 DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n",
1280 drm_get_connector_name(connector
));
1281 if (put_user(connector
->base
.id
,
1282 connector_id
+ copied
)) {
1289 int start
= mode_group
->num_crtcs
+
1290 mode_group
->num_encoders
;
1291 for (i
= start
; i
< start
+ mode_group
->num_connectors
; i
++) {
1292 if (put_user(mode_group
->id_list
[i
],
1293 connector_id
+ copied
)) {
1301 card_res
->count_connectors
= connector_count
;
1303 DRM_DEBUG_KMS("CRTC[%d] CONNECTORS[%d] ENCODERS[%d]\n", card_res
->count_crtcs
,
1304 card_res
->count_connectors
, card_res
->count_encoders
);
1307 mutex_unlock(&dev
->mode_config
.mutex
);
1312 * drm_mode_getcrtc - get CRTC configuration
1313 * @inode: inode from the ioctl
1314 * @filp: file * from the ioctl
1315 * @cmd: cmd from ioctl
1316 * @arg: arg from ioctl
1319 * Takes mode config lock.
1321 * Construct a CRTC configuration structure to return to the user.
1323 * Called by the user via ioctl.
1326 * Zero on success, errno on failure.
1328 int drm_mode_getcrtc(struct drm_device
*dev
,
1329 void *data
, struct drm_file
*file_priv
)
1331 struct drm_mode_crtc
*crtc_resp
= data
;
1332 struct drm_crtc
*crtc
;
1333 struct drm_mode_object
*obj
;
1336 if (!drm_core_check_feature(dev
, DRIVER_MODESET
))
1339 mutex_lock(&dev
->mode_config
.mutex
);
1341 obj
= drm_mode_object_find(dev
, crtc_resp
->crtc_id
,
1342 DRM_MODE_OBJECT_CRTC
);
1347 crtc
= obj_to_crtc(obj
);
1349 crtc_resp
->x
= crtc
->x
;
1350 crtc_resp
->y
= crtc
->y
;
1351 crtc_resp
->gamma_size
= crtc
->gamma_size
;
1353 crtc_resp
->fb_id
= crtc
->fb
->base
.id
;
1355 crtc_resp
->fb_id
= 0;
1357 if (crtc
->enabled
) {
1359 drm_crtc_convert_to_umode(&crtc_resp
->mode
, &crtc
->mode
);
1360 crtc_resp
->mode_valid
= 1;
1363 crtc_resp
->mode_valid
= 0;
1367 mutex_unlock(&dev
->mode_config
.mutex
);
1372 * drm_mode_getconnector - get connector configuration
1373 * @inode: inode from the ioctl
1374 * @filp: file * from the ioctl
1375 * @cmd: cmd from ioctl
1376 * @arg: arg from ioctl
1379 * Takes mode config lock.
1381 * Construct a connector configuration structure to return to the user.
1383 * Called by the user via ioctl.
1386 * Zero on success, errno on failure.
1388 int drm_mode_getconnector(struct drm_device
*dev
, void *data
,
1389 struct drm_file
*file_priv
)
1391 struct drm_mode_get_connector
*out_resp
= data
;
1392 struct drm_mode_object
*obj
;
1393 struct drm_connector
*connector
;
1394 struct drm_display_mode
*mode
;
1396 int props_count
= 0;
1397 int encoders_count
= 0;
1401 struct drm_mode_modeinfo u_mode
;
1402 struct drm_mode_modeinfo __user
*mode_ptr
;
1403 uint32_t __user
*prop_ptr
;
1404 uint64_t __user
*prop_values
;
1405 uint32_t __user
*encoder_ptr
;
1407 if (!drm_core_check_feature(dev
, DRIVER_MODESET
))
1410 memset(&u_mode
, 0, sizeof(struct drm_mode_modeinfo
));
1412 DRM_DEBUG_KMS("[CONNECTOR:%d:?]\n", out_resp
->connector_id
);
1414 mutex_lock(&dev
->mode_config
.mutex
);
1416 obj
= drm_mode_object_find(dev
, out_resp
->connector_id
,
1417 DRM_MODE_OBJECT_CONNECTOR
);
1422 connector
= obj_to_connector(obj
);
1424 for (i
= 0; i
< DRM_CONNECTOR_MAX_PROPERTY
; i
++) {
1425 if (connector
->property_ids
[i
] != 0) {
1430 for (i
= 0; i
< DRM_CONNECTOR_MAX_ENCODER
; i
++) {
1431 if (connector
->encoder_ids
[i
] != 0) {
1436 if (out_resp
->count_modes
== 0) {
1437 connector
->funcs
->fill_modes(connector
,
1438 dev
->mode_config
.max_width
,
1439 dev
->mode_config
.max_height
);
1442 /* delayed so we get modes regardless of pre-fill_modes state */
1443 list_for_each_entry(mode
, &connector
->modes
, head
)
1446 out_resp
->connector_id
= connector
->base
.id
;
1447 out_resp
->connector_type
= connector
->connector_type
;
1448 out_resp
->connector_type_id
= connector
->connector_type_id
;
1449 out_resp
->mm_width
= connector
->display_info
.width_mm
;
1450 out_resp
->mm_height
= connector
->display_info
.height_mm
;
1451 out_resp
->subpixel
= connector
->display_info
.subpixel_order
;
1452 out_resp
->connection
= connector
->status
;
1453 if (connector
->encoder
)
1454 out_resp
->encoder_id
= connector
->encoder
->base
.id
;
1456 out_resp
->encoder_id
= 0;
1459 * This ioctl is called twice, once to determine how much space is
1460 * needed, and the 2nd time to fill it.
1462 if ((out_resp
->count_modes
>= mode_count
) && mode_count
) {
1464 mode_ptr
= (struct drm_mode_modeinfo __user
*)(unsigned long)out_resp
->modes_ptr
;
1465 list_for_each_entry(mode
, &connector
->modes
, head
) {
1466 drm_crtc_convert_to_umode(&u_mode
, mode
);
1467 if (copy_to_user(mode_ptr
+ copied
,
1468 &u_mode
, sizeof(u_mode
))) {
1475 out_resp
->count_modes
= mode_count
;
1477 if ((out_resp
->count_props
>= props_count
) && props_count
) {
1479 prop_ptr
= (uint32_t __user
*)(unsigned long)(out_resp
->props_ptr
);
1480 prop_values
= (uint64_t __user
*)(unsigned long)(out_resp
->prop_values_ptr
);
1481 for (i
= 0; i
< DRM_CONNECTOR_MAX_PROPERTY
; i
++) {
1482 if (connector
->property_ids
[i
] != 0) {
1483 if (put_user(connector
->property_ids
[i
],
1484 prop_ptr
+ copied
)) {
1489 if (put_user(connector
->property_values
[i
],
1490 prop_values
+ copied
)) {
1498 out_resp
->count_props
= props_count
;
1500 if ((out_resp
->count_encoders
>= encoders_count
) && encoders_count
) {
1502 encoder_ptr
= (uint32_t __user
*)(unsigned long)(out_resp
->encoders_ptr
);
1503 for (i
= 0; i
< DRM_CONNECTOR_MAX_ENCODER
; i
++) {
1504 if (connector
->encoder_ids
[i
] != 0) {
1505 if (put_user(connector
->encoder_ids
[i
],
1506 encoder_ptr
+ copied
)) {
1514 out_resp
->count_encoders
= encoders_count
;
1517 mutex_unlock(&dev
->mode_config
.mutex
);
1521 int drm_mode_getencoder(struct drm_device
*dev
, void *data
,
1522 struct drm_file
*file_priv
)
1524 struct drm_mode_get_encoder
*enc_resp
= data
;
1525 struct drm_mode_object
*obj
;
1526 struct drm_encoder
*encoder
;
1529 if (!drm_core_check_feature(dev
, DRIVER_MODESET
))
1532 mutex_lock(&dev
->mode_config
.mutex
);
1533 obj
= drm_mode_object_find(dev
, enc_resp
->encoder_id
,
1534 DRM_MODE_OBJECT_ENCODER
);
1539 encoder
= obj_to_encoder(obj
);
1542 enc_resp
->crtc_id
= encoder
->crtc
->base
.id
;
1544 enc_resp
->crtc_id
= 0;
1545 enc_resp
->encoder_type
= encoder
->encoder_type
;
1546 enc_resp
->encoder_id
= encoder
->base
.id
;
1547 enc_resp
->possible_crtcs
= encoder
->possible_crtcs
;
1548 enc_resp
->possible_clones
= encoder
->possible_clones
;
1551 mutex_unlock(&dev
->mode_config
.mutex
);
1556 * drm_mode_getplane_res - get plane info
1559 * @file_priv: DRM file info
1562 * Takes mode config lock.
1564 * Return an plane count and set of IDs.
1566 int drm_mode_getplane_res(struct drm_device
*dev
, void *data
,
1567 struct drm_file
*file_priv
)
1569 struct drm_mode_get_plane_res
*plane_resp
= data
;
1570 struct drm_mode_config
*config
;
1571 struct drm_plane
*plane
;
1572 uint32_t __user
*plane_ptr
;
1573 int copied
= 0, ret
= 0;
1575 if (!drm_core_check_feature(dev
, DRIVER_MODESET
))
1578 mutex_lock(&dev
->mode_config
.mutex
);
1579 config
= &dev
->mode_config
;
1582 * This ioctl is called twice, once to determine how much space is
1583 * needed, and the 2nd time to fill it.
1585 if (config
->num_plane
&&
1586 (plane_resp
->count_planes
>= config
->num_plane
)) {
1587 plane_ptr
= (uint32_t __user
*)(unsigned long)plane_resp
->plane_id_ptr
;
1589 list_for_each_entry(plane
, &config
->plane_list
, head
) {
1590 if (put_user(plane
->base
.id
, plane_ptr
+ copied
)) {
1597 plane_resp
->count_planes
= config
->num_plane
;
1600 mutex_unlock(&dev
->mode_config
.mutex
);
1605 * drm_mode_getplane - get plane info
1608 * @file_priv: DRM file info
1611 * Takes mode config lock.
1613 * Return plane info, including formats supported, gamma size, any
1616 int drm_mode_getplane(struct drm_device
*dev
, void *data
,
1617 struct drm_file
*file_priv
)
1619 struct drm_mode_get_plane
*plane_resp
= data
;
1620 struct drm_mode_object
*obj
;
1621 struct drm_plane
*plane
;
1622 uint32_t __user
*format_ptr
;
1625 if (!drm_core_check_feature(dev
, DRIVER_MODESET
))
1628 mutex_lock(&dev
->mode_config
.mutex
);
1629 obj
= drm_mode_object_find(dev
, plane_resp
->plane_id
,
1630 DRM_MODE_OBJECT_PLANE
);
1635 plane
= obj_to_plane(obj
);
1638 plane_resp
->crtc_id
= plane
->crtc
->base
.id
;
1640 plane_resp
->crtc_id
= 0;
1643 plane_resp
->fb_id
= plane
->fb
->base
.id
;
1645 plane_resp
->fb_id
= 0;
1647 plane_resp
->plane_id
= plane
->base
.id
;
1648 plane_resp
->possible_crtcs
= plane
->possible_crtcs
;
1649 plane_resp
->gamma_size
= plane
->gamma_size
;
1652 * This ioctl is called twice, once to determine how much space is
1653 * needed, and the 2nd time to fill it.
1655 if (plane
->format_count
&&
1656 (plane_resp
->count_format_types
>= plane
->format_count
)) {
1657 format_ptr
= (uint32_t __user
*)(unsigned long)plane_resp
->format_type_ptr
;
1658 if (copy_to_user(format_ptr
,
1659 plane
->format_types
,
1660 sizeof(uint32_t) * plane
->format_count
)) {
1665 plane_resp
->count_format_types
= plane
->format_count
;
1668 mutex_unlock(&dev
->mode_config
.mutex
);
1673 * drm_mode_setplane - set up or tear down an plane
1675 * @data: ioctl data*
1676 * @file_prive: DRM file info
1679 * Takes mode config lock.
1681 * Set plane info, including placement, fb, scaling, and other factors.
1682 * Or pass a NULL fb to disable.
1684 int drm_mode_setplane(struct drm_device
*dev
, void *data
,
1685 struct drm_file
*file_priv
)
1687 struct drm_mode_set_plane
*plane_req
= data
;
1688 struct drm_mode_object
*obj
;
1689 struct drm_plane
*plane
;
1690 struct drm_crtc
*crtc
;
1691 struct drm_framebuffer
*fb
;
1693 unsigned int fb_width
, fb_height
;
1696 if (!drm_core_check_feature(dev
, DRIVER_MODESET
))
1699 mutex_lock(&dev
->mode_config
.mutex
);
1702 * First, find the plane, crtc, and fb objects. If not available,
1703 * we don't bother to call the driver.
1705 obj
= drm_mode_object_find(dev
, plane_req
->plane_id
,
1706 DRM_MODE_OBJECT_PLANE
);
1708 DRM_DEBUG_KMS("Unknown plane ID %d\n",
1709 plane_req
->plane_id
);
1713 plane
= obj_to_plane(obj
);
1715 /* No fb means shut it down */
1716 if (!plane_req
->fb_id
) {
1717 plane
->funcs
->disable_plane(plane
);
1723 obj
= drm_mode_object_find(dev
, plane_req
->crtc_id
,
1724 DRM_MODE_OBJECT_CRTC
);
1726 DRM_DEBUG_KMS("Unknown crtc ID %d\n",
1727 plane_req
->crtc_id
);
1731 crtc
= obj_to_crtc(obj
);
1733 obj
= drm_mode_object_find(dev
, plane_req
->fb_id
,
1734 DRM_MODE_OBJECT_FB
);
1736 DRM_DEBUG_KMS("Unknown framebuffer ID %d\n",
1741 fb
= obj_to_fb(obj
);
1743 /* Check whether this plane supports the fb pixel format. */
1744 for (i
= 0; i
< plane
->format_count
; i
++)
1745 if (fb
->pixel_format
== plane
->format_types
[i
])
1747 if (i
== plane
->format_count
) {
1748 DRM_DEBUG_KMS("Invalid pixel format 0x%08x\n", fb
->pixel_format
);
1753 fb_width
= fb
->width
<< 16;
1754 fb_height
= fb
->height
<< 16;
1756 /* Make sure source coordinates are inside the fb. */
1757 if (plane_req
->src_w
> fb_width
||
1758 plane_req
->src_x
> fb_width
- plane_req
->src_w
||
1759 plane_req
->src_h
> fb_height
||
1760 plane_req
->src_y
> fb_height
- plane_req
->src_h
) {
1761 DRM_DEBUG_KMS("Invalid source coordinates "
1762 "%u.%06ux%u.%06u+%u.%06u+%u.%06u\n",
1763 plane_req
->src_w
>> 16,
1764 ((plane_req
->src_w
& 0xffff) * 15625) >> 10,
1765 plane_req
->src_h
>> 16,
1766 ((plane_req
->src_h
& 0xffff) * 15625) >> 10,
1767 plane_req
->src_x
>> 16,
1768 ((plane_req
->src_x
& 0xffff) * 15625) >> 10,
1769 plane_req
->src_y
>> 16,
1770 ((plane_req
->src_y
& 0xffff) * 15625) >> 10);
1775 /* Give drivers some help against integer overflows */
1776 if (plane_req
->crtc_w
> INT_MAX
||
1777 plane_req
->crtc_x
> INT_MAX
- (int32_t) plane_req
->crtc_w
||
1778 plane_req
->crtc_h
> INT_MAX
||
1779 plane_req
->crtc_y
> INT_MAX
- (int32_t) plane_req
->crtc_h
) {
1780 DRM_DEBUG_KMS("Invalid CRTC coordinates %ux%u+%d+%d\n",
1781 plane_req
->crtc_w
, plane_req
->crtc_h
,
1782 plane_req
->crtc_x
, plane_req
->crtc_y
);
1787 ret
= plane
->funcs
->update_plane(plane
, crtc
, fb
,
1788 plane_req
->crtc_x
, plane_req
->crtc_y
,
1789 plane_req
->crtc_w
, plane_req
->crtc_h
,
1790 plane_req
->src_x
, plane_req
->src_y
,
1791 plane_req
->src_w
, plane_req
->src_h
);
1798 mutex_unlock(&dev
->mode_config
.mutex
);
1804 * drm_mode_setcrtc - set CRTC configuration
1805 * @inode: inode from the ioctl
1806 * @filp: file * from the ioctl
1807 * @cmd: cmd from ioctl
1808 * @arg: arg from ioctl
1811 * Takes mode config lock.
1813 * Build a new CRTC configuration based on user request.
1815 * Called by the user via ioctl.
1818 * Zero on success, errno on failure.
1820 int drm_mode_setcrtc(struct drm_device
*dev
, void *data
,
1821 struct drm_file
*file_priv
)
1823 struct drm_mode_config
*config
= &dev
->mode_config
;
1824 struct drm_mode_crtc
*crtc_req
= data
;
1825 struct drm_mode_object
*obj
;
1826 struct drm_crtc
*crtc
;
1827 struct drm_connector
**connector_set
= NULL
, *connector
;
1828 struct drm_framebuffer
*fb
= NULL
;
1829 struct drm_display_mode
*mode
= NULL
;
1830 struct drm_mode_set set
;
1831 uint32_t __user
*set_connectors_ptr
;
1835 if (!drm_core_check_feature(dev
, DRIVER_MODESET
))
1838 /* For some reason crtc x/y offsets are signed internally. */
1839 if (crtc_req
->x
> INT_MAX
|| crtc_req
->y
> INT_MAX
)
1842 mutex_lock(&dev
->mode_config
.mutex
);
1843 obj
= drm_mode_object_find(dev
, crtc_req
->crtc_id
,
1844 DRM_MODE_OBJECT_CRTC
);
1846 DRM_DEBUG_KMS("Unknown CRTC ID %d\n", crtc_req
->crtc_id
);
1850 crtc
= obj_to_crtc(obj
);
1851 DRM_DEBUG_KMS("[CRTC:%d]\n", crtc
->base
.id
);
1853 if (crtc_req
->mode_valid
) {
1854 /* If we have a mode we need a framebuffer. */
1855 /* If we pass -1, set the mode with the currently bound fb */
1856 if (crtc_req
->fb_id
== -1) {
1858 DRM_DEBUG_KMS("CRTC doesn't have current FB\n");
1864 obj
= drm_mode_object_find(dev
, crtc_req
->fb_id
,
1865 DRM_MODE_OBJECT_FB
);
1867 DRM_DEBUG_KMS("Unknown FB ID%d\n",
1872 fb
= obj_to_fb(obj
);
1875 mode
= drm_mode_create(dev
);
1881 ret
= drm_crtc_convert_umode(mode
, &crtc_req
->mode
);
1883 DRM_DEBUG_KMS("Invalid mode\n");
1887 drm_mode_set_crtcinfo(mode
, CRTC_INTERLACE_HALVE_V
);
1889 if (mode
->hdisplay
> fb
->width
||
1890 mode
->vdisplay
> fb
->height
||
1891 crtc_req
->x
> fb
->width
- mode
->hdisplay
||
1892 crtc_req
->y
> fb
->height
- mode
->vdisplay
) {
1893 DRM_DEBUG_KMS("Invalid CRTC viewport %ux%u+%u+%u for fb size %ux%u.\n",
1894 mode
->hdisplay
, mode
->vdisplay
,
1895 crtc_req
->x
, crtc_req
->y
,
1896 fb
->width
, fb
->height
);
1902 if (crtc_req
->count_connectors
== 0 && mode
) {
1903 DRM_DEBUG_KMS("Count connectors is 0 but mode set\n");
1908 if (crtc_req
->count_connectors
> 0 && (!mode
|| !fb
)) {
1909 DRM_DEBUG_KMS("Count connectors is %d but no mode or fb set\n",
1910 crtc_req
->count_connectors
);
1915 if (crtc_req
->count_connectors
> 0) {
1918 /* Avoid unbounded kernel memory allocation */
1919 if (crtc_req
->count_connectors
> config
->num_connector
) {
1924 connector_set
= kmalloc(crtc_req
->count_connectors
*
1925 sizeof(struct drm_connector
*),
1927 if (!connector_set
) {
1932 for (i
= 0; i
< crtc_req
->count_connectors
; i
++) {
1933 set_connectors_ptr
= (uint32_t __user
*)(unsigned long)crtc_req
->set_connectors_ptr
;
1934 if (get_user(out_id
, &set_connectors_ptr
[i
])) {
1939 obj
= drm_mode_object_find(dev
, out_id
,
1940 DRM_MODE_OBJECT_CONNECTOR
);
1942 DRM_DEBUG_KMS("Connector id %d unknown\n",
1947 connector
= obj_to_connector(obj
);
1948 DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n",
1950 drm_get_connector_name(connector
));
1952 connector_set
[i
] = connector
;
1957 set
.x
= crtc_req
->x
;
1958 set
.y
= crtc_req
->y
;
1960 set
.connectors
= connector_set
;
1961 set
.num_connectors
= crtc_req
->count_connectors
;
1963 ret
= crtc
->funcs
->set_config(&set
);
1966 kfree(connector_set
);
1967 drm_mode_destroy(dev
, mode
);
1968 mutex_unlock(&dev
->mode_config
.mutex
);
1972 int drm_mode_cursor_ioctl(struct drm_device
*dev
,
1973 void *data
, struct drm_file
*file_priv
)
1975 struct drm_mode_cursor
*req
= data
;
1976 struct drm_mode_object
*obj
;
1977 struct drm_crtc
*crtc
;
1980 if (!drm_core_check_feature(dev
, DRIVER_MODESET
))
1986 mutex_lock(&dev
->mode_config
.mutex
);
1987 obj
= drm_mode_object_find(dev
, req
->crtc_id
, DRM_MODE_OBJECT_CRTC
);
1989 DRM_DEBUG_KMS("Unknown CRTC ID %d\n", req
->crtc_id
);
1993 crtc
= obj_to_crtc(obj
);
1995 if (req
->flags
& DRM_MODE_CURSOR_BO
) {
1996 if (!crtc
->funcs
->cursor_set
) {
2000 /* Turns off the cursor if handle is 0 */
2001 ret
= crtc
->funcs
->cursor_set(crtc
, file_priv
, req
->handle
,
2002 req
->width
, req
->height
);
2005 if (req
->flags
& DRM_MODE_CURSOR_MOVE
) {
2006 if (crtc
->funcs
->cursor_move
) {
2007 ret
= crtc
->funcs
->cursor_move(crtc
, req
->x
, req
->y
);
2014 mutex_unlock(&dev
->mode_config
.mutex
);
2018 /* Original addfb only supported RGB formats, so figure out which one */
2019 uint32_t drm_mode_legacy_fb_format(uint32_t bpp
, uint32_t depth
)
2025 fmt
= DRM_FORMAT_RGB332
;
2029 fmt
= DRM_FORMAT_XRGB1555
;
2031 fmt
= DRM_FORMAT_RGB565
;
2034 fmt
= DRM_FORMAT_RGB888
;
2038 fmt
= DRM_FORMAT_XRGB8888
;
2039 else if (depth
== 30)
2040 fmt
= DRM_FORMAT_XRGB2101010
;
2042 fmt
= DRM_FORMAT_ARGB8888
;
2045 DRM_ERROR("bad bpp, assuming x8r8g8b8 pixel format\n");
2046 fmt
= DRM_FORMAT_XRGB8888
;
2052 EXPORT_SYMBOL(drm_mode_legacy_fb_format
);
2055 * drm_mode_addfb - add an FB to the graphics configuration
2056 * @inode: inode from the ioctl
2057 * @filp: file * from the ioctl
2058 * @cmd: cmd from ioctl
2059 * @arg: arg from ioctl
2062 * Takes mode config lock.
2064 * Add a new FB to the specified CRTC, given a user request.
2066 * Called by the user via ioctl.
2069 * Zero on success, errno on failure.
2071 int drm_mode_addfb(struct drm_device
*dev
,
2072 void *data
, struct drm_file
*file_priv
)
2074 struct drm_mode_fb_cmd
*or = data
;
2075 struct drm_mode_fb_cmd2 r
= {};
2076 struct drm_mode_config
*config
= &dev
->mode_config
;
2077 struct drm_framebuffer
*fb
;
2080 /* Use new struct with format internally */
2081 r
.fb_id
= or->fb_id
;
2082 r
.width
= or->width
;
2083 r
.height
= or->height
;
2084 r
.pitches
[0] = or->pitch
;
2085 r
.pixel_format
= drm_mode_legacy_fb_format(or->bpp
, or->depth
);
2086 r
.handles
[0] = or->handle
;
2088 if (!drm_core_check_feature(dev
, DRIVER_MODESET
))
2091 if ((config
->min_width
> r
.width
) || (r
.width
> config
->max_width
))
2094 if ((config
->min_height
> r
.height
) || (r
.height
> config
->max_height
))
2097 mutex_lock(&dev
->mode_config
.mutex
);
2099 /* TODO check buffer is sufficiently large */
2100 /* TODO setup destructor callback */
2102 fb
= dev
->mode_config
.funcs
->fb_create(dev
, file_priv
, &r
);
2104 DRM_ERROR("could not create framebuffer\n");
2109 or->fb_id
= fb
->base
.id
;
2110 list_add(&fb
->filp_head
, &file_priv
->fbs
);
2111 DRM_DEBUG_KMS("[FB:%d]\n", fb
->base
.id
);
2114 mutex_unlock(&dev
->mode_config
.mutex
);
2118 static int format_check(struct drm_mode_fb_cmd2
*r
)
2120 uint32_t format
= r
->pixel_format
& ~DRM_FORMAT_BIG_ENDIAN
;
2124 case DRM_FORMAT_RGB332
:
2125 case DRM_FORMAT_BGR233
:
2126 case DRM_FORMAT_XRGB4444
:
2127 case DRM_FORMAT_XBGR4444
:
2128 case DRM_FORMAT_RGBX4444
:
2129 case DRM_FORMAT_BGRX4444
:
2130 case DRM_FORMAT_ARGB4444
:
2131 case DRM_FORMAT_ABGR4444
:
2132 case DRM_FORMAT_RGBA4444
:
2133 case DRM_FORMAT_BGRA4444
:
2134 case DRM_FORMAT_XRGB1555
:
2135 case DRM_FORMAT_XBGR1555
:
2136 case DRM_FORMAT_RGBX5551
:
2137 case DRM_FORMAT_BGRX5551
:
2138 case DRM_FORMAT_ARGB1555
:
2139 case DRM_FORMAT_ABGR1555
:
2140 case DRM_FORMAT_RGBA5551
:
2141 case DRM_FORMAT_BGRA5551
:
2142 case DRM_FORMAT_RGB565
:
2143 case DRM_FORMAT_BGR565
:
2144 case DRM_FORMAT_RGB888
:
2145 case DRM_FORMAT_BGR888
:
2146 case DRM_FORMAT_XRGB8888
:
2147 case DRM_FORMAT_XBGR8888
:
2148 case DRM_FORMAT_RGBX8888
:
2149 case DRM_FORMAT_BGRX8888
:
2150 case DRM_FORMAT_ARGB8888
:
2151 case DRM_FORMAT_ABGR8888
:
2152 case DRM_FORMAT_RGBA8888
:
2153 case DRM_FORMAT_BGRA8888
:
2154 case DRM_FORMAT_XRGB2101010
:
2155 case DRM_FORMAT_XBGR2101010
:
2156 case DRM_FORMAT_RGBX1010102
:
2157 case DRM_FORMAT_BGRX1010102
:
2158 case DRM_FORMAT_ARGB2101010
:
2159 case DRM_FORMAT_ABGR2101010
:
2160 case DRM_FORMAT_RGBA1010102
:
2161 case DRM_FORMAT_BGRA1010102
:
2162 case DRM_FORMAT_YUYV
:
2163 case DRM_FORMAT_YVYU
:
2164 case DRM_FORMAT_UYVY
:
2165 case DRM_FORMAT_VYUY
:
2166 case DRM_FORMAT_AYUV
:
2167 case DRM_FORMAT_NV12
:
2168 case DRM_FORMAT_NV21
:
2169 case DRM_FORMAT_NV16
:
2170 case DRM_FORMAT_NV61
:
2171 case DRM_FORMAT_YUV410
:
2172 case DRM_FORMAT_YVU410
:
2173 case DRM_FORMAT_YUV411
:
2174 case DRM_FORMAT_YVU411
:
2175 case DRM_FORMAT_YUV420
:
2176 case DRM_FORMAT_YVU420
:
2177 case DRM_FORMAT_YUV422
:
2178 case DRM_FORMAT_YVU422
:
2179 case DRM_FORMAT_YUV444
:
2180 case DRM_FORMAT_YVU444
:
2188 * drm_mode_addfb2 - add an FB to the graphics configuration
2189 * @inode: inode from the ioctl
2190 * @filp: file * from the ioctl
2191 * @cmd: cmd from ioctl
2192 * @arg: arg from ioctl
2195 * Takes mode config lock.
2197 * Add a new FB to the specified CRTC, given a user request with format.
2199 * Called by the user via ioctl.
2202 * Zero on success, errno on failure.
2204 int drm_mode_addfb2(struct drm_device
*dev
,
2205 void *data
, struct drm_file
*file_priv
)
2207 struct drm_mode_fb_cmd2
*r
= data
;
2208 struct drm_mode_config
*config
= &dev
->mode_config
;
2209 struct drm_framebuffer
*fb
;
2212 if (!drm_core_check_feature(dev
, DRIVER_MODESET
))
2215 if ((config
->min_width
> r
->width
) || (r
->width
> config
->max_width
)) {
2216 DRM_ERROR("bad framebuffer width %d, should be >= %d && <= %d\n",
2217 r
->width
, config
->min_width
, config
->max_width
);
2220 if ((config
->min_height
> r
->height
) || (r
->height
> config
->max_height
)) {
2221 DRM_ERROR("bad framebuffer height %d, should be >= %d && <= %d\n",
2222 r
->height
, config
->min_height
, config
->max_height
);
2226 ret
= format_check(r
);
2228 DRM_ERROR("bad framebuffer format 0x%08x\n", r
->pixel_format
);
2232 mutex_lock(&dev
->mode_config
.mutex
);
2234 fb
= dev
->mode_config
.funcs
->fb_create(dev
, file_priv
, r
);
2236 DRM_ERROR("could not create framebuffer\n");
2241 r
->fb_id
= fb
->base
.id
;
2242 list_add(&fb
->filp_head
, &file_priv
->fbs
);
2243 DRM_DEBUG_KMS("[FB:%d]\n", fb
->base
.id
);
2246 mutex_unlock(&dev
->mode_config
.mutex
);
2251 * drm_mode_rmfb - remove an FB from the configuration
2252 * @inode: inode from the ioctl
2253 * @filp: file * from the ioctl
2254 * @cmd: cmd from ioctl
2255 * @arg: arg from ioctl
2258 * Takes mode config lock.
2260 * Remove the FB specified by the user.
2262 * Called by the user via ioctl.
2265 * Zero on success, errno on failure.
2267 int drm_mode_rmfb(struct drm_device
*dev
,
2268 void *data
, struct drm_file
*file_priv
)
2270 struct drm_mode_object
*obj
;
2271 struct drm_framebuffer
*fb
= NULL
;
2272 struct drm_framebuffer
*fbl
= NULL
;
2273 uint32_t *id
= data
;
2277 if (!drm_core_check_feature(dev
, DRIVER_MODESET
))
2280 mutex_lock(&dev
->mode_config
.mutex
);
2281 obj
= drm_mode_object_find(dev
, *id
, DRM_MODE_OBJECT_FB
);
2282 /* TODO check that we really get a framebuffer back. */
2287 fb
= obj_to_fb(obj
);
2289 list_for_each_entry(fbl
, &file_priv
->fbs
, filp_head
)
2298 /* TODO release all crtc connected to the framebuffer */
2299 /* TODO unhock the destructor from the buffer object */
2301 list_del(&fb
->filp_head
);
2302 fb
->funcs
->destroy(fb
);
2305 mutex_unlock(&dev
->mode_config
.mutex
);
2310 * drm_mode_getfb - get FB info
2311 * @inode: inode from the ioctl
2312 * @filp: file * from the ioctl
2313 * @cmd: cmd from ioctl
2314 * @arg: arg from ioctl
2317 * Takes mode config lock.
2319 * Lookup the FB given its ID and return info about it.
2321 * Called by the user via ioctl.
2324 * Zero on success, errno on failure.
2326 int drm_mode_getfb(struct drm_device
*dev
,
2327 void *data
, struct drm_file
*file_priv
)
2329 struct drm_mode_fb_cmd
*r
= data
;
2330 struct drm_mode_object
*obj
;
2331 struct drm_framebuffer
*fb
;
2334 if (!drm_core_check_feature(dev
, DRIVER_MODESET
))
2337 mutex_lock(&dev
->mode_config
.mutex
);
2338 obj
= drm_mode_object_find(dev
, r
->fb_id
, DRM_MODE_OBJECT_FB
);
2343 fb
= obj_to_fb(obj
);
2345 r
->height
= fb
->height
;
2346 r
->width
= fb
->width
;
2347 r
->depth
= fb
->depth
;
2348 r
->bpp
= fb
->bits_per_pixel
;
2349 r
->pitch
= fb
->pitches
[0];
2350 fb
->funcs
->create_handle(fb
, file_priv
, &r
->handle
);
2353 mutex_unlock(&dev
->mode_config
.mutex
);
2357 int drm_mode_dirtyfb_ioctl(struct drm_device
*dev
,
2358 void *data
, struct drm_file
*file_priv
)
2360 struct drm_clip_rect __user
*clips_ptr
;
2361 struct drm_clip_rect
*clips
= NULL
;
2362 struct drm_mode_fb_dirty_cmd
*r
= data
;
2363 struct drm_mode_object
*obj
;
2364 struct drm_framebuffer
*fb
;
2369 if (!drm_core_check_feature(dev
, DRIVER_MODESET
))
2372 mutex_lock(&dev
->mode_config
.mutex
);
2373 obj
= drm_mode_object_find(dev
, r
->fb_id
, DRM_MODE_OBJECT_FB
);
2378 fb
= obj_to_fb(obj
);
2380 num_clips
= r
->num_clips
;
2381 clips_ptr
= (struct drm_clip_rect __user
*)(unsigned long)r
->clips_ptr
;
2383 if (!num_clips
!= !clips_ptr
) {
2388 flags
= DRM_MODE_FB_DIRTY_FLAGS
& r
->flags
;
2390 /* If userspace annotates copy, clips must come in pairs */
2391 if (flags
& DRM_MODE_FB_DIRTY_ANNOTATE_COPY
&& (num_clips
% 2)) {
2396 if (num_clips
&& clips_ptr
) {
2397 if (num_clips
< 0 || num_clips
> DRM_MODE_FB_DIRTY_MAX_CLIPS
) {
2401 clips
= kzalloc(num_clips
* sizeof(*clips
), GFP_KERNEL
);
2407 ret
= copy_from_user(clips
, clips_ptr
,
2408 num_clips
* sizeof(*clips
));
2415 if (fb
->funcs
->dirty
) {
2416 ret
= fb
->funcs
->dirty(fb
, file_priv
, flags
, r
->color
,
2426 mutex_unlock(&dev
->mode_config
.mutex
);
2432 * drm_fb_release - remove and free the FBs on this file
2433 * @filp: file * from the ioctl
2436 * Takes mode config lock.
2438 * Destroy all the FBs associated with @filp.
2440 * Called by the user via ioctl.
2443 * Zero on success, errno on failure.
2445 void drm_fb_release(struct drm_file
*priv
)
2447 struct drm_device
*dev
= priv
->minor
->dev
;
2448 struct drm_framebuffer
*fb
, *tfb
;
2450 mutex_lock(&dev
->mode_config
.mutex
);
2451 list_for_each_entry_safe(fb
, tfb
, &priv
->fbs
, filp_head
) {
2452 list_del(&fb
->filp_head
);
2453 fb
->funcs
->destroy(fb
);
2455 mutex_unlock(&dev
->mode_config
.mutex
);
2459 * drm_mode_attachmode - add a mode to the user mode list
2461 * @connector: connector to add the mode to
2462 * @mode: mode to add
2464 * Add @mode to @connector's user mode list.
2466 static void drm_mode_attachmode(struct drm_device
*dev
,
2467 struct drm_connector
*connector
,
2468 struct drm_display_mode
*mode
)
2470 list_add_tail(&mode
->head
, &connector
->user_modes
);
2473 int drm_mode_attachmode_crtc(struct drm_device
*dev
, struct drm_crtc
*crtc
,
2474 const struct drm_display_mode
*mode
)
2476 struct drm_connector
*connector
;
2478 struct drm_display_mode
*dup_mode
, *next
;
2481 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
, head
) {
2482 if (!connector
->encoder
)
2484 if (connector
->encoder
->crtc
== crtc
) {
2485 dup_mode
= drm_mode_duplicate(dev
, mode
);
2490 list_add_tail(&dup_mode
->head
, &list
);
2494 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
, head
) {
2495 if (!connector
->encoder
)
2497 if (connector
->encoder
->crtc
== crtc
)
2498 list_move_tail(list
.next
, &connector
->user_modes
);
2501 WARN_ON(!list_empty(&list
));
2504 list_for_each_entry_safe(dup_mode
, next
, &list
, head
)
2505 drm_mode_destroy(dev
, dup_mode
);
2509 EXPORT_SYMBOL(drm_mode_attachmode_crtc
);
2511 static int drm_mode_detachmode(struct drm_device
*dev
,
2512 struct drm_connector
*connector
,
2513 struct drm_display_mode
*mode
)
2517 struct drm_display_mode
*match_mode
, *t
;
2519 list_for_each_entry_safe(match_mode
, t
, &connector
->user_modes
, head
) {
2520 if (drm_mode_equal(match_mode
, mode
)) {
2521 list_del(&match_mode
->head
);
2522 drm_mode_destroy(dev
, match_mode
);
2534 int drm_mode_detachmode_crtc(struct drm_device
*dev
, struct drm_display_mode
*mode
)
2536 struct drm_connector
*connector
;
2538 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
, head
) {
2539 drm_mode_detachmode(dev
, connector
, mode
);
2543 EXPORT_SYMBOL(drm_mode_detachmode_crtc
);
2546 * drm_fb_attachmode - Attach a user mode to an connector
2547 * @inode: inode from the ioctl
2548 * @filp: file * from the ioctl
2549 * @cmd: cmd from ioctl
2550 * @arg: arg from ioctl
2552 * This attaches a user specified mode to an connector.
2553 * Called by the user via ioctl.
2556 * Zero on success, errno on failure.
2558 int drm_mode_attachmode_ioctl(struct drm_device
*dev
,
2559 void *data
, struct drm_file
*file_priv
)
2561 struct drm_mode_mode_cmd
*mode_cmd
= data
;
2562 struct drm_connector
*connector
;
2563 struct drm_display_mode
*mode
;
2564 struct drm_mode_object
*obj
;
2565 struct drm_mode_modeinfo
*umode
= &mode_cmd
->mode
;
2568 if (!drm_core_check_feature(dev
, DRIVER_MODESET
))
2571 mutex_lock(&dev
->mode_config
.mutex
);
2573 obj
= drm_mode_object_find(dev
, mode_cmd
->connector_id
, DRM_MODE_OBJECT_CONNECTOR
);
2578 connector
= obj_to_connector(obj
);
2580 mode
= drm_mode_create(dev
);
2586 ret
= drm_crtc_convert_umode(mode
, umode
);
2588 DRM_DEBUG_KMS("Invalid mode\n");
2589 drm_mode_destroy(dev
, mode
);
2593 drm_mode_attachmode(dev
, connector
, mode
);
2595 mutex_unlock(&dev
->mode_config
.mutex
);
2601 * drm_fb_detachmode - Detach a user specified mode from an connector
2602 * @inode: inode from the ioctl
2603 * @filp: file * from the ioctl
2604 * @cmd: cmd from ioctl
2605 * @arg: arg from ioctl
2607 * Called by the user via ioctl.
2610 * Zero on success, errno on failure.
2612 int drm_mode_detachmode_ioctl(struct drm_device
*dev
,
2613 void *data
, struct drm_file
*file_priv
)
2615 struct drm_mode_object
*obj
;
2616 struct drm_mode_mode_cmd
*mode_cmd
= data
;
2617 struct drm_connector
*connector
;
2618 struct drm_display_mode mode
;
2619 struct drm_mode_modeinfo
*umode
= &mode_cmd
->mode
;
2622 if (!drm_core_check_feature(dev
, DRIVER_MODESET
))
2625 mutex_lock(&dev
->mode_config
.mutex
);
2627 obj
= drm_mode_object_find(dev
, mode_cmd
->connector_id
, DRM_MODE_OBJECT_CONNECTOR
);
2632 connector
= obj_to_connector(obj
);
2634 ret
= drm_crtc_convert_umode(&mode
, umode
);
2636 DRM_DEBUG_KMS("Invalid mode\n");
2640 ret
= drm_mode_detachmode(dev
, connector
, &mode
);
2642 mutex_unlock(&dev
->mode_config
.mutex
);
2646 struct drm_property
*drm_property_create(struct drm_device
*dev
, int flags
,
2647 const char *name
, int num_values
)
2649 struct drm_property
*property
= NULL
;
2652 property
= kzalloc(sizeof(struct drm_property
), GFP_KERNEL
);
2657 property
->values
= kzalloc(sizeof(uint64_t)*num_values
, GFP_KERNEL
);
2658 if (!property
->values
)
2662 ret
= drm_mode_object_get(dev
, &property
->base
, DRM_MODE_OBJECT_PROPERTY
);
2666 property
->flags
= flags
;
2667 property
->num_values
= num_values
;
2668 INIT_LIST_HEAD(&property
->enum_blob_list
);
2671 strncpy(property
->name
, name
, DRM_PROP_NAME_LEN
);
2672 property
->name
[DRM_PROP_NAME_LEN
-1] = '\0';
2675 list_add_tail(&property
->head
, &dev
->mode_config
.property_list
);
2678 kfree(property
->values
);
2682 EXPORT_SYMBOL(drm_property_create
);
2684 struct drm_property
*drm_property_create_enum(struct drm_device
*dev
, int flags
,
2686 const struct drm_prop_enum_list
*props
,
2689 struct drm_property
*property
;
2692 flags
|= DRM_MODE_PROP_ENUM
;
2694 property
= drm_property_create(dev
, flags
, name
, num_values
);
2698 for (i
= 0; i
< num_values
; i
++) {
2699 ret
= drm_property_add_enum(property
, i
,
2703 drm_property_destroy(dev
, property
);
2710 EXPORT_SYMBOL(drm_property_create_enum
);
2712 struct drm_property
*drm_property_create_range(struct drm_device
*dev
, int flags
,
2714 uint64_t min
, uint64_t max
)
2716 struct drm_property
*property
;
2718 flags
|= DRM_MODE_PROP_RANGE
;
2720 property
= drm_property_create(dev
, flags
, name
, 2);
2724 property
->values
[0] = min
;
2725 property
->values
[1] = max
;
2729 EXPORT_SYMBOL(drm_property_create_range
);
2731 int drm_property_add_enum(struct drm_property
*property
, int index
,
2732 uint64_t value
, const char *name
)
2734 struct drm_property_enum
*prop_enum
;
2736 if (!(property
->flags
& DRM_MODE_PROP_ENUM
))
2739 if (!list_empty(&property
->enum_blob_list
)) {
2740 list_for_each_entry(prop_enum
, &property
->enum_blob_list
, head
) {
2741 if (prop_enum
->value
== value
) {
2742 strncpy(prop_enum
->name
, name
, DRM_PROP_NAME_LEN
);
2743 prop_enum
->name
[DRM_PROP_NAME_LEN
-1] = '\0';
2749 prop_enum
= kzalloc(sizeof(struct drm_property_enum
), GFP_KERNEL
);
2753 strncpy(prop_enum
->name
, name
, DRM_PROP_NAME_LEN
);
2754 prop_enum
->name
[DRM_PROP_NAME_LEN
-1] = '\0';
2755 prop_enum
->value
= value
;
2757 property
->values
[index
] = value
;
2758 list_add_tail(&prop_enum
->head
, &property
->enum_blob_list
);
2761 EXPORT_SYMBOL(drm_property_add_enum
);
2763 void drm_property_destroy(struct drm_device
*dev
, struct drm_property
*property
)
2765 struct drm_property_enum
*prop_enum
, *pt
;
2767 list_for_each_entry_safe(prop_enum
, pt
, &property
->enum_blob_list
, head
) {
2768 list_del(&prop_enum
->head
);
2772 if (property
->num_values
)
2773 kfree(property
->values
);
2774 drm_mode_object_put(dev
, &property
->base
);
2775 list_del(&property
->head
);
2778 EXPORT_SYMBOL(drm_property_destroy
);
2780 int drm_connector_attach_property(struct drm_connector
*connector
,
2781 struct drm_property
*property
, uint64_t init_val
)
2785 for (i
= 0; i
< DRM_CONNECTOR_MAX_PROPERTY
; i
++) {
2786 if (connector
->property_ids
[i
] == 0) {
2787 connector
->property_ids
[i
] = property
->base
.id
;
2788 connector
->property_values
[i
] = init_val
;
2793 if (i
== DRM_CONNECTOR_MAX_PROPERTY
)
2797 EXPORT_SYMBOL(drm_connector_attach_property
);
2799 int drm_connector_property_set_value(struct drm_connector
*connector
,
2800 struct drm_property
*property
, uint64_t value
)
2804 for (i
= 0; i
< DRM_CONNECTOR_MAX_PROPERTY
; i
++) {
2805 if (connector
->property_ids
[i
] == property
->base
.id
) {
2806 connector
->property_values
[i
] = value
;
2811 if (i
== DRM_CONNECTOR_MAX_PROPERTY
)
2815 EXPORT_SYMBOL(drm_connector_property_set_value
);
2817 int drm_connector_property_get_value(struct drm_connector
*connector
,
2818 struct drm_property
*property
, uint64_t *val
)
2822 for (i
= 0; i
< DRM_CONNECTOR_MAX_PROPERTY
; i
++) {
2823 if (connector
->property_ids
[i
] == property
->base
.id
) {
2824 *val
= connector
->property_values
[i
];
2829 if (i
== DRM_CONNECTOR_MAX_PROPERTY
)
2833 EXPORT_SYMBOL(drm_connector_property_get_value
);
2835 int drm_mode_getproperty_ioctl(struct drm_device
*dev
,
2836 void *data
, struct drm_file
*file_priv
)
2838 struct drm_mode_object
*obj
;
2839 struct drm_mode_get_property
*out_resp
= data
;
2840 struct drm_property
*property
;
2843 int value_count
= 0;
2846 struct drm_property_enum
*prop_enum
;
2847 struct drm_mode_property_enum __user
*enum_ptr
;
2848 struct drm_property_blob
*prop_blob
;
2849 uint32_t __user
*blob_id_ptr
;
2850 uint64_t __user
*values_ptr
;
2851 uint32_t __user
*blob_length_ptr
;
2853 if (!drm_core_check_feature(dev
, DRIVER_MODESET
))
2856 mutex_lock(&dev
->mode_config
.mutex
);
2857 obj
= drm_mode_object_find(dev
, out_resp
->prop_id
, DRM_MODE_OBJECT_PROPERTY
);
2862 property
= obj_to_property(obj
);
2864 if (property
->flags
& DRM_MODE_PROP_ENUM
) {
2865 list_for_each_entry(prop_enum
, &property
->enum_blob_list
, head
)
2867 } else if (property
->flags
& DRM_MODE_PROP_BLOB
) {
2868 list_for_each_entry(prop_blob
, &property
->enum_blob_list
, head
)
2872 value_count
= property
->num_values
;
2874 strncpy(out_resp
->name
, property
->name
, DRM_PROP_NAME_LEN
);
2875 out_resp
->name
[DRM_PROP_NAME_LEN
-1] = 0;
2876 out_resp
->flags
= property
->flags
;
2878 if ((out_resp
->count_values
>= value_count
) && value_count
) {
2879 values_ptr
= (uint64_t __user
*)(unsigned long)out_resp
->values_ptr
;
2880 for (i
= 0; i
< value_count
; i
++) {
2881 if (copy_to_user(values_ptr
+ i
, &property
->values
[i
], sizeof(uint64_t))) {
2887 out_resp
->count_values
= value_count
;
2889 if (property
->flags
& DRM_MODE_PROP_ENUM
) {
2890 if ((out_resp
->count_enum_blobs
>= enum_count
) && enum_count
) {
2892 enum_ptr
= (struct drm_mode_property_enum __user
*)(unsigned long)out_resp
->enum_blob_ptr
;
2893 list_for_each_entry(prop_enum
, &property
->enum_blob_list
, head
) {
2895 if (copy_to_user(&enum_ptr
[copied
].value
, &prop_enum
->value
, sizeof(uint64_t))) {
2900 if (copy_to_user(&enum_ptr
[copied
].name
,
2901 &prop_enum
->name
, DRM_PROP_NAME_LEN
)) {
2908 out_resp
->count_enum_blobs
= enum_count
;
2911 if (property
->flags
& DRM_MODE_PROP_BLOB
) {
2912 if ((out_resp
->count_enum_blobs
>= blob_count
) && blob_count
) {
2914 blob_id_ptr
= (uint32_t __user
*)(unsigned long)out_resp
->enum_blob_ptr
;
2915 blob_length_ptr
= (uint32_t __user
*)(unsigned long)out_resp
->values_ptr
;
2917 list_for_each_entry(prop_blob
, &property
->enum_blob_list
, head
) {
2918 if (put_user(prop_blob
->base
.id
, blob_id_ptr
+ copied
)) {
2923 if (put_user(prop_blob
->length
, blob_length_ptr
+ copied
)) {
2931 out_resp
->count_enum_blobs
= blob_count
;
2934 mutex_unlock(&dev
->mode_config
.mutex
);
2938 static struct drm_property_blob
*drm_property_create_blob(struct drm_device
*dev
, int length
,
2941 struct drm_property_blob
*blob
;
2944 if (!length
|| !data
)
2947 blob
= kzalloc(sizeof(struct drm_property_blob
)+length
, GFP_KERNEL
);
2951 ret
= drm_mode_object_get(dev
, &blob
->base
, DRM_MODE_OBJECT_BLOB
);
2957 blob
->length
= length
;
2959 memcpy(blob
->data
, data
, length
);
2961 list_add_tail(&blob
->head
, &dev
->mode_config
.property_blob_list
);
2965 static void drm_property_destroy_blob(struct drm_device
*dev
,
2966 struct drm_property_blob
*blob
)
2968 drm_mode_object_put(dev
, &blob
->base
);
2969 list_del(&blob
->head
);
2973 int drm_mode_getblob_ioctl(struct drm_device
*dev
,
2974 void *data
, struct drm_file
*file_priv
)
2976 struct drm_mode_object
*obj
;
2977 struct drm_mode_get_blob
*out_resp
= data
;
2978 struct drm_property_blob
*blob
;
2980 void __user
*blob_ptr
;
2982 if (!drm_core_check_feature(dev
, DRIVER_MODESET
))
2985 mutex_lock(&dev
->mode_config
.mutex
);
2986 obj
= drm_mode_object_find(dev
, out_resp
->blob_id
, DRM_MODE_OBJECT_BLOB
);
2991 blob
= obj_to_blob(obj
);
2993 if (out_resp
->length
== blob
->length
) {
2994 blob_ptr
= (void __user
*)(unsigned long)out_resp
->data
;
2995 if (copy_to_user(blob_ptr
, blob
->data
, blob
->length
)){
3000 out_resp
->length
= blob
->length
;
3003 mutex_unlock(&dev
->mode_config
.mutex
);
3007 int drm_mode_connector_update_edid_property(struct drm_connector
*connector
,
3010 struct drm_device
*dev
= connector
->dev
;
3013 if (connector
->edid_blob_ptr
)
3014 drm_property_destroy_blob(dev
, connector
->edid_blob_ptr
);
3016 /* Delete edid, when there is none. */
3018 connector
->edid_blob_ptr
= NULL
;
3019 ret
= drm_connector_property_set_value(connector
, dev
->mode_config
.edid_property
, 0);
3023 size
= EDID_LENGTH
* (1 + edid
->extensions
);
3024 connector
->edid_blob_ptr
= drm_property_create_blob(connector
->dev
,
3027 ret
= drm_connector_property_set_value(connector
,
3028 dev
->mode_config
.edid_property
,
3029 connector
->edid_blob_ptr
->base
.id
);
3033 EXPORT_SYMBOL(drm_mode_connector_update_edid_property
);
3035 int drm_mode_connector_property_set_ioctl(struct drm_device
*dev
,
3036 void *data
, struct drm_file
*file_priv
)
3038 struct drm_mode_connector_set_property
*out_resp
= data
;
3039 struct drm_mode_object
*obj
;
3040 struct drm_property
*property
;
3041 struct drm_connector
*connector
;
3045 if (!drm_core_check_feature(dev
, DRIVER_MODESET
))
3048 mutex_lock(&dev
->mode_config
.mutex
);
3050 obj
= drm_mode_object_find(dev
, out_resp
->connector_id
, DRM_MODE_OBJECT_CONNECTOR
);
3054 connector
= obj_to_connector(obj
);
3056 for (i
= 0; i
< DRM_CONNECTOR_MAX_PROPERTY
; i
++) {
3057 if (connector
->property_ids
[i
] == out_resp
->prop_id
)
3061 if (i
== DRM_CONNECTOR_MAX_PROPERTY
) {
3065 obj
= drm_mode_object_find(dev
, out_resp
->prop_id
, DRM_MODE_OBJECT_PROPERTY
);
3069 property
= obj_to_property(obj
);
3071 if (property
->flags
& DRM_MODE_PROP_IMMUTABLE
)
3074 if (property
->flags
& DRM_MODE_PROP_RANGE
) {
3075 if (out_resp
->value
< property
->values
[0])
3078 if (out_resp
->value
> property
->values
[1])
3082 for (i
= 0; i
< property
->num_values
; i
++) {
3083 if (property
->values
[i
] == out_resp
->value
) {
3093 /* Do DPMS ourselves */
3094 if (property
== connector
->dev
->mode_config
.dpms_property
) {
3095 if (connector
->funcs
->dpms
)
3096 (*connector
->funcs
->dpms
)(connector
, (int) out_resp
->value
);
3098 } else if (connector
->funcs
->set_property
)
3099 ret
= connector
->funcs
->set_property(connector
, property
, out_resp
->value
);
3101 /* store the property value if successful */
3103 drm_connector_property_set_value(connector
, property
, out_resp
->value
);
3105 mutex_unlock(&dev
->mode_config
.mutex
);
3109 int drm_mode_connector_attach_encoder(struct drm_connector
*connector
,
3110 struct drm_encoder
*encoder
)
3114 for (i
= 0; i
< DRM_CONNECTOR_MAX_ENCODER
; i
++) {
3115 if (connector
->encoder_ids
[i
] == 0) {
3116 connector
->encoder_ids
[i
] = encoder
->base
.id
;
3122 EXPORT_SYMBOL(drm_mode_connector_attach_encoder
);
3124 void drm_mode_connector_detach_encoder(struct drm_connector
*connector
,
3125 struct drm_encoder
*encoder
)
3128 for (i
= 0; i
< DRM_CONNECTOR_MAX_ENCODER
; i
++) {
3129 if (connector
->encoder_ids
[i
] == encoder
->base
.id
) {
3130 connector
->encoder_ids
[i
] = 0;
3131 if (connector
->encoder
== encoder
)
3132 connector
->encoder
= NULL
;
3137 EXPORT_SYMBOL(drm_mode_connector_detach_encoder
);
3139 int drm_mode_crtc_set_gamma_size(struct drm_crtc
*crtc
,
3142 crtc
->gamma_size
= gamma_size
;
3144 crtc
->gamma_store
= kzalloc(gamma_size
* sizeof(uint16_t) * 3, GFP_KERNEL
);
3145 if (!crtc
->gamma_store
) {
3146 crtc
->gamma_size
= 0;
3152 EXPORT_SYMBOL(drm_mode_crtc_set_gamma_size
);
3154 int drm_mode_gamma_set_ioctl(struct drm_device
*dev
,
3155 void *data
, struct drm_file
*file_priv
)
3157 struct drm_mode_crtc_lut
*crtc_lut
= data
;
3158 struct drm_mode_object
*obj
;
3159 struct drm_crtc
*crtc
;
3160 void *r_base
, *g_base
, *b_base
;
3164 if (!drm_core_check_feature(dev
, DRIVER_MODESET
))
3167 mutex_lock(&dev
->mode_config
.mutex
);
3168 obj
= drm_mode_object_find(dev
, crtc_lut
->crtc_id
, DRM_MODE_OBJECT_CRTC
);
3173 crtc
= obj_to_crtc(obj
);
3175 /* memcpy into gamma store */
3176 if (crtc_lut
->gamma_size
!= crtc
->gamma_size
) {
3181 size
= crtc_lut
->gamma_size
* (sizeof(uint16_t));
3182 r_base
= crtc
->gamma_store
;
3183 if (copy_from_user(r_base
, (void __user
*)(unsigned long)crtc_lut
->red
, size
)) {
3188 g_base
= r_base
+ size
;
3189 if (copy_from_user(g_base
, (void __user
*)(unsigned long)crtc_lut
->green
, size
)) {
3194 b_base
= g_base
+ size
;
3195 if (copy_from_user(b_base
, (void __user
*)(unsigned long)crtc_lut
->blue
, size
)) {
3200 crtc
->funcs
->gamma_set(crtc
, r_base
, g_base
, b_base
, 0, crtc
->gamma_size
);
3203 mutex_unlock(&dev
->mode_config
.mutex
);
3208 int drm_mode_gamma_get_ioctl(struct drm_device
*dev
,
3209 void *data
, struct drm_file
*file_priv
)
3211 struct drm_mode_crtc_lut
*crtc_lut
= data
;
3212 struct drm_mode_object
*obj
;
3213 struct drm_crtc
*crtc
;
3214 void *r_base
, *g_base
, *b_base
;
3218 if (!drm_core_check_feature(dev
, DRIVER_MODESET
))
3221 mutex_lock(&dev
->mode_config
.mutex
);
3222 obj
= drm_mode_object_find(dev
, crtc_lut
->crtc_id
, DRM_MODE_OBJECT_CRTC
);
3227 crtc
= obj_to_crtc(obj
);
3229 /* memcpy into gamma store */
3230 if (crtc_lut
->gamma_size
!= crtc
->gamma_size
) {
3235 size
= crtc_lut
->gamma_size
* (sizeof(uint16_t));
3236 r_base
= crtc
->gamma_store
;
3237 if (copy_to_user((void __user
*)(unsigned long)crtc_lut
->red
, r_base
, size
)) {
3242 g_base
= r_base
+ size
;
3243 if (copy_to_user((void __user
*)(unsigned long)crtc_lut
->green
, g_base
, size
)) {
3248 b_base
= g_base
+ size
;
3249 if (copy_to_user((void __user
*)(unsigned long)crtc_lut
->blue
, b_base
, size
)) {
3254 mutex_unlock(&dev
->mode_config
.mutex
);
3258 int drm_mode_page_flip_ioctl(struct drm_device
*dev
,
3259 void *data
, struct drm_file
*file_priv
)
3261 struct drm_mode_crtc_page_flip
*page_flip
= data
;
3262 struct drm_mode_object
*obj
;
3263 struct drm_crtc
*crtc
;
3264 struct drm_framebuffer
*fb
;
3265 struct drm_pending_vblank_event
*e
= NULL
;
3266 unsigned long flags
;
3269 if (page_flip
->flags
& ~DRM_MODE_PAGE_FLIP_FLAGS
||
3270 page_flip
->reserved
!= 0)
3273 mutex_lock(&dev
->mode_config
.mutex
);
3274 obj
= drm_mode_object_find(dev
, page_flip
->crtc_id
, DRM_MODE_OBJECT_CRTC
);
3277 crtc
= obj_to_crtc(obj
);
3279 if (crtc
->fb
== NULL
) {
3280 /* The framebuffer is currently unbound, presumably
3281 * due to a hotplug event, that userspace has not
3288 if (crtc
->funcs
->page_flip
== NULL
)
3291 obj
= drm_mode_object_find(dev
, page_flip
->fb_id
, DRM_MODE_OBJECT_FB
);
3294 fb
= obj_to_fb(obj
);
3296 if (crtc
->mode
.hdisplay
> fb
->width
||
3297 crtc
->mode
.vdisplay
> fb
->height
||
3298 crtc
->x
> fb
->width
- crtc
->mode
.hdisplay
||
3299 crtc
->y
> fb
->height
- crtc
->mode
.vdisplay
) {
3300 DRM_DEBUG_KMS("Invalid fb size %ux%u for CRTC viewport %ux%u+%d+%d.\n",
3301 fb
->width
, fb
->height
,
3302 crtc
->mode
.hdisplay
, crtc
->mode
.vdisplay
,
3308 if (page_flip
->flags
& DRM_MODE_PAGE_FLIP_EVENT
) {
3310 spin_lock_irqsave(&dev
->event_lock
, flags
);
3311 if (file_priv
->event_space
< sizeof e
->event
) {
3312 spin_unlock_irqrestore(&dev
->event_lock
, flags
);
3315 file_priv
->event_space
-= sizeof e
->event
;
3316 spin_unlock_irqrestore(&dev
->event_lock
, flags
);
3318 e
= kzalloc(sizeof *e
, GFP_KERNEL
);
3320 spin_lock_irqsave(&dev
->event_lock
, flags
);
3321 file_priv
->event_space
+= sizeof e
->event
;
3322 spin_unlock_irqrestore(&dev
->event_lock
, flags
);
3326 e
->event
.base
.type
= DRM_EVENT_FLIP_COMPLETE
;
3327 e
->event
.base
.length
= sizeof e
->event
;
3328 e
->event
.user_data
= page_flip
->user_data
;
3329 e
->base
.event
= &e
->event
.base
;
3330 e
->base
.file_priv
= file_priv
;
3332 (void (*) (struct drm_pending_event
*)) kfree
;
3335 ret
= crtc
->funcs
->page_flip(crtc
, fb
, e
);
3337 spin_lock_irqsave(&dev
->event_lock
, flags
);
3338 file_priv
->event_space
+= sizeof e
->event
;
3339 spin_unlock_irqrestore(&dev
->event_lock
, flags
);
3344 mutex_unlock(&dev
->mode_config
.mutex
);
3348 void drm_mode_config_reset(struct drm_device
*dev
)
3350 struct drm_crtc
*crtc
;
3351 struct drm_encoder
*encoder
;
3352 struct drm_connector
*connector
;
3354 list_for_each_entry(crtc
, &dev
->mode_config
.crtc_list
, head
)
3355 if (crtc
->funcs
->reset
)
3356 crtc
->funcs
->reset(crtc
);
3358 list_for_each_entry(encoder
, &dev
->mode_config
.encoder_list
, head
)
3359 if (encoder
->funcs
->reset
)
3360 encoder
->funcs
->reset(encoder
);
3362 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
, head
)
3363 if (connector
->funcs
->reset
)
3364 connector
->funcs
->reset(connector
);
3366 EXPORT_SYMBOL(drm_mode_config_reset
);
3368 int drm_mode_create_dumb_ioctl(struct drm_device
*dev
,
3369 void *data
, struct drm_file
*file_priv
)
3371 struct drm_mode_create_dumb
*args
= data
;
3373 if (!dev
->driver
->dumb_create
)
3375 return dev
->driver
->dumb_create(file_priv
, dev
, args
);
3378 int drm_mode_mmap_dumb_ioctl(struct drm_device
*dev
,
3379 void *data
, struct drm_file
*file_priv
)
3381 struct drm_mode_map_dumb
*args
= data
;
3383 /* call driver ioctl to get mmap offset */
3384 if (!dev
->driver
->dumb_map_offset
)
3387 return dev
->driver
->dumb_map_offset(file_priv
, dev
, args
->handle
, &args
->offset
);
3390 int drm_mode_destroy_dumb_ioctl(struct drm_device
*dev
,
3391 void *data
, struct drm_file
*file_priv
)
3393 struct drm_mode_destroy_dumb
*args
= data
;
3395 if (!dev
->driver
->dumb_destroy
)
3398 return dev
->driver
->dumb_destroy(file_priv
, dev
, args
->handle
);
3402 * Just need to support RGB formats here for compat with code that doesn't
3403 * use pixel formats directly yet.
3405 void drm_fb_get_bpp_depth(uint32_t format
, unsigned int *depth
,
3409 case DRM_FORMAT_RGB332
:
3410 case DRM_FORMAT_BGR233
:
3414 case DRM_FORMAT_XRGB1555
:
3415 case DRM_FORMAT_XBGR1555
:
3416 case DRM_FORMAT_RGBX5551
:
3417 case DRM_FORMAT_BGRX5551
:
3418 case DRM_FORMAT_ARGB1555
:
3419 case DRM_FORMAT_ABGR1555
:
3420 case DRM_FORMAT_RGBA5551
:
3421 case DRM_FORMAT_BGRA5551
:
3425 case DRM_FORMAT_RGB565
:
3426 case DRM_FORMAT_BGR565
:
3430 case DRM_FORMAT_RGB888
:
3431 case DRM_FORMAT_BGR888
:
3435 case DRM_FORMAT_XRGB8888
:
3436 case DRM_FORMAT_XBGR8888
:
3437 case DRM_FORMAT_RGBX8888
:
3438 case DRM_FORMAT_BGRX8888
:
3442 case DRM_FORMAT_XRGB2101010
:
3443 case DRM_FORMAT_XBGR2101010
:
3444 case DRM_FORMAT_RGBX1010102
:
3445 case DRM_FORMAT_BGRX1010102
:
3446 case DRM_FORMAT_ARGB2101010
:
3447 case DRM_FORMAT_ABGR2101010
:
3448 case DRM_FORMAT_RGBA1010102
:
3449 case DRM_FORMAT_BGRA1010102
:
3453 case DRM_FORMAT_ARGB8888
:
3454 case DRM_FORMAT_ABGR8888
:
3455 case DRM_FORMAT_RGBA8888
:
3456 case DRM_FORMAT_BGRA8888
:
3461 DRM_DEBUG_KMS("unsupported pixel format\n");
3467 EXPORT_SYMBOL(drm_fb_get_bpp_depth
);