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>
37 struct drm_prop_enum_list
{
42 /* Avoid boilerplate. I'm tired of typing. */
43 #define DRM_ENUM_NAME_FN(fnname, list) \
44 char *fnname(int val) \
47 for (i = 0; i < ARRAY_SIZE(list); i++) { \
48 if (list[i].type == val) \
49 return list[i].name; \
57 static struct drm_prop_enum_list drm_dpms_enum_list
[] =
58 { { DRM_MODE_DPMS_ON
, "On" },
59 { DRM_MODE_DPMS_STANDBY
, "Standby" },
60 { DRM_MODE_DPMS_SUSPEND
, "Suspend" },
61 { DRM_MODE_DPMS_OFF
, "Off" }
64 DRM_ENUM_NAME_FN(drm_get_dpms_name
, drm_dpms_enum_list
)
69 static struct drm_prop_enum_list drm_scaling_mode_enum_list
[] =
71 { DRM_MODE_SCALE_NONE
, "None" },
72 { DRM_MODE_SCALE_FULLSCREEN
, "Full" },
73 { DRM_MODE_SCALE_CENTER
, "Center" },
74 { DRM_MODE_SCALE_ASPECT
, "Full aspect" },
77 static struct drm_prop_enum_list drm_dithering_mode_enum_list
[] =
79 { DRM_MODE_DITHERING_OFF
, "Off" },
80 { DRM_MODE_DITHERING_ON
, "On" },
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 struct drm_conn_prop_enum_list
{
135 * Connector and encoder types.
137 static struct drm_conn_prop_enum_list drm_connector_enum_list
[] =
138 { { DRM_MODE_CONNECTOR_Unknown
, "Unknown", 0 },
139 { DRM_MODE_CONNECTOR_VGA
, "VGA", 0 },
140 { DRM_MODE_CONNECTOR_DVII
, "DVI-I", 0 },
141 { DRM_MODE_CONNECTOR_DVID
, "DVI-D", 0 },
142 { DRM_MODE_CONNECTOR_DVIA
, "DVI-A", 0 },
143 { DRM_MODE_CONNECTOR_Composite
, "Composite", 0 },
144 { DRM_MODE_CONNECTOR_SVIDEO
, "SVIDEO", 0 },
145 { DRM_MODE_CONNECTOR_LVDS
, "LVDS", 0 },
146 { DRM_MODE_CONNECTOR_Component
, "Component", 0 },
147 { DRM_MODE_CONNECTOR_9PinDIN
, "9-pin DIN", 0 },
148 { DRM_MODE_CONNECTOR_DisplayPort
, "DisplayPort", 0 },
149 { DRM_MODE_CONNECTOR_HDMIA
, "HDMI Type A", 0 },
150 { DRM_MODE_CONNECTOR_HDMIB
, "HDMI Type B", 0 },
151 { DRM_MODE_CONNECTOR_TV
, "TV", 0 },
154 static struct drm_prop_enum_list drm_encoder_enum_list
[] =
155 { { DRM_MODE_ENCODER_NONE
, "None" },
156 { DRM_MODE_ENCODER_DAC
, "DAC" },
157 { DRM_MODE_ENCODER_TMDS
, "TMDS" },
158 { DRM_MODE_ENCODER_LVDS
, "LVDS" },
159 { DRM_MODE_ENCODER_TVDAC
, "TV" },
162 char *drm_get_encoder_name(struct drm_encoder
*encoder
)
166 snprintf(buf
, 32, "%s-%d",
167 drm_encoder_enum_list
[encoder
->encoder_type
].name
,
172 char *drm_get_connector_name(struct drm_connector
*connector
)
176 snprintf(buf
, 32, "%s-%d",
177 drm_connector_enum_list
[connector
->connector_type
].name
,
178 connector
->connector_type_id
);
181 EXPORT_SYMBOL(drm_get_connector_name
);
183 char *drm_get_connector_status_name(enum drm_connector_status status
)
185 if (status
== connector_status_connected
)
187 else if (status
== connector_status_disconnected
)
188 return "disconnected";
194 * drm_mode_object_get - allocate a new identifier
196 * @ptr: object pointer, used to generate unique ID
201 * Create a unique identifier based on @ptr in @dev's identifier space. Used
202 * for tracking modes, CRTCs and connectors.
205 * New unique (relative to other objects in @dev) integer identifier for the
208 static int drm_mode_object_get(struct drm_device
*dev
,
209 struct drm_mode_object
*obj
, uint32_t obj_type
)
215 if (idr_pre_get(&dev
->mode_config
.crtc_idr
, GFP_KERNEL
) == 0) {
216 DRM_ERROR("Ran out memory getting a mode number\n");
220 mutex_lock(&dev
->mode_config
.idr_mutex
);
221 ret
= idr_get_new_above(&dev
->mode_config
.crtc_idr
, obj
, 1, &new_id
);
222 mutex_unlock(&dev
->mode_config
.idr_mutex
);
227 obj
->type
= obj_type
;
232 * drm_mode_object_put - free an identifer
237 * Caller must hold DRM mode_config lock.
239 * Free @id from @dev's unique identifier pool.
241 static void drm_mode_object_put(struct drm_device
*dev
,
242 struct drm_mode_object
*object
)
244 mutex_lock(&dev
->mode_config
.idr_mutex
);
245 idr_remove(&dev
->mode_config
.crtc_idr
, object
->id
);
246 mutex_unlock(&dev
->mode_config
.idr_mutex
);
249 void *drm_mode_object_find(struct drm_device
*dev
, uint32_t id
, uint32_t type
)
251 struct drm_mode_object
*obj
= NULL
;
253 mutex_lock(&dev
->mode_config
.idr_mutex
);
254 obj
= idr_find(&dev
->mode_config
.crtc_idr
, id
);
255 if (!obj
|| (obj
->type
!= type
) || (obj
->id
!= id
))
257 mutex_unlock(&dev
->mode_config
.idr_mutex
);
261 EXPORT_SYMBOL(drm_mode_object_find
);
264 * drm_framebuffer_init - initialize a framebuffer
268 * Caller must hold mode config lock.
270 * Allocates an ID for the framebuffer's parent mode object, sets its mode
271 * functions & device file and adds it to the master fd list.
274 * Zero on success, error code on falure.
276 int drm_framebuffer_init(struct drm_device
*dev
, struct drm_framebuffer
*fb
,
277 const struct drm_framebuffer_funcs
*funcs
)
281 ret
= drm_mode_object_get(dev
, &fb
->base
, DRM_MODE_OBJECT_FB
);
288 dev
->mode_config
.num_fb
++;
289 list_add(&fb
->head
, &dev
->mode_config
.fb_list
);
293 EXPORT_SYMBOL(drm_framebuffer_init
);
296 * drm_framebuffer_cleanup - remove a framebuffer object
297 * @fb: framebuffer to remove
300 * Caller must hold mode config lock.
302 * Scans all the CRTCs in @dev's mode_config. If they're using @fb, removes
303 * it, setting it to NULL.
305 void drm_framebuffer_cleanup(struct drm_framebuffer
*fb
)
307 struct drm_device
*dev
= fb
->dev
;
308 struct drm_crtc
*crtc
;
309 struct drm_mode_set set
;
312 /* remove from any CRTC */
313 list_for_each_entry(crtc
, &dev
->mode_config
.crtc_list
, head
) {
314 if (crtc
->fb
== fb
) {
315 /* should turn off the crtc */
316 memset(&set
, 0, sizeof(struct drm_mode_set
));
319 ret
= crtc
->funcs
->set_config(&set
);
321 DRM_ERROR("failed to reset crtc %p when fb was deleted\n", crtc
);
325 drm_mode_object_put(dev
, &fb
->base
);
327 dev
->mode_config
.num_fb
--;
329 EXPORT_SYMBOL(drm_framebuffer_cleanup
);
332 * drm_crtc_init - Initialise a new CRTC object
334 * @crtc: CRTC object to init
335 * @funcs: callbacks for the new CRTC
338 * Caller must hold mode config lock.
340 * Inits a new object created as base part of an driver crtc object.
342 void drm_crtc_init(struct drm_device
*dev
, struct drm_crtc
*crtc
,
343 const struct drm_crtc_funcs
*funcs
)
348 mutex_lock(&dev
->mode_config
.mutex
);
349 drm_mode_object_get(dev
, &crtc
->base
, DRM_MODE_OBJECT_CRTC
);
351 list_add_tail(&crtc
->head
, &dev
->mode_config
.crtc_list
);
352 dev
->mode_config
.num_crtc
++;
353 mutex_unlock(&dev
->mode_config
.mutex
);
355 EXPORT_SYMBOL(drm_crtc_init
);
358 * drm_crtc_cleanup - Cleans up the core crtc usage.
359 * @crtc: CRTC to cleanup
362 * Caller must hold mode config lock.
364 * Cleanup @crtc. Removes from drm modesetting space
365 * does NOT free object, caller does that.
367 void drm_crtc_cleanup(struct drm_crtc
*crtc
)
369 struct drm_device
*dev
= crtc
->dev
;
371 if (crtc
->gamma_store
) {
372 kfree(crtc
->gamma_store
);
373 crtc
->gamma_store
= NULL
;
376 drm_mode_object_put(dev
, &crtc
->base
);
377 list_del(&crtc
->head
);
378 dev
->mode_config
.num_crtc
--;
380 EXPORT_SYMBOL(drm_crtc_cleanup
);
383 * drm_mode_probed_add - add a mode to a connector's probed mode list
384 * @connector: connector the new mode
388 * Caller must hold mode config lock.
390 * Add @mode to @connector's mode list for later use.
392 void drm_mode_probed_add(struct drm_connector
*connector
,
393 struct drm_display_mode
*mode
)
395 list_add(&mode
->head
, &connector
->probed_modes
);
397 EXPORT_SYMBOL(drm_mode_probed_add
);
400 * drm_mode_remove - remove and free a mode
401 * @connector: connector list to modify
402 * @mode: mode to remove
405 * Caller must hold mode config lock.
407 * Remove @mode from @connector's mode list, then free it.
409 void drm_mode_remove(struct drm_connector
*connector
,
410 struct drm_display_mode
*mode
)
412 list_del(&mode
->head
);
415 EXPORT_SYMBOL(drm_mode_remove
);
418 * drm_connector_init - Init a preallocated connector
420 * @connector: the connector to init
421 * @funcs: callbacks for this connector
422 * @name: user visible name of the connector
425 * Caller must hold @dev's mode_config lock.
427 * Initialises a preallocated connector. Connectors should be
428 * subclassed as part of driver connector objects.
430 void drm_connector_init(struct drm_device
*dev
,
431 struct drm_connector
*connector
,
432 const struct drm_connector_funcs
*funcs
,
435 mutex_lock(&dev
->mode_config
.mutex
);
437 connector
->dev
= dev
;
438 connector
->funcs
= funcs
;
439 drm_mode_object_get(dev
, &connector
->base
, DRM_MODE_OBJECT_CONNECTOR
);
440 connector
->connector_type
= connector_type
;
441 connector
->connector_type_id
=
442 ++drm_connector_enum_list
[connector_type
].count
; /* TODO */
443 INIT_LIST_HEAD(&connector
->user_modes
);
444 INIT_LIST_HEAD(&connector
->probed_modes
);
445 INIT_LIST_HEAD(&connector
->modes
);
446 connector
->edid_blob_ptr
= NULL
;
448 list_add_tail(&connector
->head
, &dev
->mode_config
.connector_list
);
449 dev
->mode_config
.num_connector
++;
451 drm_connector_attach_property(connector
,
452 dev
->mode_config
.edid_property
, 0);
454 drm_connector_attach_property(connector
,
455 dev
->mode_config
.dpms_property
, 0);
457 mutex_unlock(&dev
->mode_config
.mutex
);
459 EXPORT_SYMBOL(drm_connector_init
);
462 * drm_connector_cleanup - cleans up an initialised connector
463 * @connector: connector to cleanup
466 * Caller must hold @dev's mode_config lock.
468 * Cleans up the connector but doesn't free the object.
470 void drm_connector_cleanup(struct drm_connector
*connector
)
472 struct drm_device
*dev
= connector
->dev
;
473 struct drm_display_mode
*mode
, *t
;
475 list_for_each_entry_safe(mode
, t
, &connector
->probed_modes
, head
)
476 drm_mode_remove(connector
, mode
);
478 list_for_each_entry_safe(mode
, t
, &connector
->modes
, head
)
479 drm_mode_remove(connector
, mode
);
481 list_for_each_entry_safe(mode
, t
, &connector
->user_modes
, head
)
482 drm_mode_remove(connector
, mode
);
484 mutex_lock(&dev
->mode_config
.mutex
);
485 drm_mode_object_put(dev
, &connector
->base
);
486 list_del(&connector
->head
);
487 mutex_unlock(&dev
->mode_config
.mutex
);
489 EXPORT_SYMBOL(drm_connector_cleanup
);
491 void drm_encoder_init(struct drm_device
*dev
,
492 struct drm_encoder
*encoder
,
493 const struct drm_encoder_funcs
*funcs
,
496 mutex_lock(&dev
->mode_config
.mutex
);
500 drm_mode_object_get(dev
, &encoder
->base
, DRM_MODE_OBJECT_ENCODER
);
501 encoder
->encoder_type
= encoder_type
;
502 encoder
->funcs
= funcs
;
504 list_add_tail(&encoder
->head
, &dev
->mode_config
.encoder_list
);
505 dev
->mode_config
.num_encoder
++;
507 mutex_unlock(&dev
->mode_config
.mutex
);
509 EXPORT_SYMBOL(drm_encoder_init
);
511 void drm_encoder_cleanup(struct drm_encoder
*encoder
)
513 struct drm_device
*dev
= encoder
->dev
;
514 mutex_lock(&dev
->mode_config
.mutex
);
515 drm_mode_object_put(dev
, &encoder
->base
);
516 list_del(&encoder
->head
);
517 mutex_unlock(&dev
->mode_config
.mutex
);
519 EXPORT_SYMBOL(drm_encoder_cleanup
);
522 * drm_mode_create - create a new display mode
526 * Caller must hold DRM mode_config lock.
528 * Create a new drm_display_mode, give it an ID, and return it.
531 * Pointer to new mode on success, NULL on error.
533 struct drm_display_mode
*drm_mode_create(struct drm_device
*dev
)
535 struct drm_display_mode
*nmode
;
537 nmode
= kzalloc(sizeof(struct drm_display_mode
), GFP_KERNEL
);
541 drm_mode_object_get(dev
, &nmode
->base
, DRM_MODE_OBJECT_MODE
);
544 EXPORT_SYMBOL(drm_mode_create
);
547 * drm_mode_destroy - remove a mode
549 * @mode: mode to remove
552 * Caller must hold mode config lock.
554 * Free @mode's unique identifier, then free it.
556 void drm_mode_destroy(struct drm_device
*dev
, struct drm_display_mode
*mode
)
558 drm_mode_object_put(dev
, &mode
->base
);
562 EXPORT_SYMBOL(drm_mode_destroy
);
564 static int drm_mode_create_standard_connector_properties(struct drm_device
*dev
)
566 struct drm_property
*edid
;
567 struct drm_property
*dpms
;
571 * Standard properties (apply to all connectors)
573 edid
= drm_property_create(dev
, DRM_MODE_PROP_BLOB
|
574 DRM_MODE_PROP_IMMUTABLE
,
576 dev
->mode_config
.edid_property
= edid
;
578 dpms
= drm_property_create(dev
, DRM_MODE_PROP_ENUM
,
579 "DPMS", ARRAY_SIZE(drm_dpms_enum_list
));
580 for (i
= 0; i
< ARRAY_SIZE(drm_dpms_enum_list
); i
++)
581 drm_property_add_enum(dpms
, i
, drm_dpms_enum_list
[i
].type
,
582 drm_dpms_enum_list
[i
].name
);
583 dev
->mode_config
.dpms_property
= dpms
;
589 * drm_mode_create_dvi_i_properties - create DVI-I specific connector properties
592 * Called by a driver the first time a DVI-I connector is made.
594 int drm_mode_create_dvi_i_properties(struct drm_device
*dev
)
596 struct drm_property
*dvi_i_selector
;
597 struct drm_property
*dvi_i_subconnector
;
600 if (dev
->mode_config
.dvi_i_select_subconnector_property
)
604 drm_property_create(dev
, DRM_MODE_PROP_ENUM
,
605 "select subconnector",
606 ARRAY_SIZE(drm_dvi_i_select_enum_list
));
607 for (i
= 0; i
< ARRAY_SIZE(drm_dvi_i_select_enum_list
); i
++)
608 drm_property_add_enum(dvi_i_selector
, i
,
609 drm_dvi_i_select_enum_list
[i
].type
,
610 drm_dvi_i_select_enum_list
[i
].name
);
611 dev
->mode_config
.dvi_i_select_subconnector_property
= dvi_i_selector
;
614 drm_property_create(dev
, DRM_MODE_PROP_ENUM
|
615 DRM_MODE_PROP_IMMUTABLE
,
617 ARRAY_SIZE(drm_dvi_i_subconnector_enum_list
));
618 for (i
= 0; i
< ARRAY_SIZE(drm_dvi_i_subconnector_enum_list
); i
++)
619 drm_property_add_enum(dvi_i_subconnector
, i
,
620 drm_dvi_i_subconnector_enum_list
[i
].type
,
621 drm_dvi_i_subconnector_enum_list
[i
].name
);
622 dev
->mode_config
.dvi_i_subconnector_property
= dvi_i_subconnector
;
626 EXPORT_SYMBOL(drm_mode_create_dvi_i_properties
);
629 * drm_create_tv_properties - create TV specific connector properties
631 * @num_modes: number of different TV formats (modes) supported
632 * @modes: array of pointers to strings containing name of each format
634 * Called by a driver's TV initialization routine, this function creates
635 * the TV specific connector properties for a given device. Caller is
636 * responsible for allocating a list of format names and passing them to
639 int drm_mode_create_tv_properties(struct drm_device
*dev
, int num_modes
,
642 struct drm_property
*tv_selector
;
643 struct drm_property
*tv_subconnector
;
646 if (dev
->mode_config
.tv_select_subconnector_property
)
650 * Basic connector properties
652 tv_selector
= drm_property_create(dev
, DRM_MODE_PROP_ENUM
,
653 "select subconnector",
654 ARRAY_SIZE(drm_tv_select_enum_list
));
655 for (i
= 0; i
< ARRAY_SIZE(drm_tv_select_enum_list
); i
++)
656 drm_property_add_enum(tv_selector
, i
,
657 drm_tv_select_enum_list
[i
].type
,
658 drm_tv_select_enum_list
[i
].name
);
659 dev
->mode_config
.tv_select_subconnector_property
= tv_selector
;
662 drm_property_create(dev
, DRM_MODE_PROP_ENUM
|
663 DRM_MODE_PROP_IMMUTABLE
, "subconnector",
664 ARRAY_SIZE(drm_tv_subconnector_enum_list
));
665 for (i
= 0; i
< ARRAY_SIZE(drm_tv_subconnector_enum_list
); i
++)
666 drm_property_add_enum(tv_subconnector
, i
,
667 drm_tv_subconnector_enum_list
[i
].type
,
668 drm_tv_subconnector_enum_list
[i
].name
);
669 dev
->mode_config
.tv_subconnector_property
= tv_subconnector
;
672 * Other, TV specific properties: margins & TV modes.
674 dev
->mode_config
.tv_left_margin_property
=
675 drm_property_create(dev
, DRM_MODE_PROP_RANGE
,
677 dev
->mode_config
.tv_left_margin_property
->values
[0] = 0;
678 dev
->mode_config
.tv_left_margin_property
->values
[1] = 100;
680 dev
->mode_config
.tv_right_margin_property
=
681 drm_property_create(dev
, DRM_MODE_PROP_RANGE
,
683 dev
->mode_config
.tv_right_margin_property
->values
[0] = 0;
684 dev
->mode_config
.tv_right_margin_property
->values
[1] = 100;
686 dev
->mode_config
.tv_top_margin_property
=
687 drm_property_create(dev
, DRM_MODE_PROP_RANGE
,
689 dev
->mode_config
.tv_top_margin_property
->values
[0] = 0;
690 dev
->mode_config
.tv_top_margin_property
->values
[1] = 100;
692 dev
->mode_config
.tv_bottom_margin_property
=
693 drm_property_create(dev
, DRM_MODE_PROP_RANGE
,
695 dev
->mode_config
.tv_bottom_margin_property
->values
[0] = 0;
696 dev
->mode_config
.tv_bottom_margin_property
->values
[1] = 100;
698 dev
->mode_config
.tv_mode_property
=
699 drm_property_create(dev
, DRM_MODE_PROP_ENUM
,
701 for (i
= 0; i
< num_modes
; i
++)
702 drm_property_add_enum(dev
->mode_config
.tv_mode_property
, i
,
705 dev
->mode_config
.tv_brightness_property
=
706 drm_property_create(dev
, DRM_MODE_PROP_RANGE
,
708 dev
->mode_config
.tv_brightness_property
->values
[0] = 0;
709 dev
->mode_config
.tv_brightness_property
->values
[1] = 100;
711 dev
->mode_config
.tv_contrast_property
=
712 drm_property_create(dev
, DRM_MODE_PROP_RANGE
,
714 dev
->mode_config
.tv_contrast_property
->values
[0] = 0;
715 dev
->mode_config
.tv_contrast_property
->values
[1] = 100;
717 dev
->mode_config
.tv_flicker_reduction_property
=
718 drm_property_create(dev
, DRM_MODE_PROP_RANGE
,
719 "flicker reduction", 2);
720 dev
->mode_config
.tv_flicker_reduction_property
->values
[0] = 0;
721 dev
->mode_config
.tv_flicker_reduction_property
->values
[1] = 100;
723 dev
->mode_config
.tv_overscan_property
=
724 drm_property_create(dev
, DRM_MODE_PROP_RANGE
,
726 dev
->mode_config
.tv_overscan_property
->values
[0] = 0;
727 dev
->mode_config
.tv_overscan_property
->values
[1] = 100;
729 dev
->mode_config
.tv_saturation_property
=
730 drm_property_create(dev
, DRM_MODE_PROP_RANGE
,
732 dev
->mode_config
.tv_saturation_property
->values
[0] = 0;
733 dev
->mode_config
.tv_saturation_property
->values
[1] = 100;
735 dev
->mode_config
.tv_hue_property
=
736 drm_property_create(dev
, DRM_MODE_PROP_RANGE
,
738 dev
->mode_config
.tv_hue_property
->values
[0] = 0;
739 dev
->mode_config
.tv_hue_property
->values
[1] = 100;
743 EXPORT_SYMBOL(drm_mode_create_tv_properties
);
746 * drm_mode_create_scaling_mode_property - create scaling mode property
749 * Called by a driver the first time it's needed, must be attached to desired
752 int drm_mode_create_scaling_mode_property(struct drm_device
*dev
)
754 struct drm_property
*scaling_mode
;
757 if (dev
->mode_config
.scaling_mode_property
)
761 drm_property_create(dev
, DRM_MODE_PROP_ENUM
, "scaling mode",
762 ARRAY_SIZE(drm_scaling_mode_enum_list
));
763 for (i
= 0; i
< ARRAY_SIZE(drm_scaling_mode_enum_list
); i
++)
764 drm_property_add_enum(scaling_mode
, i
,
765 drm_scaling_mode_enum_list
[i
].type
,
766 drm_scaling_mode_enum_list
[i
].name
);
768 dev
->mode_config
.scaling_mode_property
= scaling_mode
;
772 EXPORT_SYMBOL(drm_mode_create_scaling_mode_property
);
775 * drm_mode_create_dithering_property - create dithering property
778 * Called by a driver the first time it's needed, must be attached to desired
781 int drm_mode_create_dithering_property(struct drm_device
*dev
)
783 struct drm_property
*dithering_mode
;
786 if (dev
->mode_config
.dithering_mode_property
)
790 drm_property_create(dev
, DRM_MODE_PROP_ENUM
, "dithering",
791 ARRAY_SIZE(drm_dithering_mode_enum_list
));
792 for (i
= 0; i
< ARRAY_SIZE(drm_dithering_mode_enum_list
); i
++)
793 drm_property_add_enum(dithering_mode
, i
,
794 drm_dithering_mode_enum_list
[i
].type
,
795 drm_dithering_mode_enum_list
[i
].name
);
796 dev
->mode_config
.dithering_mode_property
= dithering_mode
;
800 EXPORT_SYMBOL(drm_mode_create_dithering_property
);
803 * drm_mode_config_init - initialize DRM mode_configuration structure
807 * None, should happen single threaded at init time.
809 * Initialize @dev's mode_config structure, used for tracking the graphics
810 * configuration of @dev.
812 void drm_mode_config_init(struct drm_device
*dev
)
814 mutex_init(&dev
->mode_config
.mutex
);
815 mutex_init(&dev
->mode_config
.idr_mutex
);
816 INIT_LIST_HEAD(&dev
->mode_config
.fb_list
);
817 INIT_LIST_HEAD(&dev
->mode_config
.fb_kernel_list
);
818 INIT_LIST_HEAD(&dev
->mode_config
.crtc_list
);
819 INIT_LIST_HEAD(&dev
->mode_config
.connector_list
);
820 INIT_LIST_HEAD(&dev
->mode_config
.encoder_list
);
821 INIT_LIST_HEAD(&dev
->mode_config
.property_list
);
822 INIT_LIST_HEAD(&dev
->mode_config
.property_blob_list
);
823 idr_init(&dev
->mode_config
.crtc_idr
);
825 mutex_lock(&dev
->mode_config
.mutex
);
826 drm_mode_create_standard_connector_properties(dev
);
827 mutex_unlock(&dev
->mode_config
.mutex
);
829 /* Just to be sure */
830 dev
->mode_config
.num_fb
= 0;
831 dev
->mode_config
.num_connector
= 0;
832 dev
->mode_config
.num_crtc
= 0;
833 dev
->mode_config
.num_encoder
= 0;
835 EXPORT_SYMBOL(drm_mode_config_init
);
837 int drm_mode_group_init(struct drm_device
*dev
, struct drm_mode_group
*group
)
839 uint32_t total_objects
= 0;
841 total_objects
+= dev
->mode_config
.num_crtc
;
842 total_objects
+= dev
->mode_config
.num_connector
;
843 total_objects
+= dev
->mode_config
.num_encoder
;
845 if (total_objects
== 0)
848 group
->id_list
= kzalloc(total_objects
* sizeof(uint32_t), GFP_KERNEL
);
852 group
->num_crtcs
= 0;
853 group
->num_connectors
= 0;
854 group
->num_encoders
= 0;
858 int drm_mode_group_init_legacy_group(struct drm_device
*dev
,
859 struct drm_mode_group
*group
)
861 struct drm_crtc
*crtc
;
862 struct drm_encoder
*encoder
;
863 struct drm_connector
*connector
;
866 if ((ret
= drm_mode_group_init(dev
, group
)))
869 list_for_each_entry(crtc
, &dev
->mode_config
.crtc_list
, head
)
870 group
->id_list
[group
->num_crtcs
++] = crtc
->base
.id
;
872 list_for_each_entry(encoder
, &dev
->mode_config
.encoder_list
, head
)
873 group
->id_list
[group
->num_crtcs
+ group
->num_encoders
++] =
876 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
, head
)
877 group
->id_list
[group
->num_crtcs
+ group
->num_encoders
+
878 group
->num_connectors
++] = connector
->base
.id
;
884 * drm_mode_config_cleanup - free up DRM mode_config info
888 * Caller must hold mode config lock.
890 * Free up all the connectors and CRTCs associated with this DRM device, then
891 * free up the framebuffers and associated buffer objects.
893 * FIXME: cleanup any dangling user buffer objects too
895 void drm_mode_config_cleanup(struct drm_device
*dev
)
897 struct drm_connector
*connector
, *ot
;
898 struct drm_crtc
*crtc
, *ct
;
899 struct drm_encoder
*encoder
, *enct
;
900 struct drm_framebuffer
*fb
, *fbt
;
901 struct drm_property
*property
, *pt
;
903 list_for_each_entry_safe(encoder
, enct
, &dev
->mode_config
.encoder_list
,
905 encoder
->funcs
->destroy(encoder
);
908 list_for_each_entry_safe(connector
, ot
,
909 &dev
->mode_config
.connector_list
, head
) {
910 connector
->funcs
->destroy(connector
);
913 list_for_each_entry_safe(property
, pt
, &dev
->mode_config
.property_list
,
915 drm_property_destroy(dev
, property
);
918 list_for_each_entry_safe(fb
, fbt
, &dev
->mode_config
.fb_list
, head
) {
919 fb
->funcs
->destroy(fb
);
922 list_for_each_entry_safe(crtc
, ct
, &dev
->mode_config
.crtc_list
, head
) {
923 crtc
->funcs
->destroy(crtc
);
927 EXPORT_SYMBOL(drm_mode_config_cleanup
);
930 * drm_crtc_convert_to_umode - convert a drm_display_mode into a modeinfo
931 * @out: drm_mode_modeinfo struct to return to the user
932 * @in: drm_display_mode to use
937 * Convert a drm_display_mode into a drm_mode_modeinfo structure to return to
940 void drm_crtc_convert_to_umode(struct drm_mode_modeinfo
*out
,
941 struct drm_display_mode
*in
)
943 out
->clock
= in
->clock
;
944 out
->hdisplay
= in
->hdisplay
;
945 out
->hsync_start
= in
->hsync_start
;
946 out
->hsync_end
= in
->hsync_end
;
947 out
->htotal
= in
->htotal
;
948 out
->hskew
= in
->hskew
;
949 out
->vdisplay
= in
->vdisplay
;
950 out
->vsync_start
= in
->vsync_start
;
951 out
->vsync_end
= in
->vsync_end
;
952 out
->vtotal
= in
->vtotal
;
953 out
->vscan
= in
->vscan
;
954 out
->vrefresh
= in
->vrefresh
;
955 out
->flags
= in
->flags
;
956 out
->type
= in
->type
;
957 strncpy(out
->name
, in
->name
, DRM_DISPLAY_MODE_LEN
);
958 out
->name
[DRM_DISPLAY_MODE_LEN
-1] = 0;
962 * drm_crtc_convert_to_umode - convert a modeinfo into a drm_display_mode
963 * @out: drm_display_mode to return to the user
964 * @in: drm_mode_modeinfo to use
969 * Convert a drm_mode_modeinfo into a drm_display_mode structure to return to
972 void drm_crtc_convert_umode(struct drm_display_mode
*out
,
973 struct drm_mode_modeinfo
*in
)
975 out
->clock
= in
->clock
;
976 out
->hdisplay
= in
->hdisplay
;
977 out
->hsync_start
= in
->hsync_start
;
978 out
->hsync_end
= in
->hsync_end
;
979 out
->htotal
= in
->htotal
;
980 out
->hskew
= in
->hskew
;
981 out
->vdisplay
= in
->vdisplay
;
982 out
->vsync_start
= in
->vsync_start
;
983 out
->vsync_end
= in
->vsync_end
;
984 out
->vtotal
= in
->vtotal
;
985 out
->vscan
= in
->vscan
;
986 out
->vrefresh
= in
->vrefresh
;
987 out
->flags
= in
->flags
;
988 out
->type
= in
->type
;
989 strncpy(out
->name
, in
->name
, DRM_DISPLAY_MODE_LEN
);
990 out
->name
[DRM_DISPLAY_MODE_LEN
-1] = 0;
994 * drm_mode_getresources - get graphics configuration
995 * @inode: inode from the ioctl
996 * @filp: file * from the ioctl
997 * @cmd: cmd from ioctl
998 * @arg: arg from ioctl
1001 * Takes mode config lock.
1003 * Construct a set of configuration description structures and return
1004 * them to the user, including CRTC, connector and framebuffer configuration.
1006 * Called by the user via ioctl.
1009 * Zero on success, errno on failure.
1011 int drm_mode_getresources(struct drm_device
*dev
, void *data
,
1012 struct drm_file
*file_priv
)
1014 struct drm_mode_card_res
*card_res
= data
;
1015 struct list_head
*lh
;
1016 struct drm_framebuffer
*fb
;
1017 struct drm_connector
*connector
;
1018 struct drm_crtc
*crtc
;
1019 struct drm_encoder
*encoder
;
1021 int connector_count
= 0;
1024 int encoder_count
= 0;
1026 uint32_t __user
*fb_id
;
1027 uint32_t __user
*crtc_id
;
1028 uint32_t __user
*connector_id
;
1029 uint32_t __user
*encoder_id
;
1030 struct drm_mode_group
*mode_group
;
1032 mutex_lock(&dev
->mode_config
.mutex
);
1035 * For the non-control nodes we need to limit the list of resources
1036 * by IDs in the group list for this node
1038 list_for_each(lh
, &file_priv
->fbs
)
1041 mode_group
= &file_priv
->master
->minor
->mode_group
;
1042 if (file_priv
->master
->minor
->type
== DRM_MINOR_CONTROL
) {
1044 list_for_each(lh
, &dev
->mode_config
.crtc_list
)
1047 list_for_each(lh
, &dev
->mode_config
.connector_list
)
1050 list_for_each(lh
, &dev
->mode_config
.encoder_list
)
1054 crtc_count
= mode_group
->num_crtcs
;
1055 connector_count
= mode_group
->num_connectors
;
1056 encoder_count
= mode_group
->num_encoders
;
1059 card_res
->max_height
= dev
->mode_config
.max_height
;
1060 card_res
->min_height
= dev
->mode_config
.min_height
;
1061 card_res
->max_width
= dev
->mode_config
.max_width
;
1062 card_res
->min_width
= dev
->mode_config
.min_width
;
1064 /* handle this in 4 parts */
1066 if (card_res
->count_fbs
>= fb_count
) {
1068 fb_id
= (uint32_t __user
*)(unsigned long)card_res
->fb_id_ptr
;
1069 list_for_each_entry(fb
, &file_priv
->fbs
, head
) {
1070 if (put_user(fb
->base
.id
, fb_id
+ copied
)) {
1077 card_res
->count_fbs
= fb_count
;
1080 if (card_res
->count_crtcs
>= crtc_count
) {
1082 crtc_id
= (uint32_t __user
*)(unsigned long)card_res
->crtc_id_ptr
;
1083 if (file_priv
->master
->minor
->type
== DRM_MINOR_CONTROL
) {
1084 list_for_each_entry(crtc
, &dev
->mode_config
.crtc_list
,
1086 DRM_DEBUG_KMS("CRTC ID is %d\n", crtc
->base
.id
);
1087 if (put_user(crtc
->base
.id
, crtc_id
+ copied
)) {
1094 for (i
= 0; i
< mode_group
->num_crtcs
; i
++) {
1095 if (put_user(mode_group
->id_list
[i
],
1096 crtc_id
+ copied
)) {
1104 card_res
->count_crtcs
= crtc_count
;
1107 if (card_res
->count_encoders
>= encoder_count
) {
1109 encoder_id
= (uint32_t __user
*)(unsigned long)card_res
->encoder_id_ptr
;
1110 if (file_priv
->master
->minor
->type
== DRM_MINOR_CONTROL
) {
1111 list_for_each_entry(encoder
,
1112 &dev
->mode_config
.encoder_list
,
1114 DRM_DEBUG_KMS("ENCODER ID is %d\n",
1116 if (put_user(encoder
->base
.id
, encoder_id
+
1124 for (i
= mode_group
->num_crtcs
; i
< mode_group
->num_crtcs
+ mode_group
->num_encoders
; i
++) {
1125 if (put_user(mode_group
->id_list
[i
],
1126 encoder_id
+ copied
)) {
1135 card_res
->count_encoders
= encoder_count
;
1138 if (card_res
->count_connectors
>= connector_count
) {
1140 connector_id
= (uint32_t __user
*)(unsigned long)card_res
->connector_id_ptr
;
1141 if (file_priv
->master
->minor
->type
== DRM_MINOR_CONTROL
) {
1142 list_for_each_entry(connector
,
1143 &dev
->mode_config
.connector_list
,
1145 DRM_DEBUG_KMS("CONNECTOR ID is %d\n",
1146 connector
->base
.id
);
1147 if (put_user(connector
->base
.id
,
1148 connector_id
+ copied
)) {
1155 int start
= mode_group
->num_crtcs
+
1156 mode_group
->num_encoders
;
1157 for (i
= start
; i
< start
+ mode_group
->num_connectors
; i
++) {
1158 if (put_user(mode_group
->id_list
[i
],
1159 connector_id
+ copied
)) {
1167 card_res
->count_connectors
= connector_count
;
1169 DRM_DEBUG_KMS("Counted %d %d %d\n", card_res
->count_crtcs
,
1170 card_res
->count_connectors
, card_res
->count_encoders
);
1173 mutex_unlock(&dev
->mode_config
.mutex
);
1178 * drm_mode_getcrtc - get CRTC configuration
1179 * @inode: inode from the ioctl
1180 * @filp: file * from the ioctl
1181 * @cmd: cmd from ioctl
1182 * @arg: arg from ioctl
1187 * Construct a CRTC configuration structure to return to the user.
1189 * Called by the user via ioctl.
1192 * Zero on success, errno on failure.
1194 int drm_mode_getcrtc(struct drm_device
*dev
,
1195 void *data
, struct drm_file
*file_priv
)
1197 struct drm_mode_crtc
*crtc_resp
= data
;
1198 struct drm_crtc
*crtc
;
1199 struct drm_mode_object
*obj
;
1202 mutex_lock(&dev
->mode_config
.mutex
);
1204 obj
= drm_mode_object_find(dev
, crtc_resp
->crtc_id
,
1205 DRM_MODE_OBJECT_CRTC
);
1210 crtc
= obj_to_crtc(obj
);
1212 crtc_resp
->x
= crtc
->x
;
1213 crtc_resp
->y
= crtc
->y
;
1214 crtc_resp
->gamma_size
= crtc
->gamma_size
;
1216 crtc_resp
->fb_id
= crtc
->fb
->base
.id
;
1218 crtc_resp
->fb_id
= 0;
1220 if (crtc
->enabled
) {
1222 drm_crtc_convert_to_umode(&crtc_resp
->mode
, &crtc
->mode
);
1223 crtc_resp
->mode_valid
= 1;
1226 crtc_resp
->mode_valid
= 0;
1230 mutex_unlock(&dev
->mode_config
.mutex
);
1235 * drm_mode_getconnector - get connector configuration
1236 * @inode: inode from the ioctl
1237 * @filp: file * from the ioctl
1238 * @cmd: cmd from ioctl
1239 * @arg: arg from ioctl
1244 * Construct a connector configuration structure to return to the user.
1246 * Called by the user via ioctl.
1249 * Zero on success, errno on failure.
1251 int drm_mode_getconnector(struct drm_device
*dev
, void *data
,
1252 struct drm_file
*file_priv
)
1254 struct drm_mode_get_connector
*out_resp
= data
;
1255 struct drm_mode_object
*obj
;
1256 struct drm_connector
*connector
;
1257 struct drm_display_mode
*mode
;
1259 int props_count
= 0;
1260 int encoders_count
= 0;
1264 struct drm_mode_modeinfo u_mode
;
1265 struct drm_mode_modeinfo __user
*mode_ptr
;
1266 uint32_t __user
*prop_ptr
;
1267 uint64_t __user
*prop_values
;
1268 uint32_t __user
*encoder_ptr
;
1270 memset(&u_mode
, 0, sizeof(struct drm_mode_modeinfo
));
1272 DRM_DEBUG_KMS("connector id %d:\n", out_resp
->connector_id
);
1274 mutex_lock(&dev
->mode_config
.mutex
);
1276 obj
= drm_mode_object_find(dev
, out_resp
->connector_id
,
1277 DRM_MODE_OBJECT_CONNECTOR
);
1282 connector
= obj_to_connector(obj
);
1284 for (i
= 0; i
< DRM_CONNECTOR_MAX_PROPERTY
; i
++) {
1285 if (connector
->property_ids
[i
] != 0) {
1290 for (i
= 0; i
< DRM_CONNECTOR_MAX_ENCODER
; i
++) {
1291 if (connector
->encoder_ids
[i
] != 0) {
1296 if (out_resp
->count_modes
== 0) {
1297 connector
->funcs
->fill_modes(connector
,
1298 dev
->mode_config
.max_width
,
1299 dev
->mode_config
.max_height
);
1302 /* delayed so we get modes regardless of pre-fill_modes state */
1303 list_for_each_entry(mode
, &connector
->modes
, head
)
1306 out_resp
->connector_id
= connector
->base
.id
;
1307 out_resp
->connector_type
= connector
->connector_type
;
1308 out_resp
->connector_type_id
= connector
->connector_type_id
;
1309 out_resp
->mm_width
= connector
->display_info
.width_mm
;
1310 out_resp
->mm_height
= connector
->display_info
.height_mm
;
1311 out_resp
->subpixel
= connector
->display_info
.subpixel_order
;
1312 out_resp
->connection
= connector
->status
;
1313 if (connector
->encoder
)
1314 out_resp
->encoder_id
= connector
->encoder
->base
.id
;
1316 out_resp
->encoder_id
= 0;
1319 * This ioctl is called twice, once to determine how much space is
1320 * needed, and the 2nd time to fill it.
1322 if ((out_resp
->count_modes
>= mode_count
) && mode_count
) {
1324 mode_ptr
= (struct drm_mode_modeinfo
*)(unsigned long)out_resp
->modes_ptr
;
1325 list_for_each_entry(mode
, &connector
->modes
, head
) {
1326 drm_crtc_convert_to_umode(&u_mode
, mode
);
1327 if (copy_to_user(mode_ptr
+ copied
,
1328 &u_mode
, sizeof(u_mode
))) {
1335 out_resp
->count_modes
= mode_count
;
1337 if ((out_resp
->count_props
>= props_count
) && props_count
) {
1339 prop_ptr
= (uint32_t *)(unsigned long)(out_resp
->props_ptr
);
1340 prop_values
= (uint64_t *)(unsigned long)(out_resp
->prop_values_ptr
);
1341 for (i
= 0; i
< DRM_CONNECTOR_MAX_PROPERTY
; i
++) {
1342 if (connector
->property_ids
[i
] != 0) {
1343 if (put_user(connector
->property_ids
[i
],
1344 prop_ptr
+ copied
)) {
1349 if (put_user(connector
->property_values
[i
],
1350 prop_values
+ copied
)) {
1358 out_resp
->count_props
= props_count
;
1360 if ((out_resp
->count_encoders
>= encoders_count
) && encoders_count
) {
1362 encoder_ptr
= (uint32_t *)(unsigned long)(out_resp
->encoders_ptr
);
1363 for (i
= 0; i
< DRM_CONNECTOR_MAX_ENCODER
; i
++) {
1364 if (connector
->encoder_ids
[i
] != 0) {
1365 if (put_user(connector
->encoder_ids
[i
],
1366 encoder_ptr
+ copied
)) {
1374 out_resp
->count_encoders
= encoders_count
;
1377 mutex_unlock(&dev
->mode_config
.mutex
);
1381 int drm_mode_getencoder(struct drm_device
*dev
, void *data
,
1382 struct drm_file
*file_priv
)
1384 struct drm_mode_get_encoder
*enc_resp
= data
;
1385 struct drm_mode_object
*obj
;
1386 struct drm_encoder
*encoder
;
1389 mutex_lock(&dev
->mode_config
.mutex
);
1390 obj
= drm_mode_object_find(dev
, enc_resp
->encoder_id
,
1391 DRM_MODE_OBJECT_ENCODER
);
1396 encoder
= obj_to_encoder(obj
);
1399 enc_resp
->crtc_id
= encoder
->crtc
->base
.id
;
1401 enc_resp
->crtc_id
= 0;
1402 enc_resp
->encoder_type
= encoder
->encoder_type
;
1403 enc_resp
->encoder_id
= encoder
->base
.id
;
1404 enc_resp
->possible_crtcs
= encoder
->possible_crtcs
;
1405 enc_resp
->possible_clones
= encoder
->possible_clones
;
1408 mutex_unlock(&dev
->mode_config
.mutex
);
1413 * drm_mode_setcrtc - set CRTC configuration
1414 * @inode: inode from the ioctl
1415 * @filp: file * from the ioctl
1416 * @cmd: cmd from ioctl
1417 * @arg: arg from ioctl
1422 * Build a new CRTC configuration based on user request.
1424 * Called by the user via ioctl.
1427 * Zero on success, errno on failure.
1429 int drm_mode_setcrtc(struct drm_device
*dev
, void *data
,
1430 struct drm_file
*file_priv
)
1432 struct drm_mode_config
*config
= &dev
->mode_config
;
1433 struct drm_mode_crtc
*crtc_req
= data
;
1434 struct drm_mode_object
*obj
;
1435 struct drm_crtc
*crtc
, *crtcfb
;
1436 struct drm_connector
**connector_set
= NULL
, *connector
;
1437 struct drm_framebuffer
*fb
= NULL
;
1438 struct drm_display_mode
*mode
= NULL
;
1439 struct drm_mode_set set
;
1440 uint32_t __user
*set_connectors_ptr
;
1444 mutex_lock(&dev
->mode_config
.mutex
);
1445 obj
= drm_mode_object_find(dev
, crtc_req
->crtc_id
,
1446 DRM_MODE_OBJECT_CRTC
);
1448 DRM_DEBUG_KMS("Unknown CRTC ID %d\n", crtc_req
->crtc_id
);
1452 crtc
= obj_to_crtc(obj
);
1454 if (crtc_req
->mode_valid
) {
1455 /* If we have a mode we need a framebuffer. */
1456 /* If we pass -1, set the mode with the currently bound fb */
1457 if (crtc_req
->fb_id
== -1) {
1458 list_for_each_entry(crtcfb
,
1459 &dev
->mode_config
.crtc_list
, head
) {
1460 if (crtcfb
== crtc
) {
1461 DRM_DEBUG_KMS("Using current fb for "
1467 obj
= drm_mode_object_find(dev
, crtc_req
->fb_id
,
1468 DRM_MODE_OBJECT_FB
);
1470 DRM_DEBUG_KMS("Unknown FB ID%d\n",
1475 fb
= obj_to_fb(obj
);
1478 mode
= drm_mode_create(dev
);
1479 drm_crtc_convert_umode(mode
, &crtc_req
->mode
);
1480 drm_mode_set_crtcinfo(mode
, CRTC_INTERLACE_HALVE_V
);
1483 if (crtc_req
->count_connectors
== 0 && mode
) {
1484 DRM_DEBUG_KMS("Count connectors is 0 but mode set\n");
1489 if (crtc_req
->count_connectors
> 0 && (!mode
|| !fb
)) {
1490 DRM_DEBUG_KMS("Count connectors is %d but no mode or fb set\n",
1491 crtc_req
->count_connectors
);
1496 if (crtc_req
->count_connectors
> 0) {
1499 /* Avoid unbounded kernel memory allocation */
1500 if (crtc_req
->count_connectors
> config
->num_connector
) {
1505 connector_set
= kmalloc(crtc_req
->count_connectors
*
1506 sizeof(struct drm_connector
*),
1508 if (!connector_set
) {
1513 for (i
= 0; i
< crtc_req
->count_connectors
; i
++) {
1514 set_connectors_ptr
= (uint32_t *)(unsigned long)crtc_req
->set_connectors_ptr
;
1515 if (get_user(out_id
, &set_connectors_ptr
[i
])) {
1520 obj
= drm_mode_object_find(dev
, out_id
,
1521 DRM_MODE_OBJECT_CONNECTOR
);
1523 DRM_DEBUG_KMS("Connector id %d unknown\n",
1528 connector
= obj_to_connector(obj
);
1530 connector_set
[i
] = connector
;
1535 set
.x
= crtc_req
->x
;
1536 set
.y
= crtc_req
->y
;
1538 set
.connectors
= connector_set
;
1539 set
.num_connectors
= crtc_req
->count_connectors
;
1541 ret
= crtc
->funcs
->set_config(&set
);
1544 kfree(connector_set
);
1545 mutex_unlock(&dev
->mode_config
.mutex
);
1549 int drm_mode_cursor_ioctl(struct drm_device
*dev
,
1550 void *data
, struct drm_file
*file_priv
)
1552 struct drm_mode_cursor
*req
= data
;
1553 struct drm_mode_object
*obj
;
1554 struct drm_crtc
*crtc
;
1557 DRM_DEBUG_KMS("\n");
1560 DRM_ERROR("no operation set\n");
1564 mutex_lock(&dev
->mode_config
.mutex
);
1565 obj
= drm_mode_object_find(dev
, req
->crtc_id
, DRM_MODE_OBJECT_CRTC
);
1567 DRM_DEBUG_KMS("Unknown CRTC ID %d\n", req
->crtc_id
);
1571 crtc
= obj_to_crtc(obj
);
1573 if (req
->flags
& DRM_MODE_CURSOR_BO
) {
1574 if (!crtc
->funcs
->cursor_set
) {
1575 DRM_ERROR("crtc does not support cursor\n");
1579 /* Turns off the cursor if handle is 0 */
1580 ret
= crtc
->funcs
->cursor_set(crtc
, file_priv
, req
->handle
,
1581 req
->width
, req
->height
);
1584 if (req
->flags
& DRM_MODE_CURSOR_MOVE
) {
1585 if (crtc
->funcs
->cursor_move
) {
1586 ret
= crtc
->funcs
->cursor_move(crtc
, req
->x
, req
->y
);
1588 DRM_ERROR("crtc does not support cursor\n");
1594 mutex_unlock(&dev
->mode_config
.mutex
);
1599 * drm_mode_addfb - add an FB to the graphics configuration
1600 * @inode: inode from the ioctl
1601 * @filp: file * from the ioctl
1602 * @cmd: cmd from ioctl
1603 * @arg: arg from ioctl
1606 * Takes mode config lock.
1608 * Add a new FB to the specified CRTC, given a user request.
1610 * Called by the user via ioctl.
1613 * Zero on success, errno on failure.
1615 int drm_mode_addfb(struct drm_device
*dev
,
1616 void *data
, struct drm_file
*file_priv
)
1618 struct drm_mode_fb_cmd
*r
= data
;
1619 struct drm_mode_config
*config
= &dev
->mode_config
;
1620 struct drm_framebuffer
*fb
;
1623 if ((config
->min_width
> r
->width
) || (r
->width
> config
->max_width
)) {
1624 DRM_ERROR("mode new framebuffer width not within limits\n");
1627 if ((config
->min_height
> r
->height
) || (r
->height
> config
->max_height
)) {
1628 DRM_ERROR("mode new framebuffer height not within limits\n");
1632 mutex_lock(&dev
->mode_config
.mutex
);
1634 /* TODO check buffer is sufficently large */
1635 /* TODO setup destructor callback */
1637 fb
= dev
->mode_config
.funcs
->fb_create(dev
, file_priv
, r
);
1639 DRM_ERROR("could not create framebuffer\n");
1644 r
->fb_id
= fb
->base
.id
;
1645 list_add(&fb
->filp_head
, &file_priv
->fbs
);
1648 mutex_unlock(&dev
->mode_config
.mutex
);
1653 * drm_mode_rmfb - remove an FB from the configuration
1654 * @inode: inode from the ioctl
1655 * @filp: file * from the ioctl
1656 * @cmd: cmd from ioctl
1657 * @arg: arg from ioctl
1660 * Takes mode config lock.
1662 * Remove the FB specified by the user.
1664 * Called by the user via ioctl.
1667 * Zero on success, errno on failure.
1669 int drm_mode_rmfb(struct drm_device
*dev
,
1670 void *data
, struct drm_file
*file_priv
)
1672 struct drm_mode_object
*obj
;
1673 struct drm_framebuffer
*fb
= NULL
;
1674 struct drm_framebuffer
*fbl
= NULL
;
1675 uint32_t *id
= data
;
1679 mutex_lock(&dev
->mode_config
.mutex
);
1680 obj
= drm_mode_object_find(dev
, *id
, DRM_MODE_OBJECT_FB
);
1681 /* TODO check that we realy get a framebuffer back. */
1683 DRM_ERROR("mode invalid framebuffer id\n");
1687 fb
= obj_to_fb(obj
);
1689 list_for_each_entry(fbl
, &file_priv
->fbs
, filp_head
)
1694 DRM_ERROR("tried to remove a fb that we didn't own\n");
1699 /* TODO release all crtc connected to the framebuffer */
1700 /* TODO unhock the destructor from the buffer object */
1702 list_del(&fb
->filp_head
);
1703 fb
->funcs
->destroy(fb
);
1706 mutex_unlock(&dev
->mode_config
.mutex
);
1711 * drm_mode_getfb - get FB info
1712 * @inode: inode from the ioctl
1713 * @filp: file * from the ioctl
1714 * @cmd: cmd from ioctl
1715 * @arg: arg from ioctl
1720 * Lookup the FB given its ID and return info about it.
1722 * Called by the user via ioctl.
1725 * Zero on success, errno on failure.
1727 int drm_mode_getfb(struct drm_device
*dev
,
1728 void *data
, struct drm_file
*file_priv
)
1730 struct drm_mode_fb_cmd
*r
= data
;
1731 struct drm_mode_object
*obj
;
1732 struct drm_framebuffer
*fb
;
1735 mutex_lock(&dev
->mode_config
.mutex
);
1736 obj
= drm_mode_object_find(dev
, r
->fb_id
, DRM_MODE_OBJECT_FB
);
1738 DRM_ERROR("invalid framebuffer id\n");
1742 fb
= obj_to_fb(obj
);
1744 r
->height
= fb
->height
;
1745 r
->width
= fb
->width
;
1746 r
->depth
= fb
->depth
;
1747 r
->bpp
= fb
->bits_per_pixel
;
1748 r
->pitch
= fb
->pitch
;
1749 fb
->funcs
->create_handle(fb
, file_priv
, &r
->handle
);
1752 mutex_unlock(&dev
->mode_config
.mutex
);
1757 * drm_fb_release - remove and free the FBs on this file
1758 * @filp: file * from the ioctl
1761 * Takes mode config lock.
1763 * Destroy all the FBs associated with @filp.
1765 * Called by the user via ioctl.
1768 * Zero on success, errno on failure.
1770 void drm_fb_release(struct drm_file
*priv
)
1772 struct drm_device
*dev
= priv
->minor
->dev
;
1773 struct drm_framebuffer
*fb
, *tfb
;
1775 mutex_lock(&dev
->mode_config
.mutex
);
1776 list_for_each_entry_safe(fb
, tfb
, &priv
->fbs
, filp_head
) {
1777 list_del(&fb
->filp_head
);
1778 fb
->funcs
->destroy(fb
);
1780 mutex_unlock(&dev
->mode_config
.mutex
);
1784 * drm_mode_attachmode - add a mode to the user mode list
1786 * @connector: connector to add the mode to
1787 * @mode: mode to add
1789 * Add @mode to @connector's user mode list.
1791 static int drm_mode_attachmode(struct drm_device
*dev
,
1792 struct drm_connector
*connector
,
1793 struct drm_display_mode
*mode
)
1797 list_add_tail(&mode
->head
, &connector
->user_modes
);
1801 int drm_mode_attachmode_crtc(struct drm_device
*dev
, struct drm_crtc
*crtc
,
1802 struct drm_display_mode
*mode
)
1804 struct drm_connector
*connector
;
1806 struct drm_display_mode
*dup_mode
;
1808 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
, head
) {
1809 if (!connector
->encoder
)
1811 if (connector
->encoder
->crtc
== crtc
) {
1813 dup_mode
= drm_mode_duplicate(dev
, mode
);
1816 ret
= drm_mode_attachmode(dev
, connector
, dup_mode
);
1824 EXPORT_SYMBOL(drm_mode_attachmode_crtc
);
1826 static int drm_mode_detachmode(struct drm_device
*dev
,
1827 struct drm_connector
*connector
,
1828 struct drm_display_mode
*mode
)
1832 struct drm_display_mode
*match_mode
, *t
;
1834 list_for_each_entry_safe(match_mode
, t
, &connector
->user_modes
, head
) {
1835 if (drm_mode_equal(match_mode
, mode
)) {
1836 list_del(&match_mode
->head
);
1837 drm_mode_destroy(dev
, match_mode
);
1849 int drm_mode_detachmode_crtc(struct drm_device
*dev
, struct drm_display_mode
*mode
)
1851 struct drm_connector
*connector
;
1853 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
, head
) {
1854 drm_mode_detachmode(dev
, connector
, mode
);
1858 EXPORT_SYMBOL(drm_mode_detachmode_crtc
);
1861 * drm_fb_attachmode - Attach a user mode to an connector
1862 * @inode: inode from the ioctl
1863 * @filp: file * from the ioctl
1864 * @cmd: cmd from ioctl
1865 * @arg: arg from ioctl
1867 * This attaches a user specified mode to an connector.
1868 * Called by the user via ioctl.
1871 * Zero on success, errno on failure.
1873 int drm_mode_attachmode_ioctl(struct drm_device
*dev
,
1874 void *data
, struct drm_file
*file_priv
)
1876 struct drm_mode_mode_cmd
*mode_cmd
= data
;
1877 struct drm_connector
*connector
;
1878 struct drm_display_mode
*mode
;
1879 struct drm_mode_object
*obj
;
1880 struct drm_mode_modeinfo
*umode
= &mode_cmd
->mode
;
1883 mutex_lock(&dev
->mode_config
.mutex
);
1885 obj
= drm_mode_object_find(dev
, mode_cmd
->connector_id
, DRM_MODE_OBJECT_CONNECTOR
);
1890 connector
= obj_to_connector(obj
);
1892 mode
= drm_mode_create(dev
);
1898 drm_crtc_convert_umode(mode
, umode
);
1900 ret
= drm_mode_attachmode(dev
, connector
, mode
);
1902 mutex_unlock(&dev
->mode_config
.mutex
);
1908 * drm_fb_detachmode - Detach a user specified mode from an connector
1909 * @inode: inode from the ioctl
1910 * @filp: file * from the ioctl
1911 * @cmd: cmd from ioctl
1912 * @arg: arg from ioctl
1914 * Called by the user via ioctl.
1917 * Zero on success, errno on failure.
1919 int drm_mode_detachmode_ioctl(struct drm_device
*dev
,
1920 void *data
, struct drm_file
*file_priv
)
1922 struct drm_mode_object
*obj
;
1923 struct drm_mode_mode_cmd
*mode_cmd
= data
;
1924 struct drm_connector
*connector
;
1925 struct drm_display_mode mode
;
1926 struct drm_mode_modeinfo
*umode
= &mode_cmd
->mode
;
1929 mutex_lock(&dev
->mode_config
.mutex
);
1931 obj
= drm_mode_object_find(dev
, mode_cmd
->connector_id
, DRM_MODE_OBJECT_CONNECTOR
);
1936 connector
= obj_to_connector(obj
);
1938 drm_crtc_convert_umode(&mode
, umode
);
1939 ret
= drm_mode_detachmode(dev
, connector
, &mode
);
1941 mutex_unlock(&dev
->mode_config
.mutex
);
1945 struct drm_property
*drm_property_create(struct drm_device
*dev
, int flags
,
1946 const char *name
, int num_values
)
1948 struct drm_property
*property
= NULL
;
1950 property
= kzalloc(sizeof(struct drm_property
), GFP_KERNEL
);
1955 property
->values
= kzalloc(sizeof(uint64_t)*num_values
, GFP_KERNEL
);
1956 if (!property
->values
)
1960 drm_mode_object_get(dev
, &property
->base
, DRM_MODE_OBJECT_PROPERTY
);
1961 property
->flags
= flags
;
1962 property
->num_values
= num_values
;
1963 INIT_LIST_HEAD(&property
->enum_blob_list
);
1966 strncpy(property
->name
, name
, DRM_PROP_NAME_LEN
);
1968 list_add_tail(&property
->head
, &dev
->mode_config
.property_list
);
1974 EXPORT_SYMBOL(drm_property_create
);
1976 int drm_property_add_enum(struct drm_property
*property
, int index
,
1977 uint64_t value
, const char *name
)
1979 struct drm_property_enum
*prop_enum
;
1981 if (!(property
->flags
& DRM_MODE_PROP_ENUM
))
1984 if (!list_empty(&property
->enum_blob_list
)) {
1985 list_for_each_entry(prop_enum
, &property
->enum_blob_list
, head
) {
1986 if (prop_enum
->value
== value
) {
1987 strncpy(prop_enum
->name
, name
, DRM_PROP_NAME_LEN
);
1988 prop_enum
->name
[DRM_PROP_NAME_LEN
-1] = '\0';
1994 prop_enum
= kzalloc(sizeof(struct drm_property_enum
), GFP_KERNEL
);
1998 strncpy(prop_enum
->name
, name
, DRM_PROP_NAME_LEN
);
1999 prop_enum
->name
[DRM_PROP_NAME_LEN
-1] = '\0';
2000 prop_enum
->value
= value
;
2002 property
->values
[index
] = value
;
2003 list_add_tail(&prop_enum
->head
, &property
->enum_blob_list
);
2006 EXPORT_SYMBOL(drm_property_add_enum
);
2008 void drm_property_destroy(struct drm_device
*dev
, struct drm_property
*property
)
2010 struct drm_property_enum
*prop_enum
, *pt
;
2012 list_for_each_entry_safe(prop_enum
, pt
, &property
->enum_blob_list
, head
) {
2013 list_del(&prop_enum
->head
);
2017 if (property
->num_values
)
2018 kfree(property
->values
);
2019 drm_mode_object_put(dev
, &property
->base
);
2020 list_del(&property
->head
);
2023 EXPORT_SYMBOL(drm_property_destroy
);
2025 int drm_connector_attach_property(struct drm_connector
*connector
,
2026 struct drm_property
*property
, uint64_t init_val
)
2030 for (i
= 0; i
< DRM_CONNECTOR_MAX_PROPERTY
; i
++) {
2031 if (connector
->property_ids
[i
] == 0) {
2032 connector
->property_ids
[i
] = property
->base
.id
;
2033 connector
->property_values
[i
] = init_val
;
2038 if (i
== DRM_CONNECTOR_MAX_PROPERTY
)
2042 EXPORT_SYMBOL(drm_connector_attach_property
);
2044 int drm_connector_property_set_value(struct drm_connector
*connector
,
2045 struct drm_property
*property
, uint64_t value
)
2049 for (i
= 0; i
< DRM_CONNECTOR_MAX_PROPERTY
; i
++) {
2050 if (connector
->property_ids
[i
] == property
->base
.id
) {
2051 connector
->property_values
[i
] = value
;
2056 if (i
== DRM_CONNECTOR_MAX_PROPERTY
)
2060 EXPORT_SYMBOL(drm_connector_property_set_value
);
2062 int drm_connector_property_get_value(struct drm_connector
*connector
,
2063 struct drm_property
*property
, uint64_t *val
)
2067 for (i
= 0; i
< DRM_CONNECTOR_MAX_PROPERTY
; i
++) {
2068 if (connector
->property_ids
[i
] == property
->base
.id
) {
2069 *val
= connector
->property_values
[i
];
2074 if (i
== DRM_CONNECTOR_MAX_PROPERTY
)
2078 EXPORT_SYMBOL(drm_connector_property_get_value
);
2080 int drm_mode_getproperty_ioctl(struct drm_device
*dev
,
2081 void *data
, struct drm_file
*file_priv
)
2083 struct drm_mode_object
*obj
;
2084 struct drm_mode_get_property
*out_resp
= data
;
2085 struct drm_property
*property
;
2088 int value_count
= 0;
2091 struct drm_property_enum
*prop_enum
;
2092 struct drm_mode_property_enum __user
*enum_ptr
;
2093 struct drm_property_blob
*prop_blob
;
2094 uint32_t *blob_id_ptr
;
2095 uint64_t __user
*values_ptr
;
2096 uint32_t __user
*blob_length_ptr
;
2098 mutex_lock(&dev
->mode_config
.mutex
);
2099 obj
= drm_mode_object_find(dev
, out_resp
->prop_id
, DRM_MODE_OBJECT_PROPERTY
);
2104 property
= obj_to_property(obj
);
2106 if (property
->flags
& DRM_MODE_PROP_ENUM
) {
2107 list_for_each_entry(prop_enum
, &property
->enum_blob_list
, head
)
2109 } else if (property
->flags
& DRM_MODE_PROP_BLOB
) {
2110 list_for_each_entry(prop_blob
, &property
->enum_blob_list
, head
)
2114 value_count
= property
->num_values
;
2116 strncpy(out_resp
->name
, property
->name
, DRM_PROP_NAME_LEN
);
2117 out_resp
->name
[DRM_PROP_NAME_LEN
-1] = 0;
2118 out_resp
->flags
= property
->flags
;
2120 if ((out_resp
->count_values
>= value_count
) && value_count
) {
2121 values_ptr
= (uint64_t *)(unsigned long)out_resp
->values_ptr
;
2122 for (i
= 0; i
< value_count
; i
++) {
2123 if (copy_to_user(values_ptr
+ i
, &property
->values
[i
], sizeof(uint64_t))) {
2129 out_resp
->count_values
= value_count
;
2131 if (property
->flags
& DRM_MODE_PROP_ENUM
) {
2132 if ((out_resp
->count_enum_blobs
>= enum_count
) && enum_count
) {
2134 enum_ptr
= (struct drm_mode_property_enum
*)(unsigned long)out_resp
->enum_blob_ptr
;
2135 list_for_each_entry(prop_enum
, &property
->enum_blob_list
, head
) {
2137 if (copy_to_user(&enum_ptr
[copied
].value
, &prop_enum
->value
, sizeof(uint64_t))) {
2142 if (copy_to_user(&enum_ptr
[copied
].name
,
2143 &prop_enum
->name
, DRM_PROP_NAME_LEN
)) {
2150 out_resp
->count_enum_blobs
= enum_count
;
2153 if (property
->flags
& DRM_MODE_PROP_BLOB
) {
2154 if ((out_resp
->count_enum_blobs
>= blob_count
) && blob_count
) {
2156 blob_id_ptr
= (uint32_t *)(unsigned long)out_resp
->enum_blob_ptr
;
2157 blob_length_ptr
= (uint32_t *)(unsigned long)out_resp
->values_ptr
;
2159 list_for_each_entry(prop_blob
, &property
->enum_blob_list
, head
) {
2160 if (put_user(prop_blob
->base
.id
, blob_id_ptr
+ copied
)) {
2165 if (put_user(prop_blob
->length
, blob_length_ptr
+ copied
)) {
2173 out_resp
->count_enum_blobs
= blob_count
;
2176 mutex_unlock(&dev
->mode_config
.mutex
);
2180 static struct drm_property_blob
*drm_property_create_blob(struct drm_device
*dev
, int length
,
2183 struct drm_property_blob
*blob
;
2185 if (!length
|| !data
)
2188 blob
= kzalloc(sizeof(struct drm_property_blob
)+length
, GFP_KERNEL
);
2192 blob
->data
= (void *)((char *)blob
+ sizeof(struct drm_property_blob
));
2193 blob
->length
= length
;
2195 memcpy(blob
->data
, data
, length
);
2197 drm_mode_object_get(dev
, &blob
->base
, DRM_MODE_OBJECT_BLOB
);
2199 list_add_tail(&blob
->head
, &dev
->mode_config
.property_blob_list
);
2203 static void drm_property_destroy_blob(struct drm_device
*dev
,
2204 struct drm_property_blob
*blob
)
2206 drm_mode_object_put(dev
, &blob
->base
);
2207 list_del(&blob
->head
);
2211 int drm_mode_getblob_ioctl(struct drm_device
*dev
,
2212 void *data
, struct drm_file
*file_priv
)
2214 struct drm_mode_object
*obj
;
2215 struct drm_mode_get_blob
*out_resp
= data
;
2216 struct drm_property_blob
*blob
;
2220 mutex_lock(&dev
->mode_config
.mutex
);
2221 obj
= drm_mode_object_find(dev
, out_resp
->blob_id
, DRM_MODE_OBJECT_BLOB
);
2226 blob
= obj_to_blob(obj
);
2228 if (out_resp
->length
== blob
->length
) {
2229 blob_ptr
= (void *)(unsigned long)out_resp
->data
;
2230 if (copy_to_user(blob_ptr
, blob
->data
, blob
->length
)){
2235 out_resp
->length
= blob
->length
;
2238 mutex_unlock(&dev
->mode_config
.mutex
);
2242 int drm_mode_connector_update_edid_property(struct drm_connector
*connector
,
2245 struct drm_device
*dev
= connector
->dev
;
2248 if (connector
->edid_blob_ptr
)
2249 drm_property_destroy_blob(dev
, connector
->edid_blob_ptr
);
2251 /* Delete edid, when there is none. */
2253 connector
->edid_blob_ptr
= NULL
;
2254 ret
= drm_connector_property_set_value(connector
, dev
->mode_config
.edid_property
, 0);
2258 connector
->edid_blob_ptr
= drm_property_create_blob(connector
->dev
, 128, edid
);
2260 ret
= drm_connector_property_set_value(connector
,
2261 dev
->mode_config
.edid_property
,
2262 connector
->edid_blob_ptr
->base
.id
);
2266 EXPORT_SYMBOL(drm_mode_connector_update_edid_property
);
2268 int drm_mode_connector_property_set_ioctl(struct drm_device
*dev
,
2269 void *data
, struct drm_file
*file_priv
)
2271 struct drm_mode_connector_set_property
*out_resp
= data
;
2272 struct drm_mode_object
*obj
;
2273 struct drm_property
*property
;
2274 struct drm_connector
*connector
;
2278 mutex_lock(&dev
->mode_config
.mutex
);
2280 obj
= drm_mode_object_find(dev
, out_resp
->connector_id
, DRM_MODE_OBJECT_CONNECTOR
);
2284 connector
= obj_to_connector(obj
);
2286 for (i
= 0; i
< DRM_CONNECTOR_MAX_PROPERTY
; i
++) {
2287 if (connector
->property_ids
[i
] == out_resp
->prop_id
)
2291 if (i
== DRM_CONNECTOR_MAX_PROPERTY
) {
2295 obj
= drm_mode_object_find(dev
, out_resp
->prop_id
, DRM_MODE_OBJECT_PROPERTY
);
2299 property
= obj_to_property(obj
);
2301 if (property
->flags
& DRM_MODE_PROP_IMMUTABLE
)
2304 if (property
->flags
& DRM_MODE_PROP_RANGE
) {
2305 if (out_resp
->value
< property
->values
[0])
2308 if (out_resp
->value
> property
->values
[1])
2312 for (i
= 0; i
< property
->num_values
; i
++) {
2313 if (property
->values
[i
] == out_resp
->value
) {
2323 /* Do DPMS ourselves */
2324 if (property
== connector
->dev
->mode_config
.dpms_property
) {
2325 if (connector
->funcs
->dpms
)
2326 (*connector
->funcs
->dpms
)(connector
, (int) out_resp
->value
);
2328 } else if (connector
->funcs
->set_property
)
2329 ret
= connector
->funcs
->set_property(connector
, property
, out_resp
->value
);
2331 /* store the property value if succesful */
2333 drm_connector_property_set_value(connector
, property
, out_resp
->value
);
2335 mutex_unlock(&dev
->mode_config
.mutex
);
2339 int drm_mode_connector_attach_encoder(struct drm_connector
*connector
,
2340 struct drm_encoder
*encoder
)
2344 for (i
= 0; i
< DRM_CONNECTOR_MAX_ENCODER
; i
++) {
2345 if (connector
->encoder_ids
[i
] == 0) {
2346 connector
->encoder_ids
[i
] = encoder
->base
.id
;
2352 EXPORT_SYMBOL(drm_mode_connector_attach_encoder
);
2354 void drm_mode_connector_detach_encoder(struct drm_connector
*connector
,
2355 struct drm_encoder
*encoder
)
2358 for (i
= 0; i
< DRM_CONNECTOR_MAX_ENCODER
; i
++) {
2359 if (connector
->encoder_ids
[i
] == encoder
->base
.id
) {
2360 connector
->encoder_ids
[i
] = 0;
2361 if (connector
->encoder
== encoder
)
2362 connector
->encoder
= NULL
;
2367 EXPORT_SYMBOL(drm_mode_connector_detach_encoder
);
2369 bool drm_mode_crtc_set_gamma_size(struct drm_crtc
*crtc
,
2372 crtc
->gamma_size
= gamma_size
;
2374 crtc
->gamma_store
= kzalloc(gamma_size
* sizeof(uint16_t) * 3, GFP_KERNEL
);
2375 if (!crtc
->gamma_store
) {
2376 crtc
->gamma_size
= 0;
2382 EXPORT_SYMBOL(drm_mode_crtc_set_gamma_size
);
2384 int drm_mode_gamma_set_ioctl(struct drm_device
*dev
,
2385 void *data
, struct drm_file
*file_priv
)
2387 struct drm_mode_crtc_lut
*crtc_lut
= data
;
2388 struct drm_mode_object
*obj
;
2389 struct drm_crtc
*crtc
;
2390 void *r_base
, *g_base
, *b_base
;
2394 mutex_lock(&dev
->mode_config
.mutex
);
2395 obj
= drm_mode_object_find(dev
, crtc_lut
->crtc_id
, DRM_MODE_OBJECT_CRTC
);
2400 crtc
= obj_to_crtc(obj
);
2402 /* memcpy into gamma store */
2403 if (crtc_lut
->gamma_size
!= crtc
->gamma_size
) {
2408 size
= crtc_lut
->gamma_size
* (sizeof(uint16_t));
2409 r_base
= crtc
->gamma_store
;
2410 if (copy_from_user(r_base
, (void __user
*)(unsigned long)crtc_lut
->red
, size
)) {
2415 g_base
= r_base
+ size
;
2416 if (copy_from_user(g_base
, (void __user
*)(unsigned long)crtc_lut
->green
, size
)) {
2421 b_base
= g_base
+ size
;
2422 if (copy_from_user(b_base
, (void __user
*)(unsigned long)crtc_lut
->blue
, size
)) {
2427 crtc
->funcs
->gamma_set(crtc
, r_base
, g_base
, b_base
, crtc
->gamma_size
);
2430 mutex_unlock(&dev
->mode_config
.mutex
);
2435 int drm_mode_gamma_get_ioctl(struct drm_device
*dev
,
2436 void *data
, struct drm_file
*file_priv
)
2438 struct drm_mode_crtc_lut
*crtc_lut
= data
;
2439 struct drm_mode_object
*obj
;
2440 struct drm_crtc
*crtc
;
2441 void *r_base
, *g_base
, *b_base
;
2445 mutex_lock(&dev
->mode_config
.mutex
);
2446 obj
= drm_mode_object_find(dev
, crtc_lut
->crtc_id
, DRM_MODE_OBJECT_CRTC
);
2451 crtc
= obj_to_crtc(obj
);
2453 /* memcpy into gamma store */
2454 if (crtc_lut
->gamma_size
!= crtc
->gamma_size
) {
2459 size
= crtc_lut
->gamma_size
* (sizeof(uint16_t));
2460 r_base
= crtc
->gamma_store
;
2461 if (copy_to_user((void __user
*)(unsigned long)crtc_lut
->red
, r_base
, size
)) {
2466 g_base
= r_base
+ size
;
2467 if (copy_to_user((void __user
*)(unsigned long)crtc_lut
->green
, g_base
, size
)) {
2472 b_base
= g_base
+ size
;
2473 if (copy_to_user((void __user
*)(unsigned long)crtc_lut
->blue
, b_base
, size
)) {
2478 mutex_unlock(&dev
->mode_config
.mutex
);