drm/amdgpu: revert "use more than 64KB fragment size if possible"
[cascardo/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 #include <drm/drm_rect.h>
39 #include <drm/drm_mode_object.h>
40 #include <drm/drm_framebuffer.h>
41 #include <drm/drm_modes.h>
42 #include <drm/drm_connector.h>
43 #include <drm/drm_encoder.h>
44 #include <drm/drm_property.h>
45 #include <drm/drm_bridge.h>
46 #include <drm/drm_edid.h>
47 #include <drm/drm_plane.h>
48 #include <drm/drm_blend.h>
49 #include <drm/drm_color_mgmt.h>
50
51 struct drm_device;
52 struct drm_mode_set;
53 struct drm_file;
54 struct drm_clip_rect;
55 struct device_node;
56 struct fence;
57 struct edid;
58
59 static inline int64_t U642I64(uint64_t val)
60 {
61         return (int64_t)*((int64_t *)&val);
62 }
63 static inline uint64_t I642U64(int64_t val)
64 {
65         return (uint64_t)*((uint64_t *)&val);
66 }
67
68 /* data corresponds to displayid vend/prod/serial */
69 struct drm_tile_group {
70         struct kref refcount;
71         struct drm_device *dev;
72         int id;
73         u8 group_data[8];
74 };
75
76 struct drm_crtc;
77 struct drm_encoder;
78 struct drm_pending_vblank_event;
79 struct drm_plane;
80 struct drm_bridge;
81 struct drm_atomic_state;
82
83 struct drm_crtc_helper_funcs;
84 struct drm_encoder_helper_funcs;
85 struct drm_plane_helper_funcs;
86
87 /**
88  * struct drm_crtc_state - mutable CRTC state
89  * @crtc: backpointer to the CRTC
90  * @enable: whether the CRTC should be enabled, gates all other state
91  * @active: whether the CRTC is actively displaying (used for DPMS)
92  * @planes_changed: planes on this crtc are updated
93  * @mode_changed: crtc_state->mode or crtc_state->enable has been changed
94  * @active_changed: crtc_state->active has been toggled.
95  * @connectors_changed: connectors to this crtc have been updated
96  * @zpos_changed: zpos values of planes on this crtc have been updated
97  * @color_mgmt_changed: color management properties have changed (degamma or
98  *      gamma LUT or CSC matrix)
99  * @plane_mask: bitmask of (1 << drm_plane_index(plane)) of attached planes
100  * @connector_mask: bitmask of (1 << drm_connector_index(connector)) of attached connectors
101  * @encoder_mask: bitmask of (1 << drm_encoder_index(encoder)) of attached encoders
102  * @last_vblank_count: for helpers and drivers to capture the vblank of the
103  *      update to ensure framebuffer cleanup isn't done too early
104  * @adjusted_mode: for use by helpers and drivers to compute adjusted mode timings
105  * @mode: current mode timings
106  * @mode_blob: &drm_property_blob for @mode
107  * @degamma_lut: Lookup table for converting framebuffer pixel data
108  *      before apply the conversion matrix
109  * @ctm: Transformation matrix
110  * @gamma_lut: Lookup table for converting pixel data after the
111  *      conversion matrix
112  * @event: optional pointer to a DRM event to signal upon completion of the
113  *      state update
114  * @state: backpointer to global drm_atomic_state
115  *
116  * Note that the distinction between @enable and @active is rather subtile:
117  * Flipping @active while @enable is set without changing anything else may
118  * never return in a failure from the ->atomic_check callback. Userspace assumes
119  * that a DPMS On will always succeed. In other words: @enable controls resource
120  * assignment, @active controls the actual hardware state.
121  */
122 struct drm_crtc_state {
123         struct drm_crtc *crtc;
124
125         bool enable;
126         bool active;
127
128         /* computed state bits used by helpers and drivers */
129         bool planes_changed : 1;
130         bool mode_changed : 1;
131         bool active_changed : 1;
132         bool connectors_changed : 1;
133         bool zpos_changed : 1;
134         bool color_mgmt_changed : 1;
135
136         /* attached planes bitmask:
137          * WARNING: transitional helpers do not maintain plane_mask so
138          * drivers not converted over to atomic helpers should not rely
139          * on plane_mask being accurate!
140          */
141         u32 plane_mask;
142
143         u32 connector_mask;
144         u32 encoder_mask;
145
146         /* last_vblank_count: for vblank waits before cleanup */
147         u32 last_vblank_count;
148
149         /* adjusted_mode: for use by helpers and drivers */
150         struct drm_display_mode adjusted_mode;
151
152         struct drm_display_mode mode;
153
154         /* blob property to expose current mode to atomic userspace */
155         struct drm_property_blob *mode_blob;
156
157         /* blob property to expose color management to userspace */
158         struct drm_property_blob *degamma_lut;
159         struct drm_property_blob *ctm;
160         struct drm_property_blob *gamma_lut;
161
162         struct drm_pending_vblank_event *event;
163
164         struct drm_atomic_state *state;
165 };
166
167 /**
168  * struct drm_crtc_funcs - control CRTCs for a given device
169  *
170  * The drm_crtc_funcs structure is the central CRTC management structure
171  * in the DRM.  Each CRTC controls one or more connectors (note that the name
172  * CRTC is simply historical, a CRTC may control LVDS, VGA, DVI, TV out, etc.
173  * connectors, not just CRTs).
174  *
175  * Each driver is responsible for filling out this structure at startup time,
176  * in addition to providing other modesetting features, like i2c and DDC
177  * bus accessors.
178  */
179 struct drm_crtc_funcs {
180         /**
181          * @reset:
182          *
183          * Reset CRTC hardware and software state to off. This function isn't
184          * called by the core directly, only through drm_mode_config_reset().
185          * It's not a helper hook only for historical reasons.
186          *
187          * Atomic drivers can use drm_atomic_helper_crtc_reset() to reset
188          * atomic state using this hook.
189          */
190         void (*reset)(struct drm_crtc *crtc);
191
192         /**
193          * @cursor_set:
194          *
195          * Update the cursor image. The cursor position is relative to the CRTC
196          * and can be partially or fully outside of the visible area.
197          *
198          * Note that contrary to all other KMS functions the legacy cursor entry
199          * points don't take a framebuffer object, but instead take directly a
200          * raw buffer object id from the driver's buffer manager (which is
201          * either GEM or TTM for current drivers).
202          *
203          * This entry point is deprecated, drivers should instead implement
204          * universal plane support and register a proper cursor plane using
205          * drm_crtc_init_with_planes().
206          *
207          * This callback is optional
208          *
209          * RETURNS:
210          *
211          * 0 on success or a negative error code on failure.
212          */
213         int (*cursor_set)(struct drm_crtc *crtc, struct drm_file *file_priv,
214                           uint32_t handle, uint32_t width, uint32_t height);
215
216         /**
217          * @cursor_set2:
218          *
219          * Update the cursor image, including hotspot information. The hotspot
220          * must not affect the cursor position in CRTC coordinates, but is only
221          * meant as a hint for virtualized display hardware to coordinate the
222          * guests and hosts cursor position. The cursor hotspot is relative to
223          * the cursor image. Otherwise this works exactly like @cursor_set.
224          *
225          * This entry point is deprecated, drivers should instead implement
226          * universal plane support and register a proper cursor plane using
227          * drm_crtc_init_with_planes().
228          *
229          * This callback is optional.
230          *
231          * RETURNS:
232          *
233          * 0 on success or a negative error code on failure.
234          */
235         int (*cursor_set2)(struct drm_crtc *crtc, struct drm_file *file_priv,
236                            uint32_t handle, uint32_t width, uint32_t height,
237                            int32_t hot_x, int32_t hot_y);
238
239         /**
240          * @cursor_move:
241          *
242          * Update the cursor position. The cursor does not need to be visible
243          * when this hook is called.
244          *
245          * This entry point is deprecated, drivers should instead implement
246          * universal plane support and register a proper cursor plane using
247          * drm_crtc_init_with_planes().
248          *
249          * This callback is optional.
250          *
251          * RETURNS:
252          *
253          * 0 on success or a negative error code on failure.
254          */
255         int (*cursor_move)(struct drm_crtc *crtc, int x, int y);
256
257         /**
258          * @gamma_set:
259          *
260          * Set gamma on the CRTC.
261          *
262          * This callback is optional.
263          *
264          * NOTE:
265          *
266          * Drivers that support gamma tables and also fbdev emulation through
267          * the provided helper library need to take care to fill out the gamma
268          * hooks for both. Currently there's a bit an unfortunate duplication
269          * going on, which should eventually be unified to just one set of
270          * hooks.
271          */
272         int (*gamma_set)(struct drm_crtc *crtc, u16 *r, u16 *g, u16 *b,
273                          uint32_t size);
274
275         /**
276          * @destroy:
277          *
278          * Clean up plane resources. This is only called at driver unload time
279          * through drm_mode_config_cleanup() since a CRTC cannot be hotplugged
280          * in DRM.
281          */
282         void (*destroy)(struct drm_crtc *crtc);
283
284         /**
285          * @set_config:
286          *
287          * This is the main legacy entry point to change the modeset state on a
288          * CRTC. All the details of the desired configuration are passed in a
289          * struct &drm_mode_set - see there for details.
290          *
291          * Drivers implementing atomic modeset should use
292          * drm_atomic_helper_set_config() to implement this hook.
293          *
294          * RETURNS:
295          *
296          * 0 on success or a negative error code on failure.
297          */
298         int (*set_config)(struct drm_mode_set *set);
299
300         /**
301          * @page_flip:
302          *
303          * Legacy entry point to schedule a flip to the given framebuffer.
304          *
305          * Page flipping is a synchronization mechanism that replaces the frame
306          * buffer being scanned out by the CRTC with a new frame buffer during
307          * vertical blanking, avoiding tearing (except when requested otherwise
308          * through the DRM_MODE_PAGE_FLIP_ASYNC flag). When an application
309          * requests a page flip the DRM core verifies that the new frame buffer
310          * is large enough to be scanned out by the CRTC in the currently
311          * configured mode and then calls the CRTC ->page_flip() operation with a
312          * pointer to the new frame buffer.
313          *
314          * The driver must wait for any pending rendering to the new framebuffer
315          * to complete before executing the flip. It should also wait for any
316          * pending rendering from other drivers if the underlying buffer is a
317          * shared dma-buf.
318          *
319          * An application can request to be notified when the page flip has
320          * completed. The drm core will supply a struct &drm_event in the event
321          * parameter in this case. This can be handled by the
322          * drm_crtc_send_vblank_event() function, which the driver should call on
323          * the provided event upon completion of the flip. Note that if
324          * the driver supports vblank signalling and timestamping the vblank
325          * counters and timestamps must agree with the ones returned from page
326          * flip events. With the current vblank helper infrastructure this can
327          * be achieved by holding a vblank reference while the page flip is
328          * pending, acquired through drm_crtc_vblank_get() and released with
329          * drm_crtc_vblank_put(). Drivers are free to implement their own vblank
330          * counter and timestamp tracking though, e.g. if they have accurate
331          * timestamp registers in hardware.
332          *
333          * This callback is optional.
334          *
335          * NOTE:
336          *
337          * Very early versions of the KMS ABI mandated that the driver must
338          * block (but not reject) any rendering to the old framebuffer until the
339          * flip operation has completed and the old framebuffer is no longer
340          * visible. This requirement has been lifted, and userspace is instead
341          * expected to request delivery of an event and wait with recycling old
342          * buffers until such has been received.
343          *
344          * RETURNS:
345          *
346          * 0 on success or a negative error code on failure. Note that if a
347          * ->page_flip() operation is already pending the callback should return
348          * -EBUSY. Pageflips on a disabled CRTC (either by setting a NULL mode
349          * or just runtime disabled through DPMS respectively the new atomic
350          * "ACTIVE" state) should result in an -EINVAL error code. Note that
351          * drm_atomic_helper_page_flip() checks this already for atomic drivers.
352          */
353         int (*page_flip)(struct drm_crtc *crtc,
354                          struct drm_framebuffer *fb,
355                          struct drm_pending_vblank_event *event,
356                          uint32_t flags);
357
358         /**
359          * @page_flip_target:
360          *
361          * Same as @page_flip but with an additional parameter specifying the
362          * absolute target vertical blank period (as reported by
363          * drm_crtc_vblank_count()) when the flip should take effect.
364          *
365          * Note that the core code calls drm_crtc_vblank_get before this entry
366          * point, and will call drm_crtc_vblank_put if this entry point returns
367          * any non-0 error code. It's the driver's responsibility to call
368          * drm_crtc_vblank_put after this entry point returns 0, typically when
369          * the flip completes.
370          */
371         int (*page_flip_target)(struct drm_crtc *crtc,
372                                 struct drm_framebuffer *fb,
373                                 struct drm_pending_vblank_event *event,
374                                 uint32_t flags, uint32_t target);
375
376         /**
377          * @set_property:
378          *
379          * This is the legacy entry point to update a property attached to the
380          * CRTC.
381          *
382          * Drivers implementing atomic modeset should use
383          * drm_atomic_helper_crtc_set_property() to implement this hook.
384          *
385          * This callback is optional if the driver does not support any legacy
386          * driver-private properties.
387          *
388          * RETURNS:
389          *
390          * 0 on success or a negative error code on failure.
391          */
392         int (*set_property)(struct drm_crtc *crtc,
393                             struct drm_property *property, uint64_t val);
394
395         /**
396          * @atomic_duplicate_state:
397          *
398          * Duplicate the current atomic state for this CRTC and return it.
399          * The core and helpers gurantee that any atomic state duplicated with
400          * this hook and still owned by the caller (i.e. not transferred to the
401          * driver by calling ->atomic_commit() from struct
402          * &drm_mode_config_funcs) will be cleaned up by calling the
403          * @atomic_destroy_state hook in this structure.
404          *
405          * Atomic drivers which don't subclass struct &drm_crtc should use
406          * drm_atomic_helper_crtc_duplicate_state(). Drivers that subclass the
407          * state structure to extend it with driver-private state should use
408          * __drm_atomic_helper_crtc_duplicate_state() to make sure shared state is
409          * duplicated in a consistent fashion across drivers.
410          *
411          * It is an error to call this hook before crtc->state has been
412          * initialized correctly.
413          *
414          * NOTE:
415          *
416          * If the duplicate state references refcounted resources this hook must
417          * acquire a reference for each of them. The driver must release these
418          * references again in @atomic_destroy_state.
419          *
420          * RETURNS:
421          *
422          * Duplicated atomic state or NULL when the allocation failed.
423          */
424         struct drm_crtc_state *(*atomic_duplicate_state)(struct drm_crtc *crtc);
425
426         /**
427          * @atomic_destroy_state:
428          *
429          * Destroy a state duplicated with @atomic_duplicate_state and release
430          * or unreference all resources it references
431          */
432         void (*atomic_destroy_state)(struct drm_crtc *crtc,
433                                      struct drm_crtc_state *state);
434
435         /**
436          * @atomic_set_property:
437          *
438          * Decode a driver-private property value and store the decoded value
439          * into the passed-in state structure. Since the atomic core decodes all
440          * standardized properties (even for extensions beyond the core set of
441          * properties which might not be implemented by all drivers) this
442          * requires drivers to subclass the state structure.
443          *
444          * Such driver-private properties should really only be implemented for
445          * truly hardware/vendor specific state. Instead it is preferred to
446          * standardize atomic extension and decode the properties used to expose
447          * such an extension in the core.
448          *
449          * Do not call this function directly, use
450          * drm_atomic_crtc_set_property() instead.
451          *
452          * This callback is optional if the driver does not support any
453          * driver-private atomic properties.
454          *
455          * NOTE:
456          *
457          * This function is called in the state assembly phase of atomic
458          * modesets, which can be aborted for any reason (including on
459          * userspace's request to just check whether a configuration would be
460          * possible). Drivers MUST NOT touch any persistent state (hardware or
461          * software) or data structures except the passed in @state parameter.
462          *
463          * Also since userspace controls in which order properties are set this
464          * function must not do any input validation (since the state update is
465          * incomplete and hence likely inconsistent). Instead any such input
466          * validation must be done in the various atomic_check callbacks.
467          *
468          * RETURNS:
469          *
470          * 0 if the property has been found, -EINVAL if the property isn't
471          * implemented by the driver (which should never happen, the core only
472          * asks for properties attached to this CRTC). No other validation is
473          * allowed by the driver. The core already checks that the property
474          * value is within the range (integer, valid enum value, ...) the driver
475          * set when registering the property.
476          */
477         int (*atomic_set_property)(struct drm_crtc *crtc,
478                                    struct drm_crtc_state *state,
479                                    struct drm_property *property,
480                                    uint64_t val);
481         /**
482          * @atomic_get_property:
483          *
484          * Reads out the decoded driver-private property. This is used to
485          * implement the GETCRTC IOCTL.
486          *
487          * Do not call this function directly, use
488          * drm_atomic_crtc_get_property() instead.
489          *
490          * This callback is optional if the driver does not support any
491          * driver-private atomic properties.
492          *
493          * RETURNS:
494          *
495          * 0 on success, -EINVAL if the property isn't implemented by the
496          * driver (which should never happen, the core only asks for
497          * properties attached to this CRTC).
498          */
499         int (*atomic_get_property)(struct drm_crtc *crtc,
500                                    const struct drm_crtc_state *state,
501                                    struct drm_property *property,
502                                    uint64_t *val);
503
504         /**
505          * @late_register:
506          *
507          * This optional hook can be used to register additional userspace
508          * interfaces attached to the crtc like debugfs interfaces.
509          * It is called late in the driver load sequence from drm_dev_register().
510          * Everything added from this callback should be unregistered in
511          * the early_unregister callback.
512          *
513          * Returns:
514          *
515          * 0 on success, or a negative error code on failure.
516          */
517         int (*late_register)(struct drm_crtc *crtc);
518
519         /**
520          * @early_unregister:
521          *
522          * This optional hook should be used to unregister the additional
523          * userspace interfaces attached to the crtc from
524          * late_unregister(). It is called from drm_dev_unregister(),
525          * early in the driver unload sequence to disable userspace access
526          * before data structures are torndown.
527          */
528         void (*early_unregister)(struct drm_crtc *crtc);
529 };
530
531 /**
532  * struct drm_crtc - central CRTC control structure
533  * @dev: parent DRM device
534  * @port: OF node used by drm_of_find_possible_crtcs()
535  * @head: list management
536  * @name: human readable name, can be overwritten by the driver
537  * @mutex: per-CRTC locking
538  * @base: base KMS object for ID tracking etc.
539  * @primary: primary plane for this CRTC
540  * @cursor: cursor plane for this CRTC
541  * @cursor_x: current x position of the cursor, used for universal cursor planes
542  * @cursor_y: current y position of the cursor, used for universal cursor planes
543  * @enabled: is this CRTC enabled?
544  * @mode: current mode timings
545  * @hwmode: mode timings as programmed to hw regs
546  * @x: x position on screen
547  * @y: y position on screen
548  * @funcs: CRTC control functions
549  * @gamma_size: size of gamma ramp
550  * @gamma_store: gamma ramp values
551  * @helper_private: mid-layer private data
552  * @properties: property tracking for this CRTC
553  *
554  * Each CRTC may have one or more connectors associated with it.  This structure
555  * allows the CRTC to be controlled.
556  */
557 struct drm_crtc {
558         struct drm_device *dev;
559         struct device_node *port;
560         struct list_head head;
561
562         char *name;
563
564         /**
565          * @mutex:
566          *
567          * This provides a read lock for the overall crtc state (mode, dpms
568          * state, ...) and a write lock for everything which can be update
569          * without a full modeset (fb, cursor data, crtc properties ...). Full
570          * modeset also need to grab dev->mode_config.connection_mutex.
571          */
572         struct drm_modeset_lock mutex;
573
574         struct drm_mode_object base;
575
576         /* primary and cursor planes for CRTC */
577         struct drm_plane *primary;
578         struct drm_plane *cursor;
579
580         /**
581          * @index: Position inside the mode_config.list, can be used as an array
582          * index. It is invariant over the lifetime of the CRTC.
583          */
584         unsigned index;
585
586         /* position of cursor plane on crtc */
587         int cursor_x;
588         int cursor_y;
589
590         bool enabled;
591
592         /* Requested mode from modesetting. */
593         struct drm_display_mode mode;
594
595         /* Programmed mode in hw, after adjustments for encoders,
596          * crtc, panel scaling etc. Needed for timestamping etc.
597          */
598         struct drm_display_mode hwmode;
599
600         int x, y;
601         const struct drm_crtc_funcs *funcs;
602
603         /* Legacy FB CRTC gamma size for reporting to userspace */
604         uint32_t gamma_size;
605         uint16_t *gamma_store;
606
607         /* if you are using the helper */
608         const struct drm_crtc_helper_funcs *helper_private;
609
610         struct drm_object_properties properties;
611
612         /**
613          * @state:
614          *
615          * Current atomic state for this CRTC.
616          */
617         struct drm_crtc_state *state;
618
619         /**
620          * @commit_list:
621          *
622          * List of &drm_crtc_commit structures tracking pending commits.
623          * Protected by @commit_lock. This list doesn't hold its own full
624          * reference, but burrows it from the ongoing commit. Commit entries
625          * must be removed from this list once the commit is fully completed,
626          * but before it's correspoding &drm_atomic_state gets destroyed.
627          */
628         struct list_head commit_list;
629
630         /**
631          * @commit_lock:
632          *
633          * Spinlock to protect @commit_list.
634          */
635         spinlock_t commit_lock;
636
637         /**
638          * @acquire_ctx:
639          *
640          * Per-CRTC implicit acquire context used by atomic drivers for legacy
641          * IOCTLs, so that atomic drivers can get at the locking acquire
642          * context.
643          */
644         struct drm_modeset_acquire_ctx *acquire_ctx;
645 };
646
647 /**
648  * struct drm_mode_set - new values for a CRTC config change
649  * @fb: framebuffer to use for new config
650  * @crtc: CRTC whose configuration we're about to change
651  * @mode: mode timings to use
652  * @x: position of this CRTC relative to @fb
653  * @y: position of this CRTC relative to @fb
654  * @connectors: array of connectors to drive with this CRTC if possible
655  * @num_connectors: size of @connectors array
656  *
657  * Represents a single crtc the connectors that it drives with what mode
658  * and from which framebuffer it scans out from.
659  *
660  * This is used to set modes.
661  */
662 struct drm_mode_set {
663         struct drm_framebuffer *fb;
664         struct drm_crtc *crtc;
665         struct drm_display_mode *mode;
666
667         uint32_t x;
668         uint32_t y;
669
670         struct drm_connector **connectors;
671         size_t num_connectors;
672 };
673
674 /**
675  * struct drm_mode_config_funcs - basic driver provided mode setting functions
676  *
677  * Some global (i.e. not per-CRTC, connector, etc) mode setting functions that
678  * involve drivers.
679  */
680 struct drm_mode_config_funcs {
681         /**
682          * @fb_create:
683          *
684          * Create a new framebuffer object. The core does basic checks on the
685          * requested metadata, but most of that is left to the driver. See
686          * struct &drm_mode_fb_cmd2 for details.
687          *
688          * If the parameters are deemed valid and the backing storage objects in
689          * the underlying memory manager all exist, then the driver allocates
690          * a new &drm_framebuffer structure, subclassed to contain
691          * driver-specific information (like the internal native buffer object
692          * references). It also needs to fill out all relevant metadata, which
693          * should be done by calling drm_helper_mode_fill_fb_struct().
694          *
695          * The initialization is finalized by calling drm_framebuffer_init(),
696          * which registers the framebuffer and makes it accessible to other
697          * threads.
698          *
699          * RETURNS:
700          *
701          * A new framebuffer with an initial reference count of 1 or a negative
702          * error code encoded with ERR_PTR().
703          */
704         struct drm_framebuffer *(*fb_create)(struct drm_device *dev,
705                                              struct drm_file *file_priv,
706                                              const struct drm_mode_fb_cmd2 *mode_cmd);
707
708         /**
709          * @output_poll_changed:
710          *
711          * Callback used by helpers to inform the driver of output configuration
712          * changes.
713          *
714          * Drivers implementing fbdev emulation with the helpers can call
715          * drm_fb_helper_hotplug_changed from this hook to inform the fbdev
716          * helper of output changes.
717          *
718          * FIXME:
719          *
720          * Except that there's no vtable for device-level helper callbacks
721          * there's no reason this is a core function.
722          */
723         void (*output_poll_changed)(struct drm_device *dev);
724
725         /**
726          * @atomic_check:
727          *
728          * This is the only hook to validate an atomic modeset update. This
729          * function must reject any modeset and state changes which the hardware
730          * or driver doesn't support. This includes but is of course not limited
731          * to:
732          *
733          *  - Checking that the modes, framebuffers, scaling and placement
734          *    requirements and so on are within the limits of the hardware.
735          *
736          *  - Checking that any hidden shared resources are not oversubscribed.
737          *    This can be shared PLLs, shared lanes, overall memory bandwidth,
738          *    display fifo space (where shared between planes or maybe even
739          *    CRTCs).
740          *
741          *  - Checking that virtualized resources exported to userspace are not
742          *    oversubscribed. For various reasons it can make sense to expose
743          *    more planes, crtcs or encoders than which are physically there. One
744          *    example is dual-pipe operations (which generally should be hidden
745          *    from userspace if when lockstepped in hardware, exposed otherwise),
746          *    where a plane might need 1 hardware plane (if it's just on one
747          *    pipe), 2 hardware planes (when it spans both pipes) or maybe even
748          *    shared a hardware plane with a 2nd plane (if there's a compatible
749          *    plane requested on the area handled by the other pipe).
750          *
751          *  - Check that any transitional state is possible and that if
752          *    requested, the update can indeed be done in the vblank period
753          *    without temporarily disabling some functions.
754          *
755          *  - Check any other constraints the driver or hardware might have.
756          *
757          *  - This callback also needs to correctly fill out the &drm_crtc_state
758          *    in this update to make sure that drm_atomic_crtc_needs_modeset()
759          *    reflects the nature of the possible update and returns true if and
760          *    only if the update cannot be applied without tearing within one
761          *    vblank on that CRTC. The core uses that information to reject
762          *    updates which require a full modeset (i.e. blanking the screen, or
763          *    at least pausing updates for a substantial amount of time) if
764          *    userspace has disallowed that in its request.
765          *
766          *  - The driver also does not need to repeat basic input validation
767          *    like done for the corresponding legacy entry points. The core does
768          *    that before calling this hook.
769          *
770          * See the documentation of @atomic_commit for an exhaustive list of
771          * error conditions which don't have to be checked at the
772          * ->atomic_check() stage?
773          *
774          * See the documentation for struct &drm_atomic_state for how exactly
775          * an atomic modeset update is described.
776          *
777          * Drivers using the atomic helpers can implement this hook using
778          * drm_atomic_helper_check(), or one of the exported sub-functions of
779          * it.
780          *
781          * RETURNS:
782          *
783          * 0 on success or one of the below negative error codes:
784          *
785          *  - -EINVAL, if any of the above constraints are violated.
786          *
787          *  - -EDEADLK, when returned from an attempt to acquire an additional
788          *    &drm_modeset_lock through drm_modeset_lock().
789          *
790          *  - -ENOMEM, if allocating additional state sub-structures failed due
791          *    to lack of memory.
792          *
793          *  - -EINTR, -EAGAIN or -ERESTARTSYS, if the IOCTL should be restarted.
794          *    This can either be due to a pending signal, or because the driver
795          *    needs to completely bail out to recover from an exceptional
796          *    situation like a GPU hang. From a userspace point all errors are
797          *    treated equally.
798          */
799         int (*atomic_check)(struct drm_device *dev,
800                             struct drm_atomic_state *state);
801
802         /**
803          * @atomic_commit:
804          *
805          * This is the only hook to commit an atomic modeset update. The core
806          * guarantees that @atomic_check has been called successfully before
807          * calling this function, and that nothing has been changed in the
808          * interim.
809          *
810          * See the documentation for struct &drm_atomic_state for how exactly
811          * an atomic modeset update is described.
812          *
813          * Drivers using the atomic helpers can implement this hook using
814          * drm_atomic_helper_commit(), or one of the exported sub-functions of
815          * it.
816          *
817          * Nonblocking commits (as indicated with the nonblock parameter) must
818          * do any preparatory work which might result in an unsuccessful commit
819          * in the context of this callback. The only exceptions are hardware
820          * errors resulting in -EIO. But even in that case the driver must
821          * ensure that the display pipe is at least running, to avoid
822          * compositors crashing when pageflips don't work. Anything else,
823          * specifically committing the update to the hardware, should be done
824          * without blocking the caller. For updates which do not require a
825          * modeset this must be guaranteed.
826          *
827          * The driver must wait for any pending rendering to the new
828          * framebuffers to complete before executing the flip. It should also
829          * wait for any pending rendering from other drivers if the underlying
830          * buffer is a shared dma-buf. Nonblocking commits must not wait for
831          * rendering in the context of this callback.
832          *
833          * An application can request to be notified when the atomic commit has
834          * completed. These events are per-CRTC and can be distinguished by the
835          * CRTC index supplied in &drm_event to userspace.
836          *
837          * The drm core will supply a struct &drm_event in the event
838          * member of each CRTC's &drm_crtc_state structure. This can be handled by the
839          * drm_crtc_send_vblank_event() function, which the driver should call on
840          * the provided event upon completion of the atomic commit. Note that if
841          * the driver supports vblank signalling and timestamping the vblank
842          * counters and timestamps must agree with the ones returned from page
843          * flip events. With the current vblank helper infrastructure this can
844          * be achieved by holding a vblank reference while the page flip is
845          * pending, acquired through drm_crtc_vblank_get() and released with
846          * drm_crtc_vblank_put(). Drivers are free to implement their own vblank
847          * counter and timestamp tracking though, e.g. if they have accurate
848          * timestamp registers in hardware.
849          *
850          * NOTE:
851          *
852          * Drivers are not allowed to shut down any display pipe successfully
853          * enabled through an atomic commit on their own. Doing so can result in
854          * compositors crashing if a page flip is suddenly rejected because the
855          * pipe is off.
856          *
857          * RETURNS:
858          *
859          * 0 on success or one of the below negative error codes:
860          *
861          *  - -EBUSY, if a nonblocking updated is requested and there is
862          *    an earlier updated pending. Drivers are allowed to support a queue
863          *    of outstanding updates, but currently no driver supports that.
864          *    Note that drivers must wait for preceding updates to complete if a
865          *    synchronous update is requested, they are not allowed to fail the
866          *    commit in that case.
867          *
868          *  - -ENOMEM, if the driver failed to allocate memory. Specifically
869          *    this can happen when trying to pin framebuffers, which must only
870          *    be done when committing the state.
871          *
872          *  - -ENOSPC, as a refinement of the more generic -ENOMEM to indicate
873          *    that the driver has run out of vram, iommu space or similar GPU
874          *    address space needed for framebuffer.
875          *
876          *  - -EIO, if the hardware completely died.
877          *
878          *  - -EINTR, -EAGAIN or -ERESTARTSYS, if the IOCTL should be restarted.
879          *    This can either be due to a pending signal, or because the driver
880          *    needs to completely bail out to recover from an exceptional
881          *    situation like a GPU hang. From a userspace point of view all errors are
882          *    treated equally.
883          *
884          * This list is exhaustive. Specifically this hook is not allowed to
885          * return -EINVAL (any invalid requests should be caught in
886          * @atomic_check) or -EDEADLK (this function must not acquire
887          * additional modeset locks).
888          */
889         int (*atomic_commit)(struct drm_device *dev,
890                              struct drm_atomic_state *state,
891                              bool nonblock);
892
893         /**
894          * @atomic_state_alloc:
895          *
896          * This optional hook can be used by drivers that want to subclass struct
897          * &drm_atomic_state to be able to track their own driver-private global
898          * state easily. If this hook is implemented, drivers must also
899          * implement @atomic_state_clear and @atomic_state_free.
900          *
901          * RETURNS:
902          *
903          * A new &drm_atomic_state on success or NULL on failure.
904          */
905         struct drm_atomic_state *(*atomic_state_alloc)(struct drm_device *dev);
906
907         /**
908          * @atomic_state_clear:
909          *
910          * This hook must clear any driver private state duplicated into the
911          * passed-in &drm_atomic_state. This hook is called when the caller
912          * encountered a &drm_modeset_lock deadlock and needs to drop all
913          * already acquired locks as part of the deadlock avoidance dance
914          * implemented in drm_modeset_lock_backoff().
915          *
916          * Any duplicated state must be invalidated since a concurrent atomic
917          * update might change it, and the drm atomic interfaces always apply
918          * updates as relative changes to the current state.
919          *
920          * Drivers that implement this must call drm_atomic_state_default_clear()
921          * to clear common state.
922          */
923         void (*atomic_state_clear)(struct drm_atomic_state *state);
924
925         /**
926          * @atomic_state_free:
927          *
928          * This hook needs driver private resources and the &drm_atomic_state
929          * itself. Note that the core first calls drm_atomic_state_clear() to
930          * avoid code duplicate between the clear and free hooks.
931          *
932          * Drivers that implement this must call drm_atomic_state_default_free()
933          * to release common resources.
934          */
935         void (*atomic_state_free)(struct drm_atomic_state *state);
936 };
937
938 /**
939  * struct drm_mode_config - Mode configuration control structure
940  * @mutex: mutex protecting KMS related lists and structures
941  * @connection_mutex: ww mutex protecting connector state and routing
942  * @acquire_ctx: global implicit acquire context used by atomic drivers for
943  *      legacy IOCTLs
944  * @fb_lock: mutex to protect fb state and lists
945  * @num_fb: number of fbs available
946  * @fb_list: list of framebuffers available
947  * @num_encoder: number of encoders on this device
948  * @encoder_list: list of encoder objects
949  * @num_overlay_plane: number of overlay planes on this device
950  * @num_total_plane: number of universal (i.e. with primary/curso) planes on this device
951  * @plane_list: list of plane objects
952  * @num_crtc: number of CRTCs on this device
953  * @crtc_list: list of CRTC objects
954  * @property_list: list of property objects
955  * @min_width: minimum pixel width on this device
956  * @min_height: minimum pixel height on this device
957  * @max_width: maximum pixel width on this device
958  * @max_height: maximum pixel height on this device
959  * @funcs: core driver provided mode setting functions
960  * @fb_base: base address of the framebuffer
961  * @poll_enabled: track polling support for this device
962  * @poll_running: track polling status for this device
963  * @delayed_event: track delayed poll uevent deliver for this device
964  * @output_poll_work: delayed work for polling in process context
965  * @property_blob_list: list of all the blob property objects
966  * @blob_lock: mutex for blob property allocation and management
967  * @*_property: core property tracking
968  * @preferred_depth: preferred RBG pixel depth, used by fb helpers
969  * @prefer_shadow: hint to userspace to prefer shadow-fb rendering
970  * @cursor_width: hint to userspace for max cursor width
971  * @cursor_height: hint to userspace for max cursor height
972  * @helper_private: mid-layer private data
973  *
974  * Core mode resource tracking structure.  All CRTC, encoders, and connectors
975  * enumerated by the driver are added here, as are global properties.  Some
976  * global restrictions are also here, e.g. dimension restrictions.
977  */
978 struct drm_mode_config {
979         struct mutex mutex; /* protects configuration (mode lists etc.) */
980         struct drm_modeset_lock connection_mutex; /* protects connector->encoder and encoder->crtc links */
981         struct drm_modeset_acquire_ctx *acquire_ctx; /* for legacy _lock_all() / _unlock_all() */
982
983         /**
984          * @idr_mutex:
985          *
986          * Mutex for KMS ID allocation and management. Protects both @crtc_idr
987          * and @tile_idr.
988          */
989         struct mutex idr_mutex;
990
991         /**
992          * @crtc_idr:
993          *
994          * Main KMS ID tracking object. Use this idr for all IDs, fb, crtc,
995          * connector, modes - just makes life easier to have only one.
996          */
997         struct idr crtc_idr;
998
999         /**
1000          * @tile_idr:
1001          *
1002          * Use this idr for allocating new IDs for tiled sinks like use in some
1003          * high-res DP MST screens.
1004          */
1005         struct idr tile_idr;
1006
1007         struct mutex fb_lock; /* proctects global and per-file fb lists */
1008         int num_fb;
1009         struct list_head fb_list;
1010
1011         /**
1012          * @num_connector: Number of connectors on this device.
1013          */
1014         int num_connector;
1015         /**
1016          * @connector_ida: ID allocator for connector indices.
1017          */
1018         struct ida connector_ida;
1019         /**
1020          * @connector_list: List of connector objects.
1021          */
1022         struct list_head connector_list;
1023         int num_encoder;
1024         struct list_head encoder_list;
1025
1026         /*
1027          * Track # of overlay planes separately from # of total planes.  By
1028          * default we only advertise overlay planes to userspace; if userspace
1029          * sets the "universal plane" capability bit, we'll go ahead and
1030          * expose all planes.
1031          */
1032         int num_overlay_plane;
1033         int num_total_plane;
1034         struct list_head plane_list;
1035
1036         int num_crtc;
1037         struct list_head crtc_list;
1038
1039         struct list_head property_list;
1040
1041         int min_width, min_height;
1042         int max_width, max_height;
1043         const struct drm_mode_config_funcs *funcs;
1044         resource_size_t fb_base;
1045
1046         /* output poll support */
1047         bool poll_enabled;
1048         bool poll_running;
1049         bool delayed_event;
1050         struct delayed_work output_poll_work;
1051
1052         struct mutex blob_lock;
1053
1054         /* pointers to standard properties */
1055         struct list_head property_blob_list;
1056         /**
1057          * @edid_property: Default connector property to hold the EDID of the
1058          * currently connected sink, if any.
1059          */
1060         struct drm_property *edid_property;
1061         /**
1062          * @dpms_property: Default connector property to control the
1063          * connector's DPMS state.
1064          */
1065         struct drm_property *dpms_property;
1066         /**
1067          * @path_property: Default connector property to hold the DP MST path
1068          * for the port.
1069          */
1070         struct drm_property *path_property;
1071         /**
1072          * @tile_property: Default connector property to store the tile
1073          * position of a tiled screen, for sinks which need to be driven with
1074          * multiple CRTCs.
1075          */
1076         struct drm_property *tile_property;
1077         /**
1078          * @plane_type_property: Default plane property to differentiate
1079          * CURSOR, PRIMARY and OVERLAY legacy uses of planes.
1080          */
1081         struct drm_property *plane_type_property;
1082         /**
1083          * @rotation_property: Optional property for planes or CRTCs to specifiy
1084          * rotation.
1085          */
1086         struct drm_property *rotation_property;
1087         /**
1088          * @prop_src_x: Default atomic plane property for the plane source
1089          * position in the connected &drm_framebuffer.
1090          */
1091         struct drm_property *prop_src_x;
1092         /**
1093          * @prop_src_y: Default atomic plane property for the plane source
1094          * position in the connected &drm_framebuffer.
1095          */
1096         struct drm_property *prop_src_y;
1097         /**
1098          * @prop_src_w: Default atomic plane property for the plane source
1099          * position in the connected &drm_framebuffer.
1100          */
1101         struct drm_property *prop_src_w;
1102         /**
1103          * @prop_src_h: Default atomic plane property for the plane source
1104          * position in the connected &drm_framebuffer.
1105          */
1106         struct drm_property *prop_src_h;
1107         /**
1108          * @prop_crtc_x: Default atomic plane property for the plane destination
1109          * position in the &drm_crtc is is being shown on.
1110          */
1111         struct drm_property *prop_crtc_x;
1112         /**
1113          * @prop_crtc_y: Default atomic plane property for the plane destination
1114          * position in the &drm_crtc is is being shown on.
1115          */
1116         struct drm_property *prop_crtc_y;
1117         /**
1118          * @prop_crtc_w: Default atomic plane property for the plane destination
1119          * position in the &drm_crtc is is being shown on.
1120          */
1121         struct drm_property *prop_crtc_w;
1122         /**
1123          * @prop_crtc_h: Default atomic plane property for the plane destination
1124          * position in the &drm_crtc is is being shown on.
1125          */
1126         struct drm_property *prop_crtc_h;
1127         /**
1128          * @prop_fb_id: Default atomic plane property to specify the
1129          * &drm_framebuffer.
1130          */
1131         struct drm_property *prop_fb_id;
1132         /**
1133          * @prop_crtc_id: Default atomic plane property to specify the
1134          * &drm_crtc.
1135          */
1136         struct drm_property *prop_crtc_id;
1137         /**
1138          * @prop_active: Default atomic CRTC property to control the active
1139          * state, which is the simplified implementation for DPMS in atomic
1140          * drivers.
1141          */
1142         struct drm_property *prop_active;
1143         /**
1144          * @prop_mode_id: Default atomic CRTC property to set the mode for a
1145          * CRTC. A 0 mode implies that the CRTC is entirely disabled - all
1146          * connectors must be of and active must be set to disabled, too.
1147          */
1148         struct drm_property *prop_mode_id;
1149
1150         /**
1151          * @dvi_i_subconnector_property: Optional DVI-I property to
1152          * differentiate between analog or digital mode.
1153          */
1154         struct drm_property *dvi_i_subconnector_property;
1155         /**
1156          * @dvi_i_select_subconnector_property: Optional DVI-I property to
1157          * select between analog or digital mode.
1158          */
1159         struct drm_property *dvi_i_select_subconnector_property;
1160
1161         /**
1162          * @tv_subconnector_property: Optional TV property to differentiate
1163          * between different TV connector types.
1164          */
1165         struct drm_property *tv_subconnector_property;
1166         /**
1167          * @tv_select_subconnector_property: Optional TV property to select
1168          * between different TV connector types.
1169          */
1170         struct drm_property *tv_select_subconnector_property;
1171         /**
1172          * @tv_mode_property: Optional TV property to select
1173          * the output TV mode.
1174          */
1175         struct drm_property *tv_mode_property;
1176         /**
1177          * @tv_left_margin_property: Optional TV property to set the left
1178          * margin.
1179          */
1180         struct drm_property *tv_left_margin_property;
1181         /**
1182          * @tv_right_margin_property: Optional TV property to set the right
1183          * margin.
1184          */
1185         struct drm_property *tv_right_margin_property;
1186         /**
1187          * @tv_top_margin_property: Optional TV property to set the right
1188          * margin.
1189          */
1190         struct drm_property *tv_top_margin_property;
1191         /**
1192          * @tv_bottom_margin_property: Optional TV property to set the right
1193          * margin.
1194          */
1195         struct drm_property *tv_bottom_margin_property;
1196         /**
1197          * @tv_brightness_property: Optional TV property to set the
1198          * brightness.
1199          */
1200         struct drm_property *tv_brightness_property;
1201         /**
1202          * @tv_contrast_property: Optional TV property to set the
1203          * contrast.
1204          */
1205         struct drm_property *tv_contrast_property;
1206         /**
1207          * @tv_flicker_reduction_property: Optional TV property to control the
1208          * flicker reduction mode.
1209          */
1210         struct drm_property *tv_flicker_reduction_property;
1211         /**
1212          * @tv_overscan_property: Optional TV property to control the overscan
1213          * setting.
1214          */
1215         struct drm_property *tv_overscan_property;
1216         /**
1217          * @tv_saturation_property: Optional TV property to set the
1218          * saturation.
1219          */
1220         struct drm_property *tv_saturation_property;
1221         /**
1222          * @tv_hue_property: Optional TV property to set the hue.
1223          */
1224         struct drm_property *tv_hue_property;
1225
1226         /**
1227          * @scaling_mode_property: Optional connector property to control the
1228          * upscaling, mostly used for built-in panels.
1229          */
1230         struct drm_property *scaling_mode_property;
1231         /**
1232          * @aspect_ratio_property: Optional connector property to control the
1233          * HDMI infoframe aspect ratio setting.
1234          */
1235         struct drm_property *aspect_ratio_property;
1236         /**
1237          * @degamma_lut_property: Optional CRTC property to set the LUT used to
1238          * convert the framebuffer's colors to linear gamma.
1239          */
1240         struct drm_property *degamma_lut_property;
1241         /**
1242          * @degamma_lut_size_property: Optional CRTC property for the size of
1243          * the degamma LUT as supported by the driver (read-only).
1244          */
1245         struct drm_property *degamma_lut_size_property;
1246         /**
1247          * @ctm_property: Optional CRTC property to set the
1248          * matrix used to convert colors after the lookup in the
1249          * degamma LUT.
1250          */
1251         struct drm_property *ctm_property;
1252         /**
1253          * @gamma_lut_property: Optional CRTC property to set the LUT used to
1254          * convert the colors, after the CTM matrix, to the gamma space of the
1255          * connected screen.
1256          */
1257         struct drm_property *gamma_lut_property;
1258         /**
1259          * @gamma_lut_size_property: Optional CRTC property for the size of the
1260          * gamma LUT as supported by the driver (read-only).
1261          */
1262         struct drm_property *gamma_lut_size_property;
1263
1264         /**
1265          * @suggested_x_property: Optional connector property with a hint for
1266          * the position of the output on the host's screen.
1267          */
1268         struct drm_property *suggested_x_property;
1269         /**
1270          * @suggested_y_property: Optional connector property with a hint for
1271          * the position of the output on the host's screen.
1272          */
1273         struct drm_property *suggested_y_property;
1274
1275         /* dumb ioctl parameters */
1276         uint32_t preferred_depth, prefer_shadow;
1277
1278         /**
1279          * @async_page_flip: Does this device support async flips on the primary
1280          * plane?
1281          */
1282         bool async_page_flip;
1283
1284         /**
1285          * @allow_fb_modifiers:
1286          *
1287          * Whether the driver supports fb modifiers in the ADDFB2.1 ioctl call.
1288          */
1289         bool allow_fb_modifiers;
1290
1291         /* cursor size */
1292         uint32_t cursor_width, cursor_height;
1293
1294         struct drm_mode_config_helper_funcs *helper_private;
1295 };
1296
1297 #define obj_to_crtc(x) container_of(x, struct drm_crtc, base)
1298
1299 extern __printf(6, 7)
1300 int drm_crtc_init_with_planes(struct drm_device *dev,
1301                               struct drm_crtc *crtc,
1302                               struct drm_plane *primary,
1303                               struct drm_plane *cursor,
1304                               const struct drm_crtc_funcs *funcs,
1305                               const char *name, ...);
1306 extern void drm_crtc_cleanup(struct drm_crtc *crtc);
1307
1308 /**
1309  * drm_crtc_index - find the index of a registered CRTC
1310  * @crtc: CRTC to find index for
1311  *
1312  * Given a registered CRTC, return the index of that CRTC within a DRM
1313  * device's list of CRTCs.
1314  */
1315 static inline unsigned int drm_crtc_index(struct drm_crtc *crtc)
1316 {
1317         return crtc->index;
1318 }
1319
1320 /**
1321  * drm_crtc_mask - find the mask of a registered CRTC
1322  * @crtc: CRTC to find mask for
1323  *
1324  * Given a registered CRTC, return the mask bit of that CRTC for an
1325  * encoder's possible_crtcs field.
1326  */
1327 static inline uint32_t drm_crtc_mask(struct drm_crtc *crtc)
1328 {
1329         return 1 << drm_crtc_index(crtc);
1330 }
1331
1332 extern void drm_crtc_get_hv_timing(const struct drm_display_mode *mode,
1333                                    int *hdisplay, int *vdisplay);
1334 extern int drm_crtc_force_disable(struct drm_crtc *crtc);
1335 extern int drm_crtc_force_disable_all(struct drm_device *dev);
1336
1337 extern void drm_mode_config_init(struct drm_device *dev);
1338 extern void drm_mode_config_reset(struct drm_device *dev);
1339 extern void drm_mode_config_cleanup(struct drm_device *dev);
1340
1341 extern int drm_mode_set_config_internal(struct drm_mode_set *set);
1342
1343 extern struct drm_tile_group *drm_mode_create_tile_group(struct drm_device *dev,
1344                                                          char topology[8]);
1345 extern struct drm_tile_group *drm_mode_get_tile_group(struct drm_device *dev,
1346                                                char topology[8]);
1347 extern void drm_mode_put_tile_group(struct drm_device *dev,
1348                                    struct drm_tile_group *tg);
1349
1350 /* Helpers */
1351 static inline struct drm_crtc *drm_crtc_find(struct drm_device *dev,
1352         uint32_t id)
1353 {
1354         struct drm_mode_object *mo;
1355         mo = drm_mode_object_find(dev, id, DRM_MODE_OBJECT_CRTC);
1356         return mo ? obj_to_crtc(mo) : NULL;
1357 }
1358
1359 #define drm_for_each_crtc(crtc, dev) \
1360         list_for_each_entry(crtc, &(dev)->mode_config.crtc_list, head)
1361
1362 static inline void
1363 assert_drm_connector_list_read_locked(struct drm_mode_config *mode_config)
1364 {
1365         /*
1366          * The connector hotadd/remove code currently grabs both locks when
1367          * updating lists. Hence readers need only hold either of them to be
1368          * safe and the check amounts to
1369          *
1370          * WARN_ON(not_holding(A) && not_holding(B)).
1371          */
1372         WARN_ON(!mutex_is_locked(&mode_config->mutex) &&
1373                 !drm_modeset_is_locked(&mode_config->connection_mutex));
1374 }
1375
1376 #endif /* __DRM_CRTC_H__ */