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