Home | History | Annotate | Line # | Download | only in drm
      1  1.7  riastrad /*	$NetBSD: drm_connector.c,v 1.7 2021/12/19 12:32:01 riastradh Exp $	*/
      2  1.1  riastrad 
      3  1.1  riastrad /*
      4  1.1  riastrad  * Copyright (c) 2016 Intel Corporation
      5  1.1  riastrad  *
      6  1.1  riastrad  * Permission to use, copy, modify, distribute, and sell this software and its
      7  1.1  riastrad  * documentation for any purpose is hereby granted without fee, provided that
      8  1.1  riastrad  * the above copyright notice appear in all copies and that both that copyright
      9  1.1  riastrad  * notice and this permission notice appear in supporting documentation, and
     10  1.1  riastrad  * that the name of the copyright holders not be used in advertising or
     11  1.1  riastrad  * publicity pertaining to distribution of the software without specific,
     12  1.1  riastrad  * written prior permission.  The copyright holders make no representations
     13  1.1  riastrad  * about the suitability of this software for any purpose.  It is provided "as
     14  1.1  riastrad  * is" without express or implied warranty.
     15  1.1  riastrad  *
     16  1.1  riastrad  * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
     17  1.1  riastrad  * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
     18  1.1  riastrad  * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
     19  1.1  riastrad  * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
     20  1.1  riastrad  * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
     21  1.1  riastrad  * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
     22  1.1  riastrad  * OF THIS SOFTWARE.
     23  1.1  riastrad  */
     24  1.1  riastrad 
     25  1.1  riastrad #include <sys/cdefs.h>
     26  1.7  riastrad __KERNEL_RCSID(0, "$NetBSD: drm_connector.c,v 1.7 2021/12/19 12:32:01 riastradh Exp $");
     27  1.1  riastrad 
     28  1.1  riastrad #include <drm/drm_connector.h>
     29  1.1  riastrad #include <drm/drm_edid.h>
     30  1.1  riastrad #include <drm/drm_encoder.h>
     31  1.1  riastrad #include <drm/drm_utils.h>
     32  1.1  riastrad #include <drm/drm_print.h>
     33  1.1  riastrad #include <drm/drm_drv.h>
     34  1.1  riastrad #include <drm/drm_file.h>
     35  1.1  riastrad 
     36  1.1  riastrad #include <linux/uaccess.h>
     37  1.1  riastrad 
     38  1.1  riastrad #include "drm_crtc_internal.h"
     39  1.1  riastrad #include "drm_internal.h"
     40  1.1  riastrad 
     41  1.7  riastrad #include <linux/nbsd-namespace.h>
     42  1.7  riastrad 
     43  1.1  riastrad /**
     44  1.1  riastrad  * DOC: overview
     45  1.1  riastrad  *
     46  1.1  riastrad  * In DRM connectors are the general abstraction for display sinks, and include
     47  1.1  riastrad  * als fixed panels or anything else that can display pixels in some form. As
     48  1.1  riastrad  * opposed to all other KMS objects representing hardware (like CRTC, encoder or
     49  1.1  riastrad  * plane abstractions) connectors can be hotplugged and unplugged at runtime.
     50  1.1  riastrad  * Hence they are reference-counted using drm_connector_get() and
     51  1.1  riastrad  * drm_connector_put().
     52  1.1  riastrad  *
     53  1.1  riastrad  * KMS driver must create, initialize, register and attach at a &struct
     54  1.1  riastrad  * drm_connector for each such sink. The instance is created as other KMS
     55  1.1  riastrad  * objects and initialized by setting the following fields. The connector is
     56  1.1  riastrad  * initialized with a call to drm_connector_init() with a pointer to the
     57  1.1  riastrad  * &struct drm_connector_funcs and a connector type, and then exposed to
     58  1.1  riastrad  * userspace with a call to drm_connector_register().
     59  1.1  riastrad  *
     60  1.1  riastrad  * Connectors must be attached to an encoder to be used. For devices that map
     61  1.1  riastrad  * connectors to encoders 1:1, the connector should be attached at
     62  1.1  riastrad  * initialization time with a call to drm_connector_attach_encoder(). The
     63  1.1  riastrad  * driver must also set the &drm_connector.encoder field to point to the
     64  1.1  riastrad  * attached encoder.
     65  1.1  riastrad  *
     66  1.1  riastrad  * For connectors which are not fixed (like built-in panels) the driver needs to
     67  1.1  riastrad  * support hotplug notifications. The simplest way to do that is by using the
     68  1.1  riastrad  * probe helpers, see drm_kms_helper_poll_init() for connectors which don't have
     69  1.1  riastrad  * hardware support for hotplug interrupts. Connectors with hardware hotplug
     70  1.1  riastrad  * support can instead use e.g. drm_helper_hpd_irq_event().
     71  1.1  riastrad  */
     72  1.1  riastrad 
     73  1.1  riastrad struct drm_conn_prop_enum_list {
     74  1.1  riastrad 	int type;
     75  1.1  riastrad 	const char *name;
     76  1.1  riastrad 	struct ida ida;
     77  1.1  riastrad };
     78  1.1  riastrad 
     79  1.1  riastrad /*
     80  1.1  riastrad  * Connector and encoder types.
     81  1.1  riastrad  */
     82  1.1  riastrad static struct drm_conn_prop_enum_list drm_connector_enum_list[] = {
     83  1.1  riastrad 	{ DRM_MODE_CONNECTOR_Unknown, "Unknown" },
     84  1.1  riastrad 	{ DRM_MODE_CONNECTOR_VGA, "VGA" },
     85  1.1  riastrad 	{ DRM_MODE_CONNECTOR_DVII, "DVI-I" },
     86  1.1  riastrad 	{ DRM_MODE_CONNECTOR_DVID, "DVI-D" },
     87  1.1  riastrad 	{ DRM_MODE_CONNECTOR_DVIA, "DVI-A" },
     88  1.1  riastrad 	{ DRM_MODE_CONNECTOR_Composite, "Composite" },
     89  1.1  riastrad 	{ DRM_MODE_CONNECTOR_SVIDEO, "SVIDEO" },
     90  1.1  riastrad 	{ DRM_MODE_CONNECTOR_LVDS, "LVDS" },
     91  1.1  riastrad 	{ DRM_MODE_CONNECTOR_Component, "Component" },
     92  1.1  riastrad 	{ DRM_MODE_CONNECTOR_9PinDIN, "DIN" },
     93  1.1  riastrad 	{ DRM_MODE_CONNECTOR_DisplayPort, "DP" },
     94  1.1  riastrad 	{ DRM_MODE_CONNECTOR_HDMIA, "HDMI-A" },
     95  1.1  riastrad 	{ DRM_MODE_CONNECTOR_HDMIB, "HDMI-B" },
     96  1.1  riastrad 	{ DRM_MODE_CONNECTOR_TV, "TV" },
     97  1.1  riastrad 	{ DRM_MODE_CONNECTOR_eDP, "eDP" },
     98  1.1  riastrad 	{ DRM_MODE_CONNECTOR_VIRTUAL, "Virtual" },
     99  1.1  riastrad 	{ DRM_MODE_CONNECTOR_DSI, "DSI" },
    100  1.1  riastrad 	{ DRM_MODE_CONNECTOR_DPI, "DPI" },
    101  1.1  riastrad 	{ DRM_MODE_CONNECTOR_WRITEBACK, "Writeback" },
    102  1.1  riastrad 	{ DRM_MODE_CONNECTOR_SPI, "SPI" },
    103  1.1  riastrad };
    104  1.1  riastrad 
    105  1.1  riastrad void drm_connector_ida_init(void)
    106  1.1  riastrad {
    107  1.1  riastrad 	int i;
    108  1.1  riastrad 
    109  1.1  riastrad 	for (i = 0; i < ARRAY_SIZE(drm_connector_enum_list); i++)
    110  1.1  riastrad 		ida_init(&drm_connector_enum_list[i].ida);
    111  1.1  riastrad }
    112  1.1  riastrad 
    113  1.1  riastrad void drm_connector_ida_destroy(void)
    114  1.1  riastrad {
    115  1.1  riastrad 	int i;
    116  1.1  riastrad 
    117  1.1  riastrad 	for (i = 0; i < ARRAY_SIZE(drm_connector_enum_list); i++)
    118  1.1  riastrad 		ida_destroy(&drm_connector_enum_list[i].ida);
    119  1.1  riastrad }
    120  1.1  riastrad 
    121  1.1  riastrad /**
    122  1.1  riastrad  * drm_connector_get_cmdline_mode - reads the user's cmdline mode
    123  1.1  riastrad  * @connector: connector to quwery
    124  1.1  riastrad  *
    125  1.1  riastrad  * The kernel supports per-connector configuration of its consoles through
    126  1.1  riastrad  * use of the video= parameter. This function parses that option and
    127  1.1  riastrad  * extracts the user's specified mode (or enable/disable status) for a
    128  1.1  riastrad  * particular connector. This is typically only used during the early fbdev
    129  1.1  riastrad  * setup.
    130  1.1  riastrad  */
    131  1.1  riastrad static void drm_connector_get_cmdline_mode(struct drm_connector *connector)
    132  1.1  riastrad {
    133  1.1  riastrad 	struct drm_cmdline_mode *mode = &connector->cmdline_mode;
    134  1.2  riastrad #ifdef __NetBSD__
    135  1.2  riastrad 	const char *option;
    136  1.2  riastrad 	prop_dictionary_t prop = device_properties(connector->dev->dev);
    137  1.2  riastrad 	if (!prop_dictionary_get_string(prop, connector->name, &option))
    138  1.2  riastrad 		return;
    139  1.2  riastrad #else
    140  1.1  riastrad 	char *option = NULL;
    141  1.1  riastrad 
    142  1.1  riastrad 	if (fb_get_options(connector->name, &option))
    143  1.1  riastrad 		return;
    144  1.2  riastrad #endif
    145  1.1  riastrad 
    146  1.1  riastrad 	if (!drm_mode_parse_command_line_for_connector(option,
    147  1.1  riastrad 						       connector,
    148  1.1  riastrad 						       mode))
    149  1.1  riastrad 		return;
    150  1.1  riastrad 
    151  1.1  riastrad 	if (mode->force) {
    152  1.1  riastrad 		DRM_INFO("forcing %s connector %s\n", connector->name,
    153  1.1  riastrad 			 drm_get_connector_force_name(mode->force));
    154  1.1  riastrad 		connector->force = mode->force;
    155  1.1  riastrad 	}
    156  1.1  riastrad 
    157  1.1  riastrad 	DRM_DEBUG_KMS("cmdline mode for connector %s %s %dx%d@%dHz%s%s%s\n",
    158  1.1  riastrad 		      connector->name, mode->name,
    159  1.1  riastrad 		      mode->xres, mode->yres,
    160  1.1  riastrad 		      mode->refresh_specified ? mode->refresh : 60,
    161  1.1  riastrad 		      mode->rb ? " reduced blanking" : "",
    162  1.1  riastrad 		      mode->margins ? " with margins" : "",
    163  1.1  riastrad 		      mode->interlace ?  " interlaced" : "");
    164  1.1  riastrad }
    165  1.1  riastrad 
    166  1.1  riastrad static void drm_connector_free(struct kref *kref)
    167  1.1  riastrad {
    168  1.1  riastrad 	struct drm_connector *connector =
    169  1.1  riastrad 		container_of(kref, struct drm_connector, base.refcount);
    170  1.1  riastrad 	struct drm_device *dev = connector->dev;
    171  1.1  riastrad 
    172  1.1  riastrad 	drm_mode_object_unregister(dev, &connector->base);
    173  1.1  riastrad 	connector->funcs->destroy(connector);
    174  1.1  riastrad }
    175  1.1  riastrad 
    176  1.1  riastrad void drm_connector_free_work_fn(struct work_struct *work)
    177  1.1  riastrad {
    178  1.1  riastrad 	struct drm_connector *connector, *n;
    179  1.1  riastrad 	struct drm_device *dev =
    180  1.1  riastrad 		container_of(work, struct drm_device, mode_config.connector_free_work);
    181  1.1  riastrad 	struct drm_mode_config *config = &dev->mode_config;
    182  1.1  riastrad 	unsigned long flags;
    183  1.1  riastrad 	struct llist_node *freed;
    184  1.1  riastrad 
    185  1.1  riastrad 	spin_lock_irqsave(&config->connector_list_lock, flags);
    186  1.1  riastrad 	freed = llist_del_all(&config->connector_free_list);
    187  1.1  riastrad 	spin_unlock_irqrestore(&config->connector_list_lock, flags);
    188  1.1  riastrad 
    189  1.1  riastrad 	llist_for_each_entry_safe(connector, n, freed, free_node) {
    190  1.1  riastrad 		drm_mode_object_unregister(dev, &connector->base);
    191  1.1  riastrad 		connector->funcs->destroy(connector);
    192  1.1  riastrad 	}
    193  1.1  riastrad }
    194  1.1  riastrad 
    195  1.1  riastrad /**
    196  1.1  riastrad  * drm_connector_init - Init a preallocated connector
    197  1.1  riastrad  * @dev: DRM device
    198  1.1  riastrad  * @connector: the connector to init
    199  1.1  riastrad  * @funcs: callbacks for this connector
    200  1.1  riastrad  * @connector_type: user visible type of the connector
    201  1.1  riastrad  *
    202  1.1  riastrad  * Initialises a preallocated connector. Connectors should be
    203  1.1  riastrad  * subclassed as part of driver connector objects.
    204  1.1  riastrad  *
    205  1.1  riastrad  * Returns:
    206  1.1  riastrad  * Zero on success, error code on failure.
    207  1.1  riastrad  */
    208  1.1  riastrad int drm_connector_init(struct drm_device *dev,
    209  1.1  riastrad 		       struct drm_connector *connector,
    210  1.1  riastrad 		       const struct drm_connector_funcs *funcs,
    211  1.1  riastrad 		       int connector_type)
    212  1.1  riastrad {
    213  1.1  riastrad 	struct drm_mode_config *config = &dev->mode_config;
    214  1.1  riastrad 	int ret;
    215  1.1  riastrad 	struct ida *connector_ida =
    216  1.1  riastrad 		&drm_connector_enum_list[connector_type].ida;
    217  1.1  riastrad 
    218  1.1  riastrad 	WARN_ON(drm_drv_uses_atomic_modeset(dev) &&
    219  1.1  riastrad 		(!funcs->atomic_destroy_state ||
    220  1.1  riastrad 		 !funcs->atomic_duplicate_state));
    221  1.1  riastrad 
    222  1.1  riastrad 	ret = __drm_mode_object_add(dev, &connector->base,
    223  1.1  riastrad 				    DRM_MODE_OBJECT_CONNECTOR,
    224  1.1  riastrad 				    false, drm_connector_free);
    225  1.1  riastrad 	if (ret)
    226  1.1  riastrad 		return ret;
    227  1.1  riastrad 
    228  1.1  riastrad 	connector->base.properties = &connector->properties;
    229  1.1  riastrad 	connector->dev = dev;
    230  1.1  riastrad 	connector->funcs = funcs;
    231  1.1  riastrad 
    232  1.1  riastrad 	/* connector index is used with 32bit bitmasks */
    233  1.1  riastrad 	ret = ida_simple_get(&config->connector_ida, 0, 32, GFP_KERNEL);
    234  1.1  riastrad 	if (ret < 0) {
    235  1.1  riastrad 		DRM_DEBUG_KMS("Failed to allocate %s connector index: %d\n",
    236  1.1  riastrad 			      drm_connector_enum_list[connector_type].name,
    237  1.1  riastrad 			      ret);
    238  1.1  riastrad 		goto out_put;
    239  1.1  riastrad 	}
    240  1.1  riastrad 	connector->index = ret;
    241  1.1  riastrad 	ret = 0;
    242  1.1  riastrad 
    243  1.1  riastrad 	connector->connector_type = connector_type;
    244  1.1  riastrad 	connector->connector_type_id =
    245  1.1  riastrad 		ida_simple_get(connector_ida, 1, 0, GFP_KERNEL);
    246  1.1  riastrad 	if (connector->connector_type_id < 0) {
    247  1.1  riastrad 		ret = connector->connector_type_id;
    248  1.1  riastrad 		goto out_put_id;
    249  1.1  riastrad 	}
    250  1.1  riastrad 	connector->name =
    251  1.1  riastrad 		kasprintf(GFP_KERNEL, "%s-%d",
    252  1.1  riastrad 			  drm_connector_enum_list[connector_type].name,
    253  1.1  riastrad 			  connector->connector_type_id);
    254  1.1  riastrad 	if (!connector->name) {
    255  1.1  riastrad 		ret = -ENOMEM;
    256  1.1  riastrad 		goto out_put_type_id;
    257  1.1  riastrad 	}
    258  1.1  riastrad 
    259  1.1  riastrad 	INIT_LIST_HEAD(&connector->probed_modes);
    260  1.1  riastrad 	INIT_LIST_HEAD(&connector->modes);
    261  1.1  riastrad 	mutex_init(&connector->mutex);
    262  1.1  riastrad 	connector->edid_blob_ptr = NULL;
    263  1.1  riastrad 	connector->tile_blob_ptr = NULL;
    264  1.1  riastrad 	connector->status = connector_status_unknown;
    265  1.1  riastrad 	connector->display_info.panel_orientation =
    266  1.1  riastrad 		DRM_MODE_PANEL_ORIENTATION_UNKNOWN;
    267  1.1  riastrad 
    268  1.1  riastrad 	drm_connector_get_cmdline_mode(connector);
    269  1.1  riastrad 
    270  1.1  riastrad 	/* We should add connectors at the end to avoid upsetting the connector
    271  1.1  riastrad 	 * index too much. */
    272  1.1  riastrad 	spin_lock_irq(&config->connector_list_lock);
    273  1.1  riastrad 	list_add_tail(&connector->head, &config->connector_list);
    274  1.1  riastrad 	config->num_connector++;
    275  1.1  riastrad 	spin_unlock_irq(&config->connector_list_lock);
    276  1.1  riastrad 
    277  1.1  riastrad 	if (connector_type != DRM_MODE_CONNECTOR_VIRTUAL &&
    278  1.1  riastrad 	    connector_type != DRM_MODE_CONNECTOR_WRITEBACK)
    279  1.1  riastrad 		drm_connector_attach_edid_property(connector);
    280  1.1  riastrad 
    281  1.1  riastrad 	drm_object_attach_property(&connector->base,
    282  1.1  riastrad 				      config->dpms_property, 0);
    283  1.1  riastrad 
    284  1.1  riastrad 	drm_object_attach_property(&connector->base,
    285  1.1  riastrad 				   config->link_status_property,
    286  1.1  riastrad 				   0);
    287  1.1  riastrad 
    288  1.1  riastrad 	drm_object_attach_property(&connector->base,
    289  1.1  riastrad 				   config->non_desktop_property,
    290  1.1  riastrad 				   0);
    291  1.1  riastrad 	drm_object_attach_property(&connector->base,
    292  1.1  riastrad 				   config->tile_property,
    293  1.1  riastrad 				   0);
    294  1.1  riastrad 
    295  1.1  riastrad 	if (drm_core_check_feature(dev, DRIVER_ATOMIC)) {
    296  1.1  riastrad 		drm_object_attach_property(&connector->base, config->prop_crtc_id, 0);
    297  1.1  riastrad 	}
    298  1.1  riastrad 
    299  1.1  riastrad 	connector->debugfs_entry = NULL;
    300  1.1  riastrad out_put_type_id:
    301  1.1  riastrad 	if (ret)
    302  1.1  riastrad 		ida_simple_remove(connector_ida, connector->connector_type_id);
    303  1.1  riastrad out_put_id:
    304  1.1  riastrad 	if (ret)
    305  1.1  riastrad 		ida_simple_remove(&config->connector_ida, connector->index);
    306  1.1  riastrad out_put:
    307  1.1  riastrad 	if (ret)
    308  1.1  riastrad 		drm_mode_object_unregister(dev, &connector->base);
    309  1.1  riastrad 
    310  1.1  riastrad 	return ret;
    311  1.1  riastrad }
    312  1.1  riastrad EXPORT_SYMBOL(drm_connector_init);
    313  1.1  riastrad 
    314  1.1  riastrad /**
    315  1.1  riastrad  * drm_connector_init_with_ddc - Init a preallocated connector
    316  1.1  riastrad  * @dev: DRM device
    317  1.1  riastrad  * @connector: the connector to init
    318  1.1  riastrad  * @funcs: callbacks for this connector
    319  1.1  riastrad  * @connector_type: user visible type of the connector
    320  1.1  riastrad  * @ddc: pointer to the associated ddc adapter
    321  1.1  riastrad  *
    322  1.1  riastrad  * Initialises a preallocated connector. Connectors should be
    323  1.1  riastrad  * subclassed as part of driver connector objects.
    324  1.1  riastrad  *
    325  1.1  riastrad  * Ensures that the ddc field of the connector is correctly set.
    326  1.1  riastrad  *
    327  1.1  riastrad  * Returns:
    328  1.1  riastrad  * Zero on success, error code on failure.
    329  1.1  riastrad  */
    330  1.1  riastrad int drm_connector_init_with_ddc(struct drm_device *dev,
    331  1.1  riastrad 				struct drm_connector *connector,
    332  1.1  riastrad 				const struct drm_connector_funcs *funcs,
    333  1.1  riastrad 				int connector_type,
    334  1.1  riastrad 				struct i2c_adapter *ddc)
    335  1.1  riastrad {
    336  1.1  riastrad 	int ret;
    337  1.1  riastrad 
    338  1.1  riastrad 	ret = drm_connector_init(dev, connector, funcs, connector_type);
    339  1.1  riastrad 	if (ret)
    340  1.1  riastrad 		return ret;
    341  1.1  riastrad 
    342  1.1  riastrad 	/* provide ddc symlink in sysfs */
    343  1.1  riastrad 	connector->ddc = ddc;
    344  1.1  riastrad 
    345  1.1  riastrad 	return ret;
    346  1.1  riastrad }
    347  1.1  riastrad EXPORT_SYMBOL(drm_connector_init_with_ddc);
    348  1.1  riastrad 
    349  1.1  riastrad /**
    350  1.1  riastrad  * drm_connector_attach_edid_property - attach edid property.
    351  1.1  riastrad  * @connector: the connector
    352  1.1  riastrad  *
    353  1.1  riastrad  * Some connector types like DRM_MODE_CONNECTOR_VIRTUAL do not get a
    354  1.1  riastrad  * edid property attached by default.  This function can be used to
    355  1.1  riastrad  * explicitly enable the edid property in these cases.
    356  1.1  riastrad  */
    357  1.1  riastrad void drm_connector_attach_edid_property(struct drm_connector *connector)
    358  1.1  riastrad {
    359  1.1  riastrad 	struct drm_mode_config *config = &connector->dev->mode_config;
    360  1.1  riastrad 
    361  1.1  riastrad 	drm_object_attach_property(&connector->base,
    362  1.1  riastrad 				   config->edid_property,
    363  1.1  riastrad 				   0);
    364  1.1  riastrad }
    365  1.1  riastrad EXPORT_SYMBOL(drm_connector_attach_edid_property);
    366  1.1  riastrad 
    367  1.1  riastrad /**
    368  1.1  riastrad  * drm_connector_attach_encoder - attach a connector to an encoder
    369  1.1  riastrad  * @connector: connector to attach
    370  1.1  riastrad  * @encoder: encoder to attach @connector to
    371  1.1  riastrad  *
    372  1.1  riastrad  * This function links up a connector to an encoder. Note that the routing
    373  1.1  riastrad  * restrictions between encoders and crtcs are exposed to userspace through the
    374  1.1  riastrad  * possible_clones and possible_crtcs bitmasks.
    375  1.1  riastrad  *
    376  1.1  riastrad  * Returns:
    377  1.1  riastrad  * Zero on success, negative errno on failure.
    378  1.1  riastrad  */
    379  1.1  riastrad int drm_connector_attach_encoder(struct drm_connector *connector,
    380  1.1  riastrad 				 struct drm_encoder *encoder)
    381  1.1  riastrad {
    382  1.1  riastrad 	/*
    383  1.1  riastrad 	 * In the past, drivers have attempted to model the static association
    384  1.1  riastrad 	 * of connector to encoder in simple connector/encoder devices using a
    385  1.1  riastrad 	 * direct assignment of connector->encoder = encoder. This connection
    386  1.1  riastrad 	 * is a logical one and the responsibility of the core, so drivers are
    387  1.1  riastrad 	 * expected not to mess with this.
    388  1.1  riastrad 	 *
    389  1.1  riastrad 	 * Note that the error return should've been enough here, but a large
    390  1.1  riastrad 	 * majority of drivers ignores the return value, so add in a big WARN
    391  1.1  riastrad 	 * to get people's attention.
    392  1.1  riastrad 	 */
    393  1.1  riastrad 	if (WARN_ON(connector->encoder))
    394  1.1  riastrad 		return -EINVAL;
    395  1.1  riastrad 
    396  1.1  riastrad 	connector->possible_encoders |= drm_encoder_mask(encoder);
    397  1.1  riastrad 
    398  1.1  riastrad 	return 0;
    399  1.1  riastrad }
    400  1.1  riastrad EXPORT_SYMBOL(drm_connector_attach_encoder);
    401  1.1  riastrad 
    402  1.1  riastrad /**
    403  1.1  riastrad  * drm_connector_has_possible_encoder - check if the connector and encoder are
    404  1.1  riastrad  * associated with each other
    405  1.1  riastrad  * @connector: the connector
    406  1.1  riastrad  * @encoder: the encoder
    407  1.1  riastrad  *
    408  1.1  riastrad  * Returns:
    409  1.1  riastrad  * True if @encoder is one of the possible encoders for @connector.
    410  1.1  riastrad  */
    411  1.1  riastrad bool drm_connector_has_possible_encoder(struct drm_connector *connector,
    412  1.1  riastrad 					struct drm_encoder *encoder)
    413  1.1  riastrad {
    414  1.1  riastrad 	return connector->possible_encoders & drm_encoder_mask(encoder);
    415  1.1  riastrad }
    416  1.1  riastrad EXPORT_SYMBOL(drm_connector_has_possible_encoder);
    417  1.1  riastrad 
    418  1.1  riastrad static void drm_mode_remove(struct drm_connector *connector,
    419  1.1  riastrad 			    struct drm_display_mode *mode)
    420  1.1  riastrad {
    421  1.1  riastrad 	list_del(&mode->head);
    422  1.1  riastrad 	drm_mode_destroy(connector->dev, mode);
    423  1.1  riastrad }
    424  1.1  riastrad 
    425  1.1  riastrad /**
    426  1.1  riastrad  * drm_connector_cleanup - cleans up an initialised connector
    427  1.1  riastrad  * @connector: connector to cleanup
    428  1.1  riastrad  *
    429  1.1  riastrad  * Cleans up the connector but doesn't free the object.
    430  1.1  riastrad  */
    431  1.1  riastrad void drm_connector_cleanup(struct drm_connector *connector)
    432  1.1  riastrad {
    433  1.1  riastrad 	struct drm_device *dev = connector->dev;
    434  1.1  riastrad 	struct drm_display_mode *mode, *t;
    435  1.1  riastrad 
    436  1.1  riastrad 	/* The connector should have been removed from userspace long before
    437  1.1  riastrad 	 * it is finally destroyed.
    438  1.1  riastrad 	 */
    439  1.1  riastrad 	if (WARN_ON(connector->registration_state ==
    440  1.1  riastrad 		    DRM_CONNECTOR_REGISTERED))
    441  1.1  riastrad 		drm_connector_unregister(connector);
    442  1.1  riastrad 
    443  1.1  riastrad 	if (connector->tile_group) {
    444  1.1  riastrad 		drm_mode_put_tile_group(dev, connector->tile_group);
    445  1.1  riastrad 		connector->tile_group = NULL;
    446  1.1  riastrad 	}
    447  1.1  riastrad 
    448  1.1  riastrad 	list_for_each_entry_safe(mode, t, &connector->probed_modes, head)
    449  1.1  riastrad 		drm_mode_remove(connector, mode);
    450  1.1  riastrad 
    451  1.1  riastrad 	list_for_each_entry_safe(mode, t, &connector->modes, head)
    452  1.1  riastrad 		drm_mode_remove(connector, mode);
    453  1.1  riastrad 
    454  1.1  riastrad 	ida_simple_remove(&drm_connector_enum_list[connector->connector_type].ida,
    455  1.1  riastrad 			  connector->connector_type_id);
    456  1.1  riastrad 
    457  1.1  riastrad 	ida_simple_remove(&dev->mode_config.connector_ida,
    458  1.1  riastrad 			  connector->index);
    459  1.1  riastrad 
    460  1.1  riastrad 	kfree(connector->display_info.bus_formats);
    461  1.1  riastrad 	drm_mode_object_unregister(dev, &connector->base);
    462  1.1  riastrad 	kfree(connector->name);
    463  1.1  riastrad 	connector->name = NULL;
    464  1.1  riastrad 	spin_lock_irq(&dev->mode_config.connector_list_lock);
    465  1.1  riastrad 	list_del(&connector->head);
    466  1.1  riastrad 	dev->mode_config.num_connector--;
    467  1.1  riastrad 	spin_unlock_irq(&dev->mode_config.connector_list_lock);
    468  1.1  riastrad 
    469  1.1  riastrad 	WARN_ON(connector->state && !connector->funcs->atomic_destroy_state);
    470  1.1  riastrad 	if (connector->state && connector->funcs->atomic_destroy_state)
    471  1.1  riastrad 		connector->funcs->atomic_destroy_state(connector,
    472  1.1  riastrad 						       connector->state);
    473  1.1  riastrad 
    474  1.1  riastrad 	mutex_destroy(&connector->mutex);
    475  1.1  riastrad 
    476  1.1  riastrad 	memset(connector, 0, sizeof(*connector));
    477  1.1  riastrad }
    478  1.1  riastrad EXPORT_SYMBOL(drm_connector_cleanup);
    479  1.1  riastrad 
    480  1.1  riastrad /**
    481  1.1  riastrad  * drm_connector_register - register a connector
    482  1.1  riastrad  * @connector: the connector to register
    483  1.1  riastrad  *
    484  1.1  riastrad  * Register userspace interfaces for a connector. Only call this for connectors
    485  1.1  riastrad  * which can be hotplugged after drm_dev_register() has been called already,
    486  1.1  riastrad  * e.g. DP MST connectors. All other connectors will be registered automatically
    487  1.1  riastrad  * when calling drm_dev_register().
    488  1.1  riastrad  *
    489  1.1  riastrad  * Returns:
    490  1.1  riastrad  * Zero on success, error code on failure.
    491  1.1  riastrad  */
    492  1.1  riastrad int drm_connector_register(struct drm_connector *connector)
    493  1.1  riastrad {
    494  1.1  riastrad 	int ret = 0;
    495  1.1  riastrad 
    496  1.1  riastrad 	if (!connector->dev->registered)
    497  1.1  riastrad 		return 0;
    498  1.1  riastrad 
    499  1.1  riastrad 	mutex_lock(&connector->mutex);
    500  1.1  riastrad 	if (connector->registration_state != DRM_CONNECTOR_INITIALIZING)
    501  1.1  riastrad 		goto unlock;
    502  1.1  riastrad 
    503  1.1  riastrad 	ret = drm_sysfs_connector_add(connector);
    504  1.1  riastrad 	if (ret)
    505  1.1  riastrad 		goto unlock;
    506  1.1  riastrad 
    507  1.1  riastrad 	drm_debugfs_connector_add(connector);
    508  1.1  riastrad 
    509  1.1  riastrad 	if (connector->funcs->late_register) {
    510  1.1  riastrad 		ret = connector->funcs->late_register(connector);
    511  1.1  riastrad 		if (ret)
    512  1.1  riastrad 			goto err_debugfs;
    513  1.1  riastrad 	}
    514  1.1  riastrad 
    515  1.1  riastrad 	drm_mode_object_register(connector->dev, &connector->base);
    516  1.1  riastrad 
    517  1.1  riastrad 	connector->registration_state = DRM_CONNECTOR_REGISTERED;
    518  1.1  riastrad 	goto unlock;
    519  1.1  riastrad 
    520  1.1  riastrad err_debugfs:
    521  1.1  riastrad 	drm_debugfs_connector_remove(connector);
    522  1.1  riastrad 	drm_sysfs_connector_remove(connector);
    523  1.1  riastrad unlock:
    524  1.1  riastrad 	mutex_unlock(&connector->mutex);
    525  1.1  riastrad 	return ret;
    526  1.1  riastrad }
    527  1.1  riastrad EXPORT_SYMBOL(drm_connector_register);
    528  1.1  riastrad 
    529  1.1  riastrad /**
    530  1.1  riastrad  * drm_connector_unregister - unregister a connector
    531  1.1  riastrad  * @connector: the connector to unregister
    532  1.1  riastrad  *
    533  1.1  riastrad  * Unregister userspace interfaces for a connector. Only call this for
    534  1.1  riastrad  * connectors which have registered explicitly by calling drm_dev_register(),
    535  1.1  riastrad  * since connectors are unregistered automatically when drm_dev_unregister() is
    536  1.1  riastrad  * called.
    537  1.1  riastrad  */
    538  1.1  riastrad void drm_connector_unregister(struct drm_connector *connector)
    539  1.1  riastrad {
    540  1.1  riastrad 	mutex_lock(&connector->mutex);
    541  1.1  riastrad 	if (connector->registration_state != DRM_CONNECTOR_REGISTERED) {
    542  1.1  riastrad 		mutex_unlock(&connector->mutex);
    543  1.1  riastrad 		return;
    544  1.1  riastrad 	}
    545  1.1  riastrad 
    546  1.1  riastrad 	if (connector->funcs->early_unregister)
    547  1.1  riastrad 		connector->funcs->early_unregister(connector);
    548  1.1  riastrad 
    549  1.1  riastrad 	drm_sysfs_connector_remove(connector);
    550  1.1  riastrad 	drm_debugfs_connector_remove(connector);
    551  1.1  riastrad 
    552  1.1  riastrad 	connector->registration_state = DRM_CONNECTOR_UNREGISTERED;
    553  1.1  riastrad 	mutex_unlock(&connector->mutex);
    554  1.1  riastrad }
    555  1.1  riastrad EXPORT_SYMBOL(drm_connector_unregister);
    556  1.1  riastrad 
    557  1.1  riastrad void drm_connector_unregister_all(struct drm_device *dev)
    558  1.1  riastrad {
    559  1.1  riastrad 	struct drm_connector *connector;
    560  1.1  riastrad 	struct drm_connector_list_iter conn_iter;
    561  1.1  riastrad 
    562  1.1  riastrad 	drm_connector_list_iter_begin(dev, &conn_iter);
    563  1.1  riastrad 	drm_for_each_connector_iter(connector, &conn_iter)
    564  1.1  riastrad 		drm_connector_unregister(connector);
    565  1.1  riastrad 	drm_connector_list_iter_end(&conn_iter);
    566  1.1  riastrad }
    567  1.1  riastrad 
    568  1.1  riastrad int drm_connector_register_all(struct drm_device *dev)
    569  1.1  riastrad {
    570  1.1  riastrad 	struct drm_connector *connector;
    571  1.1  riastrad 	struct drm_connector_list_iter conn_iter;
    572  1.1  riastrad 	int ret = 0;
    573  1.1  riastrad 
    574  1.1  riastrad 	drm_connector_list_iter_begin(dev, &conn_iter);
    575  1.1  riastrad 	drm_for_each_connector_iter(connector, &conn_iter) {
    576  1.1  riastrad 		ret = drm_connector_register(connector);
    577  1.1  riastrad 		if (ret)
    578  1.1  riastrad 			break;
    579  1.1  riastrad 	}
    580  1.1  riastrad 	drm_connector_list_iter_end(&conn_iter);
    581  1.1  riastrad 
    582  1.1  riastrad 	if (ret)
    583  1.1  riastrad 		drm_connector_unregister_all(dev);
    584  1.1  riastrad 	return ret;
    585  1.1  riastrad }
    586  1.1  riastrad 
    587  1.1  riastrad /**
    588  1.1  riastrad  * drm_get_connector_status_name - return a string for connector status
    589  1.1  riastrad  * @status: connector status to compute name of
    590  1.1  riastrad  *
    591  1.1  riastrad  * In contrast to the other drm_get_*_name functions this one here returns a
    592  1.1  riastrad  * const pointer and hence is threadsafe.
    593  1.1  riastrad  */
    594  1.1  riastrad const char *drm_get_connector_status_name(enum drm_connector_status status)
    595  1.1  riastrad {
    596  1.1  riastrad 	if (status == connector_status_connected)
    597  1.1  riastrad 		return "connected";
    598  1.1  riastrad 	else if (status == connector_status_disconnected)
    599  1.1  riastrad 		return "disconnected";
    600  1.1  riastrad 	else
    601  1.1  riastrad 		return "unknown";
    602  1.1  riastrad }
    603  1.1  riastrad EXPORT_SYMBOL(drm_get_connector_status_name);
    604  1.1  riastrad 
    605  1.1  riastrad /**
    606  1.1  riastrad  * drm_get_connector_force_name - return a string for connector force
    607  1.1  riastrad  * @force: connector force to get name of
    608  1.1  riastrad  *
    609  1.1  riastrad  * Returns: const pointer to name.
    610  1.1  riastrad  */
    611  1.1  riastrad const char *drm_get_connector_force_name(enum drm_connector_force force)
    612  1.1  riastrad {
    613  1.1  riastrad 	switch (force) {
    614  1.1  riastrad 	case DRM_FORCE_UNSPECIFIED:
    615  1.1  riastrad 		return "unspecified";
    616  1.1  riastrad 	case DRM_FORCE_OFF:
    617  1.1  riastrad 		return "off";
    618  1.1  riastrad 	case DRM_FORCE_ON:
    619  1.1  riastrad 		return "on";
    620  1.1  riastrad 	case DRM_FORCE_ON_DIGITAL:
    621  1.1  riastrad 		return "digital";
    622  1.1  riastrad 	default:
    623  1.1  riastrad 		return "unknown";
    624  1.1  riastrad 	}
    625  1.1  riastrad }
    626  1.1  riastrad 
    627  1.5  riastrad #if IS_ENABLED(CONFIG_LOCKDEP)
    628  1.1  riastrad static struct lockdep_map connector_list_iter_dep_map = {
    629  1.1  riastrad 	.name = "drm_connector_list_iter"
    630  1.1  riastrad };
    631  1.1  riastrad #endif
    632  1.1  riastrad 
    633  1.1  riastrad /**
    634  1.1  riastrad  * drm_connector_list_iter_begin - initialize a connector_list iterator
    635  1.1  riastrad  * @dev: DRM device
    636  1.1  riastrad  * @iter: connector_list iterator
    637  1.1  riastrad  *
    638  1.1  riastrad  * Sets @iter up to walk the &drm_mode_config.connector_list of @dev. @iter
    639  1.1  riastrad  * must always be cleaned up again by calling drm_connector_list_iter_end().
    640  1.1  riastrad  * Iteration itself happens using drm_connector_list_iter_next() or
    641  1.1  riastrad  * drm_for_each_connector_iter().
    642  1.1  riastrad  */
    643  1.1  riastrad void drm_connector_list_iter_begin(struct drm_device *dev,
    644  1.1  riastrad 				   struct drm_connector_list_iter *iter)
    645  1.1  riastrad {
    646  1.1  riastrad 	iter->dev = dev;
    647  1.1  riastrad 	iter->conn = NULL;
    648  1.1  riastrad 	lock_acquire_shared_recursive(&connector_list_iter_dep_map, 0, 1, NULL, _RET_IP_);
    649  1.1  riastrad }
    650  1.1  riastrad EXPORT_SYMBOL(drm_connector_list_iter_begin);
    651  1.1  riastrad 
    652  1.1  riastrad /*
    653  1.1  riastrad  * Extra-safe connector put function that works in any context. Should only be
    654  1.1  riastrad  * used from the connector_iter functions, where we never really expect to
    655  1.1  riastrad  * actually release the connector when dropping our final reference.
    656  1.1  riastrad  */
    657  1.1  riastrad static void
    658  1.1  riastrad __drm_connector_put_safe(struct drm_connector *conn)
    659  1.1  riastrad {
    660  1.1  riastrad 	struct drm_mode_config *config = &conn->dev->mode_config;
    661  1.1  riastrad 
    662  1.1  riastrad 	lockdep_assert_held(&config->connector_list_lock);
    663  1.1  riastrad 
    664  1.3  riastrad 	/* XXX sketchy function pointer cast */
    665  1.3  riastrad 	if (!kref_put(&conn->base.refcount, (void (*)(struct kref *))voidop))
    666  1.1  riastrad 		return;
    667  1.1  riastrad 
    668  1.1  riastrad 	llist_add(&conn->free_node, &config->connector_free_list);
    669  1.1  riastrad 	schedule_work(&config->connector_free_work);
    670  1.1  riastrad }
    671  1.1  riastrad 
    672  1.1  riastrad /**
    673  1.1  riastrad  * drm_connector_list_iter_next - return next connector
    674  1.1  riastrad  * @iter: connector_list iterator
    675  1.1  riastrad  *
    676  1.1  riastrad  * Returns the next connector for @iter, or NULL when the list walk has
    677  1.1  riastrad  * completed.
    678  1.1  riastrad  */
    679  1.1  riastrad struct drm_connector *
    680  1.1  riastrad drm_connector_list_iter_next(struct drm_connector_list_iter *iter)
    681  1.1  riastrad {
    682  1.1  riastrad 	struct drm_connector *old_conn = iter->conn;
    683  1.1  riastrad 	struct drm_mode_config *config = &iter->dev->mode_config;
    684  1.1  riastrad 	struct list_head *lhead;
    685  1.1  riastrad 	unsigned long flags;
    686  1.1  riastrad 
    687  1.1  riastrad 	spin_lock_irqsave(&config->connector_list_lock, flags);
    688  1.1  riastrad 	lhead = old_conn ? &old_conn->head : &config->connector_list;
    689  1.1  riastrad 
    690  1.1  riastrad 	do {
    691  1.1  riastrad 		if (lhead->next == &config->connector_list) {
    692  1.1  riastrad 			iter->conn = NULL;
    693  1.1  riastrad 			break;
    694  1.1  riastrad 		}
    695  1.1  riastrad 
    696  1.1  riastrad 		lhead = lhead->next;
    697  1.1  riastrad 		iter->conn = list_entry(lhead, struct drm_connector, head);
    698  1.1  riastrad 
    699  1.1  riastrad 		/* loop until it's not a zombie connector */
    700  1.1  riastrad 	} while (!kref_get_unless_zero(&iter->conn->base.refcount));
    701  1.1  riastrad 
    702  1.1  riastrad 	if (old_conn)
    703  1.1  riastrad 		__drm_connector_put_safe(old_conn);
    704  1.1  riastrad 	spin_unlock_irqrestore(&config->connector_list_lock, flags);
    705  1.1  riastrad 
    706  1.1  riastrad 	return iter->conn;
    707  1.1  riastrad }
    708  1.1  riastrad EXPORT_SYMBOL(drm_connector_list_iter_next);
    709  1.1  riastrad 
    710  1.1  riastrad /**
    711  1.1  riastrad  * drm_connector_list_iter_end - tear down a connector_list iterator
    712  1.1  riastrad  * @iter: connector_list iterator
    713  1.1  riastrad  *
    714  1.1  riastrad  * Tears down @iter and releases any resources (like &drm_connector references)
    715  1.1  riastrad  * acquired while walking the list. This must always be called, both when the
    716  1.1  riastrad  * iteration completes fully or when it was aborted without walking the entire
    717  1.1  riastrad  * list.
    718  1.1  riastrad  */
    719  1.1  riastrad void drm_connector_list_iter_end(struct drm_connector_list_iter *iter)
    720  1.1  riastrad {
    721  1.1  riastrad 	struct drm_mode_config *config = &iter->dev->mode_config;
    722  1.1  riastrad 	unsigned long flags;
    723  1.1  riastrad 
    724  1.1  riastrad 	iter->dev = NULL;
    725  1.1  riastrad 	if (iter->conn) {
    726  1.1  riastrad 		spin_lock_irqsave(&config->connector_list_lock, flags);
    727  1.1  riastrad 		__drm_connector_put_safe(iter->conn);
    728  1.1  riastrad 		spin_unlock_irqrestore(&config->connector_list_lock, flags);
    729  1.1  riastrad 	}
    730  1.1  riastrad 	lock_release(&connector_list_iter_dep_map, _RET_IP_);
    731  1.1  riastrad }
    732  1.1  riastrad EXPORT_SYMBOL(drm_connector_list_iter_end);
    733  1.1  riastrad 
    734  1.1  riastrad static const struct drm_prop_enum_list drm_subpixel_enum_list[] = {
    735  1.1  riastrad 	{ SubPixelUnknown, "Unknown" },
    736  1.1  riastrad 	{ SubPixelHorizontalRGB, "Horizontal RGB" },
    737  1.1  riastrad 	{ SubPixelHorizontalBGR, "Horizontal BGR" },
    738  1.1  riastrad 	{ SubPixelVerticalRGB, "Vertical RGB" },
    739  1.1  riastrad 	{ SubPixelVerticalBGR, "Vertical BGR" },
    740  1.1  riastrad 	{ SubPixelNone, "None" },
    741  1.1  riastrad };
    742  1.1  riastrad 
    743  1.1  riastrad /**
    744  1.1  riastrad  * drm_get_subpixel_order_name - return a string for a given subpixel enum
    745  1.1  riastrad  * @order: enum of subpixel_order
    746  1.1  riastrad  *
    747  1.1  riastrad  * Note you could abuse this and return something out of bounds, but that
    748  1.1  riastrad  * would be a caller error.  No unscrubbed user data should make it here.
    749  1.1  riastrad  */
    750  1.1  riastrad const char *drm_get_subpixel_order_name(enum subpixel_order order)
    751  1.1  riastrad {
    752  1.1  riastrad 	return drm_subpixel_enum_list[order].name;
    753  1.1  riastrad }
    754  1.1  riastrad EXPORT_SYMBOL(drm_get_subpixel_order_name);
    755  1.1  riastrad 
    756  1.1  riastrad static const struct drm_prop_enum_list drm_dpms_enum_list[] = {
    757  1.1  riastrad 	{ DRM_MODE_DPMS_ON, "On" },
    758  1.1  riastrad 	{ DRM_MODE_DPMS_STANDBY, "Standby" },
    759  1.1  riastrad 	{ DRM_MODE_DPMS_SUSPEND, "Suspend" },
    760  1.1  riastrad 	{ DRM_MODE_DPMS_OFF, "Off" }
    761  1.1  riastrad };
    762  1.1  riastrad DRM_ENUM_NAME_FN(drm_get_dpms_name, drm_dpms_enum_list)
    763  1.1  riastrad 
    764  1.1  riastrad static const struct drm_prop_enum_list drm_link_status_enum_list[] = {
    765  1.1  riastrad 	{ DRM_MODE_LINK_STATUS_GOOD, "Good" },
    766  1.1  riastrad 	{ DRM_MODE_LINK_STATUS_BAD, "Bad" },
    767  1.1  riastrad };
    768  1.1  riastrad 
    769  1.1  riastrad /**
    770  1.1  riastrad  * drm_display_info_set_bus_formats - set the supported bus formats
    771  1.1  riastrad  * @info: display info to store bus formats in
    772  1.1  riastrad  * @formats: array containing the supported bus formats
    773  1.1  riastrad  * @num_formats: the number of entries in the fmts array
    774  1.1  riastrad  *
    775  1.1  riastrad  * Store the supported bus formats in display info structure.
    776  1.1  riastrad  * See MEDIA_BUS_FMT_* definitions in include/uapi/linux/media-bus-format.h for
    777  1.1  riastrad  * a full list of available formats.
    778  1.1  riastrad  */
    779  1.1  riastrad int drm_display_info_set_bus_formats(struct drm_display_info *info,
    780  1.1  riastrad 				     const u32 *formats,
    781  1.1  riastrad 				     unsigned int num_formats)
    782  1.1  riastrad {
    783  1.1  riastrad 	u32 *fmts = NULL;
    784  1.1  riastrad 
    785  1.1  riastrad 	if (!formats && num_formats)
    786  1.1  riastrad 		return -EINVAL;
    787  1.1  riastrad 
    788  1.1  riastrad 	if (formats && num_formats) {
    789  1.1  riastrad 		fmts = kmemdup(formats, sizeof(*formats) * num_formats,
    790  1.1  riastrad 			       GFP_KERNEL);
    791  1.1  riastrad 		if (!fmts)
    792  1.1  riastrad 			return -ENOMEM;
    793  1.1  riastrad 	}
    794  1.1  riastrad 
    795  1.1  riastrad 	kfree(info->bus_formats);
    796  1.1  riastrad 	info->bus_formats = fmts;
    797  1.1  riastrad 	info->num_bus_formats = num_formats;
    798  1.1  riastrad 
    799  1.1  riastrad 	return 0;
    800  1.1  riastrad }
    801  1.1  riastrad EXPORT_SYMBOL(drm_display_info_set_bus_formats);
    802  1.1  riastrad 
    803  1.1  riastrad /* Optional connector properties. */
    804  1.1  riastrad static const struct drm_prop_enum_list drm_scaling_mode_enum_list[] = {
    805  1.1  riastrad 	{ DRM_MODE_SCALE_NONE, "None" },
    806  1.1  riastrad 	{ DRM_MODE_SCALE_FULLSCREEN, "Full" },
    807  1.1  riastrad 	{ DRM_MODE_SCALE_CENTER, "Center" },
    808  1.1  riastrad 	{ DRM_MODE_SCALE_ASPECT, "Full aspect" },
    809  1.1  riastrad };
    810  1.1  riastrad 
    811  1.1  riastrad static const struct drm_prop_enum_list drm_aspect_ratio_enum_list[] = {
    812  1.1  riastrad 	{ DRM_MODE_PICTURE_ASPECT_NONE, "Automatic" },
    813  1.1  riastrad 	{ DRM_MODE_PICTURE_ASPECT_4_3, "4:3" },
    814  1.1  riastrad 	{ DRM_MODE_PICTURE_ASPECT_16_9, "16:9" },
    815  1.1  riastrad };
    816  1.1  riastrad 
    817  1.1  riastrad static const struct drm_prop_enum_list drm_content_type_enum_list[] = {
    818  1.1  riastrad 	{ DRM_MODE_CONTENT_TYPE_NO_DATA, "No Data" },
    819  1.1  riastrad 	{ DRM_MODE_CONTENT_TYPE_GRAPHICS, "Graphics" },
    820  1.1  riastrad 	{ DRM_MODE_CONTENT_TYPE_PHOTO, "Photo" },
    821  1.1  riastrad 	{ DRM_MODE_CONTENT_TYPE_CINEMA, "Cinema" },
    822  1.1  riastrad 	{ DRM_MODE_CONTENT_TYPE_GAME, "Game" },
    823  1.1  riastrad };
    824  1.1  riastrad 
    825  1.1  riastrad static const struct drm_prop_enum_list drm_panel_orientation_enum_list[] = {
    826  1.1  riastrad 	{ DRM_MODE_PANEL_ORIENTATION_NORMAL,	"Normal"	},
    827  1.1  riastrad 	{ DRM_MODE_PANEL_ORIENTATION_BOTTOM_UP,	"Upside Down"	},
    828  1.1  riastrad 	{ DRM_MODE_PANEL_ORIENTATION_LEFT_UP,	"Left Side Up"	},
    829  1.1  riastrad 	{ DRM_MODE_PANEL_ORIENTATION_RIGHT_UP,	"Right Side Up"	},
    830  1.1  riastrad };
    831  1.1  riastrad 
    832  1.1  riastrad static const struct drm_prop_enum_list drm_dvi_i_select_enum_list[] = {
    833  1.1  riastrad 	{ DRM_MODE_SUBCONNECTOR_Automatic, "Automatic" }, /* DVI-I and TV-out */
    834  1.1  riastrad 	{ DRM_MODE_SUBCONNECTOR_DVID,      "DVI-D"     }, /* DVI-I  */
    835  1.1  riastrad 	{ DRM_MODE_SUBCONNECTOR_DVIA,      "DVI-A"     }, /* DVI-I  */
    836  1.1  riastrad };
    837  1.1  riastrad DRM_ENUM_NAME_FN(drm_get_dvi_i_select_name, drm_dvi_i_select_enum_list)
    838  1.1  riastrad 
    839  1.1  riastrad static const struct drm_prop_enum_list drm_dvi_i_subconnector_enum_list[] = {
    840  1.1  riastrad 	{ DRM_MODE_SUBCONNECTOR_Unknown,   "Unknown"   }, /* DVI-I and TV-out */
    841  1.1  riastrad 	{ DRM_MODE_SUBCONNECTOR_DVID,      "DVI-D"     }, /* DVI-I  */
    842  1.1  riastrad 	{ DRM_MODE_SUBCONNECTOR_DVIA,      "DVI-A"     }, /* DVI-I  */
    843  1.1  riastrad };
    844  1.1  riastrad DRM_ENUM_NAME_FN(drm_get_dvi_i_subconnector_name,
    845  1.1  riastrad 		 drm_dvi_i_subconnector_enum_list)
    846  1.1  riastrad 
    847  1.1  riastrad static const struct drm_prop_enum_list drm_tv_select_enum_list[] = {
    848  1.1  riastrad 	{ DRM_MODE_SUBCONNECTOR_Automatic, "Automatic" }, /* DVI-I and TV-out */
    849  1.1  riastrad 	{ DRM_MODE_SUBCONNECTOR_Composite, "Composite" }, /* TV-out */
    850  1.1  riastrad 	{ DRM_MODE_SUBCONNECTOR_SVIDEO,    "SVIDEO"    }, /* TV-out */
    851  1.1  riastrad 	{ DRM_MODE_SUBCONNECTOR_Component, "Component" }, /* TV-out */
    852  1.1  riastrad 	{ DRM_MODE_SUBCONNECTOR_SCART,     "SCART"     }, /* TV-out */
    853  1.1  riastrad };
    854  1.1  riastrad DRM_ENUM_NAME_FN(drm_get_tv_select_name, drm_tv_select_enum_list)
    855  1.1  riastrad 
    856  1.1  riastrad static const struct drm_prop_enum_list drm_tv_subconnector_enum_list[] = {
    857  1.1  riastrad 	{ DRM_MODE_SUBCONNECTOR_Unknown,   "Unknown"   }, /* DVI-I and TV-out */
    858  1.1  riastrad 	{ DRM_MODE_SUBCONNECTOR_Composite, "Composite" }, /* TV-out */
    859  1.1  riastrad 	{ DRM_MODE_SUBCONNECTOR_SVIDEO,    "SVIDEO"    }, /* TV-out */
    860  1.1  riastrad 	{ DRM_MODE_SUBCONNECTOR_Component, "Component" }, /* TV-out */
    861  1.1  riastrad 	{ DRM_MODE_SUBCONNECTOR_SCART,     "SCART"     }, /* TV-out */
    862  1.1  riastrad };
    863  1.1  riastrad DRM_ENUM_NAME_FN(drm_get_tv_subconnector_name,
    864  1.1  riastrad 		 drm_tv_subconnector_enum_list)
    865  1.1  riastrad 
    866  1.1  riastrad static const struct drm_prop_enum_list hdmi_colorspaces[] = {
    867  1.1  riastrad 	/* For Default case, driver will set the colorspace */
    868  1.1  riastrad 	{ DRM_MODE_COLORIMETRY_DEFAULT, "Default" },
    869  1.1  riastrad 	/* Standard Definition Colorimetry based on CEA 861 */
    870  1.1  riastrad 	{ DRM_MODE_COLORIMETRY_SMPTE_170M_YCC, "SMPTE_170M_YCC" },
    871  1.1  riastrad 	{ DRM_MODE_COLORIMETRY_BT709_YCC, "BT709_YCC" },
    872  1.1  riastrad 	/* Standard Definition Colorimetry based on IEC 61966-2-4 */
    873  1.1  riastrad 	{ DRM_MODE_COLORIMETRY_XVYCC_601, "XVYCC_601" },
    874  1.1  riastrad 	/* High Definition Colorimetry based on IEC 61966-2-4 */
    875  1.1  riastrad 	{ DRM_MODE_COLORIMETRY_XVYCC_709, "XVYCC_709" },
    876  1.1  riastrad 	/* Colorimetry based on IEC 61966-2-1/Amendment 1 */
    877  1.1  riastrad 	{ DRM_MODE_COLORIMETRY_SYCC_601, "SYCC_601" },
    878  1.1  riastrad 	/* Colorimetry based on IEC 61966-2-5 [33] */
    879  1.1  riastrad 	{ DRM_MODE_COLORIMETRY_OPYCC_601, "opYCC_601" },
    880  1.1  riastrad 	/* Colorimetry based on IEC 61966-2-5 */
    881  1.1  riastrad 	{ DRM_MODE_COLORIMETRY_OPRGB, "opRGB" },
    882  1.1  riastrad 	/* Colorimetry based on ITU-R BT.2020 */
    883  1.1  riastrad 	{ DRM_MODE_COLORIMETRY_BT2020_CYCC, "BT2020_CYCC" },
    884  1.1  riastrad 	/* Colorimetry based on ITU-R BT.2020 */
    885  1.1  riastrad 	{ DRM_MODE_COLORIMETRY_BT2020_RGB, "BT2020_RGB" },
    886  1.1  riastrad 	/* Colorimetry based on ITU-R BT.2020 */
    887  1.1  riastrad 	{ DRM_MODE_COLORIMETRY_BT2020_YCC, "BT2020_YCC" },
    888  1.1  riastrad 	/* Added as part of Additional Colorimetry Extension in 861.G */
    889  1.1  riastrad 	{ DRM_MODE_COLORIMETRY_DCI_P3_RGB_D65, "DCI-P3_RGB_D65" },
    890  1.1  riastrad 	{ DRM_MODE_COLORIMETRY_DCI_P3_RGB_THEATER, "DCI-P3_RGB_Theater" },
    891  1.1  riastrad };
    892  1.1  riastrad 
    893  1.1  riastrad /*
    894  1.1  riastrad  * As per DP 1.4a spec, 2.2.5.7.5 VSC SDP Payload for Pixel Encoding/Colorimetry
    895  1.1  riastrad  * Format Table 2-120
    896  1.1  riastrad  */
    897  1.1  riastrad static const struct drm_prop_enum_list dp_colorspaces[] = {
    898  1.1  riastrad 	/* For Default case, driver will set the colorspace */
    899  1.1  riastrad 	{ DRM_MODE_COLORIMETRY_DEFAULT, "Default" },
    900  1.1  riastrad 	{ DRM_MODE_COLORIMETRY_RGB_WIDE_FIXED, "RGB_Wide_Gamut_Fixed_Point" },
    901  1.1  riastrad 	/* Colorimetry based on scRGB (IEC 61966-2-2) */
    902  1.1  riastrad 	{ DRM_MODE_COLORIMETRY_RGB_WIDE_FLOAT, "RGB_Wide_Gamut_Floating_Point" },
    903  1.1  riastrad 	/* Colorimetry based on IEC 61966-2-5 */
    904  1.1  riastrad 	{ DRM_MODE_COLORIMETRY_OPRGB, "opRGB" },
    905  1.1  riastrad 	/* Colorimetry based on SMPTE RP 431-2 */
    906  1.1  riastrad 	{ DRM_MODE_COLORIMETRY_DCI_P3_RGB_D65, "DCI-P3_RGB_D65" },
    907  1.1  riastrad 	/* Colorimetry based on ITU-R BT.2020 */
    908  1.1  riastrad 	{ DRM_MODE_COLORIMETRY_BT2020_RGB, "BT2020_RGB" },
    909  1.1  riastrad 	{ DRM_MODE_COLORIMETRY_BT601_YCC, "BT601_YCC" },
    910  1.1  riastrad 	{ DRM_MODE_COLORIMETRY_BT709_YCC, "BT709_YCC" },
    911  1.1  riastrad 	/* Standard Definition Colorimetry based on IEC 61966-2-4 */
    912  1.1  riastrad 	{ DRM_MODE_COLORIMETRY_XVYCC_601, "XVYCC_601" },
    913  1.1  riastrad 	/* High Definition Colorimetry based on IEC 61966-2-4 */
    914  1.1  riastrad 	{ DRM_MODE_COLORIMETRY_XVYCC_709, "XVYCC_709" },
    915  1.1  riastrad 	/* Colorimetry based on IEC 61966-2-1/Amendment 1 */
    916  1.1  riastrad 	{ DRM_MODE_COLORIMETRY_SYCC_601, "SYCC_601" },
    917  1.1  riastrad 	/* Colorimetry based on IEC 61966-2-5 [33] */
    918  1.1  riastrad 	{ DRM_MODE_COLORIMETRY_OPYCC_601, "opYCC_601" },
    919  1.1  riastrad 	/* Colorimetry based on ITU-R BT.2020 */
    920  1.1  riastrad 	{ DRM_MODE_COLORIMETRY_BT2020_CYCC, "BT2020_CYCC" },
    921  1.1  riastrad 	/* Colorimetry based on ITU-R BT.2020 */
    922  1.1  riastrad 	{ DRM_MODE_COLORIMETRY_BT2020_YCC, "BT2020_YCC" },
    923  1.1  riastrad };
    924  1.1  riastrad 
    925  1.1  riastrad /**
    926  1.1  riastrad  * DOC: standard connector properties
    927  1.1  riastrad  *
    928  1.1  riastrad  * DRM connectors have a few standardized properties:
    929  1.1  riastrad  *
    930  1.1  riastrad  * EDID:
    931  1.1  riastrad  * 	Blob property which contains the current EDID read from the sink. This
    932  1.1  riastrad  * 	is useful to parse sink identification information like vendor, model
    933  1.1  riastrad  * 	and serial. Drivers should update this property by calling
    934  1.1  riastrad  * 	drm_connector_update_edid_property(), usually after having parsed
    935  1.1  riastrad  * 	the EDID using drm_add_edid_modes(). Userspace cannot change this
    936  1.1  riastrad  * 	property.
    937  1.1  riastrad  * DPMS:
    938  1.1  riastrad  * 	Legacy property for setting the power state of the connector. For atomic
    939  1.1  riastrad  * 	drivers this is only provided for backwards compatibility with existing
    940  1.1  riastrad  * 	drivers, it remaps to controlling the "ACTIVE" property on the CRTC the
    941  1.1  riastrad  * 	connector is linked to. Drivers should never set this property directly,
    942  1.1  riastrad  * 	it is handled by the DRM core by calling the &drm_connector_funcs.dpms
    943  1.1  riastrad  * 	callback. For atomic drivers the remapping to the "ACTIVE" property is
    944  1.1  riastrad  * 	implemented in the DRM core.  This is the only standard connector
    945  1.1  riastrad  * 	property that userspace can change.
    946  1.1  riastrad  *
    947  1.1  riastrad  * 	Note that this property cannot be set through the MODE_ATOMIC ioctl,
    948  1.1  riastrad  * 	userspace must use "ACTIVE" on the CRTC instead.
    949  1.1  riastrad  *
    950  1.1  riastrad  * 	WARNING:
    951  1.1  riastrad  *
    952  1.1  riastrad  * 	For userspace also running on legacy drivers the "DPMS" semantics are a
    953  1.1  riastrad  * 	lot more complicated. First, userspace cannot rely on the "DPMS" value
    954  1.1  riastrad  * 	returned by the GETCONNECTOR actually reflecting reality, because many
    955  1.1  riastrad  * 	drivers fail to update it. For atomic drivers this is taken care of in
    956  1.1  riastrad  * 	drm_atomic_helper_update_legacy_modeset_state().
    957  1.1  riastrad  *
    958  1.1  riastrad  * 	The second issue is that the DPMS state is only well-defined when the
    959  1.1  riastrad  * 	connector is connected to a CRTC. In atomic the DRM core enforces that
    960  1.1  riastrad  * 	"ACTIVE" is off in such a case, no such checks exists for "DPMS".
    961  1.1  riastrad  *
    962  1.1  riastrad  * 	Finally, when enabling an output using the legacy SETCONFIG ioctl then
    963  1.1  riastrad  * 	"DPMS" is forced to ON. But see above, that might not be reflected in
    964  1.1  riastrad  * 	the software value on legacy drivers.
    965  1.1  riastrad  *
    966  1.1  riastrad  * 	Summarizing: Only set "DPMS" when the connector is known to be enabled,
    967  1.1  riastrad  * 	assume that a successful SETCONFIG call also sets "DPMS" to on, and
    968  1.1  riastrad  * 	never read back the value of "DPMS" because it can be incorrect.
    969  1.1  riastrad  * PATH:
    970  1.1  riastrad  * 	Connector path property to identify how this sink is physically
    971  1.1  riastrad  * 	connected. Used by DP MST. This should be set by calling
    972  1.1  riastrad  * 	drm_connector_set_path_property(), in the case of DP MST with the
    973  1.1  riastrad  * 	path property the MST manager created. Userspace cannot change this
    974  1.1  riastrad  * 	property.
    975  1.1  riastrad  * TILE:
    976  1.1  riastrad  * 	Connector tile group property to indicate how a set of DRM connector
    977  1.1  riastrad  * 	compose together into one logical screen. This is used by both high-res
    978  1.1  riastrad  * 	external screens (often only using a single cable, but exposing multiple
    979  1.1  riastrad  * 	DP MST sinks), or high-res integrated panels (like dual-link DSI) which
    980  1.1  riastrad  * 	are not gen-locked. Note that for tiled panels which are genlocked, like
    981  1.1  riastrad  * 	dual-link LVDS or dual-link DSI, the driver should try to not expose the
    982  1.1  riastrad  * 	tiling and virtualize both &drm_crtc and &drm_plane if needed. Drivers
    983  1.1  riastrad  * 	should update this value using drm_connector_set_tile_property().
    984  1.1  riastrad  * 	Userspace cannot change this property.
    985  1.1  riastrad  * link-status:
    986  1.1  riastrad  *      Connector link-status property to indicate the status of link. The
    987  1.1  riastrad  *      default value of link-status is "GOOD". If something fails during or
    988  1.1  riastrad  *      after modeset, the kernel driver may set this to "BAD" and issue a
    989  1.1  riastrad  *      hotplug uevent. Drivers should update this value using
    990  1.1  riastrad  *      drm_connector_set_link_status_property().
    991  1.1  riastrad  * non_desktop:
    992  1.1  riastrad  * 	Indicates the output should be ignored for purposes of displaying a
    993  1.1  riastrad  * 	standard desktop environment or console. This is most likely because
    994  1.1  riastrad  * 	the output device is not rectilinear.
    995  1.1  riastrad  * Content Protection:
    996  1.1  riastrad  *	This property is used by userspace to request the kernel protect future
    997  1.1  riastrad  *	content communicated over the link. When requested, kernel will apply
    998  1.1  riastrad  *	the appropriate means of protection (most often HDCP), and use the
    999  1.1  riastrad  *	property to tell userspace the protection is active.
   1000  1.1  riastrad  *
   1001  1.1  riastrad  *	Drivers can set this up by calling
   1002  1.1  riastrad  *	drm_connector_attach_content_protection_property() on initialization.
   1003  1.1  riastrad  *
   1004  1.1  riastrad  *	The value of this property can be one of the following:
   1005  1.1  riastrad  *
   1006  1.1  riastrad  *	DRM_MODE_CONTENT_PROTECTION_UNDESIRED = 0
   1007  1.1  riastrad  *		The link is not protected, content is transmitted in the clear.
   1008  1.1  riastrad  *	DRM_MODE_CONTENT_PROTECTION_DESIRED = 1
   1009  1.1  riastrad  *		Userspace has requested content protection, but the link is not
   1010  1.1  riastrad  *		currently protected. When in this state, kernel should enable
   1011  1.1  riastrad  *		Content Protection as soon as possible.
   1012  1.1  riastrad  *	DRM_MODE_CONTENT_PROTECTION_ENABLED = 2
   1013  1.1  riastrad  *		Userspace has requested content protection, and the link is
   1014  1.1  riastrad  *		protected. Only the driver can set the property to this value.
   1015  1.1  riastrad  *		If userspace attempts to set to ENABLED, kernel will return
   1016  1.1  riastrad  *		-EINVAL.
   1017  1.1  riastrad  *
   1018  1.1  riastrad  *	A few guidelines:
   1019  1.1  riastrad  *
   1020  1.1  riastrad  *	- DESIRED state should be preserved until userspace de-asserts it by
   1021  1.1  riastrad  *	  setting the property to UNDESIRED. This means ENABLED should only
   1022  1.1  riastrad  *	  transition to UNDESIRED when the user explicitly requests it.
   1023  1.1  riastrad  *	- If the state is DESIRED, kernel should attempt to re-authenticate the
   1024  1.1  riastrad  *	  link whenever possible. This includes across disable/enable, dpms,
   1025  1.1  riastrad  *	  hotplug, downstream device changes, link status failures, etc..
   1026  1.1  riastrad  *	- Kernel sends uevent with the connector id and property id through
   1027  1.1  riastrad  *	  @drm_hdcp_update_content_protection, upon below kernel triggered
   1028  1.1  riastrad  *	  scenarios:
   1029  1.1  riastrad  *
   1030  1.1  riastrad  *		- DESIRED -> ENABLED (authentication success)
   1031  1.1  riastrad  *		- ENABLED -> DESIRED (termination of authentication)
   1032  1.1  riastrad  *	- Please note no uevents for userspace triggered property state changes,
   1033  1.1  riastrad  *	  which can't fail such as
   1034  1.1  riastrad  *
   1035  1.1  riastrad  *		- DESIRED/ENABLED -> UNDESIRED
   1036  1.1  riastrad  *		- UNDESIRED -> DESIRED
   1037  1.1  riastrad  *	- Userspace is responsible for polling the property or listen to uevents
   1038  1.1  riastrad  *	  to determine when the value transitions from ENABLED to DESIRED.
   1039  1.1  riastrad  *	  This signifies the link is no longer protected and userspace should
   1040  1.1  riastrad  *	  take appropriate action (whatever that might be).
   1041  1.1  riastrad  *
   1042  1.1  riastrad  * HDCP Content Type:
   1043  1.1  riastrad  *	This Enum property is used by the userspace to declare the content type
   1044  1.1  riastrad  *	of the display stream, to kernel. Here display stream stands for any
   1045  1.1  riastrad  *	display content that userspace intended to display through HDCP
   1046  1.1  riastrad  *	encryption.
   1047  1.1  riastrad  *
   1048  1.1  riastrad  *	Content Type of a stream is decided by the owner of the stream, as
   1049  1.1  riastrad  *	"HDCP Type0" or "HDCP Type1".
   1050  1.1  riastrad  *
   1051  1.1  riastrad  *	The value of the property can be one of the below:
   1052  1.1  riastrad  *	  - "HDCP Type0": DRM_MODE_HDCP_CONTENT_TYPE0 = 0
   1053  1.1  riastrad  *	  - "HDCP Type1": DRM_MODE_HDCP_CONTENT_TYPE1 = 1
   1054  1.1  riastrad  *
   1055  1.1  riastrad  *	When kernel starts the HDCP authentication (see "Content Protection"
   1056  1.1  riastrad  *	for details), it uses the content type in "HDCP Content Type"
   1057  1.1  riastrad  *	for performing the HDCP authentication with the display sink.
   1058  1.1  riastrad  *
   1059  1.1  riastrad  *	Please note in HDCP spec versions, a link can be authenticated with
   1060  1.1  riastrad  *	HDCP 2.2 for Content Type 0/Content Type 1. Where as a link can be
   1061  1.1  riastrad  *	authenticated with HDCP1.4 only for Content Type 0(though it is implicit
   1062  1.1  riastrad  *	in nature. As there is no reference for Content Type in HDCP1.4).
   1063  1.1  riastrad  *
   1064  1.1  riastrad  *	HDCP2.2 authentication protocol itself takes the "Content Type" as a
   1065  1.1  riastrad  *	parameter, which is a input for the DP HDCP2.2 encryption algo.
   1066  1.1  riastrad  *
   1067  1.1  riastrad  *	In case of Type 0 content protection request, kernel driver can choose
   1068  1.1  riastrad  *	either of HDCP spec versions 1.4 and 2.2. When HDCP2.2 is used for
   1069  1.1  riastrad  *	"HDCP Type 0", a HDCP 2.2 capable repeater in the downstream can send
   1070  1.1  riastrad  *	that content to a HDCP 1.4 authenticated HDCP sink (Type0 link).
   1071  1.1  riastrad  *	But if the content is classified as "HDCP Type 1", above mentioned
   1072  1.1  riastrad  *	HDCP 2.2 repeater wont send the content to the HDCP sink as it can't
   1073  1.1  riastrad  *	authenticate the HDCP1.4 capable sink for "HDCP Type 1".
   1074  1.1  riastrad  *
   1075  1.1  riastrad  *	Please note userspace can be ignorant of the HDCP versions used by the
   1076  1.1  riastrad  *	kernel driver to achieve the "HDCP Content Type".
   1077  1.1  riastrad  *
   1078  1.1  riastrad  *	At current scenario, classifying a content as Type 1 ensures that the
   1079  1.1  riastrad  *	content will be displayed only through the HDCP2.2 encrypted link.
   1080  1.1  riastrad  *
   1081  1.1  riastrad  *	Note that the HDCP Content Type property is introduced at HDCP 2.2, and
   1082  1.1  riastrad  *	defaults to type 0. It is only exposed by drivers supporting HDCP 2.2
   1083  1.1  riastrad  *	(hence supporting Type 0 and Type 1). Based on how next versions of
   1084  1.1  riastrad  *	HDCP specs are defined content Type could be used for higher versions
   1085  1.1  riastrad  *	too.
   1086  1.1  riastrad  *
   1087  1.1  riastrad  *	If content type is changed when "Content Protection" is not UNDESIRED,
   1088  1.1  riastrad  *	then kernel will disable the HDCP and re-enable with new type in the
   1089  1.1  riastrad  *	same atomic commit. And when "Content Protection" is ENABLED, it means
   1090  1.1  riastrad  *	that link is HDCP authenticated and encrypted, for the transmission of
   1091  1.1  riastrad  *	the Type of stream mentioned at "HDCP Content Type".
   1092  1.1  riastrad  *
   1093  1.1  riastrad  * HDR_OUTPUT_METADATA:
   1094  1.1  riastrad  *	Connector property to enable userspace to send HDR Metadata to
   1095  1.1  riastrad  *	driver. This metadata is based on the composition and blending
   1096  1.1  riastrad  *	policies decided by user, taking into account the hardware and
   1097  1.1  riastrad  *	sink capabilities. The driver gets this metadata and creates a
   1098  1.1  riastrad  *	Dynamic Range and Mastering Infoframe (DRM) in case of HDMI,
   1099  1.1  riastrad  *	SDP packet (Non-audio INFOFRAME SDP v1.3) for DP. This is then
   1100  1.1  riastrad  *	sent to sink. This notifies the sink of the upcoming frame's Color
   1101  1.1  riastrad  *	Encoding and Luminance parameters.
   1102  1.1  riastrad  *
   1103  1.1  riastrad  *	Userspace first need to detect the HDR capabilities of sink by
   1104  1.1  riastrad  *	reading and parsing the EDID. Details of HDR metadata for HDMI
   1105  1.1  riastrad  *	are added in CTA 861.G spec. For DP , its defined in VESA DP
   1106  1.1  riastrad  *	Standard v1.4. It needs to then get the metadata information
   1107  1.1  riastrad  *	of the video/game/app content which are encoded in HDR (basically
   1108  1.1  riastrad  *	using HDR transfer functions). With this information it needs to
   1109  1.1  riastrad  *	decide on a blending policy and compose the relevant
   1110  1.1  riastrad  *	layers/overlays into a common format. Once this blending is done,
   1111  1.1  riastrad  *	userspace will be aware of the metadata of the composed frame to
   1112  1.1  riastrad  *	be send to sink. It then uses this property to communicate this
   1113  1.1  riastrad  *	metadata to driver which then make a Infoframe packet and sends
   1114  1.1  riastrad  *	to sink based on the type of encoder connected.
   1115  1.1  riastrad  *
   1116  1.1  riastrad  *	Userspace will be responsible to do Tone mapping operation in case:
   1117  1.1  riastrad  *		- Some layers are HDR and others are SDR
   1118  1.1  riastrad  *		- HDR layers luminance is not same as sink
   1119  1.1  riastrad  *
   1120  1.1  riastrad  *	It will even need to do colorspace conversion and get all layers
   1121  1.1  riastrad  *	to one common colorspace for blending. It can use either GL, Media
   1122  1.1  riastrad  *	or display engine to get this done based on the capabilties of the
   1123  1.1  riastrad  *	associated hardware.
   1124  1.1  riastrad  *
   1125  1.1  riastrad  *	Driver expects metadata to be put in &struct hdr_output_metadata
   1126  1.1  riastrad  *	structure from userspace. This is received as blob and stored in
   1127  1.1  riastrad  *	&drm_connector_state.hdr_output_metadata. It parses EDID and saves the
   1128  1.1  riastrad  *	sink metadata in &struct hdr_sink_metadata, as
   1129  1.1  riastrad  *	&drm_connector.hdr_sink_metadata.  Driver uses
   1130  1.1  riastrad  *	drm_hdmi_infoframe_set_hdr_metadata() helper to set the HDR metadata,
   1131  1.1  riastrad  *	hdmi_drm_infoframe_pack() to pack the infoframe as per spec, in case of
   1132  1.1  riastrad  *	HDMI encoder.
   1133  1.1  riastrad  *
   1134  1.1  riastrad  * max bpc:
   1135  1.1  riastrad  *	This range property is used by userspace to limit the bit depth. When
   1136  1.1  riastrad  *	used the driver would limit the bpc in accordance with the valid range
   1137  1.1  riastrad  *	supported by the hardware and sink. Drivers to use the function
   1138  1.1  riastrad  *	drm_connector_attach_max_bpc_property() to create and attach the
   1139  1.1  riastrad  *	property to the connector during initialization.
   1140  1.1  riastrad  *
   1141  1.1  riastrad  * Connectors also have one standardized atomic property:
   1142  1.1  riastrad  *
   1143  1.1  riastrad  * CRTC_ID:
   1144  1.1  riastrad  * 	Mode object ID of the &drm_crtc this connector should be connected to.
   1145  1.1  riastrad  *
   1146  1.1  riastrad  * Connectors for LCD panels may also have one standardized property:
   1147  1.1  riastrad  *
   1148  1.1  riastrad  * panel orientation:
   1149  1.1  riastrad  *	On some devices the LCD panel is mounted in the casing in such a way
   1150  1.1  riastrad  *	that the up/top side of the panel does not match with the top side of
   1151  1.1  riastrad  *	the device. Userspace can use this property to check for this.
   1152  1.1  riastrad  *	Note that input coordinates from touchscreens (input devices with
   1153  1.1  riastrad  *	INPUT_PROP_DIRECT) will still map 1:1 to the actual LCD panel
   1154  1.1  riastrad  *	coordinates, so if userspace rotates the picture to adjust for
   1155  1.1  riastrad  *	the orientation it must also apply the same transformation to the
   1156  1.1  riastrad  *	touchscreen input coordinates. This property is initialized by calling
   1157  1.1  riastrad  *	drm_connector_init_panel_orientation_property().
   1158  1.1  riastrad  *
   1159  1.1  riastrad  * scaling mode:
   1160  1.1  riastrad  *	This property defines how a non-native mode is upscaled to the native
   1161  1.1  riastrad  *	mode of an LCD panel:
   1162  1.1  riastrad  *
   1163  1.1  riastrad  *	None:
   1164  1.1  riastrad  *		No upscaling happens, scaling is left to the panel. Not all
   1165  1.1  riastrad  *		drivers expose this mode.
   1166  1.1  riastrad  *	Full:
   1167  1.1  riastrad  *		The output is upscaled to the full resolution of the panel,
   1168  1.1  riastrad  *		ignoring the aspect ratio.
   1169  1.1  riastrad  *	Center:
   1170  1.1  riastrad  *		No upscaling happens, the output is centered within the native
   1171  1.1  riastrad  *		resolution the panel.
   1172  1.1  riastrad  *	Full aspect:
   1173  1.1  riastrad  *		The output is upscaled to maximize either the width or height
   1174  1.1  riastrad  *		while retaining the aspect ratio.
   1175  1.1  riastrad  *
   1176  1.1  riastrad  *	This property should be set up by calling
   1177  1.1  riastrad  *	drm_connector_attach_scaling_mode_property(). Note that drivers
   1178  1.1  riastrad  *	can also expose this property to external outputs, in which case they
   1179  1.1  riastrad  *	must support "None", which should be the default (since external screens
   1180  1.1  riastrad  *	have a built-in scaler).
   1181  1.1  riastrad  */
   1182  1.1  riastrad 
   1183  1.1  riastrad int drm_connector_create_standard_properties(struct drm_device *dev)
   1184  1.1  riastrad {
   1185  1.1  riastrad 	struct drm_property *prop;
   1186  1.1  riastrad 
   1187  1.1  riastrad 	prop = drm_property_create(dev, DRM_MODE_PROP_BLOB |
   1188  1.1  riastrad 				   DRM_MODE_PROP_IMMUTABLE,
   1189  1.1  riastrad 				   "EDID", 0);
   1190  1.1  riastrad 	if (!prop)
   1191  1.1  riastrad 		return -ENOMEM;
   1192  1.1  riastrad 	dev->mode_config.edid_property = prop;
   1193  1.1  riastrad 
   1194  1.1  riastrad 	prop = drm_property_create_enum(dev, 0,
   1195  1.1  riastrad 				   "DPMS", drm_dpms_enum_list,
   1196  1.1  riastrad 				   ARRAY_SIZE(drm_dpms_enum_list));
   1197  1.1  riastrad 	if (!prop)
   1198  1.1  riastrad 		return -ENOMEM;
   1199  1.1  riastrad 	dev->mode_config.dpms_property = prop;
   1200  1.1  riastrad 
   1201  1.1  riastrad 	prop = drm_property_create(dev,
   1202  1.1  riastrad 				   DRM_MODE_PROP_BLOB |
   1203  1.1  riastrad 				   DRM_MODE_PROP_IMMUTABLE,
   1204  1.1  riastrad 				   "PATH", 0);
   1205  1.1  riastrad 	if (!prop)
   1206  1.1  riastrad 		return -ENOMEM;
   1207  1.1  riastrad 	dev->mode_config.path_property = prop;
   1208  1.1  riastrad 
   1209  1.1  riastrad 	prop = drm_property_create(dev,
   1210  1.1  riastrad 				   DRM_MODE_PROP_BLOB |
   1211  1.1  riastrad 				   DRM_MODE_PROP_IMMUTABLE,
   1212  1.1  riastrad 				   "TILE", 0);
   1213  1.1  riastrad 	if (!prop)
   1214  1.1  riastrad 		return -ENOMEM;
   1215  1.1  riastrad 	dev->mode_config.tile_property = prop;
   1216  1.1  riastrad 
   1217  1.1  riastrad 	prop = drm_property_create_enum(dev, 0, "link-status",
   1218  1.1  riastrad 					drm_link_status_enum_list,
   1219  1.1  riastrad 					ARRAY_SIZE(drm_link_status_enum_list));
   1220  1.1  riastrad 	if (!prop)
   1221  1.1  riastrad 		return -ENOMEM;
   1222  1.1  riastrad 	dev->mode_config.link_status_property = prop;
   1223  1.1  riastrad 
   1224  1.1  riastrad 	prop = drm_property_create_bool(dev, DRM_MODE_PROP_IMMUTABLE, "non-desktop");
   1225  1.1  riastrad 	if (!prop)
   1226  1.1  riastrad 		return -ENOMEM;
   1227  1.1  riastrad 	dev->mode_config.non_desktop_property = prop;
   1228  1.1  riastrad 
   1229  1.1  riastrad 	prop = drm_property_create(dev, DRM_MODE_PROP_BLOB,
   1230  1.1  riastrad 				   "HDR_OUTPUT_METADATA", 0);
   1231  1.1  riastrad 	if (!prop)
   1232  1.1  riastrad 		return -ENOMEM;
   1233  1.1  riastrad 	dev->mode_config.hdr_output_metadata_property = prop;
   1234  1.1  riastrad 
   1235  1.1  riastrad 	return 0;
   1236  1.1  riastrad }
   1237  1.1  riastrad 
   1238  1.1  riastrad /**
   1239  1.1  riastrad  * drm_mode_create_dvi_i_properties - create DVI-I specific connector properties
   1240  1.1  riastrad  * @dev: DRM device
   1241  1.1  riastrad  *
   1242  1.1  riastrad  * Called by a driver the first time a DVI-I connector is made.
   1243  1.1  riastrad  */
   1244  1.1  riastrad int drm_mode_create_dvi_i_properties(struct drm_device *dev)
   1245  1.1  riastrad {
   1246  1.1  riastrad 	struct drm_property *dvi_i_selector;
   1247  1.1  riastrad 	struct drm_property *dvi_i_subconnector;
   1248  1.1  riastrad 
   1249  1.1  riastrad 	if (dev->mode_config.dvi_i_select_subconnector_property)
   1250  1.1  riastrad 		return 0;
   1251  1.1  riastrad 
   1252  1.1  riastrad 	dvi_i_selector =
   1253  1.1  riastrad 		drm_property_create_enum(dev, 0,
   1254  1.1  riastrad 				    "select subconnector",
   1255  1.1  riastrad 				    drm_dvi_i_select_enum_list,
   1256  1.1  riastrad 				    ARRAY_SIZE(drm_dvi_i_select_enum_list));
   1257  1.1  riastrad 	dev->mode_config.dvi_i_select_subconnector_property = dvi_i_selector;
   1258  1.1  riastrad 
   1259  1.1  riastrad 	dvi_i_subconnector = drm_property_create_enum(dev, DRM_MODE_PROP_IMMUTABLE,
   1260  1.1  riastrad 				    "subconnector",
   1261  1.1  riastrad 				    drm_dvi_i_subconnector_enum_list,
   1262  1.1  riastrad 				    ARRAY_SIZE(drm_dvi_i_subconnector_enum_list));
   1263  1.1  riastrad 	dev->mode_config.dvi_i_subconnector_property = dvi_i_subconnector;
   1264  1.1  riastrad 
   1265  1.1  riastrad 	return 0;
   1266  1.1  riastrad }
   1267  1.1  riastrad EXPORT_SYMBOL(drm_mode_create_dvi_i_properties);
   1268  1.1  riastrad 
   1269  1.1  riastrad /**
   1270  1.1  riastrad  * DOC: HDMI connector properties
   1271  1.1  riastrad  *
   1272  1.1  riastrad  * content type (HDMI specific):
   1273  1.1  riastrad  *	Indicates content type setting to be used in HDMI infoframes to indicate
   1274  1.1  riastrad  *	content type for the external device, so that it adjusts its display
   1275  1.1  riastrad  *	settings accordingly.
   1276  1.1  riastrad  *
   1277  1.1  riastrad  *	The value of this property can be one of the following:
   1278  1.1  riastrad  *
   1279  1.1  riastrad  *	No Data:
   1280  1.1  riastrad  *		Content type is unknown
   1281  1.1  riastrad  *	Graphics:
   1282  1.1  riastrad  *		Content type is graphics
   1283  1.1  riastrad  *	Photo:
   1284  1.1  riastrad  *		Content type is photo
   1285  1.1  riastrad  *	Cinema:
   1286  1.1  riastrad  *		Content type is cinema
   1287  1.1  riastrad  *	Game:
   1288  1.1  riastrad  *		Content type is game
   1289  1.1  riastrad  *
   1290  1.1  riastrad  *	Drivers can set up this property by calling
   1291  1.1  riastrad  *	drm_connector_attach_content_type_property(). Decoding to
   1292  1.1  riastrad  *	infoframe values is done through drm_hdmi_avi_infoframe_content_type().
   1293  1.1  riastrad  */
   1294  1.1  riastrad 
   1295  1.1  riastrad /**
   1296  1.1  riastrad  * drm_connector_attach_content_type_property - attach content-type property
   1297  1.1  riastrad  * @connector: connector to attach content type property on.
   1298  1.1  riastrad  *
   1299  1.1  riastrad  * Called by a driver the first time a HDMI connector is made.
   1300  1.1  riastrad  */
   1301  1.1  riastrad int drm_connector_attach_content_type_property(struct drm_connector *connector)
   1302  1.1  riastrad {
   1303  1.1  riastrad 	if (!drm_mode_create_content_type_property(connector->dev))
   1304  1.1  riastrad 		drm_object_attach_property(&connector->base,
   1305  1.1  riastrad 					   connector->dev->mode_config.content_type_property,
   1306  1.1  riastrad 					   DRM_MODE_CONTENT_TYPE_NO_DATA);
   1307  1.1  riastrad 	return 0;
   1308  1.1  riastrad }
   1309  1.1  riastrad EXPORT_SYMBOL(drm_connector_attach_content_type_property);
   1310  1.1  riastrad 
   1311  1.1  riastrad 
   1312  1.1  riastrad /**
   1313  1.1  riastrad  * drm_hdmi_avi_infoframe_content_type() - fill the HDMI AVI infoframe
   1314  1.1  riastrad  *                                         content type information, based
   1315  1.1  riastrad  *                                         on correspondent DRM property.
   1316  1.1  riastrad  * @frame: HDMI AVI infoframe
   1317  1.1  riastrad  * @conn_state: DRM display connector state
   1318  1.1  riastrad  *
   1319  1.1  riastrad  */
   1320  1.1  riastrad void drm_hdmi_avi_infoframe_content_type(struct hdmi_avi_infoframe *frame,
   1321  1.1  riastrad 					 const struct drm_connector_state *conn_state)
   1322  1.1  riastrad {
   1323  1.1  riastrad 	switch (conn_state->content_type) {
   1324  1.1  riastrad 	case DRM_MODE_CONTENT_TYPE_GRAPHICS:
   1325  1.1  riastrad 		frame->content_type = HDMI_CONTENT_TYPE_GRAPHICS;
   1326  1.1  riastrad 		break;
   1327  1.1  riastrad 	case DRM_MODE_CONTENT_TYPE_CINEMA:
   1328  1.1  riastrad 		frame->content_type = HDMI_CONTENT_TYPE_CINEMA;
   1329  1.1  riastrad 		break;
   1330  1.1  riastrad 	case DRM_MODE_CONTENT_TYPE_GAME:
   1331  1.1  riastrad 		frame->content_type = HDMI_CONTENT_TYPE_GAME;
   1332  1.1  riastrad 		break;
   1333  1.1  riastrad 	case DRM_MODE_CONTENT_TYPE_PHOTO:
   1334  1.1  riastrad 		frame->content_type = HDMI_CONTENT_TYPE_PHOTO;
   1335  1.1  riastrad 		break;
   1336  1.1  riastrad 	default:
   1337  1.1  riastrad 		/* Graphics is the default(0) */
   1338  1.1  riastrad 		frame->content_type = HDMI_CONTENT_TYPE_GRAPHICS;
   1339  1.1  riastrad 	}
   1340  1.1  riastrad 
   1341  1.1  riastrad 	frame->itc = conn_state->content_type != DRM_MODE_CONTENT_TYPE_NO_DATA;
   1342  1.1  riastrad }
   1343  1.1  riastrad EXPORT_SYMBOL(drm_hdmi_avi_infoframe_content_type);
   1344  1.1  riastrad 
   1345  1.1  riastrad /**
   1346  1.1  riastrad  * drm_mode_attach_tv_margin_properties - attach TV connector margin properties
   1347  1.1  riastrad  * @connector: DRM connector
   1348  1.1  riastrad  *
   1349  1.1  riastrad  * Called by a driver when it needs to attach TV margin props to a connector.
   1350  1.1  riastrad  * Typically used on SDTV and HDMI connectors.
   1351  1.1  riastrad  */
   1352  1.1  riastrad void drm_connector_attach_tv_margin_properties(struct drm_connector *connector)
   1353  1.1  riastrad {
   1354  1.1  riastrad 	struct drm_device *dev = connector->dev;
   1355  1.1  riastrad 
   1356  1.1  riastrad 	drm_object_attach_property(&connector->base,
   1357  1.1  riastrad 				   dev->mode_config.tv_left_margin_property,
   1358  1.1  riastrad 				   0);
   1359  1.1  riastrad 	drm_object_attach_property(&connector->base,
   1360  1.1  riastrad 				   dev->mode_config.tv_right_margin_property,
   1361  1.1  riastrad 				   0);
   1362  1.1  riastrad 	drm_object_attach_property(&connector->base,
   1363  1.1  riastrad 				   dev->mode_config.tv_top_margin_property,
   1364  1.1  riastrad 				   0);
   1365  1.1  riastrad 	drm_object_attach_property(&connector->base,
   1366  1.1  riastrad 				   dev->mode_config.tv_bottom_margin_property,
   1367  1.1  riastrad 				   0);
   1368  1.1  riastrad }
   1369  1.1  riastrad EXPORT_SYMBOL(drm_connector_attach_tv_margin_properties);
   1370  1.1  riastrad 
   1371  1.1  riastrad /**
   1372  1.1  riastrad  * drm_mode_create_tv_margin_properties - create TV connector margin properties
   1373  1.1  riastrad  * @dev: DRM device
   1374  1.1  riastrad  *
   1375  1.1  riastrad  * Called by a driver's HDMI connector initialization routine, this function
   1376  1.1  riastrad  * creates the TV margin properties for a given device. No need to call this
   1377  1.1  riastrad  * function for an SDTV connector, it's already called from
   1378  1.1  riastrad  * drm_mode_create_tv_properties().
   1379  1.1  riastrad  */
   1380  1.1  riastrad int drm_mode_create_tv_margin_properties(struct drm_device *dev)
   1381  1.1  riastrad {
   1382  1.1  riastrad 	if (dev->mode_config.tv_left_margin_property)
   1383  1.1  riastrad 		return 0;
   1384  1.1  riastrad 
   1385  1.1  riastrad 	dev->mode_config.tv_left_margin_property =
   1386  1.1  riastrad 		drm_property_create_range(dev, 0, "left margin", 0, 100);
   1387  1.1  riastrad 	if (!dev->mode_config.tv_left_margin_property)
   1388  1.1  riastrad 		return -ENOMEM;
   1389  1.1  riastrad 
   1390  1.1  riastrad 	dev->mode_config.tv_right_margin_property =
   1391  1.1  riastrad 		drm_property_create_range(dev, 0, "right margin", 0, 100);
   1392  1.1  riastrad 	if (!dev->mode_config.tv_right_margin_property)
   1393  1.1  riastrad 		return -ENOMEM;
   1394  1.1  riastrad 
   1395  1.1  riastrad 	dev->mode_config.tv_top_margin_property =
   1396  1.1  riastrad 		drm_property_create_range(dev, 0, "top margin", 0, 100);
   1397  1.1  riastrad 	if (!dev->mode_config.tv_top_margin_property)
   1398  1.1  riastrad 		return -ENOMEM;
   1399  1.1  riastrad 
   1400  1.1  riastrad 	dev->mode_config.tv_bottom_margin_property =
   1401  1.1  riastrad 		drm_property_create_range(dev, 0, "bottom margin", 0, 100);
   1402  1.1  riastrad 	if (!dev->mode_config.tv_bottom_margin_property)
   1403  1.1  riastrad 		return -ENOMEM;
   1404  1.1  riastrad 
   1405  1.1  riastrad 	return 0;
   1406  1.1  riastrad }
   1407  1.1  riastrad EXPORT_SYMBOL(drm_mode_create_tv_margin_properties);
   1408  1.1  riastrad 
   1409  1.1  riastrad /**
   1410  1.1  riastrad  * drm_mode_create_tv_properties - create TV specific connector properties
   1411  1.1  riastrad  * @dev: DRM device
   1412  1.1  riastrad  * @num_modes: number of different TV formats (modes) supported
   1413  1.1  riastrad  * @modes: array of pointers to strings containing name of each format
   1414  1.1  riastrad  *
   1415  1.1  riastrad  * Called by a driver's TV initialization routine, this function creates
   1416  1.1  riastrad  * the TV specific connector properties for a given device.  Caller is
   1417  1.1  riastrad  * responsible for allocating a list of format names and passing them to
   1418  1.1  riastrad  * this routine.
   1419  1.1  riastrad  */
   1420  1.1  riastrad int drm_mode_create_tv_properties(struct drm_device *dev,
   1421  1.1  riastrad 				  unsigned int num_modes,
   1422  1.1  riastrad 				  const char * const modes[])
   1423  1.1  riastrad {
   1424  1.1  riastrad 	struct drm_property *tv_selector;
   1425  1.1  riastrad 	struct drm_property *tv_subconnector;
   1426  1.1  riastrad 	unsigned int i;
   1427  1.1  riastrad 
   1428  1.1  riastrad 	if (dev->mode_config.tv_select_subconnector_property)
   1429  1.1  riastrad 		return 0;
   1430  1.1  riastrad 
   1431  1.1  riastrad 	/*
   1432  1.1  riastrad 	 * Basic connector properties
   1433  1.1  riastrad 	 */
   1434  1.1  riastrad 	tv_selector = drm_property_create_enum(dev, 0,
   1435  1.1  riastrad 					  "select subconnector",
   1436  1.1  riastrad 					  drm_tv_select_enum_list,
   1437  1.1  riastrad 					  ARRAY_SIZE(drm_tv_select_enum_list));
   1438  1.1  riastrad 	if (!tv_selector)
   1439  1.1  riastrad 		goto nomem;
   1440  1.1  riastrad 
   1441  1.1  riastrad 	dev->mode_config.tv_select_subconnector_property = tv_selector;
   1442  1.1  riastrad 
   1443  1.1  riastrad 	tv_subconnector =
   1444  1.1  riastrad 		drm_property_create_enum(dev, DRM_MODE_PROP_IMMUTABLE,
   1445  1.1  riastrad 				    "subconnector",
   1446  1.1  riastrad 				    drm_tv_subconnector_enum_list,
   1447  1.1  riastrad 				    ARRAY_SIZE(drm_tv_subconnector_enum_list));
   1448  1.1  riastrad 	if (!tv_subconnector)
   1449  1.1  riastrad 		goto nomem;
   1450  1.1  riastrad 	dev->mode_config.tv_subconnector_property = tv_subconnector;
   1451  1.1  riastrad 
   1452  1.1  riastrad 	/*
   1453  1.1  riastrad 	 * Other, TV specific properties: margins & TV modes.
   1454  1.1  riastrad 	 */
   1455  1.1  riastrad 	if (drm_mode_create_tv_margin_properties(dev))
   1456  1.1  riastrad 		goto nomem;
   1457  1.1  riastrad 
   1458  1.1  riastrad 	dev->mode_config.tv_mode_property =
   1459  1.1  riastrad 		drm_property_create(dev, DRM_MODE_PROP_ENUM,
   1460  1.1  riastrad 				    "mode", num_modes);
   1461  1.1  riastrad 	if (!dev->mode_config.tv_mode_property)
   1462  1.1  riastrad 		goto nomem;
   1463  1.1  riastrad 
   1464  1.1  riastrad 	for (i = 0; i < num_modes; i++)
   1465  1.1  riastrad 		drm_property_add_enum(dev->mode_config.tv_mode_property,
   1466  1.1  riastrad 				      i, modes[i]);
   1467  1.1  riastrad 
   1468  1.1  riastrad 	dev->mode_config.tv_brightness_property =
   1469  1.1  riastrad 		drm_property_create_range(dev, 0, "brightness", 0, 100);
   1470  1.1  riastrad 	if (!dev->mode_config.tv_brightness_property)
   1471  1.1  riastrad 		goto nomem;
   1472  1.1  riastrad 
   1473  1.1  riastrad 	dev->mode_config.tv_contrast_property =
   1474  1.1  riastrad 		drm_property_create_range(dev, 0, "contrast", 0, 100);
   1475  1.1  riastrad 	if (!dev->mode_config.tv_contrast_property)
   1476  1.1  riastrad 		goto nomem;
   1477  1.1  riastrad 
   1478  1.1  riastrad 	dev->mode_config.tv_flicker_reduction_property =
   1479  1.1  riastrad 		drm_property_create_range(dev, 0, "flicker reduction", 0, 100);
   1480  1.1  riastrad 	if (!dev->mode_config.tv_flicker_reduction_property)
   1481  1.1  riastrad 		goto nomem;
   1482  1.1  riastrad 
   1483  1.1  riastrad 	dev->mode_config.tv_overscan_property =
   1484  1.1  riastrad 		drm_property_create_range(dev, 0, "overscan", 0, 100);
   1485  1.1  riastrad 	if (!dev->mode_config.tv_overscan_property)
   1486  1.1  riastrad 		goto nomem;
   1487  1.1  riastrad 
   1488  1.1  riastrad 	dev->mode_config.tv_saturation_property =
   1489  1.1  riastrad 		drm_property_create_range(dev, 0, "saturation", 0, 100);
   1490  1.1  riastrad 	if (!dev->mode_config.tv_saturation_property)
   1491  1.1  riastrad 		goto nomem;
   1492  1.1  riastrad 
   1493  1.1  riastrad 	dev->mode_config.tv_hue_property =
   1494  1.1  riastrad 		drm_property_create_range(dev, 0, "hue", 0, 100);
   1495  1.1  riastrad 	if (!dev->mode_config.tv_hue_property)
   1496  1.1  riastrad 		goto nomem;
   1497  1.1  riastrad 
   1498  1.1  riastrad 	return 0;
   1499  1.1  riastrad nomem:
   1500  1.1  riastrad 	return -ENOMEM;
   1501  1.1  riastrad }
   1502  1.1  riastrad EXPORT_SYMBOL(drm_mode_create_tv_properties);
   1503  1.1  riastrad 
   1504  1.1  riastrad /**
   1505  1.1  riastrad  * drm_mode_create_scaling_mode_property - create scaling mode property
   1506  1.1  riastrad  * @dev: DRM device
   1507  1.1  riastrad  *
   1508  1.1  riastrad  * Called by a driver the first time it's needed, must be attached to desired
   1509  1.1  riastrad  * connectors.
   1510  1.1  riastrad  *
   1511  1.1  riastrad  * Atomic drivers should use drm_connector_attach_scaling_mode_property()
   1512  1.1  riastrad  * instead to correctly assign &drm_connector_state.picture_aspect_ratio
   1513  1.1  riastrad  * in the atomic state.
   1514  1.1  riastrad  */
   1515  1.1  riastrad int drm_mode_create_scaling_mode_property(struct drm_device *dev)
   1516  1.1  riastrad {
   1517  1.1  riastrad 	struct drm_property *scaling_mode;
   1518  1.1  riastrad 
   1519  1.1  riastrad 	if (dev->mode_config.scaling_mode_property)
   1520  1.1  riastrad 		return 0;
   1521  1.1  riastrad 
   1522  1.1  riastrad 	scaling_mode =
   1523  1.1  riastrad 		drm_property_create_enum(dev, 0, "scaling mode",
   1524  1.1  riastrad 				drm_scaling_mode_enum_list,
   1525  1.1  riastrad 				    ARRAY_SIZE(drm_scaling_mode_enum_list));
   1526  1.1  riastrad 
   1527  1.1  riastrad 	dev->mode_config.scaling_mode_property = scaling_mode;
   1528  1.1  riastrad 
   1529  1.1  riastrad 	return 0;
   1530  1.1  riastrad }
   1531  1.1  riastrad EXPORT_SYMBOL(drm_mode_create_scaling_mode_property);
   1532  1.1  riastrad 
   1533  1.1  riastrad /**
   1534  1.1  riastrad  * DOC: Variable refresh properties
   1535  1.1  riastrad  *
   1536  1.1  riastrad  * Variable refresh rate capable displays can dynamically adjust their
   1537  1.1  riastrad  * refresh rate by extending the duration of their vertical front porch
   1538  1.1  riastrad  * until page flip or timeout occurs. This can reduce or remove stuttering
   1539  1.1  riastrad  * and latency in scenarios where the page flip does not align with the
   1540  1.1  riastrad  * vblank interval.
   1541  1.1  riastrad  *
   1542  1.1  riastrad  * An example scenario would be an application flipping at a constant rate
   1543  1.1  riastrad  * of 48Hz on a 60Hz display. The page flip will frequently miss the vblank
   1544  1.1  riastrad  * interval and the same contents will be displayed twice. This can be
   1545  1.1  riastrad  * observed as stuttering for content with motion.
   1546  1.1  riastrad  *
   1547  1.1  riastrad  * If variable refresh rate was active on a display that supported a
   1548  1.1  riastrad  * variable refresh range from 35Hz to 60Hz no stuttering would be observable
   1549  1.1  riastrad  * for the example scenario. The minimum supported variable refresh rate of
   1550  1.1  riastrad  * 35Hz is below the page flip frequency and the vertical front porch can
   1551  1.1  riastrad  * be extended until the page flip occurs. The vblank interval will be
   1552  1.1  riastrad  * directly aligned to the page flip rate.
   1553  1.1  riastrad  *
   1554  1.1  riastrad  * Not all userspace content is suitable for use with variable refresh rate.
   1555  1.1  riastrad  * Large and frequent changes in vertical front porch duration may worsen
   1556  1.1  riastrad  * perceived stuttering for input sensitive applications.
   1557  1.1  riastrad  *
   1558  1.1  riastrad  * Panel brightness will also vary with vertical front porch duration. Some
   1559  1.1  riastrad  * panels may have noticeable differences in brightness between the minimum
   1560  1.1  riastrad  * vertical front porch duration and the maximum vertical front porch duration.
   1561  1.1  riastrad  * Large and frequent changes in vertical front porch duration may produce
   1562  1.1  riastrad  * observable flickering for such panels.
   1563  1.1  riastrad  *
   1564  1.1  riastrad  * Userspace control for variable refresh rate is supported via properties
   1565  1.1  riastrad  * on the &drm_connector and &drm_crtc objects.
   1566  1.1  riastrad  *
   1567  1.1  riastrad  * "vrr_capable":
   1568  1.1  riastrad  *	Optional &drm_connector boolean property that drivers should attach
   1569  1.1  riastrad  *	with drm_connector_attach_vrr_capable_property() on connectors that
   1570  1.1  riastrad  *	could support variable refresh rates. Drivers should update the
   1571  1.1  riastrad  *	property value by calling drm_connector_set_vrr_capable_property().
   1572  1.1  riastrad  *
   1573  1.1  riastrad  *	Absence of the property should indicate absence of support.
   1574  1.1  riastrad  *
   1575  1.1  riastrad  * "VRR_ENABLED":
   1576  1.1  riastrad  *	Default &drm_crtc boolean property that notifies the driver that the
   1577  1.1  riastrad  *	content on the CRTC is suitable for variable refresh rate presentation.
   1578  1.1  riastrad  *	The driver will take this property as a hint to enable variable
   1579  1.1  riastrad  *	refresh rate support if the receiver supports it, ie. if the
   1580  1.1  riastrad  *	"vrr_capable" property is true on the &drm_connector object. The
   1581  1.1  riastrad  *	vertical front porch duration will be extended until page-flip or
   1582  1.1  riastrad  *	timeout when enabled.
   1583  1.1  riastrad  *
   1584  1.1  riastrad  *	The minimum vertical front porch duration is defined as the vertical
   1585  1.1  riastrad  *	front porch duration for the current mode.
   1586  1.1  riastrad  *
   1587  1.1  riastrad  *	The maximum vertical front porch duration is greater than or equal to
   1588  1.1  riastrad  *	the minimum vertical front porch duration. The duration is derived
   1589  1.1  riastrad  *	from the minimum supported variable refresh rate for the connector.
   1590  1.1  riastrad  *
   1591  1.1  riastrad  *	The driver may place further restrictions within these minimum
   1592  1.1  riastrad  *	and maximum bounds.
   1593  1.1  riastrad  */
   1594  1.1  riastrad 
   1595  1.1  riastrad /**
   1596  1.1  riastrad  * drm_connector_attach_vrr_capable_property - creates the
   1597  1.1  riastrad  * vrr_capable property
   1598  1.1  riastrad  * @connector: connector to create the vrr_capable property on.
   1599  1.1  riastrad  *
   1600  1.1  riastrad  * This is used by atomic drivers to add support for querying
   1601  1.1  riastrad  * variable refresh rate capability for a connector.
   1602  1.1  riastrad  *
   1603  1.1  riastrad  * Returns:
   1604  1.1  riastrad  * Zero on success, negative errono on failure.
   1605  1.1  riastrad  */
   1606  1.1  riastrad int drm_connector_attach_vrr_capable_property(
   1607  1.1  riastrad 	struct drm_connector *connector)
   1608  1.1  riastrad {
   1609  1.1  riastrad 	struct drm_device *dev = connector->dev;
   1610  1.1  riastrad 	struct drm_property *prop;
   1611  1.1  riastrad 
   1612  1.1  riastrad 	if (!connector->vrr_capable_property) {
   1613  1.1  riastrad 		prop = drm_property_create_bool(dev, DRM_MODE_PROP_IMMUTABLE,
   1614  1.1  riastrad 			"vrr_capable");
   1615  1.1  riastrad 		if (!prop)
   1616  1.1  riastrad 			return -ENOMEM;
   1617  1.1  riastrad 
   1618  1.1  riastrad 		connector->vrr_capable_property = prop;
   1619  1.1  riastrad 		drm_object_attach_property(&connector->base, prop, 0);
   1620  1.1  riastrad 	}
   1621  1.1  riastrad 
   1622  1.1  riastrad 	return 0;
   1623  1.1  riastrad }
   1624  1.1  riastrad EXPORT_SYMBOL(drm_connector_attach_vrr_capable_property);
   1625  1.1  riastrad 
   1626  1.1  riastrad /**
   1627  1.1  riastrad  * drm_connector_attach_scaling_mode_property - attach atomic scaling mode property
   1628  1.1  riastrad  * @connector: connector to attach scaling mode property on.
   1629  1.1  riastrad  * @scaling_mode_mask: or'ed mask of BIT(%DRM_MODE_SCALE_\*).
   1630  1.1  riastrad  *
   1631  1.1  riastrad  * This is used to add support for scaling mode to atomic drivers.
   1632  1.1  riastrad  * The scaling mode will be set to &drm_connector_state.picture_aspect_ratio
   1633  1.1  riastrad  * and can be used from &drm_connector_helper_funcs->atomic_check for validation.
   1634  1.1  riastrad  *
   1635  1.1  riastrad  * This is the atomic version of drm_mode_create_scaling_mode_property().
   1636  1.1  riastrad  *
   1637  1.1  riastrad  * Returns:
   1638  1.1  riastrad  * Zero on success, negative errno on failure.
   1639  1.1  riastrad  */
   1640  1.1  riastrad int drm_connector_attach_scaling_mode_property(struct drm_connector *connector,
   1641  1.1  riastrad 					       u32 scaling_mode_mask)
   1642  1.1  riastrad {
   1643  1.1  riastrad 	struct drm_device *dev = connector->dev;
   1644  1.1  riastrad 	struct drm_property *scaling_mode_property;
   1645  1.1  riastrad 	int i;
   1646  1.1  riastrad 	const unsigned valid_scaling_mode_mask =
   1647  1.1  riastrad 		(1U << ARRAY_SIZE(drm_scaling_mode_enum_list)) - 1;
   1648  1.1  riastrad 
   1649  1.1  riastrad 	if (WARN_ON(hweight32(scaling_mode_mask) < 2 ||
   1650  1.1  riastrad 		    scaling_mode_mask & ~valid_scaling_mode_mask))
   1651  1.1  riastrad 		return -EINVAL;
   1652  1.1  riastrad 
   1653  1.1  riastrad 	scaling_mode_property =
   1654  1.1  riastrad 		drm_property_create(dev, DRM_MODE_PROP_ENUM, "scaling mode",
   1655  1.1  riastrad 				    hweight32(scaling_mode_mask));
   1656  1.1  riastrad 
   1657  1.1  riastrad 	if (!scaling_mode_property)
   1658  1.1  riastrad 		return -ENOMEM;
   1659  1.1  riastrad 
   1660  1.1  riastrad 	for (i = 0; i < ARRAY_SIZE(drm_scaling_mode_enum_list); i++) {
   1661  1.1  riastrad 		int ret;
   1662  1.1  riastrad 
   1663  1.1  riastrad 		if (!(BIT(i) & scaling_mode_mask))
   1664  1.1  riastrad 			continue;
   1665  1.1  riastrad 
   1666  1.1  riastrad 		ret = drm_property_add_enum(scaling_mode_property,
   1667  1.1  riastrad 					    drm_scaling_mode_enum_list[i].type,
   1668  1.1  riastrad 					    drm_scaling_mode_enum_list[i].name);
   1669  1.1  riastrad 
   1670  1.1  riastrad 		if (ret) {
   1671  1.1  riastrad 			drm_property_destroy(dev, scaling_mode_property);
   1672  1.1  riastrad 
   1673  1.1  riastrad 			return ret;
   1674  1.1  riastrad 		}
   1675  1.1  riastrad 	}
   1676  1.1  riastrad 
   1677  1.1  riastrad 	drm_object_attach_property(&connector->base,
   1678  1.1  riastrad 				   scaling_mode_property, 0);
   1679  1.1  riastrad 
   1680  1.1  riastrad 	connector->scaling_mode_property = scaling_mode_property;
   1681  1.1  riastrad 
   1682  1.1  riastrad 	return 0;
   1683  1.1  riastrad }
   1684  1.1  riastrad EXPORT_SYMBOL(drm_connector_attach_scaling_mode_property);
   1685  1.1  riastrad 
   1686  1.1  riastrad /**
   1687  1.1  riastrad  * drm_mode_create_aspect_ratio_property - create aspect ratio property
   1688  1.1  riastrad  * @dev: DRM device
   1689  1.1  riastrad  *
   1690  1.1  riastrad  * Called by a driver the first time it's needed, must be attached to desired
   1691  1.1  riastrad  * connectors.
   1692  1.1  riastrad  *
   1693  1.1  riastrad  * Returns:
   1694  1.1  riastrad  * Zero on success, negative errno on failure.
   1695  1.1  riastrad  */
   1696  1.1  riastrad int drm_mode_create_aspect_ratio_property(struct drm_device *dev)
   1697  1.1  riastrad {
   1698  1.1  riastrad 	if (dev->mode_config.aspect_ratio_property)
   1699  1.1  riastrad 		return 0;
   1700  1.1  riastrad 
   1701  1.1  riastrad 	dev->mode_config.aspect_ratio_property =
   1702  1.1  riastrad 		drm_property_create_enum(dev, 0, "aspect ratio",
   1703  1.1  riastrad 				drm_aspect_ratio_enum_list,
   1704  1.1  riastrad 				ARRAY_SIZE(drm_aspect_ratio_enum_list));
   1705  1.1  riastrad 
   1706  1.1  riastrad 	if (dev->mode_config.aspect_ratio_property == NULL)
   1707  1.1  riastrad 		return -ENOMEM;
   1708  1.1  riastrad 
   1709  1.1  riastrad 	return 0;
   1710  1.1  riastrad }
   1711  1.1  riastrad EXPORT_SYMBOL(drm_mode_create_aspect_ratio_property);
   1712  1.1  riastrad 
   1713  1.1  riastrad /**
   1714  1.1  riastrad  * DOC: standard connector properties
   1715  1.1  riastrad  *
   1716  1.1  riastrad  * Colorspace:
   1717  1.1  riastrad  *     This property helps select a suitable colorspace based on the sink
   1718  1.1  riastrad  *     capability. Modern sink devices support wider gamut like BT2020.
   1719  1.1  riastrad  *     This helps switch to BT2020 mode if the BT2020 encoded video stream
   1720  1.1  riastrad  *     is being played by the user, same for any other colorspace. Thereby
   1721  1.1  riastrad  *     giving a good visual experience to users.
   1722  1.1  riastrad  *
   1723  1.1  riastrad  *     The expectation from userspace is that it should parse the EDID
   1724  1.1  riastrad  *     and get supported colorspaces. Use this property and switch to the
   1725  1.1  riastrad  *     one supported. Sink supported colorspaces should be retrieved by
   1726  1.1  riastrad  *     userspace from EDID and driver will not explicitly expose them.
   1727  1.1  riastrad  *
   1728  1.1  riastrad  *     Basically the expectation from userspace is:
   1729  1.1  riastrad  *      - Set up CRTC DEGAMMA/CTM/GAMMA to convert to some sink
   1730  1.1  riastrad  *        colorspace
   1731  1.1  riastrad  *      - Set this new property to let the sink know what it
   1732  1.1  riastrad  *        converted the CRTC output to.
   1733  1.1  riastrad  *      - This property is just to inform sink what colorspace
   1734  1.1  riastrad  *        source is trying to drive.
   1735  1.1  riastrad  *
   1736  1.1  riastrad  * Because between HDMI and DP have different colorspaces,
   1737  1.1  riastrad  * drm_mode_create_hdmi_colorspace_property() is used for HDMI connector and
   1738  1.1  riastrad  * drm_mode_create_dp_colorspace_property() is used for DP connector.
   1739  1.1  riastrad  */
   1740  1.1  riastrad 
   1741  1.1  riastrad /**
   1742  1.1  riastrad  * drm_mode_create_hdmi_colorspace_property - create hdmi colorspace property
   1743  1.1  riastrad  * @connector: connector to create the Colorspace property on.
   1744  1.1  riastrad  *
   1745  1.1  riastrad  * Called by a driver the first time it's needed, must be attached to desired
   1746  1.1  riastrad  * HDMI connectors.
   1747  1.1  riastrad  *
   1748  1.1  riastrad  * Returns:
   1749  1.1  riastrad  * Zero on success, negative errono on failure.
   1750  1.1  riastrad  */
   1751  1.1  riastrad int drm_mode_create_hdmi_colorspace_property(struct drm_connector *connector)
   1752  1.1  riastrad {
   1753  1.1  riastrad 	struct drm_device *dev = connector->dev;
   1754  1.1  riastrad 
   1755  1.1  riastrad 	if (connector->colorspace_property)
   1756  1.1  riastrad 		return 0;
   1757  1.1  riastrad 
   1758  1.1  riastrad 	connector->colorspace_property =
   1759  1.1  riastrad 		drm_property_create_enum(dev, DRM_MODE_PROP_ENUM, "Colorspace",
   1760  1.1  riastrad 					 hdmi_colorspaces,
   1761  1.1  riastrad 					 ARRAY_SIZE(hdmi_colorspaces));
   1762  1.1  riastrad 
   1763  1.1  riastrad 	if (!connector->colorspace_property)
   1764  1.1  riastrad 		return -ENOMEM;
   1765  1.1  riastrad 
   1766  1.1  riastrad 	return 0;
   1767  1.1  riastrad }
   1768  1.1  riastrad EXPORT_SYMBOL(drm_mode_create_hdmi_colorspace_property);
   1769  1.1  riastrad 
   1770  1.1  riastrad /**
   1771  1.1  riastrad  * drm_mode_create_dp_colorspace_property - create dp colorspace property
   1772  1.1  riastrad  * @connector: connector to create the Colorspace property on.
   1773  1.1  riastrad  *
   1774  1.1  riastrad  * Called by a driver the first time it's needed, must be attached to desired
   1775  1.1  riastrad  * DP connectors.
   1776  1.1  riastrad  *
   1777  1.1  riastrad  * Returns:
   1778  1.1  riastrad  * Zero on success, negative errono on failure.
   1779  1.1  riastrad  */
   1780  1.1  riastrad int drm_mode_create_dp_colorspace_property(struct drm_connector *connector)
   1781  1.1  riastrad {
   1782  1.1  riastrad 	struct drm_device *dev = connector->dev;
   1783  1.1  riastrad 
   1784  1.1  riastrad 	if (connector->colorspace_property)
   1785  1.1  riastrad 		return 0;
   1786  1.1  riastrad 
   1787  1.1  riastrad 	connector->colorspace_property =
   1788  1.1  riastrad 		drm_property_create_enum(dev, DRM_MODE_PROP_ENUM, "Colorspace",
   1789  1.1  riastrad 					 dp_colorspaces,
   1790  1.1  riastrad 					 ARRAY_SIZE(dp_colorspaces));
   1791  1.1  riastrad 
   1792  1.1  riastrad 	if (!connector->colorspace_property)
   1793  1.1  riastrad 		return -ENOMEM;
   1794  1.1  riastrad 
   1795  1.1  riastrad 	return 0;
   1796  1.1  riastrad }
   1797  1.1  riastrad EXPORT_SYMBOL(drm_mode_create_dp_colorspace_property);
   1798  1.1  riastrad 
   1799  1.1  riastrad /**
   1800  1.1  riastrad  * drm_mode_create_content_type_property - create content type property
   1801  1.1  riastrad  * @dev: DRM device
   1802  1.1  riastrad  *
   1803  1.1  riastrad  * Called by a driver the first time it's needed, must be attached to desired
   1804  1.1  riastrad  * connectors.
   1805  1.1  riastrad  *
   1806  1.1  riastrad  * Returns:
   1807  1.1  riastrad  * Zero on success, negative errno on failure.
   1808  1.1  riastrad  */
   1809  1.1  riastrad int drm_mode_create_content_type_property(struct drm_device *dev)
   1810  1.1  riastrad {
   1811  1.1  riastrad 	if (dev->mode_config.content_type_property)
   1812  1.1  riastrad 		return 0;
   1813  1.1  riastrad 
   1814  1.1  riastrad 	dev->mode_config.content_type_property =
   1815  1.1  riastrad 		drm_property_create_enum(dev, 0, "content type",
   1816  1.1  riastrad 					 drm_content_type_enum_list,
   1817  1.1  riastrad 					 ARRAY_SIZE(drm_content_type_enum_list));
   1818  1.1  riastrad 
   1819  1.1  riastrad 	if (dev->mode_config.content_type_property == NULL)
   1820  1.1  riastrad 		return -ENOMEM;
   1821  1.1  riastrad 
   1822  1.1  riastrad 	return 0;
   1823  1.1  riastrad }
   1824  1.1  riastrad EXPORT_SYMBOL(drm_mode_create_content_type_property);
   1825  1.1  riastrad 
   1826  1.1  riastrad /**
   1827  1.1  riastrad  * drm_mode_create_suggested_offset_properties - create suggests offset properties
   1828  1.1  riastrad  * @dev: DRM device
   1829  1.1  riastrad  *
   1830  1.1  riastrad  * Create the the suggested x/y offset property for connectors.
   1831  1.1  riastrad  */
   1832  1.1  riastrad int drm_mode_create_suggested_offset_properties(struct drm_device *dev)
   1833  1.1  riastrad {
   1834  1.1  riastrad 	if (dev->mode_config.suggested_x_property && dev->mode_config.suggested_y_property)
   1835  1.1  riastrad 		return 0;
   1836  1.1  riastrad 
   1837  1.1  riastrad 	dev->mode_config.suggested_x_property =
   1838  1.1  riastrad 		drm_property_create_range(dev, DRM_MODE_PROP_IMMUTABLE, "suggested X", 0, 0xffffffff);
   1839  1.1  riastrad 
   1840  1.1  riastrad 	dev->mode_config.suggested_y_property =
   1841  1.1  riastrad 		drm_property_create_range(dev, DRM_MODE_PROP_IMMUTABLE, "suggested Y", 0, 0xffffffff);
   1842  1.1  riastrad 
   1843  1.1  riastrad 	if (dev->mode_config.suggested_x_property == NULL ||
   1844  1.1  riastrad 	    dev->mode_config.suggested_y_property == NULL)
   1845  1.1  riastrad 		return -ENOMEM;
   1846  1.1  riastrad 	return 0;
   1847  1.1  riastrad }
   1848  1.1  riastrad EXPORT_SYMBOL(drm_mode_create_suggested_offset_properties);
   1849  1.1  riastrad 
   1850  1.1  riastrad /**
   1851  1.1  riastrad  * drm_connector_set_path_property - set tile property on connector
   1852  1.1  riastrad  * @connector: connector to set property on.
   1853  1.1  riastrad  * @path: path to use for property; must not be NULL.
   1854  1.1  riastrad  *
   1855  1.1  riastrad  * This creates a property to expose to userspace to specify a
   1856  1.1  riastrad  * connector path. This is mainly used for DisplayPort MST where
   1857  1.1  riastrad  * connectors have a topology and we want to allow userspace to give
   1858  1.1  riastrad  * them more meaningful names.
   1859  1.1  riastrad  *
   1860  1.1  riastrad  * Returns:
   1861  1.1  riastrad  * Zero on success, negative errno on failure.
   1862  1.1  riastrad  */
   1863  1.1  riastrad int drm_connector_set_path_property(struct drm_connector *connector,
   1864  1.1  riastrad 				    const char *path)
   1865  1.1  riastrad {
   1866  1.1  riastrad 	struct drm_device *dev = connector->dev;
   1867  1.1  riastrad 	int ret;
   1868  1.1  riastrad 
   1869  1.1  riastrad 	ret = drm_property_replace_global_blob(dev,
   1870  1.1  riastrad 	                                       &connector->path_blob_ptr,
   1871  1.1  riastrad 	                                       strlen(path) + 1,
   1872  1.1  riastrad 	                                       path,
   1873  1.1  riastrad 	                                       &connector->base,
   1874  1.1  riastrad 	                                       dev->mode_config.path_property);
   1875  1.1  riastrad 	return ret;
   1876  1.1  riastrad }
   1877  1.1  riastrad EXPORT_SYMBOL(drm_connector_set_path_property);
   1878  1.1  riastrad 
   1879  1.1  riastrad /**
   1880  1.1  riastrad  * drm_connector_set_tile_property - set tile property on connector
   1881  1.1  riastrad  * @connector: connector to set property on.
   1882  1.1  riastrad  *
   1883  1.1  riastrad  * This looks up the tile information for a connector, and creates a
   1884  1.1  riastrad  * property for userspace to parse if it exists. The property is of
   1885  1.1  riastrad  * the form of 8 integers using ':' as a separator.
   1886  1.1  riastrad  * This is used for dual port tiled displays with DisplayPort SST
   1887  1.1  riastrad  * or DisplayPort MST connectors.
   1888  1.1  riastrad  *
   1889  1.1  riastrad  * Returns:
   1890  1.1  riastrad  * Zero on success, errno on failure.
   1891  1.1  riastrad  */
   1892  1.1  riastrad int drm_connector_set_tile_property(struct drm_connector *connector)
   1893  1.1  riastrad {
   1894  1.1  riastrad 	struct drm_device *dev = connector->dev;
   1895  1.1  riastrad 	char tile[256];
   1896  1.1  riastrad 	int ret;
   1897  1.1  riastrad 
   1898  1.1  riastrad 	if (!connector->has_tile) {
   1899  1.1  riastrad 		ret  = drm_property_replace_global_blob(dev,
   1900  1.1  riastrad 		                                        &connector->tile_blob_ptr,
   1901  1.1  riastrad 		                                        0,
   1902  1.1  riastrad 		                                        NULL,
   1903  1.1  riastrad 		                                        &connector->base,
   1904  1.1  riastrad 		                                        dev->mode_config.tile_property);
   1905  1.1  riastrad 		return ret;
   1906  1.1  riastrad 	}
   1907  1.1  riastrad 
   1908  1.1  riastrad 	snprintf(tile, 256, "%d:%d:%d:%d:%d:%d:%d:%d",
   1909  1.1  riastrad 		 connector->tile_group->id, connector->tile_is_single_monitor,
   1910  1.1  riastrad 		 connector->num_h_tile, connector->num_v_tile,
   1911  1.1  riastrad 		 connector->tile_h_loc, connector->tile_v_loc,
   1912  1.1  riastrad 		 connector->tile_h_size, connector->tile_v_size);
   1913  1.1  riastrad 
   1914  1.1  riastrad 	ret = drm_property_replace_global_blob(dev,
   1915  1.1  riastrad 	                                       &connector->tile_blob_ptr,
   1916  1.1  riastrad 	                                       strlen(tile) + 1,
   1917  1.1  riastrad 	                                       tile,
   1918  1.1  riastrad 	                                       &connector->base,
   1919  1.1  riastrad 	                                       dev->mode_config.tile_property);
   1920  1.1  riastrad 	return ret;
   1921  1.1  riastrad }
   1922  1.1  riastrad EXPORT_SYMBOL(drm_connector_set_tile_property);
   1923  1.1  riastrad 
   1924  1.1  riastrad /**
   1925  1.1  riastrad  * drm_connector_update_edid_property - update the edid property of a connector
   1926  1.1  riastrad  * @connector: drm connector
   1927  1.1  riastrad  * @edid: new value of the edid property
   1928  1.1  riastrad  *
   1929  1.1  riastrad  * This function creates a new blob modeset object and assigns its id to the
   1930  1.1  riastrad  * connector's edid property.
   1931  1.1  riastrad  * Since we also parse tile information from EDID's displayID block, we also
   1932  1.1  riastrad  * set the connector's tile property here. See drm_connector_set_tile_property()
   1933  1.1  riastrad  * for more details.
   1934  1.1  riastrad  *
   1935  1.1  riastrad  * Returns:
   1936  1.1  riastrad  * Zero on success, negative errno on failure.
   1937  1.1  riastrad  */
   1938  1.1  riastrad int drm_connector_update_edid_property(struct drm_connector *connector,
   1939  1.1  riastrad 				       const struct edid *edid)
   1940  1.1  riastrad {
   1941  1.1  riastrad 	struct drm_device *dev = connector->dev;
   1942  1.1  riastrad 	size_t size = 0;
   1943  1.1  riastrad 	int ret;
   1944  1.1  riastrad 
   1945  1.1  riastrad 	/* ignore requests to set edid when overridden */
   1946  1.1  riastrad 	if (connector->override_edid)
   1947  1.1  riastrad 		return 0;
   1948  1.1  riastrad 
   1949  1.1  riastrad 	if (edid)
   1950  1.1  riastrad 		size = EDID_LENGTH * (1 + edid->extensions);
   1951  1.1  riastrad 
   1952  1.1  riastrad 	/* Set the display info, using edid if available, otherwise
   1953  1.1  riastrad 	 * reseting the values to defaults. This duplicates the work
   1954  1.1  riastrad 	 * done in drm_add_edid_modes, but that function is not
   1955  1.1  riastrad 	 * consistently called before this one in all drivers and the
   1956  1.1  riastrad 	 * computation is cheap enough that it seems better to
   1957  1.1  riastrad 	 * duplicate it rather than attempt to ensure some arbitrary
   1958  1.1  riastrad 	 * ordering of calls.
   1959  1.1  riastrad 	 */
   1960  1.1  riastrad 	if (edid)
   1961  1.1  riastrad 		drm_add_display_info(connector, edid);
   1962  1.1  riastrad 	else
   1963  1.1  riastrad 		drm_reset_display_info(connector);
   1964  1.1  riastrad 
   1965  1.1  riastrad 	drm_object_property_set_value(&connector->base,
   1966  1.1  riastrad 				      dev->mode_config.non_desktop_property,
   1967  1.1  riastrad 				      connector->display_info.non_desktop);
   1968  1.1  riastrad 
   1969  1.1  riastrad 	ret = drm_property_replace_global_blob(dev,
   1970  1.1  riastrad 					       &connector->edid_blob_ptr,
   1971  1.1  riastrad 	                                       size,
   1972  1.1  riastrad 	                                       edid,
   1973  1.1  riastrad 	                                       &connector->base,
   1974  1.1  riastrad 	                                       dev->mode_config.edid_property);
   1975  1.1  riastrad 	if (ret)
   1976  1.1  riastrad 		return ret;
   1977  1.1  riastrad 	return drm_connector_set_tile_property(connector);
   1978  1.1  riastrad }
   1979  1.1  riastrad EXPORT_SYMBOL(drm_connector_update_edid_property);
   1980  1.1  riastrad 
   1981  1.1  riastrad /**
   1982  1.1  riastrad  * drm_connector_set_link_status_property - Set link status property of a connector
   1983  1.1  riastrad  * @connector: drm connector
   1984  1.1  riastrad  * @link_status: new value of link status property (0: Good, 1: Bad)
   1985  1.1  riastrad  *
   1986  1.1  riastrad  * In usual working scenario, this link status property will always be set to
   1987  1.1  riastrad  * "GOOD". If something fails during or after a mode set, the kernel driver
   1988  1.1  riastrad  * may set this link status property to "BAD". The caller then needs to send a
   1989  1.1  riastrad  * hotplug uevent for userspace to re-check the valid modes through
   1990  1.1  riastrad  * GET_CONNECTOR_IOCTL and retry modeset.
   1991  1.1  riastrad  *
   1992  1.1  riastrad  * Note: Drivers cannot rely on userspace to support this property and
   1993  1.1  riastrad  * issue a modeset. As such, they may choose to handle issues (like
   1994  1.1  riastrad  * re-training a link) without userspace's intervention.
   1995  1.1  riastrad  *
   1996  1.1  riastrad  * The reason for adding this property is to handle link training failures, but
   1997  1.1  riastrad  * it is not limited to DP or link training. For example, if we implement
   1998  1.1  riastrad  * asynchronous setcrtc, this property can be used to report any failures in that.
   1999  1.1  riastrad  */
   2000  1.1  riastrad void drm_connector_set_link_status_property(struct drm_connector *connector,
   2001  1.1  riastrad 					    uint64_t link_status)
   2002  1.1  riastrad {
   2003  1.1  riastrad 	struct drm_device *dev = connector->dev;
   2004  1.1  riastrad 
   2005  1.1  riastrad 	drm_modeset_lock(&dev->mode_config.connection_mutex, NULL);
   2006  1.1  riastrad 	connector->state->link_status = link_status;
   2007  1.1  riastrad 	drm_modeset_unlock(&dev->mode_config.connection_mutex);
   2008  1.1  riastrad }
   2009  1.1  riastrad EXPORT_SYMBOL(drm_connector_set_link_status_property);
   2010  1.1  riastrad 
   2011  1.1  riastrad /**
   2012  1.1  riastrad  * drm_connector_attach_max_bpc_property - attach "max bpc" property
   2013  1.1  riastrad  * @connector: connector to attach max bpc property on.
   2014  1.1  riastrad  * @min: The minimum bit depth supported by the connector.
   2015  1.1  riastrad  * @max: The maximum bit depth supported by the connector.
   2016  1.1  riastrad  *
   2017  1.1  riastrad  * This is used to add support for limiting the bit depth on a connector.
   2018  1.1  riastrad  *
   2019  1.1  riastrad  * Returns:
   2020  1.1  riastrad  * Zero on success, negative errno on failure.
   2021  1.1  riastrad  */
   2022  1.1  riastrad int drm_connector_attach_max_bpc_property(struct drm_connector *connector,
   2023  1.1  riastrad 					  int min, int max)
   2024  1.1  riastrad {
   2025  1.1  riastrad 	struct drm_device *dev = connector->dev;
   2026  1.1  riastrad 	struct drm_property *prop;
   2027  1.1  riastrad 
   2028  1.1  riastrad 	prop = connector->max_bpc_property;
   2029  1.1  riastrad 	if (!prop) {
   2030  1.1  riastrad 		prop = drm_property_create_range(dev, 0, "max bpc", min, max);
   2031  1.1  riastrad 		if (!prop)
   2032  1.1  riastrad 			return -ENOMEM;
   2033  1.1  riastrad 
   2034  1.1  riastrad 		connector->max_bpc_property = prop;
   2035  1.1  riastrad 	}
   2036  1.1  riastrad 
   2037  1.1  riastrad 	drm_object_attach_property(&connector->base, prop, max);
   2038  1.1  riastrad 	connector->state->max_requested_bpc = max;
   2039  1.1  riastrad 	connector->state->max_bpc = max;
   2040  1.1  riastrad 
   2041  1.1  riastrad 	return 0;
   2042  1.1  riastrad }
   2043  1.1  riastrad EXPORT_SYMBOL(drm_connector_attach_max_bpc_property);
   2044  1.1  riastrad 
   2045  1.1  riastrad /**
   2046  1.1  riastrad  * drm_connector_set_vrr_capable_property - sets the variable refresh rate
   2047  1.1  riastrad  * capable property for a connector
   2048  1.1  riastrad  * @connector: drm connector
   2049  1.1  riastrad  * @capable: True if the connector is variable refresh rate capable
   2050  1.1  riastrad  *
   2051  1.1  riastrad  * Should be used by atomic drivers to update the indicated support for
   2052  1.1  riastrad  * variable refresh rate over a connector.
   2053  1.1  riastrad  */
   2054  1.1  riastrad void drm_connector_set_vrr_capable_property(
   2055  1.1  riastrad 		struct drm_connector *connector, bool capable)
   2056  1.1  riastrad {
   2057  1.1  riastrad 	drm_object_property_set_value(&connector->base,
   2058  1.1  riastrad 				      connector->vrr_capable_property,
   2059  1.1  riastrad 				      capable);
   2060  1.1  riastrad }
   2061  1.1  riastrad EXPORT_SYMBOL(drm_connector_set_vrr_capable_property);
   2062  1.1  riastrad 
   2063  1.1  riastrad /**
   2064  1.1  riastrad  * drm_connector_init_panel_orientation_property -
   2065  1.1  riastrad  *	initialize the connecters panel_orientation property
   2066  1.1  riastrad  * @connector: connector for which to init the panel-orientation property.
   2067  1.1  riastrad  * @width: width in pixels of the panel, used for panel quirk detection
   2068  1.1  riastrad  * @height: height in pixels of the panel, used for panel quirk detection
   2069  1.1  riastrad  *
   2070  1.1  riastrad  * This function should only be called for built-in panels, after setting
   2071  1.1  riastrad  * connector->display_info.panel_orientation first (if known).
   2072  1.1  riastrad  *
   2073  1.1  riastrad  * This function will check for platform specific (e.g. DMI based) quirks
   2074  1.1  riastrad  * overriding display_info.panel_orientation first, then if panel_orientation
   2075  1.1  riastrad  * is not DRM_MODE_PANEL_ORIENTATION_UNKNOWN it will attach the
   2076  1.1  riastrad  * "panel orientation" property to the connector.
   2077  1.1  riastrad  *
   2078  1.1  riastrad  * Returns:
   2079  1.1  riastrad  * Zero on success, negative errno on failure.
   2080  1.1  riastrad  */
   2081  1.1  riastrad int drm_connector_init_panel_orientation_property(
   2082  1.1  riastrad 	struct drm_connector *connector, int width, int height)
   2083  1.1  riastrad {
   2084  1.1  riastrad 	struct drm_device *dev = connector->dev;
   2085  1.1  riastrad 	struct drm_display_info *info = &connector->display_info;
   2086  1.1  riastrad 	struct drm_property *prop;
   2087  1.1  riastrad 	int orientation_quirk;
   2088  1.1  riastrad 
   2089  1.1  riastrad 	orientation_quirk = drm_get_panel_orientation_quirk(width, height);
   2090  1.1  riastrad 	if (orientation_quirk != DRM_MODE_PANEL_ORIENTATION_UNKNOWN)
   2091  1.1  riastrad 		info->panel_orientation = orientation_quirk;
   2092  1.1  riastrad 
   2093  1.1  riastrad 	if (info->panel_orientation == DRM_MODE_PANEL_ORIENTATION_UNKNOWN)
   2094  1.1  riastrad 		return 0;
   2095  1.1  riastrad 
   2096  1.1  riastrad 	prop = dev->mode_config.panel_orientation_property;
   2097  1.1  riastrad 	if (!prop) {
   2098  1.1  riastrad 		prop = drm_property_create_enum(dev, DRM_MODE_PROP_IMMUTABLE,
   2099  1.1  riastrad 				"panel orientation",
   2100  1.1  riastrad 				drm_panel_orientation_enum_list,
   2101  1.1  riastrad 				ARRAY_SIZE(drm_panel_orientation_enum_list));
   2102  1.1  riastrad 		if (!prop)
   2103  1.1  riastrad 			return -ENOMEM;
   2104  1.1  riastrad 
   2105  1.1  riastrad 		dev->mode_config.panel_orientation_property = prop;
   2106  1.1  riastrad 	}
   2107  1.1  riastrad 
   2108  1.1  riastrad 	drm_object_attach_property(&connector->base, prop,
   2109  1.1  riastrad 				   info->panel_orientation);
   2110  1.1  riastrad 	return 0;
   2111  1.1  riastrad }
   2112  1.1  riastrad EXPORT_SYMBOL(drm_connector_init_panel_orientation_property);
   2113  1.1  riastrad 
   2114  1.1  riastrad int drm_connector_set_obj_prop(struct drm_mode_object *obj,
   2115  1.1  riastrad 				    struct drm_property *property,
   2116  1.1  riastrad 				    uint64_t value)
   2117  1.1  riastrad {
   2118  1.1  riastrad 	int ret = -EINVAL;
   2119  1.1  riastrad 	struct drm_connector *connector = obj_to_connector(obj);
   2120  1.1  riastrad 
   2121  1.1  riastrad 	/* Do DPMS ourselves */
   2122  1.1  riastrad 	if (property == connector->dev->mode_config.dpms_property) {
   2123  1.1  riastrad 		ret = (*connector->funcs->dpms)(connector, (int)value);
   2124  1.1  riastrad 	} else if (connector->funcs->set_property)
   2125  1.1  riastrad 		ret = connector->funcs->set_property(connector, property, value);
   2126  1.1  riastrad 
   2127  1.1  riastrad 	if (!ret)
   2128  1.1  riastrad 		drm_object_property_set_value(&connector->base, property, value);
   2129  1.1  riastrad 	return ret;
   2130  1.1  riastrad }
   2131  1.1  riastrad 
   2132  1.1  riastrad int drm_connector_property_set_ioctl(struct drm_device *dev,
   2133  1.1  riastrad 				     void *data, struct drm_file *file_priv)
   2134  1.1  riastrad {
   2135  1.1  riastrad 	struct drm_mode_connector_set_property *conn_set_prop = data;
   2136  1.1  riastrad 	struct drm_mode_obj_set_property obj_set_prop = {
   2137  1.1  riastrad 		.value = conn_set_prop->value,
   2138  1.1  riastrad 		.prop_id = conn_set_prop->prop_id,
   2139  1.1  riastrad 		.obj_id = conn_set_prop->connector_id,
   2140  1.1  riastrad 		.obj_type = DRM_MODE_OBJECT_CONNECTOR
   2141  1.1  riastrad 	};
   2142  1.1  riastrad 
   2143  1.1  riastrad 	/* It does all the locking and checking we need */
   2144  1.1  riastrad 	return drm_mode_obj_set_property_ioctl(dev, &obj_set_prop, file_priv);
   2145  1.1  riastrad }
   2146  1.1  riastrad 
   2147  1.1  riastrad static struct drm_encoder *drm_connector_get_encoder(struct drm_connector *connector)
   2148  1.1  riastrad {
   2149  1.1  riastrad 	/* For atomic drivers only state objects are synchronously updated and
   2150  1.1  riastrad 	 * protected by modeset locks, so check those first. */
   2151  1.1  riastrad 	if (connector->state)
   2152  1.1  riastrad 		return connector->state->best_encoder;
   2153  1.1  riastrad 	return connector->encoder;
   2154  1.1  riastrad }
   2155  1.1  riastrad 
   2156  1.1  riastrad static bool
   2157  1.1  riastrad drm_mode_expose_to_userspace(const struct drm_display_mode *mode,
   2158  1.1  riastrad 			     const struct list_head *export_list,
   2159  1.1  riastrad 			     const struct drm_file *file_priv)
   2160  1.1  riastrad {
   2161  1.1  riastrad 	/*
   2162  1.1  riastrad 	 * If user-space hasn't configured the driver to expose the stereo 3D
   2163  1.1  riastrad 	 * modes, don't expose them.
   2164  1.1  riastrad 	 */
   2165  1.1  riastrad 	if (!file_priv->stereo_allowed && drm_mode_is_stereo(mode))
   2166  1.1  riastrad 		return false;
   2167  1.1  riastrad 	/*
   2168  1.1  riastrad 	 * If user-space hasn't configured the driver to expose the modes
   2169  1.1  riastrad 	 * with aspect-ratio, don't expose them. However if such a mode
   2170  1.1  riastrad 	 * is unique, let it be exposed, but reset the aspect-ratio flags
   2171  1.1  riastrad 	 * while preparing the list of user-modes.
   2172  1.1  riastrad 	 */
   2173  1.1  riastrad 	if (!file_priv->aspect_ratio_allowed) {
   2174  1.1  riastrad 		struct drm_display_mode *mode_itr;
   2175  1.1  riastrad 
   2176  1.1  riastrad 		list_for_each_entry(mode_itr, export_list, export_head)
   2177  1.1  riastrad 			if (drm_mode_match(mode_itr, mode,
   2178  1.1  riastrad 					   DRM_MODE_MATCH_TIMINGS |
   2179  1.1  riastrad 					   DRM_MODE_MATCH_CLOCK |
   2180  1.1  riastrad 					   DRM_MODE_MATCH_FLAGS |
   2181  1.1  riastrad 					   DRM_MODE_MATCH_3D_FLAGS))
   2182  1.1  riastrad 				return false;
   2183  1.1  riastrad 	}
   2184  1.1  riastrad 
   2185  1.1  riastrad 	return true;
   2186  1.1  riastrad }
   2187  1.1  riastrad 
   2188  1.1  riastrad int drm_mode_getconnector(struct drm_device *dev, void *data,
   2189  1.1  riastrad 			  struct drm_file *file_priv)
   2190  1.1  riastrad {
   2191  1.1  riastrad 	struct drm_mode_get_connector *out_resp = data;
   2192  1.1  riastrad 	struct drm_connector *connector;
   2193  1.1  riastrad 	struct drm_encoder *encoder;
   2194  1.1  riastrad 	struct drm_display_mode *mode;
   2195  1.1  riastrad 	int mode_count = 0;
   2196  1.1  riastrad 	int encoders_count = 0;
   2197  1.1  riastrad 	int ret = 0;
   2198  1.1  riastrad 	int copied = 0;
   2199  1.1  riastrad 	struct drm_mode_modeinfo u_mode;
   2200  1.1  riastrad 	struct drm_mode_modeinfo __user *mode_ptr;
   2201  1.1  riastrad 	uint32_t __user *encoder_ptr;
   2202  1.3  riastrad 	struct list_head export_list = LIST_HEAD_INIT(export_list);
   2203  1.1  riastrad 
   2204  1.1  riastrad 	if (!drm_core_check_feature(dev, DRIVER_MODESET))
   2205  1.1  riastrad 		return -EOPNOTSUPP;
   2206  1.1  riastrad 
   2207  1.1  riastrad 	memset(&u_mode, 0, sizeof(struct drm_mode_modeinfo));
   2208  1.1  riastrad 
   2209  1.1  riastrad 	connector = drm_connector_lookup(dev, file_priv, out_resp->connector_id);
   2210  1.1  riastrad 	if (!connector)
   2211  1.1  riastrad 		return -ENOENT;
   2212  1.1  riastrad 
   2213  1.1  riastrad 	encoders_count = hweight32(connector->possible_encoders);
   2214  1.1  riastrad 
   2215  1.1  riastrad 	if ((out_resp->count_encoders >= encoders_count) && encoders_count) {
   2216  1.1  riastrad 		copied = 0;
   2217  1.1  riastrad 		encoder_ptr = (uint32_t __user *)(unsigned long)(out_resp->encoders_ptr);
   2218  1.1  riastrad 
   2219  1.1  riastrad 		drm_connector_for_each_possible_encoder(connector, encoder) {
   2220  1.1  riastrad 			if (put_user(encoder->base.id, encoder_ptr + copied)) {
   2221  1.1  riastrad 				ret = -EFAULT;
   2222  1.1  riastrad 				goto out;
   2223  1.1  riastrad 			}
   2224  1.1  riastrad 			copied++;
   2225  1.1  riastrad 		}
   2226  1.1  riastrad 	}
   2227  1.1  riastrad 	out_resp->count_encoders = encoders_count;
   2228  1.1  riastrad 
   2229  1.1  riastrad 	out_resp->connector_id = connector->base.id;
   2230  1.1  riastrad 	out_resp->connector_type = connector->connector_type;
   2231  1.1  riastrad 	out_resp->connector_type_id = connector->connector_type_id;
   2232  1.1  riastrad 
   2233  1.1  riastrad 	mutex_lock(&dev->mode_config.mutex);
   2234  1.1  riastrad 	if (out_resp->count_modes == 0) {
   2235  1.1  riastrad 		connector->funcs->fill_modes(connector,
   2236  1.1  riastrad 					     dev->mode_config.max_width,
   2237  1.1  riastrad 					     dev->mode_config.max_height);
   2238  1.1  riastrad 	}
   2239  1.1  riastrad 
   2240  1.1  riastrad 	out_resp->mm_width = connector->display_info.width_mm;
   2241  1.1  riastrad 	out_resp->mm_height = connector->display_info.height_mm;
   2242  1.1  riastrad 	out_resp->subpixel = connector->display_info.subpixel_order;
   2243  1.1  riastrad 	out_resp->connection = connector->status;
   2244  1.1  riastrad 
   2245  1.1  riastrad 	/* delayed so we get modes regardless of pre-fill_modes state */
   2246  1.1  riastrad 	list_for_each_entry(mode, &connector->modes, head)
   2247  1.1  riastrad 		if (drm_mode_expose_to_userspace(mode, &export_list,
   2248  1.1  riastrad 						 file_priv)) {
   2249  1.1  riastrad 			list_add_tail(&mode->export_head, &export_list);
   2250  1.1  riastrad 			mode_count++;
   2251  1.1  riastrad 		}
   2252  1.1  riastrad 
   2253  1.1  riastrad 	/*
   2254  1.1  riastrad 	 * This ioctl is called twice, once to determine how much space is
   2255  1.1  riastrad 	 * needed, and the 2nd time to fill it.
   2256  1.1  riastrad 	 * The modes that need to be exposed to the user are maintained in the
   2257  1.1  riastrad 	 * 'export_list'. When the ioctl is called first time to determine the,
   2258  1.1  riastrad 	 * space, the export_list gets filled, to find the no.of modes. In the
   2259  1.1  riastrad 	 * 2nd time, the user modes are filled, one by one from the export_list.
   2260  1.1  riastrad 	 */
   2261  1.1  riastrad 	if ((out_resp->count_modes >= mode_count) && mode_count) {
   2262  1.1  riastrad 		copied = 0;
   2263  1.1  riastrad 		mode_ptr = (struct drm_mode_modeinfo __user *)(unsigned long)out_resp->modes_ptr;
   2264  1.1  riastrad 		list_for_each_entry(mode, &export_list, export_head) {
   2265  1.1  riastrad 			drm_mode_convert_to_umode(&u_mode, mode);
   2266  1.1  riastrad 			/*
   2267  1.1  riastrad 			 * Reset aspect ratio flags of user-mode, if modes with
   2268  1.1  riastrad 			 * aspect-ratio are not supported.
   2269  1.1  riastrad 			 */
   2270  1.1  riastrad 			if (!file_priv->aspect_ratio_allowed)
   2271  1.1  riastrad 				u_mode.flags &= ~DRM_MODE_FLAG_PIC_AR_MASK;
   2272  1.1  riastrad 			if (copy_to_user(mode_ptr + copied,
   2273  1.1  riastrad 					 &u_mode, sizeof(u_mode))) {
   2274  1.1  riastrad 				ret = -EFAULT;
   2275  1.1  riastrad 				mutex_unlock(&dev->mode_config.mutex);
   2276  1.1  riastrad 
   2277  1.1  riastrad 				goto out;
   2278  1.1  riastrad 			}
   2279  1.1  riastrad 			copied++;
   2280  1.1  riastrad 		}
   2281  1.1  riastrad 	}
   2282  1.1  riastrad 	out_resp->count_modes = mode_count;
   2283  1.1  riastrad 	mutex_unlock(&dev->mode_config.mutex);
   2284  1.1  riastrad 
   2285  1.1  riastrad 	drm_modeset_lock(&dev->mode_config.connection_mutex, NULL);
   2286  1.1  riastrad 	encoder = drm_connector_get_encoder(connector);
   2287  1.1  riastrad 	if (encoder)
   2288  1.1  riastrad 		out_resp->encoder_id = encoder->base.id;
   2289  1.1  riastrad 	else
   2290  1.1  riastrad 		out_resp->encoder_id = 0;
   2291  1.1  riastrad 
   2292  1.1  riastrad 	/* Only grab properties after probing, to make sure EDID and other
   2293  1.1  riastrad 	 * properties reflect the latest status. */
   2294  1.1  riastrad 	ret = drm_mode_object_get_properties(&connector->base, file_priv->atomic,
   2295  1.1  riastrad 			(uint32_t __user *)(unsigned long)(out_resp->props_ptr),
   2296  1.1  riastrad 			(uint64_t __user *)(unsigned long)(out_resp->prop_values_ptr),
   2297  1.1  riastrad 			&out_resp->count_props);
   2298  1.1  riastrad 	drm_modeset_unlock(&dev->mode_config.connection_mutex);
   2299  1.1  riastrad 
   2300  1.1  riastrad out:
   2301  1.1  riastrad 	drm_connector_put(connector);
   2302  1.1  riastrad 
   2303  1.1  riastrad 	return ret;
   2304  1.1  riastrad }
   2305  1.1  riastrad 
   2306  1.1  riastrad 
   2307  1.1  riastrad /**
   2308  1.1  riastrad  * DOC: Tile group
   2309  1.1  riastrad  *
   2310  1.1  riastrad  * Tile groups are used to represent tiled monitors with a unique integer
   2311  1.1  riastrad  * identifier. Tiled monitors using DisplayID v1.3 have a unique 8-byte handle,
   2312  1.1  riastrad  * we store this in a tile group, so we have a common identifier for all tiles
   2313  1.1  riastrad  * in a monitor group. The property is called "TILE". Drivers can manage tile
   2314  1.1  riastrad  * groups using drm_mode_create_tile_group(), drm_mode_put_tile_group() and
   2315  1.1  riastrad  * drm_mode_get_tile_group(). But this is only needed for internal panels where
   2316  1.1  riastrad  * the tile group information is exposed through a non-standard way.
   2317  1.1  riastrad  */
   2318  1.1  riastrad 
   2319  1.1  riastrad static void drm_tile_group_free(struct kref *kref)
   2320  1.1  riastrad {
   2321  1.1  riastrad 	struct drm_tile_group *tg = container_of(kref, struct drm_tile_group, refcount);
   2322  1.1  riastrad 	struct drm_device *dev = tg->dev;
   2323  1.1  riastrad 	mutex_lock(&dev->mode_config.idr_mutex);
   2324  1.1  riastrad 	idr_remove(&dev->mode_config.tile_idr, tg->id);
   2325  1.1  riastrad 	mutex_unlock(&dev->mode_config.idr_mutex);
   2326  1.1  riastrad 	kfree(tg);
   2327  1.1  riastrad }
   2328  1.1  riastrad 
   2329  1.1  riastrad /**
   2330  1.1  riastrad  * drm_mode_put_tile_group - drop a reference to a tile group.
   2331  1.1  riastrad  * @dev: DRM device
   2332  1.1  riastrad  * @tg: tile group to drop reference to.
   2333  1.1  riastrad  *
   2334  1.1  riastrad  * drop reference to tile group and free if 0.
   2335  1.1  riastrad  */
   2336  1.1  riastrad void drm_mode_put_tile_group(struct drm_device *dev,
   2337  1.1  riastrad 			     struct drm_tile_group *tg)
   2338  1.1  riastrad {
   2339  1.1  riastrad 	kref_put(&tg->refcount, drm_tile_group_free);
   2340  1.1  riastrad }
   2341  1.1  riastrad EXPORT_SYMBOL(drm_mode_put_tile_group);
   2342  1.1  riastrad 
   2343  1.1  riastrad /**
   2344  1.1  riastrad  * drm_mode_get_tile_group - get a reference to an existing tile group
   2345  1.1  riastrad  * @dev: DRM device
   2346  1.1  riastrad  * @topology: 8-bytes unique per monitor.
   2347  1.1  riastrad  *
   2348  1.1  riastrad  * Use the unique bytes to get a reference to an existing tile group.
   2349  1.1  riastrad  *
   2350  1.1  riastrad  * RETURNS:
   2351  1.1  riastrad  * tile group or NULL if not found.
   2352  1.1  riastrad  */
   2353  1.1  riastrad struct drm_tile_group *drm_mode_get_tile_group(struct drm_device *dev,
   2354  1.4  riastrad 					       const char topology[8])
   2355  1.1  riastrad {
   2356  1.1  riastrad 	struct drm_tile_group *tg;
   2357  1.1  riastrad 	int id;
   2358  1.1  riastrad 	mutex_lock(&dev->mode_config.idr_mutex);
   2359  1.1  riastrad 	idr_for_each_entry(&dev->mode_config.tile_idr, tg, id) {
   2360  1.1  riastrad 		if (!memcmp(tg->group_data, topology, 8)) {
   2361  1.1  riastrad 			if (!kref_get_unless_zero(&tg->refcount))
   2362  1.1  riastrad 				tg = NULL;
   2363  1.1  riastrad 			mutex_unlock(&dev->mode_config.idr_mutex);
   2364  1.1  riastrad 			return tg;
   2365  1.1  riastrad 		}
   2366  1.1  riastrad 	}
   2367  1.1  riastrad 	mutex_unlock(&dev->mode_config.idr_mutex);
   2368  1.1  riastrad 	return NULL;
   2369  1.1  riastrad }
   2370  1.1  riastrad EXPORT_SYMBOL(drm_mode_get_tile_group);
   2371  1.1  riastrad 
   2372  1.1  riastrad /**
   2373  1.1  riastrad  * drm_mode_create_tile_group - create a tile group from a displayid description
   2374  1.1  riastrad  * @dev: DRM device
   2375  1.1  riastrad  * @topology: 8-bytes unique per monitor.
   2376  1.1  riastrad  *
   2377  1.1  riastrad  * Create a tile group for the unique monitor, and get a unique
   2378  1.1  riastrad  * identifier for the tile group.
   2379  1.1  riastrad  *
   2380  1.1  riastrad  * RETURNS:
   2381  1.1  riastrad  * new tile group or NULL.
   2382  1.1  riastrad  */
   2383  1.1  riastrad struct drm_tile_group *drm_mode_create_tile_group(struct drm_device *dev,
   2384  1.4  riastrad 						  const char topology[8])
   2385  1.1  riastrad {
   2386  1.1  riastrad 	struct drm_tile_group *tg;
   2387  1.1  riastrad 	int ret;
   2388  1.1  riastrad 
   2389  1.1  riastrad 	tg = kzalloc(sizeof(*tg), GFP_KERNEL);
   2390  1.1  riastrad 	if (!tg)
   2391  1.1  riastrad 		return NULL;
   2392  1.1  riastrad 
   2393  1.1  riastrad 	kref_init(&tg->refcount);
   2394  1.1  riastrad 	memcpy(tg->group_data, topology, 8);
   2395  1.1  riastrad 	tg->dev = dev;
   2396  1.1  riastrad 
   2397  1.6  riastrad 	idr_preload(GFP_KERNEL);
   2398  1.1  riastrad 	mutex_lock(&dev->mode_config.idr_mutex);
   2399  1.1  riastrad 	ret = idr_alloc(&dev->mode_config.tile_idr, tg, 1, 0, GFP_KERNEL);
   2400  1.1  riastrad 	if (ret >= 0) {
   2401  1.1  riastrad 		tg->id = ret;
   2402  1.1  riastrad 	} else {
   2403  1.1  riastrad 		kfree(tg);
   2404  1.1  riastrad 		tg = NULL;
   2405  1.1  riastrad 	}
   2406  1.1  riastrad 
   2407  1.1  riastrad 	mutex_unlock(&dev->mode_config.idr_mutex);
   2408  1.6  riastrad 	idr_preload_end();
   2409  1.1  riastrad 	return tg;
   2410  1.1  riastrad }
   2411  1.1  riastrad EXPORT_SYMBOL(drm_mode_create_tile_group);
   2412