/*1* Copyright (c) 2016 Intel Corporation2*3* Permission to use, copy, modify, distribute, and sell this software and its4* documentation for any purpose is hereby granted without fee, provided that5* the above copyright notice appear in all copies and that both that copyright6* notice and this permission notice appear in supporting documentation, and7* that the name of the copyright holders not be used in advertising or8* publicity pertaining to distribution of the software without specific,9* written prior permission. The copyright holders make no representations10* about the suitability of this software for any purpose. It is provided "as11* is" without express or implied warranty.12*13* THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,14* INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO15* EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR16* CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,17* DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER18* TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE19* OF THIS SOFTWARE.20*/2122#include <drm/drm_auth.h>23#include <drm/drm_connector.h>24#include <drm/drm_drv.h>25#include <drm/drm_edid.h>26#include <drm/drm_encoder.h>27#include <drm/drm_file.h>28#include <drm/drm_managed.h>29#include <drm/drm_panel.h>30#include <drm/drm_print.h>31#include <drm/drm_privacy_screen_consumer.h>32#include <drm/drm_sysfs.h>33#include <drm/drm_utils.h>3435#include <linux/export.h>36#include <linux/platform_device.h>37#include <linux/property.h>38#include <linux/uaccess.h>3940#include <video/cmdline.h>4142#include "drm_crtc_internal.h"43#include "drm_internal.h"4445/**46* DOC: overview47*48* In DRM connectors are the general abstraction for display sinks, and include49* also fixed panels or anything else that can display pixels in some form. As50* opposed to all other KMS objects representing hardware (like CRTC, encoder or51* plane abstractions) connectors can be hotplugged and unplugged at runtime.52* Hence they are reference-counted using drm_connector_get() and53* drm_connector_put().54*55* KMS driver must create, initialize, register and attach at a &struct56* drm_connector for each such sink. The instance is created as other KMS57* objects and initialized by setting the following fields. The connector is58* initialized with a call to drm_connector_init() with a pointer to the59* &struct drm_connector_funcs and a connector type, and then exposed to60* userspace with a call to drm_connector_register().61*62* Connectors must be attached to an encoder to be used. For devices that map63* connectors to encoders 1:1, the connector should be attached at64* initialization time with a call to drm_connector_attach_encoder(). The65* driver must also set the &drm_connector.encoder field to point to the66* attached encoder.67*68* For connectors which are not fixed (like built-in panels) the driver needs to69* support hotplug notifications. The simplest way to do that is by using the70* probe helpers, see drm_kms_helper_poll_init() for connectors which don't have71* hardware support for hotplug interrupts. Connectors with hardware hotplug72* support can instead use e.g. drm_helper_hpd_irq_event().73*/7475/*76* Global connector list for drm_connector_find_by_fwnode().77* Note drm_connector_[un]register() first take connector->lock and then78* take the connector_list_lock.79*/80static DEFINE_MUTEX(connector_list_lock);81static LIST_HEAD(connector_list);8283struct drm_conn_prop_enum_list {84int type;85const char *name;86struct ida ida;87};8889/*90* Connector and encoder types.91*/92static struct drm_conn_prop_enum_list drm_connector_enum_list[] = {93{ DRM_MODE_CONNECTOR_Unknown, "Unknown" },94{ DRM_MODE_CONNECTOR_VGA, "VGA" },95{ DRM_MODE_CONNECTOR_DVII, "DVI-I" },96{ DRM_MODE_CONNECTOR_DVID, "DVI-D" },97{ DRM_MODE_CONNECTOR_DVIA, "DVI-A" },98{ DRM_MODE_CONNECTOR_Composite, "Composite" },99{ DRM_MODE_CONNECTOR_SVIDEO, "SVIDEO" },100{ DRM_MODE_CONNECTOR_LVDS, "LVDS" },101{ DRM_MODE_CONNECTOR_Component, "Component" },102{ DRM_MODE_CONNECTOR_9PinDIN, "DIN" },103{ DRM_MODE_CONNECTOR_DisplayPort, "DP" },104{ DRM_MODE_CONNECTOR_HDMIA, "HDMI-A" },105{ DRM_MODE_CONNECTOR_HDMIB, "HDMI-B" },106{ DRM_MODE_CONNECTOR_TV, "TV" },107{ DRM_MODE_CONNECTOR_eDP, "eDP" },108{ DRM_MODE_CONNECTOR_VIRTUAL, "Virtual" },109{ DRM_MODE_CONNECTOR_DSI, "DSI" },110{ DRM_MODE_CONNECTOR_DPI, "DPI" },111{ DRM_MODE_CONNECTOR_WRITEBACK, "Writeback" },112{ DRM_MODE_CONNECTOR_SPI, "SPI" },113{ DRM_MODE_CONNECTOR_USB, "USB" },114};115116void drm_connector_ida_init(void)117{118int i;119120for (i = 0; i < ARRAY_SIZE(drm_connector_enum_list); i++)121ida_init(&drm_connector_enum_list[i].ida);122}123124void drm_connector_ida_destroy(void)125{126int i;127128for (i = 0; i < ARRAY_SIZE(drm_connector_enum_list); i++)129ida_destroy(&drm_connector_enum_list[i].ida);130}131132/**133* drm_get_connector_type_name - return a string for connector type134* @type: The connector type (DRM_MODE_CONNECTOR_*)135*136* Returns: the name of the connector type, or NULL if the type is not valid.137*/138const char *drm_get_connector_type_name(unsigned int type)139{140if (type < ARRAY_SIZE(drm_connector_enum_list))141return drm_connector_enum_list[type].name;142143return NULL;144}145EXPORT_SYMBOL(drm_get_connector_type_name);146147/**148* drm_connector_get_cmdline_mode - reads the user's cmdline mode149* @connector: connector to query150*151* The kernel supports per-connector configuration of its consoles through152* use of the video= parameter. This function parses that option and153* extracts the user's specified mode (or enable/disable status) for a154* particular connector. This is typically only used during the early fbdev155* setup.156*/157static void drm_connector_get_cmdline_mode(struct drm_connector *connector)158{159struct drm_cmdline_mode *mode = &connector->cmdline_mode;160const char *option;161162option = video_get_options(connector->name);163if (!option)164return;165166if (!drm_mode_parse_command_line_for_connector(option,167connector,168mode))169return;170171if (mode->force) {172DRM_INFO("forcing %s connector %s\n", connector->name,173drm_get_connector_force_name(mode->force));174connector->force = mode->force;175}176177if (mode->panel_orientation != DRM_MODE_PANEL_ORIENTATION_UNKNOWN) {178DRM_INFO("cmdline forces connector %s panel_orientation to %d\n",179connector->name, mode->panel_orientation);180drm_connector_set_panel_orientation(connector,181mode->panel_orientation);182}183184DRM_DEBUG_KMS("cmdline mode for connector %s %s %dx%d@%dHz%s%s%s\n",185connector->name, mode->name,186mode->xres, mode->yres,187mode->refresh_specified ? mode->refresh : 60,188mode->rb ? " reduced blanking" : "",189mode->margins ? " with margins" : "",190mode->interlace ? " interlaced" : "");191}192193static void drm_connector_free(struct kref *kref)194{195struct drm_connector *connector =196container_of(kref, struct drm_connector, base.refcount);197struct drm_device *dev = connector->dev;198199drm_mode_object_unregister(dev, &connector->base);200connector->funcs->destroy(connector);201}202203void drm_connector_free_work_fn(struct work_struct *work)204{205struct drm_connector *connector, *n;206struct drm_device *dev =207container_of(work, struct drm_device, mode_config.connector_free_work);208struct drm_mode_config *config = &dev->mode_config;209unsigned long flags;210struct llist_node *freed;211212spin_lock_irqsave(&config->connector_list_lock, flags);213freed = llist_del_all(&config->connector_free_list);214spin_unlock_irqrestore(&config->connector_list_lock, flags);215216llist_for_each_entry_safe(connector, n, freed, free_node) {217drm_mode_object_unregister(dev, &connector->base);218connector->funcs->destroy(connector);219}220}221222static int drm_connector_init_only(struct drm_device *dev,223struct drm_connector *connector,224const struct drm_connector_funcs *funcs,225int connector_type,226struct i2c_adapter *ddc)227{228struct drm_mode_config *config = &dev->mode_config;229int ret;230struct ida *connector_ida =231&drm_connector_enum_list[connector_type].ida;232233WARN_ON(drm_drv_uses_atomic_modeset(dev) &&234(!funcs->atomic_destroy_state ||235!funcs->atomic_duplicate_state));236237ret = __drm_mode_object_add(dev, &connector->base,238DRM_MODE_OBJECT_CONNECTOR,239false, drm_connector_free);240if (ret)241return ret;242243connector->base.properties = &connector->properties;244connector->dev = dev;245connector->funcs = funcs;246247/* connector index is used with 32bit bitmasks */248ret = ida_alloc_max(&config->connector_ida, 31, GFP_KERNEL);249if (ret < 0) {250DRM_DEBUG_KMS("Failed to allocate %s connector index: %d\n",251drm_connector_enum_list[connector_type].name,252ret);253goto out_put;254}255connector->index = ret;256ret = 0;257258connector->connector_type = connector_type;259connector->connector_type_id =260ida_alloc_min(connector_ida, 1, GFP_KERNEL);261if (connector->connector_type_id < 0) {262ret = connector->connector_type_id;263goto out_put_id;264}265connector->name =266kasprintf(GFP_KERNEL, "%s-%d",267drm_connector_enum_list[connector_type].name,268connector->connector_type_id);269if (!connector->name) {270ret = -ENOMEM;271goto out_put_type_id;272}273274/* provide ddc symlink in sysfs */275connector->ddc = ddc;276277INIT_LIST_HEAD(&connector->head);278INIT_LIST_HEAD(&connector->global_connector_list_entry);279INIT_LIST_HEAD(&connector->probed_modes);280INIT_LIST_HEAD(&connector->modes);281mutex_init(&connector->mutex);282mutex_init(&connector->cec.mutex);283mutex_init(&connector->eld_mutex);284mutex_init(&connector->edid_override_mutex);285mutex_init(&connector->hdmi.infoframes.lock);286mutex_init(&connector->hdmi_audio.lock);287connector->edid_blob_ptr = NULL;288connector->epoch_counter = 0;289connector->tile_blob_ptr = NULL;290connector->status = connector_status_unknown;291connector->display_info.panel_orientation =292DRM_MODE_PANEL_ORIENTATION_UNKNOWN;293294drm_connector_get_cmdline_mode(connector);295296if (connector_type != DRM_MODE_CONNECTOR_VIRTUAL &&297connector_type != DRM_MODE_CONNECTOR_WRITEBACK)298drm_connector_attach_edid_property(connector);299300drm_object_attach_property(&connector->base,301config->dpms_property, 0);302303drm_object_attach_property(&connector->base,304config->link_status_property,3050);306307drm_object_attach_property(&connector->base,308config->non_desktop_property,3090);310drm_object_attach_property(&connector->base,311config->tile_property,3120);313314if (drm_core_check_feature(dev, DRIVER_ATOMIC)) {315drm_object_attach_property(&connector->base, config->prop_crtc_id, 0);316}317318connector->debugfs_entry = NULL;319out_put_type_id:320if (ret)321ida_free(connector_ida, connector->connector_type_id);322out_put_id:323if (ret)324ida_free(&config->connector_ida, connector->index);325out_put:326if (ret)327drm_mode_object_unregister(dev, &connector->base);328329return ret;330}331332static void drm_connector_add(struct drm_connector *connector)333{334struct drm_device *dev = connector->dev;335struct drm_mode_config *config = &dev->mode_config;336337if (drm_WARN_ON(dev, !list_empty(&connector->head)))338return;339340spin_lock_irq(&config->connector_list_lock);341list_add_tail(&connector->head, &config->connector_list);342config->num_connector++;343spin_unlock_irq(&config->connector_list_lock);344}345346static void drm_connector_remove(struct drm_connector *connector)347{348struct drm_device *dev = connector->dev;349350/*351* For dynamic connectors drm_connector_cleanup() can call this function352* before the connector is registered and added to the list.353*/354if (list_empty(&connector->head))355return;356357spin_lock_irq(&dev->mode_config.connector_list_lock);358list_del_init(&connector->head);359dev->mode_config.num_connector--;360spin_unlock_irq(&dev->mode_config.connector_list_lock);361}362363static int drm_connector_init_and_add(struct drm_device *dev,364struct drm_connector *connector,365const struct drm_connector_funcs *funcs,366int connector_type,367struct i2c_adapter *ddc)368{369int ret;370371ret = drm_connector_init_only(dev, connector, funcs, connector_type, ddc);372if (ret)373return ret;374375drm_connector_add(connector);376377return 0;378}379380/**381* drm_connector_init - Init a preallocated connector382* @dev: DRM device383* @connector: the connector to init384* @funcs: callbacks for this connector385* @connector_type: user visible type of the connector386*387* Initialises a preallocated connector. Connectors should be388* subclassed as part of driver connector objects.389*390* At driver unload time the driver's &drm_connector_funcs.destroy hook391* should call drm_connector_cleanup() and free the connector structure.392* The connector structure should not be allocated with devm_kzalloc().393*394* Note: consider using drmm_connector_init() instead of395* drm_connector_init() to let the DRM managed resource infrastructure396* take care of cleanup and deallocation.397*398* Returns:399* Zero on success, error code on failure.400*/401int drm_connector_init(struct drm_device *dev,402struct drm_connector *connector,403const struct drm_connector_funcs *funcs,404int connector_type)405{406if (drm_WARN_ON(dev, !(funcs && funcs->destroy)))407return -EINVAL;408409return drm_connector_init_and_add(dev, connector, funcs, connector_type, NULL);410}411EXPORT_SYMBOL(drm_connector_init);412413/**414* drm_connector_dynamic_init - Init a preallocated dynamic connector415* @dev: DRM device416* @connector: the connector to init417* @funcs: callbacks for this connector418* @connector_type: user visible type of the connector419* @ddc: pointer to the associated ddc adapter420*421* Initialises a preallocated dynamic connector. Connectors should be422* subclassed as part of driver connector objects. The connector423* structure should not be allocated with devm_kzalloc().424*425* Drivers should call this for dynamic connectors which can be hotplugged426* after drm_dev_register() has been called already, e.g. DP MST connectors.427* For all other - static - connectors, drivers should call one of the428* drm_connector_init*()/drmm_connector_init*() functions.429*430* After calling this function the drivers must call431* drm_connector_dynamic_register().432*433* To remove the connector the driver must call drm_connector_unregister()434* followed by drm_connector_put(). Putting the last reference will call the435* driver's &drm_connector_funcs.destroy hook, which in turn must call436* drm_connector_cleanup() and free the connector structure.437*438* Returns:439* Zero on success, error code on failure.440*/441int drm_connector_dynamic_init(struct drm_device *dev,442struct drm_connector *connector,443const struct drm_connector_funcs *funcs,444int connector_type,445struct i2c_adapter *ddc)446{447if (drm_WARN_ON(dev, !(funcs && funcs->destroy)))448return -EINVAL;449450return drm_connector_init_only(dev, connector, funcs, connector_type, ddc);451}452EXPORT_SYMBOL(drm_connector_dynamic_init);453454/**455* drm_connector_init_with_ddc - Init a preallocated connector456* @dev: DRM device457* @connector: the connector to init458* @funcs: callbacks for this connector459* @connector_type: user visible type of the connector460* @ddc: pointer to the associated ddc adapter461*462* Initialises a preallocated connector. Connectors should be463* subclassed as part of driver connector objects.464*465* At driver unload time the driver's &drm_connector_funcs.destroy hook466* should call drm_connector_cleanup() and free the connector structure.467* The connector structure should not be allocated with devm_kzalloc().468*469* Ensures that the ddc field of the connector is correctly set.470*471* Note: consider using drmm_connector_init() instead of472* drm_connector_init_with_ddc() to let the DRM managed resource473* infrastructure take care of cleanup and deallocation.474*475* Returns:476* Zero on success, error code on failure.477*/478int drm_connector_init_with_ddc(struct drm_device *dev,479struct drm_connector *connector,480const struct drm_connector_funcs *funcs,481int connector_type,482struct i2c_adapter *ddc)483{484if (drm_WARN_ON(dev, !(funcs && funcs->destroy)))485return -EINVAL;486487return drm_connector_init_and_add(dev, connector, funcs, connector_type, ddc);488}489EXPORT_SYMBOL(drm_connector_init_with_ddc);490491static void drm_connector_cleanup_action(struct drm_device *dev,492void *ptr)493{494struct drm_connector *connector = ptr;495496drm_connector_cleanup(connector);497}498499/**500* drmm_connector_init - Init a preallocated connector501* @dev: DRM device502* @connector: the connector to init503* @funcs: callbacks for this connector504* @connector_type: user visible type of the connector505* @ddc: optional pointer to the associated ddc adapter506*507* Initialises a preallocated connector. Connectors should be508* subclassed as part of driver connector objects.509*510* Cleanup is automatically handled with a call to511* drm_connector_cleanup() in a DRM-managed action.512*513* The connector structure should be allocated with drmm_kzalloc().514*515* The @drm_connector_funcs.destroy hook must be NULL.516*517* Returns:518* Zero on success, error code on failure.519*/520int drmm_connector_init(struct drm_device *dev,521struct drm_connector *connector,522const struct drm_connector_funcs *funcs,523int connector_type,524struct i2c_adapter *ddc)525{526int ret;527528if (drm_WARN_ON(dev, funcs && funcs->destroy))529return -EINVAL;530531ret = drm_connector_init_and_add(dev, connector, funcs, connector_type, ddc);532if (ret)533return ret;534535ret = drmm_add_action_or_reset(dev, drm_connector_cleanup_action,536connector);537if (ret)538return ret;539540return 0;541}542EXPORT_SYMBOL(drmm_connector_init);543544/**545* drmm_connector_hdmi_init - Init a preallocated HDMI connector546* @dev: DRM device547* @connector: A pointer to the HDMI connector to init548* @vendor: HDMI Controller Vendor name549* @product: HDMI Controller Product name550* @funcs: callbacks for this connector551* @hdmi_funcs: HDMI-related callbacks for this connector552* @connector_type: user visible type of the connector553* @ddc: optional pointer to the associated ddc adapter554* @supported_formats: Bitmask of @hdmi_colorspace listing supported output formats555* @max_bpc: Maximum bits per char the HDMI connector supports556*557* Initialises a preallocated HDMI connector. Connectors can be558* subclassed as part of driver connector objects.559*560* Cleanup is automatically handled with a call to561* drm_connector_cleanup() in a DRM-managed action.562*563* The connector structure should be allocated with drmm_kzalloc().564*565* The @drm_connector_funcs.destroy hook must be NULL.566*567* Returns:568* Zero on success, error code on failure.569*/570int drmm_connector_hdmi_init(struct drm_device *dev,571struct drm_connector *connector,572const char *vendor, const char *product,573const struct drm_connector_funcs *funcs,574const struct drm_connector_hdmi_funcs *hdmi_funcs,575int connector_type,576struct i2c_adapter *ddc,577unsigned long supported_formats,578unsigned int max_bpc)579{580int ret;581582if (!vendor || !product)583return -EINVAL;584585if ((strlen(vendor) > DRM_CONNECTOR_HDMI_VENDOR_LEN) ||586(strlen(product) > DRM_CONNECTOR_HDMI_PRODUCT_LEN))587return -EINVAL;588589if (!(connector_type == DRM_MODE_CONNECTOR_HDMIA ||590connector_type == DRM_MODE_CONNECTOR_HDMIB))591return -EINVAL;592593if (!supported_formats || !(supported_formats & BIT(HDMI_COLORSPACE_RGB)))594return -EINVAL;595596if (connector->ycbcr_420_allowed != !!(supported_formats & BIT(HDMI_COLORSPACE_YUV420)))597return -EINVAL;598599if (!(max_bpc == 8 || max_bpc == 10 || max_bpc == 12))600return -EINVAL;601602ret = drmm_connector_init(dev, connector, funcs, connector_type, ddc);603if (ret)604return ret;605606connector->hdmi.supported_formats = supported_formats;607strtomem_pad(connector->hdmi.vendor, vendor, 0);608strtomem_pad(connector->hdmi.product, product, 0);609610/*611* drm_connector_attach_max_bpc_property() requires the612* connector to have a state.613*/614if (connector->funcs->reset)615connector->funcs->reset(connector);616617drm_connector_attach_max_bpc_property(connector, 8, max_bpc);618connector->max_bpc = max_bpc;619620if (max_bpc > 8)621drm_connector_attach_hdr_output_metadata_property(connector);622623connector->hdmi.funcs = hdmi_funcs;624625return 0;626}627EXPORT_SYMBOL(drmm_connector_hdmi_init);628629/**630* drm_connector_attach_edid_property - attach edid property.631* @connector: the connector632*633* Some connector types like DRM_MODE_CONNECTOR_VIRTUAL do not get a634* edid property attached by default. This function can be used to635* explicitly enable the edid property in these cases.636*/637void drm_connector_attach_edid_property(struct drm_connector *connector)638{639struct drm_mode_config *config = &connector->dev->mode_config;640641drm_object_attach_property(&connector->base,642config->edid_property,6430);644}645EXPORT_SYMBOL(drm_connector_attach_edid_property);646647/**648* drm_connector_attach_encoder - attach a connector to an encoder649* @connector: connector to attach650* @encoder: encoder to attach @connector to651*652* This function links up a connector to an encoder. Note that the routing653* restrictions between encoders and crtcs are exposed to userspace through the654* possible_clones and possible_crtcs bitmasks.655*656* Returns:657* Zero on success, negative errno on failure.658*/659int drm_connector_attach_encoder(struct drm_connector *connector,660struct drm_encoder *encoder)661{662/*663* In the past, drivers have attempted to model the static association664* of connector to encoder in simple connector/encoder devices using a665* direct assignment of connector->encoder = encoder. This connection666* is a logical one and the responsibility of the core, so drivers are667* expected not to mess with this.668*669* Note that the error return should've been enough here, but a large670* majority of drivers ignores the return value, so add in a big WARN671* to get people's attention.672*/673if (WARN_ON(connector->encoder))674return -EINVAL;675676connector->possible_encoders |= drm_encoder_mask(encoder);677678return 0;679}680EXPORT_SYMBOL(drm_connector_attach_encoder);681682/**683* drm_connector_has_possible_encoder - check if the connector and encoder are684* associated with each other685* @connector: the connector686* @encoder: the encoder687*688* Returns:689* True if @encoder is one of the possible encoders for @connector.690*/691bool drm_connector_has_possible_encoder(struct drm_connector *connector,692struct drm_encoder *encoder)693{694return connector->possible_encoders & drm_encoder_mask(encoder);695}696EXPORT_SYMBOL(drm_connector_has_possible_encoder);697698static void drm_mode_remove(struct drm_connector *connector,699struct drm_display_mode *mode)700{701list_del(&mode->head);702drm_mode_destroy(connector->dev, mode);703}704705/**706* drm_connector_cec_phys_addr_invalidate - invalidate CEC physical address707* @connector: connector undergoing CEC operation708*709* Invalidated CEC physical address set for this DRM connector.710*/711void drm_connector_cec_phys_addr_invalidate(struct drm_connector *connector)712{713mutex_lock(&connector->cec.mutex);714715if (connector->cec.funcs &&716connector->cec.funcs->phys_addr_invalidate)717connector->cec.funcs->phys_addr_invalidate(connector);718719mutex_unlock(&connector->cec.mutex);720}721EXPORT_SYMBOL(drm_connector_cec_phys_addr_invalidate);722723/**724* drm_connector_cec_phys_addr_set - propagate CEC physical address725* @connector: connector undergoing CEC operation726*727* Propagate CEC physical address from the display_info to this DRM connector.728*/729void drm_connector_cec_phys_addr_set(struct drm_connector *connector)730{731u16 addr;732733mutex_lock(&connector->cec.mutex);734735addr = connector->display_info.source_physical_address;736737if (connector->cec.funcs &&738connector->cec.funcs->phys_addr_set)739connector->cec.funcs->phys_addr_set(connector, addr);740741mutex_unlock(&connector->cec.mutex);742}743EXPORT_SYMBOL(drm_connector_cec_phys_addr_set);744745/**746* drm_connector_cleanup - cleans up an initialised connector747* @connector: connector to cleanup748*749* Cleans up the connector but doesn't free the object.750*/751void drm_connector_cleanup(struct drm_connector *connector)752{753struct drm_device *dev = connector->dev;754struct drm_display_mode *mode, *t;755756/* The connector should have been removed from userspace long before757* it is finally destroyed.758*/759if (WARN_ON(connector->registration_state ==760DRM_CONNECTOR_REGISTERED))761drm_connector_unregister(connector);762763platform_device_unregister(connector->hdmi_audio.codec_pdev);764765if (connector->privacy_screen) {766drm_privacy_screen_put(connector->privacy_screen);767connector->privacy_screen = NULL;768}769770if (connector->tile_group) {771drm_mode_put_tile_group(dev, connector->tile_group);772connector->tile_group = NULL;773}774775list_for_each_entry_safe(mode, t, &connector->probed_modes, head)776drm_mode_remove(connector, mode);777778list_for_each_entry_safe(mode, t, &connector->modes, head)779drm_mode_remove(connector, mode);780781ida_free(&drm_connector_enum_list[connector->connector_type].ida,782connector->connector_type_id);783784ida_free(&dev->mode_config.connector_ida, connector->index);785786kfree(connector->display_info.bus_formats);787kfree(connector->display_info.vics);788drm_mode_object_unregister(dev, &connector->base);789kfree(connector->name);790connector->name = NULL;791fwnode_handle_put(connector->fwnode);792connector->fwnode = NULL;793794drm_connector_remove(connector);795796WARN_ON(connector->state && !connector->funcs->atomic_destroy_state);797if (connector->state && connector->funcs->atomic_destroy_state)798connector->funcs->atomic_destroy_state(connector,799connector->state);800801mutex_destroy(&connector->hdmi_audio.lock);802mutex_destroy(&connector->hdmi.infoframes.lock);803mutex_destroy(&connector->mutex);804805memset(connector, 0, sizeof(*connector));806807if (dev->registered)808drm_sysfs_hotplug_event(dev);809}810EXPORT_SYMBOL(drm_connector_cleanup);811812/**813* drm_connector_register - register a connector814* @connector: the connector to register815*816* Register userspace interfaces for a connector. Drivers shouldn't call this817* function. Static connectors will be registered automatically by DRM core818* from drm_dev_register(), dynamic connectors (MST) should be registered by819* drivers calling drm_connector_dynamic_register().820*821* When the connector is no longer available, callers must call822* drm_connector_unregister().823*824* Note: Existing uses of this function in drivers should be a nop already and825* are scheduled to be removed.826*827* Returns:828* Zero on success, error code on failure.829*/830int drm_connector_register(struct drm_connector *connector)831{832int ret = 0;833834if (!connector->dev->registered)835return 0;836837mutex_lock(&connector->mutex);838if (connector->registration_state != DRM_CONNECTOR_INITIALIZING)839goto unlock;840841ret = drm_sysfs_connector_add(connector);842if (ret)843goto unlock;844845drm_debugfs_connector_add(connector);846847if (connector->funcs->late_register) {848ret = connector->funcs->late_register(connector);849if (ret)850goto err_debugfs;851}852853ret = drm_sysfs_connector_add_late(connector);854if (ret)855goto err_late_register;856857drm_mode_object_register(connector->dev, &connector->base);858859connector->registration_state = DRM_CONNECTOR_REGISTERED;860861/* Let userspace know we have a new connector */862drm_sysfs_connector_hotplug_event(connector);863864if (connector->privacy_screen)865drm_privacy_screen_register_notifier(connector->privacy_screen,866&connector->privacy_screen_notifier);867868mutex_lock(&connector_list_lock);869list_add_tail(&connector->global_connector_list_entry, &connector_list);870mutex_unlock(&connector_list_lock);871goto unlock;872873err_late_register:874if (connector->funcs->early_unregister)875connector->funcs->early_unregister(connector);876err_debugfs:877drm_debugfs_connector_remove(connector);878drm_sysfs_connector_remove(connector);879unlock:880mutex_unlock(&connector->mutex);881return ret;882}883EXPORT_SYMBOL(drm_connector_register);884885/**886* drm_connector_dynamic_register - register a dynamic connector887* @connector: the connector to register888*889* Register userspace interfaces for a connector. Only call this for connectors890* initialized by calling drm_connector_dynamic_init(). All other connectors891* will be registered automatically when calling drm_dev_register().892*893* When the connector is no longer available the driver must call894* drm_connector_unregister().895*896* Returns:897* Zero on success, error code on failure.898*/899int drm_connector_dynamic_register(struct drm_connector *connector)900{901/* Was the connector inited already? */902if (WARN_ON(!(connector->funcs && connector->funcs->destroy)))903return -EINVAL;904905drm_connector_add(connector);906907return drm_connector_register(connector);908}909EXPORT_SYMBOL(drm_connector_dynamic_register);910911/**912* drm_connector_unregister - unregister a connector913* @connector: the connector to unregister914*915* Unregister userspace interfaces for a connector. Drivers should call this916* for dynamic connectors (MST) only, which were registered explicitly by917* calling drm_connector_dynamic_register(). All other - static - connectors918* will be unregistered automatically by DRM core and drivers shouldn't call919* this function for those.920*921* Note: Existing uses of this function in drivers for static connectors922* should be a nop already and are scheduled to be removed.923*/924void drm_connector_unregister(struct drm_connector *connector)925{926mutex_lock(&connector->mutex);927if (connector->registration_state != DRM_CONNECTOR_REGISTERED) {928mutex_unlock(&connector->mutex);929return;930}931932mutex_lock(&connector_list_lock);933list_del_init(&connector->global_connector_list_entry);934mutex_unlock(&connector_list_lock);935936if (connector->privacy_screen)937drm_privacy_screen_unregister_notifier(938connector->privacy_screen,939&connector->privacy_screen_notifier);940941drm_sysfs_connector_remove_early(connector);942943if (connector->funcs->early_unregister)944connector->funcs->early_unregister(connector);945946drm_debugfs_connector_remove(connector);947drm_sysfs_connector_remove(connector);948949connector->registration_state = DRM_CONNECTOR_UNREGISTERED;950mutex_unlock(&connector->mutex);951}952EXPORT_SYMBOL(drm_connector_unregister);953954void drm_connector_unregister_all(struct drm_device *dev)955{956struct drm_connector *connector;957struct drm_connector_list_iter conn_iter;958959drm_connector_list_iter_begin(dev, &conn_iter);960drm_for_each_connector_iter(connector, &conn_iter)961drm_connector_unregister(connector);962drm_connector_list_iter_end(&conn_iter);963}964965int drm_connector_register_all(struct drm_device *dev)966{967struct drm_connector *connector;968struct drm_connector_list_iter conn_iter;969int ret = 0;970971drm_connector_list_iter_begin(dev, &conn_iter);972drm_for_each_connector_iter(connector, &conn_iter) {973ret = drm_connector_register(connector);974if (ret)975break;976}977drm_connector_list_iter_end(&conn_iter);978979if (ret)980drm_connector_unregister_all(dev);981return ret;982}983984/**985* drm_get_connector_status_name - return a string for connector status986* @status: connector status to compute name of987*988* In contrast to the other drm_get_*_name functions this one here returns a989* const pointer and hence is threadsafe.990*991* Returns: connector status string992*/993const char *drm_get_connector_status_name(enum drm_connector_status status)994{995if (status == connector_status_connected)996return "connected";997else if (status == connector_status_disconnected)998return "disconnected";999else1000return "unknown";1001}1002EXPORT_SYMBOL(drm_get_connector_status_name);10031004/**1005* drm_get_connector_force_name - return a string for connector force1006* @force: connector force to get name of1007*1008* Returns: const pointer to name.1009*/1010const char *drm_get_connector_force_name(enum drm_connector_force force)1011{1012switch (force) {1013case DRM_FORCE_UNSPECIFIED:1014return "unspecified";1015case DRM_FORCE_OFF:1016return "off";1017case DRM_FORCE_ON:1018return "on";1019case DRM_FORCE_ON_DIGITAL:1020return "digital";1021default:1022return "unknown";1023}1024}10251026#ifdef CONFIG_LOCKDEP1027static struct lockdep_map connector_list_iter_dep_map = {1028.name = "drm_connector_list_iter"1029};1030#endif10311032/**1033* drm_connector_list_iter_begin - initialize a connector_list iterator1034* @dev: DRM device1035* @iter: connector_list iterator1036*1037* Sets @iter up to walk the &drm_mode_config.connector_list of @dev. @iter1038* must always be cleaned up again by calling drm_connector_list_iter_end().1039* Iteration itself happens using drm_connector_list_iter_next() or1040* drm_for_each_connector_iter().1041*/1042void drm_connector_list_iter_begin(struct drm_device *dev,1043struct drm_connector_list_iter *iter)1044{1045iter->dev = dev;1046iter->conn = NULL;1047lock_acquire_shared_recursive(&connector_list_iter_dep_map, 0, 1, NULL, _RET_IP_);1048}1049EXPORT_SYMBOL(drm_connector_list_iter_begin);10501051/*1052* Extra-safe connector put function that works in any context. Should only be1053* used from the connector_iter functions, where we never really expect to1054* actually release the connector when dropping our final reference.1055*/1056static void1057__drm_connector_put_safe(struct drm_connector *conn)1058{1059struct drm_mode_config *config = &conn->dev->mode_config;10601061lockdep_assert_held(&config->connector_list_lock);10621063if (!refcount_dec_and_test(&conn->base.refcount.refcount))1064return;10651066llist_add(&conn->free_node, &config->connector_free_list);1067schedule_work(&config->connector_free_work);1068}10691070/**1071* drm_connector_list_iter_next - return next connector1072* @iter: connector_list iterator1073*1074* Returns: the next connector for @iter, or NULL when the list walk has1075* completed.1076*/1077struct drm_connector *1078drm_connector_list_iter_next(struct drm_connector_list_iter *iter)1079{1080struct drm_connector *old_conn = iter->conn;1081struct drm_mode_config *config = &iter->dev->mode_config;1082struct list_head *lhead;1083unsigned long flags;10841085spin_lock_irqsave(&config->connector_list_lock, flags);1086lhead = old_conn ? &old_conn->head : &config->connector_list;10871088do {1089if (lhead->next == &config->connector_list) {1090iter->conn = NULL;1091break;1092}10931094lhead = lhead->next;1095iter->conn = list_entry(lhead, struct drm_connector, head);10961097/* loop until it's not a zombie connector */1098} while (!kref_get_unless_zero(&iter->conn->base.refcount));10991100if (old_conn)1101__drm_connector_put_safe(old_conn);1102spin_unlock_irqrestore(&config->connector_list_lock, flags);11031104return iter->conn;1105}1106EXPORT_SYMBOL(drm_connector_list_iter_next);11071108/**1109* drm_connector_list_iter_end - tear down a connector_list iterator1110* @iter: connector_list iterator1111*1112* Tears down @iter and releases any resources (like &drm_connector references)1113* acquired while walking the list. This must always be called, both when the1114* iteration completes fully or when it was aborted without walking the entire1115* list.1116*/1117void drm_connector_list_iter_end(struct drm_connector_list_iter *iter)1118{1119struct drm_mode_config *config = &iter->dev->mode_config;1120unsigned long flags;11211122iter->dev = NULL;1123if (iter->conn) {1124spin_lock_irqsave(&config->connector_list_lock, flags);1125__drm_connector_put_safe(iter->conn);1126spin_unlock_irqrestore(&config->connector_list_lock, flags);1127}1128lock_release(&connector_list_iter_dep_map, _RET_IP_);1129}1130EXPORT_SYMBOL(drm_connector_list_iter_end);11311132static const struct drm_prop_enum_list drm_subpixel_enum_list[] = {1133{ SubPixelUnknown, "Unknown" },1134{ SubPixelHorizontalRGB, "Horizontal RGB" },1135{ SubPixelHorizontalBGR, "Horizontal BGR" },1136{ SubPixelVerticalRGB, "Vertical RGB" },1137{ SubPixelVerticalBGR, "Vertical BGR" },1138{ SubPixelNone, "None" },1139};11401141/**1142* drm_get_subpixel_order_name - return a string for a given subpixel enum1143* @order: enum of subpixel_order1144*1145* Note you could abuse this and return something out of bounds, but that1146* would be a caller error. No unscrubbed user data should make it here.1147*1148* Returns: string describing an enumerated subpixel property1149*/1150const char *drm_get_subpixel_order_name(enum subpixel_order order)1151{1152return drm_subpixel_enum_list[order].name;1153}1154EXPORT_SYMBOL(drm_get_subpixel_order_name);11551156static const struct drm_prop_enum_list drm_dpms_enum_list[] = {1157{ DRM_MODE_DPMS_ON, "On" },1158{ DRM_MODE_DPMS_STANDBY, "Standby" },1159{ DRM_MODE_DPMS_SUSPEND, "Suspend" },1160{ DRM_MODE_DPMS_OFF, "Off" }1161};1162DRM_ENUM_NAME_FN(drm_get_dpms_name, drm_dpms_enum_list)11631164static const struct drm_prop_enum_list drm_link_status_enum_list[] = {1165{ DRM_MODE_LINK_STATUS_GOOD, "Good" },1166{ DRM_MODE_LINK_STATUS_BAD, "Bad" },1167};11681169/**1170* drm_display_info_set_bus_formats - set the supported bus formats1171* @info: display info to store bus formats in1172* @formats: array containing the supported bus formats1173* @num_formats: the number of entries in the fmts array1174*1175* Store the supported bus formats in display info structure.1176* See MEDIA_BUS_FMT_* definitions in include/uapi/linux/media-bus-format.h for1177* a full list of available formats.1178*1179* Returns:1180* 0 on success or a negative error code on failure.1181*/1182int drm_display_info_set_bus_formats(struct drm_display_info *info,1183const u32 *formats,1184unsigned int num_formats)1185{1186u32 *fmts = NULL;11871188if (!formats && num_formats)1189return -EINVAL;11901191if (formats && num_formats) {1192fmts = kmemdup(formats, sizeof(*formats) * num_formats,1193GFP_KERNEL);1194if (!fmts)1195return -ENOMEM;1196}11971198kfree(info->bus_formats);1199info->bus_formats = fmts;1200info->num_bus_formats = num_formats;12011202return 0;1203}1204EXPORT_SYMBOL(drm_display_info_set_bus_formats);12051206/* Optional connector properties. */1207static const struct drm_prop_enum_list drm_scaling_mode_enum_list[] = {1208{ DRM_MODE_SCALE_NONE, "None" },1209{ DRM_MODE_SCALE_FULLSCREEN, "Full" },1210{ DRM_MODE_SCALE_CENTER, "Center" },1211{ DRM_MODE_SCALE_ASPECT, "Full aspect" },1212};12131214static const struct drm_prop_enum_list drm_aspect_ratio_enum_list[] = {1215{ DRM_MODE_PICTURE_ASPECT_NONE, "Automatic" },1216{ DRM_MODE_PICTURE_ASPECT_4_3, "4:3" },1217{ DRM_MODE_PICTURE_ASPECT_16_9, "16:9" },1218};12191220static const struct drm_prop_enum_list drm_content_type_enum_list[] = {1221{ DRM_MODE_CONTENT_TYPE_NO_DATA, "No Data" },1222{ DRM_MODE_CONTENT_TYPE_GRAPHICS, "Graphics" },1223{ DRM_MODE_CONTENT_TYPE_PHOTO, "Photo" },1224{ DRM_MODE_CONTENT_TYPE_CINEMA, "Cinema" },1225{ DRM_MODE_CONTENT_TYPE_GAME, "Game" },1226};12271228static const struct drm_prop_enum_list drm_panel_orientation_enum_list[] = {1229{ DRM_MODE_PANEL_ORIENTATION_NORMAL, "Normal" },1230{ DRM_MODE_PANEL_ORIENTATION_BOTTOM_UP, "Upside Down" },1231{ DRM_MODE_PANEL_ORIENTATION_LEFT_UP, "Left Side Up" },1232{ DRM_MODE_PANEL_ORIENTATION_RIGHT_UP, "Right Side Up" },1233};12341235static const struct drm_prop_enum_list drm_dvi_i_select_enum_list[] = {1236{ DRM_MODE_SUBCONNECTOR_Automatic, "Automatic" }, /* DVI-I and TV-out */1237{ DRM_MODE_SUBCONNECTOR_DVID, "DVI-D" }, /* DVI-I */1238{ DRM_MODE_SUBCONNECTOR_DVIA, "DVI-A" }, /* DVI-I */1239};1240DRM_ENUM_NAME_FN(drm_get_dvi_i_select_name, drm_dvi_i_select_enum_list)12411242static const struct drm_prop_enum_list drm_dvi_i_subconnector_enum_list[] = {1243{ DRM_MODE_SUBCONNECTOR_Unknown, "Unknown" }, /* DVI-I, TV-out and DP */1244{ DRM_MODE_SUBCONNECTOR_DVID, "DVI-D" }, /* DVI-I */1245{ DRM_MODE_SUBCONNECTOR_DVIA, "DVI-A" }, /* DVI-I */1246};1247DRM_ENUM_NAME_FN(drm_get_dvi_i_subconnector_name,1248drm_dvi_i_subconnector_enum_list)12491250static const struct drm_prop_enum_list drm_tv_mode_enum_list[] = {1251{ DRM_MODE_TV_MODE_NTSC, "NTSC" },1252{ DRM_MODE_TV_MODE_NTSC_443, "NTSC-443" },1253{ DRM_MODE_TV_MODE_NTSC_J, "NTSC-J" },1254{ DRM_MODE_TV_MODE_PAL, "PAL" },1255{ DRM_MODE_TV_MODE_PAL_M, "PAL-M" },1256{ DRM_MODE_TV_MODE_PAL_N, "PAL-N" },1257{ DRM_MODE_TV_MODE_SECAM, "SECAM" },1258{ DRM_MODE_TV_MODE_MONOCHROME, "Mono" },1259};1260DRM_ENUM_NAME_FN(drm_get_tv_mode_name, drm_tv_mode_enum_list)12611262/**1263* drm_get_tv_mode_from_name - Translates a TV mode name into its enum value1264* @name: TV Mode name we want to convert1265* @len: Length of @name1266*1267* Translates @name into an enum drm_connector_tv_mode.1268*1269* Returns: the enum value on success, a negative errno otherwise.1270*/1271int drm_get_tv_mode_from_name(const char *name, size_t len)1272{1273unsigned int i;12741275for (i = 0; i < ARRAY_SIZE(drm_tv_mode_enum_list); i++) {1276const struct drm_prop_enum_list *item = &drm_tv_mode_enum_list[i];12771278if (strlen(item->name) == len && !strncmp(item->name, name, len))1279return item->type;1280}12811282return -EINVAL;1283}1284EXPORT_SYMBOL(drm_get_tv_mode_from_name);12851286static const struct drm_prop_enum_list drm_tv_select_enum_list[] = {1287{ DRM_MODE_SUBCONNECTOR_Automatic, "Automatic" }, /* DVI-I and TV-out */1288{ DRM_MODE_SUBCONNECTOR_Composite, "Composite" }, /* TV-out */1289{ DRM_MODE_SUBCONNECTOR_SVIDEO, "SVIDEO" }, /* TV-out */1290{ DRM_MODE_SUBCONNECTOR_Component, "Component" }, /* TV-out */1291{ DRM_MODE_SUBCONNECTOR_SCART, "SCART" }, /* TV-out */1292};1293DRM_ENUM_NAME_FN(drm_get_tv_select_name, drm_tv_select_enum_list)12941295static const struct drm_prop_enum_list drm_tv_subconnector_enum_list[] = {1296{ DRM_MODE_SUBCONNECTOR_Unknown, "Unknown" }, /* DVI-I, TV-out and DP */1297{ DRM_MODE_SUBCONNECTOR_Composite, "Composite" }, /* TV-out */1298{ DRM_MODE_SUBCONNECTOR_SVIDEO, "SVIDEO" }, /* TV-out */1299{ DRM_MODE_SUBCONNECTOR_Component, "Component" }, /* TV-out */1300{ DRM_MODE_SUBCONNECTOR_SCART, "SCART" }, /* TV-out */1301};1302DRM_ENUM_NAME_FN(drm_get_tv_subconnector_name,1303drm_tv_subconnector_enum_list)13041305static const struct drm_prop_enum_list drm_dp_subconnector_enum_list[] = {1306{ DRM_MODE_SUBCONNECTOR_Unknown, "Unknown" }, /* DVI-I, TV-out and DP */1307{ DRM_MODE_SUBCONNECTOR_VGA, "VGA" }, /* DP */1308{ DRM_MODE_SUBCONNECTOR_DVID, "DVI-D" }, /* DP */1309{ DRM_MODE_SUBCONNECTOR_HDMIA, "HDMI" }, /* DP */1310{ DRM_MODE_SUBCONNECTOR_DisplayPort, "DP" }, /* DP */1311{ DRM_MODE_SUBCONNECTOR_Wireless, "Wireless" }, /* DP */1312{ DRM_MODE_SUBCONNECTOR_Native, "Native" }, /* DP */1313};13141315DRM_ENUM_NAME_FN(drm_get_dp_subconnector_name,1316drm_dp_subconnector_enum_list)131713181319static const char * const colorspace_names[] = {1320/* For Default case, driver will set the colorspace */1321[DRM_MODE_COLORIMETRY_DEFAULT] = "Default",1322/* Standard Definition Colorimetry based on CEA 861 */1323[DRM_MODE_COLORIMETRY_SMPTE_170M_YCC] = "SMPTE_170M_YCC",1324[DRM_MODE_COLORIMETRY_BT709_YCC] = "BT709_YCC",1325/* Standard Definition Colorimetry based on IEC 61966-2-4 */1326[DRM_MODE_COLORIMETRY_XVYCC_601] = "XVYCC_601",1327/* High Definition Colorimetry based on IEC 61966-2-4 */1328[DRM_MODE_COLORIMETRY_XVYCC_709] = "XVYCC_709",1329/* Colorimetry based on IEC 61966-2-1/Amendment 1 */1330[DRM_MODE_COLORIMETRY_SYCC_601] = "SYCC_601",1331/* Colorimetry based on IEC 61966-2-5 [33] */1332[DRM_MODE_COLORIMETRY_OPYCC_601] = "opYCC_601",1333/* Colorimetry based on IEC 61966-2-5 */1334[DRM_MODE_COLORIMETRY_OPRGB] = "opRGB",1335/* Colorimetry based on ITU-R BT.2020 */1336[DRM_MODE_COLORIMETRY_BT2020_CYCC] = "BT2020_CYCC",1337/* Colorimetry based on ITU-R BT.2020 */1338[DRM_MODE_COLORIMETRY_BT2020_RGB] = "BT2020_RGB",1339/* Colorimetry based on ITU-R BT.2020 */1340[DRM_MODE_COLORIMETRY_BT2020_YCC] = "BT2020_YCC",1341/* Added as part of Additional Colorimetry Extension in 861.G */1342[DRM_MODE_COLORIMETRY_DCI_P3_RGB_D65] = "DCI-P3_RGB_D65",1343[DRM_MODE_COLORIMETRY_DCI_P3_RGB_THEATER] = "DCI-P3_RGB_Theater",1344[DRM_MODE_COLORIMETRY_RGB_WIDE_FIXED] = "RGB_WIDE_FIXED",1345/* Colorimetry based on scRGB (IEC 61966-2-2) */1346[DRM_MODE_COLORIMETRY_RGB_WIDE_FLOAT] = "RGB_WIDE_FLOAT",1347[DRM_MODE_COLORIMETRY_BT601_YCC] = "BT601_YCC",1348};13491350/**1351* drm_get_colorspace_name - return a string for color encoding1352* @colorspace: color space to compute name of1353*1354* In contrast to the other drm_get_*_name functions this one here returns a1355* const pointer and hence is threadsafe.1356*/1357const char *drm_get_colorspace_name(enum drm_colorspace colorspace)1358{1359if (colorspace < ARRAY_SIZE(colorspace_names) && colorspace_names[colorspace])1360return colorspace_names[colorspace];1361else1362return "(null)";1363}13641365static const u32 hdmi_colorspaces =1366BIT(DRM_MODE_COLORIMETRY_SMPTE_170M_YCC) |1367BIT(DRM_MODE_COLORIMETRY_BT709_YCC) |1368BIT(DRM_MODE_COLORIMETRY_XVYCC_601) |1369BIT(DRM_MODE_COLORIMETRY_XVYCC_709) |1370BIT(DRM_MODE_COLORIMETRY_SYCC_601) |1371BIT(DRM_MODE_COLORIMETRY_OPYCC_601) |1372BIT(DRM_MODE_COLORIMETRY_OPRGB) |1373BIT(DRM_MODE_COLORIMETRY_BT2020_CYCC) |1374BIT(DRM_MODE_COLORIMETRY_BT2020_RGB) |1375BIT(DRM_MODE_COLORIMETRY_BT2020_YCC) |1376BIT(DRM_MODE_COLORIMETRY_DCI_P3_RGB_D65) |1377BIT(DRM_MODE_COLORIMETRY_DCI_P3_RGB_THEATER);13781379/*1380* As per DP 1.4a spec, 2.2.5.7.5 VSC SDP Payload for Pixel Encoding/Colorimetry1381* Format Table 2-1201382*/1383static const u32 dp_colorspaces =1384BIT(DRM_MODE_COLORIMETRY_RGB_WIDE_FIXED) |1385BIT(DRM_MODE_COLORIMETRY_RGB_WIDE_FLOAT) |1386BIT(DRM_MODE_COLORIMETRY_OPRGB) |1387BIT(DRM_MODE_COLORIMETRY_DCI_P3_RGB_D65) |1388BIT(DRM_MODE_COLORIMETRY_BT2020_RGB) |1389BIT(DRM_MODE_COLORIMETRY_BT601_YCC) |1390BIT(DRM_MODE_COLORIMETRY_BT709_YCC) |1391BIT(DRM_MODE_COLORIMETRY_XVYCC_601) |1392BIT(DRM_MODE_COLORIMETRY_XVYCC_709) |1393BIT(DRM_MODE_COLORIMETRY_SYCC_601) |1394BIT(DRM_MODE_COLORIMETRY_OPYCC_601) |1395BIT(DRM_MODE_COLORIMETRY_BT2020_CYCC) |1396BIT(DRM_MODE_COLORIMETRY_BT2020_YCC);13971398static const struct drm_prop_enum_list broadcast_rgb_names[] = {1399{ DRM_HDMI_BROADCAST_RGB_AUTO, "Automatic" },1400{ DRM_HDMI_BROADCAST_RGB_FULL, "Full" },1401{ DRM_HDMI_BROADCAST_RGB_LIMITED, "Limited 16:235" },1402};14031404/*1405* drm_hdmi_connector_get_broadcast_rgb_name - Return a string for HDMI connector RGB broadcast selection1406* @broadcast_rgb: Broadcast RGB selection to compute name of1407*1408* Returns: the name of the Broadcast RGB selection, or NULL if the type1409* is not valid.1410*/1411const char *1412drm_hdmi_connector_get_broadcast_rgb_name(enum drm_hdmi_broadcast_rgb broadcast_rgb)1413{1414if (broadcast_rgb >= ARRAY_SIZE(broadcast_rgb_names))1415return NULL;14161417return broadcast_rgb_names[broadcast_rgb].name;1418}1419EXPORT_SYMBOL(drm_hdmi_connector_get_broadcast_rgb_name);14201421static const char * const output_format_str[] = {1422[HDMI_COLORSPACE_RGB] = "RGB",1423[HDMI_COLORSPACE_YUV420] = "YUV 4:2:0",1424[HDMI_COLORSPACE_YUV422] = "YUV 4:2:2",1425[HDMI_COLORSPACE_YUV444] = "YUV 4:4:4",1426};14271428/*1429* drm_hdmi_connector_get_output_format_name() - Return a string for HDMI connector output format1430* @fmt: Output format to compute name of1431*1432* Returns: the name of the output format, or NULL if the type is not1433* valid.1434*/1435const char *1436drm_hdmi_connector_get_output_format_name(enum hdmi_colorspace fmt)1437{1438if (fmt >= ARRAY_SIZE(output_format_str))1439return NULL;14401441return output_format_str[fmt];1442}1443EXPORT_SYMBOL(drm_hdmi_connector_get_output_format_name);14441445/**1446* DOC: standard connector properties1447*1448* DRM connectors have a few standardized properties:1449*1450* EDID:1451* Blob property which contains the current EDID read from the sink. This1452* is useful to parse sink identification information like vendor, model1453* and serial. Drivers should update this property by calling1454* drm_connector_update_edid_property(), usually after having parsed1455* the EDID using drm_add_edid_modes(). Userspace cannot change this1456* property.1457*1458* User-space should not parse the EDID to obtain information exposed via1459* other KMS properties (because the kernel might apply limits, quirks or1460* fixups to the EDID). For instance, user-space should not try to parse1461* mode lists from the EDID.1462* DPMS:1463* Legacy property for setting the power state of the connector. For atomic1464* drivers this is only provided for backwards compatibility with existing1465* drivers, it remaps to controlling the "ACTIVE" property on the CRTC the1466* connector is linked to. Drivers should never set this property directly,1467* it is handled by the DRM core by calling the &drm_connector_funcs.dpms1468* callback. For atomic drivers the remapping to the "ACTIVE" property is1469* implemented in the DRM core.1470*1471* On atomic drivers any DPMS setproperty ioctl where the value does not1472* change is completely skipped, otherwise a full atomic commit will occur.1473* On legacy drivers the exact behavior is driver specific.1474*1475* Note that this property cannot be set through the MODE_ATOMIC ioctl,1476* userspace must use "ACTIVE" on the CRTC instead.1477*1478* WARNING:1479*1480* For userspace also running on legacy drivers the "DPMS" semantics are a1481* lot more complicated. First, userspace cannot rely on the "DPMS" value1482* returned by the GETCONNECTOR actually reflecting reality, because many1483* drivers fail to update it. For atomic drivers this is taken care of in1484* drm_atomic_helper_update_legacy_modeset_state().1485*1486* The second issue is that the DPMS state is only well-defined when the1487* connector is connected to a CRTC. In atomic the DRM core enforces that1488* "ACTIVE" is off in such a case, no such checks exists for "DPMS".1489*1490* Finally, when enabling an output using the legacy SETCONFIG ioctl then1491* "DPMS" is forced to ON. But see above, that might not be reflected in1492* the software value on legacy drivers.1493*1494* Summarizing: Only set "DPMS" when the connector is known to be enabled,1495* assume that a successful SETCONFIG call also sets "DPMS" to on, and1496* never read back the value of "DPMS" because it can be incorrect.1497* PATH:1498* Connector path property to identify how this sink is physically1499* connected. Used by DP MST. This should be set by calling1500* drm_connector_set_path_property(), in the case of DP MST with the1501* path property the MST manager created. Userspace cannot change this1502* property.1503*1504* In the case of DP MST, the property has the format1505* ``mst:<parent>-<ports>`` where ``<parent>`` is the KMS object ID of the1506* parent connector and ``<ports>`` is a hyphen-separated list of DP MST1507* port numbers. Note, KMS object IDs are not guaranteed to be stable1508* across reboots.1509* TILE:1510* Connector tile group property to indicate how a set of DRM connector1511* compose together into one logical screen. This is used by both high-res1512* external screens (often only using a single cable, but exposing multiple1513* DP MST sinks), or high-res integrated panels (like dual-link DSI) which1514* are not gen-locked. Note that for tiled panels which are genlocked, like1515* dual-link LVDS or dual-link DSI, the driver should try to not expose the1516* tiling and virtualise both &drm_crtc and &drm_plane if needed. Drivers1517* should update this value using drm_connector_set_tile_property().1518* Userspace cannot change this property.1519* link-status:1520* Connector link-status property to indicate the status of link. The1521* default value of link-status is "GOOD". If something fails during or1522* after modeset, the kernel driver may set this to "BAD" and issue a1523* hotplug uevent. Drivers should update this value using1524* drm_connector_set_link_status_property().1525*1526* When user-space receives the hotplug uevent and detects a "BAD"1527* link-status, the sink doesn't receive pixels anymore (e.g. the screen1528* becomes completely black). The list of available modes may have1529* changed. User-space is expected to pick a new mode if the current one1530* has disappeared and perform a new modeset with link-status set to1531* "GOOD" to re-enable the connector.1532*1533* If multiple connectors share the same CRTC and one of them gets a "BAD"1534* link-status, the other are unaffected (ie. the sinks still continue to1535* receive pixels).1536*1537* When user-space performs an atomic commit on a connector with a "BAD"1538* link-status without resetting the property to "GOOD", the sink may1539* still not receive pixels. When user-space performs an atomic commit1540* which resets the link-status property to "GOOD" without the1541* ALLOW_MODESET flag set, it might fail because a modeset is required.1542*1543* User-space can only change link-status to "GOOD", changing it to "BAD"1544* is a no-op.1545*1546* For backwards compatibility with non-atomic userspace the kernel1547* tries to automatically set the link-status back to "GOOD" in the1548* SETCRTC IOCTL. This might fail if the mode is no longer valid, similar1549* to how it might fail if a different screen has been connected in the1550* interim.1551* non_desktop:1552* Indicates the output should be ignored for purposes of displaying a1553* standard desktop environment or console. This is most likely because1554* the output device is not rectilinear.1555* Content Protection:1556* This property is used by userspace to request the kernel protect future1557* content communicated over the link. When requested, kernel will apply1558* the appropriate means of protection (most often HDCP), and use the1559* property to tell userspace the protection is active.1560*1561* Drivers can set this up by calling1562* drm_connector_attach_content_protection_property() on initialization.1563*1564* The value of this property can be one of the following:1565*1566* DRM_MODE_CONTENT_PROTECTION_UNDESIRED = 01567* The link is not protected, content is transmitted in the clear.1568* DRM_MODE_CONTENT_PROTECTION_DESIRED = 11569* Userspace has requested content protection, but the link is not1570* currently protected. When in this state, kernel should enable1571* Content Protection as soon as possible.1572* DRM_MODE_CONTENT_PROTECTION_ENABLED = 21573* Userspace has requested content protection, and the link is1574* protected. Only the driver can set the property to this value.1575* If userspace attempts to set to ENABLED, kernel will return1576* -EINVAL.1577*1578* A few guidelines:1579*1580* - DESIRED state should be preserved until userspace de-asserts it by1581* setting the property to UNDESIRED. This means ENABLED should only1582* transition to UNDESIRED when the user explicitly requests it.1583* - If the state is DESIRED, kernel should attempt to re-authenticate the1584* link whenever possible. This includes across disable/enable, dpms,1585* hotplug, downstream device changes, link status failures, etc..1586* - Kernel sends uevent with the connector id and property id through1587* @drm_hdcp_update_content_protection, upon below kernel triggered1588* scenarios:1589*1590* - DESIRED -> ENABLED (authentication success)1591* - ENABLED -> DESIRED (termination of authentication)1592* - Please note no uevents for userspace triggered property state changes,1593* which can't fail such as1594*1595* - DESIRED/ENABLED -> UNDESIRED1596* - UNDESIRED -> DESIRED1597* - Userspace is responsible for polling the property or listen to uevents1598* to determine when the value transitions from ENABLED to DESIRED.1599* This signifies the link is no longer protected and userspace should1600* take appropriate action (whatever that might be).1601*1602* HDCP Content Type:1603* This Enum property is used by the userspace to declare the content type1604* of the display stream, to kernel. Here display stream stands for any1605* display content that userspace intended to display through HDCP1606* encryption.1607*1608* Content Type of a stream is decided by the owner of the stream, as1609* "HDCP Type0" or "HDCP Type1".1610*1611* The value of the property can be one of the below:1612* - "HDCP Type0": DRM_MODE_HDCP_CONTENT_TYPE0 = 01613* - "HDCP Type1": DRM_MODE_HDCP_CONTENT_TYPE1 = 11614*1615* When kernel starts the HDCP authentication (see "Content Protection"1616* for details), it uses the content type in "HDCP Content Type"1617* for performing the HDCP authentication with the display sink.1618*1619* Please note in HDCP spec versions, a link can be authenticated with1620* HDCP 2.2 for Content Type 0/Content Type 1. Where as a link can be1621* authenticated with HDCP1.4 only for Content Type 0(though it is implicit1622* in nature. As there is no reference for Content Type in HDCP1.4).1623*1624* HDCP2.2 authentication protocol itself takes the "Content Type" as a1625* parameter, which is a input for the DP HDCP2.2 encryption algo.1626*1627* In case of Type 0 content protection request, kernel driver can choose1628* either of HDCP spec versions 1.4 and 2.2. When HDCP2.2 is used for1629* "HDCP Type 0", a HDCP 2.2 capable repeater in the downstream can send1630* that content to a HDCP 1.4 authenticated HDCP sink (Type0 link).1631* But if the content is classified as "HDCP Type 1", above mentioned1632* HDCP 2.2 repeater wont send the content to the HDCP sink as it can't1633* authenticate the HDCP1.4 capable sink for "HDCP Type 1".1634*1635* Please note userspace can be ignorant of the HDCP versions used by the1636* kernel driver to achieve the "HDCP Content Type".1637*1638* At current scenario, classifying a content as Type 1 ensures that the1639* content will be displayed only through the HDCP2.2 encrypted link.1640*1641* Note that the HDCP Content Type property is introduced at HDCP 2.2, and1642* defaults to type 0. It is only exposed by drivers supporting HDCP 2.21643* (hence supporting Type 0 and Type 1). Based on how next versions of1644* HDCP specs are defined content Type could be used for higher versions1645* too.1646*1647* If content type is changed when "Content Protection" is not UNDESIRED,1648* then kernel will disable the HDCP and re-enable with new type in the1649* same atomic commit. And when "Content Protection" is ENABLED, it means1650* that link is HDCP authenticated and encrypted, for the transmission of1651* the Type of stream mentioned at "HDCP Content Type".1652*1653* HDR_OUTPUT_METADATA:1654* Connector property to enable userspace to send HDR Metadata to1655* driver. This metadata is based on the composition and blending1656* policies decided by user, taking into account the hardware and1657* sink capabilities. The driver gets this metadata and creates a1658* Dynamic Range and Mastering Infoframe (DRM) in case of HDMI,1659* SDP packet (Non-audio INFOFRAME SDP v1.3) for DP. This is then1660* sent to sink. This notifies the sink of the upcoming frame's Color1661* Encoding and Luminance parameters.1662*1663* Userspace first need to detect the HDR capabilities of sink by1664* reading and parsing the EDID. Details of HDR metadata for HDMI1665* are added in CTA 861.G spec. For DP , its defined in VESA DP1666* Standard v1.4. It needs to then get the metadata information1667* of the video/game/app content which are encoded in HDR (basically1668* using HDR transfer functions). With this information it needs to1669* decide on a blending policy and compose the relevant1670* layers/overlays into a common format. Once this blending is done,1671* userspace will be aware of the metadata of the composed frame to1672* be send to sink. It then uses this property to communicate this1673* metadata to driver which then make a Infoframe packet and sends1674* to sink based on the type of encoder connected.1675*1676* Userspace will be responsible to do Tone mapping operation in case:1677* - Some layers are HDR and others are SDR1678* - HDR layers luminance is not same as sink1679*1680* It will even need to do colorspace conversion and get all layers1681* to one common colorspace for blending. It can use either GL, Media1682* or display engine to get this done based on the capabilities of the1683* associated hardware.1684*1685* Driver expects metadata to be put in &struct hdr_output_metadata1686* structure from userspace. This is received as blob and stored in1687* &drm_connector_state.hdr_output_metadata. It parses EDID and saves the1688* sink metadata in &struct hdr_sink_metadata, as1689* &drm_connector.display_info.hdr_sink_metadata. Driver uses1690* drm_hdmi_infoframe_set_hdr_metadata() helper to set the HDR metadata,1691* hdmi_drm_infoframe_pack() to pack the infoframe as per spec, in case of1692* HDMI encoder.1693*1694* max bpc:1695* This range property is used by userspace to limit the bit depth. When1696* used the driver would limit the bpc in accordance with the valid range1697* supported by the hardware and sink. Drivers to use the function1698* drm_connector_attach_max_bpc_property() to create and attach the1699* property to the connector during initialization.1700*1701* Connectors also have one standardized atomic property:1702*1703* CRTC_ID:1704* Mode object ID of the &drm_crtc this connector should be connected to.1705*1706* Connectors for LCD panels may also have one standardized property:1707*1708* panel orientation:1709* On some devices the LCD panel is mounted in the casing in such a way1710* that the up/top side of the panel does not match with the top side of1711* the device. Userspace can use this property to check for this.1712* Note that input coordinates from touchscreens (input devices with1713* INPUT_PROP_DIRECT) will still map 1:1 to the actual LCD panel1714* coordinates, so if userspace rotates the picture to adjust for1715* the orientation it must also apply the same transformation to the1716* touchscreen input coordinates. This property is initialized by calling1717* drm_connector_set_panel_orientation() or1718* drm_connector_set_panel_orientation_with_quirk()1719*1720* scaling mode:1721* This property defines how a non-native mode is upscaled to the native1722* mode of an LCD panel:1723*1724* None:1725* No upscaling happens, scaling is left to the panel. Not all1726* drivers expose this mode.1727* Full:1728* The output is upscaled to the full resolution of the panel,1729* ignoring the aspect ratio.1730* Center:1731* No upscaling happens, the output is centered within the native1732* resolution the panel.1733* Full aspect:1734* The output is upscaled to maximize either the width or height1735* while retaining the aspect ratio.1736*1737* This property should be set up by calling1738* drm_connector_attach_scaling_mode_property(). Note that drivers1739* can also expose this property to external outputs, in which case they1740* must support "None", which should be the default (since external screens1741* have a built-in scaler).1742*1743* subconnector:1744* This property is used by DVI-I, TVout and DisplayPort to indicate different1745* connector subtypes. Enum values more or less match with those from main1746* connector types.1747* For DVI-I and TVout there is also a matching property "select subconnector"1748* allowing to switch between signal types.1749* DP subconnector corresponds to a downstream port.1750*1751* privacy-screen sw-state, privacy-screen hw-state:1752* These 2 optional properties can be used to query the state of the1753* electronic privacy screen that is available on some displays; and in1754* some cases also control the state. If a driver implements these1755* properties then both properties must be present.1756*1757* "privacy-screen hw-state" is read-only and reflects the actual state1758* of the privacy-screen, possible values: "Enabled", "Disabled,1759* "Enabled-locked", "Disabled-locked". The locked states indicate1760* that the state cannot be changed through the DRM API. E.g. there1761* might be devices where the firmware-setup options, or a hardware1762* slider-switch, offer always on / off modes.1763*1764* "privacy-screen sw-state" can be set to change the privacy-screen state1765* when not locked. In this case the driver must update the hw-state1766* property to reflect the new state on completion of the commit of the1767* sw-state property. Setting the sw-state property when the hw-state is1768* locked must be interpreted by the driver as a request to change the1769* state to the set state when the hw-state becomes unlocked. E.g. if1770* "privacy-screen hw-state" is "Enabled-locked" and the sw-state1771* gets set to "Disabled" followed by the user unlocking the state by1772* changing the slider-switch position, then the driver must set the1773* state to "Disabled" upon receiving the unlock event.1774*1775* In some cases the privacy-screen's actual state might change outside of1776* control of the DRM code. E.g. there might be a firmware handled hotkey1777* which toggles the actual state, or the actual state might be changed1778* through another userspace API such as writing /proc/acpi/ibm/lcdshadow.1779* In this case the driver must update both the hw-state and the sw-state1780* to reflect the new value, overwriting any pending state requests in the1781* sw-state. Any pending sw-state requests are thus discarded.1782*1783* Note that the ability for the state to change outside of control of1784* the DRM master process means that userspace must not cache the value1785* of the sw-state. Caching the sw-state value and including it in later1786* atomic commits may lead to overriding a state change done through e.g.1787* a firmware handled hotkey. Therefor userspace must not include the1788* privacy-screen sw-state in an atomic commit unless it wants to change1789* its value.1790*1791* left margin, right margin, top margin, bottom margin:1792* Add margins to the connector's viewport. This is typically used to1793* mitigate overscan on TVs.1794*1795* The value is the size in pixels of the black border which will be1796* added. The attached CRTC's content will be scaled to fill the whole1797* area inside the margin.1798*1799* The margins configuration might be sent to the sink, e.g. via HDMI AVI1800* InfoFrames.1801*1802* Drivers can set up these properties by calling1803* drm_mode_create_tv_margin_properties().1804*/18051806int drm_connector_create_standard_properties(struct drm_device *dev)1807{1808struct drm_property *prop;18091810prop = drm_property_create(dev, DRM_MODE_PROP_BLOB |1811DRM_MODE_PROP_IMMUTABLE,1812"EDID", 0);1813if (!prop)1814return -ENOMEM;1815dev->mode_config.edid_property = prop;18161817prop = drm_property_create_enum(dev, 0,1818"DPMS", drm_dpms_enum_list,1819ARRAY_SIZE(drm_dpms_enum_list));1820if (!prop)1821return -ENOMEM;1822dev->mode_config.dpms_property = prop;18231824prop = drm_property_create(dev,1825DRM_MODE_PROP_BLOB |1826DRM_MODE_PROP_IMMUTABLE,1827"PATH", 0);1828if (!prop)1829return -ENOMEM;1830dev->mode_config.path_property = prop;18311832prop = drm_property_create(dev,1833DRM_MODE_PROP_BLOB |1834DRM_MODE_PROP_IMMUTABLE,1835"TILE", 0);1836if (!prop)1837return -ENOMEM;1838dev->mode_config.tile_property = prop;18391840prop = drm_property_create_enum(dev, 0, "link-status",1841drm_link_status_enum_list,1842ARRAY_SIZE(drm_link_status_enum_list));1843if (!prop)1844return -ENOMEM;1845dev->mode_config.link_status_property = prop;18461847prop = drm_property_create_bool(dev, DRM_MODE_PROP_IMMUTABLE, "non-desktop");1848if (!prop)1849return -ENOMEM;1850dev->mode_config.non_desktop_property = prop;18511852prop = drm_property_create(dev, DRM_MODE_PROP_BLOB,1853"HDR_OUTPUT_METADATA", 0);1854if (!prop)1855return -ENOMEM;1856dev->mode_config.hdr_output_metadata_property = prop;18571858return 0;1859}18601861/**1862* drm_mode_create_dvi_i_properties - create DVI-I specific connector properties1863* @dev: DRM device1864*1865* Called by a driver the first time a DVI-I connector is made.1866*1867* Returns: %01868*/1869int drm_mode_create_dvi_i_properties(struct drm_device *dev)1870{1871struct drm_property *dvi_i_selector;1872struct drm_property *dvi_i_subconnector;18731874if (dev->mode_config.dvi_i_select_subconnector_property)1875return 0;18761877dvi_i_selector =1878drm_property_create_enum(dev, 0,1879"select subconnector",1880drm_dvi_i_select_enum_list,1881ARRAY_SIZE(drm_dvi_i_select_enum_list));1882dev->mode_config.dvi_i_select_subconnector_property = dvi_i_selector;18831884dvi_i_subconnector = drm_property_create_enum(dev, DRM_MODE_PROP_IMMUTABLE,1885"subconnector",1886drm_dvi_i_subconnector_enum_list,1887ARRAY_SIZE(drm_dvi_i_subconnector_enum_list));1888dev->mode_config.dvi_i_subconnector_property = dvi_i_subconnector;18891890return 0;1891}1892EXPORT_SYMBOL(drm_mode_create_dvi_i_properties);18931894/**1895* drm_connector_attach_dp_subconnector_property - create subconnector property for DP1896* @connector: drm_connector to attach property1897*1898* Called by a driver when DP connector is created.1899*/1900void drm_connector_attach_dp_subconnector_property(struct drm_connector *connector)1901{1902struct drm_mode_config *mode_config = &connector->dev->mode_config;19031904if (!mode_config->dp_subconnector_property)1905mode_config->dp_subconnector_property =1906drm_property_create_enum(connector->dev,1907DRM_MODE_PROP_IMMUTABLE,1908"subconnector",1909drm_dp_subconnector_enum_list,1910ARRAY_SIZE(drm_dp_subconnector_enum_list));19111912drm_object_attach_property(&connector->base,1913mode_config->dp_subconnector_property,1914DRM_MODE_SUBCONNECTOR_Unknown);1915}1916EXPORT_SYMBOL(drm_connector_attach_dp_subconnector_property);19171918/**1919* DOC: HDMI connector properties1920*1921* Broadcast RGB (HDMI specific)1922* Indicates the Quantization Range (Full vs Limited) used. The color1923* processing pipeline will be adjusted to match the value of the1924* property, and the Infoframes will be generated and sent accordingly.1925*1926* This property is only relevant if the HDMI output format is RGB. If1927* it's one of the YCbCr variant, it will be ignored.1928*1929* The CRTC attached to the connector must be configured by user-space to1930* always produce full-range pixels.1931*1932* The value of this property can be one of the following:1933*1934* Automatic:1935* The quantization range is selected automatically based on the1936* mode according to the HDMI specifications (HDMI 1.4b - Section1937* 6.6 - Video Quantization Ranges).1938*1939* Full:1940* Full quantization range is forced.1941*1942* Limited 16:235:1943* Limited quantization range is forced. Unlike the name suggests,1944* this works for any number of bits-per-component.1945*1946* Property values other than Automatic can result in colors being off (if1947* limited is selected but the display expects full), or a black screen1948* (if full is selected but the display expects limited).1949*1950* Drivers can set up this property by calling1951* drm_connector_attach_broadcast_rgb_property().1952*1953* content type (HDMI specific):1954* Indicates content type setting to be used in HDMI infoframes to indicate1955* content type for the external device, so that it adjusts its display1956* settings accordingly.1957*1958* The value of this property can be one of the following:1959*1960* No Data:1961* Content type is unknown1962* Graphics:1963* Content type is graphics1964* Photo:1965* Content type is photo1966* Cinema:1967* Content type is cinema1968* Game:1969* Content type is game1970*1971* The meaning of each content type is defined in CTA-861-G table 15.1972*1973* Drivers can set up this property by calling1974* drm_connector_attach_content_type_property(). Decoding to1975* infoframe values is done through drm_hdmi_avi_infoframe_content_type().1976*/19771978/*1979* TODO: Document the properties:1980* - brightness1981* - contrast1982* - flicker reduction1983* - hue1984* - mode1985* - overscan1986* - saturation1987* - select subconnector1988*/1989/**1990* DOC: Analog TV Connector Properties1991*1992* TV Mode:1993* Indicates the TV Mode used on an analog TV connector. The value1994* of this property can be one of the following:1995*1996* NTSC:1997* TV Mode is CCIR System M (aka 525-lines) together with1998* the NTSC Color Encoding.1999*2000* NTSC-443:2001*2002* TV Mode is CCIR System M (aka 525-lines) together with2003* the NTSC Color Encoding, but with a color subcarrier2004* frequency of 4.43MHz2005*2006* NTSC-J:2007*2008* TV Mode is CCIR System M (aka 525-lines) together with2009* the NTSC Color Encoding, but with a black level equal to2010* the blanking level.2011*2012* PAL:2013*2014* TV Mode is CCIR System B (aka 625-lines) together with2015* the PAL Color Encoding.2016*2017* PAL-M:2018*2019* TV Mode is CCIR System M (aka 525-lines) together with2020* the PAL Color Encoding.2021*2022* PAL-N:2023*2024* TV Mode is CCIR System N together with the PAL Color2025* Encoding, a color subcarrier frequency of 3.58MHz, the2026* SECAM color space, and narrower channels than other PAL2027* variants.2028*2029* SECAM:2030*2031* TV Mode is CCIR System B (aka 625-lines) together with2032* the SECAM Color Encoding.2033*2034* Mono:2035*2036* Use timings appropriate to the DRM mode, including2037* equalizing pulses for a 525-line or 625-line mode,2038* with no pedestal or color encoding.2039*2040* Drivers can set up this property by calling2041* drm_mode_create_tv_properties().2042*/20432044/**2045* drm_connector_attach_content_type_property - attach content-type property2046* @connector: connector to attach content type property on.2047*2048* Called by a driver the first time a HDMI connector is made.2049*2050* Returns: %02051*/2052int drm_connector_attach_content_type_property(struct drm_connector *connector)2053{2054if (!drm_mode_create_content_type_property(connector->dev))2055drm_object_attach_property(&connector->base,2056connector->dev->mode_config.content_type_property,2057DRM_MODE_CONTENT_TYPE_NO_DATA);2058return 0;2059}2060EXPORT_SYMBOL(drm_connector_attach_content_type_property);20612062/**2063* drm_connector_attach_tv_margin_properties - attach TV connector margin2064* properties2065* @connector: DRM connector2066*2067* Called by a driver when it needs to attach TV margin props to a connector.2068* Typically used on SDTV and HDMI connectors.2069*/2070void drm_connector_attach_tv_margin_properties(struct drm_connector *connector)2071{2072struct drm_device *dev = connector->dev;20732074drm_object_attach_property(&connector->base,2075dev->mode_config.tv_left_margin_property,20760);2077drm_object_attach_property(&connector->base,2078dev->mode_config.tv_right_margin_property,20790);2080drm_object_attach_property(&connector->base,2081dev->mode_config.tv_top_margin_property,20820);2083drm_object_attach_property(&connector->base,2084dev->mode_config.tv_bottom_margin_property,20850);2086}2087EXPORT_SYMBOL(drm_connector_attach_tv_margin_properties);20882089/**2090* drm_mode_create_tv_margin_properties - create TV connector margin properties2091* @dev: DRM device2092*2093* Called by a driver's HDMI connector initialization routine, this function2094* creates the TV margin properties for a given device. No need to call this2095* function for an SDTV connector, it's already called from2096* drm_mode_create_tv_properties_legacy().2097*2098* Returns:2099* 0 on success or a negative error code on failure.2100*/2101int drm_mode_create_tv_margin_properties(struct drm_device *dev)2102{2103if (dev->mode_config.tv_left_margin_property)2104return 0;21052106dev->mode_config.tv_left_margin_property =2107drm_property_create_range(dev, 0, "left margin", 0, 100);2108if (!dev->mode_config.tv_left_margin_property)2109return -ENOMEM;21102111dev->mode_config.tv_right_margin_property =2112drm_property_create_range(dev, 0, "right margin", 0, 100);2113if (!dev->mode_config.tv_right_margin_property)2114return -ENOMEM;21152116dev->mode_config.tv_top_margin_property =2117drm_property_create_range(dev, 0, "top margin", 0, 100);2118if (!dev->mode_config.tv_top_margin_property)2119return -ENOMEM;21202121dev->mode_config.tv_bottom_margin_property =2122drm_property_create_range(dev, 0, "bottom margin", 0, 100);2123if (!dev->mode_config.tv_bottom_margin_property)2124return -ENOMEM;21252126return 0;2127}2128EXPORT_SYMBOL(drm_mode_create_tv_margin_properties);21292130/**2131* drm_mode_create_tv_properties_legacy - create TV specific connector properties2132* @dev: DRM device2133* @num_modes: number of different TV formats (modes) supported2134* @modes: array of pointers to strings containing name of each format2135*2136* Called by a driver's TV initialization routine, this function creates2137* the TV specific connector properties for a given device. Caller is2138* responsible for allocating a list of format names and passing them to2139* this routine.2140*2141* NOTE: This functions registers the deprecated "mode" connector2142* property to select the analog TV mode (ie, NTSC, PAL, etc.). New2143* drivers must use drm_mode_create_tv_properties() instead.2144*2145* Returns:2146* 0 on success or a negative error code on failure.2147*/2148int drm_mode_create_tv_properties_legacy(struct drm_device *dev,2149unsigned int num_modes,2150const char * const modes[])2151{2152struct drm_property *tv_selector;2153struct drm_property *tv_subconnector;2154unsigned int i;21552156if (dev->mode_config.tv_select_subconnector_property)2157return 0;21582159/*2160* Basic connector properties2161*/2162tv_selector = drm_property_create_enum(dev, 0,2163"select subconnector",2164drm_tv_select_enum_list,2165ARRAY_SIZE(drm_tv_select_enum_list));2166if (!tv_selector)2167goto nomem;21682169dev->mode_config.tv_select_subconnector_property = tv_selector;21702171tv_subconnector =2172drm_property_create_enum(dev, DRM_MODE_PROP_IMMUTABLE,2173"subconnector",2174drm_tv_subconnector_enum_list,2175ARRAY_SIZE(drm_tv_subconnector_enum_list));2176if (!tv_subconnector)2177goto nomem;2178dev->mode_config.tv_subconnector_property = tv_subconnector;21792180/*2181* Other, TV specific properties: margins & TV modes.2182*/2183if (drm_mode_create_tv_margin_properties(dev))2184goto nomem;21852186if (num_modes) {2187dev->mode_config.legacy_tv_mode_property =2188drm_property_create(dev, DRM_MODE_PROP_ENUM,2189"mode", num_modes);2190if (!dev->mode_config.legacy_tv_mode_property)2191goto nomem;21922193for (i = 0; i < num_modes; i++)2194drm_property_add_enum(dev->mode_config.legacy_tv_mode_property,2195i, modes[i]);2196}21972198dev->mode_config.tv_brightness_property =2199drm_property_create_range(dev, 0, "brightness", 0, 100);2200if (!dev->mode_config.tv_brightness_property)2201goto nomem;22022203dev->mode_config.tv_contrast_property =2204drm_property_create_range(dev, 0, "contrast", 0, 100);2205if (!dev->mode_config.tv_contrast_property)2206goto nomem;22072208dev->mode_config.tv_flicker_reduction_property =2209drm_property_create_range(dev, 0, "flicker reduction", 0, 100);2210if (!dev->mode_config.tv_flicker_reduction_property)2211goto nomem;22122213dev->mode_config.tv_overscan_property =2214drm_property_create_range(dev, 0, "overscan", 0, 100);2215if (!dev->mode_config.tv_overscan_property)2216goto nomem;22172218dev->mode_config.tv_saturation_property =2219drm_property_create_range(dev, 0, "saturation", 0, 100);2220if (!dev->mode_config.tv_saturation_property)2221goto nomem;22222223dev->mode_config.tv_hue_property =2224drm_property_create_range(dev, 0, "hue", 0, 100);2225if (!dev->mode_config.tv_hue_property)2226goto nomem;22272228return 0;2229nomem:2230return -ENOMEM;2231}2232EXPORT_SYMBOL(drm_mode_create_tv_properties_legacy);22332234/**2235* drm_mode_create_tv_properties - create TV specific connector properties2236* @dev: DRM device2237* @supported_tv_modes: Bitmask of TV modes supported (See DRM_MODE_TV_MODE_*)2238*2239* Called by a driver's TV initialization routine, this function creates2240* the TV specific connector properties for a given device.2241*2242* Returns:2243* 0 on success or a negative error code on failure.2244*/2245int drm_mode_create_tv_properties(struct drm_device *dev,2246unsigned int supported_tv_modes)2247{2248struct drm_prop_enum_list tv_mode_list[DRM_MODE_TV_MODE_MAX];2249struct drm_property *tv_mode;2250unsigned int i, len = 0;22512252if (dev->mode_config.tv_mode_property)2253return 0;22542255for (i = 0; i < DRM_MODE_TV_MODE_MAX; i++) {2256if (!(supported_tv_modes & BIT(i)))2257continue;22582259tv_mode_list[len].type = i;2260tv_mode_list[len].name = drm_get_tv_mode_name(i);2261len++;2262}22632264tv_mode = drm_property_create_enum(dev, 0, "TV mode",2265tv_mode_list, len);2266if (!tv_mode)2267return -ENOMEM;22682269dev->mode_config.tv_mode_property = tv_mode;22702271return drm_mode_create_tv_properties_legacy(dev, 0, NULL);2272}2273EXPORT_SYMBOL(drm_mode_create_tv_properties);22742275/**2276* drm_mode_create_scaling_mode_property - create scaling mode property2277* @dev: DRM device2278*2279* Called by a driver the first time it's needed, must be attached to desired2280* connectors.2281*2282* Atomic drivers should use drm_connector_attach_scaling_mode_property()2283* instead to correctly assign &drm_connector_state.scaling_mode2284* in the atomic state.2285*2286* Returns: %02287*/2288int drm_mode_create_scaling_mode_property(struct drm_device *dev)2289{2290struct drm_property *scaling_mode;22912292if (dev->mode_config.scaling_mode_property)2293return 0;22942295scaling_mode =2296drm_property_create_enum(dev, 0, "scaling mode",2297drm_scaling_mode_enum_list,2298ARRAY_SIZE(drm_scaling_mode_enum_list));22992300dev->mode_config.scaling_mode_property = scaling_mode;23012302return 0;2303}2304EXPORT_SYMBOL(drm_mode_create_scaling_mode_property);23052306/**2307* DOC: Variable refresh properties2308*2309* Variable refresh rate capable displays can dynamically adjust their2310* refresh rate by extending the duration of their vertical front porch2311* until page flip or timeout occurs. This can reduce or remove stuttering2312* and latency in scenarios where the page flip does not align with the2313* vblank interval.2314*2315* An example scenario would be an application flipping at a constant rate2316* of 48Hz on a 60Hz display. The page flip will frequently miss the vblank2317* interval and the same contents will be displayed twice. This can be2318* observed as stuttering for content with motion.2319*2320* If variable refresh rate was active on a display that supported a2321* variable refresh range from 35Hz to 60Hz no stuttering would be observable2322* for the example scenario. The minimum supported variable refresh rate of2323* 35Hz is below the page flip frequency and the vertical front porch can2324* be extended until the page flip occurs. The vblank interval will be2325* directly aligned to the page flip rate.2326*2327* Not all userspace content is suitable for use with variable refresh rate.2328* Large and frequent changes in vertical front porch duration may worsen2329* perceived stuttering for input sensitive applications.2330*2331* Panel brightness will also vary with vertical front porch duration. Some2332* panels may have noticeable differences in brightness between the minimum2333* vertical front porch duration and the maximum vertical front porch duration.2334* Large and frequent changes in vertical front porch duration may produce2335* observable flickering for such panels.2336*2337* Userspace control for variable refresh rate is supported via properties2338* on the &drm_connector and &drm_crtc objects.2339*2340* "vrr_capable":2341* Optional &drm_connector boolean property that drivers should attach2342* with drm_connector_attach_vrr_capable_property() on connectors that2343* could support variable refresh rates. Drivers should update the2344* property value by calling drm_connector_set_vrr_capable_property().2345*2346* Absence of the property should indicate absence of support.2347*2348* "VRR_ENABLED":2349* Default &drm_crtc boolean property that notifies the driver that the2350* content on the CRTC is suitable for variable refresh rate presentation.2351* The driver will take this property as a hint to enable variable2352* refresh rate support if the receiver supports it, ie. if the2353* "vrr_capable" property is true on the &drm_connector object. The2354* vertical front porch duration will be extended until page-flip or2355* timeout when enabled.2356*2357* The minimum vertical front porch duration is defined as the vertical2358* front porch duration for the current mode.2359*2360* The maximum vertical front porch duration is greater than or equal to2361* the minimum vertical front porch duration. The duration is derived2362* from the minimum supported variable refresh rate for the connector.2363*2364* The driver may place further restrictions within these minimum2365* and maximum bounds.2366*/23672368/**2369* drm_connector_attach_vrr_capable_property - creates the2370* vrr_capable property2371* @connector: connector to create the vrr_capable property on.2372*2373* This is used by atomic drivers to add support for querying2374* variable refresh rate capability for a connector.2375*2376* Returns:2377* Zero on success, negative errno on failure.2378*/2379int drm_connector_attach_vrr_capable_property(2380struct drm_connector *connector)2381{2382struct drm_device *dev = connector->dev;2383struct drm_property *prop;23842385if (!connector->vrr_capable_property) {2386prop = drm_property_create_bool(dev, DRM_MODE_PROP_IMMUTABLE,2387"vrr_capable");2388if (!prop)2389return -ENOMEM;23902391connector->vrr_capable_property = prop;2392drm_object_attach_property(&connector->base, prop, 0);2393}23942395return 0;2396}2397EXPORT_SYMBOL(drm_connector_attach_vrr_capable_property);23982399/**2400* drm_connector_attach_scaling_mode_property - attach atomic scaling mode property2401* @connector: connector to attach scaling mode property on.2402* @scaling_mode_mask: or'ed mask of BIT(%DRM_MODE_SCALE_\*).2403*2404* This is used to add support for scaling mode to atomic drivers.2405* The scaling mode will be set to &drm_connector_state.scaling_mode2406* and can be used from &drm_connector_helper_funcs->atomic_check for validation.2407*2408* This is the atomic version of drm_mode_create_scaling_mode_property().2409*2410* Returns:2411* Zero on success, negative errno on failure.2412*/2413int drm_connector_attach_scaling_mode_property(struct drm_connector *connector,2414u32 scaling_mode_mask)2415{2416struct drm_device *dev = connector->dev;2417struct drm_property *scaling_mode_property;2418int i;2419const unsigned valid_scaling_mode_mask =2420(1U << ARRAY_SIZE(drm_scaling_mode_enum_list)) - 1;24212422if (WARN_ON(hweight32(scaling_mode_mask) < 2 ||2423scaling_mode_mask & ~valid_scaling_mode_mask))2424return -EINVAL;24252426scaling_mode_property =2427drm_property_create(dev, DRM_MODE_PROP_ENUM, "scaling mode",2428hweight32(scaling_mode_mask));24292430if (!scaling_mode_property)2431return -ENOMEM;24322433for (i = 0; i < ARRAY_SIZE(drm_scaling_mode_enum_list); i++) {2434int ret;24352436if (!(BIT(i) & scaling_mode_mask))2437continue;24382439ret = drm_property_add_enum(scaling_mode_property,2440drm_scaling_mode_enum_list[i].type,2441drm_scaling_mode_enum_list[i].name);24422443if (ret) {2444drm_property_destroy(dev, scaling_mode_property);24452446return ret;2447}2448}24492450drm_object_attach_property(&connector->base,2451scaling_mode_property, 0);24522453connector->scaling_mode_property = scaling_mode_property;24542455return 0;2456}2457EXPORT_SYMBOL(drm_connector_attach_scaling_mode_property);24582459/**2460* drm_mode_create_aspect_ratio_property - create aspect ratio property2461* @dev: DRM device2462*2463* Called by a driver the first time it's needed, must be attached to desired2464* connectors.2465*2466* Returns:2467* Zero on success, negative errno on failure.2468*/2469int drm_mode_create_aspect_ratio_property(struct drm_device *dev)2470{2471if (dev->mode_config.aspect_ratio_property)2472return 0;24732474dev->mode_config.aspect_ratio_property =2475drm_property_create_enum(dev, 0, "aspect ratio",2476drm_aspect_ratio_enum_list,2477ARRAY_SIZE(drm_aspect_ratio_enum_list));24782479if (dev->mode_config.aspect_ratio_property == NULL)2480return -ENOMEM;24812482return 0;2483}2484EXPORT_SYMBOL(drm_mode_create_aspect_ratio_property);24852486/**2487* DOC: standard connector properties2488*2489* Colorspace:2490* This property is used to inform the driver about the color encoding2491* user space configured the pixel operation properties to produce.2492* The variants set the colorimetry, transfer characteristics, and which2493* YCbCr conversion should be used when necessary.2494* The transfer characteristics from HDR_OUTPUT_METADATA takes precedence2495* over this property.2496* User space always configures the pixel operation properties to produce2497* full quantization range data (see the Broadcast RGB property).2498*2499* Drivers inform the sink about what colorimetry, transfer2500* characteristics, YCbCr conversion, and quantization range to expect2501* (this can depend on the output mode, output format and other2502* properties). Drivers also convert the user space provided data to what2503* the sink expects.2504*2505* User space has to check if the sink supports all of the possible2506* colorimetries that the driver is allowed to pick by parsing the EDID.2507*2508* For historical reasons this property exposes a number of variants which2509* result in undefined behavior.2510*2511* Default:2512* The behavior is driver-specific.2513*2514* BT2020_RGB:2515*2516* BT2020_YCC:2517* User space configures the pixel operation properties to produce2518* RGB content with Rec. ITU-R BT.2020 colorimetry, Rec.2519* ITU-R BT.2020 (Table 4, RGB) transfer characteristics and full2520* quantization range.2521* User space can use the HDR_OUTPUT_METADATA property to set the2522* transfer characteristics to PQ (Rec. ITU-R BT.2100 Table 4) or2523* HLG (Rec. ITU-R BT.2100 Table 5) in which case, user space2524* configures pixel operation properties to produce content with2525* the respective transfer characteristics.2526* User space has to make sure the sink supports Rec.2527* ITU-R BT.2020 R'G'B' and Rec. ITU-R BT.2020 Y'C'BC'R2528* colorimetry.2529* Drivers can configure the sink to use an RGB format, tell the2530* sink to expect Rec. ITU-R BT.2020 R'G'B' colorimetry and convert2531* to the appropriate quantization range.2532* Drivers can configure the sink to use a YCbCr format, tell the2533* sink to expect Rec. ITU-R BT.2020 Y'C'BC'R colorimetry, convert2534* to YCbCr using the Rec. ITU-R BT.2020 non-constant luminance2535* conversion matrix and convert to the appropriate quantization2536* range.2537* The variants BT2020_RGB and BT2020_YCC are equivalent and the2538* driver chooses between RGB and YCbCr on its own.2539*2540* SMPTE_170M_YCC:2541* BT709_YCC:2542* XVYCC_601:2543* XVYCC_709:2544* SYCC_601:2545* opYCC_601:2546* opRGB:2547* BT2020_CYCC:2548* DCI-P3_RGB_D65:2549* DCI-P3_RGB_Theater:2550* RGB_WIDE_FIXED:2551* RGB_WIDE_FLOAT:2552*2553* BT601_YCC:2554* The behavior is undefined.2555*2556* Because between HDMI and DP have different colorspaces,2557* drm_mode_create_hdmi_colorspace_property() is used for HDMI connector and2558* drm_mode_create_dp_colorspace_property() is used for DP connector.2559*/25602561static int drm_mode_create_colorspace_property(struct drm_connector *connector,2562u32 supported_colorspaces)2563{2564struct drm_device *dev = connector->dev;2565u32 colorspaces = supported_colorspaces | BIT(DRM_MODE_COLORIMETRY_DEFAULT);2566struct drm_prop_enum_list enum_list[DRM_MODE_COLORIMETRY_COUNT];2567int i, len;25682569if (connector->colorspace_property)2570return 0;25712572if (!supported_colorspaces) {2573drm_err(dev, "No supported colorspaces provded on [CONNECTOR:%d:%s]\n",2574connector->base.id, connector->name);2575return -EINVAL;2576}25772578if ((supported_colorspaces & -BIT(DRM_MODE_COLORIMETRY_COUNT)) != 0) {2579drm_err(dev, "Unknown colorspace provded on [CONNECTOR:%d:%s]\n",2580connector->base.id, connector->name);2581return -EINVAL;2582}25832584len = 0;2585for (i = 0; i < DRM_MODE_COLORIMETRY_COUNT; i++) {2586if ((colorspaces & BIT(i)) == 0)2587continue;25882589enum_list[len].type = i;2590enum_list[len].name = colorspace_names[i];2591len++;2592}25932594connector->colorspace_property =2595drm_property_create_enum(dev, DRM_MODE_PROP_ENUM, "Colorspace",2596enum_list,2597len);25982599if (!connector->colorspace_property)2600return -ENOMEM;26012602return 0;2603}26042605/**2606* drm_mode_create_hdmi_colorspace_property - create hdmi colorspace property2607* @connector: connector to create the Colorspace property on.2608* @supported_colorspaces: bitmap of supported color spaces2609*2610* Called by a driver the first time it's needed, must be attached to desired2611* HDMI connectors.2612*2613* Returns:2614* Zero on success, negative errno on failure.2615*/2616int drm_mode_create_hdmi_colorspace_property(struct drm_connector *connector,2617u32 supported_colorspaces)2618{2619u32 colorspaces;26202621if (supported_colorspaces)2622colorspaces = supported_colorspaces & hdmi_colorspaces;2623else2624colorspaces = hdmi_colorspaces;26252626return drm_mode_create_colorspace_property(connector, colorspaces);2627}2628EXPORT_SYMBOL(drm_mode_create_hdmi_colorspace_property);26292630/**2631* drm_mode_create_dp_colorspace_property - create dp colorspace property2632* @connector: connector to create the Colorspace property on.2633* @supported_colorspaces: bitmap of supported color spaces2634*2635* Called by a driver the first time it's needed, must be attached to desired2636* DP connectors.2637*2638* Returns:2639* Zero on success, negative errno on failure.2640*/2641int drm_mode_create_dp_colorspace_property(struct drm_connector *connector,2642u32 supported_colorspaces)2643{2644u32 colorspaces;26452646if (supported_colorspaces)2647colorspaces = supported_colorspaces & dp_colorspaces;2648else2649colorspaces = dp_colorspaces;26502651return drm_mode_create_colorspace_property(connector, colorspaces);2652}2653EXPORT_SYMBOL(drm_mode_create_dp_colorspace_property);26542655/**2656* drm_mode_create_content_type_property - create content type property2657* @dev: DRM device2658*2659* Called by a driver the first time it's needed, must be attached to desired2660* connectors.2661*2662* Returns:2663* Zero on success, negative errno on failure.2664*/2665int drm_mode_create_content_type_property(struct drm_device *dev)2666{2667if (dev->mode_config.content_type_property)2668return 0;26692670dev->mode_config.content_type_property =2671drm_property_create_enum(dev, 0, "content type",2672drm_content_type_enum_list,2673ARRAY_SIZE(drm_content_type_enum_list));26742675if (dev->mode_config.content_type_property == NULL)2676return -ENOMEM;26772678return 0;2679}2680EXPORT_SYMBOL(drm_mode_create_content_type_property);26812682/**2683* drm_mode_create_suggested_offset_properties - create suggests offset properties2684* @dev: DRM device2685*2686* Create the suggested x/y offset property for connectors.2687*2688* Returns:2689* 0 on success or a negative error code on failure.2690*/2691int drm_mode_create_suggested_offset_properties(struct drm_device *dev)2692{2693if (dev->mode_config.suggested_x_property && dev->mode_config.suggested_y_property)2694return 0;26952696dev->mode_config.suggested_x_property =2697drm_property_create_range(dev, DRM_MODE_PROP_IMMUTABLE, "suggested X", 0, 0xffffffff);26982699dev->mode_config.suggested_y_property =2700drm_property_create_range(dev, DRM_MODE_PROP_IMMUTABLE, "suggested Y", 0, 0xffffffff);27012702if (dev->mode_config.suggested_x_property == NULL ||2703dev->mode_config.suggested_y_property == NULL)2704return -ENOMEM;2705return 0;2706}2707EXPORT_SYMBOL(drm_mode_create_suggested_offset_properties);27082709/**2710* drm_connector_set_path_property - set tile property on connector2711* @connector: connector to set property on.2712* @path: path to use for property; must not be NULL.2713*2714* This creates a property to expose to userspace to specify a2715* connector path. This is mainly used for DisplayPort MST where2716* connectors have a topology and we want to allow userspace to give2717* them more meaningful names.2718*2719* Returns:2720* Zero on success, negative errno on failure.2721*/2722int drm_connector_set_path_property(struct drm_connector *connector,2723const char *path)2724{2725struct drm_device *dev = connector->dev;2726int ret;27272728ret = drm_property_replace_global_blob(dev,2729&connector->path_blob_ptr,2730strlen(path) + 1,2731path,2732&connector->base,2733dev->mode_config.path_property);2734return ret;2735}2736EXPORT_SYMBOL(drm_connector_set_path_property);27372738/**2739* drm_connector_set_tile_property - set tile property on connector2740* @connector: connector to set property on.2741*2742* This looks up the tile information for a connector, and creates a2743* property for userspace to parse if it exists. The property is of2744* the form of 8 integers using ':' as a separator.2745* This is used for dual port tiled displays with DisplayPort SST2746* or DisplayPort MST connectors.2747*2748* Returns:2749* Zero on success, errno on failure.2750*/2751int drm_connector_set_tile_property(struct drm_connector *connector)2752{2753struct drm_device *dev = connector->dev;2754char tile[256];2755int ret;27562757if (!connector->has_tile) {2758ret = drm_property_replace_global_blob(dev,2759&connector->tile_blob_ptr,27600,2761NULL,2762&connector->base,2763dev->mode_config.tile_property);2764return ret;2765}27662767snprintf(tile, 256, "%d:%d:%d:%d:%d:%d:%d:%d",2768connector->tile_group->id, connector->tile_is_single_monitor,2769connector->num_h_tile, connector->num_v_tile,2770connector->tile_h_loc, connector->tile_v_loc,2771connector->tile_h_size, connector->tile_v_size);27722773ret = drm_property_replace_global_blob(dev,2774&connector->tile_blob_ptr,2775strlen(tile) + 1,2776tile,2777&connector->base,2778dev->mode_config.tile_property);2779return ret;2780}2781EXPORT_SYMBOL(drm_connector_set_tile_property);27822783/**2784* drm_connector_set_link_status_property - Set link status property of a connector2785* @connector: drm connector2786* @link_status: new value of link status property (0: Good, 1: Bad)2787*2788* In usual working scenario, this link status property will always be set to2789* "GOOD". If something fails during or after a mode set, the kernel driver2790* may set this link status property to "BAD". The caller then needs to send a2791* hotplug uevent for userspace to re-check the valid modes through2792* GET_CONNECTOR_IOCTL and retry modeset.2793*2794* Note: Drivers cannot rely on userspace to support this property and2795* issue a modeset. As such, they may choose to handle issues (like2796* re-training a link) without userspace's intervention.2797*2798* The reason for adding this property is to handle link training failures, but2799* it is not limited to DP or link training. For example, if we implement2800* asynchronous setcrtc, this property can be used to report any failures in that.2801*/2802void drm_connector_set_link_status_property(struct drm_connector *connector,2803uint64_t link_status)2804{2805struct drm_device *dev = connector->dev;28062807drm_modeset_lock(&dev->mode_config.connection_mutex, NULL);2808connector->state->link_status = link_status;2809drm_modeset_unlock(&dev->mode_config.connection_mutex);2810}2811EXPORT_SYMBOL(drm_connector_set_link_status_property);28122813/**2814* drm_connector_attach_max_bpc_property - attach "max bpc" property2815* @connector: connector to attach max bpc property on.2816* @min: The minimum bit depth supported by the connector.2817* @max: The maximum bit depth supported by the connector.2818*2819* This is used to add support for limiting the bit depth on a connector.2820*2821* Returns:2822* Zero on success, negative errno on failure.2823*/2824int drm_connector_attach_max_bpc_property(struct drm_connector *connector,2825int min, int max)2826{2827struct drm_device *dev = connector->dev;2828struct drm_property *prop;28292830prop = connector->max_bpc_property;2831if (!prop) {2832prop = drm_property_create_range(dev, 0, "max bpc", min, max);2833if (!prop)2834return -ENOMEM;28352836connector->max_bpc_property = prop;2837}28382839drm_object_attach_property(&connector->base, prop, max);2840connector->state->max_requested_bpc = max;2841connector->state->max_bpc = max;28422843return 0;2844}2845EXPORT_SYMBOL(drm_connector_attach_max_bpc_property);28462847/**2848* drm_connector_attach_hdr_output_metadata_property - attach "HDR_OUTPUT_METADA" property2849* @connector: connector to attach the property on.2850*2851* This is used to allow the userspace to send HDR Metadata to the2852* driver.2853*2854* Returns:2855* Zero on success, negative errno on failure.2856*/2857int drm_connector_attach_hdr_output_metadata_property(struct drm_connector *connector)2858{2859struct drm_device *dev = connector->dev;2860struct drm_property *prop = dev->mode_config.hdr_output_metadata_property;28612862drm_object_attach_property(&connector->base, prop, 0);28632864return 0;2865}2866EXPORT_SYMBOL(drm_connector_attach_hdr_output_metadata_property);28672868/**2869* drm_connector_attach_broadcast_rgb_property - attach "Broadcast RGB" property2870* @connector: connector to attach the property on.2871*2872* This is used to add support for forcing the RGB range on a connector2873*2874* Returns:2875* Zero on success, negative errno on failure.2876*/2877int drm_connector_attach_broadcast_rgb_property(struct drm_connector *connector)2878{2879struct drm_device *dev = connector->dev;2880struct drm_property *prop;28812882prop = connector->broadcast_rgb_property;2883if (!prop) {2884prop = drm_property_create_enum(dev, DRM_MODE_PROP_ENUM,2885"Broadcast RGB",2886broadcast_rgb_names,2887ARRAY_SIZE(broadcast_rgb_names));2888if (!prop)2889return -EINVAL;28902891connector->broadcast_rgb_property = prop;2892}28932894drm_object_attach_property(&connector->base, prop,2895DRM_HDMI_BROADCAST_RGB_AUTO);28962897return 0;2898}2899EXPORT_SYMBOL(drm_connector_attach_broadcast_rgb_property);29002901/**2902* drm_connector_attach_colorspace_property - attach "Colorspace" property2903* @connector: connector to attach the property on.2904*2905* This is used to allow the userspace to signal the output colorspace2906* to the driver.2907*2908* Returns:2909* Zero on success, negative errno on failure.2910*/2911int drm_connector_attach_colorspace_property(struct drm_connector *connector)2912{2913struct drm_property *prop = connector->colorspace_property;29142915drm_object_attach_property(&connector->base, prop, DRM_MODE_COLORIMETRY_DEFAULT);29162917return 0;2918}2919EXPORT_SYMBOL(drm_connector_attach_colorspace_property);29202921/**2922* drm_connector_atomic_hdr_metadata_equal - checks if the hdr metadata changed2923* @old_state: old connector state to compare2924* @new_state: new connector state to compare2925*2926* This is used by HDR-enabled drivers to test whether the HDR metadata2927* have changed between two different connector state (and thus probably2928* requires a full blown mode change).2929*2930* Returns:2931* True if the metadata are equal, False otherwise2932*/2933bool drm_connector_atomic_hdr_metadata_equal(struct drm_connector_state *old_state,2934struct drm_connector_state *new_state)2935{2936struct drm_property_blob *old_blob = old_state->hdr_output_metadata;2937struct drm_property_blob *new_blob = new_state->hdr_output_metadata;29382939if (!old_blob || !new_blob)2940return old_blob == new_blob;29412942if (old_blob->length != new_blob->length)2943return false;29442945return !memcmp(old_blob->data, new_blob->data, old_blob->length);2946}2947EXPORT_SYMBOL(drm_connector_atomic_hdr_metadata_equal);29482949/**2950* drm_connector_set_vrr_capable_property - sets the variable refresh rate2951* capable property for a connector2952* @connector: drm connector2953* @capable: True if the connector is variable refresh rate capable2954*2955* Should be used by atomic drivers to update the indicated support for2956* variable refresh rate over a connector.2957*/2958void drm_connector_set_vrr_capable_property(2959struct drm_connector *connector, bool capable)2960{2961if (!connector->vrr_capable_property)2962return;29632964drm_object_property_set_value(&connector->base,2965connector->vrr_capable_property,2966capable);2967}2968EXPORT_SYMBOL(drm_connector_set_vrr_capable_property);29692970/**2971* drm_connector_set_panel_orientation - sets the connector's panel_orientation2972* @connector: connector for which to set the panel-orientation property.2973* @panel_orientation: drm_panel_orientation value to set2974*2975* This function sets the connector's panel_orientation and attaches2976* a "panel orientation" property to the connector.2977*2978* Calling this function on a connector where the panel_orientation has2979* already been set is a no-op (e.g. the orientation has been overridden with2980* a kernel commandline option).2981*2982* It is allowed to call this function with a panel_orientation of2983* DRM_MODE_PANEL_ORIENTATION_UNKNOWN, in which case it is a no-op.2984*2985* The function shouldn't be called in panel after drm is registered (i.e.2986* drm_dev_register() is called in drm).2987*2988* Returns:2989* Zero on success, negative errno on failure.2990*/2991int drm_connector_set_panel_orientation(2992struct drm_connector *connector,2993enum drm_panel_orientation panel_orientation)2994{2995struct drm_device *dev = connector->dev;2996struct drm_display_info *info = &connector->display_info;2997struct drm_property *prop;29982999/* Already set? */3000if (info->panel_orientation != DRM_MODE_PANEL_ORIENTATION_UNKNOWN)3001return 0;30023003/* Don't attach the property if the orientation is unknown */3004if (panel_orientation == DRM_MODE_PANEL_ORIENTATION_UNKNOWN)3005return 0;30063007info->panel_orientation = panel_orientation;30083009prop = dev->mode_config.panel_orientation_property;3010if (!prop) {3011prop = drm_property_create_enum(dev, DRM_MODE_PROP_IMMUTABLE,3012"panel orientation",3013drm_panel_orientation_enum_list,3014ARRAY_SIZE(drm_panel_orientation_enum_list));3015if (!prop)3016return -ENOMEM;30173018dev->mode_config.panel_orientation_property = prop;3019}30203021drm_object_attach_property(&connector->base, prop,3022info->panel_orientation);3023return 0;3024}3025EXPORT_SYMBOL(drm_connector_set_panel_orientation);30263027/**3028* drm_connector_set_panel_orientation_with_quirk - set the3029* connector's panel_orientation after checking for quirks3030* @connector: connector for which to init the panel-orientation property.3031* @panel_orientation: drm_panel_orientation value to set3032* @width: width in pixels of the panel, used for panel quirk detection3033* @height: height in pixels of the panel, used for panel quirk detection3034*3035* Like drm_connector_set_panel_orientation(), but with a check for platform3036* specific (e.g. DMI based) quirks overriding the passed in panel_orientation.3037*3038* Returns:3039* Zero on success, negative errno on failure.3040*/3041int drm_connector_set_panel_orientation_with_quirk(3042struct drm_connector *connector,3043enum drm_panel_orientation panel_orientation,3044int width, int height)3045{3046int orientation_quirk;30473048orientation_quirk = drm_get_panel_orientation_quirk(width, height);3049if (orientation_quirk != DRM_MODE_PANEL_ORIENTATION_UNKNOWN)3050panel_orientation = orientation_quirk;30513052return drm_connector_set_panel_orientation(connector,3053panel_orientation);3054}3055EXPORT_SYMBOL(drm_connector_set_panel_orientation_with_quirk);30563057/**3058* drm_connector_set_orientation_from_panel -3059* set the connector's panel_orientation from panel's callback.3060* @connector: connector for which to init the panel-orientation property.3061* @panel: panel that can provide orientation information.3062*3063* Drm drivers should call this function before drm_dev_register().3064* Orientation is obtained from panel's .get_orientation() callback.3065*3066* Returns:3067* Zero on success, negative errno on failure.3068*/3069int drm_connector_set_orientation_from_panel(3070struct drm_connector *connector,3071struct drm_panel *panel)3072{3073enum drm_panel_orientation orientation;30743075if (panel && panel->funcs && panel->funcs->get_orientation)3076orientation = panel->funcs->get_orientation(panel);3077else3078orientation = DRM_MODE_PANEL_ORIENTATION_UNKNOWN;30793080return drm_connector_set_panel_orientation(connector, orientation);3081}3082EXPORT_SYMBOL(drm_connector_set_orientation_from_panel);30833084static const struct drm_prop_enum_list privacy_screen_enum[] = {3085{ PRIVACY_SCREEN_DISABLED, "Disabled" },3086{ PRIVACY_SCREEN_ENABLED, "Enabled" },3087{ PRIVACY_SCREEN_DISABLED_LOCKED, "Disabled-locked" },3088{ PRIVACY_SCREEN_ENABLED_LOCKED, "Enabled-locked" },3089};30903091/**3092* drm_connector_create_privacy_screen_properties - create the drm connecter's3093* privacy-screen properties.3094* @connector: connector for which to create the privacy-screen properties3095*3096* This function creates the "privacy-screen sw-state" and "privacy-screen3097* hw-state" properties for the connector. They are not attached.3098*/3099void3100drm_connector_create_privacy_screen_properties(struct drm_connector *connector)3101{3102if (connector->privacy_screen_sw_state_property)3103return;31043105/* Note sw-state only supports the first 2 values of the enum */3106connector->privacy_screen_sw_state_property =3107drm_property_create_enum(connector->dev, DRM_MODE_PROP_ENUM,3108"privacy-screen sw-state",3109privacy_screen_enum, 2);31103111connector->privacy_screen_hw_state_property =3112drm_property_create_enum(connector->dev,3113DRM_MODE_PROP_IMMUTABLE | DRM_MODE_PROP_ENUM,3114"privacy-screen hw-state",3115privacy_screen_enum,3116ARRAY_SIZE(privacy_screen_enum));3117}3118EXPORT_SYMBOL(drm_connector_create_privacy_screen_properties);31193120/**3121* drm_connector_attach_privacy_screen_properties - attach the drm connecter's3122* privacy-screen properties.3123* @connector: connector on which to attach the privacy-screen properties3124*3125* This function attaches the "privacy-screen sw-state" and "privacy-screen3126* hw-state" properties to the connector. The initial state of both is set3127* to "Disabled".3128*/3129void3130drm_connector_attach_privacy_screen_properties(struct drm_connector *connector)3131{3132if (!connector->privacy_screen_sw_state_property)3133return;31343135drm_object_attach_property(&connector->base,3136connector->privacy_screen_sw_state_property,3137PRIVACY_SCREEN_DISABLED);31383139drm_object_attach_property(&connector->base,3140connector->privacy_screen_hw_state_property,3141PRIVACY_SCREEN_DISABLED);3142}3143EXPORT_SYMBOL(drm_connector_attach_privacy_screen_properties);31443145static void drm_connector_update_privacy_screen_properties(3146struct drm_connector *connector, bool set_sw_state)3147{3148enum drm_privacy_screen_status sw_state, hw_state;31493150drm_privacy_screen_get_state(connector->privacy_screen,3151&sw_state, &hw_state);31523153if (set_sw_state)3154connector->state->privacy_screen_sw_state = sw_state;3155drm_object_property_set_value(&connector->base,3156connector->privacy_screen_hw_state_property, hw_state);3157}31583159static int drm_connector_privacy_screen_notifier(3160struct notifier_block *nb, unsigned long action, void *data)3161{3162struct drm_connector *connector =3163container_of(nb, struct drm_connector, privacy_screen_notifier);3164struct drm_device *dev = connector->dev;31653166drm_modeset_lock(&dev->mode_config.connection_mutex, NULL);3167drm_connector_update_privacy_screen_properties(connector, true);3168drm_modeset_unlock(&dev->mode_config.connection_mutex);31693170drm_sysfs_connector_property_event(connector,3171connector->privacy_screen_sw_state_property);3172drm_sysfs_connector_property_event(connector,3173connector->privacy_screen_hw_state_property);31743175return NOTIFY_DONE;3176}31773178/**3179* drm_connector_attach_privacy_screen_provider - attach a privacy-screen to3180* the connector3181* @connector: connector to attach the privacy-screen to3182* @priv: drm_privacy_screen to attach3183*3184* Create and attach the standard privacy-screen properties and register3185* a generic notifier for generating sysfs-connector-status-events3186* on external changes to the privacy-screen status.3187* This function takes ownership of the passed in drm_privacy_screen and will3188* call drm_privacy_screen_put() on it when the connector is destroyed.3189*/3190void drm_connector_attach_privacy_screen_provider(3191struct drm_connector *connector, struct drm_privacy_screen *priv)3192{3193connector->privacy_screen = priv;3194connector->privacy_screen_notifier.notifier_call =3195drm_connector_privacy_screen_notifier;31963197drm_connector_create_privacy_screen_properties(connector);3198drm_connector_update_privacy_screen_properties(connector, true);3199drm_connector_attach_privacy_screen_properties(connector);3200}3201EXPORT_SYMBOL(drm_connector_attach_privacy_screen_provider);32023203/**3204* drm_connector_update_privacy_screen - update connector's privacy-screen sw-state3205* @connector_state: connector-state to update the privacy-screen for3206*3207* This function calls drm_privacy_screen_set_sw_state() on the connector's3208* privacy-screen.3209*3210* If the connector has no privacy-screen, then this is a no-op.3211*/3212void drm_connector_update_privacy_screen(const struct drm_connector_state *connector_state)3213{3214struct drm_connector *connector = connector_state->connector;3215int ret;32163217if (!connector->privacy_screen)3218return;32193220ret = drm_privacy_screen_set_sw_state(connector->privacy_screen,3221connector_state->privacy_screen_sw_state);3222if (ret) {3223drm_err(connector->dev, "Error updating privacy-screen sw_state\n");3224return;3225}32263227/* The hw_state property value may have changed, update it. */3228drm_connector_update_privacy_screen_properties(connector, false);3229}3230EXPORT_SYMBOL(drm_connector_update_privacy_screen);32313232int drm_connector_set_obj_prop(struct drm_mode_object *obj,3233struct drm_property *property,3234uint64_t value)3235{3236int ret = -EINVAL;3237struct drm_connector *connector = obj_to_connector(obj);32383239/* Do DPMS ourselves */3240if (property == connector->dev->mode_config.dpms_property) {3241ret = (*connector->funcs->dpms)(connector, (int)value);3242} else if (connector->funcs->set_property)3243ret = connector->funcs->set_property(connector, property, value);32443245if (!ret)3246drm_object_property_set_value(&connector->base, property, value);3247return ret;3248}32493250int drm_connector_property_set_ioctl(struct drm_device *dev,3251void *data, struct drm_file *file_priv)3252{3253struct drm_mode_connector_set_property *conn_set_prop = data;3254struct drm_mode_obj_set_property obj_set_prop = {3255.value = conn_set_prop->value,3256.prop_id = conn_set_prop->prop_id,3257.obj_id = conn_set_prop->connector_id,3258.obj_type = DRM_MODE_OBJECT_CONNECTOR3259};32603261/* It does all the locking and checking we need */3262return drm_mode_obj_set_property_ioctl(dev, &obj_set_prop, file_priv);3263}32643265static struct drm_encoder *drm_connector_get_encoder(struct drm_connector *connector)3266{3267/* For atomic drivers only state objects are synchronously updated and3268* protected by modeset locks, so check those first.3269*/3270if (connector->state)3271return connector->state->best_encoder;3272return connector->encoder;3273}32743275static bool3276drm_mode_expose_to_userspace(const struct drm_display_mode *mode,3277const struct list_head *modes,3278const struct drm_file *file_priv)3279{3280/*3281* If user-space hasn't configured the driver to expose the stereo 3D3282* modes, don't expose them.3283*/3284if (!file_priv->stereo_allowed && drm_mode_is_stereo(mode))3285return false;3286/*3287* If user-space hasn't configured the driver to expose the modes3288* with aspect-ratio, don't expose them. However if such a mode3289* is unique, let it be exposed, but reset the aspect-ratio flags3290* while preparing the list of user-modes.3291*/3292if (!file_priv->aspect_ratio_allowed) {3293const struct drm_display_mode *mode_itr;32943295list_for_each_entry(mode_itr, modes, head) {3296if (mode_itr->expose_to_userspace &&3297drm_mode_match(mode_itr, mode,3298DRM_MODE_MATCH_TIMINGS |3299DRM_MODE_MATCH_CLOCK |3300DRM_MODE_MATCH_FLAGS |3301DRM_MODE_MATCH_3D_FLAGS))3302return false;3303}3304}33053306return true;3307}33083309int drm_mode_getconnector(struct drm_device *dev, void *data,3310struct drm_file *file_priv)3311{3312struct drm_mode_get_connector *out_resp = data;3313struct drm_connector *connector;3314struct drm_encoder *encoder;3315struct drm_display_mode *mode;3316int mode_count = 0;3317int encoders_count = 0;3318int ret = 0;3319int copied = 0;3320struct drm_mode_modeinfo u_mode;3321struct drm_mode_modeinfo __user *mode_ptr;3322uint32_t __user *encoder_ptr;3323bool is_current_master;33243325if (!drm_core_check_feature(dev, DRIVER_MODESET))3326return -EOPNOTSUPP;33273328memset(&u_mode, 0, sizeof(struct drm_mode_modeinfo));33293330connector = drm_connector_lookup(dev, file_priv, out_resp->connector_id);3331if (!connector)3332return -ENOENT;33333334encoders_count = hweight32(connector->possible_encoders);33353336if ((out_resp->count_encoders >= encoders_count) && encoders_count) {3337copied = 0;3338encoder_ptr = (uint32_t __user *)(unsigned long)(out_resp->encoders_ptr);33393340drm_connector_for_each_possible_encoder(connector, encoder) {3341if (put_user(encoder->base.id, encoder_ptr + copied)) {3342ret = -EFAULT;3343goto out;3344}3345copied++;3346}3347}3348out_resp->count_encoders = encoders_count;33493350out_resp->connector_id = connector->base.id;3351out_resp->connector_type = connector->connector_type;3352out_resp->connector_type_id = connector->connector_type_id;33533354is_current_master = drm_is_current_master(file_priv);33553356mutex_lock(&dev->mode_config.mutex);3357if (out_resp->count_modes == 0) {3358if (is_current_master)3359connector->funcs->fill_modes(connector,3360dev->mode_config.max_width,3361dev->mode_config.max_height);3362else3363drm_dbg_kms(dev, "User-space requested a forced probe on [CONNECTOR:%d:%s] but is not the DRM master, demoting to read-only probe\n",3364connector->base.id, connector->name);3365}33663367out_resp->mm_width = connector->display_info.width_mm;3368out_resp->mm_height = connector->display_info.height_mm;3369out_resp->subpixel = connector->display_info.subpixel_order;3370out_resp->connection = connector->status;33713372/* delayed so we get modes regardless of pre-fill_modes state */3373list_for_each_entry(mode, &connector->modes, head) {3374WARN_ON(mode->expose_to_userspace);33753376if (drm_mode_expose_to_userspace(mode, &connector->modes,3377file_priv)) {3378mode->expose_to_userspace = true;3379mode_count++;3380}3381}33823383/*3384* This ioctl is called twice, once to determine how much space is3385* needed, and the 2nd time to fill it.3386*/3387if ((out_resp->count_modes >= mode_count) && mode_count) {3388copied = 0;3389mode_ptr = (struct drm_mode_modeinfo __user *)(unsigned long)out_resp->modes_ptr;3390list_for_each_entry(mode, &connector->modes, head) {3391if (!mode->expose_to_userspace)3392continue;33933394/* Clear the tag for the next time around */3395mode->expose_to_userspace = false;33963397drm_mode_convert_to_umode(&u_mode, mode);3398/*3399* Reset aspect ratio flags of user-mode, if modes with3400* aspect-ratio are not supported.3401*/3402if (!file_priv->aspect_ratio_allowed)3403u_mode.flags &= ~DRM_MODE_FLAG_PIC_AR_MASK;3404if (copy_to_user(mode_ptr + copied,3405&u_mode, sizeof(u_mode))) {3406ret = -EFAULT;34073408/*3409* Clear the tag for the rest of3410* the modes for the next time around.3411*/3412list_for_each_entry_continue(mode, &connector->modes, head)3413mode->expose_to_userspace = false;34143415mutex_unlock(&dev->mode_config.mutex);34163417goto out;3418}3419copied++;3420}3421} else {3422/* Clear the tag for the next time around */3423list_for_each_entry(mode, &connector->modes, head)3424mode->expose_to_userspace = false;3425}34263427out_resp->count_modes = mode_count;3428mutex_unlock(&dev->mode_config.mutex);34293430drm_modeset_lock(&dev->mode_config.connection_mutex, NULL);3431encoder = drm_connector_get_encoder(connector);3432if (encoder)3433out_resp->encoder_id = encoder->base.id;3434else3435out_resp->encoder_id = 0;34363437/* Only grab properties after probing, to make sure EDID and other3438* properties reflect the latest status.3439*/3440ret = drm_mode_object_get_properties(&connector->base, file_priv->atomic,3441(uint32_t __user *)(unsigned long)(out_resp->props_ptr),3442(uint64_t __user *)(unsigned long)(out_resp->prop_values_ptr),3443&out_resp->count_props);3444drm_modeset_unlock(&dev->mode_config.connection_mutex);34453446out:3447drm_connector_put(connector);34483449return ret;3450}34513452/**3453* drm_connector_find_by_fwnode - Find a connector based on the associated fwnode3454* @fwnode: fwnode for which to find the matching drm_connector3455*3456* This functions looks up a drm_connector based on its associated fwnode. When3457* a connector is found a reference to the connector is returned. The caller must3458* call drm_connector_put() to release this reference when it is done with the3459* connector.3460*3461* Returns: A reference to the found connector or an ERR_PTR().3462*/3463struct drm_connector *drm_connector_find_by_fwnode(struct fwnode_handle *fwnode)3464{3465struct drm_connector *connector, *found = ERR_PTR(-ENODEV);34663467if (!fwnode)3468return ERR_PTR(-ENODEV);34693470mutex_lock(&connector_list_lock);34713472list_for_each_entry(connector, &connector_list, global_connector_list_entry) {3473if (connector->fwnode == fwnode ||3474(connector->fwnode && connector->fwnode->secondary == fwnode)) {3475drm_connector_get(connector);3476found = connector;3477break;3478}3479}34803481mutex_unlock(&connector_list_lock);34823483return found;3484}34853486/**3487* drm_connector_oob_hotplug_event - Report out-of-band hotplug event to connector3488* @connector_fwnode: fwnode_handle to report the event on3489* @status: hot plug detect logical state3490*3491* On some hardware a hotplug event notification may come from outside the display3492* driver / device. An example of this is some USB Type-C setups where the hardware3493* muxes the DisplayPort data and aux-lines but does not pass the altmode HPD3494* status bit to the GPU's DP HPD pin.3495*3496* This function can be used to report these out-of-band events after obtaining3497* a drm_connector reference through calling drm_connector_find_by_fwnode().3498*/3499void drm_connector_oob_hotplug_event(struct fwnode_handle *connector_fwnode,3500enum drm_connector_status status)3501{3502struct drm_connector *connector;35033504connector = drm_connector_find_by_fwnode(connector_fwnode);3505if (IS_ERR(connector))3506return;35073508if (connector->funcs->oob_hotplug_event)3509connector->funcs->oob_hotplug_event(connector, status);35103511drm_connector_put(connector);3512}3513EXPORT_SYMBOL(drm_connector_oob_hotplug_event);351435153516/**3517* DOC: Tile group3518*3519* Tile groups are used to represent tiled monitors with a unique integer3520* identifier. Tiled monitors using DisplayID v1.3 have a unique 8-byte handle,3521* we store this in a tile group, so we have a common identifier for all tiles3522* in a monitor group. The property is called "TILE". Drivers can manage tile3523* groups using drm_mode_create_tile_group(), drm_mode_put_tile_group() and3524* drm_mode_get_tile_group(). But this is only needed for internal panels where3525* the tile group information is exposed through a non-standard way.3526*/35273528static void drm_tile_group_free(struct kref *kref)3529{3530struct drm_tile_group *tg = container_of(kref, struct drm_tile_group, refcount);3531struct drm_device *dev = tg->dev;35323533mutex_lock(&dev->mode_config.idr_mutex);3534idr_remove(&dev->mode_config.tile_idr, tg->id);3535mutex_unlock(&dev->mode_config.idr_mutex);3536kfree(tg);3537}35383539/**3540* drm_mode_put_tile_group - drop a reference to a tile group.3541* @dev: DRM device3542* @tg: tile group to drop reference to.3543*3544* drop reference to tile group and free if 0.3545*/3546void drm_mode_put_tile_group(struct drm_device *dev,3547struct drm_tile_group *tg)3548{3549kref_put(&tg->refcount, drm_tile_group_free);3550}3551EXPORT_SYMBOL(drm_mode_put_tile_group);35523553/**3554* drm_mode_get_tile_group - get a reference to an existing tile group3555* @dev: DRM device3556* @topology: 8-bytes unique per monitor.3557*3558* Use the unique bytes to get a reference to an existing tile group.3559*3560* RETURNS:3561* tile group or NULL if not found.3562*/3563struct drm_tile_group *drm_mode_get_tile_group(struct drm_device *dev,3564const char topology[8])3565{3566struct drm_tile_group *tg;3567int id;35683569mutex_lock(&dev->mode_config.idr_mutex);3570idr_for_each_entry(&dev->mode_config.tile_idr, tg, id) {3571if (!memcmp(tg->group_data, topology, 8)) {3572if (!kref_get_unless_zero(&tg->refcount))3573tg = NULL;3574mutex_unlock(&dev->mode_config.idr_mutex);3575return tg;3576}3577}3578mutex_unlock(&dev->mode_config.idr_mutex);3579return NULL;3580}3581EXPORT_SYMBOL(drm_mode_get_tile_group);35823583/**3584* drm_mode_create_tile_group - create a tile group from a displayid description3585* @dev: DRM device3586* @topology: 8-bytes unique per monitor.3587*3588* Create a tile group for the unique monitor, and get a unique3589* identifier for the tile group.3590*3591* RETURNS:3592* new tile group or NULL.3593*/3594struct drm_tile_group *drm_mode_create_tile_group(struct drm_device *dev,3595const char topology[8])3596{3597struct drm_tile_group *tg;3598int ret;35993600tg = kzalloc(sizeof(*tg), GFP_KERNEL);3601if (!tg)3602return NULL;36033604kref_init(&tg->refcount);3605memcpy(tg->group_data, topology, 8);3606tg->dev = dev;36073608mutex_lock(&dev->mode_config.idr_mutex);3609ret = idr_alloc(&dev->mode_config.tile_idr, tg, 1, 0, GFP_KERNEL);3610if (ret >= 0) {3611tg->id = ret;3612} else {3613kfree(tg);3614tg = NULL;3615}36163617mutex_unlock(&dev->mode_config.idr_mutex);3618return tg;3619}3620EXPORT_SYMBOL(drm_mode_create_tile_group);362136223623