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 */
113 DRM_ENUM_NAME_FN(drm_get_tv_select_name
, drm_tv_select_enum_list
)
115 static struct drm_prop_enum_list drm_tv_subconnector_enum_list
[] =
117 { DRM_MODE_SUBCONNECTOR_Unknown
, "Unknown" }, /* DVI-I and TV-out */
118 { DRM_MODE_SUBCONNECTOR_Composite
, "Composite" }, /* TV-out */
119 { DRM_MODE_SUBCONNECTOR_SVIDEO
, "SVIDEO" }, /* TV-out */
120 { DRM_MODE_SUBCONNECTOR_Component
, "Component" }, /* TV-out */
123 DRM_ENUM_NAME_FN(drm_get_tv_subconnector_name
,
124 drm_tv_subconnector_enum_list
)
126 struct drm_conn_prop_enum_list
{
133 * Connector and encoder types.
135 static struct drm_conn_prop_enum_list drm_connector_enum_list
[] =
136 { { DRM_MODE_CONNECTOR_Unknown
, "Unknown", 0 },
137 { DRM_MODE_CONNECTOR_VGA
, "VGA", 0 },
138 { DRM_MODE_CONNECTOR_DVII
, "DVI-I", 0 },
139 { DRM_MODE_CONNECTOR_DVID
, "DVI-D", 0 },
140 { DRM_MODE_CONNECTOR_DVIA
, "DVI-A", 0 },
141 { DRM_MODE_CONNECTOR_Composite
, "Composite", 0 },
142 { DRM_MODE_CONNECTOR_SVIDEO
, "SVIDEO", 0 },
143 { DRM_MODE_CONNECTOR_LVDS
, "LVDS", 0 },
144 { DRM_MODE_CONNECTOR_Component
, "Component", 0 },
145 { DRM_MODE_CONNECTOR_9PinDIN
, "9-pin DIN", 0 },
146 { DRM_MODE_CONNECTOR_DisplayPort
, "DisplayPort", 0 },
147 { DRM_MODE_CONNECTOR_HDMIA
, "HDMI Type A", 0 },
148 { DRM_MODE_CONNECTOR_HDMIB
, "HDMI Type B", 0 },
151 static struct drm_prop_enum_list drm_encoder_enum_list
[] =
152 { { DRM_MODE_ENCODER_NONE
, "None" },
153 { DRM_MODE_ENCODER_DAC
, "DAC" },
154 { DRM_MODE_ENCODER_TMDS
, "TMDS" },
155 { DRM_MODE_ENCODER_LVDS
, "LVDS" },
156 { DRM_MODE_ENCODER_TVDAC
, "TV" },
159 char *drm_get_encoder_name(struct drm_encoder
*encoder
)
163 snprintf(buf
, 32, "%s-%d",
164 drm_encoder_enum_list
[encoder
->encoder_type
].name
,
169 char *drm_get_connector_name(struct drm_connector
*connector
)
173 snprintf(buf
, 32, "%s-%d",
174 drm_connector_enum_list
[connector
->connector_type
].name
,
175 connector
->connector_type_id
);
178 EXPORT_SYMBOL(drm_get_connector_name
);
180 char *drm_get_connector_status_name(enum drm_connector_status status
)
182 if (status
== connector_status_connected
)
184 else if (status
== connector_status_disconnected
)
185 return "disconnected";
191 * drm_mode_object_get - allocate a new identifier
193 * @ptr: object pointer, used to generate unique ID
198 * Create a unique identifier based on @ptr in @dev's identifier space. Used
199 * for tracking modes, CRTCs and connectors.
202 * New unique (relative to other objects in @dev) integer identifier for the
205 static int drm_mode_object_get(struct drm_device
*dev
,
206 struct drm_mode_object
*obj
, uint32_t obj_type
)
212 if (idr_pre_get(&dev
->mode_config
.crtc_idr
, GFP_KERNEL
) == 0) {
213 DRM_ERROR("Ran out memory getting a mode number\n");
217 mutex_lock(&dev
->mode_config
.idr_mutex
);
218 ret
= idr_get_new_above(&dev
->mode_config
.crtc_idr
, obj
, 1, &new_id
);
219 mutex_unlock(&dev
->mode_config
.idr_mutex
);
224 obj
->type
= obj_type
;
229 * drm_mode_object_put - free an identifer
234 * Caller must hold DRM mode_config lock.
236 * Free @id from @dev's unique identifier pool.
238 static void drm_mode_object_put(struct drm_device
*dev
,
239 struct drm_mode_object
*object
)
241 mutex_lock(&dev
->mode_config
.idr_mutex
);
242 idr_remove(&dev
->mode_config
.crtc_idr
, object
->id
);
243 mutex_unlock(&dev
->mode_config
.idr_mutex
);
246 void *drm_mode_object_find(struct drm_device
*dev
, uint32_t id
, uint32_t type
)
248 struct drm_mode_object
*obj
= NULL
;
250 mutex_lock(&dev
->mode_config
.idr_mutex
);
251 obj
= idr_find(&dev
->mode_config
.crtc_idr
, id
);
252 if (!obj
|| (obj
->type
!= type
) || (obj
->id
!= id
))
254 mutex_unlock(&dev
->mode_config
.idr_mutex
);
258 EXPORT_SYMBOL(drm_mode_object_find
);
261 * drm_framebuffer_init - initialize a framebuffer
265 * Caller must hold mode config lock.
267 * Allocates an ID for the framebuffer's parent mode object, sets its mode
268 * functions & device file and adds it to the master fd list.
271 * Zero on success, error code on falure.
273 int drm_framebuffer_init(struct drm_device
*dev
, struct drm_framebuffer
*fb
,
274 const struct drm_framebuffer_funcs
*funcs
)
278 ret
= drm_mode_object_get(dev
, &fb
->base
, DRM_MODE_OBJECT_FB
);
285 dev
->mode_config
.num_fb
++;
286 list_add(&fb
->head
, &dev
->mode_config
.fb_list
);
290 EXPORT_SYMBOL(drm_framebuffer_init
);
293 * drm_framebuffer_cleanup - remove a framebuffer object
294 * @fb: framebuffer to remove
297 * Caller must hold mode config lock.
299 * Scans all the CRTCs in @dev's mode_config. If they're using @fb, removes
300 * it, setting it to NULL.
302 void drm_framebuffer_cleanup(struct drm_framebuffer
*fb
)
304 struct drm_device
*dev
= fb
->dev
;
305 struct drm_crtc
*crtc
;
306 struct drm_mode_set set
;
309 /* remove from any CRTC */
310 list_for_each_entry(crtc
, &dev
->mode_config
.crtc_list
, head
) {
311 if (crtc
->fb
== fb
) {
312 /* should turn off the crtc */
313 memset(&set
, 0, sizeof(struct drm_mode_set
));
316 ret
= crtc
->funcs
->set_config(&set
);
318 DRM_ERROR("failed to reset crtc %p when fb was deleted\n", crtc
);
322 drm_mode_object_put(dev
, &fb
->base
);
324 dev
->mode_config
.num_fb
--;
326 EXPORT_SYMBOL(drm_framebuffer_cleanup
);
329 * drm_crtc_init - Initialise a new CRTC object
331 * @crtc: CRTC object to init
332 * @funcs: callbacks for the new CRTC
335 * Caller must hold mode config lock.
337 * Inits a new object created as base part of an driver crtc object.
339 void drm_crtc_init(struct drm_device
*dev
, struct drm_crtc
*crtc
,
340 const struct drm_crtc_funcs
*funcs
)
345 mutex_lock(&dev
->mode_config
.mutex
);
346 drm_mode_object_get(dev
, &crtc
->base
, DRM_MODE_OBJECT_CRTC
);
348 list_add_tail(&crtc
->head
, &dev
->mode_config
.crtc_list
);
349 dev
->mode_config
.num_crtc
++;
350 mutex_unlock(&dev
->mode_config
.mutex
);
352 EXPORT_SYMBOL(drm_crtc_init
);
355 * drm_crtc_cleanup - Cleans up the core crtc usage.
356 * @crtc: CRTC to cleanup
359 * Caller must hold mode config lock.
361 * Cleanup @crtc. Removes from drm modesetting space
362 * does NOT free object, caller does that.
364 void drm_crtc_cleanup(struct drm_crtc
*crtc
)
366 struct drm_device
*dev
= crtc
->dev
;
368 if (crtc
->gamma_store
) {
369 kfree(crtc
->gamma_store
);
370 crtc
->gamma_store
= NULL
;
373 drm_mode_object_put(dev
, &crtc
->base
);
374 list_del(&crtc
->head
);
375 dev
->mode_config
.num_crtc
--;
377 EXPORT_SYMBOL(drm_crtc_cleanup
);
380 * drm_mode_probed_add - add a mode to a connector's probed mode list
381 * @connector: connector the new mode
385 * Caller must hold mode config lock.
387 * Add @mode to @connector's mode list for later use.
389 void drm_mode_probed_add(struct drm_connector
*connector
,
390 struct drm_display_mode
*mode
)
392 list_add(&mode
->head
, &connector
->probed_modes
);
394 EXPORT_SYMBOL(drm_mode_probed_add
);
397 * drm_mode_remove - remove and free a mode
398 * @connector: connector list to modify
399 * @mode: mode to remove
402 * Caller must hold mode config lock.
404 * Remove @mode from @connector's mode list, then free it.
406 void drm_mode_remove(struct drm_connector
*connector
,
407 struct drm_display_mode
*mode
)
409 list_del(&mode
->head
);
412 EXPORT_SYMBOL(drm_mode_remove
);
415 * drm_connector_init - Init a preallocated connector
417 * @connector: the connector to init
418 * @funcs: callbacks for this connector
419 * @name: user visible name of the connector
422 * Caller must hold @dev's mode_config lock.
424 * Initialises a preallocated connector. Connectors should be
425 * subclassed as part of driver connector objects.
427 void drm_connector_init(struct drm_device
*dev
,
428 struct drm_connector
*connector
,
429 const struct drm_connector_funcs
*funcs
,
432 mutex_lock(&dev
->mode_config
.mutex
);
434 connector
->dev
= dev
;
435 connector
->funcs
= funcs
;
436 drm_mode_object_get(dev
, &connector
->base
, DRM_MODE_OBJECT_CONNECTOR
);
437 connector
->connector_type
= connector_type
;
438 connector
->connector_type_id
=
439 ++drm_connector_enum_list
[connector_type
].count
; /* TODO */
440 INIT_LIST_HEAD(&connector
->user_modes
);
441 INIT_LIST_HEAD(&connector
->probed_modes
);
442 INIT_LIST_HEAD(&connector
->modes
);
443 connector
->edid_blob_ptr
= NULL
;
445 list_add_tail(&connector
->head
, &dev
->mode_config
.connector_list
);
446 dev
->mode_config
.num_connector
++;
448 drm_connector_attach_property(connector
,
449 dev
->mode_config
.edid_property
, 0);
451 drm_connector_attach_property(connector
,
452 dev
->mode_config
.dpms_property
, 0);
454 mutex_unlock(&dev
->mode_config
.mutex
);
456 EXPORT_SYMBOL(drm_connector_init
);
459 * drm_connector_cleanup - cleans up an initialised connector
460 * @connector: connector to cleanup
463 * Caller must hold @dev's mode_config lock.
465 * Cleans up the connector but doesn't free the object.
467 void drm_connector_cleanup(struct drm_connector
*connector
)
469 struct drm_device
*dev
= connector
->dev
;
470 struct drm_display_mode
*mode
, *t
;
472 list_for_each_entry_safe(mode
, t
, &connector
->probed_modes
, head
)
473 drm_mode_remove(connector
, mode
);
475 list_for_each_entry_safe(mode
, t
, &connector
->modes
, head
)
476 drm_mode_remove(connector
, mode
);
478 list_for_each_entry_safe(mode
, t
, &connector
->user_modes
, head
)
479 drm_mode_remove(connector
, mode
);
481 mutex_lock(&dev
->mode_config
.mutex
);
482 drm_mode_object_put(dev
, &connector
->base
);
483 list_del(&connector
->head
);
484 mutex_unlock(&dev
->mode_config
.mutex
);
486 EXPORT_SYMBOL(drm_connector_cleanup
);
488 void drm_encoder_init(struct drm_device
*dev
,
489 struct drm_encoder
*encoder
,
490 const struct drm_encoder_funcs
*funcs
,
493 mutex_lock(&dev
->mode_config
.mutex
);
497 drm_mode_object_get(dev
, &encoder
->base
, DRM_MODE_OBJECT_ENCODER
);
498 encoder
->encoder_type
= encoder_type
;
499 encoder
->funcs
= funcs
;
501 list_add_tail(&encoder
->head
, &dev
->mode_config
.encoder_list
);
502 dev
->mode_config
.num_encoder
++;
504 mutex_unlock(&dev
->mode_config
.mutex
);
506 EXPORT_SYMBOL(drm_encoder_init
);
508 void drm_encoder_cleanup(struct drm_encoder
*encoder
)
510 struct drm_device
*dev
= encoder
->dev
;
511 mutex_lock(&dev
->mode_config
.mutex
);
512 drm_mode_object_put(dev
, &encoder
->base
);
513 list_del(&encoder
->head
);
514 mutex_unlock(&dev
->mode_config
.mutex
);
516 EXPORT_SYMBOL(drm_encoder_cleanup
);
519 * drm_mode_create - create a new display mode
523 * Caller must hold DRM mode_config lock.
525 * Create a new drm_display_mode, give it an ID, and return it.
528 * Pointer to new mode on success, NULL on error.
530 struct drm_display_mode
*drm_mode_create(struct drm_device
*dev
)
532 struct drm_display_mode
*nmode
;
534 nmode
= kzalloc(sizeof(struct drm_display_mode
), GFP_KERNEL
);
538 drm_mode_object_get(dev
, &nmode
->base
, DRM_MODE_OBJECT_MODE
);
541 EXPORT_SYMBOL(drm_mode_create
);
544 * drm_mode_destroy - remove a mode
546 * @mode: mode to remove
549 * Caller must hold mode config lock.
551 * Free @mode's unique identifier, then free it.
553 void drm_mode_destroy(struct drm_device
*dev
, struct drm_display_mode
*mode
)
555 drm_mode_object_put(dev
, &mode
->base
);
559 EXPORT_SYMBOL(drm_mode_destroy
);
561 static int drm_mode_create_standard_connector_properties(struct drm_device
*dev
)
563 struct drm_property
*edid
;
564 struct drm_property
*dpms
;
568 * Standard properties (apply to all connectors)
570 edid
= drm_property_create(dev
, DRM_MODE_PROP_BLOB
|
571 DRM_MODE_PROP_IMMUTABLE
,
573 dev
->mode_config
.edid_property
= edid
;
575 dpms
= drm_property_create(dev
, DRM_MODE_PROP_ENUM
,
576 "DPMS", ARRAY_SIZE(drm_dpms_enum_list
));
577 for (i
= 0; i
< ARRAY_SIZE(drm_dpms_enum_list
); i
++)
578 drm_property_add_enum(dpms
, i
, drm_dpms_enum_list
[i
].type
,
579 drm_dpms_enum_list
[i
].name
);
580 dev
->mode_config
.dpms_property
= dpms
;
586 * drm_mode_create_dvi_i_properties - create DVI-I specific connector properties
589 * Called by a driver the first time a DVI-I connector is made.
591 int drm_mode_create_dvi_i_properties(struct drm_device
*dev
)
593 struct drm_property
*dvi_i_selector
;
594 struct drm_property
*dvi_i_subconnector
;
597 if (dev
->mode_config
.dvi_i_select_subconnector_property
)
601 drm_property_create(dev
, DRM_MODE_PROP_ENUM
,
602 "select subconnector",
603 ARRAY_SIZE(drm_dvi_i_select_enum_list
));
604 for (i
= 0; i
< ARRAY_SIZE(drm_dvi_i_select_enum_list
); i
++)
605 drm_property_add_enum(dvi_i_selector
, i
,
606 drm_dvi_i_select_enum_list
[i
].type
,
607 drm_dvi_i_select_enum_list
[i
].name
);
608 dev
->mode_config
.dvi_i_select_subconnector_property
= dvi_i_selector
;
611 drm_property_create(dev
, DRM_MODE_PROP_ENUM
|
612 DRM_MODE_PROP_IMMUTABLE
,
614 ARRAY_SIZE(drm_dvi_i_subconnector_enum_list
));
615 for (i
= 0; i
< ARRAY_SIZE(drm_dvi_i_subconnector_enum_list
); i
++)
616 drm_property_add_enum(dvi_i_subconnector
, i
,
617 drm_dvi_i_subconnector_enum_list
[i
].type
,
618 drm_dvi_i_subconnector_enum_list
[i
].name
);
619 dev
->mode_config
.dvi_i_subconnector_property
= dvi_i_subconnector
;
623 EXPORT_SYMBOL(drm_mode_create_dvi_i_properties
);
626 * drm_create_tv_properties - create TV specific connector properties
628 * @num_modes: number of different TV formats (modes) supported
629 * @modes: array of pointers to strings containing name of each format
631 * Called by a driver's TV initialization routine, this function creates
632 * the TV specific connector properties for a given device. Caller is
633 * responsible for allocating a list of format names and passing them to
636 int drm_mode_create_tv_properties(struct drm_device
*dev
, int num_modes
,
639 struct drm_property
*tv_selector
;
640 struct drm_property
*tv_subconnector
;
643 if (dev
->mode_config
.tv_select_subconnector_property
)
647 * Basic connector properties
649 tv_selector
= drm_property_create(dev
, DRM_MODE_PROP_ENUM
,
650 "select subconnector",
651 ARRAY_SIZE(drm_tv_select_enum_list
));
652 for (i
= 0; i
< ARRAY_SIZE(drm_tv_select_enum_list
); i
++)
653 drm_property_add_enum(tv_selector
, i
,
654 drm_tv_select_enum_list
[i
].type
,
655 drm_tv_select_enum_list
[i
].name
);
656 dev
->mode_config
.tv_select_subconnector_property
= tv_selector
;
659 drm_property_create(dev
, DRM_MODE_PROP_ENUM
|
660 DRM_MODE_PROP_IMMUTABLE
, "subconnector",
661 ARRAY_SIZE(drm_tv_subconnector_enum_list
));
662 for (i
= 0; i
< ARRAY_SIZE(drm_tv_subconnector_enum_list
); i
++)
663 drm_property_add_enum(tv_subconnector
, i
,
664 drm_tv_subconnector_enum_list
[i
].type
,
665 drm_tv_subconnector_enum_list
[i
].name
);
666 dev
->mode_config
.tv_subconnector_property
= tv_subconnector
;
669 * Other, TV specific properties: margins & TV modes.
671 dev
->mode_config
.tv_left_margin_property
=
672 drm_property_create(dev
, DRM_MODE_PROP_RANGE
,
674 dev
->mode_config
.tv_left_margin_property
->values
[0] = 0;
675 dev
->mode_config
.tv_left_margin_property
->values
[1] = 100;
677 dev
->mode_config
.tv_right_margin_property
=
678 drm_property_create(dev
, DRM_MODE_PROP_RANGE
,
680 dev
->mode_config
.tv_right_margin_property
->values
[0] = 0;
681 dev
->mode_config
.tv_right_margin_property
->values
[1] = 100;
683 dev
->mode_config
.tv_top_margin_property
=
684 drm_property_create(dev
, DRM_MODE_PROP_RANGE
,
686 dev
->mode_config
.tv_top_margin_property
->values
[0] = 0;
687 dev
->mode_config
.tv_top_margin_property
->values
[1] = 100;
689 dev
->mode_config
.tv_bottom_margin_property
=
690 drm_property_create(dev
, DRM_MODE_PROP_RANGE
,
692 dev
->mode_config
.tv_bottom_margin_property
->values
[0] = 0;
693 dev
->mode_config
.tv_bottom_margin_property
->values
[1] = 100;
695 dev
->mode_config
.tv_mode_property
=
696 drm_property_create(dev
, DRM_MODE_PROP_ENUM
,
698 for (i
= 0; i
< num_modes
; i
++)
699 drm_property_add_enum(dev
->mode_config
.tv_mode_property
, i
,
704 EXPORT_SYMBOL(drm_mode_create_tv_properties
);
707 * drm_mode_create_scaling_mode_property - create scaling mode property
710 * Called by a driver the first time it's needed, must be attached to desired
713 int drm_mode_create_scaling_mode_property(struct drm_device
*dev
)
715 struct drm_property
*scaling_mode
;
718 if (dev
->mode_config
.scaling_mode_property
)
722 drm_property_create(dev
, DRM_MODE_PROP_ENUM
, "scaling mode",
723 ARRAY_SIZE(drm_scaling_mode_enum_list
));
724 for (i
= 0; i
< ARRAY_SIZE(drm_scaling_mode_enum_list
); i
++)
725 drm_property_add_enum(scaling_mode
, i
,
726 drm_scaling_mode_enum_list
[i
].type
,
727 drm_scaling_mode_enum_list
[i
].name
);
729 dev
->mode_config
.scaling_mode_property
= scaling_mode
;
733 EXPORT_SYMBOL(drm_mode_create_scaling_mode_property
);
736 * drm_mode_create_dithering_property - create dithering property
739 * Called by a driver the first time it's needed, must be attached to desired
742 int drm_mode_create_dithering_property(struct drm_device
*dev
)
744 struct drm_property
*dithering_mode
;
747 if (dev
->mode_config
.dithering_mode_property
)
751 drm_property_create(dev
, DRM_MODE_PROP_ENUM
, "dithering",
752 ARRAY_SIZE(drm_dithering_mode_enum_list
));
753 for (i
= 0; i
< ARRAY_SIZE(drm_dithering_mode_enum_list
); i
++)
754 drm_property_add_enum(dithering_mode
, i
,
755 drm_dithering_mode_enum_list
[i
].type
,
756 drm_dithering_mode_enum_list
[i
].name
);
757 dev
->mode_config
.dithering_mode_property
= dithering_mode
;
761 EXPORT_SYMBOL(drm_mode_create_dithering_property
);
764 * drm_mode_config_init - initialize DRM mode_configuration structure
768 * None, should happen single threaded at init time.
770 * Initialize @dev's mode_config structure, used for tracking the graphics
771 * configuration of @dev.
773 void drm_mode_config_init(struct drm_device
*dev
)
775 mutex_init(&dev
->mode_config
.mutex
);
776 mutex_init(&dev
->mode_config
.idr_mutex
);
777 INIT_LIST_HEAD(&dev
->mode_config
.fb_list
);
778 INIT_LIST_HEAD(&dev
->mode_config
.fb_kernel_list
);
779 INIT_LIST_HEAD(&dev
->mode_config
.crtc_list
);
780 INIT_LIST_HEAD(&dev
->mode_config
.connector_list
);
781 INIT_LIST_HEAD(&dev
->mode_config
.encoder_list
);
782 INIT_LIST_HEAD(&dev
->mode_config
.property_list
);
783 INIT_LIST_HEAD(&dev
->mode_config
.property_blob_list
);
784 idr_init(&dev
->mode_config
.crtc_idr
);
786 mutex_lock(&dev
->mode_config
.mutex
);
787 drm_mode_create_standard_connector_properties(dev
);
788 mutex_unlock(&dev
->mode_config
.mutex
);
790 /* Just to be sure */
791 dev
->mode_config
.num_fb
= 0;
792 dev
->mode_config
.num_connector
= 0;
793 dev
->mode_config
.num_crtc
= 0;
794 dev
->mode_config
.num_encoder
= 0;
796 EXPORT_SYMBOL(drm_mode_config_init
);
798 int drm_mode_group_init(struct drm_device
*dev
, struct drm_mode_group
*group
)
800 uint32_t total_objects
= 0;
802 total_objects
+= dev
->mode_config
.num_crtc
;
803 total_objects
+= dev
->mode_config
.num_connector
;
804 total_objects
+= dev
->mode_config
.num_encoder
;
806 if (total_objects
== 0)
809 group
->id_list
= kzalloc(total_objects
* sizeof(uint32_t), GFP_KERNEL
);
813 group
->num_crtcs
= 0;
814 group
->num_connectors
= 0;
815 group
->num_encoders
= 0;
819 int drm_mode_group_init_legacy_group(struct drm_device
*dev
,
820 struct drm_mode_group
*group
)
822 struct drm_crtc
*crtc
;
823 struct drm_encoder
*encoder
;
824 struct drm_connector
*connector
;
827 if ((ret
= drm_mode_group_init(dev
, group
)))
830 list_for_each_entry(crtc
, &dev
->mode_config
.crtc_list
, head
)
831 group
->id_list
[group
->num_crtcs
++] = crtc
->base
.id
;
833 list_for_each_entry(encoder
, &dev
->mode_config
.encoder_list
, head
)
834 group
->id_list
[group
->num_crtcs
+ group
->num_encoders
++] =
837 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
, head
)
838 group
->id_list
[group
->num_crtcs
+ group
->num_encoders
+
839 group
->num_connectors
++] = connector
->base
.id
;
845 * drm_mode_config_cleanup - free up DRM mode_config info
849 * Caller must hold mode config lock.
851 * Free up all the connectors and CRTCs associated with this DRM device, then
852 * free up the framebuffers and associated buffer objects.
854 * FIXME: cleanup any dangling user buffer objects too
856 void drm_mode_config_cleanup(struct drm_device
*dev
)
858 struct drm_connector
*connector
, *ot
;
859 struct drm_crtc
*crtc
, *ct
;
860 struct drm_encoder
*encoder
, *enct
;
861 struct drm_framebuffer
*fb
, *fbt
;
862 struct drm_property
*property
, *pt
;
864 list_for_each_entry_safe(encoder
, enct
, &dev
->mode_config
.encoder_list
,
866 encoder
->funcs
->destroy(encoder
);
869 list_for_each_entry_safe(connector
, ot
,
870 &dev
->mode_config
.connector_list
, head
) {
871 connector
->funcs
->destroy(connector
);
874 list_for_each_entry_safe(property
, pt
, &dev
->mode_config
.property_list
,
876 drm_property_destroy(dev
, property
);
879 list_for_each_entry_safe(fb
, fbt
, &dev
->mode_config
.fb_list
, head
) {
880 fb
->funcs
->destroy(fb
);
883 list_for_each_entry_safe(crtc
, ct
, &dev
->mode_config
.crtc_list
, head
) {
884 crtc
->funcs
->destroy(crtc
);
888 EXPORT_SYMBOL(drm_mode_config_cleanup
);
891 * drm_crtc_convert_to_umode - convert a drm_display_mode into a modeinfo
892 * @out: drm_mode_modeinfo struct to return to the user
893 * @in: drm_display_mode to use
898 * Convert a drm_display_mode into a drm_mode_modeinfo structure to return to
901 void drm_crtc_convert_to_umode(struct drm_mode_modeinfo
*out
,
902 struct drm_display_mode
*in
)
904 out
->clock
= in
->clock
;
905 out
->hdisplay
= in
->hdisplay
;
906 out
->hsync_start
= in
->hsync_start
;
907 out
->hsync_end
= in
->hsync_end
;
908 out
->htotal
= in
->htotal
;
909 out
->hskew
= in
->hskew
;
910 out
->vdisplay
= in
->vdisplay
;
911 out
->vsync_start
= in
->vsync_start
;
912 out
->vsync_end
= in
->vsync_end
;
913 out
->vtotal
= in
->vtotal
;
914 out
->vscan
= in
->vscan
;
915 out
->vrefresh
= in
->vrefresh
;
916 out
->flags
= in
->flags
;
917 out
->type
= in
->type
;
918 strncpy(out
->name
, in
->name
, DRM_DISPLAY_MODE_LEN
);
919 out
->name
[DRM_DISPLAY_MODE_LEN
-1] = 0;
923 * drm_crtc_convert_to_umode - convert a modeinfo into a drm_display_mode
924 * @out: drm_display_mode to return to the user
925 * @in: drm_mode_modeinfo to use
930 * Convert a drm_mode_modeinfo into a drm_display_mode structure to return to
933 void drm_crtc_convert_umode(struct drm_display_mode
*out
,
934 struct drm_mode_modeinfo
*in
)
936 out
->clock
= in
->clock
;
937 out
->hdisplay
= in
->hdisplay
;
938 out
->hsync_start
= in
->hsync_start
;
939 out
->hsync_end
= in
->hsync_end
;
940 out
->htotal
= in
->htotal
;
941 out
->hskew
= in
->hskew
;
942 out
->vdisplay
= in
->vdisplay
;
943 out
->vsync_start
= in
->vsync_start
;
944 out
->vsync_end
= in
->vsync_end
;
945 out
->vtotal
= in
->vtotal
;
946 out
->vscan
= in
->vscan
;
947 out
->vrefresh
= in
->vrefresh
;
948 out
->flags
= in
->flags
;
949 out
->type
= in
->type
;
950 strncpy(out
->name
, in
->name
, DRM_DISPLAY_MODE_LEN
);
951 out
->name
[DRM_DISPLAY_MODE_LEN
-1] = 0;
955 * drm_mode_getresources - get graphics configuration
956 * @inode: inode from the ioctl
957 * @filp: file * from the ioctl
958 * @cmd: cmd from ioctl
959 * @arg: arg from ioctl
962 * Takes mode config lock.
964 * Construct a set of configuration description structures and return
965 * them to the user, including CRTC, connector and framebuffer configuration.
967 * Called by the user via ioctl.
970 * Zero on success, errno on failure.
972 int drm_mode_getresources(struct drm_device
*dev
, void *data
,
973 struct drm_file
*file_priv
)
975 struct drm_mode_card_res
*card_res
= data
;
976 struct list_head
*lh
;
977 struct drm_framebuffer
*fb
;
978 struct drm_connector
*connector
;
979 struct drm_crtc
*crtc
;
980 struct drm_encoder
*encoder
;
982 int connector_count
= 0;
985 int encoder_count
= 0;
987 uint32_t __user
*fb_id
;
988 uint32_t __user
*crtc_id
;
989 uint32_t __user
*connector_id
;
990 uint32_t __user
*encoder_id
;
991 struct drm_mode_group
*mode_group
;
993 mutex_lock(&dev
->mode_config
.mutex
);
996 * For the non-control nodes we need to limit the list of resources
997 * by IDs in the group list for this node
999 list_for_each(lh
, &file_priv
->fbs
)
1002 mode_group
= &file_priv
->master
->minor
->mode_group
;
1003 if (file_priv
->master
->minor
->type
== DRM_MINOR_CONTROL
) {
1005 list_for_each(lh
, &dev
->mode_config
.crtc_list
)
1008 list_for_each(lh
, &dev
->mode_config
.connector_list
)
1011 list_for_each(lh
, &dev
->mode_config
.encoder_list
)
1015 crtc_count
= mode_group
->num_crtcs
;
1016 connector_count
= mode_group
->num_connectors
;
1017 encoder_count
= mode_group
->num_encoders
;
1020 card_res
->max_height
= dev
->mode_config
.max_height
;
1021 card_res
->min_height
= dev
->mode_config
.min_height
;
1022 card_res
->max_width
= dev
->mode_config
.max_width
;
1023 card_res
->min_width
= dev
->mode_config
.min_width
;
1025 /* handle this in 4 parts */
1027 if (card_res
->count_fbs
>= fb_count
) {
1029 fb_id
= (uint32_t __user
*)(unsigned long)card_res
->fb_id_ptr
;
1030 list_for_each_entry(fb
, &file_priv
->fbs
, head
) {
1031 if (put_user(fb
->base
.id
, fb_id
+ copied
)) {
1038 card_res
->count_fbs
= fb_count
;
1041 if (card_res
->count_crtcs
>= crtc_count
) {
1043 crtc_id
= (uint32_t __user
*)(unsigned long)card_res
->crtc_id_ptr
;
1044 if (file_priv
->master
->minor
->type
== DRM_MINOR_CONTROL
) {
1045 list_for_each_entry(crtc
, &dev
->mode_config
.crtc_list
,
1047 DRM_DEBUG("CRTC ID is %d\n", crtc
->base
.id
);
1048 if (put_user(crtc
->base
.id
, crtc_id
+ copied
)) {
1055 for (i
= 0; i
< mode_group
->num_crtcs
; i
++) {
1056 if (put_user(mode_group
->id_list
[i
],
1057 crtc_id
+ copied
)) {
1065 card_res
->count_crtcs
= crtc_count
;
1068 if (card_res
->count_encoders
>= encoder_count
) {
1070 encoder_id
= (uint32_t __user
*)(unsigned long)card_res
->encoder_id_ptr
;
1071 if (file_priv
->master
->minor
->type
== DRM_MINOR_CONTROL
) {
1072 list_for_each_entry(encoder
,
1073 &dev
->mode_config
.encoder_list
,
1075 DRM_DEBUG("ENCODER ID is %d\n",
1077 if (put_user(encoder
->base
.id
, encoder_id
+
1085 for (i
= mode_group
->num_crtcs
; i
< mode_group
->num_crtcs
+ mode_group
->num_encoders
; i
++) {
1086 if (put_user(mode_group
->id_list
[i
],
1087 encoder_id
+ copied
)) {
1096 card_res
->count_encoders
= encoder_count
;
1099 if (card_res
->count_connectors
>= connector_count
) {
1101 connector_id
= (uint32_t __user
*)(unsigned long)card_res
->connector_id_ptr
;
1102 if (file_priv
->master
->minor
->type
== DRM_MINOR_CONTROL
) {
1103 list_for_each_entry(connector
,
1104 &dev
->mode_config
.connector_list
,
1106 DRM_DEBUG("CONNECTOR ID is %d\n",
1107 connector
->base
.id
);
1108 if (put_user(connector
->base
.id
,
1109 connector_id
+ copied
)) {
1116 int start
= mode_group
->num_crtcs
+
1117 mode_group
->num_encoders
;
1118 for (i
= start
; i
< start
+ mode_group
->num_connectors
; i
++) {
1119 if (put_user(mode_group
->id_list
[i
],
1120 connector_id
+ copied
)) {
1128 card_res
->count_connectors
= connector_count
;
1130 DRM_DEBUG("Counted %d %d %d\n", card_res
->count_crtcs
,
1131 card_res
->count_connectors
, card_res
->count_encoders
);
1134 mutex_unlock(&dev
->mode_config
.mutex
);
1139 * drm_mode_getcrtc - get CRTC configuration
1140 * @inode: inode from the ioctl
1141 * @filp: file * from the ioctl
1142 * @cmd: cmd from ioctl
1143 * @arg: arg from ioctl
1148 * Construct a CRTC configuration structure to return to the user.
1150 * Called by the user via ioctl.
1153 * Zero on success, errno on failure.
1155 int drm_mode_getcrtc(struct drm_device
*dev
,
1156 void *data
, struct drm_file
*file_priv
)
1158 struct drm_mode_crtc
*crtc_resp
= data
;
1159 struct drm_crtc
*crtc
;
1160 struct drm_mode_object
*obj
;
1163 mutex_lock(&dev
->mode_config
.mutex
);
1165 obj
= drm_mode_object_find(dev
, crtc_resp
->crtc_id
,
1166 DRM_MODE_OBJECT_CRTC
);
1171 crtc
= obj_to_crtc(obj
);
1173 crtc_resp
->x
= crtc
->x
;
1174 crtc_resp
->y
= crtc
->y
;
1175 crtc_resp
->gamma_size
= crtc
->gamma_size
;
1177 crtc_resp
->fb_id
= crtc
->fb
->base
.id
;
1179 crtc_resp
->fb_id
= 0;
1181 if (crtc
->enabled
) {
1183 drm_crtc_convert_to_umode(&crtc_resp
->mode
, &crtc
->mode
);
1184 crtc_resp
->mode_valid
= 1;
1187 crtc_resp
->mode_valid
= 0;
1191 mutex_unlock(&dev
->mode_config
.mutex
);
1196 * drm_mode_getconnector - get connector configuration
1197 * @inode: inode from the ioctl
1198 * @filp: file * from the ioctl
1199 * @cmd: cmd from ioctl
1200 * @arg: arg from ioctl
1205 * Construct a connector configuration structure to return to the user.
1207 * Called by the user via ioctl.
1210 * Zero on success, errno on failure.
1212 int drm_mode_getconnector(struct drm_device
*dev
, void *data
,
1213 struct drm_file
*file_priv
)
1215 struct drm_mode_get_connector
*out_resp
= data
;
1216 struct drm_mode_object
*obj
;
1217 struct drm_connector
*connector
;
1218 struct drm_display_mode
*mode
;
1220 int props_count
= 0;
1221 int encoders_count
= 0;
1225 struct drm_mode_modeinfo u_mode
;
1226 struct drm_mode_modeinfo __user
*mode_ptr
;
1227 uint32_t __user
*prop_ptr
;
1228 uint64_t __user
*prop_values
;
1229 uint32_t __user
*encoder_ptr
;
1231 memset(&u_mode
, 0, sizeof(struct drm_mode_modeinfo
));
1233 DRM_DEBUG("connector id %d:\n", out_resp
->connector_id
);
1235 mutex_lock(&dev
->mode_config
.mutex
);
1237 obj
= drm_mode_object_find(dev
, out_resp
->connector_id
,
1238 DRM_MODE_OBJECT_CONNECTOR
);
1243 connector
= obj_to_connector(obj
);
1245 for (i
= 0; i
< DRM_CONNECTOR_MAX_PROPERTY
; i
++) {
1246 if (connector
->property_ids
[i
] != 0) {
1251 for (i
= 0; i
< DRM_CONNECTOR_MAX_ENCODER
; i
++) {
1252 if (connector
->encoder_ids
[i
] != 0) {
1257 if (out_resp
->count_modes
== 0) {
1258 connector
->funcs
->fill_modes(connector
,
1259 dev
->mode_config
.max_width
,
1260 dev
->mode_config
.max_height
);
1263 /* delayed so we get modes regardless of pre-fill_modes state */
1264 list_for_each_entry(mode
, &connector
->modes
, head
)
1267 out_resp
->connector_id
= connector
->base
.id
;
1268 out_resp
->connector_type
= connector
->connector_type
;
1269 out_resp
->connector_type_id
= connector
->connector_type_id
;
1270 out_resp
->mm_width
= connector
->display_info
.width_mm
;
1271 out_resp
->mm_height
= connector
->display_info
.height_mm
;
1272 out_resp
->subpixel
= connector
->display_info
.subpixel_order
;
1273 out_resp
->connection
= connector
->status
;
1274 if (connector
->encoder
)
1275 out_resp
->encoder_id
= connector
->encoder
->base
.id
;
1277 out_resp
->encoder_id
= 0;
1280 * This ioctl is called twice, once to determine how much space is
1281 * needed, and the 2nd time to fill it.
1283 if ((out_resp
->count_modes
>= mode_count
) && mode_count
) {
1285 mode_ptr
= (struct drm_mode_modeinfo
*)(unsigned long)out_resp
->modes_ptr
;
1286 list_for_each_entry(mode
, &connector
->modes
, head
) {
1287 drm_crtc_convert_to_umode(&u_mode
, mode
);
1288 if (copy_to_user(mode_ptr
+ copied
,
1289 &u_mode
, sizeof(u_mode
))) {
1296 out_resp
->count_modes
= mode_count
;
1298 if ((out_resp
->count_props
>= props_count
) && props_count
) {
1300 prop_ptr
= (uint32_t *)(unsigned long)(out_resp
->props_ptr
);
1301 prop_values
= (uint64_t *)(unsigned long)(out_resp
->prop_values_ptr
);
1302 for (i
= 0; i
< DRM_CONNECTOR_MAX_PROPERTY
; i
++) {
1303 if (connector
->property_ids
[i
] != 0) {
1304 if (put_user(connector
->property_ids
[i
],
1305 prop_ptr
+ copied
)) {
1310 if (put_user(connector
->property_values
[i
],
1311 prop_values
+ copied
)) {
1319 out_resp
->count_props
= props_count
;
1321 if ((out_resp
->count_encoders
>= encoders_count
) && encoders_count
) {
1323 encoder_ptr
= (uint32_t *)(unsigned long)(out_resp
->encoders_ptr
);
1324 for (i
= 0; i
< DRM_CONNECTOR_MAX_ENCODER
; i
++) {
1325 if (connector
->encoder_ids
[i
] != 0) {
1326 if (put_user(connector
->encoder_ids
[i
],
1327 encoder_ptr
+ copied
)) {
1335 out_resp
->count_encoders
= encoders_count
;
1338 mutex_unlock(&dev
->mode_config
.mutex
);
1342 int drm_mode_getencoder(struct drm_device
*dev
, void *data
,
1343 struct drm_file
*file_priv
)
1345 struct drm_mode_get_encoder
*enc_resp
= data
;
1346 struct drm_mode_object
*obj
;
1347 struct drm_encoder
*encoder
;
1350 mutex_lock(&dev
->mode_config
.mutex
);
1351 obj
= drm_mode_object_find(dev
, enc_resp
->encoder_id
,
1352 DRM_MODE_OBJECT_ENCODER
);
1357 encoder
= obj_to_encoder(obj
);
1360 enc_resp
->crtc_id
= encoder
->crtc
->base
.id
;
1362 enc_resp
->crtc_id
= 0;
1363 enc_resp
->encoder_type
= encoder
->encoder_type
;
1364 enc_resp
->encoder_id
= encoder
->base
.id
;
1365 enc_resp
->possible_crtcs
= encoder
->possible_crtcs
;
1366 enc_resp
->possible_clones
= encoder
->possible_clones
;
1369 mutex_unlock(&dev
->mode_config
.mutex
);
1374 * drm_mode_setcrtc - set CRTC configuration
1375 * @inode: inode from the ioctl
1376 * @filp: file * from the ioctl
1377 * @cmd: cmd from ioctl
1378 * @arg: arg from ioctl
1383 * Build a new CRTC configuration based on user request.
1385 * Called by the user via ioctl.
1388 * Zero on success, errno on failure.
1390 int drm_mode_setcrtc(struct drm_device
*dev
, void *data
,
1391 struct drm_file
*file_priv
)
1393 struct drm_mode_config
*config
= &dev
->mode_config
;
1394 struct drm_mode_crtc
*crtc_req
= data
;
1395 struct drm_mode_object
*obj
;
1396 struct drm_crtc
*crtc
, *crtcfb
;
1397 struct drm_connector
**connector_set
= NULL
, *connector
;
1398 struct drm_framebuffer
*fb
= NULL
;
1399 struct drm_display_mode
*mode
= NULL
;
1400 struct drm_mode_set set
;
1401 uint32_t __user
*set_connectors_ptr
;
1405 mutex_lock(&dev
->mode_config
.mutex
);
1406 obj
= drm_mode_object_find(dev
, crtc_req
->crtc_id
,
1407 DRM_MODE_OBJECT_CRTC
);
1409 DRM_DEBUG("Unknown CRTC ID %d\n", crtc_req
->crtc_id
);
1413 crtc
= obj_to_crtc(obj
);
1415 if (crtc_req
->mode_valid
) {
1416 /* If we have a mode we need a framebuffer. */
1417 /* If we pass -1, set the mode with the currently bound fb */
1418 if (crtc_req
->fb_id
== -1) {
1419 list_for_each_entry(crtcfb
,
1420 &dev
->mode_config
.crtc_list
, head
) {
1421 if (crtcfb
== crtc
) {
1422 DRM_DEBUG("Using current fb for setmode\n");
1427 obj
= drm_mode_object_find(dev
, crtc_req
->fb_id
,
1428 DRM_MODE_OBJECT_FB
);
1430 DRM_DEBUG("Unknown FB ID%d\n", crtc_req
->fb_id
);
1434 fb
= obj_to_fb(obj
);
1437 mode
= drm_mode_create(dev
);
1438 drm_crtc_convert_umode(mode
, &crtc_req
->mode
);
1439 drm_mode_set_crtcinfo(mode
, CRTC_INTERLACE_HALVE_V
);
1442 if (crtc_req
->count_connectors
== 0 && mode
) {
1443 DRM_DEBUG("Count connectors is 0 but mode set\n");
1448 if (crtc_req
->count_connectors
> 0 && (!mode
|| !fb
)) {
1449 DRM_DEBUG("Count connectors is %d but no mode or fb set\n",
1450 crtc_req
->count_connectors
);
1455 if (crtc_req
->count_connectors
> 0) {
1458 /* Avoid unbounded kernel memory allocation */
1459 if (crtc_req
->count_connectors
> config
->num_connector
) {
1464 connector_set
= kmalloc(crtc_req
->count_connectors
*
1465 sizeof(struct drm_connector
*),
1467 if (!connector_set
) {
1472 for (i
= 0; i
< crtc_req
->count_connectors
; i
++) {
1473 set_connectors_ptr
= (uint32_t *)(unsigned long)crtc_req
->set_connectors_ptr
;
1474 if (get_user(out_id
, &set_connectors_ptr
[i
])) {
1479 obj
= drm_mode_object_find(dev
, out_id
,
1480 DRM_MODE_OBJECT_CONNECTOR
);
1482 DRM_DEBUG("Connector id %d unknown\n", out_id
);
1486 connector
= obj_to_connector(obj
);
1488 connector_set
[i
] = connector
;
1493 set
.x
= crtc_req
->x
;
1494 set
.y
= crtc_req
->y
;
1496 set
.connectors
= connector_set
;
1497 set
.num_connectors
= crtc_req
->count_connectors
;
1499 ret
= crtc
->funcs
->set_config(&set
);
1502 kfree(connector_set
);
1503 mutex_unlock(&dev
->mode_config
.mutex
);
1507 int drm_mode_cursor_ioctl(struct drm_device
*dev
,
1508 void *data
, struct drm_file
*file_priv
)
1510 struct drm_mode_cursor
*req
= data
;
1511 struct drm_mode_object
*obj
;
1512 struct drm_crtc
*crtc
;
1518 DRM_ERROR("no operation set\n");
1522 mutex_lock(&dev
->mode_config
.mutex
);
1523 obj
= drm_mode_object_find(dev
, req
->crtc_id
, DRM_MODE_OBJECT_CRTC
);
1525 DRM_DEBUG("Unknown CRTC ID %d\n", req
->crtc_id
);
1529 crtc
= obj_to_crtc(obj
);
1531 if (req
->flags
& DRM_MODE_CURSOR_BO
) {
1532 if (!crtc
->funcs
->cursor_set
) {
1533 DRM_ERROR("crtc does not support cursor\n");
1537 /* Turns off the cursor if handle is 0 */
1538 ret
= crtc
->funcs
->cursor_set(crtc
, file_priv
, req
->handle
,
1539 req
->width
, req
->height
);
1542 if (req
->flags
& DRM_MODE_CURSOR_MOVE
) {
1543 if (crtc
->funcs
->cursor_move
) {
1544 ret
= crtc
->funcs
->cursor_move(crtc
, req
->x
, req
->y
);
1546 DRM_ERROR("crtc does not support cursor\n");
1552 mutex_unlock(&dev
->mode_config
.mutex
);
1557 * drm_mode_addfb - add an FB to the graphics configuration
1558 * @inode: inode from the ioctl
1559 * @filp: file * from the ioctl
1560 * @cmd: cmd from ioctl
1561 * @arg: arg from ioctl
1564 * Takes mode config lock.
1566 * Add a new FB to the specified CRTC, given a user request.
1568 * Called by the user via ioctl.
1571 * Zero on success, errno on failure.
1573 int drm_mode_addfb(struct drm_device
*dev
,
1574 void *data
, struct drm_file
*file_priv
)
1576 struct drm_mode_fb_cmd
*r
= data
;
1577 struct drm_mode_config
*config
= &dev
->mode_config
;
1578 struct drm_framebuffer
*fb
;
1581 if ((config
->min_width
> r
->width
) || (r
->width
> config
->max_width
)) {
1582 DRM_ERROR("mode new framebuffer width not within limits\n");
1585 if ((config
->min_height
> r
->height
) || (r
->height
> config
->max_height
)) {
1586 DRM_ERROR("mode new framebuffer height not within limits\n");
1590 mutex_lock(&dev
->mode_config
.mutex
);
1592 /* TODO check buffer is sufficently large */
1593 /* TODO setup destructor callback */
1595 fb
= dev
->mode_config
.funcs
->fb_create(dev
, file_priv
, r
);
1597 DRM_ERROR("could not create framebuffer\n");
1602 r
->fb_id
= fb
->base
.id
;
1603 list_add(&fb
->filp_head
, &file_priv
->fbs
);
1606 mutex_unlock(&dev
->mode_config
.mutex
);
1611 * drm_mode_rmfb - remove an FB from the configuration
1612 * @inode: inode from the ioctl
1613 * @filp: file * from the ioctl
1614 * @cmd: cmd from ioctl
1615 * @arg: arg from ioctl
1618 * Takes mode config lock.
1620 * Remove the FB specified by the user.
1622 * Called by the user via ioctl.
1625 * Zero on success, errno on failure.
1627 int drm_mode_rmfb(struct drm_device
*dev
,
1628 void *data
, struct drm_file
*file_priv
)
1630 struct drm_mode_object
*obj
;
1631 struct drm_framebuffer
*fb
= NULL
;
1632 struct drm_framebuffer
*fbl
= NULL
;
1633 uint32_t *id
= data
;
1637 mutex_lock(&dev
->mode_config
.mutex
);
1638 obj
= drm_mode_object_find(dev
, *id
, DRM_MODE_OBJECT_FB
);
1639 /* TODO check that we realy get a framebuffer back. */
1641 DRM_ERROR("mode invalid framebuffer id\n");
1645 fb
= obj_to_fb(obj
);
1647 list_for_each_entry(fbl
, &file_priv
->fbs
, filp_head
)
1652 DRM_ERROR("tried to remove a fb that we didn't own\n");
1657 /* TODO release all crtc connected to the framebuffer */
1658 /* TODO unhock the destructor from the buffer object */
1660 list_del(&fb
->filp_head
);
1661 fb
->funcs
->destroy(fb
);
1664 mutex_unlock(&dev
->mode_config
.mutex
);
1669 * drm_mode_getfb - get FB info
1670 * @inode: inode from the ioctl
1671 * @filp: file * from the ioctl
1672 * @cmd: cmd from ioctl
1673 * @arg: arg from ioctl
1678 * Lookup the FB given its ID and return info about it.
1680 * Called by the user via ioctl.
1683 * Zero on success, errno on failure.
1685 int drm_mode_getfb(struct drm_device
*dev
,
1686 void *data
, struct drm_file
*file_priv
)
1688 struct drm_mode_fb_cmd
*r
= data
;
1689 struct drm_mode_object
*obj
;
1690 struct drm_framebuffer
*fb
;
1693 mutex_lock(&dev
->mode_config
.mutex
);
1694 obj
= drm_mode_object_find(dev
, r
->fb_id
, DRM_MODE_OBJECT_FB
);
1696 DRM_ERROR("invalid framebuffer id\n");
1700 fb
= obj_to_fb(obj
);
1702 r
->height
= fb
->height
;
1703 r
->width
= fb
->width
;
1704 r
->depth
= fb
->depth
;
1705 r
->bpp
= fb
->bits_per_pixel
;
1706 r
->pitch
= fb
->pitch
;
1707 fb
->funcs
->create_handle(fb
, file_priv
, &r
->handle
);
1710 mutex_unlock(&dev
->mode_config
.mutex
);
1715 * drm_fb_release - remove and free the FBs on this file
1716 * @filp: file * from the ioctl
1719 * Takes mode config lock.
1721 * Destroy all the FBs associated with @filp.
1723 * Called by the user via ioctl.
1726 * Zero on success, errno on failure.
1728 void drm_fb_release(struct drm_file
*priv
)
1730 struct drm_device
*dev
= priv
->minor
->dev
;
1731 struct drm_framebuffer
*fb
, *tfb
;
1733 mutex_lock(&dev
->mode_config
.mutex
);
1734 list_for_each_entry_safe(fb
, tfb
, &priv
->fbs
, filp_head
) {
1735 list_del(&fb
->filp_head
);
1736 fb
->funcs
->destroy(fb
);
1738 mutex_unlock(&dev
->mode_config
.mutex
);
1742 * drm_mode_attachmode - add a mode to the user mode list
1744 * @connector: connector to add the mode to
1745 * @mode: mode to add
1747 * Add @mode to @connector's user mode list.
1749 static int drm_mode_attachmode(struct drm_device
*dev
,
1750 struct drm_connector
*connector
,
1751 struct drm_display_mode
*mode
)
1755 list_add_tail(&mode
->head
, &connector
->user_modes
);
1759 int drm_mode_attachmode_crtc(struct drm_device
*dev
, struct drm_crtc
*crtc
,
1760 struct drm_display_mode
*mode
)
1762 struct drm_connector
*connector
;
1764 struct drm_display_mode
*dup_mode
;
1766 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
, head
) {
1767 if (!connector
->encoder
)
1769 if (connector
->encoder
->crtc
== crtc
) {
1771 dup_mode
= drm_mode_duplicate(dev
, mode
);
1774 ret
= drm_mode_attachmode(dev
, connector
, dup_mode
);
1782 EXPORT_SYMBOL(drm_mode_attachmode_crtc
);
1784 static int drm_mode_detachmode(struct drm_device
*dev
,
1785 struct drm_connector
*connector
,
1786 struct drm_display_mode
*mode
)
1790 struct drm_display_mode
*match_mode
, *t
;
1792 list_for_each_entry_safe(match_mode
, t
, &connector
->user_modes
, head
) {
1793 if (drm_mode_equal(match_mode
, mode
)) {
1794 list_del(&match_mode
->head
);
1795 drm_mode_destroy(dev
, match_mode
);
1807 int drm_mode_detachmode_crtc(struct drm_device
*dev
, struct drm_display_mode
*mode
)
1809 struct drm_connector
*connector
;
1811 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
, head
) {
1812 drm_mode_detachmode(dev
, connector
, mode
);
1816 EXPORT_SYMBOL(drm_mode_detachmode_crtc
);
1819 * drm_fb_attachmode - Attach a user mode to an connector
1820 * @inode: inode from the ioctl
1821 * @filp: file * from the ioctl
1822 * @cmd: cmd from ioctl
1823 * @arg: arg from ioctl
1825 * This attaches a user specified mode to an connector.
1826 * Called by the user via ioctl.
1829 * Zero on success, errno on failure.
1831 int drm_mode_attachmode_ioctl(struct drm_device
*dev
,
1832 void *data
, struct drm_file
*file_priv
)
1834 struct drm_mode_mode_cmd
*mode_cmd
= data
;
1835 struct drm_connector
*connector
;
1836 struct drm_display_mode
*mode
;
1837 struct drm_mode_object
*obj
;
1838 struct drm_mode_modeinfo
*umode
= &mode_cmd
->mode
;
1841 mutex_lock(&dev
->mode_config
.mutex
);
1843 obj
= drm_mode_object_find(dev
, mode_cmd
->connector_id
, DRM_MODE_OBJECT_CONNECTOR
);
1848 connector
= obj_to_connector(obj
);
1850 mode
= drm_mode_create(dev
);
1856 drm_crtc_convert_umode(mode
, umode
);
1858 ret
= drm_mode_attachmode(dev
, connector
, mode
);
1860 mutex_unlock(&dev
->mode_config
.mutex
);
1866 * drm_fb_detachmode - Detach a user specified mode from an connector
1867 * @inode: inode from the ioctl
1868 * @filp: file * from the ioctl
1869 * @cmd: cmd from ioctl
1870 * @arg: arg from ioctl
1872 * Called by the user via ioctl.
1875 * Zero on success, errno on failure.
1877 int drm_mode_detachmode_ioctl(struct drm_device
*dev
,
1878 void *data
, struct drm_file
*file_priv
)
1880 struct drm_mode_object
*obj
;
1881 struct drm_mode_mode_cmd
*mode_cmd
= data
;
1882 struct drm_connector
*connector
;
1883 struct drm_display_mode mode
;
1884 struct drm_mode_modeinfo
*umode
= &mode_cmd
->mode
;
1887 mutex_lock(&dev
->mode_config
.mutex
);
1889 obj
= drm_mode_object_find(dev
, mode_cmd
->connector_id
, DRM_MODE_OBJECT_CONNECTOR
);
1894 connector
= obj_to_connector(obj
);
1896 drm_crtc_convert_umode(&mode
, umode
);
1897 ret
= drm_mode_detachmode(dev
, connector
, &mode
);
1899 mutex_unlock(&dev
->mode_config
.mutex
);
1903 struct drm_property
*drm_property_create(struct drm_device
*dev
, int flags
,
1904 const char *name
, int num_values
)
1906 struct drm_property
*property
= NULL
;
1908 property
= kzalloc(sizeof(struct drm_property
), GFP_KERNEL
);
1913 property
->values
= kzalloc(sizeof(uint64_t)*num_values
, GFP_KERNEL
);
1914 if (!property
->values
)
1918 drm_mode_object_get(dev
, &property
->base
, DRM_MODE_OBJECT_PROPERTY
);
1919 property
->flags
= flags
;
1920 property
->num_values
= num_values
;
1921 INIT_LIST_HEAD(&property
->enum_blob_list
);
1924 strncpy(property
->name
, name
, DRM_PROP_NAME_LEN
);
1926 list_add_tail(&property
->head
, &dev
->mode_config
.property_list
);
1932 EXPORT_SYMBOL(drm_property_create
);
1934 int drm_property_add_enum(struct drm_property
*property
, int index
,
1935 uint64_t value
, const char *name
)
1937 struct drm_property_enum
*prop_enum
;
1939 if (!(property
->flags
& DRM_MODE_PROP_ENUM
))
1942 if (!list_empty(&property
->enum_blob_list
)) {
1943 list_for_each_entry(prop_enum
, &property
->enum_blob_list
, head
) {
1944 if (prop_enum
->value
== value
) {
1945 strncpy(prop_enum
->name
, name
, DRM_PROP_NAME_LEN
);
1946 prop_enum
->name
[DRM_PROP_NAME_LEN
-1] = '\0';
1952 prop_enum
= kzalloc(sizeof(struct drm_property_enum
), GFP_KERNEL
);
1956 strncpy(prop_enum
->name
, name
, DRM_PROP_NAME_LEN
);
1957 prop_enum
->name
[DRM_PROP_NAME_LEN
-1] = '\0';
1958 prop_enum
->value
= value
;
1960 property
->values
[index
] = value
;
1961 list_add_tail(&prop_enum
->head
, &property
->enum_blob_list
);
1964 EXPORT_SYMBOL(drm_property_add_enum
);
1966 void drm_property_destroy(struct drm_device
*dev
, struct drm_property
*property
)
1968 struct drm_property_enum
*prop_enum
, *pt
;
1970 list_for_each_entry_safe(prop_enum
, pt
, &property
->enum_blob_list
, head
) {
1971 list_del(&prop_enum
->head
);
1975 if (property
->num_values
)
1976 kfree(property
->values
);
1977 drm_mode_object_put(dev
, &property
->base
);
1978 list_del(&property
->head
);
1981 EXPORT_SYMBOL(drm_property_destroy
);
1983 int drm_connector_attach_property(struct drm_connector
*connector
,
1984 struct drm_property
*property
, uint64_t init_val
)
1988 for (i
= 0; i
< DRM_CONNECTOR_MAX_PROPERTY
; i
++) {
1989 if (connector
->property_ids
[i
] == 0) {
1990 connector
->property_ids
[i
] = property
->base
.id
;
1991 connector
->property_values
[i
] = init_val
;
1996 if (i
== DRM_CONNECTOR_MAX_PROPERTY
)
2000 EXPORT_SYMBOL(drm_connector_attach_property
);
2002 int drm_connector_property_set_value(struct drm_connector
*connector
,
2003 struct drm_property
*property
, uint64_t value
)
2007 for (i
= 0; i
< DRM_CONNECTOR_MAX_PROPERTY
; i
++) {
2008 if (connector
->property_ids
[i
] == property
->base
.id
) {
2009 connector
->property_values
[i
] = value
;
2014 if (i
== DRM_CONNECTOR_MAX_PROPERTY
)
2018 EXPORT_SYMBOL(drm_connector_property_set_value
);
2020 int drm_connector_property_get_value(struct drm_connector
*connector
,
2021 struct drm_property
*property
, uint64_t *val
)
2025 for (i
= 0; i
< DRM_CONNECTOR_MAX_PROPERTY
; i
++) {
2026 if (connector
->property_ids
[i
] == property
->base
.id
) {
2027 *val
= connector
->property_values
[i
];
2032 if (i
== DRM_CONNECTOR_MAX_PROPERTY
)
2036 EXPORT_SYMBOL(drm_connector_property_get_value
);
2038 int drm_mode_getproperty_ioctl(struct drm_device
*dev
,
2039 void *data
, struct drm_file
*file_priv
)
2041 struct drm_mode_object
*obj
;
2042 struct drm_mode_get_property
*out_resp
= data
;
2043 struct drm_property
*property
;
2046 int value_count
= 0;
2049 struct drm_property_enum
*prop_enum
;
2050 struct drm_mode_property_enum __user
*enum_ptr
;
2051 struct drm_property_blob
*prop_blob
;
2052 uint32_t *blob_id_ptr
;
2053 uint64_t __user
*values_ptr
;
2054 uint32_t __user
*blob_length_ptr
;
2056 mutex_lock(&dev
->mode_config
.mutex
);
2057 obj
= drm_mode_object_find(dev
, out_resp
->prop_id
, DRM_MODE_OBJECT_PROPERTY
);
2062 property
= obj_to_property(obj
);
2064 if (property
->flags
& DRM_MODE_PROP_ENUM
) {
2065 list_for_each_entry(prop_enum
, &property
->enum_blob_list
, head
)
2067 } else if (property
->flags
& DRM_MODE_PROP_BLOB
) {
2068 list_for_each_entry(prop_blob
, &property
->enum_blob_list
, head
)
2072 value_count
= property
->num_values
;
2074 strncpy(out_resp
->name
, property
->name
, DRM_PROP_NAME_LEN
);
2075 out_resp
->name
[DRM_PROP_NAME_LEN
-1] = 0;
2076 out_resp
->flags
= property
->flags
;
2078 if ((out_resp
->count_values
>= value_count
) && value_count
) {
2079 values_ptr
= (uint64_t *)(unsigned long)out_resp
->values_ptr
;
2080 for (i
= 0; i
< value_count
; i
++) {
2081 if (copy_to_user(values_ptr
+ i
, &property
->values
[i
], sizeof(uint64_t))) {
2087 out_resp
->count_values
= value_count
;
2089 if (property
->flags
& DRM_MODE_PROP_ENUM
) {
2090 if ((out_resp
->count_enum_blobs
>= enum_count
) && enum_count
) {
2092 enum_ptr
= (struct drm_mode_property_enum
*)(unsigned long)out_resp
->enum_blob_ptr
;
2093 list_for_each_entry(prop_enum
, &property
->enum_blob_list
, head
) {
2095 if (copy_to_user(&enum_ptr
[copied
].value
, &prop_enum
->value
, sizeof(uint64_t))) {
2100 if (copy_to_user(&enum_ptr
[copied
].name
,
2101 &prop_enum
->name
, DRM_PROP_NAME_LEN
)) {
2108 out_resp
->count_enum_blobs
= enum_count
;
2111 if (property
->flags
& DRM_MODE_PROP_BLOB
) {
2112 if ((out_resp
->count_enum_blobs
>= blob_count
) && blob_count
) {
2114 blob_id_ptr
= (uint32_t *)(unsigned long)out_resp
->enum_blob_ptr
;
2115 blob_length_ptr
= (uint32_t *)(unsigned long)out_resp
->values_ptr
;
2117 list_for_each_entry(prop_blob
, &property
->enum_blob_list
, head
) {
2118 if (put_user(prop_blob
->base
.id
, blob_id_ptr
+ copied
)) {
2123 if (put_user(prop_blob
->length
, blob_length_ptr
+ copied
)) {
2131 out_resp
->count_enum_blobs
= blob_count
;
2134 mutex_unlock(&dev
->mode_config
.mutex
);
2138 static struct drm_property_blob
*drm_property_create_blob(struct drm_device
*dev
, int length
,
2141 struct drm_property_blob
*blob
;
2143 if (!length
|| !data
)
2146 blob
= kzalloc(sizeof(struct drm_property_blob
)+length
, GFP_KERNEL
);
2150 blob
->data
= (void *)((char *)blob
+ sizeof(struct drm_property_blob
));
2151 blob
->length
= length
;
2153 memcpy(blob
->data
, data
, length
);
2155 drm_mode_object_get(dev
, &blob
->base
, DRM_MODE_OBJECT_BLOB
);
2157 list_add_tail(&blob
->head
, &dev
->mode_config
.property_blob_list
);
2161 static void drm_property_destroy_blob(struct drm_device
*dev
,
2162 struct drm_property_blob
*blob
)
2164 drm_mode_object_put(dev
, &blob
->base
);
2165 list_del(&blob
->head
);
2169 int drm_mode_getblob_ioctl(struct drm_device
*dev
,
2170 void *data
, struct drm_file
*file_priv
)
2172 struct drm_mode_object
*obj
;
2173 struct drm_mode_get_blob
*out_resp
= data
;
2174 struct drm_property_blob
*blob
;
2178 mutex_lock(&dev
->mode_config
.mutex
);
2179 obj
= drm_mode_object_find(dev
, out_resp
->blob_id
, DRM_MODE_OBJECT_BLOB
);
2184 blob
= obj_to_blob(obj
);
2186 if (out_resp
->length
== blob
->length
) {
2187 blob_ptr
= (void *)(unsigned long)out_resp
->data
;
2188 if (copy_to_user(blob_ptr
, blob
->data
, blob
->length
)){
2193 out_resp
->length
= blob
->length
;
2196 mutex_unlock(&dev
->mode_config
.mutex
);
2200 int drm_mode_connector_update_edid_property(struct drm_connector
*connector
,
2203 struct drm_device
*dev
= connector
->dev
;
2206 if (connector
->edid_blob_ptr
)
2207 drm_property_destroy_blob(dev
, connector
->edid_blob_ptr
);
2209 /* Delete edid, when there is none. */
2211 connector
->edid_blob_ptr
= NULL
;
2212 ret
= drm_connector_property_set_value(connector
, dev
->mode_config
.edid_property
, 0);
2216 connector
->edid_blob_ptr
= drm_property_create_blob(connector
->dev
, 128, edid
);
2218 ret
= drm_connector_property_set_value(connector
,
2219 dev
->mode_config
.edid_property
,
2220 connector
->edid_blob_ptr
->base
.id
);
2224 EXPORT_SYMBOL(drm_mode_connector_update_edid_property
);
2226 int drm_mode_connector_property_set_ioctl(struct drm_device
*dev
,
2227 void *data
, struct drm_file
*file_priv
)
2229 struct drm_mode_connector_set_property
*out_resp
= data
;
2230 struct drm_mode_object
*obj
;
2231 struct drm_property
*property
;
2232 struct drm_connector
*connector
;
2236 mutex_lock(&dev
->mode_config
.mutex
);
2238 obj
= drm_mode_object_find(dev
, out_resp
->connector_id
, DRM_MODE_OBJECT_CONNECTOR
);
2242 connector
= obj_to_connector(obj
);
2244 for (i
= 0; i
< DRM_CONNECTOR_MAX_PROPERTY
; i
++) {
2245 if (connector
->property_ids
[i
] == out_resp
->prop_id
)
2249 if (i
== DRM_CONNECTOR_MAX_PROPERTY
) {
2253 obj
= drm_mode_object_find(dev
, out_resp
->prop_id
, DRM_MODE_OBJECT_PROPERTY
);
2257 property
= obj_to_property(obj
);
2259 if (property
->flags
& DRM_MODE_PROP_IMMUTABLE
)
2262 if (property
->flags
& DRM_MODE_PROP_RANGE
) {
2263 if (out_resp
->value
< property
->values
[0])
2266 if (out_resp
->value
> property
->values
[1])
2270 for (i
= 0; i
< property
->num_values
; i
++) {
2271 if (property
->values
[i
] == out_resp
->value
) {
2281 /* Do DPMS ourselves */
2282 if (property
== connector
->dev
->mode_config
.dpms_property
) {
2283 if (connector
->funcs
->dpms
)
2284 (*connector
->funcs
->dpms
)(connector
, (int) out_resp
->value
);
2286 } else if (connector
->funcs
->set_property
)
2287 ret
= connector
->funcs
->set_property(connector
, property
, out_resp
->value
);
2289 /* store the property value if succesful */
2291 drm_connector_property_set_value(connector
, property
, out_resp
->value
);
2293 mutex_unlock(&dev
->mode_config
.mutex
);
2297 int drm_mode_connector_attach_encoder(struct drm_connector
*connector
,
2298 struct drm_encoder
*encoder
)
2302 for (i
= 0; i
< DRM_CONNECTOR_MAX_ENCODER
; i
++) {
2303 if (connector
->encoder_ids
[i
] == 0) {
2304 connector
->encoder_ids
[i
] = encoder
->base
.id
;
2310 EXPORT_SYMBOL(drm_mode_connector_attach_encoder
);
2312 void drm_mode_connector_detach_encoder(struct drm_connector
*connector
,
2313 struct drm_encoder
*encoder
)
2316 for (i
= 0; i
< DRM_CONNECTOR_MAX_ENCODER
; i
++) {
2317 if (connector
->encoder_ids
[i
] == encoder
->base
.id
) {
2318 connector
->encoder_ids
[i
] = 0;
2319 if (connector
->encoder
== encoder
)
2320 connector
->encoder
= NULL
;
2325 EXPORT_SYMBOL(drm_mode_connector_detach_encoder
);
2327 bool drm_mode_crtc_set_gamma_size(struct drm_crtc
*crtc
,
2330 crtc
->gamma_size
= gamma_size
;
2332 crtc
->gamma_store
= kzalloc(gamma_size
* sizeof(uint16_t) * 3, GFP_KERNEL
);
2333 if (!crtc
->gamma_store
) {
2334 crtc
->gamma_size
= 0;
2340 EXPORT_SYMBOL(drm_mode_crtc_set_gamma_size
);
2342 int drm_mode_gamma_set_ioctl(struct drm_device
*dev
,
2343 void *data
, struct drm_file
*file_priv
)
2345 struct drm_mode_crtc_lut
*crtc_lut
= data
;
2346 struct drm_mode_object
*obj
;
2347 struct drm_crtc
*crtc
;
2348 void *r_base
, *g_base
, *b_base
;
2352 mutex_lock(&dev
->mode_config
.mutex
);
2353 obj
= drm_mode_object_find(dev
, crtc_lut
->crtc_id
, DRM_MODE_OBJECT_CRTC
);
2358 crtc
= obj_to_crtc(obj
);
2360 /* memcpy into gamma store */
2361 if (crtc_lut
->gamma_size
!= crtc
->gamma_size
) {
2366 size
= crtc_lut
->gamma_size
* (sizeof(uint16_t));
2367 r_base
= crtc
->gamma_store
;
2368 if (copy_from_user(r_base
, (void __user
*)(unsigned long)crtc_lut
->red
, size
)) {
2373 g_base
= r_base
+ size
;
2374 if (copy_from_user(g_base
, (void __user
*)(unsigned long)crtc_lut
->green
, size
)) {
2379 b_base
= g_base
+ size
;
2380 if (copy_from_user(b_base
, (void __user
*)(unsigned long)crtc_lut
->blue
, size
)) {
2385 crtc
->funcs
->gamma_set(crtc
, r_base
, g_base
, b_base
, crtc
->gamma_size
);
2388 mutex_unlock(&dev
->mode_config
.mutex
);
2393 int drm_mode_gamma_get_ioctl(struct drm_device
*dev
,
2394 void *data
, struct drm_file
*file_priv
)
2396 struct drm_mode_crtc_lut
*crtc_lut
= data
;
2397 struct drm_mode_object
*obj
;
2398 struct drm_crtc
*crtc
;
2399 void *r_base
, *g_base
, *b_base
;
2403 mutex_lock(&dev
->mode_config
.mutex
);
2404 obj
= drm_mode_object_find(dev
, crtc_lut
->crtc_id
, DRM_MODE_OBJECT_CRTC
);
2409 crtc
= obj_to_crtc(obj
);
2411 /* memcpy into gamma store */
2412 if (crtc_lut
->gamma_size
!= crtc
->gamma_size
) {
2417 size
= crtc_lut
->gamma_size
* (sizeof(uint16_t));
2418 r_base
= crtc
->gamma_store
;
2419 if (copy_to_user((void __user
*)(unsigned long)crtc_lut
->red
, r_base
, size
)) {
2424 g_base
= r_base
+ size
;
2425 if (copy_to_user((void __user
*)(unsigned long)crtc_lut
->green
, g_base
, size
)) {
2430 b_base
= g_base
+ size
;
2431 if (copy_to_user((void __user
*)(unsigned long)crtc_lut
->blue
, b_base
, size
)) {
2436 mutex_unlock(&dev
->mode_config
.mutex
);