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