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_edid.h>
26 #include <drm/drm_encoder.h>
27 #include <drm/drm_panel.h>
28 #include <drm/drm_utils.h>
29 #include <drm/drm_print.h>
30 #include <drm/drm_drv.h>
31 #include <drm/drm_file.h>
32 #include <drm/drm_privacy_screen_consumer.h>
33 #include <drm/drm_sysfs.h>
36 #include <linux/uaccess.h>
38 #include "drm_crtc_internal.h"
39 #include "drm_internal.h"
44 * In DRM connectors are the general abstraction for display sinks, and include
45 * also fixed panels or anything else that can display pixels in some form. As
46 * opposed to all other KMS objects representing hardware (like CRTC, encoder or
47 * plane abstractions) connectors can be hotplugged and unplugged at runtime.
48 * Hence they are reference-counted using drm_connector_get() and
49 * drm_connector_put().
51 * KMS driver must create, initialize, register and attach at a &struct
52 * drm_connector for each such sink. The instance is created as other KMS
53 * objects and initialized by setting the following fields. The connector is
54 * initialized with a call to drm_connector_init() with a pointer to the
55 * &struct drm_connector_funcs and a connector type, and then exposed to
56 * userspace with a call to drm_connector_register().
58 * Connectors must be attached to an encoder to be used. For devices that map
59 * connectors to encoders 1:1, the connector should be attached at
60 * initialization time with a call to drm_connector_attach_encoder(). The
61 * driver must also set the &drm_connector.encoder field to point to the
64 * For connectors which are not fixed (like built-in panels) the driver needs to
65 * support hotplug notifications. The simplest way to do that is by using the
66 * probe helpers, see drm_kms_helper_poll_init() for connectors which don't have
67 * hardware support for hotplug interrupts. Connectors with hardware hotplug
68 * support can instead use e.g. drm_helper_hpd_irq_event().
72 * Global connector list for drm_connector_find_by_fwnode().
73 * Note drm_connector_[un]register() first take connector->lock and then
74 * take the connector_list_lock.
76 static DEFINE_MUTEX(connector_list_lock);
77 static LIST_HEAD(connector_list);
79 struct drm_conn_prop_enum_list {
86 * Connector and encoder types.
88 static struct drm_conn_prop_enum_list drm_connector_enum_list[] = {
89 { DRM_MODE_CONNECTOR_Unknown, "Unknown" },
90 { DRM_MODE_CONNECTOR_VGA, "VGA" },
91 { DRM_MODE_CONNECTOR_DVII, "DVI-I" },
92 { DRM_MODE_CONNECTOR_DVID, "DVI-D" },
93 { DRM_MODE_CONNECTOR_DVIA, "DVI-A" },
94 { DRM_MODE_CONNECTOR_Composite, "Composite" },
95 { DRM_MODE_CONNECTOR_SVIDEO, "SVIDEO" },
96 { DRM_MODE_CONNECTOR_LVDS, "LVDS" },
97 { DRM_MODE_CONNECTOR_Component, "Component" },
98 { DRM_MODE_CONNECTOR_9PinDIN, "DIN" },
99 { DRM_MODE_CONNECTOR_DisplayPort, "DP" },
100 { DRM_MODE_CONNECTOR_HDMIA, "HDMI-A" },
101 { DRM_MODE_CONNECTOR_HDMIB, "HDMI-B" },
102 { DRM_MODE_CONNECTOR_TV, "TV" },
103 { DRM_MODE_CONNECTOR_eDP, "eDP" },
104 { DRM_MODE_CONNECTOR_VIRTUAL, "Virtual" },
105 { DRM_MODE_CONNECTOR_DSI, "DSI" },
106 { DRM_MODE_CONNECTOR_DPI, "DPI" },
107 { DRM_MODE_CONNECTOR_WRITEBACK, "Writeback" },
108 { DRM_MODE_CONNECTOR_SPI, "SPI" },
109 { DRM_MODE_CONNECTOR_USB, "USB" },
112 void drm_connector_ida_init(void)
116 for (i = 0; i < ARRAY_SIZE(drm_connector_enum_list); i++)
117 ida_init(&drm_connector_enum_list[i].ida);
120 void drm_connector_ida_destroy(void)
124 for (i = 0; i < ARRAY_SIZE(drm_connector_enum_list); i++)
125 ida_destroy(&drm_connector_enum_list[i].ida);
129 * drm_get_connector_type_name - return a string for connector type
130 * @type: The connector type (DRM_MODE_CONNECTOR_*)
132 * Returns: the name of the connector type, or NULL if the type is not valid.
134 const char *drm_get_connector_type_name(unsigned int type)
136 if (type < ARRAY_SIZE(drm_connector_enum_list))
137 return drm_connector_enum_list[type].name;
141 EXPORT_SYMBOL(drm_get_connector_type_name);
144 * drm_connector_get_cmdline_mode - reads the user's cmdline mode
145 * @connector: connector to query
147 * The kernel supports per-connector configuration of its consoles through
148 * use of the video= parameter. This function parses that option and
149 * extracts the user's specified mode (or enable/disable status) for a
150 * particular connector. This is typically only used during the early fbdev
153 static void drm_connector_get_cmdline_mode(struct drm_connector *connector)
155 struct drm_cmdline_mode *mode = &connector->cmdline_mode;
158 if (fb_get_options(connector->name, &option))
161 if (!drm_mode_parse_command_line_for_connector(option,
167 DRM_INFO("forcing %s connector %s\n", connector->name,
168 drm_get_connector_force_name(mode->force));
169 connector->force = mode->force;
172 if (mode->panel_orientation != DRM_MODE_PANEL_ORIENTATION_UNKNOWN) {
173 DRM_INFO("cmdline forces connector %s panel_orientation to %d\n",
174 connector->name, mode->panel_orientation);
175 drm_connector_set_panel_orientation(connector,
176 mode->panel_orientation);
179 DRM_DEBUG_KMS("cmdline mode for connector %s %s %dx%d@%dHz%s%s%s\n",
180 connector->name, mode->name,
181 mode->xres, mode->yres,
182 mode->refresh_specified ? mode->refresh : 60,
183 mode->rb ? " reduced blanking" : "",
184 mode->margins ? " with margins" : "",
185 mode->interlace ? " interlaced" : "");
188 static void drm_connector_free(struct kref *kref)
190 struct drm_connector *connector =
191 container_of(kref, struct drm_connector, base.refcount);
192 struct drm_device *dev = connector->dev;
194 drm_mode_object_unregister(dev, &connector->base);
195 connector->funcs->destroy(connector);
198 void drm_connector_free_work_fn(struct work_struct *work)
200 struct drm_connector *connector, *n;
201 struct drm_device *dev =
202 container_of(work, struct drm_device, mode_config.connector_free_work);
203 struct drm_mode_config *config = &dev->mode_config;
205 struct llist_node *freed;
207 spin_lock_irqsave(&config->connector_list_lock, flags);
208 freed = llist_del_all(&config->connector_free_list);
209 spin_unlock_irqrestore(&config->connector_list_lock, flags);
211 llist_for_each_entry_safe(connector, n, freed, free_node) {
212 drm_mode_object_unregister(dev, &connector->base);
213 connector->funcs->destroy(connector);
218 * drm_connector_init - Init a preallocated connector
220 * @connector: the connector to init
221 * @funcs: callbacks for this connector
222 * @connector_type: user visible type of the connector
224 * Initialises a preallocated connector. Connectors should be
225 * subclassed as part of driver connector objects.
228 * Zero on success, error code on failure.
230 int drm_connector_init(struct drm_device *dev,
231 struct drm_connector *connector,
232 const struct drm_connector_funcs *funcs,
235 struct drm_mode_config *config = &dev->mode_config;
237 struct ida *connector_ida =
238 &drm_connector_enum_list[connector_type].ida;
240 WARN_ON(drm_drv_uses_atomic_modeset(dev) &&
241 (!funcs->atomic_destroy_state ||
242 !funcs->atomic_duplicate_state));
244 ret = __drm_mode_object_add(dev, &connector->base,
245 DRM_MODE_OBJECT_CONNECTOR,
246 false, drm_connector_free);
250 connector->base.properties = &connector->properties;
251 connector->dev = dev;
252 connector->funcs = funcs;
254 /* connector index is used with 32bit bitmasks */
255 ret = ida_alloc_max(&config->connector_ida, 31, GFP_KERNEL);
257 DRM_DEBUG_KMS("Failed to allocate %s connector index: %d\n",
258 drm_connector_enum_list[connector_type].name,
262 connector->index = ret;
265 connector->connector_type = connector_type;
266 connector->connector_type_id =
267 ida_alloc_min(connector_ida, 1, GFP_KERNEL);
268 if (connector->connector_type_id < 0) {
269 ret = connector->connector_type_id;
273 kasprintf(GFP_KERNEL, "%s-%d",
274 drm_connector_enum_list[connector_type].name,
275 connector->connector_type_id);
276 if (!connector->name) {
278 goto out_put_type_id;
281 INIT_LIST_HEAD(&connector->global_connector_list_entry);
282 INIT_LIST_HEAD(&connector->probed_modes);
283 INIT_LIST_HEAD(&connector->modes);
284 mutex_init(&connector->mutex);
285 connector->edid_blob_ptr = NULL;
286 connector->epoch_counter = 0;
287 connector->tile_blob_ptr = NULL;
288 connector->status = connector_status_unknown;
289 connector->display_info.panel_orientation =
290 DRM_MODE_PANEL_ORIENTATION_UNKNOWN;
292 drm_connector_get_cmdline_mode(connector);
294 /* We should add connectors at the end to avoid upsetting the connector
297 spin_lock_irq(&config->connector_list_lock);
298 list_add_tail(&connector->head, &config->connector_list);
299 config->num_connector++;
300 spin_unlock_irq(&config->connector_list_lock);
302 if (connector_type != DRM_MODE_CONNECTOR_VIRTUAL &&
303 connector_type != DRM_MODE_CONNECTOR_WRITEBACK)
304 drm_connector_attach_edid_property(connector);
306 drm_object_attach_property(&connector->base,
307 config->dpms_property, 0);
309 drm_object_attach_property(&connector->base,
310 config->link_status_property,
313 drm_object_attach_property(&connector->base,
314 config->non_desktop_property,
316 drm_object_attach_property(&connector->base,
317 config->tile_property,
320 if (drm_core_check_feature(dev, DRIVER_ATOMIC)) {
321 drm_object_attach_property(&connector->base, config->prop_crtc_id, 0);
324 connector->debugfs_entry = NULL;
327 ida_free(connector_ida, connector->connector_type_id);
330 ida_free(&config->connector_ida, connector->index);
333 drm_mode_object_unregister(dev, &connector->base);
337 EXPORT_SYMBOL(drm_connector_init);
340 * drm_connector_init_with_ddc - Init a preallocated connector
342 * @connector: the connector to init
343 * @funcs: callbacks for this connector
344 * @connector_type: user visible type of the connector
345 * @ddc: pointer to the associated ddc adapter
347 * Initialises a preallocated connector. Connectors should be
348 * subclassed as part of driver connector objects.
350 * Ensures that the ddc field of the connector is correctly set.
353 * Zero on success, error code on failure.
355 int drm_connector_init_with_ddc(struct drm_device *dev,
356 struct drm_connector *connector,
357 const struct drm_connector_funcs *funcs,
359 struct i2c_adapter *ddc)
363 ret = drm_connector_init(dev, connector, funcs, connector_type);
367 /* provide ddc symlink in sysfs */
368 connector->ddc = ddc;
372 EXPORT_SYMBOL(drm_connector_init_with_ddc);
375 * drm_connector_attach_edid_property - attach edid property.
376 * @connector: the connector
378 * Some connector types like DRM_MODE_CONNECTOR_VIRTUAL do not get a
379 * edid property attached by default. This function can be used to
380 * explicitly enable the edid property in these cases.
382 void drm_connector_attach_edid_property(struct drm_connector *connector)
384 struct drm_mode_config *config = &connector->dev->mode_config;
386 drm_object_attach_property(&connector->base,
387 config->edid_property,
390 EXPORT_SYMBOL(drm_connector_attach_edid_property);
393 * drm_connector_attach_encoder - attach a connector to an encoder
394 * @connector: connector to attach
395 * @encoder: encoder to attach @connector to
397 * This function links up a connector to an encoder. Note that the routing
398 * restrictions between encoders and crtcs are exposed to userspace through the
399 * possible_clones and possible_crtcs bitmasks.
402 * Zero on success, negative errno on failure.
404 int drm_connector_attach_encoder(struct drm_connector *connector,
405 struct drm_encoder *encoder)
408 * In the past, drivers have attempted to model the static association
409 * of connector to encoder in simple connector/encoder devices using a
410 * direct assignment of connector->encoder = encoder. This connection
411 * is a logical one and the responsibility of the core, so drivers are
412 * expected not to mess with this.
414 * Note that the error return should've been enough here, but a large
415 * majority of drivers ignores the return value, so add in a big WARN
416 * to get people's attention.
418 if (WARN_ON(connector->encoder))
421 connector->possible_encoders |= drm_encoder_mask(encoder);
425 EXPORT_SYMBOL(drm_connector_attach_encoder);
428 * drm_connector_has_possible_encoder - check if the connector and encoder are
429 * associated with each other
430 * @connector: the connector
431 * @encoder: the encoder
434 * True if @encoder is one of the possible encoders for @connector.
436 bool drm_connector_has_possible_encoder(struct drm_connector *connector,
437 struct drm_encoder *encoder)
439 return connector->possible_encoders & drm_encoder_mask(encoder);
441 EXPORT_SYMBOL(drm_connector_has_possible_encoder);
443 static void drm_mode_remove(struct drm_connector *connector,
444 struct drm_display_mode *mode)
446 list_del(&mode->head);
447 drm_mode_destroy(connector->dev, mode);
451 * drm_connector_cleanup - cleans up an initialised connector
452 * @connector: connector to cleanup
454 * Cleans up the connector but doesn't free the object.
456 void drm_connector_cleanup(struct drm_connector *connector)
458 struct drm_device *dev = connector->dev;
459 struct drm_display_mode *mode, *t;
461 /* The connector should have been removed from userspace long before
462 * it is finally destroyed.
464 if (WARN_ON(connector->registration_state ==
465 DRM_CONNECTOR_REGISTERED))
466 drm_connector_unregister(connector);
468 if (connector->privacy_screen) {
469 drm_privacy_screen_put(connector->privacy_screen);
470 connector->privacy_screen = NULL;
473 if (connector->tile_group) {
474 drm_mode_put_tile_group(dev, connector->tile_group);
475 connector->tile_group = NULL;
478 list_for_each_entry_safe(mode, t, &connector->probed_modes, head)
479 drm_mode_remove(connector, mode);
481 list_for_each_entry_safe(mode, t, &connector->modes, head)
482 drm_mode_remove(connector, mode);
484 ida_free(&drm_connector_enum_list[connector->connector_type].ida,
485 connector->connector_type_id);
487 ida_free(&dev->mode_config.connector_ida, connector->index);
489 kfree(connector->display_info.bus_formats);
490 drm_mode_object_unregister(dev, &connector->base);
491 kfree(connector->name);
492 connector->name = NULL;
493 fwnode_handle_put(connector->fwnode);
494 connector->fwnode = NULL;
495 spin_lock_irq(&dev->mode_config.connector_list_lock);
496 list_del(&connector->head);
497 dev->mode_config.num_connector--;
498 spin_unlock_irq(&dev->mode_config.connector_list_lock);
500 WARN_ON(connector->state && !connector->funcs->atomic_destroy_state);
501 if (connector->state && connector->funcs->atomic_destroy_state)
502 connector->funcs->atomic_destroy_state(connector,
505 mutex_destroy(&connector->mutex);
507 memset(connector, 0, sizeof(*connector));
509 EXPORT_SYMBOL(drm_connector_cleanup);
512 * drm_connector_register - register a connector
513 * @connector: the connector to register
515 * Register userspace interfaces for a connector. Only call this for connectors
516 * which can be hotplugged after drm_dev_register() has been called already,
517 * e.g. DP MST connectors. All other connectors will be registered automatically
518 * when calling drm_dev_register().
521 * Zero on success, error code on failure.
523 int drm_connector_register(struct drm_connector *connector)
527 if (!connector->dev->registered)
530 mutex_lock(&connector->mutex);
531 if (connector->registration_state != DRM_CONNECTOR_INITIALIZING)
534 ret = drm_sysfs_connector_add(connector);
538 drm_debugfs_connector_add(connector);
540 if (connector->funcs->late_register) {
541 ret = connector->funcs->late_register(connector);
546 drm_mode_object_register(connector->dev, &connector->base);
548 connector->registration_state = DRM_CONNECTOR_REGISTERED;
550 /* Let userspace know we have a new connector */
551 drm_sysfs_connector_hotplug_event(connector);
553 if (connector->privacy_screen)
554 drm_privacy_screen_register_notifier(connector->privacy_screen,
555 &connector->privacy_screen_notifier);
557 mutex_lock(&connector_list_lock);
558 list_add_tail(&connector->global_connector_list_entry, &connector_list);
559 mutex_unlock(&connector_list_lock);
563 drm_debugfs_connector_remove(connector);
564 drm_sysfs_connector_remove(connector);
566 mutex_unlock(&connector->mutex);
569 EXPORT_SYMBOL(drm_connector_register);
572 * drm_connector_unregister - unregister a connector
573 * @connector: the connector to unregister
575 * Unregister userspace interfaces for a connector. Only call this for
576 * connectors which have registered explicitly by calling drm_dev_register(),
577 * since connectors are unregistered automatically when drm_dev_unregister() is
580 void drm_connector_unregister(struct drm_connector *connector)
582 mutex_lock(&connector->mutex);
583 if (connector->registration_state != DRM_CONNECTOR_REGISTERED) {
584 mutex_unlock(&connector->mutex);
588 mutex_lock(&connector_list_lock);
589 list_del_init(&connector->global_connector_list_entry);
590 mutex_unlock(&connector_list_lock);
592 if (connector->privacy_screen)
593 drm_privacy_screen_unregister_notifier(
594 connector->privacy_screen,
595 &connector->privacy_screen_notifier);
597 if (connector->funcs->early_unregister)
598 connector->funcs->early_unregister(connector);
600 drm_sysfs_connector_remove(connector);
601 drm_debugfs_connector_remove(connector);
603 connector->registration_state = DRM_CONNECTOR_UNREGISTERED;
604 mutex_unlock(&connector->mutex);
606 EXPORT_SYMBOL(drm_connector_unregister);
608 void drm_connector_unregister_all(struct drm_device *dev)
610 struct drm_connector *connector;
611 struct drm_connector_list_iter conn_iter;
613 drm_connector_list_iter_begin(dev, &conn_iter);
614 drm_for_each_connector_iter(connector, &conn_iter)
615 drm_connector_unregister(connector);
616 drm_connector_list_iter_end(&conn_iter);
619 int drm_connector_register_all(struct drm_device *dev)
621 struct drm_connector *connector;
622 struct drm_connector_list_iter conn_iter;
625 drm_connector_list_iter_begin(dev, &conn_iter);
626 drm_for_each_connector_iter(connector, &conn_iter) {
627 ret = drm_connector_register(connector);
631 drm_connector_list_iter_end(&conn_iter);
634 drm_connector_unregister_all(dev);
639 * drm_get_connector_status_name - return a string for connector status
640 * @status: connector status to compute name of
642 * In contrast to the other drm_get_*_name functions this one here returns a
643 * const pointer and hence is threadsafe.
645 * Returns: connector status string
647 const char *drm_get_connector_status_name(enum drm_connector_status status)
649 if (status == connector_status_connected)
651 else if (status == connector_status_disconnected)
652 return "disconnected";
656 EXPORT_SYMBOL(drm_get_connector_status_name);
659 * drm_get_connector_force_name - return a string for connector force
660 * @force: connector force to get name of
662 * Returns: const pointer to name.
664 const char *drm_get_connector_force_name(enum drm_connector_force force)
667 case DRM_FORCE_UNSPECIFIED:
668 return "unspecified";
673 case DRM_FORCE_ON_DIGITAL:
680 #ifdef CONFIG_LOCKDEP
681 static struct lockdep_map connector_list_iter_dep_map = {
682 .name = "drm_connector_list_iter"
687 * drm_connector_list_iter_begin - initialize a connector_list iterator
689 * @iter: connector_list iterator
691 * Sets @iter up to walk the &drm_mode_config.connector_list of @dev. @iter
692 * must always be cleaned up again by calling drm_connector_list_iter_end().
693 * Iteration itself happens using drm_connector_list_iter_next() or
694 * drm_for_each_connector_iter().
696 void drm_connector_list_iter_begin(struct drm_device *dev,
697 struct drm_connector_list_iter *iter)
701 lock_acquire_shared_recursive(&connector_list_iter_dep_map, 0, 1, NULL, _RET_IP_);
703 EXPORT_SYMBOL(drm_connector_list_iter_begin);
706 * Extra-safe connector put function that works in any context. Should only be
707 * used from the connector_iter functions, where we never really expect to
708 * actually release the connector when dropping our final reference.
711 __drm_connector_put_safe(struct drm_connector *conn)
713 struct drm_mode_config *config = &conn->dev->mode_config;
715 lockdep_assert_held(&config->connector_list_lock);
717 if (!refcount_dec_and_test(&conn->base.refcount.refcount))
720 llist_add(&conn->free_node, &config->connector_free_list);
721 schedule_work(&config->connector_free_work);
725 * drm_connector_list_iter_next - return next connector
726 * @iter: connector_list iterator
728 * Returns: the next connector for @iter, or NULL when the list walk has
731 struct drm_connector *
732 drm_connector_list_iter_next(struct drm_connector_list_iter *iter)
734 struct drm_connector *old_conn = iter->conn;
735 struct drm_mode_config *config = &iter->dev->mode_config;
736 struct list_head *lhead;
739 spin_lock_irqsave(&config->connector_list_lock, flags);
740 lhead = old_conn ? &old_conn->head : &config->connector_list;
743 if (lhead->next == &config->connector_list) {
749 iter->conn = list_entry(lhead, struct drm_connector, head);
751 /* loop until it's not a zombie connector */
752 } while (!kref_get_unless_zero(&iter->conn->base.refcount));
755 __drm_connector_put_safe(old_conn);
756 spin_unlock_irqrestore(&config->connector_list_lock, flags);
760 EXPORT_SYMBOL(drm_connector_list_iter_next);
763 * drm_connector_list_iter_end - tear down a connector_list iterator
764 * @iter: connector_list iterator
766 * Tears down @iter and releases any resources (like &drm_connector references)
767 * acquired while walking the list. This must always be called, both when the
768 * iteration completes fully or when it was aborted without walking the entire
771 void drm_connector_list_iter_end(struct drm_connector_list_iter *iter)
773 struct drm_mode_config *config = &iter->dev->mode_config;
778 spin_lock_irqsave(&config->connector_list_lock, flags);
779 __drm_connector_put_safe(iter->conn);
780 spin_unlock_irqrestore(&config->connector_list_lock, flags);
782 lock_release(&connector_list_iter_dep_map, _RET_IP_);
784 EXPORT_SYMBOL(drm_connector_list_iter_end);
786 static const struct drm_prop_enum_list drm_subpixel_enum_list[] = {
787 { SubPixelUnknown, "Unknown" },
788 { SubPixelHorizontalRGB, "Horizontal RGB" },
789 { SubPixelHorizontalBGR, "Horizontal BGR" },
790 { SubPixelVerticalRGB, "Vertical RGB" },
791 { SubPixelVerticalBGR, "Vertical BGR" },
792 { SubPixelNone, "None" },
796 * drm_get_subpixel_order_name - return a string for a given subpixel enum
797 * @order: enum of subpixel_order
799 * Note you could abuse this and return something out of bounds, but that
800 * would be a caller error. No unscrubbed user data should make it here.
802 * Returns: string describing an enumerated subpixel property
804 const char *drm_get_subpixel_order_name(enum subpixel_order order)
806 return drm_subpixel_enum_list[order].name;
808 EXPORT_SYMBOL(drm_get_subpixel_order_name);
810 static const struct drm_prop_enum_list drm_dpms_enum_list[] = {
811 { DRM_MODE_DPMS_ON, "On" },
812 { DRM_MODE_DPMS_STANDBY, "Standby" },
813 { DRM_MODE_DPMS_SUSPEND, "Suspend" },
814 { DRM_MODE_DPMS_OFF, "Off" }
816 DRM_ENUM_NAME_FN(drm_get_dpms_name, drm_dpms_enum_list)
818 static const struct drm_prop_enum_list drm_link_status_enum_list[] = {
819 { DRM_MODE_LINK_STATUS_GOOD, "Good" },
820 { DRM_MODE_LINK_STATUS_BAD, "Bad" },
824 * drm_display_info_set_bus_formats - set the supported bus formats
825 * @info: display info to store bus formats in
826 * @formats: array containing the supported bus formats
827 * @num_formats: the number of entries in the fmts array
829 * Store the supported bus formats in display info structure.
830 * See MEDIA_BUS_FMT_* definitions in include/uapi/linux/media-bus-format.h for
831 * a full list of available formats.
834 * 0 on success or a negative error code on failure.
836 int drm_display_info_set_bus_formats(struct drm_display_info *info,
838 unsigned int num_formats)
842 if (!formats && num_formats)
845 if (formats && num_formats) {
846 fmts = kmemdup(formats, sizeof(*formats) * num_formats,
852 kfree(info->bus_formats);
853 info->bus_formats = fmts;
854 info->num_bus_formats = num_formats;
858 EXPORT_SYMBOL(drm_display_info_set_bus_formats);
860 /* Optional connector properties. */
861 static const struct drm_prop_enum_list drm_scaling_mode_enum_list[] = {
862 { DRM_MODE_SCALE_NONE, "None" },
863 { DRM_MODE_SCALE_FULLSCREEN, "Full" },
864 { DRM_MODE_SCALE_CENTER, "Center" },
865 { DRM_MODE_SCALE_ASPECT, "Full aspect" },
868 static const struct drm_prop_enum_list drm_aspect_ratio_enum_list[] = {
869 { DRM_MODE_PICTURE_ASPECT_NONE, "Automatic" },
870 { DRM_MODE_PICTURE_ASPECT_4_3, "4:3" },
871 { DRM_MODE_PICTURE_ASPECT_16_9, "16:9" },
874 static const struct drm_prop_enum_list drm_content_type_enum_list[] = {
875 { DRM_MODE_CONTENT_TYPE_NO_DATA, "No Data" },
876 { DRM_MODE_CONTENT_TYPE_GRAPHICS, "Graphics" },
877 { DRM_MODE_CONTENT_TYPE_PHOTO, "Photo" },
878 { DRM_MODE_CONTENT_TYPE_CINEMA, "Cinema" },
879 { DRM_MODE_CONTENT_TYPE_GAME, "Game" },
882 static const struct drm_prop_enum_list drm_panel_orientation_enum_list[] = {
883 { DRM_MODE_PANEL_ORIENTATION_NORMAL, "Normal" },
884 { DRM_MODE_PANEL_ORIENTATION_BOTTOM_UP, "Upside Down" },
885 { DRM_MODE_PANEL_ORIENTATION_LEFT_UP, "Left Side Up" },
886 { DRM_MODE_PANEL_ORIENTATION_RIGHT_UP, "Right Side Up" },
889 static const struct drm_prop_enum_list drm_dvi_i_select_enum_list[] = {
890 { DRM_MODE_SUBCONNECTOR_Automatic, "Automatic" }, /* DVI-I and TV-out */
891 { DRM_MODE_SUBCONNECTOR_DVID, "DVI-D" }, /* DVI-I */
892 { DRM_MODE_SUBCONNECTOR_DVIA, "DVI-A" }, /* DVI-I */
894 DRM_ENUM_NAME_FN(drm_get_dvi_i_select_name, drm_dvi_i_select_enum_list)
896 static const struct drm_prop_enum_list drm_dvi_i_subconnector_enum_list[] = {
897 { DRM_MODE_SUBCONNECTOR_Unknown, "Unknown" }, /* DVI-I, TV-out and DP */
898 { DRM_MODE_SUBCONNECTOR_DVID, "DVI-D" }, /* DVI-I */
899 { DRM_MODE_SUBCONNECTOR_DVIA, "DVI-A" }, /* DVI-I */
901 DRM_ENUM_NAME_FN(drm_get_dvi_i_subconnector_name,
902 drm_dvi_i_subconnector_enum_list)
904 static const struct drm_prop_enum_list drm_tv_select_enum_list[] = {
905 { DRM_MODE_SUBCONNECTOR_Automatic, "Automatic" }, /* DVI-I and TV-out */
906 { DRM_MODE_SUBCONNECTOR_Composite, "Composite" }, /* TV-out */
907 { DRM_MODE_SUBCONNECTOR_SVIDEO, "SVIDEO" }, /* TV-out */
908 { DRM_MODE_SUBCONNECTOR_Component, "Component" }, /* TV-out */
909 { DRM_MODE_SUBCONNECTOR_SCART, "SCART" }, /* TV-out */
911 DRM_ENUM_NAME_FN(drm_get_tv_select_name, drm_tv_select_enum_list)
913 static const struct drm_prop_enum_list drm_tv_subconnector_enum_list[] = {
914 { DRM_MODE_SUBCONNECTOR_Unknown, "Unknown" }, /* DVI-I, TV-out and DP */
915 { DRM_MODE_SUBCONNECTOR_Composite, "Composite" }, /* TV-out */
916 { DRM_MODE_SUBCONNECTOR_SVIDEO, "SVIDEO" }, /* TV-out */
917 { DRM_MODE_SUBCONNECTOR_Component, "Component" }, /* TV-out */
918 { DRM_MODE_SUBCONNECTOR_SCART, "SCART" }, /* TV-out */
920 DRM_ENUM_NAME_FN(drm_get_tv_subconnector_name,
921 drm_tv_subconnector_enum_list)
923 static const struct drm_prop_enum_list drm_dp_subconnector_enum_list[] = {
924 { DRM_MODE_SUBCONNECTOR_Unknown, "Unknown" }, /* DVI-I, TV-out and DP */
925 { DRM_MODE_SUBCONNECTOR_VGA, "VGA" }, /* DP */
926 { DRM_MODE_SUBCONNECTOR_DVID, "DVI-D" }, /* DP */
927 { DRM_MODE_SUBCONNECTOR_HDMIA, "HDMI" }, /* DP */
928 { DRM_MODE_SUBCONNECTOR_DisplayPort, "DP" }, /* DP */
929 { DRM_MODE_SUBCONNECTOR_Wireless, "Wireless" }, /* DP */
930 { DRM_MODE_SUBCONNECTOR_Native, "Native" }, /* DP */
933 DRM_ENUM_NAME_FN(drm_get_dp_subconnector_name,
934 drm_dp_subconnector_enum_list)
936 static const struct drm_prop_enum_list hdmi_colorspaces[] = {
937 /* For Default case, driver will set the colorspace */
938 { DRM_MODE_COLORIMETRY_DEFAULT, "Default" },
939 /* Standard Definition Colorimetry based on CEA 861 */
940 { DRM_MODE_COLORIMETRY_SMPTE_170M_YCC, "SMPTE_170M_YCC" },
941 { DRM_MODE_COLORIMETRY_BT709_YCC, "BT709_YCC" },
942 /* Standard Definition Colorimetry based on IEC 61966-2-4 */
943 { DRM_MODE_COLORIMETRY_XVYCC_601, "XVYCC_601" },
944 /* High Definition Colorimetry based on IEC 61966-2-4 */
945 { DRM_MODE_COLORIMETRY_XVYCC_709, "XVYCC_709" },
946 /* Colorimetry based on IEC 61966-2-1/Amendment 1 */
947 { DRM_MODE_COLORIMETRY_SYCC_601, "SYCC_601" },
948 /* Colorimetry based on IEC 61966-2-5 [33] */
949 { DRM_MODE_COLORIMETRY_OPYCC_601, "opYCC_601" },
950 /* Colorimetry based on IEC 61966-2-5 */
951 { DRM_MODE_COLORIMETRY_OPRGB, "opRGB" },
952 /* Colorimetry based on ITU-R BT.2020 */
953 { DRM_MODE_COLORIMETRY_BT2020_CYCC, "BT2020_CYCC" },
954 /* Colorimetry based on ITU-R BT.2020 */
955 { DRM_MODE_COLORIMETRY_BT2020_RGB, "BT2020_RGB" },
956 /* Colorimetry based on ITU-R BT.2020 */
957 { DRM_MODE_COLORIMETRY_BT2020_YCC, "BT2020_YCC" },
958 /* Added as part of Additional Colorimetry Extension in 861.G */
959 { DRM_MODE_COLORIMETRY_DCI_P3_RGB_D65, "DCI-P3_RGB_D65" },
960 { DRM_MODE_COLORIMETRY_DCI_P3_RGB_THEATER, "DCI-P3_RGB_Theater" },
964 * As per DP 1.4a spec, 2.2.5.7.5 VSC SDP Payload for Pixel Encoding/Colorimetry
967 static const struct drm_prop_enum_list dp_colorspaces[] = {
968 /* For Default case, driver will set the colorspace */
969 { DRM_MODE_COLORIMETRY_DEFAULT, "Default" },
970 { DRM_MODE_COLORIMETRY_RGB_WIDE_FIXED, "RGB_Wide_Gamut_Fixed_Point" },
971 /* Colorimetry based on scRGB (IEC 61966-2-2) */
972 { DRM_MODE_COLORIMETRY_RGB_WIDE_FLOAT, "RGB_Wide_Gamut_Floating_Point" },
973 /* Colorimetry based on IEC 61966-2-5 */
974 { DRM_MODE_COLORIMETRY_OPRGB, "opRGB" },
975 /* Colorimetry based on SMPTE RP 431-2 */
976 { DRM_MODE_COLORIMETRY_DCI_P3_RGB_D65, "DCI-P3_RGB_D65" },
977 /* Colorimetry based on ITU-R BT.2020 */
978 { DRM_MODE_COLORIMETRY_BT2020_RGB, "BT2020_RGB" },
979 { DRM_MODE_COLORIMETRY_BT601_YCC, "BT601_YCC" },
980 { DRM_MODE_COLORIMETRY_BT709_YCC, "BT709_YCC" },
981 /* Standard Definition Colorimetry based on IEC 61966-2-4 */
982 { DRM_MODE_COLORIMETRY_XVYCC_601, "XVYCC_601" },
983 /* High Definition Colorimetry based on IEC 61966-2-4 */
984 { DRM_MODE_COLORIMETRY_XVYCC_709, "XVYCC_709" },
985 /* Colorimetry based on IEC 61966-2-1/Amendment 1 */
986 { DRM_MODE_COLORIMETRY_SYCC_601, "SYCC_601" },
987 /* Colorimetry based on IEC 61966-2-5 [33] */
988 { DRM_MODE_COLORIMETRY_OPYCC_601, "opYCC_601" },
989 /* Colorimetry based on ITU-R BT.2020 */
990 { DRM_MODE_COLORIMETRY_BT2020_CYCC, "BT2020_CYCC" },
991 /* Colorimetry based on ITU-R BT.2020 */
992 { DRM_MODE_COLORIMETRY_BT2020_YCC, "BT2020_YCC" },
996 * DOC: standard connector properties
998 * DRM connectors have a few standardized properties:
1001 * Blob property which contains the current EDID read from the sink. This
1002 * is useful to parse sink identification information like vendor, model
1003 * and serial. Drivers should update this property by calling
1004 * drm_connector_update_edid_property(), usually after having parsed
1005 * the EDID using drm_add_edid_modes(). Userspace cannot change this
1008 * User-space should not parse the EDID to obtain information exposed via
1009 * other KMS properties (because the kernel might apply limits, quirks or
1010 * fixups to the EDID). For instance, user-space should not try to parse
1011 * mode lists from the EDID.
1013 * Legacy property for setting the power state of the connector. For atomic
1014 * drivers this is only provided for backwards compatibility with existing
1015 * drivers, it remaps to controlling the "ACTIVE" property on the CRTC the
1016 * connector is linked to. Drivers should never set this property directly,
1017 * it is handled by the DRM core by calling the &drm_connector_funcs.dpms
1018 * callback. For atomic drivers the remapping to the "ACTIVE" property is
1019 * implemented in the DRM core.
1021 * Note that this property cannot be set through the MODE_ATOMIC ioctl,
1022 * userspace must use "ACTIVE" on the CRTC instead.
1026 * For userspace also running on legacy drivers the "DPMS" semantics are a
1027 * lot more complicated. First, userspace cannot rely on the "DPMS" value
1028 * returned by the GETCONNECTOR actually reflecting reality, because many
1029 * drivers fail to update it. For atomic drivers this is taken care of in
1030 * drm_atomic_helper_update_legacy_modeset_state().
1032 * The second issue is that the DPMS state is only well-defined when the
1033 * connector is connected to a CRTC. In atomic the DRM core enforces that
1034 * "ACTIVE" is off in such a case, no such checks exists for "DPMS".
1036 * Finally, when enabling an output using the legacy SETCONFIG ioctl then
1037 * "DPMS" is forced to ON. But see above, that might not be reflected in
1038 * the software value on legacy drivers.
1040 * Summarizing: Only set "DPMS" when the connector is known to be enabled,
1041 * assume that a successful SETCONFIG call also sets "DPMS" to on, and
1042 * never read back the value of "DPMS" because it can be incorrect.
1044 * Connector path property to identify how this sink is physically
1045 * connected. Used by DP MST. This should be set by calling
1046 * drm_connector_set_path_property(), in the case of DP MST with the
1047 * path property the MST manager created. Userspace cannot change this
1050 * Connector tile group property to indicate how a set of DRM connector
1051 * compose together into one logical screen. This is used by both high-res
1052 * external screens (often only using a single cable, but exposing multiple
1053 * DP MST sinks), or high-res integrated panels (like dual-link DSI) which
1054 * are not gen-locked. Note that for tiled panels which are genlocked, like
1055 * dual-link LVDS or dual-link DSI, the driver should try to not expose the
1056 * tiling and virtualise both &drm_crtc and &drm_plane if needed. Drivers
1057 * should update this value using drm_connector_set_tile_property().
1058 * Userspace cannot change this property.
1060 * Connector link-status property to indicate the status of link. The
1061 * default value of link-status is "GOOD". If something fails during or
1062 * after modeset, the kernel driver may set this to "BAD" and issue a
1063 * hotplug uevent. Drivers should update this value using
1064 * drm_connector_set_link_status_property().
1066 * When user-space receives the hotplug uevent and detects a "BAD"
1067 * link-status, the sink doesn't receive pixels anymore (e.g. the screen
1068 * becomes completely black). The list of available modes may have
1069 * changed. User-space is expected to pick a new mode if the current one
1070 * has disappeared and perform a new modeset with link-status set to
1071 * "GOOD" to re-enable the connector.
1073 * If multiple connectors share the same CRTC and one of them gets a "BAD"
1074 * link-status, the other are unaffected (ie. the sinks still continue to
1077 * When user-space performs an atomic commit on a connector with a "BAD"
1078 * link-status without resetting the property to "GOOD", the sink may
1079 * still not receive pixels. When user-space performs an atomic commit
1080 * which resets the link-status property to "GOOD" without the
1081 * ALLOW_MODESET flag set, it might fail because a modeset is required.
1083 * User-space can only change link-status to "GOOD", changing it to "BAD"
1086 * For backwards compatibility with non-atomic userspace the kernel
1087 * tries to automatically set the link-status back to "GOOD" in the
1088 * SETCRTC IOCTL. This might fail if the mode is no longer valid, similar
1089 * to how it might fail if a different screen has been connected in the
1092 * Indicates the output should be ignored for purposes of displaying a
1093 * standard desktop environment or console. This is most likely because
1094 * the output device is not rectilinear.
1095 * Content Protection:
1096 * This property is used by userspace to request the kernel protect future
1097 * content communicated over the link. When requested, kernel will apply
1098 * the appropriate means of protection (most often HDCP), and use the
1099 * property to tell userspace the protection is active.
1101 * Drivers can set this up by calling
1102 * drm_connector_attach_content_protection_property() on initialization.
1104 * The value of this property can be one of the following:
1106 * DRM_MODE_CONTENT_PROTECTION_UNDESIRED = 0
1107 * The link is not protected, content is transmitted in the clear.
1108 * DRM_MODE_CONTENT_PROTECTION_DESIRED = 1
1109 * Userspace has requested content protection, but the link is not
1110 * currently protected. When in this state, kernel should enable
1111 * Content Protection as soon as possible.
1112 * DRM_MODE_CONTENT_PROTECTION_ENABLED = 2
1113 * Userspace has requested content protection, and the link is
1114 * protected. Only the driver can set the property to this value.
1115 * If userspace attempts to set to ENABLED, kernel will return
1120 * - DESIRED state should be preserved until userspace de-asserts it by
1121 * setting the property to UNDESIRED. This means ENABLED should only
1122 * transition to UNDESIRED when the user explicitly requests it.
1123 * - If the state is DESIRED, kernel should attempt to re-authenticate the
1124 * link whenever possible. This includes across disable/enable, dpms,
1125 * hotplug, downstream device changes, link status failures, etc..
1126 * - Kernel sends uevent with the connector id and property id through
1127 * @drm_hdcp_update_content_protection, upon below kernel triggered
1130 * - DESIRED -> ENABLED (authentication success)
1131 * - ENABLED -> DESIRED (termination of authentication)
1132 * - Please note no uevents for userspace triggered property state changes,
1133 * which can't fail such as
1135 * - DESIRED/ENABLED -> UNDESIRED
1136 * - UNDESIRED -> DESIRED
1137 * - Userspace is responsible for polling the property or listen to uevents
1138 * to determine when the value transitions from ENABLED to DESIRED.
1139 * This signifies the link is no longer protected and userspace should
1140 * take appropriate action (whatever that might be).
1142 * HDCP Content Type:
1143 * This Enum property is used by the userspace to declare the content type
1144 * of the display stream, to kernel. Here display stream stands for any
1145 * display content that userspace intended to display through HDCP
1148 * Content Type of a stream is decided by the owner of the stream, as
1149 * "HDCP Type0" or "HDCP Type1".
1151 * The value of the property can be one of the below:
1152 * - "HDCP Type0": DRM_MODE_HDCP_CONTENT_TYPE0 = 0
1153 * - "HDCP Type1": DRM_MODE_HDCP_CONTENT_TYPE1 = 1
1155 * When kernel starts the HDCP authentication (see "Content Protection"
1156 * for details), it uses the content type in "HDCP Content Type"
1157 * for performing the HDCP authentication with the display sink.
1159 * Please note in HDCP spec versions, a link can be authenticated with
1160 * HDCP 2.2 for Content Type 0/Content Type 1. Where as a link can be
1161 * authenticated with HDCP1.4 only for Content Type 0(though it is implicit
1162 * in nature. As there is no reference for Content Type in HDCP1.4).
1164 * HDCP2.2 authentication protocol itself takes the "Content Type" as a
1165 * parameter, which is a input for the DP HDCP2.2 encryption algo.
1167 * In case of Type 0 content protection request, kernel driver can choose
1168 * either of HDCP spec versions 1.4 and 2.2. When HDCP2.2 is used for
1169 * "HDCP Type 0", a HDCP 2.2 capable repeater in the downstream can send
1170 * that content to a HDCP 1.4 authenticated HDCP sink (Type0 link).
1171 * But if the content is classified as "HDCP Type 1", above mentioned
1172 * HDCP 2.2 repeater wont send the content to the HDCP sink as it can't
1173 * authenticate the HDCP1.4 capable sink for "HDCP Type 1".
1175 * Please note userspace can be ignorant of the HDCP versions used by the
1176 * kernel driver to achieve the "HDCP Content Type".
1178 * At current scenario, classifying a content as Type 1 ensures that the
1179 * content will be displayed only through the HDCP2.2 encrypted link.
1181 * Note that the HDCP Content Type property is introduced at HDCP 2.2, and
1182 * defaults to type 0. It is only exposed by drivers supporting HDCP 2.2
1183 * (hence supporting Type 0 and Type 1). Based on how next versions of
1184 * HDCP specs are defined content Type could be used for higher versions
1187 * If content type is changed when "Content Protection" is not UNDESIRED,
1188 * then kernel will disable the HDCP and re-enable with new type in the
1189 * same atomic commit. And when "Content Protection" is ENABLED, it means
1190 * that link is HDCP authenticated and encrypted, for the transmission of
1191 * the Type of stream mentioned at "HDCP Content Type".
1193 * HDR_OUTPUT_METADATA:
1194 * Connector property to enable userspace to send HDR Metadata to
1195 * driver. This metadata is based on the composition and blending
1196 * policies decided by user, taking into account the hardware and
1197 * sink capabilities. The driver gets this metadata and creates a
1198 * Dynamic Range and Mastering Infoframe (DRM) in case of HDMI,
1199 * SDP packet (Non-audio INFOFRAME SDP v1.3) for DP. This is then
1200 * sent to sink. This notifies the sink of the upcoming frame's Color
1201 * Encoding and Luminance parameters.
1203 * Userspace first need to detect the HDR capabilities of sink by
1204 * reading and parsing the EDID. Details of HDR metadata for HDMI
1205 * are added in CTA 861.G spec. For DP , its defined in VESA DP
1206 * Standard v1.4. It needs to then get the metadata information
1207 * of the video/game/app content which are encoded in HDR (basically
1208 * using HDR transfer functions). With this information it needs to
1209 * decide on a blending policy and compose the relevant
1210 * layers/overlays into a common format. Once this blending is done,
1211 * userspace will be aware of the metadata of the composed frame to
1212 * be send to sink. It then uses this property to communicate this
1213 * metadata to driver which then make a Infoframe packet and sends
1214 * to sink based on the type of encoder connected.
1216 * Userspace will be responsible to do Tone mapping operation in case:
1217 * - Some layers are HDR and others are SDR
1218 * - HDR layers luminance is not same as sink
1220 * It will even need to do colorspace conversion and get all layers
1221 * to one common colorspace for blending. It can use either GL, Media
1222 * or display engine to get this done based on the capabilities of the
1223 * associated hardware.
1225 * Driver expects metadata to be put in &struct hdr_output_metadata
1226 * structure from userspace. This is received as blob and stored in
1227 * &drm_connector_state.hdr_output_metadata. It parses EDID and saves the
1228 * sink metadata in &struct hdr_sink_metadata, as
1229 * &drm_connector.hdr_sink_metadata. Driver uses
1230 * drm_hdmi_infoframe_set_hdr_metadata() helper to set the HDR metadata,
1231 * hdmi_drm_infoframe_pack() to pack the infoframe as per spec, in case of
1235 * This range property is used by userspace to limit the bit depth. When
1236 * used the driver would limit the bpc in accordance with the valid range
1237 * supported by the hardware and sink. Drivers to use the function
1238 * drm_connector_attach_max_bpc_property() to create and attach the
1239 * property to the connector during initialization.
1241 * Connectors also have one standardized atomic property:
1244 * Mode object ID of the &drm_crtc this connector should be connected to.
1246 * Connectors for LCD panels may also have one standardized property:
1248 * panel orientation:
1249 * On some devices the LCD panel is mounted in the casing in such a way
1250 * that the up/top side of the panel does not match with the top side of
1251 * the device. Userspace can use this property to check for this.
1252 * Note that input coordinates from touchscreens (input devices with
1253 * INPUT_PROP_DIRECT) will still map 1:1 to the actual LCD panel
1254 * coordinates, so if userspace rotates the picture to adjust for
1255 * the orientation it must also apply the same transformation to the
1256 * touchscreen input coordinates. This property is initialized by calling
1257 * drm_connector_set_panel_orientation() or
1258 * drm_connector_set_panel_orientation_with_quirk()
1261 * This property defines how a non-native mode is upscaled to the native
1262 * mode of an LCD panel:
1265 * No upscaling happens, scaling is left to the panel. Not all
1266 * drivers expose this mode.
1268 * The output is upscaled to the full resolution of the panel,
1269 * ignoring the aspect ratio.
1271 * No upscaling happens, the output is centered within the native
1272 * resolution the panel.
1274 * The output is upscaled to maximize either the width or height
1275 * while retaining the aspect ratio.
1277 * This property should be set up by calling
1278 * drm_connector_attach_scaling_mode_property(). Note that drivers
1279 * can also expose this property to external outputs, in which case they
1280 * must support "None", which should be the default (since external screens
1281 * have a built-in scaler).
1284 * This property is used by DVI-I, TVout and DisplayPort to indicate different
1285 * connector subtypes. Enum values more or less match with those from main
1287 * For DVI-I and TVout there is also a matching property "select subconnector"
1288 * allowing to switch between signal types.
1289 * DP subconnector corresponds to a downstream port.
1291 * privacy-screen sw-state, privacy-screen hw-state:
1292 * These 2 optional properties can be used to query the state of the
1293 * electronic privacy screen that is available on some displays; and in
1294 * some cases also control the state. If a driver implements these
1295 * properties then both properties must be present.
1297 * "privacy-screen hw-state" is read-only and reflects the actual state
1298 * of the privacy-screen, possible values: "Enabled", "Disabled,
1299 * "Enabled-locked", "Disabled-locked". The locked states indicate
1300 * that the state cannot be changed through the DRM API. E.g. there
1301 * might be devices where the firmware-setup options, or a hardware
1302 * slider-switch, offer always on / off modes.
1304 * "privacy-screen sw-state" can be set to change the privacy-screen state
1305 * when not locked. In this case the driver must update the hw-state
1306 * property to reflect the new state on completion of the commit of the
1307 * sw-state property. Setting the sw-state property when the hw-state is
1308 * locked must be interpreted by the driver as a request to change the
1309 * state to the set state when the hw-state becomes unlocked. E.g. if
1310 * "privacy-screen hw-state" is "Enabled-locked" and the sw-state
1311 * gets set to "Disabled" followed by the user unlocking the state by
1312 * changing the slider-switch position, then the driver must set the
1313 * state to "Disabled" upon receiving the unlock event.
1315 * In some cases the privacy-screen's actual state might change outside of
1316 * control of the DRM code. E.g. there might be a firmware handled hotkey
1317 * which toggles the actual state, or the actual state might be changed
1318 * through another userspace API such as writing /proc/acpi/ibm/lcdshadow.
1319 * In this case the driver must update both the hw-state and the sw-state
1320 * to reflect the new value, overwriting any pending state requests in the
1321 * sw-state. Any pending sw-state requests are thus discarded.
1323 * Note that the ability for the state to change outside of control of
1324 * the DRM master process means that userspace must not cache the value
1325 * of the sw-state. Caching the sw-state value and including it in later
1326 * atomic commits may lead to overriding a state change done through e.g.
1327 * a firmware handled hotkey. Therefor userspace must not include the
1328 * privacy-screen sw-state in an atomic commit unless it wants to change
1332 int drm_connector_create_standard_properties(struct drm_device *dev)
1334 struct drm_property *prop;
1336 prop = drm_property_create(dev, DRM_MODE_PROP_BLOB |
1337 DRM_MODE_PROP_IMMUTABLE,
1341 dev->mode_config.edid_property = prop;
1343 prop = drm_property_create_enum(dev, 0,
1344 "DPMS", drm_dpms_enum_list,
1345 ARRAY_SIZE(drm_dpms_enum_list));
1348 dev->mode_config.dpms_property = prop;
1350 prop = drm_property_create(dev,
1351 DRM_MODE_PROP_BLOB |
1352 DRM_MODE_PROP_IMMUTABLE,
1356 dev->mode_config.path_property = prop;
1358 prop = drm_property_create(dev,
1359 DRM_MODE_PROP_BLOB |
1360 DRM_MODE_PROP_IMMUTABLE,
1364 dev->mode_config.tile_property = prop;
1366 prop = drm_property_create_enum(dev, 0, "link-status",
1367 drm_link_status_enum_list,
1368 ARRAY_SIZE(drm_link_status_enum_list));
1371 dev->mode_config.link_status_property = prop;
1373 prop = drm_property_create_bool(dev, DRM_MODE_PROP_IMMUTABLE, "non-desktop");
1376 dev->mode_config.non_desktop_property = prop;
1378 prop = drm_property_create(dev, DRM_MODE_PROP_BLOB,
1379 "HDR_OUTPUT_METADATA", 0);
1382 dev->mode_config.hdr_output_metadata_property = prop;
1388 * drm_mode_create_dvi_i_properties - create DVI-I specific connector properties
1391 * Called by a driver the first time a DVI-I connector is made.
1395 int drm_mode_create_dvi_i_properties(struct drm_device *dev)
1397 struct drm_property *dvi_i_selector;
1398 struct drm_property *dvi_i_subconnector;
1400 if (dev->mode_config.dvi_i_select_subconnector_property)
1404 drm_property_create_enum(dev, 0,
1405 "select subconnector",
1406 drm_dvi_i_select_enum_list,
1407 ARRAY_SIZE(drm_dvi_i_select_enum_list));
1408 dev->mode_config.dvi_i_select_subconnector_property = dvi_i_selector;
1410 dvi_i_subconnector = drm_property_create_enum(dev, DRM_MODE_PROP_IMMUTABLE,
1412 drm_dvi_i_subconnector_enum_list,
1413 ARRAY_SIZE(drm_dvi_i_subconnector_enum_list));
1414 dev->mode_config.dvi_i_subconnector_property = dvi_i_subconnector;
1418 EXPORT_SYMBOL(drm_mode_create_dvi_i_properties);
1421 * drm_connector_attach_dp_subconnector_property - create subconnector property for DP
1422 * @connector: drm_connector to attach property
1424 * Called by a driver when DP connector is created.
1426 void drm_connector_attach_dp_subconnector_property(struct drm_connector *connector)
1428 struct drm_mode_config *mode_config = &connector->dev->mode_config;
1430 if (!mode_config->dp_subconnector_property)
1431 mode_config->dp_subconnector_property =
1432 drm_property_create_enum(connector->dev,
1433 DRM_MODE_PROP_IMMUTABLE,
1435 drm_dp_subconnector_enum_list,
1436 ARRAY_SIZE(drm_dp_subconnector_enum_list));
1438 drm_object_attach_property(&connector->base,
1439 mode_config->dp_subconnector_property,
1440 DRM_MODE_SUBCONNECTOR_Unknown);
1442 EXPORT_SYMBOL(drm_connector_attach_dp_subconnector_property);
1445 * DOC: HDMI connector properties
1447 * content type (HDMI specific):
1448 * Indicates content type setting to be used in HDMI infoframes to indicate
1449 * content type for the external device, so that it adjusts its display
1450 * settings accordingly.
1452 * The value of this property can be one of the following:
1455 * Content type is unknown
1457 * Content type is graphics
1459 * Content type is photo
1461 * Content type is cinema
1463 * Content type is game
1465 * The meaning of each content type is defined in CTA-861-G table 15.
1467 * Drivers can set up this property by calling
1468 * drm_connector_attach_content_type_property(). Decoding to
1469 * infoframe values is done through drm_hdmi_avi_infoframe_content_type().
1473 * drm_connector_attach_content_type_property - attach content-type property
1474 * @connector: connector to attach content type property on.
1476 * Called by a driver the first time a HDMI connector is made.
1480 int drm_connector_attach_content_type_property(struct drm_connector *connector)
1482 if (!drm_mode_create_content_type_property(connector->dev))
1483 drm_object_attach_property(&connector->base,
1484 connector->dev->mode_config.content_type_property,
1485 DRM_MODE_CONTENT_TYPE_NO_DATA);
1488 EXPORT_SYMBOL(drm_connector_attach_content_type_property);
1491 * drm_connector_attach_tv_margin_properties - attach TV connector margin
1493 * @connector: DRM connector
1495 * Called by a driver when it needs to attach TV margin props to a connector.
1496 * Typically used on SDTV and HDMI connectors.
1498 void drm_connector_attach_tv_margin_properties(struct drm_connector *connector)
1500 struct drm_device *dev = connector->dev;
1502 drm_object_attach_property(&connector->base,
1503 dev->mode_config.tv_left_margin_property,
1505 drm_object_attach_property(&connector->base,
1506 dev->mode_config.tv_right_margin_property,
1508 drm_object_attach_property(&connector->base,
1509 dev->mode_config.tv_top_margin_property,
1511 drm_object_attach_property(&connector->base,
1512 dev->mode_config.tv_bottom_margin_property,
1515 EXPORT_SYMBOL(drm_connector_attach_tv_margin_properties);
1518 * drm_mode_create_tv_margin_properties - create TV connector margin properties
1521 * Called by a driver's HDMI connector initialization routine, this function
1522 * creates the TV margin properties for a given device. No need to call this
1523 * function for an SDTV connector, it's already called from
1524 * drm_mode_create_tv_properties().
1527 * 0 on success or a negative error code on failure.
1529 int drm_mode_create_tv_margin_properties(struct drm_device *dev)
1531 if (dev->mode_config.tv_left_margin_property)
1534 dev->mode_config.tv_left_margin_property =
1535 drm_property_create_range(dev, 0, "left margin", 0, 100);
1536 if (!dev->mode_config.tv_left_margin_property)
1539 dev->mode_config.tv_right_margin_property =
1540 drm_property_create_range(dev, 0, "right margin", 0, 100);
1541 if (!dev->mode_config.tv_right_margin_property)
1544 dev->mode_config.tv_top_margin_property =
1545 drm_property_create_range(dev, 0, "top margin", 0, 100);
1546 if (!dev->mode_config.tv_top_margin_property)
1549 dev->mode_config.tv_bottom_margin_property =
1550 drm_property_create_range(dev, 0, "bottom margin", 0, 100);
1551 if (!dev->mode_config.tv_bottom_margin_property)
1556 EXPORT_SYMBOL(drm_mode_create_tv_margin_properties);
1559 * drm_mode_create_tv_properties - create TV specific connector properties
1561 * @num_modes: number of different TV formats (modes) supported
1562 * @modes: array of pointers to strings containing name of each format
1564 * Called by a driver's TV initialization routine, this function creates
1565 * the TV specific connector properties for a given device. Caller is
1566 * responsible for allocating a list of format names and passing them to
1570 * 0 on success or a negative error code on failure.
1572 int drm_mode_create_tv_properties(struct drm_device *dev,
1573 unsigned int num_modes,
1574 const char * const modes[])
1576 struct drm_property *tv_selector;
1577 struct drm_property *tv_subconnector;
1580 if (dev->mode_config.tv_select_subconnector_property)
1584 * Basic connector properties
1586 tv_selector = drm_property_create_enum(dev, 0,
1587 "select subconnector",
1588 drm_tv_select_enum_list,
1589 ARRAY_SIZE(drm_tv_select_enum_list));
1593 dev->mode_config.tv_select_subconnector_property = tv_selector;
1596 drm_property_create_enum(dev, DRM_MODE_PROP_IMMUTABLE,
1598 drm_tv_subconnector_enum_list,
1599 ARRAY_SIZE(drm_tv_subconnector_enum_list));
1600 if (!tv_subconnector)
1602 dev->mode_config.tv_subconnector_property = tv_subconnector;
1605 * Other, TV specific properties: margins & TV modes.
1607 if (drm_mode_create_tv_margin_properties(dev))
1610 dev->mode_config.tv_mode_property =
1611 drm_property_create(dev, DRM_MODE_PROP_ENUM,
1613 if (!dev->mode_config.tv_mode_property)
1616 for (i = 0; i < num_modes; i++)
1617 drm_property_add_enum(dev->mode_config.tv_mode_property,
1620 dev->mode_config.tv_brightness_property =
1621 drm_property_create_range(dev, 0, "brightness", 0, 100);
1622 if (!dev->mode_config.tv_brightness_property)
1625 dev->mode_config.tv_contrast_property =
1626 drm_property_create_range(dev, 0, "contrast", 0, 100);
1627 if (!dev->mode_config.tv_contrast_property)
1630 dev->mode_config.tv_flicker_reduction_property =
1631 drm_property_create_range(dev, 0, "flicker reduction", 0, 100);
1632 if (!dev->mode_config.tv_flicker_reduction_property)
1635 dev->mode_config.tv_overscan_property =
1636 drm_property_create_range(dev, 0, "overscan", 0, 100);
1637 if (!dev->mode_config.tv_overscan_property)
1640 dev->mode_config.tv_saturation_property =
1641 drm_property_create_range(dev, 0, "saturation", 0, 100);
1642 if (!dev->mode_config.tv_saturation_property)
1645 dev->mode_config.tv_hue_property =
1646 drm_property_create_range(dev, 0, "hue", 0, 100);
1647 if (!dev->mode_config.tv_hue_property)
1654 EXPORT_SYMBOL(drm_mode_create_tv_properties);
1657 * drm_mode_create_scaling_mode_property - create scaling mode property
1660 * Called by a driver the first time it's needed, must be attached to desired
1663 * Atomic drivers should use drm_connector_attach_scaling_mode_property()
1664 * instead to correctly assign &drm_connector_state.scaling_mode
1665 * in the atomic state.
1669 int drm_mode_create_scaling_mode_property(struct drm_device *dev)
1671 struct drm_property *scaling_mode;
1673 if (dev->mode_config.scaling_mode_property)
1677 drm_property_create_enum(dev, 0, "scaling mode",
1678 drm_scaling_mode_enum_list,
1679 ARRAY_SIZE(drm_scaling_mode_enum_list));
1681 dev->mode_config.scaling_mode_property = scaling_mode;
1685 EXPORT_SYMBOL(drm_mode_create_scaling_mode_property);
1688 * DOC: Variable refresh properties
1690 * Variable refresh rate capable displays can dynamically adjust their
1691 * refresh rate by extending the duration of their vertical front porch
1692 * until page flip or timeout occurs. This can reduce or remove stuttering
1693 * and latency in scenarios where the page flip does not align with the
1696 * An example scenario would be an application flipping at a constant rate
1697 * of 48Hz on a 60Hz display. The page flip will frequently miss the vblank
1698 * interval and the same contents will be displayed twice. This can be
1699 * observed as stuttering for content with motion.
1701 * If variable refresh rate was active on a display that supported a
1702 * variable refresh range from 35Hz to 60Hz no stuttering would be observable
1703 * for the example scenario. The minimum supported variable refresh rate of
1704 * 35Hz is below the page flip frequency and the vertical front porch can
1705 * be extended until the page flip occurs. The vblank interval will be
1706 * directly aligned to the page flip rate.
1708 * Not all userspace content is suitable for use with variable refresh rate.
1709 * Large and frequent changes in vertical front porch duration may worsen
1710 * perceived stuttering for input sensitive applications.
1712 * Panel brightness will also vary with vertical front porch duration. Some
1713 * panels may have noticeable differences in brightness between the minimum
1714 * vertical front porch duration and the maximum vertical front porch duration.
1715 * Large and frequent changes in vertical front porch duration may produce
1716 * observable flickering for such panels.
1718 * Userspace control for variable refresh rate is supported via properties
1719 * on the &drm_connector and &drm_crtc objects.
1722 * Optional &drm_connector boolean property that drivers should attach
1723 * with drm_connector_attach_vrr_capable_property() on connectors that
1724 * could support variable refresh rates. Drivers should update the
1725 * property value by calling drm_connector_set_vrr_capable_property().
1727 * Absence of the property should indicate absence of support.
1730 * Default &drm_crtc boolean property that notifies the driver that the
1731 * content on the CRTC is suitable for variable refresh rate presentation.
1732 * The driver will take this property as a hint to enable variable
1733 * refresh rate support if the receiver supports it, ie. if the
1734 * "vrr_capable" property is true on the &drm_connector object. The
1735 * vertical front porch duration will be extended until page-flip or
1736 * timeout when enabled.
1738 * The minimum vertical front porch duration is defined as the vertical
1739 * front porch duration for the current mode.
1741 * The maximum vertical front porch duration is greater than or equal to
1742 * the minimum vertical front porch duration. The duration is derived
1743 * from the minimum supported variable refresh rate for the connector.
1745 * The driver may place further restrictions within these minimum
1746 * and maximum bounds.
1750 * drm_connector_attach_vrr_capable_property - creates the
1751 * vrr_capable property
1752 * @connector: connector to create the vrr_capable property on.
1754 * This is used by atomic drivers to add support for querying
1755 * variable refresh rate capability for a connector.
1758 * Zero on success, negative errno on failure.
1760 int drm_connector_attach_vrr_capable_property(
1761 struct drm_connector *connector)
1763 struct drm_device *dev = connector->dev;
1764 struct drm_property *prop;
1766 if (!connector->vrr_capable_property) {
1767 prop = drm_property_create_bool(dev, DRM_MODE_PROP_IMMUTABLE,
1772 connector->vrr_capable_property = prop;
1773 drm_object_attach_property(&connector->base, prop, 0);
1778 EXPORT_SYMBOL(drm_connector_attach_vrr_capable_property);
1781 * drm_connector_attach_scaling_mode_property - attach atomic scaling mode property
1782 * @connector: connector to attach scaling mode property on.
1783 * @scaling_mode_mask: or'ed mask of BIT(%DRM_MODE_SCALE_\*).
1785 * This is used to add support for scaling mode to atomic drivers.
1786 * The scaling mode will be set to &drm_connector_state.scaling_mode
1787 * and can be used from &drm_connector_helper_funcs->atomic_check for validation.
1789 * This is the atomic version of drm_mode_create_scaling_mode_property().
1792 * Zero on success, negative errno on failure.
1794 int drm_connector_attach_scaling_mode_property(struct drm_connector *connector,
1795 u32 scaling_mode_mask)
1797 struct drm_device *dev = connector->dev;
1798 struct drm_property *scaling_mode_property;
1800 const unsigned valid_scaling_mode_mask =
1801 (1U << ARRAY_SIZE(drm_scaling_mode_enum_list)) - 1;
1803 if (WARN_ON(hweight32(scaling_mode_mask) < 2 ||
1804 scaling_mode_mask & ~valid_scaling_mode_mask))
1807 scaling_mode_property =
1808 drm_property_create(dev, DRM_MODE_PROP_ENUM, "scaling mode",
1809 hweight32(scaling_mode_mask));
1811 if (!scaling_mode_property)
1814 for (i = 0; i < ARRAY_SIZE(drm_scaling_mode_enum_list); i++) {
1817 if (!(BIT(i) & scaling_mode_mask))
1820 ret = drm_property_add_enum(scaling_mode_property,
1821 drm_scaling_mode_enum_list[i].type,
1822 drm_scaling_mode_enum_list[i].name);
1825 drm_property_destroy(dev, scaling_mode_property);
1831 drm_object_attach_property(&connector->base,
1832 scaling_mode_property, 0);
1834 connector->scaling_mode_property = scaling_mode_property;
1838 EXPORT_SYMBOL(drm_connector_attach_scaling_mode_property);
1841 * drm_mode_create_aspect_ratio_property - create aspect ratio property
1844 * Called by a driver the first time it's needed, must be attached to desired
1848 * Zero on success, negative errno on failure.
1850 int drm_mode_create_aspect_ratio_property(struct drm_device *dev)
1852 if (dev->mode_config.aspect_ratio_property)
1855 dev->mode_config.aspect_ratio_property =
1856 drm_property_create_enum(dev, 0, "aspect ratio",
1857 drm_aspect_ratio_enum_list,
1858 ARRAY_SIZE(drm_aspect_ratio_enum_list));
1860 if (dev->mode_config.aspect_ratio_property == NULL)
1865 EXPORT_SYMBOL(drm_mode_create_aspect_ratio_property);
1868 * DOC: standard connector properties
1871 * This property helps select a suitable colorspace based on the sink
1872 * capability. Modern sink devices support wider gamut like BT2020.
1873 * This helps switch to BT2020 mode if the BT2020 encoded video stream
1874 * is being played by the user, same for any other colorspace. Thereby
1875 * giving a good visual experience to users.
1877 * The expectation from userspace is that it should parse the EDID
1878 * and get supported colorspaces. Use this property and switch to the
1879 * one supported. Sink supported colorspaces should be retrieved by
1880 * userspace from EDID and driver will not explicitly expose them.
1882 * Basically the expectation from userspace is:
1883 * - Set up CRTC DEGAMMA/CTM/GAMMA to convert to some sink
1885 * - Set this new property to let the sink know what it
1886 * converted the CRTC output to.
1887 * - This property is just to inform sink what colorspace
1888 * source is trying to drive.
1890 * Because between HDMI and DP have different colorspaces,
1891 * drm_mode_create_hdmi_colorspace_property() is used for HDMI connector and
1892 * drm_mode_create_dp_colorspace_property() is used for DP connector.
1896 * drm_mode_create_hdmi_colorspace_property - create hdmi colorspace property
1897 * @connector: connector to create the Colorspace property on.
1899 * Called by a driver the first time it's needed, must be attached to desired
1903 * Zero on success, negative errno on failure.
1905 int drm_mode_create_hdmi_colorspace_property(struct drm_connector *connector)
1907 struct drm_device *dev = connector->dev;
1909 if (connector->colorspace_property)
1912 connector->colorspace_property =
1913 drm_property_create_enum(dev, DRM_MODE_PROP_ENUM, "Colorspace",
1915 ARRAY_SIZE(hdmi_colorspaces));
1917 if (!connector->colorspace_property)
1922 EXPORT_SYMBOL(drm_mode_create_hdmi_colorspace_property);
1925 * drm_mode_create_dp_colorspace_property - create dp colorspace property
1926 * @connector: connector to create the Colorspace property on.
1928 * Called by a driver the first time it's needed, must be attached to desired
1932 * Zero on success, negative errno on failure.
1934 int drm_mode_create_dp_colorspace_property(struct drm_connector *connector)
1936 struct drm_device *dev = connector->dev;
1938 if (connector->colorspace_property)
1941 connector->colorspace_property =
1942 drm_property_create_enum(dev, DRM_MODE_PROP_ENUM, "Colorspace",
1944 ARRAY_SIZE(dp_colorspaces));
1946 if (!connector->colorspace_property)
1951 EXPORT_SYMBOL(drm_mode_create_dp_colorspace_property);
1954 * drm_mode_create_content_type_property - create content type property
1957 * Called by a driver the first time it's needed, must be attached to desired
1961 * Zero on success, negative errno on failure.
1963 int drm_mode_create_content_type_property(struct drm_device *dev)
1965 if (dev->mode_config.content_type_property)
1968 dev->mode_config.content_type_property =
1969 drm_property_create_enum(dev, 0, "content type",
1970 drm_content_type_enum_list,
1971 ARRAY_SIZE(drm_content_type_enum_list));
1973 if (dev->mode_config.content_type_property == NULL)
1978 EXPORT_SYMBOL(drm_mode_create_content_type_property);
1981 * drm_mode_create_suggested_offset_properties - create suggests offset properties
1984 * Create the suggested x/y offset property for connectors.
1987 * 0 on success or a negative error code on failure.
1989 int drm_mode_create_suggested_offset_properties(struct drm_device *dev)
1991 if (dev->mode_config.suggested_x_property && dev->mode_config.suggested_y_property)
1994 dev->mode_config.suggested_x_property =
1995 drm_property_create_range(dev, DRM_MODE_PROP_IMMUTABLE, "suggested X", 0, 0xffffffff);
1997 dev->mode_config.suggested_y_property =
1998 drm_property_create_range(dev, DRM_MODE_PROP_IMMUTABLE, "suggested Y", 0, 0xffffffff);
2000 if (dev->mode_config.suggested_x_property == NULL ||
2001 dev->mode_config.suggested_y_property == NULL)
2005 EXPORT_SYMBOL(drm_mode_create_suggested_offset_properties);
2008 * drm_connector_set_path_property - set tile property on connector
2009 * @connector: connector to set property on.
2010 * @path: path to use for property; must not be NULL.
2012 * This creates a property to expose to userspace to specify a
2013 * connector path. This is mainly used for DisplayPort MST where
2014 * connectors have a topology and we want to allow userspace to give
2015 * them more meaningful names.
2018 * Zero on success, negative errno on failure.
2020 int drm_connector_set_path_property(struct drm_connector *connector,
2023 struct drm_device *dev = connector->dev;
2026 ret = drm_property_replace_global_blob(dev,
2027 &connector->path_blob_ptr,
2031 dev->mode_config.path_property);
2034 EXPORT_SYMBOL(drm_connector_set_path_property);
2037 * drm_connector_set_tile_property - set tile property on connector
2038 * @connector: connector to set property on.
2040 * This looks up the tile information for a connector, and creates a
2041 * property for userspace to parse if it exists. The property is of
2042 * the form of 8 integers using ':' as a separator.
2043 * This is used for dual port tiled displays with DisplayPort SST
2044 * or DisplayPort MST connectors.
2047 * Zero on success, errno on failure.
2049 int drm_connector_set_tile_property(struct drm_connector *connector)
2051 struct drm_device *dev = connector->dev;
2055 if (!connector->has_tile) {
2056 ret = drm_property_replace_global_blob(dev,
2057 &connector->tile_blob_ptr,
2061 dev->mode_config.tile_property);
2065 snprintf(tile, 256, "%d:%d:%d:%d:%d:%d:%d:%d",
2066 connector->tile_group->id, connector->tile_is_single_monitor,
2067 connector->num_h_tile, connector->num_v_tile,
2068 connector->tile_h_loc, connector->tile_v_loc,
2069 connector->tile_h_size, connector->tile_v_size);
2071 ret = drm_property_replace_global_blob(dev,
2072 &connector->tile_blob_ptr,
2076 dev->mode_config.tile_property);
2079 EXPORT_SYMBOL(drm_connector_set_tile_property);
2082 * drm_connector_set_link_status_property - Set link status property of a connector
2083 * @connector: drm connector
2084 * @link_status: new value of link status property (0: Good, 1: Bad)
2086 * In usual working scenario, this link status property will always be set to
2087 * "GOOD". If something fails during or after a mode set, the kernel driver
2088 * may set this link status property to "BAD". The caller then needs to send a
2089 * hotplug uevent for userspace to re-check the valid modes through
2090 * GET_CONNECTOR_IOCTL and retry modeset.
2092 * Note: Drivers cannot rely on userspace to support this property and
2093 * issue a modeset. As such, they may choose to handle issues (like
2094 * re-training a link) without userspace's intervention.
2096 * The reason for adding this property is to handle link training failures, but
2097 * it is not limited to DP or link training. For example, if we implement
2098 * asynchronous setcrtc, this property can be used to report any failures in that.
2100 void drm_connector_set_link_status_property(struct drm_connector *connector,
2101 uint64_t link_status)
2103 struct drm_device *dev = connector->dev;
2105 drm_modeset_lock(&dev->mode_config.connection_mutex, NULL);
2106 connector->state->link_status = link_status;
2107 drm_modeset_unlock(&dev->mode_config.connection_mutex);
2109 EXPORT_SYMBOL(drm_connector_set_link_status_property);
2112 * drm_connector_attach_max_bpc_property - attach "max bpc" property
2113 * @connector: connector to attach max bpc property on.
2114 * @min: The minimum bit depth supported by the connector.
2115 * @max: The maximum bit depth supported by the connector.
2117 * This is used to add support for limiting the bit depth on a connector.
2120 * Zero on success, negative errno on failure.
2122 int drm_connector_attach_max_bpc_property(struct drm_connector *connector,
2125 struct drm_device *dev = connector->dev;
2126 struct drm_property *prop;
2128 prop = connector->max_bpc_property;
2130 prop = drm_property_create_range(dev, 0, "max bpc", min, max);
2134 connector->max_bpc_property = prop;
2137 drm_object_attach_property(&connector->base, prop, max);
2138 connector->state->max_requested_bpc = max;
2139 connector->state->max_bpc = max;
2143 EXPORT_SYMBOL(drm_connector_attach_max_bpc_property);
2146 * drm_connector_attach_hdr_output_metadata_property - attach "HDR_OUTPUT_METADA" property
2147 * @connector: connector to attach the property on.
2149 * This is used to allow the userspace to send HDR Metadata to the
2153 * Zero on success, negative errno on failure.
2155 int drm_connector_attach_hdr_output_metadata_property(struct drm_connector *connector)
2157 struct drm_device *dev = connector->dev;
2158 struct drm_property *prop = dev->mode_config.hdr_output_metadata_property;
2160 drm_object_attach_property(&connector->base, prop, 0);
2164 EXPORT_SYMBOL(drm_connector_attach_hdr_output_metadata_property);
2167 * drm_connector_attach_colorspace_property - attach "Colorspace" property
2168 * @connector: connector to attach the property on.
2170 * This is used to allow the userspace to signal the output colorspace
2174 * Zero on success, negative errno on failure.
2176 int drm_connector_attach_colorspace_property(struct drm_connector *connector)
2178 struct drm_property *prop = connector->colorspace_property;
2180 drm_object_attach_property(&connector->base, prop, DRM_MODE_COLORIMETRY_DEFAULT);
2184 EXPORT_SYMBOL(drm_connector_attach_colorspace_property);
2187 * drm_connector_atomic_hdr_metadata_equal - checks if the hdr metadata changed
2188 * @old_state: old connector state to compare
2189 * @new_state: new connector state to compare
2191 * This is used by HDR-enabled drivers to test whether the HDR metadata
2192 * have changed between two different connector state (and thus probably
2193 * requires a full blown mode change).
2196 * True if the metadata are equal, False otherwise
2198 bool drm_connector_atomic_hdr_metadata_equal(struct drm_connector_state *old_state,
2199 struct drm_connector_state *new_state)
2201 struct drm_property_blob *old_blob = old_state->hdr_output_metadata;
2202 struct drm_property_blob *new_blob = new_state->hdr_output_metadata;
2204 if (!old_blob || !new_blob)
2205 return old_blob == new_blob;
2207 if (old_blob->length != new_blob->length)
2210 return !memcmp(old_blob->data, new_blob->data, old_blob->length);
2212 EXPORT_SYMBOL(drm_connector_atomic_hdr_metadata_equal);
2215 * drm_connector_set_vrr_capable_property - sets the variable refresh rate
2216 * capable property for a connector
2217 * @connector: drm connector
2218 * @capable: True if the connector is variable refresh rate capable
2220 * Should be used by atomic drivers to update the indicated support for
2221 * variable refresh rate over a connector.
2223 void drm_connector_set_vrr_capable_property(
2224 struct drm_connector *connector, bool capable)
2226 if (!connector->vrr_capable_property)
2229 drm_object_property_set_value(&connector->base,
2230 connector->vrr_capable_property,
2233 EXPORT_SYMBOL(drm_connector_set_vrr_capable_property);
2236 * drm_connector_set_panel_orientation - sets the connector's panel_orientation
2237 * @connector: connector for which to set the panel-orientation property.
2238 * @panel_orientation: drm_panel_orientation value to set
2240 * This function sets the connector's panel_orientation and attaches
2241 * a "panel orientation" property to the connector.
2243 * Calling this function on a connector where the panel_orientation has
2244 * already been set is a no-op (e.g. the orientation has been overridden with
2245 * a kernel commandline option).
2247 * It is allowed to call this function with a panel_orientation of
2248 * DRM_MODE_PANEL_ORIENTATION_UNKNOWN, in which case it is a no-op.
2250 * The function shouldn't be called in panel after drm is registered (i.e.
2251 * drm_dev_register() is called in drm).
2254 * Zero on success, negative errno on failure.
2256 int drm_connector_set_panel_orientation(
2257 struct drm_connector *connector,
2258 enum drm_panel_orientation panel_orientation)
2260 struct drm_device *dev = connector->dev;
2261 struct drm_display_info *info = &connector->display_info;
2262 struct drm_property *prop;
2265 if (info->panel_orientation != DRM_MODE_PANEL_ORIENTATION_UNKNOWN)
2268 /* Don't attach the property if the orientation is unknown */
2269 if (panel_orientation == DRM_MODE_PANEL_ORIENTATION_UNKNOWN)
2272 info->panel_orientation = panel_orientation;
2274 prop = dev->mode_config.panel_orientation_property;
2276 prop = drm_property_create_enum(dev, DRM_MODE_PROP_IMMUTABLE,
2277 "panel orientation",
2278 drm_panel_orientation_enum_list,
2279 ARRAY_SIZE(drm_panel_orientation_enum_list));
2283 dev->mode_config.panel_orientation_property = prop;
2286 drm_object_attach_property(&connector->base, prop,
2287 info->panel_orientation);
2290 EXPORT_SYMBOL(drm_connector_set_panel_orientation);
2293 * drm_connector_set_panel_orientation_with_quirk - set the
2294 * connector's panel_orientation after checking for quirks
2295 * @connector: connector for which to init the panel-orientation property.
2296 * @panel_orientation: drm_panel_orientation value to set
2297 * @width: width in pixels of the panel, used for panel quirk detection
2298 * @height: height in pixels of the panel, used for panel quirk detection
2300 * Like drm_connector_set_panel_orientation(), but with a check for platform
2301 * specific (e.g. DMI based) quirks overriding the passed in panel_orientation.
2304 * Zero on success, negative errno on failure.
2306 int drm_connector_set_panel_orientation_with_quirk(
2307 struct drm_connector *connector,
2308 enum drm_panel_orientation panel_orientation,
2309 int width, int height)
2311 int orientation_quirk;
2313 orientation_quirk = drm_get_panel_orientation_quirk(width, height);
2314 if (orientation_quirk != DRM_MODE_PANEL_ORIENTATION_UNKNOWN)
2315 panel_orientation = orientation_quirk;
2317 return drm_connector_set_panel_orientation(connector,
2320 EXPORT_SYMBOL(drm_connector_set_panel_orientation_with_quirk);
2323 * drm_connector_set_orientation_from_panel -
2324 * set the connector's panel_orientation from panel's callback.
2325 * @connector: connector for which to init the panel-orientation property.
2326 * @panel: panel that can provide orientation information.
2328 * Drm drivers should call this function before drm_dev_register().
2329 * Orientation is obtained from panel's .get_orientation() callback.
2332 * Zero on success, negative errno on failure.
2334 int drm_connector_set_orientation_from_panel(
2335 struct drm_connector *connector,
2336 struct drm_panel *panel)
2338 enum drm_panel_orientation orientation;
2340 if (panel && panel->funcs && panel->funcs->get_orientation)
2341 orientation = panel->funcs->get_orientation(panel);
2343 orientation = DRM_MODE_PANEL_ORIENTATION_UNKNOWN;
2345 return drm_connector_set_panel_orientation(connector, orientation);
2347 EXPORT_SYMBOL(drm_connector_set_orientation_from_panel);
2349 static const struct drm_prop_enum_list privacy_screen_enum[] = {
2350 { PRIVACY_SCREEN_DISABLED, "Disabled" },
2351 { PRIVACY_SCREEN_ENABLED, "Enabled" },
2352 { PRIVACY_SCREEN_DISABLED_LOCKED, "Disabled-locked" },
2353 { PRIVACY_SCREEN_ENABLED_LOCKED, "Enabled-locked" },
2357 * drm_connector_create_privacy_screen_properties - create the drm connecter's
2358 * privacy-screen properties.
2359 * @connector: connector for which to create the privacy-screen properties
2361 * This function creates the "privacy-screen sw-state" and "privacy-screen
2362 * hw-state" properties for the connector. They are not attached.
2365 drm_connector_create_privacy_screen_properties(struct drm_connector *connector)
2367 if (connector->privacy_screen_sw_state_property)
2370 /* Note sw-state only supports the first 2 values of the enum */
2371 connector->privacy_screen_sw_state_property =
2372 drm_property_create_enum(connector->dev, DRM_MODE_PROP_ENUM,
2373 "privacy-screen sw-state",
2374 privacy_screen_enum, 2);
2376 connector->privacy_screen_hw_state_property =
2377 drm_property_create_enum(connector->dev,
2378 DRM_MODE_PROP_IMMUTABLE | DRM_MODE_PROP_ENUM,
2379 "privacy-screen hw-state",
2380 privacy_screen_enum,
2381 ARRAY_SIZE(privacy_screen_enum));
2383 EXPORT_SYMBOL(drm_connector_create_privacy_screen_properties);
2386 * drm_connector_attach_privacy_screen_properties - attach the drm connecter's
2387 * privacy-screen properties.
2388 * @connector: connector on which to attach the privacy-screen properties
2390 * This function attaches the "privacy-screen sw-state" and "privacy-screen
2391 * hw-state" properties to the connector. The initial state of both is set
2395 drm_connector_attach_privacy_screen_properties(struct drm_connector *connector)
2397 if (!connector->privacy_screen_sw_state_property)
2400 drm_object_attach_property(&connector->base,
2401 connector->privacy_screen_sw_state_property,
2402 PRIVACY_SCREEN_DISABLED);
2404 drm_object_attach_property(&connector->base,
2405 connector->privacy_screen_hw_state_property,
2406 PRIVACY_SCREEN_DISABLED);
2408 EXPORT_SYMBOL(drm_connector_attach_privacy_screen_properties);
2410 static void drm_connector_update_privacy_screen_properties(
2411 struct drm_connector *connector, bool set_sw_state)
2413 enum drm_privacy_screen_status sw_state, hw_state;
2415 drm_privacy_screen_get_state(connector->privacy_screen,
2416 &sw_state, &hw_state);
2419 connector->state->privacy_screen_sw_state = sw_state;
2420 drm_object_property_set_value(&connector->base,
2421 connector->privacy_screen_hw_state_property, hw_state);
2424 static int drm_connector_privacy_screen_notifier(
2425 struct notifier_block *nb, unsigned long action, void *data)
2427 struct drm_connector *connector =
2428 container_of(nb, struct drm_connector, privacy_screen_notifier);
2429 struct drm_device *dev = connector->dev;
2431 drm_modeset_lock(&dev->mode_config.connection_mutex, NULL);
2432 drm_connector_update_privacy_screen_properties(connector, true);
2433 drm_modeset_unlock(&dev->mode_config.connection_mutex);
2435 drm_sysfs_connector_status_event(connector,
2436 connector->privacy_screen_sw_state_property);
2437 drm_sysfs_connector_status_event(connector,
2438 connector->privacy_screen_hw_state_property);
2444 * drm_connector_attach_privacy_screen_provider - attach a privacy-screen to
2446 * @connector: connector to attach the privacy-screen to
2447 * @priv: drm_privacy_screen to attach
2449 * Create and attach the standard privacy-screen properties and register
2450 * a generic notifier for generating sysfs-connector-status-events
2451 * on external changes to the privacy-screen status.
2452 * This function takes ownership of the passed in drm_privacy_screen and will
2453 * call drm_privacy_screen_put() on it when the connector is destroyed.
2455 void drm_connector_attach_privacy_screen_provider(
2456 struct drm_connector *connector, struct drm_privacy_screen *priv)
2458 connector->privacy_screen = priv;
2459 connector->privacy_screen_notifier.notifier_call =
2460 drm_connector_privacy_screen_notifier;
2462 drm_connector_create_privacy_screen_properties(connector);
2463 drm_connector_update_privacy_screen_properties(connector, true);
2464 drm_connector_attach_privacy_screen_properties(connector);
2466 EXPORT_SYMBOL(drm_connector_attach_privacy_screen_provider);
2469 * drm_connector_update_privacy_screen - update connector's privacy-screen sw-state
2470 * @connector_state: connector-state to update the privacy-screen for
2472 * This function calls drm_privacy_screen_set_sw_state() on the connector's
2475 * If the connector has no privacy-screen, then this is a no-op.
2477 void drm_connector_update_privacy_screen(const struct drm_connector_state *connector_state)
2479 struct drm_connector *connector = connector_state->connector;
2482 if (!connector->privacy_screen)
2485 ret = drm_privacy_screen_set_sw_state(connector->privacy_screen,
2486 connector_state->privacy_screen_sw_state);
2488 drm_err(connector->dev, "Error updating privacy-screen sw_state\n");
2492 /* The hw_state property value may have changed, update it. */
2493 drm_connector_update_privacy_screen_properties(connector, false);
2495 EXPORT_SYMBOL(drm_connector_update_privacy_screen);
2497 int drm_connector_set_obj_prop(struct drm_mode_object *obj,
2498 struct drm_property *property,
2502 struct drm_connector *connector = obj_to_connector(obj);
2504 /* Do DPMS ourselves */
2505 if (property == connector->dev->mode_config.dpms_property) {
2506 ret = (*connector->funcs->dpms)(connector, (int)value);
2507 } else if (connector->funcs->set_property)
2508 ret = connector->funcs->set_property(connector, property, value);
2511 drm_object_property_set_value(&connector->base, property, value);
2515 int drm_connector_property_set_ioctl(struct drm_device *dev,
2516 void *data, struct drm_file *file_priv)
2518 struct drm_mode_connector_set_property *conn_set_prop = data;
2519 struct drm_mode_obj_set_property obj_set_prop = {
2520 .value = conn_set_prop->value,
2521 .prop_id = conn_set_prop->prop_id,
2522 .obj_id = conn_set_prop->connector_id,
2523 .obj_type = DRM_MODE_OBJECT_CONNECTOR
2526 /* It does all the locking and checking we need */
2527 return drm_mode_obj_set_property_ioctl(dev, &obj_set_prop, file_priv);
2530 static struct drm_encoder *drm_connector_get_encoder(struct drm_connector *connector)
2532 /* For atomic drivers only state objects are synchronously updated and
2533 * protected by modeset locks, so check those first.
2535 if (connector->state)
2536 return connector->state->best_encoder;
2537 return connector->encoder;
2541 drm_mode_expose_to_userspace(const struct drm_display_mode *mode,
2542 const struct list_head *modes,
2543 const struct drm_file *file_priv)
2546 * If user-space hasn't configured the driver to expose the stereo 3D
2547 * modes, don't expose them.
2549 if (!file_priv->stereo_allowed && drm_mode_is_stereo(mode))
2552 * If user-space hasn't configured the driver to expose the modes
2553 * with aspect-ratio, don't expose them. However if such a mode
2554 * is unique, let it be exposed, but reset the aspect-ratio flags
2555 * while preparing the list of user-modes.
2557 if (!file_priv->aspect_ratio_allowed) {
2558 const struct drm_display_mode *mode_itr;
2560 list_for_each_entry(mode_itr, modes, head) {
2561 if (mode_itr->expose_to_userspace &&
2562 drm_mode_match(mode_itr, mode,
2563 DRM_MODE_MATCH_TIMINGS |
2564 DRM_MODE_MATCH_CLOCK |
2565 DRM_MODE_MATCH_FLAGS |
2566 DRM_MODE_MATCH_3D_FLAGS))
2574 int drm_mode_getconnector(struct drm_device *dev, void *data,
2575 struct drm_file *file_priv)
2577 struct drm_mode_get_connector *out_resp = data;
2578 struct drm_connector *connector;
2579 struct drm_encoder *encoder;
2580 struct drm_display_mode *mode;
2582 int encoders_count = 0;
2585 struct drm_mode_modeinfo u_mode;
2586 struct drm_mode_modeinfo __user *mode_ptr;
2587 uint32_t __user *encoder_ptr;
2588 bool is_current_master;
2590 if (!drm_core_check_feature(dev, DRIVER_MODESET))
2593 memset(&u_mode, 0, sizeof(struct drm_mode_modeinfo));
2595 connector = drm_connector_lookup(dev, file_priv, out_resp->connector_id);
2599 encoders_count = hweight32(connector->possible_encoders);
2601 if ((out_resp->count_encoders >= encoders_count) && encoders_count) {
2603 encoder_ptr = (uint32_t __user *)(unsigned long)(out_resp->encoders_ptr);
2605 drm_connector_for_each_possible_encoder(connector, encoder) {
2606 if (put_user(encoder->base.id, encoder_ptr + copied)) {
2613 out_resp->count_encoders = encoders_count;
2615 out_resp->connector_id = connector->base.id;
2616 out_resp->connector_type = connector->connector_type;
2617 out_resp->connector_type_id = connector->connector_type_id;
2619 is_current_master = drm_is_current_master(file_priv);
2621 mutex_lock(&dev->mode_config.mutex);
2622 if (out_resp->count_modes == 0) {
2623 if (is_current_master)
2624 connector->funcs->fill_modes(connector,
2625 dev->mode_config.max_width,
2626 dev->mode_config.max_height);
2628 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",
2629 connector->base.id, connector->name);
2632 out_resp->mm_width = connector->display_info.width_mm;
2633 out_resp->mm_height = connector->display_info.height_mm;
2634 out_resp->subpixel = connector->display_info.subpixel_order;
2635 out_resp->connection = connector->status;
2637 /* delayed so we get modes regardless of pre-fill_modes state */
2638 list_for_each_entry(mode, &connector->modes, head) {
2639 WARN_ON(mode->expose_to_userspace);
2641 if (drm_mode_expose_to_userspace(mode, &connector->modes,
2643 mode->expose_to_userspace = true;
2649 * This ioctl is called twice, once to determine how much space is
2650 * needed, and the 2nd time to fill it.
2652 if ((out_resp->count_modes >= mode_count) && mode_count) {
2654 mode_ptr = (struct drm_mode_modeinfo __user *)(unsigned long)out_resp->modes_ptr;
2655 list_for_each_entry(mode, &connector->modes, head) {
2656 if (!mode->expose_to_userspace)
2659 /* Clear the tag for the next time around */
2660 mode->expose_to_userspace = false;
2662 drm_mode_convert_to_umode(&u_mode, mode);
2664 * Reset aspect ratio flags of user-mode, if modes with
2665 * aspect-ratio are not supported.
2667 if (!file_priv->aspect_ratio_allowed)
2668 u_mode.flags &= ~DRM_MODE_FLAG_PIC_AR_MASK;
2669 if (copy_to_user(mode_ptr + copied,
2670 &u_mode, sizeof(u_mode))) {
2674 * Clear the tag for the rest of
2675 * the modes for the next time around.
2677 list_for_each_entry_continue(mode, &connector->modes, head)
2678 mode->expose_to_userspace = false;
2680 mutex_unlock(&dev->mode_config.mutex);
2687 /* Clear the tag for the next time around */
2688 list_for_each_entry(mode, &connector->modes, head)
2689 mode->expose_to_userspace = false;
2692 out_resp->count_modes = mode_count;
2693 mutex_unlock(&dev->mode_config.mutex);
2695 drm_modeset_lock(&dev->mode_config.connection_mutex, NULL);
2696 encoder = drm_connector_get_encoder(connector);
2698 out_resp->encoder_id = encoder->base.id;
2700 out_resp->encoder_id = 0;
2702 /* Only grab properties after probing, to make sure EDID and other
2703 * properties reflect the latest status.
2705 ret = drm_mode_object_get_properties(&connector->base, file_priv->atomic,
2706 (uint32_t __user *)(unsigned long)(out_resp->props_ptr),
2707 (uint64_t __user *)(unsigned long)(out_resp->prop_values_ptr),
2708 &out_resp->count_props);
2709 drm_modeset_unlock(&dev->mode_config.connection_mutex);
2712 drm_connector_put(connector);
2718 * drm_connector_find_by_fwnode - Find a connector based on the associated fwnode
2719 * @fwnode: fwnode for which to find the matching drm_connector
2721 * This functions looks up a drm_connector based on its associated fwnode. When
2722 * a connector is found a reference to the connector is returned. The caller must
2723 * call drm_connector_put() to release this reference when it is done with the
2726 * Returns: A reference to the found connector or an ERR_PTR().
2728 struct drm_connector *drm_connector_find_by_fwnode(struct fwnode_handle *fwnode)
2730 struct drm_connector *connector, *found = ERR_PTR(-ENODEV);
2733 return ERR_PTR(-ENODEV);
2735 mutex_lock(&connector_list_lock);
2737 list_for_each_entry(connector, &connector_list, global_connector_list_entry) {
2738 if (connector->fwnode == fwnode ||
2739 (connector->fwnode && connector->fwnode->secondary == fwnode)) {
2740 drm_connector_get(connector);
2746 mutex_unlock(&connector_list_lock);
2752 * drm_connector_oob_hotplug_event - Report out-of-band hotplug event to connector
2753 * @connector_fwnode: fwnode_handle to report the event on
2755 * On some hardware a hotplug event notification may come from outside the display
2756 * driver / device. An example of this is some USB Type-C setups where the hardware
2757 * muxes the DisplayPort data and aux-lines but does not pass the altmode HPD
2758 * status bit to the GPU's DP HPD pin.
2760 * This function can be used to report these out-of-band events after obtaining
2761 * a drm_connector reference through calling drm_connector_find_by_fwnode().
2763 void drm_connector_oob_hotplug_event(struct fwnode_handle *connector_fwnode)
2765 struct drm_connector *connector;
2767 connector = drm_connector_find_by_fwnode(connector_fwnode);
2768 if (IS_ERR(connector))
2771 if (connector->funcs->oob_hotplug_event)
2772 connector->funcs->oob_hotplug_event(connector);
2774 drm_connector_put(connector);
2776 EXPORT_SYMBOL(drm_connector_oob_hotplug_event);
2782 * Tile groups are used to represent tiled monitors with a unique integer
2783 * identifier. Tiled monitors using DisplayID v1.3 have a unique 8-byte handle,
2784 * we store this in a tile group, so we have a common identifier for all tiles
2785 * in a monitor group. The property is called "TILE". Drivers can manage tile
2786 * groups using drm_mode_create_tile_group(), drm_mode_put_tile_group() and
2787 * drm_mode_get_tile_group(). But this is only needed for internal panels where
2788 * the tile group information is exposed through a non-standard way.
2791 static void drm_tile_group_free(struct kref *kref)
2793 struct drm_tile_group *tg = container_of(kref, struct drm_tile_group, refcount);
2794 struct drm_device *dev = tg->dev;
2796 mutex_lock(&dev->mode_config.idr_mutex);
2797 idr_remove(&dev->mode_config.tile_idr, tg->id);
2798 mutex_unlock(&dev->mode_config.idr_mutex);
2803 * drm_mode_put_tile_group - drop a reference to a tile group.
2805 * @tg: tile group to drop reference to.
2807 * drop reference to tile group and free if 0.
2809 void drm_mode_put_tile_group(struct drm_device *dev,
2810 struct drm_tile_group *tg)
2812 kref_put(&tg->refcount, drm_tile_group_free);
2814 EXPORT_SYMBOL(drm_mode_put_tile_group);
2817 * drm_mode_get_tile_group - get a reference to an existing tile group
2819 * @topology: 8-bytes unique per monitor.
2821 * Use the unique bytes to get a reference to an existing tile group.
2824 * tile group or NULL if not found.
2826 struct drm_tile_group *drm_mode_get_tile_group(struct drm_device *dev,
2827 const char topology[8])
2829 struct drm_tile_group *tg;
2832 mutex_lock(&dev->mode_config.idr_mutex);
2833 idr_for_each_entry(&dev->mode_config.tile_idr, tg, id) {
2834 if (!memcmp(tg->group_data, topology, 8)) {
2835 if (!kref_get_unless_zero(&tg->refcount))
2837 mutex_unlock(&dev->mode_config.idr_mutex);
2841 mutex_unlock(&dev->mode_config.idr_mutex);
2844 EXPORT_SYMBOL(drm_mode_get_tile_group);
2847 * drm_mode_create_tile_group - create a tile group from a displayid description
2849 * @topology: 8-bytes unique per monitor.
2851 * Create a tile group for the unique monitor, and get a unique
2852 * identifier for the tile group.
2855 * new tile group or NULL.
2857 struct drm_tile_group *drm_mode_create_tile_group(struct drm_device *dev,
2858 const char topology[8])
2860 struct drm_tile_group *tg;
2863 tg = kzalloc(sizeof(*tg), GFP_KERNEL);
2867 kref_init(&tg->refcount);
2868 memcpy(tg->group_data, topology, 8);
2871 mutex_lock(&dev->mode_config.idr_mutex);
2872 ret = idr_alloc(&dev->mode_config.tile_idr, tg, 1, 0, GFP_KERNEL);
2880 mutex_unlock(&dev->mode_config.idr_mutex);
2883 EXPORT_SYMBOL(drm_mode_create_tile_group);