2 * Copyright (c) 2016 Intel Corporation
4 * Permission to use, copy, modify, distribute, and sell this software and its
5 * documentation for any purpose is hereby granted without fee, provided that
6 * the above copyright notice appear in all copies and that both that copyright
7 * notice and this permission notice appear in supporting documentation, and
8 * that the name of the copyright holders not be used in advertising or
9 * publicity pertaining to distribution of the software without specific,
10 * written prior permission. The copyright holders make no representations
11 * about the suitability of this software for any purpose. It is provided "as
12 * is" without express or implied warranty.
14 * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
15 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
16 * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
17 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
18 * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
19 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
24 #include <drm/drm_connector.h>
25 #include <drm/drm_edid.h>
26 #include <drm/drm_encoder.h>
27 #include <drm/drm_utils.h>
29 #include "drm_crtc_internal.h"
30 #include "drm_internal.h"
35 * In DRM connectors are the general abstraction for display sinks, and include
36 * als fixed panels or anything else that can display pixels in some form. As
37 * opposed to all other KMS objects representing hardware (like CRTC, encoder or
38 * plane abstractions) connectors can be hotplugged and unplugged at runtime.
39 * Hence they are reference-counted using drm_connector_get() and
40 * drm_connector_put().
42 * KMS driver must create, initialize, register and attach at a &struct
43 * drm_connector for each such sink. The instance is created as other KMS
44 * objects and initialized by setting the following fields. The connector is
45 * initialized with a call to drm_connector_init() with a pointer to the
46 * &struct drm_connector_funcs and a connector type, and then exposed to
47 * userspace with a call to drm_connector_register().
49 * Connectors must be attached to an encoder to be used. For devices that map
50 * connectors to encoders 1:1, the connector should be attached at
51 * initialization time with a call to drm_mode_connector_attach_encoder(). The
52 * driver must also set the &drm_connector.encoder field to point to the
55 * For connectors which are not fixed (like built-in panels) the driver needs to
56 * support hotplug notifications. The simplest way to do that is by using the
57 * probe helpers, see drm_kms_helper_poll_init() for connectors which don't have
58 * hardware support for hotplug interrupts. Connectors with hardware hotplug
59 * support can instead use e.g. drm_helper_hpd_irq_event().
62 struct drm_conn_prop_enum_list {
69 * Connector and encoder types.
71 static struct drm_conn_prop_enum_list drm_connector_enum_list[] = {
72 { DRM_MODE_CONNECTOR_Unknown, "Unknown" },
73 { DRM_MODE_CONNECTOR_VGA, "VGA" },
74 { DRM_MODE_CONNECTOR_DVII, "DVI-I" },
75 { DRM_MODE_CONNECTOR_DVID, "DVI-D" },
76 { DRM_MODE_CONNECTOR_DVIA, "DVI-A" },
77 { DRM_MODE_CONNECTOR_Composite, "Composite" },
78 { DRM_MODE_CONNECTOR_SVIDEO, "SVIDEO" },
79 { DRM_MODE_CONNECTOR_LVDS, "LVDS" },
80 { DRM_MODE_CONNECTOR_Component, "Component" },
81 { DRM_MODE_CONNECTOR_9PinDIN, "DIN" },
82 { DRM_MODE_CONNECTOR_DisplayPort, "DP" },
83 { DRM_MODE_CONNECTOR_HDMIA, "HDMI-A" },
84 { DRM_MODE_CONNECTOR_HDMIB, "HDMI-B" },
85 { DRM_MODE_CONNECTOR_TV, "TV" },
86 { DRM_MODE_CONNECTOR_eDP, "eDP" },
87 { DRM_MODE_CONNECTOR_VIRTUAL, "Virtual" },
88 { DRM_MODE_CONNECTOR_DSI, "DSI" },
89 { DRM_MODE_CONNECTOR_DPI, "DPI" },
92 void drm_connector_ida_init(void)
96 for (i = 0; i < ARRAY_SIZE(drm_connector_enum_list); i++)
97 ida_init(&drm_connector_enum_list[i].ida);
100 void drm_connector_ida_destroy(void)
104 for (i = 0; i < ARRAY_SIZE(drm_connector_enum_list); i++)
105 ida_destroy(&drm_connector_enum_list[i].ida);
109 * drm_connector_get_cmdline_mode - reads the user's cmdline mode
110 * @connector: connector to quwery
112 * The kernel supports per-connector configuration of its consoles through
113 * use of the video= parameter. This function parses that option and
114 * extracts the user's specified mode (or enable/disable status) for a
115 * particular connector. This is typically only used during the early fbdev
118 static void drm_connector_get_cmdline_mode(struct drm_connector *connector)
120 struct drm_cmdline_mode *mode = &connector->cmdline_mode;
123 if (fb_get_options(connector->name, &option))
126 if (!drm_mode_parse_command_line_for_connector(option,
132 DRM_INFO("forcing %s connector %s\n", connector->name,
133 drm_get_connector_force_name(mode->force));
134 connector->force = mode->force;
137 DRM_DEBUG_KMS("cmdline mode for connector %s %dx%d@%dHz%s%s%s\n",
139 mode->xres, mode->yres,
140 mode->refresh_specified ? mode->refresh : 60,
141 mode->rb ? " reduced blanking" : "",
142 mode->margins ? " with margins" : "",
143 mode->interlace ? " interlaced" : "");
146 static void drm_connector_free(struct kref *kref)
148 struct drm_connector *connector =
149 container_of(kref, struct drm_connector, base.refcount);
150 struct drm_device *dev = connector->dev;
152 drm_mode_object_unregister(dev, &connector->base);
153 connector->funcs->destroy(connector);
157 * drm_connector_init - Init a preallocated connector
159 * @connector: the connector to init
160 * @funcs: callbacks for this connector
161 * @connector_type: user visible type of the connector
163 * Initialises a preallocated connector. Connectors should be
164 * subclassed as part of driver connector objects.
167 * Zero on success, error code on failure.
169 int drm_connector_init(struct drm_device *dev,
170 struct drm_connector *connector,
171 const struct drm_connector_funcs *funcs,
174 struct drm_mode_config *config = &dev->mode_config;
176 struct ida *connector_ida =
177 &drm_connector_enum_list[connector_type].ida;
179 ret = __drm_mode_object_add(dev, &connector->base,
180 DRM_MODE_OBJECT_CONNECTOR,
181 false, drm_connector_free);
185 connector->base.properties = &connector->properties;
186 connector->dev = dev;
187 connector->funcs = funcs;
189 ret = ida_simple_get(&config->connector_ida, 0, 0, GFP_KERNEL);
192 connector->index = ret;
195 connector->connector_type = connector_type;
196 connector->connector_type_id =
197 ida_simple_get(connector_ida, 1, 0, GFP_KERNEL);
198 if (connector->connector_type_id < 0) {
199 ret = connector->connector_type_id;
203 kasprintf(GFP_KERNEL, "%s-%d",
204 drm_connector_enum_list[connector_type].name,
205 connector->connector_type_id);
206 if (!connector->name) {
208 goto out_put_type_id;
211 INIT_LIST_HEAD(&connector->probed_modes);
212 INIT_LIST_HEAD(&connector->modes);
213 mutex_init(&connector->mutex);
214 connector->edid_blob_ptr = NULL;
215 connector->status = connector_status_unknown;
216 connector->display_info.panel_orientation =
217 DRM_MODE_PANEL_ORIENTATION_UNKNOWN;
219 drm_connector_get_cmdline_mode(connector);
221 /* We should add connectors at the end to avoid upsetting the connector
223 spin_lock_irq(&config->connector_list_lock);
224 list_add_tail(&connector->head, &config->connector_list);
225 config->num_connector++;
226 spin_unlock_irq(&config->connector_list_lock);
228 if (connector_type != DRM_MODE_CONNECTOR_VIRTUAL)
229 drm_object_attach_property(&connector->base,
230 config->edid_property,
233 drm_object_attach_property(&connector->base,
234 config->dpms_property, 0);
236 drm_object_attach_property(&connector->base,
237 config->link_status_property,
240 drm_object_attach_property(&connector->base,
241 config->non_desktop_property,
244 if (drm_core_check_feature(dev, DRIVER_ATOMIC)) {
245 drm_object_attach_property(&connector->base, config->prop_crtc_id, 0);
248 connector->debugfs_entry = NULL;
251 ida_simple_remove(connector_ida, connector->connector_type_id);
254 ida_simple_remove(&config->connector_ida, connector->index);
257 drm_mode_object_unregister(dev, &connector->base);
261 EXPORT_SYMBOL(drm_connector_init);
264 * drm_mode_connector_attach_encoder - attach a connector to an encoder
265 * @connector: connector to attach
266 * @encoder: encoder to attach @connector to
268 * This function links up a connector to an encoder. Note that the routing
269 * restrictions between encoders and crtcs are exposed to userspace through the
270 * possible_clones and possible_crtcs bitmasks.
273 * Zero on success, negative errno on failure.
275 int drm_mode_connector_attach_encoder(struct drm_connector *connector,
276 struct drm_encoder *encoder)
281 * In the past, drivers have attempted to model the static association
282 * of connector to encoder in simple connector/encoder devices using a
283 * direct assignment of connector->encoder = encoder. This connection
284 * is a logical one and the responsibility of the core, so drivers are
285 * expected not to mess with this.
287 * Note that the error return should've been enough here, but a large
288 * majority of drivers ignores the return value, so add in a big WARN
289 * to get people's attention.
291 if (WARN_ON(connector->encoder))
294 for (i = 0; i < DRM_CONNECTOR_MAX_ENCODER; i++) {
295 if (connector->encoder_ids[i] == 0) {
296 connector->encoder_ids[i] = encoder->base.id;
302 EXPORT_SYMBOL(drm_mode_connector_attach_encoder);
304 static void drm_mode_remove(struct drm_connector *connector,
305 struct drm_display_mode *mode)
307 list_del(&mode->head);
308 drm_mode_destroy(connector->dev, mode);
312 * drm_connector_cleanup - cleans up an initialised connector
313 * @connector: connector to cleanup
315 * Cleans up the connector but doesn't free the object.
317 void drm_connector_cleanup(struct drm_connector *connector)
319 struct drm_device *dev = connector->dev;
320 struct drm_display_mode *mode, *t;
322 /* The connector should have been removed from userspace long before
323 * it is finally destroyed.
325 if (WARN_ON(connector->registered))
326 drm_connector_unregister(connector);
328 if (connector->tile_group) {
329 drm_mode_put_tile_group(dev, connector->tile_group);
330 connector->tile_group = NULL;
333 list_for_each_entry_safe(mode, t, &connector->probed_modes, head)
334 drm_mode_remove(connector, mode);
336 list_for_each_entry_safe(mode, t, &connector->modes, head)
337 drm_mode_remove(connector, mode);
339 ida_simple_remove(&drm_connector_enum_list[connector->connector_type].ida,
340 connector->connector_type_id);
342 ida_simple_remove(&dev->mode_config.connector_ida,
345 kfree(connector->display_info.bus_formats);
346 drm_mode_object_unregister(dev, &connector->base);
347 kfree(connector->name);
348 connector->name = NULL;
349 spin_lock_irq(&dev->mode_config.connector_list_lock);
350 list_del(&connector->head);
351 dev->mode_config.num_connector--;
352 spin_unlock_irq(&dev->mode_config.connector_list_lock);
354 WARN_ON(connector->state && !connector->funcs->atomic_destroy_state);
355 if (connector->state && connector->funcs->atomic_destroy_state)
356 connector->funcs->atomic_destroy_state(connector,
359 mutex_destroy(&connector->mutex);
361 memset(connector, 0, sizeof(*connector));
363 EXPORT_SYMBOL(drm_connector_cleanup);
366 * drm_connector_register - register a connector
367 * @connector: the connector to register
369 * Register userspace interfaces for a connector
372 * Zero on success, error code on failure.
374 int drm_connector_register(struct drm_connector *connector)
378 if (!connector->dev->registered)
381 mutex_lock(&connector->mutex);
382 if (connector->registered)
385 ret = drm_sysfs_connector_add(connector);
389 ret = drm_debugfs_connector_add(connector);
394 if (connector->funcs->late_register) {
395 ret = connector->funcs->late_register(connector);
400 drm_mode_object_register(connector->dev, &connector->base);
402 connector->registered = true;
406 drm_debugfs_connector_remove(connector);
408 drm_sysfs_connector_remove(connector);
410 mutex_unlock(&connector->mutex);
413 EXPORT_SYMBOL(drm_connector_register);
416 * drm_connector_unregister - unregister a connector
417 * @connector: the connector to unregister
419 * Unregister userspace interfaces for a connector
421 void drm_connector_unregister(struct drm_connector *connector)
423 mutex_lock(&connector->mutex);
424 if (!connector->registered) {
425 mutex_unlock(&connector->mutex);
429 if (connector->funcs->early_unregister)
430 connector->funcs->early_unregister(connector);
432 drm_sysfs_connector_remove(connector);
433 drm_debugfs_connector_remove(connector);
435 connector->registered = false;
436 mutex_unlock(&connector->mutex);
438 EXPORT_SYMBOL(drm_connector_unregister);
440 void drm_connector_unregister_all(struct drm_device *dev)
442 struct drm_connector *connector;
443 struct drm_connector_list_iter conn_iter;
445 drm_connector_list_iter_begin(dev, &conn_iter);
446 drm_for_each_connector_iter(connector, &conn_iter)
447 drm_connector_unregister(connector);
448 drm_connector_list_iter_end(&conn_iter);
451 int drm_connector_register_all(struct drm_device *dev)
453 struct drm_connector *connector;
454 struct drm_connector_list_iter conn_iter;
457 drm_connector_list_iter_begin(dev, &conn_iter);
458 drm_for_each_connector_iter(connector, &conn_iter) {
459 ret = drm_connector_register(connector);
463 drm_connector_list_iter_end(&conn_iter);
466 drm_connector_unregister_all(dev);
471 * drm_get_connector_status_name - return a string for connector status
472 * @status: connector status to compute name of
474 * In contrast to the other drm_get_*_name functions this one here returns a
475 * const pointer and hence is threadsafe.
477 const char *drm_get_connector_status_name(enum drm_connector_status status)
479 if (status == connector_status_connected)
481 else if (status == connector_status_disconnected)
482 return "disconnected";
486 EXPORT_SYMBOL(drm_get_connector_status_name);
489 * drm_get_connector_force_name - return a string for connector force
490 * @force: connector force to get name of
492 * Returns: const pointer to name.
494 const char *drm_get_connector_force_name(enum drm_connector_force force)
497 case DRM_FORCE_UNSPECIFIED:
498 return "unspecified";
503 case DRM_FORCE_ON_DIGITAL:
510 #ifdef CONFIG_LOCKDEP
511 static struct lockdep_map connector_list_iter_dep_map = {
512 .name = "drm_connector_list_iter"
517 * drm_connector_list_iter_begin - initialize a connector_list iterator
519 * @iter: connector_list iterator
521 * Sets @iter up to walk the &drm_mode_config.connector_list of @dev. @iter
522 * must always be cleaned up again by calling drm_connector_list_iter_end().
523 * Iteration itself happens using drm_connector_list_iter_next() or
524 * drm_for_each_connector_iter().
526 void drm_connector_list_iter_begin(struct drm_device *dev,
527 struct drm_connector_list_iter *iter)
531 lock_acquire_shared_recursive(&connector_list_iter_dep_map, 0, 1, NULL, _RET_IP_);
533 EXPORT_SYMBOL(drm_connector_list_iter_begin);
536 * drm_connector_list_iter_next - return next connector
537 * @iter: connectr_list iterator
539 * Returns the next connector for @iter, or NULL when the list walk has
542 struct drm_connector *
543 drm_connector_list_iter_next(struct drm_connector_list_iter *iter)
545 struct drm_connector *old_conn = iter->conn;
546 struct drm_mode_config *config = &iter->dev->mode_config;
547 struct list_head *lhead;
550 spin_lock_irqsave(&config->connector_list_lock, flags);
551 lhead = old_conn ? &old_conn->head : &config->connector_list;
554 if (lhead->next == &config->connector_list) {
560 iter->conn = list_entry(lhead, struct drm_connector, head);
562 /* loop until it's not a zombie connector */
563 } while (!kref_get_unless_zero(&iter->conn->base.refcount));
564 spin_unlock_irqrestore(&config->connector_list_lock, flags);
567 drm_connector_put(old_conn);
571 EXPORT_SYMBOL(drm_connector_list_iter_next);
574 * drm_connector_list_iter_end - tear down a connector_list iterator
575 * @iter: connector_list iterator
577 * Tears down @iter and releases any resources (like &drm_connector references)
578 * acquired while walking the list. This must always be called, both when the
579 * iteration completes fully or when it was aborted without walking the entire
582 void drm_connector_list_iter_end(struct drm_connector_list_iter *iter)
586 drm_connector_put(iter->conn);
587 lock_release(&connector_list_iter_dep_map, 0, _RET_IP_);
589 EXPORT_SYMBOL(drm_connector_list_iter_end);
591 static const struct drm_prop_enum_list drm_subpixel_enum_list[] = {
592 { SubPixelUnknown, "Unknown" },
593 { SubPixelHorizontalRGB, "Horizontal RGB" },
594 { SubPixelHorizontalBGR, "Horizontal BGR" },
595 { SubPixelVerticalRGB, "Vertical RGB" },
596 { SubPixelVerticalBGR, "Vertical BGR" },
597 { SubPixelNone, "None" },
601 * drm_get_subpixel_order_name - return a string for a given subpixel enum
602 * @order: enum of subpixel_order
604 * Note you could abuse this and return something out of bounds, but that
605 * would be a caller error. No unscrubbed user data should make it here.
607 const char *drm_get_subpixel_order_name(enum subpixel_order order)
609 return drm_subpixel_enum_list[order].name;
611 EXPORT_SYMBOL(drm_get_subpixel_order_name);
613 static const struct drm_prop_enum_list drm_dpms_enum_list[] = {
614 { DRM_MODE_DPMS_ON, "On" },
615 { DRM_MODE_DPMS_STANDBY, "Standby" },
616 { DRM_MODE_DPMS_SUSPEND, "Suspend" },
617 { DRM_MODE_DPMS_OFF, "Off" }
619 DRM_ENUM_NAME_FN(drm_get_dpms_name, drm_dpms_enum_list)
621 static const struct drm_prop_enum_list drm_link_status_enum_list[] = {
622 { DRM_MODE_LINK_STATUS_GOOD, "Good" },
623 { DRM_MODE_LINK_STATUS_BAD, "Bad" },
627 * drm_display_info_set_bus_formats - set the supported bus formats
628 * @info: display info to store bus formats in
629 * @formats: array containing the supported bus formats
630 * @num_formats: the number of entries in the fmts array
632 * Store the supported bus formats in display info structure.
633 * See MEDIA_BUS_FMT_* definitions in include/uapi/linux/media-bus-format.h for
634 * a full list of available formats.
636 int drm_display_info_set_bus_formats(struct drm_display_info *info,
638 unsigned int num_formats)
642 if (!formats && num_formats)
645 if (formats && num_formats) {
646 fmts = kmemdup(formats, sizeof(*formats) * num_formats,
652 kfree(info->bus_formats);
653 info->bus_formats = fmts;
654 info->num_bus_formats = num_formats;
658 EXPORT_SYMBOL(drm_display_info_set_bus_formats);
660 /* Optional connector properties. */
661 static const struct drm_prop_enum_list drm_scaling_mode_enum_list[] = {
662 { DRM_MODE_SCALE_NONE, "None" },
663 { DRM_MODE_SCALE_FULLSCREEN, "Full" },
664 { DRM_MODE_SCALE_CENTER, "Center" },
665 { DRM_MODE_SCALE_ASPECT, "Full aspect" },
668 static const struct drm_prop_enum_list drm_aspect_ratio_enum_list[] = {
669 { DRM_MODE_PICTURE_ASPECT_NONE, "Automatic" },
670 { DRM_MODE_PICTURE_ASPECT_4_3, "4:3" },
671 { DRM_MODE_PICTURE_ASPECT_16_9, "16:9" },
674 static const struct drm_prop_enum_list drm_panel_orientation_enum_list[] = {
675 { DRM_MODE_PANEL_ORIENTATION_NORMAL, "Normal" },
676 { DRM_MODE_PANEL_ORIENTATION_BOTTOM_UP, "Upside Down" },
677 { DRM_MODE_PANEL_ORIENTATION_LEFT_UP, "Left Side Up" },
678 { DRM_MODE_PANEL_ORIENTATION_RIGHT_UP, "Right Side Up" },
681 static const struct drm_prop_enum_list drm_dvi_i_select_enum_list[] = {
682 { DRM_MODE_SUBCONNECTOR_Automatic, "Automatic" }, /* DVI-I and TV-out */
683 { DRM_MODE_SUBCONNECTOR_DVID, "DVI-D" }, /* DVI-I */
684 { DRM_MODE_SUBCONNECTOR_DVIA, "DVI-A" }, /* DVI-I */
686 DRM_ENUM_NAME_FN(drm_get_dvi_i_select_name, drm_dvi_i_select_enum_list)
688 static const struct drm_prop_enum_list drm_dvi_i_subconnector_enum_list[] = {
689 { DRM_MODE_SUBCONNECTOR_Unknown, "Unknown" }, /* DVI-I and TV-out */
690 { DRM_MODE_SUBCONNECTOR_DVID, "DVI-D" }, /* DVI-I */
691 { DRM_MODE_SUBCONNECTOR_DVIA, "DVI-A" }, /* DVI-I */
693 DRM_ENUM_NAME_FN(drm_get_dvi_i_subconnector_name,
694 drm_dvi_i_subconnector_enum_list)
696 static const struct drm_prop_enum_list drm_tv_select_enum_list[] = {
697 { DRM_MODE_SUBCONNECTOR_Automatic, "Automatic" }, /* DVI-I and TV-out */
698 { DRM_MODE_SUBCONNECTOR_Composite, "Composite" }, /* TV-out */
699 { DRM_MODE_SUBCONNECTOR_SVIDEO, "SVIDEO" }, /* TV-out */
700 { DRM_MODE_SUBCONNECTOR_Component, "Component" }, /* TV-out */
701 { DRM_MODE_SUBCONNECTOR_SCART, "SCART" }, /* TV-out */
703 DRM_ENUM_NAME_FN(drm_get_tv_select_name, drm_tv_select_enum_list)
705 static const struct drm_prop_enum_list drm_tv_subconnector_enum_list[] = {
706 { DRM_MODE_SUBCONNECTOR_Unknown, "Unknown" }, /* DVI-I and TV-out */
707 { DRM_MODE_SUBCONNECTOR_Composite, "Composite" }, /* TV-out */
708 { DRM_MODE_SUBCONNECTOR_SVIDEO, "SVIDEO" }, /* TV-out */
709 { DRM_MODE_SUBCONNECTOR_Component, "Component" }, /* TV-out */
710 { DRM_MODE_SUBCONNECTOR_SCART, "SCART" }, /* TV-out */
712 DRM_ENUM_NAME_FN(drm_get_tv_subconnector_name,
713 drm_tv_subconnector_enum_list)
716 * DOC: standard connector properties
718 * DRM connectors have a few standardized properties:
721 * Blob property which contains the current EDID read from the sink. This
722 * is useful to parse sink identification information like vendor, model
723 * and serial. Drivers should update this property by calling
724 * drm_mode_connector_update_edid_property(), usually after having parsed
725 * the EDID using drm_add_edid_modes(). Userspace cannot change this
728 * Legacy property for setting the power state of the connector. For atomic
729 * drivers this is only provided for backwards compatibility with existing
730 * drivers, it remaps to controlling the "ACTIVE" property on the CRTC the
731 * connector is linked to. Drivers should never set this property directly,
732 * it is handled by the DRM core by calling the &drm_connector_funcs.dpms
733 * callback. For atomic drivers the remapping to the "ACTIVE" property is
734 * implemented in the DRM core. This is the only standard connector
735 * property that userspace can change.
737 * Note that this property cannot be set through the MODE_ATOMIC ioctl,
738 * userspace must use "ACTIVE" on the CRTC instead.
742 * For userspace also running on legacy drivers the "DPMS" semantics are a
743 * lot more complicated. First, userspace cannot rely on the "DPMS" value
744 * returned by the GETCONNECTOR actually reflecting reality, because many
745 * drivers fail to update it. For atomic drivers this is taken care of in
746 * drm_atomic_helper_update_legacy_modeset_state().
748 * The second issue is that the DPMS state is only well-defined when the
749 * connector is connected to a CRTC. In atomic the DRM core enforces that
750 * "ACTIVE" is off in such a case, no such checks exists for "DPMS".
752 * Finally, when enabling an output using the legacy SETCONFIG ioctl then
753 * "DPMS" is forced to ON. But see above, that might not be reflected in
754 * the software value on legacy drivers.
756 * Summarizing: Only set "DPMS" when the connector is known to be enabled,
757 * assume that a successful SETCONFIG call also sets "DPMS" to on, and
758 * never read back the value of "DPMS" because it can be incorrect.
760 * Connector path property to identify how this sink is physically
761 * connected. Used by DP MST. This should be set by calling
762 * drm_mode_connector_set_path_property(), in the case of DP MST with the
763 * path property the MST manager created. Userspace cannot change this
766 * Connector tile group property to indicate how a set of DRM connector
767 * compose together into one logical screen. This is used by both high-res
768 * external screens (often only using a single cable, but exposing multiple
769 * DP MST sinks), or high-res integrated panels (like dual-link DSI) which
770 * are not gen-locked. Note that for tiled panels which are genlocked, like
771 * dual-link LVDS or dual-link DSI, the driver should try to not expose the
772 * tiling and virtualize both &drm_crtc and &drm_plane if needed. Drivers
773 * should update this value using drm_mode_connector_set_tile_property().
774 * Userspace cannot change this property.
776 * Connector link-status property to indicate the status of link. The default
777 * value of link-status is "GOOD". If something fails during or after modeset,
778 * the kernel driver may set this to "BAD" and issue a hotplug uevent. Drivers
779 * should update this value using drm_mode_connector_set_link_status_property().
781 * Indicates the output should be ignored for purposes of displaying a
782 * standard desktop environment or console. This is most likely because
783 * the output device is not rectilinear.
785 * Connectors also have one standardized atomic property:
788 * Mode object ID of the &drm_crtc this connector should be connected to.
790 * Connectors for LCD panels may also have one standardized property:
793 * On some devices the LCD panel is mounted in the casing in such a way
794 * that the up/top side of the panel does not match with the top side of
795 * the device. Userspace can use this property to check for this.
796 * Note that input coordinates from touchscreens (input devices with
797 * INPUT_PROP_DIRECT) will still map 1:1 to the actual LCD panel
798 * coordinates, so if userspace rotates the picture to adjust for
799 * the orientation it must also apply the same transformation to the
800 * touchscreen input coordinates.
803 int drm_connector_create_standard_properties(struct drm_device *dev)
805 struct drm_property *prop;
807 prop = drm_property_create(dev, DRM_MODE_PROP_BLOB |
808 DRM_MODE_PROP_IMMUTABLE,
812 dev->mode_config.edid_property = prop;
814 prop = drm_property_create_enum(dev, 0,
815 "DPMS", drm_dpms_enum_list,
816 ARRAY_SIZE(drm_dpms_enum_list));
819 dev->mode_config.dpms_property = prop;
821 prop = drm_property_create(dev,
823 DRM_MODE_PROP_IMMUTABLE,
827 dev->mode_config.path_property = prop;
829 prop = drm_property_create(dev,
831 DRM_MODE_PROP_IMMUTABLE,
835 dev->mode_config.tile_property = prop;
837 prop = drm_property_create_enum(dev, 0, "link-status",
838 drm_link_status_enum_list,
839 ARRAY_SIZE(drm_link_status_enum_list));
842 dev->mode_config.link_status_property = prop;
844 prop = drm_property_create_bool(dev, DRM_MODE_PROP_IMMUTABLE, "non-desktop");
847 dev->mode_config.non_desktop_property = prop;
853 * drm_mode_create_dvi_i_properties - create DVI-I specific connector properties
856 * Called by a driver the first time a DVI-I connector is made.
858 int drm_mode_create_dvi_i_properties(struct drm_device *dev)
860 struct drm_property *dvi_i_selector;
861 struct drm_property *dvi_i_subconnector;
863 if (dev->mode_config.dvi_i_select_subconnector_property)
867 drm_property_create_enum(dev, 0,
868 "select subconnector",
869 drm_dvi_i_select_enum_list,
870 ARRAY_SIZE(drm_dvi_i_select_enum_list));
871 dev->mode_config.dvi_i_select_subconnector_property = dvi_i_selector;
873 dvi_i_subconnector = drm_property_create_enum(dev, DRM_MODE_PROP_IMMUTABLE,
875 drm_dvi_i_subconnector_enum_list,
876 ARRAY_SIZE(drm_dvi_i_subconnector_enum_list));
877 dev->mode_config.dvi_i_subconnector_property = dvi_i_subconnector;
881 EXPORT_SYMBOL(drm_mode_create_dvi_i_properties);
884 * drm_create_tv_properties - create TV specific connector properties
886 * @num_modes: number of different TV formats (modes) supported
887 * @modes: array of pointers to strings containing name of each format
889 * Called by a driver's TV initialization routine, this function creates
890 * the TV specific connector properties for a given device. Caller is
891 * responsible for allocating a list of format names and passing them to
894 int drm_mode_create_tv_properties(struct drm_device *dev,
895 unsigned int num_modes,
896 const char * const modes[])
898 struct drm_property *tv_selector;
899 struct drm_property *tv_subconnector;
902 if (dev->mode_config.tv_select_subconnector_property)
906 * Basic connector properties
908 tv_selector = drm_property_create_enum(dev, 0,
909 "select subconnector",
910 drm_tv_select_enum_list,
911 ARRAY_SIZE(drm_tv_select_enum_list));
915 dev->mode_config.tv_select_subconnector_property = tv_selector;
918 drm_property_create_enum(dev, DRM_MODE_PROP_IMMUTABLE,
920 drm_tv_subconnector_enum_list,
921 ARRAY_SIZE(drm_tv_subconnector_enum_list));
922 if (!tv_subconnector)
924 dev->mode_config.tv_subconnector_property = tv_subconnector;
927 * Other, TV specific properties: margins & TV modes.
929 dev->mode_config.tv_left_margin_property =
930 drm_property_create_range(dev, 0, "left margin", 0, 100);
931 if (!dev->mode_config.tv_left_margin_property)
934 dev->mode_config.tv_right_margin_property =
935 drm_property_create_range(dev, 0, "right margin", 0, 100);
936 if (!dev->mode_config.tv_right_margin_property)
939 dev->mode_config.tv_top_margin_property =
940 drm_property_create_range(dev, 0, "top margin", 0, 100);
941 if (!dev->mode_config.tv_top_margin_property)
944 dev->mode_config.tv_bottom_margin_property =
945 drm_property_create_range(dev, 0, "bottom margin", 0, 100);
946 if (!dev->mode_config.tv_bottom_margin_property)
949 dev->mode_config.tv_mode_property =
950 drm_property_create(dev, DRM_MODE_PROP_ENUM,
952 if (!dev->mode_config.tv_mode_property)
955 for (i = 0; i < num_modes; i++)
956 drm_property_add_enum(dev->mode_config.tv_mode_property, i,
959 dev->mode_config.tv_brightness_property =
960 drm_property_create_range(dev, 0, "brightness", 0, 100);
961 if (!dev->mode_config.tv_brightness_property)
964 dev->mode_config.tv_contrast_property =
965 drm_property_create_range(dev, 0, "contrast", 0, 100);
966 if (!dev->mode_config.tv_contrast_property)
969 dev->mode_config.tv_flicker_reduction_property =
970 drm_property_create_range(dev, 0, "flicker reduction", 0, 100);
971 if (!dev->mode_config.tv_flicker_reduction_property)
974 dev->mode_config.tv_overscan_property =
975 drm_property_create_range(dev, 0, "overscan", 0, 100);
976 if (!dev->mode_config.tv_overscan_property)
979 dev->mode_config.tv_saturation_property =
980 drm_property_create_range(dev, 0, "saturation", 0, 100);
981 if (!dev->mode_config.tv_saturation_property)
984 dev->mode_config.tv_hue_property =
985 drm_property_create_range(dev, 0, "hue", 0, 100);
986 if (!dev->mode_config.tv_hue_property)
993 EXPORT_SYMBOL(drm_mode_create_tv_properties);
996 * drm_mode_create_scaling_mode_property - create scaling mode property
999 * Called by a driver the first time it's needed, must be attached to desired
1002 * Atomic drivers should use drm_connector_attach_scaling_mode_property()
1003 * instead to correctly assign &drm_connector_state.picture_aspect_ratio
1004 * in the atomic state.
1006 int drm_mode_create_scaling_mode_property(struct drm_device *dev)
1008 struct drm_property *scaling_mode;
1010 if (dev->mode_config.scaling_mode_property)
1014 drm_property_create_enum(dev, 0, "scaling mode",
1015 drm_scaling_mode_enum_list,
1016 ARRAY_SIZE(drm_scaling_mode_enum_list));
1018 dev->mode_config.scaling_mode_property = scaling_mode;
1022 EXPORT_SYMBOL(drm_mode_create_scaling_mode_property);
1025 * drm_connector_attach_scaling_mode_property - attach atomic scaling mode property
1026 * @connector: connector to attach scaling mode property on.
1027 * @scaling_mode_mask: or'ed mask of BIT(%DRM_MODE_SCALE_\*).
1029 * This is used to add support for scaling mode to atomic drivers.
1030 * The scaling mode will be set to &drm_connector_state.picture_aspect_ratio
1031 * and can be used from &drm_connector_helper_funcs->atomic_check for validation.
1033 * This is the atomic version of drm_mode_create_scaling_mode_property().
1036 * Zero on success, negative errno on failure.
1038 int drm_connector_attach_scaling_mode_property(struct drm_connector *connector,
1039 u32 scaling_mode_mask)
1041 struct drm_device *dev = connector->dev;
1042 struct drm_property *scaling_mode_property;
1044 const unsigned valid_scaling_mode_mask =
1045 (1U << ARRAY_SIZE(drm_scaling_mode_enum_list)) - 1;
1047 if (WARN_ON(hweight32(scaling_mode_mask) < 2 ||
1048 scaling_mode_mask & ~valid_scaling_mode_mask))
1051 scaling_mode_property =
1052 drm_property_create(dev, DRM_MODE_PROP_ENUM, "scaling mode",
1053 hweight32(scaling_mode_mask));
1055 if (!scaling_mode_property)
1058 for (i = 0; i < ARRAY_SIZE(drm_scaling_mode_enum_list); i++) {
1061 if (!(BIT(i) & scaling_mode_mask))
1064 ret = drm_property_add_enum(scaling_mode_property, j++,
1065 drm_scaling_mode_enum_list[i].type,
1066 drm_scaling_mode_enum_list[i].name);
1069 drm_property_destroy(dev, scaling_mode_property);
1075 drm_object_attach_property(&connector->base,
1076 scaling_mode_property, 0);
1078 connector->scaling_mode_property = scaling_mode_property;
1082 EXPORT_SYMBOL(drm_connector_attach_scaling_mode_property);
1085 * drm_mode_create_aspect_ratio_property - create aspect ratio property
1088 * Called by a driver the first time it's needed, must be attached to desired
1092 * Zero on success, negative errno on failure.
1094 int drm_mode_create_aspect_ratio_property(struct drm_device *dev)
1096 if (dev->mode_config.aspect_ratio_property)
1099 dev->mode_config.aspect_ratio_property =
1100 drm_property_create_enum(dev, 0, "aspect ratio",
1101 drm_aspect_ratio_enum_list,
1102 ARRAY_SIZE(drm_aspect_ratio_enum_list));
1104 if (dev->mode_config.aspect_ratio_property == NULL)
1109 EXPORT_SYMBOL(drm_mode_create_aspect_ratio_property);
1112 * drm_mode_create_suggested_offset_properties - create suggests offset properties
1115 * Create the the suggested x/y offset property for connectors.
1117 int drm_mode_create_suggested_offset_properties(struct drm_device *dev)
1119 if (dev->mode_config.suggested_x_property && dev->mode_config.suggested_y_property)
1122 dev->mode_config.suggested_x_property =
1123 drm_property_create_range(dev, DRM_MODE_PROP_IMMUTABLE, "suggested X", 0, 0xffffffff);
1125 dev->mode_config.suggested_y_property =
1126 drm_property_create_range(dev, DRM_MODE_PROP_IMMUTABLE, "suggested Y", 0, 0xffffffff);
1128 if (dev->mode_config.suggested_x_property == NULL ||
1129 dev->mode_config.suggested_y_property == NULL)
1133 EXPORT_SYMBOL(drm_mode_create_suggested_offset_properties);
1136 * drm_mode_connector_set_path_property - set tile property on connector
1137 * @connector: connector to set property on.
1138 * @path: path to use for property; must not be NULL.
1140 * This creates a property to expose to userspace to specify a
1141 * connector path. This is mainly used for DisplayPort MST where
1142 * connectors have a topology and we want to allow userspace to give
1143 * them more meaningful names.
1146 * Zero on success, negative errno on failure.
1148 int drm_mode_connector_set_path_property(struct drm_connector *connector,
1151 struct drm_device *dev = connector->dev;
1154 ret = drm_property_replace_global_blob(dev,
1155 &connector->path_blob_ptr,
1159 dev->mode_config.path_property);
1162 EXPORT_SYMBOL(drm_mode_connector_set_path_property);
1165 * drm_mode_connector_set_tile_property - set tile property on connector
1166 * @connector: connector to set property on.
1168 * This looks up the tile information for a connector, and creates a
1169 * property for userspace to parse if it exists. The property is of
1170 * the form of 8 integers using ':' as a separator.
1173 * Zero on success, errno on failure.
1175 int drm_mode_connector_set_tile_property(struct drm_connector *connector)
1177 struct drm_device *dev = connector->dev;
1181 if (!connector->has_tile) {
1182 ret = drm_property_replace_global_blob(dev,
1183 &connector->tile_blob_ptr,
1187 dev->mode_config.tile_property);
1191 snprintf(tile, 256, "%d:%d:%d:%d:%d:%d:%d:%d",
1192 connector->tile_group->id, connector->tile_is_single_monitor,
1193 connector->num_h_tile, connector->num_v_tile,
1194 connector->tile_h_loc, connector->tile_v_loc,
1195 connector->tile_h_size, connector->tile_v_size);
1197 ret = drm_property_replace_global_blob(dev,
1198 &connector->tile_blob_ptr,
1202 dev->mode_config.tile_property);
1205 EXPORT_SYMBOL(drm_mode_connector_set_tile_property);
1208 * drm_mode_connector_update_edid_property - update the edid property of a connector
1209 * @connector: drm connector
1210 * @edid: new value of the edid property
1212 * This function creates a new blob modeset object and assigns its id to the
1213 * connector's edid property.
1216 * Zero on success, negative errno on failure.
1218 int drm_mode_connector_update_edid_property(struct drm_connector *connector,
1219 const struct edid *edid)
1221 struct drm_device *dev = connector->dev;
1225 /* ignore requests to set edid when overridden */
1226 if (connector->override_edid)
1230 size = EDID_LENGTH * (1 + edid->extensions);
1232 drm_object_property_set_value(&connector->base,
1233 dev->mode_config.non_desktop_property,
1234 connector->display_info.non_desktop);
1236 ret = drm_property_replace_global_blob(dev,
1237 &connector->edid_blob_ptr,
1241 dev->mode_config.edid_property);
1244 EXPORT_SYMBOL(drm_mode_connector_update_edid_property);
1247 * drm_mode_connector_set_link_status_property - Set link status property of a connector
1248 * @connector: drm connector
1249 * @link_status: new value of link status property (0: Good, 1: Bad)
1251 * In usual working scenario, this link status property will always be set to
1252 * "GOOD". If something fails during or after a mode set, the kernel driver
1253 * may set this link status property to "BAD". The caller then needs to send a
1254 * hotplug uevent for userspace to re-check the valid modes through
1255 * GET_CONNECTOR_IOCTL and retry modeset.
1257 * Note: Drivers cannot rely on userspace to support this property and
1258 * issue a modeset. As such, they may choose to handle issues (like
1259 * re-training a link) without userspace's intervention.
1261 * The reason for adding this property is to handle link training failures, but
1262 * it is not limited to DP or link training. For example, if we implement
1263 * asynchronous setcrtc, this property can be used to report any failures in that.
1265 void drm_mode_connector_set_link_status_property(struct drm_connector *connector,
1266 uint64_t link_status)
1268 struct drm_device *dev = connector->dev;
1270 drm_modeset_lock(&dev->mode_config.connection_mutex, NULL);
1271 connector->state->link_status = link_status;
1272 drm_modeset_unlock(&dev->mode_config.connection_mutex);
1274 EXPORT_SYMBOL(drm_mode_connector_set_link_status_property);
1277 * drm_connector_init_panel_orientation_property -
1278 * initialize the connecters panel_orientation property
1279 * @connector: connector for which to init the panel-orientation property.
1280 * @width: width in pixels of the panel, used for panel quirk detection
1281 * @height: height in pixels of the panel, used for panel quirk detection
1283 * This function should only be called for built-in panels, after setting
1284 * connector->display_info.panel_orientation first (if known).
1286 * This function will check for platform specific (e.g. DMI based) quirks
1287 * overriding display_info.panel_orientation first, then if panel_orientation
1288 * is not DRM_MODE_PANEL_ORIENTATION_UNKNOWN it will attach the
1289 * "panel orientation" property to the connector.
1292 * Zero on success, negative errno on failure.
1294 int drm_connector_init_panel_orientation_property(
1295 struct drm_connector *connector, int width, int height)
1297 struct drm_device *dev = connector->dev;
1298 struct drm_display_info *info = &connector->display_info;
1299 struct drm_property *prop;
1300 int orientation_quirk;
1302 orientation_quirk = drm_get_panel_orientation_quirk(width, height);
1303 if (orientation_quirk != DRM_MODE_PANEL_ORIENTATION_UNKNOWN)
1304 info->panel_orientation = orientation_quirk;
1306 if (info->panel_orientation == DRM_MODE_PANEL_ORIENTATION_UNKNOWN)
1309 prop = dev->mode_config.panel_orientation_property;
1311 prop = drm_property_create_enum(dev, DRM_MODE_PROP_IMMUTABLE,
1312 "panel orientation",
1313 drm_panel_orientation_enum_list,
1314 ARRAY_SIZE(drm_panel_orientation_enum_list));
1318 dev->mode_config.panel_orientation_property = prop;
1321 drm_object_attach_property(&connector->base, prop,
1322 info->panel_orientation);
1325 EXPORT_SYMBOL(drm_connector_init_panel_orientation_property);
1327 int drm_mode_connector_set_obj_prop(struct drm_mode_object *obj,
1328 struct drm_property *property,
1332 struct drm_connector *connector = obj_to_connector(obj);
1334 /* Do DPMS ourselves */
1335 if (property == connector->dev->mode_config.dpms_property) {
1336 ret = (*connector->funcs->dpms)(connector, (int)value);
1337 } else if (connector->funcs->set_property)
1338 ret = connector->funcs->set_property(connector, property, value);
1341 drm_object_property_set_value(&connector->base, property, value);
1345 int drm_mode_connector_property_set_ioctl(struct drm_device *dev,
1346 void *data, struct drm_file *file_priv)
1348 struct drm_mode_connector_set_property *conn_set_prop = data;
1349 struct drm_mode_obj_set_property obj_set_prop = {
1350 .value = conn_set_prop->value,
1351 .prop_id = conn_set_prop->prop_id,
1352 .obj_id = conn_set_prop->connector_id,
1353 .obj_type = DRM_MODE_OBJECT_CONNECTOR
1356 /* It does all the locking and checking we need */
1357 return drm_mode_obj_set_property_ioctl(dev, &obj_set_prop, file_priv);
1360 static struct drm_encoder *drm_connector_get_encoder(struct drm_connector *connector)
1362 /* For atomic drivers only state objects are synchronously updated and
1363 * protected by modeset locks, so check those first. */
1364 if (connector->state)
1365 return connector->state->best_encoder;
1366 return connector->encoder;
1369 static bool drm_mode_expose_to_userspace(const struct drm_display_mode *mode,
1370 const struct drm_file *file_priv)
1373 * If user-space hasn't configured the driver to expose the stereo 3D
1374 * modes, don't expose them.
1376 if (!file_priv->stereo_allowed && drm_mode_is_stereo(mode))
1382 int drm_mode_getconnector(struct drm_device *dev, void *data,
1383 struct drm_file *file_priv)
1385 struct drm_mode_get_connector *out_resp = data;
1386 struct drm_connector *connector;
1387 struct drm_encoder *encoder;
1388 struct drm_display_mode *mode;
1390 int encoders_count = 0;
1394 struct drm_mode_modeinfo u_mode;
1395 struct drm_mode_modeinfo __user *mode_ptr;
1396 uint32_t __user *encoder_ptr;
1398 if (!drm_core_check_feature(dev, DRIVER_MODESET))
1401 memset(&u_mode, 0, sizeof(struct drm_mode_modeinfo));
1403 connector = drm_connector_lookup(dev, file_priv, out_resp->connector_id);
1407 for (i = 0; i < DRM_CONNECTOR_MAX_ENCODER; i++)
1408 if (connector->encoder_ids[i] != 0)
1411 if ((out_resp->count_encoders >= encoders_count) && encoders_count) {
1413 encoder_ptr = (uint32_t __user *)(unsigned long)(out_resp->encoders_ptr);
1414 for (i = 0; i < DRM_CONNECTOR_MAX_ENCODER; i++) {
1415 if (connector->encoder_ids[i] != 0) {
1416 if (put_user(connector->encoder_ids[i],
1417 encoder_ptr + copied)) {
1425 out_resp->count_encoders = encoders_count;
1427 out_resp->connector_id = connector->base.id;
1428 out_resp->connector_type = connector->connector_type;
1429 out_resp->connector_type_id = connector->connector_type_id;
1431 mutex_lock(&dev->mode_config.mutex);
1432 if (out_resp->count_modes == 0) {
1433 connector->funcs->fill_modes(connector,
1434 dev->mode_config.max_width,
1435 dev->mode_config.max_height);
1438 out_resp->mm_width = connector->display_info.width_mm;
1439 out_resp->mm_height = connector->display_info.height_mm;
1440 out_resp->subpixel = connector->display_info.subpixel_order;
1441 out_resp->connection = connector->status;
1443 /* delayed so we get modes regardless of pre-fill_modes state */
1444 list_for_each_entry(mode, &connector->modes, head)
1445 if (drm_mode_expose_to_userspace(mode, file_priv))
1449 * This ioctl is called twice, once to determine how much space is
1450 * needed, and the 2nd time to fill it.
1452 if ((out_resp->count_modes >= mode_count) && mode_count) {
1454 mode_ptr = (struct drm_mode_modeinfo __user *)(unsigned long)out_resp->modes_ptr;
1455 list_for_each_entry(mode, &connector->modes, head) {
1456 if (!drm_mode_expose_to_userspace(mode, file_priv))
1459 drm_mode_convert_to_umode(&u_mode, mode);
1460 if (copy_to_user(mode_ptr + copied,
1461 &u_mode, sizeof(u_mode))) {
1463 mutex_unlock(&dev->mode_config.mutex);
1470 out_resp->count_modes = mode_count;
1471 mutex_unlock(&dev->mode_config.mutex);
1473 drm_modeset_lock(&dev->mode_config.connection_mutex, NULL);
1474 encoder = drm_connector_get_encoder(connector);
1476 out_resp->encoder_id = encoder->base.id;
1478 out_resp->encoder_id = 0;
1480 /* Only grab properties after probing, to make sure EDID and other
1481 * properties reflect the latest status. */
1482 ret = drm_mode_object_get_properties(&connector->base, file_priv->atomic,
1483 (uint32_t __user *)(unsigned long)(out_resp->props_ptr),
1484 (uint64_t __user *)(unsigned long)(out_resp->prop_values_ptr),
1485 &out_resp->count_props);
1486 drm_modeset_unlock(&dev->mode_config.connection_mutex);
1489 drm_connector_put(connector);
1498 * Tile groups are used to represent tiled monitors with a unique integer
1499 * identifier. Tiled monitors using DisplayID v1.3 have a unique 8-byte handle,
1500 * we store this in a tile group, so we have a common identifier for all tiles
1501 * in a monitor group. The property is called "TILE". Drivers can manage tile
1502 * groups using drm_mode_create_tile_group(), drm_mode_put_tile_group() and
1503 * drm_mode_get_tile_group(). But this is only needed for internal panels where
1504 * the tile group information is exposed through a non-standard way.
1507 static void drm_tile_group_free(struct kref *kref)
1509 struct drm_tile_group *tg = container_of(kref, struct drm_tile_group, refcount);
1510 struct drm_device *dev = tg->dev;
1511 mutex_lock(&dev->mode_config.idr_mutex);
1512 idr_remove(&dev->mode_config.tile_idr, tg->id);
1513 mutex_unlock(&dev->mode_config.idr_mutex);
1518 * drm_mode_put_tile_group - drop a reference to a tile group.
1520 * @tg: tile group to drop reference to.
1522 * drop reference to tile group and free if 0.
1524 void drm_mode_put_tile_group(struct drm_device *dev,
1525 struct drm_tile_group *tg)
1527 kref_put(&tg->refcount, drm_tile_group_free);
1529 EXPORT_SYMBOL(drm_mode_put_tile_group);
1532 * drm_mode_get_tile_group - get a reference to an existing tile group
1534 * @topology: 8-bytes unique per monitor.
1536 * Use the unique bytes to get a reference to an existing tile group.
1539 * tile group or NULL if not found.
1541 struct drm_tile_group *drm_mode_get_tile_group(struct drm_device *dev,
1544 struct drm_tile_group *tg;
1546 mutex_lock(&dev->mode_config.idr_mutex);
1547 idr_for_each_entry(&dev->mode_config.tile_idr, tg, id) {
1548 if (!memcmp(tg->group_data, topology, 8)) {
1549 if (!kref_get_unless_zero(&tg->refcount))
1551 mutex_unlock(&dev->mode_config.idr_mutex);
1555 mutex_unlock(&dev->mode_config.idr_mutex);
1558 EXPORT_SYMBOL(drm_mode_get_tile_group);
1561 * drm_mode_create_tile_group - create a tile group from a displayid description
1563 * @topology: 8-bytes unique per monitor.
1565 * Create a tile group for the unique monitor, and get a unique
1566 * identifier for the tile group.
1569 * new tile group or error.
1571 struct drm_tile_group *drm_mode_create_tile_group(struct drm_device *dev,
1574 struct drm_tile_group *tg;
1577 tg = kzalloc(sizeof(*tg), GFP_KERNEL);
1579 return ERR_PTR(-ENOMEM);
1581 kref_init(&tg->refcount);
1582 memcpy(tg->group_data, topology, 8);
1585 mutex_lock(&dev->mode_config.idr_mutex);
1586 ret = idr_alloc(&dev->mode_config.tile_idr, tg, 1, 0, GFP_KERNEL);
1594 mutex_unlock(&dev->mode_config.idr_mutex);
1597 EXPORT_SYMBOL(drm_mode_create_tile_group);