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