2 * Copyright (c) 2006-2008 Intel Corporation
3 * Copyright (c) 2007 Dave Airlie <airlied@linux.ie>
4 * Copyright (c) 2008 Red Hat Inc.
6 * DRM core CRTC related functions
8 * Permission to use, copy, modify, distribute, and sell this software and its
9 * documentation for any purpose is hereby granted without fee, provided that
10 * the above copyright notice appear in all copies and that both that copyright
11 * notice and this permission notice appear in supporting documentation, and
12 * that the name of the copyright holders not be used in advertising or
13 * publicity pertaining to distribution of the software without specific,
14 * written prior permission. The copyright holders make no representations
15 * about the suitability of this software for any purpose. It is provided "as
16 * is" without express or implied warranty.
18 * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
19 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
20 * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
21 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
22 * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
23 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
28 * Eric Anholt <eric@anholt.net>
29 * Dave Airlie <airlied@linux.ie>
30 * Jesse Barnes <jesse.barnes@intel.com>
32 #include <linux/list.h>
37 struct drm_prop_enum_list
{
42 /* Avoid boilerplate. I'm tired of typing. */
43 #define DRM_ENUM_NAME_FN(fnname, list) \
44 char *fnname(int val) \
47 for (i = 0; i < ARRAY_SIZE(list); i++) { \
48 if (list[i].type == val) \
49 return list[i].name; \
57 static struct drm_prop_enum_list drm_dpms_enum_list
[] =
58 { { DRM_MODE_DPMS_ON
, "On" },
59 { DRM_MODE_DPMS_STANDBY
, "Standby" },
60 { DRM_MODE_DPMS_SUSPEND
, "Suspend" },
61 { DRM_MODE_DPMS_OFF
, "Off" }
64 DRM_ENUM_NAME_FN(drm_get_dpms_name
, drm_dpms_enum_list
)
69 static struct drm_prop_enum_list drm_scaling_mode_enum_list
[] =
71 { DRM_MODE_SCALE_NONE
, "None" },
72 { DRM_MODE_SCALE_FULLSCREEN
, "Full" },
73 { DRM_MODE_SCALE_CENTER
, "Center" },
74 { DRM_MODE_SCALE_ASPECT
, "Full aspect" },
77 static struct drm_prop_enum_list drm_dithering_mode_enum_list
[] =
79 { DRM_MODE_DITHERING_OFF
, "Off" },
80 { DRM_MODE_DITHERING_ON
, "On" },
84 * Non-global properties, but "required" for certain connectors.
86 static struct drm_prop_enum_list drm_dvi_i_select_enum_list
[] =
88 { DRM_MODE_SUBCONNECTOR_Automatic
, "Automatic" }, /* DVI-I and TV-out */
89 { DRM_MODE_SUBCONNECTOR_DVID
, "DVI-D" }, /* DVI-I */
90 { DRM_MODE_SUBCONNECTOR_DVIA
, "DVI-A" }, /* DVI-I */
93 DRM_ENUM_NAME_FN(drm_get_dvi_i_select_name
, drm_dvi_i_select_enum_list
)
95 static struct drm_prop_enum_list drm_dvi_i_subconnector_enum_list
[] =
97 { DRM_MODE_SUBCONNECTOR_Unknown
, "Unknown" }, /* DVI-I and TV-out */
98 { DRM_MODE_SUBCONNECTOR_DVID
, "DVI-D" }, /* DVI-I */
99 { DRM_MODE_SUBCONNECTOR_DVIA
, "DVI-A" }, /* DVI-I */
102 DRM_ENUM_NAME_FN(drm_get_dvi_i_subconnector_name
,
103 drm_dvi_i_subconnector_enum_list
)
105 static struct drm_prop_enum_list drm_tv_select_enum_list
[] =
107 { DRM_MODE_SUBCONNECTOR_Automatic
, "Automatic" }, /* DVI-I and TV-out */
108 { DRM_MODE_SUBCONNECTOR_Composite
, "Composite" }, /* TV-out */
109 { DRM_MODE_SUBCONNECTOR_SVIDEO
, "SVIDEO" }, /* TV-out */
110 { DRM_MODE_SUBCONNECTOR_Component
, "Component" }, /* TV-out */
111 { DRM_MODE_SUBCONNECTOR_SCART
, "SCART" }, /* TV-out */
114 DRM_ENUM_NAME_FN(drm_get_tv_select_name
, drm_tv_select_enum_list
)
116 static struct drm_prop_enum_list drm_tv_subconnector_enum_list
[] =
118 { DRM_MODE_SUBCONNECTOR_Unknown
, "Unknown" }, /* DVI-I and TV-out */
119 { DRM_MODE_SUBCONNECTOR_Composite
, "Composite" }, /* TV-out */
120 { DRM_MODE_SUBCONNECTOR_SVIDEO
, "SVIDEO" }, /* TV-out */
121 { DRM_MODE_SUBCONNECTOR_Component
, "Component" }, /* TV-out */
122 { DRM_MODE_SUBCONNECTOR_SCART
, "SCART" }, /* TV-out */
125 DRM_ENUM_NAME_FN(drm_get_tv_subconnector_name
,
126 drm_tv_subconnector_enum_list
)
128 static struct drm_prop_enum_list drm_dirty_info_enum_list
[] = {
129 { DRM_MODE_DIRTY_OFF
, "Off" },
130 { DRM_MODE_DIRTY_ON
, "On" },
131 { DRM_MODE_DIRTY_ANNOTATE
, "Annotate" },
134 DRM_ENUM_NAME_FN(drm_get_dirty_info_name
,
135 drm_dirty_info_enum_list
)
137 struct drm_conn_prop_enum_list
{
144 * Connector and encoder types.
146 static struct drm_conn_prop_enum_list drm_connector_enum_list
[] =
147 { { DRM_MODE_CONNECTOR_Unknown
, "Unknown", 0 },
148 { DRM_MODE_CONNECTOR_VGA
, "VGA", 0 },
149 { DRM_MODE_CONNECTOR_DVII
, "DVI-I", 0 },
150 { DRM_MODE_CONNECTOR_DVID
, "DVI-D", 0 },
151 { DRM_MODE_CONNECTOR_DVIA
, "DVI-A", 0 },
152 { DRM_MODE_CONNECTOR_Composite
, "Composite", 0 },
153 { DRM_MODE_CONNECTOR_SVIDEO
, "SVIDEO", 0 },
154 { DRM_MODE_CONNECTOR_LVDS
, "LVDS", 0 },
155 { DRM_MODE_CONNECTOR_Component
, "Component", 0 },
156 { DRM_MODE_CONNECTOR_9PinDIN
, "9-pin DIN", 0 },
157 { DRM_MODE_CONNECTOR_DisplayPort
, "DisplayPort", 0 },
158 { DRM_MODE_CONNECTOR_HDMIA
, "HDMI Type A", 0 },
159 { DRM_MODE_CONNECTOR_HDMIB
, "HDMI Type B", 0 },
160 { DRM_MODE_CONNECTOR_TV
, "TV", 0 },
161 { DRM_MODE_CONNECTOR_eDP
, "Embedded DisplayPort", 0 },
164 static struct drm_prop_enum_list drm_encoder_enum_list
[] =
165 { { DRM_MODE_ENCODER_NONE
, "None" },
166 { DRM_MODE_ENCODER_DAC
, "DAC" },
167 { DRM_MODE_ENCODER_TMDS
, "TMDS" },
168 { DRM_MODE_ENCODER_LVDS
, "LVDS" },
169 { DRM_MODE_ENCODER_TVDAC
, "TV" },
172 char *drm_get_encoder_name(struct drm_encoder
*encoder
)
176 snprintf(buf
, 32, "%s-%d",
177 drm_encoder_enum_list
[encoder
->encoder_type
].name
,
181 EXPORT_SYMBOL(drm_get_encoder_name
);
183 char *drm_get_connector_name(struct drm_connector
*connector
)
187 snprintf(buf
, 32, "%s-%d",
188 drm_connector_enum_list
[connector
->connector_type
].name
,
189 connector
->connector_type_id
);
192 EXPORT_SYMBOL(drm_get_connector_name
);
194 char *drm_get_connector_status_name(enum drm_connector_status status
)
196 if (status
== connector_status_connected
)
198 else if (status
== connector_status_disconnected
)
199 return "disconnected";
205 * drm_mode_object_get - allocate a new identifier
207 * @ptr: object pointer, used to generate unique ID
212 * Create a unique identifier based on @ptr in @dev's identifier space. Used
213 * for tracking modes, CRTCs and connectors.
216 * New unique (relative to other objects in @dev) integer identifier for the
219 static int drm_mode_object_get(struct drm_device
*dev
,
220 struct drm_mode_object
*obj
, uint32_t obj_type
)
226 if (idr_pre_get(&dev
->mode_config
.crtc_idr
, GFP_KERNEL
) == 0) {
227 DRM_ERROR("Ran out memory getting a mode number\n");
231 mutex_lock(&dev
->mode_config
.idr_mutex
);
232 ret
= idr_get_new_above(&dev
->mode_config
.crtc_idr
, obj
, 1, &new_id
);
233 mutex_unlock(&dev
->mode_config
.idr_mutex
);
238 obj
->type
= obj_type
;
243 * drm_mode_object_put - free an identifer
248 * Caller must hold DRM mode_config lock.
250 * Free @id from @dev's unique identifier pool.
252 static void drm_mode_object_put(struct drm_device
*dev
,
253 struct drm_mode_object
*object
)
255 mutex_lock(&dev
->mode_config
.idr_mutex
);
256 idr_remove(&dev
->mode_config
.crtc_idr
, object
->id
);
257 mutex_unlock(&dev
->mode_config
.idr_mutex
);
260 struct drm_mode_object
*drm_mode_object_find(struct drm_device
*dev
,
261 uint32_t id
, uint32_t type
)
263 struct drm_mode_object
*obj
= NULL
;
265 mutex_lock(&dev
->mode_config
.idr_mutex
);
266 obj
= idr_find(&dev
->mode_config
.crtc_idr
, id
);
267 if (!obj
|| (obj
->type
!= type
) || (obj
->id
!= id
))
269 mutex_unlock(&dev
->mode_config
.idr_mutex
);
273 EXPORT_SYMBOL(drm_mode_object_find
);
276 * drm_framebuffer_init - initialize a framebuffer
280 * Caller must hold mode config lock.
282 * Allocates an ID for the framebuffer's parent mode object, sets its mode
283 * functions & device file and adds it to the master fd list.
286 * Zero on success, error code on failure.
288 int drm_framebuffer_init(struct drm_device
*dev
, struct drm_framebuffer
*fb
,
289 const struct drm_framebuffer_funcs
*funcs
)
293 ret
= drm_mode_object_get(dev
, &fb
->base
, DRM_MODE_OBJECT_FB
);
300 dev
->mode_config
.num_fb
++;
301 list_add(&fb
->head
, &dev
->mode_config
.fb_list
);
305 EXPORT_SYMBOL(drm_framebuffer_init
);
308 * drm_framebuffer_cleanup - remove a framebuffer object
309 * @fb: framebuffer to remove
312 * Caller must hold mode config lock.
314 * Scans all the CRTCs in @dev's mode_config. If they're using @fb, removes
315 * it, setting it to NULL.
317 void drm_framebuffer_cleanup(struct drm_framebuffer
*fb
)
319 struct drm_device
*dev
= fb
->dev
;
320 struct drm_crtc
*crtc
;
321 struct drm_mode_set set
;
324 /* remove from any CRTC */
325 list_for_each_entry(crtc
, &dev
->mode_config
.crtc_list
, head
) {
326 if (crtc
->fb
== fb
) {
327 /* should turn off the crtc */
328 memset(&set
, 0, sizeof(struct drm_mode_set
));
331 ret
= crtc
->funcs
->set_config(&set
);
333 DRM_ERROR("failed to reset crtc %p when fb was deleted\n", crtc
);
337 drm_mode_object_put(dev
, &fb
->base
);
339 dev
->mode_config
.num_fb
--;
341 EXPORT_SYMBOL(drm_framebuffer_cleanup
);
344 * drm_crtc_init - Initialise a new CRTC object
346 * @crtc: CRTC object to init
347 * @funcs: callbacks for the new CRTC
350 * Caller must hold mode config lock.
352 * Inits a new object created as base part of an driver crtc object.
354 void drm_crtc_init(struct drm_device
*dev
, struct drm_crtc
*crtc
,
355 const struct drm_crtc_funcs
*funcs
)
360 mutex_lock(&dev
->mode_config
.mutex
);
361 drm_mode_object_get(dev
, &crtc
->base
, DRM_MODE_OBJECT_CRTC
);
363 list_add_tail(&crtc
->head
, &dev
->mode_config
.crtc_list
);
364 dev
->mode_config
.num_crtc
++;
365 mutex_unlock(&dev
->mode_config
.mutex
);
367 EXPORT_SYMBOL(drm_crtc_init
);
370 * drm_crtc_cleanup - Cleans up the core crtc usage.
371 * @crtc: CRTC to cleanup
374 * Caller must hold mode config lock.
376 * Cleanup @crtc. Removes from drm modesetting space
377 * does NOT free object, caller does that.
379 void drm_crtc_cleanup(struct drm_crtc
*crtc
)
381 struct drm_device
*dev
= crtc
->dev
;
383 if (crtc
->gamma_store
) {
384 kfree(crtc
->gamma_store
);
385 crtc
->gamma_store
= NULL
;
388 drm_mode_object_put(dev
, &crtc
->base
);
389 list_del(&crtc
->head
);
390 dev
->mode_config
.num_crtc
--;
392 EXPORT_SYMBOL(drm_crtc_cleanup
);
395 * drm_mode_probed_add - add a mode to a connector's probed mode list
396 * @connector: connector the new mode
400 * Caller must hold mode config lock.
402 * Add @mode to @connector's mode list for later use.
404 void drm_mode_probed_add(struct drm_connector
*connector
,
405 struct drm_display_mode
*mode
)
407 list_add(&mode
->head
, &connector
->probed_modes
);
409 EXPORT_SYMBOL(drm_mode_probed_add
);
412 * drm_mode_remove - remove and free a mode
413 * @connector: connector list to modify
414 * @mode: mode to remove
417 * Caller must hold mode config lock.
419 * Remove @mode from @connector's mode list, then free it.
421 void drm_mode_remove(struct drm_connector
*connector
,
422 struct drm_display_mode
*mode
)
424 list_del(&mode
->head
);
427 EXPORT_SYMBOL(drm_mode_remove
);
430 * drm_connector_init - Init a preallocated connector
432 * @connector: the connector to init
433 * @funcs: callbacks for this connector
434 * @name: user visible name of the connector
437 * Caller must hold @dev's mode_config lock.
439 * Initialises a preallocated connector. Connectors should be
440 * subclassed as part of driver connector objects.
442 void drm_connector_init(struct drm_device
*dev
,
443 struct drm_connector
*connector
,
444 const struct drm_connector_funcs
*funcs
,
447 mutex_lock(&dev
->mode_config
.mutex
);
449 connector
->dev
= dev
;
450 connector
->funcs
= funcs
;
451 drm_mode_object_get(dev
, &connector
->base
, DRM_MODE_OBJECT_CONNECTOR
);
452 connector
->connector_type
= connector_type
;
453 connector
->connector_type_id
=
454 ++drm_connector_enum_list
[connector_type
].count
; /* TODO */
455 INIT_LIST_HEAD(&connector
->user_modes
);
456 INIT_LIST_HEAD(&connector
->probed_modes
);
457 INIT_LIST_HEAD(&connector
->modes
);
458 connector
->edid_blob_ptr
= NULL
;
460 list_add_tail(&connector
->head
, &dev
->mode_config
.connector_list
);
461 dev
->mode_config
.num_connector
++;
463 drm_connector_attach_property(connector
,
464 dev
->mode_config
.edid_property
, 0);
466 drm_connector_attach_property(connector
,
467 dev
->mode_config
.dpms_property
, 0);
469 mutex_unlock(&dev
->mode_config
.mutex
);
471 EXPORT_SYMBOL(drm_connector_init
);
474 * drm_connector_cleanup - cleans up an initialised connector
475 * @connector: connector to cleanup
478 * Caller must hold @dev's mode_config lock.
480 * Cleans up the connector but doesn't free the object.
482 void drm_connector_cleanup(struct drm_connector
*connector
)
484 struct drm_device
*dev
= connector
->dev
;
485 struct drm_display_mode
*mode
, *t
;
487 list_for_each_entry_safe(mode
, t
, &connector
->probed_modes
, head
)
488 drm_mode_remove(connector
, mode
);
490 list_for_each_entry_safe(mode
, t
, &connector
->modes
, head
)
491 drm_mode_remove(connector
, mode
);
493 list_for_each_entry_safe(mode
, t
, &connector
->user_modes
, head
)
494 drm_mode_remove(connector
, mode
);
496 kfree(connector
->fb_helper_private
);
497 mutex_lock(&dev
->mode_config
.mutex
);
498 drm_mode_object_put(dev
, &connector
->base
);
499 list_del(&connector
->head
);
500 mutex_unlock(&dev
->mode_config
.mutex
);
502 EXPORT_SYMBOL(drm_connector_cleanup
);
504 void drm_encoder_init(struct drm_device
*dev
,
505 struct drm_encoder
*encoder
,
506 const struct drm_encoder_funcs
*funcs
,
509 mutex_lock(&dev
->mode_config
.mutex
);
513 drm_mode_object_get(dev
, &encoder
->base
, DRM_MODE_OBJECT_ENCODER
);
514 encoder
->encoder_type
= encoder_type
;
515 encoder
->funcs
= funcs
;
517 list_add_tail(&encoder
->head
, &dev
->mode_config
.encoder_list
);
518 dev
->mode_config
.num_encoder
++;
520 mutex_unlock(&dev
->mode_config
.mutex
);
522 EXPORT_SYMBOL(drm_encoder_init
);
524 void drm_encoder_cleanup(struct drm_encoder
*encoder
)
526 struct drm_device
*dev
= encoder
->dev
;
527 mutex_lock(&dev
->mode_config
.mutex
);
528 drm_mode_object_put(dev
, &encoder
->base
);
529 list_del(&encoder
->head
);
530 mutex_unlock(&dev
->mode_config
.mutex
);
532 EXPORT_SYMBOL(drm_encoder_cleanup
);
535 * drm_mode_create - create a new display mode
539 * Caller must hold DRM mode_config lock.
541 * Create a new drm_display_mode, give it an ID, and return it.
544 * Pointer to new mode on success, NULL on error.
546 struct drm_display_mode
*drm_mode_create(struct drm_device
*dev
)
548 struct drm_display_mode
*nmode
;
550 nmode
= kzalloc(sizeof(struct drm_display_mode
), GFP_KERNEL
);
554 drm_mode_object_get(dev
, &nmode
->base
, DRM_MODE_OBJECT_MODE
);
557 EXPORT_SYMBOL(drm_mode_create
);
560 * drm_mode_destroy - remove a mode
562 * @mode: mode to remove
565 * Caller must hold mode config lock.
567 * Free @mode's unique identifier, then free it.
569 void drm_mode_destroy(struct drm_device
*dev
, struct drm_display_mode
*mode
)
571 drm_mode_object_put(dev
, &mode
->base
);
575 EXPORT_SYMBOL(drm_mode_destroy
);
577 static int drm_mode_create_standard_connector_properties(struct drm_device
*dev
)
579 struct drm_property
*edid
;
580 struct drm_property
*dpms
;
584 * Standard properties (apply to all connectors)
586 edid
= drm_property_create(dev
, DRM_MODE_PROP_BLOB
|
587 DRM_MODE_PROP_IMMUTABLE
,
589 dev
->mode_config
.edid_property
= edid
;
591 dpms
= drm_property_create(dev
, DRM_MODE_PROP_ENUM
,
592 "DPMS", ARRAY_SIZE(drm_dpms_enum_list
));
593 for (i
= 0; i
< ARRAY_SIZE(drm_dpms_enum_list
); i
++)
594 drm_property_add_enum(dpms
, i
, drm_dpms_enum_list
[i
].type
,
595 drm_dpms_enum_list
[i
].name
);
596 dev
->mode_config
.dpms_property
= dpms
;
602 * drm_mode_create_dvi_i_properties - create DVI-I specific connector properties
605 * Called by a driver the first time a DVI-I connector is made.
607 int drm_mode_create_dvi_i_properties(struct drm_device
*dev
)
609 struct drm_property
*dvi_i_selector
;
610 struct drm_property
*dvi_i_subconnector
;
613 if (dev
->mode_config
.dvi_i_select_subconnector_property
)
617 drm_property_create(dev
, DRM_MODE_PROP_ENUM
,
618 "select subconnector",
619 ARRAY_SIZE(drm_dvi_i_select_enum_list
));
620 for (i
= 0; i
< ARRAY_SIZE(drm_dvi_i_select_enum_list
); i
++)
621 drm_property_add_enum(dvi_i_selector
, i
,
622 drm_dvi_i_select_enum_list
[i
].type
,
623 drm_dvi_i_select_enum_list
[i
].name
);
624 dev
->mode_config
.dvi_i_select_subconnector_property
= dvi_i_selector
;
627 drm_property_create(dev
, DRM_MODE_PROP_ENUM
|
628 DRM_MODE_PROP_IMMUTABLE
,
630 ARRAY_SIZE(drm_dvi_i_subconnector_enum_list
));
631 for (i
= 0; i
< ARRAY_SIZE(drm_dvi_i_subconnector_enum_list
); i
++)
632 drm_property_add_enum(dvi_i_subconnector
, i
,
633 drm_dvi_i_subconnector_enum_list
[i
].type
,
634 drm_dvi_i_subconnector_enum_list
[i
].name
);
635 dev
->mode_config
.dvi_i_subconnector_property
= dvi_i_subconnector
;
639 EXPORT_SYMBOL(drm_mode_create_dvi_i_properties
);
642 * drm_create_tv_properties - create TV specific connector properties
644 * @num_modes: number of different TV formats (modes) supported
645 * @modes: array of pointers to strings containing name of each format
647 * Called by a driver's TV initialization routine, this function creates
648 * the TV specific connector properties for a given device. Caller is
649 * responsible for allocating a list of format names and passing them to
652 int drm_mode_create_tv_properties(struct drm_device
*dev
, int num_modes
,
655 struct drm_property
*tv_selector
;
656 struct drm_property
*tv_subconnector
;
659 if (dev
->mode_config
.tv_select_subconnector_property
)
663 * Basic connector properties
665 tv_selector
= drm_property_create(dev
, DRM_MODE_PROP_ENUM
,
666 "select subconnector",
667 ARRAY_SIZE(drm_tv_select_enum_list
));
668 for (i
= 0; i
< ARRAY_SIZE(drm_tv_select_enum_list
); i
++)
669 drm_property_add_enum(tv_selector
, i
,
670 drm_tv_select_enum_list
[i
].type
,
671 drm_tv_select_enum_list
[i
].name
);
672 dev
->mode_config
.tv_select_subconnector_property
= tv_selector
;
675 drm_property_create(dev
, DRM_MODE_PROP_ENUM
|
676 DRM_MODE_PROP_IMMUTABLE
, "subconnector",
677 ARRAY_SIZE(drm_tv_subconnector_enum_list
));
678 for (i
= 0; i
< ARRAY_SIZE(drm_tv_subconnector_enum_list
); i
++)
679 drm_property_add_enum(tv_subconnector
, i
,
680 drm_tv_subconnector_enum_list
[i
].type
,
681 drm_tv_subconnector_enum_list
[i
].name
);
682 dev
->mode_config
.tv_subconnector_property
= tv_subconnector
;
685 * Other, TV specific properties: margins & TV modes.
687 dev
->mode_config
.tv_left_margin_property
=
688 drm_property_create(dev
, DRM_MODE_PROP_RANGE
,
690 dev
->mode_config
.tv_left_margin_property
->values
[0] = 0;
691 dev
->mode_config
.tv_left_margin_property
->values
[1] = 100;
693 dev
->mode_config
.tv_right_margin_property
=
694 drm_property_create(dev
, DRM_MODE_PROP_RANGE
,
696 dev
->mode_config
.tv_right_margin_property
->values
[0] = 0;
697 dev
->mode_config
.tv_right_margin_property
->values
[1] = 100;
699 dev
->mode_config
.tv_top_margin_property
=
700 drm_property_create(dev
, DRM_MODE_PROP_RANGE
,
702 dev
->mode_config
.tv_top_margin_property
->values
[0] = 0;
703 dev
->mode_config
.tv_top_margin_property
->values
[1] = 100;
705 dev
->mode_config
.tv_bottom_margin_property
=
706 drm_property_create(dev
, DRM_MODE_PROP_RANGE
,
708 dev
->mode_config
.tv_bottom_margin_property
->values
[0] = 0;
709 dev
->mode_config
.tv_bottom_margin_property
->values
[1] = 100;
711 dev
->mode_config
.tv_mode_property
=
712 drm_property_create(dev
, DRM_MODE_PROP_ENUM
,
714 for (i
= 0; i
< num_modes
; i
++)
715 drm_property_add_enum(dev
->mode_config
.tv_mode_property
, i
,
718 dev
->mode_config
.tv_brightness_property
=
719 drm_property_create(dev
, DRM_MODE_PROP_RANGE
,
721 dev
->mode_config
.tv_brightness_property
->values
[0] = 0;
722 dev
->mode_config
.tv_brightness_property
->values
[1] = 100;
724 dev
->mode_config
.tv_contrast_property
=
725 drm_property_create(dev
, DRM_MODE_PROP_RANGE
,
727 dev
->mode_config
.tv_contrast_property
->values
[0] = 0;
728 dev
->mode_config
.tv_contrast_property
->values
[1] = 100;
730 dev
->mode_config
.tv_flicker_reduction_property
=
731 drm_property_create(dev
, DRM_MODE_PROP_RANGE
,
732 "flicker reduction", 2);
733 dev
->mode_config
.tv_flicker_reduction_property
->values
[0] = 0;
734 dev
->mode_config
.tv_flicker_reduction_property
->values
[1] = 100;
736 dev
->mode_config
.tv_overscan_property
=
737 drm_property_create(dev
, DRM_MODE_PROP_RANGE
,
739 dev
->mode_config
.tv_overscan_property
->values
[0] = 0;
740 dev
->mode_config
.tv_overscan_property
->values
[1] = 100;
742 dev
->mode_config
.tv_saturation_property
=
743 drm_property_create(dev
, DRM_MODE_PROP_RANGE
,
745 dev
->mode_config
.tv_saturation_property
->values
[0] = 0;
746 dev
->mode_config
.tv_saturation_property
->values
[1] = 100;
748 dev
->mode_config
.tv_hue_property
=
749 drm_property_create(dev
, DRM_MODE_PROP_RANGE
,
751 dev
->mode_config
.tv_hue_property
->values
[0] = 0;
752 dev
->mode_config
.tv_hue_property
->values
[1] = 100;
756 EXPORT_SYMBOL(drm_mode_create_tv_properties
);
759 * drm_mode_create_scaling_mode_property - create scaling mode property
762 * Called by a driver the first time it's needed, must be attached to desired
765 int drm_mode_create_scaling_mode_property(struct drm_device
*dev
)
767 struct drm_property
*scaling_mode
;
770 if (dev
->mode_config
.scaling_mode_property
)
774 drm_property_create(dev
, DRM_MODE_PROP_ENUM
, "scaling mode",
775 ARRAY_SIZE(drm_scaling_mode_enum_list
));
776 for (i
= 0; i
< ARRAY_SIZE(drm_scaling_mode_enum_list
); i
++)
777 drm_property_add_enum(scaling_mode
, i
,
778 drm_scaling_mode_enum_list
[i
].type
,
779 drm_scaling_mode_enum_list
[i
].name
);
781 dev
->mode_config
.scaling_mode_property
= scaling_mode
;
785 EXPORT_SYMBOL(drm_mode_create_scaling_mode_property
);
788 * drm_mode_create_dithering_property - create dithering property
791 * Called by a driver the first time it's needed, must be attached to desired
794 int drm_mode_create_dithering_property(struct drm_device
*dev
)
796 struct drm_property
*dithering_mode
;
799 if (dev
->mode_config
.dithering_mode_property
)
803 drm_property_create(dev
, DRM_MODE_PROP_ENUM
, "dithering",
804 ARRAY_SIZE(drm_dithering_mode_enum_list
));
805 for (i
= 0; i
< ARRAY_SIZE(drm_dithering_mode_enum_list
); i
++)
806 drm_property_add_enum(dithering_mode
, i
,
807 drm_dithering_mode_enum_list
[i
].type
,
808 drm_dithering_mode_enum_list
[i
].name
);
809 dev
->mode_config
.dithering_mode_property
= dithering_mode
;
813 EXPORT_SYMBOL(drm_mode_create_dithering_property
);
816 * drm_mode_create_dirty_property - create dirty property
819 * Called by a driver the first time it's needed, must be attached to desired
822 int drm_mode_create_dirty_info_property(struct drm_device
*dev
)
824 struct drm_property
*dirty_info
;
827 if (dev
->mode_config
.dirty_info_property
)
831 drm_property_create(dev
, DRM_MODE_PROP_ENUM
|
832 DRM_MODE_PROP_IMMUTABLE
,
834 ARRAY_SIZE(drm_dirty_info_enum_list
));
835 for (i
= 0; i
< ARRAY_SIZE(drm_dirty_info_enum_list
); i
++)
836 drm_property_add_enum(dirty_info
, i
,
837 drm_dirty_info_enum_list
[i
].type
,
838 drm_dirty_info_enum_list
[i
].name
);
839 dev
->mode_config
.dirty_info_property
= dirty_info
;
843 EXPORT_SYMBOL(drm_mode_create_dirty_info_property
);
846 * drm_mode_config_init - initialize DRM mode_configuration structure
850 * None, should happen single threaded at init time.
852 * Initialize @dev's mode_config structure, used for tracking the graphics
853 * configuration of @dev.
855 void drm_mode_config_init(struct drm_device
*dev
)
857 mutex_init(&dev
->mode_config
.mutex
);
858 mutex_init(&dev
->mode_config
.idr_mutex
);
859 INIT_LIST_HEAD(&dev
->mode_config
.fb_list
);
860 INIT_LIST_HEAD(&dev
->mode_config
.fb_kernel_list
);
861 INIT_LIST_HEAD(&dev
->mode_config
.crtc_list
);
862 INIT_LIST_HEAD(&dev
->mode_config
.connector_list
);
863 INIT_LIST_HEAD(&dev
->mode_config
.encoder_list
);
864 INIT_LIST_HEAD(&dev
->mode_config
.property_list
);
865 INIT_LIST_HEAD(&dev
->mode_config
.property_blob_list
);
866 idr_init(&dev
->mode_config
.crtc_idr
);
868 mutex_lock(&dev
->mode_config
.mutex
);
869 drm_mode_create_standard_connector_properties(dev
);
870 mutex_unlock(&dev
->mode_config
.mutex
);
872 /* Just to be sure */
873 dev
->mode_config
.num_fb
= 0;
874 dev
->mode_config
.num_connector
= 0;
875 dev
->mode_config
.num_crtc
= 0;
876 dev
->mode_config
.num_encoder
= 0;
878 EXPORT_SYMBOL(drm_mode_config_init
);
880 int drm_mode_group_init(struct drm_device
*dev
, struct drm_mode_group
*group
)
882 uint32_t total_objects
= 0;
884 total_objects
+= dev
->mode_config
.num_crtc
;
885 total_objects
+= dev
->mode_config
.num_connector
;
886 total_objects
+= dev
->mode_config
.num_encoder
;
888 if (total_objects
== 0)
891 group
->id_list
= kzalloc(total_objects
* sizeof(uint32_t), GFP_KERNEL
);
895 group
->num_crtcs
= 0;
896 group
->num_connectors
= 0;
897 group
->num_encoders
= 0;
901 int drm_mode_group_init_legacy_group(struct drm_device
*dev
,
902 struct drm_mode_group
*group
)
904 struct drm_crtc
*crtc
;
905 struct drm_encoder
*encoder
;
906 struct drm_connector
*connector
;
909 if ((ret
= drm_mode_group_init(dev
, group
)))
912 list_for_each_entry(crtc
, &dev
->mode_config
.crtc_list
, head
)
913 group
->id_list
[group
->num_crtcs
++] = crtc
->base
.id
;
915 list_for_each_entry(encoder
, &dev
->mode_config
.encoder_list
, head
)
916 group
->id_list
[group
->num_crtcs
+ group
->num_encoders
++] =
919 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
, head
)
920 group
->id_list
[group
->num_crtcs
+ group
->num_encoders
+
921 group
->num_connectors
++] = connector
->base
.id
;
927 * drm_mode_config_cleanup - free up DRM mode_config info
931 * Caller must hold mode config lock.
933 * Free up all the connectors and CRTCs associated with this DRM device, then
934 * free up the framebuffers and associated buffer objects.
936 * FIXME: cleanup any dangling user buffer objects too
938 void drm_mode_config_cleanup(struct drm_device
*dev
)
940 struct drm_connector
*connector
, *ot
;
941 struct drm_crtc
*crtc
, *ct
;
942 struct drm_encoder
*encoder
, *enct
;
943 struct drm_framebuffer
*fb
, *fbt
;
944 struct drm_property
*property
, *pt
;
946 list_for_each_entry_safe(encoder
, enct
, &dev
->mode_config
.encoder_list
,
948 encoder
->funcs
->destroy(encoder
);
951 list_for_each_entry_safe(connector
, ot
,
952 &dev
->mode_config
.connector_list
, head
) {
953 connector
->funcs
->destroy(connector
);
956 list_for_each_entry_safe(property
, pt
, &dev
->mode_config
.property_list
,
958 drm_property_destroy(dev
, property
);
961 list_for_each_entry_safe(fb
, fbt
, &dev
->mode_config
.fb_list
, head
) {
962 fb
->funcs
->destroy(fb
);
965 list_for_each_entry_safe(crtc
, ct
, &dev
->mode_config
.crtc_list
, head
) {
966 crtc
->funcs
->destroy(crtc
);
970 EXPORT_SYMBOL(drm_mode_config_cleanup
);
973 * drm_crtc_convert_to_umode - convert a drm_display_mode into a modeinfo
974 * @out: drm_mode_modeinfo struct to return to the user
975 * @in: drm_display_mode to use
980 * Convert a drm_display_mode into a drm_mode_modeinfo structure to return to
983 void drm_crtc_convert_to_umode(struct drm_mode_modeinfo
*out
,
984 struct drm_display_mode
*in
)
986 out
->clock
= in
->clock
;
987 out
->hdisplay
= in
->hdisplay
;
988 out
->hsync_start
= in
->hsync_start
;
989 out
->hsync_end
= in
->hsync_end
;
990 out
->htotal
= in
->htotal
;
991 out
->hskew
= in
->hskew
;
992 out
->vdisplay
= in
->vdisplay
;
993 out
->vsync_start
= in
->vsync_start
;
994 out
->vsync_end
= in
->vsync_end
;
995 out
->vtotal
= in
->vtotal
;
996 out
->vscan
= in
->vscan
;
997 out
->vrefresh
= in
->vrefresh
;
998 out
->flags
= in
->flags
;
999 out
->type
= in
->type
;
1000 strncpy(out
->name
, in
->name
, DRM_DISPLAY_MODE_LEN
);
1001 out
->name
[DRM_DISPLAY_MODE_LEN
-1] = 0;
1005 * drm_crtc_convert_to_umode - convert a modeinfo into a drm_display_mode
1006 * @out: drm_display_mode to return to the user
1007 * @in: drm_mode_modeinfo to use
1012 * Convert a drm_mode_modeinfo into a drm_display_mode structure to return to
1015 void drm_crtc_convert_umode(struct drm_display_mode
*out
,
1016 struct drm_mode_modeinfo
*in
)
1018 out
->clock
= in
->clock
;
1019 out
->hdisplay
= in
->hdisplay
;
1020 out
->hsync_start
= in
->hsync_start
;
1021 out
->hsync_end
= in
->hsync_end
;
1022 out
->htotal
= in
->htotal
;
1023 out
->hskew
= in
->hskew
;
1024 out
->vdisplay
= in
->vdisplay
;
1025 out
->vsync_start
= in
->vsync_start
;
1026 out
->vsync_end
= in
->vsync_end
;
1027 out
->vtotal
= in
->vtotal
;
1028 out
->vscan
= in
->vscan
;
1029 out
->vrefresh
= in
->vrefresh
;
1030 out
->flags
= in
->flags
;
1031 out
->type
= in
->type
;
1032 strncpy(out
->name
, in
->name
, DRM_DISPLAY_MODE_LEN
);
1033 out
->name
[DRM_DISPLAY_MODE_LEN
-1] = 0;
1037 * drm_mode_getresources - get graphics configuration
1038 * @inode: inode from the ioctl
1039 * @filp: file * from the ioctl
1040 * @cmd: cmd from ioctl
1041 * @arg: arg from ioctl
1044 * Takes mode config lock.
1046 * Construct a set of configuration description structures and return
1047 * them to the user, including CRTC, connector and framebuffer configuration.
1049 * Called by the user via ioctl.
1052 * Zero on success, errno on failure.
1054 int drm_mode_getresources(struct drm_device
*dev
, void *data
,
1055 struct drm_file
*file_priv
)
1057 struct drm_mode_card_res
*card_res
= data
;
1058 struct list_head
*lh
;
1059 struct drm_framebuffer
*fb
;
1060 struct drm_connector
*connector
;
1061 struct drm_crtc
*crtc
;
1062 struct drm_encoder
*encoder
;
1064 int connector_count
= 0;
1067 int encoder_count
= 0;
1069 uint32_t __user
*fb_id
;
1070 uint32_t __user
*crtc_id
;
1071 uint32_t __user
*connector_id
;
1072 uint32_t __user
*encoder_id
;
1073 struct drm_mode_group
*mode_group
;
1075 mutex_lock(&dev
->mode_config
.mutex
);
1078 * For the non-control nodes we need to limit the list of resources
1079 * by IDs in the group list for this node
1081 list_for_each(lh
, &file_priv
->fbs
)
1084 mode_group
= &file_priv
->master
->minor
->mode_group
;
1085 if (file_priv
->master
->minor
->type
== DRM_MINOR_CONTROL
) {
1087 list_for_each(lh
, &dev
->mode_config
.crtc_list
)
1090 list_for_each(lh
, &dev
->mode_config
.connector_list
)
1093 list_for_each(lh
, &dev
->mode_config
.encoder_list
)
1097 crtc_count
= mode_group
->num_crtcs
;
1098 connector_count
= mode_group
->num_connectors
;
1099 encoder_count
= mode_group
->num_encoders
;
1102 card_res
->max_height
= dev
->mode_config
.max_height
;
1103 card_res
->min_height
= dev
->mode_config
.min_height
;
1104 card_res
->max_width
= dev
->mode_config
.max_width
;
1105 card_res
->min_width
= dev
->mode_config
.min_width
;
1107 /* handle this in 4 parts */
1109 if (card_res
->count_fbs
>= fb_count
) {
1111 fb_id
= (uint32_t __user
*)(unsigned long)card_res
->fb_id_ptr
;
1112 list_for_each_entry(fb
, &file_priv
->fbs
, head
) {
1113 if (put_user(fb
->base
.id
, fb_id
+ copied
)) {
1120 card_res
->count_fbs
= fb_count
;
1123 if (card_res
->count_crtcs
>= crtc_count
) {
1125 crtc_id
= (uint32_t __user
*)(unsigned long)card_res
->crtc_id_ptr
;
1126 if (file_priv
->master
->minor
->type
== DRM_MINOR_CONTROL
) {
1127 list_for_each_entry(crtc
, &dev
->mode_config
.crtc_list
,
1129 DRM_DEBUG_KMS("CRTC ID is %d\n", crtc
->base
.id
);
1130 if (put_user(crtc
->base
.id
, crtc_id
+ copied
)) {
1137 for (i
= 0; i
< mode_group
->num_crtcs
; i
++) {
1138 if (put_user(mode_group
->id_list
[i
],
1139 crtc_id
+ copied
)) {
1147 card_res
->count_crtcs
= crtc_count
;
1150 if (card_res
->count_encoders
>= encoder_count
) {
1152 encoder_id
= (uint32_t __user
*)(unsigned long)card_res
->encoder_id_ptr
;
1153 if (file_priv
->master
->minor
->type
== DRM_MINOR_CONTROL
) {
1154 list_for_each_entry(encoder
,
1155 &dev
->mode_config
.encoder_list
,
1157 DRM_DEBUG_KMS("ENCODER ID is %d\n",
1159 if (put_user(encoder
->base
.id
, encoder_id
+
1167 for (i
= mode_group
->num_crtcs
; i
< mode_group
->num_crtcs
+ mode_group
->num_encoders
; i
++) {
1168 if (put_user(mode_group
->id_list
[i
],
1169 encoder_id
+ copied
)) {
1178 card_res
->count_encoders
= encoder_count
;
1181 if (card_res
->count_connectors
>= connector_count
) {
1183 connector_id
= (uint32_t __user
*)(unsigned long)card_res
->connector_id_ptr
;
1184 if (file_priv
->master
->minor
->type
== DRM_MINOR_CONTROL
) {
1185 list_for_each_entry(connector
,
1186 &dev
->mode_config
.connector_list
,
1188 DRM_DEBUG_KMS("CONNECTOR ID is %d\n",
1189 connector
->base
.id
);
1190 if (put_user(connector
->base
.id
,
1191 connector_id
+ copied
)) {
1198 int start
= mode_group
->num_crtcs
+
1199 mode_group
->num_encoders
;
1200 for (i
= start
; i
< start
+ mode_group
->num_connectors
; i
++) {
1201 if (put_user(mode_group
->id_list
[i
],
1202 connector_id
+ copied
)) {
1210 card_res
->count_connectors
= connector_count
;
1212 DRM_DEBUG_KMS("Counted %d %d %d\n", card_res
->count_crtcs
,
1213 card_res
->count_connectors
, card_res
->count_encoders
);
1216 mutex_unlock(&dev
->mode_config
.mutex
);
1221 * drm_mode_getcrtc - get CRTC configuration
1222 * @inode: inode from the ioctl
1223 * @filp: file * from the ioctl
1224 * @cmd: cmd from ioctl
1225 * @arg: arg from ioctl
1230 * Construct a CRTC configuration structure to return to the user.
1232 * Called by the user via ioctl.
1235 * Zero on success, errno on failure.
1237 int drm_mode_getcrtc(struct drm_device
*dev
,
1238 void *data
, struct drm_file
*file_priv
)
1240 struct drm_mode_crtc
*crtc_resp
= data
;
1241 struct drm_crtc
*crtc
;
1242 struct drm_mode_object
*obj
;
1245 mutex_lock(&dev
->mode_config
.mutex
);
1247 obj
= drm_mode_object_find(dev
, crtc_resp
->crtc_id
,
1248 DRM_MODE_OBJECT_CRTC
);
1253 crtc
= obj_to_crtc(obj
);
1255 crtc_resp
->x
= crtc
->x
;
1256 crtc_resp
->y
= crtc
->y
;
1257 crtc_resp
->gamma_size
= crtc
->gamma_size
;
1259 crtc_resp
->fb_id
= crtc
->fb
->base
.id
;
1261 crtc_resp
->fb_id
= 0;
1263 if (crtc
->enabled
) {
1265 drm_crtc_convert_to_umode(&crtc_resp
->mode
, &crtc
->mode
);
1266 crtc_resp
->mode_valid
= 1;
1269 crtc_resp
->mode_valid
= 0;
1273 mutex_unlock(&dev
->mode_config
.mutex
);
1278 * drm_mode_getconnector - get connector configuration
1279 * @inode: inode from the ioctl
1280 * @filp: file * from the ioctl
1281 * @cmd: cmd from ioctl
1282 * @arg: arg from ioctl
1287 * Construct a connector configuration structure to return to the user.
1289 * Called by the user via ioctl.
1292 * Zero on success, errno on failure.
1294 int drm_mode_getconnector(struct drm_device
*dev
, void *data
,
1295 struct drm_file
*file_priv
)
1297 struct drm_mode_get_connector
*out_resp
= data
;
1298 struct drm_mode_object
*obj
;
1299 struct drm_connector
*connector
;
1300 struct drm_display_mode
*mode
;
1302 int props_count
= 0;
1303 int encoders_count
= 0;
1307 struct drm_mode_modeinfo u_mode
;
1308 struct drm_mode_modeinfo __user
*mode_ptr
;
1309 uint32_t __user
*prop_ptr
;
1310 uint64_t __user
*prop_values
;
1311 uint32_t __user
*encoder_ptr
;
1313 memset(&u_mode
, 0, sizeof(struct drm_mode_modeinfo
));
1315 DRM_DEBUG_KMS("connector id %d:\n", out_resp
->connector_id
);
1317 mutex_lock(&dev
->mode_config
.mutex
);
1319 obj
= drm_mode_object_find(dev
, out_resp
->connector_id
,
1320 DRM_MODE_OBJECT_CONNECTOR
);
1325 connector
= obj_to_connector(obj
);
1327 for (i
= 0; i
< DRM_CONNECTOR_MAX_PROPERTY
; i
++) {
1328 if (connector
->property_ids
[i
] != 0) {
1333 for (i
= 0; i
< DRM_CONNECTOR_MAX_ENCODER
; i
++) {
1334 if (connector
->encoder_ids
[i
] != 0) {
1339 if (out_resp
->count_modes
== 0) {
1340 connector
->funcs
->fill_modes(connector
,
1341 dev
->mode_config
.max_width
,
1342 dev
->mode_config
.max_height
);
1345 /* delayed so we get modes regardless of pre-fill_modes state */
1346 list_for_each_entry(mode
, &connector
->modes
, head
)
1349 out_resp
->connector_id
= connector
->base
.id
;
1350 out_resp
->connector_type
= connector
->connector_type
;
1351 out_resp
->connector_type_id
= connector
->connector_type_id
;
1352 out_resp
->mm_width
= connector
->display_info
.width_mm
;
1353 out_resp
->mm_height
= connector
->display_info
.height_mm
;
1354 out_resp
->subpixel
= connector
->display_info
.subpixel_order
;
1355 out_resp
->connection
= connector
->status
;
1356 if (connector
->encoder
)
1357 out_resp
->encoder_id
= connector
->encoder
->base
.id
;
1359 out_resp
->encoder_id
= 0;
1362 * This ioctl is called twice, once to determine how much space is
1363 * needed, and the 2nd time to fill it.
1365 if ((out_resp
->count_modes
>= mode_count
) && mode_count
) {
1367 mode_ptr
= (struct drm_mode_modeinfo
*)(unsigned long)out_resp
->modes_ptr
;
1368 list_for_each_entry(mode
, &connector
->modes
, head
) {
1369 drm_crtc_convert_to_umode(&u_mode
, mode
);
1370 if (copy_to_user(mode_ptr
+ copied
,
1371 &u_mode
, sizeof(u_mode
))) {
1378 out_resp
->count_modes
= mode_count
;
1380 if ((out_resp
->count_props
>= props_count
) && props_count
) {
1382 prop_ptr
= (uint32_t *)(unsigned long)(out_resp
->props_ptr
);
1383 prop_values
= (uint64_t *)(unsigned long)(out_resp
->prop_values_ptr
);
1384 for (i
= 0; i
< DRM_CONNECTOR_MAX_PROPERTY
; i
++) {
1385 if (connector
->property_ids
[i
] != 0) {
1386 if (put_user(connector
->property_ids
[i
],
1387 prop_ptr
+ copied
)) {
1392 if (put_user(connector
->property_values
[i
],
1393 prop_values
+ copied
)) {
1401 out_resp
->count_props
= props_count
;
1403 if ((out_resp
->count_encoders
>= encoders_count
) && encoders_count
) {
1405 encoder_ptr
= (uint32_t *)(unsigned long)(out_resp
->encoders_ptr
);
1406 for (i
= 0; i
< DRM_CONNECTOR_MAX_ENCODER
; i
++) {
1407 if (connector
->encoder_ids
[i
] != 0) {
1408 if (put_user(connector
->encoder_ids
[i
],
1409 encoder_ptr
+ copied
)) {
1417 out_resp
->count_encoders
= encoders_count
;
1420 mutex_unlock(&dev
->mode_config
.mutex
);
1424 int drm_mode_getencoder(struct drm_device
*dev
, void *data
,
1425 struct drm_file
*file_priv
)
1427 struct drm_mode_get_encoder
*enc_resp
= data
;
1428 struct drm_mode_object
*obj
;
1429 struct drm_encoder
*encoder
;
1432 mutex_lock(&dev
->mode_config
.mutex
);
1433 obj
= drm_mode_object_find(dev
, enc_resp
->encoder_id
,
1434 DRM_MODE_OBJECT_ENCODER
);
1439 encoder
= obj_to_encoder(obj
);
1442 enc_resp
->crtc_id
= encoder
->crtc
->base
.id
;
1444 enc_resp
->crtc_id
= 0;
1445 enc_resp
->encoder_type
= encoder
->encoder_type
;
1446 enc_resp
->encoder_id
= encoder
->base
.id
;
1447 enc_resp
->possible_crtcs
= encoder
->possible_crtcs
;
1448 enc_resp
->possible_clones
= encoder
->possible_clones
;
1451 mutex_unlock(&dev
->mode_config
.mutex
);
1456 * drm_mode_setcrtc - set CRTC configuration
1457 * @inode: inode from the ioctl
1458 * @filp: file * from the ioctl
1459 * @cmd: cmd from ioctl
1460 * @arg: arg from ioctl
1465 * Build a new CRTC configuration based on user request.
1467 * Called by the user via ioctl.
1470 * Zero on success, errno on failure.
1472 int drm_mode_setcrtc(struct drm_device
*dev
, void *data
,
1473 struct drm_file
*file_priv
)
1475 struct drm_mode_config
*config
= &dev
->mode_config
;
1476 struct drm_mode_crtc
*crtc_req
= data
;
1477 struct drm_mode_object
*obj
;
1478 struct drm_crtc
*crtc
, *crtcfb
;
1479 struct drm_connector
**connector_set
= NULL
, *connector
;
1480 struct drm_framebuffer
*fb
= NULL
;
1481 struct drm_display_mode
*mode
= NULL
;
1482 struct drm_mode_set set
;
1483 uint32_t __user
*set_connectors_ptr
;
1487 mutex_lock(&dev
->mode_config
.mutex
);
1488 obj
= drm_mode_object_find(dev
, crtc_req
->crtc_id
,
1489 DRM_MODE_OBJECT_CRTC
);
1491 DRM_DEBUG_KMS("Unknown CRTC ID %d\n", crtc_req
->crtc_id
);
1495 crtc
= obj_to_crtc(obj
);
1497 if (crtc_req
->mode_valid
) {
1498 /* If we have a mode we need a framebuffer. */
1499 /* If we pass -1, set the mode with the currently bound fb */
1500 if (crtc_req
->fb_id
== -1) {
1501 list_for_each_entry(crtcfb
,
1502 &dev
->mode_config
.crtc_list
, head
) {
1503 if (crtcfb
== crtc
) {
1504 DRM_DEBUG_KMS("Using current fb for "
1510 obj
= drm_mode_object_find(dev
, crtc_req
->fb_id
,
1511 DRM_MODE_OBJECT_FB
);
1513 DRM_DEBUG_KMS("Unknown FB ID%d\n",
1518 fb
= obj_to_fb(obj
);
1521 mode
= drm_mode_create(dev
);
1522 drm_crtc_convert_umode(mode
, &crtc_req
->mode
);
1523 drm_mode_set_crtcinfo(mode
, CRTC_INTERLACE_HALVE_V
);
1526 if (crtc_req
->count_connectors
== 0 && mode
) {
1527 DRM_DEBUG_KMS("Count connectors is 0 but mode set\n");
1532 if (crtc_req
->count_connectors
> 0 && (!mode
|| !fb
)) {
1533 DRM_DEBUG_KMS("Count connectors is %d but no mode or fb set\n",
1534 crtc_req
->count_connectors
);
1539 if (crtc_req
->count_connectors
> 0) {
1542 /* Avoid unbounded kernel memory allocation */
1543 if (crtc_req
->count_connectors
> config
->num_connector
) {
1548 connector_set
= kmalloc(crtc_req
->count_connectors
*
1549 sizeof(struct drm_connector
*),
1551 if (!connector_set
) {
1556 for (i
= 0; i
< crtc_req
->count_connectors
; i
++) {
1557 set_connectors_ptr
= (uint32_t *)(unsigned long)crtc_req
->set_connectors_ptr
;
1558 if (get_user(out_id
, &set_connectors_ptr
[i
])) {
1563 obj
= drm_mode_object_find(dev
, out_id
,
1564 DRM_MODE_OBJECT_CONNECTOR
);
1566 DRM_DEBUG_KMS("Connector id %d unknown\n",
1571 connector
= obj_to_connector(obj
);
1573 connector_set
[i
] = connector
;
1578 set
.x
= crtc_req
->x
;
1579 set
.y
= crtc_req
->y
;
1581 set
.connectors
= connector_set
;
1582 set
.num_connectors
= crtc_req
->count_connectors
;
1584 ret
= crtc
->funcs
->set_config(&set
);
1587 kfree(connector_set
);
1588 mutex_unlock(&dev
->mode_config
.mutex
);
1592 int drm_mode_cursor_ioctl(struct drm_device
*dev
,
1593 void *data
, struct drm_file
*file_priv
)
1595 struct drm_mode_cursor
*req
= data
;
1596 struct drm_mode_object
*obj
;
1597 struct drm_crtc
*crtc
;
1601 DRM_ERROR("no operation set\n");
1605 mutex_lock(&dev
->mode_config
.mutex
);
1606 obj
= drm_mode_object_find(dev
, req
->crtc_id
, DRM_MODE_OBJECT_CRTC
);
1608 DRM_DEBUG_KMS("Unknown CRTC ID %d\n", req
->crtc_id
);
1612 crtc
= obj_to_crtc(obj
);
1614 if (req
->flags
& DRM_MODE_CURSOR_BO
) {
1615 if (!crtc
->funcs
->cursor_set
) {
1616 DRM_ERROR("crtc does not support cursor\n");
1620 /* Turns off the cursor if handle is 0 */
1621 ret
= crtc
->funcs
->cursor_set(crtc
, file_priv
, req
->handle
,
1622 req
->width
, req
->height
);
1625 if (req
->flags
& DRM_MODE_CURSOR_MOVE
) {
1626 if (crtc
->funcs
->cursor_move
) {
1627 ret
= crtc
->funcs
->cursor_move(crtc
, req
->x
, req
->y
);
1629 DRM_ERROR("crtc does not support cursor\n");
1635 mutex_unlock(&dev
->mode_config
.mutex
);
1640 * drm_mode_addfb - add an FB to the graphics configuration
1641 * @inode: inode from the ioctl
1642 * @filp: file * from the ioctl
1643 * @cmd: cmd from ioctl
1644 * @arg: arg from ioctl
1647 * Takes mode config lock.
1649 * Add a new FB to the specified CRTC, given a user request.
1651 * Called by the user via ioctl.
1654 * Zero on success, errno on failure.
1656 int drm_mode_addfb(struct drm_device
*dev
,
1657 void *data
, struct drm_file
*file_priv
)
1659 struct drm_mode_fb_cmd
*r
= data
;
1660 struct drm_mode_config
*config
= &dev
->mode_config
;
1661 struct drm_framebuffer
*fb
;
1664 if ((config
->min_width
> r
->width
) || (r
->width
> config
->max_width
)) {
1665 DRM_ERROR("mode new framebuffer width not within limits\n");
1668 if ((config
->min_height
> r
->height
) || (r
->height
> config
->max_height
)) {
1669 DRM_ERROR("mode new framebuffer height not within limits\n");
1673 mutex_lock(&dev
->mode_config
.mutex
);
1675 /* TODO check buffer is sufficently large */
1676 /* TODO setup destructor callback */
1678 fb
= dev
->mode_config
.funcs
->fb_create(dev
, file_priv
, r
);
1680 DRM_ERROR("could not create framebuffer\n");
1685 r
->fb_id
= fb
->base
.id
;
1686 list_add(&fb
->filp_head
, &file_priv
->fbs
);
1689 mutex_unlock(&dev
->mode_config
.mutex
);
1694 * drm_mode_rmfb - remove an FB from the configuration
1695 * @inode: inode from the ioctl
1696 * @filp: file * from the ioctl
1697 * @cmd: cmd from ioctl
1698 * @arg: arg from ioctl
1701 * Takes mode config lock.
1703 * Remove the FB specified by the user.
1705 * Called by the user via ioctl.
1708 * Zero on success, errno on failure.
1710 int drm_mode_rmfb(struct drm_device
*dev
,
1711 void *data
, struct drm_file
*file_priv
)
1713 struct drm_mode_object
*obj
;
1714 struct drm_framebuffer
*fb
= NULL
;
1715 struct drm_framebuffer
*fbl
= NULL
;
1716 uint32_t *id
= data
;
1720 mutex_lock(&dev
->mode_config
.mutex
);
1721 obj
= drm_mode_object_find(dev
, *id
, DRM_MODE_OBJECT_FB
);
1722 /* TODO check that we realy get a framebuffer back. */
1724 DRM_ERROR("mode invalid framebuffer id\n");
1728 fb
= obj_to_fb(obj
);
1730 list_for_each_entry(fbl
, &file_priv
->fbs
, filp_head
)
1735 DRM_ERROR("tried to remove a fb that we didn't own\n");
1740 /* TODO release all crtc connected to the framebuffer */
1741 /* TODO unhock the destructor from the buffer object */
1743 list_del(&fb
->filp_head
);
1744 fb
->funcs
->destroy(fb
);
1747 mutex_unlock(&dev
->mode_config
.mutex
);
1752 * drm_mode_getfb - get FB info
1753 * @inode: inode from the ioctl
1754 * @filp: file * from the ioctl
1755 * @cmd: cmd from ioctl
1756 * @arg: arg from ioctl
1761 * Lookup the FB given its ID and return info about it.
1763 * Called by the user via ioctl.
1766 * Zero on success, errno on failure.
1768 int drm_mode_getfb(struct drm_device
*dev
,
1769 void *data
, struct drm_file
*file_priv
)
1771 struct drm_mode_fb_cmd
*r
= data
;
1772 struct drm_mode_object
*obj
;
1773 struct drm_framebuffer
*fb
;
1776 mutex_lock(&dev
->mode_config
.mutex
);
1777 obj
= drm_mode_object_find(dev
, r
->fb_id
, DRM_MODE_OBJECT_FB
);
1779 DRM_ERROR("invalid framebuffer id\n");
1783 fb
= obj_to_fb(obj
);
1785 r
->height
= fb
->height
;
1786 r
->width
= fb
->width
;
1787 r
->depth
= fb
->depth
;
1788 r
->bpp
= fb
->bits_per_pixel
;
1789 r
->pitch
= fb
->pitch
;
1790 fb
->funcs
->create_handle(fb
, file_priv
, &r
->handle
);
1793 mutex_unlock(&dev
->mode_config
.mutex
);
1797 int drm_mode_dirtyfb_ioctl(struct drm_device
*dev
,
1798 void *data
, struct drm_file
*file_priv
)
1800 struct drm_clip_rect __user
*clips_ptr
;
1801 struct drm_clip_rect
*clips
= NULL
;
1802 struct drm_mode_fb_dirty_cmd
*r
= data
;
1803 struct drm_mode_object
*obj
;
1804 struct drm_framebuffer
*fb
;
1809 mutex_lock(&dev
->mode_config
.mutex
);
1810 obj
= drm_mode_object_find(dev
, r
->fb_id
, DRM_MODE_OBJECT_FB
);
1812 DRM_ERROR("invalid framebuffer id\n");
1816 fb
= obj_to_fb(obj
);
1818 num_clips
= r
->num_clips
;
1819 clips_ptr
= (struct drm_clip_rect
*)(unsigned long)r
->clips_ptr
;
1821 if (!num_clips
!= !clips_ptr
) {
1826 flags
= DRM_MODE_FB_DIRTY_FLAGS
& r
->flags
;
1828 /* If userspace annotates copy, clips must come in pairs */
1829 if (flags
& DRM_MODE_FB_DIRTY_ANNOTATE_COPY
&& (num_clips
% 2)) {
1834 if (num_clips
&& clips_ptr
) {
1835 clips
= kzalloc(num_clips
* sizeof(*clips
), GFP_KERNEL
);
1841 ret
= copy_from_user(clips
, clips_ptr
,
1842 num_clips
* sizeof(*clips
));
1847 if (fb
->funcs
->dirty
) {
1848 ret
= fb
->funcs
->dirty(fb
, flags
, r
->color
, clips
, num_clips
);
1857 mutex_unlock(&dev
->mode_config
.mutex
);
1863 * drm_fb_release - remove and free the FBs on this file
1864 * @filp: file * from the ioctl
1867 * Takes mode config lock.
1869 * Destroy all the FBs associated with @filp.
1871 * Called by the user via ioctl.
1874 * Zero on success, errno on failure.
1876 void drm_fb_release(struct drm_file
*priv
)
1878 struct drm_device
*dev
= priv
->minor
->dev
;
1879 struct drm_framebuffer
*fb
, *tfb
;
1881 mutex_lock(&dev
->mode_config
.mutex
);
1882 list_for_each_entry_safe(fb
, tfb
, &priv
->fbs
, filp_head
) {
1883 list_del(&fb
->filp_head
);
1884 fb
->funcs
->destroy(fb
);
1886 mutex_unlock(&dev
->mode_config
.mutex
);
1890 * drm_mode_attachmode - add a mode to the user mode list
1892 * @connector: connector to add the mode to
1893 * @mode: mode to add
1895 * Add @mode to @connector's user mode list.
1897 static int drm_mode_attachmode(struct drm_device
*dev
,
1898 struct drm_connector
*connector
,
1899 struct drm_display_mode
*mode
)
1903 list_add_tail(&mode
->head
, &connector
->user_modes
);
1907 int drm_mode_attachmode_crtc(struct drm_device
*dev
, struct drm_crtc
*crtc
,
1908 struct drm_display_mode
*mode
)
1910 struct drm_connector
*connector
;
1912 struct drm_display_mode
*dup_mode
;
1914 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
, head
) {
1915 if (!connector
->encoder
)
1917 if (connector
->encoder
->crtc
== crtc
) {
1919 dup_mode
= drm_mode_duplicate(dev
, mode
);
1922 ret
= drm_mode_attachmode(dev
, connector
, dup_mode
);
1930 EXPORT_SYMBOL(drm_mode_attachmode_crtc
);
1932 static int drm_mode_detachmode(struct drm_device
*dev
,
1933 struct drm_connector
*connector
,
1934 struct drm_display_mode
*mode
)
1938 struct drm_display_mode
*match_mode
, *t
;
1940 list_for_each_entry_safe(match_mode
, t
, &connector
->user_modes
, head
) {
1941 if (drm_mode_equal(match_mode
, mode
)) {
1942 list_del(&match_mode
->head
);
1943 drm_mode_destroy(dev
, match_mode
);
1955 int drm_mode_detachmode_crtc(struct drm_device
*dev
, struct drm_display_mode
*mode
)
1957 struct drm_connector
*connector
;
1959 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
, head
) {
1960 drm_mode_detachmode(dev
, connector
, mode
);
1964 EXPORT_SYMBOL(drm_mode_detachmode_crtc
);
1967 * drm_fb_attachmode - Attach a user mode to an connector
1968 * @inode: inode from the ioctl
1969 * @filp: file * from the ioctl
1970 * @cmd: cmd from ioctl
1971 * @arg: arg from ioctl
1973 * This attaches a user specified mode to an connector.
1974 * Called by the user via ioctl.
1977 * Zero on success, errno on failure.
1979 int drm_mode_attachmode_ioctl(struct drm_device
*dev
,
1980 void *data
, struct drm_file
*file_priv
)
1982 struct drm_mode_mode_cmd
*mode_cmd
= data
;
1983 struct drm_connector
*connector
;
1984 struct drm_display_mode
*mode
;
1985 struct drm_mode_object
*obj
;
1986 struct drm_mode_modeinfo
*umode
= &mode_cmd
->mode
;
1989 mutex_lock(&dev
->mode_config
.mutex
);
1991 obj
= drm_mode_object_find(dev
, mode_cmd
->connector_id
, DRM_MODE_OBJECT_CONNECTOR
);
1996 connector
= obj_to_connector(obj
);
1998 mode
= drm_mode_create(dev
);
2004 drm_crtc_convert_umode(mode
, umode
);
2006 ret
= drm_mode_attachmode(dev
, connector
, mode
);
2008 mutex_unlock(&dev
->mode_config
.mutex
);
2014 * drm_fb_detachmode - Detach a user specified mode from an connector
2015 * @inode: inode from the ioctl
2016 * @filp: file * from the ioctl
2017 * @cmd: cmd from ioctl
2018 * @arg: arg from ioctl
2020 * Called by the user via ioctl.
2023 * Zero on success, errno on failure.
2025 int drm_mode_detachmode_ioctl(struct drm_device
*dev
,
2026 void *data
, struct drm_file
*file_priv
)
2028 struct drm_mode_object
*obj
;
2029 struct drm_mode_mode_cmd
*mode_cmd
= data
;
2030 struct drm_connector
*connector
;
2031 struct drm_display_mode mode
;
2032 struct drm_mode_modeinfo
*umode
= &mode_cmd
->mode
;
2035 mutex_lock(&dev
->mode_config
.mutex
);
2037 obj
= drm_mode_object_find(dev
, mode_cmd
->connector_id
, DRM_MODE_OBJECT_CONNECTOR
);
2042 connector
= obj_to_connector(obj
);
2044 drm_crtc_convert_umode(&mode
, umode
);
2045 ret
= drm_mode_detachmode(dev
, connector
, &mode
);
2047 mutex_unlock(&dev
->mode_config
.mutex
);
2051 struct drm_property
*drm_property_create(struct drm_device
*dev
, int flags
,
2052 const char *name
, int num_values
)
2054 struct drm_property
*property
= NULL
;
2056 property
= kzalloc(sizeof(struct drm_property
), GFP_KERNEL
);
2061 property
->values
= kzalloc(sizeof(uint64_t)*num_values
, GFP_KERNEL
);
2062 if (!property
->values
)
2066 drm_mode_object_get(dev
, &property
->base
, DRM_MODE_OBJECT_PROPERTY
);
2067 property
->flags
= flags
;
2068 property
->num_values
= num_values
;
2069 INIT_LIST_HEAD(&property
->enum_blob_list
);
2072 strncpy(property
->name
, name
, DRM_PROP_NAME_LEN
);
2074 list_add_tail(&property
->head
, &dev
->mode_config
.property_list
);
2080 EXPORT_SYMBOL(drm_property_create
);
2082 int drm_property_add_enum(struct drm_property
*property
, int index
,
2083 uint64_t value
, const char *name
)
2085 struct drm_property_enum
*prop_enum
;
2087 if (!(property
->flags
& DRM_MODE_PROP_ENUM
))
2090 if (!list_empty(&property
->enum_blob_list
)) {
2091 list_for_each_entry(prop_enum
, &property
->enum_blob_list
, head
) {
2092 if (prop_enum
->value
== value
) {
2093 strncpy(prop_enum
->name
, name
, DRM_PROP_NAME_LEN
);
2094 prop_enum
->name
[DRM_PROP_NAME_LEN
-1] = '\0';
2100 prop_enum
= kzalloc(sizeof(struct drm_property_enum
), GFP_KERNEL
);
2104 strncpy(prop_enum
->name
, name
, DRM_PROP_NAME_LEN
);
2105 prop_enum
->name
[DRM_PROP_NAME_LEN
-1] = '\0';
2106 prop_enum
->value
= value
;
2108 property
->values
[index
] = value
;
2109 list_add_tail(&prop_enum
->head
, &property
->enum_blob_list
);
2112 EXPORT_SYMBOL(drm_property_add_enum
);
2114 void drm_property_destroy(struct drm_device
*dev
, struct drm_property
*property
)
2116 struct drm_property_enum
*prop_enum
, *pt
;
2118 list_for_each_entry_safe(prop_enum
, pt
, &property
->enum_blob_list
, head
) {
2119 list_del(&prop_enum
->head
);
2123 if (property
->num_values
)
2124 kfree(property
->values
);
2125 drm_mode_object_put(dev
, &property
->base
);
2126 list_del(&property
->head
);
2129 EXPORT_SYMBOL(drm_property_destroy
);
2131 int drm_connector_attach_property(struct drm_connector
*connector
,
2132 struct drm_property
*property
, uint64_t init_val
)
2136 for (i
= 0; i
< DRM_CONNECTOR_MAX_PROPERTY
; i
++) {
2137 if (connector
->property_ids
[i
] == 0) {
2138 connector
->property_ids
[i
] = property
->base
.id
;
2139 connector
->property_values
[i
] = init_val
;
2144 if (i
== DRM_CONNECTOR_MAX_PROPERTY
)
2148 EXPORT_SYMBOL(drm_connector_attach_property
);
2150 int drm_connector_property_set_value(struct drm_connector
*connector
,
2151 struct drm_property
*property
, uint64_t value
)
2155 for (i
= 0; i
< DRM_CONNECTOR_MAX_PROPERTY
; i
++) {
2156 if (connector
->property_ids
[i
] == property
->base
.id
) {
2157 connector
->property_values
[i
] = value
;
2162 if (i
== DRM_CONNECTOR_MAX_PROPERTY
)
2166 EXPORT_SYMBOL(drm_connector_property_set_value
);
2168 int drm_connector_property_get_value(struct drm_connector
*connector
,
2169 struct drm_property
*property
, uint64_t *val
)
2173 for (i
= 0; i
< DRM_CONNECTOR_MAX_PROPERTY
; i
++) {
2174 if (connector
->property_ids
[i
] == property
->base
.id
) {
2175 *val
= connector
->property_values
[i
];
2180 if (i
== DRM_CONNECTOR_MAX_PROPERTY
)
2184 EXPORT_SYMBOL(drm_connector_property_get_value
);
2186 int drm_mode_getproperty_ioctl(struct drm_device
*dev
,
2187 void *data
, struct drm_file
*file_priv
)
2189 struct drm_mode_object
*obj
;
2190 struct drm_mode_get_property
*out_resp
= data
;
2191 struct drm_property
*property
;
2194 int value_count
= 0;
2197 struct drm_property_enum
*prop_enum
;
2198 struct drm_mode_property_enum __user
*enum_ptr
;
2199 struct drm_property_blob
*prop_blob
;
2200 uint32_t *blob_id_ptr
;
2201 uint64_t __user
*values_ptr
;
2202 uint32_t __user
*blob_length_ptr
;
2204 mutex_lock(&dev
->mode_config
.mutex
);
2205 obj
= drm_mode_object_find(dev
, out_resp
->prop_id
, DRM_MODE_OBJECT_PROPERTY
);
2210 property
= obj_to_property(obj
);
2212 if (property
->flags
& DRM_MODE_PROP_ENUM
) {
2213 list_for_each_entry(prop_enum
, &property
->enum_blob_list
, head
)
2215 } else if (property
->flags
& DRM_MODE_PROP_BLOB
) {
2216 list_for_each_entry(prop_blob
, &property
->enum_blob_list
, head
)
2220 value_count
= property
->num_values
;
2222 strncpy(out_resp
->name
, property
->name
, DRM_PROP_NAME_LEN
);
2223 out_resp
->name
[DRM_PROP_NAME_LEN
-1] = 0;
2224 out_resp
->flags
= property
->flags
;
2226 if ((out_resp
->count_values
>= value_count
) && value_count
) {
2227 values_ptr
= (uint64_t *)(unsigned long)out_resp
->values_ptr
;
2228 for (i
= 0; i
< value_count
; i
++) {
2229 if (copy_to_user(values_ptr
+ i
, &property
->values
[i
], sizeof(uint64_t))) {
2235 out_resp
->count_values
= value_count
;
2237 if (property
->flags
& DRM_MODE_PROP_ENUM
) {
2238 if ((out_resp
->count_enum_blobs
>= enum_count
) && enum_count
) {
2240 enum_ptr
= (struct drm_mode_property_enum
*)(unsigned long)out_resp
->enum_blob_ptr
;
2241 list_for_each_entry(prop_enum
, &property
->enum_blob_list
, head
) {
2243 if (copy_to_user(&enum_ptr
[copied
].value
, &prop_enum
->value
, sizeof(uint64_t))) {
2248 if (copy_to_user(&enum_ptr
[copied
].name
,
2249 &prop_enum
->name
, DRM_PROP_NAME_LEN
)) {
2256 out_resp
->count_enum_blobs
= enum_count
;
2259 if (property
->flags
& DRM_MODE_PROP_BLOB
) {
2260 if ((out_resp
->count_enum_blobs
>= blob_count
) && blob_count
) {
2262 blob_id_ptr
= (uint32_t *)(unsigned long)out_resp
->enum_blob_ptr
;
2263 blob_length_ptr
= (uint32_t *)(unsigned long)out_resp
->values_ptr
;
2265 list_for_each_entry(prop_blob
, &property
->enum_blob_list
, head
) {
2266 if (put_user(prop_blob
->base
.id
, blob_id_ptr
+ copied
)) {
2271 if (put_user(prop_blob
->length
, blob_length_ptr
+ copied
)) {
2279 out_resp
->count_enum_blobs
= blob_count
;
2282 mutex_unlock(&dev
->mode_config
.mutex
);
2286 static struct drm_property_blob
*drm_property_create_blob(struct drm_device
*dev
, int length
,
2289 struct drm_property_blob
*blob
;
2291 if (!length
|| !data
)
2294 blob
= kzalloc(sizeof(struct drm_property_blob
)+length
, GFP_KERNEL
);
2298 blob
->data
= (void *)((char *)blob
+ sizeof(struct drm_property_blob
));
2299 blob
->length
= length
;
2301 memcpy(blob
->data
, data
, length
);
2303 drm_mode_object_get(dev
, &blob
->base
, DRM_MODE_OBJECT_BLOB
);
2305 list_add_tail(&blob
->head
, &dev
->mode_config
.property_blob_list
);
2309 static void drm_property_destroy_blob(struct drm_device
*dev
,
2310 struct drm_property_blob
*blob
)
2312 drm_mode_object_put(dev
, &blob
->base
);
2313 list_del(&blob
->head
);
2317 int drm_mode_getblob_ioctl(struct drm_device
*dev
,
2318 void *data
, struct drm_file
*file_priv
)
2320 struct drm_mode_object
*obj
;
2321 struct drm_mode_get_blob
*out_resp
= data
;
2322 struct drm_property_blob
*blob
;
2326 mutex_lock(&dev
->mode_config
.mutex
);
2327 obj
= drm_mode_object_find(dev
, out_resp
->blob_id
, DRM_MODE_OBJECT_BLOB
);
2332 blob
= obj_to_blob(obj
);
2334 if (out_resp
->length
== blob
->length
) {
2335 blob_ptr
= (void *)(unsigned long)out_resp
->data
;
2336 if (copy_to_user(blob_ptr
, blob
->data
, blob
->length
)){
2341 out_resp
->length
= blob
->length
;
2344 mutex_unlock(&dev
->mode_config
.mutex
);
2348 int drm_mode_connector_update_edid_property(struct drm_connector
*connector
,
2351 struct drm_device
*dev
= connector
->dev
;
2354 if (connector
->edid_blob_ptr
)
2355 drm_property_destroy_blob(dev
, connector
->edid_blob_ptr
);
2357 /* Delete edid, when there is none. */
2359 connector
->edid_blob_ptr
= NULL
;
2360 ret
= drm_connector_property_set_value(connector
, dev
->mode_config
.edid_property
, 0);
2364 connector
->edid_blob_ptr
= drm_property_create_blob(connector
->dev
, 128, edid
);
2366 ret
= drm_connector_property_set_value(connector
,
2367 dev
->mode_config
.edid_property
,
2368 connector
->edid_blob_ptr
->base
.id
);
2372 EXPORT_SYMBOL(drm_mode_connector_update_edid_property
);
2374 int drm_mode_connector_property_set_ioctl(struct drm_device
*dev
,
2375 void *data
, struct drm_file
*file_priv
)
2377 struct drm_mode_connector_set_property
*out_resp
= data
;
2378 struct drm_mode_object
*obj
;
2379 struct drm_property
*property
;
2380 struct drm_connector
*connector
;
2384 mutex_lock(&dev
->mode_config
.mutex
);
2386 obj
= drm_mode_object_find(dev
, out_resp
->connector_id
, DRM_MODE_OBJECT_CONNECTOR
);
2390 connector
= obj_to_connector(obj
);
2392 for (i
= 0; i
< DRM_CONNECTOR_MAX_PROPERTY
; i
++) {
2393 if (connector
->property_ids
[i
] == out_resp
->prop_id
)
2397 if (i
== DRM_CONNECTOR_MAX_PROPERTY
) {
2401 obj
= drm_mode_object_find(dev
, out_resp
->prop_id
, DRM_MODE_OBJECT_PROPERTY
);
2405 property
= obj_to_property(obj
);
2407 if (property
->flags
& DRM_MODE_PROP_IMMUTABLE
)
2410 if (property
->flags
& DRM_MODE_PROP_RANGE
) {
2411 if (out_resp
->value
< property
->values
[0])
2414 if (out_resp
->value
> property
->values
[1])
2418 for (i
= 0; i
< property
->num_values
; i
++) {
2419 if (property
->values
[i
] == out_resp
->value
) {
2429 /* Do DPMS ourselves */
2430 if (property
== connector
->dev
->mode_config
.dpms_property
) {
2431 if (connector
->funcs
->dpms
)
2432 (*connector
->funcs
->dpms
)(connector
, (int) out_resp
->value
);
2434 } else if (connector
->funcs
->set_property
)
2435 ret
= connector
->funcs
->set_property(connector
, property
, out_resp
->value
);
2437 /* store the property value if successful */
2439 drm_connector_property_set_value(connector
, property
, out_resp
->value
);
2441 mutex_unlock(&dev
->mode_config
.mutex
);
2445 int drm_mode_connector_attach_encoder(struct drm_connector
*connector
,
2446 struct drm_encoder
*encoder
)
2450 for (i
= 0; i
< DRM_CONNECTOR_MAX_ENCODER
; i
++) {
2451 if (connector
->encoder_ids
[i
] == 0) {
2452 connector
->encoder_ids
[i
] = encoder
->base
.id
;
2458 EXPORT_SYMBOL(drm_mode_connector_attach_encoder
);
2460 void drm_mode_connector_detach_encoder(struct drm_connector
*connector
,
2461 struct drm_encoder
*encoder
)
2464 for (i
= 0; i
< DRM_CONNECTOR_MAX_ENCODER
; i
++) {
2465 if (connector
->encoder_ids
[i
] == encoder
->base
.id
) {
2466 connector
->encoder_ids
[i
] = 0;
2467 if (connector
->encoder
== encoder
)
2468 connector
->encoder
= NULL
;
2473 EXPORT_SYMBOL(drm_mode_connector_detach_encoder
);
2475 bool drm_mode_crtc_set_gamma_size(struct drm_crtc
*crtc
,
2478 crtc
->gamma_size
= gamma_size
;
2480 crtc
->gamma_store
= kzalloc(gamma_size
* sizeof(uint16_t) * 3, GFP_KERNEL
);
2481 if (!crtc
->gamma_store
) {
2482 crtc
->gamma_size
= 0;
2488 EXPORT_SYMBOL(drm_mode_crtc_set_gamma_size
);
2490 int drm_mode_gamma_set_ioctl(struct drm_device
*dev
,
2491 void *data
, struct drm_file
*file_priv
)
2493 struct drm_mode_crtc_lut
*crtc_lut
= data
;
2494 struct drm_mode_object
*obj
;
2495 struct drm_crtc
*crtc
;
2496 void *r_base
, *g_base
, *b_base
;
2500 mutex_lock(&dev
->mode_config
.mutex
);
2501 obj
= drm_mode_object_find(dev
, crtc_lut
->crtc_id
, DRM_MODE_OBJECT_CRTC
);
2506 crtc
= obj_to_crtc(obj
);
2508 /* memcpy into gamma store */
2509 if (crtc_lut
->gamma_size
!= crtc
->gamma_size
) {
2514 size
= crtc_lut
->gamma_size
* (sizeof(uint16_t));
2515 r_base
= crtc
->gamma_store
;
2516 if (copy_from_user(r_base
, (void __user
*)(unsigned long)crtc_lut
->red
, size
)) {
2521 g_base
= r_base
+ size
;
2522 if (copy_from_user(g_base
, (void __user
*)(unsigned long)crtc_lut
->green
, size
)) {
2527 b_base
= g_base
+ size
;
2528 if (copy_from_user(b_base
, (void __user
*)(unsigned long)crtc_lut
->blue
, size
)) {
2533 crtc
->funcs
->gamma_set(crtc
, r_base
, g_base
, b_base
, crtc
->gamma_size
);
2536 mutex_unlock(&dev
->mode_config
.mutex
);
2541 int drm_mode_gamma_get_ioctl(struct drm_device
*dev
,
2542 void *data
, struct drm_file
*file_priv
)
2544 struct drm_mode_crtc_lut
*crtc_lut
= data
;
2545 struct drm_mode_object
*obj
;
2546 struct drm_crtc
*crtc
;
2547 void *r_base
, *g_base
, *b_base
;
2551 mutex_lock(&dev
->mode_config
.mutex
);
2552 obj
= drm_mode_object_find(dev
, crtc_lut
->crtc_id
, DRM_MODE_OBJECT_CRTC
);
2557 crtc
= obj_to_crtc(obj
);
2559 /* memcpy into gamma store */
2560 if (crtc_lut
->gamma_size
!= crtc
->gamma_size
) {
2565 size
= crtc_lut
->gamma_size
* (sizeof(uint16_t));
2566 r_base
= crtc
->gamma_store
;
2567 if (copy_to_user((void __user
*)(unsigned long)crtc_lut
->red
, r_base
, size
)) {
2572 g_base
= r_base
+ size
;
2573 if (copy_to_user((void __user
*)(unsigned long)crtc_lut
->green
, g_base
, size
)) {
2578 b_base
= g_base
+ size
;
2579 if (copy_to_user((void __user
*)(unsigned long)crtc_lut
->blue
, b_base
, size
)) {
2584 mutex_unlock(&dev
->mode_config
.mutex
);
2588 int drm_mode_page_flip_ioctl(struct drm_device
*dev
,
2589 void *data
, struct drm_file
*file_priv
)
2591 struct drm_mode_crtc_page_flip
*page_flip
= data
;
2592 struct drm_mode_object
*obj
;
2593 struct drm_crtc
*crtc
;
2594 struct drm_framebuffer
*fb
;
2595 struct drm_pending_vblank_event
*e
= NULL
;
2596 unsigned long flags
;
2599 if (page_flip
->flags
& ~DRM_MODE_PAGE_FLIP_FLAGS
||
2600 page_flip
->reserved
!= 0)
2603 mutex_lock(&dev
->mode_config
.mutex
);
2604 obj
= drm_mode_object_find(dev
, page_flip
->crtc_id
, DRM_MODE_OBJECT_CRTC
);
2607 crtc
= obj_to_crtc(obj
);
2609 if (crtc
->funcs
->page_flip
== NULL
)
2612 obj
= drm_mode_object_find(dev
, page_flip
->fb_id
, DRM_MODE_OBJECT_FB
);
2615 fb
= obj_to_fb(obj
);
2617 if (page_flip
->flags
& DRM_MODE_PAGE_FLIP_EVENT
) {
2619 spin_lock_irqsave(&dev
->event_lock
, flags
);
2620 if (file_priv
->event_space
< sizeof e
->event
) {
2621 spin_unlock_irqrestore(&dev
->event_lock
, flags
);
2624 file_priv
->event_space
-= sizeof e
->event
;
2625 spin_unlock_irqrestore(&dev
->event_lock
, flags
);
2627 e
= kzalloc(sizeof *e
, GFP_KERNEL
);
2629 spin_lock_irqsave(&dev
->event_lock
, flags
);
2630 file_priv
->event_space
+= sizeof e
->event
;
2631 spin_unlock_irqrestore(&dev
->event_lock
, flags
);
2635 e
->event
.base
.type
= DRM_EVENT_FLIP_COMPLETE
;
2636 e
->event
.base
.length
= sizeof e
->event
;
2637 e
->event
.user_data
= page_flip
->user_data
;
2638 e
->base
.event
= &e
->event
.base
;
2639 e
->base
.file_priv
= file_priv
;
2641 (void (*) (struct drm_pending_event
*)) kfree
;
2644 ret
= crtc
->funcs
->page_flip(crtc
, fb
, e
);
2646 spin_lock_irqsave(&dev
->event_lock
, flags
);
2647 file_priv
->event_space
+= sizeof e
->event
;
2648 spin_unlock_irqrestore(&dev
->event_lock
, flags
);
2653 mutex_unlock(&dev
->mode_config
.mutex
);