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