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_NON_GPU
, "Non-GPU" },
72 { DRM_MODE_SCALE_FULLSCREEN
, "Fullscreen" },
73 { DRM_MODE_SCALE_NO_SCALE
, "No scale" },
74 { DRM_MODE_SCALE_ASPECT
, "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_crtc_from_fb - find the CRTC structure associated with an fb
266 * @fb: framebuffer in question
269 * Caller must hold mode_config lock.
271 * Find CRTC in the mode_config structure that matches @fb.
274 * Pointer to the CRTC or NULL if it wasn't found.
276 struct drm_crtc
*drm_crtc_from_fb(struct drm_device
*dev
,
277 struct drm_framebuffer
*fb
)
279 struct drm_crtc
*crtc
;
281 list_for_each_entry(crtc
, &dev
->mode_config
.crtc_list
, head
) {
289 * drm_framebuffer_init - initialize a framebuffer
293 * Caller must hold mode config lock.
295 * Allocates an ID for the framebuffer's parent mode object, sets its mode
296 * functions & device file and adds it to the master fd list.
299 * Zero on success, error code on falure.
301 int drm_framebuffer_init(struct drm_device
*dev
, struct drm_framebuffer
*fb
,
302 const struct drm_framebuffer_funcs
*funcs
)
306 ret
= drm_mode_object_get(dev
, &fb
->base
, DRM_MODE_OBJECT_FB
);
313 dev
->mode_config
.num_fb
++;
314 list_add(&fb
->head
, &dev
->mode_config
.fb_list
);
318 EXPORT_SYMBOL(drm_framebuffer_init
);
321 * drm_framebuffer_cleanup - remove a framebuffer object
322 * @fb: framebuffer to remove
325 * Caller must hold mode config lock.
327 * Scans all the CRTCs in @dev's mode_config. If they're using @fb, removes
328 * it, setting it to NULL.
330 void drm_framebuffer_cleanup(struct drm_framebuffer
*fb
)
332 struct drm_device
*dev
= fb
->dev
;
333 struct drm_crtc
*crtc
;
335 /* remove from any CRTC */
336 list_for_each_entry(crtc
, &dev
->mode_config
.crtc_list
, head
) {
341 drm_mode_object_put(dev
, &fb
->base
);
343 dev
->mode_config
.num_fb
--;
345 EXPORT_SYMBOL(drm_framebuffer_cleanup
);
348 * drm_crtc_init - Initialise a new CRTC object
350 * @crtc: CRTC object to init
351 * @funcs: callbacks for the new CRTC
354 * Caller must hold mode config lock.
356 * Inits a new object created as base part of an driver crtc object.
358 void drm_crtc_init(struct drm_device
*dev
, struct drm_crtc
*crtc
,
359 const struct drm_crtc_funcs
*funcs
)
364 mutex_lock(&dev
->mode_config
.mutex
);
365 drm_mode_object_get(dev
, &crtc
->base
, DRM_MODE_OBJECT_CRTC
);
367 list_add_tail(&crtc
->head
, &dev
->mode_config
.crtc_list
);
368 dev
->mode_config
.num_crtc
++;
369 mutex_unlock(&dev
->mode_config
.mutex
);
371 EXPORT_SYMBOL(drm_crtc_init
);
374 * drm_crtc_cleanup - Cleans up the core crtc usage.
375 * @crtc: CRTC to cleanup
378 * Caller must hold mode config lock.
380 * Cleanup @crtc. Removes from drm modesetting space
381 * does NOT free object, caller does that.
383 void drm_crtc_cleanup(struct drm_crtc
*crtc
)
385 struct drm_device
*dev
= crtc
->dev
;
387 if (crtc
->gamma_store
) {
388 kfree(crtc
->gamma_store
);
389 crtc
->gamma_store
= NULL
;
392 drm_mode_object_put(dev
, &crtc
->base
);
393 list_del(&crtc
->head
);
394 dev
->mode_config
.num_crtc
--;
396 EXPORT_SYMBOL(drm_crtc_cleanup
);
399 * drm_mode_probed_add - add a mode to a connector's probed mode list
400 * @connector: connector the new mode
404 * Caller must hold mode config lock.
406 * Add @mode to @connector's mode list for later use.
408 void drm_mode_probed_add(struct drm_connector
*connector
,
409 struct drm_display_mode
*mode
)
411 list_add(&mode
->head
, &connector
->probed_modes
);
413 EXPORT_SYMBOL(drm_mode_probed_add
);
416 * drm_mode_remove - remove and free a mode
417 * @connector: connector list to modify
418 * @mode: mode to remove
421 * Caller must hold mode config lock.
423 * Remove @mode from @connector's mode list, then free it.
425 void drm_mode_remove(struct drm_connector
*connector
,
426 struct drm_display_mode
*mode
)
428 list_del(&mode
->head
);
431 EXPORT_SYMBOL(drm_mode_remove
);
434 * drm_connector_init - Init a preallocated connector
436 * @connector: the connector to init
437 * @funcs: callbacks for this connector
438 * @name: user visible name of the connector
441 * Caller must hold @dev's mode_config lock.
443 * Initialises a preallocated connector. Connectors should be
444 * subclassed as part of driver connector objects.
446 void drm_connector_init(struct drm_device
*dev
,
447 struct drm_connector
*connector
,
448 const struct drm_connector_funcs
*funcs
,
451 mutex_lock(&dev
->mode_config
.mutex
);
453 connector
->dev
= dev
;
454 connector
->funcs
= funcs
;
455 drm_mode_object_get(dev
, &connector
->base
, DRM_MODE_OBJECT_CONNECTOR
);
456 connector
->connector_type
= connector_type
;
457 connector
->connector_type_id
=
458 ++drm_connector_enum_list
[connector_type
].count
; /* TODO */
459 INIT_LIST_HEAD(&connector
->user_modes
);
460 INIT_LIST_HEAD(&connector
->probed_modes
);
461 INIT_LIST_HEAD(&connector
->modes
);
462 connector
->edid_blob_ptr
= NULL
;
464 list_add_tail(&connector
->head
, &dev
->mode_config
.connector_list
);
465 dev
->mode_config
.num_connector
++;
467 drm_connector_attach_property(connector
,
468 dev
->mode_config
.edid_property
, 0);
470 drm_connector_attach_property(connector
,
471 dev
->mode_config
.dpms_property
, 0);
473 mutex_unlock(&dev
->mode_config
.mutex
);
475 EXPORT_SYMBOL(drm_connector_init
);
478 * drm_connector_cleanup - cleans up an initialised connector
479 * @connector: connector to cleanup
482 * Caller must hold @dev's mode_config lock.
484 * Cleans up the connector but doesn't free the object.
486 void drm_connector_cleanup(struct drm_connector
*connector
)
488 struct drm_device
*dev
= connector
->dev
;
489 struct drm_display_mode
*mode
, *t
;
491 list_for_each_entry_safe(mode
, t
, &connector
->probed_modes
, head
)
492 drm_mode_remove(connector
, mode
);
494 list_for_each_entry_safe(mode
, t
, &connector
->modes
, head
)
495 drm_mode_remove(connector
, mode
);
497 list_for_each_entry_safe(mode
, t
, &connector
->user_modes
, head
)
498 drm_mode_remove(connector
, mode
);
500 mutex_lock(&dev
->mode_config
.mutex
);
501 drm_mode_object_put(dev
, &connector
->base
);
502 list_del(&connector
->head
);
503 mutex_unlock(&dev
->mode_config
.mutex
);
505 EXPORT_SYMBOL(drm_connector_cleanup
);
507 void drm_encoder_init(struct drm_device
*dev
,
508 struct drm_encoder
*encoder
,
509 const struct drm_encoder_funcs
*funcs
,
512 mutex_lock(&dev
->mode_config
.mutex
);
516 drm_mode_object_get(dev
, &encoder
->base
, DRM_MODE_OBJECT_ENCODER
);
517 encoder
->encoder_type
= encoder_type
;
518 encoder
->funcs
= funcs
;
520 list_add_tail(&encoder
->head
, &dev
->mode_config
.encoder_list
);
521 dev
->mode_config
.num_encoder
++;
523 mutex_unlock(&dev
->mode_config
.mutex
);
525 EXPORT_SYMBOL(drm_encoder_init
);
527 void drm_encoder_cleanup(struct drm_encoder
*encoder
)
529 struct drm_device
*dev
= encoder
->dev
;
530 mutex_lock(&dev
->mode_config
.mutex
);
531 drm_mode_object_put(dev
, &encoder
->base
);
532 list_del(&encoder
->head
);
533 mutex_unlock(&dev
->mode_config
.mutex
);
535 EXPORT_SYMBOL(drm_encoder_cleanup
);
538 * drm_mode_create - create a new display mode
542 * Caller must hold DRM mode_config lock.
544 * Create a new drm_display_mode, give it an ID, and return it.
547 * Pointer to new mode on success, NULL on error.
549 struct drm_display_mode
*drm_mode_create(struct drm_device
*dev
)
551 struct drm_display_mode
*nmode
;
553 nmode
= kzalloc(sizeof(struct drm_display_mode
), GFP_KERNEL
);
557 drm_mode_object_get(dev
, &nmode
->base
, DRM_MODE_OBJECT_MODE
);
560 EXPORT_SYMBOL(drm_mode_create
);
563 * drm_mode_destroy - remove a mode
565 * @mode: mode to remove
568 * Caller must hold mode config lock.
570 * Free @mode's unique identifier, then free it.
572 void drm_mode_destroy(struct drm_device
*dev
, struct drm_display_mode
*mode
)
574 drm_mode_object_put(dev
, &mode
->base
);
578 EXPORT_SYMBOL(drm_mode_destroy
);
580 static int drm_mode_create_standard_connector_properties(struct drm_device
*dev
)
582 struct drm_property
*edid
;
583 struct drm_property
*dpms
;
587 * Standard properties (apply to all connectors)
589 edid
= drm_property_create(dev
, DRM_MODE_PROP_BLOB
|
590 DRM_MODE_PROP_IMMUTABLE
,
592 dev
->mode_config
.edid_property
= edid
;
594 dpms
= drm_property_create(dev
, DRM_MODE_PROP_ENUM
,
595 "DPMS", ARRAY_SIZE(drm_dpms_enum_list
));
596 for (i
= 0; i
< ARRAY_SIZE(drm_dpms_enum_list
); i
++)
597 drm_property_add_enum(dpms
, i
, drm_dpms_enum_list
[i
].type
,
598 drm_dpms_enum_list
[i
].name
);
599 dev
->mode_config
.dpms_property
= dpms
;
605 * drm_mode_create_dvi_i_properties - create DVI-I specific connector properties
608 * Called by a driver the first time a DVI-I connector is made.
610 int drm_mode_create_dvi_i_properties(struct drm_device
*dev
)
612 struct drm_property
*dvi_i_selector
;
613 struct drm_property
*dvi_i_subconnector
;
616 if (dev
->mode_config
.dvi_i_select_subconnector_property
)
620 drm_property_create(dev
, DRM_MODE_PROP_ENUM
,
621 "select subconnector",
622 ARRAY_SIZE(drm_dvi_i_select_enum_list
));
623 for (i
= 0; i
< ARRAY_SIZE(drm_dvi_i_select_enum_list
); i
++)
624 drm_property_add_enum(dvi_i_selector
, i
,
625 drm_dvi_i_select_enum_list
[i
].type
,
626 drm_dvi_i_select_enum_list
[i
].name
);
627 dev
->mode_config
.dvi_i_select_subconnector_property
= dvi_i_selector
;
630 drm_property_create(dev
, DRM_MODE_PROP_ENUM
|
631 DRM_MODE_PROP_IMMUTABLE
,
633 ARRAY_SIZE(drm_dvi_i_subconnector_enum_list
));
634 for (i
= 0; i
< ARRAY_SIZE(drm_dvi_i_subconnector_enum_list
); i
++)
635 drm_property_add_enum(dvi_i_subconnector
, i
,
636 drm_dvi_i_subconnector_enum_list
[i
].type
,
637 drm_dvi_i_subconnector_enum_list
[i
].name
);
638 dev
->mode_config
.dvi_i_subconnector_property
= dvi_i_subconnector
;
642 EXPORT_SYMBOL(drm_mode_create_dvi_i_properties
);
645 * drm_create_tv_properties - create TV specific connector properties
647 * @num_modes: number of different TV formats (modes) supported
648 * @modes: array of pointers to strings containing name of each format
650 * Called by a driver's TV initialization routine, this function creates
651 * the TV specific connector properties for a given device. Caller is
652 * responsible for allocating a list of format names and passing them to
655 int drm_mode_create_tv_properties(struct drm_device
*dev
, int num_modes
,
658 struct drm_property
*tv_selector
;
659 struct drm_property
*tv_subconnector
;
662 if (dev
->mode_config
.tv_select_subconnector_property
)
666 * Basic connector properties
668 tv_selector
= drm_property_create(dev
, DRM_MODE_PROP_ENUM
,
669 "select subconnector",
670 ARRAY_SIZE(drm_tv_select_enum_list
));
671 for (i
= 0; i
< ARRAY_SIZE(drm_tv_select_enum_list
); i
++)
672 drm_property_add_enum(tv_selector
, i
,
673 drm_tv_select_enum_list
[i
].type
,
674 drm_tv_select_enum_list
[i
].name
);
675 dev
->mode_config
.tv_select_subconnector_property
= tv_selector
;
678 drm_property_create(dev
, DRM_MODE_PROP_ENUM
|
679 DRM_MODE_PROP_IMMUTABLE
, "subconnector",
680 ARRAY_SIZE(drm_tv_subconnector_enum_list
));
681 for (i
= 0; i
< ARRAY_SIZE(drm_tv_subconnector_enum_list
); i
++)
682 drm_property_add_enum(tv_subconnector
, i
,
683 drm_tv_subconnector_enum_list
[i
].type
,
684 drm_tv_subconnector_enum_list
[i
].name
);
685 dev
->mode_config
.tv_subconnector_property
= tv_subconnector
;
688 * Other, TV specific properties: margins & TV modes.
690 dev
->mode_config
.tv_left_margin_property
=
691 drm_property_create(dev
, DRM_MODE_PROP_RANGE
,
693 dev
->mode_config
.tv_left_margin_property
->values
[0] = 0;
694 dev
->mode_config
.tv_left_margin_property
->values
[1] = 100;
696 dev
->mode_config
.tv_right_margin_property
=
697 drm_property_create(dev
, DRM_MODE_PROP_RANGE
,
699 dev
->mode_config
.tv_right_margin_property
->values
[0] = 0;
700 dev
->mode_config
.tv_right_margin_property
->values
[1] = 100;
702 dev
->mode_config
.tv_top_margin_property
=
703 drm_property_create(dev
, DRM_MODE_PROP_RANGE
,
705 dev
->mode_config
.tv_top_margin_property
->values
[0] = 0;
706 dev
->mode_config
.tv_top_margin_property
->values
[1] = 100;
708 dev
->mode_config
.tv_bottom_margin_property
=
709 drm_property_create(dev
, DRM_MODE_PROP_RANGE
,
711 dev
->mode_config
.tv_bottom_margin_property
->values
[0] = 0;
712 dev
->mode_config
.tv_bottom_margin_property
->values
[1] = 100;
714 dev
->mode_config
.tv_mode_property
=
715 drm_property_create(dev
, DRM_MODE_PROP_ENUM
,
717 for (i
= 0; i
< num_modes
; i
++)
718 drm_property_add_enum(dev
->mode_config
.tv_mode_property
, i
,
721 dev
->mode_config
.tv_brightness_property
=
722 drm_property_create(dev
, DRM_MODE_PROP_RANGE
,
724 dev
->mode_config
.tv_brightness_property
->values
[0] = 0;
725 dev
->mode_config
.tv_brightness_property
->values
[1] = 100;
727 dev
->mode_config
.tv_contrast_property
=
728 drm_property_create(dev
, DRM_MODE_PROP_RANGE
,
730 dev
->mode_config
.tv_contrast_property
->values
[0] = 0;
731 dev
->mode_config
.tv_contrast_property
->values
[1] = 100;
733 dev
->mode_config
.tv_flicker_reduction_property
=
734 drm_property_create(dev
, DRM_MODE_PROP_RANGE
,
735 "flicker reduction", 2);
736 dev
->mode_config
.tv_flicker_reduction_property
->values
[0] = 0;
737 dev
->mode_config
.tv_flicker_reduction_property
->values
[1] = 100;
739 dev
->mode_config
.tv_overscan_property
=
740 drm_property_create(dev
, DRM_MODE_PROP_RANGE
,
742 dev
->mode_config
.tv_overscan_property
->values
[0] = 0;
743 dev
->mode_config
.tv_overscan_property
->values
[1] = 100;
745 dev
->mode_config
.tv_saturation_property
=
746 drm_property_create(dev
, DRM_MODE_PROP_RANGE
,
748 dev
->mode_config
.tv_saturation_property
->values
[0] = 0;
749 dev
->mode_config
.tv_saturation_property
->values
[1] = 100;
751 dev
->mode_config
.tv_hue_property
=
752 drm_property_create(dev
, DRM_MODE_PROP_RANGE
,
754 dev
->mode_config
.tv_hue_property
->values
[0] = 0;
755 dev
->mode_config
.tv_hue_property
->values
[1] = 100;
759 EXPORT_SYMBOL(drm_mode_create_tv_properties
);
762 * drm_mode_create_scaling_mode_property - create scaling mode property
765 * Called by a driver the first time it's needed, must be attached to desired
768 int drm_mode_create_scaling_mode_property(struct drm_device
*dev
)
770 struct drm_property
*scaling_mode
;
773 if (dev
->mode_config
.scaling_mode_property
)
777 drm_property_create(dev
, DRM_MODE_PROP_ENUM
, "scaling mode",
778 ARRAY_SIZE(drm_scaling_mode_enum_list
));
779 for (i
= 0; i
< ARRAY_SIZE(drm_scaling_mode_enum_list
); i
++)
780 drm_property_add_enum(scaling_mode
, i
,
781 drm_scaling_mode_enum_list
[i
].type
,
782 drm_scaling_mode_enum_list
[i
].name
);
784 dev
->mode_config
.scaling_mode_property
= scaling_mode
;
788 EXPORT_SYMBOL(drm_mode_create_scaling_mode_property
);
791 * drm_mode_create_dithering_property - create dithering property
794 * Called by a driver the first time it's needed, must be attached to desired
797 int drm_mode_create_dithering_property(struct drm_device
*dev
)
799 struct drm_property
*dithering_mode
;
802 if (dev
->mode_config
.dithering_mode_property
)
806 drm_property_create(dev
, DRM_MODE_PROP_ENUM
, "dithering",
807 ARRAY_SIZE(drm_dithering_mode_enum_list
));
808 for (i
= 0; i
< ARRAY_SIZE(drm_dithering_mode_enum_list
); i
++)
809 drm_property_add_enum(dithering_mode
, i
,
810 drm_dithering_mode_enum_list
[i
].type
,
811 drm_dithering_mode_enum_list
[i
].name
);
812 dev
->mode_config
.dithering_mode_property
= dithering_mode
;
816 EXPORT_SYMBOL(drm_mode_create_dithering_property
);
819 * drm_mode_config_init - initialize DRM mode_configuration structure
823 * None, should happen single threaded at init time.
825 * Initialize @dev's mode_config structure, used for tracking the graphics
826 * configuration of @dev.
828 void drm_mode_config_init(struct drm_device
*dev
)
830 mutex_init(&dev
->mode_config
.mutex
);
831 mutex_init(&dev
->mode_config
.idr_mutex
);
832 INIT_LIST_HEAD(&dev
->mode_config
.fb_list
);
833 INIT_LIST_HEAD(&dev
->mode_config
.fb_kernel_list
);
834 INIT_LIST_HEAD(&dev
->mode_config
.crtc_list
);
835 INIT_LIST_HEAD(&dev
->mode_config
.connector_list
);
836 INIT_LIST_HEAD(&dev
->mode_config
.encoder_list
);
837 INIT_LIST_HEAD(&dev
->mode_config
.property_list
);
838 INIT_LIST_HEAD(&dev
->mode_config
.property_blob_list
);
839 idr_init(&dev
->mode_config
.crtc_idr
);
841 mutex_lock(&dev
->mode_config
.mutex
);
842 drm_mode_create_standard_connector_properties(dev
);
843 mutex_unlock(&dev
->mode_config
.mutex
);
845 /* Just to be sure */
846 dev
->mode_config
.num_fb
= 0;
847 dev
->mode_config
.num_connector
= 0;
848 dev
->mode_config
.num_crtc
= 0;
849 dev
->mode_config
.num_encoder
= 0;
851 EXPORT_SYMBOL(drm_mode_config_init
);
853 int drm_mode_group_init(struct drm_device
*dev
, struct drm_mode_group
*group
)
855 uint32_t total_objects
= 0;
857 total_objects
+= dev
->mode_config
.num_crtc
;
858 total_objects
+= dev
->mode_config
.num_connector
;
859 total_objects
+= dev
->mode_config
.num_encoder
;
861 if (total_objects
== 0)
864 group
->id_list
= kzalloc(total_objects
* sizeof(uint32_t), GFP_KERNEL
);
868 group
->num_crtcs
= 0;
869 group
->num_connectors
= 0;
870 group
->num_encoders
= 0;
874 int drm_mode_group_init_legacy_group(struct drm_device
*dev
,
875 struct drm_mode_group
*group
)
877 struct drm_crtc
*crtc
;
878 struct drm_encoder
*encoder
;
879 struct drm_connector
*connector
;
882 if ((ret
= drm_mode_group_init(dev
, group
)))
885 list_for_each_entry(crtc
, &dev
->mode_config
.crtc_list
, head
)
886 group
->id_list
[group
->num_crtcs
++] = crtc
->base
.id
;
888 list_for_each_entry(encoder
, &dev
->mode_config
.encoder_list
, head
)
889 group
->id_list
[group
->num_crtcs
+ group
->num_encoders
++] =
892 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
, head
)
893 group
->id_list
[group
->num_crtcs
+ group
->num_encoders
+
894 group
->num_connectors
++] = connector
->base
.id
;
900 * drm_mode_config_cleanup - free up DRM mode_config info
904 * Caller must hold mode config lock.
906 * Free up all the connectors and CRTCs associated with this DRM device, then
907 * free up the framebuffers and associated buffer objects.
909 * FIXME: cleanup any dangling user buffer objects too
911 void drm_mode_config_cleanup(struct drm_device
*dev
)
913 struct drm_connector
*connector
, *ot
;
914 struct drm_crtc
*crtc
, *ct
;
915 struct drm_encoder
*encoder
, *enct
;
916 struct drm_framebuffer
*fb
, *fbt
;
917 struct drm_property
*property
, *pt
;
919 list_for_each_entry_safe(encoder
, enct
, &dev
->mode_config
.encoder_list
,
921 encoder
->funcs
->destroy(encoder
);
924 list_for_each_entry_safe(connector
, ot
,
925 &dev
->mode_config
.connector_list
, head
) {
926 connector
->funcs
->destroy(connector
);
929 list_for_each_entry_safe(property
, pt
, &dev
->mode_config
.property_list
,
931 drm_property_destroy(dev
, property
);
934 list_for_each_entry_safe(fb
, fbt
, &dev
->mode_config
.fb_list
, head
) {
935 fb
->funcs
->destroy(fb
);
938 list_for_each_entry_safe(crtc
, ct
, &dev
->mode_config
.crtc_list
, head
) {
939 crtc
->funcs
->destroy(crtc
);
943 EXPORT_SYMBOL(drm_mode_config_cleanup
);
946 * drm_crtc_convert_to_umode - convert a drm_display_mode into a modeinfo
947 * @out: drm_mode_modeinfo struct to return to the user
948 * @in: drm_display_mode to use
953 * Convert a drm_display_mode into a drm_mode_modeinfo structure to return to
956 void drm_crtc_convert_to_umode(struct drm_mode_modeinfo
*out
,
957 struct drm_display_mode
*in
)
959 out
->clock
= in
->clock
;
960 out
->hdisplay
= in
->hdisplay
;
961 out
->hsync_start
= in
->hsync_start
;
962 out
->hsync_end
= in
->hsync_end
;
963 out
->htotal
= in
->htotal
;
964 out
->hskew
= in
->hskew
;
965 out
->vdisplay
= in
->vdisplay
;
966 out
->vsync_start
= in
->vsync_start
;
967 out
->vsync_end
= in
->vsync_end
;
968 out
->vtotal
= in
->vtotal
;
969 out
->vscan
= in
->vscan
;
970 out
->vrefresh
= in
->vrefresh
;
971 out
->flags
= in
->flags
;
972 out
->type
= in
->type
;
973 strncpy(out
->name
, in
->name
, DRM_DISPLAY_MODE_LEN
);
974 out
->name
[DRM_DISPLAY_MODE_LEN
-1] = 0;
978 * drm_crtc_convert_to_umode - convert a modeinfo into a drm_display_mode
979 * @out: drm_display_mode to return to the user
980 * @in: drm_mode_modeinfo to use
985 * Convert a drm_mode_modeinfo into a drm_display_mode structure to return to
988 void drm_crtc_convert_umode(struct drm_display_mode
*out
,
989 struct drm_mode_modeinfo
*in
)
991 out
->clock
= in
->clock
;
992 out
->hdisplay
= in
->hdisplay
;
993 out
->hsync_start
= in
->hsync_start
;
994 out
->hsync_end
= in
->hsync_end
;
995 out
->htotal
= in
->htotal
;
996 out
->hskew
= in
->hskew
;
997 out
->vdisplay
= in
->vdisplay
;
998 out
->vsync_start
= in
->vsync_start
;
999 out
->vsync_end
= in
->vsync_end
;
1000 out
->vtotal
= in
->vtotal
;
1001 out
->vscan
= in
->vscan
;
1002 out
->vrefresh
= in
->vrefresh
;
1003 out
->flags
= in
->flags
;
1004 out
->type
= in
->type
;
1005 strncpy(out
->name
, in
->name
, DRM_DISPLAY_MODE_LEN
);
1006 out
->name
[DRM_DISPLAY_MODE_LEN
-1] = 0;
1010 * drm_mode_getresources - get graphics configuration
1011 * @inode: inode from the ioctl
1012 * @filp: file * from the ioctl
1013 * @cmd: cmd from ioctl
1014 * @arg: arg from ioctl
1017 * Takes mode config lock.
1019 * Construct a set of configuration description structures and return
1020 * them to the user, including CRTC, connector and framebuffer configuration.
1022 * Called by the user via ioctl.
1025 * Zero on success, errno on failure.
1027 int drm_mode_getresources(struct drm_device
*dev
, void *data
,
1028 struct drm_file
*file_priv
)
1030 struct drm_mode_card_res
*card_res
= data
;
1031 struct list_head
*lh
;
1032 struct drm_framebuffer
*fb
;
1033 struct drm_connector
*connector
;
1034 struct drm_crtc
*crtc
;
1035 struct drm_encoder
*encoder
;
1037 int connector_count
= 0;
1040 int encoder_count
= 0;
1042 uint32_t __user
*fb_id
;
1043 uint32_t __user
*crtc_id
;
1044 uint32_t __user
*connector_id
;
1045 uint32_t __user
*encoder_id
;
1046 struct drm_mode_group
*mode_group
;
1048 mutex_lock(&dev
->mode_config
.mutex
);
1051 * For the non-control nodes we need to limit the list of resources
1052 * by IDs in the group list for this node
1054 list_for_each(lh
, &file_priv
->fbs
)
1057 mode_group
= &file_priv
->master
->minor
->mode_group
;
1058 if (file_priv
->master
->minor
->type
== DRM_MINOR_CONTROL
) {
1060 list_for_each(lh
, &dev
->mode_config
.crtc_list
)
1063 list_for_each(lh
, &dev
->mode_config
.connector_list
)
1066 list_for_each(lh
, &dev
->mode_config
.encoder_list
)
1070 crtc_count
= mode_group
->num_crtcs
;
1071 connector_count
= mode_group
->num_connectors
;
1072 encoder_count
= mode_group
->num_encoders
;
1075 card_res
->max_height
= dev
->mode_config
.max_height
;
1076 card_res
->min_height
= dev
->mode_config
.min_height
;
1077 card_res
->max_width
= dev
->mode_config
.max_width
;
1078 card_res
->min_width
= dev
->mode_config
.min_width
;
1080 /* handle this in 4 parts */
1082 if (card_res
->count_fbs
>= fb_count
) {
1084 fb_id
= (uint32_t __user
*)(unsigned long)card_res
->fb_id_ptr
;
1085 list_for_each_entry(fb
, &file_priv
->fbs
, head
) {
1086 if (put_user(fb
->base
.id
, fb_id
+ copied
)) {
1093 card_res
->count_fbs
= fb_count
;
1096 if (card_res
->count_crtcs
>= crtc_count
) {
1098 crtc_id
= (uint32_t __user
*)(unsigned long)card_res
->crtc_id_ptr
;
1099 if (file_priv
->master
->minor
->type
== DRM_MINOR_CONTROL
) {
1100 list_for_each_entry(crtc
, &dev
->mode_config
.crtc_list
,
1102 DRM_DEBUG_KMS("CRTC ID is %d\n", crtc
->base
.id
);
1103 if (put_user(crtc
->base
.id
, crtc_id
+ copied
)) {
1110 for (i
= 0; i
< mode_group
->num_crtcs
; i
++) {
1111 if (put_user(mode_group
->id_list
[i
],
1112 crtc_id
+ copied
)) {
1120 card_res
->count_crtcs
= crtc_count
;
1123 if (card_res
->count_encoders
>= encoder_count
) {
1125 encoder_id
= (uint32_t __user
*)(unsigned long)card_res
->encoder_id_ptr
;
1126 if (file_priv
->master
->minor
->type
== DRM_MINOR_CONTROL
) {
1127 list_for_each_entry(encoder
,
1128 &dev
->mode_config
.encoder_list
,
1130 DRM_DEBUG_KMS("ENCODER ID is %d\n",
1132 if (put_user(encoder
->base
.id
, encoder_id
+
1140 for (i
= mode_group
->num_crtcs
; i
< mode_group
->num_crtcs
+ mode_group
->num_encoders
; i
++) {
1141 if (put_user(mode_group
->id_list
[i
],
1142 encoder_id
+ copied
)) {
1151 card_res
->count_encoders
= encoder_count
;
1154 if (card_res
->count_connectors
>= connector_count
) {
1156 connector_id
= (uint32_t __user
*)(unsigned long)card_res
->connector_id_ptr
;
1157 if (file_priv
->master
->minor
->type
== DRM_MINOR_CONTROL
) {
1158 list_for_each_entry(connector
,
1159 &dev
->mode_config
.connector_list
,
1161 DRM_DEBUG_KMS("CONNECTOR ID is %d\n",
1162 connector
->base
.id
);
1163 if (put_user(connector
->base
.id
,
1164 connector_id
+ copied
)) {
1171 int start
= mode_group
->num_crtcs
+
1172 mode_group
->num_encoders
;
1173 for (i
= start
; i
< start
+ mode_group
->num_connectors
; i
++) {
1174 if (put_user(mode_group
->id_list
[i
],
1175 connector_id
+ copied
)) {
1183 card_res
->count_connectors
= connector_count
;
1185 DRM_DEBUG_KMS("Counted %d %d %d\n", card_res
->count_crtcs
,
1186 card_res
->count_connectors
, card_res
->count_encoders
);
1189 mutex_unlock(&dev
->mode_config
.mutex
);
1194 * drm_mode_getcrtc - get CRTC configuration
1195 * @inode: inode from the ioctl
1196 * @filp: file * from the ioctl
1197 * @cmd: cmd from ioctl
1198 * @arg: arg from ioctl
1203 * Construct a CRTC configuration structure to return to the user.
1205 * Called by the user via ioctl.
1208 * Zero on success, errno on failure.
1210 int drm_mode_getcrtc(struct drm_device
*dev
,
1211 void *data
, struct drm_file
*file_priv
)
1213 struct drm_mode_crtc
*crtc_resp
= data
;
1214 struct drm_crtc
*crtc
;
1215 struct drm_mode_object
*obj
;
1218 mutex_lock(&dev
->mode_config
.mutex
);
1220 obj
= drm_mode_object_find(dev
, crtc_resp
->crtc_id
,
1221 DRM_MODE_OBJECT_CRTC
);
1226 crtc
= obj_to_crtc(obj
);
1228 crtc_resp
->x
= crtc
->x
;
1229 crtc_resp
->y
= crtc
->y
;
1230 crtc_resp
->gamma_size
= crtc
->gamma_size
;
1232 crtc_resp
->fb_id
= crtc
->fb
->base
.id
;
1234 crtc_resp
->fb_id
= 0;
1236 if (crtc
->enabled
) {
1238 drm_crtc_convert_to_umode(&crtc_resp
->mode
, &crtc
->mode
);
1239 crtc_resp
->mode_valid
= 1;
1242 crtc_resp
->mode_valid
= 0;
1246 mutex_unlock(&dev
->mode_config
.mutex
);
1251 * drm_mode_getconnector - get connector configuration
1252 * @inode: inode from the ioctl
1253 * @filp: file * from the ioctl
1254 * @cmd: cmd from ioctl
1255 * @arg: arg from ioctl
1260 * Construct a connector configuration structure to return to the user.
1262 * Called by the user via ioctl.
1265 * Zero on success, errno on failure.
1267 int drm_mode_getconnector(struct drm_device
*dev
, void *data
,
1268 struct drm_file
*file_priv
)
1270 struct drm_mode_get_connector
*out_resp
= data
;
1271 struct drm_mode_object
*obj
;
1272 struct drm_connector
*connector
;
1273 struct drm_display_mode
*mode
;
1275 int props_count
= 0;
1276 int encoders_count
= 0;
1280 struct drm_mode_modeinfo u_mode
;
1281 struct drm_mode_modeinfo __user
*mode_ptr
;
1282 uint32_t __user
*prop_ptr
;
1283 uint64_t __user
*prop_values
;
1284 uint32_t __user
*encoder_ptr
;
1286 memset(&u_mode
, 0, sizeof(struct drm_mode_modeinfo
));
1288 DRM_DEBUG_KMS("connector id %d:\n", out_resp
->connector_id
);
1290 mutex_lock(&dev
->mode_config
.mutex
);
1292 obj
= drm_mode_object_find(dev
, out_resp
->connector_id
,
1293 DRM_MODE_OBJECT_CONNECTOR
);
1298 connector
= obj_to_connector(obj
);
1300 for (i
= 0; i
< DRM_CONNECTOR_MAX_PROPERTY
; i
++) {
1301 if (connector
->property_ids
[i
] != 0) {
1306 for (i
= 0; i
< DRM_CONNECTOR_MAX_ENCODER
; i
++) {
1307 if (connector
->encoder_ids
[i
] != 0) {
1312 if (out_resp
->count_modes
== 0) {
1313 connector
->funcs
->fill_modes(connector
,
1314 dev
->mode_config
.max_width
,
1315 dev
->mode_config
.max_height
);
1318 /* delayed so we get modes regardless of pre-fill_modes state */
1319 list_for_each_entry(mode
, &connector
->modes
, head
)
1322 out_resp
->connector_id
= connector
->base
.id
;
1323 out_resp
->connector_type
= connector
->connector_type
;
1324 out_resp
->connector_type_id
= connector
->connector_type_id
;
1325 out_resp
->mm_width
= connector
->display_info
.width_mm
;
1326 out_resp
->mm_height
= connector
->display_info
.height_mm
;
1327 out_resp
->subpixel
= connector
->display_info
.subpixel_order
;
1328 out_resp
->connection
= connector
->status
;
1329 if (connector
->encoder
)
1330 out_resp
->encoder_id
= connector
->encoder
->base
.id
;
1332 out_resp
->encoder_id
= 0;
1335 * This ioctl is called twice, once to determine how much space is
1336 * needed, and the 2nd time to fill it.
1338 if ((out_resp
->count_modes
>= mode_count
) && mode_count
) {
1340 mode_ptr
= (struct drm_mode_modeinfo
*)(unsigned long)out_resp
->modes_ptr
;
1341 list_for_each_entry(mode
, &connector
->modes
, head
) {
1342 drm_crtc_convert_to_umode(&u_mode
, mode
);
1343 if (copy_to_user(mode_ptr
+ copied
,
1344 &u_mode
, sizeof(u_mode
))) {
1351 out_resp
->count_modes
= mode_count
;
1353 if ((out_resp
->count_props
>= props_count
) && props_count
) {
1355 prop_ptr
= (uint32_t *)(unsigned long)(out_resp
->props_ptr
);
1356 prop_values
= (uint64_t *)(unsigned long)(out_resp
->prop_values_ptr
);
1357 for (i
= 0; i
< DRM_CONNECTOR_MAX_PROPERTY
; i
++) {
1358 if (connector
->property_ids
[i
] != 0) {
1359 if (put_user(connector
->property_ids
[i
],
1360 prop_ptr
+ copied
)) {
1365 if (put_user(connector
->property_values
[i
],
1366 prop_values
+ copied
)) {
1374 out_resp
->count_props
= props_count
;
1376 if ((out_resp
->count_encoders
>= encoders_count
) && encoders_count
) {
1378 encoder_ptr
= (uint32_t *)(unsigned long)(out_resp
->encoders_ptr
);
1379 for (i
= 0; i
< DRM_CONNECTOR_MAX_ENCODER
; i
++) {
1380 if (connector
->encoder_ids
[i
] != 0) {
1381 if (put_user(connector
->encoder_ids
[i
],
1382 encoder_ptr
+ copied
)) {
1390 out_resp
->count_encoders
= encoders_count
;
1393 mutex_unlock(&dev
->mode_config
.mutex
);
1397 int drm_mode_getencoder(struct drm_device
*dev
, void *data
,
1398 struct drm_file
*file_priv
)
1400 struct drm_mode_get_encoder
*enc_resp
= data
;
1401 struct drm_mode_object
*obj
;
1402 struct drm_encoder
*encoder
;
1405 mutex_lock(&dev
->mode_config
.mutex
);
1406 obj
= drm_mode_object_find(dev
, enc_resp
->encoder_id
,
1407 DRM_MODE_OBJECT_ENCODER
);
1412 encoder
= obj_to_encoder(obj
);
1415 enc_resp
->crtc_id
= encoder
->crtc
->base
.id
;
1417 enc_resp
->crtc_id
= 0;
1418 enc_resp
->encoder_type
= encoder
->encoder_type
;
1419 enc_resp
->encoder_id
= encoder
->base
.id
;
1420 enc_resp
->possible_crtcs
= encoder
->possible_crtcs
;
1421 enc_resp
->possible_clones
= encoder
->possible_clones
;
1424 mutex_unlock(&dev
->mode_config
.mutex
);
1429 * drm_mode_setcrtc - set CRTC configuration
1430 * @inode: inode from the ioctl
1431 * @filp: file * from the ioctl
1432 * @cmd: cmd from ioctl
1433 * @arg: arg from ioctl
1438 * Build a new CRTC configuration based on user request.
1440 * Called by the user via ioctl.
1443 * Zero on success, errno on failure.
1445 int drm_mode_setcrtc(struct drm_device
*dev
, void *data
,
1446 struct drm_file
*file_priv
)
1448 struct drm_mode_config
*config
= &dev
->mode_config
;
1449 struct drm_mode_crtc
*crtc_req
= data
;
1450 struct drm_mode_object
*obj
;
1451 struct drm_crtc
*crtc
, *crtcfb
;
1452 struct drm_connector
**connector_set
= NULL
, *connector
;
1453 struct drm_framebuffer
*fb
= NULL
;
1454 struct drm_display_mode
*mode
= NULL
;
1455 struct drm_mode_set set
;
1456 uint32_t __user
*set_connectors_ptr
;
1460 mutex_lock(&dev
->mode_config
.mutex
);
1461 obj
= drm_mode_object_find(dev
, crtc_req
->crtc_id
,
1462 DRM_MODE_OBJECT_CRTC
);
1464 DRM_DEBUG_KMS("Unknown CRTC ID %d\n", crtc_req
->crtc_id
);
1468 crtc
= obj_to_crtc(obj
);
1470 if (crtc_req
->mode_valid
) {
1471 /* If we have a mode we need a framebuffer. */
1472 /* If we pass -1, set the mode with the currently bound fb */
1473 if (crtc_req
->fb_id
== -1) {
1474 list_for_each_entry(crtcfb
,
1475 &dev
->mode_config
.crtc_list
, head
) {
1476 if (crtcfb
== crtc
) {
1477 DRM_DEBUG_KMS("Using current fb for "
1483 obj
= drm_mode_object_find(dev
, crtc_req
->fb_id
,
1484 DRM_MODE_OBJECT_FB
);
1486 DRM_DEBUG_KMS("Unknown FB ID%d\n",
1491 fb
= obj_to_fb(obj
);
1494 mode
= drm_mode_create(dev
);
1495 drm_crtc_convert_umode(mode
, &crtc_req
->mode
);
1496 drm_mode_set_crtcinfo(mode
, CRTC_INTERLACE_HALVE_V
);
1499 if (crtc_req
->count_connectors
== 0 && mode
) {
1500 DRM_DEBUG_KMS("Count connectors is 0 but mode set\n");
1505 if (crtc_req
->count_connectors
> 0 && !mode
&& !fb
) {
1506 DRM_DEBUG_KMS("Count connectors is %d but no mode or fb set\n",
1507 crtc_req
->count_connectors
);
1512 if (crtc_req
->count_connectors
> 0) {
1515 /* Avoid unbounded kernel memory allocation */
1516 if (crtc_req
->count_connectors
> config
->num_connector
) {
1521 connector_set
= kmalloc(crtc_req
->count_connectors
*
1522 sizeof(struct drm_connector
*),
1524 if (!connector_set
) {
1529 for (i
= 0; i
< crtc_req
->count_connectors
; i
++) {
1530 set_connectors_ptr
= (uint32_t *)(unsigned long)crtc_req
->set_connectors_ptr
;
1531 if (get_user(out_id
, &set_connectors_ptr
[i
])) {
1536 obj
= drm_mode_object_find(dev
, out_id
,
1537 DRM_MODE_OBJECT_CONNECTOR
);
1539 DRM_DEBUG_KMS("Connector id %d unknown\n",
1544 connector
= obj_to_connector(obj
);
1546 connector_set
[i
] = connector
;
1551 set
.x
= crtc_req
->x
;
1552 set
.y
= crtc_req
->y
;
1554 set
.connectors
= connector_set
;
1555 set
.num_connectors
= crtc_req
->count_connectors
;
1557 ret
= crtc
->funcs
->set_config(&set
);
1560 kfree(connector_set
);
1561 mutex_unlock(&dev
->mode_config
.mutex
);
1565 int drm_mode_cursor_ioctl(struct drm_device
*dev
,
1566 void *data
, struct drm_file
*file_priv
)
1568 struct drm_mode_cursor
*req
= data
;
1569 struct drm_mode_object
*obj
;
1570 struct drm_crtc
*crtc
;
1573 DRM_DEBUG_KMS("\n");
1576 DRM_ERROR("no operation set\n");
1580 mutex_lock(&dev
->mode_config
.mutex
);
1581 obj
= drm_mode_object_find(dev
, req
->crtc_id
, DRM_MODE_OBJECT_CRTC
);
1583 DRM_DEBUG_KMS("Unknown CRTC ID %d\n", req
->crtc_id
);
1587 crtc
= obj_to_crtc(obj
);
1589 if (req
->flags
& DRM_MODE_CURSOR_BO
) {
1590 if (!crtc
->funcs
->cursor_set
) {
1591 DRM_ERROR("crtc does not support cursor\n");
1595 /* Turns off the cursor if handle is 0 */
1596 ret
= crtc
->funcs
->cursor_set(crtc
, file_priv
, req
->handle
,
1597 req
->width
, req
->height
);
1600 if (req
->flags
& DRM_MODE_CURSOR_MOVE
) {
1601 if (crtc
->funcs
->cursor_move
) {
1602 ret
= crtc
->funcs
->cursor_move(crtc
, req
->x
, req
->y
);
1604 DRM_ERROR("crtc does not support cursor\n");
1610 mutex_unlock(&dev
->mode_config
.mutex
);
1615 * drm_mode_addfb - add an FB to the graphics configuration
1616 * @inode: inode from the ioctl
1617 * @filp: file * from the ioctl
1618 * @cmd: cmd from ioctl
1619 * @arg: arg from ioctl
1622 * Takes mode config lock.
1624 * Add a new FB to the specified CRTC, given a user request.
1626 * Called by the user via ioctl.
1629 * Zero on success, errno on failure.
1631 int drm_mode_addfb(struct drm_device
*dev
,
1632 void *data
, struct drm_file
*file_priv
)
1634 struct drm_mode_fb_cmd
*r
= data
;
1635 struct drm_mode_config
*config
= &dev
->mode_config
;
1636 struct drm_framebuffer
*fb
;
1639 if ((config
->min_width
> r
->width
) || (r
->width
> config
->max_width
)) {
1640 DRM_ERROR("mode new framebuffer width not within limits\n");
1643 if ((config
->min_height
> r
->height
) || (r
->height
> config
->max_height
)) {
1644 DRM_ERROR("mode new framebuffer height not within limits\n");
1648 mutex_lock(&dev
->mode_config
.mutex
);
1650 /* TODO check buffer is sufficently large */
1651 /* TODO setup destructor callback */
1653 fb
= dev
->mode_config
.funcs
->fb_create(dev
, file_priv
, r
);
1655 DRM_ERROR("could not create framebuffer\n");
1660 r
->fb_id
= fb
->base
.id
;
1661 list_add(&fb
->filp_head
, &file_priv
->fbs
);
1664 mutex_unlock(&dev
->mode_config
.mutex
);
1669 * drm_mode_rmfb - remove an FB from the configuration
1670 * @inode: inode from the ioctl
1671 * @filp: file * from the ioctl
1672 * @cmd: cmd from ioctl
1673 * @arg: arg from ioctl
1676 * Takes mode config lock.
1678 * Remove the FB specified by the user.
1680 * Called by the user via ioctl.
1683 * Zero on success, errno on failure.
1685 int drm_mode_rmfb(struct drm_device
*dev
,
1686 void *data
, struct drm_file
*file_priv
)
1688 struct drm_mode_object
*obj
;
1689 struct drm_framebuffer
*fb
= NULL
;
1690 struct drm_framebuffer
*fbl
= NULL
;
1691 uint32_t *id
= data
;
1695 mutex_lock(&dev
->mode_config
.mutex
);
1696 obj
= drm_mode_object_find(dev
, *id
, DRM_MODE_OBJECT_FB
);
1697 /* TODO check that we realy get a framebuffer back. */
1699 DRM_ERROR("mode invalid framebuffer id\n");
1703 fb
= obj_to_fb(obj
);
1705 list_for_each_entry(fbl
, &file_priv
->fbs
, filp_head
)
1710 DRM_ERROR("tried to remove a fb that we didn't own\n");
1715 /* TODO release all crtc connected to the framebuffer */
1716 /* TODO unhock the destructor from the buffer object */
1718 list_del(&fb
->filp_head
);
1719 fb
->funcs
->destroy(fb
);
1722 mutex_unlock(&dev
->mode_config
.mutex
);
1727 * drm_mode_getfb - get FB info
1728 * @inode: inode from the ioctl
1729 * @filp: file * from the ioctl
1730 * @cmd: cmd from ioctl
1731 * @arg: arg from ioctl
1736 * Lookup the FB given its ID and return info about it.
1738 * Called by the user via ioctl.
1741 * Zero on success, errno on failure.
1743 int drm_mode_getfb(struct drm_device
*dev
,
1744 void *data
, struct drm_file
*file_priv
)
1746 struct drm_mode_fb_cmd
*r
= data
;
1747 struct drm_mode_object
*obj
;
1748 struct drm_framebuffer
*fb
;
1751 mutex_lock(&dev
->mode_config
.mutex
);
1752 obj
= drm_mode_object_find(dev
, r
->fb_id
, DRM_MODE_OBJECT_FB
);
1754 DRM_ERROR("invalid framebuffer id\n");
1758 fb
= obj_to_fb(obj
);
1760 r
->height
= fb
->height
;
1761 r
->width
= fb
->width
;
1762 r
->depth
= fb
->depth
;
1763 r
->bpp
= fb
->bits_per_pixel
;
1764 r
->pitch
= fb
->pitch
;
1765 fb
->funcs
->create_handle(fb
, file_priv
, &r
->handle
);
1768 mutex_unlock(&dev
->mode_config
.mutex
);
1773 * drm_fb_release - remove and free the FBs on this file
1774 * @filp: file * from the ioctl
1777 * Takes mode config lock.
1779 * Destroy all the FBs associated with @filp.
1781 * Called by the user via ioctl.
1784 * Zero on success, errno on failure.
1786 void drm_fb_release(struct drm_file
*priv
)
1788 struct drm_device
*dev
= priv
->minor
->dev
;
1789 struct drm_framebuffer
*fb
, *tfb
;
1791 mutex_lock(&dev
->mode_config
.mutex
);
1792 list_for_each_entry_safe(fb
, tfb
, &priv
->fbs
, filp_head
) {
1793 list_del(&fb
->filp_head
);
1794 fb
->funcs
->destroy(fb
);
1796 mutex_unlock(&dev
->mode_config
.mutex
);
1800 * drm_mode_attachmode - add a mode to the user mode list
1802 * @connector: connector to add the mode to
1803 * @mode: mode to add
1805 * Add @mode to @connector's user mode list.
1807 static int drm_mode_attachmode(struct drm_device
*dev
,
1808 struct drm_connector
*connector
,
1809 struct drm_display_mode
*mode
)
1813 list_add_tail(&mode
->head
, &connector
->user_modes
);
1817 int drm_mode_attachmode_crtc(struct drm_device
*dev
, struct drm_crtc
*crtc
,
1818 struct drm_display_mode
*mode
)
1820 struct drm_connector
*connector
;
1822 struct drm_display_mode
*dup_mode
;
1824 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
, head
) {
1825 if (!connector
->encoder
)
1827 if (connector
->encoder
->crtc
== crtc
) {
1829 dup_mode
= drm_mode_duplicate(dev
, mode
);
1832 ret
= drm_mode_attachmode(dev
, connector
, dup_mode
);
1840 EXPORT_SYMBOL(drm_mode_attachmode_crtc
);
1842 static int drm_mode_detachmode(struct drm_device
*dev
,
1843 struct drm_connector
*connector
,
1844 struct drm_display_mode
*mode
)
1848 struct drm_display_mode
*match_mode
, *t
;
1850 list_for_each_entry_safe(match_mode
, t
, &connector
->user_modes
, head
) {
1851 if (drm_mode_equal(match_mode
, mode
)) {
1852 list_del(&match_mode
->head
);
1853 drm_mode_destroy(dev
, match_mode
);
1865 int drm_mode_detachmode_crtc(struct drm_device
*dev
, struct drm_display_mode
*mode
)
1867 struct drm_connector
*connector
;
1869 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
, head
) {
1870 drm_mode_detachmode(dev
, connector
, mode
);
1874 EXPORT_SYMBOL(drm_mode_detachmode_crtc
);
1877 * drm_fb_attachmode - Attach a user mode to an connector
1878 * @inode: inode from the ioctl
1879 * @filp: file * from the ioctl
1880 * @cmd: cmd from ioctl
1881 * @arg: arg from ioctl
1883 * This attaches a user specified mode to an connector.
1884 * Called by the user via ioctl.
1887 * Zero on success, errno on failure.
1889 int drm_mode_attachmode_ioctl(struct drm_device
*dev
,
1890 void *data
, struct drm_file
*file_priv
)
1892 struct drm_mode_mode_cmd
*mode_cmd
= data
;
1893 struct drm_connector
*connector
;
1894 struct drm_display_mode
*mode
;
1895 struct drm_mode_object
*obj
;
1896 struct drm_mode_modeinfo
*umode
= &mode_cmd
->mode
;
1899 mutex_lock(&dev
->mode_config
.mutex
);
1901 obj
= drm_mode_object_find(dev
, mode_cmd
->connector_id
, DRM_MODE_OBJECT_CONNECTOR
);
1906 connector
= obj_to_connector(obj
);
1908 mode
= drm_mode_create(dev
);
1914 drm_crtc_convert_umode(mode
, umode
);
1916 ret
= drm_mode_attachmode(dev
, connector
, mode
);
1918 mutex_unlock(&dev
->mode_config
.mutex
);
1924 * drm_fb_detachmode - Detach a user specified mode from an connector
1925 * @inode: inode from the ioctl
1926 * @filp: file * from the ioctl
1927 * @cmd: cmd from ioctl
1928 * @arg: arg from ioctl
1930 * Called by the user via ioctl.
1933 * Zero on success, errno on failure.
1935 int drm_mode_detachmode_ioctl(struct drm_device
*dev
,
1936 void *data
, struct drm_file
*file_priv
)
1938 struct drm_mode_object
*obj
;
1939 struct drm_mode_mode_cmd
*mode_cmd
= data
;
1940 struct drm_connector
*connector
;
1941 struct drm_display_mode mode
;
1942 struct drm_mode_modeinfo
*umode
= &mode_cmd
->mode
;
1945 mutex_lock(&dev
->mode_config
.mutex
);
1947 obj
= drm_mode_object_find(dev
, mode_cmd
->connector_id
, DRM_MODE_OBJECT_CONNECTOR
);
1952 connector
= obj_to_connector(obj
);
1954 drm_crtc_convert_umode(&mode
, umode
);
1955 ret
= drm_mode_detachmode(dev
, connector
, &mode
);
1957 mutex_unlock(&dev
->mode_config
.mutex
);
1961 struct drm_property
*drm_property_create(struct drm_device
*dev
, int flags
,
1962 const char *name
, int num_values
)
1964 struct drm_property
*property
= NULL
;
1966 property
= kzalloc(sizeof(struct drm_property
), GFP_KERNEL
);
1971 property
->values
= kzalloc(sizeof(uint64_t)*num_values
, GFP_KERNEL
);
1972 if (!property
->values
)
1976 drm_mode_object_get(dev
, &property
->base
, DRM_MODE_OBJECT_PROPERTY
);
1977 property
->flags
= flags
;
1978 property
->num_values
= num_values
;
1979 INIT_LIST_HEAD(&property
->enum_blob_list
);
1982 strncpy(property
->name
, name
, DRM_PROP_NAME_LEN
);
1984 list_add_tail(&property
->head
, &dev
->mode_config
.property_list
);
1990 EXPORT_SYMBOL(drm_property_create
);
1992 int drm_property_add_enum(struct drm_property
*property
, int index
,
1993 uint64_t value
, const char *name
)
1995 struct drm_property_enum
*prop_enum
;
1997 if (!(property
->flags
& DRM_MODE_PROP_ENUM
))
2000 if (!list_empty(&property
->enum_blob_list
)) {
2001 list_for_each_entry(prop_enum
, &property
->enum_blob_list
, head
) {
2002 if (prop_enum
->value
== value
) {
2003 strncpy(prop_enum
->name
, name
, DRM_PROP_NAME_LEN
);
2004 prop_enum
->name
[DRM_PROP_NAME_LEN
-1] = '\0';
2010 prop_enum
= kzalloc(sizeof(struct drm_property_enum
), GFP_KERNEL
);
2014 strncpy(prop_enum
->name
, name
, DRM_PROP_NAME_LEN
);
2015 prop_enum
->name
[DRM_PROP_NAME_LEN
-1] = '\0';
2016 prop_enum
->value
= value
;
2018 property
->values
[index
] = value
;
2019 list_add_tail(&prop_enum
->head
, &property
->enum_blob_list
);
2022 EXPORT_SYMBOL(drm_property_add_enum
);
2024 void drm_property_destroy(struct drm_device
*dev
, struct drm_property
*property
)
2026 struct drm_property_enum
*prop_enum
, *pt
;
2028 list_for_each_entry_safe(prop_enum
, pt
, &property
->enum_blob_list
, head
) {
2029 list_del(&prop_enum
->head
);
2033 if (property
->num_values
)
2034 kfree(property
->values
);
2035 drm_mode_object_put(dev
, &property
->base
);
2036 list_del(&property
->head
);
2039 EXPORT_SYMBOL(drm_property_destroy
);
2041 int drm_connector_attach_property(struct drm_connector
*connector
,
2042 struct drm_property
*property
, uint64_t init_val
)
2046 for (i
= 0; i
< DRM_CONNECTOR_MAX_PROPERTY
; i
++) {
2047 if (connector
->property_ids
[i
] == 0) {
2048 connector
->property_ids
[i
] = property
->base
.id
;
2049 connector
->property_values
[i
] = init_val
;
2054 if (i
== DRM_CONNECTOR_MAX_PROPERTY
)
2058 EXPORT_SYMBOL(drm_connector_attach_property
);
2060 int drm_connector_property_set_value(struct drm_connector
*connector
,
2061 struct drm_property
*property
, uint64_t value
)
2065 for (i
= 0; i
< DRM_CONNECTOR_MAX_PROPERTY
; i
++) {
2066 if (connector
->property_ids
[i
] == property
->base
.id
) {
2067 connector
->property_values
[i
] = value
;
2072 if (i
== DRM_CONNECTOR_MAX_PROPERTY
)
2076 EXPORT_SYMBOL(drm_connector_property_set_value
);
2078 int drm_connector_property_get_value(struct drm_connector
*connector
,
2079 struct drm_property
*property
, uint64_t *val
)
2083 for (i
= 0; i
< DRM_CONNECTOR_MAX_PROPERTY
; i
++) {
2084 if (connector
->property_ids
[i
] == property
->base
.id
) {
2085 *val
= connector
->property_values
[i
];
2090 if (i
== DRM_CONNECTOR_MAX_PROPERTY
)
2094 EXPORT_SYMBOL(drm_connector_property_get_value
);
2096 int drm_mode_getproperty_ioctl(struct drm_device
*dev
,
2097 void *data
, struct drm_file
*file_priv
)
2099 struct drm_mode_object
*obj
;
2100 struct drm_mode_get_property
*out_resp
= data
;
2101 struct drm_property
*property
;
2104 int value_count
= 0;
2107 struct drm_property_enum
*prop_enum
;
2108 struct drm_mode_property_enum __user
*enum_ptr
;
2109 struct drm_property_blob
*prop_blob
;
2110 uint32_t *blob_id_ptr
;
2111 uint64_t __user
*values_ptr
;
2112 uint32_t __user
*blob_length_ptr
;
2114 mutex_lock(&dev
->mode_config
.mutex
);
2115 obj
= drm_mode_object_find(dev
, out_resp
->prop_id
, DRM_MODE_OBJECT_PROPERTY
);
2120 property
= obj_to_property(obj
);
2122 if (property
->flags
& DRM_MODE_PROP_ENUM
) {
2123 list_for_each_entry(prop_enum
, &property
->enum_blob_list
, head
)
2125 } else if (property
->flags
& DRM_MODE_PROP_BLOB
) {
2126 list_for_each_entry(prop_blob
, &property
->enum_blob_list
, head
)
2130 value_count
= property
->num_values
;
2132 strncpy(out_resp
->name
, property
->name
, DRM_PROP_NAME_LEN
);
2133 out_resp
->name
[DRM_PROP_NAME_LEN
-1] = 0;
2134 out_resp
->flags
= property
->flags
;
2136 if ((out_resp
->count_values
>= value_count
) && value_count
) {
2137 values_ptr
= (uint64_t *)(unsigned long)out_resp
->values_ptr
;
2138 for (i
= 0; i
< value_count
; i
++) {
2139 if (copy_to_user(values_ptr
+ i
, &property
->values
[i
], sizeof(uint64_t))) {
2145 out_resp
->count_values
= value_count
;
2147 if (property
->flags
& DRM_MODE_PROP_ENUM
) {
2148 if ((out_resp
->count_enum_blobs
>= enum_count
) && enum_count
) {
2150 enum_ptr
= (struct drm_mode_property_enum
*)(unsigned long)out_resp
->enum_blob_ptr
;
2151 list_for_each_entry(prop_enum
, &property
->enum_blob_list
, head
) {
2153 if (copy_to_user(&enum_ptr
[copied
].value
, &prop_enum
->value
, sizeof(uint64_t))) {
2158 if (copy_to_user(&enum_ptr
[copied
].name
,
2159 &prop_enum
->name
, DRM_PROP_NAME_LEN
)) {
2166 out_resp
->count_enum_blobs
= enum_count
;
2169 if (property
->flags
& DRM_MODE_PROP_BLOB
) {
2170 if ((out_resp
->count_enum_blobs
>= blob_count
) && blob_count
) {
2172 blob_id_ptr
= (uint32_t *)(unsigned long)out_resp
->enum_blob_ptr
;
2173 blob_length_ptr
= (uint32_t *)(unsigned long)out_resp
->values_ptr
;
2175 list_for_each_entry(prop_blob
, &property
->enum_blob_list
, head
) {
2176 if (put_user(prop_blob
->base
.id
, blob_id_ptr
+ copied
)) {
2181 if (put_user(prop_blob
->length
, blob_length_ptr
+ copied
)) {
2189 out_resp
->count_enum_blobs
= blob_count
;
2192 mutex_unlock(&dev
->mode_config
.mutex
);
2196 static struct drm_property_blob
*drm_property_create_blob(struct drm_device
*dev
, int length
,
2199 struct drm_property_blob
*blob
;
2201 if (!length
|| !data
)
2204 blob
= kzalloc(sizeof(struct drm_property_blob
)+length
, GFP_KERNEL
);
2208 blob
->data
= (void *)((char *)blob
+ sizeof(struct drm_property_blob
));
2209 blob
->length
= length
;
2211 memcpy(blob
->data
, data
, length
);
2213 drm_mode_object_get(dev
, &blob
->base
, DRM_MODE_OBJECT_BLOB
);
2215 list_add_tail(&blob
->head
, &dev
->mode_config
.property_blob_list
);
2219 static void drm_property_destroy_blob(struct drm_device
*dev
,
2220 struct drm_property_blob
*blob
)
2222 drm_mode_object_put(dev
, &blob
->base
);
2223 list_del(&blob
->head
);
2227 int drm_mode_getblob_ioctl(struct drm_device
*dev
,
2228 void *data
, struct drm_file
*file_priv
)
2230 struct drm_mode_object
*obj
;
2231 struct drm_mode_get_blob
*out_resp
= data
;
2232 struct drm_property_blob
*blob
;
2236 mutex_lock(&dev
->mode_config
.mutex
);
2237 obj
= drm_mode_object_find(dev
, out_resp
->blob_id
, DRM_MODE_OBJECT_BLOB
);
2242 blob
= obj_to_blob(obj
);
2244 if (out_resp
->length
== blob
->length
) {
2245 blob_ptr
= (void *)(unsigned long)out_resp
->data
;
2246 if (copy_to_user(blob_ptr
, blob
->data
, blob
->length
)){
2251 out_resp
->length
= blob
->length
;
2254 mutex_unlock(&dev
->mode_config
.mutex
);
2258 int drm_mode_connector_update_edid_property(struct drm_connector
*connector
,
2261 struct drm_device
*dev
= connector
->dev
;
2264 if (connector
->edid_blob_ptr
)
2265 drm_property_destroy_blob(dev
, connector
->edid_blob_ptr
);
2267 /* Delete edid, when there is none. */
2269 connector
->edid_blob_ptr
= NULL
;
2270 ret
= drm_connector_property_set_value(connector
, dev
->mode_config
.edid_property
, 0);
2274 connector
->edid_blob_ptr
= drm_property_create_blob(connector
->dev
, 128, edid
);
2276 ret
= drm_connector_property_set_value(connector
,
2277 dev
->mode_config
.edid_property
,
2278 connector
->edid_blob_ptr
->base
.id
);
2282 EXPORT_SYMBOL(drm_mode_connector_update_edid_property
);
2284 int drm_mode_connector_property_set_ioctl(struct drm_device
*dev
,
2285 void *data
, struct drm_file
*file_priv
)
2287 struct drm_mode_connector_set_property
*out_resp
= data
;
2288 struct drm_mode_object
*obj
;
2289 struct drm_property
*property
;
2290 struct drm_connector
*connector
;
2294 mutex_lock(&dev
->mode_config
.mutex
);
2296 obj
= drm_mode_object_find(dev
, out_resp
->connector_id
, DRM_MODE_OBJECT_CONNECTOR
);
2300 connector
= obj_to_connector(obj
);
2302 for (i
= 0; i
< DRM_CONNECTOR_MAX_PROPERTY
; i
++) {
2303 if (connector
->property_ids
[i
] == out_resp
->prop_id
)
2307 if (i
== DRM_CONNECTOR_MAX_PROPERTY
) {
2311 obj
= drm_mode_object_find(dev
, out_resp
->prop_id
, DRM_MODE_OBJECT_PROPERTY
);
2315 property
= obj_to_property(obj
);
2317 if (property
->flags
& DRM_MODE_PROP_IMMUTABLE
)
2320 if (property
->flags
& DRM_MODE_PROP_RANGE
) {
2321 if (out_resp
->value
< property
->values
[0])
2324 if (out_resp
->value
> property
->values
[1])
2328 for (i
= 0; i
< property
->num_values
; i
++) {
2329 if (property
->values
[i
] == out_resp
->value
) {
2339 /* Do DPMS ourselves */
2340 if (property
== connector
->dev
->mode_config
.dpms_property
) {
2341 if (connector
->funcs
->dpms
)
2342 (*connector
->funcs
->dpms
)(connector
, (int) out_resp
->value
);
2344 } else if (connector
->funcs
->set_property
)
2345 ret
= connector
->funcs
->set_property(connector
, property
, out_resp
->value
);
2347 /* store the property value if succesful */
2349 drm_connector_property_set_value(connector
, property
, out_resp
->value
);
2351 mutex_unlock(&dev
->mode_config
.mutex
);
2355 int drm_mode_connector_attach_encoder(struct drm_connector
*connector
,
2356 struct drm_encoder
*encoder
)
2360 for (i
= 0; i
< DRM_CONNECTOR_MAX_ENCODER
; i
++) {
2361 if (connector
->encoder_ids
[i
] == 0) {
2362 connector
->encoder_ids
[i
] = encoder
->base
.id
;
2368 EXPORT_SYMBOL(drm_mode_connector_attach_encoder
);
2370 void drm_mode_connector_detach_encoder(struct drm_connector
*connector
,
2371 struct drm_encoder
*encoder
)
2374 for (i
= 0; i
< DRM_CONNECTOR_MAX_ENCODER
; i
++) {
2375 if (connector
->encoder_ids
[i
] == encoder
->base
.id
) {
2376 connector
->encoder_ids
[i
] = 0;
2377 if (connector
->encoder
== encoder
)
2378 connector
->encoder
= NULL
;
2383 EXPORT_SYMBOL(drm_mode_connector_detach_encoder
);
2385 bool drm_mode_crtc_set_gamma_size(struct drm_crtc
*crtc
,
2388 crtc
->gamma_size
= gamma_size
;
2390 crtc
->gamma_store
= kzalloc(gamma_size
* sizeof(uint16_t) * 3, GFP_KERNEL
);
2391 if (!crtc
->gamma_store
) {
2392 crtc
->gamma_size
= 0;
2398 EXPORT_SYMBOL(drm_mode_crtc_set_gamma_size
);
2400 int drm_mode_gamma_set_ioctl(struct drm_device
*dev
,
2401 void *data
, struct drm_file
*file_priv
)
2403 struct drm_mode_crtc_lut
*crtc_lut
= data
;
2404 struct drm_mode_object
*obj
;
2405 struct drm_crtc
*crtc
;
2406 void *r_base
, *g_base
, *b_base
;
2410 mutex_lock(&dev
->mode_config
.mutex
);
2411 obj
= drm_mode_object_find(dev
, crtc_lut
->crtc_id
, DRM_MODE_OBJECT_CRTC
);
2416 crtc
= obj_to_crtc(obj
);
2418 /* memcpy into gamma store */
2419 if (crtc_lut
->gamma_size
!= crtc
->gamma_size
) {
2424 size
= crtc_lut
->gamma_size
* (sizeof(uint16_t));
2425 r_base
= crtc
->gamma_store
;
2426 if (copy_from_user(r_base
, (void __user
*)(unsigned long)crtc_lut
->red
, size
)) {
2431 g_base
= r_base
+ size
;
2432 if (copy_from_user(g_base
, (void __user
*)(unsigned long)crtc_lut
->green
, size
)) {
2437 b_base
= g_base
+ size
;
2438 if (copy_from_user(b_base
, (void __user
*)(unsigned long)crtc_lut
->blue
, size
)) {
2443 crtc
->funcs
->gamma_set(crtc
, r_base
, g_base
, b_base
, crtc
->gamma_size
);
2446 mutex_unlock(&dev
->mode_config
.mutex
);
2451 int drm_mode_gamma_get_ioctl(struct drm_device
*dev
,
2452 void *data
, struct drm_file
*file_priv
)
2454 struct drm_mode_crtc_lut
*crtc_lut
= data
;
2455 struct drm_mode_object
*obj
;
2456 struct drm_crtc
*crtc
;
2457 void *r_base
, *g_base
, *b_base
;
2461 mutex_lock(&dev
->mode_config
.mutex
);
2462 obj
= drm_mode_object_find(dev
, crtc_lut
->crtc_id
, DRM_MODE_OBJECT_CRTC
);
2467 crtc
= obj_to_crtc(obj
);
2469 /* memcpy into gamma store */
2470 if (crtc_lut
->gamma_size
!= crtc
->gamma_size
) {
2475 size
= crtc_lut
->gamma_size
* (sizeof(uint16_t));
2476 r_base
= crtc
->gamma_store
;
2477 if (copy_to_user((void __user
*)(unsigned long)crtc_lut
->red
, r_base
, size
)) {
2482 g_base
= r_base
+ size
;
2483 if (copy_to_user((void __user
*)(unsigned long)crtc_lut
->green
, g_base
, size
)) {
2488 b_base
= g_base
+ size
;
2489 if (copy_to_user((void __user
*)(unsigned long)crtc_lut
->blue
, b_base
, size
)) {
2494 mutex_unlock(&dev
->mode_config
.mutex
);