Revert "FROMLIST: drm: edid: HDMI 2.0 HF-VSDB block parsing"
[firefly-linux-kernel-4.4.55.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 /* rotation property bits */
89 #define DRM_ROTATE_MASK 0x0f
90 #define DRM_ROTATE_0    0
91 #define DRM_ROTATE_90   1
92 #define DRM_ROTATE_180  2
93 #define DRM_ROTATE_270  3
94 #define DRM_REFLECT_MASK (~DRM_ROTATE_MASK)
95 #define DRM_REFLECT_X   4
96 #define DRM_REFLECT_Y   5
97
98 enum drm_connector_force {
99         DRM_FORCE_UNSPECIFIED,
100         DRM_FORCE_OFF,
101         DRM_FORCE_ON,         /* force on analog part normally */
102         DRM_FORCE_ON_DIGITAL, /* for DVI-I use digital connector */
103 };
104
105 #include <drm/drm_modes.h>
106
107 enum drm_connector_status {
108         connector_status_connected = 1,
109         connector_status_disconnected = 2,
110         connector_status_unknown = 3,
111 };
112
113 enum subpixel_order {
114         SubPixelUnknown = 0,
115         SubPixelHorizontalRGB,
116         SubPixelHorizontalBGR,
117         SubPixelVerticalRGB,
118         SubPixelVerticalBGR,
119         SubPixelNone,
120
121 };
122
123 /**
124  * struct drm_scrambling: sink's scrambling support.
125  */
126 struct drm_scrambling {
127         /**
128          * @supported: scrambling supported for rates > 340 Mhz.
129          */
130         bool supported;
131         /**
132          * @low_rates: scrambling supported for rates <= 340 Mhz.
133          */
134         bool low_rates;
135 };
136
137 /*
138  * struct drm_scdc - Information about scdc capabilities of a HDMI 2.0 sink
139  *
140  * Provides SCDC register support and capabilities related information on a
141  * HDMI 2.0 sink. In case of a HDMI 1.4 sink, all parameter must be 0.
142  */
143 struct drm_scdc {
144         /**
145          * @supported: status control & data channel present.
146          */
147         bool supported;
148         /**
149          * @read_request: sink is capable of generating scdc read request.
150          */
151         bool read_request;
152         /**
153          * @scrambling: sink's scrambling capabilities
154          */
155         struct drm_scrambling scrambling;
156 };
157
158
159 /**
160  * struct drm_hdmi_info - runtime information about the connected HDMI sink
161  *
162  * Describes if a given display supports advanced HDMI 2.0 features.
163  * This information is available in CEA-861-F extension blocks (like HF-VSDB).
164  */
165 struct drm_hdmi_info {
166         struct drm_scdc scdc;
167 };
168
169 #define DRM_COLOR_FORMAT_RGB444         (1<<0)
170 #define DRM_COLOR_FORMAT_YCRCB444       (1<<1)
171 #define DRM_COLOR_FORMAT_YCRCB422       (1<<2)
172 /*
173  * Describes a given display (e.g. CRT or flat panel) and its limitations.
174  */
175 struct drm_display_info {
176         char name[DRM_DISPLAY_INFO_LEN];
177
178         /* Physical size */
179         unsigned int width_mm;
180         unsigned int height_mm;
181
182         /* Clock limits FIXME: storage format */
183         unsigned int min_vfreq, max_vfreq;
184         unsigned int min_hfreq, max_hfreq;
185         unsigned int pixel_clock;
186         unsigned int bpc;
187
188         enum subpixel_order subpixel_order;
189         u32 color_formats;
190
191         const u32 *bus_formats;
192         unsigned int num_bus_formats;
193
194         /**
195          * @max_tmds_clock: Maximum TMDS clock rate supported by the
196          * sink in kHz. 0 means undefined.
197          */
198         int max_tmds_clock;
199
200         /**
201          * @dvi_dual: Dual-link DVI sink?
202          */
203         bool dvi_dual;
204
205         /* Mask of supported hdmi deep color modes */
206         u8 edid_hdmi_dc_modes;
207
208         u8 cea_rev;
209
210         /**
211          * @hdmi: advance features of a HDMI sink.
212          */
213         struct drm_hdmi_info hdmi;
214 };
215
216 /* data corresponds to displayid vend/prod/serial */
217 struct drm_tile_group {
218         struct kref refcount;
219         struct drm_device *dev;
220         int id;
221         u8 group_data[8];
222 };
223
224 struct drm_framebuffer_funcs {
225         /* note: use drm_framebuffer_remove() */
226         void (*destroy)(struct drm_framebuffer *framebuffer);
227         int (*create_handle)(struct drm_framebuffer *fb,
228                              struct drm_file *file_priv,
229                              unsigned int *handle);
230         /*
231          * Optional callback for the dirty fb ioctl.
232          *
233          * Userspace can notify the driver via this callback
234          * that a area of the framebuffer has changed and should
235          * be flushed to the display hardware.
236          *
237          * See documentation in drm_mode.h for the struct
238          * drm_mode_fb_dirty_cmd for more information as all
239          * the semantics and arguments have a one to one mapping
240          * on this function.
241          */
242         int (*dirty)(struct drm_framebuffer *framebuffer,
243                      struct drm_file *file_priv, unsigned flags,
244                      unsigned color, struct drm_clip_rect *clips,
245                      unsigned num_clips);
246 };
247
248 struct drm_framebuffer {
249         struct drm_device *dev;
250         /*
251          * Note that the fb is refcounted for the benefit of driver internals,
252          * for example some hw, disabling a CRTC/plane is asynchronous, and
253          * scanout does not actually complete until the next vblank.  So some
254          * cleanup (like releasing the reference(s) on the backing GEM bo(s))
255          * should be deferred.  In cases like this, the driver would like to
256          * hold a ref to the fb even though it has already been removed from
257          * userspace perspective.
258          */
259         struct kref refcount;
260         /*
261          * Place on the dev->mode_config.fb_list, access protected by
262          * dev->mode_config.fb_lock.
263          */
264         struct list_head head;
265         struct drm_mode_object base;
266         const struct drm_framebuffer_funcs *funcs;
267         unsigned int pitches[4];
268         unsigned int offsets[4];
269         uint64_t modifier[4];
270         unsigned int width;
271         unsigned int height;
272         /* depth can be 15 or 16 */
273         unsigned int depth;
274         int bits_per_pixel;
275         int flags;
276         uint32_t pixel_format; /* fourcc format */
277         struct list_head filp_head;
278 };
279
280 struct drm_property_blob {
281         struct drm_mode_object base;
282         struct drm_device *dev;
283         struct kref refcount;
284         struct list_head head_global;
285         struct list_head head_file;
286         size_t length;
287         unsigned char data[];
288 };
289
290 struct drm_property_enum {
291         uint64_t value;
292         struct list_head head;
293         char name[DRM_PROP_NAME_LEN];
294 };
295
296 struct drm_property {
297         struct list_head head;
298         struct drm_mode_object base;
299         uint32_t flags;
300         char name[DRM_PROP_NAME_LEN];
301         uint32_t num_values;
302         uint64_t *values;
303         struct drm_device *dev;
304
305         struct list_head enum_list;
306 };
307
308 struct drm_crtc;
309 struct drm_connector;
310 struct drm_encoder;
311 struct drm_pending_vblank_event;
312 struct drm_plane;
313 struct drm_bridge;
314 struct drm_atomic_state;
315
316 /**
317  * struct drm_crtc_state - mutable CRTC state
318  * @crtc: backpointer to the CRTC
319  * @enable: whether the CRTC should be enabled, gates all other state
320  * @active: whether the CRTC is actively displaying (used for DPMS)
321  * @planes_changed: planes on this crtc are updated
322  * @mode_changed: crtc_state->mode or crtc_state->enable has been changed
323  * @active_changed: crtc_state->active has been toggled.
324  * @connectors_changed: connectors to this crtc have been updated
325  * @plane_mask: bitmask of (1 << drm_plane_index(plane)) of attached planes
326  * @last_vblank_count: for helpers and drivers to capture the vblank of the
327  *      update to ensure framebuffer cleanup isn't done too early
328  * @adjusted_mode: for use by helpers and drivers to compute adjusted mode timings
329  * @mode: current mode timings
330  * @event: optional pointer to a DRM event to signal upon completion of the
331  *      state update
332  * @state: backpointer to global drm_atomic_state
333  *
334  * Note that the distinction between @enable and @active is rather subtile:
335  * Flipping @active while @enable is set without changing anything else may
336  * never return in a failure from the ->atomic_check callback. Userspace assumes
337  * that a DPMS On will always succeed. In other words: @enable controls resource
338  * assignment, @active controls the actual hardware state.
339  */
340 struct drm_crtc_state {
341         struct drm_crtc *crtc;
342
343         bool enable;
344         bool active;
345
346         /* computed state bits used by helpers and drivers */
347         bool planes_changed : 1;
348         bool mode_changed : 1;
349         bool active_changed : 1;
350         bool connectors_changed : 1;
351
352         /* attached planes bitmask:
353          * WARNING: transitional helpers do not maintain plane_mask so
354          * drivers not converted over to atomic helpers should not rely
355          * on plane_mask being accurate!
356          */
357         u32 plane_mask;
358
359         /* last_vblank_count: for vblank waits before cleanup */
360         u32 last_vblank_count;
361
362         /* adjusted_mode: for use by helpers and drivers */
363         struct drm_display_mode adjusted_mode;
364
365         struct drm_display_mode mode;
366
367         /* blob property to expose current mode to atomic userspace */
368         struct drm_property_blob *mode_blob;
369
370         struct drm_pending_vblank_event *event;
371
372         struct drm_atomic_state *state;
373 };
374
375 /**
376  * struct drm_crtc_funcs - control CRTCs for a given device
377  * @save: save CRTC state
378  * @restore: restore CRTC state
379  * @reset: reset CRTC after state has been invalidated (e.g. resume)
380  * @cursor_set: setup the cursor
381  * @cursor_set2: setup the cursor with hotspot, superseeds @cursor_set if set
382  * @cursor_move: move the cursor
383  * @gamma_set: specify color ramp for CRTC
384  * @destroy: deinit and free object
385  * @set_property: called when a property is changed
386  * @set_config: apply a new CRTC configuration
387  * @page_flip: initiate a page flip
388  * @atomic_duplicate_state: duplicate the atomic state for this CRTC
389  * @atomic_destroy_state: destroy an atomic state for this CRTC
390  * @atomic_set_property: set a property on an atomic state for this CRTC
391  *    (do not call directly, use drm_atomic_crtc_set_property())
392  * @atomic_get_property: get a property on an atomic state for this CRTC
393  *    (do not call directly, use drm_atomic_crtc_get_property())
394  *
395  * The drm_crtc_funcs structure is the central CRTC management structure
396  * in the DRM.  Each CRTC controls one or more connectors (note that the name
397  * CRTC is simply historical, a CRTC may control LVDS, VGA, DVI, TV out, etc.
398  * connectors, not just CRTs).
399  *
400  * Each driver is responsible for filling out this structure at startup time,
401  * in addition to providing other modesetting features, like i2c and DDC
402  * bus accessors.
403  */
404 struct drm_crtc_funcs {
405         /* Save CRTC state */
406         void (*save)(struct drm_crtc *crtc); /* suspend? */
407         /* Restore CRTC state */
408         void (*restore)(struct drm_crtc *crtc); /* resume? */
409         /* Reset CRTC state */
410         void (*reset)(struct drm_crtc *crtc);
411
412         /* cursor controls */
413         int (*cursor_set)(struct drm_crtc *crtc, struct drm_file *file_priv,
414                           uint32_t handle, uint32_t width, uint32_t height);
415         int (*cursor_set2)(struct drm_crtc *crtc, struct drm_file *file_priv,
416                            uint32_t handle, uint32_t width, uint32_t height,
417                            int32_t hot_x, int32_t hot_y);
418         int (*cursor_move)(struct drm_crtc *crtc, int x, int y);
419
420         /* Set gamma on the CRTC */
421         void (*gamma_set)(struct drm_crtc *crtc, u16 *r, u16 *g, u16 *b,
422                           uint32_t start, uint32_t size);
423         /* Object destroy routine */
424         void (*destroy)(struct drm_crtc *crtc);
425
426         int (*set_config)(struct drm_mode_set *set);
427
428         /*
429          * Flip to the given framebuffer.  This implements the page
430          * flip ioctl described in drm_mode.h, specifically, the
431          * implementation must return immediately and block all
432          * rendering to the current fb until the flip has completed.
433          * If userspace set the event flag in the ioctl, the event
434          * argument will point to an event to send back when the flip
435          * completes, otherwise it will be NULL.
436          */
437         int (*page_flip)(struct drm_crtc *crtc,
438                          struct drm_framebuffer *fb,
439                          struct drm_pending_vblank_event *event,
440                          uint32_t flags);
441
442         int (*set_property)(struct drm_crtc *crtc,
443                             struct drm_property *property, uint64_t val);
444
445         /* atomic update handling */
446         struct drm_crtc_state *(*atomic_duplicate_state)(struct drm_crtc *crtc);
447         void (*atomic_destroy_state)(struct drm_crtc *crtc,
448                                      struct drm_crtc_state *state);
449         int (*atomic_set_property)(struct drm_crtc *crtc,
450                                    struct drm_crtc_state *state,
451                                    struct drm_property *property,
452                                    uint64_t val);
453         int (*atomic_get_property)(struct drm_crtc *crtc,
454                                    const struct drm_crtc_state *state,
455                                    struct drm_property *property,
456                                    uint64_t *val);
457
458         /**
459          * @late_register:
460          *
461          * This optional hook can be used to register additional userspace
462          * interfaces attached to the crtc like debugfs interfaces.
463          * It is called late in the driver load sequence from drm_dev_register().
464          * Everything added from this callback should be unregistered in
465          * the early_unregister callback.
466          *
467          * Returns:
468          *
469          * 0 on success, or a negative error code on failure.
470          */
471         int (*late_register)(struct drm_crtc *crtc);
472
473         /**
474          * @early_unregister:
475          *
476          * This optional hook should be used to unregister the additional
477          * userspace interfaces attached to the crtc from
478          * late_unregister(). It is called from drm_dev_unregister(),
479          * early in the driver unload sequence to disable userspace access
480          * before data structures are torndown.
481          */
482         void (*early_unregister)(struct drm_crtc *crtc);
483 };
484
485 /**
486  * struct drm_crtc - central CRTC control structure
487  * @dev: parent DRM device
488  * @port: OF node used by drm_of_find_possible_crtcs()
489  * @head: list management
490  * @mutex: per-CRTC locking
491  * @base: base KMS object for ID tracking etc.
492  * @primary: primary plane for this CRTC
493  * @cursor: cursor plane for this CRTC
494  * @cursor_x: current x position of the cursor, used for universal cursor planes
495  * @cursor_y: current y position of the cursor, used for universal cursor planes
496  * @enabled: is this CRTC enabled?
497  * @mode: current mode timings
498  * @hwmode: mode timings as programmed to hw regs
499  * @x: x position on screen
500  * @y: y position on screen
501  * @funcs: CRTC control functions
502  * @gamma_size: size of gamma ramp
503  * @gamma_store: gamma ramp values
504  * @helper_private: mid-layer private data
505  * @properties: property tracking for this CRTC
506  * @state: current atomic state for this CRTC
507  * @acquire_ctx: per-CRTC implicit acquire context used by atomic drivers for
508  *      legacy ioctls
509  *
510  * Each CRTC may have one or more connectors associated with it.  This structure
511  * allows the CRTC to be controlled.
512  */
513 struct drm_crtc {
514         struct drm_device *dev;
515         struct device_node *port;
516         struct list_head head;
517
518         /*
519          * crtc mutex
520          *
521          * This provides a read lock for the overall crtc state (mode, dpms
522          * state, ...) and a write lock for everything which can be update
523          * without a full modeset (fb, cursor data, ...)
524          */
525         struct drm_modeset_lock mutex;
526
527         struct drm_mode_object base;
528
529         /* primary and cursor planes for CRTC */
530         struct drm_plane *primary;
531         struct drm_plane *cursor;
532
533         /* position of cursor plane on crtc */
534         int cursor_x;
535         int cursor_y;
536
537         bool enabled;
538
539         /* Requested mode from modesetting. */
540         struct drm_display_mode mode;
541
542         /* Programmed mode in hw, after adjustments for encoders,
543          * crtc, panel scaling etc. Needed for timestamping etc.
544          */
545         struct drm_display_mode hwmode;
546
547         int x, y;
548         const struct drm_crtc_funcs *funcs;
549
550         /* CRTC gamma size for reporting to userspace */
551         uint32_t gamma_size;
552         uint16_t *gamma_store;
553
554         /* if you are using the helper */
555         const void *helper_private;
556
557         struct drm_object_properties properties;
558
559         struct drm_crtc_state *state;
560
561         /*
562          * For legacy crtc ioctls so that atomic drivers can get at the locking
563          * acquire context.
564          */
565         struct drm_modeset_acquire_ctx *acquire_ctx;
566 };
567
568 /**
569  * struct drm_connector_state - mutable connector state
570  * @connector: backpointer to the connector
571  * @crtc: CRTC to connect connector to, NULL if disabled
572  * @best_encoder: can be used by helpers and drivers to select the encoder
573  * @state: backpointer to global drm_atomic_state
574  */
575 struct drm_connector_state {
576         struct drm_connector *connector;
577
578         struct drm_crtc *crtc;  /* do not write directly, use drm_atomic_set_crtc_for_connector() */
579
580         struct drm_encoder *best_encoder;
581
582         struct drm_atomic_state *state;
583 };
584
585 /**
586  * struct drm_connector_funcs - control connectors on a given device
587  * @dpms: set power state
588  * @save: save connector state
589  * @restore: restore connector state
590  * @reset: reset connector after state has been invalidated (e.g. resume)
591  * @detect: is this connector active?
592  * @fill_modes: fill mode list for this connector
593  * @set_property: property for this connector may need an update
594  * @destroy: make object go away
595  * @force: notify the driver that the connector is forced on
596  * @atomic_duplicate_state: duplicate the atomic state for this connector
597  * @atomic_destroy_state: destroy an atomic state for this connector
598  * @atomic_set_property: set a property on an atomic state for this connector
599  *    (do not call directly, use drm_atomic_connector_set_property())
600  * @atomic_get_property: get a property on an atomic state for this connector
601  *    (do not call directly, use drm_atomic_connector_get_property())
602  *
603  * Each CRTC may have one or more connectors attached to it.  The functions
604  * below allow the core DRM code to control connectors, enumerate available modes,
605  * etc.
606  */
607 struct drm_connector_funcs {
608         int (*dpms)(struct drm_connector *connector, int mode);
609         void (*save)(struct drm_connector *connector);
610         void (*restore)(struct drm_connector *connector);
611         void (*reset)(struct drm_connector *connector);
612
613         /* Check to see if anything is attached to the connector.
614          * @force is set to false whilst polling, true when checking the
615          * connector due to user request. @force can be used by the driver
616          * to avoid expensive, destructive operations during automated
617          * probing.
618          */
619         enum drm_connector_status (*detect)(struct drm_connector *connector,
620                                             bool force);
621         int (*fill_modes)(struct drm_connector *connector, uint32_t max_width, uint32_t max_height);
622         int (*set_property)(struct drm_connector *connector, struct drm_property *property,
623                              uint64_t val);
624
625         /**
626          * @late_register:
627          *
628          * This optional hook can be used to register additional userspace
629          * interfaces attached to the connector, light backlight control, i2c,
630          * DP aux or similar interfaces. It is called late in the driver load
631          * sequence from drm_connector_register() when registering all the
632          * core drm connector interfaces. Everything added from this callback
633          * should be unregistered in the early_unregister callback.
634          *
635          * Returns:
636          *
637          * 0 on success, or a negative error code on failure.
638          */
639         int (*late_register)(struct drm_connector *connector);
640
641         /**
642          * @early_unregister:
643          *
644          * This optional hook should be used to unregister the additional
645          * userspace interfaces attached to the connector from
646          * late_unregister(). It is called from drm_connector_unregister(),
647          * early in the driver unload sequence to disable userspace access
648          * before data structures are torndown.
649          */
650         void (*early_unregister)(struct drm_connector *connector);
651
652         void (*destroy)(struct drm_connector *connector);
653         void (*force)(struct drm_connector *connector);
654
655         /* atomic update handling */
656         struct drm_connector_state *(*atomic_duplicate_state)(struct drm_connector *connector);
657         void (*atomic_destroy_state)(struct drm_connector *connector,
658                                      struct drm_connector_state *state);
659         int (*atomic_set_property)(struct drm_connector *connector,
660                                    struct drm_connector_state *state,
661                                    struct drm_property *property,
662                                    uint64_t val);
663         int (*atomic_get_property)(struct drm_connector *connector,
664                                    const struct drm_connector_state *state,
665                                    struct drm_property *property,
666                                    uint64_t *val);
667 };
668
669 /**
670  * struct drm_encoder_funcs - encoder controls
671  * @reset: reset state (e.g. at init or resume time)
672  * @destroy: cleanup and free associated data
673  *
674  * Encoders sit between CRTCs and connectors.
675  */
676 struct drm_encoder_funcs {
677         void (*reset)(struct drm_encoder *encoder);
678         void (*destroy)(struct drm_encoder *encoder);
679
680         /**
681          * @late_register:
682          *
683          * This optional hook can be used to register additional userspace
684          * interfaces attached to the encoder like debugfs interfaces.
685          * It is called late in the driver load sequence from drm_dev_register().
686          * Everything added from this callback should be unregistered in
687          * the early_unregister callback.
688          *
689          * Returns:
690          *
691          * 0 on success, or a negative error code on failure.
692          */
693         int (*late_register)(struct drm_encoder *encoder);
694
695         /**
696          * @early_unregister:
697          *
698          * This optional hook should be used to unregister the additional
699          * userspace interfaces attached to the encoder from
700          * late_unregister(). It is called from drm_dev_unregister(),
701          * early in the driver unload sequence to disable userspace access
702          * before data structures are torndown.
703          */
704         void (*early_unregister)(struct drm_encoder *encoder);
705 };
706
707 #define DRM_CONNECTOR_MAX_ENCODER 3
708
709 /**
710  * struct drm_encoder - central DRM encoder structure
711  * @dev: parent DRM device
712  * @head: list management
713  * @base: base KMS object
714  * @name: encoder name
715  * @encoder_type: one of the %DRM_MODE_ENCODER_<foo> types in drm_mode.h
716  * @possible_crtcs: bitmask of potential CRTC bindings
717  * @possible_clones: bitmask of potential sibling encoders for cloning
718  * @crtc: currently bound CRTC
719  * @bridge: bridge associated to the encoder
720  * @funcs: control functions
721  * @helper_private: mid-layer private data
722  *
723  * CRTCs drive pixels to encoders, which convert them into signals
724  * appropriate for a given connector or set of connectors.
725  */
726 struct drm_encoder {
727         struct drm_device *dev;
728         struct list_head head;
729
730         struct drm_mode_object base;
731         char *name;
732         int encoder_type;
733         uint32_t possible_crtcs;
734         uint32_t possible_clones;
735
736         struct drm_crtc *crtc;
737         struct drm_bridge *bridge;
738         const struct drm_encoder_funcs *funcs;
739         const void *helper_private;
740 };
741
742 /* should we poll this connector for connects and disconnects */
743 /* hot plug detectable */
744 #define DRM_CONNECTOR_POLL_HPD (1 << 0)
745 /* poll for connections */
746 #define DRM_CONNECTOR_POLL_CONNECT (1 << 1)
747 /* can cleanly poll for disconnections without flickering the screen */
748 /* DACs should rarely do this without a lot of testing */
749 #define DRM_CONNECTOR_POLL_DISCONNECT (1 << 2)
750
751 #define MAX_ELD_BYTES   128
752
753 /**
754  * struct drm_connector - central DRM connector control structure
755  * @dev: parent DRM device
756  * @port: OF node used by find connector by node.
757  * @kdev: kernel device for sysfs attributes
758  * @attr: sysfs attributes
759  * @head: list management
760  * @base: base KMS object
761  * @name: connector name
762  * @connector_type: one of the %DRM_MODE_CONNECTOR_<foo> types from drm_mode.h
763  * @connector_type_id: index into connector type enum
764  * @interlace_allowed: can this connector handle interlaced modes?
765  * @doublescan_allowed: can this connector handle doublescan?
766  * @stereo_allowed: can this connector handle stereo modes?
767  * @modes: modes available on this connector (from fill_modes() + user)
768  * @status: one of the drm_connector_status enums (connected, not, or unknown)
769  * @probed_modes: list of modes derived directly from the display
770  * @display_info: information about attached display (e.g. from EDID)
771  * @funcs: connector control functions
772  * @edid_blob_ptr: DRM property containing EDID if present
773  * @properties: property tracking for this connector
774  * @path_blob_ptr: DRM blob property data for the DP MST path property
775  * @polled: a %DRM_CONNECTOR_POLL_<foo> value for core driven polling
776  * @dpms: current dpms state
777  * @helper_private: mid-layer private data
778  * @cmdline_mode: mode line parsed from the kernel cmdline for this connector
779  * @force: a %DRM_FORCE_<foo> state for forced mode sets
780  * @override_edid: has the EDID been overwritten through debugfs for testing?
781  * @encoder_ids: valid encoders for this connector
782  * @encoder: encoder driving this connector, if any
783  * @eld: EDID-like data, if present
784  * @latency_present: AV delay info from ELD, if found
785  * @video_latency: video latency info from ELD, if found
786  * @audio_latency: audio latency info from ELD, if found
787  * @null_edid_counter: track sinks that give us all zeros for the EDID
788  * @bad_edid_counter: track sinks that give us an EDID with invalid checksum
789  * @edid_corrupt: indicates whether the last read EDID was corrupt
790  * @debugfs_entry: debugfs directory for this connector
791  * @state: current atomic state for this connector
792  * @has_tile: is this connector connected to a tiled monitor
793  * @tile_group: tile group for the connected monitor
794  * @tile_is_single_monitor: whether the tile is one monitor housing
795  * @num_h_tile: number of horizontal tiles in the tile group
796  * @num_v_tile: number of vertical tiles in the tile group
797  * @tile_h_loc: horizontal location of this tile
798  * @tile_v_loc: vertical location of this tile
799  * @tile_h_size: horizontal size of this tile.
800  * @tile_v_size: vertical size of this tile.
801  *
802  * Each connector may be connected to one or more CRTCs, or may be clonable by
803  * another connector if they can share a CRTC.  Each connector also has a specific
804  * position in the broader display (referred to as a 'screen' though it could
805  * span multiple monitors).
806  */
807 struct drm_connector {
808         struct drm_device *dev;
809         struct device_node *port;
810         struct device *kdev;
811         struct device_attribute *attr;
812         struct list_head head;
813
814         struct drm_mode_object base;
815
816         char *name;
817         int connector_type;
818         int connector_type_id;
819         bool interlace_allowed;
820         bool doublescan_allowed;
821         bool stereo_allowed;
822         struct list_head modes; /* list of modes on this connector */
823
824         enum drm_connector_status status;
825
826         /* these are modes added by probing with DDC or the BIOS */
827         struct list_head probed_modes;
828
829         struct drm_display_info display_info;
830         const struct drm_connector_funcs *funcs;
831
832         struct drm_property_blob *edid_blob_ptr;
833         struct drm_object_properties properties;
834
835         struct drm_property_blob *path_blob_ptr;
836
837         struct drm_property_blob *tile_blob_ptr;
838
839         uint8_t polled; /* DRM_CONNECTOR_POLL_* */
840
841         /* requested DPMS state */
842         int dpms;
843
844         const void *helper_private;
845
846         /* forced on connector */
847         struct drm_cmdline_mode cmdline_mode;
848         enum drm_connector_force force;
849         bool override_edid;
850         uint32_t encoder_ids[DRM_CONNECTOR_MAX_ENCODER];
851         struct drm_encoder *encoder; /* currently active encoder */
852         bool loader_protect;
853
854         /* EDID bits */
855         uint8_t eld[MAX_ELD_BYTES];
856         bool latency_present[2];
857         int video_latency[2];   /* [0]: progressive, [1]: interlaced */
858         int audio_latency[2];
859         int null_edid_counter; /* needed to workaround some HW bugs where we get all 0s */
860         unsigned bad_edid_counter;
861
862         /* Flag for raw EDID header corruption - used in Displayport
863          * compliance testing - * Displayport Link CTS Core 1.2 rev1.1 4.2.2.6
864          */
865         bool edid_corrupt;
866
867         struct dentry *debugfs_entry;
868
869         struct drm_connector_state *state;
870
871         /* DisplayID bits */
872         bool has_tile;
873         struct drm_tile_group *tile_group;
874         bool tile_is_single_monitor;
875
876         uint8_t num_h_tile, num_v_tile;
877         uint8_t tile_h_loc, tile_v_loc;
878         uint16_t tile_h_size, tile_v_size;
879 };
880
881 /**
882  * struct drm_plane_state - mutable plane state
883  * @plane: backpointer to the plane
884  * @crtc: currently bound CRTC, NULL if disabled
885  * @fb: currently bound framebuffer
886  * @fence: optional fence to wait for before scanning out @fb
887  * @crtc_x: left position of visible portion of plane on crtc
888  * @crtc_y: upper position of visible portion of plane on crtc
889  * @crtc_w: width of visible portion of plane on crtc
890  * @crtc_h: height of visible portion of plane on crtc
891  * @src_x: left position of visible portion of plane within
892  *      plane (in 16.16)
893  * @src_y: upper position of visible portion of plane within
894  *      plane (in 16.16)
895  * @src_w: width of visible portion of plane (in 16.16)
896  * @src_h: height of visible portion of plane (in 16.16)
897  * @state: backpointer to global drm_atomic_state
898  */
899 struct drm_plane_state {
900         struct drm_plane *plane;
901
902         struct drm_crtc *crtc;   /* do not write directly, use drm_atomic_set_crtc_for_plane() */
903         struct drm_framebuffer *fb;  /* do not write directly, use drm_atomic_set_fb_for_plane() */
904         struct fence *fence;
905
906         /* Signed dest location allows it to be partially off screen */
907         int32_t crtc_x, crtc_y;
908         uint32_t crtc_w, crtc_h;
909
910         /* Source values are 16.16 fixed point */
911         uint32_t src_x, src_y;
912         uint32_t src_h, src_w;
913
914         /* Plane rotation */
915         unsigned int rotation;
916
917         struct drm_atomic_state *state;
918 };
919
920
921 /**
922  * struct drm_plane_funcs - driver plane control functions
923  * @update_plane: update the plane configuration
924  * @disable_plane: shut down the plane
925  * @destroy: clean up plane resources
926  * @reset: reset plane after state has been invalidated (e.g. resume)
927  * @set_property: called when a property is changed
928  * @atomic_duplicate_state: duplicate the atomic state for this plane
929  * @atomic_destroy_state: destroy an atomic state for this plane
930  * @atomic_set_property: set a property on an atomic state for this plane
931  *    (do not call directly, use drm_atomic_plane_set_property())
932  * @atomic_get_property: get a property on an atomic state for this plane
933  *    (do not call directly, use drm_atomic_plane_get_property())
934  */
935 struct drm_plane_funcs {
936         int (*update_plane)(struct drm_plane *plane,
937                             struct drm_crtc *crtc, struct drm_framebuffer *fb,
938                             int crtc_x, int crtc_y,
939                             unsigned int crtc_w, unsigned int crtc_h,
940                             uint32_t src_x, uint32_t src_y,
941                             uint32_t src_w, uint32_t src_h);
942         int (*disable_plane)(struct drm_plane *plane);
943         void (*destroy)(struct drm_plane *plane);
944         void (*reset)(struct drm_plane *plane);
945
946         int (*set_property)(struct drm_plane *plane,
947                             struct drm_property *property, uint64_t val);
948
949         /* atomic update handling */
950         struct drm_plane_state *(*atomic_duplicate_state)(struct drm_plane *plane);
951         void (*atomic_destroy_state)(struct drm_plane *plane,
952                                      struct drm_plane_state *state);
953         int (*atomic_set_property)(struct drm_plane *plane,
954                                    struct drm_plane_state *state,
955                                    struct drm_property *property,
956                                    uint64_t val);
957         int (*atomic_get_property)(struct drm_plane *plane,
958                                    const struct drm_plane_state *state,
959                                    struct drm_property *property,
960                                    uint64_t *val);
961         /**
962          * @late_register:
963          *
964          * This optional hook can be used to register additional userspace
965          * interfaces attached to the plane like debugfs interfaces.
966          * It is called late in the driver load sequence from drm_dev_register().
967          * Everything added from this callback should be unregistered in
968          * the early_unregister callback.
969          *
970          * Returns:
971          *
972          * 0 on success, or a negative error code on failure.
973          */
974         int (*late_register)(struct drm_plane *plane);
975
976         /**
977          * @early_unregister:
978          *
979          * This optional hook should be used to unregister the additional
980          * userspace interfaces attached to the plane from
981          * late_unregister(). It is called from drm_dev_unregister(),
982          * early in the driver unload sequence to disable userspace access
983          * before data structures are torndown.
984          */
985         void (*early_unregister)(struct drm_plane *plane);
986 };
987
988 enum drm_plane_type {
989         DRM_PLANE_TYPE_OVERLAY,
990         DRM_PLANE_TYPE_PRIMARY,
991         DRM_PLANE_TYPE_CURSOR,
992 };
993
994 /**
995  * struct drm_plane - central DRM plane control structure
996  * @dev: DRM device this plane belongs to
997  * @parent: this plane share some resources with parent plane.
998  * @head: for list management
999  * @base: base mode object
1000  * @possible_crtcs: pipes this plane can be bound to
1001  * @format_types: array of formats supported by this plane
1002  * @format_count: number of formats supported
1003  * @format_default: driver hasn't supplied supported formats for the plane
1004  * @crtc: currently bound CRTC
1005  * @fb: currently bound fb
1006  * @old_fb: Temporary tracking of the old fb while a modeset is ongoing. Used by
1007  *      drm_mode_set_config_internal() to implement correct refcounting.
1008  * @funcs: helper functions
1009  * @properties: property tracking for this plane
1010  * @type: type of plane (overlay, primary, cursor)
1011  * @state: current atomic state for this plane
1012  */
1013 struct drm_plane {
1014         struct drm_device *dev;
1015         struct drm_plane *parent;
1016         struct list_head head;
1017
1018         struct drm_modeset_lock mutex;
1019
1020         struct drm_mode_object base;
1021
1022         uint32_t possible_crtcs;
1023         uint32_t *format_types;
1024         unsigned int format_count;
1025         bool format_default;
1026
1027         struct drm_crtc *crtc;
1028         struct drm_framebuffer *fb;
1029
1030         struct drm_framebuffer *old_fb;
1031
1032         const struct drm_plane_funcs *funcs;
1033
1034         struct drm_object_properties properties;
1035
1036         enum drm_plane_type type;
1037
1038         const void *helper_private;
1039
1040         struct drm_plane_state *state;
1041 };
1042
1043 /**
1044  * struct drm_bridge_funcs - drm_bridge control functions
1045  * @attach: Called during drm_bridge_attach
1046  * @mode_fixup: Try to fixup (or reject entirely) proposed mode for this bridge
1047  * @disable: Called right before encoder prepare, disables the bridge
1048  * @post_disable: Called right after encoder prepare, for lockstepped disable
1049  * @mode_set: Set this mode to the bridge
1050  * @pre_enable: Called right before encoder commit, for lockstepped commit
1051  * @enable: Called right after encoder commit, enables the bridge
1052  */
1053 struct drm_bridge_funcs {
1054         int (*attach)(struct drm_bridge *bridge);
1055         bool (*mode_fixup)(struct drm_bridge *bridge,
1056                            const struct drm_display_mode *mode,
1057                            struct drm_display_mode *adjusted_mode);
1058         void (*disable)(struct drm_bridge *bridge);
1059         void (*post_disable)(struct drm_bridge *bridge);
1060         void (*mode_set)(struct drm_bridge *bridge,
1061                          struct drm_display_mode *mode,
1062                          struct drm_display_mode *adjusted_mode);
1063         void (*pre_enable)(struct drm_bridge *bridge);
1064         void (*enable)(struct drm_bridge *bridge);
1065 };
1066
1067 /**
1068  * struct drm_bridge - central DRM bridge control structure
1069  * @dev: DRM device this bridge belongs to
1070  * @encoder: encoder to which this bridge is connected
1071  * @next: the next bridge in the encoder chain
1072  * @of_node: device node pointer to the bridge
1073  * @list: to keep track of all added bridges
1074  * @funcs: control functions
1075  * @driver_private: pointer to the bridge driver's internal context
1076  */
1077 struct drm_bridge {
1078         struct drm_device *dev;
1079         struct drm_encoder *encoder;
1080         struct drm_bridge *next;
1081 #ifdef CONFIG_OF
1082         struct device_node *of_node;
1083 #endif
1084         struct list_head list;
1085
1086         const struct drm_bridge_funcs *funcs;
1087         void *driver_private;
1088 };
1089
1090 /**
1091  * struct drm_atomic_state - the global state object for atomic updates
1092  * @dev: parent DRM device
1093  * @allow_modeset: allow full modeset
1094  * @legacy_cursor_update: hint to enforce legacy cursor ioctl semantics
1095  * @planes: pointer to array of plane pointers
1096  * @plane_states: pointer to array of plane states pointers
1097  * @crtcs: pointer to array of CRTC pointers
1098  * @crtc_states: pointer to array of CRTC states pointers
1099  * @num_connector: size of the @connectors and @connector_states arrays
1100  * @connectors: pointer to array of connector pointers
1101  * @connector_states: pointer to array of connector states pointers
1102  * @acquire_ctx: acquire context for this atomic modeset state update
1103  */
1104 struct drm_atomic_state {
1105         struct drm_device *dev;
1106         bool allow_modeset : 1;
1107         bool legacy_cursor_update : 1;
1108         struct drm_plane **planes;
1109         struct drm_plane_state **plane_states;
1110         struct drm_crtc **crtcs;
1111         struct drm_crtc_state **crtc_states;
1112         int num_connector;
1113         struct drm_connector **connectors;
1114         struct drm_connector_state **connector_states;
1115
1116         struct drm_modeset_acquire_ctx *acquire_ctx;
1117 };
1118
1119
1120 /**
1121  * struct drm_mode_set - new values for a CRTC config change
1122  * @fb: framebuffer to use for new config
1123  * @crtc: CRTC whose configuration we're about to change
1124  * @mode: mode timings to use
1125  * @x: position of this CRTC relative to @fb
1126  * @y: position of this CRTC relative to @fb
1127  * @connectors: array of connectors to drive with this CRTC if possible
1128  * @num_connectors: size of @connectors array
1129  *
1130  * Represents a single crtc the connectors that it drives with what mode
1131  * and from which framebuffer it scans out from.
1132  *
1133  * This is used to set modes.
1134  */
1135 struct drm_mode_set {
1136         struct drm_framebuffer *fb;
1137         struct drm_crtc *crtc;
1138         struct drm_display_mode *mode;
1139
1140         uint32_t x;
1141         uint32_t y;
1142
1143         struct drm_connector **connectors;
1144         size_t num_connectors;
1145 };
1146
1147 /**
1148  * struct drm_mode_config_funcs - basic driver provided mode setting functions
1149  * @fb_create: create a new framebuffer object
1150  * @output_poll_changed: function to handle output configuration changes
1151  * @atomic_check: check whether a given atomic state update is possible
1152  * @atomic_commit: commit an atomic state update previously verified with
1153  *      atomic_check()
1154  * @atomic_state_alloc: allocate a new atomic state
1155  * @atomic_state_clear: clear the atomic state
1156  * @atomic_state_free: free the atomic state
1157  *
1158  * Some global (i.e. not per-CRTC, connector, etc) mode setting functions that
1159  * involve drivers.
1160  */
1161 struct drm_mode_config_funcs {
1162         struct drm_framebuffer *(*fb_create)(struct drm_device *dev,
1163                                              struct drm_file *file_priv,
1164                                              struct drm_mode_fb_cmd2 *mode_cmd);
1165         void (*output_poll_changed)(struct drm_device *dev);
1166
1167         int (*atomic_check)(struct drm_device *dev,
1168                             struct drm_atomic_state *a);
1169         int (*atomic_commit)(struct drm_device *dev,
1170                              struct drm_atomic_state *a,
1171                              bool async);
1172         struct drm_atomic_state *(*atomic_state_alloc)(struct drm_device *dev);
1173         void (*atomic_state_clear)(struct drm_atomic_state *state);
1174         void (*atomic_state_free)(struct drm_atomic_state *state);
1175 };
1176
1177 /**
1178  * struct drm_mode_config - Mode configuration control structure
1179  * @mutex: mutex protecting KMS related lists and structures
1180  * @connection_mutex: ww mutex protecting connector state and routing
1181  * @acquire_ctx: global implicit acquire context used by atomic drivers for
1182  *      legacy ioctls
1183  * @idr_mutex: mutex for KMS ID allocation and management
1184  * @crtc_idr: main KMS ID tracking object
1185  * @fb_lock: mutex to protect fb state and lists
1186  * @num_fb: number of fbs available
1187  * @fb_list: list of framebuffers available
1188  * @num_connector: number of connectors on this device
1189  * @connector_list: list of connector objects
1190  * @num_encoder: number of encoders on this device
1191  * @encoder_list: list of encoder objects
1192  * @num_overlay_plane: number of overlay planes on this device
1193  * @num_total_plane: number of universal (i.e. with primary/curso) planes on this device
1194  * @plane_list: list of plane objects
1195  * @num_crtc: number of CRTCs on this device
1196  * @crtc_list: list of CRTC objects
1197  * @property_list: list of property objects
1198  * @min_width: minimum pixel width on this device
1199  * @min_height: minimum pixel height on this device
1200  * @max_width: maximum pixel width on this device
1201  * @max_height: maximum pixel height on this device
1202  * @funcs: core driver provided mode setting functions
1203  * @fb_base: base address of the framebuffer
1204  * @poll_enabled: track polling support for this device
1205  * @poll_running: track polling status for this device
1206  * @output_poll_work: delayed work for polling in process context
1207  * @property_blob_list: list of all the blob property objects
1208  * @blob_lock: mutex for blob property allocation and management
1209  * @*_property: core property tracking
1210  * @preferred_depth: preferred RBG pixel depth, used by fb helpers
1211  * @prefer_shadow: hint to userspace to prefer shadow-fb rendering
1212  * @async_page_flip: does this device support async flips on the primary plane?
1213  * @cursor_width: hint to userspace for max cursor width
1214  * @cursor_height: hint to userspace for max cursor height
1215  *
1216  * Core mode resource tracking structure.  All CRTC, encoders, and connectors
1217  * enumerated by the driver are added here, as are global properties.  Some
1218  * global restrictions are also here, e.g. dimension restrictions.
1219  */
1220 struct drm_mode_config {
1221         struct mutex mutex; /* protects configuration (mode lists etc.) */
1222         struct drm_modeset_lock connection_mutex; /* protects connector->encoder and encoder->crtc links */
1223         struct drm_modeset_acquire_ctx *acquire_ctx; /* for legacy _lock_all() / _unlock_all() */
1224         struct mutex idr_mutex; /* for IDR management */
1225         struct idr crtc_idr; /* use this idr for all IDs, fb, crtc, connector, modes - just makes life easier */
1226         struct idr tile_idr; /* use this idr for all IDs, fb, crtc, connector, modes - just makes life easier */
1227         /* this is limited to one for now */
1228
1229         struct mutex fb_lock; /* proctects global and per-file fb lists */
1230         int num_fb;
1231         struct list_head fb_list;
1232
1233         int num_connector;
1234         struct list_head connector_list;
1235         int num_encoder;
1236         struct list_head encoder_list;
1237
1238         /*
1239          * Track # of overlay planes separately from # of total planes.  By
1240          * default we only advertise overlay planes to userspace; if userspace
1241          * sets the "universal plane" capability bit, we'll go ahead and
1242          * expose all planes.
1243          */
1244         int num_overlay_plane;
1245         int num_total_plane;
1246         int num_share_plane;
1247         int num_share_overlay_plane;
1248         struct list_head plane_list;
1249
1250         int num_crtc;
1251         struct list_head crtc_list;
1252
1253         struct list_head property_list;
1254
1255         int min_width, min_height;
1256         int max_width, max_height;
1257         const struct drm_mode_config_funcs *funcs;
1258         resource_size_t fb_base;
1259
1260         /* output poll support */
1261         bool poll_enabled;
1262         bool poll_running;
1263         bool delayed_event;
1264         struct delayed_work output_poll_work;
1265
1266         struct mutex blob_lock;
1267
1268         /* pointers to share properties */
1269         struct drm_property *prop_share_id;
1270         struct drm_property *prop_share_flags;
1271
1272         /* pointers to standard properties */
1273         struct list_head property_blob_list;
1274         struct drm_property *edid_property;
1275         struct drm_property *dpms_property;
1276         struct drm_property *path_property;
1277         struct drm_property *tile_property;
1278         struct drm_property *plane_type_property;
1279         struct drm_property *rotation_property;
1280         struct drm_property *prop_src_x;
1281         struct drm_property *prop_src_y;
1282         struct drm_property *prop_src_w;
1283         struct drm_property *prop_src_h;
1284         struct drm_property *prop_crtc_x;
1285         struct drm_property *prop_crtc_y;
1286         struct drm_property *prop_crtc_w;
1287         struct drm_property *prop_crtc_h;
1288         struct drm_property *prop_fb_id;
1289         struct drm_property *prop_crtc_id;
1290         struct drm_property *prop_active;
1291         struct drm_property *prop_mode_id;
1292
1293         /* DVI-I properties */
1294         struct drm_property *dvi_i_subconnector_property;
1295         struct drm_property *dvi_i_select_subconnector_property;
1296
1297         /* TV properties */
1298         struct drm_property *tv_subconnector_property;
1299         struct drm_property *tv_select_subconnector_property;
1300         struct drm_property *tv_mode_property;
1301         struct drm_property *tv_left_margin_property;
1302         struct drm_property *tv_right_margin_property;
1303         struct drm_property *tv_top_margin_property;
1304         struct drm_property *tv_bottom_margin_property;
1305         struct drm_property *tv_brightness_property;
1306         struct drm_property *tv_contrast_property;
1307         struct drm_property *tv_flicker_reduction_property;
1308         struct drm_property *tv_overscan_property;
1309         struct drm_property *tv_saturation_property;
1310         struct drm_property *tv_hue_property;
1311
1312         /* Optional properties */
1313         struct drm_property *scaling_mode_property;
1314         struct drm_property *aspect_ratio_property;
1315         struct drm_property *dirty_info_property;
1316
1317         /* properties for virtual machine layout */
1318         struct drm_property *suggested_x_property;
1319         struct drm_property *suggested_y_property;
1320
1321         /* dumb ioctl parameters */
1322         uint32_t preferred_depth, prefer_shadow;
1323
1324         /* whether async page flip is supported or not */
1325         bool async_page_flip;
1326
1327         /* whether the driver supports fb modifiers */
1328         bool allow_fb_modifiers;
1329
1330         /* cursor size */
1331         uint32_t cursor_width, cursor_height;
1332 };
1333
1334 /**
1335  * drm_for_each_plane_mask - iterate over planes specified by bitmask
1336  * @plane: the loop cursor
1337  * @dev: the DRM device
1338  * @plane_mask: bitmask of plane indices
1339  *
1340  * Iterate over all planes specified by bitmask.
1341  */
1342 #define drm_for_each_plane_mask(plane, dev, plane_mask) \
1343         list_for_each_entry((plane), &(dev)->mode_config.plane_list, head) \
1344                 if ((plane_mask) & (1 << drm_plane_index(plane)))
1345
1346
1347 #define obj_to_crtc(x) container_of(x, struct drm_crtc, base)
1348 #define obj_to_connector(x) container_of(x, struct drm_connector, base)
1349 #define obj_to_encoder(x) container_of(x, struct drm_encoder, base)
1350 #define obj_to_mode(x) container_of(x, struct drm_display_mode, base)
1351 #define obj_to_fb(x) container_of(x, struct drm_framebuffer, base)
1352 #define obj_to_property(x) container_of(x, struct drm_property, base)
1353 #define obj_to_blob(x) container_of(x, struct drm_property_blob, base)
1354 #define obj_to_plane(x) container_of(x, struct drm_plane, base)
1355
1356 struct drm_prop_enum_list {
1357         int type;
1358         char *name;
1359 };
1360
1361 extern __printf(6, 7)
1362 int drm_crtc_init_with_planes(struct drm_device *dev,
1363                               struct drm_crtc *crtc,
1364                               struct drm_plane *primary,
1365                               struct drm_plane *cursor,
1366                               const struct drm_crtc_funcs *funcs,
1367                               const char *name, ...);
1368 extern void drm_crtc_cleanup(struct drm_crtc *crtc);
1369 extern unsigned int drm_crtc_index(struct drm_crtc *crtc);
1370
1371 /**
1372  * drm_crtc_mask - find the mask of a registered CRTC
1373  * @crtc: CRTC to find mask for
1374  *
1375  * Given a registered CRTC, return the mask bit of that CRTC for an
1376  * encoder's possible_crtcs field.
1377  */
1378 static inline uint32_t drm_crtc_mask(struct drm_crtc *crtc)
1379 {
1380         return 1 << drm_crtc_index(crtc);
1381 }
1382
1383 extern void drm_connector_ida_init(void);
1384 extern void drm_connector_ida_destroy(void);
1385 extern int drm_connector_init(struct drm_device *dev,
1386                               struct drm_connector *connector,
1387                               const struct drm_connector_funcs *funcs,
1388                               int connector_type);
1389 int drm_connector_register(struct drm_connector *connector);
1390 void drm_connector_unregister(struct drm_connector *connector);
1391
1392 extern void drm_connector_cleanup(struct drm_connector *connector);
1393 extern unsigned int drm_connector_index(struct drm_connector *connector);
1394
1395 /* helpers to {un}register all connectors from sysfs for device */
1396 extern int drm_connector_register_all(struct drm_device *dev);
1397 extern void drm_connector_unregister_all(struct drm_device *dev);
1398
1399 extern int drm_bridge_add(struct drm_bridge *bridge);
1400 extern void drm_bridge_remove(struct drm_bridge *bridge);
1401 extern struct drm_bridge *of_drm_find_bridge(struct device_node *np);
1402 extern int drm_bridge_attach(struct drm_device *dev, struct drm_bridge *bridge);
1403
1404 bool drm_bridge_mode_fixup(struct drm_bridge *bridge,
1405                         const struct drm_display_mode *mode,
1406                         struct drm_display_mode *adjusted_mode);
1407 void drm_bridge_disable(struct drm_bridge *bridge);
1408 void drm_bridge_post_disable(struct drm_bridge *bridge);
1409 void drm_bridge_mode_set(struct drm_bridge *bridge,
1410                         struct drm_display_mode *mode,
1411                         struct drm_display_mode *adjusted_mode);
1412 void drm_bridge_pre_enable(struct drm_bridge *bridge);
1413 void drm_bridge_enable(struct drm_bridge *bridge);
1414
1415 extern __printf(5, 6)
1416 int drm_encoder_init(struct drm_device *dev,
1417                      struct drm_encoder *encoder,
1418                      const struct drm_encoder_funcs *funcs,
1419                      int encoder_type, const char *name, ...);
1420
1421 /**
1422  * drm_encoder_crtc_ok - can a given crtc drive a given encoder?
1423  * @encoder: encoder to test
1424  * @crtc: crtc to test
1425  *
1426  * Return false if @encoder can't be driven by @crtc, true otherwise.
1427  */
1428 static inline bool drm_encoder_crtc_ok(struct drm_encoder *encoder,
1429                                        struct drm_crtc *crtc)
1430 {
1431         return !!(encoder->possible_crtcs & drm_crtc_mask(crtc));
1432 }
1433
1434 extern __printf(8, 9)
1435 int drm_universal_plane_init(struct drm_device *dev,
1436                              struct drm_plane *plane,
1437                              unsigned long possible_crtcs,
1438                              const struct drm_plane_funcs *funcs,
1439                              const uint32_t *formats,
1440                              unsigned int format_count,
1441                              enum drm_plane_type type,
1442                              const char *name, ...);
1443 extern int drm_plane_init(struct drm_device *dev,
1444                           struct drm_plane *plane,
1445                           unsigned long possible_crtcs,
1446                           const struct drm_plane_funcs *funcs,
1447                           const uint32_t *formats, unsigned int format_count,
1448                           bool is_primary);
1449 extern int drm_share_plane_init(struct drm_device *dev, struct drm_plane *plane,
1450                                 struct drm_plane *parent,
1451                                 unsigned long possible_crtcs,
1452                                 const struct drm_plane_funcs *funcs,
1453                                 const uint32_t *formats,
1454                                 unsigned int format_count,
1455                                 enum drm_plane_type type);
1456 extern void drm_plane_cleanup(struct drm_plane *plane);
1457 extern unsigned int drm_plane_index(struct drm_plane *plane);
1458 extern struct drm_plane * drm_plane_from_index(struct drm_device *dev, int idx);
1459 extern void drm_plane_force_disable(struct drm_plane *plane);
1460 extern int drm_plane_check_pixel_format(const struct drm_plane *plane,
1461                                         u32 format);
1462 extern void drm_crtc_get_hv_timing(const struct drm_display_mode *mode,
1463                                    int *hdisplay, int *vdisplay);
1464 extern int drm_crtc_check_viewport(const struct drm_crtc *crtc,
1465                                    int x, int y,
1466                                    const struct drm_display_mode *mode,
1467                                    const struct drm_framebuffer *fb);
1468
1469 extern void drm_encoder_cleanup(struct drm_encoder *encoder);
1470
1471 extern const char *drm_get_connector_status_name(enum drm_connector_status status);
1472 extern const char *drm_get_subpixel_order_name(enum subpixel_order order);
1473 extern const char *drm_get_dpms_name(int val);
1474 extern const char *drm_get_dvi_i_subconnector_name(int val);
1475 extern const char *drm_get_dvi_i_select_name(int val);
1476 extern const char *drm_get_tv_subconnector_name(int val);
1477 extern const char *drm_get_tv_select_name(int val);
1478 extern const char *drm_get_connector_name(int val);
1479 extern void drm_fb_release(struct drm_file *file_priv);
1480 extern void drm_property_destroy_user_blobs(struct drm_device *dev,
1481                                             struct drm_file *file_priv);
1482 extern bool drm_probe_ddc(struct i2c_adapter *adapter);
1483 extern struct edid *drm_get_edid(struct drm_connector *connector,
1484                                  struct i2c_adapter *adapter);
1485 extern struct edid *drm_edid_duplicate(const struct edid *edid);
1486 extern int drm_add_edid_modes(struct drm_connector *connector, struct edid *edid);
1487 extern void drm_mode_config_init(struct drm_device *dev);
1488 extern void drm_mode_config_reset(struct drm_device *dev);
1489 extern void drm_mode_config_cleanup(struct drm_device *dev);
1490
1491 extern int drm_mode_connector_set_path_property(struct drm_connector *connector,
1492                                                 const char *path);
1493 int drm_mode_connector_set_tile_property(struct drm_connector *connector);
1494 extern int drm_mode_connector_update_edid_property(struct drm_connector *connector,
1495                                                    const struct edid *edid);
1496
1497 extern int drm_display_info_set_bus_formats(struct drm_display_info *info,
1498                                             const u32 *formats,
1499                                             unsigned int num_formats);
1500
1501 static inline bool drm_property_type_is(struct drm_property *property,
1502                 uint32_t type)
1503 {
1504         /* instanceof for props.. handles extended type vs original types: */
1505         if (property->flags & DRM_MODE_PROP_EXTENDED_TYPE)
1506                 return (property->flags & DRM_MODE_PROP_EXTENDED_TYPE) == type;
1507         return property->flags & type;
1508 }
1509
1510 static inline bool drm_property_type_valid(struct drm_property *property)
1511 {
1512         if (property->flags & DRM_MODE_PROP_EXTENDED_TYPE)
1513                 return !(property->flags & DRM_MODE_PROP_LEGACY_TYPE);
1514         return !!(property->flags & DRM_MODE_PROP_LEGACY_TYPE);
1515 }
1516
1517 extern int drm_object_property_set_value(struct drm_mode_object *obj,
1518                                          struct drm_property *property,
1519                                          uint64_t val);
1520 extern int drm_object_property_get_value(struct drm_mode_object *obj,
1521                                          struct drm_property *property,
1522                                          uint64_t *value);
1523 extern int drm_framebuffer_init(struct drm_device *dev,
1524                                 struct drm_framebuffer *fb,
1525                                 const struct drm_framebuffer_funcs *funcs);
1526 extern struct drm_framebuffer *drm_framebuffer_lookup(struct drm_device *dev,
1527                                                       uint32_t id);
1528 extern void drm_framebuffer_unreference(struct drm_framebuffer *fb);
1529 extern void drm_framebuffer_reference(struct drm_framebuffer *fb);
1530 extern void drm_framebuffer_remove(struct drm_framebuffer *fb);
1531 extern void drm_framebuffer_cleanup(struct drm_framebuffer *fb);
1532 extern void drm_framebuffer_unregister_private(struct drm_framebuffer *fb);
1533
1534 extern void drm_object_attach_property(struct drm_mode_object *obj,
1535                                        struct drm_property *property,
1536                                        uint64_t init_val);
1537 extern struct drm_property *drm_property_create(struct drm_device *dev, int flags,
1538                                                 const char *name, int num_values);
1539 extern struct drm_property *drm_property_create_enum(struct drm_device *dev, int flags,
1540                                          const char *name,
1541                                          const struct drm_prop_enum_list *props,
1542                                          int num_values);
1543 struct drm_property *drm_property_create_bitmask(struct drm_device *dev,
1544                                          int flags, const char *name,
1545                                          const struct drm_prop_enum_list *props,
1546                                          int num_props,
1547                                          uint64_t supported_bits);
1548 struct drm_property *drm_property_create_range(struct drm_device *dev, int flags,
1549                                          const char *name,
1550                                          uint64_t min, uint64_t max);
1551 struct drm_property *drm_property_create_signed_range(struct drm_device *dev,
1552                                          int flags, const char *name,
1553                                          int64_t min, int64_t max);
1554 struct drm_property *drm_property_create_object(struct drm_device *dev,
1555                                          int flags, const char *name, uint32_t type);
1556 struct drm_property *drm_property_create_bool(struct drm_device *dev, int flags,
1557                                          const char *name);
1558 struct drm_property_blob *drm_property_create_blob(struct drm_device *dev,
1559                                                    size_t length,
1560                                                    const void *data);
1561 struct drm_property_blob *drm_property_lookup_blob(struct drm_device *dev,
1562                                                    uint32_t id);
1563 struct drm_property_blob *drm_property_reference_blob(struct drm_property_blob *blob);
1564 void drm_property_unreference_blob(struct drm_property_blob *blob);
1565 extern void drm_property_destroy(struct drm_device *dev, struct drm_property *property);
1566 extern int drm_property_add_enum(struct drm_property *property, int index,
1567                                  uint64_t value, const char *name);
1568 extern int drm_mode_create_dvi_i_properties(struct drm_device *dev);
1569 extern int drm_mode_create_tv_properties(struct drm_device *dev,
1570                                          unsigned int num_modes,
1571                                          const char * const modes[]);
1572 extern int drm_mode_create_scaling_mode_property(struct drm_device *dev);
1573 extern int drm_mode_create_aspect_ratio_property(struct drm_device *dev);
1574 extern int drm_mode_create_dirty_info_property(struct drm_device *dev);
1575 extern int drm_mode_create_suggested_offset_properties(struct drm_device *dev);
1576 extern bool drm_property_change_valid_get(struct drm_property *property,
1577                                          uint64_t value, struct drm_mode_object **ref);
1578 extern void drm_property_change_valid_put(struct drm_property *property,
1579                 struct drm_mode_object *ref);
1580
1581 extern int drm_mode_connector_attach_encoder(struct drm_connector *connector,
1582                                              struct drm_encoder *encoder);
1583 extern int drm_mode_crtc_set_gamma_size(struct drm_crtc *crtc,
1584                                          int gamma_size);
1585 extern struct drm_mode_object *drm_mode_object_find(struct drm_device *dev,
1586                 uint32_t id, uint32_t type);
1587
1588 /* IOCTLs */
1589 extern int drm_mode_getresources(struct drm_device *dev,
1590                                  void *data, struct drm_file *file_priv);
1591 extern int drm_mode_getplane_res(struct drm_device *dev, void *data,
1592                                    struct drm_file *file_priv);
1593 extern int drm_mode_getcrtc(struct drm_device *dev,
1594                             void *data, struct drm_file *file_priv);
1595 extern int drm_mode_getconnector(struct drm_device *dev,
1596                               void *data, struct drm_file *file_priv);
1597 extern int drm_mode_set_config_internal(struct drm_mode_set *set);
1598 extern int drm_mode_setcrtc(struct drm_device *dev,
1599                             void *data, struct drm_file *file_priv);
1600 extern int drm_mode_getplane(struct drm_device *dev,
1601                                void *data, struct drm_file *file_priv);
1602 extern int drm_mode_setplane(struct drm_device *dev,
1603                                void *data, struct drm_file *file_priv);
1604 extern int drm_mode_cursor_ioctl(struct drm_device *dev,
1605                                 void *data, struct drm_file *file_priv);
1606 extern int drm_mode_cursor2_ioctl(struct drm_device *dev,
1607                                 void *data, struct drm_file *file_priv);
1608 extern int drm_mode_addfb(struct drm_device *dev,
1609                           void *data, struct drm_file *file_priv);
1610 extern int drm_mode_addfb2(struct drm_device *dev,
1611                            void *data, struct drm_file *file_priv);
1612 extern uint32_t drm_mode_legacy_fb_format(uint32_t bpp, uint32_t depth);
1613 extern int drm_mode_rmfb(struct drm_device *dev,
1614                          void *data, struct drm_file *file_priv);
1615 extern int drm_mode_getfb(struct drm_device *dev,
1616                           void *data, struct drm_file *file_priv);
1617 extern int drm_mode_dirtyfb_ioctl(struct drm_device *dev,
1618                                   void *data, struct drm_file *file_priv);
1619
1620 extern int drm_mode_getproperty_ioctl(struct drm_device *dev,
1621                                       void *data, struct drm_file *file_priv);
1622 extern int drm_mode_getblob_ioctl(struct drm_device *dev,
1623                                   void *data, struct drm_file *file_priv);
1624 extern int drm_mode_createblob_ioctl(struct drm_device *dev,
1625                                      void *data, struct drm_file *file_priv);
1626 extern int drm_mode_destroyblob_ioctl(struct drm_device *dev,
1627                                       void *data, struct drm_file *file_priv);
1628 extern int drm_mode_connector_property_set_ioctl(struct drm_device *dev,
1629                                               void *data, struct drm_file *file_priv);
1630 extern int drm_mode_getencoder(struct drm_device *dev,
1631                                void *data, struct drm_file *file_priv);
1632 extern int drm_mode_gamma_get_ioctl(struct drm_device *dev,
1633                                     void *data, struct drm_file *file_priv);
1634 extern int drm_mode_gamma_set_ioctl(struct drm_device *dev,
1635                                     void *data, struct drm_file *file_priv);
1636 extern u8 drm_match_cea_mode(const struct drm_display_mode *to_match);
1637 extern enum hdmi_picture_aspect drm_get_cea_aspect_ratio(const u8 video_code);
1638 extern bool drm_detect_hdmi_monitor(struct edid *edid);
1639 extern bool drm_detect_monitor_audio(struct edid *edid);
1640 extern bool drm_rgb_quant_range_selectable(struct edid *edid);
1641 extern int drm_mode_page_flip_ioctl(struct drm_device *dev,
1642                                     void *data, struct drm_file *file_priv);
1643 extern int drm_add_modes_noedid(struct drm_connector *connector,
1644                                 int hdisplay, int vdisplay);
1645 extern void drm_set_preferred_mode(struct drm_connector *connector,
1646                                    int hpref, int vpref);
1647
1648 extern int drm_edid_header_is_valid(const u8 *raw_edid);
1649 extern bool drm_edid_block_valid(u8 *raw_edid, int block, bool print_bad_edid,
1650                                  bool *edid_corrupt);
1651 extern bool drm_edid_is_valid(struct edid *edid);
1652
1653 extern struct drm_tile_group *drm_mode_create_tile_group(struct drm_device *dev,
1654                                                          char topology[8]);
1655 extern struct drm_tile_group *drm_mode_get_tile_group(struct drm_device *dev,
1656                                                char topology[8]);
1657 extern void drm_mode_put_tile_group(struct drm_device *dev,
1658                                    struct drm_tile_group *tg);
1659 struct drm_display_mode *drm_mode_find_dmt(struct drm_device *dev,
1660                                            int hsize, int vsize, int fresh,
1661                                            bool rb);
1662
1663 extern int drm_mode_create_dumb_ioctl(struct drm_device *dev,
1664                                       void *data, struct drm_file *file_priv);
1665 extern int drm_mode_mmap_dumb_ioctl(struct drm_device *dev,
1666                                     void *data, struct drm_file *file_priv);
1667 extern int drm_mode_destroy_dumb_ioctl(struct drm_device *dev,
1668                                       void *data, struct drm_file *file_priv);
1669 extern int drm_mode_obj_get_properties_ioctl(struct drm_device *dev, void *data,
1670                                              struct drm_file *file_priv);
1671 extern int drm_mode_obj_set_property_ioctl(struct drm_device *dev, void *data,
1672                                            struct drm_file *file_priv);
1673 extern int drm_mode_plane_set_obj_prop(struct drm_plane *plane,
1674                                        struct drm_property *property,
1675                                        uint64_t value);
1676 extern int drm_mode_atomic_ioctl(struct drm_device *dev,
1677                                  void *data, struct drm_file *file_priv);
1678
1679 extern void drm_fb_get_bpp_depth(uint32_t format, unsigned int *depth,
1680                                  int *bpp);
1681 extern int drm_format_num_planes(uint32_t format);
1682 extern int drm_format_plane_bpp(uint32_t format, int plane);
1683 extern int drm_format_plane_cpp(uint32_t format, int plane);
1684 extern int drm_format_horz_chroma_subsampling(uint32_t format);
1685 extern int drm_format_vert_chroma_subsampling(uint32_t format);
1686 extern const char *drm_get_format_name(uint32_t format);
1687 extern struct drm_property *drm_mode_create_rotation_property(struct drm_device *dev,
1688                                                               unsigned int supported_rotations);
1689 extern unsigned int drm_rotation_simplify(unsigned int rotation,
1690                                           unsigned int supported_rotations);
1691
1692 /* Helpers */
1693
1694 static inline struct drm_plane *drm_plane_find(struct drm_device *dev,
1695                 uint32_t id)
1696 {
1697         struct drm_mode_object *mo;
1698         mo = drm_mode_object_find(dev, id, DRM_MODE_OBJECT_PLANE);
1699         return mo ? obj_to_plane(mo) : NULL;
1700 }
1701
1702 static inline struct drm_crtc *drm_crtc_find(struct drm_device *dev,
1703         uint32_t id)
1704 {
1705         struct drm_mode_object *mo;
1706         mo = drm_mode_object_find(dev, id, DRM_MODE_OBJECT_CRTC);
1707         return mo ? obj_to_crtc(mo) : NULL;
1708 }
1709
1710 static inline struct drm_encoder *drm_encoder_find(struct drm_device *dev,
1711         uint32_t id)
1712 {
1713         struct drm_mode_object *mo;
1714         mo = drm_mode_object_find(dev, id, DRM_MODE_OBJECT_ENCODER);
1715         return mo ? obj_to_encoder(mo) : NULL;
1716 }
1717
1718 static inline struct drm_connector *drm_connector_find(struct drm_device *dev,
1719                 uint32_t id)
1720 {
1721         struct drm_mode_object *mo;
1722         mo = drm_mode_object_find(dev, id, DRM_MODE_OBJECT_CONNECTOR);
1723         return mo ? obj_to_connector(mo) : NULL;
1724 }
1725
1726 static inline struct drm_property *drm_property_find(struct drm_device *dev,
1727                 uint32_t id)
1728 {
1729         struct drm_mode_object *mo;
1730         mo = drm_mode_object_find(dev, id, DRM_MODE_OBJECT_PROPERTY);
1731         return mo ? obj_to_property(mo) : NULL;
1732 }
1733
1734 /* Plane list iterator for legacy (overlay only) planes. */
1735 #define drm_for_each_legacy_plane(plane, dev) \
1736         list_for_each_entry(plane, &(dev)->mode_config.plane_list, head) \
1737                 if (plane->type == DRM_PLANE_TYPE_OVERLAY)
1738
1739 #define drm_for_each_plane(plane, dev) \
1740         list_for_each_entry(plane, &(dev)->mode_config.plane_list, head)
1741
1742 #define drm_for_each_crtc(crtc, dev) \
1743         list_for_each_entry(crtc, &(dev)->mode_config.crtc_list, head)
1744
1745 static inline void
1746 assert_drm_connector_list_read_locked(struct drm_mode_config *mode_config)
1747 {
1748         /*
1749          * The connector hotadd/remove code currently grabs both locks when
1750          * updating lists. Hence readers need only hold either of them to be
1751          * safe and the check amounts to
1752          *
1753          * WARN_ON(not_holding(A) && not_holding(B)).
1754          */
1755         WARN_ON(!mutex_is_locked(&mode_config->mutex) &&
1756                 !drm_modeset_is_locked(&mode_config->connection_mutex));
1757 }
1758
1759 #define drm_for_each_connector(connector, dev) \
1760         for (assert_drm_connector_list_read_locked(&(dev)->mode_config),        \
1761              connector = list_first_entry(&(dev)->mode_config.connector_list,   \
1762                                           struct drm_connector, head);          \
1763              &connector->head != (&(dev)->mode_config.connector_list);          \
1764              connector = list_next_entry(connector, head))
1765
1766 #define drm_for_each_encoder(encoder, dev) \
1767         list_for_each_entry(encoder, &(dev)->mode_config.encoder_list, head)
1768
1769 #define drm_for_each_fb(fb, dev) \
1770         for (WARN_ON(!mutex_is_locked(&(dev)->mode_config.fb_lock)),            \
1771              fb = list_first_entry(&(dev)->mode_config.fb_list, \
1772                                           struct drm_framebuffer, head);        \
1773              &fb->head != (&(dev)->mode_config.fb_list);                        \
1774              fb = list_next_entry(fb, head))
1775
1776 #endif /* __DRM_CRTC_H__ */