| 1 | /* |
| 2 | * Copyright (c) 2016 Intel Corporation |
| 3 | * |
| 4 | * Permission to use, copy, modify, distribute, and sell this software and its |
| 5 | * documentation for any purpose is hereby granted without fee, provided that |
| 6 | * the above copyright notice appear in all copies and that both that copyright |
| 7 | * notice and this permission notice appear in supporting documentation, and |
| 8 | * that the name of the copyright holders not be used in advertising or |
| 9 | * publicity pertaining to distribution of the software without specific, |
| 10 | * written prior permission. The copyright holders make no representations |
| 11 | * about the suitability of this software for any purpose. It is provided "as |
| 12 | * is" without express or implied warranty. |
| 13 | * |
| 14 | * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, |
| 15 | * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO |
| 16 | * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR |
| 17 | * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, |
| 18 | * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER |
| 19 | * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE |
| 20 | * OF THIS SOFTWARE. |
| 21 | */ |
| 22 | |
| 23 | #include <drm/drm_auth.h> |
| 24 | #include <drm/drm_connector.h> |
| 25 | #include <drm/drm_drv.h> |
| 26 | #include <drm/drm_edid.h> |
| 27 | #include <drm/drm_encoder.h> |
| 28 | #include <drm/drm_file.h> |
| 29 | #include <drm/drm_managed.h> |
| 30 | #include <drm/drm_panel.h> |
| 31 | #include <drm/drm_print.h> |
| 32 | #include <drm/drm_privacy_screen_consumer.h> |
| 33 | #include <drm/drm_sysfs.h> |
| 34 | #include <drm/drm_utils.h> |
| 35 | |
| 36 | #include <linux/export.h> |
| 37 | #include <linux/platform_device.h> |
| 38 | #include <linux/property.h> |
| 39 | #include <linux/uaccess.h> |
| 40 | |
| 41 | #include <video/cmdline.h> |
| 42 | |
| 43 | #include "drm_crtc_internal.h" |
| 44 | #include "drm_internal.h" |
| 45 | |
| 46 | /** |
| 47 | * DOC: overview |
| 48 | * |
| 49 | * In DRM connectors are the general abstraction for display sinks, and include |
| 50 | * also fixed panels or anything else that can display pixels in some form. As |
| 51 | * opposed to all other KMS objects representing hardware (like CRTC, encoder or |
| 52 | * plane abstractions) connectors can be hotplugged and unplugged at runtime. |
| 53 | * Hence they are reference-counted using drm_connector_get() and |
| 54 | * drm_connector_put(). |
| 55 | * |
| 56 | * KMS driver must create, initialize, register and attach at a &struct |
| 57 | * drm_connector for each such sink. The instance is created as other KMS |
| 58 | * objects and initialized by setting the following fields. The connector is |
| 59 | * initialized with a call to drm_connector_init() with a pointer to the |
| 60 | * &struct drm_connector_funcs and a connector type, and then exposed to |
| 61 | * userspace with a call to drm_connector_register(). |
| 62 | * |
| 63 | * Connectors must be attached to an encoder to be used. For devices that map |
| 64 | * connectors to encoders 1:1, the connector should be attached at |
| 65 | * initialization time with a call to drm_connector_attach_encoder(). The |
| 66 | * driver must also set the &drm_connector.encoder field to point to the |
| 67 | * attached encoder. |
| 68 | * |
| 69 | * For connectors which are not fixed (like built-in panels) the driver needs to |
| 70 | * support hotplug notifications. The simplest way to do that is by using the |
| 71 | * probe helpers, see drm_kms_helper_poll_init() for connectors which don't have |
| 72 | * hardware support for hotplug interrupts. Connectors with hardware hotplug |
| 73 | * support can instead use e.g. drm_helper_hpd_irq_event(). |
| 74 | */ |
| 75 | |
| 76 | /* |
| 77 | * Global connector list for drm_connector_find_by_fwnode(). |
| 78 | * Note drm_connector_[un]register() first take connector->lock and then |
| 79 | * take the connector_list_lock. |
| 80 | */ |
| 81 | static DEFINE_MUTEX(connector_list_lock); |
| 82 | static LIST_HEAD(connector_list); |
| 83 | |
| 84 | struct drm_conn_prop_enum_list { |
| 85 | int type; |
| 86 | const char *name; |
| 87 | struct ida ida; |
| 88 | }; |
| 89 | |
| 90 | /* |
| 91 | * Connector and encoder types. |
| 92 | */ |
| 93 | static struct drm_conn_prop_enum_list drm_connector_enum_list[] = { |
| 94 | { DRM_MODE_CONNECTOR_Unknown, "Unknown" }, |
| 95 | { DRM_MODE_CONNECTOR_VGA, "VGA" }, |
| 96 | { DRM_MODE_CONNECTOR_DVII, "DVI-I" }, |
| 97 | { DRM_MODE_CONNECTOR_DVID, "DVI-D" }, |
| 98 | { DRM_MODE_CONNECTOR_DVIA, "DVI-A" }, |
| 99 | { DRM_MODE_CONNECTOR_Composite, "Composite" }, |
| 100 | { DRM_MODE_CONNECTOR_SVIDEO, "SVIDEO" }, |
| 101 | { DRM_MODE_CONNECTOR_LVDS, "LVDS" }, |
| 102 | { DRM_MODE_CONNECTOR_Component, "Component" }, |
| 103 | { DRM_MODE_CONNECTOR_9PinDIN, "DIN" }, |
| 104 | { DRM_MODE_CONNECTOR_DisplayPort, "DP" }, |
| 105 | { DRM_MODE_CONNECTOR_HDMIA, "HDMI-A" }, |
| 106 | { DRM_MODE_CONNECTOR_HDMIB, "HDMI-B" }, |
| 107 | { DRM_MODE_CONNECTOR_TV, "TV" }, |
| 108 | { DRM_MODE_CONNECTOR_eDP, "eDP" }, |
| 109 | { DRM_MODE_CONNECTOR_VIRTUAL, "Virtual" }, |
| 110 | { DRM_MODE_CONNECTOR_DSI, "DSI" }, |
| 111 | { DRM_MODE_CONNECTOR_DPI, "DPI" }, |
| 112 | { DRM_MODE_CONNECTOR_WRITEBACK, "Writeback" }, |
| 113 | { DRM_MODE_CONNECTOR_SPI, "SPI" }, |
| 114 | { DRM_MODE_CONNECTOR_USB, "USB" }, |
| 115 | }; |
| 116 | |
| 117 | void drm_connector_ida_init(void) |
| 118 | { |
| 119 | int i; |
| 120 | |
| 121 | for (i = 0; i < ARRAY_SIZE(drm_connector_enum_list); i++) |
| 122 | ida_init(ida: &drm_connector_enum_list[i].ida); |
| 123 | } |
| 124 | |
| 125 | void drm_connector_ida_destroy(void) |
| 126 | { |
| 127 | int i; |
| 128 | |
| 129 | for (i = 0; i < ARRAY_SIZE(drm_connector_enum_list); i++) |
| 130 | ida_destroy(ida: &drm_connector_enum_list[i].ida); |
| 131 | } |
| 132 | |
| 133 | /** |
| 134 | * drm_get_connector_type_name - return a string for connector type |
| 135 | * @type: The connector type (DRM_MODE_CONNECTOR_*) |
| 136 | * |
| 137 | * Returns: the name of the connector type, or NULL if the type is not valid. |
| 138 | */ |
| 139 | const char *drm_get_connector_type_name(unsigned int type) |
| 140 | { |
| 141 | if (type < ARRAY_SIZE(drm_connector_enum_list)) |
| 142 | return drm_connector_enum_list[type].name; |
| 143 | |
| 144 | return NULL; |
| 145 | } |
| 146 | EXPORT_SYMBOL(drm_get_connector_type_name); |
| 147 | |
| 148 | /** |
| 149 | * drm_connector_get_cmdline_mode - reads the user's cmdline mode |
| 150 | * @connector: connector to query |
| 151 | * |
| 152 | * The kernel supports per-connector configuration of its consoles through |
| 153 | * use of the video= parameter. This function parses that option and |
| 154 | * extracts the user's specified mode (or enable/disable status) for a |
| 155 | * particular connector. This is typically only used during the early fbdev |
| 156 | * setup. |
| 157 | */ |
| 158 | static void drm_connector_get_cmdline_mode(struct drm_connector *connector) |
| 159 | { |
| 160 | struct drm_cmdline_mode *mode = &connector->cmdline_mode; |
| 161 | const char *option; |
| 162 | |
| 163 | option = video_get_options(name: connector->name); |
| 164 | if (!option) |
| 165 | return; |
| 166 | |
| 167 | if (!drm_mode_parse_command_line_for_connector(mode_option: option, |
| 168 | connector, |
| 169 | mode)) |
| 170 | return; |
| 171 | |
| 172 | if (mode->force) { |
| 173 | DRM_INFO("forcing %s connector %s\n" , connector->name, |
| 174 | drm_get_connector_force_name(mode->force)); |
| 175 | connector->force = mode->force; |
| 176 | } |
| 177 | |
| 178 | if (mode->panel_orientation != DRM_MODE_PANEL_ORIENTATION_UNKNOWN) { |
| 179 | DRM_INFO("cmdline forces connector %s panel_orientation to %d\n" , |
| 180 | connector->name, mode->panel_orientation); |
| 181 | drm_connector_set_panel_orientation(connector, |
| 182 | panel_orientation: mode->panel_orientation); |
| 183 | } |
| 184 | |
| 185 | DRM_DEBUG_KMS("cmdline mode for connector %s %s %dx%d@%dHz%s%s%s\n" , |
| 186 | connector->name, mode->name, |
| 187 | mode->xres, mode->yres, |
| 188 | mode->refresh_specified ? mode->refresh : 60, |
| 189 | mode->rb ? " reduced blanking" : "" , |
| 190 | mode->margins ? " with margins" : "" , |
| 191 | mode->interlace ? " interlaced" : "" ); |
| 192 | } |
| 193 | |
| 194 | static void drm_connector_free(struct kref *kref) |
| 195 | { |
| 196 | struct drm_connector *connector = |
| 197 | container_of(kref, struct drm_connector, base.refcount); |
| 198 | struct drm_device *dev = connector->dev; |
| 199 | |
| 200 | drm_mode_object_unregister(dev, object: &connector->base); |
| 201 | connector->funcs->destroy(connector); |
| 202 | } |
| 203 | |
| 204 | void drm_connector_free_work_fn(struct work_struct *work) |
| 205 | { |
| 206 | struct drm_connector *connector, *n; |
| 207 | struct drm_device *dev = |
| 208 | container_of(work, struct drm_device, mode_config.connector_free_work); |
| 209 | struct drm_mode_config *config = &dev->mode_config; |
| 210 | unsigned long flags; |
| 211 | struct llist_node *freed; |
| 212 | |
| 213 | spin_lock_irqsave(&config->connector_list_lock, flags); |
| 214 | freed = llist_del_all(head: &config->connector_free_list); |
| 215 | spin_unlock_irqrestore(lock: &config->connector_list_lock, flags); |
| 216 | |
| 217 | llist_for_each_entry_safe(connector, n, freed, free_node) { |
| 218 | drm_mode_object_unregister(dev, object: &connector->base); |
| 219 | connector->funcs->destroy(connector); |
| 220 | } |
| 221 | } |
| 222 | |
| 223 | static int drm_connector_init_only(struct drm_device *dev, |
| 224 | struct drm_connector *connector, |
| 225 | const struct drm_connector_funcs *funcs, |
| 226 | int connector_type, |
| 227 | struct i2c_adapter *ddc) |
| 228 | { |
| 229 | struct drm_mode_config *config = &dev->mode_config; |
| 230 | int ret; |
| 231 | struct ida *connector_ida = |
| 232 | &drm_connector_enum_list[connector_type].ida; |
| 233 | |
| 234 | WARN_ON(drm_drv_uses_atomic_modeset(dev) && |
| 235 | (!funcs->atomic_destroy_state || |
| 236 | !funcs->atomic_duplicate_state)); |
| 237 | |
| 238 | ret = __drm_mode_object_add(dev, obj: &connector->base, |
| 239 | DRM_MODE_OBJECT_CONNECTOR, |
| 240 | register_obj: false, obj_free_cb: drm_connector_free); |
| 241 | if (ret) |
| 242 | return ret; |
| 243 | |
| 244 | connector->base.properties = &connector->properties; |
| 245 | connector->dev = dev; |
| 246 | connector->funcs = funcs; |
| 247 | |
| 248 | /* connector index is used with 32bit bitmasks */ |
| 249 | ret = ida_alloc_max(ida: &config->connector_ida, max: 31, GFP_KERNEL); |
| 250 | if (ret < 0) { |
| 251 | DRM_DEBUG_KMS("Failed to allocate %s connector index: %d\n" , |
| 252 | drm_connector_enum_list[connector_type].name, |
| 253 | ret); |
| 254 | goto out_put; |
| 255 | } |
| 256 | connector->index = ret; |
| 257 | ret = 0; |
| 258 | |
| 259 | connector->connector_type = connector_type; |
| 260 | connector->connector_type_id = |
| 261 | ida_alloc_min(ida: connector_ida, min: 1, GFP_KERNEL); |
| 262 | if (connector->connector_type_id < 0) { |
| 263 | ret = connector->connector_type_id; |
| 264 | goto out_put_id; |
| 265 | } |
| 266 | connector->name = |
| 267 | kasprintf(GFP_KERNEL, fmt: "%s-%d" , |
| 268 | drm_connector_enum_list[connector_type].name, |
| 269 | connector->connector_type_id); |
| 270 | if (!connector->name) { |
| 271 | ret = -ENOMEM; |
| 272 | goto out_put_type_id; |
| 273 | } |
| 274 | |
| 275 | /* provide ddc symlink in sysfs */ |
| 276 | connector->ddc = ddc; |
| 277 | |
| 278 | INIT_LIST_HEAD(list: &connector->head); |
| 279 | INIT_LIST_HEAD(list: &connector->global_connector_list_entry); |
| 280 | INIT_LIST_HEAD(list: &connector->probed_modes); |
| 281 | INIT_LIST_HEAD(list: &connector->modes); |
| 282 | mutex_init(&connector->mutex); |
| 283 | mutex_init(&connector->cec.mutex); |
| 284 | mutex_init(&connector->eld_mutex); |
| 285 | mutex_init(&connector->edid_override_mutex); |
| 286 | mutex_init(&connector->hdmi.infoframes.lock); |
| 287 | mutex_init(&connector->hdmi_audio.lock); |
| 288 | connector->edid_blob_ptr = NULL; |
| 289 | connector->epoch_counter = 0; |
| 290 | connector->tile_blob_ptr = NULL; |
| 291 | connector->status = connector_status_unknown; |
| 292 | connector->display_info.panel_orientation = |
| 293 | DRM_MODE_PANEL_ORIENTATION_UNKNOWN; |
| 294 | |
| 295 | drm_connector_get_cmdline_mode(connector); |
| 296 | |
| 297 | if (connector_type != DRM_MODE_CONNECTOR_VIRTUAL && |
| 298 | connector_type != DRM_MODE_CONNECTOR_WRITEBACK) |
| 299 | drm_connector_attach_edid_property(connector); |
| 300 | |
| 301 | drm_object_attach_property(obj: &connector->base, |
| 302 | property: config->dpms_property, init_val: 0); |
| 303 | |
| 304 | drm_object_attach_property(obj: &connector->base, |
| 305 | property: config->link_status_property, |
| 306 | init_val: 0); |
| 307 | |
| 308 | drm_object_attach_property(obj: &connector->base, |
| 309 | property: config->non_desktop_property, |
| 310 | init_val: 0); |
| 311 | drm_object_attach_property(obj: &connector->base, |
| 312 | property: config->tile_property, |
| 313 | init_val: 0); |
| 314 | |
| 315 | if (drm_core_check_feature(dev, feature: DRIVER_ATOMIC)) { |
| 316 | drm_object_attach_property(obj: &connector->base, property: config->prop_crtc_id, init_val: 0); |
| 317 | } |
| 318 | |
| 319 | connector->debugfs_entry = NULL; |
| 320 | out_put_type_id: |
| 321 | if (ret) |
| 322 | ida_free(connector_ida, id: connector->connector_type_id); |
| 323 | out_put_id: |
| 324 | if (ret) |
| 325 | ida_free(&config->connector_ida, id: connector->index); |
| 326 | out_put: |
| 327 | if (ret) |
| 328 | drm_mode_object_unregister(dev, object: &connector->base); |
| 329 | |
| 330 | return ret; |
| 331 | } |
| 332 | |
| 333 | static void drm_connector_add(struct drm_connector *connector) |
| 334 | { |
| 335 | struct drm_device *dev = connector->dev; |
| 336 | struct drm_mode_config *config = &dev->mode_config; |
| 337 | |
| 338 | if (drm_WARN_ON(dev, !list_empty(&connector->head))) |
| 339 | return; |
| 340 | |
| 341 | spin_lock_irq(lock: &config->connector_list_lock); |
| 342 | list_add_tail(new: &connector->head, head: &config->connector_list); |
| 343 | config->num_connector++; |
| 344 | spin_unlock_irq(lock: &config->connector_list_lock); |
| 345 | } |
| 346 | |
| 347 | static void drm_connector_remove(struct drm_connector *connector) |
| 348 | { |
| 349 | struct drm_device *dev = connector->dev; |
| 350 | |
| 351 | /* |
| 352 | * For dynamic connectors drm_connector_cleanup() can call this function |
| 353 | * before the connector is registered and added to the list. |
| 354 | */ |
| 355 | if (list_empty(head: &connector->head)) |
| 356 | return; |
| 357 | |
| 358 | spin_lock_irq(lock: &dev->mode_config.connector_list_lock); |
| 359 | list_del_init(entry: &connector->head); |
| 360 | dev->mode_config.num_connector--; |
| 361 | spin_unlock_irq(lock: &dev->mode_config.connector_list_lock); |
| 362 | } |
| 363 | |
| 364 | static int drm_connector_init_and_add(struct drm_device *dev, |
| 365 | struct drm_connector *connector, |
| 366 | const struct drm_connector_funcs *funcs, |
| 367 | int connector_type, |
| 368 | struct i2c_adapter *ddc) |
| 369 | { |
| 370 | int ret; |
| 371 | |
| 372 | ret = drm_connector_init_only(dev, connector, funcs, connector_type, ddc); |
| 373 | if (ret) |
| 374 | return ret; |
| 375 | |
| 376 | drm_connector_add(connector); |
| 377 | |
| 378 | return 0; |
| 379 | } |
| 380 | |
| 381 | /** |
| 382 | * drm_connector_init - Init a preallocated connector |
| 383 | * @dev: DRM device |
| 384 | * @connector: the connector to init |
| 385 | * @funcs: callbacks for this connector |
| 386 | * @connector_type: user visible type of the connector |
| 387 | * |
| 388 | * Initialises a preallocated connector. Connectors should be |
| 389 | * subclassed as part of driver connector objects. |
| 390 | * |
| 391 | * At driver unload time the driver's &drm_connector_funcs.destroy hook |
| 392 | * should call drm_connector_cleanup() and free the connector structure. |
| 393 | * The connector structure should not be allocated with devm_kzalloc(). |
| 394 | * |
| 395 | * Note: consider using drmm_connector_init() instead of |
| 396 | * drm_connector_init() to let the DRM managed resource infrastructure |
| 397 | * take care of cleanup and deallocation. |
| 398 | * |
| 399 | * Returns: |
| 400 | * Zero on success, error code on failure. |
| 401 | */ |
| 402 | int drm_connector_init(struct drm_device *dev, |
| 403 | struct drm_connector *connector, |
| 404 | const struct drm_connector_funcs *funcs, |
| 405 | int connector_type) |
| 406 | { |
| 407 | if (drm_WARN_ON(dev, !(funcs && funcs->destroy))) |
| 408 | return -EINVAL; |
| 409 | |
| 410 | return drm_connector_init_and_add(dev, connector, funcs, connector_type, NULL); |
| 411 | } |
| 412 | EXPORT_SYMBOL(drm_connector_init); |
| 413 | |
| 414 | /** |
| 415 | * drm_connector_dynamic_init - Init a preallocated dynamic connector |
| 416 | * @dev: DRM device |
| 417 | * @connector: the connector to init |
| 418 | * @funcs: callbacks for this connector |
| 419 | * @connector_type: user visible type of the connector |
| 420 | * @ddc: pointer to the associated ddc adapter |
| 421 | * |
| 422 | * Initialises a preallocated dynamic connector. Connectors should be |
| 423 | * subclassed as part of driver connector objects. The connector |
| 424 | * structure should not be allocated with devm_kzalloc(). |
| 425 | * |
| 426 | * Drivers should call this for dynamic connectors which can be hotplugged |
| 427 | * after drm_dev_register() has been called already, e.g. DP MST connectors. |
| 428 | * For all other - static - connectors, drivers should call one of the |
| 429 | * drm_connector_init*()/drmm_connector_init*() functions. |
| 430 | * |
| 431 | * After calling this function the drivers must call |
| 432 | * drm_connector_dynamic_register(). |
| 433 | * |
| 434 | * To remove the connector the driver must call drm_connector_unregister() |
| 435 | * followed by drm_connector_put(). Putting the last reference will call the |
| 436 | * driver's &drm_connector_funcs.destroy hook, which in turn must call |
| 437 | * drm_connector_cleanup() and free the connector structure. |
| 438 | * |
| 439 | * Returns: |
| 440 | * Zero on success, error code on failure. |
| 441 | */ |
| 442 | int drm_connector_dynamic_init(struct drm_device *dev, |
| 443 | struct drm_connector *connector, |
| 444 | const struct drm_connector_funcs *funcs, |
| 445 | int connector_type, |
| 446 | struct i2c_adapter *ddc) |
| 447 | { |
| 448 | if (drm_WARN_ON(dev, !(funcs && funcs->destroy))) |
| 449 | return -EINVAL; |
| 450 | |
| 451 | return drm_connector_init_only(dev, connector, funcs, connector_type, ddc); |
| 452 | } |
| 453 | EXPORT_SYMBOL(drm_connector_dynamic_init); |
| 454 | |
| 455 | /** |
| 456 | * drm_connector_init_with_ddc - Init a preallocated connector |
| 457 | * @dev: DRM device |
| 458 | * @connector: the connector to init |
| 459 | * @funcs: callbacks for this connector |
| 460 | * @connector_type: user visible type of the connector |
| 461 | * @ddc: pointer to the associated ddc adapter |
| 462 | * |
| 463 | * Initialises a preallocated connector. Connectors should be |
| 464 | * subclassed as part of driver connector objects. |
| 465 | * |
| 466 | * At driver unload time the driver's &drm_connector_funcs.destroy hook |
| 467 | * should call drm_connector_cleanup() and free the connector structure. |
| 468 | * The connector structure should not be allocated with devm_kzalloc(). |
| 469 | * |
| 470 | * Ensures that the ddc field of the connector is correctly set. |
| 471 | * |
| 472 | * Note: consider using drmm_connector_init() instead of |
| 473 | * drm_connector_init_with_ddc() to let the DRM managed resource |
| 474 | * infrastructure take care of cleanup and deallocation. |
| 475 | * |
| 476 | * Returns: |
| 477 | * Zero on success, error code on failure. |
| 478 | */ |
| 479 | int drm_connector_init_with_ddc(struct drm_device *dev, |
| 480 | struct drm_connector *connector, |
| 481 | const struct drm_connector_funcs *funcs, |
| 482 | int connector_type, |
| 483 | struct i2c_adapter *ddc) |
| 484 | { |
| 485 | if (drm_WARN_ON(dev, !(funcs && funcs->destroy))) |
| 486 | return -EINVAL; |
| 487 | |
| 488 | return drm_connector_init_and_add(dev, connector, funcs, connector_type, ddc); |
| 489 | } |
| 490 | EXPORT_SYMBOL(drm_connector_init_with_ddc); |
| 491 | |
| 492 | static void drm_connector_cleanup_action(struct drm_device *dev, |
| 493 | void *ptr) |
| 494 | { |
| 495 | struct drm_connector *connector = ptr; |
| 496 | |
| 497 | drm_connector_cleanup(connector); |
| 498 | } |
| 499 | |
| 500 | /** |
| 501 | * drmm_connector_init - Init a preallocated connector |
| 502 | * @dev: DRM device |
| 503 | * @connector: the connector to init |
| 504 | * @funcs: callbacks for this connector |
| 505 | * @connector_type: user visible type of the connector |
| 506 | * @ddc: optional pointer to the associated ddc adapter |
| 507 | * |
| 508 | * Initialises a preallocated connector. Connectors should be |
| 509 | * subclassed as part of driver connector objects. |
| 510 | * |
| 511 | * Cleanup is automatically handled with a call to |
| 512 | * drm_connector_cleanup() in a DRM-managed action. |
| 513 | * |
| 514 | * The connector structure should be allocated with drmm_kzalloc(). |
| 515 | * |
| 516 | * The @drm_connector_funcs.destroy hook must be NULL. |
| 517 | * |
| 518 | * Returns: |
| 519 | * Zero on success, error code on failure. |
| 520 | */ |
| 521 | int drmm_connector_init(struct drm_device *dev, |
| 522 | struct drm_connector *connector, |
| 523 | const struct drm_connector_funcs *funcs, |
| 524 | int connector_type, |
| 525 | struct i2c_adapter *ddc) |
| 526 | { |
| 527 | int ret; |
| 528 | |
| 529 | if (drm_WARN_ON(dev, funcs && funcs->destroy)) |
| 530 | return -EINVAL; |
| 531 | |
| 532 | ret = drm_connector_init_and_add(dev, connector, funcs, connector_type, ddc); |
| 533 | if (ret) |
| 534 | return ret; |
| 535 | |
| 536 | ret = drmm_add_action_or_reset(dev, drm_connector_cleanup_action, |
| 537 | connector); |
| 538 | if (ret) |
| 539 | return ret; |
| 540 | |
| 541 | return 0; |
| 542 | } |
| 543 | EXPORT_SYMBOL(drmm_connector_init); |
| 544 | |
| 545 | /** |
| 546 | * drmm_connector_hdmi_init - Init a preallocated HDMI connector |
| 547 | * @dev: DRM device |
| 548 | * @connector: A pointer to the HDMI connector to init |
| 549 | * @vendor: HDMI Controller Vendor name |
| 550 | * @product: HDMI Controller Product name |
| 551 | * @funcs: callbacks for this connector |
| 552 | * @hdmi_funcs: HDMI-related callbacks for this connector |
| 553 | * @connector_type: user visible type of the connector |
| 554 | * @ddc: optional pointer to the associated ddc adapter |
| 555 | * @supported_formats: Bitmask of @hdmi_colorspace listing supported output formats |
| 556 | * @max_bpc: Maximum bits per char the HDMI connector supports |
| 557 | * |
| 558 | * Initialises a preallocated HDMI connector. Connectors can be |
| 559 | * subclassed as part of driver connector objects. |
| 560 | * |
| 561 | * Cleanup is automatically handled with a call to |
| 562 | * drm_connector_cleanup() in a DRM-managed action. |
| 563 | * |
| 564 | * The connector structure should be allocated with drmm_kzalloc(). |
| 565 | * |
| 566 | * The @drm_connector_funcs.destroy hook must be NULL. |
| 567 | * |
| 568 | * Returns: |
| 569 | * Zero on success, error code on failure. |
| 570 | */ |
| 571 | int drmm_connector_hdmi_init(struct drm_device *dev, |
| 572 | struct drm_connector *connector, |
| 573 | const char *vendor, const char *product, |
| 574 | const struct drm_connector_funcs *funcs, |
| 575 | const struct drm_connector_hdmi_funcs *hdmi_funcs, |
| 576 | int connector_type, |
| 577 | struct i2c_adapter *ddc, |
| 578 | unsigned long supported_formats, |
| 579 | unsigned int max_bpc) |
| 580 | { |
| 581 | int ret; |
| 582 | |
| 583 | if (!vendor || !product) |
| 584 | return -EINVAL; |
| 585 | |
| 586 | if ((strlen(vendor) > DRM_CONNECTOR_HDMI_VENDOR_LEN) || |
| 587 | (strlen(product) > DRM_CONNECTOR_HDMI_PRODUCT_LEN)) |
| 588 | return -EINVAL; |
| 589 | |
| 590 | if (!(connector_type == DRM_MODE_CONNECTOR_HDMIA || |
| 591 | connector_type == DRM_MODE_CONNECTOR_HDMIB)) |
| 592 | return -EINVAL; |
| 593 | |
| 594 | if (!supported_formats || !(supported_formats & BIT(HDMI_COLORSPACE_RGB))) |
| 595 | return -EINVAL; |
| 596 | |
| 597 | if (connector->ycbcr_420_allowed != !!(supported_formats & BIT(HDMI_COLORSPACE_YUV420))) |
| 598 | return -EINVAL; |
| 599 | |
| 600 | if (!(max_bpc == 8 || max_bpc == 10 || max_bpc == 12)) |
| 601 | return -EINVAL; |
| 602 | |
| 603 | ret = drmm_connector_init(dev, connector, funcs, connector_type, ddc); |
| 604 | if (ret) |
| 605 | return ret; |
| 606 | |
| 607 | connector->hdmi.supported_formats = supported_formats; |
| 608 | strtomem_pad(connector->hdmi.vendor, vendor, 0); |
| 609 | strtomem_pad(connector->hdmi.product, product, 0); |
| 610 | |
| 611 | /* |
| 612 | * drm_connector_attach_max_bpc_property() requires the |
| 613 | * connector to have a state. |
| 614 | */ |
| 615 | if (connector->funcs->reset) |
| 616 | connector->funcs->reset(connector); |
| 617 | |
| 618 | drm_connector_attach_max_bpc_property(connector, min: 8, max: max_bpc); |
| 619 | connector->max_bpc = max_bpc; |
| 620 | |
| 621 | if (max_bpc > 8) |
| 622 | drm_connector_attach_hdr_output_metadata_property(connector); |
| 623 | |
| 624 | connector->hdmi.funcs = hdmi_funcs; |
| 625 | |
| 626 | return 0; |
| 627 | } |
| 628 | EXPORT_SYMBOL(drmm_connector_hdmi_init); |
| 629 | |
| 630 | /** |
| 631 | * drm_connector_attach_edid_property - attach edid property. |
| 632 | * @connector: the connector |
| 633 | * |
| 634 | * Some connector types like DRM_MODE_CONNECTOR_VIRTUAL do not get a |
| 635 | * edid property attached by default. This function can be used to |
| 636 | * explicitly enable the edid property in these cases. |
| 637 | */ |
| 638 | void drm_connector_attach_edid_property(struct drm_connector *connector) |
| 639 | { |
| 640 | struct drm_mode_config *config = &connector->dev->mode_config; |
| 641 | |
| 642 | drm_object_attach_property(obj: &connector->base, |
| 643 | property: config->edid_property, |
| 644 | init_val: 0); |
| 645 | } |
| 646 | EXPORT_SYMBOL(drm_connector_attach_edid_property); |
| 647 | |
| 648 | /** |
| 649 | * drm_connector_attach_encoder - attach a connector to an encoder |
| 650 | * @connector: connector to attach |
| 651 | * @encoder: encoder to attach @connector to |
| 652 | * |
| 653 | * This function links up a connector to an encoder. Note that the routing |
| 654 | * restrictions between encoders and crtcs are exposed to userspace through the |
| 655 | * possible_clones and possible_crtcs bitmasks. |
| 656 | * |
| 657 | * Returns: |
| 658 | * Zero on success, negative errno on failure. |
| 659 | */ |
| 660 | int drm_connector_attach_encoder(struct drm_connector *connector, |
| 661 | struct drm_encoder *encoder) |
| 662 | { |
| 663 | /* |
| 664 | * In the past, drivers have attempted to model the static association |
| 665 | * of connector to encoder in simple connector/encoder devices using a |
| 666 | * direct assignment of connector->encoder = encoder. This connection |
| 667 | * is a logical one and the responsibility of the core, so drivers are |
| 668 | * expected not to mess with this. |
| 669 | * |
| 670 | * Note that the error return should've been enough here, but a large |
| 671 | * majority of drivers ignores the return value, so add in a big WARN |
| 672 | * to get people's attention. |
| 673 | */ |
| 674 | if (WARN_ON(connector->encoder)) |
| 675 | return -EINVAL; |
| 676 | |
| 677 | connector->possible_encoders |= drm_encoder_mask(encoder); |
| 678 | |
| 679 | return 0; |
| 680 | } |
| 681 | EXPORT_SYMBOL(drm_connector_attach_encoder); |
| 682 | |
| 683 | /** |
| 684 | * drm_connector_has_possible_encoder - check if the connector and encoder are |
| 685 | * associated with each other |
| 686 | * @connector: the connector |
| 687 | * @encoder: the encoder |
| 688 | * |
| 689 | * Returns: |
| 690 | * True if @encoder is one of the possible encoders for @connector. |
| 691 | */ |
| 692 | bool drm_connector_has_possible_encoder(struct drm_connector *connector, |
| 693 | struct drm_encoder *encoder) |
| 694 | { |
| 695 | return connector->possible_encoders & drm_encoder_mask(encoder); |
| 696 | } |
| 697 | EXPORT_SYMBOL(drm_connector_has_possible_encoder); |
| 698 | |
| 699 | static void drm_mode_remove(struct drm_connector *connector, |
| 700 | struct drm_display_mode *mode) |
| 701 | { |
| 702 | list_del(entry: &mode->head); |
| 703 | drm_mode_destroy(dev: connector->dev, mode); |
| 704 | } |
| 705 | |
| 706 | /** |
| 707 | * drm_connector_cec_phys_addr_invalidate - invalidate CEC physical address |
| 708 | * @connector: connector undergoing CEC operation |
| 709 | * |
| 710 | * Invalidated CEC physical address set for this DRM connector. |
| 711 | */ |
| 712 | void drm_connector_cec_phys_addr_invalidate(struct drm_connector *connector) |
| 713 | { |
| 714 | mutex_lock(&connector->cec.mutex); |
| 715 | |
| 716 | if (connector->cec.funcs && |
| 717 | connector->cec.funcs->phys_addr_invalidate) |
| 718 | connector->cec.funcs->phys_addr_invalidate(connector); |
| 719 | |
| 720 | mutex_unlock(lock: &connector->cec.mutex); |
| 721 | } |
| 722 | EXPORT_SYMBOL(drm_connector_cec_phys_addr_invalidate); |
| 723 | |
| 724 | /** |
| 725 | * drm_connector_cec_phys_addr_set - propagate CEC physical address |
| 726 | * @connector: connector undergoing CEC operation |
| 727 | * |
| 728 | * Propagate CEC physical address from the display_info to this DRM connector. |
| 729 | */ |
| 730 | void drm_connector_cec_phys_addr_set(struct drm_connector *connector) |
| 731 | { |
| 732 | u16 addr; |
| 733 | |
| 734 | mutex_lock(&connector->cec.mutex); |
| 735 | |
| 736 | addr = connector->display_info.source_physical_address; |
| 737 | |
| 738 | if (connector->cec.funcs && |
| 739 | connector->cec.funcs->phys_addr_set) |
| 740 | connector->cec.funcs->phys_addr_set(connector, addr); |
| 741 | |
| 742 | mutex_unlock(lock: &connector->cec.mutex); |
| 743 | } |
| 744 | EXPORT_SYMBOL(drm_connector_cec_phys_addr_set); |
| 745 | |
| 746 | /** |
| 747 | * drm_connector_cleanup - cleans up an initialised connector |
| 748 | * @connector: connector to cleanup |
| 749 | * |
| 750 | * Cleans up the connector but doesn't free the object. |
| 751 | */ |
| 752 | void drm_connector_cleanup(struct drm_connector *connector) |
| 753 | { |
| 754 | struct drm_device *dev = connector->dev; |
| 755 | struct drm_display_mode *mode, *t; |
| 756 | |
| 757 | /* The connector should have been removed from userspace long before |
| 758 | * it is finally destroyed. |
| 759 | */ |
| 760 | if (WARN_ON(connector->registration_state == |
| 761 | DRM_CONNECTOR_REGISTERED)) |
| 762 | drm_connector_unregister(connector); |
| 763 | |
| 764 | platform_device_unregister(connector->hdmi_audio.codec_pdev); |
| 765 | |
| 766 | if (connector->privacy_screen) { |
| 767 | drm_privacy_screen_put(priv: connector->privacy_screen); |
| 768 | connector->privacy_screen = NULL; |
| 769 | } |
| 770 | |
| 771 | if (connector->tile_group) { |
| 772 | drm_mode_put_tile_group(dev, tg: connector->tile_group); |
| 773 | connector->tile_group = NULL; |
| 774 | } |
| 775 | |
| 776 | list_for_each_entry_safe(mode, t, &connector->probed_modes, head) |
| 777 | drm_mode_remove(connector, mode); |
| 778 | |
| 779 | list_for_each_entry_safe(mode, t, &connector->modes, head) |
| 780 | drm_mode_remove(connector, mode); |
| 781 | |
| 782 | ida_free(&drm_connector_enum_list[connector->connector_type].ida, |
| 783 | id: connector->connector_type_id); |
| 784 | |
| 785 | ida_free(&dev->mode_config.connector_ida, id: connector->index); |
| 786 | |
| 787 | kfree(objp: connector->display_info.bus_formats); |
| 788 | kfree(objp: connector->display_info.vics); |
| 789 | drm_mode_object_unregister(dev, object: &connector->base); |
| 790 | kfree(objp: connector->name); |
| 791 | connector->name = NULL; |
| 792 | fwnode_handle_put(fwnode: connector->fwnode); |
| 793 | connector->fwnode = NULL; |
| 794 | |
| 795 | drm_connector_remove(connector); |
| 796 | |
| 797 | WARN_ON(connector->state && !connector->funcs->atomic_destroy_state); |
| 798 | if (connector->state && connector->funcs->atomic_destroy_state) |
| 799 | connector->funcs->atomic_destroy_state(connector, |
| 800 | connector->state); |
| 801 | |
| 802 | mutex_destroy(lock: &connector->hdmi_audio.lock); |
| 803 | mutex_destroy(lock: &connector->hdmi.infoframes.lock); |
| 804 | mutex_destroy(lock: &connector->mutex); |
| 805 | |
| 806 | memset(connector, 0, sizeof(*connector)); |
| 807 | |
| 808 | if (dev->registered) |
| 809 | drm_sysfs_hotplug_event(dev); |
| 810 | } |
| 811 | EXPORT_SYMBOL(drm_connector_cleanup); |
| 812 | |
| 813 | /** |
| 814 | * drm_connector_register - register a connector |
| 815 | * @connector: the connector to register |
| 816 | * |
| 817 | * Register userspace interfaces for a connector. Drivers shouldn't call this |
| 818 | * function. Static connectors will be registered automatically by DRM core |
| 819 | * from drm_dev_register(), dynamic connectors (MST) should be registered by |
| 820 | * drivers calling drm_connector_dynamic_register(). |
| 821 | * |
| 822 | * When the connector is no longer available, callers must call |
| 823 | * drm_connector_unregister(). |
| 824 | * |
| 825 | * Note: Existing uses of this function in drivers should be a nop already and |
| 826 | * are scheduled to be removed. |
| 827 | * |
| 828 | * Returns: |
| 829 | * Zero on success, error code on failure. |
| 830 | */ |
| 831 | int drm_connector_register(struct drm_connector *connector) |
| 832 | { |
| 833 | int ret = 0; |
| 834 | |
| 835 | if (!connector->dev->registered) |
| 836 | return 0; |
| 837 | |
| 838 | mutex_lock(&connector->mutex); |
| 839 | if (connector->registration_state != DRM_CONNECTOR_INITIALIZING) |
| 840 | goto unlock; |
| 841 | |
| 842 | ret = drm_sysfs_connector_add(connector); |
| 843 | if (ret) |
| 844 | goto unlock; |
| 845 | |
| 846 | drm_debugfs_connector_add(connector); |
| 847 | |
| 848 | if (connector->funcs->late_register) { |
| 849 | ret = connector->funcs->late_register(connector); |
| 850 | if (ret) |
| 851 | goto err_debugfs; |
| 852 | } |
| 853 | |
| 854 | ret = drm_sysfs_connector_add_late(connector); |
| 855 | if (ret) |
| 856 | goto err_late_register; |
| 857 | |
| 858 | drm_mode_object_register(dev: connector->dev, obj: &connector->base); |
| 859 | |
| 860 | connector->registration_state = DRM_CONNECTOR_REGISTERED; |
| 861 | |
| 862 | /* Let userspace know we have a new connector */ |
| 863 | drm_sysfs_connector_hotplug_event(connector); |
| 864 | |
| 865 | if (connector->privacy_screen) |
| 866 | drm_privacy_screen_register_notifier(priv: connector->privacy_screen, |
| 867 | nb: &connector->privacy_screen_notifier); |
| 868 | |
| 869 | mutex_lock(&connector_list_lock); |
| 870 | list_add_tail(new: &connector->global_connector_list_entry, head: &connector_list); |
| 871 | mutex_unlock(lock: &connector_list_lock); |
| 872 | goto unlock; |
| 873 | |
| 874 | err_late_register: |
| 875 | if (connector->funcs->early_unregister) |
| 876 | connector->funcs->early_unregister(connector); |
| 877 | err_debugfs: |
| 878 | drm_debugfs_connector_remove(connector); |
| 879 | drm_sysfs_connector_remove(connector); |
| 880 | unlock: |
| 881 | mutex_unlock(lock: &connector->mutex); |
| 882 | return ret; |
| 883 | } |
| 884 | EXPORT_SYMBOL(drm_connector_register); |
| 885 | |
| 886 | /** |
| 887 | * drm_connector_dynamic_register - register a dynamic connector |
| 888 | * @connector: the connector to register |
| 889 | * |
| 890 | * Register userspace interfaces for a connector. Only call this for connectors |
| 891 | * initialized by calling drm_connector_dynamic_init(). All other connectors |
| 892 | * will be registered automatically when calling drm_dev_register(). |
| 893 | * |
| 894 | * When the connector is no longer available the driver must call |
| 895 | * drm_connector_unregister(). |
| 896 | * |
| 897 | * Returns: |
| 898 | * Zero on success, error code on failure. |
| 899 | */ |
| 900 | int drm_connector_dynamic_register(struct drm_connector *connector) |
| 901 | { |
| 902 | /* Was the connector inited already? */ |
| 903 | if (WARN_ON(!(connector->funcs && connector->funcs->destroy))) |
| 904 | return -EINVAL; |
| 905 | |
| 906 | drm_connector_add(connector); |
| 907 | |
| 908 | return drm_connector_register(connector); |
| 909 | } |
| 910 | EXPORT_SYMBOL(drm_connector_dynamic_register); |
| 911 | |
| 912 | /** |
| 913 | * drm_connector_unregister - unregister a connector |
| 914 | * @connector: the connector to unregister |
| 915 | * |
| 916 | * Unregister userspace interfaces for a connector. Drivers should call this |
| 917 | * for dynamic connectors (MST) only, which were registered explicitly by |
| 918 | * calling drm_connector_dynamic_register(). All other - static - connectors |
| 919 | * will be unregistered automatically by DRM core and drivers shouldn't call |
| 920 | * this function for those. |
| 921 | * |
| 922 | * Note: Existing uses of this function in drivers for static connectors |
| 923 | * should be a nop already and are scheduled to be removed. |
| 924 | */ |
| 925 | void drm_connector_unregister(struct drm_connector *connector) |
| 926 | { |
| 927 | mutex_lock(&connector->mutex); |
| 928 | if (connector->registration_state != DRM_CONNECTOR_REGISTERED) { |
| 929 | mutex_unlock(lock: &connector->mutex); |
| 930 | return; |
| 931 | } |
| 932 | |
| 933 | mutex_lock(&connector_list_lock); |
| 934 | list_del_init(entry: &connector->global_connector_list_entry); |
| 935 | mutex_unlock(lock: &connector_list_lock); |
| 936 | |
| 937 | if (connector->privacy_screen) |
| 938 | drm_privacy_screen_unregister_notifier( |
| 939 | priv: connector->privacy_screen, |
| 940 | nb: &connector->privacy_screen_notifier); |
| 941 | |
| 942 | drm_sysfs_connector_remove_early(connector); |
| 943 | |
| 944 | if (connector->funcs->early_unregister) |
| 945 | connector->funcs->early_unregister(connector); |
| 946 | |
| 947 | drm_debugfs_connector_remove(connector); |
| 948 | drm_sysfs_connector_remove(connector); |
| 949 | |
| 950 | connector->registration_state = DRM_CONNECTOR_UNREGISTERED; |
| 951 | mutex_unlock(lock: &connector->mutex); |
| 952 | } |
| 953 | EXPORT_SYMBOL(drm_connector_unregister); |
| 954 | |
| 955 | void drm_connector_unregister_all(struct drm_device *dev) |
| 956 | { |
| 957 | struct drm_connector *connector; |
| 958 | struct drm_connector_list_iter conn_iter; |
| 959 | |
| 960 | drm_connector_list_iter_begin(dev, iter: &conn_iter); |
| 961 | drm_for_each_connector_iter(connector, &conn_iter) |
| 962 | drm_connector_unregister(connector); |
| 963 | drm_connector_list_iter_end(iter: &conn_iter); |
| 964 | } |
| 965 | |
| 966 | int drm_connector_register_all(struct drm_device *dev) |
| 967 | { |
| 968 | struct drm_connector *connector; |
| 969 | struct drm_connector_list_iter conn_iter; |
| 970 | int ret = 0; |
| 971 | |
| 972 | drm_connector_list_iter_begin(dev, iter: &conn_iter); |
| 973 | drm_for_each_connector_iter(connector, &conn_iter) { |
| 974 | ret = drm_connector_register(connector); |
| 975 | if (ret) |
| 976 | break; |
| 977 | } |
| 978 | drm_connector_list_iter_end(iter: &conn_iter); |
| 979 | |
| 980 | if (ret) |
| 981 | drm_connector_unregister_all(dev); |
| 982 | return ret; |
| 983 | } |
| 984 | |
| 985 | /** |
| 986 | * drm_get_connector_status_name - return a string for connector status |
| 987 | * @status: connector status to compute name of |
| 988 | * |
| 989 | * In contrast to the other drm_get_*_name functions this one here returns a |
| 990 | * const pointer and hence is threadsafe. |
| 991 | * |
| 992 | * Returns: connector status string |
| 993 | */ |
| 994 | const char *drm_get_connector_status_name(enum drm_connector_status status) |
| 995 | { |
| 996 | if (status == connector_status_connected) |
| 997 | return "connected" ; |
| 998 | else if (status == connector_status_disconnected) |
| 999 | return "disconnected" ; |
| 1000 | else |
| 1001 | return "unknown" ; |
| 1002 | } |
| 1003 | EXPORT_SYMBOL(drm_get_connector_status_name); |
| 1004 | |
| 1005 | /** |
| 1006 | * drm_get_connector_force_name - return a string for connector force |
| 1007 | * @force: connector force to get name of |
| 1008 | * |
| 1009 | * Returns: const pointer to name. |
| 1010 | */ |
| 1011 | const char *drm_get_connector_force_name(enum drm_connector_force force) |
| 1012 | { |
| 1013 | switch (force) { |
| 1014 | case DRM_FORCE_UNSPECIFIED: |
| 1015 | return "unspecified" ; |
| 1016 | case DRM_FORCE_OFF: |
| 1017 | return "off" ; |
| 1018 | case DRM_FORCE_ON: |
| 1019 | return "on" ; |
| 1020 | case DRM_FORCE_ON_DIGITAL: |
| 1021 | return "digital" ; |
| 1022 | default: |
| 1023 | return "unknown" ; |
| 1024 | } |
| 1025 | } |
| 1026 | |
| 1027 | #ifdef CONFIG_LOCKDEP |
| 1028 | static struct lockdep_map connector_list_iter_dep_map = { |
| 1029 | .name = "drm_connector_list_iter" |
| 1030 | }; |
| 1031 | #endif |
| 1032 | |
| 1033 | /** |
| 1034 | * drm_connector_list_iter_begin - initialize a connector_list iterator |
| 1035 | * @dev: DRM device |
| 1036 | * @iter: connector_list iterator |
| 1037 | * |
| 1038 | * Sets @iter up to walk the &drm_mode_config.connector_list of @dev. @iter |
| 1039 | * must always be cleaned up again by calling drm_connector_list_iter_end(). |
| 1040 | * Iteration itself happens using drm_connector_list_iter_next() or |
| 1041 | * drm_for_each_connector_iter(). |
| 1042 | */ |
| 1043 | void drm_connector_list_iter_begin(struct drm_device *dev, |
| 1044 | struct drm_connector_list_iter *iter) |
| 1045 | { |
| 1046 | iter->dev = dev; |
| 1047 | iter->conn = NULL; |
| 1048 | lock_acquire_shared_recursive(&connector_list_iter_dep_map, 0, 1, NULL, _RET_IP_); |
| 1049 | } |
| 1050 | EXPORT_SYMBOL(drm_connector_list_iter_begin); |
| 1051 | |
| 1052 | /* |
| 1053 | * Extra-safe connector put function that works in any context. Should only be |
| 1054 | * used from the connector_iter functions, where we never really expect to |
| 1055 | * actually release the connector when dropping our final reference. |
| 1056 | */ |
| 1057 | static void |
| 1058 | __drm_connector_put_safe(struct drm_connector *conn) |
| 1059 | { |
| 1060 | struct drm_mode_config *config = &conn->dev->mode_config; |
| 1061 | |
| 1062 | lockdep_assert_held(&config->connector_list_lock); |
| 1063 | |
| 1064 | if (!refcount_dec_and_test(r: &conn->base.refcount.refcount)) |
| 1065 | return; |
| 1066 | |
| 1067 | llist_add(new: &conn->free_node, head: &config->connector_free_list); |
| 1068 | schedule_work(work: &config->connector_free_work); |
| 1069 | } |
| 1070 | |
| 1071 | /** |
| 1072 | * drm_connector_list_iter_next - return next connector |
| 1073 | * @iter: connector_list iterator |
| 1074 | * |
| 1075 | * Returns: the next connector for @iter, or NULL when the list walk has |
| 1076 | * completed. |
| 1077 | */ |
| 1078 | struct drm_connector * |
| 1079 | drm_connector_list_iter_next(struct drm_connector_list_iter *iter) |
| 1080 | { |
| 1081 | struct drm_connector *old_conn = iter->conn; |
| 1082 | struct drm_mode_config *config = &iter->dev->mode_config; |
| 1083 | struct list_head *lhead; |
| 1084 | unsigned long flags; |
| 1085 | |
| 1086 | spin_lock_irqsave(&config->connector_list_lock, flags); |
| 1087 | lhead = old_conn ? &old_conn->head : &config->connector_list; |
| 1088 | |
| 1089 | do { |
| 1090 | if (lhead->next == &config->connector_list) { |
| 1091 | iter->conn = NULL; |
| 1092 | break; |
| 1093 | } |
| 1094 | |
| 1095 | lhead = lhead->next; |
| 1096 | iter->conn = list_entry(lhead, struct drm_connector, head); |
| 1097 | |
| 1098 | /* loop until it's not a zombie connector */ |
| 1099 | } while (!kref_get_unless_zero(kref: &iter->conn->base.refcount)); |
| 1100 | |
| 1101 | if (old_conn) |
| 1102 | __drm_connector_put_safe(conn: old_conn); |
| 1103 | spin_unlock_irqrestore(lock: &config->connector_list_lock, flags); |
| 1104 | |
| 1105 | return iter->conn; |
| 1106 | } |
| 1107 | EXPORT_SYMBOL(drm_connector_list_iter_next); |
| 1108 | |
| 1109 | /** |
| 1110 | * drm_connector_list_iter_end - tear down a connector_list iterator |
| 1111 | * @iter: connector_list iterator |
| 1112 | * |
| 1113 | * Tears down @iter and releases any resources (like &drm_connector references) |
| 1114 | * acquired while walking the list. This must always be called, both when the |
| 1115 | * iteration completes fully or when it was aborted without walking the entire |
| 1116 | * list. |
| 1117 | */ |
| 1118 | void drm_connector_list_iter_end(struct drm_connector_list_iter *iter) |
| 1119 | { |
| 1120 | struct drm_mode_config *config = &iter->dev->mode_config; |
| 1121 | unsigned long flags; |
| 1122 | |
| 1123 | iter->dev = NULL; |
| 1124 | if (iter->conn) { |
| 1125 | spin_lock_irqsave(&config->connector_list_lock, flags); |
| 1126 | __drm_connector_put_safe(conn: iter->conn); |
| 1127 | spin_unlock_irqrestore(lock: &config->connector_list_lock, flags); |
| 1128 | } |
| 1129 | lock_release(lock: &connector_list_iter_dep_map, _RET_IP_); |
| 1130 | } |
| 1131 | EXPORT_SYMBOL(drm_connector_list_iter_end); |
| 1132 | |
| 1133 | static const struct drm_prop_enum_list drm_subpixel_enum_list[] = { |
| 1134 | { SubPixelUnknown, "Unknown" }, |
| 1135 | { SubPixelHorizontalRGB, "Horizontal RGB" }, |
| 1136 | { SubPixelHorizontalBGR, "Horizontal BGR" }, |
| 1137 | { SubPixelVerticalRGB, "Vertical RGB" }, |
| 1138 | { SubPixelVerticalBGR, "Vertical BGR" }, |
| 1139 | { SubPixelNone, "None" }, |
| 1140 | }; |
| 1141 | |
| 1142 | /** |
| 1143 | * drm_get_subpixel_order_name - return a string for a given subpixel enum |
| 1144 | * @order: enum of subpixel_order |
| 1145 | * |
| 1146 | * Note you could abuse this and return something out of bounds, but that |
| 1147 | * would be a caller error. No unscrubbed user data should make it here. |
| 1148 | * |
| 1149 | * Returns: string describing an enumerated subpixel property |
| 1150 | */ |
| 1151 | const char *drm_get_subpixel_order_name(enum subpixel_order order) |
| 1152 | { |
| 1153 | return drm_subpixel_enum_list[order].name; |
| 1154 | } |
| 1155 | EXPORT_SYMBOL(drm_get_subpixel_order_name); |
| 1156 | |
| 1157 | static const struct drm_prop_enum_list drm_dpms_enum_list[] = { |
| 1158 | { DRM_MODE_DPMS_ON, "On" }, |
| 1159 | { DRM_MODE_DPMS_STANDBY, "Standby" }, |
| 1160 | { DRM_MODE_DPMS_SUSPEND, "Suspend" }, |
| 1161 | { DRM_MODE_DPMS_OFF, "Off" } |
| 1162 | }; |
| 1163 | DRM_ENUM_NAME_FN(drm_get_dpms_name, drm_dpms_enum_list) |
| 1164 | |
| 1165 | static const struct drm_prop_enum_list drm_link_status_enum_list[] = { |
| 1166 | { DRM_MODE_LINK_STATUS_GOOD, "Good" }, |
| 1167 | { DRM_MODE_LINK_STATUS_BAD, "Bad" }, |
| 1168 | }; |
| 1169 | |
| 1170 | /** |
| 1171 | * drm_display_info_set_bus_formats - set the supported bus formats |
| 1172 | * @info: display info to store bus formats in |
| 1173 | * @formats: array containing the supported bus formats |
| 1174 | * @num_formats: the number of entries in the fmts array |
| 1175 | * |
| 1176 | * Store the supported bus formats in display info structure. |
| 1177 | * See MEDIA_BUS_FMT_* definitions in include/uapi/linux/media-bus-format.h for |
| 1178 | * a full list of available formats. |
| 1179 | * |
| 1180 | * Returns: |
| 1181 | * 0 on success or a negative error code on failure. |
| 1182 | */ |
| 1183 | int drm_display_info_set_bus_formats(struct drm_display_info *info, |
| 1184 | const u32 *formats, |
| 1185 | unsigned int num_formats) |
| 1186 | { |
| 1187 | u32 *fmts = NULL; |
| 1188 | |
| 1189 | if (!formats && num_formats) |
| 1190 | return -EINVAL; |
| 1191 | |
| 1192 | if (formats && num_formats) { |
| 1193 | fmts = kmemdup(formats, sizeof(*formats) * num_formats, |
| 1194 | GFP_KERNEL); |
| 1195 | if (!fmts) |
| 1196 | return -ENOMEM; |
| 1197 | } |
| 1198 | |
| 1199 | kfree(objp: info->bus_formats); |
| 1200 | info->bus_formats = fmts; |
| 1201 | info->num_bus_formats = num_formats; |
| 1202 | |
| 1203 | return 0; |
| 1204 | } |
| 1205 | EXPORT_SYMBOL(drm_display_info_set_bus_formats); |
| 1206 | |
| 1207 | /* Optional connector properties. */ |
| 1208 | static const struct drm_prop_enum_list drm_scaling_mode_enum_list[] = { |
| 1209 | { DRM_MODE_SCALE_NONE, "None" }, |
| 1210 | { DRM_MODE_SCALE_FULLSCREEN, "Full" }, |
| 1211 | { DRM_MODE_SCALE_CENTER, "Center" }, |
| 1212 | { DRM_MODE_SCALE_ASPECT, "Full aspect" }, |
| 1213 | }; |
| 1214 | |
| 1215 | static const struct drm_prop_enum_list drm_aspect_ratio_enum_list[] = { |
| 1216 | { DRM_MODE_PICTURE_ASPECT_NONE, "Automatic" }, |
| 1217 | { DRM_MODE_PICTURE_ASPECT_4_3, "4:3" }, |
| 1218 | { DRM_MODE_PICTURE_ASPECT_16_9, "16:9" }, |
| 1219 | }; |
| 1220 | |
| 1221 | static const struct drm_prop_enum_list drm_content_type_enum_list[] = { |
| 1222 | { DRM_MODE_CONTENT_TYPE_NO_DATA, "No Data" }, |
| 1223 | { DRM_MODE_CONTENT_TYPE_GRAPHICS, "Graphics" }, |
| 1224 | { DRM_MODE_CONTENT_TYPE_PHOTO, "Photo" }, |
| 1225 | { DRM_MODE_CONTENT_TYPE_CINEMA, "Cinema" }, |
| 1226 | { DRM_MODE_CONTENT_TYPE_GAME, "Game" }, |
| 1227 | }; |
| 1228 | |
| 1229 | static const struct drm_prop_enum_list drm_panel_orientation_enum_list[] = { |
| 1230 | { DRM_MODE_PANEL_ORIENTATION_NORMAL, "Normal" }, |
| 1231 | { DRM_MODE_PANEL_ORIENTATION_BOTTOM_UP, "Upside Down" }, |
| 1232 | { DRM_MODE_PANEL_ORIENTATION_LEFT_UP, "Left Side Up" }, |
| 1233 | { DRM_MODE_PANEL_ORIENTATION_RIGHT_UP, "Right Side Up" }, |
| 1234 | }; |
| 1235 | |
| 1236 | static const struct drm_prop_enum_list drm_dvi_i_select_enum_list[] = { |
| 1237 | { DRM_MODE_SUBCONNECTOR_Automatic, "Automatic" }, /* DVI-I and TV-out */ |
| 1238 | { DRM_MODE_SUBCONNECTOR_DVID, "DVI-D" }, /* DVI-I */ |
| 1239 | { DRM_MODE_SUBCONNECTOR_DVIA, "DVI-A" }, /* DVI-I */ |
| 1240 | }; |
| 1241 | DRM_ENUM_NAME_FN(drm_get_dvi_i_select_name, drm_dvi_i_select_enum_list) |
| 1242 | |
| 1243 | static const struct drm_prop_enum_list drm_dvi_i_subconnector_enum_list[] = { |
| 1244 | { DRM_MODE_SUBCONNECTOR_Unknown, "Unknown" }, /* DVI-I, TV-out and DP */ |
| 1245 | { DRM_MODE_SUBCONNECTOR_DVID, "DVI-D" }, /* DVI-I */ |
| 1246 | { DRM_MODE_SUBCONNECTOR_DVIA, "DVI-A" }, /* DVI-I */ |
| 1247 | }; |
| 1248 | DRM_ENUM_NAME_FN(drm_get_dvi_i_subconnector_name, |
| 1249 | drm_dvi_i_subconnector_enum_list) |
| 1250 | |
| 1251 | static const struct drm_prop_enum_list drm_tv_mode_enum_list[] = { |
| 1252 | { DRM_MODE_TV_MODE_NTSC, "NTSC" }, |
| 1253 | { DRM_MODE_TV_MODE_NTSC_443, "NTSC-443" }, |
| 1254 | { DRM_MODE_TV_MODE_NTSC_J, "NTSC-J" }, |
| 1255 | { DRM_MODE_TV_MODE_PAL, "PAL" }, |
| 1256 | { DRM_MODE_TV_MODE_PAL_M, "PAL-M" }, |
| 1257 | { DRM_MODE_TV_MODE_PAL_N, "PAL-N" }, |
| 1258 | { DRM_MODE_TV_MODE_SECAM, "SECAM" }, |
| 1259 | { DRM_MODE_TV_MODE_MONOCHROME, "Mono" }, |
| 1260 | }; |
| 1261 | DRM_ENUM_NAME_FN(drm_get_tv_mode_name, drm_tv_mode_enum_list) |
| 1262 | |
| 1263 | /** |
| 1264 | * drm_get_tv_mode_from_name - Translates a TV mode name into its enum value |
| 1265 | * @name: TV Mode name we want to convert |
| 1266 | * @len: Length of @name |
| 1267 | * |
| 1268 | * Translates @name into an enum drm_connector_tv_mode. |
| 1269 | * |
| 1270 | * Returns: the enum value on success, a negative errno otherwise. |
| 1271 | */ |
| 1272 | int drm_get_tv_mode_from_name(const char *name, size_t len) |
| 1273 | { |
| 1274 | unsigned int i; |
| 1275 | |
| 1276 | for (i = 0; i < ARRAY_SIZE(drm_tv_mode_enum_list); i++) { |
| 1277 | const struct drm_prop_enum_list *item = &drm_tv_mode_enum_list[i]; |
| 1278 | |
| 1279 | if (strlen(item->name) == len && !strncmp(item->name, name, len)) |
| 1280 | return item->type; |
| 1281 | } |
| 1282 | |
| 1283 | return -EINVAL; |
| 1284 | } |
| 1285 | EXPORT_SYMBOL(drm_get_tv_mode_from_name); |
| 1286 | |
| 1287 | static const struct drm_prop_enum_list drm_tv_select_enum_list[] = { |
| 1288 | { DRM_MODE_SUBCONNECTOR_Automatic, "Automatic" }, /* DVI-I and TV-out */ |
| 1289 | { DRM_MODE_SUBCONNECTOR_Composite, "Composite" }, /* TV-out */ |
| 1290 | { DRM_MODE_SUBCONNECTOR_SVIDEO, "SVIDEO" }, /* TV-out */ |
| 1291 | { DRM_MODE_SUBCONNECTOR_Component, "Component" }, /* TV-out */ |
| 1292 | { DRM_MODE_SUBCONNECTOR_SCART, "SCART" }, /* TV-out */ |
| 1293 | }; |
| 1294 | DRM_ENUM_NAME_FN(drm_get_tv_select_name, drm_tv_select_enum_list) |
| 1295 | |
| 1296 | static const struct drm_prop_enum_list drm_tv_subconnector_enum_list[] = { |
| 1297 | { DRM_MODE_SUBCONNECTOR_Unknown, "Unknown" }, /* DVI-I, TV-out and DP */ |
| 1298 | { DRM_MODE_SUBCONNECTOR_Composite, "Composite" }, /* TV-out */ |
| 1299 | { DRM_MODE_SUBCONNECTOR_SVIDEO, "SVIDEO" }, /* TV-out */ |
| 1300 | { DRM_MODE_SUBCONNECTOR_Component, "Component" }, /* TV-out */ |
| 1301 | { DRM_MODE_SUBCONNECTOR_SCART, "SCART" }, /* TV-out */ |
| 1302 | }; |
| 1303 | DRM_ENUM_NAME_FN(drm_get_tv_subconnector_name, |
| 1304 | drm_tv_subconnector_enum_list) |
| 1305 | |
| 1306 | static const struct drm_prop_enum_list drm_dp_subconnector_enum_list[] = { |
| 1307 | { DRM_MODE_SUBCONNECTOR_Unknown, "Unknown" }, /* DVI-I, TV-out and DP */ |
| 1308 | { DRM_MODE_SUBCONNECTOR_VGA, "VGA" }, /* DP */ |
| 1309 | { DRM_MODE_SUBCONNECTOR_DVID, "DVI-D" }, /* DP */ |
| 1310 | { DRM_MODE_SUBCONNECTOR_HDMIA, "HDMI" }, /* DP */ |
| 1311 | { DRM_MODE_SUBCONNECTOR_DisplayPort, "DP" }, /* DP */ |
| 1312 | { DRM_MODE_SUBCONNECTOR_Wireless, "Wireless" }, /* DP */ |
| 1313 | { DRM_MODE_SUBCONNECTOR_Native, "Native" }, /* DP */ |
| 1314 | }; |
| 1315 | |
| 1316 | DRM_ENUM_NAME_FN(drm_get_dp_subconnector_name, |
| 1317 | drm_dp_subconnector_enum_list) |
| 1318 | |
| 1319 | |
| 1320 | static const char * const colorspace_names[] = { |
| 1321 | /* For Default case, driver will set the colorspace */ |
| 1322 | [DRM_MODE_COLORIMETRY_DEFAULT] = "Default" , |
| 1323 | /* Standard Definition Colorimetry based on CEA 861 */ |
| 1324 | [DRM_MODE_COLORIMETRY_SMPTE_170M_YCC] = "SMPTE_170M_YCC" , |
| 1325 | [DRM_MODE_COLORIMETRY_BT709_YCC] = "BT709_YCC" , |
| 1326 | /* Standard Definition Colorimetry based on IEC 61966-2-4 */ |
| 1327 | [DRM_MODE_COLORIMETRY_XVYCC_601] = "XVYCC_601" , |
| 1328 | /* High Definition Colorimetry based on IEC 61966-2-4 */ |
| 1329 | [DRM_MODE_COLORIMETRY_XVYCC_709] = "XVYCC_709" , |
| 1330 | /* Colorimetry based on IEC 61966-2-1/Amendment 1 */ |
| 1331 | [DRM_MODE_COLORIMETRY_SYCC_601] = "SYCC_601" , |
| 1332 | /* Colorimetry based on IEC 61966-2-5 [33] */ |
| 1333 | [DRM_MODE_COLORIMETRY_OPYCC_601] = "opYCC_601" , |
| 1334 | /* Colorimetry based on IEC 61966-2-5 */ |
| 1335 | [DRM_MODE_COLORIMETRY_OPRGB] = "opRGB" , |
| 1336 | /* Colorimetry based on ITU-R BT.2020 */ |
| 1337 | [DRM_MODE_COLORIMETRY_BT2020_CYCC] = "BT2020_CYCC" , |
| 1338 | /* Colorimetry based on ITU-R BT.2020 */ |
| 1339 | [DRM_MODE_COLORIMETRY_BT2020_RGB] = "BT2020_RGB" , |
| 1340 | /* Colorimetry based on ITU-R BT.2020 */ |
| 1341 | [DRM_MODE_COLORIMETRY_BT2020_YCC] = "BT2020_YCC" , |
| 1342 | /* Added as part of Additional Colorimetry Extension in 861.G */ |
| 1343 | [DRM_MODE_COLORIMETRY_DCI_P3_RGB_D65] = "DCI-P3_RGB_D65" , |
| 1344 | [DRM_MODE_COLORIMETRY_DCI_P3_RGB_THEATER] = "DCI-P3_RGB_Theater" , |
| 1345 | [DRM_MODE_COLORIMETRY_RGB_WIDE_FIXED] = "RGB_WIDE_FIXED" , |
| 1346 | /* Colorimetry based on scRGB (IEC 61966-2-2) */ |
| 1347 | [DRM_MODE_COLORIMETRY_RGB_WIDE_FLOAT] = "RGB_WIDE_FLOAT" , |
| 1348 | [DRM_MODE_COLORIMETRY_BT601_YCC] = "BT601_YCC" , |
| 1349 | }; |
| 1350 | |
| 1351 | /** |
| 1352 | * drm_get_colorspace_name - return a string for color encoding |
| 1353 | * @colorspace: color space to compute name of |
| 1354 | * |
| 1355 | * In contrast to the other drm_get_*_name functions this one here returns a |
| 1356 | * const pointer and hence is threadsafe. |
| 1357 | */ |
| 1358 | const char *drm_get_colorspace_name(enum drm_colorspace colorspace) |
| 1359 | { |
| 1360 | if (colorspace < ARRAY_SIZE(colorspace_names) && colorspace_names[colorspace]) |
| 1361 | return colorspace_names[colorspace]; |
| 1362 | else |
| 1363 | return "(null)" ; |
| 1364 | } |
| 1365 | |
| 1366 | static const u32 hdmi_colorspaces = |
| 1367 | BIT(DRM_MODE_COLORIMETRY_SMPTE_170M_YCC) | |
| 1368 | BIT(DRM_MODE_COLORIMETRY_BT709_YCC) | |
| 1369 | BIT(DRM_MODE_COLORIMETRY_XVYCC_601) | |
| 1370 | BIT(DRM_MODE_COLORIMETRY_XVYCC_709) | |
| 1371 | BIT(DRM_MODE_COLORIMETRY_SYCC_601) | |
| 1372 | BIT(DRM_MODE_COLORIMETRY_OPYCC_601) | |
| 1373 | BIT(DRM_MODE_COLORIMETRY_OPRGB) | |
| 1374 | BIT(DRM_MODE_COLORIMETRY_BT2020_CYCC) | |
| 1375 | BIT(DRM_MODE_COLORIMETRY_BT2020_RGB) | |
| 1376 | BIT(DRM_MODE_COLORIMETRY_BT2020_YCC) | |
| 1377 | BIT(DRM_MODE_COLORIMETRY_DCI_P3_RGB_D65) | |
| 1378 | BIT(DRM_MODE_COLORIMETRY_DCI_P3_RGB_THEATER); |
| 1379 | |
| 1380 | /* |
| 1381 | * As per DP 1.4a spec, 2.2.5.7.5 VSC SDP Payload for Pixel Encoding/Colorimetry |
| 1382 | * Format Table 2-120 |
| 1383 | */ |
| 1384 | static const u32 dp_colorspaces = |
| 1385 | BIT(DRM_MODE_COLORIMETRY_RGB_WIDE_FIXED) | |
| 1386 | BIT(DRM_MODE_COLORIMETRY_RGB_WIDE_FLOAT) | |
| 1387 | BIT(DRM_MODE_COLORIMETRY_OPRGB) | |
| 1388 | BIT(DRM_MODE_COLORIMETRY_DCI_P3_RGB_D65) | |
| 1389 | BIT(DRM_MODE_COLORIMETRY_BT2020_RGB) | |
| 1390 | BIT(DRM_MODE_COLORIMETRY_BT601_YCC) | |
| 1391 | BIT(DRM_MODE_COLORIMETRY_BT709_YCC) | |
| 1392 | BIT(DRM_MODE_COLORIMETRY_XVYCC_601) | |
| 1393 | BIT(DRM_MODE_COLORIMETRY_XVYCC_709) | |
| 1394 | BIT(DRM_MODE_COLORIMETRY_SYCC_601) | |
| 1395 | BIT(DRM_MODE_COLORIMETRY_OPYCC_601) | |
| 1396 | BIT(DRM_MODE_COLORIMETRY_BT2020_CYCC) | |
| 1397 | BIT(DRM_MODE_COLORIMETRY_BT2020_YCC); |
| 1398 | |
| 1399 | static const struct drm_prop_enum_list broadcast_rgb_names[] = { |
| 1400 | { DRM_HDMI_BROADCAST_RGB_AUTO, "Automatic" }, |
| 1401 | { DRM_HDMI_BROADCAST_RGB_FULL, "Full" }, |
| 1402 | { DRM_HDMI_BROADCAST_RGB_LIMITED, "Limited 16:235" }, |
| 1403 | }; |
| 1404 | |
| 1405 | /* |
| 1406 | * drm_hdmi_connector_get_broadcast_rgb_name - Return a string for HDMI connector RGB broadcast selection |
| 1407 | * @broadcast_rgb: Broadcast RGB selection to compute name of |
| 1408 | * |
| 1409 | * Returns: the name of the Broadcast RGB selection, or NULL if the type |
| 1410 | * is not valid. |
| 1411 | */ |
| 1412 | const char * |
| 1413 | drm_hdmi_connector_get_broadcast_rgb_name(enum drm_hdmi_broadcast_rgb broadcast_rgb) |
| 1414 | { |
| 1415 | if (broadcast_rgb >= ARRAY_SIZE(broadcast_rgb_names)) |
| 1416 | return NULL; |
| 1417 | |
| 1418 | return broadcast_rgb_names[broadcast_rgb].name; |
| 1419 | } |
| 1420 | EXPORT_SYMBOL(drm_hdmi_connector_get_broadcast_rgb_name); |
| 1421 | |
| 1422 | static const char * const output_format_str[] = { |
| 1423 | [HDMI_COLORSPACE_RGB] = "RGB" , |
| 1424 | [HDMI_COLORSPACE_YUV420] = "YUV 4:2:0" , |
| 1425 | [HDMI_COLORSPACE_YUV422] = "YUV 4:2:2" , |
| 1426 | [HDMI_COLORSPACE_YUV444] = "YUV 4:4:4" , |
| 1427 | }; |
| 1428 | |
| 1429 | /* |
| 1430 | * drm_hdmi_connector_get_output_format_name() - Return a string for HDMI connector output format |
| 1431 | * @fmt: Output format to compute name of |
| 1432 | * |
| 1433 | * Returns: the name of the output format, or NULL if the type is not |
| 1434 | * valid. |
| 1435 | */ |
| 1436 | const char * |
| 1437 | drm_hdmi_connector_get_output_format_name(enum hdmi_colorspace fmt) |
| 1438 | { |
| 1439 | if (fmt >= ARRAY_SIZE(output_format_str)) |
| 1440 | return NULL; |
| 1441 | |
| 1442 | return output_format_str[fmt]; |
| 1443 | } |
| 1444 | EXPORT_SYMBOL(drm_hdmi_connector_get_output_format_name); |
| 1445 | |
| 1446 | /** |
| 1447 | * DOC: standard connector properties |
| 1448 | * |
| 1449 | * DRM connectors have a few standardized properties: |
| 1450 | * |
| 1451 | * EDID: |
| 1452 | * Blob property which contains the current EDID read from the sink. This |
| 1453 | * is useful to parse sink identification information like vendor, model |
| 1454 | * and serial. Drivers should update this property by calling |
| 1455 | * drm_connector_update_edid_property(), usually after having parsed |
| 1456 | * the EDID using drm_add_edid_modes(). Userspace cannot change this |
| 1457 | * property. |
| 1458 | * |
| 1459 | * User-space should not parse the EDID to obtain information exposed via |
| 1460 | * other KMS properties (because the kernel might apply limits, quirks or |
| 1461 | * fixups to the EDID). For instance, user-space should not try to parse |
| 1462 | * mode lists from the EDID. |
| 1463 | * DPMS: |
| 1464 | * Legacy property for setting the power state of the connector. For atomic |
| 1465 | * drivers this is only provided for backwards compatibility with existing |
| 1466 | * drivers, it remaps to controlling the "ACTIVE" property on the CRTC the |
| 1467 | * connector is linked to. Drivers should never set this property directly, |
| 1468 | * it is handled by the DRM core by calling the &drm_connector_funcs.dpms |
| 1469 | * callback. For atomic drivers the remapping to the "ACTIVE" property is |
| 1470 | * implemented in the DRM core. |
| 1471 | * |
| 1472 | * On atomic drivers any DPMS setproperty ioctl where the value does not |
| 1473 | * change is completely skipped, otherwise a full atomic commit will occur. |
| 1474 | * On legacy drivers the exact behavior is driver specific. |
| 1475 | * |
| 1476 | * Note that this property cannot be set through the MODE_ATOMIC ioctl, |
| 1477 | * userspace must use "ACTIVE" on the CRTC instead. |
| 1478 | * |
| 1479 | * WARNING: |
| 1480 | * |
| 1481 | * For userspace also running on legacy drivers the "DPMS" semantics are a |
| 1482 | * lot more complicated. First, userspace cannot rely on the "DPMS" value |
| 1483 | * returned by the GETCONNECTOR actually reflecting reality, because many |
| 1484 | * drivers fail to update it. For atomic drivers this is taken care of in |
| 1485 | * drm_atomic_helper_update_legacy_modeset_state(). |
| 1486 | * |
| 1487 | * The second issue is that the DPMS state is only well-defined when the |
| 1488 | * connector is connected to a CRTC. In atomic the DRM core enforces that |
| 1489 | * "ACTIVE" is off in such a case, no such checks exists for "DPMS". |
| 1490 | * |
| 1491 | * Finally, when enabling an output using the legacy SETCONFIG ioctl then |
| 1492 | * "DPMS" is forced to ON. But see above, that might not be reflected in |
| 1493 | * the software value on legacy drivers. |
| 1494 | * |
| 1495 | * Summarizing: Only set "DPMS" when the connector is known to be enabled, |
| 1496 | * assume that a successful SETCONFIG call also sets "DPMS" to on, and |
| 1497 | * never read back the value of "DPMS" because it can be incorrect. |
| 1498 | * PATH: |
| 1499 | * Connector path property to identify how this sink is physically |
| 1500 | * connected. Used by DP MST. This should be set by calling |
| 1501 | * drm_connector_set_path_property(), in the case of DP MST with the |
| 1502 | * path property the MST manager created. Userspace cannot change this |
| 1503 | * property. |
| 1504 | * |
| 1505 | * In the case of DP MST, the property has the format |
| 1506 | * ``mst:<parent>-<ports>`` where ``<parent>`` is the KMS object ID of the |
| 1507 | * parent connector and ``<ports>`` is a hyphen-separated list of DP MST |
| 1508 | * port numbers. Note, KMS object IDs are not guaranteed to be stable |
| 1509 | * across reboots. |
| 1510 | * TILE: |
| 1511 | * Connector tile group property to indicate how a set of DRM connector |
| 1512 | * compose together into one logical screen. This is used by both high-res |
| 1513 | * external screens (often only using a single cable, but exposing multiple |
| 1514 | * DP MST sinks), or high-res integrated panels (like dual-link DSI) which |
| 1515 | * are not gen-locked. Note that for tiled panels which are genlocked, like |
| 1516 | * dual-link LVDS or dual-link DSI, the driver should try to not expose the |
| 1517 | * tiling and virtualise both &drm_crtc and &drm_plane if needed. Drivers |
| 1518 | * should update this value using drm_connector_set_tile_property(). |
| 1519 | * Userspace cannot change this property. |
| 1520 | * link-status: |
| 1521 | * Connector link-status property to indicate the status of link. The |
| 1522 | * default value of link-status is "GOOD". If something fails during or |
| 1523 | * after modeset, the kernel driver may set this to "BAD" and issue a |
| 1524 | * hotplug uevent. Drivers should update this value using |
| 1525 | * drm_connector_set_link_status_property(). |
| 1526 | * |
| 1527 | * When user-space receives the hotplug uevent and detects a "BAD" |
| 1528 | * link-status, the sink doesn't receive pixels anymore (e.g. the screen |
| 1529 | * becomes completely black). The list of available modes may have |
| 1530 | * changed. User-space is expected to pick a new mode if the current one |
| 1531 | * has disappeared and perform a new modeset with link-status set to |
| 1532 | * "GOOD" to re-enable the connector. |
| 1533 | * |
| 1534 | * If multiple connectors share the same CRTC and one of them gets a "BAD" |
| 1535 | * link-status, the other are unaffected (ie. the sinks still continue to |
| 1536 | * receive pixels). |
| 1537 | * |
| 1538 | * When user-space performs an atomic commit on a connector with a "BAD" |
| 1539 | * link-status without resetting the property to "GOOD", the sink may |
| 1540 | * still not receive pixels. When user-space performs an atomic commit |
| 1541 | * which resets the link-status property to "GOOD" without the |
| 1542 | * ALLOW_MODESET flag set, it might fail because a modeset is required. |
| 1543 | * |
| 1544 | * User-space can only change link-status to "GOOD", changing it to "BAD" |
| 1545 | * is a no-op. |
| 1546 | * |
| 1547 | * For backwards compatibility with non-atomic userspace the kernel |
| 1548 | * tries to automatically set the link-status back to "GOOD" in the |
| 1549 | * SETCRTC IOCTL. This might fail if the mode is no longer valid, similar |
| 1550 | * to how it might fail if a different screen has been connected in the |
| 1551 | * interim. |
| 1552 | * non_desktop: |
| 1553 | * Indicates the output should be ignored for purposes of displaying a |
| 1554 | * standard desktop environment or console. This is most likely because |
| 1555 | * the output device is not rectilinear. |
| 1556 | * Content Protection: |
| 1557 | * This property is used by userspace to request the kernel protect future |
| 1558 | * content communicated over the link. When requested, kernel will apply |
| 1559 | * the appropriate means of protection (most often HDCP), and use the |
| 1560 | * property to tell userspace the protection is active. |
| 1561 | * |
| 1562 | * Drivers can set this up by calling |
| 1563 | * drm_connector_attach_content_protection_property() on initialization. |
| 1564 | * |
| 1565 | * The value of this property can be one of the following: |
| 1566 | * |
| 1567 | * DRM_MODE_CONTENT_PROTECTION_UNDESIRED = 0 |
| 1568 | * The link is not protected, content is transmitted in the clear. |
| 1569 | * DRM_MODE_CONTENT_PROTECTION_DESIRED = 1 |
| 1570 | * Userspace has requested content protection, but the link is not |
| 1571 | * currently protected. When in this state, kernel should enable |
| 1572 | * Content Protection as soon as possible. |
| 1573 | * DRM_MODE_CONTENT_PROTECTION_ENABLED = 2 |
| 1574 | * Userspace has requested content protection, and the link is |
| 1575 | * protected. Only the driver can set the property to this value. |
| 1576 | * If userspace attempts to set to ENABLED, kernel will return |
| 1577 | * -EINVAL. |
| 1578 | * |
| 1579 | * A few guidelines: |
| 1580 | * |
| 1581 | * - DESIRED state should be preserved until userspace de-asserts it by |
| 1582 | * setting the property to UNDESIRED. This means ENABLED should only |
| 1583 | * transition to UNDESIRED when the user explicitly requests it. |
| 1584 | * - If the state is DESIRED, kernel should attempt to re-authenticate the |
| 1585 | * link whenever possible. This includes across disable/enable, dpms, |
| 1586 | * hotplug, downstream device changes, link status failures, etc.. |
| 1587 | * - Kernel sends uevent with the connector id and property id through |
| 1588 | * @drm_hdcp_update_content_protection, upon below kernel triggered |
| 1589 | * scenarios: |
| 1590 | * |
| 1591 | * - DESIRED -> ENABLED (authentication success) |
| 1592 | * - ENABLED -> DESIRED (termination of authentication) |
| 1593 | * - Please note no uevents for userspace triggered property state changes, |
| 1594 | * which can't fail such as |
| 1595 | * |
| 1596 | * - DESIRED/ENABLED -> UNDESIRED |
| 1597 | * - UNDESIRED -> DESIRED |
| 1598 | * - Userspace is responsible for polling the property or listen to uevents |
| 1599 | * to determine when the value transitions from ENABLED to DESIRED. |
| 1600 | * This signifies the link is no longer protected and userspace should |
| 1601 | * take appropriate action (whatever that might be). |
| 1602 | * |
| 1603 | * HDCP Content Type: |
| 1604 | * This Enum property is used by the userspace to declare the content type |
| 1605 | * of the display stream, to kernel. Here display stream stands for any |
| 1606 | * display content that userspace intended to display through HDCP |
| 1607 | * encryption. |
| 1608 | * |
| 1609 | * Content Type of a stream is decided by the owner of the stream, as |
| 1610 | * "HDCP Type0" or "HDCP Type1". |
| 1611 | * |
| 1612 | * The value of the property can be one of the below: |
| 1613 | * - "HDCP Type0": DRM_MODE_HDCP_CONTENT_TYPE0 = 0 |
| 1614 | * - "HDCP Type1": DRM_MODE_HDCP_CONTENT_TYPE1 = 1 |
| 1615 | * |
| 1616 | * When kernel starts the HDCP authentication (see "Content Protection" |
| 1617 | * for details), it uses the content type in "HDCP Content Type" |
| 1618 | * for performing the HDCP authentication with the display sink. |
| 1619 | * |
| 1620 | * Please note in HDCP spec versions, a link can be authenticated with |
| 1621 | * HDCP 2.2 for Content Type 0/Content Type 1. Where as a link can be |
| 1622 | * authenticated with HDCP1.4 only for Content Type 0(though it is implicit |
| 1623 | * in nature. As there is no reference for Content Type in HDCP1.4). |
| 1624 | * |
| 1625 | * HDCP2.2 authentication protocol itself takes the "Content Type" as a |
| 1626 | * parameter, which is a input for the DP HDCP2.2 encryption algo. |
| 1627 | * |
| 1628 | * In case of Type 0 content protection request, kernel driver can choose |
| 1629 | * either of HDCP spec versions 1.4 and 2.2. When HDCP2.2 is used for |
| 1630 | * "HDCP Type 0", a HDCP 2.2 capable repeater in the downstream can send |
| 1631 | * that content to a HDCP 1.4 authenticated HDCP sink (Type0 link). |
| 1632 | * But if the content is classified as "HDCP Type 1", above mentioned |
| 1633 | * HDCP 2.2 repeater wont send the content to the HDCP sink as it can't |
| 1634 | * authenticate the HDCP1.4 capable sink for "HDCP Type 1". |
| 1635 | * |
| 1636 | * Please note userspace can be ignorant of the HDCP versions used by the |
| 1637 | * kernel driver to achieve the "HDCP Content Type". |
| 1638 | * |
| 1639 | * At current scenario, classifying a content as Type 1 ensures that the |
| 1640 | * content will be displayed only through the HDCP2.2 encrypted link. |
| 1641 | * |
| 1642 | * Note that the HDCP Content Type property is introduced at HDCP 2.2, and |
| 1643 | * defaults to type 0. It is only exposed by drivers supporting HDCP 2.2 |
| 1644 | * (hence supporting Type 0 and Type 1). Based on how next versions of |
| 1645 | * HDCP specs are defined content Type could be used for higher versions |
| 1646 | * too. |
| 1647 | * |
| 1648 | * If content type is changed when "Content Protection" is not UNDESIRED, |
| 1649 | * then kernel will disable the HDCP and re-enable with new type in the |
| 1650 | * same atomic commit. And when "Content Protection" is ENABLED, it means |
| 1651 | * that link is HDCP authenticated and encrypted, for the transmission of |
| 1652 | * the Type of stream mentioned at "HDCP Content Type". |
| 1653 | * |
| 1654 | * HDR_OUTPUT_METADATA: |
| 1655 | * Connector property to enable userspace to send HDR Metadata to |
| 1656 | * driver. This metadata is based on the composition and blending |
| 1657 | * policies decided by user, taking into account the hardware and |
| 1658 | * sink capabilities. The driver gets this metadata and creates a |
| 1659 | * Dynamic Range and Mastering Infoframe (DRM) in case of HDMI, |
| 1660 | * SDP packet (Non-audio INFOFRAME SDP v1.3) for DP. This is then |
| 1661 | * sent to sink. This notifies the sink of the upcoming frame's Color |
| 1662 | * Encoding and Luminance parameters. |
| 1663 | * |
| 1664 | * Userspace first need to detect the HDR capabilities of sink by |
| 1665 | * reading and parsing the EDID. Details of HDR metadata for HDMI |
| 1666 | * are added in CTA 861.G spec. For DP , its defined in VESA DP |
| 1667 | * Standard v1.4. It needs to then get the metadata information |
| 1668 | * of the video/game/app content which are encoded in HDR (basically |
| 1669 | * using HDR transfer functions). With this information it needs to |
| 1670 | * decide on a blending policy and compose the relevant |
| 1671 | * layers/overlays into a common format. Once this blending is done, |
| 1672 | * userspace will be aware of the metadata of the composed frame to |
| 1673 | * be send to sink. It then uses this property to communicate this |
| 1674 | * metadata to driver which then make a Infoframe packet and sends |
| 1675 | * to sink based on the type of encoder connected. |
| 1676 | * |
| 1677 | * Userspace will be responsible to do Tone mapping operation in case: |
| 1678 | * - Some layers are HDR and others are SDR |
| 1679 | * - HDR layers luminance is not same as sink |
| 1680 | * |
| 1681 | * It will even need to do colorspace conversion and get all layers |
| 1682 | * to one common colorspace for blending. It can use either GL, Media |
| 1683 | * or display engine to get this done based on the capabilities of the |
| 1684 | * associated hardware. |
| 1685 | * |
| 1686 | * Driver expects metadata to be put in &struct hdr_output_metadata |
| 1687 | * structure from userspace. This is received as blob and stored in |
| 1688 | * &drm_connector_state.hdr_output_metadata. It parses EDID and saves the |
| 1689 | * sink metadata in &struct hdr_sink_metadata, as |
| 1690 | * &drm_connector.display_info.hdr_sink_metadata. Driver uses |
| 1691 | * drm_hdmi_infoframe_set_hdr_metadata() helper to set the HDR metadata, |
| 1692 | * hdmi_drm_infoframe_pack() to pack the infoframe as per spec, in case of |
| 1693 | * HDMI encoder. |
| 1694 | * |
| 1695 | * max bpc: |
| 1696 | * This range property is used by userspace to limit the bit depth. When |
| 1697 | * used the driver would limit the bpc in accordance with the valid range |
| 1698 | * supported by the hardware and sink. Drivers to use the function |
| 1699 | * drm_connector_attach_max_bpc_property() to create and attach the |
| 1700 | * property to the connector during initialization. |
| 1701 | * |
| 1702 | * Connectors also have one standardized atomic property: |
| 1703 | * |
| 1704 | * CRTC_ID: |
| 1705 | * Mode object ID of the &drm_crtc this connector should be connected to. |
| 1706 | * |
| 1707 | * Connectors for LCD panels may also have one standardized property: |
| 1708 | * |
| 1709 | * panel orientation: |
| 1710 | * On some devices the LCD panel is mounted in the casing in such a way |
| 1711 | * that the up/top side of the panel does not match with the top side of |
| 1712 | * the device. Userspace can use this property to check for this. |
| 1713 | * Note that input coordinates from touchscreens (input devices with |
| 1714 | * INPUT_PROP_DIRECT) will still map 1:1 to the actual LCD panel |
| 1715 | * coordinates, so if userspace rotates the picture to adjust for |
| 1716 | * the orientation it must also apply the same transformation to the |
| 1717 | * touchscreen input coordinates. This property is initialized by calling |
| 1718 | * drm_connector_set_panel_orientation() or |
| 1719 | * drm_connector_set_panel_orientation_with_quirk() |
| 1720 | * |
| 1721 | * scaling mode: |
| 1722 | * This property defines how a non-native mode is upscaled to the native |
| 1723 | * mode of an LCD panel: |
| 1724 | * |
| 1725 | * None: |
| 1726 | * No upscaling happens, scaling is left to the panel. Not all |
| 1727 | * drivers expose this mode. |
| 1728 | * Full: |
| 1729 | * The output is upscaled to the full resolution of the panel, |
| 1730 | * ignoring the aspect ratio. |
| 1731 | * Center: |
| 1732 | * No upscaling happens, the output is centered within the native |
| 1733 | * resolution the panel. |
| 1734 | * Full aspect: |
| 1735 | * The output is upscaled to maximize either the width or height |
| 1736 | * while retaining the aspect ratio. |
| 1737 | * |
| 1738 | * This property should be set up by calling |
| 1739 | * drm_connector_attach_scaling_mode_property(). Note that drivers |
| 1740 | * can also expose this property to external outputs, in which case they |
| 1741 | * must support "None", which should be the default (since external screens |
| 1742 | * have a built-in scaler). |
| 1743 | * |
| 1744 | * subconnector: |
| 1745 | * This property is used by DVI-I, TVout and DisplayPort to indicate different |
| 1746 | * connector subtypes. Enum values more or less match with those from main |
| 1747 | * connector types. |
| 1748 | * For DVI-I and TVout there is also a matching property "select subconnector" |
| 1749 | * allowing to switch between signal types. |
| 1750 | * DP subconnector corresponds to a downstream port. |
| 1751 | * |
| 1752 | * privacy-screen sw-state, privacy-screen hw-state: |
| 1753 | * These 2 optional properties can be used to query the state of the |
| 1754 | * electronic privacy screen that is available on some displays; and in |
| 1755 | * some cases also control the state. If a driver implements these |
| 1756 | * properties then both properties must be present. |
| 1757 | * |
| 1758 | * "privacy-screen hw-state" is read-only and reflects the actual state |
| 1759 | * of the privacy-screen, possible values: "Enabled", "Disabled, |
| 1760 | * "Enabled-locked", "Disabled-locked". The locked states indicate |
| 1761 | * that the state cannot be changed through the DRM API. E.g. there |
| 1762 | * might be devices where the firmware-setup options, or a hardware |
| 1763 | * slider-switch, offer always on / off modes. |
| 1764 | * |
| 1765 | * "privacy-screen sw-state" can be set to change the privacy-screen state |
| 1766 | * when not locked. In this case the driver must update the hw-state |
| 1767 | * property to reflect the new state on completion of the commit of the |
| 1768 | * sw-state property. Setting the sw-state property when the hw-state is |
| 1769 | * locked must be interpreted by the driver as a request to change the |
| 1770 | * state to the set state when the hw-state becomes unlocked. E.g. if |
| 1771 | * "privacy-screen hw-state" is "Enabled-locked" and the sw-state |
| 1772 | * gets set to "Disabled" followed by the user unlocking the state by |
| 1773 | * changing the slider-switch position, then the driver must set the |
| 1774 | * state to "Disabled" upon receiving the unlock event. |
| 1775 | * |
| 1776 | * In some cases the privacy-screen's actual state might change outside of |
| 1777 | * control of the DRM code. E.g. there might be a firmware handled hotkey |
| 1778 | * which toggles the actual state, or the actual state might be changed |
| 1779 | * through another userspace API such as writing /proc/acpi/ibm/lcdshadow. |
| 1780 | * In this case the driver must update both the hw-state and the sw-state |
| 1781 | * to reflect the new value, overwriting any pending state requests in the |
| 1782 | * sw-state. Any pending sw-state requests are thus discarded. |
| 1783 | * |
| 1784 | * Note that the ability for the state to change outside of control of |
| 1785 | * the DRM master process means that userspace must not cache the value |
| 1786 | * of the sw-state. Caching the sw-state value and including it in later |
| 1787 | * atomic commits may lead to overriding a state change done through e.g. |
| 1788 | * a firmware handled hotkey. Therefor userspace must not include the |
| 1789 | * privacy-screen sw-state in an atomic commit unless it wants to change |
| 1790 | * its value. |
| 1791 | * |
| 1792 | * left margin, right margin, top margin, bottom margin: |
| 1793 | * Add margins to the connector's viewport. This is typically used to |
| 1794 | * mitigate overscan on TVs. |
| 1795 | * |
| 1796 | * The value is the size in pixels of the black border which will be |
| 1797 | * added. The attached CRTC's content will be scaled to fill the whole |
| 1798 | * area inside the margin. |
| 1799 | * |
| 1800 | * The margins configuration might be sent to the sink, e.g. via HDMI AVI |
| 1801 | * InfoFrames. |
| 1802 | * |
| 1803 | * Drivers can set up these properties by calling |
| 1804 | * drm_mode_create_tv_margin_properties(). |
| 1805 | */ |
| 1806 | |
| 1807 | int drm_connector_create_standard_properties(struct drm_device *dev) |
| 1808 | { |
| 1809 | struct drm_property *prop; |
| 1810 | |
| 1811 | prop = drm_property_create(dev, DRM_MODE_PROP_BLOB | |
| 1812 | DRM_MODE_PROP_IMMUTABLE, |
| 1813 | name: "EDID" , num_values: 0); |
| 1814 | if (!prop) |
| 1815 | return -ENOMEM; |
| 1816 | dev->mode_config.edid_property = prop; |
| 1817 | |
| 1818 | prop = drm_property_create_enum(dev, flags: 0, |
| 1819 | name: "DPMS" , props: drm_dpms_enum_list, |
| 1820 | ARRAY_SIZE(drm_dpms_enum_list)); |
| 1821 | if (!prop) |
| 1822 | return -ENOMEM; |
| 1823 | dev->mode_config.dpms_property = prop; |
| 1824 | |
| 1825 | prop = drm_property_create(dev, |
| 1826 | DRM_MODE_PROP_BLOB | |
| 1827 | DRM_MODE_PROP_IMMUTABLE, |
| 1828 | name: "PATH" , num_values: 0); |
| 1829 | if (!prop) |
| 1830 | return -ENOMEM; |
| 1831 | dev->mode_config.path_property = prop; |
| 1832 | |
| 1833 | prop = drm_property_create(dev, |
| 1834 | DRM_MODE_PROP_BLOB | |
| 1835 | DRM_MODE_PROP_IMMUTABLE, |
| 1836 | name: "TILE" , num_values: 0); |
| 1837 | if (!prop) |
| 1838 | return -ENOMEM; |
| 1839 | dev->mode_config.tile_property = prop; |
| 1840 | |
| 1841 | prop = drm_property_create_enum(dev, flags: 0, name: "link-status" , |
| 1842 | props: drm_link_status_enum_list, |
| 1843 | ARRAY_SIZE(drm_link_status_enum_list)); |
| 1844 | if (!prop) |
| 1845 | return -ENOMEM; |
| 1846 | dev->mode_config.link_status_property = prop; |
| 1847 | |
| 1848 | prop = drm_property_create_bool(dev, DRM_MODE_PROP_IMMUTABLE, name: "non-desktop" ); |
| 1849 | if (!prop) |
| 1850 | return -ENOMEM; |
| 1851 | dev->mode_config.non_desktop_property = prop; |
| 1852 | |
| 1853 | prop = drm_property_create(dev, DRM_MODE_PROP_BLOB, |
| 1854 | name: "HDR_OUTPUT_METADATA" , num_values: 0); |
| 1855 | if (!prop) |
| 1856 | return -ENOMEM; |
| 1857 | dev->mode_config.hdr_output_metadata_property = prop; |
| 1858 | |
| 1859 | return 0; |
| 1860 | } |
| 1861 | |
| 1862 | /** |
| 1863 | * drm_mode_create_dvi_i_properties - create DVI-I specific connector properties |
| 1864 | * @dev: DRM device |
| 1865 | * |
| 1866 | * Called by a driver the first time a DVI-I connector is made. |
| 1867 | * |
| 1868 | * Returns: %0 |
| 1869 | */ |
| 1870 | int drm_mode_create_dvi_i_properties(struct drm_device *dev) |
| 1871 | { |
| 1872 | struct drm_property *dvi_i_selector; |
| 1873 | struct drm_property *dvi_i_subconnector; |
| 1874 | |
| 1875 | if (dev->mode_config.dvi_i_select_subconnector_property) |
| 1876 | return 0; |
| 1877 | |
| 1878 | dvi_i_selector = |
| 1879 | drm_property_create_enum(dev, flags: 0, |
| 1880 | name: "select subconnector" , |
| 1881 | props: drm_dvi_i_select_enum_list, |
| 1882 | ARRAY_SIZE(drm_dvi_i_select_enum_list)); |
| 1883 | dev->mode_config.dvi_i_select_subconnector_property = dvi_i_selector; |
| 1884 | |
| 1885 | dvi_i_subconnector = drm_property_create_enum(dev, DRM_MODE_PROP_IMMUTABLE, |
| 1886 | name: "subconnector" , |
| 1887 | props: drm_dvi_i_subconnector_enum_list, |
| 1888 | ARRAY_SIZE(drm_dvi_i_subconnector_enum_list)); |
| 1889 | dev->mode_config.dvi_i_subconnector_property = dvi_i_subconnector; |
| 1890 | |
| 1891 | return 0; |
| 1892 | } |
| 1893 | EXPORT_SYMBOL(drm_mode_create_dvi_i_properties); |
| 1894 | |
| 1895 | /** |
| 1896 | * drm_connector_attach_dp_subconnector_property - create subconnector property for DP |
| 1897 | * @connector: drm_connector to attach property |
| 1898 | * |
| 1899 | * Called by a driver when DP connector is created. |
| 1900 | */ |
| 1901 | void drm_connector_attach_dp_subconnector_property(struct drm_connector *connector) |
| 1902 | { |
| 1903 | struct drm_mode_config *mode_config = &connector->dev->mode_config; |
| 1904 | |
| 1905 | if (!mode_config->dp_subconnector_property) |
| 1906 | mode_config->dp_subconnector_property = |
| 1907 | drm_property_create_enum(dev: connector->dev, |
| 1908 | DRM_MODE_PROP_IMMUTABLE, |
| 1909 | name: "subconnector" , |
| 1910 | props: drm_dp_subconnector_enum_list, |
| 1911 | ARRAY_SIZE(drm_dp_subconnector_enum_list)); |
| 1912 | |
| 1913 | drm_object_attach_property(obj: &connector->base, |
| 1914 | property: mode_config->dp_subconnector_property, |
| 1915 | init_val: DRM_MODE_SUBCONNECTOR_Unknown); |
| 1916 | } |
| 1917 | EXPORT_SYMBOL(drm_connector_attach_dp_subconnector_property); |
| 1918 | |
| 1919 | /** |
| 1920 | * DOC: HDMI connector properties |
| 1921 | * |
| 1922 | * Broadcast RGB (HDMI specific) |
| 1923 | * Indicates the Quantization Range (Full vs Limited) used. The color |
| 1924 | * processing pipeline will be adjusted to match the value of the |
| 1925 | * property, and the Infoframes will be generated and sent accordingly. |
| 1926 | * |
| 1927 | * This property is only relevant if the HDMI output format is RGB. If |
| 1928 | * it's one of the YCbCr variant, it will be ignored. |
| 1929 | * |
| 1930 | * The CRTC attached to the connector must be configured by user-space to |
| 1931 | * always produce full-range pixels. |
| 1932 | * |
| 1933 | * The value of this property can be one of the following: |
| 1934 | * |
| 1935 | * Automatic: |
| 1936 | * The quantization range is selected automatically based on the |
| 1937 | * mode according to the HDMI specifications (HDMI 1.4b - Section |
| 1938 | * 6.6 - Video Quantization Ranges). |
| 1939 | * |
| 1940 | * Full: |
| 1941 | * Full quantization range is forced. |
| 1942 | * |
| 1943 | * Limited 16:235: |
| 1944 | * Limited quantization range is forced. Unlike the name suggests, |
| 1945 | * this works for any number of bits-per-component. |
| 1946 | * |
| 1947 | * Property values other than Automatic can result in colors being off (if |
| 1948 | * limited is selected but the display expects full), or a black screen |
| 1949 | * (if full is selected but the display expects limited). |
| 1950 | * |
| 1951 | * Drivers can set up this property by calling |
| 1952 | * drm_connector_attach_broadcast_rgb_property(). |
| 1953 | * |
| 1954 | * content type (HDMI specific): |
| 1955 | * Indicates content type setting to be used in HDMI infoframes to indicate |
| 1956 | * content type for the external device, so that it adjusts its display |
| 1957 | * settings accordingly. |
| 1958 | * |
| 1959 | * The value of this property can be one of the following: |
| 1960 | * |
| 1961 | * No Data: |
| 1962 | * Content type is unknown |
| 1963 | * Graphics: |
| 1964 | * Content type is graphics |
| 1965 | * Photo: |
| 1966 | * Content type is photo |
| 1967 | * Cinema: |
| 1968 | * Content type is cinema |
| 1969 | * Game: |
| 1970 | * Content type is game |
| 1971 | * |
| 1972 | * The meaning of each content type is defined in CTA-861-G table 15. |
| 1973 | * |
| 1974 | * Drivers can set up this property by calling |
| 1975 | * drm_connector_attach_content_type_property(). Decoding to |
| 1976 | * infoframe values is done through drm_hdmi_avi_infoframe_content_type(). |
| 1977 | */ |
| 1978 | |
| 1979 | /* |
| 1980 | * TODO: Document the properties: |
| 1981 | * - brightness |
| 1982 | * - contrast |
| 1983 | * - flicker reduction |
| 1984 | * - hue |
| 1985 | * - mode |
| 1986 | * - overscan |
| 1987 | * - saturation |
| 1988 | * - select subconnector |
| 1989 | */ |
| 1990 | /** |
| 1991 | * DOC: Analog TV Connector Properties |
| 1992 | * |
| 1993 | * TV Mode: |
| 1994 | * Indicates the TV Mode used on an analog TV connector. The value |
| 1995 | * of this property can be one of the following: |
| 1996 | * |
| 1997 | * NTSC: |
| 1998 | * TV Mode is CCIR System M (aka 525-lines) together with |
| 1999 | * the NTSC Color Encoding. |
| 2000 | * |
| 2001 | * NTSC-443: |
| 2002 | * |
| 2003 | * TV Mode is CCIR System M (aka 525-lines) together with |
| 2004 | * the NTSC Color Encoding, but with a color subcarrier |
| 2005 | * frequency of 4.43MHz |
| 2006 | * |
| 2007 | * NTSC-J: |
| 2008 | * |
| 2009 | * TV Mode is CCIR System M (aka 525-lines) together with |
| 2010 | * the NTSC Color Encoding, but with a black level equal to |
| 2011 | * the blanking level. |
| 2012 | * |
| 2013 | * PAL: |
| 2014 | * |
| 2015 | * TV Mode is CCIR System B (aka 625-lines) together with |
| 2016 | * the PAL Color Encoding. |
| 2017 | * |
| 2018 | * PAL-M: |
| 2019 | * |
| 2020 | * TV Mode is CCIR System M (aka 525-lines) together with |
| 2021 | * the PAL Color Encoding. |
| 2022 | * |
| 2023 | * PAL-N: |
| 2024 | * |
| 2025 | * TV Mode is CCIR System N together with the PAL Color |
| 2026 | * Encoding, a color subcarrier frequency of 3.58MHz, the |
| 2027 | * SECAM color space, and narrower channels than other PAL |
| 2028 | * variants. |
| 2029 | * |
| 2030 | * SECAM: |
| 2031 | * |
| 2032 | * TV Mode is CCIR System B (aka 625-lines) together with |
| 2033 | * the SECAM Color Encoding. |
| 2034 | * |
| 2035 | * Mono: |
| 2036 | * |
| 2037 | * Use timings appropriate to the DRM mode, including |
| 2038 | * equalizing pulses for a 525-line or 625-line mode, |
| 2039 | * with no pedestal or color encoding. |
| 2040 | * |
| 2041 | * Drivers can set up this property by calling |
| 2042 | * drm_mode_create_tv_properties(). |
| 2043 | */ |
| 2044 | |
| 2045 | /** |
| 2046 | * drm_connector_attach_content_type_property - attach content-type property |
| 2047 | * @connector: connector to attach content type property on. |
| 2048 | * |
| 2049 | * Called by a driver the first time a HDMI connector is made. |
| 2050 | * |
| 2051 | * Returns: %0 |
| 2052 | */ |
| 2053 | int drm_connector_attach_content_type_property(struct drm_connector *connector) |
| 2054 | { |
| 2055 | if (!drm_mode_create_content_type_property(dev: connector->dev)) |
| 2056 | drm_object_attach_property(obj: &connector->base, |
| 2057 | property: connector->dev->mode_config.content_type_property, |
| 2058 | DRM_MODE_CONTENT_TYPE_NO_DATA); |
| 2059 | return 0; |
| 2060 | } |
| 2061 | EXPORT_SYMBOL(drm_connector_attach_content_type_property); |
| 2062 | |
| 2063 | /** |
| 2064 | * drm_connector_attach_tv_margin_properties - attach TV connector margin |
| 2065 | * properties |
| 2066 | * @connector: DRM connector |
| 2067 | * |
| 2068 | * Called by a driver when it needs to attach TV margin props to a connector. |
| 2069 | * Typically used on SDTV and HDMI connectors. |
| 2070 | */ |
| 2071 | void drm_connector_attach_tv_margin_properties(struct drm_connector *connector) |
| 2072 | { |
| 2073 | struct drm_device *dev = connector->dev; |
| 2074 | |
| 2075 | drm_object_attach_property(obj: &connector->base, |
| 2076 | property: dev->mode_config.tv_left_margin_property, |
| 2077 | init_val: 0); |
| 2078 | drm_object_attach_property(obj: &connector->base, |
| 2079 | property: dev->mode_config.tv_right_margin_property, |
| 2080 | init_val: 0); |
| 2081 | drm_object_attach_property(obj: &connector->base, |
| 2082 | property: dev->mode_config.tv_top_margin_property, |
| 2083 | init_val: 0); |
| 2084 | drm_object_attach_property(obj: &connector->base, |
| 2085 | property: dev->mode_config.tv_bottom_margin_property, |
| 2086 | init_val: 0); |
| 2087 | } |
| 2088 | EXPORT_SYMBOL(drm_connector_attach_tv_margin_properties); |
| 2089 | |
| 2090 | /** |
| 2091 | * drm_mode_create_tv_margin_properties - create TV connector margin properties |
| 2092 | * @dev: DRM device |
| 2093 | * |
| 2094 | * Called by a driver's HDMI connector initialization routine, this function |
| 2095 | * creates the TV margin properties for a given device. No need to call this |
| 2096 | * function for an SDTV connector, it's already called from |
| 2097 | * drm_mode_create_tv_properties_legacy(). |
| 2098 | * |
| 2099 | * Returns: |
| 2100 | * 0 on success or a negative error code on failure. |
| 2101 | */ |
| 2102 | int drm_mode_create_tv_margin_properties(struct drm_device *dev) |
| 2103 | { |
| 2104 | if (dev->mode_config.tv_left_margin_property) |
| 2105 | return 0; |
| 2106 | |
| 2107 | dev->mode_config.tv_left_margin_property = |
| 2108 | drm_property_create_range(dev, flags: 0, name: "left margin" , min: 0, max: 100); |
| 2109 | if (!dev->mode_config.tv_left_margin_property) |
| 2110 | return -ENOMEM; |
| 2111 | |
| 2112 | dev->mode_config.tv_right_margin_property = |
| 2113 | drm_property_create_range(dev, flags: 0, name: "right margin" , min: 0, max: 100); |
| 2114 | if (!dev->mode_config.tv_right_margin_property) |
| 2115 | return -ENOMEM; |
| 2116 | |
| 2117 | dev->mode_config.tv_top_margin_property = |
| 2118 | drm_property_create_range(dev, flags: 0, name: "top margin" , min: 0, max: 100); |
| 2119 | if (!dev->mode_config.tv_top_margin_property) |
| 2120 | return -ENOMEM; |
| 2121 | |
| 2122 | dev->mode_config.tv_bottom_margin_property = |
| 2123 | drm_property_create_range(dev, flags: 0, name: "bottom margin" , min: 0, max: 100); |
| 2124 | if (!dev->mode_config.tv_bottom_margin_property) |
| 2125 | return -ENOMEM; |
| 2126 | |
| 2127 | return 0; |
| 2128 | } |
| 2129 | EXPORT_SYMBOL(drm_mode_create_tv_margin_properties); |
| 2130 | |
| 2131 | /** |
| 2132 | * drm_mode_create_tv_properties_legacy - create TV specific connector properties |
| 2133 | * @dev: DRM device |
| 2134 | * @num_modes: number of different TV formats (modes) supported |
| 2135 | * @modes: array of pointers to strings containing name of each format |
| 2136 | * |
| 2137 | * Called by a driver's TV initialization routine, this function creates |
| 2138 | * the TV specific connector properties for a given device. Caller is |
| 2139 | * responsible for allocating a list of format names and passing them to |
| 2140 | * this routine. |
| 2141 | * |
| 2142 | * NOTE: This functions registers the deprecated "mode" connector |
| 2143 | * property to select the analog TV mode (ie, NTSC, PAL, etc.). New |
| 2144 | * drivers must use drm_mode_create_tv_properties() instead. |
| 2145 | * |
| 2146 | * Returns: |
| 2147 | * 0 on success or a negative error code on failure. |
| 2148 | */ |
| 2149 | int drm_mode_create_tv_properties_legacy(struct drm_device *dev, |
| 2150 | unsigned int num_modes, |
| 2151 | const char * const modes[]) |
| 2152 | { |
| 2153 | struct drm_property *tv_selector; |
| 2154 | struct drm_property *tv_subconnector; |
| 2155 | unsigned int i; |
| 2156 | |
| 2157 | if (dev->mode_config.tv_select_subconnector_property) |
| 2158 | return 0; |
| 2159 | |
| 2160 | /* |
| 2161 | * Basic connector properties |
| 2162 | */ |
| 2163 | tv_selector = drm_property_create_enum(dev, flags: 0, |
| 2164 | name: "select subconnector" , |
| 2165 | props: drm_tv_select_enum_list, |
| 2166 | ARRAY_SIZE(drm_tv_select_enum_list)); |
| 2167 | if (!tv_selector) |
| 2168 | goto nomem; |
| 2169 | |
| 2170 | dev->mode_config.tv_select_subconnector_property = tv_selector; |
| 2171 | |
| 2172 | tv_subconnector = |
| 2173 | drm_property_create_enum(dev, DRM_MODE_PROP_IMMUTABLE, |
| 2174 | name: "subconnector" , |
| 2175 | props: drm_tv_subconnector_enum_list, |
| 2176 | ARRAY_SIZE(drm_tv_subconnector_enum_list)); |
| 2177 | if (!tv_subconnector) |
| 2178 | goto nomem; |
| 2179 | dev->mode_config.tv_subconnector_property = tv_subconnector; |
| 2180 | |
| 2181 | /* |
| 2182 | * Other, TV specific properties: margins & TV modes. |
| 2183 | */ |
| 2184 | if (drm_mode_create_tv_margin_properties(dev)) |
| 2185 | goto nomem; |
| 2186 | |
| 2187 | if (num_modes) { |
| 2188 | dev->mode_config.legacy_tv_mode_property = |
| 2189 | drm_property_create(dev, DRM_MODE_PROP_ENUM, |
| 2190 | name: "mode" , num_values: num_modes); |
| 2191 | if (!dev->mode_config.legacy_tv_mode_property) |
| 2192 | goto nomem; |
| 2193 | |
| 2194 | for (i = 0; i < num_modes; i++) |
| 2195 | drm_property_add_enum(property: dev->mode_config.legacy_tv_mode_property, |
| 2196 | value: i, name: modes[i]); |
| 2197 | } |
| 2198 | |
| 2199 | dev->mode_config.tv_brightness_property = |
| 2200 | drm_property_create_range(dev, flags: 0, name: "brightness" , min: 0, max: 100); |
| 2201 | if (!dev->mode_config.tv_brightness_property) |
| 2202 | goto nomem; |
| 2203 | |
| 2204 | dev->mode_config.tv_contrast_property = |
| 2205 | drm_property_create_range(dev, flags: 0, name: "contrast" , min: 0, max: 100); |
| 2206 | if (!dev->mode_config.tv_contrast_property) |
| 2207 | goto nomem; |
| 2208 | |
| 2209 | dev->mode_config.tv_flicker_reduction_property = |
| 2210 | drm_property_create_range(dev, flags: 0, name: "flicker reduction" , min: 0, max: 100); |
| 2211 | if (!dev->mode_config.tv_flicker_reduction_property) |
| 2212 | goto nomem; |
| 2213 | |
| 2214 | dev->mode_config.tv_overscan_property = |
| 2215 | drm_property_create_range(dev, flags: 0, name: "overscan" , min: 0, max: 100); |
| 2216 | if (!dev->mode_config.tv_overscan_property) |
| 2217 | goto nomem; |
| 2218 | |
| 2219 | dev->mode_config.tv_saturation_property = |
| 2220 | drm_property_create_range(dev, flags: 0, name: "saturation" , min: 0, max: 100); |
| 2221 | if (!dev->mode_config.tv_saturation_property) |
| 2222 | goto nomem; |
| 2223 | |
| 2224 | dev->mode_config.tv_hue_property = |
| 2225 | drm_property_create_range(dev, flags: 0, name: "hue" , min: 0, max: 100); |
| 2226 | if (!dev->mode_config.tv_hue_property) |
| 2227 | goto nomem; |
| 2228 | |
| 2229 | return 0; |
| 2230 | nomem: |
| 2231 | return -ENOMEM; |
| 2232 | } |
| 2233 | EXPORT_SYMBOL(drm_mode_create_tv_properties_legacy); |
| 2234 | |
| 2235 | /** |
| 2236 | * drm_mode_create_tv_properties - create TV specific connector properties |
| 2237 | * @dev: DRM device |
| 2238 | * @supported_tv_modes: Bitmask of TV modes supported (See DRM_MODE_TV_MODE_*) |
| 2239 | * |
| 2240 | * Called by a driver's TV initialization routine, this function creates |
| 2241 | * the TV specific connector properties for a given device. |
| 2242 | * |
| 2243 | * Returns: |
| 2244 | * 0 on success or a negative error code on failure. |
| 2245 | */ |
| 2246 | int drm_mode_create_tv_properties(struct drm_device *dev, |
| 2247 | unsigned int supported_tv_modes) |
| 2248 | { |
| 2249 | struct drm_prop_enum_list tv_mode_list[DRM_MODE_TV_MODE_MAX]; |
| 2250 | struct drm_property *tv_mode; |
| 2251 | unsigned int i, len = 0; |
| 2252 | |
| 2253 | if (dev->mode_config.tv_mode_property) |
| 2254 | return 0; |
| 2255 | |
| 2256 | for (i = 0; i < DRM_MODE_TV_MODE_MAX; i++) { |
| 2257 | if (!(supported_tv_modes & BIT(i))) |
| 2258 | continue; |
| 2259 | |
| 2260 | tv_mode_list[len].type = i; |
| 2261 | tv_mode_list[len].name = drm_get_tv_mode_name(val: i); |
| 2262 | len++; |
| 2263 | } |
| 2264 | |
| 2265 | tv_mode = drm_property_create_enum(dev, flags: 0, name: "TV mode" , |
| 2266 | props: tv_mode_list, num_values: len); |
| 2267 | if (!tv_mode) |
| 2268 | return -ENOMEM; |
| 2269 | |
| 2270 | dev->mode_config.tv_mode_property = tv_mode; |
| 2271 | |
| 2272 | return drm_mode_create_tv_properties_legacy(dev, 0, NULL); |
| 2273 | } |
| 2274 | EXPORT_SYMBOL(drm_mode_create_tv_properties); |
| 2275 | |
| 2276 | /** |
| 2277 | * drm_mode_create_scaling_mode_property - create scaling mode property |
| 2278 | * @dev: DRM device |
| 2279 | * |
| 2280 | * Called by a driver the first time it's needed, must be attached to desired |
| 2281 | * connectors. |
| 2282 | * |
| 2283 | * Atomic drivers should use drm_connector_attach_scaling_mode_property() |
| 2284 | * instead to correctly assign &drm_connector_state.scaling_mode |
| 2285 | * in the atomic state. |
| 2286 | * |
| 2287 | * Returns: %0 |
| 2288 | */ |
| 2289 | int drm_mode_create_scaling_mode_property(struct drm_device *dev) |
| 2290 | { |
| 2291 | struct drm_property *scaling_mode; |
| 2292 | |
| 2293 | if (dev->mode_config.scaling_mode_property) |
| 2294 | return 0; |
| 2295 | |
| 2296 | scaling_mode = |
| 2297 | drm_property_create_enum(dev, flags: 0, name: "scaling mode" , |
| 2298 | props: drm_scaling_mode_enum_list, |
| 2299 | ARRAY_SIZE(drm_scaling_mode_enum_list)); |
| 2300 | |
| 2301 | dev->mode_config.scaling_mode_property = scaling_mode; |
| 2302 | |
| 2303 | return 0; |
| 2304 | } |
| 2305 | EXPORT_SYMBOL(drm_mode_create_scaling_mode_property); |
| 2306 | |
| 2307 | /** |
| 2308 | * DOC: Variable refresh properties |
| 2309 | * |
| 2310 | * Variable refresh rate capable displays can dynamically adjust their |
| 2311 | * refresh rate by extending the duration of their vertical front porch |
| 2312 | * until page flip or timeout occurs. This can reduce or remove stuttering |
| 2313 | * and latency in scenarios where the page flip does not align with the |
| 2314 | * vblank interval. |
| 2315 | * |
| 2316 | * An example scenario would be an application flipping at a constant rate |
| 2317 | * of 48Hz on a 60Hz display. The page flip will frequently miss the vblank |
| 2318 | * interval and the same contents will be displayed twice. This can be |
| 2319 | * observed as stuttering for content with motion. |
| 2320 | * |
| 2321 | * If variable refresh rate was active on a display that supported a |
| 2322 | * variable refresh range from 35Hz to 60Hz no stuttering would be observable |
| 2323 | * for the example scenario. The minimum supported variable refresh rate of |
| 2324 | * 35Hz is below the page flip frequency and the vertical front porch can |
| 2325 | * be extended until the page flip occurs. The vblank interval will be |
| 2326 | * directly aligned to the page flip rate. |
| 2327 | * |
| 2328 | * Not all userspace content is suitable for use with variable refresh rate. |
| 2329 | * Large and frequent changes in vertical front porch duration may worsen |
| 2330 | * perceived stuttering for input sensitive applications. |
| 2331 | * |
| 2332 | * Panel brightness will also vary with vertical front porch duration. Some |
| 2333 | * panels may have noticeable differences in brightness between the minimum |
| 2334 | * vertical front porch duration and the maximum vertical front porch duration. |
| 2335 | * Large and frequent changes in vertical front porch duration may produce |
| 2336 | * observable flickering for such panels. |
| 2337 | * |
| 2338 | * Userspace control for variable refresh rate is supported via properties |
| 2339 | * on the &drm_connector and &drm_crtc objects. |
| 2340 | * |
| 2341 | * "vrr_capable": |
| 2342 | * Optional &drm_connector boolean property that drivers should attach |
| 2343 | * with drm_connector_attach_vrr_capable_property() on connectors that |
| 2344 | * could support variable refresh rates. Drivers should update the |
| 2345 | * property value by calling drm_connector_set_vrr_capable_property(). |
| 2346 | * |
| 2347 | * Absence of the property should indicate absence of support. |
| 2348 | * |
| 2349 | * "VRR_ENABLED": |
| 2350 | * Default &drm_crtc boolean property that notifies the driver that the |
| 2351 | * content on the CRTC is suitable for variable refresh rate presentation. |
| 2352 | * The driver will take this property as a hint to enable variable |
| 2353 | * refresh rate support if the receiver supports it, ie. if the |
| 2354 | * "vrr_capable" property is true on the &drm_connector object. The |
| 2355 | * vertical front porch duration will be extended until page-flip or |
| 2356 | * timeout when enabled. |
| 2357 | * |
| 2358 | * The minimum vertical front porch duration is defined as the vertical |
| 2359 | * front porch duration for the current mode. |
| 2360 | * |
| 2361 | * The maximum vertical front porch duration is greater than or equal to |
| 2362 | * the minimum vertical front porch duration. The duration is derived |
| 2363 | * from the minimum supported variable refresh rate for the connector. |
| 2364 | * |
| 2365 | * The driver may place further restrictions within these minimum |
| 2366 | * and maximum bounds. |
| 2367 | */ |
| 2368 | |
| 2369 | /** |
| 2370 | * drm_connector_attach_vrr_capable_property - creates the |
| 2371 | * vrr_capable property |
| 2372 | * @connector: connector to create the vrr_capable property on. |
| 2373 | * |
| 2374 | * This is used by atomic drivers to add support for querying |
| 2375 | * variable refresh rate capability for a connector. |
| 2376 | * |
| 2377 | * Returns: |
| 2378 | * Zero on success, negative errno on failure. |
| 2379 | */ |
| 2380 | int drm_connector_attach_vrr_capable_property( |
| 2381 | struct drm_connector *connector) |
| 2382 | { |
| 2383 | struct drm_device *dev = connector->dev; |
| 2384 | struct drm_property *prop; |
| 2385 | |
| 2386 | if (!connector->vrr_capable_property) { |
| 2387 | prop = drm_property_create_bool(dev, DRM_MODE_PROP_IMMUTABLE, |
| 2388 | name: "vrr_capable" ); |
| 2389 | if (!prop) |
| 2390 | return -ENOMEM; |
| 2391 | |
| 2392 | connector->vrr_capable_property = prop; |
| 2393 | drm_object_attach_property(obj: &connector->base, property: prop, init_val: 0); |
| 2394 | } |
| 2395 | |
| 2396 | return 0; |
| 2397 | } |
| 2398 | EXPORT_SYMBOL(drm_connector_attach_vrr_capable_property); |
| 2399 | |
| 2400 | /** |
| 2401 | * drm_connector_attach_scaling_mode_property - attach atomic scaling mode property |
| 2402 | * @connector: connector to attach scaling mode property on. |
| 2403 | * @scaling_mode_mask: or'ed mask of BIT(%DRM_MODE_SCALE_\*). |
| 2404 | * |
| 2405 | * This is used to add support for scaling mode to atomic drivers. |
| 2406 | * The scaling mode will be set to &drm_connector_state.scaling_mode |
| 2407 | * and can be used from &drm_connector_helper_funcs->atomic_check for validation. |
| 2408 | * |
| 2409 | * This is the atomic version of drm_mode_create_scaling_mode_property(). |
| 2410 | * |
| 2411 | * Returns: |
| 2412 | * Zero on success, negative errno on failure. |
| 2413 | */ |
| 2414 | int drm_connector_attach_scaling_mode_property(struct drm_connector *connector, |
| 2415 | u32 scaling_mode_mask) |
| 2416 | { |
| 2417 | struct drm_device *dev = connector->dev; |
| 2418 | struct drm_property *scaling_mode_property; |
| 2419 | int i; |
| 2420 | const unsigned valid_scaling_mode_mask = |
| 2421 | (1U << ARRAY_SIZE(drm_scaling_mode_enum_list)) - 1; |
| 2422 | |
| 2423 | if (WARN_ON(hweight32(scaling_mode_mask) < 2 || |
| 2424 | scaling_mode_mask & ~valid_scaling_mode_mask)) |
| 2425 | return -EINVAL; |
| 2426 | |
| 2427 | scaling_mode_property = |
| 2428 | drm_property_create(dev, DRM_MODE_PROP_ENUM, name: "scaling mode" , |
| 2429 | hweight32(scaling_mode_mask)); |
| 2430 | |
| 2431 | if (!scaling_mode_property) |
| 2432 | return -ENOMEM; |
| 2433 | |
| 2434 | for (i = 0; i < ARRAY_SIZE(drm_scaling_mode_enum_list); i++) { |
| 2435 | int ret; |
| 2436 | |
| 2437 | if (!(BIT(i) & scaling_mode_mask)) |
| 2438 | continue; |
| 2439 | |
| 2440 | ret = drm_property_add_enum(property: scaling_mode_property, |
| 2441 | value: drm_scaling_mode_enum_list[i].type, |
| 2442 | name: drm_scaling_mode_enum_list[i].name); |
| 2443 | |
| 2444 | if (ret) { |
| 2445 | drm_property_destroy(dev, property: scaling_mode_property); |
| 2446 | |
| 2447 | return ret; |
| 2448 | } |
| 2449 | } |
| 2450 | |
| 2451 | drm_object_attach_property(obj: &connector->base, |
| 2452 | property: scaling_mode_property, init_val: 0); |
| 2453 | |
| 2454 | connector->scaling_mode_property = scaling_mode_property; |
| 2455 | |
| 2456 | return 0; |
| 2457 | } |
| 2458 | EXPORT_SYMBOL(drm_connector_attach_scaling_mode_property); |
| 2459 | |
| 2460 | /** |
| 2461 | * drm_mode_create_aspect_ratio_property - create aspect ratio property |
| 2462 | * @dev: DRM device |
| 2463 | * |
| 2464 | * Called by a driver the first time it's needed, must be attached to desired |
| 2465 | * connectors. |
| 2466 | * |
| 2467 | * Returns: |
| 2468 | * Zero on success, negative errno on failure. |
| 2469 | */ |
| 2470 | int drm_mode_create_aspect_ratio_property(struct drm_device *dev) |
| 2471 | { |
| 2472 | if (dev->mode_config.aspect_ratio_property) |
| 2473 | return 0; |
| 2474 | |
| 2475 | dev->mode_config.aspect_ratio_property = |
| 2476 | drm_property_create_enum(dev, flags: 0, name: "aspect ratio" , |
| 2477 | props: drm_aspect_ratio_enum_list, |
| 2478 | ARRAY_SIZE(drm_aspect_ratio_enum_list)); |
| 2479 | |
| 2480 | if (dev->mode_config.aspect_ratio_property == NULL) |
| 2481 | return -ENOMEM; |
| 2482 | |
| 2483 | return 0; |
| 2484 | } |
| 2485 | EXPORT_SYMBOL(drm_mode_create_aspect_ratio_property); |
| 2486 | |
| 2487 | /** |
| 2488 | * DOC: standard connector properties |
| 2489 | * |
| 2490 | * Colorspace: |
| 2491 | * This property is used to inform the driver about the color encoding |
| 2492 | * user space configured the pixel operation properties to produce. |
| 2493 | * The variants set the colorimetry, transfer characteristics, and which |
| 2494 | * YCbCr conversion should be used when necessary. |
| 2495 | * The transfer characteristics from HDR_OUTPUT_METADATA takes precedence |
| 2496 | * over this property. |
| 2497 | * User space always configures the pixel operation properties to produce |
| 2498 | * full quantization range data (see the Broadcast RGB property). |
| 2499 | * |
| 2500 | * Drivers inform the sink about what colorimetry, transfer |
| 2501 | * characteristics, YCbCr conversion, and quantization range to expect |
| 2502 | * (this can depend on the output mode, output format and other |
| 2503 | * properties). Drivers also convert the user space provided data to what |
| 2504 | * the sink expects. |
| 2505 | * |
| 2506 | * User space has to check if the sink supports all of the possible |
| 2507 | * colorimetries that the driver is allowed to pick by parsing the EDID. |
| 2508 | * |
| 2509 | * For historical reasons this property exposes a number of variants which |
| 2510 | * result in undefined behavior. |
| 2511 | * |
| 2512 | * Default: |
| 2513 | * The behavior is driver-specific. |
| 2514 | * |
| 2515 | * BT2020_RGB: |
| 2516 | * |
| 2517 | * BT2020_YCC: |
| 2518 | * User space configures the pixel operation properties to produce |
| 2519 | * RGB content with Rec. ITU-R BT.2020 colorimetry, Rec. |
| 2520 | * ITU-R BT.2020 (Table 4, RGB) transfer characteristics and full |
| 2521 | * quantization range. |
| 2522 | * User space can use the HDR_OUTPUT_METADATA property to set the |
| 2523 | * transfer characteristics to PQ (Rec. ITU-R BT.2100 Table 4) or |
| 2524 | * HLG (Rec. ITU-R BT.2100 Table 5) in which case, user space |
| 2525 | * configures pixel operation properties to produce content with |
| 2526 | * the respective transfer characteristics. |
| 2527 | * User space has to make sure the sink supports Rec. |
| 2528 | * ITU-R BT.2020 R'G'B' and Rec. ITU-R BT.2020 Y'C'BC'R |
| 2529 | * colorimetry. |
| 2530 | * Drivers can configure the sink to use an RGB format, tell the |
| 2531 | * sink to expect Rec. ITU-R BT.2020 R'G'B' colorimetry and convert |
| 2532 | * to the appropriate quantization range. |
| 2533 | * Drivers can configure the sink to use a YCbCr format, tell the |
| 2534 | * sink to expect Rec. ITU-R BT.2020 Y'C'BC'R colorimetry, convert |
| 2535 | * to YCbCr using the Rec. ITU-R BT.2020 non-constant luminance |
| 2536 | * conversion matrix and convert to the appropriate quantization |
| 2537 | * range. |
| 2538 | * The variants BT2020_RGB and BT2020_YCC are equivalent and the |
| 2539 | * driver chooses between RGB and YCbCr on its own. |
| 2540 | * |
| 2541 | * SMPTE_170M_YCC: |
| 2542 | * BT709_YCC: |
| 2543 | * XVYCC_601: |
| 2544 | * XVYCC_709: |
| 2545 | * SYCC_601: |
| 2546 | * opYCC_601: |
| 2547 | * opRGB: |
| 2548 | * BT2020_CYCC: |
| 2549 | * DCI-P3_RGB_D65: |
| 2550 | * DCI-P3_RGB_Theater: |
| 2551 | * RGB_WIDE_FIXED: |
| 2552 | * RGB_WIDE_FLOAT: |
| 2553 | * |
| 2554 | * BT601_YCC: |
| 2555 | * The behavior is undefined. |
| 2556 | * |
| 2557 | * Because between HDMI and DP have different colorspaces, |
| 2558 | * drm_mode_create_hdmi_colorspace_property() is used for HDMI connector and |
| 2559 | * drm_mode_create_dp_colorspace_property() is used for DP connector. |
| 2560 | */ |
| 2561 | |
| 2562 | static int drm_mode_create_colorspace_property(struct drm_connector *connector, |
| 2563 | u32 supported_colorspaces) |
| 2564 | { |
| 2565 | struct drm_device *dev = connector->dev; |
| 2566 | u32 colorspaces = supported_colorspaces | BIT(DRM_MODE_COLORIMETRY_DEFAULT); |
| 2567 | struct drm_prop_enum_list enum_list[DRM_MODE_COLORIMETRY_COUNT]; |
| 2568 | int i, len; |
| 2569 | |
| 2570 | if (connector->colorspace_property) |
| 2571 | return 0; |
| 2572 | |
| 2573 | if (!supported_colorspaces) { |
| 2574 | drm_err(dev, "No supported colorspaces provded on [CONNECTOR:%d:%s]\n" , |
| 2575 | connector->base.id, connector->name); |
| 2576 | return -EINVAL; |
| 2577 | } |
| 2578 | |
| 2579 | if ((supported_colorspaces & -BIT(DRM_MODE_COLORIMETRY_COUNT)) != 0) { |
| 2580 | drm_err(dev, "Unknown colorspace provded on [CONNECTOR:%d:%s]\n" , |
| 2581 | connector->base.id, connector->name); |
| 2582 | return -EINVAL; |
| 2583 | } |
| 2584 | |
| 2585 | len = 0; |
| 2586 | for (i = 0; i < DRM_MODE_COLORIMETRY_COUNT; i++) { |
| 2587 | if ((colorspaces & BIT(i)) == 0) |
| 2588 | continue; |
| 2589 | |
| 2590 | enum_list[len].type = i; |
| 2591 | enum_list[len].name = colorspace_names[i]; |
| 2592 | len++; |
| 2593 | } |
| 2594 | |
| 2595 | connector->colorspace_property = |
| 2596 | drm_property_create_enum(dev, DRM_MODE_PROP_ENUM, name: "Colorspace" , |
| 2597 | props: enum_list, |
| 2598 | num_values: len); |
| 2599 | |
| 2600 | if (!connector->colorspace_property) |
| 2601 | return -ENOMEM; |
| 2602 | |
| 2603 | return 0; |
| 2604 | } |
| 2605 | |
| 2606 | /** |
| 2607 | * drm_mode_create_hdmi_colorspace_property - create hdmi colorspace property |
| 2608 | * @connector: connector to create the Colorspace property on. |
| 2609 | * @supported_colorspaces: bitmap of supported color spaces |
| 2610 | * |
| 2611 | * Called by a driver the first time it's needed, must be attached to desired |
| 2612 | * HDMI connectors. |
| 2613 | * |
| 2614 | * Returns: |
| 2615 | * Zero on success, negative errno on failure. |
| 2616 | */ |
| 2617 | int drm_mode_create_hdmi_colorspace_property(struct drm_connector *connector, |
| 2618 | u32 supported_colorspaces) |
| 2619 | { |
| 2620 | u32 colorspaces; |
| 2621 | |
| 2622 | if (supported_colorspaces) |
| 2623 | colorspaces = supported_colorspaces & hdmi_colorspaces; |
| 2624 | else |
| 2625 | colorspaces = hdmi_colorspaces; |
| 2626 | |
| 2627 | return drm_mode_create_colorspace_property(connector, supported_colorspaces: colorspaces); |
| 2628 | } |
| 2629 | EXPORT_SYMBOL(drm_mode_create_hdmi_colorspace_property); |
| 2630 | |
| 2631 | /** |
| 2632 | * drm_mode_create_dp_colorspace_property - create dp colorspace property |
| 2633 | * @connector: connector to create the Colorspace property on. |
| 2634 | * @supported_colorspaces: bitmap of supported color spaces |
| 2635 | * |
| 2636 | * Called by a driver the first time it's needed, must be attached to desired |
| 2637 | * DP connectors. |
| 2638 | * |
| 2639 | * Returns: |
| 2640 | * Zero on success, negative errno on failure. |
| 2641 | */ |
| 2642 | int drm_mode_create_dp_colorspace_property(struct drm_connector *connector, |
| 2643 | u32 supported_colorspaces) |
| 2644 | { |
| 2645 | u32 colorspaces; |
| 2646 | |
| 2647 | if (supported_colorspaces) |
| 2648 | colorspaces = supported_colorspaces & dp_colorspaces; |
| 2649 | else |
| 2650 | colorspaces = dp_colorspaces; |
| 2651 | |
| 2652 | return drm_mode_create_colorspace_property(connector, supported_colorspaces: colorspaces); |
| 2653 | } |
| 2654 | EXPORT_SYMBOL(drm_mode_create_dp_colorspace_property); |
| 2655 | |
| 2656 | /** |
| 2657 | * drm_mode_create_content_type_property - create content type property |
| 2658 | * @dev: DRM device |
| 2659 | * |
| 2660 | * Called by a driver the first time it's needed, must be attached to desired |
| 2661 | * connectors. |
| 2662 | * |
| 2663 | * Returns: |
| 2664 | * Zero on success, negative errno on failure. |
| 2665 | */ |
| 2666 | int drm_mode_create_content_type_property(struct drm_device *dev) |
| 2667 | { |
| 2668 | if (dev->mode_config.content_type_property) |
| 2669 | return 0; |
| 2670 | |
| 2671 | dev->mode_config.content_type_property = |
| 2672 | drm_property_create_enum(dev, flags: 0, name: "content type" , |
| 2673 | props: drm_content_type_enum_list, |
| 2674 | ARRAY_SIZE(drm_content_type_enum_list)); |
| 2675 | |
| 2676 | if (dev->mode_config.content_type_property == NULL) |
| 2677 | return -ENOMEM; |
| 2678 | |
| 2679 | return 0; |
| 2680 | } |
| 2681 | EXPORT_SYMBOL(drm_mode_create_content_type_property); |
| 2682 | |
| 2683 | /** |
| 2684 | * drm_mode_create_suggested_offset_properties - create suggests offset properties |
| 2685 | * @dev: DRM device |
| 2686 | * |
| 2687 | * Create the suggested x/y offset property for connectors. |
| 2688 | * |
| 2689 | * Returns: |
| 2690 | * 0 on success or a negative error code on failure. |
| 2691 | */ |
| 2692 | int drm_mode_create_suggested_offset_properties(struct drm_device *dev) |
| 2693 | { |
| 2694 | if (dev->mode_config.suggested_x_property && dev->mode_config.suggested_y_property) |
| 2695 | return 0; |
| 2696 | |
| 2697 | dev->mode_config.suggested_x_property = |
| 2698 | drm_property_create_range(dev, DRM_MODE_PROP_IMMUTABLE, name: "suggested X" , min: 0, max: 0xffffffff); |
| 2699 | |
| 2700 | dev->mode_config.suggested_y_property = |
| 2701 | drm_property_create_range(dev, DRM_MODE_PROP_IMMUTABLE, name: "suggested Y" , min: 0, max: 0xffffffff); |
| 2702 | |
| 2703 | if (dev->mode_config.suggested_x_property == NULL || |
| 2704 | dev->mode_config.suggested_y_property == NULL) |
| 2705 | return -ENOMEM; |
| 2706 | return 0; |
| 2707 | } |
| 2708 | EXPORT_SYMBOL(drm_mode_create_suggested_offset_properties); |
| 2709 | |
| 2710 | /** |
| 2711 | * drm_connector_set_path_property - set tile property on connector |
| 2712 | * @connector: connector to set property on. |
| 2713 | * @path: path to use for property; must not be NULL. |
| 2714 | * |
| 2715 | * This creates a property to expose to userspace to specify a |
| 2716 | * connector path. This is mainly used for DisplayPort MST where |
| 2717 | * connectors have a topology and we want to allow userspace to give |
| 2718 | * them more meaningful names. |
| 2719 | * |
| 2720 | * Returns: |
| 2721 | * Zero on success, negative errno on failure. |
| 2722 | */ |
| 2723 | int drm_connector_set_path_property(struct drm_connector *connector, |
| 2724 | const char *path) |
| 2725 | { |
| 2726 | struct drm_device *dev = connector->dev; |
| 2727 | int ret; |
| 2728 | |
| 2729 | ret = drm_property_replace_global_blob(dev, |
| 2730 | replace: &connector->path_blob_ptr, |
| 2731 | strlen(path) + 1, |
| 2732 | data: path, |
| 2733 | obj_holds_id: &connector->base, |
| 2734 | prop_holds_id: dev->mode_config.path_property); |
| 2735 | return ret; |
| 2736 | } |
| 2737 | EXPORT_SYMBOL(drm_connector_set_path_property); |
| 2738 | |
| 2739 | /** |
| 2740 | * drm_connector_set_tile_property - set tile property on connector |
| 2741 | * @connector: connector to set property on. |
| 2742 | * |
| 2743 | * This looks up the tile information for a connector, and creates a |
| 2744 | * property for userspace to parse if it exists. The property is of |
| 2745 | * the form of 8 integers using ':' as a separator. |
| 2746 | * This is used for dual port tiled displays with DisplayPort SST |
| 2747 | * or DisplayPort MST connectors. |
| 2748 | * |
| 2749 | * Returns: |
| 2750 | * Zero on success, errno on failure. |
| 2751 | */ |
| 2752 | int drm_connector_set_tile_property(struct drm_connector *connector) |
| 2753 | { |
| 2754 | struct drm_device *dev = connector->dev; |
| 2755 | char tile[256]; |
| 2756 | int ret; |
| 2757 | |
| 2758 | if (!connector->has_tile) { |
| 2759 | ret = drm_property_replace_global_blob(dev, |
| 2760 | replace: &connector->tile_blob_ptr, |
| 2761 | length: 0, |
| 2762 | NULL, |
| 2763 | obj_holds_id: &connector->base, |
| 2764 | prop_holds_id: dev->mode_config.tile_property); |
| 2765 | return ret; |
| 2766 | } |
| 2767 | |
| 2768 | snprintf(buf: tile, size: 256, fmt: "%d:%d:%d:%d:%d:%d:%d:%d" , |
| 2769 | connector->tile_group->id, connector->tile_is_single_monitor, |
| 2770 | connector->num_h_tile, connector->num_v_tile, |
| 2771 | connector->tile_h_loc, connector->tile_v_loc, |
| 2772 | connector->tile_h_size, connector->tile_v_size); |
| 2773 | |
| 2774 | ret = drm_property_replace_global_blob(dev, |
| 2775 | replace: &connector->tile_blob_ptr, |
| 2776 | strlen(tile) + 1, |
| 2777 | data: tile, |
| 2778 | obj_holds_id: &connector->base, |
| 2779 | prop_holds_id: dev->mode_config.tile_property); |
| 2780 | return ret; |
| 2781 | } |
| 2782 | EXPORT_SYMBOL(drm_connector_set_tile_property); |
| 2783 | |
| 2784 | /** |
| 2785 | * drm_connector_set_link_status_property - Set link status property of a connector |
| 2786 | * @connector: drm connector |
| 2787 | * @link_status: new value of link status property (0: Good, 1: Bad) |
| 2788 | * |
| 2789 | * In usual working scenario, this link status property will always be set to |
| 2790 | * "GOOD". If something fails during or after a mode set, the kernel driver |
| 2791 | * may set this link status property to "BAD". The caller then needs to send a |
| 2792 | * hotplug uevent for userspace to re-check the valid modes through |
| 2793 | * GET_CONNECTOR_IOCTL and retry modeset. |
| 2794 | * |
| 2795 | * Note: Drivers cannot rely on userspace to support this property and |
| 2796 | * issue a modeset. As such, they may choose to handle issues (like |
| 2797 | * re-training a link) without userspace's intervention. |
| 2798 | * |
| 2799 | * The reason for adding this property is to handle link training failures, but |
| 2800 | * it is not limited to DP or link training. For example, if we implement |
| 2801 | * asynchronous setcrtc, this property can be used to report any failures in that. |
| 2802 | */ |
| 2803 | void drm_connector_set_link_status_property(struct drm_connector *connector, |
| 2804 | uint64_t link_status) |
| 2805 | { |
| 2806 | struct drm_device *dev = connector->dev; |
| 2807 | |
| 2808 | drm_modeset_lock(lock: &dev->mode_config.connection_mutex, NULL); |
| 2809 | connector->state->link_status = link_status; |
| 2810 | drm_modeset_unlock(lock: &dev->mode_config.connection_mutex); |
| 2811 | } |
| 2812 | EXPORT_SYMBOL(drm_connector_set_link_status_property); |
| 2813 | |
| 2814 | /** |
| 2815 | * drm_connector_attach_max_bpc_property - attach "max bpc" property |
| 2816 | * @connector: connector to attach max bpc property on. |
| 2817 | * @min: The minimum bit depth supported by the connector. |
| 2818 | * @max: The maximum bit depth supported by the connector. |
| 2819 | * |
| 2820 | * This is used to add support for limiting the bit depth on a connector. |
| 2821 | * |
| 2822 | * Returns: |
| 2823 | * Zero on success, negative errno on failure. |
| 2824 | */ |
| 2825 | int drm_connector_attach_max_bpc_property(struct drm_connector *connector, |
| 2826 | int min, int max) |
| 2827 | { |
| 2828 | struct drm_device *dev = connector->dev; |
| 2829 | struct drm_property *prop; |
| 2830 | |
| 2831 | prop = connector->max_bpc_property; |
| 2832 | if (!prop) { |
| 2833 | prop = drm_property_create_range(dev, flags: 0, name: "max bpc" , min, max); |
| 2834 | if (!prop) |
| 2835 | return -ENOMEM; |
| 2836 | |
| 2837 | connector->max_bpc_property = prop; |
| 2838 | } |
| 2839 | |
| 2840 | drm_object_attach_property(obj: &connector->base, property: prop, init_val: max); |
| 2841 | connector->state->max_requested_bpc = max; |
| 2842 | connector->state->max_bpc = max; |
| 2843 | |
| 2844 | return 0; |
| 2845 | } |
| 2846 | EXPORT_SYMBOL(drm_connector_attach_max_bpc_property); |
| 2847 | |
| 2848 | /** |
| 2849 | * drm_connector_attach_hdr_output_metadata_property - attach "HDR_OUTPUT_METADA" property |
| 2850 | * @connector: connector to attach the property on. |
| 2851 | * |
| 2852 | * This is used to allow the userspace to send HDR Metadata to the |
| 2853 | * driver. |
| 2854 | * |
| 2855 | * Returns: |
| 2856 | * Zero on success, negative errno on failure. |
| 2857 | */ |
| 2858 | int drm_connector_attach_hdr_output_metadata_property(struct drm_connector *connector) |
| 2859 | { |
| 2860 | struct drm_device *dev = connector->dev; |
| 2861 | struct drm_property *prop = dev->mode_config.hdr_output_metadata_property; |
| 2862 | |
| 2863 | drm_object_attach_property(obj: &connector->base, property: prop, init_val: 0); |
| 2864 | |
| 2865 | return 0; |
| 2866 | } |
| 2867 | EXPORT_SYMBOL(drm_connector_attach_hdr_output_metadata_property); |
| 2868 | |
| 2869 | /** |
| 2870 | * drm_connector_attach_broadcast_rgb_property - attach "Broadcast RGB" property |
| 2871 | * @connector: connector to attach the property on. |
| 2872 | * |
| 2873 | * This is used to add support for forcing the RGB range on a connector |
| 2874 | * |
| 2875 | * Returns: |
| 2876 | * Zero on success, negative errno on failure. |
| 2877 | */ |
| 2878 | int drm_connector_attach_broadcast_rgb_property(struct drm_connector *connector) |
| 2879 | { |
| 2880 | struct drm_device *dev = connector->dev; |
| 2881 | struct drm_property *prop; |
| 2882 | |
| 2883 | prop = connector->broadcast_rgb_property; |
| 2884 | if (!prop) { |
| 2885 | prop = drm_property_create_enum(dev, DRM_MODE_PROP_ENUM, |
| 2886 | name: "Broadcast RGB" , |
| 2887 | props: broadcast_rgb_names, |
| 2888 | ARRAY_SIZE(broadcast_rgb_names)); |
| 2889 | if (!prop) |
| 2890 | return -EINVAL; |
| 2891 | |
| 2892 | connector->broadcast_rgb_property = prop; |
| 2893 | } |
| 2894 | |
| 2895 | drm_object_attach_property(obj: &connector->base, property: prop, |
| 2896 | init_val: DRM_HDMI_BROADCAST_RGB_AUTO); |
| 2897 | |
| 2898 | return 0; |
| 2899 | } |
| 2900 | EXPORT_SYMBOL(drm_connector_attach_broadcast_rgb_property); |
| 2901 | |
| 2902 | /** |
| 2903 | * drm_connector_attach_colorspace_property - attach "Colorspace" property |
| 2904 | * @connector: connector to attach the property on. |
| 2905 | * |
| 2906 | * This is used to allow the userspace to signal the output colorspace |
| 2907 | * to the driver. |
| 2908 | * |
| 2909 | * Returns: |
| 2910 | * Zero on success, negative errno on failure. |
| 2911 | */ |
| 2912 | int drm_connector_attach_colorspace_property(struct drm_connector *connector) |
| 2913 | { |
| 2914 | struct drm_property *prop = connector->colorspace_property; |
| 2915 | |
| 2916 | drm_object_attach_property(obj: &connector->base, property: prop, init_val: DRM_MODE_COLORIMETRY_DEFAULT); |
| 2917 | |
| 2918 | return 0; |
| 2919 | } |
| 2920 | EXPORT_SYMBOL(drm_connector_attach_colorspace_property); |
| 2921 | |
| 2922 | /** |
| 2923 | * drm_connector_atomic_hdr_metadata_equal - checks if the hdr metadata changed |
| 2924 | * @old_state: old connector state to compare |
| 2925 | * @new_state: new connector state to compare |
| 2926 | * |
| 2927 | * This is used by HDR-enabled drivers to test whether the HDR metadata |
| 2928 | * have changed between two different connector state (and thus probably |
| 2929 | * requires a full blown mode change). |
| 2930 | * |
| 2931 | * Returns: |
| 2932 | * True if the metadata are equal, False otherwise |
| 2933 | */ |
| 2934 | bool drm_connector_atomic_hdr_metadata_equal(struct drm_connector_state *old_state, |
| 2935 | struct drm_connector_state *new_state) |
| 2936 | { |
| 2937 | struct drm_property_blob *old_blob = old_state->hdr_output_metadata; |
| 2938 | struct drm_property_blob *new_blob = new_state->hdr_output_metadata; |
| 2939 | |
| 2940 | if (!old_blob || !new_blob) |
| 2941 | return old_blob == new_blob; |
| 2942 | |
| 2943 | if (old_blob->length != new_blob->length) |
| 2944 | return false; |
| 2945 | |
| 2946 | return !memcmp(p: old_blob->data, q: new_blob->data, size: old_blob->length); |
| 2947 | } |
| 2948 | EXPORT_SYMBOL(drm_connector_atomic_hdr_metadata_equal); |
| 2949 | |
| 2950 | /** |
| 2951 | * drm_connector_set_vrr_capable_property - sets the variable refresh rate |
| 2952 | * capable property for a connector |
| 2953 | * @connector: drm connector |
| 2954 | * @capable: True if the connector is variable refresh rate capable |
| 2955 | * |
| 2956 | * Should be used by atomic drivers to update the indicated support for |
| 2957 | * variable refresh rate over a connector. |
| 2958 | */ |
| 2959 | void drm_connector_set_vrr_capable_property( |
| 2960 | struct drm_connector *connector, bool capable) |
| 2961 | { |
| 2962 | if (!connector->vrr_capable_property) |
| 2963 | return; |
| 2964 | |
| 2965 | drm_object_property_set_value(obj: &connector->base, |
| 2966 | property: connector->vrr_capable_property, |
| 2967 | val: capable); |
| 2968 | } |
| 2969 | EXPORT_SYMBOL(drm_connector_set_vrr_capable_property); |
| 2970 | |
| 2971 | /** |
| 2972 | * drm_connector_set_panel_orientation - sets the connector's panel_orientation |
| 2973 | * @connector: connector for which to set the panel-orientation property. |
| 2974 | * @panel_orientation: drm_panel_orientation value to set |
| 2975 | * |
| 2976 | * This function sets the connector's panel_orientation and attaches |
| 2977 | * a "panel orientation" property to the connector. |
| 2978 | * |
| 2979 | * Calling this function on a connector where the panel_orientation has |
| 2980 | * already been set is a no-op (e.g. the orientation has been overridden with |
| 2981 | * a kernel commandline option). |
| 2982 | * |
| 2983 | * It is allowed to call this function with a panel_orientation of |
| 2984 | * DRM_MODE_PANEL_ORIENTATION_UNKNOWN, in which case it is a no-op. |
| 2985 | * |
| 2986 | * The function shouldn't be called in panel after drm is registered (i.e. |
| 2987 | * drm_dev_register() is called in drm). |
| 2988 | * |
| 2989 | * Returns: |
| 2990 | * Zero on success, negative errno on failure. |
| 2991 | */ |
| 2992 | int drm_connector_set_panel_orientation( |
| 2993 | struct drm_connector *connector, |
| 2994 | enum drm_panel_orientation panel_orientation) |
| 2995 | { |
| 2996 | struct drm_device *dev = connector->dev; |
| 2997 | struct drm_display_info *info = &connector->display_info; |
| 2998 | struct drm_property *prop; |
| 2999 | |
| 3000 | /* Already set? */ |
| 3001 | if (info->panel_orientation != DRM_MODE_PANEL_ORIENTATION_UNKNOWN) |
| 3002 | return 0; |
| 3003 | |
| 3004 | /* Don't attach the property if the orientation is unknown */ |
| 3005 | if (panel_orientation == DRM_MODE_PANEL_ORIENTATION_UNKNOWN) |
| 3006 | return 0; |
| 3007 | |
| 3008 | info->panel_orientation = panel_orientation; |
| 3009 | |
| 3010 | prop = dev->mode_config.panel_orientation_property; |
| 3011 | if (!prop) { |
| 3012 | prop = drm_property_create_enum(dev, DRM_MODE_PROP_IMMUTABLE, |
| 3013 | name: "panel orientation" , |
| 3014 | props: drm_panel_orientation_enum_list, |
| 3015 | ARRAY_SIZE(drm_panel_orientation_enum_list)); |
| 3016 | if (!prop) |
| 3017 | return -ENOMEM; |
| 3018 | |
| 3019 | dev->mode_config.panel_orientation_property = prop; |
| 3020 | } |
| 3021 | |
| 3022 | drm_object_attach_property(obj: &connector->base, property: prop, |
| 3023 | init_val: info->panel_orientation); |
| 3024 | return 0; |
| 3025 | } |
| 3026 | EXPORT_SYMBOL(drm_connector_set_panel_orientation); |
| 3027 | |
| 3028 | /** |
| 3029 | * drm_connector_set_panel_orientation_with_quirk - set the |
| 3030 | * connector's panel_orientation after checking for quirks |
| 3031 | * @connector: connector for which to init the panel-orientation property. |
| 3032 | * @panel_orientation: drm_panel_orientation value to set |
| 3033 | * @width: width in pixels of the panel, used for panel quirk detection |
| 3034 | * @height: height in pixels of the panel, used for panel quirk detection |
| 3035 | * |
| 3036 | * Like drm_connector_set_panel_orientation(), but with a check for platform |
| 3037 | * specific (e.g. DMI based) quirks overriding the passed in panel_orientation. |
| 3038 | * |
| 3039 | * Returns: |
| 3040 | * Zero on success, negative errno on failure. |
| 3041 | */ |
| 3042 | int drm_connector_set_panel_orientation_with_quirk( |
| 3043 | struct drm_connector *connector, |
| 3044 | enum drm_panel_orientation panel_orientation, |
| 3045 | int width, int height) |
| 3046 | { |
| 3047 | int orientation_quirk; |
| 3048 | |
| 3049 | orientation_quirk = drm_get_panel_orientation_quirk(width, height); |
| 3050 | if (orientation_quirk != DRM_MODE_PANEL_ORIENTATION_UNKNOWN) |
| 3051 | panel_orientation = orientation_quirk; |
| 3052 | |
| 3053 | return drm_connector_set_panel_orientation(connector, |
| 3054 | panel_orientation); |
| 3055 | } |
| 3056 | EXPORT_SYMBOL(drm_connector_set_panel_orientation_with_quirk); |
| 3057 | |
| 3058 | /** |
| 3059 | * drm_connector_set_orientation_from_panel - |
| 3060 | * set the connector's panel_orientation from panel's callback. |
| 3061 | * @connector: connector for which to init the panel-orientation property. |
| 3062 | * @panel: panel that can provide orientation information. |
| 3063 | * |
| 3064 | * Drm drivers should call this function before drm_dev_register(). |
| 3065 | * Orientation is obtained from panel's .get_orientation() callback. |
| 3066 | * |
| 3067 | * Returns: |
| 3068 | * Zero on success, negative errno on failure. |
| 3069 | */ |
| 3070 | int drm_connector_set_orientation_from_panel( |
| 3071 | struct drm_connector *connector, |
| 3072 | struct drm_panel *panel) |
| 3073 | { |
| 3074 | enum drm_panel_orientation orientation; |
| 3075 | |
| 3076 | if (panel && panel->funcs && panel->funcs->get_orientation) |
| 3077 | orientation = panel->funcs->get_orientation(panel); |
| 3078 | else |
| 3079 | orientation = DRM_MODE_PANEL_ORIENTATION_UNKNOWN; |
| 3080 | |
| 3081 | return drm_connector_set_panel_orientation(connector, orientation); |
| 3082 | } |
| 3083 | EXPORT_SYMBOL(drm_connector_set_orientation_from_panel); |
| 3084 | |
| 3085 | static const struct drm_prop_enum_list privacy_screen_enum[] = { |
| 3086 | { PRIVACY_SCREEN_DISABLED, "Disabled" }, |
| 3087 | { PRIVACY_SCREEN_ENABLED, "Enabled" }, |
| 3088 | { PRIVACY_SCREEN_DISABLED_LOCKED, "Disabled-locked" }, |
| 3089 | { PRIVACY_SCREEN_ENABLED_LOCKED, "Enabled-locked" }, |
| 3090 | }; |
| 3091 | |
| 3092 | /** |
| 3093 | * drm_connector_create_privacy_screen_properties - create the drm connecter's |
| 3094 | * privacy-screen properties. |
| 3095 | * @connector: connector for which to create the privacy-screen properties |
| 3096 | * |
| 3097 | * This function creates the "privacy-screen sw-state" and "privacy-screen |
| 3098 | * hw-state" properties for the connector. They are not attached. |
| 3099 | */ |
| 3100 | void |
| 3101 | drm_connector_create_privacy_screen_properties(struct drm_connector *connector) |
| 3102 | { |
| 3103 | if (connector->privacy_screen_sw_state_property) |
| 3104 | return; |
| 3105 | |
| 3106 | /* Note sw-state only supports the first 2 values of the enum */ |
| 3107 | connector->privacy_screen_sw_state_property = |
| 3108 | drm_property_create_enum(dev: connector->dev, DRM_MODE_PROP_ENUM, |
| 3109 | name: "privacy-screen sw-state" , |
| 3110 | props: privacy_screen_enum, num_values: 2); |
| 3111 | |
| 3112 | connector->privacy_screen_hw_state_property = |
| 3113 | drm_property_create_enum(dev: connector->dev, |
| 3114 | DRM_MODE_PROP_IMMUTABLE | DRM_MODE_PROP_ENUM, |
| 3115 | name: "privacy-screen hw-state" , |
| 3116 | props: privacy_screen_enum, |
| 3117 | ARRAY_SIZE(privacy_screen_enum)); |
| 3118 | } |
| 3119 | EXPORT_SYMBOL(drm_connector_create_privacy_screen_properties); |
| 3120 | |
| 3121 | /** |
| 3122 | * drm_connector_attach_privacy_screen_properties - attach the drm connecter's |
| 3123 | * privacy-screen properties. |
| 3124 | * @connector: connector on which to attach the privacy-screen properties |
| 3125 | * |
| 3126 | * This function attaches the "privacy-screen sw-state" and "privacy-screen |
| 3127 | * hw-state" properties to the connector. The initial state of both is set |
| 3128 | * to "Disabled". |
| 3129 | */ |
| 3130 | void |
| 3131 | drm_connector_attach_privacy_screen_properties(struct drm_connector *connector) |
| 3132 | { |
| 3133 | if (!connector->privacy_screen_sw_state_property) |
| 3134 | return; |
| 3135 | |
| 3136 | drm_object_attach_property(obj: &connector->base, |
| 3137 | property: connector->privacy_screen_sw_state_property, |
| 3138 | init_val: PRIVACY_SCREEN_DISABLED); |
| 3139 | |
| 3140 | drm_object_attach_property(obj: &connector->base, |
| 3141 | property: connector->privacy_screen_hw_state_property, |
| 3142 | init_val: PRIVACY_SCREEN_DISABLED); |
| 3143 | } |
| 3144 | EXPORT_SYMBOL(drm_connector_attach_privacy_screen_properties); |
| 3145 | |
| 3146 | static void drm_connector_update_privacy_screen_properties( |
| 3147 | struct drm_connector *connector, bool set_sw_state) |
| 3148 | { |
| 3149 | enum drm_privacy_screen_status sw_state, hw_state; |
| 3150 | |
| 3151 | drm_privacy_screen_get_state(priv: connector->privacy_screen, |
| 3152 | sw_state_ret: &sw_state, hw_state_ret: &hw_state); |
| 3153 | |
| 3154 | if (set_sw_state) |
| 3155 | connector->state->privacy_screen_sw_state = sw_state; |
| 3156 | drm_object_property_set_value(obj: &connector->base, |
| 3157 | property: connector->privacy_screen_hw_state_property, val: hw_state); |
| 3158 | } |
| 3159 | |
| 3160 | static int drm_connector_privacy_screen_notifier( |
| 3161 | struct notifier_block *nb, unsigned long action, void *data) |
| 3162 | { |
| 3163 | struct drm_connector *connector = |
| 3164 | container_of(nb, struct drm_connector, privacy_screen_notifier); |
| 3165 | struct drm_device *dev = connector->dev; |
| 3166 | |
| 3167 | drm_modeset_lock(lock: &dev->mode_config.connection_mutex, NULL); |
| 3168 | drm_connector_update_privacy_screen_properties(connector, set_sw_state: true); |
| 3169 | drm_modeset_unlock(lock: &dev->mode_config.connection_mutex); |
| 3170 | |
| 3171 | drm_sysfs_connector_property_event(connector, |
| 3172 | property: connector->privacy_screen_sw_state_property); |
| 3173 | drm_sysfs_connector_property_event(connector, |
| 3174 | property: connector->privacy_screen_hw_state_property); |
| 3175 | |
| 3176 | return NOTIFY_DONE; |
| 3177 | } |
| 3178 | |
| 3179 | /** |
| 3180 | * drm_connector_attach_privacy_screen_provider - attach a privacy-screen to |
| 3181 | * the connector |
| 3182 | * @connector: connector to attach the privacy-screen to |
| 3183 | * @priv: drm_privacy_screen to attach |
| 3184 | * |
| 3185 | * Create and attach the standard privacy-screen properties and register |
| 3186 | * a generic notifier for generating sysfs-connector-status-events |
| 3187 | * on external changes to the privacy-screen status. |
| 3188 | * This function takes ownership of the passed in drm_privacy_screen and will |
| 3189 | * call drm_privacy_screen_put() on it when the connector is destroyed. |
| 3190 | */ |
| 3191 | void drm_connector_attach_privacy_screen_provider( |
| 3192 | struct drm_connector *connector, struct drm_privacy_screen *priv) |
| 3193 | { |
| 3194 | connector->privacy_screen = priv; |
| 3195 | connector->privacy_screen_notifier.notifier_call = |
| 3196 | drm_connector_privacy_screen_notifier; |
| 3197 | |
| 3198 | drm_connector_create_privacy_screen_properties(connector); |
| 3199 | drm_connector_update_privacy_screen_properties(connector, set_sw_state: true); |
| 3200 | drm_connector_attach_privacy_screen_properties(connector); |
| 3201 | } |
| 3202 | EXPORT_SYMBOL(drm_connector_attach_privacy_screen_provider); |
| 3203 | |
| 3204 | /** |
| 3205 | * drm_connector_update_privacy_screen - update connector's privacy-screen sw-state |
| 3206 | * @connector_state: connector-state to update the privacy-screen for |
| 3207 | * |
| 3208 | * This function calls drm_privacy_screen_set_sw_state() on the connector's |
| 3209 | * privacy-screen. |
| 3210 | * |
| 3211 | * If the connector has no privacy-screen, then this is a no-op. |
| 3212 | */ |
| 3213 | void drm_connector_update_privacy_screen(const struct drm_connector_state *connector_state) |
| 3214 | { |
| 3215 | struct drm_connector *connector = connector_state->connector; |
| 3216 | int ret; |
| 3217 | |
| 3218 | if (!connector->privacy_screen) |
| 3219 | return; |
| 3220 | |
| 3221 | ret = drm_privacy_screen_set_sw_state(priv: connector->privacy_screen, |
| 3222 | sw_state: connector_state->privacy_screen_sw_state); |
| 3223 | if (ret) { |
| 3224 | drm_err(connector->dev, "Error updating privacy-screen sw_state\n" ); |
| 3225 | return; |
| 3226 | } |
| 3227 | |
| 3228 | /* The hw_state property value may have changed, update it. */ |
| 3229 | drm_connector_update_privacy_screen_properties(connector, set_sw_state: false); |
| 3230 | } |
| 3231 | EXPORT_SYMBOL(drm_connector_update_privacy_screen); |
| 3232 | |
| 3233 | int drm_connector_set_obj_prop(struct drm_mode_object *obj, |
| 3234 | struct drm_property *property, |
| 3235 | uint64_t value) |
| 3236 | { |
| 3237 | int ret = -EINVAL; |
| 3238 | struct drm_connector *connector = obj_to_connector(obj); |
| 3239 | |
| 3240 | /* Do DPMS ourselves */ |
| 3241 | if (property == connector->dev->mode_config.dpms_property) { |
| 3242 | ret = (*connector->funcs->dpms)(connector, (int)value); |
| 3243 | } else if (connector->funcs->set_property) |
| 3244 | ret = connector->funcs->set_property(connector, property, value); |
| 3245 | |
| 3246 | if (!ret) |
| 3247 | drm_object_property_set_value(obj: &connector->base, property, val: value); |
| 3248 | return ret; |
| 3249 | } |
| 3250 | |
| 3251 | int drm_connector_property_set_ioctl(struct drm_device *dev, |
| 3252 | void *data, struct drm_file *file_priv) |
| 3253 | { |
| 3254 | struct drm_mode_connector_set_property *conn_set_prop = data; |
| 3255 | struct drm_mode_obj_set_property obj_set_prop = { |
| 3256 | .value = conn_set_prop->value, |
| 3257 | .prop_id = conn_set_prop->prop_id, |
| 3258 | .obj_id = conn_set_prop->connector_id, |
| 3259 | .obj_type = DRM_MODE_OBJECT_CONNECTOR |
| 3260 | }; |
| 3261 | |
| 3262 | /* It does all the locking and checking we need */ |
| 3263 | return drm_mode_obj_set_property_ioctl(dev, data: &obj_set_prop, file_priv); |
| 3264 | } |
| 3265 | |
| 3266 | static struct drm_encoder *drm_connector_get_encoder(struct drm_connector *connector) |
| 3267 | { |
| 3268 | /* For atomic drivers only state objects are synchronously updated and |
| 3269 | * protected by modeset locks, so check those first. |
| 3270 | */ |
| 3271 | if (connector->state) |
| 3272 | return connector->state->best_encoder; |
| 3273 | return connector->encoder; |
| 3274 | } |
| 3275 | |
| 3276 | static bool |
| 3277 | drm_mode_expose_to_userspace(const struct drm_display_mode *mode, |
| 3278 | const struct list_head *modes, |
| 3279 | const struct drm_file *file_priv) |
| 3280 | { |
| 3281 | /* |
| 3282 | * If user-space hasn't configured the driver to expose the stereo 3D |
| 3283 | * modes, don't expose them. |
| 3284 | */ |
| 3285 | if (!file_priv->stereo_allowed && drm_mode_is_stereo(mode)) |
| 3286 | return false; |
| 3287 | /* |
| 3288 | * If user-space hasn't configured the driver to expose the modes |
| 3289 | * with aspect-ratio, don't expose them. However if such a mode |
| 3290 | * is unique, let it be exposed, but reset the aspect-ratio flags |
| 3291 | * while preparing the list of user-modes. |
| 3292 | */ |
| 3293 | if (!file_priv->aspect_ratio_allowed) { |
| 3294 | const struct drm_display_mode *mode_itr; |
| 3295 | |
| 3296 | list_for_each_entry(mode_itr, modes, head) { |
| 3297 | if (mode_itr->expose_to_userspace && |
| 3298 | drm_mode_match(mode1: mode_itr, mode2: mode, |
| 3299 | DRM_MODE_MATCH_TIMINGS | |
| 3300 | DRM_MODE_MATCH_CLOCK | |
| 3301 | DRM_MODE_MATCH_FLAGS | |
| 3302 | DRM_MODE_MATCH_3D_FLAGS)) |
| 3303 | return false; |
| 3304 | } |
| 3305 | } |
| 3306 | |
| 3307 | return true; |
| 3308 | } |
| 3309 | |
| 3310 | int drm_mode_getconnector(struct drm_device *dev, void *data, |
| 3311 | struct drm_file *file_priv) |
| 3312 | { |
| 3313 | struct drm_mode_get_connector *out_resp = data; |
| 3314 | struct drm_connector *connector; |
| 3315 | struct drm_encoder *encoder; |
| 3316 | struct drm_display_mode *mode; |
| 3317 | int mode_count = 0; |
| 3318 | int encoders_count = 0; |
| 3319 | int ret = 0; |
| 3320 | int copied = 0; |
| 3321 | struct drm_mode_modeinfo u_mode; |
| 3322 | struct drm_mode_modeinfo __user *mode_ptr; |
| 3323 | uint32_t __user *encoder_ptr; |
| 3324 | bool is_current_master; |
| 3325 | |
| 3326 | if (!drm_core_check_feature(dev, feature: DRIVER_MODESET)) |
| 3327 | return -EOPNOTSUPP; |
| 3328 | |
| 3329 | memset(&u_mode, 0, sizeof(struct drm_mode_modeinfo)); |
| 3330 | |
| 3331 | connector = drm_connector_lookup(dev, file_priv, id: out_resp->connector_id); |
| 3332 | if (!connector) |
| 3333 | return -ENOENT; |
| 3334 | |
| 3335 | encoders_count = hweight32(connector->possible_encoders); |
| 3336 | |
| 3337 | if ((out_resp->count_encoders >= encoders_count) && encoders_count) { |
| 3338 | copied = 0; |
| 3339 | encoder_ptr = (uint32_t __user *)(unsigned long)(out_resp->encoders_ptr); |
| 3340 | |
| 3341 | drm_connector_for_each_possible_encoder(connector, encoder) { |
| 3342 | if (put_user(encoder->base.id, encoder_ptr + copied)) { |
| 3343 | ret = -EFAULT; |
| 3344 | goto out; |
| 3345 | } |
| 3346 | copied++; |
| 3347 | } |
| 3348 | } |
| 3349 | out_resp->count_encoders = encoders_count; |
| 3350 | |
| 3351 | out_resp->connector_id = connector->base.id; |
| 3352 | out_resp->connector_type = connector->connector_type; |
| 3353 | out_resp->connector_type_id = connector->connector_type_id; |
| 3354 | |
| 3355 | is_current_master = drm_is_current_master(fpriv: file_priv); |
| 3356 | |
| 3357 | mutex_lock(&dev->mode_config.mutex); |
| 3358 | if (out_resp->count_modes == 0) { |
| 3359 | if (is_current_master) |
| 3360 | connector->funcs->fill_modes(connector, |
| 3361 | dev->mode_config.max_width, |
| 3362 | dev->mode_config.max_height); |
| 3363 | else |
| 3364 | drm_dbg_kms(dev, "User-space requested a forced probe on [CONNECTOR:%d:%s] but is not the DRM master, demoting to read-only probe\n" , |
| 3365 | connector->base.id, connector->name); |
| 3366 | } |
| 3367 | |
| 3368 | out_resp->mm_width = connector->display_info.width_mm; |
| 3369 | out_resp->mm_height = connector->display_info.height_mm; |
| 3370 | out_resp->subpixel = connector->display_info.subpixel_order; |
| 3371 | out_resp->connection = connector->status; |
| 3372 | |
| 3373 | /* delayed so we get modes regardless of pre-fill_modes state */ |
| 3374 | list_for_each_entry(mode, &connector->modes, head) { |
| 3375 | WARN_ON(mode->expose_to_userspace); |
| 3376 | |
| 3377 | if (drm_mode_expose_to_userspace(mode, modes: &connector->modes, |
| 3378 | file_priv)) { |
| 3379 | mode->expose_to_userspace = true; |
| 3380 | mode_count++; |
| 3381 | } |
| 3382 | } |
| 3383 | |
| 3384 | /* |
| 3385 | * This ioctl is called twice, once to determine how much space is |
| 3386 | * needed, and the 2nd time to fill it. |
| 3387 | */ |
| 3388 | if ((out_resp->count_modes >= mode_count) && mode_count) { |
| 3389 | copied = 0; |
| 3390 | mode_ptr = (struct drm_mode_modeinfo __user *)(unsigned long)out_resp->modes_ptr; |
| 3391 | list_for_each_entry(mode, &connector->modes, head) { |
| 3392 | if (!mode->expose_to_userspace) |
| 3393 | continue; |
| 3394 | |
| 3395 | /* Clear the tag for the next time around */ |
| 3396 | mode->expose_to_userspace = false; |
| 3397 | |
| 3398 | drm_mode_convert_to_umode(out: &u_mode, in: mode); |
| 3399 | /* |
| 3400 | * Reset aspect ratio flags of user-mode, if modes with |
| 3401 | * aspect-ratio are not supported. |
| 3402 | */ |
| 3403 | if (!file_priv->aspect_ratio_allowed) |
| 3404 | u_mode.flags &= ~DRM_MODE_FLAG_PIC_AR_MASK; |
| 3405 | if (copy_to_user(to: mode_ptr + copied, |
| 3406 | from: &u_mode, n: sizeof(u_mode))) { |
| 3407 | ret = -EFAULT; |
| 3408 | |
| 3409 | /* |
| 3410 | * Clear the tag for the rest of |
| 3411 | * the modes for the next time around. |
| 3412 | */ |
| 3413 | list_for_each_entry_continue(mode, &connector->modes, head) |
| 3414 | mode->expose_to_userspace = false; |
| 3415 | |
| 3416 | mutex_unlock(lock: &dev->mode_config.mutex); |
| 3417 | |
| 3418 | goto out; |
| 3419 | } |
| 3420 | copied++; |
| 3421 | } |
| 3422 | } else { |
| 3423 | /* Clear the tag for the next time around */ |
| 3424 | list_for_each_entry(mode, &connector->modes, head) |
| 3425 | mode->expose_to_userspace = false; |
| 3426 | } |
| 3427 | |
| 3428 | out_resp->count_modes = mode_count; |
| 3429 | mutex_unlock(lock: &dev->mode_config.mutex); |
| 3430 | |
| 3431 | drm_modeset_lock(lock: &dev->mode_config.connection_mutex, NULL); |
| 3432 | encoder = drm_connector_get_encoder(connector); |
| 3433 | if (encoder) |
| 3434 | out_resp->encoder_id = encoder->base.id; |
| 3435 | else |
| 3436 | out_resp->encoder_id = 0; |
| 3437 | |
| 3438 | /* Only grab properties after probing, to make sure EDID and other |
| 3439 | * properties reflect the latest status. |
| 3440 | */ |
| 3441 | ret = drm_mode_object_get_properties(obj: &connector->base, atomic: file_priv->atomic, |
| 3442 | plane_color_pipeline: file_priv->plane_color_pipeline, |
| 3443 | prop_ptr: (uint32_t __user *)(unsigned long)(out_resp->props_ptr), |
| 3444 | prop_values: (uint64_t __user *)(unsigned long)(out_resp->prop_values_ptr), |
| 3445 | arg_count_props: &out_resp->count_props); |
| 3446 | drm_modeset_unlock(lock: &dev->mode_config.connection_mutex); |
| 3447 | |
| 3448 | out: |
| 3449 | drm_connector_put(connector); |
| 3450 | |
| 3451 | return ret; |
| 3452 | } |
| 3453 | |
| 3454 | /** |
| 3455 | * drm_connector_find_by_fwnode - Find a connector based on the associated fwnode |
| 3456 | * @fwnode: fwnode for which to find the matching drm_connector |
| 3457 | * |
| 3458 | * This functions looks up a drm_connector based on its associated fwnode. When |
| 3459 | * a connector is found a reference to the connector is returned. The caller must |
| 3460 | * call drm_connector_put() to release this reference when it is done with the |
| 3461 | * connector. |
| 3462 | * |
| 3463 | * Returns: A reference to the found connector or an ERR_PTR(). |
| 3464 | */ |
| 3465 | struct drm_connector *drm_connector_find_by_fwnode(struct fwnode_handle *fwnode) |
| 3466 | { |
| 3467 | struct drm_connector *connector, *found = ERR_PTR(error: -ENODEV); |
| 3468 | |
| 3469 | if (!fwnode) |
| 3470 | return ERR_PTR(error: -ENODEV); |
| 3471 | |
| 3472 | mutex_lock(&connector_list_lock); |
| 3473 | |
| 3474 | list_for_each_entry(connector, &connector_list, global_connector_list_entry) { |
| 3475 | if (connector->fwnode == fwnode || |
| 3476 | (connector->fwnode && connector->fwnode->secondary == fwnode)) { |
| 3477 | drm_connector_get(connector); |
| 3478 | found = connector; |
| 3479 | break; |
| 3480 | } |
| 3481 | } |
| 3482 | |
| 3483 | mutex_unlock(lock: &connector_list_lock); |
| 3484 | |
| 3485 | return found; |
| 3486 | } |
| 3487 | |
| 3488 | /** |
| 3489 | * drm_connector_oob_hotplug_event - Report out-of-band hotplug event to connector |
| 3490 | * @connector_fwnode: fwnode_handle to report the event on |
| 3491 | * @status: hot plug detect logical state |
| 3492 | * |
| 3493 | * On some hardware a hotplug event notification may come from outside the display |
| 3494 | * driver / device. An example of this is some USB Type-C setups where the hardware |
| 3495 | * muxes the DisplayPort data and aux-lines but does not pass the altmode HPD |
| 3496 | * status bit to the GPU's DP HPD pin. |
| 3497 | * |
| 3498 | * This function can be used to report these out-of-band events after obtaining |
| 3499 | * a drm_connector reference through calling drm_connector_find_by_fwnode(). |
| 3500 | */ |
| 3501 | void drm_connector_oob_hotplug_event(struct fwnode_handle *connector_fwnode, |
| 3502 | enum drm_connector_status status) |
| 3503 | { |
| 3504 | struct drm_connector *connector; |
| 3505 | |
| 3506 | connector = drm_connector_find_by_fwnode(fwnode: connector_fwnode); |
| 3507 | if (IS_ERR(ptr: connector)) |
| 3508 | return; |
| 3509 | |
| 3510 | if (connector->funcs->oob_hotplug_event) |
| 3511 | connector->funcs->oob_hotplug_event(connector, status); |
| 3512 | |
| 3513 | drm_connector_put(connector); |
| 3514 | } |
| 3515 | EXPORT_SYMBOL(drm_connector_oob_hotplug_event); |
| 3516 | |
| 3517 | |
| 3518 | /** |
| 3519 | * DOC: Tile group |
| 3520 | * |
| 3521 | * Tile groups are used to represent tiled monitors with a unique integer |
| 3522 | * identifier. Tiled monitors using DisplayID v1.3 have a unique 8-byte handle, |
| 3523 | * we store this in a tile group, so we have a common identifier for all tiles |
| 3524 | * in a monitor group. The property is called "TILE". Drivers can manage tile |
| 3525 | * groups using drm_mode_create_tile_group(), drm_mode_put_tile_group() and |
| 3526 | * drm_mode_get_tile_group(). But this is only needed for internal panels where |
| 3527 | * the tile group information is exposed through a non-standard way. |
| 3528 | */ |
| 3529 | |
| 3530 | static void drm_tile_group_free(struct kref *kref) |
| 3531 | { |
| 3532 | struct drm_tile_group *tg = container_of(kref, struct drm_tile_group, refcount); |
| 3533 | struct drm_device *dev = tg->dev; |
| 3534 | |
| 3535 | mutex_lock(&dev->mode_config.idr_mutex); |
| 3536 | idr_remove(&dev->mode_config.tile_idr, id: tg->id); |
| 3537 | mutex_unlock(lock: &dev->mode_config.idr_mutex); |
| 3538 | kfree(objp: tg); |
| 3539 | } |
| 3540 | |
| 3541 | /** |
| 3542 | * drm_mode_put_tile_group - drop a reference to a tile group. |
| 3543 | * @dev: DRM device |
| 3544 | * @tg: tile group to drop reference to. |
| 3545 | * |
| 3546 | * drop reference to tile group and free if 0. |
| 3547 | */ |
| 3548 | void drm_mode_put_tile_group(struct drm_device *dev, |
| 3549 | struct drm_tile_group *tg) |
| 3550 | { |
| 3551 | kref_put(kref: &tg->refcount, release: drm_tile_group_free); |
| 3552 | } |
| 3553 | EXPORT_SYMBOL(drm_mode_put_tile_group); |
| 3554 | |
| 3555 | /** |
| 3556 | * drm_mode_get_tile_group - get a reference to an existing tile group |
| 3557 | * @dev: DRM device |
| 3558 | * @topology: 8-bytes unique per monitor. |
| 3559 | * |
| 3560 | * Use the unique bytes to get a reference to an existing tile group. |
| 3561 | * |
| 3562 | * RETURNS: |
| 3563 | * tile group or NULL if not found. |
| 3564 | */ |
| 3565 | struct drm_tile_group *drm_mode_get_tile_group(struct drm_device *dev, |
| 3566 | const char topology[8]) |
| 3567 | { |
| 3568 | struct drm_tile_group *tg; |
| 3569 | int id; |
| 3570 | |
| 3571 | mutex_lock(&dev->mode_config.idr_mutex); |
| 3572 | idr_for_each_entry(&dev->mode_config.tile_idr, tg, id) { |
| 3573 | if (!memcmp(p: tg->group_data, q: topology, size: 8)) { |
| 3574 | if (!kref_get_unless_zero(kref: &tg->refcount)) |
| 3575 | tg = NULL; |
| 3576 | mutex_unlock(lock: &dev->mode_config.idr_mutex); |
| 3577 | return tg; |
| 3578 | } |
| 3579 | } |
| 3580 | mutex_unlock(lock: &dev->mode_config.idr_mutex); |
| 3581 | return NULL; |
| 3582 | } |
| 3583 | EXPORT_SYMBOL(drm_mode_get_tile_group); |
| 3584 | |
| 3585 | /** |
| 3586 | * drm_mode_create_tile_group - create a tile group from a displayid description |
| 3587 | * @dev: DRM device |
| 3588 | * @topology: 8-bytes unique per monitor. |
| 3589 | * |
| 3590 | * Create a tile group for the unique monitor, and get a unique |
| 3591 | * identifier for the tile group. |
| 3592 | * |
| 3593 | * RETURNS: |
| 3594 | * new tile group or NULL. |
| 3595 | */ |
| 3596 | struct drm_tile_group *drm_mode_create_tile_group(struct drm_device *dev, |
| 3597 | const char topology[8]) |
| 3598 | { |
| 3599 | struct drm_tile_group *tg; |
| 3600 | int ret; |
| 3601 | |
| 3602 | tg = kzalloc(sizeof(*tg), GFP_KERNEL); |
| 3603 | if (!tg) |
| 3604 | return NULL; |
| 3605 | |
| 3606 | kref_init(kref: &tg->refcount); |
| 3607 | memcpy(tg->group_data, topology, 8); |
| 3608 | tg->dev = dev; |
| 3609 | |
| 3610 | mutex_lock(&dev->mode_config.idr_mutex); |
| 3611 | ret = idr_alloc(&dev->mode_config.tile_idr, ptr: tg, start: 1, end: 0, GFP_KERNEL); |
| 3612 | if (ret >= 0) { |
| 3613 | tg->id = ret; |
| 3614 | } else { |
| 3615 | kfree(objp: tg); |
| 3616 | tg = NULL; |
| 3617 | } |
| 3618 | |
| 3619 | mutex_unlock(lock: &dev->mode_config.idr_mutex); |
| 3620 | return tg; |
| 3621 | } |
| 3622 | EXPORT_SYMBOL(drm_mode_create_tile_group); |
| 3623 | |