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/drmP.h> 24 #include <drm/drm_connector.h> 25 #include <drm/drm_edid.h> 26 #include <drm/drm_encoder.h> 27 #include <drm/drm_utils.h> 28 29 #include "drm_crtc_internal.h" 30 #include "drm_internal.h" 31 32 /** 33 * DOC: overview 34 * 35 * In DRM connectors are the general abstraction for display sinks, and include 36 * als fixed panels or anything else that can display pixels in some form. As 37 * opposed to all other KMS objects representing hardware (like CRTC, encoder or 38 * plane abstractions) connectors can be hotplugged and unplugged at runtime. 39 * Hence they are reference-counted using drm_connector_get() and 40 * drm_connector_put(). 41 * 42 * KMS driver must create, initialize, register and attach at a &struct 43 * drm_connector for each such sink. The instance is created as other KMS 44 * objects and initialized by setting the following fields. The connector is 45 * initialized with a call to drm_connector_init() with a pointer to the 46 * &struct drm_connector_funcs and a connector type, and then exposed to 47 * userspace with a call to drm_connector_register(). 48 * 49 * Connectors must be attached to an encoder to be used. For devices that map 50 * connectors to encoders 1:1, the connector should be attached at 51 * initialization time with a call to drm_connector_attach_encoder(). The 52 * driver must also set the &drm_connector.encoder field to point to the 53 * attached encoder. 54 * 55 * For connectors which are not fixed (like built-in panels) the driver needs to 56 * support hotplug notifications. The simplest way to do that is by using the 57 * probe helpers, see drm_kms_helper_poll_init() for connectors which don't have 58 * hardware support for hotplug interrupts. Connectors with hardware hotplug 59 * support can instead use e.g. drm_helper_hpd_irq_event(). 60 */ 61 62 struct drm_conn_prop_enum_list { 63 int type; 64 const char *name; 65 struct ida ida; 66 }; 67 68 /* 69 * Connector and encoder types. 70 */ 71 static struct drm_conn_prop_enum_list drm_connector_enum_list[] = { 72 { DRM_MODE_CONNECTOR_Unknown, "Unknown" }, 73 { DRM_MODE_CONNECTOR_VGA, "VGA" }, 74 { DRM_MODE_CONNECTOR_DVII, "DVI-I" }, 75 { DRM_MODE_CONNECTOR_DVID, "DVI-D" }, 76 { DRM_MODE_CONNECTOR_DVIA, "DVI-A" }, 77 { DRM_MODE_CONNECTOR_Composite, "Composite" }, 78 { DRM_MODE_CONNECTOR_SVIDEO, "SVIDEO" }, 79 { DRM_MODE_CONNECTOR_LVDS, "LVDS" }, 80 { DRM_MODE_CONNECTOR_Component, "Component" }, 81 { DRM_MODE_CONNECTOR_9PinDIN, "DIN" }, 82 { DRM_MODE_CONNECTOR_DisplayPort, "DP" }, 83 { DRM_MODE_CONNECTOR_HDMIA, "HDMI-A" }, 84 { DRM_MODE_CONNECTOR_HDMIB, "HDMI-B" }, 85 { DRM_MODE_CONNECTOR_TV, "TV" }, 86 { DRM_MODE_CONNECTOR_eDP, "eDP" }, 87 { DRM_MODE_CONNECTOR_VIRTUAL, "Virtual" }, 88 { DRM_MODE_CONNECTOR_DSI, "DSI" }, 89 { DRM_MODE_CONNECTOR_DPI, "DPI" }, 90 { DRM_MODE_CONNECTOR_WRITEBACK, "Writeback" }, 91 }; 92 93 void drm_connector_ida_init(void) 94 { 95 int i; 96 97 for (i = 0; i < ARRAY_SIZE(drm_connector_enum_list); i++) 98 ida_init(&drm_connector_enum_list[i].ida); 99 } 100 101 void drm_connector_ida_destroy(void) 102 { 103 int i; 104 105 for (i = 0; i < ARRAY_SIZE(drm_connector_enum_list); i++) 106 ida_destroy(&drm_connector_enum_list[i].ida); 107 } 108 109 /** 110 * drm_connector_get_cmdline_mode - reads the user's cmdline mode 111 * @connector: connector to quwery 112 * 113 * The kernel supports per-connector configuration of its consoles through 114 * use of the video= parameter. This function parses that option and 115 * extracts the user's specified mode (or enable/disable status) for a 116 * particular connector. This is typically only used during the early fbdev 117 * setup. 118 */ 119 static void drm_connector_get_cmdline_mode(struct drm_connector *connector) 120 { 121 struct drm_cmdline_mode *mode = &connector->cmdline_mode; 122 char *option = NULL; 123 124 #ifdef __linux__ 125 if (fb_get_options(connector->name, &option)) 126 return; 127 #endif 128 129 if (!drm_mode_parse_command_line_for_connector(option, 130 connector, 131 mode)) 132 return; 133 134 if (mode->force) { 135 DRM_INFO("forcing %s connector %s\n", connector->name, 136 drm_get_connector_force_name(mode->force)); 137 connector->force = mode->force; 138 } 139 140 DRM_DEBUG_KMS("cmdline mode for connector %s %dx%d@%dHz%s%s%s\n", 141 connector->name, 142 mode->xres, mode->yres, 143 mode->refresh_specified ? mode->refresh : 60, 144 mode->rb ? " reduced blanking" : "", 145 mode->margins ? " with margins" : "", 146 mode->interlace ? " interlaced" : ""); 147 } 148 149 static void drm_connector_free(struct kref *kref) 150 { 151 struct drm_connector *connector = 152 container_of(kref, struct drm_connector, base.refcount); 153 struct drm_device *dev = connector->dev; 154 155 drm_mode_object_unregister(dev, &connector->base); 156 connector->funcs->destroy(connector); 157 } 158 159 void drm_connector_free_work_fn(struct work_struct *work) 160 { 161 struct drm_connector *connector, *n; 162 struct drm_device *dev = 163 container_of(work, struct drm_device, mode_config.connector_free_work); 164 struct drm_mode_config *config = &dev->mode_config; 165 unsigned long flags; 166 struct llist_node *freed; 167 168 spin_lock_irqsave(&config->connector_list_lock, flags); 169 freed = llist_del_all(&config->connector_free_list); 170 spin_unlock_irqrestore(&config->connector_list_lock, flags); 171 172 llist_for_each_entry_safe(connector, n, freed, free_node) { 173 drm_mode_object_unregister(dev, &connector->base); 174 connector->funcs->destroy(connector); 175 } 176 } 177 178 /** 179 * drm_connector_init - Init a preallocated connector 180 * @dev: DRM device 181 * @connector: the connector to init 182 * @funcs: callbacks for this connector 183 * @connector_type: user visible type of the connector 184 * 185 * Initialises a preallocated connector. Connectors should be 186 * subclassed as part of driver connector objects. 187 * 188 * Returns: 189 * Zero on success, error code on failure. 190 */ 191 int drm_connector_init(struct drm_device *dev, 192 struct drm_connector *connector, 193 const struct drm_connector_funcs *funcs, 194 int connector_type) 195 { 196 struct drm_mode_config *config = &dev->mode_config; 197 int ret; 198 struct ida *connector_ida = 199 &drm_connector_enum_list[connector_type].ida; 200 201 WARN_ON(drm_drv_uses_atomic_modeset(dev) && 202 (!funcs->atomic_destroy_state || 203 !funcs->atomic_duplicate_state)); 204 205 ret = __drm_mode_object_add(dev, &connector->base, 206 DRM_MODE_OBJECT_CONNECTOR, 207 false, drm_connector_free); 208 if (ret) 209 return ret; 210 211 connector->base.properties = &connector->properties; 212 connector->dev = dev; 213 connector->funcs = funcs; 214 215 /* connector index is used with 32bit bitmasks */ 216 ret = ida_simple_get(&config->connector_ida, 0, 32, GFP_KERNEL); 217 if (ret < 0) { 218 DRM_DEBUG_KMS("Failed to allocate %s connector index: %d\n", 219 drm_connector_enum_list[connector_type].name, 220 ret); 221 goto out_put; 222 } 223 connector->index = ret; 224 ret = 0; 225 226 connector->connector_type = connector_type; 227 connector->connector_type_id = 228 ida_simple_get(connector_ida, 1, 0, GFP_KERNEL); 229 if (connector->connector_type_id < 0) { 230 ret = connector->connector_type_id; 231 goto out_put_id; 232 } 233 connector->name = 234 kasprintf(GFP_KERNEL, "%s-%d", 235 drm_connector_enum_list[connector_type].name, 236 connector->connector_type_id); 237 if (!connector->name) { 238 ret = -ENOMEM; 239 goto out_put_type_id; 240 } 241 242 INIT_LIST_HEAD(&connector->probed_modes); 243 INIT_LIST_HEAD(&connector->modes); 244 rw_init(&connector->mutex, "cnlk"); 245 connector->edid_blob_ptr = NULL; 246 connector->status = connector_status_unknown; 247 connector->display_info.panel_orientation = 248 DRM_MODE_PANEL_ORIENTATION_UNKNOWN; 249 250 drm_connector_get_cmdline_mode(connector); 251 252 /* We should add connectors at the end to avoid upsetting the connector 253 * index too much. */ 254 spin_lock_irq(&config->connector_list_lock); 255 list_add_tail(&connector->head, &config->connector_list); 256 config->num_connector++; 257 spin_unlock_irq(&config->connector_list_lock); 258 259 if (connector_type != DRM_MODE_CONNECTOR_VIRTUAL && 260 connector_type != DRM_MODE_CONNECTOR_WRITEBACK) 261 drm_object_attach_property(&connector->base, 262 config->edid_property, 263 0); 264 265 drm_object_attach_property(&connector->base, 266 config->dpms_property, 0); 267 268 drm_object_attach_property(&connector->base, 269 config->link_status_property, 270 0); 271 272 drm_object_attach_property(&connector->base, 273 config->non_desktop_property, 274 0); 275 276 if (drm_core_check_feature(dev, DRIVER_ATOMIC)) { 277 drm_object_attach_property(&connector->base, config->prop_crtc_id, 0); 278 } 279 280 connector->debugfs_entry = NULL; 281 out_put_type_id: 282 if (ret) 283 ida_simple_remove(connector_ida, connector->connector_type_id); 284 out_put_id: 285 if (ret) 286 ida_simple_remove(&config->connector_ida, connector->index); 287 out_put: 288 if (ret) 289 drm_mode_object_unregister(dev, &connector->base); 290 291 return ret; 292 } 293 EXPORT_SYMBOL(drm_connector_init); 294 295 /** 296 * drm_connector_attach_encoder - attach a connector to an encoder 297 * @connector: connector to attach 298 * @encoder: encoder to attach @connector to 299 * 300 * This function links up a connector to an encoder. Note that the routing 301 * restrictions between encoders and crtcs are exposed to userspace through the 302 * possible_clones and possible_crtcs bitmasks. 303 * 304 * Returns: 305 * Zero on success, negative errno on failure. 306 */ 307 int drm_connector_attach_encoder(struct drm_connector *connector, 308 struct drm_encoder *encoder) 309 { 310 int i; 311 312 /* 313 * In the past, drivers have attempted to model the static association 314 * of connector to encoder in simple connector/encoder devices using a 315 * direct assignment of connector->encoder = encoder. This connection 316 * is a logical one and the responsibility of the core, so drivers are 317 * expected not to mess with this. 318 * 319 * Note that the error return should've been enough here, but a large 320 * majority of drivers ignores the return value, so add in a big WARN 321 * to get people's attention. 322 */ 323 if (WARN_ON(connector->encoder)) 324 return -EINVAL; 325 326 for (i = 0; i < ARRAY_SIZE(connector->encoder_ids); i++) { 327 if (connector->encoder_ids[i] == 0) { 328 connector->encoder_ids[i] = encoder->base.id; 329 return 0; 330 } 331 } 332 return -ENOMEM; 333 } 334 EXPORT_SYMBOL(drm_connector_attach_encoder); 335 336 /** 337 * drm_connector_has_possible_encoder - check if the connector and encoder are assosicated with each other 338 * @connector: the connector 339 * @encoder: the encoder 340 * 341 * Returns: 342 * True if @encoder is one of the possible encoders for @connector. 343 */ 344 bool drm_connector_has_possible_encoder(struct drm_connector *connector, 345 struct drm_encoder *encoder) 346 { 347 struct drm_encoder *enc; 348 int i; 349 350 drm_connector_for_each_possible_encoder(connector, enc, i) { 351 if (enc == encoder) 352 return true; 353 } 354 355 return false; 356 } 357 EXPORT_SYMBOL(drm_connector_has_possible_encoder); 358 359 static void drm_mode_remove(struct drm_connector *connector, 360 struct drm_display_mode *mode) 361 { 362 list_del(&mode->head); 363 drm_mode_destroy(connector->dev, mode); 364 } 365 366 /** 367 * drm_connector_cleanup - cleans up an initialised connector 368 * @connector: connector to cleanup 369 * 370 * Cleans up the connector but doesn't free the object. 371 */ 372 void drm_connector_cleanup(struct drm_connector *connector) 373 { 374 struct drm_device *dev = connector->dev; 375 struct drm_display_mode *mode, *t; 376 377 /* The connector should have been removed from userspace long before 378 * it is finally destroyed. 379 */ 380 if (WARN_ON(connector->registered)) 381 drm_connector_unregister(connector); 382 383 if (connector->tile_group) { 384 drm_mode_put_tile_group(dev, connector->tile_group); 385 connector->tile_group = NULL; 386 } 387 388 list_for_each_entry_safe(mode, t, &connector->probed_modes, head) 389 drm_mode_remove(connector, mode); 390 391 list_for_each_entry_safe(mode, t, &connector->modes, head) 392 drm_mode_remove(connector, mode); 393 394 ida_simple_remove(&drm_connector_enum_list[connector->connector_type].ida, 395 connector->connector_type_id); 396 397 ida_simple_remove(&dev->mode_config.connector_ida, 398 connector->index); 399 400 kfree(connector->display_info.bus_formats); 401 drm_mode_object_unregister(dev, &connector->base); 402 kfree(connector->name); 403 connector->name = NULL; 404 spin_lock_irq(&dev->mode_config.connector_list_lock); 405 list_del(&connector->head); 406 dev->mode_config.num_connector--; 407 spin_unlock_irq(&dev->mode_config.connector_list_lock); 408 409 WARN_ON(connector->state && !connector->funcs->atomic_destroy_state); 410 if (connector->state && connector->funcs->atomic_destroy_state) 411 connector->funcs->atomic_destroy_state(connector, 412 connector->state); 413 414 mutex_destroy(&connector->mutex); 415 416 memset(connector, 0, sizeof(*connector)); 417 } 418 EXPORT_SYMBOL(drm_connector_cleanup); 419 420 /** 421 * drm_connector_register - register a connector 422 * @connector: the connector to register 423 * 424 * Register userspace interfaces for a connector 425 * 426 * Returns: 427 * Zero on success, error code on failure. 428 */ 429 int drm_connector_register(struct drm_connector *connector) 430 { 431 int ret = 0; 432 433 if (!connector->dev->registered) 434 return 0; 435 436 mutex_lock(&connector->mutex); 437 if (connector->registered) 438 goto unlock; 439 440 ret = drm_sysfs_connector_add(connector); 441 if (ret) 442 goto unlock; 443 444 ret = drm_debugfs_connector_add(connector); 445 if (ret) { 446 goto err_sysfs; 447 } 448 449 if (connector->funcs->late_register) { 450 ret = connector->funcs->late_register(connector); 451 if (ret) 452 goto err_debugfs; 453 } 454 455 drm_mode_object_register(connector->dev, &connector->base); 456 457 connector->registered = true; 458 goto unlock; 459 460 err_debugfs: 461 drm_debugfs_connector_remove(connector); 462 err_sysfs: 463 drm_sysfs_connector_remove(connector); 464 unlock: 465 mutex_unlock(&connector->mutex); 466 return ret; 467 } 468 EXPORT_SYMBOL(drm_connector_register); 469 470 /** 471 * drm_connector_unregister - unregister a connector 472 * @connector: the connector to unregister 473 * 474 * Unregister userspace interfaces for a connector 475 */ 476 void drm_connector_unregister(struct drm_connector *connector) 477 { 478 mutex_lock(&connector->mutex); 479 if (!connector->registered) { 480 mutex_unlock(&connector->mutex); 481 return; 482 } 483 484 if (connector->funcs->early_unregister) 485 connector->funcs->early_unregister(connector); 486 487 drm_sysfs_connector_remove(connector); 488 drm_debugfs_connector_remove(connector); 489 490 connector->registered = false; 491 mutex_unlock(&connector->mutex); 492 } 493 EXPORT_SYMBOL(drm_connector_unregister); 494 495 void drm_connector_unregister_all(struct drm_device *dev) 496 { 497 struct drm_connector *connector; 498 struct drm_connector_list_iter conn_iter; 499 500 drm_connector_list_iter_begin(dev, &conn_iter); 501 drm_for_each_connector_iter(connector, &conn_iter) 502 drm_connector_unregister(connector); 503 drm_connector_list_iter_end(&conn_iter); 504 } 505 506 int drm_connector_register_all(struct drm_device *dev) 507 { 508 struct drm_connector *connector; 509 struct drm_connector_list_iter conn_iter; 510 int ret = 0; 511 512 drm_connector_list_iter_begin(dev, &conn_iter); 513 drm_for_each_connector_iter(connector, &conn_iter) { 514 ret = drm_connector_register(connector); 515 if (ret) 516 break; 517 } 518 drm_connector_list_iter_end(&conn_iter); 519 520 if (ret) 521 drm_connector_unregister_all(dev); 522 return ret; 523 } 524 525 /** 526 * drm_get_connector_status_name - return a string for connector status 527 * @status: connector status to compute name of 528 * 529 * In contrast to the other drm_get_*_name functions this one here returns a 530 * const pointer and hence is threadsafe. 531 */ 532 const char *drm_get_connector_status_name(enum drm_connector_status status) 533 { 534 if (status == connector_status_connected) 535 return "connected"; 536 else if (status == connector_status_disconnected) 537 return "disconnected"; 538 else 539 return "unknown"; 540 } 541 EXPORT_SYMBOL(drm_get_connector_status_name); 542 543 /** 544 * drm_get_connector_force_name - return a string for connector force 545 * @force: connector force to get name of 546 * 547 * Returns: const pointer to name. 548 */ 549 const char *drm_get_connector_force_name(enum drm_connector_force force) 550 { 551 switch (force) { 552 case DRM_FORCE_UNSPECIFIED: 553 return "unspecified"; 554 case DRM_FORCE_OFF: 555 return "off"; 556 case DRM_FORCE_ON: 557 return "on"; 558 case DRM_FORCE_ON_DIGITAL: 559 return "digital"; 560 default: 561 return "unknown"; 562 } 563 } 564 565 #ifdef CONFIG_LOCKDEP 566 static struct lockdep_map connector_list_iter_dep_map = { 567 .name = "drm_connector_list_iter" 568 }; 569 #endif 570 571 /** 572 * drm_connector_list_iter_begin - initialize a connector_list iterator 573 * @dev: DRM device 574 * @iter: connector_list iterator 575 * 576 * Sets @iter up to walk the &drm_mode_config.connector_list of @dev. @iter 577 * must always be cleaned up again by calling drm_connector_list_iter_end(). 578 * Iteration itself happens using drm_connector_list_iter_next() or 579 * drm_for_each_connector_iter(). 580 */ 581 void drm_connector_list_iter_begin(struct drm_device *dev, 582 struct drm_connector_list_iter *iter) 583 { 584 iter->dev = dev; 585 iter->conn = NULL; 586 lock_acquire_shared_recursive(&connector_list_iter_dep_map, 0, 1, NULL, _RET_IP_); 587 } 588 EXPORT_SYMBOL(drm_connector_list_iter_begin); 589 590 /* 591 * Extra-safe connector put function that works in any context. Should only be 592 * used from the connector_iter functions, where we never really expect to 593 * actually release the connector when dropping our final reference. 594 */ 595 static void 596 __drm_connector_put_safe(struct drm_connector *conn) 597 { 598 struct drm_mode_config *config = &conn->dev->mode_config; 599 600 lockdep_assert_held(&config->connector_list_lock); 601 602 if (!refcount_dec_and_test(&conn->base.refcount.refcount)) 603 return; 604 605 llist_add(&conn->free_node, &config->connector_free_list); 606 schedule_work(&config->connector_free_work); 607 } 608 609 /** 610 * drm_connector_list_iter_next - return next connector 611 * @iter: connector_list iterator 612 * 613 * Returns the next connector for @iter, or NULL when the list walk has 614 * completed. 615 */ 616 struct drm_connector * 617 drm_connector_list_iter_next(struct drm_connector_list_iter *iter) 618 { 619 struct drm_connector *old_conn = iter->conn; 620 struct drm_mode_config *config = &iter->dev->mode_config; 621 struct list_head *lhead; 622 unsigned long flags; 623 624 spin_lock_irqsave(&config->connector_list_lock, flags); 625 lhead = old_conn ? &old_conn->head : &config->connector_list; 626 627 do { 628 if (lhead->next == &config->connector_list) { 629 iter->conn = NULL; 630 break; 631 } 632 633 lhead = lhead->next; 634 iter->conn = list_entry(lhead, struct drm_connector, head); 635 636 /* loop until it's not a zombie connector */ 637 } while (!kref_get_unless_zero(&iter->conn->base.refcount)); 638 639 if (old_conn) 640 __drm_connector_put_safe(old_conn); 641 spin_unlock_irqrestore(&config->connector_list_lock, flags); 642 643 return iter->conn; 644 } 645 EXPORT_SYMBOL(drm_connector_list_iter_next); 646 647 /** 648 * drm_connector_list_iter_end - tear down a connector_list iterator 649 * @iter: connector_list iterator 650 * 651 * Tears down @iter and releases any resources (like &drm_connector references) 652 * acquired while walking the list. This must always be called, both when the 653 * iteration completes fully or when it was aborted without walking the entire 654 * list. 655 */ 656 void drm_connector_list_iter_end(struct drm_connector_list_iter *iter) 657 { 658 struct drm_mode_config *config = &iter->dev->mode_config; 659 unsigned long flags; 660 661 iter->dev = NULL; 662 if (iter->conn) { 663 spin_lock_irqsave(&config->connector_list_lock, flags); 664 __drm_connector_put_safe(iter->conn); 665 spin_unlock_irqrestore(&config->connector_list_lock, flags); 666 } 667 lock_release(&connector_list_iter_dep_map, 0, _RET_IP_); 668 } 669 EXPORT_SYMBOL(drm_connector_list_iter_end); 670 671 static const struct drm_prop_enum_list drm_subpixel_enum_list[] = { 672 { SubPixelUnknown, "Unknown" }, 673 { SubPixelHorizontalRGB, "Horizontal RGB" }, 674 { SubPixelHorizontalBGR, "Horizontal BGR" }, 675 { SubPixelVerticalRGB, "Vertical RGB" }, 676 { SubPixelVerticalBGR, "Vertical BGR" }, 677 { SubPixelNone, "None" }, 678 }; 679 680 /** 681 * drm_get_subpixel_order_name - return a string for a given subpixel enum 682 * @order: enum of subpixel_order 683 * 684 * Note you could abuse this and return something out of bounds, but that 685 * would be a caller error. No unscrubbed user data should make it here. 686 */ 687 const char *drm_get_subpixel_order_name(enum subpixel_order order) 688 { 689 return drm_subpixel_enum_list[order].name; 690 } 691 EXPORT_SYMBOL(drm_get_subpixel_order_name); 692 693 static const struct drm_prop_enum_list drm_dpms_enum_list[] = { 694 { DRM_MODE_DPMS_ON, "On" }, 695 { DRM_MODE_DPMS_STANDBY, "Standby" }, 696 { DRM_MODE_DPMS_SUSPEND, "Suspend" }, 697 { DRM_MODE_DPMS_OFF, "Off" } 698 }; 699 DRM_ENUM_NAME_FN(drm_get_dpms_name, drm_dpms_enum_list) 700 701 static const struct drm_prop_enum_list drm_link_status_enum_list[] = { 702 { DRM_MODE_LINK_STATUS_GOOD, "Good" }, 703 { DRM_MODE_LINK_STATUS_BAD, "Bad" }, 704 }; 705 706 /** 707 * drm_display_info_set_bus_formats - set the supported bus formats 708 * @info: display info to store bus formats in 709 * @formats: array containing the supported bus formats 710 * @num_formats: the number of entries in the fmts array 711 * 712 * Store the supported bus formats in display info structure. 713 * See MEDIA_BUS_FMT_* definitions in include/uapi/linux/media-bus-format.h for 714 * a full list of available formats. 715 */ 716 int drm_display_info_set_bus_formats(struct drm_display_info *info, 717 const u32 *formats, 718 unsigned int num_formats) 719 { 720 u32 *fmts = NULL; 721 722 if (!formats && num_formats) 723 return -EINVAL; 724 725 if (formats && num_formats) { 726 fmts = kmemdup(formats, sizeof(*formats) * num_formats, 727 GFP_KERNEL); 728 if (!fmts) 729 return -ENOMEM; 730 } 731 732 kfree(info->bus_formats); 733 info->bus_formats = fmts; 734 info->num_bus_formats = num_formats; 735 736 return 0; 737 } 738 EXPORT_SYMBOL(drm_display_info_set_bus_formats); 739 740 /* Optional connector properties. */ 741 static const struct drm_prop_enum_list drm_scaling_mode_enum_list[] = { 742 { DRM_MODE_SCALE_NONE, "None" }, 743 { DRM_MODE_SCALE_FULLSCREEN, "Full" }, 744 { DRM_MODE_SCALE_CENTER, "Center" }, 745 { DRM_MODE_SCALE_ASPECT, "Full aspect" }, 746 }; 747 748 static const struct drm_prop_enum_list drm_aspect_ratio_enum_list[] = { 749 { DRM_MODE_PICTURE_ASPECT_NONE, "Automatic" }, 750 { DRM_MODE_PICTURE_ASPECT_4_3, "4:3" }, 751 { DRM_MODE_PICTURE_ASPECT_16_9, "16:9" }, 752 }; 753 754 static const struct drm_prop_enum_list drm_content_type_enum_list[] = { 755 { DRM_MODE_CONTENT_TYPE_NO_DATA, "No Data" }, 756 { DRM_MODE_CONTENT_TYPE_GRAPHICS, "Graphics" }, 757 { DRM_MODE_CONTENT_TYPE_PHOTO, "Photo" }, 758 { DRM_MODE_CONTENT_TYPE_CINEMA, "Cinema" }, 759 { DRM_MODE_CONTENT_TYPE_GAME, "Game" }, 760 }; 761 762 static const struct drm_prop_enum_list drm_panel_orientation_enum_list[] = { 763 { DRM_MODE_PANEL_ORIENTATION_NORMAL, "Normal" }, 764 { DRM_MODE_PANEL_ORIENTATION_BOTTOM_UP, "Upside Down" }, 765 { DRM_MODE_PANEL_ORIENTATION_LEFT_UP, "Left Side Up" }, 766 { DRM_MODE_PANEL_ORIENTATION_RIGHT_UP, "Right Side Up" }, 767 }; 768 769 static const struct drm_prop_enum_list drm_dvi_i_select_enum_list[] = { 770 { DRM_MODE_SUBCONNECTOR_Automatic, "Automatic" }, /* DVI-I and TV-out */ 771 { DRM_MODE_SUBCONNECTOR_DVID, "DVI-D" }, /* DVI-I */ 772 { DRM_MODE_SUBCONNECTOR_DVIA, "DVI-A" }, /* DVI-I */ 773 }; 774 DRM_ENUM_NAME_FN(drm_get_dvi_i_select_name, drm_dvi_i_select_enum_list) 775 776 static const struct drm_prop_enum_list drm_dvi_i_subconnector_enum_list[] = { 777 { DRM_MODE_SUBCONNECTOR_Unknown, "Unknown" }, /* DVI-I and TV-out */ 778 { DRM_MODE_SUBCONNECTOR_DVID, "DVI-D" }, /* DVI-I */ 779 { DRM_MODE_SUBCONNECTOR_DVIA, "DVI-A" }, /* DVI-I */ 780 }; 781 DRM_ENUM_NAME_FN(drm_get_dvi_i_subconnector_name, 782 drm_dvi_i_subconnector_enum_list) 783 784 static const struct drm_prop_enum_list drm_tv_select_enum_list[] = { 785 { DRM_MODE_SUBCONNECTOR_Automatic, "Automatic" }, /* DVI-I and TV-out */ 786 { DRM_MODE_SUBCONNECTOR_Composite, "Composite" }, /* TV-out */ 787 { DRM_MODE_SUBCONNECTOR_SVIDEO, "SVIDEO" }, /* TV-out */ 788 { DRM_MODE_SUBCONNECTOR_Component, "Component" }, /* TV-out */ 789 { DRM_MODE_SUBCONNECTOR_SCART, "SCART" }, /* TV-out */ 790 }; 791 DRM_ENUM_NAME_FN(drm_get_tv_select_name, drm_tv_select_enum_list) 792 793 static const struct drm_prop_enum_list drm_tv_subconnector_enum_list[] = { 794 { DRM_MODE_SUBCONNECTOR_Unknown, "Unknown" }, /* DVI-I and TV-out */ 795 { DRM_MODE_SUBCONNECTOR_Composite, "Composite" }, /* TV-out */ 796 { DRM_MODE_SUBCONNECTOR_SVIDEO, "SVIDEO" }, /* TV-out */ 797 { DRM_MODE_SUBCONNECTOR_Component, "Component" }, /* TV-out */ 798 { DRM_MODE_SUBCONNECTOR_SCART, "SCART" }, /* TV-out */ 799 }; 800 DRM_ENUM_NAME_FN(drm_get_tv_subconnector_name, 801 drm_tv_subconnector_enum_list) 802 803 static struct drm_prop_enum_list drm_cp_enum_list[] = { 804 { DRM_MODE_CONTENT_PROTECTION_UNDESIRED, "Undesired" }, 805 { DRM_MODE_CONTENT_PROTECTION_DESIRED, "Desired" }, 806 { DRM_MODE_CONTENT_PROTECTION_ENABLED, "Enabled" }, 807 }; 808 DRM_ENUM_NAME_FN(drm_get_content_protection_name, drm_cp_enum_list) 809 810 /** 811 * DOC: standard connector properties 812 * 813 * DRM connectors have a few standardized properties: 814 * 815 * EDID: 816 * Blob property which contains the current EDID read from the sink. This 817 * is useful to parse sink identification information like vendor, model 818 * and serial. Drivers should update this property by calling 819 * drm_connector_update_edid_property(), usually after having parsed 820 * the EDID using drm_add_edid_modes(). Userspace cannot change this 821 * property. 822 * DPMS: 823 * Legacy property for setting the power state of the connector. For atomic 824 * drivers this is only provided for backwards compatibility with existing 825 * drivers, it remaps to controlling the "ACTIVE" property on the CRTC the 826 * connector is linked to. Drivers should never set this property directly, 827 * it is handled by the DRM core by calling the &drm_connector_funcs.dpms 828 * callback. For atomic drivers the remapping to the "ACTIVE" property is 829 * implemented in the DRM core. This is the only standard connector 830 * property that userspace can change. 831 * 832 * Note that this property cannot be set through the MODE_ATOMIC ioctl, 833 * userspace must use "ACTIVE" on the CRTC instead. 834 * 835 * WARNING: 836 * 837 * For userspace also running on legacy drivers the "DPMS" semantics are a 838 * lot more complicated. First, userspace cannot rely on the "DPMS" value 839 * returned by the GETCONNECTOR actually reflecting reality, because many 840 * drivers fail to update it. For atomic drivers this is taken care of in 841 * drm_atomic_helper_update_legacy_modeset_state(). 842 * 843 * The second issue is that the DPMS state is only well-defined when the 844 * connector is connected to a CRTC. In atomic the DRM core enforces that 845 * "ACTIVE" is off in such a case, no such checks exists for "DPMS". 846 * 847 * Finally, when enabling an output using the legacy SETCONFIG ioctl then 848 * "DPMS" is forced to ON. But see above, that might not be reflected in 849 * the software value on legacy drivers. 850 * 851 * Summarizing: Only set "DPMS" when the connector is known to be enabled, 852 * assume that a successful SETCONFIG call also sets "DPMS" to on, and 853 * never read back the value of "DPMS" because it can be incorrect. 854 * PATH: 855 * Connector path property to identify how this sink is physically 856 * connected. Used by DP MST. This should be set by calling 857 * drm_connector_set_path_property(), in the case of DP MST with the 858 * path property the MST manager created. Userspace cannot change this 859 * property. 860 * TILE: 861 * Connector tile group property to indicate how a set of DRM connector 862 * compose together into one logical screen. This is used by both high-res 863 * external screens (often only using a single cable, but exposing multiple 864 * DP MST sinks), or high-res integrated panels (like dual-link DSI) which 865 * are not gen-locked. Note that for tiled panels which are genlocked, like 866 * dual-link LVDS or dual-link DSI, the driver should try to not expose the 867 * tiling and virtualize both &drm_crtc and &drm_plane if needed. Drivers 868 * should update this value using drm_connector_set_tile_property(). 869 * Userspace cannot change this property. 870 * link-status: 871 * Connector link-status property to indicate the status of link. The 872 * default value of link-status is "GOOD". If something fails during or 873 * after modeset, the kernel driver may set this to "BAD" and issue a 874 * hotplug uevent. Drivers should update this value using 875 * drm_connector_set_link_status_property(). 876 * non_desktop: 877 * Indicates the output should be ignored for purposes of displaying a 878 * standard desktop environment or console. This is most likely because 879 * the output device is not rectilinear. 880 * Content Protection: 881 * This property is used by userspace to request the kernel protect future 882 * content communicated over the link. When requested, kernel will apply 883 * the appropriate means of protection (most often HDCP), and use the 884 * property to tell userspace the protection is active. 885 * 886 * Drivers can set this up by calling 887 * drm_connector_attach_content_protection_property() on initialization. 888 * 889 * The value of this property can be one of the following: 890 * 891 * DRM_MODE_CONTENT_PROTECTION_UNDESIRED = 0 892 * The link is not protected, content is transmitted in the clear. 893 * DRM_MODE_CONTENT_PROTECTION_DESIRED = 1 894 * Userspace has requested content protection, but the link is not 895 * currently protected. When in this state, kernel should enable 896 * Content Protection as soon as possible. 897 * DRM_MODE_CONTENT_PROTECTION_ENABLED = 2 898 * Userspace has requested content protection, and the link is 899 * protected. Only the driver can set the property to this value. 900 * If userspace attempts to set to ENABLED, kernel will return 901 * -EINVAL. 902 * 903 * A few guidelines: 904 * 905 * - DESIRED state should be preserved until userspace de-asserts it by 906 * setting the property to UNDESIRED. This means ENABLED should only 907 * transition to UNDESIRED when the user explicitly requests it. 908 * - If the state is DESIRED, kernel should attempt to re-authenticate the 909 * link whenever possible. This includes across disable/enable, dpms, 910 * hotplug, downstream device changes, link status failures, etc.. 911 * - Userspace is responsible for polling the property to determine when 912 * the value transitions from ENABLED to DESIRED. This signifies the link 913 * is no longer protected and userspace should take appropriate action 914 * (whatever that might be). 915 * 916 * Connectors also have one standardized atomic property: 917 * 918 * CRTC_ID: 919 * Mode object ID of the &drm_crtc this connector should be connected to. 920 * 921 * Connectors for LCD panels may also have one standardized property: 922 * 923 * panel orientation: 924 * On some devices the LCD panel is mounted in the casing in such a way 925 * that the up/top side of the panel does not match with the top side of 926 * the device. Userspace can use this property to check for this. 927 * Note that input coordinates from touchscreens (input devices with 928 * INPUT_PROP_DIRECT) will still map 1:1 to the actual LCD panel 929 * coordinates, so if userspace rotates the picture to adjust for 930 * the orientation it must also apply the same transformation to the 931 * touchscreen input coordinates. This property is initialized by calling 932 * drm_connector_init_panel_orientation_property(). 933 * 934 * scaling mode: 935 * This property defines how a non-native mode is upscaled to the native 936 * mode of an LCD panel: 937 * 938 * None: 939 * No upscaling happens, scaling is left to the panel. Not all 940 * drivers expose this mode. 941 * Full: 942 * The output is upscaled to the full resolution of the panel, 943 * ignoring the aspect ratio. 944 * Center: 945 * No upscaling happens, the output is centered within the native 946 * resolution the panel. 947 * Full aspect: 948 * The output is upscaled to maximize either the width or height 949 * while retaining the aspect ratio. 950 * 951 * This property should be set up by calling 952 * drm_connector_attach_scaling_mode_property(). Note that drivers 953 * can also expose this property to external outputs, in which case they 954 * must support "None", which should be the default (since external screens 955 * have a built-in scaler). 956 */ 957 958 int drm_connector_create_standard_properties(struct drm_device *dev) 959 { 960 struct drm_property *prop; 961 962 prop = drm_property_create(dev, DRM_MODE_PROP_BLOB | 963 DRM_MODE_PROP_IMMUTABLE, 964 "EDID", 0); 965 if (!prop) 966 return -ENOMEM; 967 dev->mode_config.edid_property = prop; 968 969 prop = drm_property_create_enum(dev, 0, 970 "DPMS", drm_dpms_enum_list, 971 ARRAY_SIZE(drm_dpms_enum_list)); 972 if (!prop) 973 return -ENOMEM; 974 dev->mode_config.dpms_property = prop; 975 976 prop = drm_property_create(dev, 977 DRM_MODE_PROP_BLOB | 978 DRM_MODE_PROP_IMMUTABLE, 979 "PATH", 0); 980 if (!prop) 981 return -ENOMEM; 982 dev->mode_config.path_property = prop; 983 984 prop = drm_property_create(dev, 985 DRM_MODE_PROP_BLOB | 986 DRM_MODE_PROP_IMMUTABLE, 987 "TILE", 0); 988 if (!prop) 989 return -ENOMEM; 990 dev->mode_config.tile_property = prop; 991 992 prop = drm_property_create_enum(dev, 0, "link-status", 993 drm_link_status_enum_list, 994 ARRAY_SIZE(drm_link_status_enum_list)); 995 if (!prop) 996 return -ENOMEM; 997 dev->mode_config.link_status_property = prop; 998 999 prop = drm_property_create_bool(dev, DRM_MODE_PROP_IMMUTABLE, "non-desktop"); 1000 if (!prop) 1001 return -ENOMEM; 1002 dev->mode_config.non_desktop_property = prop; 1003 1004 return 0; 1005 } 1006 1007 /** 1008 * drm_mode_create_dvi_i_properties - create DVI-I specific connector properties 1009 * @dev: DRM device 1010 * 1011 * Called by a driver the first time a DVI-I connector is made. 1012 */ 1013 int drm_mode_create_dvi_i_properties(struct drm_device *dev) 1014 { 1015 struct drm_property *dvi_i_selector; 1016 struct drm_property *dvi_i_subconnector; 1017 1018 if (dev->mode_config.dvi_i_select_subconnector_property) 1019 return 0; 1020 1021 dvi_i_selector = 1022 drm_property_create_enum(dev, 0, 1023 "select subconnector", 1024 drm_dvi_i_select_enum_list, 1025 ARRAY_SIZE(drm_dvi_i_select_enum_list)); 1026 dev->mode_config.dvi_i_select_subconnector_property = dvi_i_selector; 1027 1028 dvi_i_subconnector = drm_property_create_enum(dev, DRM_MODE_PROP_IMMUTABLE, 1029 "subconnector", 1030 drm_dvi_i_subconnector_enum_list, 1031 ARRAY_SIZE(drm_dvi_i_subconnector_enum_list)); 1032 dev->mode_config.dvi_i_subconnector_property = dvi_i_subconnector; 1033 1034 return 0; 1035 } 1036 EXPORT_SYMBOL(drm_mode_create_dvi_i_properties); 1037 1038 /** 1039 * DOC: HDMI connector properties 1040 * 1041 * content type (HDMI specific): 1042 * Indicates content type setting to be used in HDMI infoframes to indicate 1043 * content type for the external device, so that it adjusts it's display 1044 * settings accordingly. 1045 * 1046 * The value of this property can be one of the following: 1047 * 1048 * No Data: 1049 * Content type is unknown 1050 * Graphics: 1051 * Content type is graphics 1052 * Photo: 1053 * Content type is photo 1054 * Cinema: 1055 * Content type is cinema 1056 * Game: 1057 * Content type is game 1058 * 1059 * Drivers can set up this property by calling 1060 * drm_connector_attach_content_type_property(). Decoding to 1061 * infoframe values is done through drm_hdmi_avi_infoframe_content_type(). 1062 */ 1063 1064 /** 1065 * drm_connector_attach_content_type_property - attach content-type property 1066 * @connector: connector to attach content type property on. 1067 * 1068 * Called by a driver the first time a HDMI connector is made. 1069 */ 1070 int drm_connector_attach_content_type_property(struct drm_connector *connector) 1071 { 1072 if (!drm_mode_create_content_type_property(connector->dev)) 1073 drm_object_attach_property(&connector->base, 1074 connector->dev->mode_config.content_type_property, 1075 DRM_MODE_CONTENT_TYPE_NO_DATA); 1076 return 0; 1077 } 1078 EXPORT_SYMBOL(drm_connector_attach_content_type_property); 1079 1080 1081 /** 1082 * drm_hdmi_avi_infoframe_content_type() - fill the HDMI AVI infoframe 1083 * content type information, based 1084 * on correspondent DRM property. 1085 * @frame: HDMI AVI infoframe 1086 * @conn_state: DRM display connector state 1087 * 1088 */ 1089 void drm_hdmi_avi_infoframe_content_type(struct hdmi_avi_infoframe *frame, 1090 const struct drm_connector_state *conn_state) 1091 { 1092 switch (conn_state->content_type) { 1093 case DRM_MODE_CONTENT_TYPE_GRAPHICS: 1094 frame->content_type = HDMI_CONTENT_TYPE_GRAPHICS; 1095 break; 1096 case DRM_MODE_CONTENT_TYPE_CINEMA: 1097 frame->content_type = HDMI_CONTENT_TYPE_CINEMA; 1098 break; 1099 case DRM_MODE_CONTENT_TYPE_GAME: 1100 frame->content_type = HDMI_CONTENT_TYPE_GAME; 1101 break; 1102 case DRM_MODE_CONTENT_TYPE_PHOTO: 1103 frame->content_type = HDMI_CONTENT_TYPE_PHOTO; 1104 break; 1105 default: 1106 /* Graphics is the default(0) */ 1107 frame->content_type = HDMI_CONTENT_TYPE_GRAPHICS; 1108 } 1109 1110 frame->itc = conn_state->content_type != DRM_MODE_CONTENT_TYPE_NO_DATA; 1111 } 1112 EXPORT_SYMBOL(drm_hdmi_avi_infoframe_content_type); 1113 1114 /** 1115 * drm_create_tv_properties - create TV specific connector properties 1116 * @dev: DRM device 1117 * @num_modes: number of different TV formats (modes) supported 1118 * @modes: array of pointers to strings containing name of each format 1119 * 1120 * Called by a driver's TV initialization routine, this function creates 1121 * the TV specific connector properties for a given device. Caller is 1122 * responsible for allocating a list of format names and passing them to 1123 * this routine. 1124 */ 1125 int drm_mode_create_tv_properties(struct drm_device *dev, 1126 unsigned int num_modes, 1127 const char * const modes[]) 1128 { 1129 struct drm_property *tv_selector; 1130 struct drm_property *tv_subconnector; 1131 unsigned int i; 1132 1133 if (dev->mode_config.tv_select_subconnector_property) 1134 return 0; 1135 1136 /* 1137 * Basic connector properties 1138 */ 1139 tv_selector = drm_property_create_enum(dev, 0, 1140 "select subconnector", 1141 drm_tv_select_enum_list, 1142 ARRAY_SIZE(drm_tv_select_enum_list)); 1143 if (!tv_selector) 1144 goto nomem; 1145 1146 dev->mode_config.tv_select_subconnector_property = tv_selector; 1147 1148 tv_subconnector = 1149 drm_property_create_enum(dev, DRM_MODE_PROP_IMMUTABLE, 1150 "subconnector", 1151 drm_tv_subconnector_enum_list, 1152 ARRAY_SIZE(drm_tv_subconnector_enum_list)); 1153 if (!tv_subconnector) 1154 goto nomem; 1155 dev->mode_config.tv_subconnector_property = tv_subconnector; 1156 1157 /* 1158 * Other, TV specific properties: margins & TV modes. 1159 */ 1160 dev->mode_config.tv_left_margin_property = 1161 drm_property_create_range(dev, 0, "left margin", 0, 100); 1162 if (!dev->mode_config.tv_left_margin_property) 1163 goto nomem; 1164 1165 dev->mode_config.tv_right_margin_property = 1166 drm_property_create_range(dev, 0, "right margin", 0, 100); 1167 if (!dev->mode_config.tv_right_margin_property) 1168 goto nomem; 1169 1170 dev->mode_config.tv_top_margin_property = 1171 drm_property_create_range(dev, 0, "top margin", 0, 100); 1172 if (!dev->mode_config.tv_top_margin_property) 1173 goto nomem; 1174 1175 dev->mode_config.tv_bottom_margin_property = 1176 drm_property_create_range(dev, 0, "bottom margin", 0, 100); 1177 if (!dev->mode_config.tv_bottom_margin_property) 1178 goto nomem; 1179 1180 dev->mode_config.tv_mode_property = 1181 drm_property_create(dev, DRM_MODE_PROP_ENUM, 1182 "mode", num_modes); 1183 if (!dev->mode_config.tv_mode_property) 1184 goto nomem; 1185 1186 for (i = 0; i < num_modes; i++) 1187 drm_property_add_enum(dev->mode_config.tv_mode_property, 1188 i, modes[i]); 1189 1190 dev->mode_config.tv_brightness_property = 1191 drm_property_create_range(dev, 0, "brightness", 0, 100); 1192 if (!dev->mode_config.tv_brightness_property) 1193 goto nomem; 1194 1195 dev->mode_config.tv_contrast_property = 1196 drm_property_create_range(dev, 0, "contrast", 0, 100); 1197 if (!dev->mode_config.tv_contrast_property) 1198 goto nomem; 1199 1200 dev->mode_config.tv_flicker_reduction_property = 1201 drm_property_create_range(dev, 0, "flicker reduction", 0, 100); 1202 if (!dev->mode_config.tv_flicker_reduction_property) 1203 goto nomem; 1204 1205 dev->mode_config.tv_overscan_property = 1206 drm_property_create_range(dev, 0, "overscan", 0, 100); 1207 if (!dev->mode_config.tv_overscan_property) 1208 goto nomem; 1209 1210 dev->mode_config.tv_saturation_property = 1211 drm_property_create_range(dev, 0, "saturation", 0, 100); 1212 if (!dev->mode_config.tv_saturation_property) 1213 goto nomem; 1214 1215 dev->mode_config.tv_hue_property = 1216 drm_property_create_range(dev, 0, "hue", 0, 100); 1217 if (!dev->mode_config.tv_hue_property) 1218 goto nomem; 1219 1220 return 0; 1221 nomem: 1222 return -ENOMEM; 1223 } 1224 EXPORT_SYMBOL(drm_mode_create_tv_properties); 1225 1226 /** 1227 * drm_mode_create_scaling_mode_property - create scaling mode property 1228 * @dev: DRM device 1229 * 1230 * Called by a driver the first time it's needed, must be attached to desired 1231 * connectors. 1232 * 1233 * Atomic drivers should use drm_connector_attach_scaling_mode_property() 1234 * instead to correctly assign &drm_connector_state.picture_aspect_ratio 1235 * in the atomic state. 1236 */ 1237 int drm_mode_create_scaling_mode_property(struct drm_device *dev) 1238 { 1239 struct drm_property *scaling_mode; 1240 1241 if (dev->mode_config.scaling_mode_property) 1242 return 0; 1243 1244 scaling_mode = 1245 drm_property_create_enum(dev, 0, "scaling mode", 1246 drm_scaling_mode_enum_list, 1247 ARRAY_SIZE(drm_scaling_mode_enum_list)); 1248 1249 dev->mode_config.scaling_mode_property = scaling_mode; 1250 1251 return 0; 1252 } 1253 EXPORT_SYMBOL(drm_mode_create_scaling_mode_property); 1254 1255 /** 1256 * drm_connector_attach_scaling_mode_property - attach atomic scaling mode property 1257 * @connector: connector to attach scaling mode property on. 1258 * @scaling_mode_mask: or'ed mask of BIT(%DRM_MODE_SCALE_\*). 1259 * 1260 * This is used to add support for scaling mode to atomic drivers. 1261 * The scaling mode will be set to &drm_connector_state.picture_aspect_ratio 1262 * and can be used from &drm_connector_helper_funcs->atomic_check for validation. 1263 * 1264 * This is the atomic version of drm_mode_create_scaling_mode_property(). 1265 * 1266 * Returns: 1267 * Zero on success, negative errno on failure. 1268 */ 1269 int drm_connector_attach_scaling_mode_property(struct drm_connector *connector, 1270 u32 scaling_mode_mask) 1271 { 1272 struct drm_device *dev = connector->dev; 1273 struct drm_property *scaling_mode_property; 1274 int i; 1275 const unsigned valid_scaling_mode_mask = 1276 (1U << ARRAY_SIZE(drm_scaling_mode_enum_list)) - 1; 1277 1278 if (WARN_ON(hweight32(scaling_mode_mask) < 2 || 1279 scaling_mode_mask & ~valid_scaling_mode_mask)) 1280 return -EINVAL; 1281 1282 scaling_mode_property = 1283 drm_property_create(dev, DRM_MODE_PROP_ENUM, "scaling mode", 1284 hweight32(scaling_mode_mask)); 1285 1286 if (!scaling_mode_property) 1287 return -ENOMEM; 1288 1289 for (i = 0; i < ARRAY_SIZE(drm_scaling_mode_enum_list); i++) { 1290 int ret; 1291 1292 if (!(BIT(i) & scaling_mode_mask)) 1293 continue; 1294 1295 ret = drm_property_add_enum(scaling_mode_property, 1296 drm_scaling_mode_enum_list[i].type, 1297 drm_scaling_mode_enum_list[i].name); 1298 1299 if (ret) { 1300 drm_property_destroy(dev, scaling_mode_property); 1301 1302 return ret; 1303 } 1304 } 1305 1306 drm_object_attach_property(&connector->base, 1307 scaling_mode_property, 0); 1308 1309 connector->scaling_mode_property = scaling_mode_property; 1310 1311 return 0; 1312 } 1313 EXPORT_SYMBOL(drm_connector_attach_scaling_mode_property); 1314 1315 /** 1316 * drm_connector_attach_content_protection_property - attach content protection 1317 * property 1318 * 1319 * @connector: connector to attach CP property on. 1320 * 1321 * This is used to add support for content protection on select connectors. 1322 * Content Protection is intentionally vague to allow for different underlying 1323 * technologies, however it is most implemented by HDCP. 1324 * 1325 * The content protection will be set to &drm_connector_state.content_protection 1326 * 1327 * Returns: 1328 * Zero on success, negative errno on failure. 1329 */ 1330 int drm_connector_attach_content_protection_property( 1331 struct drm_connector *connector) 1332 { 1333 struct drm_device *dev = connector->dev; 1334 struct drm_property *prop; 1335 1336 prop = drm_property_create_enum(dev, 0, "Content Protection", 1337 drm_cp_enum_list, 1338 ARRAY_SIZE(drm_cp_enum_list)); 1339 if (!prop) 1340 return -ENOMEM; 1341 1342 drm_object_attach_property(&connector->base, prop, 1343 DRM_MODE_CONTENT_PROTECTION_UNDESIRED); 1344 1345 connector->content_protection_property = prop; 1346 1347 return 0; 1348 } 1349 EXPORT_SYMBOL(drm_connector_attach_content_protection_property); 1350 1351 /** 1352 * drm_mode_create_aspect_ratio_property - create aspect ratio property 1353 * @dev: DRM device 1354 * 1355 * Called by a driver the first time it's needed, must be attached to desired 1356 * connectors. 1357 * 1358 * Returns: 1359 * Zero on success, negative errno on failure. 1360 */ 1361 int drm_mode_create_aspect_ratio_property(struct drm_device *dev) 1362 { 1363 if (dev->mode_config.aspect_ratio_property) 1364 return 0; 1365 1366 dev->mode_config.aspect_ratio_property = 1367 drm_property_create_enum(dev, 0, "aspect ratio", 1368 drm_aspect_ratio_enum_list, 1369 ARRAY_SIZE(drm_aspect_ratio_enum_list)); 1370 1371 if (dev->mode_config.aspect_ratio_property == NULL) 1372 return -ENOMEM; 1373 1374 return 0; 1375 } 1376 EXPORT_SYMBOL(drm_mode_create_aspect_ratio_property); 1377 1378 /** 1379 * drm_mode_create_content_type_property - create content type property 1380 * @dev: DRM device 1381 * 1382 * Called by a driver the first time it's needed, must be attached to desired 1383 * connectors. 1384 * 1385 * Returns: 1386 * Zero on success, negative errno on failure. 1387 */ 1388 int drm_mode_create_content_type_property(struct drm_device *dev) 1389 { 1390 if (dev->mode_config.content_type_property) 1391 return 0; 1392 1393 dev->mode_config.content_type_property = 1394 drm_property_create_enum(dev, 0, "content type", 1395 drm_content_type_enum_list, 1396 ARRAY_SIZE(drm_content_type_enum_list)); 1397 1398 if (dev->mode_config.content_type_property == NULL) 1399 return -ENOMEM; 1400 1401 return 0; 1402 } 1403 EXPORT_SYMBOL(drm_mode_create_content_type_property); 1404 1405 /** 1406 * drm_mode_create_suggested_offset_properties - create suggests offset properties 1407 * @dev: DRM device 1408 * 1409 * Create the the suggested x/y offset property for connectors. 1410 */ 1411 int drm_mode_create_suggested_offset_properties(struct drm_device *dev) 1412 { 1413 if (dev->mode_config.suggested_x_property && dev->mode_config.suggested_y_property) 1414 return 0; 1415 1416 dev->mode_config.suggested_x_property = 1417 drm_property_create_range(dev, DRM_MODE_PROP_IMMUTABLE, "suggested X", 0, 0xffffffff); 1418 1419 dev->mode_config.suggested_y_property = 1420 drm_property_create_range(dev, DRM_MODE_PROP_IMMUTABLE, "suggested Y", 0, 0xffffffff); 1421 1422 if (dev->mode_config.suggested_x_property == NULL || 1423 dev->mode_config.suggested_y_property == NULL) 1424 return -ENOMEM; 1425 return 0; 1426 } 1427 EXPORT_SYMBOL(drm_mode_create_suggested_offset_properties); 1428 1429 /** 1430 * drm_connector_set_path_property - set tile property on connector 1431 * @connector: connector to set property on. 1432 * @path: path to use for property; must not be NULL. 1433 * 1434 * This creates a property to expose to userspace to specify a 1435 * connector path. This is mainly used for DisplayPort MST where 1436 * connectors have a topology and we want to allow userspace to give 1437 * them more meaningful names. 1438 * 1439 * Returns: 1440 * Zero on success, negative errno on failure. 1441 */ 1442 int drm_connector_set_path_property(struct drm_connector *connector, 1443 const char *path) 1444 { 1445 struct drm_device *dev = connector->dev; 1446 int ret; 1447 1448 ret = drm_property_replace_global_blob(dev, 1449 &connector->path_blob_ptr, 1450 strlen(path) + 1, 1451 path, 1452 &connector->base, 1453 dev->mode_config.path_property); 1454 return ret; 1455 } 1456 EXPORT_SYMBOL(drm_connector_set_path_property); 1457 1458 /** 1459 * drm_connector_set_tile_property - set tile property on connector 1460 * @connector: connector to set property on. 1461 * 1462 * This looks up the tile information for a connector, and creates a 1463 * property for userspace to parse if it exists. The property is of 1464 * the form of 8 integers using ':' as a separator. 1465 * 1466 * Returns: 1467 * Zero on success, errno on failure. 1468 */ 1469 int drm_connector_set_tile_property(struct drm_connector *connector) 1470 { 1471 struct drm_device *dev = connector->dev; 1472 char tile[256]; 1473 int ret; 1474 1475 if (!connector->has_tile) { 1476 ret = drm_property_replace_global_blob(dev, 1477 &connector->tile_blob_ptr, 1478 0, 1479 NULL, 1480 &connector->base, 1481 dev->mode_config.tile_property); 1482 return ret; 1483 } 1484 1485 snprintf(tile, 256, "%d:%d:%d:%d:%d:%d:%d:%d", 1486 connector->tile_group->id, connector->tile_is_single_monitor, 1487 connector->num_h_tile, connector->num_v_tile, 1488 connector->tile_h_loc, connector->tile_v_loc, 1489 connector->tile_h_size, connector->tile_v_size); 1490 1491 ret = drm_property_replace_global_blob(dev, 1492 &connector->tile_blob_ptr, 1493 strlen(tile) + 1, 1494 tile, 1495 &connector->base, 1496 dev->mode_config.tile_property); 1497 return ret; 1498 } 1499 EXPORT_SYMBOL(drm_connector_set_tile_property); 1500 1501 /** 1502 * drm_connector_update_edid_property - update the edid property of a connector 1503 * @connector: drm connector 1504 * @edid: new value of the edid property 1505 * 1506 * This function creates a new blob modeset object and assigns its id to the 1507 * connector's edid property. 1508 * 1509 * Returns: 1510 * Zero on success, negative errno on failure. 1511 */ 1512 int drm_connector_update_edid_property(struct drm_connector *connector, 1513 const struct edid *edid) 1514 { 1515 struct drm_device *dev = connector->dev; 1516 size_t size = 0; 1517 int ret; 1518 1519 /* ignore requests to set edid when overridden */ 1520 if (connector->override_edid) 1521 return 0; 1522 1523 if (edid) 1524 size = EDID_LENGTH * (1 + edid->extensions); 1525 1526 /* Set the display info, using edid if available, otherwise 1527 * reseting the values to defaults. This duplicates the work 1528 * done in drm_add_edid_modes, but that function is not 1529 * consistently called before this one in all drivers and the 1530 * computation is cheap enough that it seems better to 1531 * duplicate it rather than attempt to ensure some arbitrary 1532 * ordering of calls. 1533 */ 1534 if (edid) 1535 drm_add_display_info(connector, edid); 1536 else 1537 drm_reset_display_info(connector); 1538 1539 drm_object_property_set_value(&connector->base, 1540 dev->mode_config.non_desktop_property, 1541 connector->display_info.non_desktop); 1542 1543 ret = drm_property_replace_global_blob(dev, 1544 &connector->edid_blob_ptr, 1545 size, 1546 edid, 1547 &connector->base, 1548 dev->mode_config.edid_property); 1549 return ret; 1550 } 1551 EXPORT_SYMBOL(drm_connector_update_edid_property); 1552 1553 /** 1554 * drm_connector_set_link_status_property - Set link status property of a connector 1555 * @connector: drm connector 1556 * @link_status: new value of link status property (0: Good, 1: Bad) 1557 * 1558 * In usual working scenario, this link status property will always be set to 1559 * "GOOD". If something fails during or after a mode set, the kernel driver 1560 * may set this link status property to "BAD". The caller then needs to send a 1561 * hotplug uevent for userspace to re-check the valid modes through 1562 * GET_CONNECTOR_IOCTL and retry modeset. 1563 * 1564 * Note: Drivers cannot rely on userspace to support this property and 1565 * issue a modeset. As such, they may choose to handle issues (like 1566 * re-training a link) without userspace's intervention. 1567 * 1568 * The reason for adding this property is to handle link training failures, but 1569 * it is not limited to DP or link training. For example, if we implement 1570 * asynchronous setcrtc, this property can be used to report any failures in that. 1571 */ 1572 void drm_connector_set_link_status_property(struct drm_connector *connector, 1573 uint64_t link_status) 1574 { 1575 struct drm_device *dev = connector->dev; 1576 1577 drm_modeset_lock(&dev->mode_config.connection_mutex, NULL); 1578 connector->state->link_status = link_status; 1579 drm_modeset_unlock(&dev->mode_config.connection_mutex); 1580 } 1581 EXPORT_SYMBOL(drm_connector_set_link_status_property); 1582 1583 /** 1584 * drm_connector_init_panel_orientation_property - 1585 * initialize the connecters panel_orientation property 1586 * @connector: connector for which to init the panel-orientation property. 1587 * @width: width in pixels of the panel, used for panel quirk detection 1588 * @height: height in pixels of the panel, used for panel quirk detection 1589 * 1590 * This function should only be called for built-in panels, after setting 1591 * connector->display_info.panel_orientation first (if known). 1592 * 1593 * This function will check for platform specific (e.g. DMI based) quirks 1594 * overriding display_info.panel_orientation first, then if panel_orientation 1595 * is not DRM_MODE_PANEL_ORIENTATION_UNKNOWN it will attach the 1596 * "panel orientation" property to the connector. 1597 * 1598 * Returns: 1599 * Zero on success, negative errno on failure. 1600 */ 1601 int drm_connector_init_panel_orientation_property( 1602 struct drm_connector *connector, int width, int height) 1603 { 1604 struct drm_device *dev = connector->dev; 1605 struct drm_display_info *info = &connector->display_info; 1606 struct drm_property *prop; 1607 int orientation_quirk; 1608 1609 orientation_quirk = drm_get_panel_orientation_quirk(width, height); 1610 if (orientation_quirk != DRM_MODE_PANEL_ORIENTATION_UNKNOWN) 1611 info->panel_orientation = orientation_quirk; 1612 1613 if (info->panel_orientation == DRM_MODE_PANEL_ORIENTATION_UNKNOWN) 1614 return 0; 1615 1616 prop = dev->mode_config.panel_orientation_property; 1617 if (!prop) { 1618 prop = drm_property_create_enum(dev, DRM_MODE_PROP_IMMUTABLE, 1619 "panel orientation", 1620 drm_panel_orientation_enum_list, 1621 ARRAY_SIZE(drm_panel_orientation_enum_list)); 1622 if (!prop) 1623 return -ENOMEM; 1624 1625 dev->mode_config.panel_orientation_property = prop; 1626 } 1627 1628 drm_object_attach_property(&connector->base, prop, 1629 info->panel_orientation); 1630 return 0; 1631 } 1632 EXPORT_SYMBOL(drm_connector_init_panel_orientation_property); 1633 1634 int drm_connector_set_obj_prop(struct drm_mode_object *obj, 1635 struct drm_property *property, 1636 uint64_t value) 1637 { 1638 int ret = -EINVAL; 1639 struct drm_connector *connector = obj_to_connector(obj); 1640 1641 /* Do DPMS ourselves */ 1642 if (property == connector->dev->mode_config.dpms_property) { 1643 ret = (*connector->funcs->dpms)(connector, (int)value); 1644 #ifdef __OpenBSD__ 1645 } else if (property == connector->backlight_property) { 1646 connector->backlight_device->props.brightness = value; 1647 backlight_schedule_update_status(connector->backlight_device); 1648 ret = 0; 1649 #endif 1650 } else if (connector->funcs->set_property) 1651 ret = connector->funcs->set_property(connector, property, value); 1652 1653 if (!ret) 1654 drm_object_property_set_value(&connector->base, property, value); 1655 return ret; 1656 } 1657 1658 int drm_connector_property_set_ioctl(struct drm_device *dev, 1659 void *data, struct drm_file *file_priv) 1660 { 1661 struct drm_mode_connector_set_property *conn_set_prop = data; 1662 struct drm_mode_obj_set_property obj_set_prop = { 1663 .value = conn_set_prop->value, 1664 .prop_id = conn_set_prop->prop_id, 1665 .obj_id = conn_set_prop->connector_id, 1666 .obj_type = DRM_MODE_OBJECT_CONNECTOR 1667 }; 1668 1669 /* It does all the locking and checking we need */ 1670 return drm_mode_obj_set_property_ioctl(dev, &obj_set_prop, file_priv); 1671 } 1672 1673 static struct drm_encoder *drm_connector_get_encoder(struct drm_connector *connector) 1674 { 1675 /* For atomic drivers only state objects are synchronously updated and 1676 * protected by modeset locks, so check those first. */ 1677 if (connector->state) 1678 return connector->state->best_encoder; 1679 return connector->encoder; 1680 } 1681 1682 static bool 1683 drm_mode_expose_to_userspace(const struct drm_display_mode *mode, 1684 const struct list_head *export_list, 1685 const struct drm_file *file_priv) 1686 { 1687 /* 1688 * If user-space hasn't configured the driver to expose the stereo 3D 1689 * modes, don't expose them. 1690 */ 1691 if (!file_priv->stereo_allowed && drm_mode_is_stereo(mode)) 1692 return false; 1693 /* 1694 * If user-space hasn't configured the driver to expose the modes 1695 * with aspect-ratio, don't expose them. However if such a mode 1696 * is unique, let it be exposed, but reset the aspect-ratio flags 1697 * while preparing the list of user-modes. 1698 */ 1699 if (!file_priv->aspect_ratio_allowed) { 1700 struct drm_display_mode *mode_itr; 1701 1702 list_for_each_entry(mode_itr, export_list, export_head) 1703 if (drm_mode_match(mode_itr, mode, 1704 DRM_MODE_MATCH_TIMINGS | 1705 DRM_MODE_MATCH_CLOCK | 1706 DRM_MODE_MATCH_FLAGS | 1707 DRM_MODE_MATCH_3D_FLAGS)) 1708 return false; 1709 } 1710 1711 return true; 1712 } 1713 1714 int drm_mode_getconnector(struct drm_device *dev, void *data, 1715 struct drm_file *file_priv) 1716 { 1717 struct drm_mode_get_connector *out_resp = data; 1718 struct drm_connector *connector; 1719 struct drm_encoder *encoder; 1720 struct drm_display_mode *mode; 1721 int mode_count = 0; 1722 int encoders_count = 0; 1723 int ret = 0; 1724 int copied = 0; 1725 int i; 1726 struct drm_mode_modeinfo u_mode; 1727 struct drm_mode_modeinfo __user *mode_ptr; 1728 uint32_t __user *encoder_ptr; 1729 DRM_LIST_HEAD(export_list); 1730 1731 if (!drm_core_check_feature(dev, DRIVER_MODESET)) 1732 return -EINVAL; 1733 1734 memset(&u_mode, 0, sizeof(struct drm_mode_modeinfo)); 1735 1736 connector = drm_connector_lookup(dev, file_priv, out_resp->connector_id); 1737 if (!connector) 1738 return -ENOENT; 1739 1740 drm_connector_for_each_possible_encoder(connector, encoder, i) 1741 encoders_count++; 1742 1743 if ((out_resp->count_encoders >= encoders_count) && encoders_count) { 1744 copied = 0; 1745 encoder_ptr = (uint32_t __user *)(unsigned long)(out_resp->encoders_ptr); 1746 1747 drm_connector_for_each_possible_encoder(connector, encoder, i) { 1748 if (put_user(encoder->base.id, encoder_ptr + copied)) { 1749 ret = -EFAULT; 1750 goto out; 1751 } 1752 copied++; 1753 } 1754 } 1755 out_resp->count_encoders = encoders_count; 1756 1757 out_resp->connector_id = connector->base.id; 1758 out_resp->connector_type = connector->connector_type; 1759 out_resp->connector_type_id = connector->connector_type_id; 1760 1761 mutex_lock(&dev->mode_config.mutex); 1762 if (out_resp->count_modes == 0) { 1763 connector->funcs->fill_modes(connector, 1764 dev->mode_config.max_width, 1765 dev->mode_config.max_height); 1766 } 1767 1768 out_resp->mm_width = connector->display_info.width_mm; 1769 out_resp->mm_height = connector->display_info.height_mm; 1770 out_resp->subpixel = connector->display_info.subpixel_order; 1771 out_resp->connection = connector->status; 1772 1773 /* delayed so we get modes regardless of pre-fill_modes state */ 1774 list_for_each_entry(mode, &connector->modes, head) 1775 if (drm_mode_expose_to_userspace(mode, &export_list, 1776 file_priv)) { 1777 list_add_tail(&mode->export_head, &export_list); 1778 mode_count++; 1779 } 1780 1781 /* 1782 * This ioctl is called twice, once to determine how much space is 1783 * needed, and the 2nd time to fill it. 1784 * The modes that need to be exposed to the user are maintained in the 1785 * 'export_list'. When the ioctl is called first time to determine the, 1786 * space, the export_list gets filled, to find the no.of modes. In the 1787 * 2nd time, the user modes are filled, one by one from the export_list. 1788 */ 1789 if ((out_resp->count_modes >= mode_count) && mode_count) { 1790 copied = 0; 1791 mode_ptr = (struct drm_mode_modeinfo __user *)(unsigned long)out_resp->modes_ptr; 1792 list_for_each_entry(mode, &export_list, export_head) { 1793 drm_mode_convert_to_umode(&u_mode, mode); 1794 /* 1795 * Reset aspect ratio flags of user-mode, if modes with 1796 * aspect-ratio are not supported. 1797 */ 1798 if (!file_priv->aspect_ratio_allowed) 1799 u_mode.flags &= ~DRM_MODE_FLAG_PIC_AR_MASK; 1800 if (copy_to_user(mode_ptr + copied, 1801 &u_mode, sizeof(u_mode))) { 1802 ret = -EFAULT; 1803 mutex_unlock(&dev->mode_config.mutex); 1804 1805 goto out; 1806 } 1807 copied++; 1808 } 1809 } 1810 out_resp->count_modes = mode_count; 1811 mutex_unlock(&dev->mode_config.mutex); 1812 1813 drm_modeset_lock(&dev->mode_config.connection_mutex, NULL); 1814 encoder = drm_connector_get_encoder(connector); 1815 if (encoder) 1816 out_resp->encoder_id = encoder->base.id; 1817 else 1818 out_resp->encoder_id = 0; 1819 1820 /* Only grab properties after probing, to make sure EDID and other 1821 * properties reflect the latest status. */ 1822 ret = drm_mode_object_get_properties(&connector->base, file_priv->atomic, 1823 (uint32_t __user *)(unsigned long)(out_resp->props_ptr), 1824 (uint64_t __user *)(unsigned long)(out_resp->prop_values_ptr), 1825 &out_resp->count_props); 1826 drm_modeset_unlock(&dev->mode_config.connection_mutex); 1827 1828 out: 1829 drm_connector_put(connector); 1830 1831 return ret; 1832 } 1833 1834 1835 /** 1836 * DOC: Tile group 1837 * 1838 * Tile groups are used to represent tiled monitors with a unique integer 1839 * identifier. Tiled monitors using DisplayID v1.3 have a unique 8-byte handle, 1840 * we store this in a tile group, so we have a common identifier for all tiles 1841 * in a monitor group. The property is called "TILE". Drivers can manage tile 1842 * groups using drm_mode_create_tile_group(), drm_mode_put_tile_group() and 1843 * drm_mode_get_tile_group(). But this is only needed for internal panels where 1844 * the tile group information is exposed through a non-standard way. 1845 */ 1846 1847 static void drm_tile_group_free(struct kref *kref) 1848 { 1849 struct drm_tile_group *tg = container_of(kref, struct drm_tile_group, refcount); 1850 struct drm_device *dev = tg->dev; 1851 mutex_lock(&dev->mode_config.idr_mutex); 1852 idr_remove(&dev->mode_config.tile_idr, tg->id); 1853 mutex_unlock(&dev->mode_config.idr_mutex); 1854 kfree(tg); 1855 } 1856 1857 /** 1858 * drm_mode_put_tile_group - drop a reference to a tile group. 1859 * @dev: DRM device 1860 * @tg: tile group to drop reference to. 1861 * 1862 * drop reference to tile group and free if 0. 1863 */ 1864 void drm_mode_put_tile_group(struct drm_device *dev, 1865 struct drm_tile_group *tg) 1866 { 1867 kref_put(&tg->refcount, drm_tile_group_free); 1868 } 1869 EXPORT_SYMBOL(drm_mode_put_tile_group); 1870 1871 /** 1872 * drm_mode_get_tile_group - get a reference to an existing tile group 1873 * @dev: DRM device 1874 * @topology: 8-bytes unique per monitor. 1875 * 1876 * Use the unique bytes to get a reference to an existing tile group. 1877 * 1878 * RETURNS: 1879 * tile group or NULL if not found. 1880 */ 1881 struct drm_tile_group *drm_mode_get_tile_group(struct drm_device *dev, 1882 char topology[8]) 1883 { 1884 struct drm_tile_group *tg; 1885 int id; 1886 mutex_lock(&dev->mode_config.idr_mutex); 1887 idr_for_each_entry(&dev->mode_config.tile_idr, tg, id) { 1888 if (!memcmp(tg->group_data, topology, 8)) { 1889 if (!kref_get_unless_zero(&tg->refcount)) 1890 tg = NULL; 1891 mutex_unlock(&dev->mode_config.idr_mutex); 1892 return tg; 1893 } 1894 } 1895 mutex_unlock(&dev->mode_config.idr_mutex); 1896 return NULL; 1897 } 1898 EXPORT_SYMBOL(drm_mode_get_tile_group); 1899 1900 /** 1901 * drm_mode_create_tile_group - create a tile group from a displayid description 1902 * @dev: DRM device 1903 * @topology: 8-bytes unique per monitor. 1904 * 1905 * Create a tile group for the unique monitor, and get a unique 1906 * identifier for the tile group. 1907 * 1908 * RETURNS: 1909 * new tile group or error. 1910 */ 1911 struct drm_tile_group *drm_mode_create_tile_group(struct drm_device *dev, 1912 char topology[8]) 1913 { 1914 struct drm_tile_group *tg; 1915 int ret; 1916 1917 tg = kzalloc(sizeof(*tg), GFP_KERNEL); 1918 if (!tg) 1919 return ERR_PTR(-ENOMEM); 1920 1921 kref_init(&tg->refcount); 1922 memcpy(tg->group_data, topology, 8); 1923 tg->dev = dev; 1924 1925 mutex_lock(&dev->mode_config.idr_mutex); 1926 ret = idr_alloc(&dev->mode_config.tile_idr, tg, 1, 0, GFP_KERNEL); 1927 if (ret >= 0) { 1928 tg->id = ret; 1929 } else { 1930 kfree(tg); 1931 tg = ERR_PTR(ret); 1932 } 1933 1934 mutex_unlock(&dev->mode_config.idr_mutex); 1935 return tg; 1936 } 1937 EXPORT_SYMBOL(drm_mode_create_tile_group); 1938