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>
37 #include <linux/uaccess.h>
39 #include "drm_crtc_internal.h"
40 #include "drm_internal.h"
45 * In DRM connectors are the general abstraction for display sinks, and include
46 * also fixed panels or anything else that can display pixels in some form. As
47 * opposed to all other KMS objects representing hardware (like CRTC, encoder or
48 * plane abstractions) connectors can be hotplugged and unplugged at runtime.
49 * Hence they are reference-counted using drm_connector_get() and
50 * drm_connector_put().
52 * KMS driver must create, initialize, register and attach at a &struct
53 * drm_connector for each such sink. The instance is created as other KMS
54 * objects and initialized by setting the following fields. The connector is
55 * initialized with a call to drm_connector_init() with a pointer to the
56 * &struct drm_connector_funcs and a connector type, and then exposed to
57 * userspace with a call to drm_connector_register().
59 * Connectors must be attached to an encoder to be used. For devices that map
60 * connectors to encoders 1:1, the connector should be attached at
61 * initialization time with a call to drm_connector_attach_encoder(). The
62 * driver must also set the &drm_connector.encoder field to point to the
65 * For connectors which are not fixed (like built-in panels) the driver needs to
66 * support hotplug notifications. The simplest way to do that is by using the
67 * probe helpers, see drm_kms_helper_poll_init() for connectors which don't have
68 * hardware support for hotplug interrupts. Connectors with hardware hotplug
69 * support can instead use e.g. drm_helper_hpd_irq_event().
73 * Global connector list for drm_connector_find_by_fwnode().
74 * Note drm_connector_[un]register() first take connector->lock and then
75 * take the connector_list_lock.
77 static DEFINE_MUTEX(connector_list_lock);
78 static LIST_HEAD(connector_list);
80 struct drm_conn_prop_enum_list {
87 * Connector and encoder types.
89 static struct drm_conn_prop_enum_list drm_connector_enum_list[] = {
90 { DRM_MODE_CONNECTOR_Unknown, "Unknown" },
91 { DRM_MODE_CONNECTOR_VGA, "VGA" },
92 { DRM_MODE_CONNECTOR_DVII, "DVI-I" },
93 { DRM_MODE_CONNECTOR_DVID, "DVI-D" },
94 { DRM_MODE_CONNECTOR_DVIA, "DVI-A" },
95 { DRM_MODE_CONNECTOR_Composite, "Composite" },
96 { DRM_MODE_CONNECTOR_SVIDEO, "SVIDEO" },
97 { DRM_MODE_CONNECTOR_LVDS, "LVDS" },
98 { DRM_MODE_CONNECTOR_Component, "Component" },
99 { DRM_MODE_CONNECTOR_9PinDIN, "DIN" },
100 { DRM_MODE_CONNECTOR_DisplayPort, "DP" },
101 { DRM_MODE_CONNECTOR_HDMIA, "HDMI-A" },
102 { DRM_MODE_CONNECTOR_HDMIB, "HDMI-B" },
103 { DRM_MODE_CONNECTOR_TV, "TV" },
104 { DRM_MODE_CONNECTOR_eDP, "eDP" },
105 { DRM_MODE_CONNECTOR_VIRTUAL, "Virtual" },
106 { DRM_MODE_CONNECTOR_DSI, "DSI" },
107 { DRM_MODE_CONNECTOR_DPI, "DPI" },
108 { DRM_MODE_CONNECTOR_WRITEBACK, "Writeback" },
109 { DRM_MODE_CONNECTOR_SPI, "SPI" },
110 { DRM_MODE_CONNECTOR_USB, "USB" },
113 void drm_connector_ida_init(void)
117 for (i = 0; i < ARRAY_SIZE(drm_connector_enum_list); i++)
118 ida_init(&drm_connector_enum_list[i].ida);
121 void drm_connector_ida_destroy(void)
125 for (i = 0; i < ARRAY_SIZE(drm_connector_enum_list); i++)
126 ida_destroy(&drm_connector_enum_list[i].ida);
130 * drm_get_connector_type_name - return a string for connector type
131 * @type: The connector type (DRM_MODE_CONNECTOR_*)
133 * Returns: the name of the connector type, or NULL if the type is not valid.
135 const char *drm_get_connector_type_name(unsigned int type)
137 if (type < ARRAY_SIZE(drm_connector_enum_list))
138 return drm_connector_enum_list[type].name;
142 EXPORT_SYMBOL(drm_get_connector_type_name);
145 * drm_connector_get_cmdline_mode - reads the user's cmdline mode
146 * @connector: connector to query
148 * The kernel supports per-connector configuration of its consoles through
149 * use of the video= parameter. This function parses that option and
150 * extracts the user's specified mode (or enable/disable status) for a
151 * particular connector. This is typically only used during the early fbdev
154 static void drm_connector_get_cmdline_mode(struct drm_connector *connector)
156 struct drm_cmdline_mode *mode = &connector->cmdline_mode;
159 if (fb_get_options(connector->name, &option))
162 if (!drm_mode_parse_command_line_for_connector(option,
168 DRM_INFO("forcing %s connector %s\n", connector->name,
169 drm_get_connector_force_name(mode->force));
170 connector->force = mode->force;
173 if (mode->panel_orientation != DRM_MODE_PANEL_ORIENTATION_UNKNOWN) {
174 DRM_INFO("cmdline forces connector %s panel_orientation to %d\n",
175 connector->name, mode->panel_orientation);
176 drm_connector_set_panel_orientation(connector,
177 mode->panel_orientation);
180 DRM_DEBUG_KMS("cmdline mode for connector %s %s %dx%d@%dHz%s%s%s\n",
181 connector->name, mode->name,
182 mode->xres, mode->yres,
183 mode->refresh_specified ? mode->refresh : 60,
184 mode->rb ? " reduced blanking" : "",
185 mode->margins ? " with margins" : "",
186 mode->interlace ? " interlaced" : "");
189 static void drm_connector_free(struct kref *kref)
191 struct drm_connector *connector =
192 container_of(kref, struct drm_connector, base.refcount);
193 struct drm_device *dev = connector->dev;
195 drm_mode_object_unregister(dev, &connector->base);
196 connector->funcs->destroy(connector);
199 void drm_connector_free_work_fn(struct work_struct *work)
201 struct drm_connector *connector, *n;
202 struct drm_device *dev =
203 container_of(work, struct drm_device, mode_config.connector_free_work);
204 struct drm_mode_config *config = &dev->mode_config;
206 struct llist_node *freed;
208 spin_lock_irqsave(&config->connector_list_lock, flags);
209 freed = llist_del_all(&config->connector_free_list);
210 spin_unlock_irqrestore(&config->connector_list_lock, flags);
212 llist_for_each_entry_safe(connector, n, freed, free_node) {
213 drm_mode_object_unregister(dev, &connector->base);
214 connector->funcs->destroy(connector);
218 static int __drm_connector_init(struct drm_device *dev,
219 struct drm_connector *connector,
220 const struct drm_connector_funcs *funcs,
222 struct i2c_adapter *ddc)
224 struct drm_mode_config *config = &dev->mode_config;
226 struct ida *connector_ida =
227 &drm_connector_enum_list[connector_type].ida;
229 WARN_ON(drm_drv_uses_atomic_modeset(dev) &&
230 (!funcs->atomic_destroy_state ||
231 !funcs->atomic_duplicate_state));
233 ret = __drm_mode_object_add(dev, &connector->base,
234 DRM_MODE_OBJECT_CONNECTOR,
235 false, drm_connector_free);
239 connector->base.properties = &connector->properties;
240 connector->dev = dev;
241 connector->funcs = funcs;
243 /* connector index is used with 32bit bitmasks */
244 ret = ida_alloc_max(&config->connector_ida, 31, GFP_KERNEL);
246 DRM_DEBUG_KMS("Failed to allocate %s connector index: %d\n",
247 drm_connector_enum_list[connector_type].name,
251 connector->index = ret;
254 connector->connector_type = connector_type;
255 connector->connector_type_id =
256 ida_alloc_min(connector_ida, 1, GFP_KERNEL);
257 if (connector->connector_type_id < 0) {
258 ret = connector->connector_type_id;
262 kasprintf(GFP_KERNEL, "%s-%d",
263 drm_connector_enum_list[connector_type].name,
264 connector->connector_type_id);
265 if (!connector->name) {
267 goto out_put_type_id;
270 /* provide ddc symlink in sysfs */
271 connector->ddc = ddc;
273 INIT_LIST_HEAD(&connector->global_connector_list_entry);
274 INIT_LIST_HEAD(&connector->probed_modes);
275 INIT_LIST_HEAD(&connector->modes);
276 mutex_init(&connector->mutex);
277 connector->edid_blob_ptr = NULL;
278 connector->epoch_counter = 0;
279 connector->tile_blob_ptr = NULL;
280 connector->status = connector_status_unknown;
281 connector->display_info.panel_orientation =
282 DRM_MODE_PANEL_ORIENTATION_UNKNOWN;
284 drm_connector_get_cmdline_mode(connector);
286 /* We should add connectors at the end to avoid upsetting the connector
289 spin_lock_irq(&config->connector_list_lock);
290 list_add_tail(&connector->head, &config->connector_list);
291 config->num_connector++;
292 spin_unlock_irq(&config->connector_list_lock);
294 if (connector_type != DRM_MODE_CONNECTOR_VIRTUAL &&
295 connector_type != DRM_MODE_CONNECTOR_WRITEBACK)
296 drm_connector_attach_edid_property(connector);
298 drm_object_attach_property(&connector->base,
299 config->dpms_property, 0);
301 drm_object_attach_property(&connector->base,
302 config->link_status_property,
305 drm_object_attach_property(&connector->base,
306 config->non_desktop_property,
308 drm_object_attach_property(&connector->base,
309 config->tile_property,
312 if (drm_core_check_feature(dev, DRIVER_ATOMIC)) {
313 drm_object_attach_property(&connector->base, config->prop_crtc_id, 0);
316 connector->debugfs_entry = NULL;
319 ida_free(connector_ida, connector->connector_type_id);
322 ida_free(&config->connector_ida, connector->index);
325 drm_mode_object_unregister(dev, &connector->base);
331 * drm_connector_init - Init a preallocated connector
333 * @connector: the connector to init
334 * @funcs: callbacks for this connector
335 * @connector_type: user visible type of the connector
337 * Initialises a preallocated connector. Connectors should be
338 * subclassed as part of driver connector objects.
340 * At driver unload time the driver's &drm_connector_funcs.destroy hook
341 * should call drm_connector_cleanup() and free the connector structure.
342 * The connector structure should not be allocated with devm_kzalloc().
344 * Note: consider using drmm_connector_init() instead of
345 * drm_connector_init() to let the DRM managed resource infrastructure
346 * take care of cleanup and deallocation.
349 * Zero on success, error code on failure.
351 int drm_connector_init(struct drm_device *dev,
352 struct drm_connector *connector,
353 const struct drm_connector_funcs *funcs,
356 if (drm_WARN_ON(dev, !(funcs && funcs->destroy)))
359 return __drm_connector_init(dev, connector, funcs, connector_type, NULL);
361 EXPORT_SYMBOL(drm_connector_init);
364 * drm_connector_init_with_ddc - Init a preallocated connector
366 * @connector: the connector to init
367 * @funcs: callbacks for this connector
368 * @connector_type: user visible type of the connector
369 * @ddc: pointer to the associated ddc adapter
371 * Initialises a preallocated connector. Connectors should be
372 * subclassed as part of driver connector objects.
374 * At driver unload time the driver's &drm_connector_funcs.destroy hook
375 * should call drm_connector_cleanup() and free the connector structure.
376 * The connector structure should not be allocated with devm_kzalloc().
378 * Ensures that the ddc field of the connector is correctly set.
380 * Note: consider using drmm_connector_init() instead of
381 * drm_connector_init_with_ddc() to let the DRM managed resource
382 * infrastructure take care of cleanup and deallocation.
385 * Zero on success, error code on failure.
387 int drm_connector_init_with_ddc(struct drm_device *dev,
388 struct drm_connector *connector,
389 const struct drm_connector_funcs *funcs,
391 struct i2c_adapter *ddc)
393 if (drm_WARN_ON(dev, !(funcs && funcs->destroy)))
396 return __drm_connector_init(dev, connector, funcs, connector_type, ddc);
398 EXPORT_SYMBOL(drm_connector_init_with_ddc);
400 static void drm_connector_cleanup_action(struct drm_device *dev,
403 struct drm_connector *connector = ptr;
405 drm_connector_cleanup(connector);
409 * drmm_connector_init - Init a preallocated connector
411 * @connector: the connector to init
412 * @funcs: callbacks for this connector
413 * @connector_type: user visible type of the connector
414 * @ddc: optional pointer to the associated ddc adapter
416 * Initialises a preallocated connector. Connectors should be
417 * subclassed as part of driver connector objects.
419 * Cleanup is automatically handled with a call to
420 * drm_connector_cleanup() in a DRM-managed action.
422 * The connector structure should be allocated with drmm_kzalloc().
425 * Zero on success, error code on failure.
427 int drmm_connector_init(struct drm_device *dev,
428 struct drm_connector *connector,
429 const struct drm_connector_funcs *funcs,
431 struct i2c_adapter *ddc)
435 if (drm_WARN_ON(dev, funcs && funcs->destroy))
438 ret = __drm_connector_init(dev, connector, funcs, connector_type, ddc);
442 ret = drmm_add_action_or_reset(dev, drm_connector_cleanup_action,
449 EXPORT_SYMBOL(drmm_connector_init);
452 * drm_connector_attach_edid_property - attach edid property.
453 * @connector: the connector
455 * Some connector types like DRM_MODE_CONNECTOR_VIRTUAL do not get a
456 * edid property attached by default. This function can be used to
457 * explicitly enable the edid property in these cases.
459 void drm_connector_attach_edid_property(struct drm_connector *connector)
461 struct drm_mode_config *config = &connector->dev->mode_config;
463 drm_object_attach_property(&connector->base,
464 config->edid_property,
467 EXPORT_SYMBOL(drm_connector_attach_edid_property);
470 * drm_connector_attach_encoder - attach a connector to an encoder
471 * @connector: connector to attach
472 * @encoder: encoder to attach @connector to
474 * This function links up a connector to an encoder. Note that the routing
475 * restrictions between encoders and crtcs are exposed to userspace through the
476 * possible_clones and possible_crtcs bitmasks.
479 * Zero on success, negative errno on failure.
481 int drm_connector_attach_encoder(struct drm_connector *connector,
482 struct drm_encoder *encoder)
485 * In the past, drivers have attempted to model the static association
486 * of connector to encoder in simple connector/encoder devices using a
487 * direct assignment of connector->encoder = encoder. This connection
488 * is a logical one and the responsibility of the core, so drivers are
489 * expected not to mess with this.
491 * Note that the error return should've been enough here, but a large
492 * majority of drivers ignores the return value, so add in a big WARN
493 * to get people's attention.
495 if (WARN_ON(connector->encoder))
498 connector->possible_encoders |= drm_encoder_mask(encoder);
502 EXPORT_SYMBOL(drm_connector_attach_encoder);
505 * drm_connector_has_possible_encoder - check if the connector and encoder are
506 * associated with each other
507 * @connector: the connector
508 * @encoder: the encoder
511 * True if @encoder is one of the possible encoders for @connector.
513 bool drm_connector_has_possible_encoder(struct drm_connector *connector,
514 struct drm_encoder *encoder)
516 return connector->possible_encoders & drm_encoder_mask(encoder);
518 EXPORT_SYMBOL(drm_connector_has_possible_encoder);
520 static void drm_mode_remove(struct drm_connector *connector,
521 struct drm_display_mode *mode)
523 list_del(&mode->head);
524 drm_mode_destroy(connector->dev, mode);
528 * drm_connector_cleanup - cleans up an initialised connector
529 * @connector: connector to cleanup
531 * Cleans up the connector but doesn't free the object.
533 void drm_connector_cleanup(struct drm_connector *connector)
535 struct drm_device *dev = connector->dev;
536 struct drm_display_mode *mode, *t;
538 /* The connector should have been removed from userspace long before
539 * it is finally destroyed.
541 if (WARN_ON(connector->registration_state ==
542 DRM_CONNECTOR_REGISTERED))
543 drm_connector_unregister(connector);
545 if (connector->privacy_screen) {
546 drm_privacy_screen_put(connector->privacy_screen);
547 connector->privacy_screen = NULL;
550 if (connector->tile_group) {
551 drm_mode_put_tile_group(dev, connector->tile_group);
552 connector->tile_group = NULL;
555 list_for_each_entry_safe(mode, t, &connector->probed_modes, head)
556 drm_mode_remove(connector, mode);
558 list_for_each_entry_safe(mode, t, &connector->modes, head)
559 drm_mode_remove(connector, mode);
561 ida_free(&drm_connector_enum_list[connector->connector_type].ida,
562 connector->connector_type_id);
564 ida_free(&dev->mode_config.connector_ida, connector->index);
566 kfree(connector->display_info.bus_formats);
567 drm_mode_object_unregister(dev, &connector->base);
568 kfree(connector->name);
569 connector->name = NULL;
570 fwnode_handle_put(connector->fwnode);
571 connector->fwnode = NULL;
572 spin_lock_irq(&dev->mode_config.connector_list_lock);
573 list_del(&connector->head);
574 dev->mode_config.num_connector--;
575 spin_unlock_irq(&dev->mode_config.connector_list_lock);
577 WARN_ON(connector->state && !connector->funcs->atomic_destroy_state);
578 if (connector->state && connector->funcs->atomic_destroy_state)
579 connector->funcs->atomic_destroy_state(connector,
582 mutex_destroy(&connector->mutex);
584 memset(connector, 0, sizeof(*connector));
587 drm_sysfs_hotplug_event(dev);
589 EXPORT_SYMBOL(drm_connector_cleanup);
592 * drm_connector_register - register a connector
593 * @connector: the connector to register
595 * Register userspace interfaces for a connector. Only call this for connectors
596 * which can be hotplugged after drm_dev_register() has been called already,
597 * e.g. DP MST connectors. All other connectors will be registered automatically
598 * when calling drm_dev_register().
600 * When the connector is no longer available, callers must call
601 * drm_connector_unregister().
604 * Zero on success, error code on failure.
606 int drm_connector_register(struct drm_connector *connector)
610 if (!connector->dev->registered)
613 mutex_lock(&connector->mutex);
614 if (connector->registration_state != DRM_CONNECTOR_INITIALIZING)
617 ret = drm_sysfs_connector_add(connector);
621 drm_debugfs_connector_add(connector);
623 if (connector->funcs->late_register) {
624 ret = connector->funcs->late_register(connector);
629 drm_mode_object_register(connector->dev, &connector->base);
631 connector->registration_state = DRM_CONNECTOR_REGISTERED;
633 /* Let userspace know we have a new connector */
634 drm_sysfs_connector_hotplug_event(connector);
636 if (connector->privacy_screen)
637 drm_privacy_screen_register_notifier(connector->privacy_screen,
638 &connector->privacy_screen_notifier);
640 mutex_lock(&connector_list_lock);
641 list_add_tail(&connector->global_connector_list_entry, &connector_list);
642 mutex_unlock(&connector_list_lock);
646 drm_debugfs_connector_remove(connector);
647 drm_sysfs_connector_remove(connector);
649 mutex_unlock(&connector->mutex);
652 EXPORT_SYMBOL(drm_connector_register);
655 * drm_connector_unregister - unregister a connector
656 * @connector: the connector to unregister
658 * Unregister userspace interfaces for a connector. Only call this for
659 * connectors which have been registered explicitly by calling
660 * drm_connector_register().
662 void drm_connector_unregister(struct drm_connector *connector)
664 mutex_lock(&connector->mutex);
665 if (connector->registration_state != DRM_CONNECTOR_REGISTERED) {
666 mutex_unlock(&connector->mutex);
670 mutex_lock(&connector_list_lock);
671 list_del_init(&connector->global_connector_list_entry);
672 mutex_unlock(&connector_list_lock);
674 if (connector->privacy_screen)
675 drm_privacy_screen_unregister_notifier(
676 connector->privacy_screen,
677 &connector->privacy_screen_notifier);
679 if (connector->funcs->early_unregister)
680 connector->funcs->early_unregister(connector);
682 drm_sysfs_connector_remove(connector);
683 drm_debugfs_connector_remove(connector);
685 connector->registration_state = DRM_CONNECTOR_UNREGISTERED;
686 mutex_unlock(&connector->mutex);
688 EXPORT_SYMBOL(drm_connector_unregister);
690 void drm_connector_unregister_all(struct drm_device *dev)
692 struct drm_connector *connector;
693 struct drm_connector_list_iter conn_iter;
695 drm_connector_list_iter_begin(dev, &conn_iter);
696 drm_for_each_connector_iter(connector, &conn_iter)
697 drm_connector_unregister(connector);
698 drm_connector_list_iter_end(&conn_iter);
701 int drm_connector_register_all(struct drm_device *dev)
703 struct drm_connector *connector;
704 struct drm_connector_list_iter conn_iter;
707 drm_connector_list_iter_begin(dev, &conn_iter);
708 drm_for_each_connector_iter(connector, &conn_iter) {
709 ret = drm_connector_register(connector);
713 drm_connector_list_iter_end(&conn_iter);
716 drm_connector_unregister_all(dev);
721 * drm_get_connector_status_name - return a string for connector status
722 * @status: connector status to compute name of
724 * In contrast to the other drm_get_*_name functions this one here returns a
725 * const pointer and hence is threadsafe.
727 * Returns: connector status string
729 const char *drm_get_connector_status_name(enum drm_connector_status status)
731 if (status == connector_status_connected)
733 else if (status == connector_status_disconnected)
734 return "disconnected";
738 EXPORT_SYMBOL(drm_get_connector_status_name);
741 * drm_get_connector_force_name - return a string for connector force
742 * @force: connector force to get name of
744 * Returns: const pointer to name.
746 const char *drm_get_connector_force_name(enum drm_connector_force force)
749 case DRM_FORCE_UNSPECIFIED:
750 return "unspecified";
755 case DRM_FORCE_ON_DIGITAL:
762 #ifdef CONFIG_LOCKDEP
763 static struct lockdep_map connector_list_iter_dep_map = {
764 .name = "drm_connector_list_iter"
769 * drm_connector_list_iter_begin - initialize a connector_list iterator
771 * @iter: connector_list iterator
773 * Sets @iter up to walk the &drm_mode_config.connector_list of @dev. @iter
774 * must always be cleaned up again by calling drm_connector_list_iter_end().
775 * Iteration itself happens using drm_connector_list_iter_next() or
776 * drm_for_each_connector_iter().
778 void drm_connector_list_iter_begin(struct drm_device *dev,
779 struct drm_connector_list_iter *iter)
783 lock_acquire_shared_recursive(&connector_list_iter_dep_map, 0, 1, NULL, _RET_IP_);
785 EXPORT_SYMBOL(drm_connector_list_iter_begin);
788 * Extra-safe connector put function that works in any context. Should only be
789 * used from the connector_iter functions, where we never really expect to
790 * actually release the connector when dropping our final reference.
793 __drm_connector_put_safe(struct drm_connector *conn)
795 struct drm_mode_config *config = &conn->dev->mode_config;
797 lockdep_assert_held(&config->connector_list_lock);
799 if (!refcount_dec_and_test(&conn->base.refcount.refcount))
802 llist_add(&conn->free_node, &config->connector_free_list);
803 schedule_work(&config->connector_free_work);
807 * drm_connector_list_iter_next - return next connector
808 * @iter: connector_list iterator
810 * Returns: the next connector for @iter, or NULL when the list walk has
813 struct drm_connector *
814 drm_connector_list_iter_next(struct drm_connector_list_iter *iter)
816 struct drm_connector *old_conn = iter->conn;
817 struct drm_mode_config *config = &iter->dev->mode_config;
818 struct list_head *lhead;
821 spin_lock_irqsave(&config->connector_list_lock, flags);
822 lhead = old_conn ? &old_conn->head : &config->connector_list;
825 if (lhead->next == &config->connector_list) {
831 iter->conn = list_entry(lhead, struct drm_connector, head);
833 /* loop until it's not a zombie connector */
834 } while (!kref_get_unless_zero(&iter->conn->base.refcount));
837 __drm_connector_put_safe(old_conn);
838 spin_unlock_irqrestore(&config->connector_list_lock, flags);
842 EXPORT_SYMBOL(drm_connector_list_iter_next);
845 * drm_connector_list_iter_end - tear down a connector_list iterator
846 * @iter: connector_list iterator
848 * Tears down @iter and releases any resources (like &drm_connector references)
849 * acquired while walking the list. This must always be called, both when the
850 * iteration completes fully or when it was aborted without walking the entire
853 void drm_connector_list_iter_end(struct drm_connector_list_iter *iter)
855 struct drm_mode_config *config = &iter->dev->mode_config;
860 spin_lock_irqsave(&config->connector_list_lock, flags);
861 __drm_connector_put_safe(iter->conn);
862 spin_unlock_irqrestore(&config->connector_list_lock, flags);
864 lock_release(&connector_list_iter_dep_map, _RET_IP_);
866 EXPORT_SYMBOL(drm_connector_list_iter_end);
868 static const struct drm_prop_enum_list drm_subpixel_enum_list[] = {
869 { SubPixelUnknown, "Unknown" },
870 { SubPixelHorizontalRGB, "Horizontal RGB" },
871 { SubPixelHorizontalBGR, "Horizontal BGR" },
872 { SubPixelVerticalRGB, "Vertical RGB" },
873 { SubPixelVerticalBGR, "Vertical BGR" },
874 { SubPixelNone, "None" },
878 * drm_get_subpixel_order_name - return a string for a given subpixel enum
879 * @order: enum of subpixel_order
881 * Note you could abuse this and return something out of bounds, but that
882 * would be a caller error. No unscrubbed user data should make it here.
884 * Returns: string describing an enumerated subpixel property
886 const char *drm_get_subpixel_order_name(enum subpixel_order order)
888 return drm_subpixel_enum_list[order].name;
890 EXPORT_SYMBOL(drm_get_subpixel_order_name);
892 static const struct drm_prop_enum_list drm_dpms_enum_list[] = {
893 { DRM_MODE_DPMS_ON, "On" },
894 { DRM_MODE_DPMS_STANDBY, "Standby" },
895 { DRM_MODE_DPMS_SUSPEND, "Suspend" },
896 { DRM_MODE_DPMS_OFF, "Off" }
898 DRM_ENUM_NAME_FN(drm_get_dpms_name, drm_dpms_enum_list)
900 static const struct drm_prop_enum_list drm_link_status_enum_list[] = {
901 { DRM_MODE_LINK_STATUS_GOOD, "Good" },
902 { DRM_MODE_LINK_STATUS_BAD, "Bad" },
906 * drm_display_info_set_bus_formats - set the supported bus formats
907 * @info: display info to store bus formats in
908 * @formats: array containing the supported bus formats
909 * @num_formats: the number of entries in the fmts array
911 * Store the supported bus formats in display info structure.
912 * See MEDIA_BUS_FMT_* definitions in include/uapi/linux/media-bus-format.h for
913 * a full list of available formats.
916 * 0 on success or a negative error code on failure.
918 int drm_display_info_set_bus_formats(struct drm_display_info *info,
920 unsigned int num_formats)
924 if (!formats && num_formats)
927 if (formats && num_formats) {
928 fmts = kmemdup(formats, sizeof(*formats) * num_formats,
934 kfree(info->bus_formats);
935 info->bus_formats = fmts;
936 info->num_bus_formats = num_formats;
940 EXPORT_SYMBOL(drm_display_info_set_bus_formats);
942 /* Optional connector properties. */
943 static const struct drm_prop_enum_list drm_scaling_mode_enum_list[] = {
944 { DRM_MODE_SCALE_NONE, "None" },
945 { DRM_MODE_SCALE_FULLSCREEN, "Full" },
946 { DRM_MODE_SCALE_CENTER, "Center" },
947 { DRM_MODE_SCALE_ASPECT, "Full aspect" },
950 static const struct drm_prop_enum_list drm_aspect_ratio_enum_list[] = {
951 { DRM_MODE_PICTURE_ASPECT_NONE, "Automatic" },
952 { DRM_MODE_PICTURE_ASPECT_4_3, "4:3" },
953 { DRM_MODE_PICTURE_ASPECT_16_9, "16:9" },
956 static const struct drm_prop_enum_list drm_content_type_enum_list[] = {
957 { DRM_MODE_CONTENT_TYPE_NO_DATA, "No Data" },
958 { DRM_MODE_CONTENT_TYPE_GRAPHICS, "Graphics" },
959 { DRM_MODE_CONTENT_TYPE_PHOTO, "Photo" },
960 { DRM_MODE_CONTENT_TYPE_CINEMA, "Cinema" },
961 { DRM_MODE_CONTENT_TYPE_GAME, "Game" },
964 static const struct drm_prop_enum_list drm_panel_orientation_enum_list[] = {
965 { DRM_MODE_PANEL_ORIENTATION_NORMAL, "Normal" },
966 { DRM_MODE_PANEL_ORIENTATION_BOTTOM_UP, "Upside Down" },
967 { DRM_MODE_PANEL_ORIENTATION_LEFT_UP, "Left Side Up" },
968 { DRM_MODE_PANEL_ORIENTATION_RIGHT_UP, "Right Side Up" },
971 static const struct drm_prop_enum_list drm_dvi_i_select_enum_list[] = {
972 { DRM_MODE_SUBCONNECTOR_Automatic, "Automatic" }, /* DVI-I and TV-out */
973 { DRM_MODE_SUBCONNECTOR_DVID, "DVI-D" }, /* DVI-I */
974 { DRM_MODE_SUBCONNECTOR_DVIA, "DVI-A" }, /* DVI-I */
976 DRM_ENUM_NAME_FN(drm_get_dvi_i_select_name, drm_dvi_i_select_enum_list)
978 static const struct drm_prop_enum_list drm_dvi_i_subconnector_enum_list[] = {
979 { DRM_MODE_SUBCONNECTOR_Unknown, "Unknown" }, /* DVI-I, TV-out and DP */
980 { DRM_MODE_SUBCONNECTOR_DVID, "DVI-D" }, /* DVI-I */
981 { DRM_MODE_SUBCONNECTOR_DVIA, "DVI-A" }, /* DVI-I */
983 DRM_ENUM_NAME_FN(drm_get_dvi_i_subconnector_name,
984 drm_dvi_i_subconnector_enum_list)
986 static const struct drm_prop_enum_list drm_tv_select_enum_list[] = {
987 { DRM_MODE_SUBCONNECTOR_Automatic, "Automatic" }, /* DVI-I and TV-out */
988 { DRM_MODE_SUBCONNECTOR_Composite, "Composite" }, /* TV-out */
989 { DRM_MODE_SUBCONNECTOR_SVIDEO, "SVIDEO" }, /* TV-out */
990 { DRM_MODE_SUBCONNECTOR_Component, "Component" }, /* TV-out */
991 { DRM_MODE_SUBCONNECTOR_SCART, "SCART" }, /* TV-out */
993 DRM_ENUM_NAME_FN(drm_get_tv_select_name, drm_tv_select_enum_list)
995 static const struct drm_prop_enum_list drm_tv_subconnector_enum_list[] = {
996 { DRM_MODE_SUBCONNECTOR_Unknown, "Unknown" }, /* DVI-I, TV-out and DP */
997 { DRM_MODE_SUBCONNECTOR_Composite, "Composite" }, /* TV-out */
998 { DRM_MODE_SUBCONNECTOR_SVIDEO, "SVIDEO" }, /* TV-out */
999 { DRM_MODE_SUBCONNECTOR_Component, "Component" }, /* TV-out */
1000 { DRM_MODE_SUBCONNECTOR_SCART, "SCART" }, /* TV-out */
1002 DRM_ENUM_NAME_FN(drm_get_tv_subconnector_name,
1003 drm_tv_subconnector_enum_list)
1005 static const struct drm_prop_enum_list drm_dp_subconnector_enum_list[] = {
1006 { DRM_MODE_SUBCONNECTOR_Unknown, "Unknown" }, /* DVI-I, TV-out and DP */
1007 { DRM_MODE_SUBCONNECTOR_VGA, "VGA" }, /* DP */
1008 { DRM_MODE_SUBCONNECTOR_DVID, "DVI-D" }, /* DP */
1009 { DRM_MODE_SUBCONNECTOR_HDMIA, "HDMI" }, /* DP */
1010 { DRM_MODE_SUBCONNECTOR_DisplayPort, "DP" }, /* DP */
1011 { DRM_MODE_SUBCONNECTOR_Wireless, "Wireless" }, /* DP */
1012 { DRM_MODE_SUBCONNECTOR_Native, "Native" }, /* DP */
1015 DRM_ENUM_NAME_FN(drm_get_dp_subconnector_name,
1016 drm_dp_subconnector_enum_list)
1018 static const struct drm_prop_enum_list hdmi_colorspaces[] = {
1019 /* For Default case, driver will set the colorspace */
1020 { DRM_MODE_COLORIMETRY_DEFAULT, "Default" },
1021 /* Standard Definition Colorimetry based on CEA 861 */
1022 { DRM_MODE_COLORIMETRY_SMPTE_170M_YCC, "SMPTE_170M_YCC" },
1023 { DRM_MODE_COLORIMETRY_BT709_YCC, "BT709_YCC" },
1024 /* Standard Definition Colorimetry based on IEC 61966-2-4 */
1025 { DRM_MODE_COLORIMETRY_XVYCC_601, "XVYCC_601" },
1026 /* High Definition Colorimetry based on IEC 61966-2-4 */
1027 { DRM_MODE_COLORIMETRY_XVYCC_709, "XVYCC_709" },
1028 /* Colorimetry based on IEC 61966-2-1/Amendment 1 */
1029 { DRM_MODE_COLORIMETRY_SYCC_601, "SYCC_601" },
1030 /* Colorimetry based on IEC 61966-2-5 [33] */
1031 { DRM_MODE_COLORIMETRY_OPYCC_601, "opYCC_601" },
1032 /* Colorimetry based on IEC 61966-2-5 */
1033 { DRM_MODE_COLORIMETRY_OPRGB, "opRGB" },
1034 /* Colorimetry based on ITU-R BT.2020 */
1035 { DRM_MODE_COLORIMETRY_BT2020_CYCC, "BT2020_CYCC" },
1036 /* Colorimetry based on ITU-R BT.2020 */
1037 { DRM_MODE_COLORIMETRY_BT2020_RGB, "BT2020_RGB" },
1038 /* Colorimetry based on ITU-R BT.2020 */
1039 { DRM_MODE_COLORIMETRY_BT2020_YCC, "BT2020_YCC" },
1040 /* Added as part of Additional Colorimetry Extension in 861.G */
1041 { DRM_MODE_COLORIMETRY_DCI_P3_RGB_D65, "DCI-P3_RGB_D65" },
1042 { DRM_MODE_COLORIMETRY_DCI_P3_RGB_THEATER, "DCI-P3_RGB_Theater" },
1046 * As per DP 1.4a spec, 2.2.5.7.5 VSC SDP Payload for Pixel Encoding/Colorimetry
1047 * Format Table 2-120
1049 static const struct drm_prop_enum_list dp_colorspaces[] = {
1050 /* For Default case, driver will set the colorspace */
1051 { DRM_MODE_COLORIMETRY_DEFAULT, "Default" },
1052 { DRM_MODE_COLORIMETRY_RGB_WIDE_FIXED, "RGB_Wide_Gamut_Fixed_Point" },
1053 /* Colorimetry based on scRGB (IEC 61966-2-2) */
1054 { DRM_MODE_COLORIMETRY_RGB_WIDE_FLOAT, "RGB_Wide_Gamut_Floating_Point" },
1055 /* Colorimetry based on IEC 61966-2-5 */
1056 { DRM_MODE_COLORIMETRY_OPRGB, "opRGB" },
1057 /* Colorimetry based on SMPTE RP 431-2 */
1058 { DRM_MODE_COLORIMETRY_DCI_P3_RGB_D65, "DCI-P3_RGB_D65" },
1059 /* Colorimetry based on ITU-R BT.2020 */
1060 { DRM_MODE_COLORIMETRY_BT2020_RGB, "BT2020_RGB" },
1061 { DRM_MODE_COLORIMETRY_BT601_YCC, "BT601_YCC" },
1062 { DRM_MODE_COLORIMETRY_BT709_YCC, "BT709_YCC" },
1063 /* Standard Definition Colorimetry based on IEC 61966-2-4 */
1064 { DRM_MODE_COLORIMETRY_XVYCC_601, "XVYCC_601" },
1065 /* High Definition Colorimetry based on IEC 61966-2-4 */
1066 { DRM_MODE_COLORIMETRY_XVYCC_709, "XVYCC_709" },
1067 /* Colorimetry based on IEC 61966-2-1/Amendment 1 */
1068 { DRM_MODE_COLORIMETRY_SYCC_601, "SYCC_601" },
1069 /* Colorimetry based on IEC 61966-2-5 [33] */
1070 { DRM_MODE_COLORIMETRY_OPYCC_601, "opYCC_601" },
1071 /* Colorimetry based on ITU-R BT.2020 */
1072 { DRM_MODE_COLORIMETRY_BT2020_CYCC, "BT2020_CYCC" },
1073 /* Colorimetry based on ITU-R BT.2020 */
1074 { DRM_MODE_COLORIMETRY_BT2020_YCC, "BT2020_YCC" },
1078 * DOC: standard connector properties
1080 * DRM connectors have a few standardized properties:
1083 * Blob property which contains the current EDID read from the sink. This
1084 * is useful to parse sink identification information like vendor, model
1085 * and serial. Drivers should update this property by calling
1086 * drm_connector_update_edid_property(), usually after having parsed
1087 * the EDID using drm_add_edid_modes(). Userspace cannot change this
1090 * User-space should not parse the EDID to obtain information exposed via
1091 * other KMS properties (because the kernel might apply limits, quirks or
1092 * fixups to the EDID). For instance, user-space should not try to parse
1093 * mode lists from the EDID.
1095 * Legacy property for setting the power state of the connector. For atomic
1096 * drivers this is only provided for backwards compatibility with existing
1097 * drivers, it remaps to controlling the "ACTIVE" property on the CRTC the
1098 * connector is linked to. Drivers should never set this property directly,
1099 * it is handled by the DRM core by calling the &drm_connector_funcs.dpms
1100 * callback. For atomic drivers the remapping to the "ACTIVE" property is
1101 * implemented in the DRM core.
1103 * Note that this property cannot be set through the MODE_ATOMIC ioctl,
1104 * userspace must use "ACTIVE" on the CRTC instead.
1108 * For userspace also running on legacy drivers the "DPMS" semantics are a
1109 * lot more complicated. First, userspace cannot rely on the "DPMS" value
1110 * returned by the GETCONNECTOR actually reflecting reality, because many
1111 * drivers fail to update it. For atomic drivers this is taken care of in
1112 * drm_atomic_helper_update_legacy_modeset_state().
1114 * The second issue is that the DPMS state is only well-defined when the
1115 * connector is connected to a CRTC. In atomic the DRM core enforces that
1116 * "ACTIVE" is off in such a case, no such checks exists for "DPMS".
1118 * Finally, when enabling an output using the legacy SETCONFIG ioctl then
1119 * "DPMS" is forced to ON. But see above, that might not be reflected in
1120 * the software value on legacy drivers.
1122 * Summarizing: Only set "DPMS" when the connector is known to be enabled,
1123 * assume that a successful SETCONFIG call also sets "DPMS" to on, and
1124 * never read back the value of "DPMS" because it can be incorrect.
1126 * Connector path property to identify how this sink is physically
1127 * connected. Used by DP MST. This should be set by calling
1128 * drm_connector_set_path_property(), in the case of DP MST with the
1129 * path property the MST manager created. Userspace cannot change this
1132 * Connector tile group property to indicate how a set of DRM connector
1133 * compose together into one logical screen. This is used by both high-res
1134 * external screens (often only using a single cable, but exposing multiple
1135 * DP MST sinks), or high-res integrated panels (like dual-link DSI) which
1136 * are not gen-locked. Note that for tiled panels which are genlocked, like
1137 * dual-link LVDS or dual-link DSI, the driver should try to not expose the
1138 * tiling and virtualise both &drm_crtc and &drm_plane if needed. Drivers
1139 * should update this value using drm_connector_set_tile_property().
1140 * Userspace cannot change this property.
1142 * Connector link-status property to indicate the status of link. The
1143 * default value of link-status is "GOOD". If something fails during or
1144 * after modeset, the kernel driver may set this to "BAD" and issue a
1145 * hotplug uevent. Drivers should update this value using
1146 * drm_connector_set_link_status_property().
1148 * When user-space receives the hotplug uevent and detects a "BAD"
1149 * link-status, the sink doesn't receive pixels anymore (e.g. the screen
1150 * becomes completely black). The list of available modes may have
1151 * changed. User-space is expected to pick a new mode if the current one
1152 * has disappeared and perform a new modeset with link-status set to
1153 * "GOOD" to re-enable the connector.
1155 * If multiple connectors share the same CRTC and one of them gets a "BAD"
1156 * link-status, the other are unaffected (ie. the sinks still continue to
1159 * When user-space performs an atomic commit on a connector with a "BAD"
1160 * link-status without resetting the property to "GOOD", the sink may
1161 * still not receive pixels. When user-space performs an atomic commit
1162 * which resets the link-status property to "GOOD" without the
1163 * ALLOW_MODESET flag set, it might fail because a modeset is required.
1165 * User-space can only change link-status to "GOOD", changing it to "BAD"
1168 * For backwards compatibility with non-atomic userspace the kernel
1169 * tries to automatically set the link-status back to "GOOD" in the
1170 * SETCRTC IOCTL. This might fail if the mode is no longer valid, similar
1171 * to how it might fail if a different screen has been connected in the
1174 * Indicates the output should be ignored for purposes of displaying a
1175 * standard desktop environment or console. This is most likely because
1176 * the output device is not rectilinear.
1177 * Content Protection:
1178 * This property is used by userspace to request the kernel protect future
1179 * content communicated over the link. When requested, kernel will apply
1180 * the appropriate means of protection (most often HDCP), and use the
1181 * property to tell userspace the protection is active.
1183 * Drivers can set this up by calling
1184 * drm_connector_attach_content_protection_property() on initialization.
1186 * The value of this property can be one of the following:
1188 * DRM_MODE_CONTENT_PROTECTION_UNDESIRED = 0
1189 * The link is not protected, content is transmitted in the clear.
1190 * DRM_MODE_CONTENT_PROTECTION_DESIRED = 1
1191 * Userspace has requested content protection, but the link is not
1192 * currently protected. When in this state, kernel should enable
1193 * Content Protection as soon as possible.
1194 * DRM_MODE_CONTENT_PROTECTION_ENABLED = 2
1195 * Userspace has requested content protection, and the link is
1196 * protected. Only the driver can set the property to this value.
1197 * If userspace attempts to set to ENABLED, kernel will return
1202 * - DESIRED state should be preserved until userspace de-asserts it by
1203 * setting the property to UNDESIRED. This means ENABLED should only
1204 * transition to UNDESIRED when the user explicitly requests it.
1205 * - If the state is DESIRED, kernel should attempt to re-authenticate the
1206 * link whenever possible. This includes across disable/enable, dpms,
1207 * hotplug, downstream device changes, link status failures, etc..
1208 * - Kernel sends uevent with the connector id and property id through
1209 * @drm_hdcp_update_content_protection, upon below kernel triggered
1212 * - DESIRED -> ENABLED (authentication success)
1213 * - ENABLED -> DESIRED (termination of authentication)
1214 * - Please note no uevents for userspace triggered property state changes,
1215 * which can't fail such as
1217 * - DESIRED/ENABLED -> UNDESIRED
1218 * - UNDESIRED -> DESIRED
1219 * - Userspace is responsible for polling the property or listen to uevents
1220 * to determine when the value transitions from ENABLED to DESIRED.
1221 * This signifies the link is no longer protected and userspace should
1222 * take appropriate action (whatever that might be).
1224 * HDCP Content Type:
1225 * This Enum property is used by the userspace to declare the content type
1226 * of the display stream, to kernel. Here display stream stands for any
1227 * display content that userspace intended to display through HDCP
1230 * Content Type of a stream is decided by the owner of the stream, as
1231 * "HDCP Type0" or "HDCP Type1".
1233 * The value of the property can be one of the below:
1234 * - "HDCP Type0": DRM_MODE_HDCP_CONTENT_TYPE0 = 0
1235 * - "HDCP Type1": DRM_MODE_HDCP_CONTENT_TYPE1 = 1
1237 * When kernel starts the HDCP authentication (see "Content Protection"
1238 * for details), it uses the content type in "HDCP Content Type"
1239 * for performing the HDCP authentication with the display sink.
1241 * Please note in HDCP spec versions, a link can be authenticated with
1242 * HDCP 2.2 for Content Type 0/Content Type 1. Where as a link can be
1243 * authenticated with HDCP1.4 only for Content Type 0(though it is implicit
1244 * in nature. As there is no reference for Content Type in HDCP1.4).
1246 * HDCP2.2 authentication protocol itself takes the "Content Type" as a
1247 * parameter, which is a input for the DP HDCP2.2 encryption algo.
1249 * In case of Type 0 content protection request, kernel driver can choose
1250 * either of HDCP spec versions 1.4 and 2.2. When HDCP2.2 is used for
1251 * "HDCP Type 0", a HDCP 2.2 capable repeater in the downstream can send
1252 * that content to a HDCP 1.4 authenticated HDCP sink (Type0 link).
1253 * But if the content is classified as "HDCP Type 1", above mentioned
1254 * HDCP 2.2 repeater wont send the content to the HDCP sink as it can't
1255 * authenticate the HDCP1.4 capable sink for "HDCP Type 1".
1257 * Please note userspace can be ignorant of the HDCP versions used by the
1258 * kernel driver to achieve the "HDCP Content Type".
1260 * At current scenario, classifying a content as Type 1 ensures that the
1261 * content will be displayed only through the HDCP2.2 encrypted link.
1263 * Note that the HDCP Content Type property is introduced at HDCP 2.2, and
1264 * defaults to type 0. It is only exposed by drivers supporting HDCP 2.2
1265 * (hence supporting Type 0 and Type 1). Based on how next versions of
1266 * HDCP specs are defined content Type could be used for higher versions
1269 * If content type is changed when "Content Protection" is not UNDESIRED,
1270 * then kernel will disable the HDCP and re-enable with new type in the
1271 * same atomic commit. And when "Content Protection" is ENABLED, it means
1272 * that link is HDCP authenticated and encrypted, for the transmission of
1273 * the Type of stream mentioned at "HDCP Content Type".
1275 * HDR_OUTPUT_METADATA:
1276 * Connector property to enable userspace to send HDR Metadata to
1277 * driver. This metadata is based on the composition and blending
1278 * policies decided by user, taking into account the hardware and
1279 * sink capabilities. The driver gets this metadata and creates a
1280 * Dynamic Range and Mastering Infoframe (DRM) in case of HDMI,
1281 * SDP packet (Non-audio INFOFRAME SDP v1.3) for DP. This is then
1282 * sent to sink. This notifies the sink of the upcoming frame's Color
1283 * Encoding and Luminance parameters.
1285 * Userspace first need to detect the HDR capabilities of sink by
1286 * reading and parsing the EDID. Details of HDR metadata for HDMI
1287 * are added in CTA 861.G spec. For DP , its defined in VESA DP
1288 * Standard v1.4. It needs to then get the metadata information
1289 * of the video/game/app content which are encoded in HDR (basically
1290 * using HDR transfer functions). With this information it needs to
1291 * decide on a blending policy and compose the relevant
1292 * layers/overlays into a common format. Once this blending is done,
1293 * userspace will be aware of the metadata of the composed frame to
1294 * be send to sink. It then uses this property to communicate this
1295 * metadata to driver which then make a Infoframe packet and sends
1296 * to sink based on the type of encoder connected.
1298 * Userspace will be responsible to do Tone mapping operation in case:
1299 * - Some layers are HDR and others are SDR
1300 * - HDR layers luminance is not same as sink
1302 * It will even need to do colorspace conversion and get all layers
1303 * to one common colorspace for blending. It can use either GL, Media
1304 * or display engine to get this done based on the capabilities of the
1305 * associated hardware.
1307 * Driver expects metadata to be put in &struct hdr_output_metadata
1308 * structure from userspace. This is received as blob and stored in
1309 * &drm_connector_state.hdr_output_metadata. It parses EDID and saves the
1310 * sink metadata in &struct hdr_sink_metadata, as
1311 * &drm_connector.hdr_sink_metadata. Driver uses
1312 * drm_hdmi_infoframe_set_hdr_metadata() helper to set the HDR metadata,
1313 * hdmi_drm_infoframe_pack() to pack the infoframe as per spec, in case of
1317 * This range property is used by userspace to limit the bit depth. When
1318 * used the driver would limit the bpc in accordance with the valid range
1319 * supported by the hardware and sink. Drivers to use the function
1320 * drm_connector_attach_max_bpc_property() to create and attach the
1321 * property to the connector during initialization.
1323 * Connectors also have one standardized atomic property:
1326 * Mode object ID of the &drm_crtc this connector should be connected to.
1328 * Connectors for LCD panels may also have one standardized property:
1330 * panel orientation:
1331 * On some devices the LCD panel is mounted in the casing in such a way
1332 * that the up/top side of the panel does not match with the top side of
1333 * the device. Userspace can use this property to check for this.
1334 * Note that input coordinates from touchscreens (input devices with
1335 * INPUT_PROP_DIRECT) will still map 1:1 to the actual LCD panel
1336 * coordinates, so if userspace rotates the picture to adjust for
1337 * the orientation it must also apply the same transformation to the
1338 * touchscreen input coordinates. This property is initialized by calling
1339 * drm_connector_set_panel_orientation() or
1340 * drm_connector_set_panel_orientation_with_quirk()
1343 * This property defines how a non-native mode is upscaled to the native
1344 * mode of an LCD panel:
1347 * No upscaling happens, scaling is left to the panel. Not all
1348 * drivers expose this mode.
1350 * The output is upscaled to the full resolution of the panel,
1351 * ignoring the aspect ratio.
1353 * No upscaling happens, the output is centered within the native
1354 * resolution the panel.
1356 * The output is upscaled to maximize either the width or height
1357 * while retaining the aspect ratio.
1359 * This property should be set up by calling
1360 * drm_connector_attach_scaling_mode_property(). Note that drivers
1361 * can also expose this property to external outputs, in which case they
1362 * must support "None", which should be the default (since external screens
1363 * have a built-in scaler).
1366 * This property is used by DVI-I, TVout and DisplayPort to indicate different
1367 * connector subtypes. Enum values more or less match with those from main
1369 * For DVI-I and TVout there is also a matching property "select subconnector"
1370 * allowing to switch between signal types.
1371 * DP subconnector corresponds to a downstream port.
1373 * privacy-screen sw-state, privacy-screen hw-state:
1374 * These 2 optional properties can be used to query the state of the
1375 * electronic privacy screen that is available on some displays; and in
1376 * some cases also control the state. If a driver implements these
1377 * properties then both properties must be present.
1379 * "privacy-screen hw-state" is read-only and reflects the actual state
1380 * of the privacy-screen, possible values: "Enabled", "Disabled,
1381 * "Enabled-locked", "Disabled-locked". The locked states indicate
1382 * that the state cannot be changed through the DRM API. E.g. there
1383 * might be devices where the firmware-setup options, or a hardware
1384 * slider-switch, offer always on / off modes.
1386 * "privacy-screen sw-state" can be set to change the privacy-screen state
1387 * when not locked. In this case the driver must update the hw-state
1388 * property to reflect the new state on completion of the commit of the
1389 * sw-state property. Setting the sw-state property when the hw-state is
1390 * locked must be interpreted by the driver as a request to change the
1391 * state to the set state when the hw-state becomes unlocked. E.g. if
1392 * "privacy-screen hw-state" is "Enabled-locked" and the sw-state
1393 * gets set to "Disabled" followed by the user unlocking the state by
1394 * changing the slider-switch position, then the driver must set the
1395 * state to "Disabled" upon receiving the unlock event.
1397 * In some cases the privacy-screen's actual state might change outside of
1398 * control of the DRM code. E.g. there might be a firmware handled hotkey
1399 * which toggles the actual state, or the actual state might be changed
1400 * through another userspace API such as writing /proc/acpi/ibm/lcdshadow.
1401 * In this case the driver must update both the hw-state and the sw-state
1402 * to reflect the new value, overwriting any pending state requests in the
1403 * sw-state. Any pending sw-state requests are thus discarded.
1405 * Note that the ability for the state to change outside of control of
1406 * the DRM master process means that userspace must not cache the value
1407 * of the sw-state. Caching the sw-state value and including it in later
1408 * atomic commits may lead to overriding a state change done through e.g.
1409 * a firmware handled hotkey. Therefor userspace must not include the
1410 * privacy-screen sw-state in an atomic commit unless it wants to change
1414 int drm_connector_create_standard_properties(struct drm_device *dev)
1416 struct drm_property *prop;
1418 prop = drm_property_create(dev, DRM_MODE_PROP_BLOB |
1419 DRM_MODE_PROP_IMMUTABLE,
1423 dev->mode_config.edid_property = prop;
1425 prop = drm_property_create_enum(dev, 0,
1426 "DPMS", drm_dpms_enum_list,
1427 ARRAY_SIZE(drm_dpms_enum_list));
1430 dev->mode_config.dpms_property = prop;
1432 prop = drm_property_create(dev,
1433 DRM_MODE_PROP_BLOB |
1434 DRM_MODE_PROP_IMMUTABLE,
1438 dev->mode_config.path_property = prop;
1440 prop = drm_property_create(dev,
1441 DRM_MODE_PROP_BLOB |
1442 DRM_MODE_PROP_IMMUTABLE,
1446 dev->mode_config.tile_property = prop;
1448 prop = drm_property_create_enum(dev, 0, "link-status",
1449 drm_link_status_enum_list,
1450 ARRAY_SIZE(drm_link_status_enum_list));
1453 dev->mode_config.link_status_property = prop;
1455 prop = drm_property_create_bool(dev, DRM_MODE_PROP_IMMUTABLE, "non-desktop");
1458 dev->mode_config.non_desktop_property = prop;
1460 prop = drm_property_create(dev, DRM_MODE_PROP_BLOB,
1461 "HDR_OUTPUT_METADATA", 0);
1464 dev->mode_config.hdr_output_metadata_property = prop;
1470 * drm_mode_create_dvi_i_properties - create DVI-I specific connector properties
1473 * Called by a driver the first time a DVI-I connector is made.
1477 int drm_mode_create_dvi_i_properties(struct drm_device *dev)
1479 struct drm_property *dvi_i_selector;
1480 struct drm_property *dvi_i_subconnector;
1482 if (dev->mode_config.dvi_i_select_subconnector_property)
1486 drm_property_create_enum(dev, 0,
1487 "select subconnector",
1488 drm_dvi_i_select_enum_list,
1489 ARRAY_SIZE(drm_dvi_i_select_enum_list));
1490 dev->mode_config.dvi_i_select_subconnector_property = dvi_i_selector;
1492 dvi_i_subconnector = drm_property_create_enum(dev, DRM_MODE_PROP_IMMUTABLE,
1494 drm_dvi_i_subconnector_enum_list,
1495 ARRAY_SIZE(drm_dvi_i_subconnector_enum_list));
1496 dev->mode_config.dvi_i_subconnector_property = dvi_i_subconnector;
1500 EXPORT_SYMBOL(drm_mode_create_dvi_i_properties);
1503 * drm_connector_attach_dp_subconnector_property - create subconnector property for DP
1504 * @connector: drm_connector to attach property
1506 * Called by a driver when DP connector is created.
1508 void drm_connector_attach_dp_subconnector_property(struct drm_connector *connector)
1510 struct drm_mode_config *mode_config = &connector->dev->mode_config;
1512 if (!mode_config->dp_subconnector_property)
1513 mode_config->dp_subconnector_property =
1514 drm_property_create_enum(connector->dev,
1515 DRM_MODE_PROP_IMMUTABLE,
1517 drm_dp_subconnector_enum_list,
1518 ARRAY_SIZE(drm_dp_subconnector_enum_list));
1520 drm_object_attach_property(&connector->base,
1521 mode_config->dp_subconnector_property,
1522 DRM_MODE_SUBCONNECTOR_Unknown);
1524 EXPORT_SYMBOL(drm_connector_attach_dp_subconnector_property);
1527 * DOC: HDMI connector properties
1529 * content type (HDMI specific):
1530 * Indicates content type setting to be used in HDMI infoframes to indicate
1531 * content type for the external device, so that it adjusts its display
1532 * settings accordingly.
1534 * The value of this property can be one of the following:
1537 * Content type is unknown
1539 * Content type is graphics
1541 * Content type is photo
1543 * Content type is cinema
1545 * Content type is game
1547 * The meaning of each content type is defined in CTA-861-G table 15.
1549 * Drivers can set up this property by calling
1550 * drm_connector_attach_content_type_property(). Decoding to
1551 * infoframe values is done through drm_hdmi_avi_infoframe_content_type().
1555 * drm_connector_attach_content_type_property - attach content-type property
1556 * @connector: connector to attach content type property on.
1558 * Called by a driver the first time a HDMI connector is made.
1562 int drm_connector_attach_content_type_property(struct drm_connector *connector)
1564 if (!drm_mode_create_content_type_property(connector->dev))
1565 drm_object_attach_property(&connector->base,
1566 connector->dev->mode_config.content_type_property,
1567 DRM_MODE_CONTENT_TYPE_NO_DATA);
1570 EXPORT_SYMBOL(drm_connector_attach_content_type_property);
1573 * drm_connector_attach_tv_margin_properties - attach TV connector margin
1575 * @connector: DRM connector
1577 * Called by a driver when it needs to attach TV margin props to a connector.
1578 * Typically used on SDTV and HDMI connectors.
1580 void drm_connector_attach_tv_margin_properties(struct drm_connector *connector)
1582 struct drm_device *dev = connector->dev;
1584 drm_object_attach_property(&connector->base,
1585 dev->mode_config.tv_left_margin_property,
1587 drm_object_attach_property(&connector->base,
1588 dev->mode_config.tv_right_margin_property,
1590 drm_object_attach_property(&connector->base,
1591 dev->mode_config.tv_top_margin_property,
1593 drm_object_attach_property(&connector->base,
1594 dev->mode_config.tv_bottom_margin_property,
1597 EXPORT_SYMBOL(drm_connector_attach_tv_margin_properties);
1600 * drm_mode_create_tv_margin_properties - create TV connector margin properties
1603 * Called by a driver's HDMI connector initialization routine, this function
1604 * creates the TV margin properties for a given device. No need to call this
1605 * function for an SDTV connector, it's already called from
1606 * drm_mode_create_tv_properties().
1609 * 0 on success or a negative error code on failure.
1611 int drm_mode_create_tv_margin_properties(struct drm_device *dev)
1613 if (dev->mode_config.tv_left_margin_property)
1616 dev->mode_config.tv_left_margin_property =
1617 drm_property_create_range(dev, 0, "left margin", 0, 100);
1618 if (!dev->mode_config.tv_left_margin_property)
1621 dev->mode_config.tv_right_margin_property =
1622 drm_property_create_range(dev, 0, "right margin", 0, 100);
1623 if (!dev->mode_config.tv_right_margin_property)
1626 dev->mode_config.tv_top_margin_property =
1627 drm_property_create_range(dev, 0, "top margin", 0, 100);
1628 if (!dev->mode_config.tv_top_margin_property)
1631 dev->mode_config.tv_bottom_margin_property =
1632 drm_property_create_range(dev, 0, "bottom margin", 0, 100);
1633 if (!dev->mode_config.tv_bottom_margin_property)
1638 EXPORT_SYMBOL(drm_mode_create_tv_margin_properties);
1641 * drm_mode_create_tv_properties - create TV specific connector properties
1643 * @num_modes: number of different TV formats (modes) supported
1644 * @modes: array of pointers to strings containing name of each format
1646 * Called by a driver's TV initialization routine, this function creates
1647 * the TV specific connector properties for a given device. Caller is
1648 * responsible for allocating a list of format names and passing them to
1652 * 0 on success or a negative error code on failure.
1654 int drm_mode_create_tv_properties(struct drm_device *dev,
1655 unsigned int num_modes,
1656 const char * const modes[])
1658 struct drm_property *tv_selector;
1659 struct drm_property *tv_subconnector;
1662 if (dev->mode_config.tv_select_subconnector_property)
1666 * Basic connector properties
1668 tv_selector = drm_property_create_enum(dev, 0,
1669 "select subconnector",
1670 drm_tv_select_enum_list,
1671 ARRAY_SIZE(drm_tv_select_enum_list));
1675 dev->mode_config.tv_select_subconnector_property = tv_selector;
1678 drm_property_create_enum(dev, DRM_MODE_PROP_IMMUTABLE,
1680 drm_tv_subconnector_enum_list,
1681 ARRAY_SIZE(drm_tv_subconnector_enum_list));
1682 if (!tv_subconnector)
1684 dev->mode_config.tv_subconnector_property = tv_subconnector;
1687 * Other, TV specific properties: margins & TV modes.
1689 if (drm_mode_create_tv_margin_properties(dev))
1692 dev->mode_config.tv_mode_property =
1693 drm_property_create(dev, DRM_MODE_PROP_ENUM,
1695 if (!dev->mode_config.tv_mode_property)
1698 for (i = 0; i < num_modes; i++)
1699 drm_property_add_enum(dev->mode_config.tv_mode_property,
1702 dev->mode_config.tv_brightness_property =
1703 drm_property_create_range(dev, 0, "brightness", 0, 100);
1704 if (!dev->mode_config.tv_brightness_property)
1707 dev->mode_config.tv_contrast_property =
1708 drm_property_create_range(dev, 0, "contrast", 0, 100);
1709 if (!dev->mode_config.tv_contrast_property)
1712 dev->mode_config.tv_flicker_reduction_property =
1713 drm_property_create_range(dev, 0, "flicker reduction", 0, 100);
1714 if (!dev->mode_config.tv_flicker_reduction_property)
1717 dev->mode_config.tv_overscan_property =
1718 drm_property_create_range(dev, 0, "overscan", 0, 100);
1719 if (!dev->mode_config.tv_overscan_property)
1722 dev->mode_config.tv_saturation_property =
1723 drm_property_create_range(dev, 0, "saturation", 0, 100);
1724 if (!dev->mode_config.tv_saturation_property)
1727 dev->mode_config.tv_hue_property =
1728 drm_property_create_range(dev, 0, "hue", 0, 100);
1729 if (!dev->mode_config.tv_hue_property)
1736 EXPORT_SYMBOL(drm_mode_create_tv_properties);
1739 * drm_mode_create_scaling_mode_property - create scaling mode property
1742 * Called by a driver the first time it's needed, must be attached to desired
1745 * Atomic drivers should use drm_connector_attach_scaling_mode_property()
1746 * instead to correctly assign &drm_connector_state.scaling_mode
1747 * in the atomic state.
1751 int drm_mode_create_scaling_mode_property(struct drm_device *dev)
1753 struct drm_property *scaling_mode;
1755 if (dev->mode_config.scaling_mode_property)
1759 drm_property_create_enum(dev, 0, "scaling mode",
1760 drm_scaling_mode_enum_list,
1761 ARRAY_SIZE(drm_scaling_mode_enum_list));
1763 dev->mode_config.scaling_mode_property = scaling_mode;
1767 EXPORT_SYMBOL(drm_mode_create_scaling_mode_property);
1770 * DOC: Variable refresh properties
1772 * Variable refresh rate capable displays can dynamically adjust their
1773 * refresh rate by extending the duration of their vertical front porch
1774 * until page flip or timeout occurs. This can reduce or remove stuttering
1775 * and latency in scenarios where the page flip does not align with the
1778 * An example scenario would be an application flipping at a constant rate
1779 * of 48Hz on a 60Hz display. The page flip will frequently miss the vblank
1780 * interval and the same contents will be displayed twice. This can be
1781 * observed as stuttering for content with motion.
1783 * If variable refresh rate was active on a display that supported a
1784 * variable refresh range from 35Hz to 60Hz no stuttering would be observable
1785 * for the example scenario. The minimum supported variable refresh rate of
1786 * 35Hz is below the page flip frequency and the vertical front porch can
1787 * be extended until the page flip occurs. The vblank interval will be
1788 * directly aligned to the page flip rate.
1790 * Not all userspace content is suitable for use with variable refresh rate.
1791 * Large and frequent changes in vertical front porch duration may worsen
1792 * perceived stuttering for input sensitive applications.
1794 * Panel brightness will also vary with vertical front porch duration. Some
1795 * panels may have noticeable differences in brightness between the minimum
1796 * vertical front porch duration and the maximum vertical front porch duration.
1797 * Large and frequent changes in vertical front porch duration may produce
1798 * observable flickering for such panels.
1800 * Userspace control for variable refresh rate is supported via properties
1801 * on the &drm_connector and &drm_crtc objects.
1804 * Optional &drm_connector boolean property that drivers should attach
1805 * with drm_connector_attach_vrr_capable_property() on connectors that
1806 * could support variable refresh rates. Drivers should update the
1807 * property value by calling drm_connector_set_vrr_capable_property().
1809 * Absence of the property should indicate absence of support.
1812 * Default &drm_crtc boolean property that notifies the driver that the
1813 * content on the CRTC is suitable for variable refresh rate presentation.
1814 * The driver will take this property as a hint to enable variable
1815 * refresh rate support if the receiver supports it, ie. if the
1816 * "vrr_capable" property is true on the &drm_connector object. The
1817 * vertical front porch duration will be extended until page-flip or
1818 * timeout when enabled.
1820 * The minimum vertical front porch duration is defined as the vertical
1821 * front porch duration for the current mode.
1823 * The maximum vertical front porch duration is greater than or equal to
1824 * the minimum vertical front porch duration. The duration is derived
1825 * from the minimum supported variable refresh rate for the connector.
1827 * The driver may place further restrictions within these minimum
1828 * and maximum bounds.
1832 * drm_connector_attach_vrr_capable_property - creates the
1833 * vrr_capable property
1834 * @connector: connector to create the vrr_capable property on.
1836 * This is used by atomic drivers to add support for querying
1837 * variable refresh rate capability for a connector.
1840 * Zero on success, negative errno on failure.
1842 int drm_connector_attach_vrr_capable_property(
1843 struct drm_connector *connector)
1845 struct drm_device *dev = connector->dev;
1846 struct drm_property *prop;
1848 if (!connector->vrr_capable_property) {
1849 prop = drm_property_create_bool(dev, DRM_MODE_PROP_IMMUTABLE,
1854 connector->vrr_capable_property = prop;
1855 drm_object_attach_property(&connector->base, prop, 0);
1860 EXPORT_SYMBOL(drm_connector_attach_vrr_capable_property);
1863 * drm_connector_attach_scaling_mode_property - attach atomic scaling mode property
1864 * @connector: connector to attach scaling mode property on.
1865 * @scaling_mode_mask: or'ed mask of BIT(%DRM_MODE_SCALE_\*).
1867 * This is used to add support for scaling mode to atomic drivers.
1868 * The scaling mode will be set to &drm_connector_state.scaling_mode
1869 * and can be used from &drm_connector_helper_funcs->atomic_check for validation.
1871 * This is the atomic version of drm_mode_create_scaling_mode_property().
1874 * Zero on success, negative errno on failure.
1876 int drm_connector_attach_scaling_mode_property(struct drm_connector *connector,
1877 u32 scaling_mode_mask)
1879 struct drm_device *dev = connector->dev;
1880 struct drm_property *scaling_mode_property;
1882 const unsigned valid_scaling_mode_mask =
1883 (1U << ARRAY_SIZE(drm_scaling_mode_enum_list)) - 1;
1885 if (WARN_ON(hweight32(scaling_mode_mask) < 2 ||
1886 scaling_mode_mask & ~valid_scaling_mode_mask))
1889 scaling_mode_property =
1890 drm_property_create(dev, DRM_MODE_PROP_ENUM, "scaling mode",
1891 hweight32(scaling_mode_mask));
1893 if (!scaling_mode_property)
1896 for (i = 0; i < ARRAY_SIZE(drm_scaling_mode_enum_list); i++) {
1899 if (!(BIT(i) & scaling_mode_mask))
1902 ret = drm_property_add_enum(scaling_mode_property,
1903 drm_scaling_mode_enum_list[i].type,
1904 drm_scaling_mode_enum_list[i].name);
1907 drm_property_destroy(dev, scaling_mode_property);
1913 drm_object_attach_property(&connector->base,
1914 scaling_mode_property, 0);
1916 connector->scaling_mode_property = scaling_mode_property;
1920 EXPORT_SYMBOL(drm_connector_attach_scaling_mode_property);
1923 * drm_mode_create_aspect_ratio_property - create aspect ratio property
1926 * Called by a driver the first time it's needed, must be attached to desired
1930 * Zero on success, negative errno on failure.
1932 int drm_mode_create_aspect_ratio_property(struct drm_device *dev)
1934 if (dev->mode_config.aspect_ratio_property)
1937 dev->mode_config.aspect_ratio_property =
1938 drm_property_create_enum(dev, 0, "aspect ratio",
1939 drm_aspect_ratio_enum_list,
1940 ARRAY_SIZE(drm_aspect_ratio_enum_list));
1942 if (dev->mode_config.aspect_ratio_property == NULL)
1947 EXPORT_SYMBOL(drm_mode_create_aspect_ratio_property);
1950 * DOC: standard connector properties
1953 * This property helps select a suitable colorspace based on the sink
1954 * capability. Modern sink devices support wider gamut like BT2020.
1955 * This helps switch to BT2020 mode if the BT2020 encoded video stream
1956 * is being played by the user, same for any other colorspace. Thereby
1957 * giving a good visual experience to users.
1959 * The expectation from userspace is that it should parse the EDID
1960 * and get supported colorspaces. Use this property and switch to the
1961 * one supported. Sink supported colorspaces should be retrieved by
1962 * userspace from EDID and driver will not explicitly expose them.
1964 * Basically the expectation from userspace is:
1965 * - Set up CRTC DEGAMMA/CTM/GAMMA to convert to some sink
1967 * - Set this new property to let the sink know what it
1968 * converted the CRTC output to.
1969 * - This property is just to inform sink what colorspace
1970 * source is trying to drive.
1972 * Because between HDMI and DP have different colorspaces,
1973 * drm_mode_create_hdmi_colorspace_property() is used for HDMI connector and
1974 * drm_mode_create_dp_colorspace_property() is used for DP connector.
1978 * drm_mode_create_hdmi_colorspace_property - create hdmi colorspace property
1979 * @connector: connector to create the Colorspace property on.
1981 * Called by a driver the first time it's needed, must be attached to desired
1985 * Zero on success, negative errno on failure.
1987 int drm_mode_create_hdmi_colorspace_property(struct drm_connector *connector)
1989 struct drm_device *dev = connector->dev;
1991 if (connector->colorspace_property)
1994 connector->colorspace_property =
1995 drm_property_create_enum(dev, DRM_MODE_PROP_ENUM, "Colorspace",
1997 ARRAY_SIZE(hdmi_colorspaces));
1999 if (!connector->colorspace_property)
2004 EXPORT_SYMBOL(drm_mode_create_hdmi_colorspace_property);
2007 * drm_mode_create_dp_colorspace_property - create dp colorspace property
2008 * @connector: connector to create the Colorspace property on.
2010 * Called by a driver the first time it's needed, must be attached to desired
2014 * Zero on success, negative errno on failure.
2016 int drm_mode_create_dp_colorspace_property(struct drm_connector *connector)
2018 struct drm_device *dev = connector->dev;
2020 if (connector->colorspace_property)
2023 connector->colorspace_property =
2024 drm_property_create_enum(dev, DRM_MODE_PROP_ENUM, "Colorspace",
2026 ARRAY_SIZE(dp_colorspaces));
2028 if (!connector->colorspace_property)
2033 EXPORT_SYMBOL(drm_mode_create_dp_colorspace_property);
2036 * drm_mode_create_content_type_property - create content type property
2039 * Called by a driver the first time it's needed, must be attached to desired
2043 * Zero on success, negative errno on failure.
2045 int drm_mode_create_content_type_property(struct drm_device *dev)
2047 if (dev->mode_config.content_type_property)
2050 dev->mode_config.content_type_property =
2051 drm_property_create_enum(dev, 0, "content type",
2052 drm_content_type_enum_list,
2053 ARRAY_SIZE(drm_content_type_enum_list));
2055 if (dev->mode_config.content_type_property == NULL)
2060 EXPORT_SYMBOL(drm_mode_create_content_type_property);
2063 * drm_mode_create_suggested_offset_properties - create suggests offset properties
2066 * Create the suggested x/y offset property for connectors.
2069 * 0 on success or a negative error code on failure.
2071 int drm_mode_create_suggested_offset_properties(struct drm_device *dev)
2073 if (dev->mode_config.suggested_x_property && dev->mode_config.suggested_y_property)
2076 dev->mode_config.suggested_x_property =
2077 drm_property_create_range(dev, DRM_MODE_PROP_IMMUTABLE, "suggested X", 0, 0xffffffff);
2079 dev->mode_config.suggested_y_property =
2080 drm_property_create_range(dev, DRM_MODE_PROP_IMMUTABLE, "suggested Y", 0, 0xffffffff);
2082 if (dev->mode_config.suggested_x_property == NULL ||
2083 dev->mode_config.suggested_y_property == NULL)
2087 EXPORT_SYMBOL(drm_mode_create_suggested_offset_properties);
2090 * drm_connector_set_path_property - set tile property on connector
2091 * @connector: connector to set property on.
2092 * @path: path to use for property; must not be NULL.
2094 * This creates a property to expose to userspace to specify a
2095 * connector path. This is mainly used for DisplayPort MST where
2096 * connectors have a topology and we want to allow userspace to give
2097 * them more meaningful names.
2100 * Zero on success, negative errno on failure.
2102 int drm_connector_set_path_property(struct drm_connector *connector,
2105 struct drm_device *dev = connector->dev;
2108 ret = drm_property_replace_global_blob(dev,
2109 &connector->path_blob_ptr,
2113 dev->mode_config.path_property);
2116 EXPORT_SYMBOL(drm_connector_set_path_property);
2119 * drm_connector_set_tile_property - set tile property on connector
2120 * @connector: connector to set property on.
2122 * This looks up the tile information for a connector, and creates a
2123 * property for userspace to parse if it exists. The property is of
2124 * the form of 8 integers using ':' as a separator.
2125 * This is used for dual port tiled displays with DisplayPort SST
2126 * or DisplayPort MST connectors.
2129 * Zero on success, errno on failure.
2131 int drm_connector_set_tile_property(struct drm_connector *connector)
2133 struct drm_device *dev = connector->dev;
2137 if (!connector->has_tile) {
2138 ret = drm_property_replace_global_blob(dev,
2139 &connector->tile_blob_ptr,
2143 dev->mode_config.tile_property);
2147 snprintf(tile, 256, "%d:%d:%d:%d:%d:%d:%d:%d",
2148 connector->tile_group->id, connector->tile_is_single_monitor,
2149 connector->num_h_tile, connector->num_v_tile,
2150 connector->tile_h_loc, connector->tile_v_loc,
2151 connector->tile_h_size, connector->tile_v_size);
2153 ret = drm_property_replace_global_blob(dev,
2154 &connector->tile_blob_ptr,
2158 dev->mode_config.tile_property);
2161 EXPORT_SYMBOL(drm_connector_set_tile_property);
2164 * drm_connector_set_link_status_property - Set link status property of a connector
2165 * @connector: drm connector
2166 * @link_status: new value of link status property (0: Good, 1: Bad)
2168 * In usual working scenario, this link status property will always be set to
2169 * "GOOD". If something fails during or after a mode set, the kernel driver
2170 * may set this link status property to "BAD". The caller then needs to send a
2171 * hotplug uevent for userspace to re-check the valid modes through
2172 * GET_CONNECTOR_IOCTL and retry modeset.
2174 * Note: Drivers cannot rely on userspace to support this property and
2175 * issue a modeset. As such, they may choose to handle issues (like
2176 * re-training a link) without userspace's intervention.
2178 * The reason for adding this property is to handle link training failures, but
2179 * it is not limited to DP or link training. For example, if we implement
2180 * asynchronous setcrtc, this property can be used to report any failures in that.
2182 void drm_connector_set_link_status_property(struct drm_connector *connector,
2183 uint64_t link_status)
2185 struct drm_device *dev = connector->dev;
2187 drm_modeset_lock(&dev->mode_config.connection_mutex, NULL);
2188 connector->state->link_status = link_status;
2189 drm_modeset_unlock(&dev->mode_config.connection_mutex);
2191 EXPORT_SYMBOL(drm_connector_set_link_status_property);
2194 * drm_connector_attach_max_bpc_property - attach "max bpc" property
2195 * @connector: connector to attach max bpc property on.
2196 * @min: The minimum bit depth supported by the connector.
2197 * @max: The maximum bit depth supported by the connector.
2199 * This is used to add support for limiting the bit depth on a connector.
2202 * Zero on success, negative errno on failure.
2204 int drm_connector_attach_max_bpc_property(struct drm_connector *connector,
2207 struct drm_device *dev = connector->dev;
2208 struct drm_property *prop;
2210 prop = connector->max_bpc_property;
2212 prop = drm_property_create_range(dev, 0, "max bpc", min, max);
2216 connector->max_bpc_property = prop;
2219 drm_object_attach_property(&connector->base, prop, max);
2220 connector->state->max_requested_bpc = max;
2221 connector->state->max_bpc = max;
2225 EXPORT_SYMBOL(drm_connector_attach_max_bpc_property);
2228 * drm_connector_attach_hdr_output_metadata_property - attach "HDR_OUTPUT_METADA" property
2229 * @connector: connector to attach the property on.
2231 * This is used to allow the userspace to send HDR Metadata to the
2235 * Zero on success, negative errno on failure.
2237 int drm_connector_attach_hdr_output_metadata_property(struct drm_connector *connector)
2239 struct drm_device *dev = connector->dev;
2240 struct drm_property *prop = dev->mode_config.hdr_output_metadata_property;
2242 drm_object_attach_property(&connector->base, prop, 0);
2246 EXPORT_SYMBOL(drm_connector_attach_hdr_output_metadata_property);
2249 * drm_connector_attach_colorspace_property - attach "Colorspace" property
2250 * @connector: connector to attach the property on.
2252 * This is used to allow the userspace to signal the output colorspace
2256 * Zero on success, negative errno on failure.
2258 int drm_connector_attach_colorspace_property(struct drm_connector *connector)
2260 struct drm_property *prop = connector->colorspace_property;
2262 drm_object_attach_property(&connector->base, prop, DRM_MODE_COLORIMETRY_DEFAULT);
2266 EXPORT_SYMBOL(drm_connector_attach_colorspace_property);
2269 * drm_connector_atomic_hdr_metadata_equal - checks if the hdr metadata changed
2270 * @old_state: old connector state to compare
2271 * @new_state: new connector state to compare
2273 * This is used by HDR-enabled drivers to test whether the HDR metadata
2274 * have changed between two different connector state (and thus probably
2275 * requires a full blown mode change).
2278 * True if the metadata are equal, False otherwise
2280 bool drm_connector_atomic_hdr_metadata_equal(struct drm_connector_state *old_state,
2281 struct drm_connector_state *new_state)
2283 struct drm_property_blob *old_blob = old_state->hdr_output_metadata;
2284 struct drm_property_blob *new_blob = new_state->hdr_output_metadata;
2286 if (!old_blob || !new_blob)
2287 return old_blob == new_blob;
2289 if (old_blob->length != new_blob->length)
2292 return !memcmp(old_blob->data, new_blob->data, old_blob->length);
2294 EXPORT_SYMBOL(drm_connector_atomic_hdr_metadata_equal);
2297 * drm_connector_set_vrr_capable_property - sets the variable refresh rate
2298 * capable property for a connector
2299 * @connector: drm connector
2300 * @capable: True if the connector is variable refresh rate capable
2302 * Should be used by atomic drivers to update the indicated support for
2303 * variable refresh rate over a connector.
2305 void drm_connector_set_vrr_capable_property(
2306 struct drm_connector *connector, bool capable)
2308 if (!connector->vrr_capable_property)
2311 drm_object_property_set_value(&connector->base,
2312 connector->vrr_capable_property,
2315 EXPORT_SYMBOL(drm_connector_set_vrr_capable_property);
2318 * drm_connector_set_panel_orientation - sets the connector's panel_orientation
2319 * @connector: connector for which to set the panel-orientation property.
2320 * @panel_orientation: drm_panel_orientation value to set
2322 * This function sets the connector's panel_orientation and attaches
2323 * a "panel orientation" property to the connector.
2325 * Calling this function on a connector where the panel_orientation has
2326 * already been set is a no-op (e.g. the orientation has been overridden with
2327 * a kernel commandline option).
2329 * It is allowed to call this function with a panel_orientation of
2330 * DRM_MODE_PANEL_ORIENTATION_UNKNOWN, in which case it is a no-op.
2332 * The function shouldn't be called in panel after drm is registered (i.e.
2333 * drm_dev_register() is called in drm).
2336 * Zero on success, negative errno on failure.
2338 int drm_connector_set_panel_orientation(
2339 struct drm_connector *connector,
2340 enum drm_panel_orientation panel_orientation)
2342 struct drm_device *dev = connector->dev;
2343 struct drm_display_info *info = &connector->display_info;
2344 struct drm_property *prop;
2347 if (info->panel_orientation != DRM_MODE_PANEL_ORIENTATION_UNKNOWN)
2350 /* Don't attach the property if the orientation is unknown */
2351 if (panel_orientation == DRM_MODE_PANEL_ORIENTATION_UNKNOWN)
2354 info->panel_orientation = panel_orientation;
2356 prop = dev->mode_config.panel_orientation_property;
2358 prop = drm_property_create_enum(dev, DRM_MODE_PROP_IMMUTABLE,
2359 "panel orientation",
2360 drm_panel_orientation_enum_list,
2361 ARRAY_SIZE(drm_panel_orientation_enum_list));
2365 dev->mode_config.panel_orientation_property = prop;
2368 drm_object_attach_property(&connector->base, prop,
2369 info->panel_orientation);
2372 EXPORT_SYMBOL(drm_connector_set_panel_orientation);
2375 * drm_connector_set_panel_orientation_with_quirk - set the
2376 * connector's panel_orientation after checking for quirks
2377 * @connector: connector for which to init the panel-orientation property.
2378 * @panel_orientation: drm_panel_orientation value to set
2379 * @width: width in pixels of the panel, used for panel quirk detection
2380 * @height: height in pixels of the panel, used for panel quirk detection
2382 * Like drm_connector_set_panel_orientation(), but with a check for platform
2383 * specific (e.g. DMI based) quirks overriding the passed in panel_orientation.
2386 * Zero on success, negative errno on failure.
2388 int drm_connector_set_panel_orientation_with_quirk(
2389 struct drm_connector *connector,
2390 enum drm_panel_orientation panel_orientation,
2391 int width, int height)
2393 int orientation_quirk;
2395 orientation_quirk = drm_get_panel_orientation_quirk(width, height);
2396 if (orientation_quirk != DRM_MODE_PANEL_ORIENTATION_UNKNOWN)
2397 panel_orientation = orientation_quirk;
2399 return drm_connector_set_panel_orientation(connector,
2402 EXPORT_SYMBOL(drm_connector_set_panel_orientation_with_quirk);
2405 * drm_connector_set_orientation_from_panel -
2406 * set the connector's panel_orientation from panel's callback.
2407 * @connector: connector for which to init the panel-orientation property.
2408 * @panel: panel that can provide orientation information.
2410 * Drm drivers should call this function before drm_dev_register().
2411 * Orientation is obtained from panel's .get_orientation() callback.
2414 * Zero on success, negative errno on failure.
2416 int drm_connector_set_orientation_from_panel(
2417 struct drm_connector *connector,
2418 struct drm_panel *panel)
2420 enum drm_panel_orientation orientation;
2422 if (panel && panel->funcs && panel->funcs->get_orientation)
2423 orientation = panel->funcs->get_orientation(panel);
2425 orientation = DRM_MODE_PANEL_ORIENTATION_UNKNOWN;
2427 return drm_connector_set_panel_orientation(connector, orientation);
2429 EXPORT_SYMBOL(drm_connector_set_orientation_from_panel);
2431 static const struct drm_prop_enum_list privacy_screen_enum[] = {
2432 { PRIVACY_SCREEN_DISABLED, "Disabled" },
2433 { PRIVACY_SCREEN_ENABLED, "Enabled" },
2434 { PRIVACY_SCREEN_DISABLED_LOCKED, "Disabled-locked" },
2435 { PRIVACY_SCREEN_ENABLED_LOCKED, "Enabled-locked" },
2439 * drm_connector_create_privacy_screen_properties - create the drm connecter's
2440 * privacy-screen properties.
2441 * @connector: connector for which to create the privacy-screen properties
2443 * This function creates the "privacy-screen sw-state" and "privacy-screen
2444 * hw-state" properties for the connector. They are not attached.
2447 drm_connector_create_privacy_screen_properties(struct drm_connector *connector)
2449 if (connector->privacy_screen_sw_state_property)
2452 /* Note sw-state only supports the first 2 values of the enum */
2453 connector->privacy_screen_sw_state_property =
2454 drm_property_create_enum(connector->dev, DRM_MODE_PROP_ENUM,
2455 "privacy-screen sw-state",
2456 privacy_screen_enum, 2);
2458 connector->privacy_screen_hw_state_property =
2459 drm_property_create_enum(connector->dev,
2460 DRM_MODE_PROP_IMMUTABLE | DRM_MODE_PROP_ENUM,
2461 "privacy-screen hw-state",
2462 privacy_screen_enum,
2463 ARRAY_SIZE(privacy_screen_enum));
2465 EXPORT_SYMBOL(drm_connector_create_privacy_screen_properties);
2468 * drm_connector_attach_privacy_screen_properties - attach the drm connecter's
2469 * privacy-screen properties.
2470 * @connector: connector on which to attach the privacy-screen properties
2472 * This function attaches the "privacy-screen sw-state" and "privacy-screen
2473 * hw-state" properties to the connector. The initial state of both is set
2477 drm_connector_attach_privacy_screen_properties(struct drm_connector *connector)
2479 if (!connector->privacy_screen_sw_state_property)
2482 drm_object_attach_property(&connector->base,
2483 connector->privacy_screen_sw_state_property,
2484 PRIVACY_SCREEN_DISABLED);
2486 drm_object_attach_property(&connector->base,
2487 connector->privacy_screen_hw_state_property,
2488 PRIVACY_SCREEN_DISABLED);
2490 EXPORT_SYMBOL(drm_connector_attach_privacy_screen_properties);
2492 static void drm_connector_update_privacy_screen_properties(
2493 struct drm_connector *connector, bool set_sw_state)
2495 enum drm_privacy_screen_status sw_state, hw_state;
2497 drm_privacy_screen_get_state(connector->privacy_screen,
2498 &sw_state, &hw_state);
2501 connector->state->privacy_screen_sw_state = sw_state;
2502 drm_object_property_set_value(&connector->base,
2503 connector->privacy_screen_hw_state_property, hw_state);
2506 static int drm_connector_privacy_screen_notifier(
2507 struct notifier_block *nb, unsigned long action, void *data)
2509 struct drm_connector *connector =
2510 container_of(nb, struct drm_connector, privacy_screen_notifier);
2511 struct drm_device *dev = connector->dev;
2513 drm_modeset_lock(&dev->mode_config.connection_mutex, NULL);
2514 drm_connector_update_privacy_screen_properties(connector, true);
2515 drm_modeset_unlock(&dev->mode_config.connection_mutex);
2517 drm_sysfs_connector_status_event(connector,
2518 connector->privacy_screen_sw_state_property);
2519 drm_sysfs_connector_status_event(connector,
2520 connector->privacy_screen_hw_state_property);
2526 * drm_connector_attach_privacy_screen_provider - attach a privacy-screen to
2528 * @connector: connector to attach the privacy-screen to
2529 * @priv: drm_privacy_screen to attach
2531 * Create and attach the standard privacy-screen properties and register
2532 * a generic notifier for generating sysfs-connector-status-events
2533 * on external changes to the privacy-screen status.
2534 * This function takes ownership of the passed in drm_privacy_screen and will
2535 * call drm_privacy_screen_put() on it when the connector is destroyed.
2537 void drm_connector_attach_privacy_screen_provider(
2538 struct drm_connector *connector, struct drm_privacy_screen *priv)
2540 connector->privacy_screen = priv;
2541 connector->privacy_screen_notifier.notifier_call =
2542 drm_connector_privacy_screen_notifier;
2544 drm_connector_create_privacy_screen_properties(connector);
2545 drm_connector_update_privacy_screen_properties(connector, true);
2546 drm_connector_attach_privacy_screen_properties(connector);
2548 EXPORT_SYMBOL(drm_connector_attach_privacy_screen_provider);
2551 * drm_connector_update_privacy_screen - update connector's privacy-screen sw-state
2552 * @connector_state: connector-state to update the privacy-screen for
2554 * This function calls drm_privacy_screen_set_sw_state() on the connector's
2557 * If the connector has no privacy-screen, then this is a no-op.
2559 void drm_connector_update_privacy_screen(const struct drm_connector_state *connector_state)
2561 struct drm_connector *connector = connector_state->connector;
2564 if (!connector->privacy_screen)
2567 ret = drm_privacy_screen_set_sw_state(connector->privacy_screen,
2568 connector_state->privacy_screen_sw_state);
2570 drm_err(connector->dev, "Error updating privacy-screen sw_state\n");
2574 /* The hw_state property value may have changed, update it. */
2575 drm_connector_update_privacy_screen_properties(connector, false);
2577 EXPORT_SYMBOL(drm_connector_update_privacy_screen);
2579 int drm_connector_set_obj_prop(struct drm_mode_object *obj,
2580 struct drm_property *property,
2584 struct drm_connector *connector = obj_to_connector(obj);
2586 /* Do DPMS ourselves */
2587 if (property == connector->dev->mode_config.dpms_property) {
2588 ret = (*connector->funcs->dpms)(connector, (int)value);
2589 } else if (connector->funcs->set_property)
2590 ret = connector->funcs->set_property(connector, property, value);
2593 drm_object_property_set_value(&connector->base, property, value);
2597 int drm_connector_property_set_ioctl(struct drm_device *dev,
2598 void *data, struct drm_file *file_priv)
2600 struct drm_mode_connector_set_property *conn_set_prop = data;
2601 struct drm_mode_obj_set_property obj_set_prop = {
2602 .value = conn_set_prop->value,
2603 .prop_id = conn_set_prop->prop_id,
2604 .obj_id = conn_set_prop->connector_id,
2605 .obj_type = DRM_MODE_OBJECT_CONNECTOR
2608 /* It does all the locking and checking we need */
2609 return drm_mode_obj_set_property_ioctl(dev, &obj_set_prop, file_priv);
2612 static struct drm_encoder *drm_connector_get_encoder(struct drm_connector *connector)
2614 /* For atomic drivers only state objects are synchronously updated and
2615 * protected by modeset locks, so check those first.
2617 if (connector->state)
2618 return connector->state->best_encoder;
2619 return connector->encoder;
2623 drm_mode_expose_to_userspace(const struct drm_display_mode *mode,
2624 const struct list_head *modes,
2625 const struct drm_file *file_priv)
2628 * If user-space hasn't configured the driver to expose the stereo 3D
2629 * modes, don't expose them.
2631 if (!file_priv->stereo_allowed && drm_mode_is_stereo(mode))
2634 * If user-space hasn't configured the driver to expose the modes
2635 * with aspect-ratio, don't expose them. However if such a mode
2636 * is unique, let it be exposed, but reset the aspect-ratio flags
2637 * while preparing the list of user-modes.
2639 if (!file_priv->aspect_ratio_allowed) {
2640 const struct drm_display_mode *mode_itr;
2642 list_for_each_entry(mode_itr, modes, head) {
2643 if (mode_itr->expose_to_userspace &&
2644 drm_mode_match(mode_itr, mode,
2645 DRM_MODE_MATCH_TIMINGS |
2646 DRM_MODE_MATCH_CLOCK |
2647 DRM_MODE_MATCH_FLAGS |
2648 DRM_MODE_MATCH_3D_FLAGS))
2656 int drm_mode_getconnector(struct drm_device *dev, void *data,
2657 struct drm_file *file_priv)
2659 struct drm_mode_get_connector *out_resp = data;
2660 struct drm_connector *connector;
2661 struct drm_encoder *encoder;
2662 struct drm_display_mode *mode;
2664 int encoders_count = 0;
2667 struct drm_mode_modeinfo u_mode;
2668 struct drm_mode_modeinfo __user *mode_ptr;
2669 uint32_t __user *encoder_ptr;
2670 bool is_current_master;
2672 if (!drm_core_check_feature(dev, DRIVER_MODESET))
2675 memset(&u_mode, 0, sizeof(struct drm_mode_modeinfo));
2677 connector = drm_connector_lookup(dev, file_priv, out_resp->connector_id);
2681 encoders_count = hweight32(connector->possible_encoders);
2683 if ((out_resp->count_encoders >= encoders_count) && encoders_count) {
2685 encoder_ptr = (uint32_t __user *)(unsigned long)(out_resp->encoders_ptr);
2687 drm_connector_for_each_possible_encoder(connector, encoder) {
2688 if (put_user(encoder->base.id, encoder_ptr + copied)) {
2695 out_resp->count_encoders = encoders_count;
2697 out_resp->connector_id = connector->base.id;
2698 out_resp->connector_type = connector->connector_type;
2699 out_resp->connector_type_id = connector->connector_type_id;
2701 is_current_master = drm_is_current_master(file_priv);
2703 mutex_lock(&dev->mode_config.mutex);
2704 if (out_resp->count_modes == 0) {
2705 if (is_current_master)
2706 connector->funcs->fill_modes(connector,
2707 dev->mode_config.max_width,
2708 dev->mode_config.max_height);
2710 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",
2711 connector->base.id, connector->name);
2714 out_resp->mm_width = connector->display_info.width_mm;
2715 out_resp->mm_height = connector->display_info.height_mm;
2716 out_resp->subpixel = connector->display_info.subpixel_order;
2717 out_resp->connection = connector->status;
2719 /* delayed so we get modes regardless of pre-fill_modes state */
2720 list_for_each_entry(mode, &connector->modes, head) {
2721 WARN_ON(mode->expose_to_userspace);
2723 if (drm_mode_expose_to_userspace(mode, &connector->modes,
2725 mode->expose_to_userspace = true;
2731 * This ioctl is called twice, once to determine how much space is
2732 * needed, and the 2nd time to fill it.
2734 if ((out_resp->count_modes >= mode_count) && mode_count) {
2736 mode_ptr = (struct drm_mode_modeinfo __user *)(unsigned long)out_resp->modes_ptr;
2737 list_for_each_entry(mode, &connector->modes, head) {
2738 if (!mode->expose_to_userspace)
2741 /* Clear the tag for the next time around */
2742 mode->expose_to_userspace = false;
2744 drm_mode_convert_to_umode(&u_mode, mode);
2746 * Reset aspect ratio flags of user-mode, if modes with
2747 * aspect-ratio are not supported.
2749 if (!file_priv->aspect_ratio_allowed)
2750 u_mode.flags &= ~DRM_MODE_FLAG_PIC_AR_MASK;
2751 if (copy_to_user(mode_ptr + copied,
2752 &u_mode, sizeof(u_mode))) {
2756 * Clear the tag for the rest of
2757 * the modes for the next time around.
2759 list_for_each_entry_continue(mode, &connector->modes, head)
2760 mode->expose_to_userspace = false;
2762 mutex_unlock(&dev->mode_config.mutex);
2769 /* Clear the tag for the next time around */
2770 list_for_each_entry(mode, &connector->modes, head)
2771 mode->expose_to_userspace = false;
2774 out_resp->count_modes = mode_count;
2775 mutex_unlock(&dev->mode_config.mutex);
2777 drm_modeset_lock(&dev->mode_config.connection_mutex, NULL);
2778 encoder = drm_connector_get_encoder(connector);
2780 out_resp->encoder_id = encoder->base.id;
2782 out_resp->encoder_id = 0;
2784 /* Only grab properties after probing, to make sure EDID and other
2785 * properties reflect the latest status.
2787 ret = drm_mode_object_get_properties(&connector->base, file_priv->atomic,
2788 (uint32_t __user *)(unsigned long)(out_resp->props_ptr),
2789 (uint64_t __user *)(unsigned long)(out_resp->prop_values_ptr),
2790 &out_resp->count_props);
2791 drm_modeset_unlock(&dev->mode_config.connection_mutex);
2794 drm_connector_put(connector);
2800 * drm_connector_find_by_fwnode - Find a connector based on the associated fwnode
2801 * @fwnode: fwnode for which to find the matching drm_connector
2803 * This functions looks up a drm_connector based on its associated fwnode. When
2804 * a connector is found a reference to the connector is returned. The caller must
2805 * call drm_connector_put() to release this reference when it is done with the
2808 * Returns: A reference to the found connector or an ERR_PTR().
2810 struct drm_connector *drm_connector_find_by_fwnode(struct fwnode_handle *fwnode)
2812 struct drm_connector *connector, *found = ERR_PTR(-ENODEV);
2815 return ERR_PTR(-ENODEV);
2817 mutex_lock(&connector_list_lock);
2819 list_for_each_entry(connector, &connector_list, global_connector_list_entry) {
2820 if (connector->fwnode == fwnode ||
2821 (connector->fwnode && connector->fwnode->secondary == fwnode)) {
2822 drm_connector_get(connector);
2828 mutex_unlock(&connector_list_lock);
2834 * drm_connector_oob_hotplug_event - Report out-of-band hotplug event to connector
2835 * @connector_fwnode: fwnode_handle to report the event on
2837 * On some hardware a hotplug event notification may come from outside the display
2838 * driver / device. An example of this is some USB Type-C setups where the hardware
2839 * muxes the DisplayPort data and aux-lines but does not pass the altmode HPD
2840 * status bit to the GPU's DP HPD pin.
2842 * This function can be used to report these out-of-band events after obtaining
2843 * a drm_connector reference through calling drm_connector_find_by_fwnode().
2845 void drm_connector_oob_hotplug_event(struct fwnode_handle *connector_fwnode)
2847 struct drm_connector *connector;
2849 connector = drm_connector_find_by_fwnode(connector_fwnode);
2850 if (IS_ERR(connector))
2853 if (connector->funcs->oob_hotplug_event)
2854 connector->funcs->oob_hotplug_event(connector);
2856 drm_connector_put(connector);
2858 EXPORT_SYMBOL(drm_connector_oob_hotplug_event);
2864 * Tile groups are used to represent tiled monitors with a unique integer
2865 * identifier. Tiled monitors using DisplayID v1.3 have a unique 8-byte handle,
2866 * we store this in a tile group, so we have a common identifier for all tiles
2867 * in a monitor group. The property is called "TILE". Drivers can manage tile
2868 * groups using drm_mode_create_tile_group(), drm_mode_put_tile_group() and
2869 * drm_mode_get_tile_group(). But this is only needed for internal panels where
2870 * the tile group information is exposed through a non-standard way.
2873 static void drm_tile_group_free(struct kref *kref)
2875 struct drm_tile_group *tg = container_of(kref, struct drm_tile_group, refcount);
2876 struct drm_device *dev = tg->dev;
2878 mutex_lock(&dev->mode_config.idr_mutex);
2879 idr_remove(&dev->mode_config.tile_idr, tg->id);
2880 mutex_unlock(&dev->mode_config.idr_mutex);
2885 * drm_mode_put_tile_group - drop a reference to a tile group.
2887 * @tg: tile group to drop reference to.
2889 * drop reference to tile group and free if 0.
2891 void drm_mode_put_tile_group(struct drm_device *dev,
2892 struct drm_tile_group *tg)
2894 kref_put(&tg->refcount, drm_tile_group_free);
2896 EXPORT_SYMBOL(drm_mode_put_tile_group);
2899 * drm_mode_get_tile_group - get a reference to an existing tile group
2901 * @topology: 8-bytes unique per monitor.
2903 * Use the unique bytes to get a reference to an existing tile group.
2906 * tile group or NULL if not found.
2908 struct drm_tile_group *drm_mode_get_tile_group(struct drm_device *dev,
2909 const char topology[8])
2911 struct drm_tile_group *tg;
2914 mutex_lock(&dev->mode_config.idr_mutex);
2915 idr_for_each_entry(&dev->mode_config.tile_idr, tg, id) {
2916 if (!memcmp(tg->group_data, topology, 8)) {
2917 if (!kref_get_unless_zero(&tg->refcount))
2919 mutex_unlock(&dev->mode_config.idr_mutex);
2923 mutex_unlock(&dev->mode_config.idr_mutex);
2926 EXPORT_SYMBOL(drm_mode_get_tile_group);
2929 * drm_mode_create_tile_group - create a tile group from a displayid description
2931 * @topology: 8-bytes unique per monitor.
2933 * Create a tile group for the unique monitor, and get a unique
2934 * identifier for the tile group.
2937 * new tile group or NULL.
2939 struct drm_tile_group *drm_mode_create_tile_group(struct drm_device *dev,
2940 const char topology[8])
2942 struct drm_tile_group *tg;
2945 tg = kzalloc(sizeof(*tg), GFP_KERNEL);
2949 kref_init(&tg->refcount);
2950 memcpy(tg->group_data, topology, 8);
2953 mutex_lock(&dev->mode_config.idr_mutex);
2954 ret = idr_alloc(&dev->mode_config.tile_idr, tg, 1, 0, GFP_KERNEL);
2962 mutex_unlock(&dev->mode_config.idr_mutex);
2965 EXPORT_SYMBOL(drm_mode_create_tile_group);