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");
354 drm_mode_object_put(dev
, &fb
->base
);
356 dev
->mode_config
.num_fb
--;
358 EXPORT_SYMBOL(drm_framebuffer_cleanup
);
361 * drm_crtc_init - Initialise a new CRTC object
363 * @crtc: CRTC object to init
364 * @funcs: callbacks for the new CRTC
367 * Caller must hold mode config lock.
369 * Inits a new object created as base part of an driver crtc object.
371 void drm_crtc_init(struct drm_device
*dev
, struct drm_crtc
*crtc
,
372 const struct drm_crtc_funcs
*funcs
)
377 mutex_lock(&dev
->mode_config
.mutex
);
378 drm_mode_object_get(dev
, &crtc
->base
, DRM_MODE_OBJECT_CRTC
);
380 list_add_tail(&crtc
->head
, &dev
->mode_config
.crtc_list
);
381 dev
->mode_config
.num_crtc
++;
382 mutex_unlock(&dev
->mode_config
.mutex
);
384 EXPORT_SYMBOL(drm_crtc_init
);
387 * drm_crtc_cleanup - Cleans up the core crtc usage.
388 * @crtc: CRTC to cleanup
391 * Caller must hold mode config lock.
393 * Cleanup @crtc. Removes from drm modesetting space
394 * does NOT free object, caller does that.
396 void drm_crtc_cleanup(struct drm_crtc
*crtc
)
398 struct drm_device
*dev
= crtc
->dev
;
400 if (crtc
->gamma_store
) {
401 kfree(crtc
->gamma_store
);
402 crtc
->gamma_store
= NULL
;
405 drm_mode_object_put(dev
, &crtc
->base
);
406 list_del(&crtc
->head
);
407 dev
->mode_config
.num_crtc
--;
409 EXPORT_SYMBOL(drm_crtc_cleanup
);
412 * drm_mode_probed_add - add a mode to a connector's probed mode list
413 * @connector: connector the new mode
417 * Caller must hold mode config lock.
419 * Add @mode to @connector's mode list for later use.
421 void drm_mode_probed_add(struct drm_connector
*connector
,
422 struct drm_display_mode
*mode
)
424 list_add(&mode
->head
, &connector
->probed_modes
);
426 EXPORT_SYMBOL(drm_mode_probed_add
);
429 * drm_mode_remove - remove and free a mode
430 * @connector: connector list to modify
431 * @mode: mode to remove
434 * Caller must hold mode config lock.
436 * Remove @mode from @connector's mode list, then free it.
438 void drm_mode_remove(struct drm_connector
*connector
,
439 struct drm_display_mode
*mode
)
441 list_del(&mode
->head
);
444 EXPORT_SYMBOL(drm_mode_remove
);
447 * drm_connector_init - Init a preallocated connector
449 * @connector: the connector to init
450 * @funcs: callbacks for this connector
451 * @name: user visible name of the connector
454 * Caller must hold @dev's mode_config lock.
456 * Initialises a preallocated connector. Connectors should be
457 * subclassed as part of driver connector objects.
459 void drm_connector_init(struct drm_device
*dev
,
460 struct drm_connector
*connector
,
461 const struct drm_connector_funcs
*funcs
,
464 mutex_lock(&dev
->mode_config
.mutex
);
466 connector
->dev
= dev
;
467 connector
->funcs
= funcs
;
468 drm_mode_object_get(dev
, &connector
->base
, DRM_MODE_OBJECT_CONNECTOR
);
469 connector
->connector_type
= connector_type
;
470 connector
->connector_type_id
=
471 ++drm_connector_enum_list
[connector_type
].count
; /* TODO */
472 INIT_LIST_HEAD(&connector
->user_modes
);
473 INIT_LIST_HEAD(&connector
->probed_modes
);
474 INIT_LIST_HEAD(&connector
->modes
);
475 connector
->edid_blob_ptr
= NULL
;
477 list_add_tail(&connector
->head
, &dev
->mode_config
.connector_list
);
478 dev
->mode_config
.num_connector
++;
480 if (connector_type
!= DRM_MODE_CONNECTOR_VIRTUAL
)
481 drm_connector_attach_property(connector
,
482 dev
->mode_config
.edid_property
,
485 drm_connector_attach_property(connector
,
486 dev
->mode_config
.dpms_property
, 0);
488 mutex_unlock(&dev
->mode_config
.mutex
);
490 EXPORT_SYMBOL(drm_connector_init
);
493 * drm_connector_cleanup - cleans up an initialised connector
494 * @connector: connector to cleanup
497 * Caller must hold @dev's mode_config lock.
499 * Cleans up the connector but doesn't free the object.
501 void drm_connector_cleanup(struct drm_connector
*connector
)
503 struct drm_device
*dev
= connector
->dev
;
504 struct drm_display_mode
*mode
, *t
;
506 list_for_each_entry_safe(mode
, t
, &connector
->probed_modes
, head
)
507 drm_mode_remove(connector
, mode
);
509 list_for_each_entry_safe(mode
, t
, &connector
->modes
, head
)
510 drm_mode_remove(connector
, mode
);
512 list_for_each_entry_safe(mode
, t
, &connector
->user_modes
, head
)
513 drm_mode_remove(connector
, mode
);
515 mutex_lock(&dev
->mode_config
.mutex
);
516 drm_mode_object_put(dev
, &connector
->base
);
517 list_del(&connector
->head
);
518 dev
->mode_config
.num_connector
--;
519 mutex_unlock(&dev
->mode_config
.mutex
);
521 EXPORT_SYMBOL(drm_connector_cleanup
);
523 void drm_encoder_init(struct drm_device
*dev
,
524 struct drm_encoder
*encoder
,
525 const struct drm_encoder_funcs
*funcs
,
528 mutex_lock(&dev
->mode_config
.mutex
);
532 drm_mode_object_get(dev
, &encoder
->base
, DRM_MODE_OBJECT_ENCODER
);
533 encoder
->encoder_type
= encoder_type
;
534 encoder
->funcs
= funcs
;
536 list_add_tail(&encoder
->head
, &dev
->mode_config
.encoder_list
);
537 dev
->mode_config
.num_encoder
++;
539 mutex_unlock(&dev
->mode_config
.mutex
);
541 EXPORT_SYMBOL(drm_encoder_init
);
543 void drm_encoder_cleanup(struct drm_encoder
*encoder
)
545 struct drm_device
*dev
= encoder
->dev
;
546 mutex_lock(&dev
->mode_config
.mutex
);
547 drm_mode_object_put(dev
, &encoder
->base
);
548 list_del(&encoder
->head
);
549 dev
->mode_config
.num_encoder
--;
550 mutex_unlock(&dev
->mode_config
.mutex
);
552 EXPORT_SYMBOL(drm_encoder_cleanup
);
554 int drm_plane_init(struct drm_device
*dev
, struct drm_plane
*plane
,
555 unsigned long possible_crtcs
,
556 const struct drm_plane_funcs
*funcs
,
557 uint32_t *formats
, uint32_t format_count
)
559 mutex_lock(&dev
->mode_config
.mutex
);
562 drm_mode_object_get(dev
, &plane
->base
, DRM_MODE_OBJECT_PLANE
);
563 plane
->funcs
= funcs
;
564 plane
->format_types
= kmalloc(sizeof(uint32_t) * format_count
,
566 if (!plane
->format_types
) {
567 DRM_DEBUG_KMS("out of memory when allocating plane\n");
568 drm_mode_object_put(dev
, &plane
->base
);
569 mutex_unlock(&dev
->mode_config
.mutex
);
573 memcpy(plane
->format_types
, formats
, format_count
* sizeof(uint32_t));
574 plane
->format_count
= format_count
;
575 plane
->possible_crtcs
= possible_crtcs
;
577 list_add_tail(&plane
->head
, &dev
->mode_config
.plane_list
);
578 dev
->mode_config
.num_plane
++;
580 mutex_unlock(&dev
->mode_config
.mutex
);
584 EXPORT_SYMBOL(drm_plane_init
);
586 void drm_plane_cleanup(struct drm_plane
*plane
)
588 struct drm_device
*dev
= plane
->dev
;
590 mutex_lock(&dev
->mode_config
.mutex
);
591 kfree(plane
->format_types
);
592 drm_mode_object_put(dev
, &plane
->base
);
593 list_del(&plane
->head
);
594 dev
->mode_config
.num_plane
--;
595 mutex_unlock(&dev
->mode_config
.mutex
);
597 EXPORT_SYMBOL(drm_plane_cleanup
);
600 * drm_mode_create - create a new display mode
604 * Caller must hold DRM mode_config lock.
606 * Create a new drm_display_mode, give it an ID, and return it.
609 * Pointer to new mode on success, NULL on error.
611 struct drm_display_mode
*drm_mode_create(struct drm_device
*dev
)
613 struct drm_display_mode
*nmode
;
615 nmode
= kzalloc(sizeof(struct drm_display_mode
), GFP_KERNEL
);
619 drm_mode_object_get(dev
, &nmode
->base
, DRM_MODE_OBJECT_MODE
);
622 EXPORT_SYMBOL(drm_mode_create
);
625 * drm_mode_destroy - remove a mode
627 * @mode: mode to remove
630 * Caller must hold mode config lock.
632 * Free @mode's unique identifier, then free it.
634 void drm_mode_destroy(struct drm_device
*dev
, struct drm_display_mode
*mode
)
636 drm_mode_object_put(dev
, &mode
->base
);
640 EXPORT_SYMBOL(drm_mode_destroy
);
642 static int drm_mode_create_standard_connector_properties(struct drm_device
*dev
)
644 struct drm_property
*edid
;
645 struct drm_property
*dpms
;
649 * Standard properties (apply to all connectors)
651 edid
= drm_property_create(dev
, DRM_MODE_PROP_BLOB
|
652 DRM_MODE_PROP_IMMUTABLE
,
654 dev
->mode_config
.edid_property
= edid
;
656 dpms
= drm_property_create(dev
, DRM_MODE_PROP_ENUM
,
657 "DPMS", ARRAY_SIZE(drm_dpms_enum_list
));
658 for (i
= 0; i
< ARRAY_SIZE(drm_dpms_enum_list
); i
++)
659 drm_property_add_enum(dpms
, i
, drm_dpms_enum_list
[i
].type
,
660 drm_dpms_enum_list
[i
].name
);
661 dev
->mode_config
.dpms_property
= dpms
;
667 * drm_mode_create_dvi_i_properties - create DVI-I specific connector properties
670 * Called by a driver the first time a DVI-I connector is made.
672 int drm_mode_create_dvi_i_properties(struct drm_device
*dev
)
674 struct drm_property
*dvi_i_selector
;
675 struct drm_property
*dvi_i_subconnector
;
678 if (dev
->mode_config
.dvi_i_select_subconnector_property
)
682 drm_property_create(dev
, DRM_MODE_PROP_ENUM
,
683 "select subconnector",
684 ARRAY_SIZE(drm_dvi_i_select_enum_list
));
685 for (i
= 0; i
< ARRAY_SIZE(drm_dvi_i_select_enum_list
); i
++)
686 drm_property_add_enum(dvi_i_selector
, i
,
687 drm_dvi_i_select_enum_list
[i
].type
,
688 drm_dvi_i_select_enum_list
[i
].name
);
689 dev
->mode_config
.dvi_i_select_subconnector_property
= dvi_i_selector
;
692 drm_property_create(dev
, DRM_MODE_PROP_ENUM
|
693 DRM_MODE_PROP_IMMUTABLE
,
695 ARRAY_SIZE(drm_dvi_i_subconnector_enum_list
));
696 for (i
= 0; i
< ARRAY_SIZE(drm_dvi_i_subconnector_enum_list
); i
++)
697 drm_property_add_enum(dvi_i_subconnector
, i
,
698 drm_dvi_i_subconnector_enum_list
[i
].type
,
699 drm_dvi_i_subconnector_enum_list
[i
].name
);
700 dev
->mode_config
.dvi_i_subconnector_property
= dvi_i_subconnector
;
704 EXPORT_SYMBOL(drm_mode_create_dvi_i_properties
);
707 * drm_create_tv_properties - create TV specific connector properties
709 * @num_modes: number of different TV formats (modes) supported
710 * @modes: array of pointers to strings containing name of each format
712 * Called by a driver's TV initialization routine, this function creates
713 * the TV specific connector properties for a given device. Caller is
714 * responsible for allocating a list of format names and passing them to
717 int drm_mode_create_tv_properties(struct drm_device
*dev
, int num_modes
,
720 struct drm_property
*tv_selector
;
721 struct drm_property
*tv_subconnector
;
724 if (dev
->mode_config
.tv_select_subconnector_property
)
728 * Basic connector properties
730 tv_selector
= drm_property_create(dev
, DRM_MODE_PROP_ENUM
,
731 "select subconnector",
732 ARRAY_SIZE(drm_tv_select_enum_list
));
733 for (i
= 0; i
< ARRAY_SIZE(drm_tv_select_enum_list
); i
++)
734 drm_property_add_enum(tv_selector
, i
,
735 drm_tv_select_enum_list
[i
].type
,
736 drm_tv_select_enum_list
[i
].name
);
737 dev
->mode_config
.tv_select_subconnector_property
= tv_selector
;
740 drm_property_create(dev
, DRM_MODE_PROP_ENUM
|
741 DRM_MODE_PROP_IMMUTABLE
, "subconnector",
742 ARRAY_SIZE(drm_tv_subconnector_enum_list
));
743 for (i
= 0; i
< ARRAY_SIZE(drm_tv_subconnector_enum_list
); i
++)
744 drm_property_add_enum(tv_subconnector
, i
,
745 drm_tv_subconnector_enum_list
[i
].type
,
746 drm_tv_subconnector_enum_list
[i
].name
);
747 dev
->mode_config
.tv_subconnector_property
= tv_subconnector
;
750 * Other, TV specific properties: margins & TV modes.
752 dev
->mode_config
.tv_left_margin_property
=
753 drm_property_create(dev
, DRM_MODE_PROP_RANGE
,
755 dev
->mode_config
.tv_left_margin_property
->values
[0] = 0;
756 dev
->mode_config
.tv_left_margin_property
->values
[1] = 100;
758 dev
->mode_config
.tv_right_margin_property
=
759 drm_property_create(dev
, DRM_MODE_PROP_RANGE
,
761 dev
->mode_config
.tv_right_margin_property
->values
[0] = 0;
762 dev
->mode_config
.tv_right_margin_property
->values
[1] = 100;
764 dev
->mode_config
.tv_top_margin_property
=
765 drm_property_create(dev
, DRM_MODE_PROP_RANGE
,
767 dev
->mode_config
.tv_top_margin_property
->values
[0] = 0;
768 dev
->mode_config
.tv_top_margin_property
->values
[1] = 100;
770 dev
->mode_config
.tv_bottom_margin_property
=
771 drm_property_create(dev
, DRM_MODE_PROP_RANGE
,
773 dev
->mode_config
.tv_bottom_margin_property
->values
[0] = 0;
774 dev
->mode_config
.tv_bottom_margin_property
->values
[1] = 100;
776 dev
->mode_config
.tv_mode_property
=
777 drm_property_create(dev
, DRM_MODE_PROP_ENUM
,
779 for (i
= 0; i
< num_modes
; i
++)
780 drm_property_add_enum(dev
->mode_config
.tv_mode_property
, i
,
783 dev
->mode_config
.tv_brightness_property
=
784 drm_property_create(dev
, DRM_MODE_PROP_RANGE
,
786 dev
->mode_config
.tv_brightness_property
->values
[0] = 0;
787 dev
->mode_config
.tv_brightness_property
->values
[1] = 100;
789 dev
->mode_config
.tv_contrast_property
=
790 drm_property_create(dev
, DRM_MODE_PROP_RANGE
,
792 dev
->mode_config
.tv_contrast_property
->values
[0] = 0;
793 dev
->mode_config
.tv_contrast_property
->values
[1] = 100;
795 dev
->mode_config
.tv_flicker_reduction_property
=
796 drm_property_create(dev
, DRM_MODE_PROP_RANGE
,
797 "flicker reduction", 2);
798 dev
->mode_config
.tv_flicker_reduction_property
->values
[0] = 0;
799 dev
->mode_config
.tv_flicker_reduction_property
->values
[1] = 100;
801 dev
->mode_config
.tv_overscan_property
=
802 drm_property_create(dev
, DRM_MODE_PROP_RANGE
,
804 dev
->mode_config
.tv_overscan_property
->values
[0] = 0;
805 dev
->mode_config
.tv_overscan_property
->values
[1] = 100;
807 dev
->mode_config
.tv_saturation_property
=
808 drm_property_create(dev
, DRM_MODE_PROP_RANGE
,
810 dev
->mode_config
.tv_saturation_property
->values
[0] = 0;
811 dev
->mode_config
.tv_saturation_property
->values
[1] = 100;
813 dev
->mode_config
.tv_hue_property
=
814 drm_property_create(dev
, DRM_MODE_PROP_RANGE
,
816 dev
->mode_config
.tv_hue_property
->values
[0] = 0;
817 dev
->mode_config
.tv_hue_property
->values
[1] = 100;
821 EXPORT_SYMBOL(drm_mode_create_tv_properties
);
824 * drm_mode_create_scaling_mode_property - create scaling mode property
827 * Called by a driver the first time it's needed, must be attached to desired
830 int drm_mode_create_scaling_mode_property(struct drm_device
*dev
)
832 struct drm_property
*scaling_mode
;
835 if (dev
->mode_config
.scaling_mode_property
)
839 drm_property_create(dev
, DRM_MODE_PROP_ENUM
, "scaling mode",
840 ARRAY_SIZE(drm_scaling_mode_enum_list
));
841 for (i
= 0; i
< ARRAY_SIZE(drm_scaling_mode_enum_list
); i
++)
842 drm_property_add_enum(scaling_mode
, i
,
843 drm_scaling_mode_enum_list
[i
].type
,
844 drm_scaling_mode_enum_list
[i
].name
);
846 dev
->mode_config
.scaling_mode_property
= scaling_mode
;
850 EXPORT_SYMBOL(drm_mode_create_scaling_mode_property
);
853 * drm_mode_create_dithering_property - create dithering property
856 * Called by a driver the first time it's needed, must be attached to desired
859 int drm_mode_create_dithering_property(struct drm_device
*dev
)
861 struct drm_property
*dithering_mode
;
864 if (dev
->mode_config
.dithering_mode_property
)
868 drm_property_create(dev
, DRM_MODE_PROP_ENUM
, "dithering",
869 ARRAY_SIZE(drm_dithering_mode_enum_list
));
870 for (i
= 0; i
< ARRAY_SIZE(drm_dithering_mode_enum_list
); i
++)
871 drm_property_add_enum(dithering_mode
, i
,
872 drm_dithering_mode_enum_list
[i
].type
,
873 drm_dithering_mode_enum_list
[i
].name
);
874 dev
->mode_config
.dithering_mode_property
= dithering_mode
;
878 EXPORT_SYMBOL(drm_mode_create_dithering_property
);
881 * drm_mode_create_dirty_property - create dirty property
884 * Called by a driver the first time it's needed, must be attached to desired
887 int drm_mode_create_dirty_info_property(struct drm_device
*dev
)
889 struct drm_property
*dirty_info
;
892 if (dev
->mode_config
.dirty_info_property
)
896 drm_property_create(dev
, DRM_MODE_PROP_ENUM
|
897 DRM_MODE_PROP_IMMUTABLE
,
899 ARRAY_SIZE(drm_dirty_info_enum_list
));
900 for (i
= 0; i
< ARRAY_SIZE(drm_dirty_info_enum_list
); i
++)
901 drm_property_add_enum(dirty_info
, i
,
902 drm_dirty_info_enum_list
[i
].type
,
903 drm_dirty_info_enum_list
[i
].name
);
904 dev
->mode_config
.dirty_info_property
= dirty_info
;
908 EXPORT_SYMBOL(drm_mode_create_dirty_info_property
);
911 * drm_mode_config_init - initialize DRM mode_configuration structure
915 * None, should happen single threaded at init time.
917 * Initialize @dev's mode_config structure, used for tracking the graphics
918 * configuration of @dev.
920 void drm_mode_config_init(struct drm_device
*dev
)
922 mutex_init(&dev
->mode_config
.mutex
);
923 mutex_init(&dev
->mode_config
.idr_mutex
);
924 INIT_LIST_HEAD(&dev
->mode_config
.fb_list
);
925 INIT_LIST_HEAD(&dev
->mode_config
.crtc_list
);
926 INIT_LIST_HEAD(&dev
->mode_config
.connector_list
);
927 INIT_LIST_HEAD(&dev
->mode_config
.encoder_list
);
928 INIT_LIST_HEAD(&dev
->mode_config
.property_list
);
929 INIT_LIST_HEAD(&dev
->mode_config
.property_blob_list
);
930 INIT_LIST_HEAD(&dev
->mode_config
.plane_list
);
931 idr_init(&dev
->mode_config
.crtc_idr
);
933 mutex_lock(&dev
->mode_config
.mutex
);
934 drm_mode_create_standard_connector_properties(dev
);
935 mutex_unlock(&dev
->mode_config
.mutex
);
937 /* Just to be sure */
938 dev
->mode_config
.num_fb
= 0;
939 dev
->mode_config
.num_connector
= 0;
940 dev
->mode_config
.num_crtc
= 0;
941 dev
->mode_config
.num_encoder
= 0;
943 EXPORT_SYMBOL(drm_mode_config_init
);
945 int drm_mode_group_init(struct drm_device
*dev
, struct drm_mode_group
*group
)
947 uint32_t total_objects
= 0;
949 total_objects
+= dev
->mode_config
.num_crtc
;
950 total_objects
+= dev
->mode_config
.num_connector
;
951 total_objects
+= dev
->mode_config
.num_encoder
;
953 group
->id_list
= kzalloc(total_objects
* sizeof(uint32_t), GFP_KERNEL
);
957 group
->num_crtcs
= 0;
958 group
->num_connectors
= 0;
959 group
->num_encoders
= 0;
963 int drm_mode_group_init_legacy_group(struct drm_device
*dev
,
964 struct drm_mode_group
*group
)
966 struct drm_crtc
*crtc
;
967 struct drm_encoder
*encoder
;
968 struct drm_connector
*connector
;
971 if ((ret
= drm_mode_group_init(dev
, group
)))
974 list_for_each_entry(crtc
, &dev
->mode_config
.crtc_list
, head
)
975 group
->id_list
[group
->num_crtcs
++] = crtc
->base
.id
;
977 list_for_each_entry(encoder
, &dev
->mode_config
.encoder_list
, head
)
978 group
->id_list
[group
->num_crtcs
+ group
->num_encoders
++] =
981 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
, head
)
982 group
->id_list
[group
->num_crtcs
+ group
->num_encoders
+
983 group
->num_connectors
++] = connector
->base
.id
;
989 * drm_mode_config_cleanup - free up DRM mode_config info
993 * Caller must hold mode config lock.
995 * Free up all the connectors and CRTCs associated with this DRM device, then
996 * free up the framebuffers and associated buffer objects.
998 * FIXME: cleanup any dangling user buffer objects too
1000 void drm_mode_config_cleanup(struct drm_device
*dev
)
1002 struct drm_connector
*connector
, *ot
;
1003 struct drm_crtc
*crtc
, *ct
;
1004 struct drm_encoder
*encoder
, *enct
;
1005 struct drm_framebuffer
*fb
, *fbt
;
1006 struct drm_property
*property
, *pt
;
1007 struct drm_plane
*plane
, *plt
;
1009 list_for_each_entry_safe(encoder
, enct
, &dev
->mode_config
.encoder_list
,
1011 encoder
->funcs
->destroy(encoder
);
1014 list_for_each_entry_safe(connector
, ot
,
1015 &dev
->mode_config
.connector_list
, head
) {
1016 connector
->funcs
->destroy(connector
);
1019 list_for_each_entry_safe(property
, pt
, &dev
->mode_config
.property_list
,
1021 drm_property_destroy(dev
, property
);
1024 list_for_each_entry_safe(fb
, fbt
, &dev
->mode_config
.fb_list
, head
) {
1025 fb
->funcs
->destroy(fb
);
1028 list_for_each_entry_safe(crtc
, ct
, &dev
->mode_config
.crtc_list
, head
) {
1029 crtc
->funcs
->destroy(crtc
);
1032 list_for_each_entry_safe(plane
, plt
, &dev
->mode_config
.plane_list
,
1034 plane
->funcs
->destroy(plane
);
1037 EXPORT_SYMBOL(drm_mode_config_cleanup
);
1040 * drm_crtc_convert_to_umode - convert a drm_display_mode into a modeinfo
1041 * @out: drm_mode_modeinfo struct to return to the user
1042 * @in: drm_display_mode to use
1047 * Convert a drm_display_mode into a drm_mode_modeinfo structure to return to
1050 void drm_crtc_convert_to_umode(struct drm_mode_modeinfo
*out
,
1051 struct drm_display_mode
*in
)
1053 out
->clock
= in
->clock
;
1054 out
->hdisplay
= in
->hdisplay
;
1055 out
->hsync_start
= in
->hsync_start
;
1056 out
->hsync_end
= in
->hsync_end
;
1057 out
->htotal
= in
->htotal
;
1058 out
->hskew
= in
->hskew
;
1059 out
->vdisplay
= in
->vdisplay
;
1060 out
->vsync_start
= in
->vsync_start
;
1061 out
->vsync_end
= in
->vsync_end
;
1062 out
->vtotal
= in
->vtotal
;
1063 out
->vscan
= in
->vscan
;
1064 out
->vrefresh
= in
->vrefresh
;
1065 out
->flags
= in
->flags
;
1066 out
->type
= in
->type
;
1067 strncpy(out
->name
, in
->name
, DRM_DISPLAY_MODE_LEN
);
1068 out
->name
[DRM_DISPLAY_MODE_LEN
-1] = 0;
1072 * drm_crtc_convert_to_umode - convert a modeinfo into a drm_display_mode
1073 * @out: drm_display_mode to return to the user
1074 * @in: drm_mode_modeinfo to use
1079 * Convert a drm_mode_modeinfo into a drm_display_mode structure to return to
1082 void drm_crtc_convert_umode(struct drm_display_mode
*out
,
1083 struct drm_mode_modeinfo
*in
)
1085 out
->clock
= in
->clock
;
1086 out
->hdisplay
= in
->hdisplay
;
1087 out
->hsync_start
= in
->hsync_start
;
1088 out
->hsync_end
= in
->hsync_end
;
1089 out
->htotal
= in
->htotal
;
1090 out
->hskew
= in
->hskew
;
1091 out
->vdisplay
= in
->vdisplay
;
1092 out
->vsync_start
= in
->vsync_start
;
1093 out
->vsync_end
= in
->vsync_end
;
1094 out
->vtotal
= in
->vtotal
;
1095 out
->vscan
= in
->vscan
;
1096 out
->vrefresh
= in
->vrefresh
;
1097 out
->flags
= in
->flags
;
1098 out
->type
= in
->type
;
1099 strncpy(out
->name
, in
->name
, DRM_DISPLAY_MODE_LEN
);
1100 out
->name
[DRM_DISPLAY_MODE_LEN
-1] = 0;
1104 * drm_mode_getresources - get graphics configuration
1105 * @inode: inode from the ioctl
1106 * @filp: file * from the ioctl
1107 * @cmd: cmd from ioctl
1108 * @arg: arg from ioctl
1111 * Takes mode config lock.
1113 * Construct a set of configuration description structures and return
1114 * them to the user, including CRTC, connector and framebuffer configuration.
1116 * Called by the user via ioctl.
1119 * Zero on success, errno on failure.
1121 int drm_mode_getresources(struct drm_device
*dev
, void *data
,
1122 struct drm_file
*file_priv
)
1124 struct drm_mode_card_res
*card_res
= data
;
1125 struct list_head
*lh
;
1126 struct drm_framebuffer
*fb
;
1127 struct drm_connector
*connector
;
1128 struct drm_crtc
*crtc
;
1129 struct drm_encoder
*encoder
;
1131 int connector_count
= 0;
1134 int encoder_count
= 0;
1136 uint32_t __user
*fb_id
;
1137 uint32_t __user
*crtc_id
;
1138 uint32_t __user
*connector_id
;
1139 uint32_t __user
*encoder_id
;
1140 struct drm_mode_group
*mode_group
;
1142 if (!drm_core_check_feature(dev
, DRIVER_MODESET
))
1145 mutex_lock(&dev
->mode_config
.mutex
);
1148 * For the non-control nodes we need to limit the list of resources
1149 * by IDs in the group list for this node
1151 list_for_each(lh
, &file_priv
->fbs
)
1154 mode_group
= &file_priv
->master
->minor
->mode_group
;
1155 if (file_priv
->master
->minor
->type
== DRM_MINOR_CONTROL
) {
1157 list_for_each(lh
, &dev
->mode_config
.crtc_list
)
1160 list_for_each(lh
, &dev
->mode_config
.connector_list
)
1163 list_for_each(lh
, &dev
->mode_config
.encoder_list
)
1167 crtc_count
= mode_group
->num_crtcs
;
1168 connector_count
= mode_group
->num_connectors
;
1169 encoder_count
= mode_group
->num_encoders
;
1172 card_res
->max_height
= dev
->mode_config
.max_height
;
1173 card_res
->min_height
= dev
->mode_config
.min_height
;
1174 card_res
->max_width
= dev
->mode_config
.max_width
;
1175 card_res
->min_width
= dev
->mode_config
.min_width
;
1177 /* handle this in 4 parts */
1179 if (card_res
->count_fbs
>= fb_count
) {
1181 fb_id
= (uint32_t __user
*)(unsigned long)card_res
->fb_id_ptr
;
1182 list_for_each_entry(fb
, &file_priv
->fbs
, filp_head
) {
1183 if (put_user(fb
->base
.id
, fb_id
+ copied
)) {
1190 card_res
->count_fbs
= fb_count
;
1193 if (card_res
->count_crtcs
>= crtc_count
) {
1195 crtc_id
= (uint32_t __user
*)(unsigned long)card_res
->crtc_id_ptr
;
1196 if (file_priv
->master
->minor
->type
== DRM_MINOR_CONTROL
) {
1197 list_for_each_entry(crtc
, &dev
->mode_config
.crtc_list
,
1199 DRM_DEBUG_KMS("[CRTC:%d]\n", crtc
->base
.id
);
1200 if (put_user(crtc
->base
.id
, crtc_id
+ copied
)) {
1207 for (i
= 0; i
< mode_group
->num_crtcs
; i
++) {
1208 if (put_user(mode_group
->id_list
[i
],
1209 crtc_id
+ copied
)) {
1217 card_res
->count_crtcs
= crtc_count
;
1220 if (card_res
->count_encoders
>= encoder_count
) {
1222 encoder_id
= (uint32_t __user
*)(unsigned long)card_res
->encoder_id_ptr
;
1223 if (file_priv
->master
->minor
->type
== DRM_MINOR_CONTROL
) {
1224 list_for_each_entry(encoder
,
1225 &dev
->mode_config
.encoder_list
,
1227 DRM_DEBUG_KMS("[ENCODER:%d:%s]\n", encoder
->base
.id
,
1228 drm_get_encoder_name(encoder
));
1229 if (put_user(encoder
->base
.id
, encoder_id
+
1237 for (i
= mode_group
->num_crtcs
; i
< mode_group
->num_crtcs
+ mode_group
->num_encoders
; i
++) {
1238 if (put_user(mode_group
->id_list
[i
],
1239 encoder_id
+ copied
)) {
1248 card_res
->count_encoders
= encoder_count
;
1251 if (card_res
->count_connectors
>= connector_count
) {
1253 connector_id
= (uint32_t __user
*)(unsigned long)card_res
->connector_id_ptr
;
1254 if (file_priv
->master
->minor
->type
== DRM_MINOR_CONTROL
) {
1255 list_for_each_entry(connector
,
1256 &dev
->mode_config
.connector_list
,
1258 DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n",
1260 drm_get_connector_name(connector
));
1261 if (put_user(connector
->base
.id
,
1262 connector_id
+ copied
)) {
1269 int start
= mode_group
->num_crtcs
+
1270 mode_group
->num_encoders
;
1271 for (i
= start
; i
< start
+ mode_group
->num_connectors
; i
++) {
1272 if (put_user(mode_group
->id_list
[i
],
1273 connector_id
+ copied
)) {
1281 card_res
->count_connectors
= connector_count
;
1283 DRM_DEBUG_KMS("CRTC[%d] CONNECTORS[%d] ENCODERS[%d]\n", card_res
->count_crtcs
,
1284 card_res
->count_connectors
, card_res
->count_encoders
);
1287 mutex_unlock(&dev
->mode_config
.mutex
);
1292 * drm_mode_getcrtc - get CRTC configuration
1293 * @inode: inode from the ioctl
1294 * @filp: file * from the ioctl
1295 * @cmd: cmd from ioctl
1296 * @arg: arg from ioctl
1301 * Construct a CRTC configuration structure to return to the user.
1303 * Called by the user via ioctl.
1306 * Zero on success, errno on failure.
1308 int drm_mode_getcrtc(struct drm_device
*dev
,
1309 void *data
, struct drm_file
*file_priv
)
1311 struct drm_mode_crtc
*crtc_resp
= data
;
1312 struct drm_crtc
*crtc
;
1313 struct drm_mode_object
*obj
;
1316 if (!drm_core_check_feature(dev
, DRIVER_MODESET
))
1319 mutex_lock(&dev
->mode_config
.mutex
);
1321 obj
= drm_mode_object_find(dev
, crtc_resp
->crtc_id
,
1322 DRM_MODE_OBJECT_CRTC
);
1327 crtc
= obj_to_crtc(obj
);
1329 crtc_resp
->x
= crtc
->x
;
1330 crtc_resp
->y
= crtc
->y
;
1331 crtc_resp
->gamma_size
= crtc
->gamma_size
;
1333 crtc_resp
->fb_id
= crtc
->fb
->base
.id
;
1335 crtc_resp
->fb_id
= 0;
1337 if (crtc
->enabled
) {
1339 drm_crtc_convert_to_umode(&crtc_resp
->mode
, &crtc
->mode
);
1340 crtc_resp
->mode_valid
= 1;
1343 crtc_resp
->mode_valid
= 0;
1347 mutex_unlock(&dev
->mode_config
.mutex
);
1352 * drm_mode_getconnector - get connector configuration
1353 * @inode: inode from the ioctl
1354 * @filp: file * from the ioctl
1355 * @cmd: cmd from ioctl
1356 * @arg: arg from ioctl
1361 * Construct a connector configuration structure to return to the user.
1363 * Called by the user via ioctl.
1366 * Zero on success, errno on failure.
1368 int drm_mode_getconnector(struct drm_device
*dev
, void *data
,
1369 struct drm_file
*file_priv
)
1371 struct drm_mode_get_connector
*out_resp
= data
;
1372 struct drm_mode_object
*obj
;
1373 struct drm_connector
*connector
;
1374 struct drm_display_mode
*mode
;
1376 int props_count
= 0;
1377 int encoders_count
= 0;
1381 struct drm_mode_modeinfo u_mode
;
1382 struct drm_mode_modeinfo __user
*mode_ptr
;
1383 uint32_t __user
*prop_ptr
;
1384 uint64_t __user
*prop_values
;
1385 uint32_t __user
*encoder_ptr
;
1387 if (!drm_core_check_feature(dev
, DRIVER_MODESET
))
1390 memset(&u_mode
, 0, sizeof(struct drm_mode_modeinfo
));
1392 DRM_DEBUG_KMS("[CONNECTOR:%d:?]\n", out_resp
->connector_id
);
1394 mutex_lock(&dev
->mode_config
.mutex
);
1396 obj
= drm_mode_object_find(dev
, out_resp
->connector_id
,
1397 DRM_MODE_OBJECT_CONNECTOR
);
1402 connector
= obj_to_connector(obj
);
1404 for (i
= 0; i
< DRM_CONNECTOR_MAX_PROPERTY
; i
++) {
1405 if (connector
->property_ids
[i
] != 0) {
1410 for (i
= 0; i
< DRM_CONNECTOR_MAX_ENCODER
; i
++) {
1411 if (connector
->encoder_ids
[i
] != 0) {
1416 if (out_resp
->count_modes
== 0) {
1417 connector
->funcs
->fill_modes(connector
,
1418 dev
->mode_config
.max_width
,
1419 dev
->mode_config
.max_height
);
1422 /* delayed so we get modes regardless of pre-fill_modes state */
1423 list_for_each_entry(mode
, &connector
->modes
, head
)
1426 out_resp
->connector_id
= connector
->base
.id
;
1427 out_resp
->connector_type
= connector
->connector_type
;
1428 out_resp
->connector_type_id
= connector
->connector_type_id
;
1429 out_resp
->mm_width
= connector
->display_info
.width_mm
;
1430 out_resp
->mm_height
= connector
->display_info
.height_mm
;
1431 out_resp
->subpixel
= connector
->display_info
.subpixel_order
;
1432 out_resp
->connection
= connector
->status
;
1433 if (connector
->encoder
)
1434 out_resp
->encoder_id
= connector
->encoder
->base
.id
;
1436 out_resp
->encoder_id
= 0;
1439 * This ioctl is called twice, once to determine how much space is
1440 * needed, and the 2nd time to fill it.
1442 if ((out_resp
->count_modes
>= mode_count
) && mode_count
) {
1444 mode_ptr
= (struct drm_mode_modeinfo __user
*)(unsigned long)out_resp
->modes_ptr
;
1445 list_for_each_entry(mode
, &connector
->modes
, head
) {
1446 drm_crtc_convert_to_umode(&u_mode
, mode
);
1447 if (copy_to_user(mode_ptr
+ copied
,
1448 &u_mode
, sizeof(u_mode
))) {
1455 out_resp
->count_modes
= mode_count
;
1457 if ((out_resp
->count_props
>= props_count
) && props_count
) {
1459 prop_ptr
= (uint32_t __user
*)(unsigned long)(out_resp
->props_ptr
);
1460 prop_values
= (uint64_t __user
*)(unsigned long)(out_resp
->prop_values_ptr
);
1461 for (i
= 0; i
< DRM_CONNECTOR_MAX_PROPERTY
; i
++) {
1462 if (connector
->property_ids
[i
] != 0) {
1463 if (put_user(connector
->property_ids
[i
],
1464 prop_ptr
+ copied
)) {
1469 if (put_user(connector
->property_values
[i
],
1470 prop_values
+ copied
)) {
1478 out_resp
->count_props
= props_count
;
1480 if ((out_resp
->count_encoders
>= encoders_count
) && encoders_count
) {
1482 encoder_ptr
= (uint32_t __user
*)(unsigned long)(out_resp
->encoders_ptr
);
1483 for (i
= 0; i
< DRM_CONNECTOR_MAX_ENCODER
; i
++) {
1484 if (connector
->encoder_ids
[i
] != 0) {
1485 if (put_user(connector
->encoder_ids
[i
],
1486 encoder_ptr
+ copied
)) {
1494 out_resp
->count_encoders
= encoders_count
;
1497 mutex_unlock(&dev
->mode_config
.mutex
);
1501 int drm_mode_getencoder(struct drm_device
*dev
, void *data
,
1502 struct drm_file
*file_priv
)
1504 struct drm_mode_get_encoder
*enc_resp
= data
;
1505 struct drm_mode_object
*obj
;
1506 struct drm_encoder
*encoder
;
1509 if (!drm_core_check_feature(dev
, DRIVER_MODESET
))
1512 mutex_lock(&dev
->mode_config
.mutex
);
1513 obj
= drm_mode_object_find(dev
, enc_resp
->encoder_id
,
1514 DRM_MODE_OBJECT_ENCODER
);
1519 encoder
= obj_to_encoder(obj
);
1522 enc_resp
->crtc_id
= encoder
->crtc
->base
.id
;
1524 enc_resp
->crtc_id
= 0;
1525 enc_resp
->encoder_type
= encoder
->encoder_type
;
1526 enc_resp
->encoder_id
= encoder
->base
.id
;
1527 enc_resp
->possible_crtcs
= encoder
->possible_crtcs
;
1528 enc_resp
->possible_clones
= encoder
->possible_clones
;
1531 mutex_unlock(&dev
->mode_config
.mutex
);
1536 * drm_mode_getplane_res - get plane info
1539 * @file_priv: DRM file info
1541 * Return an plane count and set of IDs.
1543 int drm_mode_getplane_res(struct drm_device
*dev
, void *data
,
1544 struct drm_file
*file_priv
)
1546 struct drm_mode_get_plane_res
*plane_resp
= data
;
1547 struct drm_mode_config
*config
;
1548 struct drm_plane
*plane
;
1549 uint32_t __user
*plane_ptr
;
1550 int copied
= 0, ret
= 0;
1552 if (!drm_core_check_feature(dev
, DRIVER_MODESET
))
1555 mutex_lock(&dev
->mode_config
.mutex
);
1556 config
= &dev
->mode_config
;
1559 * This ioctl is called twice, once to determine how much space is
1560 * needed, and the 2nd time to fill it.
1562 if (config
->num_plane
&&
1563 (plane_resp
->count_planes
>= config
->num_plane
)) {
1564 plane_ptr
= (uint32_t __user
*)(unsigned long)plane_resp
->plane_id_ptr
;
1566 list_for_each_entry(plane
, &config
->plane_list
, head
) {
1567 if (put_user(plane
->base
.id
, plane_ptr
+ copied
)) {
1574 plane_resp
->count_planes
= config
->num_plane
;
1577 mutex_unlock(&dev
->mode_config
.mutex
);
1582 * drm_mode_getplane - get plane info
1585 * @file_priv: DRM file info
1587 * Return plane info, including formats supported, gamma size, any
1590 int drm_mode_getplane(struct drm_device
*dev
, void *data
,
1591 struct drm_file
*file_priv
)
1593 struct drm_mode_get_plane
*plane_resp
= data
;
1594 struct drm_mode_object
*obj
;
1595 struct drm_plane
*plane
;
1596 uint32_t __user
*format_ptr
;
1599 if (!drm_core_check_feature(dev
, DRIVER_MODESET
))
1602 mutex_lock(&dev
->mode_config
.mutex
);
1603 obj
= drm_mode_object_find(dev
, plane_resp
->plane_id
,
1604 DRM_MODE_OBJECT_PLANE
);
1609 plane
= obj_to_plane(obj
);
1612 plane_resp
->crtc_id
= plane
->crtc
->base
.id
;
1614 plane_resp
->crtc_id
= 0;
1617 plane_resp
->fb_id
= plane
->fb
->base
.id
;
1619 plane_resp
->fb_id
= 0;
1621 plane_resp
->plane_id
= plane
->base
.id
;
1622 plane_resp
->possible_crtcs
= plane
->possible_crtcs
;
1623 plane_resp
->gamma_size
= plane
->gamma_size
;
1626 * This ioctl is called twice, once to determine how much space is
1627 * needed, and the 2nd time to fill it.
1629 if (plane
->format_count
&&
1630 (plane_resp
->count_format_types
>= plane
->format_count
)) {
1631 format_ptr
= (uint32_t __user
*)(unsigned long)plane_resp
->format_type_ptr
;
1632 if (copy_to_user(format_ptr
,
1633 plane
->format_types
,
1634 sizeof(uint32_t) * plane
->format_count
)) {
1639 plane_resp
->count_format_types
= plane
->format_count
;
1642 mutex_unlock(&dev
->mode_config
.mutex
);
1647 * drm_mode_setplane - set up or tear down an plane
1649 * @data: ioctl data*
1650 * @file_prive: DRM file info
1652 * Set plane info, including placement, fb, scaling, and other factors.
1653 * Or pass a NULL fb to disable.
1655 int drm_mode_setplane(struct drm_device
*dev
, void *data
,
1656 struct drm_file
*file_priv
)
1658 struct drm_mode_set_plane
*plane_req
= data
;
1659 struct drm_mode_object
*obj
;
1660 struct drm_plane
*plane
;
1661 struct drm_crtc
*crtc
;
1662 struct drm_framebuffer
*fb
;
1665 if (!drm_core_check_feature(dev
, DRIVER_MODESET
))
1668 mutex_lock(&dev
->mode_config
.mutex
);
1671 * First, find the plane, crtc, and fb objects. If not available,
1672 * we don't bother to call the driver.
1674 obj
= drm_mode_object_find(dev
, plane_req
->plane_id
,
1675 DRM_MODE_OBJECT_PLANE
);
1677 DRM_DEBUG_KMS("Unknown plane ID %d\n",
1678 plane_req
->plane_id
);
1682 plane
= obj_to_plane(obj
);
1684 /* No fb means shut it down */
1685 if (!plane_req
->fb_id
) {
1686 plane
->funcs
->disable_plane(plane
);
1690 obj
= drm_mode_object_find(dev
, plane_req
->crtc_id
,
1691 DRM_MODE_OBJECT_CRTC
);
1693 DRM_DEBUG_KMS("Unknown crtc ID %d\n",
1694 plane_req
->crtc_id
);
1698 crtc
= obj_to_crtc(obj
);
1700 obj
= drm_mode_object_find(dev
, plane_req
->fb_id
,
1701 DRM_MODE_OBJECT_FB
);
1703 DRM_DEBUG_KMS("Unknown framebuffer ID %d\n",
1708 fb
= obj_to_fb(obj
);
1710 ret
= plane
->funcs
->update_plane(plane
, crtc
, fb
,
1711 plane_req
->crtc_x
, plane_req
->crtc_y
,
1712 plane_req
->crtc_w
, plane_req
->crtc_h
,
1713 plane_req
->src_x
, plane_req
->src_y
,
1714 plane_req
->src_w
, plane_req
->src_h
);
1721 mutex_unlock(&dev
->mode_config
.mutex
);
1727 * drm_mode_setcrtc - set CRTC configuration
1728 * @inode: inode from the ioctl
1729 * @filp: file * from the ioctl
1730 * @cmd: cmd from ioctl
1731 * @arg: arg from ioctl
1736 * Build a new CRTC configuration based on user request.
1738 * Called by the user via ioctl.
1741 * Zero on success, errno on failure.
1743 int drm_mode_setcrtc(struct drm_device
*dev
, void *data
,
1744 struct drm_file
*file_priv
)
1746 struct drm_mode_config
*config
= &dev
->mode_config
;
1747 struct drm_mode_crtc
*crtc_req
= data
;
1748 struct drm_mode_object
*obj
;
1749 struct drm_crtc
*crtc
, *crtcfb
;
1750 struct drm_connector
**connector_set
= NULL
, *connector
;
1751 struct drm_framebuffer
*fb
= NULL
;
1752 struct drm_display_mode
*mode
= NULL
;
1753 struct drm_mode_set set
;
1754 uint32_t __user
*set_connectors_ptr
;
1758 if (!drm_core_check_feature(dev
, DRIVER_MODESET
))
1761 mutex_lock(&dev
->mode_config
.mutex
);
1762 obj
= drm_mode_object_find(dev
, crtc_req
->crtc_id
,
1763 DRM_MODE_OBJECT_CRTC
);
1765 DRM_DEBUG_KMS("Unknown CRTC ID %d\n", crtc_req
->crtc_id
);
1769 crtc
= obj_to_crtc(obj
);
1770 DRM_DEBUG_KMS("[CRTC:%d]\n", crtc
->base
.id
);
1772 if (crtc_req
->mode_valid
) {
1773 /* If we have a mode we need a framebuffer. */
1774 /* If we pass -1, set the mode with the currently bound fb */
1775 if (crtc_req
->fb_id
== -1) {
1776 list_for_each_entry(crtcfb
,
1777 &dev
->mode_config
.crtc_list
, head
) {
1778 if (crtcfb
== crtc
) {
1779 DRM_DEBUG_KMS("Using current fb for "
1785 obj
= drm_mode_object_find(dev
, crtc_req
->fb_id
,
1786 DRM_MODE_OBJECT_FB
);
1788 DRM_DEBUG_KMS("Unknown FB ID%d\n",
1793 fb
= obj_to_fb(obj
);
1796 mode
= drm_mode_create(dev
);
1797 drm_crtc_convert_umode(mode
, &crtc_req
->mode
);
1798 drm_mode_set_crtcinfo(mode
, CRTC_INTERLACE_HALVE_V
);
1801 if (crtc_req
->count_connectors
== 0 && mode
) {
1802 DRM_DEBUG_KMS("Count connectors is 0 but mode set\n");
1807 if (crtc_req
->count_connectors
> 0 && (!mode
|| !fb
)) {
1808 DRM_DEBUG_KMS("Count connectors is %d but no mode or fb set\n",
1809 crtc_req
->count_connectors
);
1814 if (crtc_req
->count_connectors
> 0) {
1817 /* Avoid unbounded kernel memory allocation */
1818 if (crtc_req
->count_connectors
> config
->num_connector
) {
1823 connector_set
= kmalloc(crtc_req
->count_connectors
*
1824 sizeof(struct drm_connector
*),
1826 if (!connector_set
) {
1831 for (i
= 0; i
< crtc_req
->count_connectors
; i
++) {
1832 set_connectors_ptr
= (uint32_t __user
*)(unsigned long)crtc_req
->set_connectors_ptr
;
1833 if (get_user(out_id
, &set_connectors_ptr
[i
])) {
1838 obj
= drm_mode_object_find(dev
, out_id
,
1839 DRM_MODE_OBJECT_CONNECTOR
);
1841 DRM_DEBUG_KMS("Connector id %d unknown\n",
1846 connector
= obj_to_connector(obj
);
1847 DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n",
1849 drm_get_connector_name(connector
));
1851 connector_set
[i
] = connector
;
1856 set
.x
= crtc_req
->x
;
1857 set
.y
= crtc_req
->y
;
1859 set
.connectors
= connector_set
;
1860 set
.num_connectors
= crtc_req
->count_connectors
;
1862 ret
= crtc
->funcs
->set_config(&set
);
1865 kfree(connector_set
);
1866 mutex_unlock(&dev
->mode_config
.mutex
);
1870 int drm_mode_cursor_ioctl(struct drm_device
*dev
,
1871 void *data
, struct drm_file
*file_priv
)
1873 struct drm_mode_cursor
*req
= data
;
1874 struct drm_mode_object
*obj
;
1875 struct drm_crtc
*crtc
;
1878 if (!drm_core_check_feature(dev
, DRIVER_MODESET
))
1884 mutex_lock(&dev
->mode_config
.mutex
);
1885 obj
= drm_mode_object_find(dev
, req
->crtc_id
, DRM_MODE_OBJECT_CRTC
);
1887 DRM_DEBUG_KMS("Unknown CRTC ID %d\n", req
->crtc_id
);
1891 crtc
= obj_to_crtc(obj
);
1893 if (req
->flags
& DRM_MODE_CURSOR_BO
) {
1894 if (!crtc
->funcs
->cursor_set
) {
1898 /* Turns off the cursor if handle is 0 */
1899 ret
= crtc
->funcs
->cursor_set(crtc
, file_priv
, req
->handle
,
1900 req
->width
, req
->height
);
1903 if (req
->flags
& DRM_MODE_CURSOR_MOVE
) {
1904 if (crtc
->funcs
->cursor_move
) {
1905 ret
= crtc
->funcs
->cursor_move(crtc
, req
->x
, req
->y
);
1912 mutex_unlock(&dev
->mode_config
.mutex
);
1916 /* Original addfb only supported RGB formats, so figure out which one */
1917 uint32_t drm_mode_legacy_fb_format(uint32_t bpp
, uint32_t depth
)
1923 fmt
= DRM_FORMAT_RGB332
;
1927 fmt
= DRM_FORMAT_XRGB1555
;
1929 fmt
= DRM_FORMAT_RGB565
;
1932 fmt
= DRM_FORMAT_RGB888
;
1936 fmt
= DRM_FORMAT_XRGB8888
;
1937 else if (depth
== 30)
1938 fmt
= DRM_FORMAT_XRGB2101010
;
1940 fmt
= DRM_FORMAT_ARGB8888
;
1943 DRM_ERROR("bad bpp, assuming x8r8g8b8 pixel format\n");
1944 fmt
= DRM_FORMAT_XRGB8888
;
1950 EXPORT_SYMBOL(drm_mode_legacy_fb_format
);
1953 * drm_mode_addfb - add an FB to the graphics configuration
1954 * @inode: inode from the ioctl
1955 * @filp: file * from the ioctl
1956 * @cmd: cmd from ioctl
1957 * @arg: arg from ioctl
1960 * Takes mode config lock.
1962 * Add a new FB to the specified CRTC, given a user request.
1964 * Called by the user via ioctl.
1967 * Zero on success, errno on failure.
1969 int drm_mode_addfb(struct drm_device
*dev
,
1970 void *data
, struct drm_file
*file_priv
)
1972 struct drm_mode_fb_cmd
*or = data
;
1973 struct drm_mode_fb_cmd2 r
= {};
1974 struct drm_mode_config
*config
= &dev
->mode_config
;
1975 struct drm_framebuffer
*fb
;
1978 /* Use new struct with format internally */
1979 r
.fb_id
= or->fb_id
;
1980 r
.width
= or->width
;
1981 r
.height
= or->height
;
1982 r
.pitches
[0] = or->pitch
;
1983 r
.pixel_format
= drm_mode_legacy_fb_format(or->bpp
, or->depth
);
1984 r
.handles
[0] = or->handle
;
1986 if (!drm_core_check_feature(dev
, DRIVER_MODESET
))
1989 if ((config
->min_width
> r
.width
) || (r
.width
> config
->max_width
))
1992 if ((config
->min_height
> r
.height
) || (r
.height
> config
->max_height
))
1995 mutex_lock(&dev
->mode_config
.mutex
);
1997 /* TODO check buffer is sufficiently large */
1998 /* TODO setup destructor callback */
2000 fb
= dev
->mode_config
.funcs
->fb_create(dev
, file_priv
, &r
);
2002 DRM_ERROR("could not create framebuffer\n");
2007 or->fb_id
= fb
->base
.id
;
2008 list_add(&fb
->filp_head
, &file_priv
->fbs
);
2009 DRM_DEBUG_KMS("[FB:%d]\n", fb
->base
.id
);
2012 mutex_unlock(&dev
->mode_config
.mutex
);
2017 * drm_mode_addfb2 - add an FB to the graphics configuration
2018 * @inode: inode from the ioctl
2019 * @filp: file * from the ioctl
2020 * @cmd: cmd from ioctl
2021 * @arg: arg from ioctl
2024 * Takes mode config lock.
2026 * Add a new FB to the specified CRTC, given a user request with format.
2028 * Called by the user via ioctl.
2031 * Zero on success, errno on failure.
2033 int drm_mode_addfb2(struct drm_device
*dev
,
2034 void *data
, struct drm_file
*file_priv
)
2036 struct drm_mode_fb_cmd2
*r
= data
;
2037 struct drm_mode_config
*config
= &dev
->mode_config
;
2038 struct drm_framebuffer
*fb
;
2041 if (!drm_core_check_feature(dev
, DRIVER_MODESET
))
2044 if ((config
->min_width
> r
->width
) || (r
->width
> config
->max_width
)) {
2045 DRM_ERROR("bad framebuffer width %d, should be >= %d && <= %d\n",
2046 r
->width
, config
->min_width
, config
->max_width
);
2049 if ((config
->min_height
> r
->height
) || (r
->height
> config
->max_height
)) {
2050 DRM_ERROR("bad framebuffer height %d, should be >= %d && <= %d\n",
2051 r
->height
, config
->min_height
, config
->max_height
);
2055 mutex_lock(&dev
->mode_config
.mutex
);
2057 fb
= dev
->mode_config
.funcs
->fb_create(dev
, file_priv
, r
);
2059 DRM_ERROR("could not create framebuffer\n");
2064 r
->fb_id
= fb
->base
.id
;
2065 list_add(&fb
->filp_head
, &file_priv
->fbs
);
2066 DRM_DEBUG_KMS("[FB:%d]\n", fb
->base
.id
);
2069 mutex_unlock(&dev
->mode_config
.mutex
);
2074 * drm_mode_rmfb - remove an FB from the configuration
2075 * @inode: inode from the ioctl
2076 * @filp: file * from the ioctl
2077 * @cmd: cmd from ioctl
2078 * @arg: arg from ioctl
2081 * Takes mode config lock.
2083 * Remove the FB specified by the user.
2085 * Called by the user via ioctl.
2088 * Zero on success, errno on failure.
2090 int drm_mode_rmfb(struct drm_device
*dev
,
2091 void *data
, struct drm_file
*file_priv
)
2093 struct drm_mode_object
*obj
;
2094 struct drm_framebuffer
*fb
= NULL
;
2095 struct drm_framebuffer
*fbl
= NULL
;
2096 uint32_t *id
= data
;
2100 if (!drm_core_check_feature(dev
, DRIVER_MODESET
))
2103 mutex_lock(&dev
->mode_config
.mutex
);
2104 obj
= drm_mode_object_find(dev
, *id
, DRM_MODE_OBJECT_FB
);
2105 /* TODO check that we really get a framebuffer back. */
2110 fb
= obj_to_fb(obj
);
2112 list_for_each_entry(fbl
, &file_priv
->fbs
, filp_head
)
2121 /* TODO release all crtc connected to the framebuffer */
2122 /* TODO unhock the destructor from the buffer object */
2124 list_del(&fb
->filp_head
);
2125 fb
->funcs
->destroy(fb
);
2128 mutex_unlock(&dev
->mode_config
.mutex
);
2133 * drm_mode_getfb - get FB info
2134 * @inode: inode from the ioctl
2135 * @filp: file * from the ioctl
2136 * @cmd: cmd from ioctl
2137 * @arg: arg from ioctl
2142 * Lookup the FB given its ID and return info about it.
2144 * Called by the user via ioctl.
2147 * Zero on success, errno on failure.
2149 int drm_mode_getfb(struct drm_device
*dev
,
2150 void *data
, struct drm_file
*file_priv
)
2152 struct drm_mode_fb_cmd
*r
= data
;
2153 struct drm_mode_object
*obj
;
2154 struct drm_framebuffer
*fb
;
2157 if (!drm_core_check_feature(dev
, DRIVER_MODESET
))
2160 mutex_lock(&dev
->mode_config
.mutex
);
2161 obj
= drm_mode_object_find(dev
, r
->fb_id
, DRM_MODE_OBJECT_FB
);
2166 fb
= obj_to_fb(obj
);
2168 r
->height
= fb
->height
;
2169 r
->width
= fb
->width
;
2170 r
->depth
= fb
->depth
;
2171 r
->bpp
= fb
->bits_per_pixel
;
2172 r
->pitch
= fb
->pitch
;
2173 fb
->funcs
->create_handle(fb
, file_priv
, &r
->handle
);
2176 mutex_unlock(&dev
->mode_config
.mutex
);
2180 int drm_mode_dirtyfb_ioctl(struct drm_device
*dev
,
2181 void *data
, struct drm_file
*file_priv
)
2183 struct drm_clip_rect __user
*clips_ptr
;
2184 struct drm_clip_rect
*clips
= NULL
;
2185 struct drm_mode_fb_dirty_cmd
*r
= data
;
2186 struct drm_mode_object
*obj
;
2187 struct drm_framebuffer
*fb
;
2192 if (!drm_core_check_feature(dev
, DRIVER_MODESET
))
2195 mutex_lock(&dev
->mode_config
.mutex
);
2196 obj
= drm_mode_object_find(dev
, r
->fb_id
, DRM_MODE_OBJECT_FB
);
2201 fb
= obj_to_fb(obj
);
2203 num_clips
= r
->num_clips
;
2204 clips_ptr
= (struct drm_clip_rect __user
*)(unsigned long)r
->clips_ptr
;
2206 if (!num_clips
!= !clips_ptr
) {
2211 flags
= DRM_MODE_FB_DIRTY_FLAGS
& r
->flags
;
2213 /* If userspace annotates copy, clips must come in pairs */
2214 if (flags
& DRM_MODE_FB_DIRTY_ANNOTATE_COPY
&& (num_clips
% 2)) {
2219 if (num_clips
&& clips_ptr
) {
2220 clips
= kzalloc(num_clips
* sizeof(*clips
), GFP_KERNEL
);
2226 ret
= copy_from_user(clips
, clips_ptr
,
2227 num_clips
* sizeof(*clips
));
2234 if (fb
->funcs
->dirty
) {
2235 ret
= fb
->funcs
->dirty(fb
, file_priv
, flags
, r
->color
,
2245 mutex_unlock(&dev
->mode_config
.mutex
);
2251 * drm_fb_release - remove and free the FBs on this file
2252 * @filp: file * from the ioctl
2255 * Takes mode config lock.
2257 * Destroy all the FBs associated with @filp.
2259 * Called by the user via ioctl.
2262 * Zero on success, errno on failure.
2264 void drm_fb_release(struct drm_file
*priv
)
2266 struct drm_device
*dev
= priv
->minor
->dev
;
2267 struct drm_framebuffer
*fb
, *tfb
;
2269 mutex_lock(&dev
->mode_config
.mutex
);
2270 list_for_each_entry_safe(fb
, tfb
, &priv
->fbs
, filp_head
) {
2271 list_del(&fb
->filp_head
);
2272 fb
->funcs
->destroy(fb
);
2274 mutex_unlock(&dev
->mode_config
.mutex
);
2278 * drm_mode_attachmode - add a mode to the user mode list
2280 * @connector: connector to add the mode to
2281 * @mode: mode to add
2283 * Add @mode to @connector's user mode list.
2285 static int drm_mode_attachmode(struct drm_device
*dev
,
2286 struct drm_connector
*connector
,
2287 struct drm_display_mode
*mode
)
2291 list_add_tail(&mode
->head
, &connector
->user_modes
);
2295 int drm_mode_attachmode_crtc(struct drm_device
*dev
, struct drm_crtc
*crtc
,
2296 struct drm_display_mode
*mode
)
2298 struct drm_connector
*connector
;
2300 struct drm_display_mode
*dup_mode
;
2302 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
, head
) {
2303 if (!connector
->encoder
)
2305 if (connector
->encoder
->crtc
== crtc
) {
2307 dup_mode
= drm_mode_duplicate(dev
, mode
);
2310 ret
= drm_mode_attachmode(dev
, connector
, dup_mode
);
2318 EXPORT_SYMBOL(drm_mode_attachmode_crtc
);
2320 static int drm_mode_detachmode(struct drm_device
*dev
,
2321 struct drm_connector
*connector
,
2322 struct drm_display_mode
*mode
)
2326 struct drm_display_mode
*match_mode
, *t
;
2328 list_for_each_entry_safe(match_mode
, t
, &connector
->user_modes
, head
) {
2329 if (drm_mode_equal(match_mode
, mode
)) {
2330 list_del(&match_mode
->head
);
2331 drm_mode_destroy(dev
, match_mode
);
2343 int drm_mode_detachmode_crtc(struct drm_device
*dev
, struct drm_display_mode
*mode
)
2345 struct drm_connector
*connector
;
2347 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
, head
) {
2348 drm_mode_detachmode(dev
, connector
, mode
);
2352 EXPORT_SYMBOL(drm_mode_detachmode_crtc
);
2355 * drm_fb_attachmode - Attach a user mode to an connector
2356 * @inode: inode from the ioctl
2357 * @filp: file * from the ioctl
2358 * @cmd: cmd from ioctl
2359 * @arg: arg from ioctl
2361 * This attaches a user specified mode to an connector.
2362 * Called by the user via ioctl.
2365 * Zero on success, errno on failure.
2367 int drm_mode_attachmode_ioctl(struct drm_device
*dev
,
2368 void *data
, struct drm_file
*file_priv
)
2370 struct drm_mode_mode_cmd
*mode_cmd
= data
;
2371 struct drm_connector
*connector
;
2372 struct drm_display_mode
*mode
;
2373 struct drm_mode_object
*obj
;
2374 struct drm_mode_modeinfo
*umode
= &mode_cmd
->mode
;
2377 if (!drm_core_check_feature(dev
, DRIVER_MODESET
))
2380 mutex_lock(&dev
->mode_config
.mutex
);
2382 obj
= drm_mode_object_find(dev
, mode_cmd
->connector_id
, DRM_MODE_OBJECT_CONNECTOR
);
2387 connector
= obj_to_connector(obj
);
2389 mode
= drm_mode_create(dev
);
2395 drm_crtc_convert_umode(mode
, umode
);
2397 ret
= drm_mode_attachmode(dev
, connector
, mode
);
2399 mutex_unlock(&dev
->mode_config
.mutex
);
2405 * drm_fb_detachmode - Detach a user specified mode from an connector
2406 * @inode: inode from the ioctl
2407 * @filp: file * from the ioctl
2408 * @cmd: cmd from ioctl
2409 * @arg: arg from ioctl
2411 * Called by the user via ioctl.
2414 * Zero on success, errno on failure.
2416 int drm_mode_detachmode_ioctl(struct drm_device
*dev
,
2417 void *data
, struct drm_file
*file_priv
)
2419 struct drm_mode_object
*obj
;
2420 struct drm_mode_mode_cmd
*mode_cmd
= data
;
2421 struct drm_connector
*connector
;
2422 struct drm_display_mode mode
;
2423 struct drm_mode_modeinfo
*umode
= &mode_cmd
->mode
;
2426 if (!drm_core_check_feature(dev
, DRIVER_MODESET
))
2429 mutex_lock(&dev
->mode_config
.mutex
);
2431 obj
= drm_mode_object_find(dev
, mode_cmd
->connector_id
, DRM_MODE_OBJECT_CONNECTOR
);
2436 connector
= obj_to_connector(obj
);
2438 drm_crtc_convert_umode(&mode
, umode
);
2439 ret
= drm_mode_detachmode(dev
, connector
, &mode
);
2441 mutex_unlock(&dev
->mode_config
.mutex
);
2445 struct drm_property
*drm_property_create(struct drm_device
*dev
, int flags
,
2446 const char *name
, int num_values
)
2448 struct drm_property
*property
= NULL
;
2450 property
= kzalloc(sizeof(struct drm_property
), GFP_KERNEL
);
2455 property
->values
= kzalloc(sizeof(uint64_t)*num_values
, GFP_KERNEL
);
2456 if (!property
->values
)
2460 drm_mode_object_get(dev
, &property
->base
, DRM_MODE_OBJECT_PROPERTY
);
2461 property
->flags
= flags
;
2462 property
->num_values
= num_values
;
2463 INIT_LIST_HEAD(&property
->enum_blob_list
);
2466 strncpy(property
->name
, name
, DRM_PROP_NAME_LEN
);
2468 list_add_tail(&property
->head
, &dev
->mode_config
.property_list
);
2474 EXPORT_SYMBOL(drm_property_create
);
2476 int drm_property_add_enum(struct drm_property
*property
, int index
,
2477 uint64_t value
, const char *name
)
2479 struct drm_property_enum
*prop_enum
;
2481 if (!(property
->flags
& DRM_MODE_PROP_ENUM
))
2484 if (!list_empty(&property
->enum_blob_list
)) {
2485 list_for_each_entry(prop_enum
, &property
->enum_blob_list
, head
) {
2486 if (prop_enum
->value
== value
) {
2487 strncpy(prop_enum
->name
, name
, DRM_PROP_NAME_LEN
);
2488 prop_enum
->name
[DRM_PROP_NAME_LEN
-1] = '\0';
2494 prop_enum
= kzalloc(sizeof(struct drm_property_enum
), GFP_KERNEL
);
2498 strncpy(prop_enum
->name
, name
, DRM_PROP_NAME_LEN
);
2499 prop_enum
->name
[DRM_PROP_NAME_LEN
-1] = '\0';
2500 prop_enum
->value
= value
;
2502 property
->values
[index
] = value
;
2503 list_add_tail(&prop_enum
->head
, &property
->enum_blob_list
);
2506 EXPORT_SYMBOL(drm_property_add_enum
);
2508 void drm_property_destroy(struct drm_device
*dev
, struct drm_property
*property
)
2510 struct drm_property_enum
*prop_enum
, *pt
;
2512 list_for_each_entry_safe(prop_enum
, pt
, &property
->enum_blob_list
, head
) {
2513 list_del(&prop_enum
->head
);
2517 if (property
->num_values
)
2518 kfree(property
->values
);
2519 drm_mode_object_put(dev
, &property
->base
);
2520 list_del(&property
->head
);
2523 EXPORT_SYMBOL(drm_property_destroy
);
2525 int drm_connector_attach_property(struct drm_connector
*connector
,
2526 struct drm_property
*property
, uint64_t init_val
)
2530 for (i
= 0; i
< DRM_CONNECTOR_MAX_PROPERTY
; i
++) {
2531 if (connector
->property_ids
[i
] == 0) {
2532 connector
->property_ids
[i
] = property
->base
.id
;
2533 connector
->property_values
[i
] = init_val
;
2538 if (i
== DRM_CONNECTOR_MAX_PROPERTY
)
2542 EXPORT_SYMBOL(drm_connector_attach_property
);
2544 int drm_connector_property_set_value(struct drm_connector
*connector
,
2545 struct drm_property
*property
, uint64_t value
)
2549 for (i
= 0; i
< DRM_CONNECTOR_MAX_PROPERTY
; i
++) {
2550 if (connector
->property_ids
[i
] == property
->base
.id
) {
2551 connector
->property_values
[i
] = value
;
2556 if (i
== DRM_CONNECTOR_MAX_PROPERTY
)
2560 EXPORT_SYMBOL(drm_connector_property_set_value
);
2562 int drm_connector_property_get_value(struct drm_connector
*connector
,
2563 struct drm_property
*property
, uint64_t *val
)
2567 for (i
= 0; i
< DRM_CONNECTOR_MAX_PROPERTY
; i
++) {
2568 if (connector
->property_ids
[i
] == property
->base
.id
) {
2569 *val
= connector
->property_values
[i
];
2574 if (i
== DRM_CONNECTOR_MAX_PROPERTY
)
2578 EXPORT_SYMBOL(drm_connector_property_get_value
);
2580 int drm_mode_getproperty_ioctl(struct drm_device
*dev
,
2581 void *data
, struct drm_file
*file_priv
)
2583 struct drm_mode_object
*obj
;
2584 struct drm_mode_get_property
*out_resp
= data
;
2585 struct drm_property
*property
;
2588 int value_count
= 0;
2591 struct drm_property_enum
*prop_enum
;
2592 struct drm_mode_property_enum __user
*enum_ptr
;
2593 struct drm_property_blob
*prop_blob
;
2594 uint32_t __user
*blob_id_ptr
;
2595 uint64_t __user
*values_ptr
;
2596 uint32_t __user
*blob_length_ptr
;
2598 if (!drm_core_check_feature(dev
, DRIVER_MODESET
))
2601 mutex_lock(&dev
->mode_config
.mutex
);
2602 obj
= drm_mode_object_find(dev
, out_resp
->prop_id
, DRM_MODE_OBJECT_PROPERTY
);
2607 property
= obj_to_property(obj
);
2609 if (property
->flags
& DRM_MODE_PROP_ENUM
) {
2610 list_for_each_entry(prop_enum
, &property
->enum_blob_list
, head
)
2612 } else if (property
->flags
& DRM_MODE_PROP_BLOB
) {
2613 list_for_each_entry(prop_blob
, &property
->enum_blob_list
, head
)
2617 value_count
= property
->num_values
;
2619 strncpy(out_resp
->name
, property
->name
, DRM_PROP_NAME_LEN
);
2620 out_resp
->name
[DRM_PROP_NAME_LEN
-1] = 0;
2621 out_resp
->flags
= property
->flags
;
2623 if ((out_resp
->count_values
>= value_count
) && value_count
) {
2624 values_ptr
= (uint64_t __user
*)(unsigned long)out_resp
->values_ptr
;
2625 for (i
= 0; i
< value_count
; i
++) {
2626 if (copy_to_user(values_ptr
+ i
, &property
->values
[i
], sizeof(uint64_t))) {
2632 out_resp
->count_values
= value_count
;
2634 if (property
->flags
& DRM_MODE_PROP_ENUM
) {
2635 if ((out_resp
->count_enum_blobs
>= enum_count
) && enum_count
) {
2637 enum_ptr
= (struct drm_mode_property_enum __user
*)(unsigned long)out_resp
->enum_blob_ptr
;
2638 list_for_each_entry(prop_enum
, &property
->enum_blob_list
, head
) {
2640 if (copy_to_user(&enum_ptr
[copied
].value
, &prop_enum
->value
, sizeof(uint64_t))) {
2645 if (copy_to_user(&enum_ptr
[copied
].name
,
2646 &prop_enum
->name
, DRM_PROP_NAME_LEN
)) {
2653 out_resp
->count_enum_blobs
= enum_count
;
2656 if (property
->flags
& DRM_MODE_PROP_BLOB
) {
2657 if ((out_resp
->count_enum_blobs
>= blob_count
) && blob_count
) {
2659 blob_id_ptr
= (uint32_t __user
*)(unsigned long)out_resp
->enum_blob_ptr
;
2660 blob_length_ptr
= (uint32_t __user
*)(unsigned long)out_resp
->values_ptr
;
2662 list_for_each_entry(prop_blob
, &property
->enum_blob_list
, head
) {
2663 if (put_user(prop_blob
->base
.id
, blob_id_ptr
+ copied
)) {
2668 if (put_user(prop_blob
->length
, blob_length_ptr
+ copied
)) {
2676 out_resp
->count_enum_blobs
= blob_count
;
2679 mutex_unlock(&dev
->mode_config
.mutex
);
2683 static struct drm_property_blob
*drm_property_create_blob(struct drm_device
*dev
, int length
,
2686 struct drm_property_blob
*blob
;
2688 if (!length
|| !data
)
2691 blob
= kzalloc(sizeof(struct drm_property_blob
)+length
, GFP_KERNEL
);
2695 blob
->data
= (void *)((char *)blob
+ sizeof(struct drm_property_blob
));
2696 blob
->length
= length
;
2698 memcpy(blob
->data
, data
, length
);
2700 drm_mode_object_get(dev
, &blob
->base
, DRM_MODE_OBJECT_BLOB
);
2702 list_add_tail(&blob
->head
, &dev
->mode_config
.property_blob_list
);
2706 static void drm_property_destroy_blob(struct drm_device
*dev
,
2707 struct drm_property_blob
*blob
)
2709 drm_mode_object_put(dev
, &blob
->base
);
2710 list_del(&blob
->head
);
2714 int drm_mode_getblob_ioctl(struct drm_device
*dev
,
2715 void *data
, struct drm_file
*file_priv
)
2717 struct drm_mode_object
*obj
;
2718 struct drm_mode_get_blob
*out_resp
= data
;
2719 struct drm_property_blob
*blob
;
2721 void __user
*blob_ptr
;
2723 if (!drm_core_check_feature(dev
, DRIVER_MODESET
))
2726 mutex_lock(&dev
->mode_config
.mutex
);
2727 obj
= drm_mode_object_find(dev
, out_resp
->blob_id
, DRM_MODE_OBJECT_BLOB
);
2732 blob
= obj_to_blob(obj
);
2734 if (out_resp
->length
== blob
->length
) {
2735 blob_ptr
= (void __user
*)(unsigned long)out_resp
->data
;
2736 if (copy_to_user(blob_ptr
, blob
->data
, blob
->length
)){
2741 out_resp
->length
= blob
->length
;
2744 mutex_unlock(&dev
->mode_config
.mutex
);
2748 int drm_mode_connector_update_edid_property(struct drm_connector
*connector
,
2751 struct drm_device
*dev
= connector
->dev
;
2754 if (connector
->edid_blob_ptr
)
2755 drm_property_destroy_blob(dev
, connector
->edid_blob_ptr
);
2757 /* Delete edid, when there is none. */
2759 connector
->edid_blob_ptr
= NULL
;
2760 ret
= drm_connector_property_set_value(connector
, dev
->mode_config
.edid_property
, 0);
2764 size
= EDID_LENGTH
* (1 + edid
->extensions
);
2765 connector
->edid_blob_ptr
= drm_property_create_blob(connector
->dev
,
2768 ret
= drm_connector_property_set_value(connector
,
2769 dev
->mode_config
.edid_property
,
2770 connector
->edid_blob_ptr
->base
.id
);
2774 EXPORT_SYMBOL(drm_mode_connector_update_edid_property
);
2776 int drm_mode_connector_property_set_ioctl(struct drm_device
*dev
,
2777 void *data
, struct drm_file
*file_priv
)
2779 struct drm_mode_connector_set_property
*out_resp
= data
;
2780 struct drm_mode_object
*obj
;
2781 struct drm_property
*property
;
2782 struct drm_connector
*connector
;
2786 if (!drm_core_check_feature(dev
, DRIVER_MODESET
))
2789 mutex_lock(&dev
->mode_config
.mutex
);
2791 obj
= drm_mode_object_find(dev
, out_resp
->connector_id
, DRM_MODE_OBJECT_CONNECTOR
);
2795 connector
= obj_to_connector(obj
);
2797 for (i
= 0; i
< DRM_CONNECTOR_MAX_PROPERTY
; i
++) {
2798 if (connector
->property_ids
[i
] == out_resp
->prop_id
)
2802 if (i
== DRM_CONNECTOR_MAX_PROPERTY
) {
2806 obj
= drm_mode_object_find(dev
, out_resp
->prop_id
, DRM_MODE_OBJECT_PROPERTY
);
2810 property
= obj_to_property(obj
);
2812 if (property
->flags
& DRM_MODE_PROP_IMMUTABLE
)
2815 if (property
->flags
& DRM_MODE_PROP_RANGE
) {
2816 if (out_resp
->value
< property
->values
[0])
2819 if (out_resp
->value
> property
->values
[1])
2823 for (i
= 0; i
< property
->num_values
; i
++) {
2824 if (property
->values
[i
] == out_resp
->value
) {
2834 /* Do DPMS ourselves */
2835 if (property
== connector
->dev
->mode_config
.dpms_property
) {
2836 if (connector
->funcs
->dpms
)
2837 (*connector
->funcs
->dpms
)(connector
, (int) out_resp
->value
);
2839 } else if (connector
->funcs
->set_property
)
2840 ret
= connector
->funcs
->set_property(connector
, property
, out_resp
->value
);
2842 /* store the property value if successful */
2844 drm_connector_property_set_value(connector
, property
, out_resp
->value
);
2846 mutex_unlock(&dev
->mode_config
.mutex
);
2850 int drm_mode_connector_attach_encoder(struct drm_connector
*connector
,
2851 struct drm_encoder
*encoder
)
2855 for (i
= 0; i
< DRM_CONNECTOR_MAX_ENCODER
; i
++) {
2856 if (connector
->encoder_ids
[i
] == 0) {
2857 connector
->encoder_ids
[i
] = encoder
->base
.id
;
2863 EXPORT_SYMBOL(drm_mode_connector_attach_encoder
);
2865 void drm_mode_connector_detach_encoder(struct drm_connector
*connector
,
2866 struct drm_encoder
*encoder
)
2869 for (i
= 0; i
< DRM_CONNECTOR_MAX_ENCODER
; i
++) {
2870 if (connector
->encoder_ids
[i
] == encoder
->base
.id
) {
2871 connector
->encoder_ids
[i
] = 0;
2872 if (connector
->encoder
== encoder
)
2873 connector
->encoder
= NULL
;
2878 EXPORT_SYMBOL(drm_mode_connector_detach_encoder
);
2880 bool drm_mode_crtc_set_gamma_size(struct drm_crtc
*crtc
,
2883 crtc
->gamma_size
= gamma_size
;
2885 crtc
->gamma_store
= kzalloc(gamma_size
* sizeof(uint16_t) * 3, GFP_KERNEL
);
2886 if (!crtc
->gamma_store
) {
2887 crtc
->gamma_size
= 0;
2893 EXPORT_SYMBOL(drm_mode_crtc_set_gamma_size
);
2895 int drm_mode_gamma_set_ioctl(struct drm_device
*dev
,
2896 void *data
, struct drm_file
*file_priv
)
2898 struct drm_mode_crtc_lut
*crtc_lut
= data
;
2899 struct drm_mode_object
*obj
;
2900 struct drm_crtc
*crtc
;
2901 void *r_base
, *g_base
, *b_base
;
2905 if (!drm_core_check_feature(dev
, DRIVER_MODESET
))
2908 mutex_lock(&dev
->mode_config
.mutex
);
2909 obj
= drm_mode_object_find(dev
, crtc_lut
->crtc_id
, DRM_MODE_OBJECT_CRTC
);
2914 crtc
= obj_to_crtc(obj
);
2916 /* memcpy into gamma store */
2917 if (crtc_lut
->gamma_size
!= crtc
->gamma_size
) {
2922 size
= crtc_lut
->gamma_size
* (sizeof(uint16_t));
2923 r_base
= crtc
->gamma_store
;
2924 if (copy_from_user(r_base
, (void __user
*)(unsigned long)crtc_lut
->red
, size
)) {
2929 g_base
= r_base
+ size
;
2930 if (copy_from_user(g_base
, (void __user
*)(unsigned long)crtc_lut
->green
, size
)) {
2935 b_base
= g_base
+ size
;
2936 if (copy_from_user(b_base
, (void __user
*)(unsigned long)crtc_lut
->blue
, size
)) {
2941 crtc
->funcs
->gamma_set(crtc
, r_base
, g_base
, b_base
, 0, crtc
->gamma_size
);
2944 mutex_unlock(&dev
->mode_config
.mutex
);
2949 int drm_mode_gamma_get_ioctl(struct drm_device
*dev
,
2950 void *data
, struct drm_file
*file_priv
)
2952 struct drm_mode_crtc_lut
*crtc_lut
= data
;
2953 struct drm_mode_object
*obj
;
2954 struct drm_crtc
*crtc
;
2955 void *r_base
, *g_base
, *b_base
;
2959 if (!drm_core_check_feature(dev
, DRIVER_MODESET
))
2962 mutex_lock(&dev
->mode_config
.mutex
);
2963 obj
= drm_mode_object_find(dev
, crtc_lut
->crtc_id
, DRM_MODE_OBJECT_CRTC
);
2968 crtc
= obj_to_crtc(obj
);
2970 /* memcpy into gamma store */
2971 if (crtc_lut
->gamma_size
!= crtc
->gamma_size
) {
2976 size
= crtc_lut
->gamma_size
* (sizeof(uint16_t));
2977 r_base
= crtc
->gamma_store
;
2978 if (copy_to_user((void __user
*)(unsigned long)crtc_lut
->red
, r_base
, size
)) {
2983 g_base
= r_base
+ size
;
2984 if (copy_to_user((void __user
*)(unsigned long)crtc_lut
->green
, g_base
, size
)) {
2989 b_base
= g_base
+ size
;
2990 if (copy_to_user((void __user
*)(unsigned long)crtc_lut
->blue
, b_base
, size
)) {
2995 mutex_unlock(&dev
->mode_config
.mutex
);
2999 int drm_mode_page_flip_ioctl(struct drm_device
*dev
,
3000 void *data
, struct drm_file
*file_priv
)
3002 struct drm_mode_crtc_page_flip
*page_flip
= data
;
3003 struct drm_mode_object
*obj
;
3004 struct drm_crtc
*crtc
;
3005 struct drm_framebuffer
*fb
;
3006 struct drm_pending_vblank_event
*e
= NULL
;
3007 unsigned long flags
;
3010 if (page_flip
->flags
& ~DRM_MODE_PAGE_FLIP_FLAGS
||
3011 page_flip
->reserved
!= 0)
3014 mutex_lock(&dev
->mode_config
.mutex
);
3015 obj
= drm_mode_object_find(dev
, page_flip
->crtc_id
, DRM_MODE_OBJECT_CRTC
);
3018 crtc
= obj_to_crtc(obj
);
3020 if (crtc
->fb
== NULL
) {
3021 /* The framebuffer is currently unbound, presumably
3022 * due to a hotplug event, that userspace has not
3029 if (crtc
->funcs
->page_flip
== NULL
)
3032 obj
= drm_mode_object_find(dev
, page_flip
->fb_id
, DRM_MODE_OBJECT_FB
);
3035 fb
= obj_to_fb(obj
);
3037 if (page_flip
->flags
& DRM_MODE_PAGE_FLIP_EVENT
) {
3039 spin_lock_irqsave(&dev
->event_lock
, flags
);
3040 if (file_priv
->event_space
< sizeof e
->event
) {
3041 spin_unlock_irqrestore(&dev
->event_lock
, flags
);
3044 file_priv
->event_space
-= sizeof e
->event
;
3045 spin_unlock_irqrestore(&dev
->event_lock
, flags
);
3047 e
= kzalloc(sizeof *e
, GFP_KERNEL
);
3049 spin_lock_irqsave(&dev
->event_lock
, flags
);
3050 file_priv
->event_space
+= sizeof e
->event
;
3051 spin_unlock_irqrestore(&dev
->event_lock
, flags
);
3055 e
->event
.base
.type
= DRM_EVENT_FLIP_COMPLETE
;
3056 e
->event
.base
.length
= sizeof e
->event
;
3057 e
->event
.user_data
= page_flip
->user_data
;
3058 e
->base
.event
= &e
->event
.base
;
3059 e
->base
.file_priv
= file_priv
;
3061 (void (*) (struct drm_pending_event
*)) kfree
;
3064 ret
= crtc
->funcs
->page_flip(crtc
, fb
, e
);
3066 spin_lock_irqsave(&dev
->event_lock
, flags
);
3067 file_priv
->event_space
+= sizeof e
->event
;
3068 spin_unlock_irqrestore(&dev
->event_lock
, flags
);
3073 mutex_unlock(&dev
->mode_config
.mutex
);
3077 void drm_mode_config_reset(struct drm_device
*dev
)
3079 struct drm_crtc
*crtc
;
3080 struct drm_encoder
*encoder
;
3081 struct drm_connector
*connector
;
3083 list_for_each_entry(crtc
, &dev
->mode_config
.crtc_list
, head
)
3084 if (crtc
->funcs
->reset
)
3085 crtc
->funcs
->reset(crtc
);
3087 list_for_each_entry(encoder
, &dev
->mode_config
.encoder_list
, head
)
3088 if (encoder
->funcs
->reset
)
3089 encoder
->funcs
->reset(encoder
);
3091 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
, head
)
3092 if (connector
->funcs
->reset
)
3093 connector
->funcs
->reset(connector
);
3095 EXPORT_SYMBOL(drm_mode_config_reset
);
3097 int drm_mode_create_dumb_ioctl(struct drm_device
*dev
,
3098 void *data
, struct drm_file
*file_priv
)
3100 struct drm_mode_create_dumb
*args
= data
;
3102 if (!dev
->driver
->dumb_create
)
3104 return dev
->driver
->dumb_create(file_priv
, dev
, args
);
3107 int drm_mode_mmap_dumb_ioctl(struct drm_device
*dev
,
3108 void *data
, struct drm_file
*file_priv
)
3110 struct drm_mode_map_dumb
*args
= data
;
3112 /* call driver ioctl to get mmap offset */
3113 if (!dev
->driver
->dumb_map_offset
)
3116 return dev
->driver
->dumb_map_offset(file_priv
, dev
, args
->handle
, &args
->offset
);
3119 int drm_mode_destroy_dumb_ioctl(struct drm_device
*dev
,
3120 void *data
, struct drm_file
*file_priv
)
3122 struct drm_mode_destroy_dumb
*args
= data
;
3124 if (!dev
->driver
->dumb_destroy
)
3127 return dev
->driver
->dumb_destroy(file_priv
, dev
, args
->handle
);
3131 * Just need to support RGB formats here for compat with code that doesn't
3132 * use pixel formats directly yet.
3134 void drm_fb_get_bpp_depth(uint32_t format
, unsigned int *depth
,
3138 case DRM_FORMAT_RGB332
:
3139 case DRM_FORMAT_BGR233
:
3143 case DRM_FORMAT_XRGB1555
:
3144 case DRM_FORMAT_XBGR1555
:
3145 case DRM_FORMAT_RGBX5551
:
3146 case DRM_FORMAT_BGRX5551
:
3147 case DRM_FORMAT_ARGB1555
:
3148 case DRM_FORMAT_ABGR1555
:
3149 case DRM_FORMAT_RGBA5551
:
3150 case DRM_FORMAT_BGRA5551
:
3154 case DRM_FORMAT_RGB565
:
3155 case DRM_FORMAT_BGR565
:
3159 case DRM_FORMAT_RGB888
:
3160 case DRM_FORMAT_BGR888
:
3164 case DRM_FORMAT_XRGB8888
:
3165 case DRM_FORMAT_XBGR8888
:
3166 case DRM_FORMAT_RGBX8888
:
3167 case DRM_FORMAT_BGRX8888
:
3171 case DRM_FORMAT_XRGB2101010
:
3172 case DRM_FORMAT_XBGR2101010
:
3173 case DRM_FORMAT_RGBX1010102
:
3174 case DRM_FORMAT_BGRX1010102
:
3175 case DRM_FORMAT_ARGB2101010
:
3176 case DRM_FORMAT_ABGR2101010
:
3177 case DRM_FORMAT_RGBA1010102
:
3178 case DRM_FORMAT_BGRA1010102
:
3182 case DRM_FORMAT_ARGB8888
:
3183 case DRM_FORMAT_ABGR8888
:
3184 case DRM_FORMAT_RGBA8888
:
3185 case DRM_FORMAT_BGRA8888
:
3190 DRM_DEBUG_KMS("unsupported pixel format\n");
3196 EXPORT_SYMBOL(drm_fb_get_bpp_depth
);