2 * Copyright (c) 2006-2008 Intel Corporation
3 * Copyright (c) 2007 Dave Airlie <airlied@linux.ie>
4 * Copyright (c) 2008 Red Hat Inc.
6 * DRM core CRTC related functions
8 * Permission to use, copy, modify, distribute, and sell this software and its
9 * documentation for any purpose is hereby granted without fee, provided that
10 * the above copyright notice appear in all copies and that both that copyright
11 * notice and this permission notice appear in supporting documentation, and
12 * that the name of the copyright holders not be used in advertising or
13 * publicity pertaining to distribution of the software without specific,
14 * written prior permission. The copyright holders make no representations
15 * about the suitability of this software for any purpose. It is provided "as
16 * is" without express or implied warranty.
18 * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
19 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
20 * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
21 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
22 * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
23 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
28 * Eric Anholt <eric@anholt.net>
29 * Dave Airlie <airlied@linux.ie>
30 * Jesse Barnes <jesse.barnes@intel.com>
32 #include <linux/list.h>
33 #include <linux/slab.h>
39 struct drm_prop_enum_list
{
44 /* Avoid boilerplate. I'm tired of typing. */
45 #define DRM_ENUM_NAME_FN(fnname, list) \
46 char *fnname(int val) \
49 for (i = 0; i < ARRAY_SIZE(list); i++) { \
50 if (list[i].type == val) \
51 return list[i].name; \
59 static struct drm_prop_enum_list drm_dpms_enum_list
[] =
60 { { DRM_MODE_DPMS_ON
, "On" },
61 { DRM_MODE_DPMS_STANDBY
, "Standby" },
62 { DRM_MODE_DPMS_SUSPEND
, "Suspend" },
63 { DRM_MODE_DPMS_OFF
, "Off" }
66 DRM_ENUM_NAME_FN(drm_get_dpms_name
, drm_dpms_enum_list
)
71 static struct drm_prop_enum_list drm_scaling_mode_enum_list
[] =
73 { DRM_MODE_SCALE_NONE
, "None" },
74 { DRM_MODE_SCALE_FULLSCREEN
, "Full" },
75 { DRM_MODE_SCALE_CENTER
, "Center" },
76 { DRM_MODE_SCALE_ASPECT
, "Full aspect" },
79 static struct drm_prop_enum_list drm_dithering_mode_enum_list
[] =
81 { DRM_MODE_DITHERING_OFF
, "Off" },
82 { DRM_MODE_DITHERING_ON
, "On" },
83 { DRM_MODE_DITHERING_AUTO
, "Automatic" },
87 * Non-global properties, but "required" for certain connectors.
89 static struct drm_prop_enum_list drm_dvi_i_select_enum_list
[] =
91 { DRM_MODE_SUBCONNECTOR_Automatic
, "Automatic" }, /* DVI-I and TV-out */
92 { DRM_MODE_SUBCONNECTOR_DVID
, "DVI-D" }, /* DVI-I */
93 { DRM_MODE_SUBCONNECTOR_DVIA
, "DVI-A" }, /* DVI-I */
96 DRM_ENUM_NAME_FN(drm_get_dvi_i_select_name
, drm_dvi_i_select_enum_list
)
98 static struct drm_prop_enum_list drm_dvi_i_subconnector_enum_list
[] =
100 { DRM_MODE_SUBCONNECTOR_Unknown
, "Unknown" }, /* DVI-I and TV-out */
101 { DRM_MODE_SUBCONNECTOR_DVID
, "DVI-D" }, /* DVI-I */
102 { DRM_MODE_SUBCONNECTOR_DVIA
, "DVI-A" }, /* DVI-I */
105 DRM_ENUM_NAME_FN(drm_get_dvi_i_subconnector_name
,
106 drm_dvi_i_subconnector_enum_list
)
108 static struct drm_prop_enum_list drm_tv_select_enum_list
[] =
110 { DRM_MODE_SUBCONNECTOR_Automatic
, "Automatic" }, /* DVI-I and TV-out */
111 { DRM_MODE_SUBCONNECTOR_Composite
, "Composite" }, /* TV-out */
112 { DRM_MODE_SUBCONNECTOR_SVIDEO
, "SVIDEO" }, /* TV-out */
113 { DRM_MODE_SUBCONNECTOR_Component
, "Component" }, /* TV-out */
114 { DRM_MODE_SUBCONNECTOR_SCART
, "SCART" }, /* TV-out */
117 DRM_ENUM_NAME_FN(drm_get_tv_select_name
, drm_tv_select_enum_list
)
119 static struct drm_prop_enum_list drm_tv_subconnector_enum_list
[] =
121 { DRM_MODE_SUBCONNECTOR_Unknown
, "Unknown" }, /* DVI-I and TV-out */
122 { DRM_MODE_SUBCONNECTOR_Composite
, "Composite" }, /* TV-out */
123 { DRM_MODE_SUBCONNECTOR_SVIDEO
, "SVIDEO" }, /* TV-out */
124 { DRM_MODE_SUBCONNECTOR_Component
, "Component" }, /* TV-out */
125 { DRM_MODE_SUBCONNECTOR_SCART
, "SCART" }, /* TV-out */
128 DRM_ENUM_NAME_FN(drm_get_tv_subconnector_name
,
129 drm_tv_subconnector_enum_list
)
131 static struct drm_prop_enum_list drm_dirty_info_enum_list
[] = {
132 { DRM_MODE_DIRTY_OFF
, "Off" },
133 { DRM_MODE_DIRTY_ON
, "On" },
134 { DRM_MODE_DIRTY_ANNOTATE
, "Annotate" },
137 DRM_ENUM_NAME_FN(drm_get_dirty_info_name
,
138 drm_dirty_info_enum_list
)
140 struct drm_conn_prop_enum_list
{
147 * Connector and encoder types.
149 static struct drm_conn_prop_enum_list drm_connector_enum_list
[] =
150 { { DRM_MODE_CONNECTOR_Unknown
, "Unknown", 0 },
151 { DRM_MODE_CONNECTOR_VGA
, "VGA", 0 },
152 { DRM_MODE_CONNECTOR_DVII
, "DVI-I", 0 },
153 { DRM_MODE_CONNECTOR_DVID
, "DVI-D", 0 },
154 { DRM_MODE_CONNECTOR_DVIA
, "DVI-A", 0 },
155 { DRM_MODE_CONNECTOR_Composite
, "Composite", 0 },
156 { DRM_MODE_CONNECTOR_SVIDEO
, "SVIDEO", 0 },
157 { DRM_MODE_CONNECTOR_LVDS
, "LVDS", 0 },
158 { DRM_MODE_CONNECTOR_Component
, "Component", 0 },
159 { DRM_MODE_CONNECTOR_9PinDIN
, "DIN", 0 },
160 { DRM_MODE_CONNECTOR_DisplayPort
, "DP", 0 },
161 { DRM_MODE_CONNECTOR_HDMIA
, "HDMI-A", 0 },
162 { DRM_MODE_CONNECTOR_HDMIB
, "HDMI-B", 0 },
163 { DRM_MODE_CONNECTOR_TV
, "TV", 0 },
164 { DRM_MODE_CONNECTOR_eDP
, "eDP", 0 },
167 static struct drm_prop_enum_list drm_encoder_enum_list
[] =
168 { { DRM_MODE_ENCODER_NONE
, "None" },
169 { DRM_MODE_ENCODER_DAC
, "DAC" },
170 { DRM_MODE_ENCODER_TMDS
, "TMDS" },
171 { DRM_MODE_ENCODER_LVDS
, "LVDS" },
172 { DRM_MODE_ENCODER_TVDAC
, "TV" },
175 char *drm_get_encoder_name(struct drm_encoder
*encoder
)
179 snprintf(buf
, 32, "%s-%d",
180 drm_encoder_enum_list
[encoder
->encoder_type
].name
,
184 EXPORT_SYMBOL(drm_get_encoder_name
);
186 char *drm_get_connector_name(struct drm_connector
*connector
)
190 snprintf(buf
, 32, "%s-%d",
191 drm_connector_enum_list
[connector
->connector_type
].name
,
192 connector
->connector_type_id
);
195 EXPORT_SYMBOL(drm_get_connector_name
);
197 char *drm_get_connector_status_name(enum drm_connector_status status
)
199 if (status
== connector_status_connected
)
201 else if (status
== connector_status_disconnected
)
202 return "disconnected";
208 * drm_mode_object_get - allocate a new identifier
210 * @ptr: object pointer, used to generate unique ID
215 * Create a unique identifier based on @ptr in @dev's identifier space. Used
216 * for tracking modes, CRTCs and connectors.
219 * New unique (relative to other objects in @dev) integer identifier for the
222 static int drm_mode_object_get(struct drm_device
*dev
,
223 struct drm_mode_object
*obj
, uint32_t obj_type
)
229 if (idr_pre_get(&dev
->mode_config
.crtc_idr
, GFP_KERNEL
) == 0) {
230 DRM_ERROR("Ran out memory getting a mode number\n");
234 mutex_lock(&dev
->mode_config
.idr_mutex
);
235 ret
= idr_get_new_above(&dev
->mode_config
.crtc_idr
, obj
, 1, &new_id
);
236 mutex_unlock(&dev
->mode_config
.idr_mutex
);
241 obj
->type
= obj_type
;
246 * drm_mode_object_put - free an identifer
251 * Caller must hold DRM mode_config lock.
253 * Free @id from @dev's unique identifier pool.
255 static void drm_mode_object_put(struct drm_device
*dev
,
256 struct drm_mode_object
*object
)
258 mutex_lock(&dev
->mode_config
.idr_mutex
);
259 idr_remove(&dev
->mode_config
.crtc_idr
, object
->id
);
260 mutex_unlock(&dev
->mode_config
.idr_mutex
);
263 struct drm_mode_object
*drm_mode_object_find(struct drm_device
*dev
,
264 uint32_t id
, uint32_t type
)
266 struct drm_mode_object
*obj
= NULL
;
268 mutex_lock(&dev
->mode_config
.idr_mutex
);
269 obj
= idr_find(&dev
->mode_config
.crtc_idr
, id
);
270 if (!obj
|| (obj
->type
!= type
) || (obj
->id
!= id
))
272 mutex_unlock(&dev
->mode_config
.idr_mutex
);
276 EXPORT_SYMBOL(drm_mode_object_find
);
279 * drm_framebuffer_init - initialize a framebuffer
283 * Caller must hold mode config lock.
285 * Allocates an ID for the framebuffer's parent mode object, sets its mode
286 * functions & device file and adds it to the master fd list.
289 * Zero on success, error code on failure.
291 int drm_framebuffer_init(struct drm_device
*dev
, struct drm_framebuffer
*fb
,
292 const struct drm_framebuffer_funcs
*funcs
)
296 ret
= drm_mode_object_get(dev
, &fb
->base
, DRM_MODE_OBJECT_FB
);
303 dev
->mode_config
.num_fb
++;
304 list_add(&fb
->head
, &dev
->mode_config
.fb_list
);
308 EXPORT_SYMBOL(drm_framebuffer_init
);
311 * drm_framebuffer_cleanup - remove a framebuffer object
312 * @fb: framebuffer to remove
315 * Caller must hold mode config lock.
317 * Scans all the CRTCs in @dev's mode_config. If they're using @fb, removes
318 * it, setting it to NULL.
320 void drm_framebuffer_cleanup(struct drm_framebuffer
*fb
)
322 struct drm_device
*dev
= fb
->dev
;
323 struct drm_crtc
*crtc
;
324 struct drm_mode_set set
;
327 /* remove from any CRTC */
328 list_for_each_entry(crtc
, &dev
->mode_config
.crtc_list
, head
) {
329 if (crtc
->fb
== fb
) {
330 /* should turn off the crtc */
331 memset(&set
, 0, sizeof(struct drm_mode_set
));
334 ret
= crtc
->funcs
->set_config(&set
);
336 DRM_ERROR("failed to reset crtc %p when fb was deleted\n", crtc
);
340 drm_mode_object_put(dev
, &fb
->base
);
342 dev
->mode_config
.num_fb
--;
344 EXPORT_SYMBOL(drm_framebuffer_cleanup
);
347 * drm_crtc_init - Initialise a new CRTC object
349 * @crtc: CRTC object to init
350 * @funcs: callbacks for the new CRTC
353 * Caller must hold mode config lock.
355 * Inits a new object created as base part of an driver crtc object.
357 void drm_crtc_init(struct drm_device
*dev
, struct drm_crtc
*crtc
,
358 const struct drm_crtc_funcs
*funcs
)
363 mutex_lock(&dev
->mode_config
.mutex
);
364 drm_mode_object_get(dev
, &crtc
->base
, DRM_MODE_OBJECT_CRTC
);
366 list_add_tail(&crtc
->head
, &dev
->mode_config
.crtc_list
);
367 dev
->mode_config
.num_crtc
++;
368 mutex_unlock(&dev
->mode_config
.mutex
);
370 EXPORT_SYMBOL(drm_crtc_init
);
373 * drm_crtc_cleanup - Cleans up the core crtc usage.
374 * @crtc: CRTC to cleanup
377 * Caller must hold mode config lock.
379 * Cleanup @crtc. Removes from drm modesetting space
380 * does NOT free object, caller does that.
382 void drm_crtc_cleanup(struct drm_crtc
*crtc
)
384 struct drm_device
*dev
= crtc
->dev
;
386 if (crtc
->gamma_store
) {
387 kfree(crtc
->gamma_store
);
388 crtc
->gamma_store
= NULL
;
391 drm_mode_object_put(dev
, &crtc
->base
);
392 list_del(&crtc
->head
);
393 dev
->mode_config
.num_crtc
--;
395 EXPORT_SYMBOL(drm_crtc_cleanup
);
398 * drm_mode_probed_add - add a mode to a connector's probed mode list
399 * @connector: connector the new mode
403 * Caller must hold mode config lock.
405 * Add @mode to @connector's mode list for later use.
407 void drm_mode_probed_add(struct drm_connector
*connector
,
408 struct drm_display_mode
*mode
)
410 list_add(&mode
->head
, &connector
->probed_modes
);
412 EXPORT_SYMBOL(drm_mode_probed_add
);
415 * drm_mode_remove - remove and free a mode
416 * @connector: connector list to modify
417 * @mode: mode to remove
420 * Caller must hold mode config lock.
422 * Remove @mode from @connector's mode list, then free it.
424 void drm_mode_remove(struct drm_connector
*connector
,
425 struct drm_display_mode
*mode
)
427 list_del(&mode
->head
);
430 EXPORT_SYMBOL(drm_mode_remove
);
433 * drm_connector_init - Init a preallocated connector
435 * @connector: the connector to init
436 * @funcs: callbacks for this connector
437 * @name: user visible name of the connector
440 * Caller must hold @dev's mode_config lock.
442 * Initialises a preallocated connector. Connectors should be
443 * subclassed as part of driver connector objects.
445 void drm_connector_init(struct drm_device
*dev
,
446 struct drm_connector
*connector
,
447 const struct drm_connector_funcs
*funcs
,
450 mutex_lock(&dev
->mode_config
.mutex
);
452 connector
->dev
= dev
;
453 connector
->funcs
= funcs
;
454 drm_mode_object_get(dev
, &connector
->base
, DRM_MODE_OBJECT_CONNECTOR
);
455 connector
->connector_type
= connector_type
;
456 connector
->connector_type_id
=
457 ++drm_connector_enum_list
[connector_type
].count
; /* TODO */
458 INIT_LIST_HEAD(&connector
->user_modes
);
459 INIT_LIST_HEAD(&connector
->probed_modes
);
460 INIT_LIST_HEAD(&connector
->modes
);
461 connector
->edid_blob_ptr
= NULL
;
463 list_add_tail(&connector
->head
, &dev
->mode_config
.connector_list
);
464 dev
->mode_config
.num_connector
++;
466 drm_connector_attach_property(connector
,
467 dev
->mode_config
.edid_property
, 0);
469 drm_connector_attach_property(connector
,
470 dev
->mode_config
.dpms_property
, 0);
472 mutex_unlock(&dev
->mode_config
.mutex
);
474 EXPORT_SYMBOL(drm_connector_init
);
477 * drm_connector_cleanup - cleans up an initialised connector
478 * @connector: connector to cleanup
481 * Caller must hold @dev's mode_config lock.
483 * Cleans up the connector but doesn't free the object.
485 void drm_connector_cleanup(struct drm_connector
*connector
)
487 struct drm_device
*dev
= connector
->dev
;
488 struct drm_display_mode
*mode
, *t
;
490 list_for_each_entry_safe(mode
, t
, &connector
->probed_modes
, head
)
491 drm_mode_remove(connector
, mode
);
493 list_for_each_entry_safe(mode
, t
, &connector
->modes
, head
)
494 drm_mode_remove(connector
, mode
);
496 list_for_each_entry_safe(mode
, t
, &connector
->user_modes
, head
)
497 drm_mode_remove(connector
, mode
);
499 mutex_lock(&dev
->mode_config
.mutex
);
500 drm_mode_object_put(dev
, &connector
->base
);
501 list_del(&connector
->head
);
502 mutex_unlock(&dev
->mode_config
.mutex
);
504 EXPORT_SYMBOL(drm_connector_cleanup
);
506 void drm_encoder_init(struct drm_device
*dev
,
507 struct drm_encoder
*encoder
,
508 const struct drm_encoder_funcs
*funcs
,
511 mutex_lock(&dev
->mode_config
.mutex
);
515 drm_mode_object_get(dev
, &encoder
->base
, DRM_MODE_OBJECT_ENCODER
);
516 encoder
->encoder_type
= encoder_type
;
517 encoder
->funcs
= funcs
;
519 list_add_tail(&encoder
->head
, &dev
->mode_config
.encoder_list
);
520 dev
->mode_config
.num_encoder
++;
522 mutex_unlock(&dev
->mode_config
.mutex
);
524 EXPORT_SYMBOL(drm_encoder_init
);
526 void drm_encoder_cleanup(struct drm_encoder
*encoder
)
528 struct drm_device
*dev
= encoder
->dev
;
529 mutex_lock(&dev
->mode_config
.mutex
);
530 drm_mode_object_put(dev
, &encoder
->base
);
531 list_del(&encoder
->head
);
532 mutex_unlock(&dev
->mode_config
.mutex
);
534 EXPORT_SYMBOL(drm_encoder_cleanup
);
537 * drm_mode_create - create a new display mode
541 * Caller must hold DRM mode_config lock.
543 * Create a new drm_display_mode, give it an ID, and return it.
546 * Pointer to new mode on success, NULL on error.
548 struct drm_display_mode
*drm_mode_create(struct drm_device
*dev
)
550 struct drm_display_mode
*nmode
;
552 nmode
= kzalloc(sizeof(struct drm_display_mode
), GFP_KERNEL
);
556 drm_mode_object_get(dev
, &nmode
->base
, DRM_MODE_OBJECT_MODE
);
559 EXPORT_SYMBOL(drm_mode_create
);
562 * drm_mode_destroy - remove a mode
564 * @mode: mode to remove
567 * Caller must hold mode config lock.
569 * Free @mode's unique identifier, then free it.
571 void drm_mode_destroy(struct drm_device
*dev
, struct drm_display_mode
*mode
)
573 drm_mode_object_put(dev
, &mode
->base
);
577 EXPORT_SYMBOL(drm_mode_destroy
);
579 static int drm_mode_create_standard_connector_properties(struct drm_device
*dev
)
581 struct drm_property
*edid
;
582 struct drm_property
*dpms
;
586 * Standard properties (apply to all connectors)
588 edid
= drm_property_create(dev
, DRM_MODE_PROP_BLOB
|
589 DRM_MODE_PROP_IMMUTABLE
,
591 dev
->mode_config
.edid_property
= edid
;
593 dpms
= drm_property_create(dev
, DRM_MODE_PROP_ENUM
,
594 "DPMS", ARRAY_SIZE(drm_dpms_enum_list
));
595 for (i
= 0; i
< ARRAY_SIZE(drm_dpms_enum_list
); i
++)
596 drm_property_add_enum(dpms
, i
, drm_dpms_enum_list
[i
].type
,
597 drm_dpms_enum_list
[i
].name
);
598 dev
->mode_config
.dpms_property
= dpms
;
604 * drm_mode_create_dvi_i_properties - create DVI-I specific connector properties
607 * Called by a driver the first time a DVI-I connector is made.
609 int drm_mode_create_dvi_i_properties(struct drm_device
*dev
)
611 struct drm_property
*dvi_i_selector
;
612 struct drm_property
*dvi_i_subconnector
;
615 if (dev
->mode_config
.dvi_i_select_subconnector_property
)
619 drm_property_create(dev
, DRM_MODE_PROP_ENUM
,
620 "select subconnector",
621 ARRAY_SIZE(drm_dvi_i_select_enum_list
));
622 for (i
= 0; i
< ARRAY_SIZE(drm_dvi_i_select_enum_list
); i
++)
623 drm_property_add_enum(dvi_i_selector
, i
,
624 drm_dvi_i_select_enum_list
[i
].type
,
625 drm_dvi_i_select_enum_list
[i
].name
);
626 dev
->mode_config
.dvi_i_select_subconnector_property
= dvi_i_selector
;
629 drm_property_create(dev
, DRM_MODE_PROP_ENUM
|
630 DRM_MODE_PROP_IMMUTABLE
,
632 ARRAY_SIZE(drm_dvi_i_subconnector_enum_list
));
633 for (i
= 0; i
< ARRAY_SIZE(drm_dvi_i_subconnector_enum_list
); i
++)
634 drm_property_add_enum(dvi_i_subconnector
, i
,
635 drm_dvi_i_subconnector_enum_list
[i
].type
,
636 drm_dvi_i_subconnector_enum_list
[i
].name
);
637 dev
->mode_config
.dvi_i_subconnector_property
= dvi_i_subconnector
;
641 EXPORT_SYMBOL(drm_mode_create_dvi_i_properties
);
644 * drm_create_tv_properties - create TV specific connector properties
646 * @num_modes: number of different TV formats (modes) supported
647 * @modes: array of pointers to strings containing name of each format
649 * Called by a driver's TV initialization routine, this function creates
650 * the TV specific connector properties for a given device. Caller is
651 * responsible for allocating a list of format names and passing them to
654 int drm_mode_create_tv_properties(struct drm_device
*dev
, int num_modes
,
657 struct drm_property
*tv_selector
;
658 struct drm_property
*tv_subconnector
;
661 if (dev
->mode_config
.tv_select_subconnector_property
)
665 * Basic connector properties
667 tv_selector
= drm_property_create(dev
, DRM_MODE_PROP_ENUM
,
668 "select subconnector",
669 ARRAY_SIZE(drm_tv_select_enum_list
));
670 for (i
= 0; i
< ARRAY_SIZE(drm_tv_select_enum_list
); i
++)
671 drm_property_add_enum(tv_selector
, i
,
672 drm_tv_select_enum_list
[i
].type
,
673 drm_tv_select_enum_list
[i
].name
);
674 dev
->mode_config
.tv_select_subconnector_property
= tv_selector
;
677 drm_property_create(dev
, DRM_MODE_PROP_ENUM
|
678 DRM_MODE_PROP_IMMUTABLE
, "subconnector",
679 ARRAY_SIZE(drm_tv_subconnector_enum_list
));
680 for (i
= 0; i
< ARRAY_SIZE(drm_tv_subconnector_enum_list
); i
++)
681 drm_property_add_enum(tv_subconnector
, i
,
682 drm_tv_subconnector_enum_list
[i
].type
,
683 drm_tv_subconnector_enum_list
[i
].name
);
684 dev
->mode_config
.tv_subconnector_property
= tv_subconnector
;
687 * Other, TV specific properties: margins & TV modes.
689 dev
->mode_config
.tv_left_margin_property
=
690 drm_property_create(dev
, DRM_MODE_PROP_RANGE
,
692 dev
->mode_config
.tv_left_margin_property
->values
[0] = 0;
693 dev
->mode_config
.tv_left_margin_property
->values
[1] = 100;
695 dev
->mode_config
.tv_right_margin_property
=
696 drm_property_create(dev
, DRM_MODE_PROP_RANGE
,
698 dev
->mode_config
.tv_right_margin_property
->values
[0] = 0;
699 dev
->mode_config
.tv_right_margin_property
->values
[1] = 100;
701 dev
->mode_config
.tv_top_margin_property
=
702 drm_property_create(dev
, DRM_MODE_PROP_RANGE
,
704 dev
->mode_config
.tv_top_margin_property
->values
[0] = 0;
705 dev
->mode_config
.tv_top_margin_property
->values
[1] = 100;
707 dev
->mode_config
.tv_bottom_margin_property
=
708 drm_property_create(dev
, DRM_MODE_PROP_RANGE
,
710 dev
->mode_config
.tv_bottom_margin_property
->values
[0] = 0;
711 dev
->mode_config
.tv_bottom_margin_property
->values
[1] = 100;
713 dev
->mode_config
.tv_mode_property
=
714 drm_property_create(dev
, DRM_MODE_PROP_ENUM
,
716 for (i
= 0; i
< num_modes
; i
++)
717 drm_property_add_enum(dev
->mode_config
.tv_mode_property
, i
,
720 dev
->mode_config
.tv_brightness_property
=
721 drm_property_create(dev
, DRM_MODE_PROP_RANGE
,
723 dev
->mode_config
.tv_brightness_property
->values
[0] = 0;
724 dev
->mode_config
.tv_brightness_property
->values
[1] = 100;
726 dev
->mode_config
.tv_contrast_property
=
727 drm_property_create(dev
, DRM_MODE_PROP_RANGE
,
729 dev
->mode_config
.tv_contrast_property
->values
[0] = 0;
730 dev
->mode_config
.tv_contrast_property
->values
[1] = 100;
732 dev
->mode_config
.tv_flicker_reduction_property
=
733 drm_property_create(dev
, DRM_MODE_PROP_RANGE
,
734 "flicker reduction", 2);
735 dev
->mode_config
.tv_flicker_reduction_property
->values
[0] = 0;
736 dev
->mode_config
.tv_flicker_reduction_property
->values
[1] = 100;
738 dev
->mode_config
.tv_overscan_property
=
739 drm_property_create(dev
, DRM_MODE_PROP_RANGE
,
741 dev
->mode_config
.tv_overscan_property
->values
[0] = 0;
742 dev
->mode_config
.tv_overscan_property
->values
[1] = 100;
744 dev
->mode_config
.tv_saturation_property
=
745 drm_property_create(dev
, DRM_MODE_PROP_RANGE
,
747 dev
->mode_config
.tv_saturation_property
->values
[0] = 0;
748 dev
->mode_config
.tv_saturation_property
->values
[1] = 100;
750 dev
->mode_config
.tv_hue_property
=
751 drm_property_create(dev
, DRM_MODE_PROP_RANGE
,
753 dev
->mode_config
.tv_hue_property
->values
[0] = 0;
754 dev
->mode_config
.tv_hue_property
->values
[1] = 100;
758 EXPORT_SYMBOL(drm_mode_create_tv_properties
);
761 * drm_mode_create_scaling_mode_property - create scaling mode property
764 * Called by a driver the first time it's needed, must be attached to desired
767 int drm_mode_create_scaling_mode_property(struct drm_device
*dev
)
769 struct drm_property
*scaling_mode
;
772 if (dev
->mode_config
.scaling_mode_property
)
776 drm_property_create(dev
, DRM_MODE_PROP_ENUM
, "scaling mode",
777 ARRAY_SIZE(drm_scaling_mode_enum_list
));
778 for (i
= 0; i
< ARRAY_SIZE(drm_scaling_mode_enum_list
); i
++)
779 drm_property_add_enum(scaling_mode
, i
,
780 drm_scaling_mode_enum_list
[i
].type
,
781 drm_scaling_mode_enum_list
[i
].name
);
783 dev
->mode_config
.scaling_mode_property
= scaling_mode
;
787 EXPORT_SYMBOL(drm_mode_create_scaling_mode_property
);
790 * drm_mode_create_dithering_property - create dithering property
793 * Called by a driver the first time it's needed, must be attached to desired
796 int drm_mode_create_dithering_property(struct drm_device
*dev
)
798 struct drm_property
*dithering_mode
;
801 if (dev
->mode_config
.dithering_mode_property
)
805 drm_property_create(dev
, DRM_MODE_PROP_ENUM
, "dithering",
806 ARRAY_SIZE(drm_dithering_mode_enum_list
));
807 for (i
= 0; i
< ARRAY_SIZE(drm_dithering_mode_enum_list
); i
++)
808 drm_property_add_enum(dithering_mode
, i
,
809 drm_dithering_mode_enum_list
[i
].type
,
810 drm_dithering_mode_enum_list
[i
].name
);
811 dev
->mode_config
.dithering_mode_property
= dithering_mode
;
815 EXPORT_SYMBOL(drm_mode_create_dithering_property
);
818 * drm_mode_create_dirty_property - create dirty property
821 * Called by a driver the first time it's needed, must be attached to desired
824 int drm_mode_create_dirty_info_property(struct drm_device
*dev
)
826 struct drm_property
*dirty_info
;
829 if (dev
->mode_config
.dirty_info_property
)
833 drm_property_create(dev
, DRM_MODE_PROP_ENUM
|
834 DRM_MODE_PROP_IMMUTABLE
,
836 ARRAY_SIZE(drm_dirty_info_enum_list
));
837 for (i
= 0; i
< ARRAY_SIZE(drm_dirty_info_enum_list
); i
++)
838 drm_property_add_enum(dirty_info
, i
,
839 drm_dirty_info_enum_list
[i
].type
,
840 drm_dirty_info_enum_list
[i
].name
);
841 dev
->mode_config
.dirty_info_property
= dirty_info
;
845 EXPORT_SYMBOL(drm_mode_create_dirty_info_property
);
848 * drm_mode_config_init - initialize DRM mode_configuration structure
852 * None, should happen single threaded at init time.
854 * Initialize @dev's mode_config structure, used for tracking the graphics
855 * configuration of @dev.
857 void drm_mode_config_init(struct drm_device
*dev
)
859 mutex_init(&dev
->mode_config
.mutex
);
860 mutex_init(&dev
->mode_config
.idr_mutex
);
861 INIT_LIST_HEAD(&dev
->mode_config
.fb_list
);
862 INIT_LIST_HEAD(&dev
->mode_config
.crtc_list
);
863 INIT_LIST_HEAD(&dev
->mode_config
.connector_list
);
864 INIT_LIST_HEAD(&dev
->mode_config
.encoder_list
);
865 INIT_LIST_HEAD(&dev
->mode_config
.property_list
);
866 INIT_LIST_HEAD(&dev
->mode_config
.property_blob_list
);
867 idr_init(&dev
->mode_config
.crtc_idr
);
869 mutex_lock(&dev
->mode_config
.mutex
);
870 drm_mode_create_standard_connector_properties(dev
);
871 mutex_unlock(&dev
->mode_config
.mutex
);
873 /* Just to be sure */
874 dev
->mode_config
.num_fb
= 0;
875 dev
->mode_config
.num_connector
= 0;
876 dev
->mode_config
.num_crtc
= 0;
877 dev
->mode_config
.num_encoder
= 0;
879 EXPORT_SYMBOL(drm_mode_config_init
);
881 int drm_mode_group_init(struct drm_device
*dev
, struct drm_mode_group
*group
)
883 uint32_t total_objects
= 0;
885 total_objects
+= dev
->mode_config
.num_crtc
;
886 total_objects
+= dev
->mode_config
.num_connector
;
887 total_objects
+= dev
->mode_config
.num_encoder
;
889 group
->id_list
= kzalloc(total_objects
* sizeof(uint32_t), GFP_KERNEL
);
893 group
->num_crtcs
= 0;
894 group
->num_connectors
= 0;
895 group
->num_encoders
= 0;
899 int drm_mode_group_init_legacy_group(struct drm_device
*dev
,
900 struct drm_mode_group
*group
)
902 struct drm_crtc
*crtc
;
903 struct drm_encoder
*encoder
;
904 struct drm_connector
*connector
;
907 if ((ret
= drm_mode_group_init(dev
, group
)))
910 list_for_each_entry(crtc
, &dev
->mode_config
.crtc_list
, head
)
911 group
->id_list
[group
->num_crtcs
++] = crtc
->base
.id
;
913 list_for_each_entry(encoder
, &dev
->mode_config
.encoder_list
, head
)
914 group
->id_list
[group
->num_crtcs
+ group
->num_encoders
++] =
917 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
, head
)
918 group
->id_list
[group
->num_crtcs
+ group
->num_encoders
+
919 group
->num_connectors
++] = connector
->base
.id
;
925 * drm_mode_config_cleanup - free up DRM mode_config info
929 * Caller must hold mode config lock.
931 * Free up all the connectors and CRTCs associated with this DRM device, then
932 * free up the framebuffers and associated buffer objects.
934 * FIXME: cleanup any dangling user buffer objects too
936 void drm_mode_config_cleanup(struct drm_device
*dev
)
938 struct drm_connector
*connector
, *ot
;
939 struct drm_crtc
*crtc
, *ct
;
940 struct drm_encoder
*encoder
, *enct
;
941 struct drm_framebuffer
*fb
, *fbt
;
942 struct drm_property
*property
, *pt
;
944 list_for_each_entry_safe(encoder
, enct
, &dev
->mode_config
.encoder_list
,
946 encoder
->funcs
->destroy(encoder
);
949 list_for_each_entry_safe(connector
, ot
,
950 &dev
->mode_config
.connector_list
, head
) {
951 connector
->funcs
->destroy(connector
);
954 list_for_each_entry_safe(property
, pt
, &dev
->mode_config
.property_list
,
956 drm_property_destroy(dev
, property
);
959 list_for_each_entry_safe(fb
, fbt
, &dev
->mode_config
.fb_list
, head
) {
960 fb
->funcs
->destroy(fb
);
963 list_for_each_entry_safe(crtc
, ct
, &dev
->mode_config
.crtc_list
, head
) {
964 crtc
->funcs
->destroy(crtc
);
968 EXPORT_SYMBOL(drm_mode_config_cleanup
);
971 * drm_crtc_convert_to_umode - convert a drm_display_mode into a modeinfo
972 * @out: drm_mode_modeinfo struct to return to the user
973 * @in: drm_display_mode to use
978 * Convert a drm_display_mode into a drm_mode_modeinfo structure to return to
981 void drm_crtc_convert_to_umode(struct drm_mode_modeinfo
*out
,
982 struct drm_display_mode
*in
)
984 out
->clock
= in
->clock
;
985 out
->hdisplay
= in
->hdisplay
;
986 out
->hsync_start
= in
->hsync_start
;
987 out
->hsync_end
= in
->hsync_end
;
988 out
->htotal
= in
->htotal
;
989 out
->hskew
= in
->hskew
;
990 out
->vdisplay
= in
->vdisplay
;
991 out
->vsync_start
= in
->vsync_start
;
992 out
->vsync_end
= in
->vsync_end
;
993 out
->vtotal
= in
->vtotal
;
994 out
->vscan
= in
->vscan
;
995 out
->vrefresh
= in
->vrefresh
;
996 out
->flags
= in
->flags
;
997 out
->type
= in
->type
;
998 strncpy(out
->name
, in
->name
, DRM_DISPLAY_MODE_LEN
);
999 out
->name
[DRM_DISPLAY_MODE_LEN
-1] = 0;
1003 * drm_crtc_convert_to_umode - convert a modeinfo into a drm_display_mode
1004 * @out: drm_display_mode to return to the user
1005 * @in: drm_mode_modeinfo to use
1010 * Convert a drm_mode_modeinfo into a drm_display_mode structure to return to
1013 void drm_crtc_convert_umode(struct drm_display_mode
*out
,
1014 struct drm_mode_modeinfo
*in
)
1016 out
->clock
= in
->clock
;
1017 out
->hdisplay
= in
->hdisplay
;
1018 out
->hsync_start
= in
->hsync_start
;
1019 out
->hsync_end
= in
->hsync_end
;
1020 out
->htotal
= in
->htotal
;
1021 out
->hskew
= in
->hskew
;
1022 out
->vdisplay
= in
->vdisplay
;
1023 out
->vsync_start
= in
->vsync_start
;
1024 out
->vsync_end
= in
->vsync_end
;
1025 out
->vtotal
= in
->vtotal
;
1026 out
->vscan
= in
->vscan
;
1027 out
->vrefresh
= in
->vrefresh
;
1028 out
->flags
= in
->flags
;
1029 out
->type
= in
->type
;
1030 strncpy(out
->name
, in
->name
, DRM_DISPLAY_MODE_LEN
);
1031 out
->name
[DRM_DISPLAY_MODE_LEN
-1] = 0;
1035 * drm_mode_getresources - get graphics configuration
1036 * @inode: inode from the ioctl
1037 * @filp: file * from the ioctl
1038 * @cmd: cmd from ioctl
1039 * @arg: arg from ioctl
1042 * Takes mode config lock.
1044 * Construct a set of configuration description structures and return
1045 * them to the user, including CRTC, connector and framebuffer configuration.
1047 * Called by the user via ioctl.
1050 * Zero on success, errno on failure.
1052 int drm_mode_getresources(struct drm_device
*dev
, void *data
,
1053 struct drm_file
*file_priv
)
1055 struct drm_mode_card_res
*card_res
= data
;
1056 struct list_head
*lh
;
1057 struct drm_framebuffer
*fb
;
1058 struct drm_connector
*connector
;
1059 struct drm_crtc
*crtc
;
1060 struct drm_encoder
*encoder
;
1062 int connector_count
= 0;
1065 int encoder_count
= 0;
1067 uint32_t __user
*fb_id
;
1068 uint32_t __user
*crtc_id
;
1069 uint32_t __user
*connector_id
;
1070 uint32_t __user
*encoder_id
;
1071 struct drm_mode_group
*mode_group
;
1073 if (!drm_core_check_feature(dev
, DRIVER_MODESET
))
1076 mutex_lock(&dev
->mode_config
.mutex
);
1079 * For the non-control nodes we need to limit the list of resources
1080 * by IDs in the group list for this node
1082 list_for_each(lh
, &file_priv
->fbs
)
1085 mode_group
= &file_priv
->master
->minor
->mode_group
;
1086 if (file_priv
->master
->minor
->type
== DRM_MINOR_CONTROL
) {
1088 list_for_each(lh
, &dev
->mode_config
.crtc_list
)
1091 list_for_each(lh
, &dev
->mode_config
.connector_list
)
1094 list_for_each(lh
, &dev
->mode_config
.encoder_list
)
1098 crtc_count
= mode_group
->num_crtcs
;
1099 connector_count
= mode_group
->num_connectors
;
1100 encoder_count
= mode_group
->num_encoders
;
1103 card_res
->max_height
= dev
->mode_config
.max_height
;
1104 card_res
->min_height
= dev
->mode_config
.min_height
;
1105 card_res
->max_width
= dev
->mode_config
.max_width
;
1106 card_res
->min_width
= dev
->mode_config
.min_width
;
1108 /* handle this in 4 parts */
1110 if (card_res
->count_fbs
>= fb_count
) {
1112 fb_id
= (uint32_t __user
*)(unsigned long)card_res
->fb_id_ptr
;
1113 list_for_each_entry(fb
, &file_priv
->fbs
, filp_head
) {
1114 if (put_user(fb
->base
.id
, fb_id
+ copied
)) {
1121 card_res
->count_fbs
= fb_count
;
1124 if (card_res
->count_crtcs
>= crtc_count
) {
1126 crtc_id
= (uint32_t __user
*)(unsigned long)card_res
->crtc_id_ptr
;
1127 if (file_priv
->master
->minor
->type
== DRM_MINOR_CONTROL
) {
1128 list_for_each_entry(crtc
, &dev
->mode_config
.crtc_list
,
1130 DRM_DEBUG_KMS("[CRTC:%d]\n", crtc
->base
.id
);
1131 if (put_user(crtc
->base
.id
, crtc_id
+ copied
)) {
1138 for (i
= 0; i
< mode_group
->num_crtcs
; i
++) {
1139 if (put_user(mode_group
->id_list
[i
],
1140 crtc_id
+ copied
)) {
1148 card_res
->count_crtcs
= crtc_count
;
1151 if (card_res
->count_encoders
>= encoder_count
) {
1153 encoder_id
= (uint32_t __user
*)(unsigned long)card_res
->encoder_id_ptr
;
1154 if (file_priv
->master
->minor
->type
== DRM_MINOR_CONTROL
) {
1155 list_for_each_entry(encoder
,
1156 &dev
->mode_config
.encoder_list
,
1158 DRM_DEBUG_KMS("[ENCODER:%d:%s]\n", encoder
->base
.id
,
1159 drm_get_encoder_name(encoder
));
1160 if (put_user(encoder
->base
.id
, encoder_id
+
1168 for (i
= mode_group
->num_crtcs
; i
< mode_group
->num_crtcs
+ mode_group
->num_encoders
; i
++) {
1169 if (put_user(mode_group
->id_list
[i
],
1170 encoder_id
+ copied
)) {
1179 card_res
->count_encoders
= encoder_count
;
1182 if (card_res
->count_connectors
>= connector_count
) {
1184 connector_id
= (uint32_t __user
*)(unsigned long)card_res
->connector_id_ptr
;
1185 if (file_priv
->master
->minor
->type
== DRM_MINOR_CONTROL
) {
1186 list_for_each_entry(connector
,
1187 &dev
->mode_config
.connector_list
,
1189 DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n",
1191 drm_get_connector_name(connector
));
1192 if (put_user(connector
->base
.id
,
1193 connector_id
+ copied
)) {
1200 int start
= mode_group
->num_crtcs
+
1201 mode_group
->num_encoders
;
1202 for (i
= start
; i
< start
+ mode_group
->num_connectors
; i
++) {
1203 if (put_user(mode_group
->id_list
[i
],
1204 connector_id
+ copied
)) {
1212 card_res
->count_connectors
= connector_count
;
1214 DRM_DEBUG_KMS("CRTC[%d] CONNECTORS[%d] ENCODERS[%d]\n", card_res
->count_crtcs
,
1215 card_res
->count_connectors
, card_res
->count_encoders
);
1218 mutex_unlock(&dev
->mode_config
.mutex
);
1223 * drm_mode_getcrtc - get CRTC configuration
1224 * @inode: inode from the ioctl
1225 * @filp: file * from the ioctl
1226 * @cmd: cmd from ioctl
1227 * @arg: arg from ioctl
1232 * Construct a CRTC configuration structure to return to the user.
1234 * Called by the user via ioctl.
1237 * Zero on success, errno on failure.
1239 int drm_mode_getcrtc(struct drm_device
*dev
,
1240 void *data
, struct drm_file
*file_priv
)
1242 struct drm_mode_crtc
*crtc_resp
= data
;
1243 struct drm_crtc
*crtc
;
1244 struct drm_mode_object
*obj
;
1247 if (!drm_core_check_feature(dev
, DRIVER_MODESET
))
1250 mutex_lock(&dev
->mode_config
.mutex
);
1252 obj
= drm_mode_object_find(dev
, crtc_resp
->crtc_id
,
1253 DRM_MODE_OBJECT_CRTC
);
1258 crtc
= obj_to_crtc(obj
);
1260 crtc_resp
->x
= crtc
->x
;
1261 crtc_resp
->y
= crtc
->y
;
1262 crtc_resp
->gamma_size
= crtc
->gamma_size
;
1264 crtc_resp
->fb_id
= crtc
->fb
->base
.id
;
1266 crtc_resp
->fb_id
= 0;
1268 if (crtc
->enabled
) {
1270 drm_crtc_convert_to_umode(&crtc_resp
->mode
, &crtc
->mode
);
1271 crtc_resp
->mode_valid
= 1;
1274 crtc_resp
->mode_valid
= 0;
1278 mutex_unlock(&dev
->mode_config
.mutex
);
1283 * drm_mode_getconnector - get connector configuration
1284 * @inode: inode from the ioctl
1285 * @filp: file * from the ioctl
1286 * @cmd: cmd from ioctl
1287 * @arg: arg from ioctl
1292 * Construct a connector configuration structure to return to the user.
1294 * Called by the user via ioctl.
1297 * Zero on success, errno on failure.
1299 int drm_mode_getconnector(struct drm_device
*dev
, void *data
,
1300 struct drm_file
*file_priv
)
1302 struct drm_mode_get_connector
*out_resp
= data
;
1303 struct drm_mode_object
*obj
;
1304 struct drm_connector
*connector
;
1305 struct drm_display_mode
*mode
;
1307 int props_count
= 0;
1308 int encoders_count
= 0;
1312 struct drm_mode_modeinfo u_mode
;
1313 struct drm_mode_modeinfo __user
*mode_ptr
;
1314 uint32_t __user
*prop_ptr
;
1315 uint64_t __user
*prop_values
;
1316 uint32_t __user
*encoder_ptr
;
1318 if (!drm_core_check_feature(dev
, DRIVER_MODESET
))
1321 memset(&u_mode
, 0, sizeof(struct drm_mode_modeinfo
));
1323 DRM_DEBUG_KMS("[CONNECTOR:%d:?]\n", out_resp
->connector_id
);
1325 mutex_lock(&dev
->mode_config
.mutex
);
1327 obj
= drm_mode_object_find(dev
, out_resp
->connector_id
,
1328 DRM_MODE_OBJECT_CONNECTOR
);
1333 connector
= obj_to_connector(obj
);
1335 for (i
= 0; i
< DRM_CONNECTOR_MAX_PROPERTY
; i
++) {
1336 if (connector
->property_ids
[i
] != 0) {
1341 for (i
= 0; i
< DRM_CONNECTOR_MAX_ENCODER
; i
++) {
1342 if (connector
->encoder_ids
[i
] != 0) {
1347 if (out_resp
->count_modes
== 0) {
1348 connector
->funcs
->fill_modes(connector
,
1349 dev
->mode_config
.max_width
,
1350 dev
->mode_config
.max_height
);
1353 /* delayed so we get modes regardless of pre-fill_modes state */
1354 list_for_each_entry(mode
, &connector
->modes
, head
)
1357 out_resp
->connector_id
= connector
->base
.id
;
1358 out_resp
->connector_type
= connector
->connector_type
;
1359 out_resp
->connector_type_id
= connector
->connector_type_id
;
1360 out_resp
->mm_width
= connector
->display_info
.width_mm
;
1361 out_resp
->mm_height
= connector
->display_info
.height_mm
;
1362 out_resp
->subpixel
= connector
->display_info
.subpixel_order
;
1363 out_resp
->connection
= connector
->status
;
1364 if (connector
->encoder
)
1365 out_resp
->encoder_id
= connector
->encoder
->base
.id
;
1367 out_resp
->encoder_id
= 0;
1370 * This ioctl is called twice, once to determine how much space is
1371 * needed, and the 2nd time to fill it.
1373 if ((out_resp
->count_modes
>= mode_count
) && mode_count
) {
1375 mode_ptr
= (struct drm_mode_modeinfo
*)(unsigned long)out_resp
->modes_ptr
;
1376 list_for_each_entry(mode
, &connector
->modes
, head
) {
1377 drm_crtc_convert_to_umode(&u_mode
, mode
);
1378 if (copy_to_user(mode_ptr
+ copied
,
1379 &u_mode
, sizeof(u_mode
))) {
1386 out_resp
->count_modes
= mode_count
;
1388 if ((out_resp
->count_props
>= props_count
) && props_count
) {
1390 prop_ptr
= (uint32_t *)(unsigned long)(out_resp
->props_ptr
);
1391 prop_values
= (uint64_t *)(unsigned long)(out_resp
->prop_values_ptr
);
1392 for (i
= 0; i
< DRM_CONNECTOR_MAX_PROPERTY
; i
++) {
1393 if (connector
->property_ids
[i
] != 0) {
1394 if (put_user(connector
->property_ids
[i
],
1395 prop_ptr
+ copied
)) {
1400 if (put_user(connector
->property_values
[i
],
1401 prop_values
+ copied
)) {
1409 out_resp
->count_props
= props_count
;
1411 if ((out_resp
->count_encoders
>= encoders_count
) && encoders_count
) {
1413 encoder_ptr
= (uint32_t *)(unsigned long)(out_resp
->encoders_ptr
);
1414 for (i
= 0; i
< DRM_CONNECTOR_MAX_ENCODER
; i
++) {
1415 if (connector
->encoder_ids
[i
] != 0) {
1416 if (put_user(connector
->encoder_ids
[i
],
1417 encoder_ptr
+ copied
)) {
1425 out_resp
->count_encoders
= encoders_count
;
1428 mutex_unlock(&dev
->mode_config
.mutex
);
1432 int drm_mode_getencoder(struct drm_device
*dev
, void *data
,
1433 struct drm_file
*file_priv
)
1435 struct drm_mode_get_encoder
*enc_resp
= data
;
1436 struct drm_mode_object
*obj
;
1437 struct drm_encoder
*encoder
;
1440 if (!drm_core_check_feature(dev
, DRIVER_MODESET
))
1443 mutex_lock(&dev
->mode_config
.mutex
);
1444 obj
= drm_mode_object_find(dev
, enc_resp
->encoder_id
,
1445 DRM_MODE_OBJECT_ENCODER
);
1450 encoder
= obj_to_encoder(obj
);
1453 enc_resp
->crtc_id
= encoder
->crtc
->base
.id
;
1455 enc_resp
->crtc_id
= 0;
1456 enc_resp
->encoder_type
= encoder
->encoder_type
;
1457 enc_resp
->encoder_id
= encoder
->base
.id
;
1458 enc_resp
->possible_crtcs
= encoder
->possible_crtcs
;
1459 enc_resp
->possible_clones
= encoder
->possible_clones
;
1462 mutex_unlock(&dev
->mode_config
.mutex
);
1467 * drm_mode_setcrtc - set CRTC configuration
1468 * @inode: inode from the ioctl
1469 * @filp: file * from the ioctl
1470 * @cmd: cmd from ioctl
1471 * @arg: arg from ioctl
1476 * Build a new CRTC configuration based on user request.
1478 * Called by the user via ioctl.
1481 * Zero on success, errno on failure.
1483 int drm_mode_setcrtc(struct drm_device
*dev
, void *data
,
1484 struct drm_file
*file_priv
)
1486 struct drm_mode_config
*config
= &dev
->mode_config
;
1487 struct drm_mode_crtc
*crtc_req
= data
;
1488 struct drm_mode_object
*obj
;
1489 struct drm_crtc
*crtc
, *crtcfb
;
1490 struct drm_connector
**connector_set
= NULL
, *connector
;
1491 struct drm_framebuffer
*fb
= NULL
;
1492 struct drm_display_mode
*mode
= NULL
;
1493 struct drm_mode_set set
;
1494 uint32_t __user
*set_connectors_ptr
;
1498 if (!drm_core_check_feature(dev
, DRIVER_MODESET
))
1501 mutex_lock(&dev
->mode_config
.mutex
);
1502 obj
= drm_mode_object_find(dev
, crtc_req
->crtc_id
,
1503 DRM_MODE_OBJECT_CRTC
);
1505 DRM_DEBUG_KMS("Unknown CRTC ID %d\n", crtc_req
->crtc_id
);
1509 crtc
= obj_to_crtc(obj
);
1510 DRM_DEBUG_KMS("[CRTC:%d]\n", crtc
->base
.id
);
1512 if (crtc_req
->mode_valid
) {
1513 /* If we have a mode we need a framebuffer. */
1514 /* If we pass -1, set the mode with the currently bound fb */
1515 if (crtc_req
->fb_id
== -1) {
1516 list_for_each_entry(crtcfb
,
1517 &dev
->mode_config
.crtc_list
, head
) {
1518 if (crtcfb
== crtc
) {
1519 DRM_DEBUG_KMS("Using current fb for "
1525 obj
= drm_mode_object_find(dev
, crtc_req
->fb_id
,
1526 DRM_MODE_OBJECT_FB
);
1528 DRM_DEBUG_KMS("Unknown FB ID%d\n",
1533 fb
= obj_to_fb(obj
);
1536 mode
= drm_mode_create(dev
);
1537 drm_crtc_convert_umode(mode
, &crtc_req
->mode
);
1538 drm_mode_set_crtcinfo(mode
, CRTC_INTERLACE_HALVE_V
);
1541 if (crtc_req
->count_connectors
== 0 && mode
) {
1542 DRM_DEBUG_KMS("Count connectors is 0 but mode set\n");
1547 if (crtc_req
->count_connectors
> 0 && (!mode
|| !fb
)) {
1548 DRM_DEBUG_KMS("Count connectors is %d but no mode or fb set\n",
1549 crtc_req
->count_connectors
);
1554 if (crtc_req
->count_connectors
> 0) {
1557 /* Avoid unbounded kernel memory allocation */
1558 if (crtc_req
->count_connectors
> config
->num_connector
) {
1563 connector_set
= kmalloc(crtc_req
->count_connectors
*
1564 sizeof(struct drm_connector
*),
1566 if (!connector_set
) {
1571 for (i
= 0; i
< crtc_req
->count_connectors
; i
++) {
1572 set_connectors_ptr
= (uint32_t *)(unsigned long)crtc_req
->set_connectors_ptr
;
1573 if (get_user(out_id
, &set_connectors_ptr
[i
])) {
1578 obj
= drm_mode_object_find(dev
, out_id
,
1579 DRM_MODE_OBJECT_CONNECTOR
);
1581 DRM_DEBUG_KMS("Connector id %d unknown\n",
1586 connector
= obj_to_connector(obj
);
1587 DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n",
1589 drm_get_connector_name(connector
));
1591 connector_set
[i
] = connector
;
1596 set
.x
= crtc_req
->x
;
1597 set
.y
= crtc_req
->y
;
1599 set
.connectors
= connector_set
;
1600 set
.num_connectors
= crtc_req
->count_connectors
;
1602 ret
= crtc
->funcs
->set_config(&set
);
1605 kfree(connector_set
);
1606 mutex_unlock(&dev
->mode_config
.mutex
);
1610 int drm_mode_cursor_ioctl(struct drm_device
*dev
,
1611 void *data
, struct drm_file
*file_priv
)
1613 struct drm_mode_cursor
*req
= data
;
1614 struct drm_mode_object
*obj
;
1615 struct drm_crtc
*crtc
;
1618 if (!drm_core_check_feature(dev
, DRIVER_MODESET
))
1622 DRM_ERROR("no operation set\n");
1626 mutex_lock(&dev
->mode_config
.mutex
);
1627 obj
= drm_mode_object_find(dev
, req
->crtc_id
, DRM_MODE_OBJECT_CRTC
);
1629 DRM_DEBUG_KMS("Unknown CRTC ID %d\n", req
->crtc_id
);
1633 crtc
= obj_to_crtc(obj
);
1635 if (req
->flags
& DRM_MODE_CURSOR_BO
) {
1636 if (!crtc
->funcs
->cursor_set
) {
1637 DRM_ERROR("crtc does not support cursor\n");
1641 /* Turns off the cursor if handle is 0 */
1642 ret
= crtc
->funcs
->cursor_set(crtc
, file_priv
, req
->handle
,
1643 req
->width
, req
->height
);
1646 if (req
->flags
& DRM_MODE_CURSOR_MOVE
) {
1647 if (crtc
->funcs
->cursor_move
) {
1648 ret
= crtc
->funcs
->cursor_move(crtc
, req
->x
, req
->y
);
1650 DRM_ERROR("crtc does not support cursor\n");
1656 mutex_unlock(&dev
->mode_config
.mutex
);
1661 * drm_mode_addfb - add an FB to the graphics configuration
1662 * @inode: inode from the ioctl
1663 * @filp: file * from the ioctl
1664 * @cmd: cmd from ioctl
1665 * @arg: arg from ioctl
1668 * Takes mode config lock.
1670 * Add a new FB to the specified CRTC, given a user request.
1672 * Called by the user via ioctl.
1675 * Zero on success, errno on failure.
1677 int drm_mode_addfb(struct drm_device
*dev
,
1678 void *data
, struct drm_file
*file_priv
)
1680 struct drm_mode_fb_cmd
*r
= data
;
1681 struct drm_mode_config
*config
= &dev
->mode_config
;
1682 struct drm_framebuffer
*fb
;
1685 if (!drm_core_check_feature(dev
, DRIVER_MODESET
))
1688 if ((config
->min_width
> r
->width
) || (r
->width
> config
->max_width
)) {
1689 DRM_ERROR("mode new framebuffer width not within limits\n");
1692 if ((config
->min_height
> r
->height
) || (r
->height
> config
->max_height
)) {
1693 DRM_ERROR("mode new framebuffer height not within limits\n");
1697 mutex_lock(&dev
->mode_config
.mutex
);
1699 /* TODO check buffer is sufficiently large */
1700 /* TODO setup destructor callback */
1702 fb
= dev
->mode_config
.funcs
->fb_create(dev
, file_priv
, r
);
1704 DRM_ERROR("could not create framebuffer\n");
1709 r
->fb_id
= fb
->base
.id
;
1710 list_add(&fb
->filp_head
, &file_priv
->fbs
);
1711 DRM_DEBUG_KMS("[FB:%d]\n", fb
->base
.id
);
1714 mutex_unlock(&dev
->mode_config
.mutex
);
1719 * drm_mode_rmfb - remove an FB from the configuration
1720 * @inode: inode from the ioctl
1721 * @filp: file * from the ioctl
1722 * @cmd: cmd from ioctl
1723 * @arg: arg from ioctl
1726 * Takes mode config lock.
1728 * Remove the FB specified by the user.
1730 * Called by the user via ioctl.
1733 * Zero on success, errno on failure.
1735 int drm_mode_rmfb(struct drm_device
*dev
,
1736 void *data
, struct drm_file
*file_priv
)
1738 struct drm_mode_object
*obj
;
1739 struct drm_framebuffer
*fb
= NULL
;
1740 struct drm_framebuffer
*fbl
= NULL
;
1741 uint32_t *id
= data
;
1745 if (!drm_core_check_feature(dev
, DRIVER_MODESET
))
1748 mutex_lock(&dev
->mode_config
.mutex
);
1749 obj
= drm_mode_object_find(dev
, *id
, DRM_MODE_OBJECT_FB
);
1750 /* TODO check that we really get a framebuffer back. */
1752 DRM_ERROR("mode invalid framebuffer id\n");
1756 fb
= obj_to_fb(obj
);
1758 list_for_each_entry(fbl
, &file_priv
->fbs
, filp_head
)
1763 DRM_ERROR("tried to remove a fb that we didn't own\n");
1768 /* TODO release all crtc connected to the framebuffer */
1769 /* TODO unhock the destructor from the buffer object */
1771 list_del(&fb
->filp_head
);
1772 fb
->funcs
->destroy(fb
);
1775 mutex_unlock(&dev
->mode_config
.mutex
);
1780 * drm_mode_getfb - get FB info
1781 * @inode: inode from the ioctl
1782 * @filp: file * from the ioctl
1783 * @cmd: cmd from ioctl
1784 * @arg: arg from ioctl
1789 * Lookup the FB given its ID and return info about it.
1791 * Called by the user via ioctl.
1794 * Zero on success, errno on failure.
1796 int drm_mode_getfb(struct drm_device
*dev
,
1797 void *data
, struct drm_file
*file_priv
)
1799 struct drm_mode_fb_cmd
*r
= data
;
1800 struct drm_mode_object
*obj
;
1801 struct drm_framebuffer
*fb
;
1804 if (!drm_core_check_feature(dev
, DRIVER_MODESET
))
1807 mutex_lock(&dev
->mode_config
.mutex
);
1808 obj
= drm_mode_object_find(dev
, r
->fb_id
, DRM_MODE_OBJECT_FB
);
1810 DRM_ERROR("invalid framebuffer id\n");
1814 fb
= obj_to_fb(obj
);
1816 r
->height
= fb
->height
;
1817 r
->width
= fb
->width
;
1818 r
->depth
= fb
->depth
;
1819 r
->bpp
= fb
->bits_per_pixel
;
1820 r
->pitch
= fb
->pitch
;
1821 fb
->funcs
->create_handle(fb
, file_priv
, &r
->handle
);
1824 mutex_unlock(&dev
->mode_config
.mutex
);
1828 int drm_mode_dirtyfb_ioctl(struct drm_device
*dev
,
1829 void *data
, struct drm_file
*file_priv
)
1831 struct drm_clip_rect __user
*clips_ptr
;
1832 struct drm_clip_rect
*clips
= NULL
;
1833 struct drm_mode_fb_dirty_cmd
*r
= data
;
1834 struct drm_mode_object
*obj
;
1835 struct drm_framebuffer
*fb
;
1840 if (!drm_core_check_feature(dev
, DRIVER_MODESET
))
1843 mutex_lock(&dev
->mode_config
.mutex
);
1844 obj
= drm_mode_object_find(dev
, r
->fb_id
, DRM_MODE_OBJECT_FB
);
1846 DRM_ERROR("invalid framebuffer id\n");
1850 fb
= obj_to_fb(obj
);
1852 num_clips
= r
->num_clips
;
1853 clips_ptr
= (struct drm_clip_rect
*)(unsigned long)r
->clips_ptr
;
1855 if (!num_clips
!= !clips_ptr
) {
1860 flags
= DRM_MODE_FB_DIRTY_FLAGS
& r
->flags
;
1862 /* If userspace annotates copy, clips must come in pairs */
1863 if (flags
& DRM_MODE_FB_DIRTY_ANNOTATE_COPY
&& (num_clips
% 2)) {
1868 if (num_clips
&& clips_ptr
) {
1869 if (num_clips
< 0 || num_clips
> DRM_MODE_FB_DIRTY_MAX_CLIPS
) {
1873 clips
= kzalloc(num_clips
* sizeof(*clips
), GFP_KERNEL
);
1879 ret
= copy_from_user(clips
, clips_ptr
,
1880 num_clips
* sizeof(*clips
));
1887 if (fb
->funcs
->dirty
) {
1888 ret
= fb
->funcs
->dirty(fb
, file_priv
, flags
, r
->color
,
1898 mutex_unlock(&dev
->mode_config
.mutex
);
1904 * drm_fb_release - remove and free the FBs on this file
1905 * @filp: file * from the ioctl
1908 * Takes mode config lock.
1910 * Destroy all the FBs associated with @filp.
1912 * Called by the user via ioctl.
1915 * Zero on success, errno on failure.
1917 void drm_fb_release(struct drm_file
*priv
)
1919 struct drm_device
*dev
= priv
->minor
->dev
;
1920 struct drm_framebuffer
*fb
, *tfb
;
1922 mutex_lock(&dev
->mode_config
.mutex
);
1923 list_for_each_entry_safe(fb
, tfb
, &priv
->fbs
, filp_head
) {
1924 list_del(&fb
->filp_head
);
1925 fb
->funcs
->destroy(fb
);
1927 mutex_unlock(&dev
->mode_config
.mutex
);
1931 * drm_mode_attachmode - add a mode to the user mode list
1933 * @connector: connector to add the mode to
1934 * @mode: mode to add
1936 * Add @mode to @connector's user mode list.
1938 static int drm_mode_attachmode(struct drm_device
*dev
,
1939 struct drm_connector
*connector
,
1940 struct drm_display_mode
*mode
)
1944 list_add_tail(&mode
->head
, &connector
->user_modes
);
1948 int drm_mode_attachmode_crtc(struct drm_device
*dev
, struct drm_crtc
*crtc
,
1949 struct drm_display_mode
*mode
)
1951 struct drm_connector
*connector
;
1953 struct drm_display_mode
*dup_mode
;
1955 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
, head
) {
1956 if (!connector
->encoder
)
1958 if (connector
->encoder
->crtc
== crtc
) {
1960 dup_mode
= drm_mode_duplicate(dev
, mode
);
1963 ret
= drm_mode_attachmode(dev
, connector
, dup_mode
);
1971 EXPORT_SYMBOL(drm_mode_attachmode_crtc
);
1973 static int drm_mode_detachmode(struct drm_device
*dev
,
1974 struct drm_connector
*connector
,
1975 struct drm_display_mode
*mode
)
1979 struct drm_display_mode
*match_mode
, *t
;
1981 list_for_each_entry_safe(match_mode
, t
, &connector
->user_modes
, head
) {
1982 if (drm_mode_equal(match_mode
, mode
)) {
1983 list_del(&match_mode
->head
);
1984 drm_mode_destroy(dev
, match_mode
);
1996 int drm_mode_detachmode_crtc(struct drm_device
*dev
, struct drm_display_mode
*mode
)
1998 struct drm_connector
*connector
;
2000 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
, head
) {
2001 drm_mode_detachmode(dev
, connector
, mode
);
2005 EXPORT_SYMBOL(drm_mode_detachmode_crtc
);
2008 * drm_fb_attachmode - Attach a user mode to an connector
2009 * @inode: inode from the ioctl
2010 * @filp: file * from the ioctl
2011 * @cmd: cmd from ioctl
2012 * @arg: arg from ioctl
2014 * This attaches a user specified mode to an connector.
2015 * Called by the user via ioctl.
2018 * Zero on success, errno on failure.
2020 int drm_mode_attachmode_ioctl(struct drm_device
*dev
,
2021 void *data
, struct drm_file
*file_priv
)
2023 struct drm_mode_mode_cmd
*mode_cmd
= data
;
2024 struct drm_connector
*connector
;
2025 struct drm_display_mode
*mode
;
2026 struct drm_mode_object
*obj
;
2027 struct drm_mode_modeinfo
*umode
= &mode_cmd
->mode
;
2030 if (!drm_core_check_feature(dev
, DRIVER_MODESET
))
2033 mutex_lock(&dev
->mode_config
.mutex
);
2035 obj
= drm_mode_object_find(dev
, mode_cmd
->connector_id
, DRM_MODE_OBJECT_CONNECTOR
);
2040 connector
= obj_to_connector(obj
);
2042 mode
= drm_mode_create(dev
);
2048 drm_crtc_convert_umode(mode
, umode
);
2050 ret
= drm_mode_attachmode(dev
, connector
, mode
);
2052 mutex_unlock(&dev
->mode_config
.mutex
);
2058 * drm_fb_detachmode - Detach a user specified mode from an connector
2059 * @inode: inode from the ioctl
2060 * @filp: file * from the ioctl
2061 * @cmd: cmd from ioctl
2062 * @arg: arg from ioctl
2064 * Called by the user via ioctl.
2067 * Zero on success, errno on failure.
2069 int drm_mode_detachmode_ioctl(struct drm_device
*dev
,
2070 void *data
, struct drm_file
*file_priv
)
2072 struct drm_mode_object
*obj
;
2073 struct drm_mode_mode_cmd
*mode_cmd
= data
;
2074 struct drm_connector
*connector
;
2075 struct drm_display_mode mode
;
2076 struct drm_mode_modeinfo
*umode
= &mode_cmd
->mode
;
2079 if (!drm_core_check_feature(dev
, DRIVER_MODESET
))
2082 mutex_lock(&dev
->mode_config
.mutex
);
2084 obj
= drm_mode_object_find(dev
, mode_cmd
->connector_id
, DRM_MODE_OBJECT_CONNECTOR
);
2089 connector
= obj_to_connector(obj
);
2091 drm_crtc_convert_umode(&mode
, umode
);
2092 ret
= drm_mode_detachmode(dev
, connector
, &mode
);
2094 mutex_unlock(&dev
->mode_config
.mutex
);
2098 struct drm_property
*drm_property_create(struct drm_device
*dev
, int flags
,
2099 const char *name
, int num_values
)
2101 struct drm_property
*property
= NULL
;
2103 property
= kzalloc(sizeof(struct drm_property
), GFP_KERNEL
);
2108 property
->values
= kzalloc(sizeof(uint64_t)*num_values
, GFP_KERNEL
);
2109 if (!property
->values
)
2113 drm_mode_object_get(dev
, &property
->base
, DRM_MODE_OBJECT_PROPERTY
);
2114 property
->flags
= flags
;
2115 property
->num_values
= num_values
;
2116 INIT_LIST_HEAD(&property
->enum_blob_list
);
2119 strncpy(property
->name
, name
, DRM_PROP_NAME_LEN
);
2121 list_add_tail(&property
->head
, &dev
->mode_config
.property_list
);
2127 EXPORT_SYMBOL(drm_property_create
);
2129 int drm_property_add_enum(struct drm_property
*property
, int index
,
2130 uint64_t value
, const char *name
)
2132 struct drm_property_enum
*prop_enum
;
2134 if (!(property
->flags
& DRM_MODE_PROP_ENUM
))
2137 if (!list_empty(&property
->enum_blob_list
)) {
2138 list_for_each_entry(prop_enum
, &property
->enum_blob_list
, head
) {
2139 if (prop_enum
->value
== value
) {
2140 strncpy(prop_enum
->name
, name
, DRM_PROP_NAME_LEN
);
2141 prop_enum
->name
[DRM_PROP_NAME_LEN
-1] = '\0';
2147 prop_enum
= kzalloc(sizeof(struct drm_property_enum
), GFP_KERNEL
);
2151 strncpy(prop_enum
->name
, name
, DRM_PROP_NAME_LEN
);
2152 prop_enum
->name
[DRM_PROP_NAME_LEN
-1] = '\0';
2153 prop_enum
->value
= value
;
2155 property
->values
[index
] = value
;
2156 list_add_tail(&prop_enum
->head
, &property
->enum_blob_list
);
2159 EXPORT_SYMBOL(drm_property_add_enum
);
2161 void drm_property_destroy(struct drm_device
*dev
, struct drm_property
*property
)
2163 struct drm_property_enum
*prop_enum
, *pt
;
2165 list_for_each_entry_safe(prop_enum
, pt
, &property
->enum_blob_list
, head
) {
2166 list_del(&prop_enum
->head
);
2170 if (property
->num_values
)
2171 kfree(property
->values
);
2172 drm_mode_object_put(dev
, &property
->base
);
2173 list_del(&property
->head
);
2176 EXPORT_SYMBOL(drm_property_destroy
);
2178 int drm_connector_attach_property(struct drm_connector
*connector
,
2179 struct drm_property
*property
, uint64_t init_val
)
2183 for (i
= 0; i
< DRM_CONNECTOR_MAX_PROPERTY
; i
++) {
2184 if (connector
->property_ids
[i
] == 0) {
2185 connector
->property_ids
[i
] = property
->base
.id
;
2186 connector
->property_values
[i
] = init_val
;
2191 if (i
== DRM_CONNECTOR_MAX_PROPERTY
)
2195 EXPORT_SYMBOL(drm_connector_attach_property
);
2197 int drm_connector_property_set_value(struct drm_connector
*connector
,
2198 struct drm_property
*property
, uint64_t value
)
2202 for (i
= 0; i
< DRM_CONNECTOR_MAX_PROPERTY
; i
++) {
2203 if (connector
->property_ids
[i
] == property
->base
.id
) {
2204 connector
->property_values
[i
] = value
;
2209 if (i
== DRM_CONNECTOR_MAX_PROPERTY
)
2213 EXPORT_SYMBOL(drm_connector_property_set_value
);
2215 int drm_connector_property_get_value(struct drm_connector
*connector
,
2216 struct drm_property
*property
, uint64_t *val
)
2220 for (i
= 0; i
< DRM_CONNECTOR_MAX_PROPERTY
; i
++) {
2221 if (connector
->property_ids
[i
] == property
->base
.id
) {
2222 *val
= connector
->property_values
[i
];
2227 if (i
== DRM_CONNECTOR_MAX_PROPERTY
)
2231 EXPORT_SYMBOL(drm_connector_property_get_value
);
2233 int drm_mode_getproperty_ioctl(struct drm_device
*dev
,
2234 void *data
, struct drm_file
*file_priv
)
2236 struct drm_mode_object
*obj
;
2237 struct drm_mode_get_property
*out_resp
= data
;
2238 struct drm_property
*property
;
2241 int value_count
= 0;
2244 struct drm_property_enum
*prop_enum
;
2245 struct drm_mode_property_enum __user
*enum_ptr
;
2246 struct drm_property_blob
*prop_blob
;
2247 uint32_t *blob_id_ptr
;
2248 uint64_t __user
*values_ptr
;
2249 uint32_t __user
*blob_length_ptr
;
2251 if (!drm_core_check_feature(dev
, DRIVER_MODESET
))
2254 mutex_lock(&dev
->mode_config
.mutex
);
2255 obj
= drm_mode_object_find(dev
, out_resp
->prop_id
, DRM_MODE_OBJECT_PROPERTY
);
2260 property
= obj_to_property(obj
);
2262 if (property
->flags
& DRM_MODE_PROP_ENUM
) {
2263 list_for_each_entry(prop_enum
, &property
->enum_blob_list
, head
)
2265 } else if (property
->flags
& DRM_MODE_PROP_BLOB
) {
2266 list_for_each_entry(prop_blob
, &property
->enum_blob_list
, head
)
2270 value_count
= property
->num_values
;
2272 strncpy(out_resp
->name
, property
->name
, DRM_PROP_NAME_LEN
);
2273 out_resp
->name
[DRM_PROP_NAME_LEN
-1] = 0;
2274 out_resp
->flags
= property
->flags
;
2276 if ((out_resp
->count_values
>= value_count
) && value_count
) {
2277 values_ptr
= (uint64_t *)(unsigned long)out_resp
->values_ptr
;
2278 for (i
= 0; i
< value_count
; i
++) {
2279 if (copy_to_user(values_ptr
+ i
, &property
->values
[i
], sizeof(uint64_t))) {
2285 out_resp
->count_values
= value_count
;
2287 if (property
->flags
& DRM_MODE_PROP_ENUM
) {
2288 if ((out_resp
->count_enum_blobs
>= enum_count
) && enum_count
) {
2290 enum_ptr
= (struct drm_mode_property_enum
*)(unsigned long)out_resp
->enum_blob_ptr
;
2291 list_for_each_entry(prop_enum
, &property
->enum_blob_list
, head
) {
2293 if (copy_to_user(&enum_ptr
[copied
].value
, &prop_enum
->value
, sizeof(uint64_t))) {
2298 if (copy_to_user(&enum_ptr
[copied
].name
,
2299 &prop_enum
->name
, DRM_PROP_NAME_LEN
)) {
2306 out_resp
->count_enum_blobs
= enum_count
;
2309 if (property
->flags
& DRM_MODE_PROP_BLOB
) {
2310 if ((out_resp
->count_enum_blobs
>= blob_count
) && blob_count
) {
2312 blob_id_ptr
= (uint32_t *)(unsigned long)out_resp
->enum_blob_ptr
;
2313 blob_length_ptr
= (uint32_t *)(unsigned long)out_resp
->values_ptr
;
2315 list_for_each_entry(prop_blob
, &property
->enum_blob_list
, head
) {
2316 if (put_user(prop_blob
->base
.id
, blob_id_ptr
+ copied
)) {
2321 if (put_user(prop_blob
->length
, blob_length_ptr
+ copied
)) {
2329 out_resp
->count_enum_blobs
= blob_count
;
2332 mutex_unlock(&dev
->mode_config
.mutex
);
2336 static struct drm_property_blob
*drm_property_create_blob(struct drm_device
*dev
, int length
,
2339 struct drm_property_blob
*blob
;
2341 if (!length
|| !data
)
2344 blob
= kzalloc(sizeof(struct drm_property_blob
)+length
, GFP_KERNEL
);
2348 blob
->data
= (void *)((char *)blob
+ sizeof(struct drm_property_blob
));
2349 blob
->length
= length
;
2351 memcpy(blob
->data
, data
, length
);
2353 drm_mode_object_get(dev
, &blob
->base
, DRM_MODE_OBJECT_BLOB
);
2355 list_add_tail(&blob
->head
, &dev
->mode_config
.property_blob_list
);
2359 static void drm_property_destroy_blob(struct drm_device
*dev
,
2360 struct drm_property_blob
*blob
)
2362 drm_mode_object_put(dev
, &blob
->base
);
2363 list_del(&blob
->head
);
2367 int drm_mode_getblob_ioctl(struct drm_device
*dev
,
2368 void *data
, struct drm_file
*file_priv
)
2370 struct drm_mode_object
*obj
;
2371 struct drm_mode_get_blob
*out_resp
= data
;
2372 struct drm_property_blob
*blob
;
2376 if (!drm_core_check_feature(dev
, DRIVER_MODESET
))
2379 mutex_lock(&dev
->mode_config
.mutex
);
2380 obj
= drm_mode_object_find(dev
, out_resp
->blob_id
, DRM_MODE_OBJECT_BLOB
);
2385 blob
= obj_to_blob(obj
);
2387 if (out_resp
->length
== blob
->length
) {
2388 blob_ptr
= (void *)(unsigned long)out_resp
->data
;
2389 if (copy_to_user(blob_ptr
, blob
->data
, blob
->length
)){
2394 out_resp
->length
= blob
->length
;
2397 mutex_unlock(&dev
->mode_config
.mutex
);
2401 int drm_mode_connector_update_edid_property(struct drm_connector
*connector
,
2404 struct drm_device
*dev
= connector
->dev
;
2407 if (connector
->edid_blob_ptr
)
2408 drm_property_destroy_blob(dev
, connector
->edid_blob_ptr
);
2410 /* Delete edid, when there is none. */
2412 connector
->edid_blob_ptr
= NULL
;
2413 ret
= drm_connector_property_set_value(connector
, dev
->mode_config
.edid_property
, 0);
2417 size
= EDID_LENGTH
* (1 + edid
->extensions
);
2418 connector
->edid_blob_ptr
= drm_property_create_blob(connector
->dev
,
2421 ret
= drm_connector_property_set_value(connector
,
2422 dev
->mode_config
.edid_property
,
2423 connector
->edid_blob_ptr
->base
.id
);
2427 EXPORT_SYMBOL(drm_mode_connector_update_edid_property
);
2429 int drm_mode_connector_property_set_ioctl(struct drm_device
*dev
,
2430 void *data
, struct drm_file
*file_priv
)
2432 struct drm_mode_connector_set_property
*out_resp
= data
;
2433 struct drm_mode_object
*obj
;
2434 struct drm_property
*property
;
2435 struct drm_connector
*connector
;
2439 if (!drm_core_check_feature(dev
, DRIVER_MODESET
))
2442 mutex_lock(&dev
->mode_config
.mutex
);
2444 obj
= drm_mode_object_find(dev
, out_resp
->connector_id
, DRM_MODE_OBJECT_CONNECTOR
);
2448 connector
= obj_to_connector(obj
);
2450 for (i
= 0; i
< DRM_CONNECTOR_MAX_PROPERTY
; i
++) {
2451 if (connector
->property_ids
[i
] == out_resp
->prop_id
)
2455 if (i
== DRM_CONNECTOR_MAX_PROPERTY
) {
2459 obj
= drm_mode_object_find(dev
, out_resp
->prop_id
, DRM_MODE_OBJECT_PROPERTY
);
2463 property
= obj_to_property(obj
);
2465 if (property
->flags
& DRM_MODE_PROP_IMMUTABLE
)
2468 if (property
->flags
& DRM_MODE_PROP_RANGE
) {
2469 if (out_resp
->value
< property
->values
[0])
2472 if (out_resp
->value
> property
->values
[1])
2476 for (i
= 0; i
< property
->num_values
; i
++) {
2477 if (property
->values
[i
] == out_resp
->value
) {
2487 /* Do DPMS ourselves */
2488 if (property
== connector
->dev
->mode_config
.dpms_property
) {
2489 if (connector
->funcs
->dpms
)
2490 (*connector
->funcs
->dpms
)(connector
, (int) out_resp
->value
);
2492 } else if (connector
->funcs
->set_property
)
2493 ret
= connector
->funcs
->set_property(connector
, property
, out_resp
->value
);
2495 /* store the property value if successful */
2497 drm_connector_property_set_value(connector
, property
, out_resp
->value
);
2499 mutex_unlock(&dev
->mode_config
.mutex
);
2503 int drm_mode_connector_attach_encoder(struct drm_connector
*connector
,
2504 struct drm_encoder
*encoder
)
2508 for (i
= 0; i
< DRM_CONNECTOR_MAX_ENCODER
; i
++) {
2509 if (connector
->encoder_ids
[i
] == 0) {
2510 connector
->encoder_ids
[i
] = encoder
->base
.id
;
2516 EXPORT_SYMBOL(drm_mode_connector_attach_encoder
);
2518 void drm_mode_connector_detach_encoder(struct drm_connector
*connector
,
2519 struct drm_encoder
*encoder
)
2522 for (i
= 0; i
< DRM_CONNECTOR_MAX_ENCODER
; i
++) {
2523 if (connector
->encoder_ids
[i
] == encoder
->base
.id
) {
2524 connector
->encoder_ids
[i
] = 0;
2525 if (connector
->encoder
== encoder
)
2526 connector
->encoder
= NULL
;
2531 EXPORT_SYMBOL(drm_mode_connector_detach_encoder
);
2533 bool drm_mode_crtc_set_gamma_size(struct drm_crtc
*crtc
,
2536 crtc
->gamma_size
= gamma_size
;
2538 crtc
->gamma_store
= kzalloc(gamma_size
* sizeof(uint16_t) * 3, GFP_KERNEL
);
2539 if (!crtc
->gamma_store
) {
2540 crtc
->gamma_size
= 0;
2546 EXPORT_SYMBOL(drm_mode_crtc_set_gamma_size
);
2548 int drm_mode_gamma_set_ioctl(struct drm_device
*dev
,
2549 void *data
, struct drm_file
*file_priv
)
2551 struct drm_mode_crtc_lut
*crtc_lut
= data
;
2552 struct drm_mode_object
*obj
;
2553 struct drm_crtc
*crtc
;
2554 void *r_base
, *g_base
, *b_base
;
2558 if (!drm_core_check_feature(dev
, DRIVER_MODESET
))
2561 mutex_lock(&dev
->mode_config
.mutex
);
2562 obj
= drm_mode_object_find(dev
, crtc_lut
->crtc_id
, DRM_MODE_OBJECT_CRTC
);
2567 crtc
= obj_to_crtc(obj
);
2569 /* memcpy into gamma store */
2570 if (crtc_lut
->gamma_size
!= crtc
->gamma_size
) {
2575 size
= crtc_lut
->gamma_size
* (sizeof(uint16_t));
2576 r_base
= crtc
->gamma_store
;
2577 if (copy_from_user(r_base
, (void __user
*)(unsigned long)crtc_lut
->red
, size
)) {
2582 g_base
= r_base
+ size
;
2583 if (copy_from_user(g_base
, (void __user
*)(unsigned long)crtc_lut
->green
, size
)) {
2588 b_base
= g_base
+ size
;
2589 if (copy_from_user(b_base
, (void __user
*)(unsigned long)crtc_lut
->blue
, size
)) {
2594 crtc
->funcs
->gamma_set(crtc
, r_base
, g_base
, b_base
, 0, crtc
->gamma_size
);
2597 mutex_unlock(&dev
->mode_config
.mutex
);
2602 int drm_mode_gamma_get_ioctl(struct drm_device
*dev
,
2603 void *data
, struct drm_file
*file_priv
)
2605 struct drm_mode_crtc_lut
*crtc_lut
= data
;
2606 struct drm_mode_object
*obj
;
2607 struct drm_crtc
*crtc
;
2608 void *r_base
, *g_base
, *b_base
;
2612 if (!drm_core_check_feature(dev
, DRIVER_MODESET
))
2615 mutex_lock(&dev
->mode_config
.mutex
);
2616 obj
= drm_mode_object_find(dev
, crtc_lut
->crtc_id
, DRM_MODE_OBJECT_CRTC
);
2621 crtc
= obj_to_crtc(obj
);
2623 /* memcpy into gamma store */
2624 if (crtc_lut
->gamma_size
!= crtc
->gamma_size
) {
2629 size
= crtc_lut
->gamma_size
* (sizeof(uint16_t));
2630 r_base
= crtc
->gamma_store
;
2631 if (copy_to_user((void __user
*)(unsigned long)crtc_lut
->red
, r_base
, size
)) {
2636 g_base
= r_base
+ size
;
2637 if (copy_to_user((void __user
*)(unsigned long)crtc_lut
->green
, g_base
, size
)) {
2642 b_base
= g_base
+ size
;
2643 if (copy_to_user((void __user
*)(unsigned long)crtc_lut
->blue
, b_base
, size
)) {
2648 mutex_unlock(&dev
->mode_config
.mutex
);
2652 int drm_mode_page_flip_ioctl(struct drm_device
*dev
,
2653 void *data
, struct drm_file
*file_priv
)
2655 struct drm_mode_crtc_page_flip
*page_flip
= data
;
2656 struct drm_mode_object
*obj
;
2657 struct drm_crtc
*crtc
;
2658 struct drm_framebuffer
*fb
;
2659 struct drm_pending_vblank_event
*e
= NULL
;
2660 unsigned long flags
;
2663 if (page_flip
->flags
& ~DRM_MODE_PAGE_FLIP_FLAGS
||
2664 page_flip
->reserved
!= 0)
2667 mutex_lock(&dev
->mode_config
.mutex
);
2668 obj
= drm_mode_object_find(dev
, page_flip
->crtc_id
, DRM_MODE_OBJECT_CRTC
);
2671 crtc
= obj_to_crtc(obj
);
2673 if (crtc
->fb
== NULL
) {
2674 /* The framebuffer is currently unbound, presumably
2675 * due to a hotplug event, that userspace has not
2682 if (crtc
->funcs
->page_flip
== NULL
)
2685 obj
= drm_mode_object_find(dev
, page_flip
->fb_id
, DRM_MODE_OBJECT_FB
);
2688 fb
= obj_to_fb(obj
);
2690 if (page_flip
->flags
& DRM_MODE_PAGE_FLIP_EVENT
) {
2692 spin_lock_irqsave(&dev
->event_lock
, flags
);
2693 if (file_priv
->event_space
< sizeof e
->event
) {
2694 spin_unlock_irqrestore(&dev
->event_lock
, flags
);
2697 file_priv
->event_space
-= sizeof e
->event
;
2698 spin_unlock_irqrestore(&dev
->event_lock
, flags
);
2700 e
= kzalloc(sizeof *e
, GFP_KERNEL
);
2702 spin_lock_irqsave(&dev
->event_lock
, flags
);
2703 file_priv
->event_space
+= sizeof e
->event
;
2704 spin_unlock_irqrestore(&dev
->event_lock
, flags
);
2708 e
->event
.base
.type
= DRM_EVENT_FLIP_COMPLETE
;
2709 e
->event
.base
.length
= sizeof e
->event
;
2710 e
->event
.user_data
= page_flip
->user_data
;
2711 e
->base
.event
= &e
->event
.base
;
2712 e
->base
.file_priv
= file_priv
;
2714 (void (*) (struct drm_pending_event
*)) kfree
;
2717 ret
= crtc
->funcs
->page_flip(crtc
, fb
, e
);
2719 spin_lock_irqsave(&dev
->event_lock
, flags
);
2720 file_priv
->event_space
+= sizeof e
->event
;
2721 spin_unlock_irqrestore(&dev
->event_lock
, flags
);
2726 mutex_unlock(&dev
->mode_config
.mutex
);
2730 void drm_mode_config_reset(struct drm_device
*dev
)
2732 struct drm_crtc
*crtc
;
2733 struct drm_encoder
*encoder
;
2734 struct drm_connector
*connector
;
2736 list_for_each_entry(crtc
, &dev
->mode_config
.crtc_list
, head
)
2737 if (crtc
->funcs
->reset
)
2738 crtc
->funcs
->reset(crtc
);
2740 list_for_each_entry(encoder
, &dev
->mode_config
.encoder_list
, head
)
2741 if (encoder
->funcs
->reset
)
2742 encoder
->funcs
->reset(encoder
);
2744 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
, head
)
2745 if (connector
->funcs
->reset
)
2746 connector
->funcs
->reset(connector
);
2748 EXPORT_SYMBOL(drm_mode_config_reset
);
2750 int drm_mode_create_dumb_ioctl(struct drm_device
*dev
,
2751 void *data
, struct drm_file
*file_priv
)
2753 struct drm_mode_create_dumb
*args
= data
;
2755 if (!dev
->driver
->dumb_create
)
2757 return dev
->driver
->dumb_create(file_priv
, dev
, args
);
2760 int drm_mode_mmap_dumb_ioctl(struct drm_device
*dev
,
2761 void *data
, struct drm_file
*file_priv
)
2763 struct drm_mode_map_dumb
*args
= data
;
2765 /* call driver ioctl to get mmap offset */
2766 if (!dev
->driver
->dumb_map_offset
)
2769 return dev
->driver
->dumb_map_offset(file_priv
, dev
, args
->handle
, &args
->offset
);
2772 int drm_mode_destroy_dumb_ioctl(struct drm_device
*dev
,
2773 void *data
, struct drm_file
*file_priv
)
2775 struct drm_mode_destroy_dumb
*args
= data
;
2777 if (!dev
->driver
->dumb_destroy
)
2780 return dev
->driver
->dumb_destroy(file_priv
, dev
, args
->handle
);