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 #if !defined(__AROS__)
33 #include <linux/list.h>
34 #include <linux/slab.h>
41 struct drm_prop_enum_list
{
46 /* Avoid boilerplate. I'm tired of typing. */
47 #define DRM_ENUM_NAME_FN(fnname, list) \
48 char *fnname(int val) \
51 for (i = 0; i < ARRAY_SIZE(list); i++) { \
52 if (list[i].type == val) \
53 return list[i].name; \
61 static struct drm_prop_enum_list drm_dpms_enum_list
[] =
62 { { DRM_MODE_DPMS_ON
, "On" },
63 { DRM_MODE_DPMS_STANDBY
, "Standby" },
64 { DRM_MODE_DPMS_SUSPEND
, "Suspend" },
65 { DRM_MODE_DPMS_OFF
, "Off" }
68 DRM_ENUM_NAME_FN(drm_get_dpms_name
, drm_dpms_enum_list
)
73 static struct drm_prop_enum_list drm_scaling_mode_enum_list
[] =
75 { DRM_MODE_SCALE_NONE
, "None" },
76 { DRM_MODE_SCALE_FULLSCREEN
, "Full" },
77 { DRM_MODE_SCALE_CENTER
, "Center" },
78 { DRM_MODE_SCALE_ASPECT
, "Full aspect" },
81 static struct drm_prop_enum_list drm_dithering_mode_enum_list
[] =
83 { DRM_MODE_DITHERING_OFF
, "Off" },
84 { DRM_MODE_DITHERING_ON
, "On" },
85 { DRM_MODE_DITHERING_AUTO
, "Automatic" },
89 * Non-global properties, but "required" for certain connectors.
91 static struct drm_prop_enum_list drm_dvi_i_select_enum_list
[] =
93 { DRM_MODE_SUBCONNECTOR_Automatic
, "Automatic" }, /* DVI-I and TV-out */
94 { DRM_MODE_SUBCONNECTOR_DVID
, "DVI-D" }, /* DVI-I */
95 { DRM_MODE_SUBCONNECTOR_DVIA
, "DVI-A" }, /* DVI-I */
98 DRM_ENUM_NAME_FN(drm_get_dvi_i_select_name
, drm_dvi_i_select_enum_list
)
100 static struct drm_prop_enum_list drm_dvi_i_subconnector_enum_list
[] =
102 { DRM_MODE_SUBCONNECTOR_Unknown
, "Unknown" }, /* DVI-I and TV-out */
103 { DRM_MODE_SUBCONNECTOR_DVID
, "DVI-D" }, /* DVI-I */
104 { DRM_MODE_SUBCONNECTOR_DVIA
, "DVI-A" }, /* DVI-I */
107 DRM_ENUM_NAME_FN(drm_get_dvi_i_subconnector_name
,
108 drm_dvi_i_subconnector_enum_list
)
110 static struct drm_prop_enum_list drm_tv_select_enum_list
[] =
112 { DRM_MODE_SUBCONNECTOR_Automatic
, "Automatic" }, /* DVI-I and TV-out */
113 { DRM_MODE_SUBCONNECTOR_Composite
, "Composite" }, /* TV-out */
114 { DRM_MODE_SUBCONNECTOR_SVIDEO
, "SVIDEO" }, /* TV-out */
115 { DRM_MODE_SUBCONNECTOR_Component
, "Component" }, /* TV-out */
116 { DRM_MODE_SUBCONNECTOR_SCART
, "SCART" }, /* TV-out */
119 DRM_ENUM_NAME_FN(drm_get_tv_select_name
, drm_tv_select_enum_list
)
121 static struct drm_prop_enum_list drm_tv_subconnector_enum_list
[] =
123 { DRM_MODE_SUBCONNECTOR_Unknown
, "Unknown" }, /* DVI-I and TV-out */
124 { DRM_MODE_SUBCONNECTOR_Composite
, "Composite" }, /* TV-out */
125 { DRM_MODE_SUBCONNECTOR_SVIDEO
, "SVIDEO" }, /* TV-out */
126 { DRM_MODE_SUBCONNECTOR_Component
, "Component" }, /* TV-out */
127 { DRM_MODE_SUBCONNECTOR_SCART
, "SCART" }, /* TV-out */
130 DRM_ENUM_NAME_FN(drm_get_tv_subconnector_name
,
131 drm_tv_subconnector_enum_list
)
133 static struct drm_prop_enum_list drm_dirty_info_enum_list
[] = {
134 { DRM_MODE_DIRTY_OFF
, "Off" },
135 { DRM_MODE_DIRTY_ON
, "On" },
136 { DRM_MODE_DIRTY_ANNOTATE
, "Annotate" },
139 DRM_ENUM_NAME_FN(drm_get_dirty_info_name
,
140 drm_dirty_info_enum_list
)
142 struct drm_conn_prop_enum_list
{
149 * Connector and encoder types.
151 static struct drm_conn_prop_enum_list drm_connector_enum_list
[] =
152 { { DRM_MODE_CONNECTOR_Unknown
, "Unknown", 0 },
153 { DRM_MODE_CONNECTOR_VGA
, "VGA", 0 },
154 { DRM_MODE_CONNECTOR_DVII
, "DVI-I", 0 },
155 { DRM_MODE_CONNECTOR_DVID
, "DVI-D", 0 },
156 { DRM_MODE_CONNECTOR_DVIA
, "DVI-A", 0 },
157 { DRM_MODE_CONNECTOR_Composite
, "Composite", 0 },
158 { DRM_MODE_CONNECTOR_SVIDEO
, "SVIDEO", 0 },
159 { DRM_MODE_CONNECTOR_LVDS
, "LVDS", 0 },
160 { DRM_MODE_CONNECTOR_Component
, "Component", 0 },
161 { DRM_MODE_CONNECTOR_9PinDIN
, "DIN", 0 },
162 { DRM_MODE_CONNECTOR_DisplayPort
, "DP", 0 },
163 { DRM_MODE_CONNECTOR_HDMIA
, "HDMI-A", 0 },
164 { DRM_MODE_CONNECTOR_HDMIB
, "HDMI-B", 0 },
165 { DRM_MODE_CONNECTOR_TV
, "TV", 0 },
166 { DRM_MODE_CONNECTOR_eDP
, "eDP", 0 },
169 static struct drm_prop_enum_list drm_encoder_enum_list
[] =
170 { { DRM_MODE_ENCODER_NONE
, "None" },
171 { DRM_MODE_ENCODER_DAC
, "DAC" },
172 { DRM_MODE_ENCODER_TMDS
, "TMDS" },
173 { DRM_MODE_ENCODER_LVDS
, "LVDS" },
174 { DRM_MODE_ENCODER_TVDAC
, "TV" },
177 char *drm_get_encoder_name(struct drm_encoder
*encoder
)
181 snprintf(buf
, 32, "%s-%d",
182 drm_encoder_enum_list
[encoder
->encoder_type
].name
,
186 EXPORT_SYMBOL(drm_get_encoder_name
);
188 char *drm_get_connector_name(struct drm_connector
*connector
)
192 snprintf(buf
, 32, "%s-%d",
193 drm_connector_enum_list
[connector
->connector_type
].name
,
194 connector
->connector_type_id
);
197 EXPORT_SYMBOL(drm_get_connector_name
);
199 char *drm_get_connector_status_name(enum drm_connector_status status
)
201 if (status
== connector_status_connected
)
203 else if (status
== connector_status_disconnected
)
204 return "disconnected";
210 * drm_mode_object_get - allocate a new identifier
212 * @ptr: object pointer, used to generate unique ID
217 * Create a unique identifier based on @ptr in @dev's identifier space. Used
218 * for tracking modes, CRTCs and connectors.
221 * New unique (relative to other objects in @dev) integer identifier for the
224 static int drm_mode_object_get(struct drm_device
*dev
,
225 struct drm_mode_object
*obj
, uint32_t obj_type
)
231 if (idr_pre_get(&dev
->mode_config
.crtc_idr
, GFP_KERNEL
) == 0) {
232 DRM_ERROR("Ran out memory getting a mode number\n");
236 mutex_lock(&dev
->mode_config
.idr_mutex
);
237 ret
= idr_get_new_above(&dev
->mode_config
.crtc_idr
, obj
, 1, &new_id
);
238 mutex_unlock(&dev
->mode_config
.idr_mutex
);
243 obj
->type
= obj_type
;
248 * drm_mode_object_put - free an identifer
253 * Caller must hold DRM mode_config lock.
255 * Free @id from @dev's unique identifier pool.
257 static void drm_mode_object_put(struct drm_device
*dev
,
258 struct drm_mode_object
*object
)
260 mutex_lock(&dev
->mode_config
.idr_mutex
);
261 idr_remove(&dev
->mode_config
.crtc_idr
, object
->id
);
262 mutex_unlock(&dev
->mode_config
.idr_mutex
);
265 struct drm_mode_object
*drm_mode_object_find(struct drm_device
*dev
,
266 uint32_t id
, uint32_t type
)
268 struct drm_mode_object
*obj
= NULL
;
270 mutex_lock(&dev
->mode_config
.idr_mutex
);
271 obj
= idr_find(&dev
->mode_config
.crtc_idr
, id
);
272 if (!obj
|| (obj
->type
!= type
) || (obj
->id
!= id
))
274 mutex_unlock(&dev
->mode_config
.idr_mutex
);
278 EXPORT_SYMBOL(drm_mode_object_find
);
281 * drm_framebuffer_init - initialize a framebuffer
285 * Caller must hold mode config lock.
287 * Allocates an ID for the framebuffer's parent mode object, sets its mode
288 * functions & device file and adds it to the master fd list.
291 * Zero on success, error code on failure.
293 int drm_framebuffer_init(struct drm_device
*dev
, struct drm_framebuffer
*fb
,
294 const struct drm_framebuffer_funcs
*funcs
)
298 ret
= drm_mode_object_get(dev
, &fb
->base
, DRM_MODE_OBJECT_FB
);
305 dev
->mode_config
.num_fb
++;
306 list_add(&fb
->head
, &dev
->mode_config
.fb_list
);
310 EXPORT_SYMBOL(drm_framebuffer_init
);
313 * drm_framebuffer_cleanup - remove a framebuffer object
314 * @fb: framebuffer to remove
317 * Caller must hold mode config lock.
319 * Scans all the CRTCs in @dev's mode_config. If they're using @fb, removes
320 * it, setting it to NULL.
322 void drm_framebuffer_cleanup(struct drm_framebuffer
*fb
)
324 struct drm_device
*dev
= fb
->dev
;
325 struct drm_crtc
*crtc
;
326 struct drm_mode_set set
;
329 /* remove from any CRTC */
330 list_for_each_entry(crtc
, &dev
->mode_config
.crtc_list
, head
) {
331 if (crtc
->fb
== fb
) {
332 /* should turn off the crtc */
333 memset(&set
, 0, sizeof(struct drm_mode_set
));
336 ret
= crtc
->funcs
->set_config(&set
);
338 DRM_ERROR("failed to reset crtc %p when fb was deleted\n", crtc
);
342 drm_mode_object_put(dev
, &fb
->base
);
344 dev
->mode_config
.num_fb
--;
346 EXPORT_SYMBOL(drm_framebuffer_cleanup
);
349 * drm_crtc_init - Initialise a new CRTC object
351 * @crtc: CRTC object to init
352 * @funcs: callbacks for the new CRTC
355 * Caller must hold mode config lock.
357 * Inits a new object created as base part of an driver crtc object.
359 void drm_crtc_init(struct drm_device
*dev
, struct drm_crtc
*crtc
,
360 const struct drm_crtc_funcs
*funcs
)
365 mutex_lock(&dev
->mode_config
.mutex
);
366 drm_mode_object_get(dev
, &crtc
->base
, DRM_MODE_OBJECT_CRTC
);
368 list_add_tail(&crtc
->head
, &dev
->mode_config
.crtc_list
);
369 dev
->mode_config
.num_crtc
++;
370 mutex_unlock(&dev
->mode_config
.mutex
);
372 EXPORT_SYMBOL(drm_crtc_init
);
375 * drm_crtc_cleanup - Cleans up the core crtc usage.
376 * @crtc: CRTC to cleanup
379 * Caller must hold mode config lock.
381 * Cleanup @crtc. Removes from drm modesetting space
382 * does NOT free object, caller does that.
384 void drm_crtc_cleanup(struct drm_crtc
*crtc
)
386 struct drm_device
*dev
= crtc
->dev
;
388 if (crtc
->gamma_store
) {
389 kfree(crtc
->gamma_store
);
390 crtc
->gamma_store
= NULL
;
393 drm_mode_object_put(dev
, &crtc
->base
);
394 list_del(&crtc
->head
);
395 dev
->mode_config
.num_crtc
--;
397 EXPORT_SYMBOL(drm_crtc_cleanup
);
400 * drm_mode_probed_add - add a mode to a connector's probed mode list
401 * @connector: connector the new mode
405 * Caller must hold mode config lock.
407 * Add @mode to @connector's mode list for later use.
409 void drm_mode_probed_add(struct drm_connector
*connector
,
410 struct drm_display_mode
*mode
)
412 list_add(&mode
->head
, &connector
->probed_modes
);
414 EXPORT_SYMBOL(drm_mode_probed_add
);
417 * drm_mode_remove - remove and free a mode
418 * @connector: connector list to modify
419 * @mode: mode to remove
422 * Caller must hold mode config lock.
424 * Remove @mode from @connector's mode list, then free it.
426 void drm_mode_remove(struct drm_connector
*connector
,
427 struct drm_display_mode
*mode
)
429 list_del(&mode
->head
);
432 EXPORT_SYMBOL(drm_mode_remove
);
435 * drm_connector_init - Init a preallocated connector
437 * @connector: the connector to init
438 * @funcs: callbacks for this connector
439 * @name: user visible name of the connector
442 * Caller must hold @dev's mode_config lock.
444 * Initialises a preallocated connector. Connectors should be
445 * subclassed as part of driver connector objects.
447 void drm_connector_init(struct drm_device
*dev
,
448 struct drm_connector
*connector
,
449 const struct drm_connector_funcs
*funcs
,
452 mutex_lock(&dev
->mode_config
.mutex
);
454 connector
->dev
= dev
;
455 connector
->funcs
= funcs
;
456 drm_mode_object_get(dev
, &connector
->base
, DRM_MODE_OBJECT_CONNECTOR
);
457 connector
->connector_type
= connector_type
;
458 connector
->connector_type_id
=
459 ++drm_connector_enum_list
[connector_type
].count
; /* TODO */
460 INIT_LIST_HEAD(&connector
->user_modes
);
461 INIT_LIST_HEAD(&connector
->probed_modes
);
462 INIT_LIST_HEAD(&connector
->modes
);
463 connector
->edid_blob_ptr
= NULL
;
465 list_add_tail(&connector
->head
, &dev
->mode_config
.connector_list
);
466 dev
->mode_config
.num_connector
++;
468 drm_connector_attach_property(connector
,
469 dev
->mode_config
.edid_property
, 0);
471 drm_connector_attach_property(connector
,
472 dev
->mode_config
.dpms_property
, 0);
474 mutex_unlock(&dev
->mode_config
.mutex
);
476 EXPORT_SYMBOL(drm_connector_init
);
479 * drm_connector_cleanup - cleans up an initialised connector
480 * @connector: connector to cleanup
483 * Caller must hold @dev's mode_config lock.
485 * Cleans up the connector but doesn't free the object.
487 void drm_connector_cleanup(struct drm_connector
*connector
)
489 struct drm_device
*dev
= connector
->dev
;
490 struct drm_display_mode
*mode
, *t
;
492 list_for_each_entry_safe(mode
, t
, &connector
->probed_modes
, head
)
493 drm_mode_remove(connector
, mode
);
495 list_for_each_entry_safe(mode
, t
, &connector
->modes
, head
)
496 drm_mode_remove(connector
, mode
);
498 list_for_each_entry_safe(mode
, t
, &connector
->user_modes
, head
)
499 drm_mode_remove(connector
, mode
);
501 mutex_lock(&dev
->mode_config
.mutex
);
502 drm_mode_object_put(dev
, &connector
->base
);
503 list_del(&connector
->head
);
504 mutex_unlock(&dev
->mode_config
.mutex
);
506 EXPORT_SYMBOL(drm_connector_cleanup
);
508 void drm_encoder_init(struct drm_device
*dev
,
509 struct drm_encoder
*encoder
,
510 const struct drm_encoder_funcs
*funcs
,
513 mutex_lock(&dev
->mode_config
.mutex
);
517 drm_mode_object_get(dev
, &encoder
->base
, DRM_MODE_OBJECT_ENCODER
);
518 encoder
->encoder_type
= encoder_type
;
519 encoder
->funcs
= funcs
;
521 list_add_tail(&encoder
->head
, &dev
->mode_config
.encoder_list
);
522 dev
->mode_config
.num_encoder
++;
524 mutex_unlock(&dev
->mode_config
.mutex
);
526 EXPORT_SYMBOL(drm_encoder_init
);
528 void drm_encoder_cleanup(struct drm_encoder
*encoder
)
530 struct drm_device
*dev
= encoder
->dev
;
531 mutex_lock(&dev
->mode_config
.mutex
);
532 drm_mode_object_put(dev
, &encoder
->base
);
533 list_del(&encoder
->head
);
534 mutex_unlock(&dev
->mode_config
.mutex
);
536 EXPORT_SYMBOL(drm_encoder_cleanup
);
539 * drm_mode_create - create a new display mode
543 * Caller must hold DRM mode_config lock.
545 * Create a new drm_display_mode, give it an ID, and return it.
548 * Pointer to new mode on success, NULL on error.
550 struct drm_display_mode
*drm_mode_create(struct drm_device
*dev
)
552 struct drm_display_mode
*nmode
;
554 nmode
= kzalloc(sizeof(struct drm_display_mode
), GFP_KERNEL
);
558 drm_mode_object_get(dev
, &nmode
->base
, DRM_MODE_OBJECT_MODE
);
561 EXPORT_SYMBOL(drm_mode_create
);
564 * drm_mode_destroy - remove a mode
566 * @mode: mode to remove
569 * Caller must hold mode config lock.
571 * Free @mode's unique identifier, then free it.
573 void drm_mode_destroy(struct drm_device
*dev
, struct drm_display_mode
*mode
)
575 drm_mode_object_put(dev
, &mode
->base
);
579 EXPORT_SYMBOL(drm_mode_destroy
);
581 static int drm_mode_create_standard_connector_properties(struct drm_device
*dev
)
583 struct drm_property
*edid
;
584 struct drm_property
*dpms
;
588 * Standard properties (apply to all connectors)
590 edid
= drm_property_create(dev
, DRM_MODE_PROP_BLOB
|
591 DRM_MODE_PROP_IMMUTABLE
,
593 dev
->mode_config
.edid_property
= edid
;
595 dpms
= drm_property_create(dev
, DRM_MODE_PROP_ENUM
,
596 "DPMS", ARRAY_SIZE(drm_dpms_enum_list
));
597 for (i
= 0; i
< ARRAY_SIZE(drm_dpms_enum_list
); i
++)
598 drm_property_add_enum(dpms
, i
, drm_dpms_enum_list
[i
].type
,
599 drm_dpms_enum_list
[i
].name
);
600 dev
->mode_config
.dpms_property
= dpms
;
606 * drm_mode_create_dvi_i_properties - create DVI-I specific connector properties
609 * Called by a driver the first time a DVI-I connector is made.
611 int drm_mode_create_dvi_i_properties(struct drm_device
*dev
)
613 struct drm_property
*dvi_i_selector
;
614 struct drm_property
*dvi_i_subconnector
;
617 if (dev
->mode_config
.dvi_i_select_subconnector_property
)
621 drm_property_create(dev
, DRM_MODE_PROP_ENUM
,
622 "select subconnector",
623 ARRAY_SIZE(drm_dvi_i_select_enum_list
));
624 for (i
= 0; i
< ARRAY_SIZE(drm_dvi_i_select_enum_list
); i
++)
625 drm_property_add_enum(dvi_i_selector
, i
,
626 drm_dvi_i_select_enum_list
[i
].type
,
627 drm_dvi_i_select_enum_list
[i
].name
);
628 dev
->mode_config
.dvi_i_select_subconnector_property
= dvi_i_selector
;
631 drm_property_create(dev
, DRM_MODE_PROP_ENUM
|
632 DRM_MODE_PROP_IMMUTABLE
,
634 ARRAY_SIZE(drm_dvi_i_subconnector_enum_list
));
635 for (i
= 0; i
< ARRAY_SIZE(drm_dvi_i_subconnector_enum_list
); i
++)
636 drm_property_add_enum(dvi_i_subconnector
, i
,
637 drm_dvi_i_subconnector_enum_list
[i
].type
,
638 drm_dvi_i_subconnector_enum_list
[i
].name
);
639 dev
->mode_config
.dvi_i_subconnector_property
= dvi_i_subconnector
;
643 EXPORT_SYMBOL(drm_mode_create_dvi_i_properties
);
646 * drm_create_tv_properties - create TV specific connector properties
648 * @num_modes: number of different TV formats (modes) supported
649 * @modes: array of pointers to strings containing name of each format
651 * Called by a driver's TV initialization routine, this function creates
652 * the TV specific connector properties for a given device. Caller is
653 * responsible for allocating a list of format names and passing them to
656 int drm_mode_create_tv_properties(struct drm_device
*dev
, int num_modes
,
659 struct drm_property
*tv_selector
;
660 struct drm_property
*tv_subconnector
;
663 if (dev
->mode_config
.tv_select_subconnector_property
)
667 * Basic connector properties
669 tv_selector
= drm_property_create(dev
, DRM_MODE_PROP_ENUM
,
670 "select subconnector",
671 ARRAY_SIZE(drm_tv_select_enum_list
));
672 for (i
= 0; i
< ARRAY_SIZE(drm_tv_select_enum_list
); i
++)
673 drm_property_add_enum(tv_selector
, i
,
674 drm_tv_select_enum_list
[i
].type
,
675 drm_tv_select_enum_list
[i
].name
);
676 dev
->mode_config
.tv_select_subconnector_property
= tv_selector
;
679 drm_property_create(dev
, DRM_MODE_PROP_ENUM
|
680 DRM_MODE_PROP_IMMUTABLE
, "subconnector",
681 ARRAY_SIZE(drm_tv_subconnector_enum_list
));
682 for (i
= 0; i
< ARRAY_SIZE(drm_tv_subconnector_enum_list
); i
++)
683 drm_property_add_enum(tv_subconnector
, i
,
684 drm_tv_subconnector_enum_list
[i
].type
,
685 drm_tv_subconnector_enum_list
[i
].name
);
686 dev
->mode_config
.tv_subconnector_property
= tv_subconnector
;
689 * Other, TV specific properties: margins & TV modes.
691 dev
->mode_config
.tv_left_margin_property
=
692 drm_property_create(dev
, DRM_MODE_PROP_RANGE
,
694 dev
->mode_config
.tv_left_margin_property
->values
[0] = 0;
695 dev
->mode_config
.tv_left_margin_property
->values
[1] = 100;
697 dev
->mode_config
.tv_right_margin_property
=
698 drm_property_create(dev
, DRM_MODE_PROP_RANGE
,
700 dev
->mode_config
.tv_right_margin_property
->values
[0] = 0;
701 dev
->mode_config
.tv_right_margin_property
->values
[1] = 100;
703 dev
->mode_config
.tv_top_margin_property
=
704 drm_property_create(dev
, DRM_MODE_PROP_RANGE
,
706 dev
->mode_config
.tv_top_margin_property
->values
[0] = 0;
707 dev
->mode_config
.tv_top_margin_property
->values
[1] = 100;
709 dev
->mode_config
.tv_bottom_margin_property
=
710 drm_property_create(dev
, DRM_MODE_PROP_RANGE
,
712 dev
->mode_config
.tv_bottom_margin_property
->values
[0] = 0;
713 dev
->mode_config
.tv_bottom_margin_property
->values
[1] = 100;
715 dev
->mode_config
.tv_mode_property
=
716 drm_property_create(dev
, DRM_MODE_PROP_ENUM
,
718 for (i
= 0; i
< num_modes
; i
++)
719 drm_property_add_enum(dev
->mode_config
.tv_mode_property
, i
,
722 dev
->mode_config
.tv_brightness_property
=
723 drm_property_create(dev
, DRM_MODE_PROP_RANGE
,
725 dev
->mode_config
.tv_brightness_property
->values
[0] = 0;
726 dev
->mode_config
.tv_brightness_property
->values
[1] = 100;
728 dev
->mode_config
.tv_contrast_property
=
729 drm_property_create(dev
, DRM_MODE_PROP_RANGE
,
731 dev
->mode_config
.tv_contrast_property
->values
[0] = 0;
732 dev
->mode_config
.tv_contrast_property
->values
[1] = 100;
734 dev
->mode_config
.tv_flicker_reduction_property
=
735 drm_property_create(dev
, DRM_MODE_PROP_RANGE
,
736 "flicker reduction", 2);
737 dev
->mode_config
.tv_flicker_reduction_property
->values
[0] = 0;
738 dev
->mode_config
.tv_flicker_reduction_property
->values
[1] = 100;
740 dev
->mode_config
.tv_overscan_property
=
741 drm_property_create(dev
, DRM_MODE_PROP_RANGE
,
743 dev
->mode_config
.tv_overscan_property
->values
[0] = 0;
744 dev
->mode_config
.tv_overscan_property
->values
[1] = 100;
746 dev
->mode_config
.tv_saturation_property
=
747 drm_property_create(dev
, DRM_MODE_PROP_RANGE
,
749 dev
->mode_config
.tv_saturation_property
->values
[0] = 0;
750 dev
->mode_config
.tv_saturation_property
->values
[1] = 100;
752 dev
->mode_config
.tv_hue_property
=
753 drm_property_create(dev
, DRM_MODE_PROP_RANGE
,
755 dev
->mode_config
.tv_hue_property
->values
[0] = 0;
756 dev
->mode_config
.tv_hue_property
->values
[1] = 100;
760 EXPORT_SYMBOL(drm_mode_create_tv_properties
);
763 * drm_mode_create_scaling_mode_property - create scaling mode property
766 * Called by a driver the first time it's needed, must be attached to desired
769 int drm_mode_create_scaling_mode_property(struct drm_device
*dev
)
771 struct drm_property
*scaling_mode
;
774 if (dev
->mode_config
.scaling_mode_property
)
778 drm_property_create(dev
, DRM_MODE_PROP_ENUM
, "scaling mode",
779 ARRAY_SIZE(drm_scaling_mode_enum_list
));
780 for (i
= 0; i
< ARRAY_SIZE(drm_scaling_mode_enum_list
); i
++)
781 drm_property_add_enum(scaling_mode
, i
,
782 drm_scaling_mode_enum_list
[i
].type
,
783 drm_scaling_mode_enum_list
[i
].name
);
785 dev
->mode_config
.scaling_mode_property
= scaling_mode
;
789 EXPORT_SYMBOL(drm_mode_create_scaling_mode_property
);
792 * drm_mode_create_dithering_property - create dithering property
795 * Called by a driver the first time it's needed, must be attached to desired
798 int drm_mode_create_dithering_property(struct drm_device
*dev
)
800 struct drm_property
*dithering_mode
;
803 if (dev
->mode_config
.dithering_mode_property
)
807 drm_property_create(dev
, DRM_MODE_PROP_ENUM
, "dithering",
808 ARRAY_SIZE(drm_dithering_mode_enum_list
));
809 for (i
= 0; i
< ARRAY_SIZE(drm_dithering_mode_enum_list
); i
++)
810 drm_property_add_enum(dithering_mode
, i
,
811 drm_dithering_mode_enum_list
[i
].type
,
812 drm_dithering_mode_enum_list
[i
].name
);
813 dev
->mode_config
.dithering_mode_property
= dithering_mode
;
817 EXPORT_SYMBOL(drm_mode_create_dithering_property
);
819 #if !defined(__AROS__)
821 * drm_mode_create_dirty_property - create dirty property
824 * Called by a driver the first time it's needed, must be attached to desired
827 int drm_mode_create_dirty_info_property(struct drm_device
*dev
)
829 struct drm_property
*dirty_info
;
832 if (dev
->mode_config
.dirty_info_property
)
836 drm_property_create(dev
, DRM_MODE_PROP_ENUM
|
837 DRM_MODE_PROP_IMMUTABLE
,
839 ARRAY_SIZE(drm_dirty_info_enum_list
));
840 for (i
= 0; i
< ARRAY_SIZE(drm_dirty_info_enum_list
); i
++)
841 drm_property_add_enum(dirty_info
, i
,
842 drm_dirty_info_enum_list
[i
].type
,
843 drm_dirty_info_enum_list
[i
].name
);
844 dev
->mode_config
.dirty_info_property
= dirty_info
;
848 EXPORT_SYMBOL(drm_mode_create_dirty_info_property
);
852 * drm_mode_config_init - initialize DRM mode_configuration structure
856 * None, should happen single threaded at init time.
858 * Initialize @dev's mode_config structure, used for tracking the graphics
859 * configuration of @dev.
861 void drm_mode_config_init(struct drm_device
*dev
)
863 mutex_init(&dev
->mode_config
.mutex
);
864 mutex_init(&dev
->mode_config
.idr_mutex
);
865 INIT_LIST_HEAD(&dev
->mode_config
.fb_list
);
866 INIT_LIST_HEAD(&dev
->mode_config
.crtc_list
);
867 INIT_LIST_HEAD(&dev
->mode_config
.connector_list
);
868 INIT_LIST_HEAD(&dev
->mode_config
.encoder_list
);
869 INIT_LIST_HEAD(&dev
->mode_config
.property_list
);
870 INIT_LIST_HEAD(&dev
->mode_config
.property_blob_list
);
871 idr_init(&dev
->mode_config
.crtc_idr
);
873 mutex_lock(&dev
->mode_config
.mutex
);
874 drm_mode_create_standard_connector_properties(dev
);
875 mutex_unlock(&dev
->mode_config
.mutex
);
877 /* Just to be sure */
878 dev
->mode_config
.num_fb
= 0;
879 dev
->mode_config
.num_connector
= 0;
880 dev
->mode_config
.num_crtc
= 0;
881 dev
->mode_config
.num_encoder
= 0;
883 EXPORT_SYMBOL(drm_mode_config_init
);
885 #if !defined(__AROS__)
886 int drm_mode_group_init(struct drm_device
*dev
, struct drm_mode_group
*group
)
888 uint32_t total_objects
= 0;
890 total_objects
+= dev
->mode_config
.num_crtc
;
891 total_objects
+= dev
->mode_config
.num_connector
;
892 total_objects
+= dev
->mode_config
.num_encoder
;
894 group
->id_list
= kzalloc(total_objects
* sizeof(uint32_t), GFP_KERNEL
);
898 group
->num_crtcs
= 0;
899 group
->num_connectors
= 0;
900 group
->num_encoders
= 0;
904 int drm_mode_group_init_legacy_group(struct drm_device
*dev
,
905 struct drm_mode_group
*group
)
907 struct drm_crtc
*crtc
;
908 struct drm_encoder
*encoder
;
909 struct drm_connector
*connector
;
912 if ((ret
= drm_mode_group_init(dev
, group
)))
915 list_for_each_entry(crtc
, &dev
->mode_config
.crtc_list
, head
)
916 group
->id_list
[group
->num_crtcs
++] = crtc
->base
.id
;
918 list_for_each_entry(encoder
, &dev
->mode_config
.encoder_list
, head
)
919 group
->id_list
[group
->num_crtcs
+ group
->num_encoders
++] =
922 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
, head
)
923 group
->id_list
[group
->num_crtcs
+ group
->num_encoders
+
924 group
->num_connectors
++] = connector
->base
.id
;
931 * drm_mode_config_cleanup - free up DRM mode_config info
935 * Caller must hold mode config lock.
937 * Free up all the connectors and CRTCs associated with this DRM device, then
938 * free up the framebuffers and associated buffer objects.
940 * FIXME: cleanup any dangling user buffer objects too
942 void drm_mode_config_cleanup(struct drm_device
*dev
)
944 struct drm_connector
*connector
, *ot
;
945 struct drm_crtc
*crtc
, *ct
;
946 struct drm_encoder
*encoder
, *enct
;
947 struct drm_framebuffer
*fb
, *fbt
;
948 struct drm_property
*property
, *pt
;
950 list_for_each_entry_safe(encoder
, enct
, &dev
->mode_config
.encoder_list
,
952 encoder
->funcs
->destroy(encoder
);
955 list_for_each_entry_safe(connector
, ot
,
956 &dev
->mode_config
.connector_list
, head
) {
957 connector
->funcs
->destroy(connector
);
960 list_for_each_entry_safe(property
, pt
, &dev
->mode_config
.property_list
,
962 drm_property_destroy(dev
, property
);
965 list_for_each_entry_safe(fb
, fbt
, &dev
->mode_config
.fb_list
, head
) {
966 fb
->funcs
->destroy(fb
);
969 list_for_each_entry_safe(crtc
, ct
, &dev
->mode_config
.crtc_list
, head
) {
970 crtc
->funcs
->destroy(crtc
);
974 EXPORT_SYMBOL(drm_mode_config_cleanup
);
977 * drm_crtc_convert_to_umode - convert a drm_display_mode into a modeinfo
978 * @out: drm_mode_modeinfo struct to return to the user
979 * @in: drm_display_mode to use
984 * Convert a drm_display_mode into a drm_mode_modeinfo structure to return to
987 void drm_crtc_convert_to_umode(struct drm_mode_modeinfo
*out
,
988 struct drm_display_mode
*in
)
990 out
->clock
= in
->clock
;
991 out
->hdisplay
= in
->hdisplay
;
992 out
->hsync_start
= in
->hsync_start
;
993 out
->hsync_end
= in
->hsync_end
;
994 out
->htotal
= in
->htotal
;
995 out
->hskew
= in
->hskew
;
996 out
->vdisplay
= in
->vdisplay
;
997 out
->vsync_start
= in
->vsync_start
;
998 out
->vsync_end
= in
->vsync_end
;
999 out
->vtotal
= in
->vtotal
;
1000 out
->vscan
= in
->vscan
;
1001 out
->vrefresh
= in
->vrefresh
;
1002 out
->flags
= in
->flags
;
1003 out
->type
= in
->type
;
1004 strncpy(out
->name
, in
->name
, DRM_DISPLAY_MODE_LEN
);
1005 out
->name
[DRM_DISPLAY_MODE_LEN
-1] = 0;
1009 * drm_crtc_convert_to_umode - convert a modeinfo into a drm_display_mode
1010 * @out: drm_display_mode to return to the user
1011 * @in: drm_mode_modeinfo to use
1016 * Convert a drm_mode_modeinfo into a drm_display_mode structure to return to
1019 void drm_crtc_convert_umode(struct drm_display_mode
*out
,
1020 struct drm_mode_modeinfo
*in
)
1022 out
->clock
= in
->clock
;
1023 out
->hdisplay
= in
->hdisplay
;
1024 out
->hsync_start
= in
->hsync_start
;
1025 out
->hsync_end
= in
->hsync_end
;
1026 out
->htotal
= in
->htotal
;
1027 out
->hskew
= in
->hskew
;
1028 out
->vdisplay
= in
->vdisplay
;
1029 out
->vsync_start
= in
->vsync_start
;
1030 out
->vsync_end
= in
->vsync_end
;
1031 out
->vtotal
= in
->vtotal
;
1032 out
->vscan
= in
->vscan
;
1033 out
->vrefresh
= in
->vrefresh
;
1034 out
->flags
= in
->flags
;
1035 out
->type
= in
->type
;
1036 strncpy(out
->name
, in
->name
, DRM_DISPLAY_MODE_LEN
);
1037 out
->name
[DRM_DISPLAY_MODE_LEN
-1] = 0;
1041 * drm_mode_getresources - get graphics configuration
1042 * @inode: inode from the ioctl
1043 * @filp: file * from the ioctl
1044 * @cmd: cmd from ioctl
1045 * @arg: arg from ioctl
1048 * Takes mode config lock.
1050 * Construct a set of configuration description structures and return
1051 * them to the user, including CRTC, connector and framebuffer configuration.
1053 * Called by the user via ioctl.
1056 * Zero on success, errno on failure.
1058 int drm_mode_getresources(struct drm_device
*dev
, void *data
,
1059 struct drm_file
*file_priv
)
1061 struct drm_mode_card_res
*card_res
= data
;
1062 struct list_head
*lh
;
1063 struct drm_framebuffer
*fb
;
1064 struct drm_connector
*connector
;
1065 struct drm_crtc
*crtc
;
1066 struct drm_encoder
*encoder
;
1068 int connector_count
= 0;
1071 int encoder_count
= 0;
1073 uint32_t __user
*fb_id
;
1074 uint32_t __user
*crtc_id
;
1075 uint32_t __user
*connector_id
;
1076 uint32_t __user
*encoder_id
;
1077 struct drm_mode_group
*mode_group
;
1079 if (!drm_core_check_feature(dev
, DRIVER_MODESET
))
1082 mutex_lock(&dev
->mode_config
.mutex
);
1085 * For the non-control nodes we need to limit the list of resources
1086 * by IDs in the group list for this node
1088 list_for_each(lh
, &file_priv
->fbs
)
1091 #if !defined(__AROS__)
1092 mode_group
= &file_priv
->master
->minor
->mode_group
;
1093 if (file_priv
->master
->minor
->type
== DRM_MINOR_CONTROL
) {
1098 list_for_each(lh
, &dev
->mode_config
.crtc_list
)
1101 list_for_each(lh
, &dev
->mode_config
.connector_list
)
1104 list_for_each(lh
, &dev
->mode_config
.encoder_list
)
1108 crtc_count
= mode_group
->num_crtcs
;
1109 connector_count
= mode_group
->num_connectors
;
1110 encoder_count
= mode_group
->num_encoders
;
1113 card_res
->max_height
= dev
->mode_config
.max_height
;
1114 card_res
->min_height
= dev
->mode_config
.min_height
;
1115 card_res
->max_width
= dev
->mode_config
.max_width
;
1116 card_res
->min_width
= dev
->mode_config
.min_width
;
1118 /* handle this in 4 parts */
1120 if (card_res
->count_fbs
>= fb_count
) {
1122 fb_id
= (uint32_t __user
*)(unsigned long)card_res
->fb_id_ptr
;
1123 list_for_each_entry(fb
, &file_priv
->fbs
, filp_head
) {
1124 if (put_user(fb
->base
.id
, fb_id
+ copied
)) {
1131 card_res
->count_fbs
= fb_count
;
1134 if (card_res
->count_crtcs
>= crtc_count
) {
1136 crtc_id
= (uint32_t __user
*)(unsigned long)card_res
->crtc_id_ptr
;
1137 #if !defined(__AROS__)
1138 if (file_priv
->master
->minor
->type
== DRM_MINOR_CONTROL
) {
1142 list_for_each_entry(crtc
, &dev
->mode_config
.crtc_list
,
1144 DRM_DEBUG_KMS("[CRTC:%d]\n", crtc
->base
.id
);
1145 if (put_user(crtc
->base
.id
, crtc_id
+ copied
)) {
1152 for (i
= 0; i
< mode_group
->num_crtcs
; i
++) {
1153 if (put_user(mode_group
->id_list
[i
],
1154 crtc_id
+ copied
)) {
1162 card_res
->count_crtcs
= crtc_count
;
1165 if (card_res
->count_encoders
>= encoder_count
) {
1167 encoder_id
= (uint32_t __user
*)(unsigned long)card_res
->encoder_id_ptr
;
1168 #if !defined(__AROS__)
1169 if (file_priv
->master
->minor
->type
== DRM_MINOR_CONTROL
) {
1173 list_for_each_entry(encoder
,
1174 &dev
->mode_config
.encoder_list
,
1176 DRM_DEBUG_KMS("[ENCODER:%d:%s]\n", encoder
->base
.id
,
1177 drm_get_encoder_name(encoder
));
1178 if (put_user(encoder
->base
.id
, encoder_id
+
1186 for (i
= mode_group
->num_crtcs
; i
< mode_group
->num_crtcs
+ mode_group
->num_encoders
; i
++) {
1187 if (put_user(mode_group
->id_list
[i
],
1188 encoder_id
+ copied
)) {
1197 card_res
->count_encoders
= encoder_count
;
1200 if (card_res
->count_connectors
>= connector_count
) {
1202 connector_id
= (uint32_t __user
*)(unsigned long)card_res
->connector_id_ptr
;
1203 #if !defined(__AROS__)
1204 if (file_priv
->master
->minor
->type
== DRM_MINOR_CONTROL
) {
1208 list_for_each_entry(connector
,
1209 &dev
->mode_config
.connector_list
,
1211 DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n",
1213 drm_get_connector_name(connector
));
1214 if (put_user(connector
->base
.id
,
1215 connector_id
+ copied
)) {
1222 int start
= mode_group
->num_crtcs
+
1223 mode_group
->num_encoders
;
1224 for (i
= start
; i
< start
+ mode_group
->num_connectors
; i
++) {
1225 if (put_user(mode_group
->id_list
[i
],
1226 connector_id
+ copied
)) {
1234 card_res
->count_connectors
= connector_count
;
1236 DRM_DEBUG_KMS("CRTC[%d] CONNECTORS[%d] ENCODERS[%d]\n", card_res
->count_crtcs
,
1237 card_res
->count_connectors
, card_res
->count_encoders
);
1240 mutex_unlock(&dev
->mode_config
.mutex
);
1245 * drm_mode_getcrtc - get CRTC configuration
1246 * @inode: inode from the ioctl
1247 * @filp: file * from the ioctl
1248 * @cmd: cmd from ioctl
1249 * @arg: arg from ioctl
1254 * Construct a CRTC configuration structure to return to the user.
1256 * Called by the user via ioctl.
1259 * Zero on success, errno on failure.
1261 int drm_mode_getcrtc(struct drm_device
*dev
,
1262 void *data
, struct drm_file
*file_priv
)
1264 struct drm_mode_crtc
*crtc_resp
= data
;
1265 struct drm_crtc
*crtc
;
1266 struct drm_mode_object
*obj
;
1269 if (!drm_core_check_feature(dev
, DRIVER_MODESET
))
1272 mutex_lock(&dev
->mode_config
.mutex
);
1274 obj
= drm_mode_object_find(dev
, crtc_resp
->crtc_id
,
1275 DRM_MODE_OBJECT_CRTC
);
1280 crtc
= obj_to_crtc(obj
);
1282 crtc_resp
->x
= crtc
->x
;
1283 crtc_resp
->y
= crtc
->y
;
1284 crtc_resp
->gamma_size
= crtc
->gamma_size
;
1286 crtc_resp
->fb_id
= crtc
->fb
->base
.id
;
1288 crtc_resp
->fb_id
= 0;
1290 if (crtc
->enabled
) {
1292 drm_crtc_convert_to_umode(&crtc_resp
->mode
, &crtc
->mode
);
1293 crtc_resp
->mode_valid
= 1;
1296 crtc_resp
->mode_valid
= 0;
1300 mutex_unlock(&dev
->mode_config
.mutex
);
1305 * drm_mode_getconnector - get connector configuration
1306 * @inode: inode from the ioctl
1307 * @filp: file * from the ioctl
1308 * @cmd: cmd from ioctl
1309 * @arg: arg from ioctl
1314 * Construct a connector configuration structure to return to the user.
1316 * Called by the user via ioctl.
1319 * Zero on success, errno on failure.
1321 int drm_mode_getconnector(struct drm_device
*dev
, void *data
,
1322 struct drm_file
*file_priv
)
1324 struct drm_mode_get_connector
*out_resp
= data
;
1325 struct drm_mode_object
*obj
;
1326 struct drm_connector
*connector
;
1327 struct drm_display_mode
*mode
;
1329 int props_count
= 0;
1330 int encoders_count
= 0;
1334 struct drm_mode_modeinfo u_mode
;
1335 struct drm_mode_modeinfo __user
*mode_ptr
;
1336 uint32_t __user
*prop_ptr
;
1337 uint64_t __user
*prop_values
;
1338 uint32_t __user
*encoder_ptr
;
1340 if (!drm_core_check_feature(dev
, DRIVER_MODESET
))
1343 memset(&u_mode
, 0, sizeof(struct drm_mode_modeinfo
));
1345 DRM_DEBUG_KMS("[CONNECTOR:%d:?]\n", out_resp
->connector_id
);
1347 mutex_lock(&dev
->mode_config
.mutex
);
1349 obj
= drm_mode_object_find(dev
, out_resp
->connector_id
,
1350 DRM_MODE_OBJECT_CONNECTOR
);
1355 connector
= obj_to_connector(obj
);
1357 for (i
= 0; i
< DRM_CONNECTOR_MAX_PROPERTY
; i
++) {
1358 if (connector
->property_ids
[i
] != 0) {
1363 for (i
= 0; i
< DRM_CONNECTOR_MAX_ENCODER
; i
++) {
1364 if (connector
->encoder_ids
[i
] != 0) {
1369 if (out_resp
->count_modes
== 0) {
1370 connector
->funcs
->fill_modes(connector
,
1371 dev
->mode_config
.max_width
,
1372 dev
->mode_config
.max_height
);
1375 /* delayed so we get modes regardless of pre-fill_modes state */
1376 list_for_each_entry(mode
, &connector
->modes
, head
)
1379 out_resp
->connector_id
= connector
->base
.id
;
1380 out_resp
->connector_type
= connector
->connector_type
;
1381 out_resp
->connector_type_id
= connector
->connector_type_id
;
1382 out_resp
->mm_width
= connector
->display_info
.width_mm
;
1383 out_resp
->mm_height
= connector
->display_info
.height_mm
;
1384 out_resp
->subpixel
= connector
->display_info
.subpixel_order
;
1385 out_resp
->connection
= connector
->status
;
1386 if (connector
->encoder
)
1387 out_resp
->encoder_id
= connector
->encoder
->base
.id
;
1389 out_resp
->encoder_id
= 0;
1392 * This ioctl is called twice, once to determine how much space is
1393 * needed, and the 2nd time to fill it.
1395 if ((out_resp
->count_modes
>= mode_count
) && mode_count
) {
1397 mode_ptr
= (struct drm_mode_modeinfo
*)(unsigned long)out_resp
->modes_ptr
;
1398 list_for_each_entry(mode
, &connector
->modes
, head
) {
1399 drm_crtc_convert_to_umode(&u_mode
, mode
);
1400 if (copy_to_user(mode_ptr
+ copied
,
1401 &u_mode
, sizeof(u_mode
))) {
1408 out_resp
->count_modes
= mode_count
;
1410 if ((out_resp
->count_props
>= props_count
) && props_count
) {
1412 prop_ptr
= (uint32_t *)(unsigned long)(out_resp
->props_ptr
);
1413 prop_values
= (uint64_t *)(unsigned long)(out_resp
->prop_values_ptr
);
1414 for (i
= 0; i
< DRM_CONNECTOR_MAX_PROPERTY
; i
++) {
1415 if (connector
->property_ids
[i
] != 0) {
1416 if (put_user(connector
->property_ids
[i
],
1417 prop_ptr
+ copied
)) {
1422 if (put_user(connector
->property_values
[i
],
1423 prop_values
+ copied
)) {
1431 out_resp
->count_props
= props_count
;
1433 if ((out_resp
->count_encoders
>= encoders_count
) && encoders_count
) {
1435 encoder_ptr
= (uint32_t *)(unsigned long)(out_resp
->encoders_ptr
);
1436 for (i
= 0; i
< DRM_CONNECTOR_MAX_ENCODER
; i
++) {
1437 if (connector
->encoder_ids
[i
] != 0) {
1438 if (put_user(connector
->encoder_ids
[i
],
1439 encoder_ptr
+ copied
)) {
1447 out_resp
->count_encoders
= encoders_count
;
1450 mutex_unlock(&dev
->mode_config
.mutex
);
1454 int drm_mode_getencoder(struct drm_device
*dev
, void *data
,
1455 struct drm_file
*file_priv
)
1457 struct drm_mode_get_encoder
*enc_resp
= data
;
1458 struct drm_mode_object
*obj
;
1459 struct drm_encoder
*encoder
;
1462 if (!drm_core_check_feature(dev
, DRIVER_MODESET
))
1465 mutex_lock(&dev
->mode_config
.mutex
);
1466 obj
= drm_mode_object_find(dev
, enc_resp
->encoder_id
,
1467 DRM_MODE_OBJECT_ENCODER
);
1472 encoder
= obj_to_encoder(obj
);
1475 enc_resp
->crtc_id
= encoder
->crtc
->base
.id
;
1477 enc_resp
->crtc_id
= 0;
1478 enc_resp
->encoder_type
= encoder
->encoder_type
;
1479 enc_resp
->encoder_id
= encoder
->base
.id
;
1480 enc_resp
->possible_crtcs
= encoder
->possible_crtcs
;
1481 enc_resp
->possible_clones
= encoder
->possible_clones
;
1484 mutex_unlock(&dev
->mode_config
.mutex
);
1489 * drm_mode_setcrtc - set CRTC configuration
1490 * @inode: inode from the ioctl
1491 * @filp: file * from the ioctl
1492 * @cmd: cmd from ioctl
1493 * @arg: arg from ioctl
1498 * Build a new CRTC configuration based on user request.
1500 * Called by the user via ioctl.
1503 * Zero on success, errno on failure.
1505 int drm_mode_setcrtc(struct drm_device
*dev
, void *data
,
1506 struct drm_file
*file_priv
)
1508 struct drm_mode_config
*config
= &dev
->mode_config
;
1509 struct drm_mode_crtc
*crtc_req
= data
;
1510 struct drm_mode_object
*obj
;
1511 struct drm_crtc
*crtc
, *crtcfb
;
1512 struct drm_connector
**connector_set
= NULL
, *connector
;
1513 struct drm_framebuffer
*fb
= NULL
;
1514 struct drm_display_mode
*mode
= NULL
;
1515 struct drm_mode_set set
;
1516 uint32_t __user
*set_connectors_ptr
;
1520 if (!drm_core_check_feature(dev
, DRIVER_MODESET
))
1523 mutex_lock(&dev
->mode_config
.mutex
);
1524 obj
= drm_mode_object_find(dev
, crtc_req
->crtc_id
,
1525 DRM_MODE_OBJECT_CRTC
);
1527 DRM_DEBUG_KMS("Unknown CRTC ID %d\n", crtc_req
->crtc_id
);
1531 crtc
= obj_to_crtc(obj
);
1532 DRM_DEBUG_KMS("[CRTC:%d]\n", crtc
->base
.id
);
1534 if (crtc_req
->mode_valid
) {
1535 /* If we have a mode we need a framebuffer. */
1536 /* If we pass -1, set the mode with the currently bound fb */
1537 if (crtc_req
->fb_id
== -1) {
1538 list_for_each_entry(crtcfb
,
1539 &dev
->mode_config
.crtc_list
, head
) {
1540 if (crtcfb
== crtc
) {
1541 DRM_DEBUG_KMS("Using current fb for "
1547 obj
= drm_mode_object_find(dev
, crtc_req
->fb_id
,
1548 DRM_MODE_OBJECT_FB
);
1550 DRM_DEBUG_KMS("Unknown FB ID%d\n",
1555 fb
= obj_to_fb(obj
);
1558 mode
= drm_mode_create(dev
);
1559 drm_crtc_convert_umode(mode
, &crtc_req
->mode
);
1560 drm_mode_set_crtcinfo(mode
, CRTC_INTERLACE_HALVE_V
);
1563 if (crtc_req
->count_connectors
== 0 && mode
) {
1564 DRM_DEBUG_KMS("Count connectors is 0 but mode set\n");
1569 if (crtc_req
->count_connectors
> 0 && (!mode
|| !fb
)) {
1570 DRM_DEBUG_KMS("Count connectors is %d but no mode or fb set\n",
1571 crtc_req
->count_connectors
);
1576 if (crtc_req
->count_connectors
> 0) {
1579 /* Avoid unbounded kernel memory allocation */
1580 if (crtc_req
->count_connectors
> config
->num_connector
) {
1585 connector_set
= kmalloc(crtc_req
->count_connectors
*
1586 sizeof(struct drm_connector
*),
1588 if (!connector_set
) {
1593 for (i
= 0; i
< crtc_req
->count_connectors
; i
++) {
1594 set_connectors_ptr
= (uint32_t *)(unsigned long)crtc_req
->set_connectors_ptr
;
1595 if (get_user(out_id
, &set_connectors_ptr
[i
])) {
1600 obj
= drm_mode_object_find(dev
, out_id
,
1601 DRM_MODE_OBJECT_CONNECTOR
);
1603 DRM_DEBUG_KMS("Connector id %d unknown\n",
1608 connector
= obj_to_connector(obj
);
1609 DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n",
1611 drm_get_connector_name(connector
));
1613 connector_set
[i
] = connector
;
1618 set
.x
= crtc_req
->x
;
1619 set
.y
= crtc_req
->y
;
1621 set
.connectors
= connector_set
;
1622 set
.num_connectors
= crtc_req
->count_connectors
;
1624 ret
= crtc
->funcs
->set_config(&set
);
1627 kfree(connector_set
);
1628 mutex_unlock(&dev
->mode_config
.mutex
);
1632 int drm_mode_cursor_ioctl(struct drm_device
*dev
,
1633 void *data
, struct drm_file
*file_priv
)
1635 struct drm_mode_cursor
*req
= data
;
1636 struct drm_mode_object
*obj
;
1637 struct drm_crtc
*crtc
;
1640 if (!drm_core_check_feature(dev
, DRIVER_MODESET
))
1644 DRM_ERROR("no operation set\n");
1648 mutex_lock(&dev
->mode_config
.mutex
);
1649 obj
= drm_mode_object_find(dev
, req
->crtc_id
, DRM_MODE_OBJECT_CRTC
);
1651 DRM_DEBUG_KMS("Unknown CRTC ID %d\n", req
->crtc_id
);
1655 crtc
= obj_to_crtc(obj
);
1657 if (req
->flags
& DRM_MODE_CURSOR_BO
) {
1658 if (!crtc
->funcs
->cursor_set
) {
1659 DRM_ERROR("crtc does not support cursor\n");
1663 /* Turns off the cursor if handle is 0 */
1664 ret
= crtc
->funcs
->cursor_set(crtc
, file_priv
, req
->handle
,
1665 req
->width
, req
->height
);
1668 if (req
->flags
& DRM_MODE_CURSOR_MOVE
) {
1669 if (crtc
->funcs
->cursor_move
) {
1670 ret
= crtc
->funcs
->cursor_move(crtc
, req
->x
, req
->y
);
1672 DRM_ERROR("crtc does not support cursor\n");
1678 mutex_unlock(&dev
->mode_config
.mutex
);
1683 * drm_mode_addfb - add an FB to the graphics configuration
1684 * @inode: inode from the ioctl
1685 * @filp: file * from the ioctl
1686 * @cmd: cmd from ioctl
1687 * @arg: arg from ioctl
1690 * Takes mode config lock.
1692 * Add a new FB to the specified CRTC, given a user request.
1694 * Called by the user via ioctl.
1697 * Zero on success, errno on failure.
1699 int drm_mode_addfb(struct drm_device
*dev
,
1700 void *data
, struct drm_file
*file_priv
)
1702 struct drm_mode_fb_cmd
*r
= data
;
1703 struct drm_mode_config
*config
= &dev
->mode_config
;
1704 struct drm_framebuffer
*fb
;
1707 if (!drm_core_check_feature(dev
, DRIVER_MODESET
))
1710 if ((config
->min_width
> r
->width
) || (r
->width
> config
->max_width
)) {
1711 DRM_ERROR("mode new framebuffer width not within limits\n");
1714 if ((config
->min_height
> r
->height
) || (r
->height
> config
->max_height
)) {
1715 DRM_ERROR("mode new framebuffer height not within limits\n");
1719 mutex_lock(&dev
->mode_config
.mutex
);
1721 /* TODO check buffer is sufficiently large */
1722 /* TODO setup destructor callback */
1724 fb
= dev
->mode_config
.funcs
->fb_create(dev
, file_priv
, r
);
1726 DRM_ERROR("could not create framebuffer\n");
1731 r
->fb_id
= fb
->base
.id
;
1732 list_add(&fb
->filp_head
, &file_priv
->fbs
);
1733 DRM_DEBUG_KMS("[FB:%d]\n", fb
->base
.id
);
1736 mutex_unlock(&dev
->mode_config
.mutex
);
1741 * drm_mode_rmfb - remove an FB from the configuration
1742 * @inode: inode from the ioctl
1743 * @filp: file * from the ioctl
1744 * @cmd: cmd from ioctl
1745 * @arg: arg from ioctl
1748 * Takes mode config lock.
1750 * Remove the FB specified by the user.
1752 * Called by the user via ioctl.
1755 * Zero on success, errno on failure.
1757 int drm_mode_rmfb(struct drm_device
*dev
,
1758 void *data
, struct drm_file
*file_priv
)
1760 struct drm_mode_object
*obj
;
1761 struct drm_framebuffer
*fb
= NULL
;
1762 struct drm_framebuffer
*fbl
= NULL
;
1763 uint32_t *id
= data
;
1767 if (!drm_core_check_feature(dev
, DRIVER_MODESET
))
1770 mutex_lock(&dev
->mode_config
.mutex
);
1771 obj
= drm_mode_object_find(dev
, *id
, DRM_MODE_OBJECT_FB
);
1772 /* TODO check that we really get a framebuffer back. */
1774 DRM_ERROR("mode invalid framebuffer id\n");
1778 fb
= obj_to_fb(obj
);
1780 list_for_each_entry(fbl
, &file_priv
->fbs
, filp_head
)
1785 DRM_ERROR("tried to remove a fb that we didn't own\n");
1790 /* TODO release all crtc connected to the framebuffer */
1791 /* TODO unhock the destructor from the buffer object */
1793 list_del(&fb
->filp_head
);
1794 fb
->funcs
->destroy(fb
);
1797 mutex_unlock(&dev
->mode_config
.mutex
);
1801 #if !defined(__AROS__)
1803 * drm_mode_getfb - get FB info
1804 * @inode: inode from the ioctl
1805 * @filp: file * from the ioctl
1806 * @cmd: cmd from ioctl
1807 * @arg: arg from ioctl
1812 * Lookup the FB given its ID and return info about it.
1814 * Called by the user via ioctl.
1817 * Zero on success, errno on failure.
1819 int drm_mode_getfb(struct drm_device
*dev
,
1820 void *data
, struct drm_file
*file_priv
)
1822 struct drm_mode_fb_cmd
*r
= data
;
1823 struct drm_mode_object
*obj
;
1824 struct drm_framebuffer
*fb
;
1827 if (!drm_core_check_feature(dev
, DRIVER_MODESET
))
1830 mutex_lock(&dev
->mode_config
.mutex
);
1831 obj
= drm_mode_object_find(dev
, r
->fb_id
, DRM_MODE_OBJECT_FB
);
1833 DRM_ERROR("invalid framebuffer id\n");
1837 fb
= obj_to_fb(obj
);
1839 r
->height
= fb
->height
;
1840 r
->width
= fb
->width
;
1841 r
->depth
= fb
->depth
;
1842 r
->bpp
= fb
->bits_per_pixel
;
1843 r
->pitch
= fb
->pitch
;
1844 fb
->funcs
->create_handle(fb
, file_priv
, &r
->handle
);
1847 mutex_unlock(&dev
->mode_config
.mutex
);
1851 int drm_mode_dirtyfb_ioctl(struct drm_device
*dev
,
1852 void *data
, struct drm_file
*file_priv
)
1854 struct drm_clip_rect __user
*clips_ptr
;
1855 struct drm_clip_rect
*clips
= NULL
;
1856 struct drm_mode_fb_dirty_cmd
*r
= data
;
1857 struct drm_mode_object
*obj
;
1858 struct drm_framebuffer
*fb
;
1863 if (!drm_core_check_feature(dev
, DRIVER_MODESET
))
1866 mutex_lock(&dev
->mode_config
.mutex
);
1867 obj
= drm_mode_object_find(dev
, r
->fb_id
, DRM_MODE_OBJECT_FB
);
1869 DRM_ERROR("invalid framebuffer id\n");
1873 fb
= obj_to_fb(obj
);
1875 num_clips
= r
->num_clips
;
1876 clips_ptr
= (struct drm_clip_rect
*)(unsigned long)r
->clips_ptr
;
1878 if (!num_clips
!= !clips_ptr
) {
1883 flags
= DRM_MODE_FB_DIRTY_FLAGS
& r
->flags
;
1885 /* If userspace annotates copy, clips must come in pairs */
1886 if (flags
& DRM_MODE_FB_DIRTY_ANNOTATE_COPY
&& (num_clips
% 2)) {
1891 if (num_clips
&& clips_ptr
) {
1892 clips
= kzalloc(num_clips
* sizeof(*clips
), GFP_KERNEL
);
1898 ret
= copy_from_user(clips
, clips_ptr
,
1899 num_clips
* sizeof(*clips
));
1906 if (fb
->funcs
->dirty
) {
1907 ret
= fb
->funcs
->dirty(fb
, file_priv
, flags
, r
->color
,
1917 mutex_unlock(&dev
->mode_config
.mutex
);
1923 * drm_fb_release - remove and free the FBs on this file
1924 * @filp: file * from the ioctl
1927 * Takes mode config lock.
1929 * Destroy all the FBs associated with @filp.
1931 * Called by the user via ioctl.
1934 * Zero on success, errno on failure.
1936 void drm_fb_release(struct drm_file
*priv
)
1938 struct drm_device
*dev
= priv
->minor
->dev
;
1939 struct drm_framebuffer
*fb
, *tfb
;
1941 mutex_lock(&dev
->mode_config
.mutex
);
1942 list_for_each_entry_safe(fb
, tfb
, &priv
->fbs
, filp_head
) {
1943 list_del(&fb
->filp_head
);
1944 fb
->funcs
->destroy(fb
);
1946 mutex_unlock(&dev
->mode_config
.mutex
);
1950 * drm_mode_attachmode - add a mode to the user mode list
1952 * @connector: connector to add the mode to
1953 * @mode: mode to add
1955 * Add @mode to @connector's user mode list.
1957 static int drm_mode_attachmode(struct drm_device
*dev
,
1958 struct drm_connector
*connector
,
1959 struct drm_display_mode
*mode
)
1963 list_add_tail(&mode
->head
, &connector
->user_modes
);
1967 int drm_mode_attachmode_crtc(struct drm_device
*dev
, struct drm_crtc
*crtc
,
1968 struct drm_display_mode
*mode
)
1970 struct drm_connector
*connector
;
1972 struct drm_display_mode
*dup_mode
;
1974 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
, head
) {
1975 if (!connector
->encoder
)
1977 if (connector
->encoder
->crtc
== crtc
) {
1979 dup_mode
= drm_mode_duplicate(dev
, mode
);
1982 ret
= drm_mode_attachmode(dev
, connector
, dup_mode
);
1990 EXPORT_SYMBOL(drm_mode_attachmode_crtc
);
1992 static int drm_mode_detachmode(struct drm_device
*dev
,
1993 struct drm_connector
*connector
,
1994 struct drm_display_mode
*mode
)
1998 struct drm_display_mode
*match_mode
, *t
;
2000 list_for_each_entry_safe(match_mode
, t
, &connector
->user_modes
, head
) {
2001 if (drm_mode_equal(match_mode
, mode
)) {
2002 list_del(&match_mode
->head
);
2003 drm_mode_destroy(dev
, match_mode
);
2015 int drm_mode_detachmode_crtc(struct drm_device
*dev
, struct drm_display_mode
*mode
)
2017 struct drm_connector
*connector
;
2019 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
, head
) {
2020 drm_mode_detachmode(dev
, connector
, mode
);
2024 EXPORT_SYMBOL(drm_mode_detachmode_crtc
);
2027 * drm_fb_attachmode - Attach a user mode to an connector
2028 * @inode: inode from the ioctl
2029 * @filp: file * from the ioctl
2030 * @cmd: cmd from ioctl
2031 * @arg: arg from ioctl
2033 * This attaches a user specified mode to an connector.
2034 * Called by the user via ioctl.
2037 * Zero on success, errno on failure.
2039 int drm_mode_attachmode_ioctl(struct drm_device
*dev
,
2040 void *data
, struct drm_file
*file_priv
)
2042 struct drm_mode_mode_cmd
*mode_cmd
= data
;
2043 struct drm_connector
*connector
;
2044 struct drm_display_mode
*mode
;
2045 struct drm_mode_object
*obj
;
2046 struct drm_mode_modeinfo
*umode
= &mode_cmd
->mode
;
2049 if (!drm_core_check_feature(dev
, DRIVER_MODESET
))
2052 mutex_lock(&dev
->mode_config
.mutex
);
2054 obj
= drm_mode_object_find(dev
, mode_cmd
->connector_id
, DRM_MODE_OBJECT_CONNECTOR
);
2059 connector
= obj_to_connector(obj
);
2061 mode
= drm_mode_create(dev
);
2067 drm_crtc_convert_umode(mode
, umode
);
2069 ret
= drm_mode_attachmode(dev
, connector
, mode
);
2071 mutex_unlock(&dev
->mode_config
.mutex
);
2077 * drm_fb_detachmode - Detach a user specified mode from an connector
2078 * @inode: inode from the ioctl
2079 * @filp: file * from the ioctl
2080 * @cmd: cmd from ioctl
2081 * @arg: arg from ioctl
2083 * Called by the user via ioctl.
2086 * Zero on success, errno on failure.
2088 int drm_mode_detachmode_ioctl(struct drm_device
*dev
,
2089 void *data
, struct drm_file
*file_priv
)
2091 struct drm_mode_object
*obj
;
2092 struct drm_mode_mode_cmd
*mode_cmd
= data
;
2093 struct drm_connector
*connector
;
2094 struct drm_display_mode mode
;
2095 struct drm_mode_modeinfo
*umode
= &mode_cmd
->mode
;
2098 if (!drm_core_check_feature(dev
, DRIVER_MODESET
))
2101 mutex_lock(&dev
->mode_config
.mutex
);
2103 obj
= drm_mode_object_find(dev
, mode_cmd
->connector_id
, DRM_MODE_OBJECT_CONNECTOR
);
2108 connector
= obj_to_connector(obj
);
2110 drm_crtc_convert_umode(&mode
, umode
);
2111 ret
= drm_mode_detachmode(dev
, connector
, &mode
);
2113 mutex_unlock(&dev
->mode_config
.mutex
);
2118 struct drm_property
*drm_property_create(struct drm_device
*dev
, int flags
,
2119 const char *name
, int num_values
)
2121 struct drm_property
*property
= NULL
;
2123 property
= kzalloc(sizeof(struct drm_property
), GFP_KERNEL
);
2128 property
->values
= kzalloc(sizeof(uint64_t)*num_values
, GFP_KERNEL
);
2129 if (!property
->values
)
2133 drm_mode_object_get(dev
, &property
->base
, DRM_MODE_OBJECT_PROPERTY
);
2134 property
->flags
= flags
;
2135 property
->num_values
= num_values
;
2136 INIT_LIST_HEAD(&property
->enum_blob_list
);
2139 strncpy(property
->name
, name
, DRM_PROP_NAME_LEN
);
2141 list_add_tail(&property
->head
, &dev
->mode_config
.property_list
);
2147 EXPORT_SYMBOL(drm_property_create
);
2149 int drm_property_add_enum(struct drm_property
*property
, int index
,
2150 uint64_t value
, const char *name
)
2152 struct drm_property_enum
*prop_enum
;
2154 if (!(property
->flags
& DRM_MODE_PROP_ENUM
))
2157 if (!list_empty(&property
->enum_blob_list
)) {
2158 list_for_each_entry(prop_enum
, &property
->enum_blob_list
, head
) {
2159 if (prop_enum
->value
== value
) {
2160 strncpy(prop_enum
->name
, name
, DRM_PROP_NAME_LEN
);
2161 prop_enum
->name
[DRM_PROP_NAME_LEN
-1] = '\0';
2167 prop_enum
= kzalloc(sizeof(struct drm_property_enum
), GFP_KERNEL
);
2171 strncpy(prop_enum
->name
, name
, DRM_PROP_NAME_LEN
);
2172 prop_enum
->name
[DRM_PROP_NAME_LEN
-1] = '\0';
2173 prop_enum
->value
= value
;
2175 property
->values
[index
] = value
;
2176 list_add_tail(&prop_enum
->head
, &property
->enum_blob_list
);
2179 EXPORT_SYMBOL(drm_property_add_enum
);
2181 void drm_property_destroy(struct drm_device
*dev
, struct drm_property
*property
)
2183 struct drm_property_enum
*prop_enum
, *pt
;
2185 list_for_each_entry_safe(prop_enum
, pt
, &property
->enum_blob_list
, head
) {
2186 list_del(&prop_enum
->head
);
2190 if (property
->num_values
)
2191 kfree(property
->values
);
2192 drm_mode_object_put(dev
, &property
->base
);
2193 list_del(&property
->head
);
2196 EXPORT_SYMBOL(drm_property_destroy
);
2198 int drm_connector_attach_property(struct drm_connector
*connector
,
2199 struct drm_property
*property
, uint64_t init_val
)
2203 for (i
= 0; i
< DRM_CONNECTOR_MAX_PROPERTY
; i
++) {
2204 if (connector
->property_ids
[i
] == 0) {
2205 connector
->property_ids
[i
] = property
->base
.id
;
2206 connector
->property_values
[i
] = init_val
;
2211 if (i
== DRM_CONNECTOR_MAX_PROPERTY
)
2215 EXPORT_SYMBOL(drm_connector_attach_property
);
2217 int drm_connector_property_set_value(struct drm_connector
*connector
,
2218 struct drm_property
*property
, uint64_t value
)
2222 for (i
= 0; i
< DRM_CONNECTOR_MAX_PROPERTY
; i
++) {
2223 if (connector
->property_ids
[i
] == property
->base
.id
) {
2224 connector
->property_values
[i
] = value
;
2229 if (i
== DRM_CONNECTOR_MAX_PROPERTY
)
2233 EXPORT_SYMBOL(drm_connector_property_set_value
);
2235 #if !defined(__AROS__)
2236 int drm_connector_property_get_value(struct drm_connector
*connector
,
2237 struct drm_property
*property
, uint64_t *val
)
2241 for (i
= 0; i
< DRM_CONNECTOR_MAX_PROPERTY
; i
++) {
2242 if (connector
->property_ids
[i
] == property
->base
.id
) {
2243 *val
= connector
->property_values
[i
];
2248 if (i
== DRM_CONNECTOR_MAX_PROPERTY
)
2252 EXPORT_SYMBOL(drm_connector_property_get_value
);
2254 int drm_mode_getproperty_ioctl(struct drm_device
*dev
,
2255 void *data
, struct drm_file
*file_priv
)
2257 struct drm_mode_object
*obj
;
2258 struct drm_mode_get_property
*out_resp
= data
;
2259 struct drm_property
*property
;
2262 int value_count
= 0;
2265 struct drm_property_enum
*prop_enum
;
2266 struct drm_mode_property_enum __user
*enum_ptr
;
2267 struct drm_property_blob
*prop_blob
;
2268 uint32_t *blob_id_ptr
;
2269 uint64_t __user
*values_ptr
;
2270 uint32_t __user
*blob_length_ptr
;
2272 if (!drm_core_check_feature(dev
, DRIVER_MODESET
))
2275 mutex_lock(&dev
->mode_config
.mutex
);
2276 obj
= drm_mode_object_find(dev
, out_resp
->prop_id
, DRM_MODE_OBJECT_PROPERTY
);
2281 property
= obj_to_property(obj
);
2283 if (property
->flags
& DRM_MODE_PROP_ENUM
) {
2284 list_for_each_entry(prop_enum
, &property
->enum_blob_list
, head
)
2286 } else if (property
->flags
& DRM_MODE_PROP_BLOB
) {
2287 list_for_each_entry(prop_blob
, &property
->enum_blob_list
, head
)
2291 value_count
= property
->num_values
;
2293 strncpy(out_resp
->name
, property
->name
, DRM_PROP_NAME_LEN
);
2294 out_resp
->name
[DRM_PROP_NAME_LEN
-1] = 0;
2295 out_resp
->flags
= property
->flags
;
2297 if ((out_resp
->count_values
>= value_count
) && value_count
) {
2298 values_ptr
= (uint64_t *)(unsigned long)out_resp
->values_ptr
;
2299 for (i
= 0; i
< value_count
; i
++) {
2300 if (copy_to_user(values_ptr
+ i
, &property
->values
[i
], sizeof(uint64_t))) {
2306 out_resp
->count_values
= value_count
;
2308 if (property
->flags
& DRM_MODE_PROP_ENUM
) {
2309 if ((out_resp
->count_enum_blobs
>= enum_count
) && enum_count
) {
2311 enum_ptr
= (struct drm_mode_property_enum
*)(unsigned long)out_resp
->enum_blob_ptr
;
2312 list_for_each_entry(prop_enum
, &property
->enum_blob_list
, head
) {
2314 if (copy_to_user(&enum_ptr
[copied
].value
, &prop_enum
->value
, sizeof(uint64_t))) {
2319 if (copy_to_user(&enum_ptr
[copied
].name
,
2320 &prop_enum
->name
, DRM_PROP_NAME_LEN
)) {
2327 out_resp
->count_enum_blobs
= enum_count
;
2330 if (property
->flags
& DRM_MODE_PROP_BLOB
) {
2331 if ((out_resp
->count_enum_blobs
>= blob_count
) && blob_count
) {
2333 blob_id_ptr
= (uint32_t *)(unsigned long)out_resp
->enum_blob_ptr
;
2334 blob_length_ptr
= (uint32_t *)(unsigned long)out_resp
->values_ptr
;
2336 list_for_each_entry(prop_blob
, &property
->enum_blob_list
, head
) {
2337 if (put_user(prop_blob
->base
.id
, blob_id_ptr
+ copied
)) {
2342 if (put_user(prop_blob
->length
, blob_length_ptr
+ copied
)) {
2350 out_resp
->count_enum_blobs
= blob_count
;
2353 mutex_unlock(&dev
->mode_config
.mutex
);
2358 static struct drm_property_blob
*drm_property_create_blob(struct drm_device
*dev
, int length
,
2361 struct drm_property_blob
*blob
;
2363 if (!length
|| !data
)
2366 blob
= kzalloc(sizeof(struct drm_property_blob
)+length
, GFP_KERNEL
);
2370 blob
->data
= (void *)((char *)blob
+ sizeof(struct drm_property_blob
));
2371 blob
->length
= length
;
2373 memcpy(blob
->data
, data
, length
);
2375 drm_mode_object_get(dev
, &blob
->base
, DRM_MODE_OBJECT_BLOB
);
2377 list_add_tail(&blob
->head
, &dev
->mode_config
.property_blob_list
);
2381 static void drm_property_destroy_blob(struct drm_device
*dev
,
2382 struct drm_property_blob
*blob
)
2384 drm_mode_object_put(dev
, &blob
->base
);
2385 list_del(&blob
->head
);
2389 #if !defined(__AROS__)
2390 int drm_mode_getblob_ioctl(struct drm_device
*dev
,
2391 void *data
, struct drm_file
*file_priv
)
2393 struct drm_mode_object
*obj
;
2394 struct drm_mode_get_blob
*out_resp
= data
;
2395 struct drm_property_blob
*blob
;
2399 if (!drm_core_check_feature(dev
, DRIVER_MODESET
))
2402 mutex_lock(&dev
->mode_config
.mutex
);
2403 obj
= drm_mode_object_find(dev
, out_resp
->blob_id
, DRM_MODE_OBJECT_BLOB
);
2408 blob
= obj_to_blob(obj
);
2410 if (out_resp
->length
== blob
->length
) {
2411 blob_ptr
= (void *)(unsigned long)out_resp
->data
;
2412 if (copy_to_user(blob_ptr
, blob
->data
, blob
->length
)){
2417 out_resp
->length
= blob
->length
;
2420 mutex_unlock(&dev
->mode_config
.mutex
);
2425 int drm_mode_connector_update_edid_property(struct drm_connector
*connector
,
2428 struct drm_device
*dev
= connector
->dev
;
2431 if (connector
->edid_blob_ptr
)
2432 drm_property_destroy_blob(dev
, connector
->edid_blob_ptr
);
2434 /* Delete edid, when there is none. */
2436 connector
->edid_blob_ptr
= NULL
;
2437 ret
= drm_connector_property_set_value(connector
, dev
->mode_config
.edid_property
, 0);
2441 size
= EDID_LENGTH
* (1 + edid
->extensions
);
2442 connector
->edid_blob_ptr
= drm_property_create_blob(connector
->dev
,
2445 ret
= drm_connector_property_set_value(connector
,
2446 dev
->mode_config
.edid_property
,
2447 connector
->edid_blob_ptr
->base
.id
);
2451 EXPORT_SYMBOL(drm_mode_connector_update_edid_property
);
2453 #if !defined(__AROS__)
2454 int drm_mode_connector_property_set_ioctl(struct drm_device
*dev
,
2455 void *data
, struct drm_file
*file_priv
)
2457 struct drm_mode_connector_set_property
*out_resp
= data
;
2458 struct drm_mode_object
*obj
;
2459 struct drm_property
*property
;
2460 struct drm_connector
*connector
;
2464 if (!drm_core_check_feature(dev
, DRIVER_MODESET
))
2467 mutex_lock(&dev
->mode_config
.mutex
);
2469 obj
= drm_mode_object_find(dev
, out_resp
->connector_id
, DRM_MODE_OBJECT_CONNECTOR
);
2473 connector
= obj_to_connector(obj
);
2475 for (i
= 0; i
< DRM_CONNECTOR_MAX_PROPERTY
; i
++) {
2476 if (connector
->property_ids
[i
] == out_resp
->prop_id
)
2480 if (i
== DRM_CONNECTOR_MAX_PROPERTY
) {
2484 obj
= drm_mode_object_find(dev
, out_resp
->prop_id
, DRM_MODE_OBJECT_PROPERTY
);
2488 property
= obj_to_property(obj
);
2490 if (property
->flags
& DRM_MODE_PROP_IMMUTABLE
)
2493 if (property
->flags
& DRM_MODE_PROP_RANGE
) {
2494 if (out_resp
->value
< property
->values
[0])
2497 if (out_resp
->value
> property
->values
[1])
2501 for (i
= 0; i
< property
->num_values
; i
++) {
2502 if (property
->values
[i
] == out_resp
->value
) {
2512 /* Do DPMS ourselves */
2513 if (property
== connector
->dev
->mode_config
.dpms_property
) {
2514 if (connector
->funcs
->dpms
)
2515 (*connector
->funcs
->dpms
)(connector
, (int) out_resp
->value
);
2517 } else if (connector
->funcs
->set_property
)
2518 ret
= connector
->funcs
->set_property(connector
, property
, out_resp
->value
);
2520 /* store the property value if successful */
2522 drm_connector_property_set_value(connector
, property
, out_resp
->value
);
2524 mutex_unlock(&dev
->mode_config
.mutex
);
2529 int drm_mode_connector_attach_encoder(struct drm_connector
*connector
,
2530 struct drm_encoder
*encoder
)
2534 for (i
= 0; i
< DRM_CONNECTOR_MAX_ENCODER
; i
++) {
2535 if (connector
->encoder_ids
[i
] == 0) {
2536 connector
->encoder_ids
[i
] = encoder
->base
.id
;
2542 EXPORT_SYMBOL(drm_mode_connector_attach_encoder
);
2544 #if !defined(__AROS__)
2545 void drm_mode_connector_detach_encoder(struct drm_connector
*connector
,
2546 struct drm_encoder
*encoder
)
2549 for (i
= 0; i
< DRM_CONNECTOR_MAX_ENCODER
; i
++) {
2550 if (connector
->encoder_ids
[i
] == encoder
->base
.id
) {
2551 connector
->encoder_ids
[i
] = 0;
2552 if (connector
->encoder
== encoder
)
2553 connector
->encoder
= NULL
;
2558 EXPORT_SYMBOL(drm_mode_connector_detach_encoder
);
2561 bool drm_mode_crtc_set_gamma_size(struct drm_crtc
*crtc
,
2564 crtc
->gamma_size
= gamma_size
;
2566 crtc
->gamma_store
= kzalloc(gamma_size
* sizeof(uint16_t) * 3, GFP_KERNEL
);
2567 if (!crtc
->gamma_store
) {
2568 crtc
->gamma_size
= 0;
2574 EXPORT_SYMBOL(drm_mode_crtc_set_gamma_size
);
2576 #if !defined(__AROS__)
2577 int drm_mode_gamma_set_ioctl(struct drm_device
*dev
,
2578 void *data
, struct drm_file
*file_priv
)
2580 struct drm_mode_crtc_lut
*crtc_lut
= data
;
2581 struct drm_mode_object
*obj
;
2582 struct drm_crtc
*crtc
;
2583 void *r_base
, *g_base
, *b_base
;
2587 if (!drm_core_check_feature(dev
, DRIVER_MODESET
))
2590 mutex_lock(&dev
->mode_config
.mutex
);
2591 obj
= drm_mode_object_find(dev
, crtc_lut
->crtc_id
, DRM_MODE_OBJECT_CRTC
);
2596 crtc
= obj_to_crtc(obj
);
2598 /* memcpy into gamma store */
2599 if (crtc_lut
->gamma_size
!= crtc
->gamma_size
) {
2604 size
= crtc_lut
->gamma_size
* (sizeof(uint16_t));
2605 r_base
= crtc
->gamma_store
;
2606 if (copy_from_user(r_base
, (void __user
*)(unsigned long)crtc_lut
->red
, size
)) {
2611 g_base
= r_base
+ size
;
2612 if (copy_from_user(g_base
, (void __user
*)(unsigned long)crtc_lut
->green
, size
)) {
2617 b_base
= g_base
+ size
;
2618 if (copy_from_user(b_base
, (void __user
*)(unsigned long)crtc_lut
->blue
, size
)) {
2623 crtc
->funcs
->gamma_set(crtc
, r_base
, g_base
, b_base
, 0, crtc
->gamma_size
);
2626 mutex_unlock(&dev
->mode_config
.mutex
);
2631 int drm_mode_gamma_get_ioctl(struct drm_device
*dev
,
2632 void *data
, struct drm_file
*file_priv
)
2634 struct drm_mode_crtc_lut
*crtc_lut
= data
;
2635 struct drm_mode_object
*obj
;
2636 struct drm_crtc
*crtc
;
2637 void *r_base
, *g_base
, *b_base
;
2641 if (!drm_core_check_feature(dev
, DRIVER_MODESET
))
2644 mutex_lock(&dev
->mode_config
.mutex
);
2645 obj
= drm_mode_object_find(dev
, crtc_lut
->crtc_id
, DRM_MODE_OBJECT_CRTC
);
2650 crtc
= obj_to_crtc(obj
);
2652 /* memcpy into gamma store */
2653 if (crtc_lut
->gamma_size
!= crtc
->gamma_size
) {
2658 size
= crtc_lut
->gamma_size
* (sizeof(uint16_t));
2659 r_base
= crtc
->gamma_store
;
2660 if (copy_to_user((void __user
*)(unsigned long)crtc_lut
->red
, r_base
, size
)) {
2665 g_base
= r_base
+ size
;
2666 if (copy_to_user((void __user
*)(unsigned long)crtc_lut
->green
, g_base
, size
)) {
2671 b_base
= g_base
+ size
;
2672 if (copy_to_user((void __user
*)(unsigned long)crtc_lut
->blue
, b_base
, size
)) {
2677 mutex_unlock(&dev
->mode_config
.mutex
);
2681 int drm_mode_page_flip_ioctl(struct drm_device
*dev
,
2682 void *data
, struct drm_file
*file_priv
)
2684 struct drm_mode_crtc_page_flip
*page_flip
= data
;
2685 struct drm_mode_object
*obj
;
2686 struct drm_crtc
*crtc
;
2687 struct drm_framebuffer
*fb
;
2688 struct drm_pending_vblank_event
*e
= NULL
;
2689 unsigned long flags
;
2692 if (page_flip
->flags
& ~DRM_MODE_PAGE_FLIP_FLAGS
||
2693 page_flip
->reserved
!= 0)
2696 mutex_lock(&dev
->mode_config
.mutex
);
2697 obj
= drm_mode_object_find(dev
, page_flip
->crtc_id
, DRM_MODE_OBJECT_CRTC
);
2700 crtc
= obj_to_crtc(obj
);
2702 if (crtc
->fb
== NULL
) {
2703 /* The framebuffer is currently unbound, presumably
2704 * due to a hotplug event, that userspace has not
2711 if (crtc
->funcs
->page_flip
== NULL
)
2714 obj
= drm_mode_object_find(dev
, page_flip
->fb_id
, DRM_MODE_OBJECT_FB
);
2717 fb
= obj_to_fb(obj
);
2719 if (page_flip
->flags
& DRM_MODE_PAGE_FLIP_EVENT
) {
2721 spin_lock_irqsave(&dev
->event_lock
, flags
);
2722 if (file_priv
->event_space
< sizeof e
->event
) {
2723 spin_unlock_irqrestore(&dev
->event_lock
, flags
);
2726 file_priv
->event_space
-= sizeof e
->event
;
2727 spin_unlock_irqrestore(&dev
->event_lock
, flags
);
2729 e
= kzalloc(sizeof *e
, GFP_KERNEL
);
2731 spin_lock_irqsave(&dev
->event_lock
, flags
);
2732 file_priv
->event_space
+= sizeof e
->event
;
2733 spin_unlock_irqrestore(&dev
->event_lock
, flags
);
2737 e
->event
.base
.type
= DRM_EVENT_FLIP_COMPLETE
;
2738 e
->event
.base
.length
= sizeof e
->event
;
2739 e
->event
.user_data
= page_flip
->user_data
;
2740 e
->base
.event
= &e
->event
.base
;
2741 e
->base
.file_priv
= file_priv
;
2743 (void (*) (struct drm_pending_event
*)) kfree
;
2746 ret
= crtc
->funcs
->page_flip(crtc
, fb
, e
);
2748 spin_lock_irqsave(&dev
->event_lock
, flags
);
2749 file_priv
->event_space
+= sizeof e
->event
;
2750 spin_unlock_irqrestore(&dev
->event_lock
, flags
);
2755 mutex_unlock(&dev
->mode_config
.mutex
);
2759 void drm_mode_config_reset(struct drm_device
*dev
)
2761 struct drm_crtc
*crtc
;
2762 struct drm_encoder
*encoder
;
2763 struct drm_connector
*connector
;
2765 list_for_each_entry(crtc
, &dev
->mode_config
.crtc_list
, head
)
2766 if (crtc
->funcs
->reset
)
2767 crtc
->funcs
->reset(crtc
);
2769 list_for_each_entry(encoder
, &dev
->mode_config
.encoder_list
, head
)
2770 if (encoder
->funcs
->reset
)
2771 encoder
->funcs
->reset(encoder
);
2773 list_for_each_entry(connector
, &dev
->mode_config
.connector_list
, head
)
2774 if (connector
->funcs
->reset
)
2775 connector
->funcs
->reset(connector
);
2777 EXPORT_SYMBOL(drm_mode_config_reset
);
2779 int drm_mode_create_dumb_ioctl(struct drm_device
*dev
,
2780 void *data
, struct drm_file
*file_priv
)
2782 struct drm_mode_create_dumb
*args
= data
;
2784 if (!dev
->driver
->dumb_create
)
2786 return dev
->driver
->dumb_create(file_priv
, dev
, args
);
2789 int drm_mode_mmap_dumb_ioctl(struct drm_device
*dev
,
2790 void *data
, struct drm_file
*file_priv
)
2792 struct drm_mode_map_dumb
*args
= data
;
2794 /* call driver ioctl to get mmap offset */
2795 if (!dev
->driver
->dumb_map_offset
)
2798 return dev
->driver
->dumb_map_offset(file_priv
, dev
, args
->handle
, &args
->offset
);
2801 int drm_mode_destroy_dumb_ioctl(struct drm_device
*dev
,
2802 void *data
, struct drm_file
*file_priv
)
2804 struct drm_mode_destroy_dumb
*args
= data
;
2806 if (!dev
->driver
->dumb_destroy
)
2809 return dev
->driver
->dumb_destroy(file_priv
, dev
, args
->handle
);