2 * Copyright (c) 2016 Intel Corporation
4 * Permission to use, copy, modify, distribute, and sell this software and its
5 * documentation for any purpose is hereby granted without fee, provided that
6 * the above copyright notice appear in all copies and that both that copyright
7 * notice and this permission notice appear in supporting documentation, and
8 * that the name of the copyright holders not be used in advertising or
9 * publicity pertaining to distribution of the software without specific,
10 * written prior permission. The copyright holders make no representations
11 * about the suitability of this software for any purpose. It is provided "as
12 * is" without express or implied warranty.
14 * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
15 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
16 * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
17 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
18 * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
19 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
24 #include <drm/drm_connector.h>
25 #include <drm/drm_edid.h>
26 #include <drm/drm_encoder.h>
27 #include <drm/drm_utils.h>
29 #include "drm_crtc_internal.h"
30 #include "drm_internal.h"
35 * In DRM connectors are the general abstraction for display sinks, and include
36 * als fixed panels or anything else that can display pixels in some form. As
37 * opposed to all other KMS objects representing hardware (like CRTC, encoder or
38 * plane abstractions) connectors can be hotplugged and unplugged at runtime.
39 * Hence they are reference-counted using drm_connector_get() and
40 * drm_connector_put().
42 * KMS driver must create, initialize, register and attach at a &struct
43 * drm_connector for each such sink. The instance is created as other KMS
44 * objects and initialized by setting the following fields. The connector is
45 * initialized with a call to drm_connector_init() with a pointer to the
46 * &struct drm_connector_funcs and a connector type, and then exposed to
47 * userspace with a call to drm_connector_register().
49 * Connectors must be attached to an encoder to be used. For devices that map
50 * connectors to encoders 1:1, the connector should be attached at
51 * initialization time with a call to drm_mode_connector_attach_encoder(). The
52 * driver must also set the &drm_connector.encoder field to point to the
55 * For connectors which are not fixed (like built-in panels) the driver needs to
56 * support hotplug notifications. The simplest way to do that is by using the
57 * probe helpers, see drm_kms_helper_poll_init() for connectors which don't have
58 * hardware support for hotplug interrupts. Connectors with hardware hotplug
59 * support can instead use e.g. drm_helper_hpd_irq_event().
62 struct drm_conn_prop_enum_list
{
69 * Connector and encoder types.
71 static struct drm_conn_prop_enum_list drm_connector_enum_list
[] = {
72 { DRM_MODE_CONNECTOR_Unknown
, "Unknown" },
73 { DRM_MODE_CONNECTOR_VGA
, "VGA" },
74 { DRM_MODE_CONNECTOR_DVII
, "DVI-I" },
75 { DRM_MODE_CONNECTOR_DVID
, "DVI-D" },
76 { DRM_MODE_CONNECTOR_DVIA
, "DVI-A" },
77 { DRM_MODE_CONNECTOR_Composite
, "Composite" },
78 { DRM_MODE_CONNECTOR_SVIDEO
, "SVIDEO" },
79 { DRM_MODE_CONNECTOR_LVDS
, "LVDS" },
80 { DRM_MODE_CONNECTOR_Component
, "Component" },
81 { DRM_MODE_CONNECTOR_9PinDIN
, "DIN" },
82 { DRM_MODE_CONNECTOR_DisplayPort
, "DP" },
83 { DRM_MODE_CONNECTOR_HDMIA
, "HDMI-A" },
84 { DRM_MODE_CONNECTOR_HDMIB
, "HDMI-B" },
85 { DRM_MODE_CONNECTOR_TV
, "TV" },
86 { DRM_MODE_CONNECTOR_eDP
, "eDP" },
87 { DRM_MODE_CONNECTOR_VIRTUAL
, "Virtual" },
88 { DRM_MODE_CONNECTOR_DSI
, "DSI" },
89 { DRM_MODE_CONNECTOR_DPI
, "DPI" },
92 void drm_connector_ida_init(void)
96 for (i
= 0; i
< ARRAY_SIZE(drm_connector_enum_list
); i
++)
97 ida_init(&drm_connector_enum_list
[i
].ida
);
100 void drm_connector_ida_destroy(void)
104 for (i
= 0; i
< ARRAY_SIZE(drm_connector_enum_list
); i
++)
105 ida_destroy(&drm_connector_enum_list
[i
].ida
);
109 * drm_connector_get_cmdline_mode - reads the user's cmdline mode
110 * @connector: connector to quwery
112 * The kernel supports per-connector configuration of its consoles through
113 * use of the video= parameter. This function parses that option and
114 * extracts the user's specified mode (or enable/disable status) for a
115 * particular connector. This is typically only used during the early fbdev
118 static void drm_connector_get_cmdline_mode(struct drm_connector
*connector
)
120 struct drm_cmdline_mode
*mode
= &connector
->cmdline_mode
;
123 if (fb_get_options(connector
->name
, &option
))
126 if (!drm_mode_parse_command_line_for_connector(option
,
132 DRM_INFO("forcing %s connector %s\n", connector
->name
,
133 drm_get_connector_force_name(mode
->force
));
134 connector
->force
= mode
->force
;
137 DRM_DEBUG_KMS("cmdline mode for connector %s %dx%d@%dHz%s%s%s\n",
139 mode
->xres
, mode
->yres
,
140 mode
->refresh_specified
? mode
->refresh
: 60,
141 mode
->rb
? " reduced blanking" : "",
142 mode
->margins
? " with margins" : "",
143 mode
->interlace
? " interlaced" : "");
146 static void drm_connector_free(struct kref
*kref
)
148 struct drm_connector
*connector
=
149 container_of(kref
, struct drm_connector
, base
.refcount
);
150 struct drm_device
*dev
= connector
->dev
;
152 drm_mode_object_unregister(dev
, &connector
->base
);
153 connector
->funcs
->destroy(connector
);
156 void drm_connector_free_work_fn(struct work_struct
*work
)
158 struct drm_connector
*connector
, *n
;
159 struct drm_device
*dev
=
160 container_of(work
, struct drm_device
, mode_config
.connector_free_work
);
161 struct drm_mode_config
*config
= &dev
->mode_config
;
163 struct llist_node
*freed
;
165 spin_lock_irqsave(&config
->connector_list_lock
, flags
);
166 freed
= llist_del_all(&config
->connector_free_list
);
167 spin_unlock_irqrestore(&config
->connector_list_lock
, flags
);
169 llist_for_each_entry_safe(connector
, n
, freed
, free_node
) {
170 drm_mode_object_unregister(dev
, &connector
->base
);
171 connector
->funcs
->destroy(connector
);
176 * drm_connector_init - Init a preallocated connector
178 * @connector: the connector to init
179 * @funcs: callbacks for this connector
180 * @connector_type: user visible type of the connector
182 * Initialises a preallocated connector. Connectors should be
183 * subclassed as part of driver connector objects.
186 * Zero on success, error code on failure.
188 int drm_connector_init(struct drm_device
*dev
,
189 struct drm_connector
*connector
,
190 const struct drm_connector_funcs
*funcs
,
193 struct drm_mode_config
*config
= &dev
->mode_config
;
195 struct ida
*connector_ida
=
196 &drm_connector_enum_list
[connector_type
].ida
;
198 ret
= __drm_mode_object_add(dev
, &connector
->base
,
199 DRM_MODE_OBJECT_CONNECTOR
,
200 false, drm_connector_free
);
204 connector
->base
.properties
= &connector
->properties
;
205 connector
->dev
= dev
;
206 connector
->funcs
= funcs
;
208 ret
= ida_simple_get(&config
->connector_ida
, 0, 0, GFP_KERNEL
);
211 connector
->index
= ret
;
214 connector
->connector_type
= connector_type
;
215 connector
->connector_type_id
=
216 ida_simple_get(connector_ida
, 1, 0, GFP_KERNEL
);
217 if (connector
->connector_type_id
< 0) {
218 ret
= connector
->connector_type_id
;
222 kasprintf(GFP_KERNEL
, "%s-%d",
223 drm_connector_enum_list
[connector_type
].name
,
224 connector
->connector_type_id
);
225 if (!connector
->name
) {
227 goto out_put_type_id
;
230 INIT_LIST_HEAD(&connector
->probed_modes
);
231 INIT_LIST_HEAD(&connector
->modes
);
232 mutex_init(&connector
->mutex
);
233 connector
->edid_blob_ptr
= NULL
;
234 connector
->status
= connector_status_unknown
;
235 connector
->display_info
.panel_orientation
=
236 DRM_MODE_PANEL_ORIENTATION_UNKNOWN
;
238 drm_connector_get_cmdline_mode(connector
);
240 /* We should add connectors at the end to avoid upsetting the connector
242 spin_lock_irq(&config
->connector_list_lock
);
243 list_add_tail(&connector
->head
, &config
->connector_list
);
244 config
->num_connector
++;
245 spin_unlock_irq(&config
->connector_list_lock
);
247 if (connector_type
!= DRM_MODE_CONNECTOR_VIRTUAL
)
248 drm_object_attach_property(&connector
->base
,
249 config
->edid_property
,
252 drm_object_attach_property(&connector
->base
,
253 config
->dpms_property
, 0);
255 drm_object_attach_property(&connector
->base
,
256 config
->link_status_property
,
259 drm_object_attach_property(&connector
->base
,
260 config
->non_desktop_property
,
263 if (drm_core_check_feature(dev
, DRIVER_ATOMIC
)) {
264 drm_object_attach_property(&connector
->base
, config
->prop_crtc_id
, 0);
267 connector
->debugfs_entry
= NULL
;
270 ida_simple_remove(connector_ida
, connector
->connector_type_id
);
273 ida_simple_remove(&config
->connector_ida
, connector
->index
);
276 drm_mode_object_unregister(dev
, &connector
->base
);
280 EXPORT_SYMBOL(drm_connector_init
);
283 * drm_mode_connector_attach_encoder - attach a connector to an encoder
284 * @connector: connector to attach
285 * @encoder: encoder to attach @connector to
287 * This function links up a connector to an encoder. Note that the routing
288 * restrictions between encoders and crtcs are exposed to userspace through the
289 * possible_clones and possible_crtcs bitmasks.
292 * Zero on success, negative errno on failure.
294 int drm_mode_connector_attach_encoder(struct drm_connector
*connector
,
295 struct drm_encoder
*encoder
)
300 * In the past, drivers have attempted to model the static association
301 * of connector to encoder in simple connector/encoder devices using a
302 * direct assignment of connector->encoder = encoder. This connection
303 * is a logical one and the responsibility of the core, so drivers are
304 * expected not to mess with this.
306 * Note that the error return should've been enough here, but a large
307 * majority of drivers ignores the return value, so add in a big WARN
308 * to get people's attention.
310 if (WARN_ON(connector
->encoder
))
313 for (i
= 0; i
< DRM_CONNECTOR_MAX_ENCODER
; i
++) {
314 if (connector
->encoder_ids
[i
] == 0) {
315 connector
->encoder_ids
[i
] = encoder
->base
.id
;
321 EXPORT_SYMBOL(drm_mode_connector_attach_encoder
);
323 static void drm_mode_remove(struct drm_connector
*connector
,
324 struct drm_display_mode
*mode
)
326 list_del(&mode
->head
);
327 drm_mode_destroy(connector
->dev
, mode
);
331 * drm_connector_cleanup - cleans up an initialised connector
332 * @connector: connector to cleanup
334 * Cleans up the connector but doesn't free the object.
336 void drm_connector_cleanup(struct drm_connector
*connector
)
338 struct drm_device
*dev
= connector
->dev
;
339 struct drm_display_mode
*mode
, *t
;
341 /* The connector should have been removed from userspace long before
342 * it is finally destroyed.
344 if (WARN_ON(connector
->registered
))
345 drm_connector_unregister(connector
);
347 if (connector
->tile_group
) {
348 drm_mode_put_tile_group(dev
, connector
->tile_group
);
349 connector
->tile_group
= NULL
;
352 list_for_each_entry_safe(mode
, t
, &connector
->probed_modes
, head
)
353 drm_mode_remove(connector
, mode
);
355 list_for_each_entry_safe(mode
, t
, &connector
->modes
, head
)
356 drm_mode_remove(connector
, mode
);
358 ida_simple_remove(&drm_connector_enum_list
[connector
->connector_type
].ida
,
359 connector
->connector_type_id
);
361 ida_simple_remove(&dev
->mode_config
.connector_ida
,
364 kfree(connector
->display_info
.bus_formats
);
365 drm_mode_object_unregister(dev
, &connector
->base
);
366 kfree(connector
->name
);
367 connector
->name
= NULL
;
368 spin_lock_irq(&dev
->mode_config
.connector_list_lock
);
369 list_del(&connector
->head
);
370 dev
->mode_config
.num_connector
--;
371 spin_unlock_irq(&dev
->mode_config
.connector_list_lock
);
373 WARN_ON(connector
->state
&& !connector
->funcs
->atomic_destroy_state
);
374 if (connector
->state
&& connector
->funcs
->atomic_destroy_state
)
375 connector
->funcs
->atomic_destroy_state(connector
,
378 mutex_destroy(&connector
->mutex
);
380 memset(connector
, 0, sizeof(*connector
));
382 EXPORT_SYMBOL(drm_connector_cleanup
);
385 * drm_connector_register - register a connector
386 * @connector: the connector to register
388 * Register userspace interfaces for a connector
391 * Zero on success, error code on failure.
393 int drm_connector_register(struct drm_connector
*connector
)
397 if (!connector
->dev
->registered
)
400 mutex_lock(&connector
->mutex
);
401 if (connector
->registered
)
404 ret
= drm_sysfs_connector_add(connector
);
408 ret
= drm_debugfs_connector_add(connector
);
413 if (connector
->funcs
->late_register
) {
414 ret
= connector
->funcs
->late_register(connector
);
419 drm_mode_object_register(connector
->dev
, &connector
->base
);
421 connector
->registered
= true;
425 drm_debugfs_connector_remove(connector
);
427 drm_sysfs_connector_remove(connector
);
429 mutex_unlock(&connector
->mutex
);
432 EXPORT_SYMBOL(drm_connector_register
);
435 * drm_connector_unregister - unregister a connector
436 * @connector: the connector to unregister
438 * Unregister userspace interfaces for a connector
440 void drm_connector_unregister(struct drm_connector
*connector
)
442 mutex_lock(&connector
->mutex
);
443 if (!connector
->registered
) {
444 mutex_unlock(&connector
->mutex
);
448 if (connector
->funcs
->early_unregister
)
449 connector
->funcs
->early_unregister(connector
);
451 drm_sysfs_connector_remove(connector
);
452 drm_debugfs_connector_remove(connector
);
454 connector
->registered
= false;
455 mutex_unlock(&connector
->mutex
);
457 EXPORT_SYMBOL(drm_connector_unregister
);
459 void drm_connector_unregister_all(struct drm_device
*dev
)
461 struct drm_connector
*connector
;
462 struct drm_connector_list_iter conn_iter
;
464 drm_connector_list_iter_begin(dev
, &conn_iter
);
465 drm_for_each_connector_iter(connector
, &conn_iter
)
466 drm_connector_unregister(connector
);
467 drm_connector_list_iter_end(&conn_iter
);
470 int drm_connector_register_all(struct drm_device
*dev
)
472 struct drm_connector
*connector
;
473 struct drm_connector_list_iter conn_iter
;
476 drm_connector_list_iter_begin(dev
, &conn_iter
);
477 drm_for_each_connector_iter(connector
, &conn_iter
) {
478 ret
= drm_connector_register(connector
);
482 drm_connector_list_iter_end(&conn_iter
);
485 drm_connector_unregister_all(dev
);
490 * drm_get_connector_status_name - return a string for connector status
491 * @status: connector status to compute name of
493 * In contrast to the other drm_get_*_name functions this one here returns a
494 * const pointer and hence is threadsafe.
496 const char *drm_get_connector_status_name(enum drm_connector_status status
)
498 if (status
== connector_status_connected
)
500 else if (status
== connector_status_disconnected
)
501 return "disconnected";
505 EXPORT_SYMBOL(drm_get_connector_status_name
);
508 * drm_get_connector_force_name - return a string for connector force
509 * @force: connector force to get name of
511 * Returns: const pointer to name.
513 const char *drm_get_connector_force_name(enum drm_connector_force force
)
516 case DRM_FORCE_UNSPECIFIED
:
517 return "unspecified";
522 case DRM_FORCE_ON_DIGITAL
:
529 #ifdef CONFIG_LOCKDEP
530 static struct lockdep_map connector_list_iter_dep_map
= {
531 .name
= "drm_connector_list_iter"
536 * drm_connector_list_iter_begin - initialize a connector_list iterator
538 * @iter: connector_list iterator
540 * Sets @iter up to walk the &drm_mode_config.connector_list of @dev. @iter
541 * must always be cleaned up again by calling drm_connector_list_iter_end().
542 * Iteration itself happens using drm_connector_list_iter_next() or
543 * drm_for_each_connector_iter().
545 void drm_connector_list_iter_begin(struct drm_device
*dev
,
546 struct drm_connector_list_iter
*iter
)
550 lock_acquire_shared_recursive(&connector_list_iter_dep_map
, 0, 1, NULL
, _RET_IP_
);
552 EXPORT_SYMBOL(drm_connector_list_iter_begin
);
555 * Extra-safe connector put function that works in any context. Should only be
556 * used from the connector_iter functions, where we never really expect to
557 * actually release the connector when dropping our final reference.
560 __drm_connector_put_safe(struct drm_connector
*conn
)
562 struct drm_mode_config
*config
= &conn
->dev
->mode_config
;
564 lockdep_assert_held(&config
->connector_list_lock
);
566 if (!refcount_dec_and_test(&conn
->base
.refcount
.refcount
))
569 llist_add(&conn
->free_node
, &config
->connector_free_list
);
570 schedule_work(&config
->connector_free_work
);
574 * drm_connector_list_iter_next - return next connector
575 * @iter: connectr_list iterator
577 * Returns the next connector for @iter, or NULL when the list walk has
580 struct drm_connector
*
581 drm_connector_list_iter_next(struct drm_connector_list_iter
*iter
)
583 struct drm_connector
*old_conn
= iter
->conn
;
584 struct drm_mode_config
*config
= &iter
->dev
->mode_config
;
585 struct list_head
*lhead
;
588 spin_lock_irqsave(&config
->connector_list_lock
, flags
);
589 lhead
= old_conn
? &old_conn
->head
: &config
->connector_list
;
592 if (lhead
->next
== &config
->connector_list
) {
598 iter
->conn
= list_entry(lhead
, struct drm_connector
, head
);
600 /* loop until it's not a zombie connector */
601 } while (!kref_get_unless_zero(&iter
->conn
->base
.refcount
));
604 __drm_connector_put_safe(old_conn
);
605 spin_unlock_irqrestore(&config
->connector_list_lock
, flags
);
609 EXPORT_SYMBOL(drm_connector_list_iter_next
);
612 * drm_connector_list_iter_end - tear down a connector_list iterator
613 * @iter: connector_list iterator
615 * Tears down @iter and releases any resources (like &drm_connector references)
616 * acquired while walking the list. This must always be called, both when the
617 * iteration completes fully or when it was aborted without walking the entire
620 void drm_connector_list_iter_end(struct drm_connector_list_iter
*iter
)
622 struct drm_mode_config
*config
= &iter
->dev
->mode_config
;
627 spin_lock_irqsave(&config
->connector_list_lock
, flags
);
628 __drm_connector_put_safe(iter
->conn
);
629 spin_unlock_irqrestore(&config
->connector_list_lock
, flags
);
631 lock_release(&connector_list_iter_dep_map
, 0, _RET_IP_
);
633 EXPORT_SYMBOL(drm_connector_list_iter_end
);
635 static const struct drm_prop_enum_list drm_subpixel_enum_list
[] = {
636 { SubPixelUnknown
, "Unknown" },
637 { SubPixelHorizontalRGB
, "Horizontal RGB" },
638 { SubPixelHorizontalBGR
, "Horizontal BGR" },
639 { SubPixelVerticalRGB
, "Vertical RGB" },
640 { SubPixelVerticalBGR
, "Vertical BGR" },
641 { SubPixelNone
, "None" },
645 * drm_get_subpixel_order_name - return a string for a given subpixel enum
646 * @order: enum of subpixel_order
648 * Note you could abuse this and return something out of bounds, but that
649 * would be a caller error. No unscrubbed user data should make it here.
651 const char *drm_get_subpixel_order_name(enum subpixel_order order
)
653 return drm_subpixel_enum_list
[order
].name
;
655 EXPORT_SYMBOL(drm_get_subpixel_order_name
);
657 static const struct drm_prop_enum_list drm_dpms_enum_list
[] = {
658 { DRM_MODE_DPMS_ON
, "On" },
659 { DRM_MODE_DPMS_STANDBY
, "Standby" },
660 { DRM_MODE_DPMS_SUSPEND
, "Suspend" },
661 { DRM_MODE_DPMS_OFF
, "Off" }
663 DRM_ENUM_NAME_FN(drm_get_dpms_name
, drm_dpms_enum_list
)
665 static const struct drm_prop_enum_list drm_link_status_enum_list
[] = {
666 { DRM_MODE_LINK_STATUS_GOOD
, "Good" },
667 { DRM_MODE_LINK_STATUS_BAD
, "Bad" },
671 * drm_display_info_set_bus_formats - set the supported bus formats
672 * @info: display info to store bus formats in
673 * @formats: array containing the supported bus formats
674 * @num_formats: the number of entries in the fmts array
676 * Store the supported bus formats in display info structure.
677 * See MEDIA_BUS_FMT_* definitions in include/uapi/linux/media-bus-format.h for
678 * a full list of available formats.
680 int drm_display_info_set_bus_formats(struct drm_display_info
*info
,
682 unsigned int num_formats
)
686 if (!formats
&& num_formats
)
689 if (formats
&& num_formats
) {
690 fmts
= kmemdup(formats
, sizeof(*formats
) * num_formats
,
696 kfree(info
->bus_formats
);
697 info
->bus_formats
= fmts
;
698 info
->num_bus_formats
= num_formats
;
702 EXPORT_SYMBOL(drm_display_info_set_bus_formats
);
704 /* Optional connector properties. */
705 static const struct drm_prop_enum_list drm_scaling_mode_enum_list
[] = {
706 { DRM_MODE_SCALE_NONE
, "None" },
707 { DRM_MODE_SCALE_FULLSCREEN
, "Full" },
708 { DRM_MODE_SCALE_CENTER
, "Center" },
709 { DRM_MODE_SCALE_ASPECT
, "Full aspect" },
712 static const struct drm_prop_enum_list drm_aspect_ratio_enum_list
[] = {
713 { DRM_MODE_PICTURE_ASPECT_NONE
, "Automatic" },
714 { DRM_MODE_PICTURE_ASPECT_4_3
, "4:3" },
715 { DRM_MODE_PICTURE_ASPECT_16_9
, "16:9" },
718 static const struct drm_prop_enum_list drm_panel_orientation_enum_list
[] = {
719 { DRM_MODE_PANEL_ORIENTATION_NORMAL
, "Normal" },
720 { DRM_MODE_PANEL_ORIENTATION_BOTTOM_UP
, "Upside Down" },
721 { DRM_MODE_PANEL_ORIENTATION_LEFT_UP
, "Left Side Up" },
722 { DRM_MODE_PANEL_ORIENTATION_RIGHT_UP
, "Right Side Up" },
725 static const struct drm_prop_enum_list drm_dvi_i_select_enum_list
[] = {
726 { DRM_MODE_SUBCONNECTOR_Automatic
, "Automatic" }, /* DVI-I and TV-out */
727 { DRM_MODE_SUBCONNECTOR_DVID
, "DVI-D" }, /* DVI-I */
728 { DRM_MODE_SUBCONNECTOR_DVIA
, "DVI-A" }, /* DVI-I */
730 DRM_ENUM_NAME_FN(drm_get_dvi_i_select_name
, drm_dvi_i_select_enum_list
)
732 static const struct drm_prop_enum_list drm_dvi_i_subconnector_enum_list
[] = {
733 { DRM_MODE_SUBCONNECTOR_Unknown
, "Unknown" }, /* DVI-I and TV-out */
734 { DRM_MODE_SUBCONNECTOR_DVID
, "DVI-D" }, /* DVI-I */
735 { DRM_MODE_SUBCONNECTOR_DVIA
, "DVI-A" }, /* DVI-I */
737 DRM_ENUM_NAME_FN(drm_get_dvi_i_subconnector_name
,
738 drm_dvi_i_subconnector_enum_list
)
740 static const struct drm_prop_enum_list drm_tv_select_enum_list
[] = {
741 { DRM_MODE_SUBCONNECTOR_Automatic
, "Automatic" }, /* DVI-I and TV-out */
742 { DRM_MODE_SUBCONNECTOR_Composite
, "Composite" }, /* TV-out */
743 { DRM_MODE_SUBCONNECTOR_SVIDEO
, "SVIDEO" }, /* TV-out */
744 { DRM_MODE_SUBCONNECTOR_Component
, "Component" }, /* TV-out */
745 { DRM_MODE_SUBCONNECTOR_SCART
, "SCART" }, /* TV-out */
747 DRM_ENUM_NAME_FN(drm_get_tv_select_name
, drm_tv_select_enum_list
)
749 static const struct drm_prop_enum_list drm_tv_subconnector_enum_list
[] = {
750 { DRM_MODE_SUBCONNECTOR_Unknown
, "Unknown" }, /* DVI-I and TV-out */
751 { DRM_MODE_SUBCONNECTOR_Composite
, "Composite" }, /* TV-out */
752 { DRM_MODE_SUBCONNECTOR_SVIDEO
, "SVIDEO" }, /* TV-out */
753 { DRM_MODE_SUBCONNECTOR_Component
, "Component" }, /* TV-out */
754 { DRM_MODE_SUBCONNECTOR_SCART
, "SCART" }, /* TV-out */
756 DRM_ENUM_NAME_FN(drm_get_tv_subconnector_name
,
757 drm_tv_subconnector_enum_list
)
760 * DOC: standard connector properties
762 * DRM connectors have a few standardized properties:
765 * Blob property which contains the current EDID read from the sink. This
766 * is useful to parse sink identification information like vendor, model
767 * and serial. Drivers should update this property by calling
768 * drm_mode_connector_update_edid_property(), usually after having parsed
769 * the EDID using drm_add_edid_modes(). Userspace cannot change this
772 * Legacy property for setting the power state of the connector. For atomic
773 * drivers this is only provided for backwards compatibility with existing
774 * drivers, it remaps to controlling the "ACTIVE" property on the CRTC the
775 * connector is linked to. Drivers should never set this property directly,
776 * it is handled by the DRM core by calling the &drm_connector_funcs.dpms
777 * callback. For atomic drivers the remapping to the "ACTIVE" property is
778 * implemented in the DRM core. This is the only standard connector
779 * property that userspace can change.
781 * Note that this property cannot be set through the MODE_ATOMIC ioctl,
782 * userspace must use "ACTIVE" on the CRTC instead.
786 * For userspace also running on legacy drivers the "DPMS" semantics are a
787 * lot more complicated. First, userspace cannot rely on the "DPMS" value
788 * returned by the GETCONNECTOR actually reflecting reality, because many
789 * drivers fail to update it. For atomic drivers this is taken care of in
790 * drm_atomic_helper_update_legacy_modeset_state().
792 * The second issue is that the DPMS state is only well-defined when the
793 * connector is connected to a CRTC. In atomic the DRM core enforces that
794 * "ACTIVE" is off in such a case, no such checks exists for "DPMS".
796 * Finally, when enabling an output using the legacy SETCONFIG ioctl then
797 * "DPMS" is forced to ON. But see above, that might not be reflected in
798 * the software value on legacy drivers.
800 * Summarizing: Only set "DPMS" when the connector is known to be enabled,
801 * assume that a successful SETCONFIG call also sets "DPMS" to on, and
802 * never read back the value of "DPMS" because it can be incorrect.
804 * Connector path property to identify how this sink is physically
805 * connected. Used by DP MST. This should be set by calling
806 * drm_mode_connector_set_path_property(), in the case of DP MST with the
807 * path property the MST manager created. Userspace cannot change this
810 * Connector tile group property to indicate how a set of DRM connector
811 * compose together into one logical screen. This is used by both high-res
812 * external screens (often only using a single cable, but exposing multiple
813 * DP MST sinks), or high-res integrated panels (like dual-link DSI) which
814 * are not gen-locked. Note that for tiled panels which are genlocked, like
815 * dual-link LVDS or dual-link DSI, the driver should try to not expose the
816 * tiling and virtualize both &drm_crtc and &drm_plane if needed. Drivers
817 * should update this value using drm_mode_connector_set_tile_property().
818 * Userspace cannot change this property.
820 * Connector link-status property to indicate the status of link. The default
821 * value of link-status is "GOOD". If something fails during or after modeset,
822 * the kernel driver may set this to "BAD" and issue a hotplug uevent. Drivers
823 * should update this value using drm_mode_connector_set_link_status_property().
825 * Indicates the output should be ignored for purposes of displaying a
826 * standard desktop environment or console. This is most likely because
827 * the output device is not rectilinear.
829 * Connectors also have one standardized atomic property:
832 * Mode object ID of the &drm_crtc this connector should be connected to.
834 * Connectors for LCD panels may also have one standardized property:
837 * On some devices the LCD panel is mounted in the casing in such a way
838 * that the up/top side of the panel does not match with the top side of
839 * the device. Userspace can use this property to check for this.
840 * Note that input coordinates from touchscreens (input devices with
841 * INPUT_PROP_DIRECT) will still map 1:1 to the actual LCD panel
842 * coordinates, so if userspace rotates the picture to adjust for
843 * the orientation it must also apply the same transformation to the
844 * touchscreen input coordinates.
847 int drm_connector_create_standard_properties(struct drm_device
*dev
)
849 struct drm_property
*prop
;
851 prop
= drm_property_create(dev
, DRM_MODE_PROP_BLOB
|
852 DRM_MODE_PROP_IMMUTABLE
,
856 dev
->mode_config
.edid_property
= prop
;
858 prop
= drm_property_create_enum(dev
, 0,
859 "DPMS", drm_dpms_enum_list
,
860 ARRAY_SIZE(drm_dpms_enum_list
));
863 dev
->mode_config
.dpms_property
= prop
;
865 prop
= drm_property_create(dev
,
867 DRM_MODE_PROP_IMMUTABLE
,
871 dev
->mode_config
.path_property
= prop
;
873 prop
= drm_property_create(dev
,
875 DRM_MODE_PROP_IMMUTABLE
,
879 dev
->mode_config
.tile_property
= prop
;
881 prop
= drm_property_create_enum(dev
, 0, "link-status",
882 drm_link_status_enum_list
,
883 ARRAY_SIZE(drm_link_status_enum_list
));
886 dev
->mode_config
.link_status_property
= prop
;
888 prop
= drm_property_create_bool(dev
, DRM_MODE_PROP_IMMUTABLE
, "non-desktop");
891 dev
->mode_config
.non_desktop_property
= prop
;
897 * drm_mode_create_dvi_i_properties - create DVI-I specific connector properties
900 * Called by a driver the first time a DVI-I connector is made.
902 int drm_mode_create_dvi_i_properties(struct drm_device
*dev
)
904 struct drm_property
*dvi_i_selector
;
905 struct drm_property
*dvi_i_subconnector
;
907 if (dev
->mode_config
.dvi_i_select_subconnector_property
)
911 drm_property_create_enum(dev
, 0,
912 "select subconnector",
913 drm_dvi_i_select_enum_list
,
914 ARRAY_SIZE(drm_dvi_i_select_enum_list
));
915 dev
->mode_config
.dvi_i_select_subconnector_property
= dvi_i_selector
;
917 dvi_i_subconnector
= drm_property_create_enum(dev
, DRM_MODE_PROP_IMMUTABLE
,
919 drm_dvi_i_subconnector_enum_list
,
920 ARRAY_SIZE(drm_dvi_i_subconnector_enum_list
));
921 dev
->mode_config
.dvi_i_subconnector_property
= dvi_i_subconnector
;
925 EXPORT_SYMBOL(drm_mode_create_dvi_i_properties
);
928 * drm_create_tv_properties - create TV specific connector properties
930 * @num_modes: number of different TV formats (modes) supported
931 * @modes: array of pointers to strings containing name of each format
933 * Called by a driver's TV initialization routine, this function creates
934 * the TV specific connector properties for a given device. Caller is
935 * responsible for allocating a list of format names and passing them to
938 int drm_mode_create_tv_properties(struct drm_device
*dev
,
939 unsigned int num_modes
,
940 const char * const modes
[])
942 struct drm_property
*tv_selector
;
943 struct drm_property
*tv_subconnector
;
946 if (dev
->mode_config
.tv_select_subconnector_property
)
950 * Basic connector properties
952 tv_selector
= drm_property_create_enum(dev
, 0,
953 "select subconnector",
954 drm_tv_select_enum_list
,
955 ARRAY_SIZE(drm_tv_select_enum_list
));
959 dev
->mode_config
.tv_select_subconnector_property
= tv_selector
;
962 drm_property_create_enum(dev
, DRM_MODE_PROP_IMMUTABLE
,
964 drm_tv_subconnector_enum_list
,
965 ARRAY_SIZE(drm_tv_subconnector_enum_list
));
966 if (!tv_subconnector
)
968 dev
->mode_config
.tv_subconnector_property
= tv_subconnector
;
971 * Other, TV specific properties: margins & TV modes.
973 dev
->mode_config
.tv_left_margin_property
=
974 drm_property_create_range(dev
, 0, "left margin", 0, 100);
975 if (!dev
->mode_config
.tv_left_margin_property
)
978 dev
->mode_config
.tv_right_margin_property
=
979 drm_property_create_range(dev
, 0, "right margin", 0, 100);
980 if (!dev
->mode_config
.tv_right_margin_property
)
983 dev
->mode_config
.tv_top_margin_property
=
984 drm_property_create_range(dev
, 0, "top margin", 0, 100);
985 if (!dev
->mode_config
.tv_top_margin_property
)
988 dev
->mode_config
.tv_bottom_margin_property
=
989 drm_property_create_range(dev
, 0, "bottom margin", 0, 100);
990 if (!dev
->mode_config
.tv_bottom_margin_property
)
993 dev
->mode_config
.tv_mode_property
=
994 drm_property_create(dev
, DRM_MODE_PROP_ENUM
,
996 if (!dev
->mode_config
.tv_mode_property
)
999 for (i
= 0; i
< num_modes
; i
++)
1000 drm_property_add_enum(dev
->mode_config
.tv_mode_property
, i
,
1003 dev
->mode_config
.tv_brightness_property
=
1004 drm_property_create_range(dev
, 0, "brightness", 0, 100);
1005 if (!dev
->mode_config
.tv_brightness_property
)
1008 dev
->mode_config
.tv_contrast_property
=
1009 drm_property_create_range(dev
, 0, "contrast", 0, 100);
1010 if (!dev
->mode_config
.tv_contrast_property
)
1013 dev
->mode_config
.tv_flicker_reduction_property
=
1014 drm_property_create_range(dev
, 0, "flicker reduction", 0, 100);
1015 if (!dev
->mode_config
.tv_flicker_reduction_property
)
1018 dev
->mode_config
.tv_overscan_property
=
1019 drm_property_create_range(dev
, 0, "overscan", 0, 100);
1020 if (!dev
->mode_config
.tv_overscan_property
)
1023 dev
->mode_config
.tv_saturation_property
=
1024 drm_property_create_range(dev
, 0, "saturation", 0, 100);
1025 if (!dev
->mode_config
.tv_saturation_property
)
1028 dev
->mode_config
.tv_hue_property
=
1029 drm_property_create_range(dev
, 0, "hue", 0, 100);
1030 if (!dev
->mode_config
.tv_hue_property
)
1037 EXPORT_SYMBOL(drm_mode_create_tv_properties
);
1040 * drm_mode_create_scaling_mode_property - create scaling mode property
1043 * Called by a driver the first time it's needed, must be attached to desired
1046 * Atomic drivers should use drm_connector_attach_scaling_mode_property()
1047 * instead to correctly assign &drm_connector_state.picture_aspect_ratio
1048 * in the atomic state.
1050 int drm_mode_create_scaling_mode_property(struct drm_device
*dev
)
1052 struct drm_property
*scaling_mode
;
1054 if (dev
->mode_config
.scaling_mode_property
)
1058 drm_property_create_enum(dev
, 0, "scaling mode",
1059 drm_scaling_mode_enum_list
,
1060 ARRAY_SIZE(drm_scaling_mode_enum_list
));
1062 dev
->mode_config
.scaling_mode_property
= scaling_mode
;
1066 EXPORT_SYMBOL(drm_mode_create_scaling_mode_property
);
1069 * drm_connector_attach_scaling_mode_property - attach atomic scaling mode property
1070 * @connector: connector to attach scaling mode property on.
1071 * @scaling_mode_mask: or'ed mask of BIT(%DRM_MODE_SCALE_\*).
1073 * This is used to add support for scaling mode to atomic drivers.
1074 * The scaling mode will be set to &drm_connector_state.picture_aspect_ratio
1075 * and can be used from &drm_connector_helper_funcs->atomic_check for validation.
1077 * This is the atomic version of drm_mode_create_scaling_mode_property().
1080 * Zero on success, negative errno on failure.
1082 int drm_connector_attach_scaling_mode_property(struct drm_connector
*connector
,
1083 u32 scaling_mode_mask
)
1085 struct drm_device
*dev
= connector
->dev
;
1086 struct drm_property
*scaling_mode_property
;
1088 const unsigned valid_scaling_mode_mask
=
1089 (1U << ARRAY_SIZE(drm_scaling_mode_enum_list
)) - 1;
1091 if (WARN_ON(hweight32(scaling_mode_mask
) < 2 ||
1092 scaling_mode_mask
& ~valid_scaling_mode_mask
))
1095 scaling_mode_property
=
1096 drm_property_create(dev
, DRM_MODE_PROP_ENUM
, "scaling mode",
1097 hweight32(scaling_mode_mask
));
1099 if (!scaling_mode_property
)
1102 for (i
= 0; i
< ARRAY_SIZE(drm_scaling_mode_enum_list
); i
++) {
1105 if (!(BIT(i
) & scaling_mode_mask
))
1108 ret
= drm_property_add_enum(scaling_mode_property
, j
++,
1109 drm_scaling_mode_enum_list
[i
].type
,
1110 drm_scaling_mode_enum_list
[i
].name
);
1113 drm_property_destroy(dev
, scaling_mode_property
);
1119 drm_object_attach_property(&connector
->base
,
1120 scaling_mode_property
, 0);
1122 connector
->scaling_mode_property
= scaling_mode_property
;
1126 EXPORT_SYMBOL(drm_connector_attach_scaling_mode_property
);
1129 * drm_mode_create_aspect_ratio_property - create aspect ratio property
1132 * Called by a driver the first time it's needed, must be attached to desired
1136 * Zero on success, negative errno on failure.
1138 int drm_mode_create_aspect_ratio_property(struct drm_device
*dev
)
1140 if (dev
->mode_config
.aspect_ratio_property
)
1143 dev
->mode_config
.aspect_ratio_property
=
1144 drm_property_create_enum(dev
, 0, "aspect ratio",
1145 drm_aspect_ratio_enum_list
,
1146 ARRAY_SIZE(drm_aspect_ratio_enum_list
));
1148 if (dev
->mode_config
.aspect_ratio_property
== NULL
)
1153 EXPORT_SYMBOL(drm_mode_create_aspect_ratio_property
);
1156 * drm_mode_create_suggested_offset_properties - create suggests offset properties
1159 * Create the the suggested x/y offset property for connectors.
1161 int drm_mode_create_suggested_offset_properties(struct drm_device
*dev
)
1163 if (dev
->mode_config
.suggested_x_property
&& dev
->mode_config
.suggested_y_property
)
1166 dev
->mode_config
.suggested_x_property
=
1167 drm_property_create_range(dev
, DRM_MODE_PROP_IMMUTABLE
, "suggested X", 0, 0xffffffff);
1169 dev
->mode_config
.suggested_y_property
=
1170 drm_property_create_range(dev
, DRM_MODE_PROP_IMMUTABLE
, "suggested Y", 0, 0xffffffff);
1172 if (dev
->mode_config
.suggested_x_property
== NULL
||
1173 dev
->mode_config
.suggested_y_property
== NULL
)
1177 EXPORT_SYMBOL(drm_mode_create_suggested_offset_properties
);
1180 * drm_mode_connector_set_path_property - set tile property on connector
1181 * @connector: connector to set property on.
1182 * @path: path to use for property; must not be NULL.
1184 * This creates a property to expose to userspace to specify a
1185 * connector path. This is mainly used for DisplayPort MST where
1186 * connectors have a topology and we want to allow userspace to give
1187 * them more meaningful names.
1190 * Zero on success, negative errno on failure.
1192 int drm_mode_connector_set_path_property(struct drm_connector
*connector
,
1195 struct drm_device
*dev
= connector
->dev
;
1198 ret
= drm_property_replace_global_blob(dev
,
1199 &connector
->path_blob_ptr
,
1203 dev
->mode_config
.path_property
);
1206 EXPORT_SYMBOL(drm_mode_connector_set_path_property
);
1209 * drm_mode_connector_set_tile_property - set tile property on connector
1210 * @connector: connector to set property on.
1212 * This looks up the tile information for a connector, and creates a
1213 * property for userspace to parse if it exists. The property is of
1214 * the form of 8 integers using ':' as a separator.
1217 * Zero on success, errno on failure.
1219 int drm_mode_connector_set_tile_property(struct drm_connector
*connector
)
1221 struct drm_device
*dev
= connector
->dev
;
1225 if (!connector
->has_tile
) {
1226 ret
= drm_property_replace_global_blob(dev
,
1227 &connector
->tile_blob_ptr
,
1231 dev
->mode_config
.tile_property
);
1235 snprintf(tile
, 256, "%d:%d:%d:%d:%d:%d:%d:%d",
1236 connector
->tile_group
->id
, connector
->tile_is_single_monitor
,
1237 connector
->num_h_tile
, connector
->num_v_tile
,
1238 connector
->tile_h_loc
, connector
->tile_v_loc
,
1239 connector
->tile_h_size
, connector
->tile_v_size
);
1241 ret
= drm_property_replace_global_blob(dev
,
1242 &connector
->tile_blob_ptr
,
1246 dev
->mode_config
.tile_property
);
1249 EXPORT_SYMBOL(drm_mode_connector_set_tile_property
);
1252 * drm_mode_connector_update_edid_property - update the edid property of a connector
1253 * @connector: drm connector
1254 * @edid: new value of the edid property
1256 * This function creates a new blob modeset object and assigns its id to the
1257 * connector's edid property.
1260 * Zero on success, negative errno on failure.
1262 int drm_mode_connector_update_edid_property(struct drm_connector
*connector
,
1263 const struct edid
*edid
)
1265 struct drm_device
*dev
= connector
->dev
;
1269 /* ignore requests to set edid when overridden */
1270 if (connector
->override_edid
)
1274 size
= EDID_LENGTH
* (1 + edid
->extensions
);
1276 /* Set the display info, using edid if available, otherwise
1277 * reseting the values to defaults. This duplicates the work
1278 * done in drm_add_edid_modes, but that function is not
1279 * consistently called before this one in all drivers and the
1280 * computation is cheap enough that it seems better to
1281 * duplicate it rather than attempt to ensure some arbitrary
1282 * ordering of calls.
1285 drm_add_display_info(connector
, edid
);
1287 drm_reset_display_info(connector
);
1289 drm_object_property_set_value(&connector
->base
,
1290 dev
->mode_config
.non_desktop_property
,
1291 connector
->display_info
.non_desktop
);
1293 ret
= drm_property_replace_global_blob(dev
,
1294 &connector
->edid_blob_ptr
,
1298 dev
->mode_config
.edid_property
);
1301 EXPORT_SYMBOL(drm_mode_connector_update_edid_property
);
1304 * drm_mode_connector_set_link_status_property - Set link status property of a connector
1305 * @connector: drm connector
1306 * @link_status: new value of link status property (0: Good, 1: Bad)
1308 * In usual working scenario, this link status property will always be set to
1309 * "GOOD". If something fails during or after a mode set, the kernel driver
1310 * may set this link status property to "BAD". The caller then needs to send a
1311 * hotplug uevent for userspace to re-check the valid modes through
1312 * GET_CONNECTOR_IOCTL and retry modeset.
1314 * Note: Drivers cannot rely on userspace to support this property and
1315 * issue a modeset. As such, they may choose to handle issues (like
1316 * re-training a link) without userspace's intervention.
1318 * The reason for adding this property is to handle link training failures, but
1319 * it is not limited to DP or link training. For example, if we implement
1320 * asynchronous setcrtc, this property can be used to report any failures in that.
1322 void drm_mode_connector_set_link_status_property(struct drm_connector
*connector
,
1323 uint64_t link_status
)
1325 struct drm_device
*dev
= connector
->dev
;
1327 drm_modeset_lock(&dev
->mode_config
.connection_mutex
, NULL
);
1328 connector
->state
->link_status
= link_status
;
1329 drm_modeset_unlock(&dev
->mode_config
.connection_mutex
);
1331 EXPORT_SYMBOL(drm_mode_connector_set_link_status_property
);
1334 * drm_connector_init_panel_orientation_property -
1335 * initialize the connecters panel_orientation property
1336 * @connector: connector for which to init the panel-orientation property.
1337 * @width: width in pixels of the panel, used for panel quirk detection
1338 * @height: height in pixels of the panel, used for panel quirk detection
1340 * This function should only be called for built-in panels, after setting
1341 * connector->display_info.panel_orientation first (if known).
1343 * This function will check for platform specific (e.g. DMI based) quirks
1344 * overriding display_info.panel_orientation first, then if panel_orientation
1345 * is not DRM_MODE_PANEL_ORIENTATION_UNKNOWN it will attach the
1346 * "panel orientation" property to the connector.
1349 * Zero on success, negative errno on failure.
1351 int drm_connector_init_panel_orientation_property(
1352 struct drm_connector
*connector
, int width
, int height
)
1354 struct drm_device
*dev
= connector
->dev
;
1355 struct drm_display_info
*info
= &connector
->display_info
;
1356 struct drm_property
*prop
;
1357 int orientation_quirk
;
1359 orientation_quirk
= drm_get_panel_orientation_quirk(width
, height
);
1360 if (orientation_quirk
!= DRM_MODE_PANEL_ORIENTATION_UNKNOWN
)
1361 info
->panel_orientation
= orientation_quirk
;
1363 if (info
->panel_orientation
== DRM_MODE_PANEL_ORIENTATION_UNKNOWN
)
1366 prop
= dev
->mode_config
.panel_orientation_property
;
1368 prop
= drm_property_create_enum(dev
, DRM_MODE_PROP_IMMUTABLE
,
1369 "panel orientation",
1370 drm_panel_orientation_enum_list
,
1371 ARRAY_SIZE(drm_panel_orientation_enum_list
));
1375 dev
->mode_config
.panel_orientation_property
= prop
;
1378 drm_object_attach_property(&connector
->base
, prop
,
1379 info
->panel_orientation
);
1382 EXPORT_SYMBOL(drm_connector_init_panel_orientation_property
);
1384 int drm_mode_connector_set_obj_prop(struct drm_mode_object
*obj
,
1385 struct drm_property
*property
,
1389 struct drm_connector
*connector
= obj_to_connector(obj
);
1391 /* Do DPMS ourselves */
1392 if (property
== connector
->dev
->mode_config
.dpms_property
) {
1393 ret
= (*connector
->funcs
->dpms
)(connector
, (int)value
);
1394 } else if (connector
->funcs
->set_property
)
1395 ret
= connector
->funcs
->set_property(connector
, property
, value
);
1398 drm_object_property_set_value(&connector
->base
, property
, value
);
1402 int drm_mode_connector_property_set_ioctl(struct drm_device
*dev
,
1403 void *data
, struct drm_file
*file_priv
)
1405 struct drm_mode_connector_set_property
*conn_set_prop
= data
;
1406 struct drm_mode_obj_set_property obj_set_prop
= {
1407 .value
= conn_set_prop
->value
,
1408 .prop_id
= conn_set_prop
->prop_id
,
1409 .obj_id
= conn_set_prop
->connector_id
,
1410 .obj_type
= DRM_MODE_OBJECT_CONNECTOR
1413 /* It does all the locking and checking we need */
1414 return drm_mode_obj_set_property_ioctl(dev
, &obj_set_prop
, file_priv
);
1417 static struct drm_encoder
*drm_connector_get_encoder(struct drm_connector
*connector
)
1419 /* For atomic drivers only state objects are synchronously updated and
1420 * protected by modeset locks, so check those first. */
1421 if (connector
->state
)
1422 return connector
->state
->best_encoder
;
1423 return connector
->encoder
;
1426 static bool drm_mode_expose_to_userspace(const struct drm_display_mode
*mode
,
1427 const struct drm_file
*file_priv
)
1430 * If user-space hasn't configured the driver to expose the stereo 3D
1431 * modes, don't expose them.
1433 if (!file_priv
->stereo_allowed
&& drm_mode_is_stereo(mode
))
1439 int drm_mode_getconnector(struct drm_device
*dev
, void *data
,
1440 struct drm_file
*file_priv
)
1442 struct drm_mode_get_connector
*out_resp
= data
;
1443 struct drm_connector
*connector
;
1444 struct drm_encoder
*encoder
;
1445 struct drm_display_mode
*mode
;
1447 int encoders_count
= 0;
1451 struct drm_mode_modeinfo u_mode
;
1452 struct drm_mode_modeinfo __user
*mode_ptr
;
1453 uint32_t __user
*encoder_ptr
;
1455 if (!drm_core_check_feature(dev
, DRIVER_MODESET
))
1458 memset(&u_mode
, 0, sizeof(struct drm_mode_modeinfo
));
1460 connector
= drm_connector_lookup(dev
, file_priv
, out_resp
->connector_id
);
1464 for (i
= 0; i
< DRM_CONNECTOR_MAX_ENCODER
; i
++)
1465 if (connector
->encoder_ids
[i
] != 0)
1468 if ((out_resp
->count_encoders
>= encoders_count
) && encoders_count
) {
1470 encoder_ptr
= (uint32_t __user
*)(unsigned long)(out_resp
->encoders_ptr
);
1471 for (i
= 0; i
< DRM_CONNECTOR_MAX_ENCODER
; i
++) {
1472 if (connector
->encoder_ids
[i
] != 0) {
1473 if (put_user(connector
->encoder_ids
[i
],
1474 encoder_ptr
+ copied
)) {
1482 out_resp
->count_encoders
= encoders_count
;
1484 out_resp
->connector_id
= connector
->base
.id
;
1485 out_resp
->connector_type
= connector
->connector_type
;
1486 out_resp
->connector_type_id
= connector
->connector_type_id
;
1488 mutex_lock(&dev
->mode_config
.mutex
);
1489 if (out_resp
->count_modes
== 0) {
1490 connector
->funcs
->fill_modes(connector
,
1491 dev
->mode_config
.max_width
,
1492 dev
->mode_config
.max_height
);
1495 out_resp
->mm_width
= connector
->display_info
.width_mm
;
1496 out_resp
->mm_height
= connector
->display_info
.height_mm
;
1497 out_resp
->subpixel
= connector
->display_info
.subpixel_order
;
1498 out_resp
->connection
= connector
->status
;
1500 /* delayed so we get modes regardless of pre-fill_modes state */
1501 list_for_each_entry(mode
, &connector
->modes
, head
)
1502 if (drm_mode_expose_to_userspace(mode
, file_priv
))
1506 * This ioctl is called twice, once to determine how much space is
1507 * needed, and the 2nd time to fill it.
1509 if ((out_resp
->count_modes
>= mode_count
) && mode_count
) {
1511 mode_ptr
= (struct drm_mode_modeinfo __user
*)(unsigned long)out_resp
->modes_ptr
;
1512 list_for_each_entry(mode
, &connector
->modes
, head
) {
1513 if (!drm_mode_expose_to_userspace(mode
, file_priv
))
1516 drm_mode_convert_to_umode(&u_mode
, mode
);
1517 if (copy_to_user(mode_ptr
+ copied
,
1518 &u_mode
, sizeof(u_mode
))) {
1520 mutex_unlock(&dev
->mode_config
.mutex
);
1527 out_resp
->count_modes
= mode_count
;
1528 mutex_unlock(&dev
->mode_config
.mutex
);
1530 drm_modeset_lock(&dev
->mode_config
.connection_mutex
, NULL
);
1531 encoder
= drm_connector_get_encoder(connector
);
1533 out_resp
->encoder_id
= encoder
->base
.id
;
1535 out_resp
->encoder_id
= 0;
1537 /* Only grab properties after probing, to make sure EDID and other
1538 * properties reflect the latest status. */
1539 ret
= drm_mode_object_get_properties(&connector
->base
, file_priv
->atomic
,
1540 (uint32_t __user
*)(unsigned long)(out_resp
->props_ptr
),
1541 (uint64_t __user
*)(unsigned long)(out_resp
->prop_values_ptr
),
1542 &out_resp
->count_props
);
1543 drm_modeset_unlock(&dev
->mode_config
.connection_mutex
);
1546 drm_connector_put(connector
);
1555 * Tile groups are used to represent tiled monitors with a unique integer
1556 * identifier. Tiled monitors using DisplayID v1.3 have a unique 8-byte handle,
1557 * we store this in a tile group, so we have a common identifier for all tiles
1558 * in a monitor group. The property is called "TILE". Drivers can manage tile
1559 * groups using drm_mode_create_tile_group(), drm_mode_put_tile_group() and
1560 * drm_mode_get_tile_group(). But this is only needed for internal panels where
1561 * the tile group information is exposed through a non-standard way.
1564 static void drm_tile_group_free(struct kref
*kref
)
1566 struct drm_tile_group
*tg
= container_of(kref
, struct drm_tile_group
, refcount
);
1567 struct drm_device
*dev
= tg
->dev
;
1568 mutex_lock(&dev
->mode_config
.idr_mutex
);
1569 idr_remove(&dev
->mode_config
.tile_idr
, tg
->id
);
1570 mutex_unlock(&dev
->mode_config
.idr_mutex
);
1575 * drm_mode_put_tile_group - drop a reference to a tile group.
1577 * @tg: tile group to drop reference to.
1579 * drop reference to tile group and free if 0.
1581 void drm_mode_put_tile_group(struct drm_device
*dev
,
1582 struct drm_tile_group
*tg
)
1584 kref_put(&tg
->refcount
, drm_tile_group_free
);
1586 EXPORT_SYMBOL(drm_mode_put_tile_group
);
1589 * drm_mode_get_tile_group - get a reference to an existing tile group
1591 * @topology: 8-bytes unique per monitor.
1593 * Use the unique bytes to get a reference to an existing tile group.
1596 * tile group or NULL if not found.
1598 struct drm_tile_group
*drm_mode_get_tile_group(struct drm_device
*dev
,
1601 struct drm_tile_group
*tg
;
1603 mutex_lock(&dev
->mode_config
.idr_mutex
);
1604 idr_for_each_entry(&dev
->mode_config
.tile_idr
, tg
, id
) {
1605 if (!memcmp(tg
->group_data
, topology
, 8)) {
1606 if (!kref_get_unless_zero(&tg
->refcount
))
1608 mutex_unlock(&dev
->mode_config
.idr_mutex
);
1612 mutex_unlock(&dev
->mode_config
.idr_mutex
);
1615 EXPORT_SYMBOL(drm_mode_get_tile_group
);
1618 * drm_mode_create_tile_group - create a tile group from a displayid description
1620 * @topology: 8-bytes unique per monitor.
1622 * Create a tile group for the unique monitor, and get a unique
1623 * identifier for the tile group.
1626 * new tile group or error.
1628 struct drm_tile_group
*drm_mode_create_tile_group(struct drm_device
*dev
,
1631 struct drm_tile_group
*tg
;
1634 tg
= kzalloc(sizeof(*tg
), GFP_KERNEL
);
1636 return ERR_PTR(-ENOMEM
);
1638 kref_init(&tg
->refcount
);
1639 memcpy(tg
->group_data
, topology
, 8);
1642 mutex_lock(&dev
->mode_config
.idr_mutex
);
1643 ret
= idr_alloc(&dev
->mode_config
.tile_idr
, tg
, 1, 0, GFP_KERNEL
);
1651 mutex_unlock(&dev
->mode_config
.idr_mutex
);
1654 EXPORT_SYMBOL(drm_mode_create_tile_group
);