Daniel Vetter | 5221719 | 2016-08-12 22:48:50 +0200 | [diff] [blame] | 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> |
Laurent Pinchart | 9338203 | 2016-11-28 20:51:09 +0200 | [diff] [blame] | 26 | #include <drm/drm_encoder.h> |
Daniel Vetter | 5221719 | 2016-08-12 22:48:50 +0200 | [diff] [blame] | 27 | |
| 28 | #include "drm_crtc_internal.h" |
| 29 | #include "drm_internal.h" |
| 30 | |
Daniel Vetter | ae2a6da | 2016-08-12 22:48:53 +0200 | [diff] [blame] | 31 | /** |
| 32 | * DOC: overview |
| 33 | * |
| 34 | * In DRM connectors are the general abstraction for display sinks, and include |
| 35 | * als fixed panels or anything else that can display pixels in some form. As |
| 36 | * opposed to all other KMS objects representing hardware (like CRTC, encoder or |
| 37 | * plane abstractions) connectors can be hotplugged and unplugged at runtime. |
| 38 | * Hence they are reference-counted using drm_connector_reference() and |
| 39 | * drm_connector_unreference(). |
| 40 | * |
Daniel Vetter | d574528 | 2017-01-25 07:26:45 +0100 | [diff] [blame] | 41 | * KMS driver must create, initialize, register and attach at a &struct |
| 42 | * drm_connector for each such sink. The instance is created as other KMS |
Daniel Vetter | aec9746 | 2017-01-25 07:26:48 +0100 | [diff] [blame] | 43 | * objects and initialized by setting the following fields. The connector is |
| 44 | * initialized with a call to drm_connector_init() with a pointer to the |
| 45 | * &struct drm_connector_funcs and a connector type, and then exposed to |
| 46 | * userspace with a call to drm_connector_register(). |
Daniel Vetter | ae2a6da | 2016-08-12 22:48:53 +0200 | [diff] [blame] | 47 | * |
| 48 | * Connectors must be attached to an encoder to be used. For devices that map |
| 49 | * connectors to encoders 1:1, the connector should be attached at |
| 50 | * initialization time with a call to drm_mode_connector_attach_encoder(). The |
Daniel Vetter | d574528 | 2017-01-25 07:26:45 +0100 | [diff] [blame] | 51 | * driver must also set the &drm_connector.encoder field to point to the |
Daniel Vetter | ae2a6da | 2016-08-12 22:48:53 +0200 | [diff] [blame] | 52 | * attached encoder. |
| 53 | * |
| 54 | * For connectors which are not fixed (like built-in panels) the driver needs to |
| 55 | * support hotplug notifications. The simplest way to do that is by using the |
| 56 | * probe helpers, see drm_kms_helper_poll_init() for connectors which don't have |
| 57 | * hardware support for hotplug interrupts. Connectors with hardware hotplug |
| 58 | * support can instead use e.g. drm_helper_hpd_irq_event(). |
| 59 | */ |
| 60 | |
Daniel Vetter | 5221719 | 2016-08-12 22:48:50 +0200 | [diff] [blame] | 61 | struct drm_conn_prop_enum_list { |
| 62 | int type; |
| 63 | const char *name; |
| 64 | struct ida ida; |
| 65 | }; |
| 66 | |
| 67 | /* |
| 68 | * Connector and encoder types. |
| 69 | */ |
| 70 | static struct drm_conn_prop_enum_list drm_connector_enum_list[] = { |
| 71 | { DRM_MODE_CONNECTOR_Unknown, "Unknown" }, |
| 72 | { DRM_MODE_CONNECTOR_VGA, "VGA" }, |
| 73 | { DRM_MODE_CONNECTOR_DVII, "DVI-I" }, |
| 74 | { DRM_MODE_CONNECTOR_DVID, "DVI-D" }, |
| 75 | { DRM_MODE_CONNECTOR_DVIA, "DVI-A" }, |
| 76 | { DRM_MODE_CONNECTOR_Composite, "Composite" }, |
| 77 | { DRM_MODE_CONNECTOR_SVIDEO, "SVIDEO" }, |
| 78 | { DRM_MODE_CONNECTOR_LVDS, "LVDS" }, |
| 79 | { DRM_MODE_CONNECTOR_Component, "Component" }, |
| 80 | { DRM_MODE_CONNECTOR_9PinDIN, "DIN" }, |
| 81 | { DRM_MODE_CONNECTOR_DisplayPort, "DP" }, |
| 82 | { DRM_MODE_CONNECTOR_HDMIA, "HDMI-A" }, |
| 83 | { DRM_MODE_CONNECTOR_HDMIB, "HDMI-B" }, |
| 84 | { DRM_MODE_CONNECTOR_TV, "TV" }, |
| 85 | { DRM_MODE_CONNECTOR_eDP, "eDP" }, |
| 86 | { DRM_MODE_CONNECTOR_VIRTUAL, "Virtual" }, |
| 87 | { DRM_MODE_CONNECTOR_DSI, "DSI" }, |
| 88 | { DRM_MODE_CONNECTOR_DPI, "DPI" }, |
| 89 | }; |
| 90 | |
| 91 | void drm_connector_ida_init(void) |
| 92 | { |
| 93 | int i; |
| 94 | |
| 95 | for (i = 0; i < ARRAY_SIZE(drm_connector_enum_list); i++) |
| 96 | ida_init(&drm_connector_enum_list[i].ida); |
| 97 | } |
| 98 | |
| 99 | void drm_connector_ida_destroy(void) |
| 100 | { |
| 101 | int i; |
| 102 | |
| 103 | for (i = 0; i < ARRAY_SIZE(drm_connector_enum_list); i++) |
| 104 | ida_destroy(&drm_connector_enum_list[i].ida); |
| 105 | } |
| 106 | |
| 107 | /** |
| 108 | * drm_connector_get_cmdline_mode - reads the user's cmdline mode |
| 109 | * @connector: connector to quwery |
| 110 | * |
Daniel Vetter | ae2a6da | 2016-08-12 22:48:53 +0200 | [diff] [blame] | 111 | * The kernel supports per-connector configuration of its consoles through |
Daniel Vetter | 5221719 | 2016-08-12 22:48:50 +0200 | [diff] [blame] | 112 | * use of the video= parameter. This function parses that option and |
| 113 | * extracts the user's specified mode (or enable/disable status) for a |
| 114 | * particular connector. This is typically only used during the early fbdev |
| 115 | * setup. |
| 116 | */ |
| 117 | static void drm_connector_get_cmdline_mode(struct drm_connector *connector) |
| 118 | { |
| 119 | struct drm_cmdline_mode *mode = &connector->cmdline_mode; |
| 120 | char *option = NULL; |
| 121 | |
| 122 | if (fb_get_options(connector->name, &option)) |
| 123 | return; |
| 124 | |
| 125 | if (!drm_mode_parse_command_line_for_connector(option, |
| 126 | connector, |
| 127 | mode)) |
| 128 | return; |
| 129 | |
| 130 | if (mode->force) { |
| 131 | const char *s; |
| 132 | |
| 133 | switch (mode->force) { |
| 134 | case DRM_FORCE_OFF: |
| 135 | s = "OFF"; |
| 136 | break; |
| 137 | case DRM_FORCE_ON_DIGITAL: |
| 138 | s = "ON - dig"; |
| 139 | break; |
| 140 | default: |
| 141 | case DRM_FORCE_ON: |
| 142 | s = "ON"; |
| 143 | break; |
| 144 | } |
| 145 | |
| 146 | DRM_INFO("forcing %s connector %s\n", connector->name, s); |
| 147 | connector->force = mode->force; |
| 148 | } |
| 149 | |
| 150 | DRM_DEBUG_KMS("cmdline mode for connector %s %dx%d@%dHz%s%s%s\n", |
| 151 | connector->name, |
| 152 | mode->xres, mode->yres, |
| 153 | mode->refresh_specified ? mode->refresh : 60, |
| 154 | mode->rb ? " reduced blanking" : "", |
| 155 | mode->margins ? " with margins" : "", |
| 156 | mode->interlace ? " interlaced" : ""); |
| 157 | } |
| 158 | |
| 159 | static void drm_connector_free(struct kref *kref) |
| 160 | { |
| 161 | struct drm_connector *connector = |
| 162 | container_of(kref, struct drm_connector, base.refcount); |
| 163 | struct drm_device *dev = connector->dev; |
| 164 | |
| 165 | drm_mode_object_unregister(dev, &connector->base); |
| 166 | connector->funcs->destroy(connector); |
| 167 | } |
| 168 | |
| 169 | /** |
| 170 | * drm_connector_init - Init a preallocated connector |
| 171 | * @dev: DRM device |
| 172 | * @connector: the connector to init |
| 173 | * @funcs: callbacks for this connector |
| 174 | * @connector_type: user visible type of the connector |
| 175 | * |
| 176 | * Initialises a preallocated connector. Connectors should be |
| 177 | * subclassed as part of driver connector objects. |
| 178 | * |
| 179 | * Returns: |
| 180 | * Zero on success, error code on failure. |
| 181 | */ |
| 182 | int drm_connector_init(struct drm_device *dev, |
| 183 | struct drm_connector *connector, |
| 184 | const struct drm_connector_funcs *funcs, |
| 185 | int connector_type) |
| 186 | { |
| 187 | struct drm_mode_config *config = &dev->mode_config; |
| 188 | int ret; |
| 189 | struct ida *connector_ida = |
| 190 | &drm_connector_enum_list[connector_type].ida; |
| 191 | |
Daniel Vetter | 5221719 | 2016-08-12 22:48:50 +0200 | [diff] [blame] | 192 | ret = drm_mode_object_get_reg(dev, &connector->base, |
| 193 | DRM_MODE_OBJECT_CONNECTOR, |
| 194 | false, drm_connector_free); |
| 195 | if (ret) |
Daniel Vetter | 613051d | 2016-12-14 00:08:06 +0100 | [diff] [blame] | 196 | return ret; |
Daniel Vetter | 5221719 | 2016-08-12 22:48:50 +0200 | [diff] [blame] | 197 | |
| 198 | connector->base.properties = &connector->properties; |
| 199 | connector->dev = dev; |
| 200 | connector->funcs = funcs; |
| 201 | |
| 202 | ret = ida_simple_get(&config->connector_ida, 0, 0, GFP_KERNEL); |
| 203 | if (ret < 0) |
| 204 | goto out_put; |
| 205 | connector->index = ret; |
| 206 | ret = 0; |
| 207 | |
| 208 | connector->connector_type = connector_type; |
| 209 | connector->connector_type_id = |
| 210 | ida_simple_get(connector_ida, 1, 0, GFP_KERNEL); |
| 211 | if (connector->connector_type_id < 0) { |
| 212 | ret = connector->connector_type_id; |
| 213 | goto out_put_id; |
| 214 | } |
| 215 | connector->name = |
| 216 | kasprintf(GFP_KERNEL, "%s-%d", |
| 217 | drm_connector_enum_list[connector_type].name, |
| 218 | connector->connector_type_id); |
| 219 | if (!connector->name) { |
| 220 | ret = -ENOMEM; |
| 221 | goto out_put_type_id; |
| 222 | } |
| 223 | |
| 224 | INIT_LIST_HEAD(&connector->probed_modes); |
| 225 | INIT_LIST_HEAD(&connector->modes); |
Daniel Vetter | e73ab00 | 2016-12-18 14:35:45 +0100 | [diff] [blame] | 226 | mutex_init(&connector->mutex); |
Daniel Vetter | 5221719 | 2016-08-12 22:48:50 +0200 | [diff] [blame] | 227 | connector->edid_blob_ptr = NULL; |
| 228 | connector->status = connector_status_unknown; |
| 229 | |
| 230 | drm_connector_get_cmdline_mode(connector); |
| 231 | |
| 232 | /* We should add connectors at the end to avoid upsetting the connector |
| 233 | * index too much. */ |
Daniel Vetter | 613051d | 2016-12-14 00:08:06 +0100 | [diff] [blame] | 234 | spin_lock_irq(&config->connector_list_lock); |
Daniel Vetter | 5221719 | 2016-08-12 22:48:50 +0200 | [diff] [blame] | 235 | list_add_tail(&connector->head, &config->connector_list); |
| 236 | config->num_connector++; |
Daniel Vetter | 613051d | 2016-12-14 00:08:06 +0100 | [diff] [blame] | 237 | spin_unlock_irq(&config->connector_list_lock); |
Daniel Vetter | 5221719 | 2016-08-12 22:48:50 +0200 | [diff] [blame] | 238 | |
| 239 | if (connector_type != DRM_MODE_CONNECTOR_VIRTUAL) |
| 240 | drm_object_attach_property(&connector->base, |
| 241 | config->edid_property, |
| 242 | 0); |
| 243 | |
| 244 | drm_object_attach_property(&connector->base, |
| 245 | config->dpms_property, 0); |
| 246 | |
Manasi Navare | 40ee6fb | 2016-12-16 12:29:06 +0200 | [diff] [blame^] | 247 | drm_object_attach_property(&connector->base, |
| 248 | config->link_status_property, |
| 249 | 0); |
| 250 | |
Daniel Vetter | 5221719 | 2016-08-12 22:48:50 +0200 | [diff] [blame] | 251 | if (drm_core_check_feature(dev, DRIVER_ATOMIC)) { |
| 252 | drm_object_attach_property(&connector->base, config->prop_crtc_id, 0); |
| 253 | } |
| 254 | |
| 255 | connector->debugfs_entry = NULL; |
| 256 | out_put_type_id: |
| 257 | if (ret) |
Christophe JAILLET | 587680c | 2016-10-02 08:01:22 +0200 | [diff] [blame] | 258 | ida_simple_remove(connector_ida, connector->connector_type_id); |
Daniel Vetter | 5221719 | 2016-08-12 22:48:50 +0200 | [diff] [blame] | 259 | out_put_id: |
| 260 | if (ret) |
Christophe JAILLET | 587680c | 2016-10-02 08:01:22 +0200 | [diff] [blame] | 261 | ida_simple_remove(&config->connector_ida, connector->index); |
Daniel Vetter | 5221719 | 2016-08-12 22:48:50 +0200 | [diff] [blame] | 262 | out_put: |
| 263 | if (ret) |
| 264 | drm_mode_object_unregister(dev, &connector->base); |
| 265 | |
Daniel Vetter | 5221719 | 2016-08-12 22:48:50 +0200 | [diff] [blame] | 266 | return ret; |
| 267 | } |
| 268 | EXPORT_SYMBOL(drm_connector_init); |
| 269 | |
| 270 | /** |
| 271 | * drm_mode_connector_attach_encoder - attach a connector to an encoder |
| 272 | * @connector: connector to attach |
| 273 | * @encoder: encoder to attach @connector to |
| 274 | * |
| 275 | * This function links up a connector to an encoder. Note that the routing |
| 276 | * restrictions between encoders and crtcs are exposed to userspace through the |
| 277 | * possible_clones and possible_crtcs bitmasks. |
| 278 | * |
| 279 | * Returns: |
| 280 | * Zero on success, negative errno on failure. |
| 281 | */ |
| 282 | int drm_mode_connector_attach_encoder(struct drm_connector *connector, |
| 283 | struct drm_encoder *encoder) |
| 284 | { |
| 285 | int i; |
| 286 | |
| 287 | /* |
| 288 | * In the past, drivers have attempted to model the static association |
| 289 | * of connector to encoder in simple connector/encoder devices using a |
| 290 | * direct assignment of connector->encoder = encoder. This connection |
| 291 | * is a logical one and the responsibility of the core, so drivers are |
| 292 | * expected not to mess with this. |
| 293 | * |
| 294 | * Note that the error return should've been enough here, but a large |
| 295 | * majority of drivers ignores the return value, so add in a big WARN |
| 296 | * to get people's attention. |
| 297 | */ |
| 298 | if (WARN_ON(connector->encoder)) |
| 299 | return -EINVAL; |
| 300 | |
| 301 | for (i = 0; i < DRM_CONNECTOR_MAX_ENCODER; i++) { |
| 302 | if (connector->encoder_ids[i] == 0) { |
| 303 | connector->encoder_ids[i] = encoder->base.id; |
| 304 | return 0; |
| 305 | } |
| 306 | } |
| 307 | return -ENOMEM; |
| 308 | } |
| 309 | EXPORT_SYMBOL(drm_mode_connector_attach_encoder); |
| 310 | |
| 311 | static void drm_mode_remove(struct drm_connector *connector, |
| 312 | struct drm_display_mode *mode) |
| 313 | { |
| 314 | list_del(&mode->head); |
| 315 | drm_mode_destroy(connector->dev, mode); |
| 316 | } |
| 317 | |
| 318 | /** |
| 319 | * drm_connector_cleanup - cleans up an initialised connector |
| 320 | * @connector: connector to cleanup |
| 321 | * |
| 322 | * Cleans up the connector but doesn't free the object. |
| 323 | */ |
| 324 | void drm_connector_cleanup(struct drm_connector *connector) |
| 325 | { |
| 326 | struct drm_device *dev = connector->dev; |
| 327 | struct drm_display_mode *mode, *t; |
| 328 | |
| 329 | /* The connector should have been removed from userspace long before |
| 330 | * it is finally destroyed. |
| 331 | */ |
| 332 | if (WARN_ON(connector->registered)) |
| 333 | drm_connector_unregister(connector); |
| 334 | |
| 335 | if (connector->tile_group) { |
| 336 | drm_mode_put_tile_group(dev, connector->tile_group); |
| 337 | connector->tile_group = NULL; |
| 338 | } |
| 339 | |
| 340 | list_for_each_entry_safe(mode, t, &connector->probed_modes, head) |
| 341 | drm_mode_remove(connector, mode); |
| 342 | |
| 343 | list_for_each_entry_safe(mode, t, &connector->modes, head) |
| 344 | drm_mode_remove(connector, mode); |
| 345 | |
Christophe JAILLET | 9a47dba | 2016-10-07 09:27:41 +0200 | [diff] [blame] | 346 | ida_simple_remove(&drm_connector_enum_list[connector->connector_type].ida, |
| 347 | connector->connector_type_id); |
Daniel Vetter | 5221719 | 2016-08-12 22:48:50 +0200 | [diff] [blame] | 348 | |
Christophe JAILLET | 9a47dba | 2016-10-07 09:27:41 +0200 | [diff] [blame] | 349 | ida_simple_remove(&dev->mode_config.connector_ida, |
| 350 | connector->index); |
Daniel Vetter | 5221719 | 2016-08-12 22:48:50 +0200 | [diff] [blame] | 351 | |
| 352 | kfree(connector->display_info.bus_formats); |
| 353 | drm_mode_object_unregister(dev, &connector->base); |
| 354 | kfree(connector->name); |
| 355 | connector->name = NULL; |
Daniel Vetter | 613051d | 2016-12-14 00:08:06 +0100 | [diff] [blame] | 356 | spin_lock_irq(&dev->mode_config.connector_list_lock); |
Daniel Vetter | 5221719 | 2016-08-12 22:48:50 +0200 | [diff] [blame] | 357 | list_del(&connector->head); |
| 358 | dev->mode_config.num_connector--; |
Daniel Vetter | 613051d | 2016-12-14 00:08:06 +0100 | [diff] [blame] | 359 | spin_unlock_irq(&dev->mode_config.connector_list_lock); |
Daniel Vetter | 5221719 | 2016-08-12 22:48:50 +0200 | [diff] [blame] | 360 | |
| 361 | WARN_ON(connector->state && !connector->funcs->atomic_destroy_state); |
| 362 | if (connector->state && connector->funcs->atomic_destroy_state) |
| 363 | connector->funcs->atomic_destroy_state(connector, |
| 364 | connector->state); |
| 365 | |
Daniel Vetter | e73ab00 | 2016-12-18 14:35:45 +0100 | [diff] [blame] | 366 | mutex_destroy(&connector->mutex); |
| 367 | |
Daniel Vetter | 5221719 | 2016-08-12 22:48:50 +0200 | [diff] [blame] | 368 | memset(connector, 0, sizeof(*connector)); |
| 369 | } |
| 370 | EXPORT_SYMBOL(drm_connector_cleanup); |
| 371 | |
| 372 | /** |
| 373 | * drm_connector_register - register a connector |
| 374 | * @connector: the connector to register |
| 375 | * |
| 376 | * Register userspace interfaces for a connector |
| 377 | * |
| 378 | * Returns: |
| 379 | * Zero on success, error code on failure. |
| 380 | */ |
| 381 | int drm_connector_register(struct drm_connector *connector) |
| 382 | { |
Daniel Vetter | e73ab00 | 2016-12-18 14:35:45 +0100 | [diff] [blame] | 383 | int ret = 0; |
Daniel Vetter | 5221719 | 2016-08-12 22:48:50 +0200 | [diff] [blame] | 384 | |
Daniel Vetter | e6e7b48 | 2017-01-12 17:15:56 +0100 | [diff] [blame] | 385 | if (!connector->dev->registered) |
| 386 | return 0; |
| 387 | |
Daniel Vetter | e73ab00 | 2016-12-18 14:35:45 +0100 | [diff] [blame] | 388 | mutex_lock(&connector->mutex); |
Daniel Vetter | 5221719 | 2016-08-12 22:48:50 +0200 | [diff] [blame] | 389 | if (connector->registered) |
Daniel Vetter | e73ab00 | 2016-12-18 14:35:45 +0100 | [diff] [blame] | 390 | goto unlock; |
Daniel Vetter | 5221719 | 2016-08-12 22:48:50 +0200 | [diff] [blame] | 391 | |
| 392 | ret = drm_sysfs_connector_add(connector); |
| 393 | if (ret) |
Daniel Vetter | e73ab00 | 2016-12-18 14:35:45 +0100 | [diff] [blame] | 394 | goto unlock; |
Daniel Vetter | 5221719 | 2016-08-12 22:48:50 +0200 | [diff] [blame] | 395 | |
| 396 | ret = drm_debugfs_connector_add(connector); |
| 397 | if (ret) { |
| 398 | goto err_sysfs; |
| 399 | } |
| 400 | |
| 401 | if (connector->funcs->late_register) { |
| 402 | ret = connector->funcs->late_register(connector); |
| 403 | if (ret) |
| 404 | goto err_debugfs; |
| 405 | } |
| 406 | |
| 407 | drm_mode_object_register(connector->dev, &connector->base); |
| 408 | |
| 409 | connector->registered = true; |
Daniel Vetter | e73ab00 | 2016-12-18 14:35:45 +0100 | [diff] [blame] | 410 | goto unlock; |
Daniel Vetter | 5221719 | 2016-08-12 22:48:50 +0200 | [diff] [blame] | 411 | |
| 412 | err_debugfs: |
| 413 | drm_debugfs_connector_remove(connector); |
| 414 | err_sysfs: |
| 415 | drm_sysfs_connector_remove(connector); |
Daniel Vetter | e73ab00 | 2016-12-18 14:35:45 +0100 | [diff] [blame] | 416 | unlock: |
| 417 | mutex_unlock(&connector->mutex); |
Daniel Vetter | 5221719 | 2016-08-12 22:48:50 +0200 | [diff] [blame] | 418 | return ret; |
| 419 | } |
| 420 | EXPORT_SYMBOL(drm_connector_register); |
| 421 | |
| 422 | /** |
| 423 | * drm_connector_unregister - unregister a connector |
| 424 | * @connector: the connector to unregister |
| 425 | * |
| 426 | * Unregister userspace interfaces for a connector |
| 427 | */ |
| 428 | void drm_connector_unregister(struct drm_connector *connector) |
| 429 | { |
Daniel Vetter | e73ab00 | 2016-12-18 14:35:45 +0100 | [diff] [blame] | 430 | mutex_lock(&connector->mutex); |
| 431 | if (!connector->registered) { |
| 432 | mutex_unlock(&connector->mutex); |
Daniel Vetter | 5221719 | 2016-08-12 22:48:50 +0200 | [diff] [blame] | 433 | return; |
Daniel Vetter | e73ab00 | 2016-12-18 14:35:45 +0100 | [diff] [blame] | 434 | } |
Daniel Vetter | 5221719 | 2016-08-12 22:48:50 +0200 | [diff] [blame] | 435 | |
| 436 | if (connector->funcs->early_unregister) |
| 437 | connector->funcs->early_unregister(connector); |
| 438 | |
| 439 | drm_sysfs_connector_remove(connector); |
| 440 | drm_debugfs_connector_remove(connector); |
| 441 | |
| 442 | connector->registered = false; |
Daniel Vetter | e73ab00 | 2016-12-18 14:35:45 +0100 | [diff] [blame] | 443 | mutex_unlock(&connector->mutex); |
Daniel Vetter | 5221719 | 2016-08-12 22:48:50 +0200 | [diff] [blame] | 444 | } |
| 445 | EXPORT_SYMBOL(drm_connector_unregister); |
| 446 | |
| 447 | void drm_connector_unregister_all(struct drm_device *dev) |
| 448 | { |
| 449 | struct drm_connector *connector; |
Daniel Vetter | 613051d | 2016-12-14 00:08:06 +0100 | [diff] [blame] | 450 | struct drm_connector_list_iter conn_iter; |
Daniel Vetter | 5221719 | 2016-08-12 22:48:50 +0200 | [diff] [blame] | 451 | |
Daniel Vetter | 613051d | 2016-12-14 00:08:06 +0100 | [diff] [blame] | 452 | drm_connector_list_iter_get(dev, &conn_iter); |
| 453 | drm_for_each_connector_iter(connector, &conn_iter) |
Daniel Vetter | 5221719 | 2016-08-12 22:48:50 +0200 | [diff] [blame] | 454 | drm_connector_unregister(connector); |
Daniel Vetter | 613051d | 2016-12-14 00:08:06 +0100 | [diff] [blame] | 455 | drm_connector_list_iter_put(&conn_iter); |
Daniel Vetter | 5221719 | 2016-08-12 22:48:50 +0200 | [diff] [blame] | 456 | } |
| 457 | |
| 458 | int drm_connector_register_all(struct drm_device *dev) |
| 459 | { |
| 460 | struct drm_connector *connector; |
Daniel Vetter | 613051d | 2016-12-14 00:08:06 +0100 | [diff] [blame] | 461 | struct drm_connector_list_iter conn_iter; |
| 462 | int ret = 0; |
Daniel Vetter | 5221719 | 2016-08-12 22:48:50 +0200 | [diff] [blame] | 463 | |
Daniel Vetter | 613051d | 2016-12-14 00:08:06 +0100 | [diff] [blame] | 464 | drm_connector_list_iter_get(dev, &conn_iter); |
| 465 | drm_for_each_connector_iter(connector, &conn_iter) { |
Daniel Vetter | 5221719 | 2016-08-12 22:48:50 +0200 | [diff] [blame] | 466 | ret = drm_connector_register(connector); |
| 467 | if (ret) |
Daniel Vetter | 613051d | 2016-12-14 00:08:06 +0100 | [diff] [blame] | 468 | break; |
Daniel Vetter | 5221719 | 2016-08-12 22:48:50 +0200 | [diff] [blame] | 469 | } |
Daniel Vetter | 613051d | 2016-12-14 00:08:06 +0100 | [diff] [blame] | 470 | drm_connector_list_iter_put(&conn_iter); |
Daniel Vetter | 5221719 | 2016-08-12 22:48:50 +0200 | [diff] [blame] | 471 | |
Daniel Vetter | 613051d | 2016-12-14 00:08:06 +0100 | [diff] [blame] | 472 | if (ret) |
| 473 | drm_connector_unregister_all(dev); |
Daniel Vetter | 5221719 | 2016-08-12 22:48:50 +0200 | [diff] [blame] | 474 | return ret; |
| 475 | } |
| 476 | |
| 477 | /** |
| 478 | * drm_get_connector_status_name - return a string for connector status |
| 479 | * @status: connector status to compute name of |
| 480 | * |
| 481 | * In contrast to the other drm_get_*_name functions this one here returns a |
| 482 | * const pointer and hence is threadsafe. |
| 483 | */ |
| 484 | const char *drm_get_connector_status_name(enum drm_connector_status status) |
| 485 | { |
| 486 | if (status == connector_status_connected) |
| 487 | return "connected"; |
| 488 | else if (status == connector_status_disconnected) |
| 489 | return "disconnected"; |
| 490 | else |
| 491 | return "unknown"; |
| 492 | } |
| 493 | EXPORT_SYMBOL(drm_get_connector_status_name); |
| 494 | |
Daniel Vetter | 613051d | 2016-12-14 00:08:06 +0100 | [diff] [blame] | 495 | #ifdef CONFIG_LOCKDEP |
| 496 | static struct lockdep_map connector_list_iter_dep_map = { |
| 497 | .name = "drm_connector_list_iter" |
| 498 | }; |
| 499 | #endif |
| 500 | |
| 501 | /** |
| 502 | * drm_connector_list_iter_get - initialize a connector_list iterator |
| 503 | * @dev: DRM device |
| 504 | * @iter: connector_list iterator |
| 505 | * |
Daniel Vetter | d574528 | 2017-01-25 07:26:45 +0100 | [diff] [blame] | 506 | * Sets @iter up to walk the &drm_mode_config.connector_list of @dev. @iter |
Daniel Vetter | 613051d | 2016-12-14 00:08:06 +0100 | [diff] [blame] | 507 | * must always be cleaned up again by calling drm_connector_list_iter_put(). |
| 508 | * Iteration itself happens using drm_connector_list_iter_next() or |
| 509 | * drm_for_each_connector_iter(). |
| 510 | */ |
| 511 | void drm_connector_list_iter_get(struct drm_device *dev, |
| 512 | struct drm_connector_list_iter *iter) |
| 513 | { |
| 514 | iter->dev = dev; |
| 515 | iter->conn = NULL; |
| 516 | lock_acquire_shared_recursive(&connector_list_iter_dep_map, 0, 1, NULL, _RET_IP_); |
| 517 | } |
| 518 | EXPORT_SYMBOL(drm_connector_list_iter_get); |
| 519 | |
| 520 | /** |
| 521 | * drm_connector_list_iter_next - return next connector |
| 522 | * @iter: connectr_list iterator |
| 523 | * |
| 524 | * Returns the next connector for @iter, or NULL when the list walk has |
| 525 | * completed. |
| 526 | */ |
| 527 | struct drm_connector * |
| 528 | drm_connector_list_iter_next(struct drm_connector_list_iter *iter) |
| 529 | { |
| 530 | struct drm_connector *old_conn = iter->conn; |
| 531 | struct drm_mode_config *config = &iter->dev->mode_config; |
| 532 | struct list_head *lhead; |
| 533 | unsigned long flags; |
| 534 | |
| 535 | spin_lock_irqsave(&config->connector_list_lock, flags); |
| 536 | lhead = old_conn ? &old_conn->head : &config->connector_list; |
| 537 | |
| 538 | do { |
| 539 | if (lhead->next == &config->connector_list) { |
| 540 | iter->conn = NULL; |
| 541 | break; |
| 542 | } |
| 543 | |
| 544 | lhead = lhead->next; |
| 545 | iter->conn = list_entry(lhead, struct drm_connector, head); |
| 546 | |
| 547 | /* loop until it's not a zombie connector */ |
| 548 | } while (!kref_get_unless_zero(&iter->conn->base.refcount)); |
| 549 | spin_unlock_irqrestore(&config->connector_list_lock, flags); |
| 550 | |
| 551 | if (old_conn) |
| 552 | drm_connector_unreference(old_conn); |
| 553 | |
| 554 | return iter->conn; |
| 555 | } |
| 556 | EXPORT_SYMBOL(drm_connector_list_iter_next); |
| 557 | |
| 558 | /** |
| 559 | * drm_connector_list_iter_put - tear down a connector_list iterator |
| 560 | * @iter: connector_list iterator |
| 561 | * |
| 562 | * Tears down @iter and releases any resources (like &drm_connector references) |
| 563 | * acquired while walking the list. This must always be called, both when the |
| 564 | * iteration completes fully or when it was aborted without walking the entire |
| 565 | * list. |
| 566 | */ |
| 567 | void drm_connector_list_iter_put(struct drm_connector_list_iter *iter) |
| 568 | { |
| 569 | iter->dev = NULL; |
| 570 | if (iter->conn) |
| 571 | drm_connector_unreference(iter->conn); |
| 572 | lock_release(&connector_list_iter_dep_map, 0, _RET_IP_); |
| 573 | } |
| 574 | EXPORT_SYMBOL(drm_connector_list_iter_put); |
| 575 | |
Daniel Vetter | 5221719 | 2016-08-12 22:48:50 +0200 | [diff] [blame] | 576 | static const struct drm_prop_enum_list drm_subpixel_enum_list[] = { |
| 577 | { SubPixelUnknown, "Unknown" }, |
| 578 | { SubPixelHorizontalRGB, "Horizontal RGB" }, |
| 579 | { SubPixelHorizontalBGR, "Horizontal BGR" }, |
| 580 | { SubPixelVerticalRGB, "Vertical RGB" }, |
| 581 | { SubPixelVerticalBGR, "Vertical BGR" }, |
| 582 | { SubPixelNone, "None" }, |
| 583 | }; |
| 584 | |
| 585 | /** |
| 586 | * drm_get_subpixel_order_name - return a string for a given subpixel enum |
| 587 | * @order: enum of subpixel_order |
| 588 | * |
| 589 | * Note you could abuse this and return something out of bounds, but that |
| 590 | * would be a caller error. No unscrubbed user data should make it here. |
| 591 | */ |
| 592 | const char *drm_get_subpixel_order_name(enum subpixel_order order) |
| 593 | { |
| 594 | return drm_subpixel_enum_list[order].name; |
| 595 | } |
| 596 | EXPORT_SYMBOL(drm_get_subpixel_order_name); |
| 597 | |
| 598 | static const struct drm_prop_enum_list drm_dpms_enum_list[] = { |
| 599 | { DRM_MODE_DPMS_ON, "On" }, |
| 600 | { DRM_MODE_DPMS_STANDBY, "Standby" }, |
| 601 | { DRM_MODE_DPMS_SUSPEND, "Suspend" }, |
| 602 | { DRM_MODE_DPMS_OFF, "Off" } |
| 603 | }; |
| 604 | DRM_ENUM_NAME_FN(drm_get_dpms_name, drm_dpms_enum_list) |
| 605 | |
Manasi Navare | 40ee6fb | 2016-12-16 12:29:06 +0200 | [diff] [blame^] | 606 | static const struct drm_prop_enum_list drm_link_status_enum_list[] = { |
| 607 | { DRM_MODE_LINK_STATUS_GOOD, "Good" }, |
| 608 | { DRM_MODE_LINK_STATUS_BAD, "Bad" }, |
| 609 | }; |
| 610 | DRM_ENUM_NAME_FN(drm_get_link_status_name, drm_link_status_enum_list) |
| 611 | |
Daniel Vetter | b3c6c8b | 2016-08-12 22:48:55 +0200 | [diff] [blame] | 612 | /** |
| 613 | * drm_display_info_set_bus_formats - set the supported bus formats |
| 614 | * @info: display info to store bus formats in |
| 615 | * @formats: array containing the supported bus formats |
| 616 | * @num_formats: the number of entries in the fmts array |
| 617 | * |
| 618 | * Store the supported bus formats in display info structure. |
| 619 | * See MEDIA_BUS_FMT_* definitions in include/uapi/linux/media-bus-format.h for |
| 620 | * a full list of available formats. |
| 621 | */ |
| 622 | int drm_display_info_set_bus_formats(struct drm_display_info *info, |
| 623 | const u32 *formats, |
| 624 | unsigned int num_formats) |
| 625 | { |
| 626 | u32 *fmts = NULL; |
| 627 | |
| 628 | if (!formats && num_formats) |
| 629 | return -EINVAL; |
| 630 | |
| 631 | if (formats && num_formats) { |
| 632 | fmts = kmemdup(formats, sizeof(*formats) * num_formats, |
| 633 | GFP_KERNEL); |
| 634 | if (!fmts) |
| 635 | return -ENOMEM; |
| 636 | } |
| 637 | |
| 638 | kfree(info->bus_formats); |
| 639 | info->bus_formats = fmts; |
| 640 | info->num_bus_formats = num_formats; |
| 641 | |
| 642 | return 0; |
| 643 | } |
| 644 | EXPORT_SYMBOL(drm_display_info_set_bus_formats); |
| 645 | |
Daniel Vetter | 5221719 | 2016-08-12 22:48:50 +0200 | [diff] [blame] | 646 | /* Optional connector properties. */ |
| 647 | static const struct drm_prop_enum_list drm_scaling_mode_enum_list[] = { |
| 648 | { DRM_MODE_SCALE_NONE, "None" }, |
| 649 | { DRM_MODE_SCALE_FULLSCREEN, "Full" }, |
| 650 | { DRM_MODE_SCALE_CENTER, "Center" }, |
| 651 | { DRM_MODE_SCALE_ASPECT, "Full aspect" }, |
| 652 | }; |
| 653 | |
| 654 | static const struct drm_prop_enum_list drm_aspect_ratio_enum_list[] = { |
| 655 | { DRM_MODE_PICTURE_ASPECT_NONE, "Automatic" }, |
| 656 | { DRM_MODE_PICTURE_ASPECT_4_3, "4:3" }, |
| 657 | { DRM_MODE_PICTURE_ASPECT_16_9, "16:9" }, |
| 658 | }; |
| 659 | |
| 660 | static const struct drm_prop_enum_list drm_dvi_i_select_enum_list[] = { |
| 661 | { DRM_MODE_SUBCONNECTOR_Automatic, "Automatic" }, /* DVI-I and TV-out */ |
| 662 | { DRM_MODE_SUBCONNECTOR_DVID, "DVI-D" }, /* DVI-I */ |
| 663 | { DRM_MODE_SUBCONNECTOR_DVIA, "DVI-A" }, /* DVI-I */ |
| 664 | }; |
| 665 | DRM_ENUM_NAME_FN(drm_get_dvi_i_select_name, drm_dvi_i_select_enum_list) |
| 666 | |
| 667 | static const struct drm_prop_enum_list drm_dvi_i_subconnector_enum_list[] = { |
| 668 | { DRM_MODE_SUBCONNECTOR_Unknown, "Unknown" }, /* DVI-I and TV-out */ |
| 669 | { DRM_MODE_SUBCONNECTOR_DVID, "DVI-D" }, /* DVI-I */ |
| 670 | { DRM_MODE_SUBCONNECTOR_DVIA, "DVI-A" }, /* DVI-I */ |
| 671 | }; |
| 672 | DRM_ENUM_NAME_FN(drm_get_dvi_i_subconnector_name, |
| 673 | drm_dvi_i_subconnector_enum_list) |
| 674 | |
| 675 | static const struct drm_prop_enum_list drm_tv_select_enum_list[] = { |
| 676 | { DRM_MODE_SUBCONNECTOR_Automatic, "Automatic" }, /* DVI-I and TV-out */ |
| 677 | { DRM_MODE_SUBCONNECTOR_Composite, "Composite" }, /* TV-out */ |
| 678 | { DRM_MODE_SUBCONNECTOR_SVIDEO, "SVIDEO" }, /* TV-out */ |
| 679 | { DRM_MODE_SUBCONNECTOR_Component, "Component" }, /* TV-out */ |
| 680 | { DRM_MODE_SUBCONNECTOR_SCART, "SCART" }, /* TV-out */ |
| 681 | }; |
| 682 | DRM_ENUM_NAME_FN(drm_get_tv_select_name, drm_tv_select_enum_list) |
| 683 | |
| 684 | static const struct drm_prop_enum_list drm_tv_subconnector_enum_list[] = { |
| 685 | { DRM_MODE_SUBCONNECTOR_Unknown, "Unknown" }, /* DVI-I and TV-out */ |
| 686 | { DRM_MODE_SUBCONNECTOR_Composite, "Composite" }, /* TV-out */ |
| 687 | { DRM_MODE_SUBCONNECTOR_SVIDEO, "SVIDEO" }, /* TV-out */ |
| 688 | { DRM_MODE_SUBCONNECTOR_Component, "Component" }, /* TV-out */ |
| 689 | { DRM_MODE_SUBCONNECTOR_SCART, "SCART" }, /* TV-out */ |
| 690 | }; |
| 691 | DRM_ENUM_NAME_FN(drm_get_tv_subconnector_name, |
| 692 | drm_tv_subconnector_enum_list) |
| 693 | |
Daniel Vetter | 4ada6f2 | 2016-11-17 09:56:48 +0100 | [diff] [blame] | 694 | /** |
| 695 | * DOC: standard connector properties |
| 696 | * |
| 697 | * DRM connectors have a few standardized properties: |
| 698 | * |
| 699 | * EDID: |
| 700 | * Blob property which contains the current EDID read from the sink. This |
| 701 | * is useful to parse sink identification information like vendor, model |
| 702 | * and serial. Drivers should update this property by calling |
| 703 | * drm_mode_connector_update_edid_property(), usually after having parsed |
| 704 | * the EDID using drm_add_edid_modes(). Userspace cannot change this |
| 705 | * property. |
| 706 | * DPMS: |
| 707 | * Legacy property for setting the power state of the connector. For atomic |
| 708 | * drivers this is only provided for backwards compatibility with existing |
| 709 | * drivers, it remaps to controlling the "ACTIVE" property on the CRTC the |
| 710 | * connector is linked to. Drivers should never set this property directly, |
Daniel Vetter | d574528 | 2017-01-25 07:26:45 +0100 | [diff] [blame] | 711 | * it is handled by the DRM core by calling the &drm_connector_funcs.dpms |
| 712 | * callback. Atomic drivers should implement this hook using |
Daniel Vetter | 4ada6f2 | 2016-11-17 09:56:48 +0100 | [diff] [blame] | 713 | * drm_atomic_helper_connector_dpms(). This is the only property standard |
| 714 | * connector property that userspace can change. |
| 715 | * PATH: |
| 716 | * Connector path property to identify how this sink is physically |
| 717 | * connected. Used by DP MST. This should be set by calling |
| 718 | * drm_mode_connector_set_path_property(), in the case of DP MST with the |
| 719 | * path property the MST manager created. Userspace cannot change this |
| 720 | * property. |
| 721 | * TILE: |
| 722 | * Connector tile group property to indicate how a set of DRM connector |
| 723 | * compose together into one logical screen. This is used by both high-res |
| 724 | * external screens (often only using a single cable, but exposing multiple |
| 725 | * DP MST sinks), or high-res integrated panels (like dual-link DSI) which |
| 726 | * are not gen-locked. Note that for tiled panels which are genlocked, like |
| 727 | * dual-link LVDS or dual-link DSI, the driver should try to not expose the |
| 728 | * tiling and virtualize both &drm_crtc and &drm_plane if needed. Drivers |
| 729 | * should update this value using drm_mode_connector_set_tile_property(). |
| 730 | * Userspace cannot change this property. |
Manasi Navare | 40ee6fb | 2016-12-16 12:29:06 +0200 | [diff] [blame^] | 731 | * link-status: |
| 732 | * Connector link-status property to indicate the status of link. The default |
| 733 | * value of link-status is "GOOD". If something fails during or after modeset, |
| 734 | * the kernel driver may set this to "BAD" and issue a hotplug uevent. Drivers |
| 735 | * should update this value using drm_mode_connector_set_link_status_property(). |
Daniel Vetter | 4ada6f2 | 2016-11-17 09:56:48 +0100 | [diff] [blame] | 736 | * |
| 737 | * Connectors also have one standardized atomic property: |
| 738 | * |
| 739 | * CRTC_ID: |
| 740 | * Mode object ID of the &drm_crtc this connector should be connected to. |
| 741 | */ |
| 742 | |
Daniel Vetter | 5221719 | 2016-08-12 22:48:50 +0200 | [diff] [blame] | 743 | int drm_connector_create_standard_properties(struct drm_device *dev) |
| 744 | { |
| 745 | struct drm_property *prop; |
| 746 | |
| 747 | prop = drm_property_create(dev, DRM_MODE_PROP_BLOB | |
| 748 | DRM_MODE_PROP_IMMUTABLE, |
| 749 | "EDID", 0); |
| 750 | if (!prop) |
| 751 | return -ENOMEM; |
| 752 | dev->mode_config.edid_property = prop; |
| 753 | |
| 754 | prop = drm_property_create_enum(dev, 0, |
| 755 | "DPMS", drm_dpms_enum_list, |
| 756 | ARRAY_SIZE(drm_dpms_enum_list)); |
| 757 | if (!prop) |
| 758 | return -ENOMEM; |
| 759 | dev->mode_config.dpms_property = prop; |
| 760 | |
| 761 | prop = drm_property_create(dev, |
| 762 | DRM_MODE_PROP_BLOB | |
| 763 | DRM_MODE_PROP_IMMUTABLE, |
| 764 | "PATH", 0); |
| 765 | if (!prop) |
| 766 | return -ENOMEM; |
| 767 | dev->mode_config.path_property = prop; |
| 768 | |
| 769 | prop = drm_property_create(dev, |
| 770 | DRM_MODE_PROP_BLOB | |
| 771 | DRM_MODE_PROP_IMMUTABLE, |
| 772 | "TILE", 0); |
| 773 | if (!prop) |
| 774 | return -ENOMEM; |
| 775 | dev->mode_config.tile_property = prop; |
| 776 | |
Manasi Navare | 40ee6fb | 2016-12-16 12:29:06 +0200 | [diff] [blame^] | 777 | prop = drm_property_create_enum(dev, 0, "link-status", |
| 778 | drm_link_status_enum_list, |
| 779 | ARRAY_SIZE(drm_link_status_enum_list)); |
| 780 | if (!prop) |
| 781 | return -ENOMEM; |
| 782 | dev->mode_config.link_status_property = prop; |
| 783 | |
Daniel Vetter | 5221719 | 2016-08-12 22:48:50 +0200 | [diff] [blame] | 784 | return 0; |
| 785 | } |
| 786 | |
| 787 | /** |
| 788 | * drm_mode_create_dvi_i_properties - create DVI-I specific connector properties |
| 789 | * @dev: DRM device |
| 790 | * |
| 791 | * Called by a driver the first time a DVI-I connector is made. |
| 792 | */ |
| 793 | int drm_mode_create_dvi_i_properties(struct drm_device *dev) |
| 794 | { |
| 795 | struct drm_property *dvi_i_selector; |
| 796 | struct drm_property *dvi_i_subconnector; |
| 797 | |
| 798 | if (dev->mode_config.dvi_i_select_subconnector_property) |
| 799 | return 0; |
| 800 | |
| 801 | dvi_i_selector = |
| 802 | drm_property_create_enum(dev, 0, |
| 803 | "select subconnector", |
| 804 | drm_dvi_i_select_enum_list, |
| 805 | ARRAY_SIZE(drm_dvi_i_select_enum_list)); |
| 806 | dev->mode_config.dvi_i_select_subconnector_property = dvi_i_selector; |
| 807 | |
| 808 | dvi_i_subconnector = drm_property_create_enum(dev, DRM_MODE_PROP_IMMUTABLE, |
| 809 | "subconnector", |
| 810 | drm_dvi_i_subconnector_enum_list, |
| 811 | ARRAY_SIZE(drm_dvi_i_subconnector_enum_list)); |
| 812 | dev->mode_config.dvi_i_subconnector_property = dvi_i_subconnector; |
| 813 | |
| 814 | return 0; |
| 815 | } |
| 816 | EXPORT_SYMBOL(drm_mode_create_dvi_i_properties); |
| 817 | |
| 818 | /** |
| 819 | * drm_create_tv_properties - create TV specific connector properties |
| 820 | * @dev: DRM device |
| 821 | * @num_modes: number of different TV formats (modes) supported |
| 822 | * @modes: array of pointers to strings containing name of each format |
| 823 | * |
| 824 | * Called by a driver's TV initialization routine, this function creates |
| 825 | * the TV specific connector properties for a given device. Caller is |
| 826 | * responsible for allocating a list of format names and passing them to |
| 827 | * this routine. |
| 828 | */ |
| 829 | int drm_mode_create_tv_properties(struct drm_device *dev, |
| 830 | unsigned int num_modes, |
| 831 | const char * const modes[]) |
| 832 | { |
| 833 | struct drm_property *tv_selector; |
| 834 | struct drm_property *tv_subconnector; |
| 835 | unsigned int i; |
| 836 | |
| 837 | if (dev->mode_config.tv_select_subconnector_property) |
| 838 | return 0; |
| 839 | |
| 840 | /* |
| 841 | * Basic connector properties |
| 842 | */ |
| 843 | tv_selector = drm_property_create_enum(dev, 0, |
| 844 | "select subconnector", |
| 845 | drm_tv_select_enum_list, |
| 846 | ARRAY_SIZE(drm_tv_select_enum_list)); |
| 847 | if (!tv_selector) |
| 848 | goto nomem; |
| 849 | |
| 850 | dev->mode_config.tv_select_subconnector_property = tv_selector; |
| 851 | |
| 852 | tv_subconnector = |
| 853 | drm_property_create_enum(dev, DRM_MODE_PROP_IMMUTABLE, |
| 854 | "subconnector", |
| 855 | drm_tv_subconnector_enum_list, |
| 856 | ARRAY_SIZE(drm_tv_subconnector_enum_list)); |
| 857 | if (!tv_subconnector) |
| 858 | goto nomem; |
| 859 | dev->mode_config.tv_subconnector_property = tv_subconnector; |
| 860 | |
| 861 | /* |
| 862 | * Other, TV specific properties: margins & TV modes. |
| 863 | */ |
| 864 | dev->mode_config.tv_left_margin_property = |
| 865 | drm_property_create_range(dev, 0, "left margin", 0, 100); |
| 866 | if (!dev->mode_config.tv_left_margin_property) |
| 867 | goto nomem; |
| 868 | |
| 869 | dev->mode_config.tv_right_margin_property = |
| 870 | drm_property_create_range(dev, 0, "right margin", 0, 100); |
| 871 | if (!dev->mode_config.tv_right_margin_property) |
| 872 | goto nomem; |
| 873 | |
| 874 | dev->mode_config.tv_top_margin_property = |
| 875 | drm_property_create_range(dev, 0, "top margin", 0, 100); |
| 876 | if (!dev->mode_config.tv_top_margin_property) |
| 877 | goto nomem; |
| 878 | |
| 879 | dev->mode_config.tv_bottom_margin_property = |
| 880 | drm_property_create_range(dev, 0, "bottom margin", 0, 100); |
| 881 | if (!dev->mode_config.tv_bottom_margin_property) |
| 882 | goto nomem; |
| 883 | |
| 884 | dev->mode_config.tv_mode_property = |
| 885 | drm_property_create(dev, DRM_MODE_PROP_ENUM, |
| 886 | "mode", num_modes); |
| 887 | if (!dev->mode_config.tv_mode_property) |
| 888 | goto nomem; |
| 889 | |
| 890 | for (i = 0; i < num_modes; i++) |
| 891 | drm_property_add_enum(dev->mode_config.tv_mode_property, i, |
| 892 | i, modes[i]); |
| 893 | |
| 894 | dev->mode_config.tv_brightness_property = |
| 895 | drm_property_create_range(dev, 0, "brightness", 0, 100); |
| 896 | if (!dev->mode_config.tv_brightness_property) |
| 897 | goto nomem; |
| 898 | |
| 899 | dev->mode_config.tv_contrast_property = |
| 900 | drm_property_create_range(dev, 0, "contrast", 0, 100); |
| 901 | if (!dev->mode_config.tv_contrast_property) |
| 902 | goto nomem; |
| 903 | |
| 904 | dev->mode_config.tv_flicker_reduction_property = |
| 905 | drm_property_create_range(dev, 0, "flicker reduction", 0, 100); |
| 906 | if (!dev->mode_config.tv_flicker_reduction_property) |
| 907 | goto nomem; |
| 908 | |
| 909 | dev->mode_config.tv_overscan_property = |
| 910 | drm_property_create_range(dev, 0, "overscan", 0, 100); |
| 911 | if (!dev->mode_config.tv_overscan_property) |
| 912 | goto nomem; |
| 913 | |
| 914 | dev->mode_config.tv_saturation_property = |
| 915 | drm_property_create_range(dev, 0, "saturation", 0, 100); |
| 916 | if (!dev->mode_config.tv_saturation_property) |
| 917 | goto nomem; |
| 918 | |
| 919 | dev->mode_config.tv_hue_property = |
| 920 | drm_property_create_range(dev, 0, "hue", 0, 100); |
| 921 | if (!dev->mode_config.tv_hue_property) |
| 922 | goto nomem; |
| 923 | |
| 924 | return 0; |
| 925 | nomem: |
| 926 | return -ENOMEM; |
| 927 | } |
| 928 | EXPORT_SYMBOL(drm_mode_create_tv_properties); |
| 929 | |
| 930 | /** |
| 931 | * drm_mode_create_scaling_mode_property - create scaling mode property |
| 932 | * @dev: DRM device |
| 933 | * |
| 934 | * Called by a driver the first time it's needed, must be attached to desired |
| 935 | * connectors. |
| 936 | */ |
| 937 | int drm_mode_create_scaling_mode_property(struct drm_device *dev) |
| 938 | { |
| 939 | struct drm_property *scaling_mode; |
| 940 | |
| 941 | if (dev->mode_config.scaling_mode_property) |
| 942 | return 0; |
| 943 | |
| 944 | scaling_mode = |
| 945 | drm_property_create_enum(dev, 0, "scaling mode", |
| 946 | drm_scaling_mode_enum_list, |
| 947 | ARRAY_SIZE(drm_scaling_mode_enum_list)); |
| 948 | |
| 949 | dev->mode_config.scaling_mode_property = scaling_mode; |
| 950 | |
| 951 | return 0; |
| 952 | } |
| 953 | EXPORT_SYMBOL(drm_mode_create_scaling_mode_property); |
| 954 | |
| 955 | /** |
| 956 | * drm_mode_create_aspect_ratio_property - create aspect ratio property |
| 957 | * @dev: DRM device |
| 958 | * |
| 959 | * Called by a driver the first time it's needed, must be attached to desired |
| 960 | * connectors. |
| 961 | * |
| 962 | * Returns: |
| 963 | * Zero on success, negative errno on failure. |
| 964 | */ |
| 965 | int drm_mode_create_aspect_ratio_property(struct drm_device *dev) |
| 966 | { |
| 967 | if (dev->mode_config.aspect_ratio_property) |
| 968 | return 0; |
| 969 | |
| 970 | dev->mode_config.aspect_ratio_property = |
| 971 | drm_property_create_enum(dev, 0, "aspect ratio", |
| 972 | drm_aspect_ratio_enum_list, |
| 973 | ARRAY_SIZE(drm_aspect_ratio_enum_list)); |
| 974 | |
| 975 | if (dev->mode_config.aspect_ratio_property == NULL) |
| 976 | return -ENOMEM; |
| 977 | |
| 978 | return 0; |
| 979 | } |
| 980 | EXPORT_SYMBOL(drm_mode_create_aspect_ratio_property); |
| 981 | |
| 982 | /** |
| 983 | * drm_mode_create_suggested_offset_properties - create suggests offset properties |
| 984 | * @dev: DRM device |
| 985 | * |
| 986 | * Create the the suggested x/y offset property for connectors. |
| 987 | */ |
| 988 | int drm_mode_create_suggested_offset_properties(struct drm_device *dev) |
| 989 | { |
| 990 | if (dev->mode_config.suggested_x_property && dev->mode_config.suggested_y_property) |
| 991 | return 0; |
| 992 | |
| 993 | dev->mode_config.suggested_x_property = |
| 994 | drm_property_create_range(dev, DRM_MODE_PROP_IMMUTABLE, "suggested X", 0, 0xffffffff); |
| 995 | |
| 996 | dev->mode_config.suggested_y_property = |
| 997 | drm_property_create_range(dev, DRM_MODE_PROP_IMMUTABLE, "suggested Y", 0, 0xffffffff); |
| 998 | |
| 999 | if (dev->mode_config.suggested_x_property == NULL || |
| 1000 | dev->mode_config.suggested_y_property == NULL) |
| 1001 | return -ENOMEM; |
| 1002 | return 0; |
| 1003 | } |
| 1004 | EXPORT_SYMBOL(drm_mode_create_suggested_offset_properties); |
| 1005 | |
| 1006 | /** |
| 1007 | * drm_mode_connector_set_path_property - set tile property on connector |
| 1008 | * @connector: connector to set property on. |
| 1009 | * @path: path to use for property; must not be NULL. |
| 1010 | * |
| 1011 | * This creates a property to expose to userspace to specify a |
| 1012 | * connector path. This is mainly used for DisplayPort MST where |
| 1013 | * connectors have a topology and we want to allow userspace to give |
| 1014 | * them more meaningful names. |
| 1015 | * |
| 1016 | * Returns: |
| 1017 | * Zero on success, negative errno on failure. |
| 1018 | */ |
| 1019 | int drm_mode_connector_set_path_property(struct drm_connector *connector, |
| 1020 | const char *path) |
| 1021 | { |
| 1022 | struct drm_device *dev = connector->dev; |
| 1023 | int ret; |
| 1024 | |
| 1025 | ret = drm_property_replace_global_blob(dev, |
| 1026 | &connector->path_blob_ptr, |
| 1027 | strlen(path) + 1, |
| 1028 | path, |
| 1029 | &connector->base, |
| 1030 | dev->mode_config.path_property); |
| 1031 | return ret; |
| 1032 | } |
| 1033 | EXPORT_SYMBOL(drm_mode_connector_set_path_property); |
| 1034 | |
| 1035 | /** |
| 1036 | * drm_mode_connector_set_tile_property - set tile property on connector |
| 1037 | * @connector: connector to set property on. |
| 1038 | * |
| 1039 | * This looks up the tile information for a connector, and creates a |
| 1040 | * property for userspace to parse if it exists. The property is of |
| 1041 | * the form of 8 integers using ':' as a separator. |
| 1042 | * |
| 1043 | * Returns: |
| 1044 | * Zero on success, errno on failure. |
| 1045 | */ |
| 1046 | int drm_mode_connector_set_tile_property(struct drm_connector *connector) |
| 1047 | { |
| 1048 | struct drm_device *dev = connector->dev; |
| 1049 | char tile[256]; |
| 1050 | int ret; |
| 1051 | |
| 1052 | if (!connector->has_tile) { |
| 1053 | ret = drm_property_replace_global_blob(dev, |
| 1054 | &connector->tile_blob_ptr, |
| 1055 | 0, |
| 1056 | NULL, |
| 1057 | &connector->base, |
| 1058 | dev->mode_config.tile_property); |
| 1059 | return ret; |
| 1060 | } |
| 1061 | |
| 1062 | snprintf(tile, 256, "%d:%d:%d:%d:%d:%d:%d:%d", |
| 1063 | connector->tile_group->id, connector->tile_is_single_monitor, |
| 1064 | connector->num_h_tile, connector->num_v_tile, |
| 1065 | connector->tile_h_loc, connector->tile_v_loc, |
| 1066 | connector->tile_h_size, connector->tile_v_size); |
| 1067 | |
| 1068 | ret = drm_property_replace_global_blob(dev, |
| 1069 | &connector->tile_blob_ptr, |
| 1070 | strlen(tile) + 1, |
| 1071 | tile, |
| 1072 | &connector->base, |
| 1073 | dev->mode_config.tile_property); |
| 1074 | return ret; |
| 1075 | } |
| 1076 | EXPORT_SYMBOL(drm_mode_connector_set_tile_property); |
| 1077 | |
| 1078 | /** |
| 1079 | * drm_mode_connector_update_edid_property - update the edid property of a connector |
| 1080 | * @connector: drm connector |
| 1081 | * @edid: new value of the edid property |
| 1082 | * |
| 1083 | * This function creates a new blob modeset object and assigns its id to the |
| 1084 | * connector's edid property. |
| 1085 | * |
| 1086 | * Returns: |
| 1087 | * Zero on success, negative errno on failure. |
| 1088 | */ |
| 1089 | int drm_mode_connector_update_edid_property(struct drm_connector *connector, |
| 1090 | const struct edid *edid) |
| 1091 | { |
| 1092 | struct drm_device *dev = connector->dev; |
| 1093 | size_t size = 0; |
| 1094 | int ret; |
| 1095 | |
| 1096 | /* ignore requests to set edid when overridden */ |
| 1097 | if (connector->override_edid) |
| 1098 | return 0; |
| 1099 | |
| 1100 | if (edid) |
| 1101 | size = EDID_LENGTH * (1 + edid->extensions); |
| 1102 | |
| 1103 | ret = drm_property_replace_global_blob(dev, |
| 1104 | &connector->edid_blob_ptr, |
| 1105 | size, |
| 1106 | edid, |
| 1107 | &connector->base, |
| 1108 | dev->mode_config.edid_property); |
| 1109 | return ret; |
| 1110 | } |
| 1111 | EXPORT_SYMBOL(drm_mode_connector_update_edid_property); |
| 1112 | |
Manasi Navare | 40ee6fb | 2016-12-16 12:29:06 +0200 | [diff] [blame^] | 1113 | /** |
| 1114 | * drm_mode_connector_set_link_status_property - Set link status property of a connector |
| 1115 | * @connector: drm connector |
| 1116 | * @link_status: new value of link status property (0: Good, 1: Bad) |
| 1117 | * |
| 1118 | * In usual working scenario, this link status property will always be set to |
| 1119 | * "GOOD". If something fails during or after a mode set, the kernel driver |
| 1120 | * may set this link status property to "BAD". The caller then needs to send a |
| 1121 | * hotplug uevent for userspace to re-check the valid modes through |
| 1122 | * GET_CONNECTOR_IOCTL and retry modeset. |
| 1123 | * |
| 1124 | * Note: Drivers cannot rely on userspace to support this property and |
| 1125 | * issue a modeset. As such, they may choose to handle issues (like |
| 1126 | * re-training a link) without userspace's intervention. |
| 1127 | * |
| 1128 | * The reason for adding this property is to handle link training failures, but |
| 1129 | * it is not limited to DP or link training. For example, if we implement |
| 1130 | * asynchronous setcrtc, this property can be used to report any failures in that. |
| 1131 | */ |
| 1132 | void drm_mode_connector_set_link_status_property(struct drm_connector *connector, |
| 1133 | uint64_t link_status) |
| 1134 | { |
| 1135 | struct drm_device *dev = connector->dev; |
| 1136 | |
| 1137 | drm_modeset_lock(&dev->mode_config.connection_mutex, NULL); |
| 1138 | connector->state->link_status = link_status; |
| 1139 | drm_modeset_unlock(&dev->mode_config.connection_mutex); |
| 1140 | } |
| 1141 | EXPORT_SYMBOL(drm_mode_connector_set_link_status_property); |
| 1142 | |
Daniel Vetter | 5221719 | 2016-08-12 22:48:50 +0200 | [diff] [blame] | 1143 | int drm_mode_connector_set_obj_prop(struct drm_mode_object *obj, |
| 1144 | struct drm_property *property, |
| 1145 | uint64_t value) |
| 1146 | { |
| 1147 | int ret = -EINVAL; |
| 1148 | struct drm_connector *connector = obj_to_connector(obj); |
| 1149 | |
| 1150 | /* Do DPMS ourselves */ |
| 1151 | if (property == connector->dev->mode_config.dpms_property) { |
| 1152 | ret = (*connector->funcs->dpms)(connector, (int)value); |
| 1153 | } else if (connector->funcs->set_property) |
| 1154 | ret = connector->funcs->set_property(connector, property, value); |
| 1155 | |
| 1156 | /* store the property value if successful */ |
| 1157 | if (!ret) |
| 1158 | drm_object_property_set_value(&connector->base, property, value); |
| 1159 | return ret; |
| 1160 | } |
| 1161 | |
| 1162 | int drm_mode_connector_property_set_ioctl(struct drm_device *dev, |
| 1163 | void *data, struct drm_file *file_priv) |
| 1164 | { |
| 1165 | struct drm_mode_connector_set_property *conn_set_prop = data; |
| 1166 | struct drm_mode_obj_set_property obj_set_prop = { |
| 1167 | .value = conn_set_prop->value, |
| 1168 | .prop_id = conn_set_prop->prop_id, |
| 1169 | .obj_id = conn_set_prop->connector_id, |
| 1170 | .obj_type = DRM_MODE_OBJECT_CONNECTOR |
| 1171 | }; |
| 1172 | |
| 1173 | /* It does all the locking and checking we need */ |
| 1174 | return drm_mode_obj_set_property_ioctl(dev, &obj_set_prop, file_priv); |
| 1175 | } |
| 1176 | |
| 1177 | static struct drm_encoder *drm_connector_get_encoder(struct drm_connector *connector) |
| 1178 | { |
| 1179 | /* For atomic drivers only state objects are synchronously updated and |
| 1180 | * protected by modeset locks, so check those first. */ |
| 1181 | if (connector->state) |
| 1182 | return connector->state->best_encoder; |
| 1183 | return connector->encoder; |
| 1184 | } |
| 1185 | |
| 1186 | static bool drm_mode_expose_to_userspace(const struct drm_display_mode *mode, |
| 1187 | const struct drm_file *file_priv) |
| 1188 | { |
| 1189 | /* |
| 1190 | * If user-space hasn't configured the driver to expose the stereo 3D |
| 1191 | * modes, don't expose them. |
| 1192 | */ |
| 1193 | if (!file_priv->stereo_allowed && drm_mode_is_stereo(mode)) |
| 1194 | return false; |
| 1195 | |
| 1196 | return true; |
| 1197 | } |
| 1198 | |
| 1199 | int drm_mode_getconnector(struct drm_device *dev, void *data, |
| 1200 | struct drm_file *file_priv) |
| 1201 | { |
| 1202 | struct drm_mode_get_connector *out_resp = data; |
| 1203 | struct drm_connector *connector; |
| 1204 | struct drm_encoder *encoder; |
| 1205 | struct drm_display_mode *mode; |
| 1206 | int mode_count = 0; |
| 1207 | int encoders_count = 0; |
| 1208 | int ret = 0; |
| 1209 | int copied = 0; |
| 1210 | int i; |
| 1211 | struct drm_mode_modeinfo u_mode; |
| 1212 | struct drm_mode_modeinfo __user *mode_ptr; |
| 1213 | uint32_t __user *encoder_ptr; |
| 1214 | |
| 1215 | if (!drm_core_check_feature(dev, DRIVER_MODESET)) |
| 1216 | return -EINVAL; |
| 1217 | |
| 1218 | memset(&u_mode, 0, sizeof(struct drm_mode_modeinfo)); |
| 1219 | |
Daniel Vetter | 5221719 | 2016-08-12 22:48:50 +0200 | [diff] [blame] | 1220 | connector = drm_connector_lookup(dev, out_resp->connector_id); |
Daniel Vetter | 91eefc0 | 2016-12-14 00:08:10 +0100 | [diff] [blame] | 1221 | if (!connector) |
| 1222 | return -ENOENT; |
Daniel Vetter | 5221719 | 2016-08-12 22:48:50 +0200 | [diff] [blame] | 1223 | |
| 1224 | drm_modeset_lock(&dev->mode_config.connection_mutex, NULL); |
| 1225 | encoder = drm_connector_get_encoder(connector); |
| 1226 | if (encoder) |
| 1227 | out_resp->encoder_id = encoder->base.id; |
| 1228 | else |
| 1229 | out_resp->encoder_id = 0; |
| 1230 | |
Daniel Vetter | 91eefc0 | 2016-12-14 00:08:10 +0100 | [diff] [blame] | 1231 | ret = drm_mode_object_get_properties(&connector->base, file_priv->atomic, |
| 1232 | (uint32_t __user *)(unsigned long)(out_resp->props_ptr), |
| 1233 | (uint64_t __user *)(unsigned long)(out_resp->prop_values_ptr), |
| 1234 | &out_resp->count_props); |
| 1235 | drm_modeset_unlock(&dev->mode_config.connection_mutex); |
| 1236 | if (ret) |
| 1237 | goto out_unref; |
| 1238 | |
| 1239 | for (i = 0; i < DRM_CONNECTOR_MAX_ENCODER; i++) |
| 1240 | if (connector->encoder_ids[i] != 0) |
| 1241 | encoders_count++; |
| 1242 | |
| 1243 | if ((out_resp->count_encoders >= encoders_count) && encoders_count) { |
| 1244 | copied = 0; |
| 1245 | encoder_ptr = (uint32_t __user *)(unsigned long)(out_resp->encoders_ptr); |
| 1246 | for (i = 0; i < DRM_CONNECTOR_MAX_ENCODER; i++) { |
| 1247 | if (connector->encoder_ids[i] != 0) { |
| 1248 | if (put_user(connector->encoder_ids[i], |
| 1249 | encoder_ptr + copied)) { |
| 1250 | ret = -EFAULT; |
| 1251 | goto out_unref; |
| 1252 | } |
| 1253 | copied++; |
| 1254 | } |
| 1255 | } |
| 1256 | } |
| 1257 | out_resp->count_encoders = encoders_count; |
| 1258 | |
| 1259 | out_resp->connector_id = connector->base.id; |
| 1260 | out_resp->connector_type = connector->connector_type; |
| 1261 | out_resp->connector_type_id = connector->connector_type_id; |
| 1262 | |
| 1263 | mutex_lock(&dev->mode_config.mutex); |
| 1264 | if (out_resp->count_modes == 0) { |
| 1265 | connector->funcs->fill_modes(connector, |
| 1266 | dev->mode_config.max_width, |
| 1267 | dev->mode_config.max_height); |
| 1268 | } |
| 1269 | |
| 1270 | out_resp->mm_width = connector->display_info.width_mm; |
| 1271 | out_resp->mm_height = connector->display_info.height_mm; |
| 1272 | out_resp->subpixel = connector->display_info.subpixel_order; |
| 1273 | out_resp->connection = connector->status; |
| 1274 | |
| 1275 | /* delayed so we get modes regardless of pre-fill_modes state */ |
| 1276 | list_for_each_entry(mode, &connector->modes, head) |
| 1277 | if (drm_mode_expose_to_userspace(mode, file_priv)) |
| 1278 | mode_count++; |
| 1279 | |
Daniel Vetter | 5221719 | 2016-08-12 22:48:50 +0200 | [diff] [blame] | 1280 | /* |
| 1281 | * This ioctl is called twice, once to determine how much space is |
| 1282 | * needed, and the 2nd time to fill it. |
| 1283 | */ |
| 1284 | if ((out_resp->count_modes >= mode_count) && mode_count) { |
| 1285 | copied = 0; |
| 1286 | mode_ptr = (struct drm_mode_modeinfo __user *)(unsigned long)out_resp->modes_ptr; |
| 1287 | list_for_each_entry(mode, &connector->modes, head) { |
| 1288 | if (!drm_mode_expose_to_userspace(mode, file_priv)) |
| 1289 | continue; |
| 1290 | |
| 1291 | drm_mode_convert_to_umode(&u_mode, mode); |
| 1292 | if (copy_to_user(mode_ptr + copied, |
| 1293 | &u_mode, sizeof(u_mode))) { |
| 1294 | ret = -EFAULT; |
| 1295 | goto out; |
| 1296 | } |
| 1297 | copied++; |
| 1298 | } |
| 1299 | } |
| 1300 | out_resp->count_modes = mode_count; |
Daniel Vetter | 5221719 | 2016-08-12 22:48:50 +0200 | [diff] [blame] | 1301 | out: |
Daniel Vetter | 5221719 | 2016-08-12 22:48:50 +0200 | [diff] [blame] | 1302 | mutex_unlock(&dev->mode_config.mutex); |
Daniel Vetter | 91eefc0 | 2016-12-14 00:08:10 +0100 | [diff] [blame] | 1303 | out_unref: |
| 1304 | drm_connector_unreference(connector); |
Daniel Vetter | 5221719 | 2016-08-12 22:48:50 +0200 | [diff] [blame] | 1305 | |
| 1306 | return ret; |
| 1307 | } |
| 1308 | |
Daniel Vetter | 9498c19 | 2016-11-14 12:58:24 +0100 | [diff] [blame] | 1309 | |
| 1310 | /** |
| 1311 | * DOC: Tile group |
| 1312 | * |
| 1313 | * Tile groups are used to represent tiled monitors with a unique integer |
| 1314 | * identifier. Tiled monitors using DisplayID v1.3 have a unique 8-byte handle, |
| 1315 | * we store this in a tile group, so we have a common identifier for all tiles |
| 1316 | * in a monitor group. The property is called "TILE". Drivers can manage tile |
| 1317 | * groups using drm_mode_create_tile_group(), drm_mode_put_tile_group() and |
| 1318 | * drm_mode_get_tile_group(). But this is only needed for internal panels where |
| 1319 | * the tile group information is exposed through a non-standard way. |
| 1320 | */ |
| 1321 | |
| 1322 | static void drm_tile_group_free(struct kref *kref) |
| 1323 | { |
| 1324 | struct drm_tile_group *tg = container_of(kref, struct drm_tile_group, refcount); |
| 1325 | struct drm_device *dev = tg->dev; |
| 1326 | mutex_lock(&dev->mode_config.idr_mutex); |
| 1327 | idr_remove(&dev->mode_config.tile_idr, tg->id); |
| 1328 | mutex_unlock(&dev->mode_config.idr_mutex); |
| 1329 | kfree(tg); |
| 1330 | } |
| 1331 | |
| 1332 | /** |
| 1333 | * drm_mode_put_tile_group - drop a reference to a tile group. |
| 1334 | * @dev: DRM device |
| 1335 | * @tg: tile group to drop reference to. |
| 1336 | * |
| 1337 | * drop reference to tile group and free if 0. |
| 1338 | */ |
| 1339 | void drm_mode_put_tile_group(struct drm_device *dev, |
| 1340 | struct drm_tile_group *tg) |
| 1341 | { |
| 1342 | kref_put(&tg->refcount, drm_tile_group_free); |
| 1343 | } |
| 1344 | EXPORT_SYMBOL(drm_mode_put_tile_group); |
| 1345 | |
| 1346 | /** |
| 1347 | * drm_mode_get_tile_group - get a reference to an existing tile group |
| 1348 | * @dev: DRM device |
| 1349 | * @topology: 8-bytes unique per monitor. |
| 1350 | * |
| 1351 | * Use the unique bytes to get a reference to an existing tile group. |
| 1352 | * |
| 1353 | * RETURNS: |
| 1354 | * tile group or NULL if not found. |
| 1355 | */ |
| 1356 | struct drm_tile_group *drm_mode_get_tile_group(struct drm_device *dev, |
| 1357 | char topology[8]) |
| 1358 | { |
| 1359 | struct drm_tile_group *tg; |
| 1360 | int id; |
| 1361 | mutex_lock(&dev->mode_config.idr_mutex); |
| 1362 | idr_for_each_entry(&dev->mode_config.tile_idr, tg, id) { |
| 1363 | if (!memcmp(tg->group_data, topology, 8)) { |
| 1364 | if (!kref_get_unless_zero(&tg->refcount)) |
| 1365 | tg = NULL; |
| 1366 | mutex_unlock(&dev->mode_config.idr_mutex); |
| 1367 | return tg; |
| 1368 | } |
| 1369 | } |
| 1370 | mutex_unlock(&dev->mode_config.idr_mutex); |
| 1371 | return NULL; |
| 1372 | } |
| 1373 | EXPORT_SYMBOL(drm_mode_get_tile_group); |
| 1374 | |
| 1375 | /** |
| 1376 | * drm_mode_create_tile_group - create a tile group from a displayid description |
| 1377 | * @dev: DRM device |
| 1378 | * @topology: 8-bytes unique per monitor. |
| 1379 | * |
| 1380 | * Create a tile group for the unique monitor, and get a unique |
| 1381 | * identifier for the tile group. |
| 1382 | * |
| 1383 | * RETURNS: |
| 1384 | * new tile group or error. |
| 1385 | */ |
| 1386 | struct drm_tile_group *drm_mode_create_tile_group(struct drm_device *dev, |
| 1387 | char topology[8]) |
| 1388 | { |
| 1389 | struct drm_tile_group *tg; |
| 1390 | int ret; |
| 1391 | |
| 1392 | tg = kzalloc(sizeof(*tg), GFP_KERNEL); |
| 1393 | if (!tg) |
| 1394 | return ERR_PTR(-ENOMEM); |
| 1395 | |
| 1396 | kref_init(&tg->refcount); |
| 1397 | memcpy(tg->group_data, topology, 8); |
| 1398 | tg->dev = dev; |
| 1399 | |
| 1400 | mutex_lock(&dev->mode_config.idr_mutex); |
| 1401 | ret = idr_alloc(&dev->mode_config.tile_idr, tg, 1, 0, GFP_KERNEL); |
| 1402 | if (ret >= 0) { |
| 1403 | tg->id = ret; |
| 1404 | } else { |
| 1405 | kfree(tg); |
| 1406 | tg = ERR_PTR(ret); |
| 1407 | } |
| 1408 | |
| 1409 | mutex_unlock(&dev->mode_config.idr_mutex); |
| 1410 | return tg; |
| 1411 | } |
| 1412 | EXPORT_SYMBOL(drm_mode_create_tile_group); |