]> git.karo-electronics.de Git - karo-tx-linux.git/blob - include/drm/drm_crtc.h
Merge branch 'drm-etnaviv-fixes' of git://git.pengutronix.de/git/lst/linux into drm...
[karo-tx-linux.git] / include / drm / drm_crtc.h
1 /*
2  * Copyright © 2006 Keith Packard
3  * Copyright © 2007-2008 Dave Airlie
4  * Copyright © 2007-2008 Intel Corporation
5  *   Jesse Barnes <jesse.barnes@intel.com>
6  *
7  * Permission is hereby granted, free of charge, to any person obtaining a
8  * copy of this software and associated documentation files (the "Software"),
9  * to deal in the Software without restriction, including without limitation
10  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
11  * and/or sell copies of the Software, and to permit persons to whom the
12  * Software is furnished to do so, subject to the following conditions:
13  *
14  * The above copyright notice and this permission notice shall be included in
15  * all copies or substantial portions of the Software.
16  *
17  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
20  * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
21  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
22  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
23  * OTHER DEALINGS IN THE SOFTWARE.
24  */
25 #ifndef __DRM_CRTC_H__
26 #define __DRM_CRTC_H__
27
28 #include <linux/i2c.h>
29 #include <linux/spinlock.h>
30 #include <linux/types.h>
31 #include <linux/idr.h>
32 #include <linux/fb.h>
33 #include <linux/hdmi.h>
34 #include <linux/media-bus-format.h>
35 #include <uapi/drm/drm_mode.h>
36 #include <uapi/drm/drm_fourcc.h>
37 #include <drm/drm_modeset_lock.h>
38
39 struct drm_device;
40 struct drm_mode_set;
41 struct drm_framebuffer;
42 struct drm_object_properties;
43 struct drm_file;
44 struct drm_clip_rect;
45 struct device_node;
46 struct fence;
47
48 #define DRM_MODE_OBJECT_CRTC 0xcccccccc
49 #define DRM_MODE_OBJECT_CONNECTOR 0xc0c0c0c0
50 #define DRM_MODE_OBJECT_ENCODER 0xe0e0e0e0
51 #define DRM_MODE_OBJECT_MODE 0xdededede
52 #define DRM_MODE_OBJECT_PROPERTY 0xb0b0b0b0
53 #define DRM_MODE_OBJECT_FB 0xfbfbfbfb
54 #define DRM_MODE_OBJECT_BLOB 0xbbbbbbbb
55 #define DRM_MODE_OBJECT_PLANE 0xeeeeeeee
56 #define DRM_MODE_OBJECT_ANY 0
57
58 struct drm_mode_object {
59         uint32_t id;
60         uint32_t type;
61         struct drm_object_properties *properties;
62 };
63
64 #define DRM_OBJECT_MAX_PROPERTY 24
65 struct drm_object_properties {
66         int count, atomic_count;
67         /* NOTE: if we ever start dynamically destroying properties (ie.
68          * not at drm_mode_config_cleanup() time), then we'd have to do
69          * a better job of detaching property from mode objects to avoid
70          * dangling property pointers:
71          */
72         struct drm_property *properties[DRM_OBJECT_MAX_PROPERTY];
73         /* do not read/write values directly, but use drm_object_property_get_value()
74          * and drm_object_property_set_value():
75          */
76         uint64_t values[DRM_OBJECT_MAX_PROPERTY];
77 };
78
79 static inline int64_t U642I64(uint64_t val)
80 {
81         return (int64_t)*((int64_t *)&val);
82 }
83 static inline uint64_t I642U64(int64_t val)
84 {
85         return (uint64_t)*((uint64_t *)&val);
86 }
87
88 /*
89  * Rotation property bits. DRM_ROTATE_<degrees> rotates the image by the
90  * specified amount in degrees in counter clockwise direction. DRM_REFLECT_X and
91  * DRM_REFLECT_Y reflects the image along the specified axis prior to rotation
92  */
93 #define DRM_ROTATE_MASK 0x0f
94 #define DRM_ROTATE_0    0
95 #define DRM_ROTATE_90   1
96 #define DRM_ROTATE_180  2
97 #define DRM_ROTATE_270  3
98 #define DRM_REFLECT_MASK (~DRM_ROTATE_MASK)
99 #define DRM_REFLECT_X   4
100 #define DRM_REFLECT_Y   5
101
102 enum drm_connector_force {
103         DRM_FORCE_UNSPECIFIED,
104         DRM_FORCE_OFF,
105         DRM_FORCE_ON,         /* force on analog part normally */
106         DRM_FORCE_ON_DIGITAL, /* for DVI-I use digital connector */
107 };
108
109 #include <drm/drm_modes.h>
110
111 enum drm_connector_status {
112         connector_status_connected = 1,
113         connector_status_disconnected = 2,
114         connector_status_unknown = 3,
115 };
116
117 enum subpixel_order {
118         SubPixelUnknown = 0,
119         SubPixelHorizontalRGB,
120         SubPixelHorizontalBGR,
121         SubPixelVerticalRGB,
122         SubPixelVerticalBGR,
123         SubPixelNone,
124 };
125
126 #define DRM_COLOR_FORMAT_RGB444         (1<<0)
127 #define DRM_COLOR_FORMAT_YCRCB444       (1<<1)
128 #define DRM_COLOR_FORMAT_YCRCB422       (1<<2)
129 /*
130  * Describes a given display (e.g. CRT or flat panel) and its limitations.
131  */
132 struct drm_display_info {
133         char name[DRM_DISPLAY_INFO_LEN];
134
135         /* Physical size */
136         unsigned int width_mm;
137         unsigned int height_mm;
138
139         /* Clock limits FIXME: storage format */
140         unsigned int min_vfreq, max_vfreq;
141         unsigned int min_hfreq, max_hfreq;
142         unsigned int pixel_clock;
143         unsigned int bpc;
144
145         enum subpixel_order subpixel_order;
146         u32 color_formats;
147
148         const u32 *bus_formats;
149         unsigned int num_bus_formats;
150
151         /* Mask of supported hdmi deep color modes */
152         u8 edid_hdmi_dc_modes;
153
154         u8 cea_rev;
155 };
156
157 /* data corresponds to displayid vend/prod/serial */
158 struct drm_tile_group {
159         struct kref refcount;
160         struct drm_device *dev;
161         int id;
162         u8 group_data[8];
163 };
164
165 /**
166  * struct drm_framebuffer_funcs - framebuffer hooks
167  */
168 struct drm_framebuffer_funcs {
169         /**
170          * @destroy:
171          *
172          * Clean up framebuffer resources, specifically also unreference the
173          * backing storage. The core guarantees to call this function for every
174          * framebuffer successfully created by ->fb_create() in
175          * &drm_mode_config_funcs. Drivers must also call
176          * drm_framebuffer_cleanup() to release DRM core resources for this
177          * framebuffer.
178          */
179         void (*destroy)(struct drm_framebuffer *framebuffer);
180
181         /**
182          * @create_handle:
183          *
184          * Create a buffer handle in the driver-specific buffer manager (either
185          * GEM or TTM) valid for the passed-in struct &drm_file. This is used by
186          * the core to implement the GETFB IOCTL, which returns (for
187          * sufficiently priviledged user) also a native buffer handle. This can
188          * be used for seamless transitions between modesetting clients by
189          * copying the current screen contents to a private buffer and blending
190          * between that and the new contents.
191          *
192          * GEM based drivers should call drm_gem_handle_create() to create the
193          * handle.
194          *
195          * RETURNS:
196          *
197          * 0 on success or a negative error code on failure.
198          */
199         int (*create_handle)(struct drm_framebuffer *fb,
200                              struct drm_file *file_priv,
201                              unsigned int *handle);
202         /**
203          * @dirty:
204          *
205          * Optional callback for the dirty fb IOCTL.
206          *
207          * Userspace can notify the driver via this callback that an area of the
208          * framebuffer has changed and should be flushed to the display
209          * hardware. This can also be used internally, e.g. by the fbdev
210          * emulation, though that's not the case currently.
211          *
212          * See documentation in drm_mode.h for the struct drm_mode_fb_dirty_cmd
213          * for more information as all the semantics and arguments have a one to
214          * one mapping on this function.
215          *
216          * RETURNS:
217          *
218          * 0 on success or a negative error code on failure.
219          */
220         int (*dirty)(struct drm_framebuffer *framebuffer,
221                      struct drm_file *file_priv, unsigned flags,
222                      unsigned color, struct drm_clip_rect *clips,
223                      unsigned num_clips);
224 };
225
226 struct drm_framebuffer {
227         struct drm_device *dev;
228         /*
229          * Note that the fb is refcounted for the benefit of driver internals,
230          * for example some hw, disabling a CRTC/plane is asynchronous, and
231          * scanout does not actually complete until the next vblank.  So some
232          * cleanup (like releasing the reference(s) on the backing GEM bo(s))
233          * should be deferred.  In cases like this, the driver would like to
234          * hold a ref to the fb even though it has already been removed from
235          * userspace perspective.
236          */
237         struct kref refcount;
238         /*
239          * Place on the dev->mode_config.fb_list, access protected by
240          * dev->mode_config.fb_lock.
241          */
242         struct list_head head;
243         struct drm_mode_object base;
244         const struct drm_framebuffer_funcs *funcs;
245         unsigned int pitches[4];
246         unsigned int offsets[4];
247         uint64_t modifier[4];
248         unsigned int width;
249         unsigned int height;
250         /* depth can be 15 or 16 */
251         unsigned int depth;
252         int bits_per_pixel;
253         int flags;
254         uint32_t pixel_format; /* fourcc format */
255         struct list_head filp_head;
256 };
257
258 struct drm_property_blob {
259         struct drm_mode_object base;
260         struct drm_device *dev;
261         struct kref refcount;
262         struct list_head head_global;
263         struct list_head head_file;
264         size_t length;
265         unsigned char data[];
266 };
267
268 struct drm_property_enum {
269         uint64_t value;
270         struct list_head head;
271         char name[DRM_PROP_NAME_LEN];
272 };
273
274 struct drm_property {
275         struct list_head head;
276         struct drm_mode_object base;
277         uint32_t flags;
278         char name[DRM_PROP_NAME_LEN];
279         uint32_t num_values;
280         uint64_t *values;
281         struct drm_device *dev;
282
283         struct list_head enum_list;
284 };
285
286 struct drm_crtc;
287 struct drm_connector;
288 struct drm_encoder;
289 struct drm_pending_vblank_event;
290 struct drm_plane;
291 struct drm_bridge;
292 struct drm_atomic_state;
293
294 struct drm_crtc_helper_funcs;
295 struct drm_encoder_helper_funcs;
296 struct drm_connector_helper_funcs;
297 struct drm_plane_helper_funcs;
298
299 /**
300  * struct drm_crtc_state - mutable CRTC state
301  * @crtc: backpointer to the CRTC
302  * @enable: whether the CRTC should be enabled, gates all other state
303  * @active: whether the CRTC is actively displaying (used for DPMS)
304  * @planes_changed: planes on this crtc are updated
305  * @mode_changed: crtc_state->mode or crtc_state->enable has been changed
306  * @active_changed: crtc_state->active has been toggled.
307  * @connectors_changed: connectors to this crtc have been updated
308  * @plane_mask: bitmask of (1 << drm_plane_index(plane)) of attached planes
309  * @last_vblank_count: for helpers and drivers to capture the vblank of the
310  *      update to ensure framebuffer cleanup isn't done too early
311  * @adjusted_mode: for use by helpers and drivers to compute adjusted mode timings
312  * @mode: current mode timings
313  * @event: optional pointer to a DRM event to signal upon completion of the
314  *      state update
315  * @state: backpointer to global drm_atomic_state
316  *
317  * Note that the distinction between @enable and @active is rather subtile:
318  * Flipping @active while @enable is set without changing anything else may
319  * never return in a failure from the ->atomic_check callback. Userspace assumes
320  * that a DPMS On will always succeed. In other words: @enable controls resource
321  * assignment, @active controls the actual hardware state.
322  */
323 struct drm_crtc_state {
324         struct drm_crtc *crtc;
325
326         bool enable;
327         bool active;
328
329         /* computed state bits used by helpers and drivers */
330         bool planes_changed : 1;
331         bool mode_changed : 1;
332         bool active_changed : 1;
333         bool connectors_changed : 1;
334
335         /* attached planes bitmask:
336          * WARNING: transitional helpers do not maintain plane_mask so
337          * drivers not converted over to atomic helpers should not rely
338          * on plane_mask being accurate!
339          */
340         u32 plane_mask;
341
342         /* last_vblank_count: for vblank waits before cleanup */
343         u32 last_vblank_count;
344
345         /* adjusted_mode: for use by helpers and drivers */
346         struct drm_display_mode adjusted_mode;
347
348         struct drm_display_mode mode;
349
350         /* blob property to expose current mode to atomic userspace */
351         struct drm_property_blob *mode_blob;
352
353         struct drm_pending_vblank_event *event;
354
355         struct drm_atomic_state *state;
356 };
357
358 /**
359  * struct drm_crtc_funcs - control CRTCs for a given device
360  *
361  * The drm_crtc_funcs structure is the central CRTC management structure
362  * in the DRM.  Each CRTC controls one or more connectors (note that the name
363  * CRTC is simply historical, a CRTC may control LVDS, VGA, DVI, TV out, etc.
364  * connectors, not just CRTs).
365  *
366  * Each driver is responsible for filling out this structure at startup time,
367  * in addition to providing other modesetting features, like i2c and DDC
368  * bus accessors.
369  */
370 struct drm_crtc_funcs {
371         /**
372          * @reset:
373          *
374          * Reset CRTC hardware and software state to off. This function isn't
375          * called by the core directly, only through drm_mode_config_reset().
376          * It's not a helper hook only for historical reasons.
377          *
378          * Atomic drivers can use drm_atomic_helper_crtc_reset() to reset
379          * atomic state using this hook.
380          */
381         void (*reset)(struct drm_crtc *crtc);
382
383         /**
384          * @cursor_set:
385          *
386          * Update the cursor image. The cursor position is relative to the CRTC
387          * and can be partially or fully outside of the visible area.
388          *
389          * Note that contrary to all other KMS functions the legacy cursor entry
390          * points don't take a framebuffer object, but instead take directly a
391          * raw buffer object id from the driver's buffer manager (which is
392          * either GEM or TTM for current drivers).
393          *
394          * This entry point is deprecated, drivers should instead implement
395          * universal plane support and register a proper cursor plane using
396          * drm_crtc_init_with_planes().
397          *
398          * This callback is optional
399          *
400          * RETURNS:
401          *
402          * 0 on success or a negative error code on failure.
403          */
404         int (*cursor_set)(struct drm_crtc *crtc, struct drm_file *file_priv,
405                           uint32_t handle, uint32_t width, uint32_t height);
406
407         /**
408          * @cursor_set2:
409          *
410          * Update the cursor image, including hotspot information. The hotspot
411          * must not affect the cursor position in CRTC coordinates, but is only
412          * meant as a hint for virtualized display hardware to coordinate the
413          * guests and hosts cursor position. The cursor hotspot is relative to
414          * the cursor image. Otherwise this works exactly like @cursor_set.
415          *
416          * This entry point is deprecated, drivers should instead implement
417          * universal plane support and register a proper cursor plane using
418          * drm_crtc_init_with_planes().
419          *
420          * This callback is optional.
421          *
422          * RETURNS:
423          *
424          * 0 on success or a negative error code on failure.
425          */
426         int (*cursor_set2)(struct drm_crtc *crtc, struct drm_file *file_priv,
427                            uint32_t handle, uint32_t width, uint32_t height,
428                            int32_t hot_x, int32_t hot_y);
429
430         /**
431          * @cursor_move:
432          *
433          * Update the cursor position. The cursor does not need to be visible
434          * when this hook is called.
435          *
436          * This entry point is deprecated, drivers should instead implement
437          * universal plane support and register a proper cursor plane using
438          * drm_crtc_init_with_planes().
439          *
440          * This callback is optional.
441          *
442          * RETURNS:
443          *
444          * 0 on success or a negative error code on failure.
445          */
446         int (*cursor_move)(struct drm_crtc *crtc, int x, int y);
447
448         /**
449          * @gamma_set:
450          *
451          * Set gamma on the CRTC.
452          *
453          * This callback is optional.
454          *
455          * NOTE:
456          *
457          * Drivers that support gamma tables and also fbdev emulation through
458          * the provided helper library need to take care to fill out the gamma
459          * hooks for both. Currently there's a bit an unfortunate duplication
460          * going on, which should eventually be unified to just one set of
461          * hooks.
462          */
463         void (*gamma_set)(struct drm_crtc *crtc, u16 *r, u16 *g, u16 *b,
464                           uint32_t start, uint32_t size);
465
466         /**
467          * @destroy:
468          *
469          * Clean up plane resources. This is only called at driver unload time
470          * through drm_mode_config_cleanup() since a CRTC cannot be hotplugged
471          * in DRM.
472          */
473         void (*destroy)(struct drm_crtc *crtc);
474
475         /**
476          * @set_config:
477          *
478          * This is the main legacy entry point to change the modeset state on a
479          * CRTC. All the details of the desired configuration are passed in a
480          * struct &drm_mode_set - see there for details.
481          *
482          * Drivers implementing atomic modeset should use
483          * drm_atomic_helper_set_config() to implement this hook.
484          *
485          * RETURNS:
486          *
487          * 0 on success or a negative error code on failure.
488          */
489         int (*set_config)(struct drm_mode_set *set);
490
491         /**
492          * @page_flip:
493          *
494          * Legacy entry point to schedule a flip to the given framebuffer.
495          *
496          * Page flipping is a synchronization mechanism that replaces the frame
497          * buffer being scanned out by the CRTC with a new frame buffer during
498          * vertical blanking, avoiding tearing (except when requested otherwise
499          * through the DRM_MODE_PAGE_FLIP_ASYNC flag). When an application
500          * requests a page flip the DRM core verifies that the new frame buffer
501          * is large enough to be scanned out by the CRTC in the currently
502          * configured mode and then calls the CRTC ->page_flip() operation with a
503          * pointer to the new frame buffer.
504          *
505          * The driver must wait for any pending rendering to the new framebuffer
506          * to complete before executing the flip. It should also wait for any
507          * pending rendering from other drivers if the underlying buffer is a
508          * shared dma-buf.
509          *
510          * An application can request to be notified when the page flip has
511          * completed. The drm core will supply a struct &drm_event in the event
512          * parameter in this case. This can be handled by the
513          * drm_crtc_send_vblank_event() function, which the driver should call on
514          * the provided event upon completion of the flip. Note that if
515          * the driver supports vblank signalling and timestamping the vblank
516          * counters and timestamps must agree with the ones returned from page
517          * flip events. With the current vblank helper infrastructure this can
518          * be achieved by holding a vblank reference while the page flip is
519          * pending, acquired through drm_crtc_vblank_get() and released with
520          * drm_crtc_vblank_put(). Drivers are free to implement their own vblank
521          * counter and timestamp tracking though, e.g. if they have accurate
522          * timestamp registers in hardware.
523          *
524          * FIXME:
525          *
526          * Up to that point drivers need to manage events themselves and can use
527          * even->base.list freely for that. Specifically they need to ensure
528          * that they don't send out page flip (or vblank) events for which the
529          * corresponding drm file has been closed already. The drm core
530          * unfortunately does not (yet) take care of that. Therefore drivers
531          * currently must clean up and release pending events in their
532          * ->preclose driver function.
533          *
534          * This callback is optional.
535          *
536          * NOTE:
537          *
538          * Very early versions of the KMS ABI mandated that the driver must
539          * block (but not reject) any rendering to the old framebuffer until the
540          * flip operation has completed and the old framebuffer is no longer
541          * visible. This requirement has been lifted, and userspace is instead
542          * expected to request delivery of an event and wait with recycling old
543          * buffers until such has been received.
544          *
545          * RETURNS:
546          *
547          * 0 on success or a negative error code on failure. Note that if a
548          * ->page_flip() operation is already pending the callback should return
549          * -EBUSY. Pageflips on a disabled CRTC (either by setting a NULL mode
550          * or just runtime disabled through DPMS respectively the new atomic
551          * "ACTIVE" state) should result in an -EINVAL error code.
552          */
553         int (*page_flip)(struct drm_crtc *crtc,
554                          struct drm_framebuffer *fb,
555                          struct drm_pending_vblank_event *event,
556                          uint32_t flags);
557
558         /**
559          * @set_property:
560          *
561          * This is the legacy entry point to update a property attached to the
562          * CRTC.
563          *
564          * Drivers implementing atomic modeset should use
565          * drm_atomic_helper_crtc_set_property() to implement this hook.
566          *
567          * This callback is optional if the driver does not support any legacy
568          * driver-private properties.
569          *
570          * RETURNS:
571          *
572          * 0 on success or a negative error code on failure.
573          */
574         int (*set_property)(struct drm_crtc *crtc,
575                             struct drm_property *property, uint64_t val);
576
577         /**
578          * @atomic_duplicate_state:
579          *
580          * Duplicate the current atomic state for this CRTC and return it.
581          * The core and helpers gurantee that any atomic state duplicated with
582          * this hook and still owned by the caller (i.e. not transferred to the
583          * driver by calling ->atomic_commit() from struct
584          * &drm_mode_config_funcs) will be cleaned up by calling the
585          * @atomic_destroy_state hook in this structure.
586          *
587          * Atomic drivers which don't subclass struct &drm_crtc should use
588          * drm_atomic_helper_crtc_duplicate_state(). Drivers that subclass the
589          * state structure to extend it with driver-private state should use
590          * __drm_atomic_helper_crtc_duplicate_state() to make sure shared state is
591          * duplicated in a consistent fashion across drivers.
592          *
593          * It is an error to call this hook before crtc->state has been
594          * initialized correctly.
595          *
596          * NOTE:
597          *
598          * If the duplicate state references refcounted resources this hook must
599          * acquire a reference for each of them. The driver must release these
600          * references again in @atomic_destroy_state.
601          *
602          * RETURNS:
603          *
604          * Duplicated atomic state or NULL when the allocation failed.
605          */
606         struct drm_crtc_state *(*atomic_duplicate_state)(struct drm_crtc *crtc);
607
608         /**
609          * @atomic_destroy_state:
610          *
611          * Destroy a state duplicated with @atomic_duplicate_state and release
612          * or unreference all resources it references
613          */
614         void (*atomic_destroy_state)(struct drm_crtc *crtc,
615                                      struct drm_crtc_state *state);
616
617         /**
618          * @atomic_set_property:
619          *
620          * Decode a driver-private property value and store the decoded value
621          * into the passed-in state structure. Since the atomic core decodes all
622          * standardized properties (even for extensions beyond the core set of
623          * properties which might not be implemented by all drivers) this
624          * requires drivers to subclass the state structure.
625          *
626          * Such driver-private properties should really only be implemented for
627          * truly hardware/vendor specific state. Instead it is preferred to
628          * standardize atomic extension and decode the properties used to expose
629          * such an extension in the core.
630          *
631          * Do not call this function directly, use
632          * drm_atomic_crtc_set_property() instead.
633          *
634          * This callback is optional if the driver does not support any
635          * driver-private atomic properties.
636          *
637          * NOTE:
638          *
639          * This function is called in the state assembly phase of atomic
640          * modesets, which can be aborted for any reason (including on
641          * userspace's request to just check whether a configuration would be
642          * possible). Drivers MUST NOT touch any persistent state (hardware or
643          * software) or data structures except the passed in @state parameter.
644          *
645          * Also since userspace controls in which order properties are set this
646          * function must not do any input validation (since the state update is
647          * incomplete and hence likely inconsistent). Instead any such input
648          * validation must be done in the various atomic_check callbacks.
649          *
650          * RETURNS:
651          *
652          * 0 if the property has been found, -EINVAL if the property isn't
653          * implemented by the driver (which should never happen, the core only
654          * asks for properties attached to this CRTC). No other validation is
655          * allowed by the driver. The core already checks that the property
656          * value is within the range (integer, valid enum value, ...) the driver
657          * set when registering the property.
658          */
659         int (*atomic_set_property)(struct drm_crtc *crtc,
660                                    struct drm_crtc_state *state,
661                                    struct drm_property *property,
662                                    uint64_t val);
663         /**
664          * @atomic_get_property:
665          *
666          * Reads out the decoded driver-private property. This is used to
667          * implement the GETCRTC IOCTL.
668          *
669          * Do not call this function directly, use
670          * drm_atomic_crtc_get_property() instead.
671          *
672          * This callback is optional if the driver does not support any
673          * driver-private atomic properties.
674          *
675          * RETURNS:
676          *
677          * 0 on success, -EINVAL if the property isn't implemented by the
678          * driver (which should never happen, the core only asks for
679          * properties attached to this CRTC).
680          */
681         int (*atomic_get_property)(struct drm_crtc *crtc,
682                                    const struct drm_crtc_state *state,
683                                    struct drm_property *property,
684                                    uint64_t *val);
685 };
686
687 /**
688  * struct drm_crtc - central CRTC control structure
689  * @dev: parent DRM device
690  * @port: OF node used by drm_of_find_possible_crtcs()
691  * @head: list management
692  * @mutex: per-CRTC locking
693  * @base: base KMS object for ID tracking etc.
694  * @primary: primary plane for this CRTC
695  * @cursor: cursor plane for this CRTC
696  * @cursor_x: current x position of the cursor, used for universal cursor planes
697  * @cursor_y: current y position of the cursor, used for universal cursor planes
698  * @enabled: is this CRTC enabled?
699  * @mode: current mode timings
700  * @hwmode: mode timings as programmed to hw regs
701  * @x: x position on screen
702  * @y: y position on screen
703  * @funcs: CRTC control functions
704  * @gamma_size: size of gamma ramp
705  * @gamma_store: gamma ramp values
706  * @helper_private: mid-layer private data
707  * @properties: property tracking for this CRTC
708  * @state: current atomic state for this CRTC
709  * @acquire_ctx: per-CRTC implicit acquire context used by atomic drivers for
710  *      legacy IOCTLs
711  *
712  * Each CRTC may have one or more connectors associated with it.  This structure
713  * allows the CRTC to be controlled.
714  */
715 struct drm_crtc {
716         struct drm_device *dev;
717         struct device_node *port;
718         struct list_head head;
719
720         char *name;
721
722         /*
723          * crtc mutex
724          *
725          * This provides a read lock for the overall crtc state (mode, dpms
726          * state, ...) and a write lock for everything which can be update
727          * without a full modeset (fb, cursor data, ...)
728          */
729         struct drm_modeset_lock mutex;
730
731         struct drm_mode_object base;
732
733         /* primary and cursor planes for CRTC */
734         struct drm_plane *primary;
735         struct drm_plane *cursor;
736
737         /* position of cursor plane on crtc */
738         int cursor_x;
739         int cursor_y;
740
741         bool enabled;
742
743         /* Requested mode from modesetting. */
744         struct drm_display_mode mode;
745
746         /* Programmed mode in hw, after adjustments for encoders,
747          * crtc, panel scaling etc. Needed for timestamping etc.
748          */
749         struct drm_display_mode hwmode;
750
751         int x, y;
752         const struct drm_crtc_funcs *funcs;
753
754         /* CRTC gamma size for reporting to userspace */
755         uint32_t gamma_size;
756         uint16_t *gamma_store;
757
758         /* if you are using the helper */
759         const struct drm_crtc_helper_funcs *helper_private;
760
761         struct drm_object_properties properties;
762
763         struct drm_crtc_state *state;
764
765         /*
766          * For legacy crtc IOCTLs so that atomic drivers can get at the locking
767          * acquire context.
768          */
769         struct drm_modeset_acquire_ctx *acquire_ctx;
770 };
771
772 /**
773  * struct drm_connector_state - mutable connector state
774  * @connector: backpointer to the connector
775  * @crtc: CRTC to connect connector to, NULL if disabled
776  * @best_encoder: can be used by helpers and drivers to select the encoder
777  * @state: backpointer to global drm_atomic_state
778  */
779 struct drm_connector_state {
780         struct drm_connector *connector;
781
782         struct drm_crtc *crtc;  /* do not write directly, use drm_atomic_set_crtc_for_connector() */
783
784         struct drm_encoder *best_encoder;
785
786         struct drm_atomic_state *state;
787 };
788
789 /**
790  * struct drm_connector_funcs - control connectors on a given device
791  *
792  * Each CRTC may have one or more connectors attached to it.  The functions
793  * below allow the core DRM code to control connectors, enumerate available modes,
794  * etc.
795  */
796 struct drm_connector_funcs {
797         /**
798          * @dpms:
799          *
800          * Legacy entry point to set the per-connector DPMS state. Legacy DPMS
801          * is exposed as a standard property on the connector, but diverted to
802          * this callback in the drm core. Note that atomic drivers don't
803          * implement the 4 level DPMS support on the connector any more, but
804          * instead only have an on/off "ACTIVE" property on the CRTC object.
805          *
806          * Drivers implementing atomic modeset should use
807          * drm_atomic_helper_connector_dpms() to implement this hook.
808          *
809          * RETURNS:
810          *
811          * 0 on success or a negative error code on failure.
812          */
813         int (*dpms)(struct drm_connector *connector, int mode);
814
815         /**
816          * @reset:
817          *
818          * Reset connector hardware and software state to off. This function isn't
819          * called by the core directly, only through drm_mode_config_reset().
820          * It's not a helper hook only for historical reasons.
821          *
822          * Atomic drivers can use drm_atomic_helper_connector_reset() to reset
823          * atomic state using this hook.
824          */
825         void (*reset)(struct drm_connector *connector);
826
827         /**
828          * @detect:
829          *
830          * Check to see if anything is attached to the connector. The parameter
831          * force is set to false whilst polling, true when checking the
832          * connector due to a user request. force can be used by the driver to
833          * avoid expensive, destructive operations during automated probing.
834          *
835          * FIXME:
836          *
837          * Note that this hook is only called by the probe helper. It's not in
838          * the helper library vtable purely for historical reasons. The only DRM
839          * core entry point to probe connector state is @fill_modes.
840          *
841          * RETURNS:
842          *
843          * drm_connector_status indicating the connector's status.
844          */
845         enum drm_connector_status (*detect)(struct drm_connector *connector,
846                                             bool force);
847
848         /**
849          * @force:
850          *
851          * This function is called to update internal encoder state when the
852          * connector is forced to a certain state by userspace, either through
853          * the sysfs interfaces or on the kernel cmdline. In that case the
854          * @detect callback isn't called.
855          *
856          * FIXME:
857          *
858          * Note that this hook is only called by the probe helper. It's not in
859          * the helper library vtable purely for historical reasons. The only DRM
860          * core entry point to probe connector state is @fill_modes.
861          */
862         void (*force)(struct drm_connector *connector);
863
864         /**
865          * @fill_modes:
866          *
867          * Entry point for output detection and basic mode validation. The
868          * driver should reprobe the output if needed (e.g. when hotplug
869          * handling is unreliable), add all detected modes to connector->modes
870          * and filter out any the device can't support in any configuration. It
871          * also needs to filter out any modes wider or higher than the
872          * parameters max_width and max_height indicate.
873          *
874          * The drivers must also prune any modes no longer valid from
875          * connector->modes. Furthermore it must update connector->status and
876          * connector->edid.  If no EDID has been received for this output
877          * connector->edid must be NULL.
878          *
879          * Drivers using the probe helpers should use
880          * drm_helper_probe_single_connector_modes() or
881          * drm_helper_probe_single_connector_modes_nomerge() to implement this
882          * function.
883          *
884          * RETURNS:
885          *
886          * The number of modes detected and filled into connector->modes.
887          */
888         int (*fill_modes)(struct drm_connector *connector, uint32_t max_width, uint32_t max_height);
889
890         /**
891          * @set_property:
892          *
893          * This is the legacy entry point to update a property attached to the
894          * connector.
895          *
896          * Drivers implementing atomic modeset should use
897          * drm_atomic_helper_connector_set_property() to implement this hook.
898          *
899          * This callback is optional if the driver does not support any legacy
900          * driver-private properties.
901          *
902          * RETURNS:
903          *
904          * 0 on success or a negative error code on failure.
905          */
906         int (*set_property)(struct drm_connector *connector, struct drm_property *property,
907                              uint64_t val);
908
909         /**
910          * @destroy:
911          *
912          * Clean up connector resources. This is called at driver unload time
913          * through drm_mode_config_cleanup(). It can also be called at runtime
914          * when a connector is being hot-unplugged for drivers that support
915          * connector hotplugging (e.g. DisplayPort MST).
916          */
917         void (*destroy)(struct drm_connector *connector);
918
919         /**
920          * @atomic_duplicate_state:
921          *
922          * Duplicate the current atomic state for this connector and return it.
923          * The core and helpers gurantee that any atomic state duplicated with
924          * this hook and still owned by the caller (i.e. not transferred to the
925          * driver by calling ->atomic_commit() from struct
926          * &drm_mode_config_funcs) will be cleaned up by calling the
927          * @atomic_destroy_state hook in this structure.
928          *
929          * Atomic drivers which don't subclass struct &drm_connector_state should use
930          * drm_atomic_helper_connector_duplicate_state(). Drivers that subclass the
931          * state structure to extend it with driver-private state should use
932          * __drm_atomic_helper_connector_duplicate_state() to make sure shared state is
933          * duplicated in a consistent fashion across drivers.
934          *
935          * It is an error to call this hook before connector->state has been
936          * initialized correctly.
937          *
938          * NOTE:
939          *
940          * If the duplicate state references refcounted resources this hook must
941          * acquire a reference for each of them. The driver must release these
942          * references again in @atomic_destroy_state.
943          *
944          * RETURNS:
945          *
946          * Duplicated atomic state or NULL when the allocation failed.
947          */
948         struct drm_connector_state *(*atomic_duplicate_state)(struct drm_connector *connector);
949
950         /**
951          * @atomic_destroy_state:
952          *
953          * Destroy a state duplicated with @atomic_duplicate_state and release
954          * or unreference all resources it references
955          */
956         void (*atomic_destroy_state)(struct drm_connector *connector,
957                                      struct drm_connector_state *state);
958
959         /**
960          * @atomic_set_property:
961          *
962          * Decode a driver-private property value and store the decoded value
963          * into the passed-in state structure. Since the atomic core decodes all
964          * standardized properties (even for extensions beyond the core set of
965          * properties which might not be implemented by all drivers) this
966          * requires drivers to subclass the state structure.
967          *
968          * Such driver-private properties should really only be implemented for
969          * truly hardware/vendor specific state. Instead it is preferred to
970          * standardize atomic extension and decode the properties used to expose
971          * such an extension in the core.
972          *
973          * Do not call this function directly, use
974          * drm_atomic_connector_set_property() instead.
975          *
976          * This callback is optional if the driver does not support any
977          * driver-private atomic properties.
978          *
979          * NOTE:
980          *
981          * This function is called in the state assembly phase of atomic
982          * modesets, which can be aborted for any reason (including on
983          * userspace's request to just check whether a configuration would be
984          * possible). Drivers MUST NOT touch any persistent state (hardware or
985          * software) or data structures except the passed in @state parameter.
986          *
987          * Also since userspace controls in which order properties are set this
988          * function must not do any input validation (since the state update is
989          * incomplete and hence likely inconsistent). Instead any such input
990          * validation must be done in the various atomic_check callbacks.
991          *
992          * RETURNS:
993          *
994          * 0 if the property has been found, -EINVAL if the property isn't
995          * implemented by the driver (which shouldn't ever happen, the core only
996          * asks for properties attached to this connector). No other validation
997          * is allowed by the driver. The core already checks that the property
998          * value is within the range (integer, valid enum value, ...) the driver
999          * set when registering the property.
1000          */
1001         int (*atomic_set_property)(struct drm_connector *connector,
1002                                    struct drm_connector_state *state,
1003                                    struct drm_property *property,
1004                                    uint64_t val);
1005
1006         /**
1007          * @atomic_get_property:
1008          *
1009          * Reads out the decoded driver-private property. This is used to
1010          * implement the GETCONNECTOR IOCTL.
1011          *
1012          * Do not call this function directly, use
1013          * drm_atomic_connector_get_property() instead.
1014          *
1015          * This callback is optional if the driver does not support any
1016          * driver-private atomic properties.
1017          *
1018          * RETURNS:
1019          *
1020          * 0 on success, -EINVAL if the property isn't implemented by the
1021          * driver (which shouldn't ever happen, the core only asks for
1022          * properties attached to this connector).
1023          */
1024         int (*atomic_get_property)(struct drm_connector *connector,
1025                                    const struct drm_connector_state *state,
1026                                    struct drm_property *property,
1027                                    uint64_t *val);
1028 };
1029
1030 /**
1031  * struct drm_encoder_funcs - encoder controls
1032  *
1033  * Encoders sit between CRTCs and connectors.
1034  */
1035 struct drm_encoder_funcs {
1036         /**
1037          * @reset:
1038          *
1039          * Reset encoder hardware and software state to off. This function isn't
1040          * called by the core directly, only through drm_mode_config_reset().
1041          * It's not a helper hook only for historical reasons.
1042          */
1043         void (*reset)(struct drm_encoder *encoder);
1044
1045         /**
1046          * @destroy:
1047          *
1048          * Clean up encoder resources. This is only called at driver unload time
1049          * through drm_mode_config_cleanup() since an encoder cannot be
1050          * hotplugged in DRM.
1051          */
1052         void (*destroy)(struct drm_encoder *encoder);
1053 };
1054
1055 #define DRM_CONNECTOR_MAX_ENCODER 3
1056
1057 /**
1058  * struct drm_encoder - central DRM encoder structure
1059  * @dev: parent DRM device
1060  * @head: list management
1061  * @base: base KMS object
1062  * @name: encoder name
1063  * @encoder_type: one of the %DRM_MODE_ENCODER_<foo> types in drm_mode.h
1064  * @possible_crtcs: bitmask of potential CRTC bindings
1065  * @possible_clones: bitmask of potential sibling encoders for cloning
1066  * @crtc: currently bound CRTC
1067  * @bridge: bridge associated to the encoder
1068  * @funcs: control functions
1069  * @helper_private: mid-layer private data
1070  *
1071  * CRTCs drive pixels to encoders, which convert them into signals
1072  * appropriate for a given connector or set of connectors.
1073  */
1074 struct drm_encoder {
1075         struct drm_device *dev;
1076         struct list_head head;
1077
1078         struct drm_mode_object base;
1079         char *name;
1080         int encoder_type;
1081         uint32_t possible_crtcs;
1082         uint32_t possible_clones;
1083
1084         struct drm_crtc *crtc;
1085         struct drm_bridge *bridge;
1086         const struct drm_encoder_funcs *funcs;
1087         const struct drm_encoder_helper_funcs *helper_private;
1088 };
1089
1090 /* should we poll this connector for connects and disconnects */
1091 /* hot plug detectable */
1092 #define DRM_CONNECTOR_POLL_HPD (1 << 0)
1093 /* poll for connections */
1094 #define DRM_CONNECTOR_POLL_CONNECT (1 << 1)
1095 /* can cleanly poll for disconnections without flickering the screen */
1096 /* DACs should rarely do this without a lot of testing */
1097 #define DRM_CONNECTOR_POLL_DISCONNECT (1 << 2)
1098
1099 #define MAX_ELD_BYTES   128
1100
1101 /**
1102  * struct drm_connector - central DRM connector control structure
1103  * @dev: parent DRM device
1104  * @kdev: kernel device for sysfs attributes
1105  * @attr: sysfs attributes
1106  * @head: list management
1107  * @base: base KMS object
1108  * @name: connector name
1109  * @connector_type: one of the %DRM_MODE_CONNECTOR_<foo> types from drm_mode.h
1110  * @connector_type_id: index into connector type enum
1111  * @interlace_allowed: can this connector handle interlaced modes?
1112  * @doublescan_allowed: can this connector handle doublescan?
1113  * @stereo_allowed: can this connector handle stereo modes?
1114  * @modes: modes available on this connector (from fill_modes() + user)
1115  * @status: one of the drm_connector_status enums (connected, not, or unknown)
1116  * @probed_modes: list of modes derived directly from the display
1117  * @display_info: information about attached display (e.g. from EDID)
1118  * @funcs: connector control functions
1119  * @edid_blob_ptr: DRM property containing EDID if present
1120  * @properties: property tracking for this connector
1121  * @path_blob_ptr: DRM blob property data for the DP MST path property
1122  * @polled: a %DRM_CONNECTOR_POLL_<foo> value for core driven polling
1123  * @dpms: current dpms state
1124  * @helper_private: mid-layer private data
1125  * @cmdline_mode: mode line parsed from the kernel cmdline for this connector
1126  * @force: a %DRM_FORCE_<foo> state for forced mode sets
1127  * @override_edid: has the EDID been overwritten through debugfs for testing?
1128  * @encoder_ids: valid encoders for this connector
1129  * @encoder: encoder driving this connector, if any
1130  * @eld: EDID-like data, if present
1131  * @dvi_dual: dual link DVI, if found
1132  * @max_tmds_clock: max clock rate, if found
1133  * @latency_present: AV delay info from ELD, if found
1134  * @video_latency: video latency info from ELD, if found
1135  * @audio_latency: audio latency info from ELD, if found
1136  * @null_edid_counter: track sinks that give us all zeros for the EDID
1137  * @bad_edid_counter: track sinks that give us an EDID with invalid checksum
1138  * @edid_corrupt: indicates whether the last read EDID was corrupt
1139  * @debugfs_entry: debugfs directory for this connector
1140  * @state: current atomic state for this connector
1141  * @has_tile: is this connector connected to a tiled monitor
1142  * @tile_group: tile group for the connected monitor
1143  * @tile_is_single_monitor: whether the tile is one monitor housing
1144  * @num_h_tile: number of horizontal tiles in the tile group
1145  * @num_v_tile: number of vertical tiles in the tile group
1146  * @tile_h_loc: horizontal location of this tile
1147  * @tile_v_loc: vertical location of this tile
1148  * @tile_h_size: horizontal size of this tile.
1149  * @tile_v_size: vertical size of this tile.
1150  *
1151  * Each connector may be connected to one or more CRTCs, or may be clonable by
1152  * another connector if they can share a CRTC.  Each connector also has a specific
1153  * position in the broader display (referred to as a 'screen' though it could
1154  * span multiple monitors).
1155  */
1156 struct drm_connector {
1157         struct drm_device *dev;
1158         struct device *kdev;
1159         struct device_attribute *attr;
1160         struct list_head head;
1161
1162         struct drm_mode_object base;
1163
1164         char *name;
1165         int connector_type;
1166         int connector_type_id;
1167         bool interlace_allowed;
1168         bool doublescan_allowed;
1169         bool stereo_allowed;
1170         struct list_head modes; /* list of modes on this connector */
1171
1172         enum drm_connector_status status;
1173
1174         /* these are modes added by probing with DDC or the BIOS */
1175         struct list_head probed_modes;
1176
1177         struct drm_display_info display_info;
1178         const struct drm_connector_funcs *funcs;
1179
1180         struct drm_property_blob *edid_blob_ptr;
1181         struct drm_object_properties properties;
1182
1183         struct drm_property_blob *path_blob_ptr;
1184
1185         struct drm_property_blob *tile_blob_ptr;
1186
1187         uint8_t polled; /* DRM_CONNECTOR_POLL_* */
1188
1189         /* requested DPMS state */
1190         int dpms;
1191
1192         const struct drm_connector_helper_funcs *helper_private;
1193
1194         /* forced on connector */
1195         struct drm_cmdline_mode cmdline_mode;
1196         enum drm_connector_force force;
1197         bool override_edid;
1198         uint32_t encoder_ids[DRM_CONNECTOR_MAX_ENCODER];
1199         struct drm_encoder *encoder; /* currently active encoder */
1200
1201         /* EDID bits */
1202         uint8_t eld[MAX_ELD_BYTES];
1203         bool dvi_dual;
1204         int max_tmds_clock;     /* in MHz */
1205         bool latency_present[2];
1206         int video_latency[2];   /* [0]: progressive, [1]: interlaced */
1207         int audio_latency[2];
1208         int null_edid_counter; /* needed to workaround some HW bugs where we get all 0s */
1209         unsigned bad_edid_counter;
1210
1211         /* Flag for raw EDID header corruption - used in Displayport
1212          * compliance testing - * Displayport Link CTS Core 1.2 rev1.1 4.2.2.6
1213          */
1214         bool edid_corrupt;
1215
1216         struct dentry *debugfs_entry;
1217
1218         struct drm_connector_state *state;
1219
1220         /* DisplayID bits */
1221         bool has_tile;
1222         struct drm_tile_group *tile_group;
1223         bool tile_is_single_monitor;
1224
1225         uint8_t num_h_tile, num_v_tile;
1226         uint8_t tile_h_loc, tile_v_loc;
1227         uint16_t tile_h_size, tile_v_size;
1228 };
1229
1230 /**
1231  * struct drm_plane_state - mutable plane state
1232  * @plane: backpointer to the plane
1233  * @crtc: currently bound CRTC, NULL if disabled
1234  * @fb: currently bound framebuffer
1235  * @fence: optional fence to wait for before scanning out @fb
1236  * @crtc_x: left position of visible portion of plane on crtc
1237  * @crtc_y: upper position of visible portion of plane on crtc
1238  * @crtc_w: width of visible portion of plane on crtc
1239  * @crtc_h: height of visible portion of plane on crtc
1240  * @src_x: left position of visible portion of plane within
1241  *      plane (in 16.16)
1242  * @src_y: upper position of visible portion of plane within
1243  *      plane (in 16.16)
1244  * @src_w: width of visible portion of plane (in 16.16)
1245  * @src_h: height of visible portion of plane (in 16.16)
1246  * @state: backpointer to global drm_atomic_state
1247  */
1248 struct drm_plane_state {
1249         struct drm_plane *plane;
1250
1251         struct drm_crtc *crtc;   /* do not write directly, use drm_atomic_set_crtc_for_plane() */
1252         struct drm_framebuffer *fb;  /* do not write directly, use drm_atomic_set_fb_for_plane() */
1253         struct fence *fence;
1254
1255         /* Signed dest location allows it to be partially off screen */
1256         int32_t crtc_x, crtc_y;
1257         uint32_t crtc_w, crtc_h;
1258
1259         /* Source values are 16.16 fixed point */
1260         uint32_t src_x, src_y;
1261         uint32_t src_h, src_w;
1262
1263         /* Plane rotation */
1264         unsigned int rotation;
1265
1266         struct drm_atomic_state *state;
1267 };
1268
1269
1270 /**
1271  * struct drm_plane_funcs - driver plane control functions
1272  */
1273 struct drm_plane_funcs {
1274         /**
1275          * @update_plane:
1276          *
1277          * This is the legacy entry point to enable and configure the plane for
1278          * the given CRTC and framebuffer. It is never called to disable the
1279          * plane, i.e. the passed-in crtc and fb paramters are never NULL.
1280          *
1281          * The source rectangle in frame buffer memory coordinates is given by
1282          * the src_x, src_y, src_w and src_h parameters (as 16.16 fixed point
1283          * values). Devices that don't support subpixel plane coordinates can
1284          * ignore the fractional part.
1285          *
1286          * The destination rectangle in CRTC coordinates is given by the
1287          * crtc_x, crtc_y, crtc_w and crtc_h parameters (as integer values).
1288          * Devices scale the source rectangle to the destination rectangle. If
1289          * scaling is not supported, and the source rectangle size doesn't match
1290          * the destination rectangle size, the driver must return a
1291          * -<errorname>EINVAL</errorname> error.
1292          *
1293          * Drivers implementing atomic modeset should use
1294          * drm_atomic_helper_update_plane() to implement this hook.
1295          *
1296          * RETURNS:
1297          *
1298          * 0 on success or a negative error code on failure.
1299          */
1300         int (*update_plane)(struct drm_plane *plane,
1301                             struct drm_crtc *crtc, struct drm_framebuffer *fb,
1302                             int crtc_x, int crtc_y,
1303                             unsigned int crtc_w, unsigned int crtc_h,
1304                             uint32_t src_x, uint32_t src_y,
1305                             uint32_t src_w, uint32_t src_h);
1306
1307         /**
1308          * @disable_plane:
1309          *
1310          * This is the legacy entry point to disable the plane. The DRM core
1311          * calls this method in response to a DRM_IOCTL_MODE_SETPLANE IOCTL call
1312          * with the frame buffer ID set to 0.  Disabled planes must not be
1313          * processed by the CRTC.
1314          *
1315          * Drivers implementing atomic modeset should use
1316          * drm_atomic_helper_disable_plane() to implement this hook.
1317          *
1318          * RETURNS:
1319          *
1320          * 0 on success or a negative error code on failure.
1321          */
1322         int (*disable_plane)(struct drm_plane *plane);
1323
1324         /**
1325          * @destroy:
1326          *
1327          * Clean up plane resources. This is only called at driver unload time
1328          * through drm_mode_config_cleanup() since a plane cannot be hotplugged
1329          * in DRM.
1330          */
1331         void (*destroy)(struct drm_plane *plane);
1332
1333         /**
1334          * @reset:
1335          *
1336          * Reset plane hardware and software state to off. This function isn't
1337          * called by the core directly, only through drm_mode_config_reset().
1338          * It's not a helper hook only for historical reasons.
1339          *
1340          * Atomic drivers can use drm_atomic_helper_plane_reset() to reset
1341          * atomic state using this hook.
1342          */
1343         void (*reset)(struct drm_plane *plane);
1344
1345         /**
1346          * @set_property:
1347          *
1348          * This is the legacy entry point to update a property attached to the
1349          * plane.
1350          *
1351          * Drivers implementing atomic modeset should use
1352          * drm_atomic_helper_plane_set_property() to implement this hook.
1353          *
1354          * This callback is optional if the driver does not support any legacy
1355          * driver-private properties.
1356          *
1357          * RETURNS:
1358          *
1359          * 0 on success or a negative error code on failure.
1360          */
1361         int (*set_property)(struct drm_plane *plane,
1362                             struct drm_property *property, uint64_t val);
1363
1364         /**
1365          * @atomic_duplicate_state:
1366          *
1367          * Duplicate the current atomic state for this plane and return it.
1368          * The core and helpers gurantee that any atomic state duplicated with
1369          * this hook and still owned by the caller (i.e. not transferred to the
1370          * driver by calling ->atomic_commit() from struct
1371          * &drm_mode_config_funcs) will be cleaned up by calling the
1372          * @atomic_destroy_state hook in this structure.
1373          *
1374          * Atomic drivers which don't subclass struct &drm_plane_state should use
1375          * drm_atomic_helper_plane_duplicate_state(). Drivers that subclass the
1376          * state structure to extend it with driver-private state should use
1377          * __drm_atomic_helper_plane_duplicate_state() to make sure shared state is
1378          * duplicated in a consistent fashion across drivers.
1379          *
1380          * It is an error to call this hook before plane->state has been
1381          * initialized correctly.
1382          *
1383          * NOTE:
1384          *
1385          * If the duplicate state references refcounted resources this hook must
1386          * acquire a reference for each of them. The driver must release these
1387          * references again in @atomic_destroy_state.
1388          *
1389          * RETURNS:
1390          *
1391          * Duplicated atomic state or NULL when the allocation failed.
1392          */
1393         struct drm_plane_state *(*atomic_duplicate_state)(struct drm_plane *plane);
1394
1395         /**
1396          * @atomic_destroy_state:
1397          *
1398          * Destroy a state duplicated with @atomic_duplicate_state and release
1399          * or unreference all resources it references
1400          */
1401         void (*atomic_destroy_state)(struct drm_plane *plane,
1402                                      struct drm_plane_state *state);
1403
1404         /**
1405          * @atomic_set_property:
1406          *
1407          * Decode a driver-private property value and store the decoded value
1408          * into the passed-in state structure. Since the atomic core decodes all
1409          * standardized properties (even for extensions beyond the core set of
1410          * properties which might not be implemented by all drivers) this
1411          * requires drivers to subclass the state structure.
1412          *
1413          * Such driver-private properties should really only be implemented for
1414          * truly hardware/vendor specific state. Instead it is preferred to
1415          * standardize atomic extension and decode the properties used to expose
1416          * such an extension in the core.
1417          *
1418          * Do not call this function directly, use
1419          * drm_atomic_plane_set_property() instead.
1420          *
1421          * This callback is optional if the driver does not support any
1422          * driver-private atomic properties.
1423          *
1424          * NOTE:
1425          *
1426          * This function is called in the state assembly phase of atomic
1427          * modesets, which can be aborted for any reason (including on
1428          * userspace's request to just check whether a configuration would be
1429          * possible). Drivers MUST NOT touch any persistent state (hardware or
1430          * software) or data structures except the passed in @state parameter.
1431          *
1432          * Also since userspace controls in which order properties are set this
1433          * function must not do any input validation (since the state update is
1434          * incomplete and hence likely inconsistent). Instead any such input
1435          * validation must be done in the various atomic_check callbacks.
1436          *
1437          * RETURNS:
1438          *
1439          * 0 if the property has been found, -EINVAL if the property isn't
1440          * implemented by the driver (which shouldn't ever happen, the core only
1441          * asks for properties attached to this plane). No other validation is
1442          * allowed by the driver. The core already checks that the property
1443          * value is within the range (integer, valid enum value, ...) the driver
1444          * set when registering the property.
1445          */
1446         int (*atomic_set_property)(struct drm_plane *plane,
1447                                    struct drm_plane_state *state,
1448                                    struct drm_property *property,
1449                                    uint64_t val);
1450
1451         /**
1452          * @atomic_get_property:
1453          *
1454          * Reads out the decoded driver-private property. This is used to
1455          * implement the GETPLANE IOCTL.
1456          *
1457          * Do not call this function directly, use
1458          * drm_atomic_plane_get_property() instead.
1459          *
1460          * This callback is optional if the driver does not support any
1461          * driver-private atomic properties.
1462          *
1463          * RETURNS:
1464          *
1465          * 0 on success, -EINVAL if the property isn't implemented by the
1466          * driver (which should never happen, the core only asks for
1467          * properties attached to this plane).
1468          */
1469         int (*atomic_get_property)(struct drm_plane *plane,
1470                                    const struct drm_plane_state *state,
1471                                    struct drm_property *property,
1472                                    uint64_t *val);
1473 };
1474
1475 enum drm_plane_type {
1476         DRM_PLANE_TYPE_OVERLAY,
1477         DRM_PLANE_TYPE_PRIMARY,
1478         DRM_PLANE_TYPE_CURSOR,
1479 };
1480
1481
1482 /**
1483  * struct drm_plane - central DRM plane control structure
1484  * @dev: DRM device this plane belongs to
1485  * @head: for list management
1486  * @base: base mode object
1487  * @possible_crtcs: pipes this plane can be bound to
1488  * @format_types: array of formats supported by this plane
1489  * @format_count: number of formats supported
1490  * @format_default: driver hasn't supplied supported formats for the plane
1491  * @crtc: currently bound CRTC
1492  * @fb: currently bound fb
1493  * @old_fb: Temporary tracking of the old fb while a modeset is ongoing. Used by
1494  *      drm_mode_set_config_internal() to implement correct refcounting.
1495  * @funcs: helper functions
1496  * @properties: property tracking for this plane
1497  * @type: type of plane (overlay, primary, cursor)
1498  * @state: current atomic state for this plane
1499  */
1500 struct drm_plane {
1501         struct drm_device *dev;
1502         struct list_head head;
1503
1504         char *name;
1505
1506         struct drm_modeset_lock mutex;
1507
1508         struct drm_mode_object base;
1509
1510         uint32_t possible_crtcs;
1511         uint32_t *format_types;
1512         unsigned int format_count;
1513         bool format_default;
1514
1515         struct drm_crtc *crtc;
1516         struct drm_framebuffer *fb;
1517
1518         struct drm_framebuffer *old_fb;
1519
1520         const struct drm_plane_funcs *funcs;
1521
1522         struct drm_object_properties properties;
1523
1524         enum drm_plane_type type;
1525
1526         const struct drm_plane_helper_funcs *helper_private;
1527
1528         struct drm_plane_state *state;
1529 };
1530
1531 /**
1532  * struct drm_bridge_funcs - drm_bridge control functions
1533  * @attach: Called during drm_bridge_attach
1534  */
1535 struct drm_bridge_funcs {
1536         int (*attach)(struct drm_bridge *bridge);
1537
1538         /**
1539          * @mode_fixup:
1540          *
1541          * This callback is used to validate and adjust a mode. The paramater
1542          * mode is the display mode that should be fed to the next element in
1543          * the display chain, either the final &drm_connector or the next
1544          * &drm_bridge. The parameter adjusted_mode is the input mode the bridge
1545          * requires. It can be modified by this callback and does not need to
1546          * match mode.
1547          *
1548          * This is the only hook that allows a bridge to reject a modeset. If
1549          * this function passes all other callbacks must succeed for this
1550          * configuration.
1551          *
1552          * NOTE:
1553          *
1554          * This function is called in the check phase of atomic modesets, which
1555          * can be aborted for any reason (including on userspace's request to
1556          * just check whether a configuration would be possible). Drivers MUST
1557          * NOT touch any persistent state (hardware or software) or data
1558          * structures except the passed in @state parameter.
1559          *
1560          * RETURNS:
1561          *
1562          * True if an acceptable configuration is possible, false if the modeset
1563          * operation should be rejected.
1564          */
1565         bool (*mode_fixup)(struct drm_bridge *bridge,
1566                            const struct drm_display_mode *mode,
1567                            struct drm_display_mode *adjusted_mode);
1568         /**
1569          * @disable:
1570          *
1571          * This callback should disable the bridge. It is called right before
1572          * the preceding element in the display pipe is disabled. If the
1573          * preceding element is a bridge this means it's called before that
1574          * bridge's ->disable() function. If the preceding element is a
1575          * &drm_encoder it's called right before the encoder's ->disable(),
1576          * ->prepare() or ->dpms() hook from struct &drm_encoder_helper_funcs.
1577          *
1578          * The bridge can assume that the display pipe (i.e. clocks and timing
1579          * signals) feeding it is still running when this callback is called.
1580          */
1581         void (*disable)(struct drm_bridge *bridge);
1582
1583         /**
1584          * @post_disable:
1585          *
1586          * This callback should disable the bridge. It is called right after
1587          * the preceding element in the display pipe is disabled. If the
1588          * preceding element is a bridge this means it's called after that
1589          * bridge's ->post_disable() function. If the preceding element is a
1590          * &drm_encoder it's called right after the encoder's ->disable(),
1591          * ->prepare() or ->dpms() hook from struct &drm_encoder_helper_funcs.
1592          *
1593          * The bridge must assume that the display pipe (i.e. clocks and timing
1594          * singals) feeding it is no longer running when this callback is
1595          * called.
1596          */
1597         void (*post_disable)(struct drm_bridge *bridge);
1598
1599         /**
1600          * @mode_set:
1601          *
1602          * This callback should set the given mode on the bridge. It is called
1603          * after the ->mode_set() callback for the preceding element in the
1604          * display pipeline has been called already. The display pipe (i.e.
1605          * clocks and timing signals) is off when this function is called.
1606          */
1607         void (*mode_set)(struct drm_bridge *bridge,
1608                          struct drm_display_mode *mode,
1609                          struct drm_display_mode *adjusted_mode);
1610         /**
1611          * @pre_enable:
1612          *
1613          * This callback should enable the bridge. It is called right before
1614          * the preceding element in the display pipe is enabled. If the
1615          * preceding element is a bridge this means it's called before that
1616          * bridge's ->pre_enable() function. If the preceding element is a
1617          * &drm_encoder it's called right before the encoder's ->enable(),
1618          * ->commit() or ->dpms() hook from struct &drm_encoder_helper_funcs.
1619          *
1620          * The display pipe (i.e. clocks and timing signals) feeding this bridge
1621          * will not yet be running when this callback is called. The bridge must
1622          * not enable the display link feeding the next bridge in the chain (if
1623          * there is one) when this callback is called.
1624          */
1625         void (*pre_enable)(struct drm_bridge *bridge);
1626
1627         /**
1628          * @enable:
1629          *
1630          * This callback should enable the bridge. It is called right after
1631          * the preceding element in the display pipe is enabled. If the
1632          * preceding element is a bridge this means it's called after that
1633          * bridge's ->enable() function. If the preceding element is a
1634          * &drm_encoder it's called right after the encoder's ->enable(),
1635          * ->commit() or ->dpms() hook from struct &drm_encoder_helper_funcs.
1636          *
1637          * The bridge can assume that the display pipe (i.e. clocks and timing
1638          * signals) feeding it is running when this callback is called. This
1639          * callback must enable the display link feeding the next bridge in the
1640          * chain if there is one.
1641          */
1642         void (*enable)(struct drm_bridge *bridge);
1643 };
1644
1645 /**
1646  * struct drm_bridge - central DRM bridge control structure
1647  * @dev: DRM device this bridge belongs to
1648  * @encoder: encoder to which this bridge is connected
1649  * @next: the next bridge in the encoder chain
1650  * @of_node: device node pointer to the bridge
1651  * @list: to keep track of all added bridges
1652  * @funcs: control functions
1653  * @driver_private: pointer to the bridge driver's internal context
1654  */
1655 struct drm_bridge {
1656         struct drm_device *dev;
1657         struct drm_encoder *encoder;
1658         struct drm_bridge *next;
1659 #ifdef CONFIG_OF
1660         struct device_node *of_node;
1661 #endif
1662         struct list_head list;
1663
1664         const struct drm_bridge_funcs *funcs;
1665         void *driver_private;
1666 };
1667
1668 /**
1669  * struct drm_atomic_state - the global state object for atomic updates
1670  * @dev: parent DRM device
1671  * @allow_modeset: allow full modeset
1672  * @legacy_cursor_update: hint to enforce legacy cursor IOCTL semantics
1673  * @planes: pointer to array of plane pointers
1674  * @plane_states: pointer to array of plane states pointers
1675  * @crtcs: pointer to array of CRTC pointers
1676  * @crtc_states: pointer to array of CRTC states pointers
1677  * @num_connector: size of the @connectors and @connector_states arrays
1678  * @connectors: pointer to array of connector pointers
1679  * @connector_states: pointer to array of connector states pointers
1680  * @acquire_ctx: acquire context for this atomic modeset state update
1681  */
1682 struct drm_atomic_state {
1683         struct drm_device *dev;
1684         bool allow_modeset : 1;
1685         bool legacy_cursor_update : 1;
1686         struct drm_plane **planes;
1687         struct drm_plane_state **plane_states;
1688         struct drm_crtc **crtcs;
1689         struct drm_crtc_state **crtc_states;
1690         int num_connector;
1691         struct drm_connector **connectors;
1692         struct drm_connector_state **connector_states;
1693
1694         struct drm_modeset_acquire_ctx *acquire_ctx;
1695 };
1696
1697
1698 /**
1699  * struct drm_mode_set - new values for a CRTC config change
1700  * @fb: framebuffer to use for new config
1701  * @crtc: CRTC whose configuration we're about to change
1702  * @mode: mode timings to use
1703  * @x: position of this CRTC relative to @fb
1704  * @y: position of this CRTC relative to @fb
1705  * @connectors: array of connectors to drive with this CRTC if possible
1706  * @num_connectors: size of @connectors array
1707  *
1708  * Represents a single crtc the connectors that it drives with what mode
1709  * and from which framebuffer it scans out from.
1710  *
1711  * This is used to set modes.
1712  */
1713 struct drm_mode_set {
1714         struct drm_framebuffer *fb;
1715         struct drm_crtc *crtc;
1716         struct drm_display_mode *mode;
1717
1718         uint32_t x;
1719         uint32_t y;
1720
1721         struct drm_connector **connectors;
1722         size_t num_connectors;
1723 };
1724
1725 /**
1726  * struct drm_mode_config_funcs - basic driver provided mode setting functions
1727  *
1728  * Some global (i.e. not per-CRTC, connector, etc) mode setting functions that
1729  * involve drivers.
1730  */
1731 struct drm_mode_config_funcs {
1732         /**
1733          * @fb_create:
1734          *
1735          * Create a new framebuffer object. The core does basic checks on the
1736          * requested metadata, but most of that is left to the driver. See
1737          * struct &drm_mode_fb_cmd2 for details.
1738          *
1739          * If the parameters are deemed valid and the backing storage objects in
1740          * the underlying memory manager all exist, then the driver allocates
1741          * a new &drm_framebuffer structure, subclassed to contain
1742          * driver-specific information (like the internal native buffer object
1743          * references). It also needs to fill out all relevant metadata, which
1744          * should be done by calling drm_helper_mode_fill_fb_struct().
1745          *
1746          * The initialization is finalized by calling drm_framebuffer_init(),
1747          * which registers the framebuffer and makes it accessible to other
1748          * threads.
1749          *
1750          * RETURNS:
1751          *
1752          * A new framebuffer with an initial reference count of 1 or a negative
1753          * error code encoded with ERR_PTR().
1754          */
1755         struct drm_framebuffer *(*fb_create)(struct drm_device *dev,
1756                                              struct drm_file *file_priv,
1757                                              const struct drm_mode_fb_cmd2 *mode_cmd);
1758
1759         /**
1760          * @output_poll_changed:
1761          *
1762          * Callback used by helpers to inform the driver of output configuration
1763          * changes.
1764          *
1765          * Drivers implementing fbdev emulation with the helpers can call
1766          * drm_fb_helper_hotplug_changed from this hook to inform the fbdev
1767          * helper of output changes.
1768          *
1769          * FIXME:
1770          *
1771          * Except that there's no vtable for device-level helper callbacks
1772          * there's no reason this is a core function.
1773          */
1774         void (*output_poll_changed)(struct drm_device *dev);
1775
1776         /**
1777          * @atomic_check:
1778          *
1779          * This is the only hook to validate an atomic modeset update. This
1780          * function must reject any modeset and state changes which the hardware
1781          * or driver doesn't support. This includes but is of course not limited
1782          * to:
1783          *
1784          *  - Checking that the modes, framebuffers, scaling and placement
1785          *    requirements and so on are within the limits of the hardware.
1786          *
1787          *  - Checking that any hidden shared resources are not oversubscribed.
1788          *    This can be shared PLLs, shared lanes, overall memory bandwidth,
1789          *    display fifo space (where shared between planes or maybe even
1790          *    CRTCs).
1791          *
1792          *  - Checking that virtualized resources exported to userspace are not
1793          *    oversubscribed. For various reasons it can make sense to expose
1794          *    more planes, crtcs or encoders than which are physically there. One
1795          *    example is dual-pipe operations (which generally should be hidden
1796          *    from userspace if when lockstepped in hardware, exposed otherwise),
1797          *    where a plane might need 1 hardware plane (if it's just on one
1798          *    pipe), 2 hardware planes (when it spans both pipes) or maybe even
1799          *    shared a hardware plane with a 2nd plane (if there's a compatible
1800          *    plane requested on the area handled by the other pipe).
1801          *
1802          *  - Check that any transitional state is possible and that if
1803          *    requested, the update can indeed be done in the vblank period
1804          *    without temporarily disabling some functions.
1805          *
1806          *  - Check any other constraints the driver or hardware might have.
1807          *
1808          *  - This callback also needs to correctly fill out the &drm_crtc_state
1809          *    in this update to make sure that drm_atomic_crtc_needs_modeset()
1810          *    reflects the nature of the possible update and returns true if and
1811          *    only if the update cannot be applied without tearing within one
1812          *    vblank on that CRTC. The core uses that information to reject
1813          *    updates which require a full modeset (i.e. blanking the screen, or
1814          *    at least pausing updates for a substantial amount of time) if
1815          *    userspace has disallowed that in its request.
1816          *
1817          *  - The driver also does not need to repeat basic input validation
1818          *    like done for the corresponding legacy entry points. The core does
1819          *    that before calling this hook.
1820          *
1821          * See the documentation of @atomic_commit for an exhaustive list of
1822          * error conditions which don't have to be checked at the
1823          * ->atomic_check() stage?
1824          *
1825          * See the documentation for struct &drm_atomic_state for how exactly
1826          * an atomic modeset update is described.
1827          *
1828          * Drivers using the atomic helpers can implement this hook using
1829          * drm_atomic_helper_check(), or one of the exported sub-functions of
1830          * it.
1831          *
1832          * RETURNS:
1833          *
1834          * 0 on success or one of the below negative error codes:
1835          *
1836          *  - -EINVAL, if any of the above constraints are violated.
1837          *
1838          *  - -EDEADLK, when returned from an attempt to acquire an additional
1839          *    &drm_modeset_lock through drm_modeset_lock().
1840          *
1841          *  - -ENOMEM, if allocating additional state sub-structures failed due
1842          *    to lack of memory.
1843          *
1844          *  - -EINTR, -EAGAIN or -ERESTARTSYS, if the IOCTL should be restarted.
1845          *    This can either be due to a pending signal, or because the driver
1846          *    needs to completely bail out to recover from an exceptional
1847          *    situation like a GPU hang. From a userspace point all errors are
1848          *    treated equally.
1849          */
1850         int (*atomic_check)(struct drm_device *dev,
1851                             struct drm_atomic_state *state);
1852
1853         /**
1854          * @atomic_commit:
1855          *
1856          * This is the only hook to commit an atomic modeset update. The core
1857          * guarantees that @atomic_check has been called successfully before
1858          * calling this function, and that nothing has been changed in the
1859          * interim.
1860          *
1861          * See the documentation for struct &drm_atomic_state for how exactly
1862          * an atomic modeset update is described.
1863          *
1864          * Drivers using the atomic helpers can implement this hook using
1865          * drm_atomic_helper_commit(), or one of the exported sub-functions of
1866          * it.
1867          *
1868          * Asynchronous commits (as indicated with the async parameter) must
1869          * do any preparatory work which might result in an unsuccessful commit
1870          * in the context of this callback. The only exceptions are hardware
1871          * errors resulting in -EIO. But even in that case the driver must
1872          * ensure that the display pipe is at least running, to avoid
1873          * compositors crashing when pageflips don't work. Anything else,
1874          * specifically committing the update to the hardware, should be done
1875          * without blocking the caller. For updates which do not require a
1876          * modeset this must be guaranteed.
1877          *
1878          * The driver must wait for any pending rendering to the new
1879          * framebuffers to complete before executing the flip. It should also
1880          * wait for any pending rendering from other drivers if the underlying
1881          * buffer is a shared dma-buf. Asynchronous commits must not wait for
1882          * rendering in the context of this callback.
1883          *
1884          * An application can request to be notified when the atomic commit has
1885          * completed. These events are per-CRTC and can be distinguished by the
1886          * CRTC index supplied in &drm_event to userspace.
1887          *
1888          * The drm core will supply a struct &drm_event in the event
1889          * member of each CRTC's &drm_crtc_state structure. This can be handled by the
1890          * drm_crtc_send_vblank_event() function, which the driver should call on
1891          * the provided event upon completion of the atomic commit. Note that if
1892          * the driver supports vblank signalling and timestamping the vblank
1893          * counters and timestamps must agree with the ones returned from page
1894          * flip events. With the current vblank helper infrastructure this can
1895          * be achieved by holding a vblank reference while the page flip is
1896          * pending, acquired through drm_crtc_vblank_get() and released with
1897          * drm_crtc_vblank_put(). Drivers are free to implement their own vblank
1898          * counter and timestamp tracking though, e.g. if they have accurate
1899          * timestamp registers in hardware.
1900          *
1901          * NOTE:
1902          *
1903          * Drivers are not allowed to shut down any display pipe successfully
1904          * enabled through an atomic commit on their own. Doing so can result in
1905          * compositors crashing if a page flip is suddenly rejected because the
1906          * pipe is off.
1907          *
1908          * RETURNS:
1909          *
1910          * 0 on success or one of the below negative error codes:
1911          *
1912          *  - -EBUSY, if an asynchronous updated is requested and there is
1913          *    an earlier updated pending. Drivers are allowed to support a queue
1914          *    of outstanding updates, but currently no driver supports that.
1915          *    Note that drivers must wait for preceding updates to complete if a
1916          *    synchronous update is requested, they are not allowed to fail the
1917          *    commit in that case.
1918          *
1919          *  - -ENOMEM, if the driver failed to allocate memory. Specifically
1920          *    this can happen when trying to pin framebuffers, which must only
1921          *    be done when committing the state.
1922          *
1923          *  - -ENOSPC, as a refinement of the more generic -ENOMEM to indicate
1924          *    that the driver has run out of vram, iommu space or similar GPU
1925          *    address space needed for framebuffer.
1926          *
1927          *  - -EIO, if the hardware completely died.
1928          *
1929          *  - -EINTR, -EAGAIN or -ERESTARTSYS, if the IOCTL should be restarted.
1930          *    This can either be due to a pending signal, or because the driver
1931          *    needs to completely bail out to recover from an exceptional
1932          *    situation like a GPU hang. From a userspace point of view all errors are
1933          *    treated equally.
1934          *
1935          * This list is exhaustive. Specifically this hook is not allowed to
1936          * return -EINVAL (any invalid requests should be caught in
1937          * @atomic_check) or -EDEADLK (this function must not acquire
1938          * additional modeset locks).
1939          */
1940         int (*atomic_commit)(struct drm_device *dev,
1941                              struct drm_atomic_state *state,
1942                              bool async);
1943
1944         /**
1945          * @atomic_state_alloc:
1946          *
1947          * This optional hook can be used by drivers that want to subclass struct
1948          * &drm_atomic_state to be able to track their own driver-private global
1949          * state easily. If this hook is implemented, drivers must also
1950          * implement @atomic_state_clear and @atomic_state_free.
1951          *
1952          * RETURNS:
1953          *
1954          * A new &drm_atomic_state on success or NULL on failure.
1955          */
1956         struct drm_atomic_state *(*atomic_state_alloc)(struct drm_device *dev);
1957
1958         /**
1959          * @atomic_state_clear:
1960          *
1961          * This hook must clear any driver private state duplicated into the
1962          * passed-in &drm_atomic_state. This hook is called when the caller
1963          * encountered a &drm_modeset_lock deadlock and needs to drop all
1964          * already acquired locks as part of the deadlock avoidance dance
1965          * implemented in drm_modeset_lock_backoff().
1966          *
1967          * Any duplicated state must be invalidated since a concurrent atomic
1968          * update might change it, and the drm atomic interfaces always apply
1969          * updates as relative changes to the current state.
1970          *
1971          * Drivers that implement this must call drm_atomic_state_default_clear()
1972          * to clear common state.
1973          */
1974         void (*atomic_state_clear)(struct drm_atomic_state *state);
1975
1976         /**
1977          * @atomic_state_free:
1978          *
1979          * This hook needs driver private resources and the &drm_atomic_state
1980          * itself. Note that the core first calls drm_atomic_state_clear() to
1981          * avoid code duplicate between the clear and free hooks.
1982          *
1983          * Drivers that implement this must call drm_atomic_state_default_free()
1984          * to release common resources.
1985          */
1986         void (*atomic_state_free)(struct drm_atomic_state *state);
1987 };
1988
1989 /**
1990  * struct drm_mode_config - Mode configuration control structure
1991  * @mutex: mutex protecting KMS related lists and structures
1992  * @connection_mutex: ww mutex protecting connector state and routing
1993  * @acquire_ctx: global implicit acquire context used by atomic drivers for
1994  *      legacy IOCTLs
1995  * @idr_mutex: mutex for KMS ID allocation and management
1996  * @crtc_idr: main KMS ID tracking object
1997  * @fb_lock: mutex to protect fb state and lists
1998  * @num_fb: number of fbs available
1999  * @fb_list: list of framebuffers available
2000  * @num_connector: number of connectors on this device
2001  * @connector_list: list of connector objects
2002  * @num_encoder: number of encoders on this device
2003  * @encoder_list: list of encoder objects
2004  * @num_overlay_plane: number of overlay planes on this device
2005  * @num_total_plane: number of universal (i.e. with primary/curso) planes on this device
2006  * @plane_list: list of plane objects
2007  * @num_crtc: number of CRTCs on this device
2008  * @crtc_list: list of CRTC objects
2009  * @property_list: list of property objects
2010  * @min_width: minimum pixel width on this device
2011  * @min_height: minimum pixel height on this device
2012  * @max_width: maximum pixel width on this device
2013  * @max_height: maximum pixel height on this device
2014  * @funcs: core driver provided mode setting functions
2015  * @fb_base: base address of the framebuffer
2016  * @poll_enabled: track polling support for this device
2017  * @poll_running: track polling status for this device
2018  * @output_poll_work: delayed work for polling in process context
2019  * @property_blob_list: list of all the blob property objects
2020  * @blob_lock: mutex for blob property allocation and management
2021  * @*_property: core property tracking
2022  * @preferred_depth: preferred RBG pixel depth, used by fb helpers
2023  * @prefer_shadow: hint to userspace to prefer shadow-fb rendering
2024  * @async_page_flip: does this device support async flips on the primary plane?
2025  * @cursor_width: hint to userspace for max cursor width
2026  * @cursor_height: hint to userspace for max cursor height
2027  *
2028  * Core mode resource tracking structure.  All CRTC, encoders, and connectors
2029  * enumerated by the driver are added here, as are global properties.  Some
2030  * global restrictions are also here, e.g. dimension restrictions.
2031  */
2032 struct drm_mode_config {
2033         struct mutex mutex; /* protects configuration (mode lists etc.) */
2034         struct drm_modeset_lock connection_mutex; /* protects connector->encoder and encoder->crtc links */
2035         struct drm_modeset_acquire_ctx *acquire_ctx; /* for legacy _lock_all() / _unlock_all() */
2036         struct mutex idr_mutex; /* for IDR management */
2037         struct idr crtc_idr; /* use this idr for all IDs, fb, crtc, connector, modes - just makes life easier */
2038         struct idr tile_idr; /* use this idr for all IDs, fb, crtc, connector, modes - just makes life easier */
2039         /* this is limited to one for now */
2040
2041         struct mutex fb_lock; /* proctects global and per-file fb lists */
2042         int num_fb;
2043         struct list_head fb_list;
2044
2045         int num_connector;
2046         struct list_head connector_list;
2047         int num_encoder;
2048         struct list_head encoder_list;
2049
2050         /*
2051          * Track # of overlay planes separately from # of total planes.  By
2052          * default we only advertise overlay planes to userspace; if userspace
2053          * sets the "universal plane" capability bit, we'll go ahead and
2054          * expose all planes.
2055          */
2056         int num_overlay_plane;
2057         int num_total_plane;
2058         struct list_head plane_list;
2059
2060         int num_crtc;
2061         struct list_head crtc_list;
2062
2063         struct list_head property_list;
2064
2065         int min_width, min_height;
2066         int max_width, max_height;
2067         const struct drm_mode_config_funcs *funcs;
2068         resource_size_t fb_base;
2069
2070         /* output poll support */
2071         bool poll_enabled;
2072         bool poll_running;
2073         bool delayed_event;
2074         struct delayed_work output_poll_work;
2075
2076         struct mutex blob_lock;
2077
2078         /* pointers to standard properties */
2079         struct list_head property_blob_list;
2080         struct drm_property *edid_property;
2081         struct drm_property *dpms_property;
2082         struct drm_property *path_property;
2083         struct drm_property *tile_property;
2084         struct drm_property *plane_type_property;
2085         struct drm_property *rotation_property;
2086         struct drm_property *prop_src_x;
2087         struct drm_property *prop_src_y;
2088         struct drm_property *prop_src_w;
2089         struct drm_property *prop_src_h;
2090         struct drm_property *prop_crtc_x;
2091         struct drm_property *prop_crtc_y;
2092         struct drm_property *prop_crtc_w;
2093         struct drm_property *prop_crtc_h;
2094         struct drm_property *prop_fb_id;
2095         struct drm_property *prop_crtc_id;
2096         struct drm_property *prop_active;
2097         struct drm_property *prop_mode_id;
2098
2099         /* DVI-I properties */
2100         struct drm_property *dvi_i_subconnector_property;
2101         struct drm_property *dvi_i_select_subconnector_property;
2102
2103         /* TV properties */
2104         struct drm_property *tv_subconnector_property;
2105         struct drm_property *tv_select_subconnector_property;
2106         struct drm_property *tv_mode_property;
2107         struct drm_property *tv_left_margin_property;
2108         struct drm_property *tv_right_margin_property;
2109         struct drm_property *tv_top_margin_property;
2110         struct drm_property *tv_bottom_margin_property;
2111         struct drm_property *tv_brightness_property;
2112         struct drm_property *tv_contrast_property;
2113         struct drm_property *tv_flicker_reduction_property;
2114         struct drm_property *tv_overscan_property;
2115         struct drm_property *tv_saturation_property;
2116         struct drm_property *tv_hue_property;
2117
2118         /* Optional properties */
2119         struct drm_property *scaling_mode_property;
2120         struct drm_property *aspect_ratio_property;
2121         struct drm_property *dirty_info_property;
2122
2123         /* properties for virtual machine layout */
2124         struct drm_property *suggested_x_property;
2125         struct drm_property *suggested_y_property;
2126
2127         /* dumb ioctl parameters */
2128         uint32_t preferred_depth, prefer_shadow;
2129
2130         /* whether async page flip is supported or not */
2131         bool async_page_flip;
2132
2133         /* whether the driver supports fb modifiers */
2134         bool allow_fb_modifiers;
2135
2136         /* cursor size */
2137         uint32_t cursor_width, cursor_height;
2138 };
2139
2140 /**
2141  * drm_for_each_plane_mask - iterate over planes specified by bitmask
2142  * @plane: the loop cursor
2143  * @dev: the DRM device
2144  * @plane_mask: bitmask of plane indices
2145  *
2146  * Iterate over all planes specified by bitmask.
2147  */
2148 #define drm_for_each_plane_mask(plane, dev, plane_mask) \
2149         list_for_each_entry((plane), &(dev)->mode_config.plane_list, head) \
2150                 for_each_if ((plane_mask) & (1 << drm_plane_index(plane)))
2151
2152
2153 #define obj_to_crtc(x) container_of(x, struct drm_crtc, base)
2154 #define obj_to_connector(x) container_of(x, struct drm_connector, base)
2155 #define obj_to_encoder(x) container_of(x, struct drm_encoder, base)
2156 #define obj_to_mode(x) container_of(x, struct drm_display_mode, base)
2157 #define obj_to_fb(x) container_of(x, struct drm_framebuffer, base)
2158 #define obj_to_property(x) container_of(x, struct drm_property, base)
2159 #define obj_to_blob(x) container_of(x, struct drm_property_blob, base)
2160 #define obj_to_plane(x) container_of(x, struct drm_plane, base)
2161
2162 struct drm_prop_enum_list {
2163         int type;
2164         char *name;
2165 };
2166
2167 extern __printf(6, 7)
2168 int drm_crtc_init_with_planes(struct drm_device *dev,
2169                               struct drm_crtc *crtc,
2170                               struct drm_plane *primary,
2171                               struct drm_plane *cursor,
2172                               const struct drm_crtc_funcs *funcs,
2173                               const char *name, ...);
2174 extern void drm_crtc_cleanup(struct drm_crtc *crtc);
2175 extern unsigned int drm_crtc_index(struct drm_crtc *crtc);
2176
2177 /**
2178  * drm_crtc_mask - find the mask of a registered CRTC
2179  * @crtc: CRTC to find mask for
2180  *
2181  * Given a registered CRTC, return the mask bit of that CRTC for an
2182  * encoder's possible_crtcs field.
2183  */
2184 static inline uint32_t drm_crtc_mask(struct drm_crtc *crtc)
2185 {
2186         return 1 << drm_crtc_index(crtc);
2187 }
2188
2189 extern void drm_connector_ida_init(void);
2190 extern void drm_connector_ida_destroy(void);
2191 extern int drm_connector_init(struct drm_device *dev,
2192                               struct drm_connector *connector,
2193                               const struct drm_connector_funcs *funcs,
2194                               int connector_type);
2195 int drm_connector_register(struct drm_connector *connector);
2196 void drm_connector_unregister(struct drm_connector *connector);
2197
2198 extern void drm_connector_cleanup(struct drm_connector *connector);
2199 extern unsigned int drm_connector_index(struct drm_connector *connector);
2200 /* helper to unplug all connectors from sysfs for device */
2201 extern void drm_connector_unplug_all(struct drm_device *dev);
2202
2203 extern int drm_bridge_add(struct drm_bridge *bridge);
2204 extern void drm_bridge_remove(struct drm_bridge *bridge);
2205 extern struct drm_bridge *of_drm_find_bridge(struct device_node *np);
2206 extern int drm_bridge_attach(struct drm_device *dev, struct drm_bridge *bridge);
2207
2208 bool drm_bridge_mode_fixup(struct drm_bridge *bridge,
2209                         const struct drm_display_mode *mode,
2210                         struct drm_display_mode *adjusted_mode);
2211 void drm_bridge_disable(struct drm_bridge *bridge);
2212 void drm_bridge_post_disable(struct drm_bridge *bridge);
2213 void drm_bridge_mode_set(struct drm_bridge *bridge,
2214                         struct drm_display_mode *mode,
2215                         struct drm_display_mode *adjusted_mode);
2216 void drm_bridge_pre_enable(struct drm_bridge *bridge);
2217 void drm_bridge_enable(struct drm_bridge *bridge);
2218
2219 extern __printf(5, 6)
2220 int drm_encoder_init(struct drm_device *dev,
2221                      struct drm_encoder *encoder,
2222                      const struct drm_encoder_funcs *funcs,
2223                      int encoder_type, const char *name, ...);
2224
2225 /**
2226  * drm_encoder_crtc_ok - can a given crtc drive a given encoder?
2227  * @encoder: encoder to test
2228  * @crtc: crtc to test
2229  *
2230  * Return false if @encoder can't be driven by @crtc, true otherwise.
2231  */
2232 static inline bool drm_encoder_crtc_ok(struct drm_encoder *encoder,
2233                                        struct drm_crtc *crtc)
2234 {
2235         return !!(encoder->possible_crtcs & drm_crtc_mask(crtc));
2236 }
2237
2238 extern __printf(8, 9)
2239 int drm_universal_plane_init(struct drm_device *dev,
2240                              struct drm_plane *plane,
2241                              unsigned long possible_crtcs,
2242                              const struct drm_plane_funcs *funcs,
2243                              const uint32_t *formats,
2244                              unsigned int format_count,
2245                              enum drm_plane_type type,
2246                              const char *name, ...);
2247 extern int drm_plane_init(struct drm_device *dev,
2248                           struct drm_plane *plane,
2249                           unsigned long possible_crtcs,
2250                           const struct drm_plane_funcs *funcs,
2251                           const uint32_t *formats, unsigned int format_count,
2252                           bool is_primary);
2253 extern void drm_plane_cleanup(struct drm_plane *plane);
2254 extern unsigned int drm_plane_index(struct drm_plane *plane);
2255 extern struct drm_plane * drm_plane_from_index(struct drm_device *dev, int idx);
2256 extern void drm_plane_force_disable(struct drm_plane *plane);
2257 extern int drm_plane_check_pixel_format(const struct drm_plane *plane,
2258                                         u32 format);
2259 extern void drm_crtc_get_hv_timing(const struct drm_display_mode *mode,
2260                                    int *hdisplay, int *vdisplay);
2261 extern int drm_crtc_check_viewport(const struct drm_crtc *crtc,
2262                                    int x, int y,
2263                                    const struct drm_display_mode *mode,
2264                                    const struct drm_framebuffer *fb);
2265
2266 extern void drm_encoder_cleanup(struct drm_encoder *encoder);
2267
2268 extern const char *drm_get_connector_status_name(enum drm_connector_status status);
2269 extern const char *drm_get_subpixel_order_name(enum subpixel_order order);
2270 extern const char *drm_get_dpms_name(int val);
2271 extern const char *drm_get_dvi_i_subconnector_name(int val);
2272 extern const char *drm_get_dvi_i_select_name(int val);
2273 extern const char *drm_get_tv_subconnector_name(int val);
2274 extern const char *drm_get_tv_select_name(int val);
2275 extern void drm_fb_release(struct drm_file *file_priv);
2276 extern void drm_property_destroy_user_blobs(struct drm_device *dev,
2277                                             struct drm_file *file_priv);
2278 extern bool drm_probe_ddc(struct i2c_adapter *adapter);
2279 extern struct edid *drm_get_edid(struct drm_connector *connector,
2280                                  struct i2c_adapter *adapter);
2281 extern struct edid *drm_edid_duplicate(const struct edid *edid);
2282 extern int drm_add_edid_modes(struct drm_connector *connector, struct edid *edid);
2283 extern void drm_mode_config_init(struct drm_device *dev);
2284 extern void drm_mode_config_reset(struct drm_device *dev);
2285 extern void drm_mode_config_cleanup(struct drm_device *dev);
2286
2287 extern int drm_mode_connector_set_path_property(struct drm_connector *connector,
2288                                                 const char *path);
2289 int drm_mode_connector_set_tile_property(struct drm_connector *connector);
2290 extern int drm_mode_connector_update_edid_property(struct drm_connector *connector,
2291                                                    const struct edid *edid);
2292
2293 extern int drm_display_info_set_bus_formats(struct drm_display_info *info,
2294                                             const u32 *formats,
2295                                             unsigned int num_formats);
2296
2297 static inline bool drm_property_type_is(struct drm_property *property,
2298                 uint32_t type)
2299 {
2300         /* instanceof for props.. handles extended type vs original types: */
2301         if (property->flags & DRM_MODE_PROP_EXTENDED_TYPE)
2302                 return (property->flags & DRM_MODE_PROP_EXTENDED_TYPE) == type;
2303         return property->flags & type;
2304 }
2305
2306 static inline bool drm_property_type_valid(struct drm_property *property)
2307 {
2308         if (property->flags & DRM_MODE_PROP_EXTENDED_TYPE)
2309                 return !(property->flags & DRM_MODE_PROP_LEGACY_TYPE);
2310         return !!(property->flags & DRM_MODE_PROP_LEGACY_TYPE);
2311 }
2312
2313 extern int drm_object_property_set_value(struct drm_mode_object *obj,
2314                                          struct drm_property *property,
2315                                          uint64_t val);
2316 extern int drm_object_property_get_value(struct drm_mode_object *obj,
2317                                          struct drm_property *property,
2318                                          uint64_t *value);
2319 extern int drm_framebuffer_init(struct drm_device *dev,
2320                                 struct drm_framebuffer *fb,
2321                                 const struct drm_framebuffer_funcs *funcs);
2322 extern struct drm_framebuffer *drm_framebuffer_lookup(struct drm_device *dev,
2323                                                       uint32_t id);
2324 extern void drm_framebuffer_unreference(struct drm_framebuffer *fb);
2325 extern void drm_framebuffer_reference(struct drm_framebuffer *fb);
2326 extern void drm_framebuffer_remove(struct drm_framebuffer *fb);
2327 extern void drm_framebuffer_cleanup(struct drm_framebuffer *fb);
2328 extern void drm_framebuffer_unregister_private(struct drm_framebuffer *fb);
2329
2330 extern void drm_object_attach_property(struct drm_mode_object *obj,
2331                                        struct drm_property *property,
2332                                        uint64_t init_val);
2333 extern struct drm_property *drm_property_create(struct drm_device *dev, int flags,
2334                                                 const char *name, int num_values);
2335 extern struct drm_property *drm_property_create_enum(struct drm_device *dev, int flags,
2336                                          const char *name,
2337                                          const struct drm_prop_enum_list *props,
2338                                          int num_values);
2339 struct drm_property *drm_property_create_bitmask(struct drm_device *dev,
2340                                          int flags, const char *name,
2341                                          const struct drm_prop_enum_list *props,
2342                                          int num_props,
2343                                          uint64_t supported_bits);
2344 struct drm_property *drm_property_create_range(struct drm_device *dev, int flags,
2345                                          const char *name,
2346                                          uint64_t min, uint64_t max);
2347 struct drm_property *drm_property_create_signed_range(struct drm_device *dev,
2348                                          int flags, const char *name,
2349                                          int64_t min, int64_t max);
2350 struct drm_property *drm_property_create_object(struct drm_device *dev,
2351                                          int flags, const char *name, uint32_t type);
2352 struct drm_property *drm_property_create_bool(struct drm_device *dev, int flags,
2353                                          const char *name);
2354 struct drm_property_blob *drm_property_create_blob(struct drm_device *dev,
2355                                                    size_t length,
2356                                                    const void *data);
2357 struct drm_property_blob *drm_property_lookup_blob(struct drm_device *dev,
2358                                                    uint32_t id);
2359 struct drm_property_blob *drm_property_reference_blob(struct drm_property_blob *blob);
2360 void drm_property_unreference_blob(struct drm_property_blob *blob);
2361 extern void drm_property_destroy(struct drm_device *dev, struct drm_property *property);
2362 extern int drm_property_add_enum(struct drm_property *property, int index,
2363                                  uint64_t value, const char *name);
2364 extern int drm_mode_create_dvi_i_properties(struct drm_device *dev);
2365 extern int drm_mode_create_tv_properties(struct drm_device *dev,
2366                                          unsigned int num_modes,
2367                                          const char * const modes[]);
2368 extern int drm_mode_create_scaling_mode_property(struct drm_device *dev);
2369 extern int drm_mode_create_aspect_ratio_property(struct drm_device *dev);
2370 extern int drm_mode_create_dirty_info_property(struct drm_device *dev);
2371 extern int drm_mode_create_suggested_offset_properties(struct drm_device *dev);
2372 extern bool drm_property_change_valid_get(struct drm_property *property,
2373                                          uint64_t value, struct drm_mode_object **ref);
2374 extern void drm_property_change_valid_put(struct drm_property *property,
2375                 struct drm_mode_object *ref);
2376
2377 extern int drm_mode_connector_attach_encoder(struct drm_connector *connector,
2378                                              struct drm_encoder *encoder);
2379 extern int drm_mode_crtc_set_gamma_size(struct drm_crtc *crtc,
2380                                          int gamma_size);
2381 extern struct drm_mode_object *drm_mode_object_find(struct drm_device *dev,
2382                 uint32_t id, uint32_t type);
2383
2384 /* IOCTLs */
2385 extern int drm_mode_getresources(struct drm_device *dev,
2386                                  void *data, struct drm_file *file_priv);
2387 extern int drm_mode_getplane_res(struct drm_device *dev, void *data,
2388                                    struct drm_file *file_priv);
2389 extern int drm_mode_getcrtc(struct drm_device *dev,
2390                             void *data, struct drm_file *file_priv);
2391 extern int drm_mode_getconnector(struct drm_device *dev,
2392                               void *data, struct drm_file *file_priv);
2393 extern int drm_mode_set_config_internal(struct drm_mode_set *set);
2394 extern int drm_mode_setcrtc(struct drm_device *dev,
2395                             void *data, struct drm_file *file_priv);
2396 extern int drm_mode_getplane(struct drm_device *dev,
2397                                void *data, struct drm_file *file_priv);
2398 extern int drm_mode_setplane(struct drm_device *dev,
2399                                void *data, struct drm_file *file_priv);
2400 extern int drm_mode_cursor_ioctl(struct drm_device *dev,
2401                                 void *data, struct drm_file *file_priv);
2402 extern int drm_mode_cursor2_ioctl(struct drm_device *dev,
2403                                 void *data, struct drm_file *file_priv);
2404 extern int drm_mode_addfb(struct drm_device *dev,
2405                           void *data, struct drm_file *file_priv);
2406 extern int drm_mode_addfb2(struct drm_device *dev,
2407                            void *data, struct drm_file *file_priv);
2408 extern uint32_t drm_mode_legacy_fb_format(uint32_t bpp, uint32_t depth);
2409 extern int drm_mode_rmfb(struct drm_device *dev,
2410                          void *data, struct drm_file *file_priv);
2411 extern int drm_mode_getfb(struct drm_device *dev,
2412                           void *data, struct drm_file *file_priv);
2413 extern int drm_mode_dirtyfb_ioctl(struct drm_device *dev,
2414                                   void *data, struct drm_file *file_priv);
2415
2416 extern int drm_mode_getproperty_ioctl(struct drm_device *dev,
2417                                       void *data, struct drm_file *file_priv);
2418 extern int drm_mode_getblob_ioctl(struct drm_device *dev,
2419                                   void *data, struct drm_file *file_priv);
2420 extern int drm_mode_createblob_ioctl(struct drm_device *dev,
2421                                      void *data, struct drm_file *file_priv);
2422 extern int drm_mode_destroyblob_ioctl(struct drm_device *dev,
2423                                       void *data, struct drm_file *file_priv);
2424 extern int drm_mode_connector_property_set_ioctl(struct drm_device *dev,
2425                                               void *data, struct drm_file *file_priv);
2426 extern int drm_mode_getencoder(struct drm_device *dev,
2427                                void *data, struct drm_file *file_priv);
2428 extern int drm_mode_gamma_get_ioctl(struct drm_device *dev,
2429                                     void *data, struct drm_file *file_priv);
2430 extern int drm_mode_gamma_set_ioctl(struct drm_device *dev,
2431                                     void *data, struct drm_file *file_priv);
2432 extern u8 drm_match_cea_mode(const struct drm_display_mode *to_match);
2433 extern enum hdmi_picture_aspect drm_get_cea_aspect_ratio(const u8 video_code);
2434 extern bool drm_detect_hdmi_monitor(struct edid *edid);
2435 extern bool drm_detect_monitor_audio(struct edid *edid);
2436 extern bool drm_rgb_quant_range_selectable(struct edid *edid);
2437 extern int drm_mode_page_flip_ioctl(struct drm_device *dev,
2438                                     void *data, struct drm_file *file_priv);
2439 extern int drm_add_modes_noedid(struct drm_connector *connector,
2440                                 int hdisplay, int vdisplay);
2441 extern void drm_set_preferred_mode(struct drm_connector *connector,
2442                                    int hpref, int vpref);
2443
2444 extern int drm_edid_header_is_valid(const u8 *raw_edid);
2445 extern bool drm_edid_block_valid(u8 *raw_edid, int block, bool print_bad_edid,
2446                                  bool *edid_corrupt);
2447 extern bool drm_edid_is_valid(struct edid *edid);
2448
2449 extern struct drm_tile_group *drm_mode_create_tile_group(struct drm_device *dev,
2450                                                          char topology[8]);
2451 extern struct drm_tile_group *drm_mode_get_tile_group(struct drm_device *dev,
2452                                                char topology[8]);
2453 extern void drm_mode_put_tile_group(struct drm_device *dev,
2454                                    struct drm_tile_group *tg);
2455 struct drm_display_mode *drm_mode_find_dmt(struct drm_device *dev,
2456                                            int hsize, int vsize, int fresh,
2457                                            bool rb);
2458
2459 extern int drm_mode_create_dumb_ioctl(struct drm_device *dev,
2460                                       void *data, struct drm_file *file_priv);
2461 extern int drm_mode_mmap_dumb_ioctl(struct drm_device *dev,
2462                                     void *data, struct drm_file *file_priv);
2463 extern int drm_mode_destroy_dumb_ioctl(struct drm_device *dev,
2464                                       void *data, struct drm_file *file_priv);
2465 extern int drm_mode_obj_get_properties_ioctl(struct drm_device *dev, void *data,
2466                                              struct drm_file *file_priv);
2467 extern int drm_mode_obj_set_property_ioctl(struct drm_device *dev, void *data,
2468                                            struct drm_file *file_priv);
2469 extern int drm_mode_plane_set_obj_prop(struct drm_plane *plane,
2470                                        struct drm_property *property,
2471                                        uint64_t value);
2472 extern int drm_mode_atomic_ioctl(struct drm_device *dev,
2473                                  void *data, struct drm_file *file_priv);
2474
2475 extern void drm_fb_get_bpp_depth(uint32_t format, unsigned int *depth,
2476                                  int *bpp);
2477 extern int drm_format_num_planes(uint32_t format);
2478 extern int drm_format_plane_cpp(uint32_t format, int plane);
2479 extern int drm_format_horz_chroma_subsampling(uint32_t format);
2480 extern int drm_format_vert_chroma_subsampling(uint32_t format);
2481 extern const char *drm_get_format_name(uint32_t format);
2482 extern struct drm_property *drm_mode_create_rotation_property(struct drm_device *dev,
2483                                                               unsigned int supported_rotations);
2484 extern unsigned int drm_rotation_simplify(unsigned int rotation,
2485                                           unsigned int supported_rotations);
2486
2487 /* Helpers */
2488
2489 static inline struct drm_plane *drm_plane_find(struct drm_device *dev,
2490                 uint32_t id)
2491 {
2492         struct drm_mode_object *mo;
2493         mo = drm_mode_object_find(dev, id, DRM_MODE_OBJECT_PLANE);
2494         return mo ? obj_to_plane(mo) : NULL;
2495 }
2496
2497 static inline struct drm_crtc *drm_crtc_find(struct drm_device *dev,
2498         uint32_t id)
2499 {
2500         struct drm_mode_object *mo;
2501         mo = drm_mode_object_find(dev, id, DRM_MODE_OBJECT_CRTC);
2502         return mo ? obj_to_crtc(mo) : NULL;
2503 }
2504
2505 static inline struct drm_encoder *drm_encoder_find(struct drm_device *dev,
2506         uint32_t id)
2507 {
2508         struct drm_mode_object *mo;
2509         mo = drm_mode_object_find(dev, id, DRM_MODE_OBJECT_ENCODER);
2510         return mo ? obj_to_encoder(mo) : NULL;
2511 }
2512
2513 static inline struct drm_connector *drm_connector_find(struct drm_device *dev,
2514                 uint32_t id)
2515 {
2516         struct drm_mode_object *mo;
2517         mo = drm_mode_object_find(dev, id, DRM_MODE_OBJECT_CONNECTOR);
2518         return mo ? obj_to_connector(mo) : NULL;
2519 }
2520
2521 static inline struct drm_property *drm_property_find(struct drm_device *dev,
2522                 uint32_t id)
2523 {
2524         struct drm_mode_object *mo;
2525         mo = drm_mode_object_find(dev, id, DRM_MODE_OBJECT_PROPERTY);
2526         return mo ? obj_to_property(mo) : NULL;
2527 }
2528
2529 /* Plane list iterator for legacy (overlay only) planes. */
2530 #define drm_for_each_legacy_plane(plane, dev) \
2531         list_for_each_entry(plane, &(dev)->mode_config.plane_list, head) \
2532                 for_each_if (plane->type == DRM_PLANE_TYPE_OVERLAY)
2533
2534 #define drm_for_each_plane(plane, dev) \
2535         list_for_each_entry(plane, &(dev)->mode_config.plane_list, head)
2536
2537 #define drm_for_each_crtc(crtc, dev) \
2538         list_for_each_entry(crtc, &(dev)->mode_config.crtc_list, head)
2539
2540 static inline void
2541 assert_drm_connector_list_read_locked(struct drm_mode_config *mode_config)
2542 {
2543         /*
2544          * The connector hotadd/remove code currently grabs both locks when
2545          * updating lists. Hence readers need only hold either of them to be
2546          * safe and the check amounts to
2547          *
2548          * WARN_ON(not_holding(A) && not_holding(B)).
2549          */
2550         WARN_ON(!mutex_is_locked(&mode_config->mutex) &&
2551                 !drm_modeset_is_locked(&mode_config->connection_mutex));
2552 }
2553
2554 #define drm_for_each_connector(connector, dev) \
2555         for (assert_drm_connector_list_read_locked(&(dev)->mode_config),        \
2556              connector = list_first_entry(&(dev)->mode_config.connector_list,   \
2557                                           struct drm_connector, head);          \
2558              &connector->head != (&(dev)->mode_config.connector_list);          \
2559              connector = list_next_entry(connector, head))
2560
2561 #define drm_for_each_encoder(encoder, dev) \
2562         list_for_each_entry(encoder, &(dev)->mode_config.encoder_list, head)
2563
2564 #define drm_for_each_fb(fb, dev) \
2565         for (WARN_ON(!mutex_is_locked(&(dev)->mode_config.fb_lock)),            \
2566              fb = list_first_entry(&(dev)->mode_config.fb_list, \
2567                                           struct drm_framebuffer, head);        \
2568              &fb->head != (&(dev)->mode_config.fb_list);                        \
2569              fb = list_next_entry(fb, head))
2570
2571 #endif /* __DRM_CRTC_H__ */