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