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
23 #include <drm/drm_auth.h>
24 #include <drm/drm_connector.h>
25 #include <drm/drm_drv.h>
26 #include <drm/drm_edid.h>
27 #include <drm/drm_encoder.h>
28 #include <drm/drm_file.h>
29 #include <drm/drm_managed.h>
30 #include <drm/drm_panel.h>
31 #include <drm/drm_print.h>
32 #include <drm/drm_privacy_screen_consumer.h>
33 #include <drm/drm_sysfs.h>
34 #include <drm/drm_utils.h>
36 #include <linux/property.h>
37 #include <linux/uaccess.h>
39 #include <video/cmdline.h>
41 #include "drm_crtc_internal.h"
42 #include "drm_internal.h"
47 * In DRM connectors are the general abstraction for display sinks, and include
48 * also fixed panels or anything else that can display pixels in some form. As
49 * opposed to all other KMS objects representing hardware (like CRTC, encoder or
50 * plane abstractions) connectors can be hotplugged and unplugged at runtime.
51 * Hence they are reference-counted using drm_connector_get() and
52 * drm_connector_put().
54 * KMS driver must create, initialize, register and attach at a &struct
55 * drm_connector for each such sink. The instance is created as other KMS
56 * objects and initialized by setting the following fields. The connector is
57 * initialized with a call to drm_connector_init() with a pointer to the
58 * &struct drm_connector_funcs and a connector type, and then exposed to
59 * userspace with a call to drm_connector_register().
61 * Connectors must be attached to an encoder to be used. For devices that map
62 * connectors to encoders 1:1, the connector should be attached at
63 * initialization time with a call to drm_connector_attach_encoder(). The
64 * driver must also set the &drm_connector.encoder field to point to the
67 * For connectors which are not fixed (like built-in panels) the driver needs to
68 * support hotplug notifications. The simplest way to do that is by using the
69 * probe helpers, see drm_kms_helper_poll_init() for connectors which don't have
70 * hardware support for hotplug interrupts. Connectors with hardware hotplug
71 * support can instead use e.g. drm_helper_hpd_irq_event().
75 * Global connector list for drm_connector_find_by_fwnode().
76 * Note drm_connector_[un]register() first take connector->lock and then
77 * take the connector_list_lock.
79 static DEFINE_MUTEX(connector_list_lock);
80 static LIST_HEAD(connector_list);
82 struct drm_conn_prop_enum_list {
89 * Connector and encoder types.
91 static struct drm_conn_prop_enum_list drm_connector_enum_list[] = {
92 { DRM_MODE_CONNECTOR_Unknown, "Unknown" },
93 { DRM_MODE_CONNECTOR_VGA, "VGA" },
94 { DRM_MODE_CONNECTOR_DVII, "DVI-I" },
95 { DRM_MODE_CONNECTOR_DVID, "DVI-D" },
96 { DRM_MODE_CONNECTOR_DVIA, "DVI-A" },
97 { DRM_MODE_CONNECTOR_Composite, "Composite" },
98 { DRM_MODE_CONNECTOR_SVIDEO, "SVIDEO" },
99 { DRM_MODE_CONNECTOR_LVDS, "LVDS" },
100 { DRM_MODE_CONNECTOR_Component, "Component" },
101 { DRM_MODE_CONNECTOR_9PinDIN, "DIN" },
102 { DRM_MODE_CONNECTOR_DisplayPort, "DP" },
103 { DRM_MODE_CONNECTOR_HDMIA, "HDMI-A" },
104 { DRM_MODE_CONNECTOR_HDMIB, "HDMI-B" },
105 { DRM_MODE_CONNECTOR_TV, "TV" },
106 { DRM_MODE_CONNECTOR_eDP, "eDP" },
107 { DRM_MODE_CONNECTOR_VIRTUAL, "Virtual" },
108 { DRM_MODE_CONNECTOR_DSI, "DSI" },
109 { DRM_MODE_CONNECTOR_DPI, "DPI" },
110 { DRM_MODE_CONNECTOR_WRITEBACK, "Writeback" },
111 { DRM_MODE_CONNECTOR_SPI, "SPI" },
112 { DRM_MODE_CONNECTOR_USB, "USB" },
115 void drm_connector_ida_init(void)
119 for (i = 0; i < ARRAY_SIZE(drm_connector_enum_list); i++)
120 ida_init(&drm_connector_enum_list[i].ida);
123 void drm_connector_ida_destroy(void)
127 for (i = 0; i < ARRAY_SIZE(drm_connector_enum_list); i++)
128 ida_destroy(&drm_connector_enum_list[i].ida);
132 * drm_get_connector_type_name - return a string for connector type
133 * @type: The connector type (DRM_MODE_CONNECTOR_*)
135 * Returns: the name of the connector type, or NULL if the type is not valid.
137 const char *drm_get_connector_type_name(unsigned int type)
139 if (type < ARRAY_SIZE(drm_connector_enum_list))
140 return drm_connector_enum_list[type].name;
144 EXPORT_SYMBOL(drm_get_connector_type_name);
147 * drm_connector_get_cmdline_mode - reads the user's cmdline mode
148 * @connector: connector to query
150 * The kernel supports per-connector configuration of its consoles through
151 * use of the video= parameter. This function parses that option and
152 * extracts the user's specified mode (or enable/disable status) for a
153 * particular connector. This is typically only used during the early fbdev
156 static void drm_connector_get_cmdline_mode(struct drm_connector *connector)
158 struct drm_cmdline_mode *mode = &connector->cmdline_mode;
161 option = video_get_options(connector->name);
165 if (!drm_mode_parse_command_line_for_connector(option,
171 DRM_INFO("forcing %s connector %s\n", connector->name,
172 drm_get_connector_force_name(mode->force));
173 connector->force = mode->force;
176 if (mode->panel_orientation != DRM_MODE_PANEL_ORIENTATION_UNKNOWN) {
177 DRM_INFO("cmdline forces connector %s panel_orientation to %d\n",
178 connector->name, mode->panel_orientation);
179 drm_connector_set_panel_orientation(connector,
180 mode->panel_orientation);
183 DRM_DEBUG_KMS("cmdline mode for connector %s %s %dx%d@%dHz%s%s%s\n",
184 connector->name, mode->name,
185 mode->xres, mode->yres,
186 mode->refresh_specified ? mode->refresh : 60,
187 mode->rb ? " reduced blanking" : "",
188 mode->margins ? " with margins" : "",
189 mode->interlace ? " interlaced" : "");
192 static void drm_connector_free(struct kref *kref)
194 struct drm_connector *connector =
195 container_of(kref, struct drm_connector, base.refcount);
196 struct drm_device *dev = connector->dev;
198 drm_mode_object_unregister(dev, &connector->base);
199 connector->funcs->destroy(connector);
202 void drm_connector_free_work_fn(struct work_struct *work)
204 struct drm_connector *connector, *n;
205 struct drm_device *dev =
206 container_of(work, struct drm_device, mode_config.connector_free_work);
207 struct drm_mode_config *config = &dev->mode_config;
209 struct llist_node *freed;
211 spin_lock_irqsave(&config->connector_list_lock, flags);
212 freed = llist_del_all(&config->connector_free_list);
213 spin_unlock_irqrestore(&config->connector_list_lock, flags);
215 llist_for_each_entry_safe(connector, n, freed, free_node) {
216 drm_mode_object_unregister(dev, &connector->base);
217 connector->funcs->destroy(connector);
221 static int __drm_connector_init(struct drm_device *dev,
222 struct drm_connector *connector,
223 const struct drm_connector_funcs *funcs,
225 struct i2c_adapter *ddc)
227 struct drm_mode_config *config = &dev->mode_config;
229 struct ida *connector_ida =
230 &drm_connector_enum_list[connector_type].ida;
232 WARN_ON(drm_drv_uses_atomic_modeset(dev) &&
233 (!funcs->atomic_destroy_state ||
234 !funcs->atomic_duplicate_state));
236 ret = __drm_mode_object_add(dev, &connector->base,
237 DRM_MODE_OBJECT_CONNECTOR,
238 false, drm_connector_free);
242 connector->base.properties = &connector->properties;
243 connector->dev = dev;
244 connector->funcs = funcs;
246 /* connector index is used with 32bit bitmasks */
247 ret = ida_alloc_max(&config->connector_ida, 31, GFP_KERNEL);
249 DRM_DEBUG_KMS("Failed to allocate %s connector index: %d\n",
250 drm_connector_enum_list[connector_type].name,
254 connector->index = ret;
257 connector->connector_type = connector_type;
258 connector->connector_type_id =
259 ida_alloc_min(connector_ida, 1, GFP_KERNEL);
260 if (connector->connector_type_id < 0) {
261 ret = connector->connector_type_id;
265 kasprintf(GFP_KERNEL, "%s-%d",
266 drm_connector_enum_list[connector_type].name,
267 connector->connector_type_id);
268 if (!connector->name) {
270 goto out_put_type_id;
273 /* provide ddc symlink in sysfs */
274 connector->ddc = ddc;
276 INIT_LIST_HEAD(&connector->global_connector_list_entry);
277 INIT_LIST_HEAD(&connector->probed_modes);
278 INIT_LIST_HEAD(&connector->modes);
279 mutex_init(&connector->mutex);
280 mutex_init(&connector->edid_override_mutex);
281 connector->edid_blob_ptr = NULL;
282 connector->epoch_counter = 0;
283 connector->tile_blob_ptr = NULL;
284 connector->status = connector_status_unknown;
285 connector->display_info.panel_orientation =
286 DRM_MODE_PANEL_ORIENTATION_UNKNOWN;
288 drm_connector_get_cmdline_mode(connector);
290 /* We should add connectors at the end to avoid upsetting the connector
293 spin_lock_irq(&config->connector_list_lock);
294 list_add_tail(&connector->head, &config->connector_list);
295 config->num_connector++;
296 spin_unlock_irq(&config->connector_list_lock);
298 if (connector_type != DRM_MODE_CONNECTOR_VIRTUAL &&
299 connector_type != DRM_MODE_CONNECTOR_WRITEBACK)
300 drm_connector_attach_edid_property(connector);
302 drm_object_attach_property(&connector->base,
303 config->dpms_property, 0);
305 drm_object_attach_property(&connector->base,
306 config->link_status_property,
309 drm_object_attach_property(&connector->base,
310 config->non_desktop_property,
312 drm_object_attach_property(&connector->base,
313 config->tile_property,
316 if (drm_core_check_feature(dev, DRIVER_ATOMIC)) {
317 drm_object_attach_property(&connector->base, config->prop_crtc_id, 0);
320 connector->debugfs_entry = NULL;
323 ida_free(connector_ida, connector->connector_type_id);
326 ida_free(&config->connector_ida, connector->index);
329 drm_mode_object_unregister(dev, &connector->base);
335 * drm_connector_init - Init a preallocated connector
337 * @connector: the connector to init
338 * @funcs: callbacks for this connector
339 * @connector_type: user visible type of the connector
341 * Initialises a preallocated connector. Connectors should be
342 * subclassed as part of driver connector objects.
344 * At driver unload time the driver's &drm_connector_funcs.destroy hook
345 * should call drm_connector_cleanup() and free the connector structure.
346 * The connector structure should not be allocated with devm_kzalloc().
348 * Note: consider using drmm_connector_init() instead of
349 * drm_connector_init() to let the DRM managed resource infrastructure
350 * take care of cleanup and deallocation.
353 * Zero on success, error code on failure.
355 int drm_connector_init(struct drm_device *dev,
356 struct drm_connector *connector,
357 const struct drm_connector_funcs *funcs,
360 if (drm_WARN_ON(dev, !(funcs && funcs->destroy)))
363 return __drm_connector_init(dev, connector, funcs, connector_type, NULL);
365 EXPORT_SYMBOL(drm_connector_init);
368 * drm_connector_init_with_ddc - Init a preallocated connector
370 * @connector: the connector to init
371 * @funcs: callbacks for this connector
372 * @connector_type: user visible type of the connector
373 * @ddc: pointer to the associated ddc adapter
375 * Initialises a preallocated connector. Connectors should be
376 * subclassed as part of driver connector objects.
378 * At driver unload time the driver's &drm_connector_funcs.destroy hook
379 * should call drm_connector_cleanup() and free the connector structure.
380 * The connector structure should not be allocated with devm_kzalloc().
382 * Ensures that the ddc field of the connector is correctly set.
384 * Note: consider using drmm_connector_init() instead of
385 * drm_connector_init_with_ddc() to let the DRM managed resource
386 * infrastructure take care of cleanup and deallocation.
389 * Zero on success, error code on failure.
391 int drm_connector_init_with_ddc(struct drm_device *dev,
392 struct drm_connector *connector,
393 const struct drm_connector_funcs *funcs,
395 struct i2c_adapter *ddc)
397 if (drm_WARN_ON(dev, !(funcs && funcs->destroy)))
400 return __drm_connector_init(dev, connector, funcs, connector_type, ddc);
402 EXPORT_SYMBOL(drm_connector_init_with_ddc);
404 static void drm_connector_cleanup_action(struct drm_device *dev,
407 struct drm_connector *connector = ptr;
409 drm_connector_cleanup(connector);
413 * drmm_connector_init - Init a preallocated connector
415 * @connector: the connector to init
416 * @funcs: callbacks for this connector
417 * @connector_type: user visible type of the connector
418 * @ddc: optional pointer to the associated ddc adapter
420 * Initialises a preallocated connector. Connectors should be
421 * subclassed as part of driver connector objects.
423 * Cleanup is automatically handled with a call to
424 * drm_connector_cleanup() in a DRM-managed action.
426 * The connector structure should be allocated with drmm_kzalloc().
429 * Zero on success, error code on failure.
431 int drmm_connector_init(struct drm_device *dev,
432 struct drm_connector *connector,
433 const struct drm_connector_funcs *funcs,
435 struct i2c_adapter *ddc)
439 if (drm_WARN_ON(dev, funcs && funcs->destroy))
442 ret = __drm_connector_init(dev, connector, funcs, connector_type, ddc);
446 ret = drmm_add_action_or_reset(dev, drm_connector_cleanup_action,
453 EXPORT_SYMBOL(drmm_connector_init);
456 * drm_connector_attach_edid_property - attach edid property.
457 * @connector: the connector
459 * Some connector types like DRM_MODE_CONNECTOR_VIRTUAL do not get a
460 * edid property attached by default. This function can be used to
461 * explicitly enable the edid property in these cases.
463 void drm_connector_attach_edid_property(struct drm_connector *connector)
465 struct drm_mode_config *config = &connector->dev->mode_config;
467 drm_object_attach_property(&connector->base,
468 config->edid_property,
471 EXPORT_SYMBOL(drm_connector_attach_edid_property);
474 * drm_connector_attach_encoder - attach a connector to an encoder
475 * @connector: connector to attach
476 * @encoder: encoder to attach @connector to
478 * This function links up a connector to an encoder. Note that the routing
479 * restrictions between encoders and crtcs are exposed to userspace through the
480 * possible_clones and possible_crtcs bitmasks.
483 * Zero on success, negative errno on failure.
485 int drm_connector_attach_encoder(struct drm_connector *connector,
486 struct drm_encoder *encoder)
489 * In the past, drivers have attempted to model the static association
490 * of connector to encoder in simple connector/encoder devices using a
491 * direct assignment of connector->encoder = encoder. This connection
492 * is a logical one and the responsibility of the core, so drivers are
493 * expected not to mess with this.
495 * Note that the error return should've been enough here, but a large
496 * majority of drivers ignores the return value, so add in a big WARN
497 * to get people's attention.
499 if (WARN_ON(connector->encoder))
502 connector->possible_encoders |= drm_encoder_mask(encoder);
506 EXPORT_SYMBOL(drm_connector_attach_encoder);
509 * drm_connector_has_possible_encoder - check if the connector and encoder are
510 * associated with each other
511 * @connector: the connector
512 * @encoder: the encoder
515 * True if @encoder is one of the possible encoders for @connector.
517 bool drm_connector_has_possible_encoder(struct drm_connector *connector,
518 struct drm_encoder *encoder)
520 return connector->possible_encoders & drm_encoder_mask(encoder);
522 EXPORT_SYMBOL(drm_connector_has_possible_encoder);
524 static void drm_mode_remove(struct drm_connector *connector,
525 struct drm_display_mode *mode)
527 list_del(&mode->head);
528 drm_mode_destroy(connector->dev, mode);
532 * drm_connector_cleanup - cleans up an initialised connector
533 * @connector: connector to cleanup
535 * Cleans up the connector but doesn't free the object.
537 void drm_connector_cleanup(struct drm_connector *connector)
539 struct drm_device *dev = connector->dev;
540 struct drm_display_mode *mode, *t;
542 /* The connector should have been removed from userspace long before
543 * it is finally destroyed.
545 if (WARN_ON(connector->registration_state ==
546 DRM_CONNECTOR_REGISTERED))
547 drm_connector_unregister(connector);
549 if (connector->privacy_screen) {
550 drm_privacy_screen_put(connector->privacy_screen);
551 connector->privacy_screen = NULL;
554 if (connector->tile_group) {
555 drm_mode_put_tile_group(dev, connector->tile_group);
556 connector->tile_group = NULL;
559 list_for_each_entry_safe(mode, t, &connector->probed_modes, head)
560 drm_mode_remove(connector, mode);
562 list_for_each_entry_safe(mode, t, &connector->modes, head)
563 drm_mode_remove(connector, mode);
565 ida_free(&drm_connector_enum_list[connector->connector_type].ida,
566 connector->connector_type_id);
568 ida_free(&dev->mode_config.connector_ida, connector->index);
570 kfree(connector->display_info.bus_formats);
571 kfree(connector->display_info.vics);
572 drm_mode_object_unregister(dev, &connector->base);
573 kfree(connector->name);
574 connector->name = NULL;
575 fwnode_handle_put(connector->fwnode);
576 connector->fwnode = NULL;
577 spin_lock_irq(&dev->mode_config.connector_list_lock);
578 list_del(&connector->head);
579 dev->mode_config.num_connector--;
580 spin_unlock_irq(&dev->mode_config.connector_list_lock);
582 WARN_ON(connector->state && !connector->funcs->atomic_destroy_state);
583 if (connector->state && connector->funcs->atomic_destroy_state)
584 connector->funcs->atomic_destroy_state(connector,
587 mutex_destroy(&connector->mutex);
589 memset(connector, 0, sizeof(*connector));
592 drm_sysfs_hotplug_event(dev);
594 EXPORT_SYMBOL(drm_connector_cleanup);
597 * drm_connector_register - register a connector
598 * @connector: the connector to register
600 * Register userspace interfaces for a connector. Only call this for connectors
601 * which can be hotplugged after drm_dev_register() has been called already,
602 * e.g. DP MST connectors. All other connectors will be registered automatically
603 * when calling drm_dev_register().
605 * When the connector is no longer available, callers must call
606 * drm_connector_unregister().
609 * Zero on success, error code on failure.
611 int drm_connector_register(struct drm_connector *connector)
615 if (!connector->dev->registered)
618 mutex_lock(&connector->mutex);
619 if (connector->registration_state != DRM_CONNECTOR_INITIALIZING)
622 ret = drm_sysfs_connector_add(connector);
626 drm_debugfs_connector_add(connector);
628 if (connector->funcs->late_register) {
629 ret = connector->funcs->late_register(connector);
634 drm_mode_object_register(connector->dev, &connector->base);
636 connector->registration_state = DRM_CONNECTOR_REGISTERED;
638 /* Let userspace know we have a new connector */
639 drm_sysfs_connector_hotplug_event(connector);
641 if (connector->privacy_screen)
642 drm_privacy_screen_register_notifier(connector->privacy_screen,
643 &connector->privacy_screen_notifier);
645 mutex_lock(&connector_list_lock);
646 list_add_tail(&connector->global_connector_list_entry, &connector_list);
647 mutex_unlock(&connector_list_lock);
651 drm_debugfs_connector_remove(connector);
652 drm_sysfs_connector_remove(connector);
654 mutex_unlock(&connector->mutex);
657 EXPORT_SYMBOL(drm_connector_register);
660 * drm_connector_unregister - unregister a connector
661 * @connector: the connector to unregister
663 * Unregister userspace interfaces for a connector. Only call this for
664 * connectors which have been registered explicitly by calling
665 * drm_connector_register().
667 void drm_connector_unregister(struct drm_connector *connector)
669 mutex_lock(&connector->mutex);
670 if (connector->registration_state != DRM_CONNECTOR_REGISTERED) {
671 mutex_unlock(&connector->mutex);
675 mutex_lock(&connector_list_lock);
676 list_del_init(&connector->global_connector_list_entry);
677 mutex_unlock(&connector_list_lock);
679 if (connector->privacy_screen)
680 drm_privacy_screen_unregister_notifier(
681 connector->privacy_screen,
682 &connector->privacy_screen_notifier);
684 if (connector->funcs->early_unregister)
685 connector->funcs->early_unregister(connector);
687 drm_sysfs_connector_remove(connector);
688 drm_debugfs_connector_remove(connector);
690 connector->registration_state = DRM_CONNECTOR_UNREGISTERED;
691 mutex_unlock(&connector->mutex);
693 EXPORT_SYMBOL(drm_connector_unregister);
695 void drm_connector_unregister_all(struct drm_device *dev)
697 struct drm_connector *connector;
698 struct drm_connector_list_iter conn_iter;
700 drm_connector_list_iter_begin(dev, &conn_iter);
701 drm_for_each_connector_iter(connector, &conn_iter)
702 drm_connector_unregister(connector);
703 drm_connector_list_iter_end(&conn_iter);
706 int drm_connector_register_all(struct drm_device *dev)
708 struct drm_connector *connector;
709 struct drm_connector_list_iter conn_iter;
712 drm_connector_list_iter_begin(dev, &conn_iter);
713 drm_for_each_connector_iter(connector, &conn_iter) {
714 ret = drm_connector_register(connector);
718 drm_connector_list_iter_end(&conn_iter);
721 drm_connector_unregister_all(dev);
726 * drm_get_connector_status_name - return a string for connector status
727 * @status: connector status to compute name of
729 * In contrast to the other drm_get_*_name functions this one here returns a
730 * const pointer and hence is threadsafe.
732 * Returns: connector status string
734 const char *drm_get_connector_status_name(enum drm_connector_status status)
736 if (status == connector_status_connected)
738 else if (status == connector_status_disconnected)
739 return "disconnected";
743 EXPORT_SYMBOL(drm_get_connector_status_name);
746 * drm_get_connector_force_name - return a string for connector force
747 * @force: connector force to get name of
749 * Returns: const pointer to name.
751 const char *drm_get_connector_force_name(enum drm_connector_force force)
754 case DRM_FORCE_UNSPECIFIED:
755 return "unspecified";
760 case DRM_FORCE_ON_DIGITAL:
767 #ifdef CONFIG_LOCKDEP
768 static struct lockdep_map connector_list_iter_dep_map = {
769 .name = "drm_connector_list_iter"
774 * drm_connector_list_iter_begin - initialize a connector_list iterator
776 * @iter: connector_list iterator
778 * Sets @iter up to walk the &drm_mode_config.connector_list of @dev. @iter
779 * must always be cleaned up again by calling drm_connector_list_iter_end().
780 * Iteration itself happens using drm_connector_list_iter_next() or
781 * drm_for_each_connector_iter().
783 void drm_connector_list_iter_begin(struct drm_device *dev,
784 struct drm_connector_list_iter *iter)
788 lock_acquire_shared_recursive(&connector_list_iter_dep_map, 0, 1, NULL, _RET_IP_);
790 EXPORT_SYMBOL(drm_connector_list_iter_begin);
793 * Extra-safe connector put function that works in any context. Should only be
794 * used from the connector_iter functions, where we never really expect to
795 * actually release the connector when dropping our final reference.
798 __drm_connector_put_safe(struct drm_connector *conn)
800 struct drm_mode_config *config = &conn->dev->mode_config;
802 lockdep_assert_held(&config->connector_list_lock);
804 if (!refcount_dec_and_test(&conn->base.refcount.refcount))
807 llist_add(&conn->free_node, &config->connector_free_list);
808 schedule_work(&config->connector_free_work);
812 * drm_connector_list_iter_next - return next connector
813 * @iter: connector_list iterator
815 * Returns: the next connector for @iter, or NULL when the list walk has
818 struct drm_connector *
819 drm_connector_list_iter_next(struct drm_connector_list_iter *iter)
821 struct drm_connector *old_conn = iter->conn;
822 struct drm_mode_config *config = &iter->dev->mode_config;
823 struct list_head *lhead;
826 spin_lock_irqsave(&config->connector_list_lock, flags);
827 lhead = old_conn ? &old_conn->head : &config->connector_list;
830 if (lhead->next == &config->connector_list) {
836 iter->conn = list_entry(lhead, struct drm_connector, head);
838 /* loop until it's not a zombie connector */
839 } while (!kref_get_unless_zero(&iter->conn->base.refcount));
842 __drm_connector_put_safe(old_conn);
843 spin_unlock_irqrestore(&config->connector_list_lock, flags);
847 EXPORT_SYMBOL(drm_connector_list_iter_next);
850 * drm_connector_list_iter_end - tear down a connector_list iterator
851 * @iter: connector_list iterator
853 * Tears down @iter and releases any resources (like &drm_connector references)
854 * acquired while walking the list. This must always be called, both when the
855 * iteration completes fully or when it was aborted without walking the entire
858 void drm_connector_list_iter_end(struct drm_connector_list_iter *iter)
860 struct drm_mode_config *config = &iter->dev->mode_config;
865 spin_lock_irqsave(&config->connector_list_lock, flags);
866 __drm_connector_put_safe(iter->conn);
867 spin_unlock_irqrestore(&config->connector_list_lock, flags);
869 lock_release(&connector_list_iter_dep_map, _RET_IP_);
871 EXPORT_SYMBOL(drm_connector_list_iter_end);
873 static const struct drm_prop_enum_list drm_subpixel_enum_list[] = {
874 { SubPixelUnknown, "Unknown" },
875 { SubPixelHorizontalRGB, "Horizontal RGB" },
876 { SubPixelHorizontalBGR, "Horizontal BGR" },
877 { SubPixelVerticalRGB, "Vertical RGB" },
878 { SubPixelVerticalBGR, "Vertical BGR" },
879 { SubPixelNone, "None" },
883 * drm_get_subpixel_order_name - return a string for a given subpixel enum
884 * @order: enum of subpixel_order
886 * Note you could abuse this and return something out of bounds, but that
887 * would be a caller error. No unscrubbed user data should make it here.
889 * Returns: string describing an enumerated subpixel property
891 const char *drm_get_subpixel_order_name(enum subpixel_order order)
893 return drm_subpixel_enum_list[order].name;
895 EXPORT_SYMBOL(drm_get_subpixel_order_name);
897 static const struct drm_prop_enum_list drm_dpms_enum_list[] = {
898 { DRM_MODE_DPMS_ON, "On" },
899 { DRM_MODE_DPMS_STANDBY, "Standby" },
900 { DRM_MODE_DPMS_SUSPEND, "Suspend" },
901 { DRM_MODE_DPMS_OFF, "Off" }
903 DRM_ENUM_NAME_FN(drm_get_dpms_name, drm_dpms_enum_list)
905 static const struct drm_prop_enum_list drm_link_status_enum_list[] = {
906 { DRM_MODE_LINK_STATUS_GOOD, "Good" },
907 { DRM_MODE_LINK_STATUS_BAD, "Bad" },
911 * drm_display_info_set_bus_formats - set the supported bus formats
912 * @info: display info to store bus formats in
913 * @formats: array containing the supported bus formats
914 * @num_formats: the number of entries in the fmts array
916 * Store the supported bus formats in display info structure.
917 * See MEDIA_BUS_FMT_* definitions in include/uapi/linux/media-bus-format.h for
918 * a full list of available formats.
921 * 0 on success or a negative error code on failure.
923 int drm_display_info_set_bus_formats(struct drm_display_info *info,
925 unsigned int num_formats)
929 if (!formats && num_formats)
932 if (formats && num_formats) {
933 fmts = kmemdup(formats, sizeof(*formats) * num_formats,
939 kfree(info->bus_formats);
940 info->bus_formats = fmts;
941 info->num_bus_formats = num_formats;
945 EXPORT_SYMBOL(drm_display_info_set_bus_formats);
947 /* Optional connector properties. */
948 static const struct drm_prop_enum_list drm_scaling_mode_enum_list[] = {
949 { DRM_MODE_SCALE_NONE, "None" },
950 { DRM_MODE_SCALE_FULLSCREEN, "Full" },
951 { DRM_MODE_SCALE_CENTER, "Center" },
952 { DRM_MODE_SCALE_ASPECT, "Full aspect" },
955 static const struct drm_prop_enum_list drm_aspect_ratio_enum_list[] = {
956 { DRM_MODE_PICTURE_ASPECT_NONE, "Automatic" },
957 { DRM_MODE_PICTURE_ASPECT_4_3, "4:3" },
958 { DRM_MODE_PICTURE_ASPECT_16_9, "16:9" },
961 static const struct drm_prop_enum_list drm_content_type_enum_list[] = {
962 { DRM_MODE_CONTENT_TYPE_NO_DATA, "No Data" },
963 { DRM_MODE_CONTENT_TYPE_GRAPHICS, "Graphics" },
964 { DRM_MODE_CONTENT_TYPE_PHOTO, "Photo" },
965 { DRM_MODE_CONTENT_TYPE_CINEMA, "Cinema" },
966 { DRM_MODE_CONTENT_TYPE_GAME, "Game" },
969 static const struct drm_prop_enum_list drm_panel_orientation_enum_list[] = {
970 { DRM_MODE_PANEL_ORIENTATION_NORMAL, "Normal" },
971 { DRM_MODE_PANEL_ORIENTATION_BOTTOM_UP, "Upside Down" },
972 { DRM_MODE_PANEL_ORIENTATION_LEFT_UP, "Left Side Up" },
973 { DRM_MODE_PANEL_ORIENTATION_RIGHT_UP, "Right Side Up" },
976 static const struct drm_prop_enum_list drm_dvi_i_select_enum_list[] = {
977 { DRM_MODE_SUBCONNECTOR_Automatic, "Automatic" }, /* DVI-I and TV-out */
978 { DRM_MODE_SUBCONNECTOR_DVID, "DVI-D" }, /* DVI-I */
979 { DRM_MODE_SUBCONNECTOR_DVIA, "DVI-A" }, /* DVI-I */
981 DRM_ENUM_NAME_FN(drm_get_dvi_i_select_name, drm_dvi_i_select_enum_list)
983 static const struct drm_prop_enum_list drm_dvi_i_subconnector_enum_list[] = {
984 { DRM_MODE_SUBCONNECTOR_Unknown, "Unknown" }, /* DVI-I, TV-out and DP */
985 { DRM_MODE_SUBCONNECTOR_DVID, "DVI-D" }, /* DVI-I */
986 { DRM_MODE_SUBCONNECTOR_DVIA, "DVI-A" }, /* DVI-I */
988 DRM_ENUM_NAME_FN(drm_get_dvi_i_subconnector_name,
989 drm_dvi_i_subconnector_enum_list)
991 static const struct drm_prop_enum_list drm_tv_mode_enum_list[] = {
992 { DRM_MODE_TV_MODE_NTSC, "NTSC" },
993 { DRM_MODE_TV_MODE_NTSC_443, "NTSC-443" },
994 { DRM_MODE_TV_MODE_NTSC_J, "NTSC-J" },
995 { DRM_MODE_TV_MODE_PAL, "PAL" },
996 { DRM_MODE_TV_MODE_PAL_M, "PAL-M" },
997 { DRM_MODE_TV_MODE_PAL_N, "PAL-N" },
998 { DRM_MODE_TV_MODE_SECAM, "SECAM" },
1000 DRM_ENUM_NAME_FN(drm_get_tv_mode_name, drm_tv_mode_enum_list)
1003 * drm_get_tv_mode_from_name - Translates a TV mode name into its enum value
1004 * @name: TV Mode name we want to convert
1005 * @len: Length of @name
1007 * Translates @name into an enum drm_connector_tv_mode.
1009 * Returns: the enum value on success, a negative errno otherwise.
1011 int drm_get_tv_mode_from_name(const char *name, size_t len)
1015 for (i = 0; i < ARRAY_SIZE(drm_tv_mode_enum_list); i++) {
1016 const struct drm_prop_enum_list *item = &drm_tv_mode_enum_list[i];
1018 if (strlen(item->name) == len && !strncmp(item->name, name, len))
1024 EXPORT_SYMBOL(drm_get_tv_mode_from_name);
1026 static const struct drm_prop_enum_list drm_tv_select_enum_list[] = {
1027 { DRM_MODE_SUBCONNECTOR_Automatic, "Automatic" }, /* DVI-I and TV-out */
1028 { DRM_MODE_SUBCONNECTOR_Composite, "Composite" }, /* TV-out */
1029 { DRM_MODE_SUBCONNECTOR_SVIDEO, "SVIDEO" }, /* TV-out */
1030 { DRM_MODE_SUBCONNECTOR_Component, "Component" }, /* TV-out */
1031 { DRM_MODE_SUBCONNECTOR_SCART, "SCART" }, /* TV-out */
1033 DRM_ENUM_NAME_FN(drm_get_tv_select_name, drm_tv_select_enum_list)
1035 static const struct drm_prop_enum_list drm_tv_subconnector_enum_list[] = {
1036 { DRM_MODE_SUBCONNECTOR_Unknown, "Unknown" }, /* DVI-I, TV-out and DP */
1037 { DRM_MODE_SUBCONNECTOR_Composite, "Composite" }, /* TV-out */
1038 { DRM_MODE_SUBCONNECTOR_SVIDEO, "SVIDEO" }, /* TV-out */
1039 { DRM_MODE_SUBCONNECTOR_Component, "Component" }, /* TV-out */
1040 { DRM_MODE_SUBCONNECTOR_SCART, "SCART" }, /* TV-out */
1042 DRM_ENUM_NAME_FN(drm_get_tv_subconnector_name,
1043 drm_tv_subconnector_enum_list)
1045 static const struct drm_prop_enum_list drm_dp_subconnector_enum_list[] = {
1046 { DRM_MODE_SUBCONNECTOR_Unknown, "Unknown" }, /* DVI-I, TV-out and DP */
1047 { DRM_MODE_SUBCONNECTOR_VGA, "VGA" }, /* DP */
1048 { DRM_MODE_SUBCONNECTOR_DVID, "DVI-D" }, /* DP */
1049 { DRM_MODE_SUBCONNECTOR_HDMIA, "HDMI" }, /* DP */
1050 { DRM_MODE_SUBCONNECTOR_DisplayPort, "DP" }, /* DP */
1051 { DRM_MODE_SUBCONNECTOR_Wireless, "Wireless" }, /* DP */
1052 { DRM_MODE_SUBCONNECTOR_Native, "Native" }, /* DP */
1055 DRM_ENUM_NAME_FN(drm_get_dp_subconnector_name,
1056 drm_dp_subconnector_enum_list)
1059 static const char * const colorspace_names[] = {
1060 /* For Default case, driver will set the colorspace */
1061 [DRM_MODE_COLORIMETRY_DEFAULT] = "Default",
1062 /* Standard Definition Colorimetry based on CEA 861 */
1063 [DRM_MODE_COLORIMETRY_SMPTE_170M_YCC] = "SMPTE_170M_YCC",
1064 [DRM_MODE_COLORIMETRY_BT709_YCC] = "BT709_YCC",
1065 /* Standard Definition Colorimetry based on IEC 61966-2-4 */
1066 [DRM_MODE_COLORIMETRY_XVYCC_601] = "XVYCC_601",
1067 /* High Definition Colorimetry based on IEC 61966-2-4 */
1068 [DRM_MODE_COLORIMETRY_XVYCC_709] = "XVYCC_709",
1069 /* Colorimetry based on IEC 61966-2-1/Amendment 1 */
1070 [DRM_MODE_COLORIMETRY_SYCC_601] = "SYCC_601",
1071 /* Colorimetry based on IEC 61966-2-5 [33] */
1072 [DRM_MODE_COLORIMETRY_OPYCC_601] = "opYCC_601",
1073 /* Colorimetry based on IEC 61966-2-5 */
1074 [DRM_MODE_COLORIMETRY_OPRGB] = "opRGB",
1075 /* Colorimetry based on ITU-R BT.2020 */
1076 [DRM_MODE_COLORIMETRY_BT2020_CYCC] = "BT2020_CYCC",
1077 /* Colorimetry based on ITU-R BT.2020 */
1078 [DRM_MODE_COLORIMETRY_BT2020_RGB] = "BT2020_RGB",
1079 /* Colorimetry based on ITU-R BT.2020 */
1080 [DRM_MODE_COLORIMETRY_BT2020_YCC] = "BT2020_YCC",
1081 /* Added as part of Additional Colorimetry Extension in 861.G */
1082 [DRM_MODE_COLORIMETRY_DCI_P3_RGB_D65] = "DCI-P3_RGB_D65",
1083 [DRM_MODE_COLORIMETRY_DCI_P3_RGB_THEATER] = "DCI-P3_RGB_Theater",
1084 [DRM_MODE_COLORIMETRY_RGB_WIDE_FIXED] = "RGB_WIDE_FIXED",
1085 /* Colorimetry based on scRGB (IEC 61966-2-2) */
1086 [DRM_MODE_COLORIMETRY_RGB_WIDE_FLOAT] = "RGB_WIDE_FLOAT",
1087 [DRM_MODE_COLORIMETRY_BT601_YCC] = "BT601_YCC",
1091 * drm_get_colorspace_name - return a string for color encoding
1092 * @colorspace: color space to compute name of
1094 * In contrast to the other drm_get_*_name functions this one here returns a
1095 * const pointer and hence is threadsafe.
1097 const char *drm_get_colorspace_name(enum drm_colorspace colorspace)
1099 if (colorspace < ARRAY_SIZE(colorspace_names) && colorspace_names[colorspace])
1100 return colorspace_names[colorspace];
1105 static const u32 hdmi_colorspaces =
1106 BIT(DRM_MODE_COLORIMETRY_SMPTE_170M_YCC) |
1107 BIT(DRM_MODE_COLORIMETRY_BT709_YCC) |
1108 BIT(DRM_MODE_COLORIMETRY_XVYCC_601) |
1109 BIT(DRM_MODE_COLORIMETRY_XVYCC_709) |
1110 BIT(DRM_MODE_COLORIMETRY_SYCC_601) |
1111 BIT(DRM_MODE_COLORIMETRY_OPYCC_601) |
1112 BIT(DRM_MODE_COLORIMETRY_OPRGB) |
1113 BIT(DRM_MODE_COLORIMETRY_BT2020_CYCC) |
1114 BIT(DRM_MODE_COLORIMETRY_BT2020_RGB) |
1115 BIT(DRM_MODE_COLORIMETRY_BT2020_YCC) |
1116 BIT(DRM_MODE_COLORIMETRY_DCI_P3_RGB_D65) |
1117 BIT(DRM_MODE_COLORIMETRY_DCI_P3_RGB_THEATER);
1120 * As per DP 1.4a spec, 2.2.5.7.5 VSC SDP Payload for Pixel Encoding/Colorimetry
1121 * Format Table 2-120
1123 static const u32 dp_colorspaces =
1124 BIT(DRM_MODE_COLORIMETRY_RGB_WIDE_FIXED) |
1125 BIT(DRM_MODE_COLORIMETRY_RGB_WIDE_FLOAT) |
1126 BIT(DRM_MODE_COLORIMETRY_OPRGB) |
1127 BIT(DRM_MODE_COLORIMETRY_DCI_P3_RGB_D65) |
1128 BIT(DRM_MODE_COLORIMETRY_BT2020_RGB) |
1129 BIT(DRM_MODE_COLORIMETRY_BT601_YCC) |
1130 BIT(DRM_MODE_COLORIMETRY_BT709_YCC) |
1131 BIT(DRM_MODE_COLORIMETRY_XVYCC_601) |
1132 BIT(DRM_MODE_COLORIMETRY_XVYCC_709) |
1133 BIT(DRM_MODE_COLORIMETRY_SYCC_601) |
1134 BIT(DRM_MODE_COLORIMETRY_OPYCC_601) |
1135 BIT(DRM_MODE_COLORIMETRY_BT2020_CYCC) |
1136 BIT(DRM_MODE_COLORIMETRY_BT2020_YCC);
1139 * DOC: standard connector properties
1141 * DRM connectors have a few standardized properties:
1144 * Blob property which contains the current EDID read from the sink. This
1145 * is useful to parse sink identification information like vendor, model
1146 * and serial. Drivers should update this property by calling
1147 * drm_connector_update_edid_property(), usually after having parsed
1148 * the EDID using drm_add_edid_modes(). Userspace cannot change this
1151 * User-space should not parse the EDID to obtain information exposed via
1152 * other KMS properties (because the kernel might apply limits, quirks or
1153 * fixups to the EDID). For instance, user-space should not try to parse
1154 * mode lists from the EDID.
1156 * Legacy property for setting the power state of the connector. For atomic
1157 * drivers this is only provided for backwards compatibility with existing
1158 * drivers, it remaps to controlling the "ACTIVE" property on the CRTC the
1159 * connector is linked to. Drivers should never set this property directly,
1160 * it is handled by the DRM core by calling the &drm_connector_funcs.dpms
1161 * callback. For atomic drivers the remapping to the "ACTIVE" property is
1162 * implemented in the DRM core.
1164 * Note that this property cannot be set through the MODE_ATOMIC ioctl,
1165 * userspace must use "ACTIVE" on the CRTC instead.
1169 * For userspace also running on legacy drivers the "DPMS" semantics are a
1170 * lot more complicated. First, userspace cannot rely on the "DPMS" value
1171 * returned by the GETCONNECTOR actually reflecting reality, because many
1172 * drivers fail to update it. For atomic drivers this is taken care of in
1173 * drm_atomic_helper_update_legacy_modeset_state().
1175 * The second issue is that the DPMS state is only well-defined when the
1176 * connector is connected to a CRTC. In atomic the DRM core enforces that
1177 * "ACTIVE" is off in such a case, no such checks exists for "DPMS".
1179 * Finally, when enabling an output using the legacy SETCONFIG ioctl then
1180 * "DPMS" is forced to ON. But see above, that might not be reflected in
1181 * the software value on legacy drivers.
1183 * Summarizing: Only set "DPMS" when the connector is known to be enabled,
1184 * assume that a successful SETCONFIG call also sets "DPMS" to on, and
1185 * never read back the value of "DPMS" because it can be incorrect.
1187 * Connector path property to identify how this sink is physically
1188 * connected. Used by DP MST. This should be set by calling
1189 * drm_connector_set_path_property(), in the case of DP MST with the
1190 * path property the MST manager created. Userspace cannot change this
1193 * Connector tile group property to indicate how a set of DRM connector
1194 * compose together into one logical screen. This is used by both high-res
1195 * external screens (often only using a single cable, but exposing multiple
1196 * DP MST sinks), or high-res integrated panels (like dual-link DSI) which
1197 * are not gen-locked. Note that for tiled panels which are genlocked, like
1198 * dual-link LVDS or dual-link DSI, the driver should try to not expose the
1199 * tiling and virtualise both &drm_crtc and &drm_plane if needed. Drivers
1200 * should update this value using drm_connector_set_tile_property().
1201 * Userspace cannot change this property.
1203 * Connector link-status property to indicate the status of link. The
1204 * default value of link-status is "GOOD". If something fails during or
1205 * after modeset, the kernel driver may set this to "BAD" and issue a
1206 * hotplug uevent. Drivers should update this value using
1207 * drm_connector_set_link_status_property().
1209 * When user-space receives the hotplug uevent and detects a "BAD"
1210 * link-status, the sink doesn't receive pixels anymore (e.g. the screen
1211 * becomes completely black). The list of available modes may have
1212 * changed. User-space is expected to pick a new mode if the current one
1213 * has disappeared and perform a new modeset with link-status set to
1214 * "GOOD" to re-enable the connector.
1216 * If multiple connectors share the same CRTC and one of them gets a "BAD"
1217 * link-status, the other are unaffected (ie. the sinks still continue to
1220 * When user-space performs an atomic commit on a connector with a "BAD"
1221 * link-status without resetting the property to "GOOD", the sink may
1222 * still not receive pixels. When user-space performs an atomic commit
1223 * which resets the link-status property to "GOOD" without the
1224 * ALLOW_MODESET flag set, it might fail because a modeset is required.
1226 * User-space can only change link-status to "GOOD", changing it to "BAD"
1229 * For backwards compatibility with non-atomic userspace the kernel
1230 * tries to automatically set the link-status back to "GOOD" in the
1231 * SETCRTC IOCTL. This might fail if the mode is no longer valid, similar
1232 * to how it might fail if a different screen has been connected in the
1235 * Indicates the output should be ignored for purposes of displaying a
1236 * standard desktop environment or console. This is most likely because
1237 * the output device is not rectilinear.
1238 * Content Protection:
1239 * This property is used by userspace to request the kernel protect future
1240 * content communicated over the link. When requested, kernel will apply
1241 * the appropriate means of protection (most often HDCP), and use the
1242 * property to tell userspace the protection is active.
1244 * Drivers can set this up by calling
1245 * drm_connector_attach_content_protection_property() on initialization.
1247 * The value of this property can be one of the following:
1249 * DRM_MODE_CONTENT_PROTECTION_UNDESIRED = 0
1250 * The link is not protected, content is transmitted in the clear.
1251 * DRM_MODE_CONTENT_PROTECTION_DESIRED = 1
1252 * Userspace has requested content protection, but the link is not
1253 * currently protected. When in this state, kernel should enable
1254 * Content Protection as soon as possible.
1255 * DRM_MODE_CONTENT_PROTECTION_ENABLED = 2
1256 * Userspace has requested content protection, and the link is
1257 * protected. Only the driver can set the property to this value.
1258 * If userspace attempts to set to ENABLED, kernel will return
1263 * - DESIRED state should be preserved until userspace de-asserts it by
1264 * setting the property to UNDESIRED. This means ENABLED should only
1265 * transition to UNDESIRED when the user explicitly requests it.
1266 * - If the state is DESIRED, kernel should attempt to re-authenticate the
1267 * link whenever possible. This includes across disable/enable, dpms,
1268 * hotplug, downstream device changes, link status failures, etc..
1269 * - Kernel sends uevent with the connector id and property id through
1270 * @drm_hdcp_update_content_protection, upon below kernel triggered
1273 * - DESIRED -> ENABLED (authentication success)
1274 * - ENABLED -> DESIRED (termination of authentication)
1275 * - Please note no uevents for userspace triggered property state changes,
1276 * which can't fail such as
1278 * - DESIRED/ENABLED -> UNDESIRED
1279 * - UNDESIRED -> DESIRED
1280 * - Userspace is responsible for polling the property or listen to uevents
1281 * to determine when the value transitions from ENABLED to DESIRED.
1282 * This signifies the link is no longer protected and userspace should
1283 * take appropriate action (whatever that might be).
1285 * HDCP Content Type:
1286 * This Enum property is used by the userspace to declare the content type
1287 * of the display stream, to kernel. Here display stream stands for any
1288 * display content that userspace intended to display through HDCP
1291 * Content Type of a stream is decided by the owner of the stream, as
1292 * "HDCP Type0" or "HDCP Type1".
1294 * The value of the property can be one of the below:
1295 * - "HDCP Type0": DRM_MODE_HDCP_CONTENT_TYPE0 = 0
1296 * - "HDCP Type1": DRM_MODE_HDCP_CONTENT_TYPE1 = 1
1298 * When kernel starts the HDCP authentication (see "Content Protection"
1299 * for details), it uses the content type in "HDCP Content Type"
1300 * for performing the HDCP authentication with the display sink.
1302 * Please note in HDCP spec versions, a link can be authenticated with
1303 * HDCP 2.2 for Content Type 0/Content Type 1. Where as a link can be
1304 * authenticated with HDCP1.4 only for Content Type 0(though it is implicit
1305 * in nature. As there is no reference for Content Type in HDCP1.4).
1307 * HDCP2.2 authentication protocol itself takes the "Content Type" as a
1308 * parameter, which is a input for the DP HDCP2.2 encryption algo.
1310 * In case of Type 0 content protection request, kernel driver can choose
1311 * either of HDCP spec versions 1.4 and 2.2. When HDCP2.2 is used for
1312 * "HDCP Type 0", a HDCP 2.2 capable repeater in the downstream can send
1313 * that content to a HDCP 1.4 authenticated HDCP sink (Type0 link).
1314 * But if the content is classified as "HDCP Type 1", above mentioned
1315 * HDCP 2.2 repeater wont send the content to the HDCP sink as it can't
1316 * authenticate the HDCP1.4 capable sink for "HDCP Type 1".
1318 * Please note userspace can be ignorant of the HDCP versions used by the
1319 * kernel driver to achieve the "HDCP Content Type".
1321 * At current scenario, classifying a content as Type 1 ensures that the
1322 * content will be displayed only through the HDCP2.2 encrypted link.
1324 * Note that the HDCP Content Type property is introduced at HDCP 2.2, and
1325 * defaults to type 0. It is only exposed by drivers supporting HDCP 2.2
1326 * (hence supporting Type 0 and Type 1). Based on how next versions of
1327 * HDCP specs are defined content Type could be used for higher versions
1330 * If content type is changed when "Content Protection" is not UNDESIRED,
1331 * then kernel will disable the HDCP and re-enable with new type in the
1332 * same atomic commit. And when "Content Protection" is ENABLED, it means
1333 * that link is HDCP authenticated and encrypted, for the transmission of
1334 * the Type of stream mentioned at "HDCP Content Type".
1336 * HDR_OUTPUT_METADATA:
1337 * Connector property to enable userspace to send HDR Metadata to
1338 * driver. This metadata is based on the composition and blending
1339 * policies decided by user, taking into account the hardware and
1340 * sink capabilities. The driver gets this metadata and creates a
1341 * Dynamic Range and Mastering Infoframe (DRM) in case of HDMI,
1342 * SDP packet (Non-audio INFOFRAME SDP v1.3) for DP. This is then
1343 * sent to sink. This notifies the sink of the upcoming frame's Color
1344 * Encoding and Luminance parameters.
1346 * Userspace first need to detect the HDR capabilities of sink by
1347 * reading and parsing the EDID. Details of HDR metadata for HDMI
1348 * are added in CTA 861.G spec. For DP , its defined in VESA DP
1349 * Standard v1.4. It needs to then get the metadata information
1350 * of the video/game/app content which are encoded in HDR (basically
1351 * using HDR transfer functions). With this information it needs to
1352 * decide on a blending policy and compose the relevant
1353 * layers/overlays into a common format. Once this blending is done,
1354 * userspace will be aware of the metadata of the composed frame to
1355 * be send to sink. It then uses this property to communicate this
1356 * metadata to driver which then make a Infoframe packet and sends
1357 * to sink based on the type of encoder connected.
1359 * Userspace will be responsible to do Tone mapping operation in case:
1360 * - Some layers are HDR and others are SDR
1361 * - HDR layers luminance is not same as sink
1363 * It will even need to do colorspace conversion and get all layers
1364 * to one common colorspace for blending. It can use either GL, Media
1365 * or display engine to get this done based on the capabilities of the
1366 * associated hardware.
1368 * Driver expects metadata to be put in &struct hdr_output_metadata
1369 * structure from userspace. This is received as blob and stored in
1370 * &drm_connector_state.hdr_output_metadata. It parses EDID and saves the
1371 * sink metadata in &struct hdr_sink_metadata, as
1372 * &drm_connector.hdr_sink_metadata. Driver uses
1373 * drm_hdmi_infoframe_set_hdr_metadata() helper to set the HDR metadata,
1374 * hdmi_drm_infoframe_pack() to pack the infoframe as per spec, in case of
1378 * This range property is used by userspace to limit the bit depth. When
1379 * used the driver would limit the bpc in accordance with the valid range
1380 * supported by the hardware and sink. Drivers to use the function
1381 * drm_connector_attach_max_bpc_property() to create and attach the
1382 * property to the connector during initialization.
1384 * Connectors also have one standardized atomic property:
1387 * Mode object ID of the &drm_crtc this connector should be connected to.
1389 * Connectors for LCD panels may also have one standardized property:
1391 * panel orientation:
1392 * On some devices the LCD panel is mounted in the casing in such a way
1393 * that the up/top side of the panel does not match with the top side of
1394 * the device. Userspace can use this property to check for this.
1395 * Note that input coordinates from touchscreens (input devices with
1396 * INPUT_PROP_DIRECT) will still map 1:1 to the actual LCD panel
1397 * coordinates, so if userspace rotates the picture to adjust for
1398 * the orientation it must also apply the same transformation to the
1399 * touchscreen input coordinates. This property is initialized by calling
1400 * drm_connector_set_panel_orientation() or
1401 * drm_connector_set_panel_orientation_with_quirk()
1404 * This property defines how a non-native mode is upscaled to the native
1405 * mode of an LCD panel:
1408 * No upscaling happens, scaling is left to the panel. Not all
1409 * drivers expose this mode.
1411 * The output is upscaled to the full resolution of the panel,
1412 * ignoring the aspect ratio.
1414 * No upscaling happens, the output is centered within the native
1415 * resolution the panel.
1417 * The output is upscaled to maximize either the width or height
1418 * while retaining the aspect ratio.
1420 * This property should be set up by calling
1421 * drm_connector_attach_scaling_mode_property(). Note that drivers
1422 * can also expose this property to external outputs, in which case they
1423 * must support "None", which should be the default (since external screens
1424 * have a built-in scaler).
1427 * This property is used by DVI-I, TVout and DisplayPort to indicate different
1428 * connector subtypes. Enum values more or less match with those from main
1430 * For DVI-I and TVout there is also a matching property "select subconnector"
1431 * allowing to switch between signal types.
1432 * DP subconnector corresponds to a downstream port.
1434 * privacy-screen sw-state, privacy-screen hw-state:
1435 * These 2 optional properties can be used to query the state of the
1436 * electronic privacy screen that is available on some displays; and in
1437 * some cases also control the state. If a driver implements these
1438 * properties then both properties must be present.
1440 * "privacy-screen hw-state" is read-only and reflects the actual state
1441 * of the privacy-screen, possible values: "Enabled", "Disabled,
1442 * "Enabled-locked", "Disabled-locked". The locked states indicate
1443 * that the state cannot be changed through the DRM API. E.g. there
1444 * might be devices where the firmware-setup options, or a hardware
1445 * slider-switch, offer always on / off modes.
1447 * "privacy-screen sw-state" can be set to change the privacy-screen state
1448 * when not locked. In this case the driver must update the hw-state
1449 * property to reflect the new state on completion of the commit of the
1450 * sw-state property. Setting the sw-state property when the hw-state is
1451 * locked must be interpreted by the driver as a request to change the
1452 * state to the set state when the hw-state becomes unlocked. E.g. if
1453 * "privacy-screen hw-state" is "Enabled-locked" and the sw-state
1454 * gets set to "Disabled" followed by the user unlocking the state by
1455 * changing the slider-switch position, then the driver must set the
1456 * state to "Disabled" upon receiving the unlock event.
1458 * In some cases the privacy-screen's actual state might change outside of
1459 * control of the DRM code. E.g. there might be a firmware handled hotkey
1460 * which toggles the actual state, or the actual state might be changed
1461 * through another userspace API such as writing /proc/acpi/ibm/lcdshadow.
1462 * In this case the driver must update both the hw-state and the sw-state
1463 * to reflect the new value, overwriting any pending state requests in the
1464 * sw-state. Any pending sw-state requests are thus discarded.
1466 * Note that the ability for the state to change outside of control of
1467 * the DRM master process means that userspace must not cache the value
1468 * of the sw-state. Caching the sw-state value and including it in later
1469 * atomic commits may lead to overriding a state change done through e.g.
1470 * a firmware handled hotkey. Therefor userspace must not include the
1471 * privacy-screen sw-state in an atomic commit unless it wants to change
1474 * left margin, right margin, top margin, bottom margin:
1475 * Add margins to the connector's viewport. This is typically used to
1476 * mitigate overscan on TVs.
1478 * The value is the size in pixels of the black border which will be
1479 * added. The attached CRTC's content will be scaled to fill the whole
1480 * area inside the margin.
1482 * The margins configuration might be sent to the sink, e.g. via HDMI AVI
1485 * Drivers can set up these properties by calling
1486 * drm_mode_create_tv_margin_properties().
1489 int drm_connector_create_standard_properties(struct drm_device *dev)
1491 struct drm_property *prop;
1493 prop = drm_property_create(dev, DRM_MODE_PROP_BLOB |
1494 DRM_MODE_PROP_IMMUTABLE,
1498 dev->mode_config.edid_property = prop;
1500 prop = drm_property_create_enum(dev, 0,
1501 "DPMS", drm_dpms_enum_list,
1502 ARRAY_SIZE(drm_dpms_enum_list));
1505 dev->mode_config.dpms_property = prop;
1507 prop = drm_property_create(dev,
1508 DRM_MODE_PROP_BLOB |
1509 DRM_MODE_PROP_IMMUTABLE,
1513 dev->mode_config.path_property = prop;
1515 prop = drm_property_create(dev,
1516 DRM_MODE_PROP_BLOB |
1517 DRM_MODE_PROP_IMMUTABLE,
1521 dev->mode_config.tile_property = prop;
1523 prop = drm_property_create_enum(dev, 0, "link-status",
1524 drm_link_status_enum_list,
1525 ARRAY_SIZE(drm_link_status_enum_list));
1528 dev->mode_config.link_status_property = prop;
1530 prop = drm_property_create_bool(dev, DRM_MODE_PROP_IMMUTABLE, "non-desktop");
1533 dev->mode_config.non_desktop_property = prop;
1535 prop = drm_property_create(dev, DRM_MODE_PROP_BLOB,
1536 "HDR_OUTPUT_METADATA", 0);
1539 dev->mode_config.hdr_output_metadata_property = prop;
1545 * drm_mode_create_dvi_i_properties - create DVI-I specific connector properties
1548 * Called by a driver the first time a DVI-I connector is made.
1552 int drm_mode_create_dvi_i_properties(struct drm_device *dev)
1554 struct drm_property *dvi_i_selector;
1555 struct drm_property *dvi_i_subconnector;
1557 if (dev->mode_config.dvi_i_select_subconnector_property)
1561 drm_property_create_enum(dev, 0,
1562 "select subconnector",
1563 drm_dvi_i_select_enum_list,
1564 ARRAY_SIZE(drm_dvi_i_select_enum_list));
1565 dev->mode_config.dvi_i_select_subconnector_property = dvi_i_selector;
1567 dvi_i_subconnector = drm_property_create_enum(dev, DRM_MODE_PROP_IMMUTABLE,
1569 drm_dvi_i_subconnector_enum_list,
1570 ARRAY_SIZE(drm_dvi_i_subconnector_enum_list));
1571 dev->mode_config.dvi_i_subconnector_property = dvi_i_subconnector;
1575 EXPORT_SYMBOL(drm_mode_create_dvi_i_properties);
1578 * drm_connector_attach_dp_subconnector_property - create subconnector property for DP
1579 * @connector: drm_connector to attach property
1581 * Called by a driver when DP connector is created.
1583 void drm_connector_attach_dp_subconnector_property(struct drm_connector *connector)
1585 struct drm_mode_config *mode_config = &connector->dev->mode_config;
1587 if (!mode_config->dp_subconnector_property)
1588 mode_config->dp_subconnector_property =
1589 drm_property_create_enum(connector->dev,
1590 DRM_MODE_PROP_IMMUTABLE,
1592 drm_dp_subconnector_enum_list,
1593 ARRAY_SIZE(drm_dp_subconnector_enum_list));
1595 drm_object_attach_property(&connector->base,
1596 mode_config->dp_subconnector_property,
1597 DRM_MODE_SUBCONNECTOR_Unknown);
1599 EXPORT_SYMBOL(drm_connector_attach_dp_subconnector_property);
1602 * DOC: HDMI connector properties
1604 * content type (HDMI specific):
1605 * Indicates content type setting to be used in HDMI infoframes to indicate
1606 * content type for the external device, so that it adjusts its display
1607 * settings accordingly.
1609 * The value of this property can be one of the following:
1612 * Content type is unknown
1614 * Content type is graphics
1616 * Content type is photo
1618 * Content type is cinema
1620 * Content type is game
1622 * The meaning of each content type is defined in CTA-861-G table 15.
1624 * Drivers can set up this property by calling
1625 * drm_connector_attach_content_type_property(). Decoding to
1626 * infoframe values is done through drm_hdmi_avi_infoframe_content_type().
1630 * TODO: Document the properties:
1633 * - flicker reduction
1638 * - select subconnector
1641 * DOC: Analog TV Connector Properties
1644 * Indicates the TV Mode used on an analog TV connector. The value
1645 * of this property can be one of the following:
1648 * TV Mode is CCIR System M (aka 525-lines) together with
1649 * the NTSC Color Encoding.
1653 * TV Mode is CCIR System M (aka 525-lines) together with
1654 * the NTSC Color Encoding, but with a color subcarrier
1655 * frequency of 4.43MHz
1659 * TV Mode is CCIR System M (aka 525-lines) together with
1660 * the NTSC Color Encoding, but with a black level equal to
1661 * the blanking level.
1665 * TV Mode is CCIR System B (aka 625-lines) together with
1666 * the PAL Color Encoding.
1670 * TV Mode is CCIR System M (aka 525-lines) together with
1671 * the PAL Color Encoding.
1675 * TV Mode is CCIR System N together with the PAL Color
1676 * Encoding, a color subcarrier frequency of 3.58MHz, the
1677 * SECAM color space, and narrower channels than other PAL
1682 * TV Mode is CCIR System B (aka 625-lines) together with
1683 * the SECAM Color Encoding.
1685 * Drivers can set up this property by calling
1686 * drm_mode_create_tv_properties().
1690 * drm_connector_attach_content_type_property - attach content-type property
1691 * @connector: connector to attach content type property on.
1693 * Called by a driver the first time a HDMI connector is made.
1697 int drm_connector_attach_content_type_property(struct drm_connector *connector)
1699 if (!drm_mode_create_content_type_property(connector->dev))
1700 drm_object_attach_property(&connector->base,
1701 connector->dev->mode_config.content_type_property,
1702 DRM_MODE_CONTENT_TYPE_NO_DATA);
1705 EXPORT_SYMBOL(drm_connector_attach_content_type_property);
1708 * drm_connector_attach_tv_margin_properties - attach TV connector margin
1710 * @connector: DRM connector
1712 * Called by a driver when it needs to attach TV margin props to a connector.
1713 * Typically used on SDTV and HDMI connectors.
1715 void drm_connector_attach_tv_margin_properties(struct drm_connector *connector)
1717 struct drm_device *dev = connector->dev;
1719 drm_object_attach_property(&connector->base,
1720 dev->mode_config.tv_left_margin_property,
1722 drm_object_attach_property(&connector->base,
1723 dev->mode_config.tv_right_margin_property,
1725 drm_object_attach_property(&connector->base,
1726 dev->mode_config.tv_top_margin_property,
1728 drm_object_attach_property(&connector->base,
1729 dev->mode_config.tv_bottom_margin_property,
1732 EXPORT_SYMBOL(drm_connector_attach_tv_margin_properties);
1735 * drm_mode_create_tv_margin_properties - create TV connector margin properties
1738 * Called by a driver's HDMI connector initialization routine, this function
1739 * creates the TV margin properties for a given device. No need to call this
1740 * function for an SDTV connector, it's already called from
1741 * drm_mode_create_tv_properties_legacy().
1744 * 0 on success or a negative error code on failure.
1746 int drm_mode_create_tv_margin_properties(struct drm_device *dev)
1748 if (dev->mode_config.tv_left_margin_property)
1751 dev->mode_config.tv_left_margin_property =
1752 drm_property_create_range(dev, 0, "left margin", 0, 100);
1753 if (!dev->mode_config.tv_left_margin_property)
1756 dev->mode_config.tv_right_margin_property =
1757 drm_property_create_range(dev, 0, "right margin", 0, 100);
1758 if (!dev->mode_config.tv_right_margin_property)
1761 dev->mode_config.tv_top_margin_property =
1762 drm_property_create_range(dev, 0, "top margin", 0, 100);
1763 if (!dev->mode_config.tv_top_margin_property)
1766 dev->mode_config.tv_bottom_margin_property =
1767 drm_property_create_range(dev, 0, "bottom margin", 0, 100);
1768 if (!dev->mode_config.tv_bottom_margin_property)
1773 EXPORT_SYMBOL(drm_mode_create_tv_margin_properties);
1776 * drm_mode_create_tv_properties_legacy - create TV specific connector properties
1778 * @num_modes: number of different TV formats (modes) supported
1779 * @modes: array of pointers to strings containing name of each format
1781 * Called by a driver's TV initialization routine, this function creates
1782 * the TV specific connector properties for a given device. Caller is
1783 * responsible for allocating a list of format names and passing them to
1786 * NOTE: This functions registers the deprecated "mode" connector
1787 * property to select the analog TV mode (ie, NTSC, PAL, etc.). New
1788 * drivers must use drm_mode_create_tv_properties() instead.
1791 * 0 on success or a negative error code on failure.
1793 int drm_mode_create_tv_properties_legacy(struct drm_device *dev,
1794 unsigned int num_modes,
1795 const char * const modes[])
1797 struct drm_property *tv_selector;
1798 struct drm_property *tv_subconnector;
1801 if (dev->mode_config.tv_select_subconnector_property)
1805 * Basic connector properties
1807 tv_selector = drm_property_create_enum(dev, 0,
1808 "select subconnector",
1809 drm_tv_select_enum_list,
1810 ARRAY_SIZE(drm_tv_select_enum_list));
1814 dev->mode_config.tv_select_subconnector_property = tv_selector;
1817 drm_property_create_enum(dev, DRM_MODE_PROP_IMMUTABLE,
1819 drm_tv_subconnector_enum_list,
1820 ARRAY_SIZE(drm_tv_subconnector_enum_list));
1821 if (!tv_subconnector)
1823 dev->mode_config.tv_subconnector_property = tv_subconnector;
1826 * Other, TV specific properties: margins & TV modes.
1828 if (drm_mode_create_tv_margin_properties(dev))
1832 dev->mode_config.legacy_tv_mode_property =
1833 drm_property_create(dev, DRM_MODE_PROP_ENUM,
1835 if (!dev->mode_config.legacy_tv_mode_property)
1838 for (i = 0; i < num_modes; i++)
1839 drm_property_add_enum(dev->mode_config.legacy_tv_mode_property,
1843 dev->mode_config.tv_brightness_property =
1844 drm_property_create_range(dev, 0, "brightness", 0, 100);
1845 if (!dev->mode_config.tv_brightness_property)
1848 dev->mode_config.tv_contrast_property =
1849 drm_property_create_range(dev, 0, "contrast", 0, 100);
1850 if (!dev->mode_config.tv_contrast_property)
1853 dev->mode_config.tv_flicker_reduction_property =
1854 drm_property_create_range(dev, 0, "flicker reduction", 0, 100);
1855 if (!dev->mode_config.tv_flicker_reduction_property)
1858 dev->mode_config.tv_overscan_property =
1859 drm_property_create_range(dev, 0, "overscan", 0, 100);
1860 if (!dev->mode_config.tv_overscan_property)
1863 dev->mode_config.tv_saturation_property =
1864 drm_property_create_range(dev, 0, "saturation", 0, 100);
1865 if (!dev->mode_config.tv_saturation_property)
1868 dev->mode_config.tv_hue_property =
1869 drm_property_create_range(dev, 0, "hue", 0, 100);
1870 if (!dev->mode_config.tv_hue_property)
1877 EXPORT_SYMBOL(drm_mode_create_tv_properties_legacy);
1880 * drm_mode_create_tv_properties - create TV specific connector properties
1882 * @supported_tv_modes: Bitmask of TV modes supported (See DRM_MODE_TV_MODE_*)
1884 * Called by a driver's TV initialization routine, this function creates
1885 * the TV specific connector properties for a given device.
1888 * 0 on success or a negative error code on failure.
1890 int drm_mode_create_tv_properties(struct drm_device *dev,
1891 unsigned int supported_tv_modes)
1893 struct drm_prop_enum_list tv_mode_list[DRM_MODE_TV_MODE_MAX];
1894 struct drm_property *tv_mode;
1895 unsigned int i, len = 0;
1897 if (dev->mode_config.tv_mode_property)
1900 for (i = 0; i < DRM_MODE_TV_MODE_MAX; i++) {
1901 if (!(supported_tv_modes & BIT(i)))
1904 tv_mode_list[len].type = i;
1905 tv_mode_list[len].name = drm_get_tv_mode_name(i);
1909 tv_mode = drm_property_create_enum(dev, 0, "TV mode",
1914 dev->mode_config.tv_mode_property = tv_mode;
1916 return drm_mode_create_tv_properties_legacy(dev, 0, NULL);
1918 EXPORT_SYMBOL(drm_mode_create_tv_properties);
1921 * drm_mode_create_scaling_mode_property - create scaling mode property
1924 * Called by a driver the first time it's needed, must be attached to desired
1927 * Atomic drivers should use drm_connector_attach_scaling_mode_property()
1928 * instead to correctly assign &drm_connector_state.scaling_mode
1929 * in the atomic state.
1933 int drm_mode_create_scaling_mode_property(struct drm_device *dev)
1935 struct drm_property *scaling_mode;
1937 if (dev->mode_config.scaling_mode_property)
1941 drm_property_create_enum(dev, 0, "scaling mode",
1942 drm_scaling_mode_enum_list,
1943 ARRAY_SIZE(drm_scaling_mode_enum_list));
1945 dev->mode_config.scaling_mode_property = scaling_mode;
1949 EXPORT_SYMBOL(drm_mode_create_scaling_mode_property);
1952 * DOC: Variable refresh properties
1954 * Variable refresh rate capable displays can dynamically adjust their
1955 * refresh rate by extending the duration of their vertical front porch
1956 * until page flip or timeout occurs. This can reduce or remove stuttering
1957 * and latency in scenarios where the page flip does not align with the
1960 * An example scenario would be an application flipping at a constant rate
1961 * of 48Hz on a 60Hz display. The page flip will frequently miss the vblank
1962 * interval and the same contents will be displayed twice. This can be
1963 * observed as stuttering for content with motion.
1965 * If variable refresh rate was active on a display that supported a
1966 * variable refresh range from 35Hz to 60Hz no stuttering would be observable
1967 * for the example scenario. The minimum supported variable refresh rate of
1968 * 35Hz is below the page flip frequency and the vertical front porch can
1969 * be extended until the page flip occurs. The vblank interval will be
1970 * directly aligned to the page flip rate.
1972 * Not all userspace content is suitable for use with variable refresh rate.
1973 * Large and frequent changes in vertical front porch duration may worsen
1974 * perceived stuttering for input sensitive applications.
1976 * Panel brightness will also vary with vertical front porch duration. Some
1977 * panels may have noticeable differences in brightness between the minimum
1978 * vertical front porch duration and the maximum vertical front porch duration.
1979 * Large and frequent changes in vertical front porch duration may produce
1980 * observable flickering for such panels.
1982 * Userspace control for variable refresh rate is supported via properties
1983 * on the &drm_connector and &drm_crtc objects.
1986 * Optional &drm_connector boolean property that drivers should attach
1987 * with drm_connector_attach_vrr_capable_property() on connectors that
1988 * could support variable refresh rates. Drivers should update the
1989 * property value by calling drm_connector_set_vrr_capable_property().
1991 * Absence of the property should indicate absence of support.
1994 * Default &drm_crtc boolean property that notifies the driver that the
1995 * content on the CRTC is suitable for variable refresh rate presentation.
1996 * The driver will take this property as a hint to enable variable
1997 * refresh rate support if the receiver supports it, ie. if the
1998 * "vrr_capable" property is true on the &drm_connector object. The
1999 * vertical front porch duration will be extended until page-flip or
2000 * timeout when enabled.
2002 * The minimum vertical front porch duration is defined as the vertical
2003 * front porch duration for the current mode.
2005 * The maximum vertical front porch duration is greater than or equal to
2006 * the minimum vertical front porch duration. The duration is derived
2007 * from the minimum supported variable refresh rate for the connector.
2009 * The driver may place further restrictions within these minimum
2010 * and maximum bounds.
2014 * drm_connector_attach_vrr_capable_property - creates the
2015 * vrr_capable property
2016 * @connector: connector to create the vrr_capable property on.
2018 * This is used by atomic drivers to add support for querying
2019 * variable refresh rate capability for a connector.
2022 * Zero on success, negative errno on failure.
2024 int drm_connector_attach_vrr_capable_property(
2025 struct drm_connector *connector)
2027 struct drm_device *dev = connector->dev;
2028 struct drm_property *prop;
2030 if (!connector->vrr_capable_property) {
2031 prop = drm_property_create_bool(dev, DRM_MODE_PROP_IMMUTABLE,
2036 connector->vrr_capable_property = prop;
2037 drm_object_attach_property(&connector->base, prop, 0);
2042 EXPORT_SYMBOL(drm_connector_attach_vrr_capable_property);
2045 * drm_connector_attach_scaling_mode_property - attach atomic scaling mode property
2046 * @connector: connector to attach scaling mode property on.
2047 * @scaling_mode_mask: or'ed mask of BIT(%DRM_MODE_SCALE_\*).
2049 * This is used to add support for scaling mode to atomic drivers.
2050 * The scaling mode will be set to &drm_connector_state.scaling_mode
2051 * and can be used from &drm_connector_helper_funcs->atomic_check for validation.
2053 * This is the atomic version of drm_mode_create_scaling_mode_property().
2056 * Zero on success, negative errno on failure.
2058 int drm_connector_attach_scaling_mode_property(struct drm_connector *connector,
2059 u32 scaling_mode_mask)
2061 struct drm_device *dev = connector->dev;
2062 struct drm_property *scaling_mode_property;
2064 const unsigned valid_scaling_mode_mask =
2065 (1U << ARRAY_SIZE(drm_scaling_mode_enum_list)) - 1;
2067 if (WARN_ON(hweight32(scaling_mode_mask) < 2 ||
2068 scaling_mode_mask & ~valid_scaling_mode_mask))
2071 scaling_mode_property =
2072 drm_property_create(dev, DRM_MODE_PROP_ENUM, "scaling mode",
2073 hweight32(scaling_mode_mask));
2075 if (!scaling_mode_property)
2078 for (i = 0; i < ARRAY_SIZE(drm_scaling_mode_enum_list); i++) {
2081 if (!(BIT(i) & scaling_mode_mask))
2084 ret = drm_property_add_enum(scaling_mode_property,
2085 drm_scaling_mode_enum_list[i].type,
2086 drm_scaling_mode_enum_list[i].name);
2089 drm_property_destroy(dev, scaling_mode_property);
2095 drm_object_attach_property(&connector->base,
2096 scaling_mode_property, 0);
2098 connector->scaling_mode_property = scaling_mode_property;
2102 EXPORT_SYMBOL(drm_connector_attach_scaling_mode_property);
2105 * drm_mode_create_aspect_ratio_property - create aspect ratio property
2108 * Called by a driver the first time it's needed, must be attached to desired
2112 * Zero on success, negative errno on failure.
2114 int drm_mode_create_aspect_ratio_property(struct drm_device *dev)
2116 if (dev->mode_config.aspect_ratio_property)
2119 dev->mode_config.aspect_ratio_property =
2120 drm_property_create_enum(dev, 0, "aspect ratio",
2121 drm_aspect_ratio_enum_list,
2122 ARRAY_SIZE(drm_aspect_ratio_enum_list));
2124 if (dev->mode_config.aspect_ratio_property == NULL)
2129 EXPORT_SYMBOL(drm_mode_create_aspect_ratio_property);
2132 * DOC: standard connector properties
2135 * This property helps select a suitable colorspace based on the sink
2136 * capability. Modern sink devices support wider gamut like BT2020.
2137 * This helps switch to BT2020 mode if the BT2020 encoded video stream
2138 * is being played by the user, same for any other colorspace. Thereby
2139 * giving a good visual experience to users.
2141 * The expectation from userspace is that it should parse the EDID
2142 * and get supported colorspaces. Use this property and switch to the
2143 * one supported. Sink supported colorspaces should be retrieved by
2144 * userspace from EDID and driver will not explicitly expose them.
2146 * Basically the expectation from userspace is:
2147 * - Set up CRTC DEGAMMA/CTM/GAMMA to convert to some sink
2149 * - Set this new property to let the sink know what it
2150 * converted the CRTC output to.
2151 * - This property is just to inform sink what colorspace
2152 * source is trying to drive.
2154 * Because between HDMI and DP have different colorspaces,
2155 * drm_mode_create_hdmi_colorspace_property() is used for HDMI connector and
2156 * drm_mode_create_dp_colorspace_property() is used for DP connector.
2159 static int drm_mode_create_colorspace_property(struct drm_connector *connector,
2160 u32 supported_colorspaces)
2162 struct drm_device *dev = connector->dev;
2163 u32 colorspaces = supported_colorspaces | BIT(DRM_MODE_COLORIMETRY_DEFAULT);
2164 struct drm_prop_enum_list enum_list[DRM_MODE_COLORIMETRY_COUNT];
2167 if (connector->colorspace_property)
2170 if (!supported_colorspaces) {
2171 drm_err(dev, "No supported colorspaces provded on [CONNECTOR:%d:%s]\n",
2172 connector->base.id, connector->name);
2176 if ((supported_colorspaces & -BIT(DRM_MODE_COLORIMETRY_COUNT)) != 0) {
2177 drm_err(dev, "Unknown colorspace provded on [CONNECTOR:%d:%s]\n",
2178 connector->base.id, connector->name);
2183 for (i = 0; i < DRM_MODE_COLORIMETRY_COUNT; i++) {
2184 if ((colorspaces & BIT(i)) == 0)
2187 enum_list[len].type = i;
2188 enum_list[len].name = colorspace_names[i];
2192 connector->colorspace_property =
2193 drm_property_create_enum(dev, DRM_MODE_PROP_ENUM, "Colorspace",
2197 if (!connector->colorspace_property)
2204 * drm_mode_create_hdmi_colorspace_property - create hdmi colorspace property
2205 * @connector: connector to create the Colorspace property on.
2206 * @supported_colorspaces: bitmap of supported color spaces
2208 * Called by a driver the first time it's needed, must be attached to desired
2212 * Zero on success, negative errno on failure.
2214 int drm_mode_create_hdmi_colorspace_property(struct drm_connector *connector,
2215 u32 supported_colorspaces)
2219 if (supported_colorspaces)
2220 colorspaces = supported_colorspaces & hdmi_colorspaces;
2222 colorspaces = hdmi_colorspaces;
2224 return drm_mode_create_colorspace_property(connector, colorspaces);
2226 EXPORT_SYMBOL(drm_mode_create_hdmi_colorspace_property);
2229 * drm_mode_create_dp_colorspace_property - create dp colorspace property
2230 * @connector: connector to create the Colorspace property on.
2231 * @supported_colorspaces: bitmap of supported color spaces
2233 * Called by a driver the first time it's needed, must be attached to desired
2237 * Zero on success, negative errno on failure.
2239 int drm_mode_create_dp_colorspace_property(struct drm_connector *connector,
2240 u32 supported_colorspaces)
2244 if (supported_colorspaces)
2245 colorspaces = supported_colorspaces & dp_colorspaces;
2247 colorspaces = dp_colorspaces;
2249 return drm_mode_create_colorspace_property(connector, colorspaces);
2251 EXPORT_SYMBOL(drm_mode_create_dp_colorspace_property);
2254 * drm_mode_create_content_type_property - create content type property
2257 * Called by a driver the first time it's needed, must be attached to desired
2261 * Zero on success, negative errno on failure.
2263 int drm_mode_create_content_type_property(struct drm_device *dev)
2265 if (dev->mode_config.content_type_property)
2268 dev->mode_config.content_type_property =
2269 drm_property_create_enum(dev, 0, "content type",
2270 drm_content_type_enum_list,
2271 ARRAY_SIZE(drm_content_type_enum_list));
2273 if (dev->mode_config.content_type_property == NULL)
2278 EXPORT_SYMBOL(drm_mode_create_content_type_property);
2281 * drm_mode_create_suggested_offset_properties - create suggests offset properties
2284 * Create the suggested x/y offset property for connectors.
2287 * 0 on success or a negative error code on failure.
2289 int drm_mode_create_suggested_offset_properties(struct drm_device *dev)
2291 if (dev->mode_config.suggested_x_property && dev->mode_config.suggested_y_property)
2294 dev->mode_config.suggested_x_property =
2295 drm_property_create_range(dev, DRM_MODE_PROP_IMMUTABLE, "suggested X", 0, 0xffffffff);
2297 dev->mode_config.suggested_y_property =
2298 drm_property_create_range(dev, DRM_MODE_PROP_IMMUTABLE, "suggested Y", 0, 0xffffffff);
2300 if (dev->mode_config.suggested_x_property == NULL ||
2301 dev->mode_config.suggested_y_property == NULL)
2305 EXPORT_SYMBOL(drm_mode_create_suggested_offset_properties);
2308 * drm_connector_set_path_property - set tile property on connector
2309 * @connector: connector to set property on.
2310 * @path: path to use for property; must not be NULL.
2312 * This creates a property to expose to userspace to specify a
2313 * connector path. This is mainly used for DisplayPort MST where
2314 * connectors have a topology and we want to allow userspace to give
2315 * them more meaningful names.
2318 * Zero on success, negative errno on failure.
2320 int drm_connector_set_path_property(struct drm_connector *connector,
2323 struct drm_device *dev = connector->dev;
2326 ret = drm_property_replace_global_blob(dev,
2327 &connector->path_blob_ptr,
2331 dev->mode_config.path_property);
2334 EXPORT_SYMBOL(drm_connector_set_path_property);
2337 * drm_connector_set_tile_property - set tile property on connector
2338 * @connector: connector to set property on.
2340 * This looks up the tile information for a connector, and creates a
2341 * property for userspace to parse if it exists. The property is of
2342 * the form of 8 integers using ':' as a separator.
2343 * This is used for dual port tiled displays with DisplayPort SST
2344 * or DisplayPort MST connectors.
2347 * Zero on success, errno on failure.
2349 int drm_connector_set_tile_property(struct drm_connector *connector)
2351 struct drm_device *dev = connector->dev;
2355 if (!connector->has_tile) {
2356 ret = drm_property_replace_global_blob(dev,
2357 &connector->tile_blob_ptr,
2361 dev->mode_config.tile_property);
2365 snprintf(tile, 256, "%d:%d:%d:%d:%d:%d:%d:%d",
2366 connector->tile_group->id, connector->tile_is_single_monitor,
2367 connector->num_h_tile, connector->num_v_tile,
2368 connector->tile_h_loc, connector->tile_v_loc,
2369 connector->tile_h_size, connector->tile_v_size);
2371 ret = drm_property_replace_global_blob(dev,
2372 &connector->tile_blob_ptr,
2376 dev->mode_config.tile_property);
2379 EXPORT_SYMBOL(drm_connector_set_tile_property);
2382 * drm_connector_set_link_status_property - Set link status property of a connector
2383 * @connector: drm connector
2384 * @link_status: new value of link status property (0: Good, 1: Bad)
2386 * In usual working scenario, this link status property will always be set to
2387 * "GOOD". If something fails during or after a mode set, the kernel driver
2388 * may set this link status property to "BAD". The caller then needs to send a
2389 * hotplug uevent for userspace to re-check the valid modes through
2390 * GET_CONNECTOR_IOCTL and retry modeset.
2392 * Note: Drivers cannot rely on userspace to support this property and
2393 * issue a modeset. As such, they may choose to handle issues (like
2394 * re-training a link) without userspace's intervention.
2396 * The reason for adding this property is to handle link training failures, but
2397 * it is not limited to DP or link training. For example, if we implement
2398 * asynchronous setcrtc, this property can be used to report any failures in that.
2400 void drm_connector_set_link_status_property(struct drm_connector *connector,
2401 uint64_t link_status)
2403 struct drm_device *dev = connector->dev;
2405 drm_modeset_lock(&dev->mode_config.connection_mutex, NULL);
2406 connector->state->link_status = link_status;
2407 drm_modeset_unlock(&dev->mode_config.connection_mutex);
2409 EXPORT_SYMBOL(drm_connector_set_link_status_property);
2412 * drm_connector_attach_max_bpc_property - attach "max bpc" property
2413 * @connector: connector to attach max bpc property on.
2414 * @min: The minimum bit depth supported by the connector.
2415 * @max: The maximum bit depth supported by the connector.
2417 * This is used to add support for limiting the bit depth on a connector.
2420 * Zero on success, negative errno on failure.
2422 int drm_connector_attach_max_bpc_property(struct drm_connector *connector,
2425 struct drm_device *dev = connector->dev;
2426 struct drm_property *prop;
2428 prop = connector->max_bpc_property;
2430 prop = drm_property_create_range(dev, 0, "max bpc", min, max);
2434 connector->max_bpc_property = prop;
2437 drm_object_attach_property(&connector->base, prop, max);
2438 connector->state->max_requested_bpc = max;
2439 connector->state->max_bpc = max;
2443 EXPORT_SYMBOL(drm_connector_attach_max_bpc_property);
2446 * drm_connector_attach_hdr_output_metadata_property - attach "HDR_OUTPUT_METADA" property
2447 * @connector: connector to attach the property on.
2449 * This is used to allow the userspace to send HDR Metadata to the
2453 * Zero on success, negative errno on failure.
2455 int drm_connector_attach_hdr_output_metadata_property(struct drm_connector *connector)
2457 struct drm_device *dev = connector->dev;
2458 struct drm_property *prop = dev->mode_config.hdr_output_metadata_property;
2460 drm_object_attach_property(&connector->base, prop, 0);
2464 EXPORT_SYMBOL(drm_connector_attach_hdr_output_metadata_property);
2467 * drm_connector_attach_colorspace_property - attach "Colorspace" property
2468 * @connector: connector to attach the property on.
2470 * This is used to allow the userspace to signal the output colorspace
2474 * Zero on success, negative errno on failure.
2476 int drm_connector_attach_colorspace_property(struct drm_connector *connector)
2478 struct drm_property *prop = connector->colorspace_property;
2480 drm_object_attach_property(&connector->base, prop, DRM_MODE_COLORIMETRY_DEFAULT);
2484 EXPORT_SYMBOL(drm_connector_attach_colorspace_property);
2487 * drm_connector_atomic_hdr_metadata_equal - checks if the hdr metadata changed
2488 * @old_state: old connector state to compare
2489 * @new_state: new connector state to compare
2491 * This is used by HDR-enabled drivers to test whether the HDR metadata
2492 * have changed between two different connector state (and thus probably
2493 * requires a full blown mode change).
2496 * True if the metadata are equal, False otherwise
2498 bool drm_connector_atomic_hdr_metadata_equal(struct drm_connector_state *old_state,
2499 struct drm_connector_state *new_state)
2501 struct drm_property_blob *old_blob = old_state->hdr_output_metadata;
2502 struct drm_property_blob *new_blob = new_state->hdr_output_metadata;
2504 if (!old_blob || !new_blob)
2505 return old_blob == new_blob;
2507 if (old_blob->length != new_blob->length)
2510 return !memcmp(old_blob->data, new_blob->data, old_blob->length);
2512 EXPORT_SYMBOL(drm_connector_atomic_hdr_metadata_equal);
2515 * drm_connector_set_vrr_capable_property - sets the variable refresh rate
2516 * capable property for a connector
2517 * @connector: drm connector
2518 * @capable: True if the connector is variable refresh rate capable
2520 * Should be used by atomic drivers to update the indicated support for
2521 * variable refresh rate over a connector.
2523 void drm_connector_set_vrr_capable_property(
2524 struct drm_connector *connector, bool capable)
2526 if (!connector->vrr_capable_property)
2529 drm_object_property_set_value(&connector->base,
2530 connector->vrr_capable_property,
2533 EXPORT_SYMBOL(drm_connector_set_vrr_capable_property);
2536 * drm_connector_set_panel_orientation - sets the connector's panel_orientation
2537 * @connector: connector for which to set the panel-orientation property.
2538 * @panel_orientation: drm_panel_orientation value to set
2540 * This function sets the connector's panel_orientation and attaches
2541 * a "panel orientation" property to the connector.
2543 * Calling this function on a connector where the panel_orientation has
2544 * already been set is a no-op (e.g. the orientation has been overridden with
2545 * a kernel commandline option).
2547 * It is allowed to call this function with a panel_orientation of
2548 * DRM_MODE_PANEL_ORIENTATION_UNKNOWN, in which case it is a no-op.
2550 * The function shouldn't be called in panel after drm is registered (i.e.
2551 * drm_dev_register() is called in drm).
2554 * Zero on success, negative errno on failure.
2556 int drm_connector_set_panel_orientation(
2557 struct drm_connector *connector,
2558 enum drm_panel_orientation panel_orientation)
2560 struct drm_device *dev = connector->dev;
2561 struct drm_display_info *info = &connector->display_info;
2562 struct drm_property *prop;
2565 if (info->panel_orientation != DRM_MODE_PANEL_ORIENTATION_UNKNOWN)
2568 /* Don't attach the property if the orientation is unknown */
2569 if (panel_orientation == DRM_MODE_PANEL_ORIENTATION_UNKNOWN)
2572 info->panel_orientation = panel_orientation;
2574 prop = dev->mode_config.panel_orientation_property;
2576 prop = drm_property_create_enum(dev, DRM_MODE_PROP_IMMUTABLE,
2577 "panel orientation",
2578 drm_panel_orientation_enum_list,
2579 ARRAY_SIZE(drm_panel_orientation_enum_list));
2583 dev->mode_config.panel_orientation_property = prop;
2586 drm_object_attach_property(&connector->base, prop,
2587 info->panel_orientation);
2590 EXPORT_SYMBOL(drm_connector_set_panel_orientation);
2593 * drm_connector_set_panel_orientation_with_quirk - set the
2594 * connector's panel_orientation after checking for quirks
2595 * @connector: connector for which to init the panel-orientation property.
2596 * @panel_orientation: drm_panel_orientation value to set
2597 * @width: width in pixels of the panel, used for panel quirk detection
2598 * @height: height in pixels of the panel, used for panel quirk detection
2600 * Like drm_connector_set_panel_orientation(), but with a check for platform
2601 * specific (e.g. DMI based) quirks overriding the passed in panel_orientation.
2604 * Zero on success, negative errno on failure.
2606 int drm_connector_set_panel_orientation_with_quirk(
2607 struct drm_connector *connector,
2608 enum drm_panel_orientation panel_orientation,
2609 int width, int height)
2611 int orientation_quirk;
2613 orientation_quirk = drm_get_panel_orientation_quirk(width, height);
2614 if (orientation_quirk != DRM_MODE_PANEL_ORIENTATION_UNKNOWN)
2615 panel_orientation = orientation_quirk;
2617 return drm_connector_set_panel_orientation(connector,
2620 EXPORT_SYMBOL(drm_connector_set_panel_orientation_with_quirk);
2623 * drm_connector_set_orientation_from_panel -
2624 * set the connector's panel_orientation from panel's callback.
2625 * @connector: connector for which to init the panel-orientation property.
2626 * @panel: panel that can provide orientation information.
2628 * Drm drivers should call this function before drm_dev_register().
2629 * Orientation is obtained from panel's .get_orientation() callback.
2632 * Zero on success, negative errno on failure.
2634 int drm_connector_set_orientation_from_panel(
2635 struct drm_connector *connector,
2636 struct drm_panel *panel)
2638 enum drm_panel_orientation orientation;
2640 if (panel && panel->funcs && panel->funcs->get_orientation)
2641 orientation = panel->funcs->get_orientation(panel);
2643 orientation = DRM_MODE_PANEL_ORIENTATION_UNKNOWN;
2645 return drm_connector_set_panel_orientation(connector, orientation);
2647 EXPORT_SYMBOL(drm_connector_set_orientation_from_panel);
2649 static const struct drm_prop_enum_list privacy_screen_enum[] = {
2650 { PRIVACY_SCREEN_DISABLED, "Disabled" },
2651 { PRIVACY_SCREEN_ENABLED, "Enabled" },
2652 { PRIVACY_SCREEN_DISABLED_LOCKED, "Disabled-locked" },
2653 { PRIVACY_SCREEN_ENABLED_LOCKED, "Enabled-locked" },
2657 * drm_connector_create_privacy_screen_properties - create the drm connecter's
2658 * privacy-screen properties.
2659 * @connector: connector for which to create the privacy-screen properties
2661 * This function creates the "privacy-screen sw-state" and "privacy-screen
2662 * hw-state" properties for the connector. They are not attached.
2665 drm_connector_create_privacy_screen_properties(struct drm_connector *connector)
2667 if (connector->privacy_screen_sw_state_property)
2670 /* Note sw-state only supports the first 2 values of the enum */
2671 connector->privacy_screen_sw_state_property =
2672 drm_property_create_enum(connector->dev, DRM_MODE_PROP_ENUM,
2673 "privacy-screen sw-state",
2674 privacy_screen_enum, 2);
2676 connector->privacy_screen_hw_state_property =
2677 drm_property_create_enum(connector->dev,
2678 DRM_MODE_PROP_IMMUTABLE | DRM_MODE_PROP_ENUM,
2679 "privacy-screen hw-state",
2680 privacy_screen_enum,
2681 ARRAY_SIZE(privacy_screen_enum));
2683 EXPORT_SYMBOL(drm_connector_create_privacy_screen_properties);
2686 * drm_connector_attach_privacy_screen_properties - attach the drm connecter's
2687 * privacy-screen properties.
2688 * @connector: connector on which to attach the privacy-screen properties
2690 * This function attaches the "privacy-screen sw-state" and "privacy-screen
2691 * hw-state" properties to the connector. The initial state of both is set
2695 drm_connector_attach_privacy_screen_properties(struct drm_connector *connector)
2697 if (!connector->privacy_screen_sw_state_property)
2700 drm_object_attach_property(&connector->base,
2701 connector->privacy_screen_sw_state_property,
2702 PRIVACY_SCREEN_DISABLED);
2704 drm_object_attach_property(&connector->base,
2705 connector->privacy_screen_hw_state_property,
2706 PRIVACY_SCREEN_DISABLED);
2708 EXPORT_SYMBOL(drm_connector_attach_privacy_screen_properties);
2710 static void drm_connector_update_privacy_screen_properties(
2711 struct drm_connector *connector, bool set_sw_state)
2713 enum drm_privacy_screen_status sw_state, hw_state;
2715 drm_privacy_screen_get_state(connector->privacy_screen,
2716 &sw_state, &hw_state);
2719 connector->state->privacy_screen_sw_state = sw_state;
2720 drm_object_property_set_value(&connector->base,
2721 connector->privacy_screen_hw_state_property, hw_state);
2724 static int drm_connector_privacy_screen_notifier(
2725 struct notifier_block *nb, unsigned long action, void *data)
2727 struct drm_connector *connector =
2728 container_of(nb, struct drm_connector, privacy_screen_notifier);
2729 struct drm_device *dev = connector->dev;
2731 drm_modeset_lock(&dev->mode_config.connection_mutex, NULL);
2732 drm_connector_update_privacy_screen_properties(connector, true);
2733 drm_modeset_unlock(&dev->mode_config.connection_mutex);
2735 drm_sysfs_connector_property_event(connector,
2736 connector->privacy_screen_sw_state_property);
2737 drm_sysfs_connector_property_event(connector,
2738 connector->privacy_screen_hw_state_property);
2744 * drm_connector_attach_privacy_screen_provider - attach a privacy-screen to
2746 * @connector: connector to attach the privacy-screen to
2747 * @priv: drm_privacy_screen to attach
2749 * Create and attach the standard privacy-screen properties and register
2750 * a generic notifier for generating sysfs-connector-status-events
2751 * on external changes to the privacy-screen status.
2752 * This function takes ownership of the passed in drm_privacy_screen and will
2753 * call drm_privacy_screen_put() on it when the connector is destroyed.
2755 void drm_connector_attach_privacy_screen_provider(
2756 struct drm_connector *connector, struct drm_privacy_screen *priv)
2758 connector->privacy_screen = priv;
2759 connector->privacy_screen_notifier.notifier_call =
2760 drm_connector_privacy_screen_notifier;
2762 drm_connector_create_privacy_screen_properties(connector);
2763 drm_connector_update_privacy_screen_properties(connector, true);
2764 drm_connector_attach_privacy_screen_properties(connector);
2766 EXPORT_SYMBOL(drm_connector_attach_privacy_screen_provider);
2769 * drm_connector_update_privacy_screen - update connector's privacy-screen sw-state
2770 * @connector_state: connector-state to update the privacy-screen for
2772 * This function calls drm_privacy_screen_set_sw_state() on the connector's
2775 * If the connector has no privacy-screen, then this is a no-op.
2777 void drm_connector_update_privacy_screen(const struct drm_connector_state *connector_state)
2779 struct drm_connector *connector = connector_state->connector;
2782 if (!connector->privacy_screen)
2785 ret = drm_privacy_screen_set_sw_state(connector->privacy_screen,
2786 connector_state->privacy_screen_sw_state);
2788 drm_err(connector->dev, "Error updating privacy-screen sw_state\n");
2792 /* The hw_state property value may have changed, update it. */
2793 drm_connector_update_privacy_screen_properties(connector, false);
2795 EXPORT_SYMBOL(drm_connector_update_privacy_screen);
2797 int drm_connector_set_obj_prop(struct drm_mode_object *obj,
2798 struct drm_property *property,
2802 struct drm_connector *connector = obj_to_connector(obj);
2804 /* Do DPMS ourselves */
2805 if (property == connector->dev->mode_config.dpms_property) {
2806 ret = (*connector->funcs->dpms)(connector, (int)value);
2807 } else if (connector->funcs->set_property)
2808 ret = connector->funcs->set_property(connector, property, value);
2811 drm_object_property_set_value(&connector->base, property, value);
2815 int drm_connector_property_set_ioctl(struct drm_device *dev,
2816 void *data, struct drm_file *file_priv)
2818 struct drm_mode_connector_set_property *conn_set_prop = data;
2819 struct drm_mode_obj_set_property obj_set_prop = {
2820 .value = conn_set_prop->value,
2821 .prop_id = conn_set_prop->prop_id,
2822 .obj_id = conn_set_prop->connector_id,
2823 .obj_type = DRM_MODE_OBJECT_CONNECTOR
2826 /* It does all the locking and checking we need */
2827 return drm_mode_obj_set_property_ioctl(dev, &obj_set_prop, file_priv);
2830 static struct drm_encoder *drm_connector_get_encoder(struct drm_connector *connector)
2832 /* For atomic drivers only state objects are synchronously updated and
2833 * protected by modeset locks, so check those first.
2835 if (connector->state)
2836 return connector->state->best_encoder;
2837 return connector->encoder;
2841 drm_mode_expose_to_userspace(const struct drm_display_mode *mode,
2842 const struct list_head *modes,
2843 const struct drm_file *file_priv)
2846 * If user-space hasn't configured the driver to expose the stereo 3D
2847 * modes, don't expose them.
2849 if (!file_priv->stereo_allowed && drm_mode_is_stereo(mode))
2852 * If user-space hasn't configured the driver to expose the modes
2853 * with aspect-ratio, don't expose them. However if such a mode
2854 * is unique, let it be exposed, but reset the aspect-ratio flags
2855 * while preparing the list of user-modes.
2857 if (!file_priv->aspect_ratio_allowed) {
2858 const struct drm_display_mode *mode_itr;
2860 list_for_each_entry(mode_itr, modes, head) {
2861 if (mode_itr->expose_to_userspace &&
2862 drm_mode_match(mode_itr, mode,
2863 DRM_MODE_MATCH_TIMINGS |
2864 DRM_MODE_MATCH_CLOCK |
2865 DRM_MODE_MATCH_FLAGS |
2866 DRM_MODE_MATCH_3D_FLAGS))
2874 int drm_mode_getconnector(struct drm_device *dev, void *data,
2875 struct drm_file *file_priv)
2877 struct drm_mode_get_connector *out_resp = data;
2878 struct drm_connector *connector;
2879 struct drm_encoder *encoder;
2880 struct drm_display_mode *mode;
2882 int encoders_count = 0;
2885 struct drm_mode_modeinfo u_mode;
2886 struct drm_mode_modeinfo __user *mode_ptr;
2887 uint32_t __user *encoder_ptr;
2888 bool is_current_master;
2890 if (!drm_core_check_feature(dev, DRIVER_MODESET))
2893 memset(&u_mode, 0, sizeof(struct drm_mode_modeinfo));
2895 connector = drm_connector_lookup(dev, file_priv, out_resp->connector_id);
2899 encoders_count = hweight32(connector->possible_encoders);
2901 if ((out_resp->count_encoders >= encoders_count) && encoders_count) {
2903 encoder_ptr = (uint32_t __user *)(unsigned long)(out_resp->encoders_ptr);
2905 drm_connector_for_each_possible_encoder(connector, encoder) {
2906 if (put_user(encoder->base.id, encoder_ptr + copied)) {
2913 out_resp->count_encoders = encoders_count;
2915 out_resp->connector_id = connector->base.id;
2916 out_resp->connector_type = connector->connector_type;
2917 out_resp->connector_type_id = connector->connector_type_id;
2919 is_current_master = drm_is_current_master(file_priv);
2921 mutex_lock(&dev->mode_config.mutex);
2922 if (out_resp->count_modes == 0) {
2923 if (is_current_master)
2924 connector->funcs->fill_modes(connector,
2925 dev->mode_config.max_width,
2926 dev->mode_config.max_height);
2928 drm_dbg_kms(dev, "User-space requested a forced probe on [CONNECTOR:%d:%s] but is not the DRM master, demoting to read-only probe",
2929 connector->base.id, connector->name);
2932 out_resp->mm_width = connector->display_info.width_mm;
2933 out_resp->mm_height = connector->display_info.height_mm;
2934 out_resp->subpixel = connector->display_info.subpixel_order;
2935 out_resp->connection = connector->status;
2937 /* delayed so we get modes regardless of pre-fill_modes state */
2938 list_for_each_entry(mode, &connector->modes, head) {
2939 WARN_ON(mode->expose_to_userspace);
2941 if (drm_mode_expose_to_userspace(mode, &connector->modes,
2943 mode->expose_to_userspace = true;
2949 * This ioctl is called twice, once to determine how much space is
2950 * needed, and the 2nd time to fill it.
2952 if ((out_resp->count_modes >= mode_count) && mode_count) {
2954 mode_ptr = (struct drm_mode_modeinfo __user *)(unsigned long)out_resp->modes_ptr;
2955 list_for_each_entry(mode, &connector->modes, head) {
2956 if (!mode->expose_to_userspace)
2959 /* Clear the tag for the next time around */
2960 mode->expose_to_userspace = false;
2962 drm_mode_convert_to_umode(&u_mode, mode);
2964 * Reset aspect ratio flags of user-mode, if modes with
2965 * aspect-ratio are not supported.
2967 if (!file_priv->aspect_ratio_allowed)
2968 u_mode.flags &= ~DRM_MODE_FLAG_PIC_AR_MASK;
2969 if (copy_to_user(mode_ptr + copied,
2970 &u_mode, sizeof(u_mode))) {
2974 * Clear the tag for the rest of
2975 * the modes for the next time around.
2977 list_for_each_entry_continue(mode, &connector->modes, head)
2978 mode->expose_to_userspace = false;
2980 mutex_unlock(&dev->mode_config.mutex);
2987 /* Clear the tag for the next time around */
2988 list_for_each_entry(mode, &connector->modes, head)
2989 mode->expose_to_userspace = false;
2992 out_resp->count_modes = mode_count;
2993 mutex_unlock(&dev->mode_config.mutex);
2995 drm_modeset_lock(&dev->mode_config.connection_mutex, NULL);
2996 encoder = drm_connector_get_encoder(connector);
2998 out_resp->encoder_id = encoder->base.id;
3000 out_resp->encoder_id = 0;
3002 /* Only grab properties after probing, to make sure EDID and other
3003 * properties reflect the latest status.
3005 ret = drm_mode_object_get_properties(&connector->base, file_priv->atomic,
3006 (uint32_t __user *)(unsigned long)(out_resp->props_ptr),
3007 (uint64_t __user *)(unsigned long)(out_resp->prop_values_ptr),
3008 &out_resp->count_props);
3009 drm_modeset_unlock(&dev->mode_config.connection_mutex);
3012 drm_connector_put(connector);
3018 * drm_connector_find_by_fwnode - Find a connector based on the associated fwnode
3019 * @fwnode: fwnode for which to find the matching drm_connector
3021 * This functions looks up a drm_connector based on its associated fwnode. When
3022 * a connector is found a reference to the connector is returned. The caller must
3023 * call drm_connector_put() to release this reference when it is done with the
3026 * Returns: A reference to the found connector or an ERR_PTR().
3028 struct drm_connector *drm_connector_find_by_fwnode(struct fwnode_handle *fwnode)
3030 struct drm_connector *connector, *found = ERR_PTR(-ENODEV);
3033 return ERR_PTR(-ENODEV);
3035 mutex_lock(&connector_list_lock);
3037 list_for_each_entry(connector, &connector_list, global_connector_list_entry) {
3038 if (connector->fwnode == fwnode ||
3039 (connector->fwnode && connector->fwnode->secondary == fwnode)) {
3040 drm_connector_get(connector);
3046 mutex_unlock(&connector_list_lock);
3052 * drm_connector_oob_hotplug_event - Report out-of-band hotplug event to connector
3053 * @connector_fwnode: fwnode_handle to report the event on
3055 * On some hardware a hotplug event notification may come from outside the display
3056 * driver / device. An example of this is some USB Type-C setups where the hardware
3057 * muxes the DisplayPort data and aux-lines but does not pass the altmode HPD
3058 * status bit to the GPU's DP HPD pin.
3060 * This function can be used to report these out-of-band events after obtaining
3061 * a drm_connector reference through calling drm_connector_find_by_fwnode().
3063 void drm_connector_oob_hotplug_event(struct fwnode_handle *connector_fwnode)
3065 struct drm_connector *connector;
3067 connector = drm_connector_find_by_fwnode(connector_fwnode);
3068 if (IS_ERR(connector))
3071 if (connector->funcs->oob_hotplug_event)
3072 connector->funcs->oob_hotplug_event(connector);
3074 drm_connector_put(connector);
3076 EXPORT_SYMBOL(drm_connector_oob_hotplug_event);
3082 * Tile groups are used to represent tiled monitors with a unique integer
3083 * identifier. Tiled monitors using DisplayID v1.3 have a unique 8-byte handle,
3084 * we store this in a tile group, so we have a common identifier for all tiles
3085 * in a monitor group. The property is called "TILE". Drivers can manage tile
3086 * groups using drm_mode_create_tile_group(), drm_mode_put_tile_group() and
3087 * drm_mode_get_tile_group(). But this is only needed for internal panels where
3088 * the tile group information is exposed through a non-standard way.
3091 static void drm_tile_group_free(struct kref *kref)
3093 struct drm_tile_group *tg = container_of(kref, struct drm_tile_group, refcount);
3094 struct drm_device *dev = tg->dev;
3096 mutex_lock(&dev->mode_config.idr_mutex);
3097 idr_remove(&dev->mode_config.tile_idr, tg->id);
3098 mutex_unlock(&dev->mode_config.idr_mutex);
3103 * drm_mode_put_tile_group - drop a reference to a tile group.
3105 * @tg: tile group to drop reference to.
3107 * drop reference to tile group and free if 0.
3109 void drm_mode_put_tile_group(struct drm_device *dev,
3110 struct drm_tile_group *tg)
3112 kref_put(&tg->refcount, drm_tile_group_free);
3114 EXPORT_SYMBOL(drm_mode_put_tile_group);
3117 * drm_mode_get_tile_group - get a reference to an existing tile group
3119 * @topology: 8-bytes unique per monitor.
3121 * Use the unique bytes to get a reference to an existing tile group.
3124 * tile group or NULL if not found.
3126 struct drm_tile_group *drm_mode_get_tile_group(struct drm_device *dev,
3127 const char topology[8])
3129 struct drm_tile_group *tg;
3132 mutex_lock(&dev->mode_config.idr_mutex);
3133 idr_for_each_entry(&dev->mode_config.tile_idr, tg, id) {
3134 if (!memcmp(tg->group_data, topology, 8)) {
3135 if (!kref_get_unless_zero(&tg->refcount))
3137 mutex_unlock(&dev->mode_config.idr_mutex);
3141 mutex_unlock(&dev->mode_config.idr_mutex);
3144 EXPORT_SYMBOL(drm_mode_get_tile_group);
3147 * drm_mode_create_tile_group - create a tile group from a displayid description
3149 * @topology: 8-bytes unique per monitor.
3151 * Create a tile group for the unique monitor, and get a unique
3152 * identifier for the tile group.
3155 * new tile group or NULL.
3157 struct drm_tile_group *drm_mode_create_tile_group(struct drm_device *dev,
3158 const char topology[8])
3160 struct drm_tile_group *tg;
3163 tg = kzalloc(sizeof(*tg), GFP_KERNEL);
3167 kref_init(&tg->refcount);
3168 memcpy(tg->group_data, topology, 8);
3171 mutex_lock(&dev->mode_config.idr_mutex);
3172 ret = idr_alloc(&dev->mode_config.tile_idr, tg, 1, 0, GFP_KERNEL);
3180 mutex_unlock(&dev->mode_config.idr_mutex);
3183 EXPORT_SYMBOL(drm_mode_create_tile_group);