GNU Linux-libre 4.19.264-gnu1
[releases.git] / include / drm / drm_connector.h
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 #ifndef __DRM_CONNECTOR_H__
24 #define __DRM_CONNECTOR_H__
25
26 #include <linux/list.h>
27 #include <linux/llist.h>
28 #include <linux/ctype.h>
29 #include <linux/hdmi.h>
30 #include <drm/drm_mode_object.h>
31
32 #include <uapi/drm/drm_mode.h>
33
34 struct drm_connector_helper_funcs;
35 struct drm_modeset_acquire_ctx;
36 struct drm_device;
37 struct drm_crtc;
38 struct drm_encoder;
39 struct drm_property;
40 struct drm_property_blob;
41 struct drm_printer;
42 struct edid;
43
44 enum drm_connector_force {
45         DRM_FORCE_UNSPECIFIED,
46         DRM_FORCE_OFF,
47         DRM_FORCE_ON,         /* force on analog part normally */
48         DRM_FORCE_ON_DIGITAL, /* for DVI-I use digital connector */
49 };
50
51 /**
52  * enum drm_connector_status - status for a &drm_connector
53  *
54  * This enum is used to track the connector status. There are no separate
55  * #defines for the uapi!
56  */
57 enum drm_connector_status {
58         /**
59          * @connector_status_connected: The connector is definitely connected to
60          * a sink device, and can be enabled.
61          */
62         connector_status_connected = 1,
63         /**
64          * @connector_status_disconnected: The connector isn't connected to a
65          * sink device which can be autodetect. For digital outputs like DP or
66          * HDMI (which can be realiable probed) this means there's really
67          * nothing there. It is driver-dependent whether a connector with this
68          * status can be lit up or not.
69          */
70         connector_status_disconnected = 2,
71         /**
72          * @connector_status_unknown: The connector's status could not be
73          * reliably detected. This happens when probing would either cause
74          * flicker (like load-detection when the connector is in use), or when a
75          * hardware resource isn't available (like when load-detection needs a
76          * free CRTC). It should be possible to light up the connector with one
77          * of the listed fallback modes. For default configuration userspace
78          * should only try to light up connectors with unknown status when
79          * there's not connector with @connector_status_connected.
80          */
81         connector_status_unknown = 3,
82 };
83
84 /**
85  * enum drm_connector_registration_status - userspace registration status for
86  * a &drm_connector
87  *
88  * This enum is used to track the status of initializing a connector and
89  * registering it with userspace, so that DRM can prevent bogus modesets on
90  * connectors that no longer exist.
91  */
92 enum drm_connector_registration_state {
93         /**
94          * @DRM_CONNECTOR_INITIALIZING: The connector has just been created,
95          * but has yet to be exposed to userspace. There should be no
96          * additional restrictions to how the state of this connector may be
97          * modified.
98          */
99         DRM_CONNECTOR_INITIALIZING = 0,
100
101         /**
102          * @DRM_CONNECTOR_REGISTERED: The connector has been fully initialized
103          * and registered with sysfs, as such it has been exposed to
104          * userspace. There should be no additional restrictions to how the
105          * state of this connector may be modified.
106          */
107         DRM_CONNECTOR_REGISTERED = 1,
108
109         /**
110          * @DRM_CONNECTOR_UNREGISTERED: The connector has either been exposed
111          * to userspace and has since been unregistered and removed from
112          * userspace, or the connector was unregistered before it had a chance
113          * to be exposed to userspace (e.g. still in the
114          * @DRM_CONNECTOR_INITIALIZING state). When a connector is
115          * unregistered, there are additional restrictions to how its state
116          * may be modified:
117          *
118          * - An unregistered connector may only have its DPMS changed from
119          *   On->Off. Once DPMS is changed to Off, it may not be switched back
120          *   to On.
121          * - Modesets are not allowed on unregistered connectors, unless they
122          *   would result in disabling its assigned CRTCs. This means
123          *   disabling a CRTC on an unregistered connector is OK, but enabling
124          *   one is not.
125          * - Removing a CRTC from an unregistered connector is OK, but new
126          *   CRTCs may never be assigned to an unregistered connector.
127          */
128         DRM_CONNECTOR_UNREGISTERED = 2,
129 };
130
131 enum subpixel_order {
132         SubPixelUnknown = 0,
133         SubPixelHorizontalRGB,
134         SubPixelHorizontalBGR,
135         SubPixelVerticalRGB,
136         SubPixelVerticalBGR,
137         SubPixelNone,
138
139 };
140
141 /**
142  * struct drm_scrambling: sink's scrambling support.
143  */
144 struct drm_scrambling {
145         /**
146          * @supported: scrambling supported for rates > 340 Mhz.
147          */
148         bool supported;
149         /**
150          * @low_rates: scrambling supported for rates <= 340 Mhz.
151          */
152         bool low_rates;
153 };
154
155 /*
156  * struct drm_scdc - Information about scdc capabilities of a HDMI 2.0 sink
157  *
158  * Provides SCDC register support and capabilities related information on a
159  * HDMI 2.0 sink. In case of a HDMI 1.4 sink, all parameter must be 0.
160  */
161 struct drm_scdc {
162         /**
163          * @supported: status control & data channel present.
164          */
165         bool supported;
166         /**
167          * @read_request: sink is capable of generating scdc read request.
168          */
169         bool read_request;
170         /**
171          * @scrambling: sink's scrambling capabilities
172          */
173         struct drm_scrambling scrambling;
174 };
175
176
177 /**
178  * struct drm_hdmi_info - runtime information about the connected HDMI sink
179  *
180  * Describes if a given display supports advanced HDMI 2.0 features.
181  * This information is available in CEA-861-F extension blocks (like HF-VSDB).
182  */
183 struct drm_hdmi_info {
184         /** @scdc: sink's scdc support and capabilities */
185         struct drm_scdc scdc;
186
187         /**
188          * @y420_vdb_modes: bitmap of modes which can support ycbcr420
189          * output only (not normal RGB/YCBCR444/422 outputs). There are total
190          * 107 VICs defined by CEA-861-F spec, so the size is 128 bits to map
191          * upto 128 VICs;
192          */
193         unsigned long y420_vdb_modes[BITS_TO_LONGS(128)];
194
195         /**
196          * @y420_cmdb_modes: bitmap of modes which can support ycbcr420
197          * output also, along with normal HDMI outputs. There are total 107
198          * VICs defined by CEA-861-F spec, so the size is 128 bits to map upto
199          * 128 VICs;
200          */
201         unsigned long y420_cmdb_modes[BITS_TO_LONGS(128)];
202
203         /** @y420_cmdb_map: bitmap of SVD index, to extraxt vcb modes */
204         u64 y420_cmdb_map;
205
206         /** @y420_dc_modes: bitmap of deep color support index */
207         u8 y420_dc_modes;
208 };
209
210 /**
211  * enum drm_link_status - connector's link_status property value
212  *
213  * This enum is used as the connector's link status property value.
214  * It is set to the values defined in uapi.
215  *
216  * @DRM_LINK_STATUS_GOOD: DP Link is Good as a result of successful
217  *                        link training
218  * @DRM_LINK_STATUS_BAD: DP Link is BAD as a result of link training
219  *                       failure
220  */
221 enum drm_link_status {
222         DRM_LINK_STATUS_GOOD = DRM_MODE_LINK_STATUS_GOOD,
223         DRM_LINK_STATUS_BAD = DRM_MODE_LINK_STATUS_BAD,
224 };
225
226 /**
227  * enum drm_panel_orientation - panel_orientation info for &drm_display_info
228  *
229  * This enum is used to track the (LCD) panel orientation. There are no
230  * separate #defines for the uapi!
231  *
232  * @DRM_MODE_PANEL_ORIENTATION_UNKNOWN: The drm driver has not provided any
233  *                                      panel orientation information (normal
234  *                                      for non panels) in this case the "panel
235  *                                      orientation" connector prop will not be
236  *                                      attached.
237  * @DRM_MODE_PANEL_ORIENTATION_NORMAL:  The top side of the panel matches the
238  *                                      top side of the device's casing.
239  * @DRM_MODE_PANEL_ORIENTATION_BOTTOM_UP: The top side of the panel matches the
240  *                                      bottom side of the device's casing, iow
241  *                                      the panel is mounted upside-down.
242  * @DRM_MODE_PANEL_ORIENTATION_LEFT_UP: The left side of the panel matches the
243  *                                      top side of the device's casing.
244  * @DRM_MODE_PANEL_ORIENTATION_RIGHT_UP: The right side of the panel matches the
245  *                                      top side of the device's casing.
246  */
247 enum drm_panel_orientation {
248         DRM_MODE_PANEL_ORIENTATION_UNKNOWN = -1,
249         DRM_MODE_PANEL_ORIENTATION_NORMAL = 0,
250         DRM_MODE_PANEL_ORIENTATION_BOTTOM_UP,
251         DRM_MODE_PANEL_ORIENTATION_LEFT_UP,
252         DRM_MODE_PANEL_ORIENTATION_RIGHT_UP,
253 };
254
255 /**
256  * struct drm_display_info - runtime data about the connected sink
257  *
258  * Describes a given display (e.g. CRT or flat panel) and its limitations. For
259  * fixed display sinks like built-in panels there's not much difference between
260  * this and &struct drm_connector. But for sinks with a real cable this
261  * structure is meant to describe all the things at the other end of the cable.
262  *
263  * For sinks which provide an EDID this can be filled out by calling
264  * drm_add_edid_modes().
265  */
266 struct drm_display_info {
267         /**
268          * @name: Name of the display.
269          */
270         char name[DRM_DISPLAY_INFO_LEN];
271
272         /**
273          * @width_mm: Physical width in mm.
274          */
275         unsigned int width_mm;
276         /**
277          * @height_mm: Physical height in mm.
278          */
279         unsigned int height_mm;
280
281         /**
282          * @pixel_clock: Maximum pixel clock supported by the sink, in units of
283          * 100Hz. This mismatches the clock in &drm_display_mode (which is in
284          * kHZ), because that's what the EDID uses as base unit.
285          */
286         unsigned int pixel_clock;
287         /**
288          * @bpc: Maximum bits per color channel. Used by HDMI and DP outputs.
289          */
290         unsigned int bpc;
291
292         /**
293          * @subpixel_order: Subpixel order of LCD panels.
294          */
295         enum subpixel_order subpixel_order;
296
297 #define DRM_COLOR_FORMAT_RGB444         (1<<0)
298 #define DRM_COLOR_FORMAT_YCRCB444       (1<<1)
299 #define DRM_COLOR_FORMAT_YCRCB422       (1<<2)
300 #define DRM_COLOR_FORMAT_YCRCB420       (1<<3)
301
302         /**
303          * @panel_orientation: Read only connector property for built-in panels,
304          * indicating the orientation of the panel vs the device's casing.
305          * drm_connector_init() sets this to DRM_MODE_PANEL_ORIENTATION_UNKNOWN.
306          * When not UNKNOWN this gets used by the drm_fb_helpers to rotate the
307          * fb to compensate and gets exported as prop to userspace.
308          */
309         int panel_orientation;
310
311         /**
312          * @color_formats: HDMI Color formats, selects between RGB and YCrCb
313          * modes. Used DRM_COLOR_FORMAT\_ defines, which are _not_ the same ones
314          * as used to describe the pixel format in framebuffers, and also don't
315          * match the formats in @bus_formats which are shared with v4l.
316          */
317         u32 color_formats;
318
319         /**
320          * @bus_formats: Pixel data format on the wire, somewhat redundant with
321          * @color_formats. Array of size @num_bus_formats encoded using
322          * MEDIA_BUS_FMT\_ defines shared with v4l and media drivers.
323          */
324         const u32 *bus_formats;
325         /**
326          * @num_bus_formats: Size of @bus_formats array.
327          */
328         unsigned int num_bus_formats;
329
330 #define DRM_BUS_FLAG_DE_LOW             (1<<0)
331 #define DRM_BUS_FLAG_DE_HIGH            (1<<1)
332 /* drive data on pos. edge */
333 #define DRM_BUS_FLAG_PIXDATA_POSEDGE    (1<<2)
334 /* drive data on neg. edge */
335 #define DRM_BUS_FLAG_PIXDATA_NEGEDGE    (1<<3)
336 /* data is transmitted MSB to LSB on the bus */
337 #define DRM_BUS_FLAG_DATA_MSB_TO_LSB    (1<<4)
338 /* data is transmitted LSB to MSB on the bus */
339 #define DRM_BUS_FLAG_DATA_LSB_TO_MSB    (1<<5)
340 /* drive sync on pos. edge */
341 #define DRM_BUS_FLAG_SYNC_POSEDGE       (1<<6)
342 /* drive sync on neg. edge */
343 #define DRM_BUS_FLAG_SYNC_NEGEDGE       (1<<7)
344
345         /**
346          * @bus_flags: Additional information (like pixel signal polarity) for
347          * the pixel data on the bus, using DRM_BUS_FLAGS\_ defines.
348          */
349         u32 bus_flags;
350
351         /**
352          * @max_tmds_clock: Maximum TMDS clock rate supported by the
353          * sink in kHz. 0 means undefined.
354          */
355         int max_tmds_clock;
356
357         /**
358          * @dvi_dual: Dual-link DVI sink?
359          */
360         bool dvi_dual;
361
362         /**
363          * @has_hdmi_infoframe: Does the sink support the HDMI infoframe?
364          */
365         bool has_hdmi_infoframe;
366
367         /**
368          * @edid_hdmi_dc_modes: Mask of supported hdmi deep color modes. Even
369          * more stuff redundant with @bus_formats.
370          */
371         u8 edid_hdmi_dc_modes;
372
373         /**
374          * @cea_rev: CEA revision of the HDMI sink.
375          */
376         u8 cea_rev;
377
378         /**
379          * @hdmi: advance features of a HDMI sink.
380          */
381         struct drm_hdmi_info hdmi;
382
383         /**
384          * @non_desktop: Non desktop display (HMD).
385          */
386         bool non_desktop;
387 };
388
389 int drm_display_info_set_bus_formats(struct drm_display_info *info,
390                                      const u32 *formats,
391                                      unsigned int num_formats);
392
393 /**
394  * struct drm_tv_connector_state - TV connector related states
395  * @subconnector: selected subconnector
396  * @margins: margins
397  * @margins.left: left margin
398  * @margins.right: right margin
399  * @margins.top: top margin
400  * @margins.bottom: bottom margin
401  * @mode: TV mode
402  * @brightness: brightness in percent
403  * @contrast: contrast in percent
404  * @flicker_reduction: flicker reduction in percent
405  * @overscan: overscan in percent
406  * @saturation: saturation in percent
407  * @hue: hue in percent
408  */
409 struct drm_tv_connector_state {
410         enum drm_mode_subconnector subconnector;
411         struct {
412                 unsigned int left;
413                 unsigned int right;
414                 unsigned int top;
415                 unsigned int bottom;
416         } margins;
417         unsigned int mode;
418         unsigned int brightness;
419         unsigned int contrast;
420         unsigned int flicker_reduction;
421         unsigned int overscan;
422         unsigned int saturation;
423         unsigned int hue;
424 };
425
426 /**
427  * struct drm_connector_state - mutable connector state
428  */
429 struct drm_connector_state {
430         /** @connector: backpointer to the connector */
431         struct drm_connector *connector;
432
433         /**
434          * @crtc: CRTC to connect connector to, NULL if disabled.
435          *
436          * Do not change this directly, use drm_atomic_set_crtc_for_connector()
437          * instead.
438          */
439         struct drm_crtc *crtc;
440
441         /**
442          * @best_encoder:
443          *
444          * Used by the atomic helpers to select the encoder, through the
445          * &drm_connector_helper_funcs.atomic_best_encoder or
446          * &drm_connector_helper_funcs.best_encoder callbacks.
447          */
448         struct drm_encoder *best_encoder;
449
450         /**
451          * @link_status: Connector link_status to keep track of whether link is
452          * GOOD or BAD to notify userspace if retraining is necessary.
453          */
454         enum drm_link_status link_status;
455
456         /** @state: backpointer to global drm_atomic_state */
457         struct drm_atomic_state *state;
458
459         /**
460          * @commit: Tracks the pending commit to prevent use-after-free conditions.
461          *
462          * Is only set when @crtc is NULL.
463          */
464         struct drm_crtc_commit *commit;
465
466         /** @tv: TV connector state */
467         struct drm_tv_connector_state tv;
468
469         /**
470          * @picture_aspect_ratio: Connector property to control the
471          * HDMI infoframe aspect ratio setting.
472          *
473          * The %DRM_MODE_PICTURE_ASPECT_\* values much match the
474          * values for &enum hdmi_picture_aspect
475          */
476         enum hdmi_picture_aspect picture_aspect_ratio;
477
478         /**
479          * @content_type: Connector property to control the
480          * HDMI infoframe content type setting.
481          * The %DRM_MODE_CONTENT_TYPE_\* values much
482          * match the values.
483          */
484         unsigned int content_type;
485
486         /**
487          * @scaling_mode: Connector property to control the
488          * upscaling, mostly used for built-in panels.
489          */
490         unsigned int scaling_mode;
491
492         /**
493          * @content_protection: Connector property to request content
494          * protection. This is most commonly used for HDCP.
495          */
496         unsigned int content_protection;
497
498         /**
499          * @writeback_job: Writeback job for writeback connectors
500          *
501          * Holds the framebuffer and out-fence for a writeback connector. As
502          * the writeback completion may be asynchronous to the normal commit
503          * cycle, the writeback job lifetime is managed separately from the
504          * normal atomic state by this object.
505          *
506          * See also: drm_writeback_queue_job() and
507          * drm_writeback_signal_completion()
508          */
509         struct drm_writeback_job *writeback_job;
510 };
511
512 /**
513  * struct drm_connector_funcs - control connectors on a given device
514  *
515  * Each CRTC may have one or more connectors attached to it.  The functions
516  * below allow the core DRM code to control connectors, enumerate available modes,
517  * etc.
518  */
519 struct drm_connector_funcs {
520         /**
521          * @dpms:
522          *
523          * Legacy entry point to set the per-connector DPMS state. Legacy DPMS
524          * is exposed as a standard property on the connector, but diverted to
525          * this callback in the drm core. Note that atomic drivers don't
526          * implement the 4 level DPMS support on the connector any more, but
527          * instead only have an on/off "ACTIVE" property on the CRTC object.
528          *
529          * This hook is not used by atomic drivers, remapping of the legacy DPMS
530          * property is entirely handled in the DRM core.
531          *
532          * RETURNS:
533          *
534          * 0 on success or a negative error code on failure.
535          */
536         int (*dpms)(struct drm_connector *connector, int mode);
537
538         /**
539          * @reset:
540          *
541          * Reset connector hardware and software state to off. This function isn't
542          * called by the core directly, only through drm_mode_config_reset().
543          * It's not a helper hook only for historical reasons.
544          *
545          * Atomic drivers can use drm_atomic_helper_connector_reset() to reset
546          * atomic state using this hook.
547          */
548         void (*reset)(struct drm_connector *connector);
549
550         /**
551          * @detect:
552          *
553          * Check to see if anything is attached to the connector. The parameter
554          * force is set to false whilst polling, true when checking the
555          * connector due to a user request. force can be used by the driver to
556          * avoid expensive, destructive operations during automated probing.
557          *
558          * This callback is optional, if not implemented the connector will be
559          * considered as always being attached.
560          *
561          * FIXME:
562          *
563          * Note that this hook is only called by the probe helper. It's not in
564          * the helper library vtable purely for historical reasons. The only DRM
565          * core entry point to probe connector state is @fill_modes.
566          *
567          * Note that the helper library will already hold
568          * &drm_mode_config.connection_mutex. Drivers which need to grab additional
569          * locks to avoid races with concurrent modeset changes need to use
570          * &drm_connector_helper_funcs.detect_ctx instead.
571          *
572          * RETURNS:
573          *
574          * drm_connector_status indicating the connector's status.
575          */
576         enum drm_connector_status (*detect)(struct drm_connector *connector,
577                                             bool force);
578
579         /**
580          * @force:
581          *
582          * This function is called to update internal encoder state when the
583          * connector is forced to a certain state by userspace, either through
584          * the sysfs interfaces or on the kernel cmdline. In that case the
585          * @detect callback isn't called.
586          *
587          * FIXME:
588          *
589          * Note that this hook is only called by the probe helper. It's not in
590          * the helper library vtable purely for historical reasons. The only DRM
591          * core entry point to probe connector state is @fill_modes.
592          */
593         void (*force)(struct drm_connector *connector);
594
595         /**
596          * @fill_modes:
597          *
598          * Entry point for output detection and basic mode validation. The
599          * driver should reprobe the output if needed (e.g. when hotplug
600          * handling is unreliable), add all detected modes to &drm_connector.modes
601          * and filter out any the device can't support in any configuration. It
602          * also needs to filter out any modes wider or higher than the
603          * parameters max_width and max_height indicate.
604          *
605          * The drivers must also prune any modes no longer valid from
606          * &drm_connector.modes. Furthermore it must update
607          * &drm_connector.status and &drm_connector.edid.  If no EDID has been
608          * received for this output connector->edid must be NULL.
609          *
610          * Drivers using the probe helpers should use
611          * drm_helper_probe_single_connector_modes() to implement this
612          * function.
613          *
614          * RETURNS:
615          *
616          * The number of modes detected and filled into &drm_connector.modes.
617          */
618         int (*fill_modes)(struct drm_connector *connector, uint32_t max_width, uint32_t max_height);
619
620         /**
621          * @set_property:
622          *
623          * This is the legacy entry point to update a property attached to the
624          * connector.
625          *
626          * This callback is optional if the driver does not support any legacy
627          * driver-private properties. For atomic drivers it is not used because
628          * property handling is done entirely in the DRM core.
629          *
630          * RETURNS:
631          *
632          * 0 on success or a negative error code on failure.
633          */
634         int (*set_property)(struct drm_connector *connector, struct drm_property *property,
635                              uint64_t val);
636
637         /**
638          * @late_register:
639          *
640          * This optional hook can be used to register additional userspace
641          * interfaces attached to the connector, light backlight control, i2c,
642          * DP aux or similar interfaces. It is called late in the driver load
643          * sequence from drm_connector_register() when registering all the
644          * core drm connector interfaces. Everything added from this callback
645          * should be unregistered in the early_unregister callback.
646          *
647          * This is called while holding &drm_connector.mutex.
648          *
649          * Returns:
650          *
651          * 0 on success, or a negative error code on failure.
652          */
653         int (*late_register)(struct drm_connector *connector);
654
655         /**
656          * @early_unregister:
657          *
658          * This optional hook should be used to unregister the additional
659          * userspace interfaces attached to the connector from
660          * late_register(). It is called from drm_connector_unregister(),
661          * early in the driver unload sequence to disable userspace access
662          * before data structures are torndown.
663          *
664          * This is called while holding &drm_connector.mutex.
665          */
666         void (*early_unregister)(struct drm_connector *connector);
667
668         /**
669          * @destroy:
670          *
671          * Clean up connector resources. This is called at driver unload time
672          * through drm_mode_config_cleanup(). It can also be called at runtime
673          * when a connector is being hot-unplugged for drivers that support
674          * connector hotplugging (e.g. DisplayPort MST).
675          */
676         void (*destroy)(struct drm_connector *connector);
677
678         /**
679          * @atomic_duplicate_state:
680          *
681          * Duplicate the current atomic state for this connector and return it.
682          * The core and helpers guarantee that any atomic state duplicated with
683          * this hook and still owned by the caller (i.e. not transferred to the
684          * driver by calling &drm_mode_config_funcs.atomic_commit) will be
685          * cleaned up by calling the @atomic_destroy_state hook in this
686          * structure.
687          *
688          * This callback is mandatory for atomic drivers.
689          *
690          * Atomic drivers which don't subclass &struct drm_connector_state should use
691          * drm_atomic_helper_connector_duplicate_state(). Drivers that subclass the
692          * state structure to extend it with driver-private state should use
693          * __drm_atomic_helper_connector_duplicate_state() to make sure shared state is
694          * duplicated in a consistent fashion across drivers.
695          *
696          * It is an error to call this hook before &drm_connector.state has been
697          * initialized correctly.
698          *
699          * NOTE:
700          *
701          * If the duplicate state references refcounted resources this hook must
702          * acquire a reference for each of them. The driver must release these
703          * references again in @atomic_destroy_state.
704          *
705          * RETURNS:
706          *
707          * Duplicated atomic state or NULL when the allocation failed.
708          */
709         struct drm_connector_state *(*atomic_duplicate_state)(struct drm_connector *connector);
710
711         /**
712          * @atomic_destroy_state:
713          *
714          * Destroy a state duplicated with @atomic_duplicate_state and release
715          * or unreference all resources it references
716          *
717          * This callback is mandatory for atomic drivers.
718          */
719         void (*atomic_destroy_state)(struct drm_connector *connector,
720                                      struct drm_connector_state *state);
721
722         /**
723          * @atomic_set_property:
724          *
725          * Decode a driver-private property value and store the decoded value
726          * into the passed-in state structure. Since the atomic core decodes all
727          * standardized properties (even for extensions beyond the core set of
728          * properties which might not be implemented by all drivers) this
729          * requires drivers to subclass the state structure.
730          *
731          * Such driver-private properties should really only be implemented for
732          * truly hardware/vendor specific state. Instead it is preferred to
733          * standardize atomic extension and decode the properties used to expose
734          * such an extension in the core.
735          *
736          * Do not call this function directly, use
737          * drm_atomic_connector_set_property() instead.
738          *
739          * This callback is optional if the driver does not support any
740          * driver-private atomic properties.
741          *
742          * NOTE:
743          *
744          * This function is called in the state assembly phase of atomic
745          * modesets, which can be aborted for any reason (including on
746          * userspace's request to just check whether a configuration would be
747          * possible). Drivers MUST NOT touch any persistent state (hardware or
748          * software) or data structures except the passed in @state parameter.
749          *
750          * Also since userspace controls in which order properties are set this
751          * function must not do any input validation (since the state update is
752          * incomplete and hence likely inconsistent). Instead any such input
753          * validation must be done in the various atomic_check callbacks.
754          *
755          * RETURNS:
756          *
757          * 0 if the property has been found, -EINVAL if the property isn't
758          * implemented by the driver (which shouldn't ever happen, the core only
759          * asks for properties attached to this connector). No other validation
760          * is allowed by the driver. The core already checks that the property
761          * value is within the range (integer, valid enum value, ...) the driver
762          * set when registering the property.
763          */
764         int (*atomic_set_property)(struct drm_connector *connector,
765                                    struct drm_connector_state *state,
766                                    struct drm_property *property,
767                                    uint64_t val);
768
769         /**
770          * @atomic_get_property:
771          *
772          * Reads out the decoded driver-private property. This is used to
773          * implement the GETCONNECTOR IOCTL.
774          *
775          * Do not call this function directly, use
776          * drm_atomic_connector_get_property() instead.
777          *
778          * This callback is optional if the driver does not support any
779          * driver-private atomic properties.
780          *
781          * RETURNS:
782          *
783          * 0 on success, -EINVAL if the property isn't implemented by the
784          * driver (which shouldn't ever happen, the core only asks for
785          * properties attached to this connector).
786          */
787         int (*atomic_get_property)(struct drm_connector *connector,
788                                    const struct drm_connector_state *state,
789                                    struct drm_property *property,
790                                    uint64_t *val);
791
792         /**
793          * @atomic_print_state:
794          *
795          * If driver subclasses &struct drm_connector_state, it should implement
796          * this optional hook for printing additional driver specific state.
797          *
798          * Do not call this directly, use drm_atomic_connector_print_state()
799          * instead.
800          */
801         void (*atomic_print_state)(struct drm_printer *p,
802                                    const struct drm_connector_state *state);
803 };
804
805 /* mode specified on the command line */
806 struct drm_cmdline_mode {
807         bool specified;
808         bool refresh_specified;
809         bool bpp_specified;
810         int xres, yres;
811         int bpp;
812         int refresh;
813         bool rb;
814         bool interlace;
815         bool cvt;
816         bool margins;
817         enum drm_connector_force force;
818 };
819
820 /**
821  * struct drm_connector - central DRM connector control structure
822  *
823  * Each connector may be connected to one or more CRTCs, or may be clonable by
824  * another connector if they can share a CRTC.  Each connector also has a specific
825  * position in the broader display (referred to as a 'screen' though it could
826  * span multiple monitors).
827  */
828 struct drm_connector {
829         /** @dev: parent DRM device */
830         struct drm_device *dev;
831         /** @kdev: kernel device for sysfs attributes */
832         struct device *kdev;
833         /** @attr: sysfs attributes */
834         struct device_attribute *attr;
835
836         /**
837          * @head:
838          *
839          * List of all connectors on a @dev, linked from
840          * &drm_mode_config.connector_list. Protected by
841          * &drm_mode_config.connector_list_lock, but please only use
842          * &drm_connector_list_iter to walk this list.
843          */
844         struct list_head head;
845
846         /** @base: base KMS object */
847         struct drm_mode_object base;
848
849         /** @name: human readable name, can be overwritten by the driver */
850         char *name;
851
852         /**
853          * @mutex: Lock for general connector state, but currently only protects
854          * @registered. Most of the connector state is still protected by
855          * &drm_mode_config.mutex.
856          */
857         struct mutex mutex;
858
859         /**
860          * @index: Compacted connector index, which matches the position inside
861          * the mode_config.list for drivers not supporting hot-add/removing. Can
862          * be used as an array index. It is invariant over the lifetime of the
863          * connector.
864          */
865         unsigned index;
866
867         /**
868          * @connector_type:
869          * one of the DRM_MODE_CONNECTOR_<foo> types from drm_mode.h
870          */
871         int connector_type;
872         /** @connector_type_id: index into connector type enum */
873         int connector_type_id;
874         /**
875          * @interlace_allowed:
876          * Can this connector handle interlaced modes? Only used by
877          * drm_helper_probe_single_connector_modes() for mode filtering.
878          */
879         bool interlace_allowed;
880         /**
881          * @doublescan_allowed:
882          * Can this connector handle doublescan? Only used by
883          * drm_helper_probe_single_connector_modes() for mode filtering.
884          */
885         bool doublescan_allowed;
886         /**
887          * @stereo_allowed:
888          * Can this connector handle stereo modes? Only used by
889          * drm_helper_probe_single_connector_modes() for mode filtering.
890          */
891         bool stereo_allowed;
892
893         /**
894          * @ycbcr_420_allowed : This bool indicates if this connector is
895          * capable of handling YCBCR 420 output. While parsing the EDID
896          * blocks, its very helpful to know, if the source is capable of
897          * handling YCBCR 420 outputs.
898          */
899         bool ycbcr_420_allowed;
900
901         /**
902          * @registration_state: Is this connector initializing, exposed
903          * (registered) with userspace, or unregistered?
904          *
905          * Protected by @mutex.
906          */
907         enum drm_connector_registration_state registration_state;
908
909         /**
910          * @modes:
911          * Modes available on this connector (from fill_modes() + user).
912          * Protected by &drm_mode_config.mutex.
913          */
914         struct list_head modes;
915
916         /**
917          * @status:
918          * One of the drm_connector_status enums (connected, not, or unknown).
919          * Protected by &drm_mode_config.mutex.
920          */
921         enum drm_connector_status status;
922
923         /**
924          * @probed_modes:
925          * These are modes added by probing with DDC or the BIOS, before
926          * filtering is applied. Used by the probe helpers. Protected by
927          * &drm_mode_config.mutex.
928          */
929         struct list_head probed_modes;
930
931         /**
932          * @display_info: Display information is filled from EDID information
933          * when a display is detected. For non hot-pluggable displays such as
934          * flat panels in embedded systems, the driver should initialize the
935          * &drm_display_info.width_mm and &drm_display_info.height_mm fields
936          * with the physical size of the display.
937          *
938          * Protected by &drm_mode_config.mutex.
939          */
940         struct drm_display_info display_info;
941
942         /** @funcs: connector control functions */
943         const struct drm_connector_funcs *funcs;
944
945         /**
946          * @edid_blob_ptr: DRM property containing EDID if present. Protected by
947          * &drm_mode_config.mutex. This should be updated only by calling
948          * drm_connector_update_edid_property().
949          */
950         struct drm_property_blob *edid_blob_ptr;
951
952         /** @properties: property tracking for this connector */
953         struct drm_object_properties properties;
954
955         /**
956          * @scaling_mode_property: Optional atomic property to control the
957          * upscaling. See drm_connector_attach_content_protection_property().
958          */
959         struct drm_property *scaling_mode_property;
960
961         /**
962          * @content_protection_property: DRM ENUM property for content
963          * protection. See drm_connector_attach_content_protection_property().
964          */
965         struct drm_property *content_protection_property;
966
967         /**
968          * @path_blob_ptr:
969          *
970          * DRM blob property data for the DP MST path property. This should only
971          * be updated by calling drm_connector_set_path_property().
972          */
973         struct drm_property_blob *path_blob_ptr;
974
975 #define DRM_CONNECTOR_POLL_HPD (1 << 0)
976 #define DRM_CONNECTOR_POLL_CONNECT (1 << 1)
977 #define DRM_CONNECTOR_POLL_DISCONNECT (1 << 2)
978
979         /**
980          * @polled:
981          *
982          * Connector polling mode, a combination of
983          *
984          * DRM_CONNECTOR_POLL_HPD
985          *     The connector generates hotplug events and doesn't need to be
986          *     periodically polled. The CONNECT and DISCONNECT flags must not
987          *     be set together with the HPD flag.
988          *
989          * DRM_CONNECTOR_POLL_CONNECT
990          *     Periodically poll the connector for connection.
991          *
992          * DRM_CONNECTOR_POLL_DISCONNECT
993          *     Periodically poll the connector for disconnection, without
994          *     causing flickering even when the connector is in use. DACs should
995          *     rarely do this without a lot of testing.
996          *
997          * Set to 0 for connectors that don't support connection status
998          * discovery.
999          */
1000         uint8_t polled;
1001
1002         /**
1003          * @dpms: Current dpms state. For legacy drivers the
1004          * &drm_connector_funcs.dpms callback must update this. For atomic
1005          * drivers, this is handled by the core atomic code, and drivers must
1006          * only take &drm_crtc_state.active into account.
1007          */
1008         int dpms;
1009
1010         /** @helper_private: mid-layer private data */
1011         const struct drm_connector_helper_funcs *helper_private;
1012
1013         /** @cmdline_mode: mode line parsed from the kernel cmdline for this connector */
1014         struct drm_cmdline_mode cmdline_mode;
1015         /** @force: a DRM_FORCE_<foo> state for forced mode sets */
1016         enum drm_connector_force force;
1017         /** @override_edid: has the EDID been overwritten through debugfs for testing? */
1018         bool override_edid;
1019
1020 #define DRM_CONNECTOR_MAX_ENCODER 3
1021         /**
1022          * @encoder_ids: Valid encoders for this connector. Please only use
1023          * drm_connector_for_each_possible_encoder() to enumerate these.
1024          */
1025         uint32_t encoder_ids[DRM_CONNECTOR_MAX_ENCODER];
1026
1027         /**
1028          * @encoder: Currently bound encoder driving this connector, if any.
1029          * Only really meaningful for non-atomic drivers. Atomic drivers should
1030          * instead look at &drm_connector_state.best_encoder, and in case they
1031          * need the CRTC driving this output, &drm_connector_state.crtc.
1032          */
1033         struct drm_encoder *encoder;
1034
1035 #define MAX_ELD_BYTES   128
1036         /** @eld: EDID-like data, if present */
1037         uint8_t eld[MAX_ELD_BYTES];
1038         /** @latency_present: AV delay info from ELD, if found */
1039         bool latency_present[2];
1040         /**
1041          * @video_latency: Video latency info from ELD, if found.
1042          * [0]: progressive, [1]: interlaced
1043          */
1044         int video_latency[2];
1045         /**
1046          * @audio_latency: audio latency info from ELD, if found
1047          * [0]: progressive, [1]: interlaced
1048          */
1049         int audio_latency[2];
1050         /**
1051          * @null_edid_counter: track sinks that give us all zeros for the EDID.
1052          * Needed to workaround some HW bugs where we get all 0s
1053          */
1054         int null_edid_counter;
1055
1056         /** @bad_edid_counter: track sinks that give us an EDID with invalid checksum */
1057         unsigned bad_edid_counter;
1058
1059         /**
1060          * @edid_corrupt: Indicates whether the last read EDID was corrupt. Used
1061          * in Displayport compliance testing - Displayport Link CTS Core 1.2
1062          * rev1.1 4.2.2.6
1063          */
1064         bool edid_corrupt;
1065
1066         /** @debugfs_entry: debugfs directory for this connector */
1067         struct dentry *debugfs_entry;
1068
1069         /**
1070          * @state:
1071          *
1072          * Current atomic state for this connector.
1073          *
1074          * This is protected by &drm_mode_config.connection_mutex. Note that
1075          * nonblocking atomic commits access the current connector state without
1076          * taking locks. Either by going through the &struct drm_atomic_state
1077          * pointers, see for_each_oldnew_connector_in_state(),
1078          * for_each_old_connector_in_state() and
1079          * for_each_new_connector_in_state(). Or through careful ordering of
1080          * atomic commit operations as implemented in the atomic helpers, see
1081          * &struct drm_crtc_commit.
1082          */
1083         struct drm_connector_state *state;
1084
1085         /* DisplayID bits. FIXME: Extract into a substruct? */
1086
1087         /**
1088          * @tile_blob_ptr:
1089          *
1090          * DRM blob property data for the tile property (used mostly by DP MST).
1091          * This is meant for screens which are driven through separate display
1092          * pipelines represented by &drm_crtc, which might not be running with
1093          * genlocked clocks. For tiled panels which are genlocked, like
1094          * dual-link LVDS or dual-link DSI, the driver should try to not expose
1095          * the tiling and virtualize both &drm_crtc and &drm_plane if needed.
1096          *
1097          * This should only be updated by calling
1098          * drm_connector_set_tile_property().
1099          */
1100         struct drm_property_blob *tile_blob_ptr;
1101
1102         /** @has_tile: is this connector connected to a tiled monitor */
1103         bool has_tile;
1104         /** @tile_group: tile group for the connected monitor */
1105         struct drm_tile_group *tile_group;
1106         /** @tile_is_single_monitor: whether the tile is one monitor housing */
1107         bool tile_is_single_monitor;
1108
1109         /** @num_h_tile: number of horizontal tiles in the tile group */
1110         /** @num_v_tile: number of vertical tiles in the tile group */
1111         uint8_t num_h_tile, num_v_tile;
1112         /** @tile_h_loc: horizontal location of this tile */
1113         /** @tile_v_loc: vertical location of this tile */
1114         uint8_t tile_h_loc, tile_v_loc;
1115         /** @tile_h_size: horizontal size of this tile. */
1116         /** @tile_v_size: vertical size of this tile. */
1117         uint16_t tile_h_size, tile_v_size;
1118
1119         /**
1120          * @free_node:
1121          *
1122          * List used only by &drm_connector_list_iter to be able to clean up a
1123          * connector from any context, in conjunction with
1124          * &drm_mode_config.connector_free_work.
1125          */
1126         struct llist_node free_node;
1127 };
1128
1129 #define obj_to_connector(x) container_of(x, struct drm_connector, base)
1130
1131 int drm_connector_init(struct drm_device *dev,
1132                        struct drm_connector *connector,
1133                        const struct drm_connector_funcs *funcs,
1134                        int connector_type);
1135 int drm_connector_register(struct drm_connector *connector);
1136 void drm_connector_unregister(struct drm_connector *connector);
1137 int drm_connector_attach_encoder(struct drm_connector *connector,
1138                                       struct drm_encoder *encoder);
1139
1140 void drm_connector_cleanup(struct drm_connector *connector);
1141
1142 static inline unsigned int drm_connector_index(const struct drm_connector *connector)
1143 {
1144         return connector->index;
1145 }
1146
1147 static inline u32 drm_connector_mask(const struct drm_connector *connector)
1148 {
1149         return 1 << connector->index;
1150 }
1151
1152 /**
1153  * drm_connector_lookup - lookup connector object
1154  * @dev: DRM device
1155  * @file_priv: drm file to check for lease against.
1156  * @id: connector object id
1157  *
1158  * This function looks up the connector object specified by id
1159  * add takes a reference to it.
1160  */
1161 static inline struct drm_connector *drm_connector_lookup(struct drm_device *dev,
1162                 struct drm_file *file_priv,
1163                 uint32_t id)
1164 {
1165         struct drm_mode_object *mo;
1166         mo = drm_mode_object_find(dev, file_priv, id, DRM_MODE_OBJECT_CONNECTOR);
1167         return mo ? obj_to_connector(mo) : NULL;
1168 }
1169
1170 /**
1171  * drm_connector_get - acquire a connector reference
1172  * @connector: DRM connector
1173  *
1174  * This function increments the connector's refcount.
1175  */
1176 static inline void drm_connector_get(struct drm_connector *connector)
1177 {
1178         drm_mode_object_get(&connector->base);
1179 }
1180
1181 /**
1182  * drm_connector_put - release a connector reference
1183  * @connector: DRM connector
1184  *
1185  * This function decrements the connector's reference count and frees the
1186  * object if the reference count drops to zero.
1187  */
1188 static inline void drm_connector_put(struct drm_connector *connector)
1189 {
1190         drm_mode_object_put(&connector->base);
1191 }
1192
1193 /**
1194  * drm_connector_reference - acquire a connector reference
1195  * @connector: DRM connector
1196  *
1197  * This is a compatibility alias for drm_connector_get() and should not be
1198  * used by new code.
1199  */
1200 static inline void drm_connector_reference(struct drm_connector *connector)
1201 {
1202         drm_connector_get(connector);
1203 }
1204
1205 /**
1206  * drm_connector_unreference - release a connector reference
1207  * @connector: DRM connector
1208  *
1209  * This is a compatibility alias for drm_connector_put() and should not be
1210  * used by new code.
1211  */
1212 static inline void drm_connector_unreference(struct drm_connector *connector)
1213 {
1214         drm_connector_put(connector);
1215 }
1216
1217 /**
1218  * drm_connector_is_unregistered - has the connector been unregistered from
1219  * userspace?
1220  * @connector: DRM connector
1221  *
1222  * Checks whether or not @connector has been unregistered from userspace.
1223  *
1224  * Returns:
1225  * True if the connector was unregistered, false if the connector is
1226  * registered or has not yet been registered with userspace.
1227  */
1228 static inline bool
1229 drm_connector_is_unregistered(struct drm_connector *connector)
1230 {
1231         return READ_ONCE(connector->registration_state) ==
1232                 DRM_CONNECTOR_UNREGISTERED;
1233 }
1234
1235 const char *drm_get_connector_status_name(enum drm_connector_status status);
1236 const char *drm_get_subpixel_order_name(enum subpixel_order order);
1237 const char *drm_get_dpms_name(int val);
1238 const char *drm_get_dvi_i_subconnector_name(int val);
1239 const char *drm_get_dvi_i_select_name(int val);
1240 const char *drm_get_tv_subconnector_name(int val);
1241 const char *drm_get_tv_select_name(int val);
1242 const char *drm_get_content_protection_name(int val);
1243
1244 int drm_mode_create_dvi_i_properties(struct drm_device *dev);
1245 int drm_mode_create_tv_properties(struct drm_device *dev,
1246                                   unsigned int num_modes,
1247                                   const char * const modes[]);
1248 int drm_mode_create_scaling_mode_property(struct drm_device *dev);
1249 int drm_connector_attach_content_type_property(struct drm_connector *dev);
1250 int drm_connector_attach_scaling_mode_property(struct drm_connector *connector,
1251                                                u32 scaling_mode_mask);
1252 int drm_connector_attach_content_protection_property(
1253                 struct drm_connector *connector);
1254 int drm_mode_create_aspect_ratio_property(struct drm_device *dev);
1255 int drm_mode_create_content_type_property(struct drm_device *dev);
1256 void drm_hdmi_avi_infoframe_content_type(struct hdmi_avi_infoframe *frame,
1257                                          const struct drm_connector_state *conn_state);
1258
1259 int drm_mode_create_suggested_offset_properties(struct drm_device *dev);
1260
1261 int drm_connector_set_path_property(struct drm_connector *connector,
1262                                     const char *path);
1263 int drm_connector_set_tile_property(struct drm_connector *connector);
1264 int drm_connector_update_edid_property(struct drm_connector *connector,
1265                                        const struct edid *edid);
1266 void drm_connector_set_link_status_property(struct drm_connector *connector,
1267                                             uint64_t link_status);
1268 int drm_connector_init_panel_orientation_property(
1269         struct drm_connector *connector, int width, int height);
1270
1271 /**
1272  * struct drm_tile_group - Tile group metadata
1273  * @refcount: reference count
1274  * @dev: DRM device
1275  * @id: tile group id exposed to userspace
1276  * @group_data: Sink-private data identifying this group
1277  *
1278  * @group_data corresponds to displayid vend/prod/serial for external screens
1279  * with an EDID.
1280  */
1281 struct drm_tile_group {
1282         struct kref refcount;
1283         struct drm_device *dev;
1284         int id;
1285         u8 group_data[8];
1286 };
1287
1288 struct drm_tile_group *drm_mode_create_tile_group(struct drm_device *dev,
1289                                                   char topology[8]);
1290 struct drm_tile_group *drm_mode_get_tile_group(struct drm_device *dev,
1291                                                char topology[8]);
1292 void drm_mode_put_tile_group(struct drm_device *dev,
1293                              struct drm_tile_group *tg);
1294
1295 /**
1296  * struct drm_connector_list_iter - connector_list iterator
1297  *
1298  * This iterator tracks state needed to be able to walk the connector_list
1299  * within struct drm_mode_config. Only use together with
1300  * drm_connector_list_iter_begin(), drm_connector_list_iter_end() and
1301  * drm_connector_list_iter_next() respectively the convenience macro
1302  * drm_for_each_connector_iter().
1303  */
1304 struct drm_connector_list_iter {
1305 /* private: */
1306         struct drm_device *dev;
1307         struct drm_connector *conn;
1308 };
1309
1310 void drm_connector_list_iter_begin(struct drm_device *dev,
1311                                    struct drm_connector_list_iter *iter);
1312 struct drm_connector *
1313 drm_connector_list_iter_next(struct drm_connector_list_iter *iter);
1314 void drm_connector_list_iter_end(struct drm_connector_list_iter *iter);
1315
1316 bool drm_connector_has_possible_encoder(struct drm_connector *connector,
1317                                         struct drm_encoder *encoder);
1318
1319 /**
1320  * drm_for_each_connector_iter - connector_list iterator macro
1321  * @connector: &struct drm_connector pointer used as cursor
1322  * @iter: &struct drm_connector_list_iter
1323  *
1324  * Note that @connector is only valid within the list body, if you want to use
1325  * @connector after calling drm_connector_list_iter_end() then you need to grab
1326  * your own reference first using drm_connector_get().
1327  */
1328 #define drm_for_each_connector_iter(connector, iter) \
1329         while ((connector = drm_connector_list_iter_next(iter)))
1330
1331 /**
1332  * drm_connector_for_each_possible_encoder - iterate connector's possible encoders
1333  * @connector: &struct drm_connector pointer
1334  * @encoder: &struct drm_encoder pointer used as cursor
1335  * @__i: int iteration cursor, for macro-internal use
1336  */
1337 #define drm_connector_for_each_possible_encoder(connector, encoder, __i) \
1338         for ((__i) = 0; (__i) < ARRAY_SIZE((connector)->encoder_ids) && \
1339                      (connector)->encoder_ids[(__i)] != 0; (__i)++) \
1340                 for_each_if((encoder) = \
1341                             drm_encoder_find((connector)->dev, NULL, \
1342                                              (connector)->encoder_ids[(__i)])) \
1343
1344 #endif