drm: Remove crtc/connector->save/restore hooks
[deliverable/linux.git] / include / drm / drm_crtc.h
CommitLineData
f453ba04
DA
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>
f453ba04 32#include <linux/fb.h>
985e5dc2 33#include <linux/hdmi.h>
b5571e9d 34#include <linux/media-bus-format.h>
d7d2c48e
DH
35#include <uapi/drm/drm_mode.h>
36#include <uapi/drm/drm_fourcc.h>
51fd371b 37#include <drm/drm_modeset_lock.h>
308e5bcb 38
f453ba04
DA
39struct drm_device;
40struct drm_mode_set;
41struct drm_framebuffer;
7e3bdf4a 42struct drm_object_properties;
595887eb
TR
43struct drm_file;
44struct drm_clip_rect;
7e435aad 45struct device_node;
e2330f07 46struct fence;
f453ba04
DA
47
48#define DRM_MODE_OBJECT_CRTC 0xcccccccc
49#define DRM_MODE_OBJECT_CONNECTOR 0xc0c0c0c0
50#define DRM_MODE_OBJECT_ENCODER 0xe0e0e0e0
51#define DRM_MODE_OBJECT_MODE 0xdededede
52#define DRM_MODE_OBJECT_PROPERTY 0xb0b0b0b0
53#define DRM_MODE_OBJECT_FB 0xfbfbfbfb
54#define DRM_MODE_OBJECT_BLOB 0xbbbbbbbb
8cf5c917 55#define DRM_MODE_OBJECT_PLANE 0xeeeeeeee
98f75de4 56#define DRM_MODE_OBJECT_ANY 0
f453ba04
DA
57
58struct drm_mode_object {
59 uint32_t id;
60 uint32_t type;
7e3bdf4a
PZ
61 struct drm_object_properties *properties;
62};
63
fe456168 64#define DRM_OBJECT_MAX_PROPERTY 24
7e3bdf4a 65struct drm_object_properties {
88a48e29 66 int count, atomic_count;
b17cd757
RC
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];
22b8b13b
RC
73 /* do not read/write values directly, but use drm_object_property_get_value()
74 * and drm_object_property_set_value():
75 */
7e3bdf4a 76 uint64_t values[DRM_OBJECT_MAX_PROPERTY];
f453ba04
DA
77};
78
ebc44cf3
RC
79static inline int64_t U642I64(uint64_t val)
80{
81 return (int64_t)*((int64_t *)&val);
82}
83static inline uint64_t I642U64(int64_t val)
84{
85 return (uint64_t)*((uint64_t *)&val);
86}
87
d9c38242
RF
88/*
89 * Rotation property bits. DRM_ROTATE_<degrees> rotates the image by the
90 * specified amount in degrees in counter clockwise direction. DRM_REFLECT_X and
91 * DRM_REFLECT_Y reflects the image along the specified axis prior to rotation
92 */
62209070 93#define DRM_ROTATE_MASK 0x0f
06596961
VS
94#define DRM_ROTATE_0 0
95#define DRM_ROTATE_90 1
96#define DRM_ROTATE_180 2
97#define DRM_ROTATE_270 3
62209070 98#define DRM_REFLECT_MASK (~DRM_ROTATE_MASK)
06596961
VS
99#define DRM_REFLECT_X 4
100#define DRM_REFLECT_Y 5
101
55310008
DV
102enum drm_connector_force {
103 DRM_FORCE_UNSPECIFIED,
104 DRM_FORCE_OFF,
105 DRM_FORCE_ON, /* force on analog part normally */
106 DRM_FORCE_ON_DIGITAL, /* for DVI-I use digital connector */
f453ba04
DA
107};
108
55310008 109#include <drm/drm_modes.h>
4aa17cf0 110
f453ba04
DA
111enum drm_connector_status {
112 connector_status_connected = 1,
113 connector_status_disconnected = 2,
114 connector_status_unknown = 3,
115};
116
117enum subpixel_order {
118 SubPixelUnknown = 0,
119 SubPixelHorizontalRGB,
120 SubPixelHorizontalBGR,
121 SubPixelVerticalRGB,
122 SubPixelVerticalBGR,
123 SubPixelNone,
124};
125
da05a5a7
JB
126#define DRM_COLOR_FORMAT_RGB444 (1<<0)
127#define DRM_COLOR_FORMAT_YCRCB444 (1<<1)
128#define DRM_COLOR_FORMAT_YCRCB422 (1<<2)
f453ba04
DA
129/*
130 * Describes a given display (e.g. CRT or flat panel) and its limitations.
131 */
132struct drm_display_info {
133 char name[DRM_DISPLAY_INFO_LEN];
fb439640 134
f453ba04
DA
135 /* Physical size */
136 unsigned int width_mm;
137 unsigned int height_mm;
138
f453ba04
DA
139 /* Clock limits FIXME: storage format */
140 unsigned int min_vfreq, max_vfreq;
141 unsigned int min_hfreq, max_hfreq;
142 unsigned int pixel_clock;
3b11228b 143 unsigned int bpc;
f453ba04 144
f453ba04 145 enum subpixel_order subpixel_order;
da05a5a7 146 u32 color_formats;
f453ba04 147
b5571e9d
BB
148 const u32 *bus_formats;
149 unsigned int num_bus_formats;
150
5d02626d
MK
151 /* Mask of supported hdmi deep color modes */
152 u8 edid_hdmi_dc_modes;
153
ebec9a7b 154 u8 cea_rev;
f453ba04
DA
155};
156
138f9ebb
DA
157/* data corresponds to displayid vend/prod/serial */
158struct drm_tile_group {
159 struct kref refcount;
160 struct drm_device *dev;
161 int id;
162 u8 group_data[8];
163};
164
f453ba04 165struct drm_framebuffer_funcs {
f7eff60e 166 /* note: use drm_framebuffer_remove() */
f453ba04
DA
167 void (*destroy)(struct drm_framebuffer *framebuffer);
168 int (*create_handle)(struct drm_framebuffer *fb,
169 struct drm_file *file_priv,
170 unsigned int *handle);
3bf0401c
DV
171 /*
172 * Optional callback for the dirty fb ioctl.
884840aa
JB
173 *
174 * Userspace can notify the driver via this callback
175 * that a area of the framebuffer has changed and should
176 * be flushed to the display hardware.
177 *
178 * See documentation in drm_mode.h for the struct
179 * drm_mode_fb_dirty_cmd for more information as all
180 * the semantics and arguments have a one to one mapping
181 * on this function.
182 */
02b00162
TH
183 int (*dirty)(struct drm_framebuffer *framebuffer,
184 struct drm_file *file_priv, unsigned flags,
884840aa
JB
185 unsigned color, struct drm_clip_rect *clips,
186 unsigned num_clips);
f453ba04
DA
187};
188
189struct drm_framebuffer {
190 struct drm_device *dev;
f7eff60e
RC
191 /*
192 * Note that the fb is refcounted for the benefit of driver internals,
193 * for example some hw, disabling a CRTC/plane is asynchronous, and
194 * scanout does not actually complete until the next vblank. So some
195 * cleanup (like releasing the reference(s) on the backing GEM bo(s))
196 * should be deferred. In cases like this, the driver would like to
197 * hold a ref to the fb even though it has already been removed from
198 * userspace perspective.
199 */
200 struct kref refcount;
4b096ac1
DV
201 /*
202 * Place on the dev->mode_config.fb_list, access protected by
203 * dev->mode_config.fb_lock.
204 */
f453ba04
DA
205 struct list_head head;
206 struct drm_mode_object base;
207 const struct drm_framebuffer_funcs *funcs;
01f2c773
VS
208 unsigned int pitches[4];
209 unsigned int offsets[4];
e3eb3250 210 uint64_t modifier[4];
f453ba04
DA
211 unsigned int width;
212 unsigned int height;
213 /* depth can be 15 or 16 */
214 unsigned int depth;
215 int bits_per_pixel;
216 int flags;
308e5bcb 217 uint32_t pixel_format; /* fourcc format */
f453ba04
DA
218 struct list_head filp_head;
219};
220
221struct drm_property_blob {
222 struct drm_mode_object base;
6bcacf51
DS
223 struct drm_device *dev;
224 struct kref refcount;
e2f5d2ea
DS
225 struct list_head head_global;
226 struct list_head head_file;
ecbbe59b 227 size_t length;
d63f5e6b 228 unsigned char data[];
f453ba04
DA
229};
230
231struct drm_property_enum {
232 uint64_t value;
233 struct list_head head;
234 char name[DRM_PROP_NAME_LEN];
235};
236
237struct drm_property {
238 struct list_head head;
239 struct drm_mode_object base;
240 uint32_t flags;
241 char name[DRM_PROP_NAME_LEN];
242 uint32_t num_values;
243 uint64_t *values;
98f75de4 244 struct drm_device *dev;
f453ba04 245
3758b341 246 struct list_head enum_list;
f453ba04
DA
247};
248
249struct drm_crtc;
250struct drm_connector;
251struct drm_encoder;
d91d8a3f 252struct drm_pending_vblank_event;
8cf5c917 253struct drm_plane;
3b336ec4 254struct drm_bridge;
144ecb97
DV
255struct drm_atomic_state;
256
4490d4c7
DV
257struct drm_crtc_helper_funcs;
258struct drm_encoder_helper_funcs;
259struct drm_connector_helper_funcs;
260struct drm_plane_helper_funcs;
261
144ecb97 262/**
cc4ceb48 263 * struct drm_crtc_state - mutable CRTC state
07cc0ef6 264 * @crtc: backpointer to the CRTC
144ecb97 265 * @enable: whether the CRTC should be enabled, gates all other state
d9b13620 266 * @active: whether the CRTC is actively displaying (used for DPMS)
fc596660
ML
267 * @planes_changed: planes on this crtc are updated
268 * @mode_changed: crtc_state->mode or crtc_state->enable has been changed
269 * @active_changed: crtc_state->active has been toggled.
270 * @connectors_changed: connectors to this crtc have been updated
6ddd388a 271 * @plane_mask: bitmask of (1 << drm_plane_index(plane)) of attached planes
623369e5
DV
272 * @last_vblank_count: for helpers and drivers to capture the vblank of the
273 * update to ensure framebuffer cleanup isn't done too early
2f324b42 274 * @adjusted_mode: for use by helpers and drivers to compute adjusted mode timings
144ecb97
DV
275 * @mode: current mode timings
276 * @event: optional pointer to a DRM event to signal upon completion of the
277 * state update
278 * @state: backpointer to global drm_atomic_state
d9b13620
DV
279 *
280 * Note that the distinction between @enable and @active is rather subtile:
281 * Flipping @active while @enable is set without changing anything else may
282 * never return in a failure from the ->atomic_check callback. Userspace assumes
283 * that a DPMS On will always succeed. In other words: @enable controls resource
284 * assignment, @active controls the actual hardware state.
144ecb97
DV
285 */
286struct drm_crtc_state {
07cc0ef6
DV
287 struct drm_crtc *crtc;
288
cc4ceb48 289 bool enable;
d9b13620 290 bool active;
144ecb97 291
c2fcd274
DV
292 /* computed state bits used by helpers and drivers */
293 bool planes_changed : 1;
623369e5 294 bool mode_changed : 1;
eab3bbef 295 bool active_changed : 1;
fc596660 296 bool connectors_changed : 1;
623369e5 297
6ddd388a
RC
298 /* attached planes bitmask:
299 * WARNING: transitional helpers do not maintain plane_mask so
300 * drivers not converted over to atomic helpers should not rely
301 * on plane_mask being accurate!
302 */
303 u32 plane_mask;
304
623369e5
DV
305 /* last_vblank_count: for vblank waits before cleanup */
306 u32 last_vblank_count;
c2fcd274 307
2f324b42
DV
308 /* adjusted_mode: for use by helpers and drivers */
309 struct drm_display_mode adjusted_mode;
310
144ecb97
DV
311 struct drm_display_mode mode;
312
99cf4a29
DS
313 /* blob property to expose current mode to atomic userspace */
314 struct drm_property_blob *mode_blob;
315
144ecb97
DV
316 struct drm_pending_vblank_event *event;
317
318 struct drm_atomic_state *state;
319};
f453ba04
DA
320
321/**
3bf0401c 322 * struct drm_crtc_funcs - control CRTCs for a given device
3b02ab88 323 * @cursor_set: setup the cursor
2c0c33d4 324 * @cursor_set2: setup the cursor with hotspot, superseeds @cursor_set if set
3b02ab88 325 * @cursor_move: move the cursor
f453ba04 326 * @gamma_set: specify color ramp for CRTC
3b02ab88
LP
327 * @set_config: apply a new CRTC configuration
328 * @page_flip: initiate a page flip
f453ba04
DA
329 *
330 * The drm_crtc_funcs structure is the central CRTC management structure
331 * in the DRM. Each CRTC controls one or more connectors (note that the name
332 * CRTC is simply historical, a CRTC may control LVDS, VGA, DVI, TV out, etc.
333 * connectors, not just CRTs).
334 *
335 * Each driver is responsible for filling out this structure at startup time,
336 * in addition to providing other modesetting features, like i2c and DDC
337 * bus accessors.
338 */
339struct drm_crtc_funcs {
88548636
DV
340 /**
341 * @reset:
342 *
343 * Reset CRTC hardware and software state to off. This function isn't
344 * called by the core directly, only through drm_mode_config_reset().
345 * It's not a helper hook only for historical reasons.
346 *
347 * Atomic drivers can use drm_atomic_helper_crtc_reset() to reset
348 * atomic state using this hook.
349 */
eb033556 350 void (*reset)(struct drm_crtc *crtc);
f453ba04
DA
351
352 /* cursor controls */
353 int (*cursor_set)(struct drm_crtc *crtc, struct drm_file *file_priv,
354 uint32_t handle, uint32_t width, uint32_t height);
4c813d4d
DA
355 int (*cursor_set2)(struct drm_crtc *crtc, struct drm_file *file_priv,
356 uint32_t handle, uint32_t width, uint32_t height,
357 int32_t hot_x, int32_t hot_y);
f453ba04
DA
358 int (*cursor_move)(struct drm_crtc *crtc, int x, int y);
359
360 /* Set gamma on the CRTC */
361 void (*gamma_set)(struct drm_crtc *crtc, u16 *r, u16 *g, u16 *b,
7203425a 362 uint32_t start, uint32_t size);
88548636
DV
363
364 /**
365 * @destroy:
366 *
367 * Clean up plane resources. This is only called at driver unload time
368 * through drm_mode_config_cleanup() since a CRTC cannot be hotplugged
369 * in DRM.
370 */
f453ba04
DA
371 void (*destroy)(struct drm_crtc *crtc);
372
373 int (*set_config)(struct drm_mode_set *set);
d91d8a3f
KH
374
375 /*
376 * Flip to the given framebuffer. This implements the page
25985edc 377 * flip ioctl described in drm_mode.h, specifically, the
d91d8a3f
KH
378 * implementation must return immediately and block all
379 * rendering to the current fb until the flip has completed.
380 * If userspace set the event flag in the ioctl, the event
381 * argument will point to an event to send back when the flip
382 * completes, otherwise it will be NULL.
383 */
384 int (*page_flip)(struct drm_crtc *crtc,
385 struct drm_framebuffer *fb,
ed8d1975
KP
386 struct drm_pending_vblank_event *event,
387 uint32_t flags);
bffd9de0 388
88548636
DV
389 /**
390 * @set_property:
391 *
392 * This is the legacy entry point to update a property attached to the
393 * CRTC.
394 *
395 * Drivers implementing atomic modeset should use
396 * drm_atomic_helper_crtc_set_property() to implement this hook.
397 *
398 * This callback is optional if the driver does not support any legacy
399 * driver-private properties.
400 *
401 * RETURNS:
402 *
403 * 0 on success or a negative error code on failure.
404 */
bffd9de0
PZ
405 int (*set_property)(struct drm_crtc *crtc,
406 struct drm_property *property, uint64_t val);
144ecb97 407
88548636
DV
408 /**
409 * @atomic_duplicate_state:
410 *
411 * Duplicate the current atomic state for this CRTC and return it.
412 * The core and helpers gurantee that any atomic state duplicated with
413 * this hook and still owned by the caller (i.e. not transferred to the
414 * driver by calling ->atomic_commit() from struct
415 * &drm_mode_config_funcs) will be cleaned up by calling the
416 * @atomic_destroy_state hook in this structure.
417 *
418 * Atomic drivers which don't subclass struct &drm_crtc should use
419 * drm_atomic_helper_crtc_duplicate_state(). Drivers that subclass the
420 * state structure to extend it with driver-private state should use
421 * __drm_atomic_helper_crtc_duplicate_state() to make sure shared state is
422 * duplicated in a consistent fashion across drivers.
423 *
424 * It is an error to call this hook before crtc->state has been
425 * initialized correctly.
426 *
427 * NOTE:
428 *
429 * If the duplicate state references refcounted resources this hook must
430 * acquire a reference for each of them. The driver must release these
431 * references again in @atomic_destroy_state.
432 *
433 * RETURNS:
434 *
435 * Duplicated atomic state or NULL when the allocation failed.
436 */
144ecb97 437 struct drm_crtc_state *(*atomic_duplicate_state)(struct drm_crtc *crtc);
88548636
DV
438
439 /**
440 * @atomic_destroy_state:
441 *
442 * Destroy a state duplicated with @atomic_duplicate_state and release
443 * or unreference all resources it references
444 */
144ecb97 445 void (*atomic_destroy_state)(struct drm_crtc *crtc,
cc4ceb48 446 struct drm_crtc_state *state);
88548636
DV
447
448 /**
449 * @atomic_set_property:
450 *
451 * Decode a driver-private property value and store the decoded value
452 * into the passed-in state structure. Since the atomic core decodes all
453 * standardized properties (even for extensions beyond the core set of
454 * properties which might not be implemented by all drivers) this
455 * requires drivers to subclass the state structure.
456 *
457 * Such driver-private properties should really only be implemented for
458 * truly hardware/vendor specific state. Instead it is preferred to
459 * standardize atomic extension and decode the properties used to expose
460 * such an extension in the core.
461 *
462 * Do not call this function directly, use
463 * drm_atomic_crtc_set_property() instead.
464 *
465 * This callback is optional if the driver does not support any
466 * driver-private atomic properties.
467 *
468 * NOTE:
469 *
470 * This function is called in the state assembly phase of atomic
471 * modesets, which can be aborted for any reason (including on
472 * userspace's request to just check whether a configuration would be
473 * possible). Drivers MUST NOT touch any persistent state (hardware or
474 * software) or data structures except the passed in @state parameter.
475 *
476 * Also since userspace controls in which order properties are set this
477 * function must not do any input validation (since the state update is
478 * incomplete and hence likely inconsistent). Instead any such input
479 * validation must be done in the various atomic_check callbacks.
480 *
481 * RETURNS:
482 *
483 * 0 if the property has been found, -EINVAL if the property isn't
484 * implemented by the driver (which should never happen, the core only
485 * asks for properties attached to this CRTC). No other validation is
486 * allowed by the driver. The core already checks that the property
487 * value is within the range (integer, valid enum value, ...) the driver
488 * set when registering the property.
489 */
144ecb97
DV
490 int (*atomic_set_property)(struct drm_crtc *crtc,
491 struct drm_crtc_state *state,
492 struct drm_property *property,
493 uint64_t val);
88548636
DV
494 /**
495 * @atomic_get_property:
496 *
497 * Reads out the decoded driver-private property. This is used to
498 * implement the GETCRTC ioctl.
499 *
500 * Do not call this function directly, use
501 * drm_atomic_crtc_get_property() instead.
502 *
503 * This callback is optional if the driver does not support any
504 * driver-private atomic properties.
505 *
506 * RETURNS:
507 *
508 * 0 on success, -EINVAL if the property isn't implemented by the
509 * driver (which should never happen, the core only asks for
510 * properties attached to this CRTC).
511 */
ac9c9256
RC
512 int (*atomic_get_property)(struct drm_crtc *crtc,
513 const struct drm_crtc_state *state,
514 struct drm_property *property,
515 uint64_t *val);
f453ba04
DA
516};
517
518/**
3bf0401c 519 * struct drm_crtc - central CRTC control structure
7749163e 520 * @dev: parent DRM device
2c0c33d4 521 * @port: OF node used by drm_of_find_possible_crtcs()
7749163e 522 * @head: list management
51fd371b 523 * @mutex: per-CRTC locking
7749163e 524 * @base: base KMS object for ID tracking etc.
e13161af
MR
525 * @primary: primary plane for this CRTC
526 * @cursor: cursor plane for this CRTC
2c0c33d4
DV
527 * @cursor_x: current x position of the cursor, used for universal cursor planes
528 * @cursor_y: current y position of the cursor, used for universal cursor planes
f453ba04 529 * @enabled: is this CRTC enabled?
7749163e
JB
530 * @mode: current mode timings
531 * @hwmode: mode timings as programmed to hw regs
f453ba04
DA
532 * @x: x position on screen
533 * @y: y position on screen
f453ba04 534 * @funcs: CRTC control functions
7749163e
JB
535 * @gamma_size: size of gamma ramp
536 * @gamma_store: gamma ramp values
7749163e 537 * @helper_private: mid-layer private data
bffd9de0 538 * @properties: property tracking for this CRTC
144ecb97 539 * @state: current atomic state for this CRTC
2c0c33d4
DV
540 * @acquire_ctx: per-CRTC implicit acquire context used by atomic drivers for
541 * legacy ioctls
f453ba04
DA
542 *
543 * Each CRTC may have one or more connectors associated with it. This structure
544 * allows the CRTC to be controlled.
545 */
546struct drm_crtc {
547 struct drm_device *dev;
7e435aad 548 struct device_node *port;
f453ba04
DA
549 struct list_head head;
550
3bf0401c 551 /*
29494c17
DV
552 * crtc mutex
553 *
554 * This provides a read lock for the overall crtc state (mode, dpms
555 * state, ...) and a write lock for everything which can be update
556 * without a full modeset (fb, cursor data, ...)
557 */
51fd371b 558 struct drm_modeset_lock mutex;
29494c17 559
f453ba04
DA
560 struct drm_mode_object base;
561
e13161af
MR
562 /* primary and cursor planes for CRTC */
563 struct drm_plane *primary;
564 struct drm_plane *cursor;
565
161d0dc1
MR
566 /* position of cursor plane on crtc */
567 int cursor_x;
568 int cursor_y;
569
f453ba04
DA
570 bool enabled;
571
27641c3f 572 /* Requested mode from modesetting. */
f453ba04
DA
573 struct drm_display_mode mode;
574
27641c3f
MK
575 /* Programmed mode in hw, after adjustments for encoders,
576 * crtc, panel scaling etc. Needed for timestamping etc.
577 */
578 struct drm_display_mode hwmode;
579
f453ba04 580 int x, y;
f453ba04
DA
581 const struct drm_crtc_funcs *funcs;
582
583 /* CRTC gamma size for reporting to userspace */
584 uint32_t gamma_size;
585 uint16_t *gamma_store;
586
587 /* if you are using the helper */
4490d4c7 588 const struct drm_crtc_helper_funcs *helper_private;
bffd9de0
PZ
589
590 struct drm_object_properties properties;
d059f652 591
144ecb97
DV
592 struct drm_crtc_state *state;
593
d059f652
DV
594 /*
595 * For legacy crtc ioctls so that atomic drivers can get at the locking
596 * acquire context.
597 */
598 struct drm_modeset_acquire_ctx *acquire_ctx;
f453ba04
DA
599};
600
144ecb97
DV
601/**
602 * struct drm_connector_state - mutable connector state
07cc0ef6 603 * @connector: backpointer to the connector
cc4ceb48 604 * @crtc: CRTC to connect connector to, NULL if disabled
623369e5 605 * @best_encoder: can be used by helpers and drivers to select the encoder
144ecb97
DV
606 * @state: backpointer to global drm_atomic_state
607 */
608struct drm_connector_state {
07cc0ef6
DV
609 struct drm_connector *connector;
610
6ddd388a 611 struct drm_crtc *crtc; /* do not write directly, use drm_atomic_set_crtc_for_connector() */
144ecb97 612
623369e5
DV
613 struct drm_encoder *best_encoder;
614
144ecb97
DV
615 struct drm_atomic_state *state;
616};
f453ba04
DA
617
618/**
3bf0401c 619 * struct drm_connector_funcs - control connectors on a given device
261ea74f 620 * @dpms: set power state
f453ba04 621 * @detect: is this connector active?
3b02ab88 622 * @fill_modes: fill mode list for this connector
13bcf01b 623 * @force: notify the driver that the connector is forced on
144ecb97 624 *
f453ba04
DA
625 * Each CRTC may have one or more connectors attached to it. The functions
626 * below allow the core DRM code to control connectors, enumerate available modes,
627 * etc.
628 */
629struct drm_connector_funcs {
9a69a9ac 630 int (*dpms)(struct drm_connector *connector, int mode);
88548636
DV
631
632 /**
633 * @reset:
634 *
635 * Reset connector hardware and software state to off. This function isn't
636 * called by the core directly, only through drm_mode_config_reset().
637 * It's not a helper hook only for historical reasons.
638 *
639 * Atomic drivers can use drm_atomic_helper_connector_reset() to reset
640 * atomic state using this hook.
641 */
eb033556 642 void (*reset)(struct drm_connector *connector);
930a9e28
CW
643
644 /* Check to see if anything is attached to the connector.
645 * @force is set to false whilst polling, true when checking the
646 * connector due to user request. @force can be used by the driver
647 * to avoid expensive, destructive operations during automated
648 * probing.
649 */
7b334fcb 650 enum drm_connector_status (*detect)(struct drm_connector *connector,
930a9e28 651 bool force);
40a518d9 652 int (*fill_modes)(struct drm_connector *connector, uint32_t max_width, uint32_t max_height);
88548636
DV
653
654 /**
655 * @set_property:
656 *
657 * This is the legacy entry point to update a property attached to the
658 * connector.
659 *
660 * Drivers implementing atomic modeset should use
661 * drm_atomic_helper_connector_set_property() to implement this hook.
662 *
663 * This callback is optional if the driver does not support any legacy
664 * driver-private properties.
665 *
666 * RETURNS:
667 *
668 * 0 on success or a negative error code on failure.
669 */
f453ba04
DA
670 int (*set_property)(struct drm_connector *connector, struct drm_property *property,
671 uint64_t val);
88548636
DV
672
673 /**
674 * @destroy:
675 *
676 * Clean up connector resources. This is called at driver unload time
677 * through drm_mode_config_cleanup(). It can also be called at runtime
678 * when a connector is being hot-unplugged for drivers that support
679 * connector hotplugging (e.g. DisplayPort MST).
680 */
f453ba04 681 void (*destroy)(struct drm_connector *connector);
d50ba256 682 void (*force)(struct drm_connector *connector);
144ecb97 683
88548636
DV
684 /**
685 * @atomic_duplicate_state:
686 *
687 * Duplicate the current atomic state for this connector and return it.
688 * The core and helpers gurantee that any atomic state duplicated with
689 * this hook and still owned by the caller (i.e. not transferred to the
690 * driver by calling ->atomic_commit() from struct
691 * &drm_mode_config_funcs) will be cleaned up by calling the
692 * @atomic_destroy_state hook in this structure.
693 *
694 * Atomic drivers which don't subclass struct &drm_connector_state should use
695 * drm_atomic_helper_connector_duplicate_state(). Drivers that subclass the
696 * state structure to extend it with driver-private state should use
697 * __drm_atomic_helper_connector_duplicate_state() to make sure shared state is
698 * duplicated in a consistent fashion across drivers.
699 *
700 * It is an error to call this hook before connector->state has been
701 * initialized correctly.
702 *
703 * NOTE:
704 *
705 * If the duplicate state references refcounted resources this hook must
706 * acquire a reference for each of them. The driver must release these
707 * references again in @atomic_destroy_state.
708 *
709 * RETURNS:
710 *
711 * Duplicated atomic state or NULL when the allocation failed.
712 */
144ecb97 713 struct drm_connector_state *(*atomic_duplicate_state)(struct drm_connector *connector);
88548636
DV
714
715 /**
716 * @atomic_destroy_state:
717 *
718 * Destroy a state duplicated with @atomic_duplicate_state and release
719 * or unreference all resources it references
720 */
144ecb97 721 void (*atomic_destroy_state)(struct drm_connector *connector,
cc4ceb48 722 struct drm_connector_state *state);
88548636
DV
723
724 /**
725 * @atomic_set_property:
726 *
727 * Decode a driver-private property value and store the decoded value
728 * into the passed-in state structure. Since the atomic core decodes all
729 * standardized properties (even for extensions beyond the core set of
730 * properties which might not be implemented by all drivers) this
731 * requires drivers to subclass the state structure.
732 *
733 * Such driver-private properties should really only be implemented for
734 * truly hardware/vendor specific state. Instead it is preferred to
735 * standardize atomic extension and decode the properties used to expose
736 * such an extension in the core.
737 *
738 * Do not call this function directly, use
739 * drm_atomic_connector_set_property() instead.
740 *
741 * This callback is optional if the driver does not support any
742 * driver-private atomic properties.
743 *
744 * NOTE:
745 *
746 * This function is called in the state assembly phase of atomic
747 * modesets, which can be aborted for any reason (including on
748 * userspace's request to just check whether a configuration would be
749 * possible). Drivers MUST NOT touch any persistent state (hardware or
750 * software) or data structures except the passed in @state parameter.
751 *
752 * Also since userspace controls in which order properties are set this
753 * function must not do any input validation (since the state update is
754 * incomplete and hence likely inconsistent). Instead any such input
755 * validation must be done in the various atomic_check callbacks.
756 *
757 * RETURNS:
758 *
759 * 0 if the property has been found, -EINVAL if the property isn't
760 * implemented by the driver (which shouldn't ever happen, the core only
761 * asks for properties attached to this connector). No other validation
762 * is allowed by the driver. The core already checks that the property
763 * value is within the range (integer, valid enum value, ...) the driver
764 * set when registering the property.
765 */
144ecb97
DV
766 int (*atomic_set_property)(struct drm_connector *connector,
767 struct drm_connector_state *state,
768 struct drm_property *property,
769 uint64_t val);
88548636
DV
770
771 /**
772 * @atomic_get_property:
773 *
774 * Reads out the decoded driver-private property. This is used to
775 * implement the GETCONNECTOR ioctl.
776 *
777 * Do not call this function directly, use
778 * drm_atomic_connector_get_property() instead.
779 *
780 * This callback is optional if the driver does not support any
781 * driver-private atomic properties.
782 *
783 * RETURNS:
784 *
785 * 0 on success, -EINVAL if the property isn't implemented by the
786 * driver (which shouldn't ever happen, the core only asks for
787 * properties attached to this connector).
788 */
ac9c9256
RC
789 int (*atomic_get_property)(struct drm_connector *connector,
790 const struct drm_connector_state *state,
791 struct drm_property *property,
792 uint64_t *val);
f453ba04
DA
793};
794
6c3db920 795/**
3bf0401c 796 * struct drm_encoder_funcs - encoder controls
6c3db920
JB
797 *
798 * Encoders sit between CRTCs and connectors.
799 */
f453ba04 800struct drm_encoder_funcs {
88548636
DV
801 /**
802 * @reset:
803 *
804 * Reset encoder hardware and software state to off. This function isn't
805 * called by the core directly, only through drm_mode_config_reset().
806 * It's not a helper hook only for historical reasons.
807 */
eb033556 808 void (*reset)(struct drm_encoder *encoder);
88548636
DV
809
810 /**
811 * @destroy:
812 *
813 * Clean up encoder resources. This is only called at driver unload time
814 * through drm_mode_config_cleanup() since an encoder cannot be
815 * hotplugged in DRM.
816 */
f453ba04
DA
817 void (*destroy)(struct drm_encoder *encoder);
818};
819
afe887df 820#define DRM_CONNECTOR_MAX_ENCODER 3
f453ba04
DA
821
822/**
3bf0401c 823 * struct drm_encoder - central DRM encoder structure
db3e4499
JB
824 * @dev: parent DRM device
825 * @head: list management
826 * @base: base KMS object
e5748946 827 * @name: encoder name
db3e4499
JB
828 * @encoder_type: one of the %DRM_MODE_ENCODER_<foo> types in drm_mode.h
829 * @possible_crtcs: bitmask of potential CRTC bindings
830 * @possible_clones: bitmask of potential sibling encoders for cloning
831 * @crtc: currently bound CRTC
3b336ec4 832 * @bridge: bridge associated to the encoder
db3e4499
JB
833 * @funcs: control functions
834 * @helper_private: mid-layer private data
835 *
836 * CRTCs drive pixels to encoders, which convert them into signals
837 * appropriate for a given connector or set of connectors.
f453ba04
DA
838 */
839struct drm_encoder {
840 struct drm_device *dev;
841 struct list_head head;
842
843 struct drm_mode_object base;
e5748946 844 char *name;
f453ba04
DA
845 int encoder_type;
846 uint32_t possible_crtcs;
847 uint32_t possible_clones;
848
849 struct drm_crtc *crtc;
3b336ec4 850 struct drm_bridge *bridge;
f453ba04 851 const struct drm_encoder_funcs *funcs;
4490d4c7 852 const struct drm_encoder_helper_funcs *helper_private;
f453ba04
DA
853};
854
eb1f8e4f
DA
855/* should we poll this connector for connects and disconnects */
856/* hot plug detectable */
857#define DRM_CONNECTOR_POLL_HPD (1 << 0)
858/* poll for connections */
859#define DRM_CONNECTOR_POLL_CONNECT (1 << 1)
860/* can cleanly poll for disconnections without flickering the screen */
861/* DACs should rarely do this without a lot of testing */
862#define DRM_CONNECTOR_POLL_DISCONNECT (1 << 2)
863
76adaa34
WF
864#define MAX_ELD_BYTES 128
865
f453ba04 866/**
3bf0401c 867 * struct drm_connector - central DRM connector control structure
72252548
JB
868 * @dev: parent DRM device
869 * @kdev: kernel device for sysfs attributes
870 * @attr: sysfs attributes
871 * @head: list management
872 * @base: base KMS object
2abdd313 873 * @name: connector name
72252548
JB
874 * @connector_type: one of the %DRM_MODE_CONNECTOR_<foo> types from drm_mode.h
875 * @connector_type_id: index into connector type enum
f453ba04
DA
876 * @interlace_allowed: can this connector handle interlaced modes?
877 * @doublescan_allowed: can this connector handle doublescan?
2c0c33d4 878 * @stereo_allowed: can this connector handle stereo modes?
72252548
JB
879 * @modes: modes available on this connector (from fill_modes() + user)
880 * @status: one of the drm_connector_status enums (connected, not, or unknown)
881 * @probed_modes: list of modes derived directly from the display
882 * @display_info: information about attached display (e.g. from EDID)
f453ba04 883 * @funcs: connector control functions
72252548 884 * @edid_blob_ptr: DRM property containing EDID if present
7e3bdf4a 885 * @properties: property tracking for this connector
2c0c33d4 886 * @path_blob_ptr: DRM blob property data for the DP MST path property
72252548
JB
887 * @polled: a %DRM_CONNECTOR_POLL_<foo> value for core driven polling
888 * @dpms: current dpms state
889 * @helper_private: mid-layer private data
2c0c33d4 890 * @cmdline_mode: mode line parsed from the kernel cmdline for this connector
72252548 891 * @force: a %DRM_FORCE_<foo> state for forced mode sets
2c0c33d4 892 * @override_edid: has the EDID been overwritten through debugfs for testing?
72252548
JB
893 * @encoder_ids: valid encoders for this connector
894 * @encoder: encoder driving this connector, if any
895 * @eld: EDID-like data, if present
896 * @dvi_dual: dual link DVI, if found
897 * @max_tmds_clock: max clock rate, if found
898 * @latency_present: AV delay info from ELD, if found
899 * @video_latency: video latency info from ELD, if found
900 * @audio_latency: audio latency info from ELD, if found
901 * @null_edid_counter: track sinks that give us all zeros for the EDID
2c0c33d4 902 * @bad_edid_counter: track sinks that give us an EDID with invalid checksum
ac6f2e29 903 * @edid_corrupt: indicates whether the last read EDID was corrupt
2c0c33d4 904 * @debugfs_entry: debugfs directory for this connector
144ecb97 905 * @state: current atomic state for this connector
40d9b043
DA
906 * @has_tile: is this connector connected to a tiled monitor
907 * @tile_group: tile group for the connected monitor
908 * @tile_is_single_monitor: whether the tile is one monitor housing
909 * @num_h_tile: number of horizontal tiles in the tile group
910 * @num_v_tile: number of vertical tiles in the tile group
911 * @tile_h_loc: horizontal location of this tile
912 * @tile_v_loc: vertical location of this tile
913 * @tile_h_size: horizontal size of this tile.
914 * @tile_v_size: vertical size of this tile.
f453ba04
DA
915 *
916 * Each connector may be connected to one or more CRTCs, or may be clonable by
917 * another connector if they can share a CRTC. Each connector also has a specific
918 * position in the broader display (referred to as a 'screen' though it could
919 * span multiple monitors).
920 */
921struct drm_connector {
922 struct drm_device *dev;
5bdebb18 923 struct device *kdev;
f453ba04
DA
924 struct device_attribute *attr;
925 struct list_head head;
926
927 struct drm_mode_object base;
928
2abdd313 929 char *name;
f453ba04
DA
930 int connector_type;
931 int connector_type_id;
932 bool interlace_allowed;
933 bool doublescan_allowed;
560a067a 934 bool stereo_allowed;
f453ba04
DA
935 struct list_head modes; /* list of modes on this connector */
936
f453ba04
DA
937 enum drm_connector_status status;
938
939 /* these are modes added by probing with DDC or the BIOS */
940 struct list_head probed_modes;
941
942 struct drm_display_info display_info;
943 const struct drm_connector_funcs *funcs;
944
f453ba04 945 struct drm_property_blob *edid_blob_ptr;
7e3bdf4a 946 struct drm_object_properties properties;
f453ba04 947
43aba7eb
DA
948 struct drm_property_blob *path_blob_ptr;
949
6f134d7b
DA
950 struct drm_property_blob *tile_blob_ptr;
951
eb1f8e4f
DA
952 uint8_t polled; /* DRM_CONNECTOR_POLL_* */
953
c9fb15f6
KP
954 /* requested DPMS state */
955 int dpms;
956
4490d4c7 957 const struct drm_connector_helper_funcs *helper_private;
f453ba04 958
d50ba256 959 /* forced on connector */
eaf99c74 960 struct drm_cmdline_mode cmdline_mode;
d50ba256 961 enum drm_connector_force force;
4cf2b281 962 bool override_edid;
f453ba04 963 uint32_t encoder_ids[DRM_CONNECTOR_MAX_ENCODER];
f453ba04 964 struct drm_encoder *encoder; /* currently active encoder */
4a9a8b71 965
76adaa34
WF
966 /* EDID bits */
967 uint8_t eld[MAX_ELD_BYTES];
968 bool dvi_dual;
969 int max_tmds_clock; /* in MHz */
970 bool latency_present[2];
971 int video_latency[2]; /* [0]: progressive, [1]: interlaced */
972 int audio_latency[2];
4a9a8b71 973 int null_edid_counter; /* needed to workaround some HW bugs where we get all 0s */
0b2443ed 974 unsigned bad_edid_counter;
30f65707 975
6ba2bd3d
TP
976 /* Flag for raw EDID header corruption - used in Displayport
977 * compliance testing - * Displayport Link CTS Core 1.2 rev1.1 4.2.2.6
978 */
979 bool edid_corrupt;
980
30f65707 981 struct dentry *debugfs_entry;
144ecb97
DV
982
983 struct drm_connector_state *state;
40d9b043
DA
984
985 /* DisplayID bits */
986 bool has_tile;
987 struct drm_tile_group *tile_group;
988 bool tile_is_single_monitor;
989
990 uint8_t num_h_tile, num_v_tile;
991 uint8_t tile_h_loc, tile_v_loc;
992 uint16_t tile_h_size, tile_v_size;
144ecb97
DV
993};
994
995/**
996 * struct drm_plane_state - mutable plane state
07cc0ef6 997 * @plane: backpointer to the plane
144ecb97 998 * @crtc: currently bound CRTC, NULL if disabled
cc4ceb48 999 * @fb: currently bound framebuffer
e2330f07 1000 * @fence: optional fence to wait for before scanning out @fb
144ecb97
DV
1001 * @crtc_x: left position of visible portion of plane on crtc
1002 * @crtc_y: upper position of visible portion of plane on crtc
1003 * @crtc_w: width of visible portion of plane on crtc
1004 * @crtc_h: height of visible portion of plane on crtc
1005 * @src_x: left position of visible portion of plane within
1006 * plane (in 16.16)
1007 * @src_y: upper position of visible portion of plane within
1008 * plane (in 16.16)
1009 * @src_w: width of visible portion of plane (in 16.16)
1010 * @src_h: height of visible portion of plane (in 16.16)
1011 * @state: backpointer to global drm_atomic_state
1012 */
1013struct drm_plane_state {
07cc0ef6
DV
1014 struct drm_plane *plane;
1015
6ddd388a
RC
1016 struct drm_crtc *crtc; /* do not write directly, use drm_atomic_set_crtc_for_plane() */
1017 struct drm_framebuffer *fb; /* do not write directly, use drm_atomic_set_fb_for_plane() */
e2330f07 1018 struct fence *fence;
144ecb97
DV
1019
1020 /* Signed dest location allows it to be partially off screen */
1021 int32_t crtc_x, crtc_y;
1022 uint32_t crtc_w, crtc_h;
1023
1024 /* Source values are 16.16 fixed point */
1025 uint32_t src_x, src_y;
1026 uint32_t src_h, src_w;
1027
1da30627
MR
1028 /* Plane rotation */
1029 unsigned int rotation;
1030
144ecb97 1031 struct drm_atomic_state *state;
f453ba04
DA
1032};
1033
144ecb97 1034
8cf5c917 1035/**
3bf0401c 1036 * struct drm_plane_funcs - driver plane control functions
8cf5c917
JB
1037 */
1038struct drm_plane_funcs {
88548636
DV
1039 /**
1040 * @update_plane:
1041 *
1042 * This is the legacy entry point to enable and configure the plane for
1043 * the given CRTC and framebuffer. It is never called to disable the
1044 * plane, i.e. the passed-in crtc and fb paramters are never NULL.
1045 *
1046 * The source rectangle in frame buffer memory coordinates is given by
1047 * the src_x, src_y, src_w and src_h parameters (as 16.16 fixed point
1048 * values). Devices that don't support subpixel plane coordinates can
1049 * ignore the fractional part.
1050 *
1051 * The destination rectangle in CRTC coordinates is given by the
1052 * crtc_x, crtc_y, crtc_w and crtc_h parameters (as integer values).
1053 * Devices scale the source rectangle to the destination rectangle. If
1054 * scaling is not supported, and the source rectangle size doesn't match
1055 * the destination rectangle size, the driver must return a
1056 * -<errorname>EINVAL</errorname> error.
1057 *
1058 * Drivers implementing atomic modeset should use
1059 * drm_atomic_helper_update_plane() to implement this hook.
1060 *
1061 * RETURNS:
1062 *
1063 * 0 on success or a negative error code on failure.
1064 */
8cf5c917
JB
1065 int (*update_plane)(struct drm_plane *plane,
1066 struct drm_crtc *crtc, struct drm_framebuffer *fb,
1067 int crtc_x, int crtc_y,
1068 unsigned int crtc_w, unsigned int crtc_h,
1069 uint32_t src_x, uint32_t src_y,
1070 uint32_t src_w, uint32_t src_h);
88548636
DV
1071
1072 /**
1073 * @disable_plane:
1074 *
1075 * This is the legacy entry point to disable the plane. The DRM core
1076 * calls this method in response to a DRM_IOCTL_MODE_SETPLANE ioctl call
1077 * with the frame buffer ID set to 0. Disabled planes must not be
1078 * processed by the CRTC.
1079 *
1080 * Drivers implementing atomic modeset should use
1081 * drm_atomic_helper_disable_plane() to implement this hook.
1082 *
1083 * RETURNS:
1084 *
1085 * 0 on success or a negative error code on failure.
1086 */
8cf5c917 1087 int (*disable_plane)(struct drm_plane *plane);
88548636
DV
1088
1089 /**
1090 * @destroy:
1091 *
1092 * Clean up plane resources. This is only called at driver unload time
1093 * through drm_mode_config_cleanup() since a plane cannot be hotplugged
1094 * in DRM.
1095 */
8cf5c917 1096 void (*destroy)(struct drm_plane *plane);
88548636
DV
1097
1098 /**
1099 * @reset:
1100 *
1101 * Reset plane hardware and software state to off. This function isn't
1102 * called by the core directly, only through drm_mode_config_reset().
1103 * It's not a helper hook only for historical reasons.
1104 *
1105 * Atomic drivers can use drm_atomic_helper_plane_reset() to reset
1106 * atomic state using this hook.
1107 */
2a0d7cfd 1108 void (*reset)(struct drm_plane *plane);
4d93914a 1109
88548636
DV
1110 /**
1111 * @set_property:
1112 *
1113 * This is the legacy entry point to update a property attached to the
1114 * plane.
1115 *
1116 * Drivers implementing atomic modeset should use
1117 * drm_atomic_helper_plane_set_property() to implement this hook.
1118 *
1119 * This callback is optional if the driver does not support any legacy
1120 * driver-private properties.
1121 *
1122 * RETURNS:
1123 *
1124 * 0 on success or a negative error code on failure.
1125 */
4d93914a
RC
1126 int (*set_property)(struct drm_plane *plane,
1127 struct drm_property *property, uint64_t val);
144ecb97 1128
88548636
DV
1129 /**
1130 * @atomic_duplicate_state:
1131 *
1132 * Duplicate the current atomic state for this plane and return it.
1133 * The core and helpers gurantee that any atomic state duplicated with
1134 * this hook and still owned by the caller (i.e. not transferred to the
1135 * driver by calling ->atomic_commit() from struct
1136 * &drm_mode_config_funcs) will be cleaned up by calling the
1137 * @atomic_destroy_state hook in this structure.
1138 *
1139 * Atomic drivers which don't subclass struct &drm_plane_state should use
1140 * drm_atomic_helper_plane_duplicate_state(). Drivers that subclass the
1141 * state structure to extend it with driver-private state should use
1142 * __drm_atomic_helper_plane_duplicate_state() to make sure shared state is
1143 * duplicated in a consistent fashion across drivers.
1144 *
1145 * It is an error to call this hook before plane->state has been
1146 * initialized correctly.
1147 *
1148 * NOTE:
1149 *
1150 * If the duplicate state references refcounted resources this hook must
1151 * acquire a reference for each of them. The driver must release these
1152 * references again in @atomic_destroy_state.
1153 *
1154 * RETURNS:
1155 *
1156 * Duplicated atomic state or NULL when the allocation failed.
1157 */
144ecb97 1158 struct drm_plane_state *(*atomic_duplicate_state)(struct drm_plane *plane);
88548636
DV
1159
1160 /**
1161 * @atomic_destroy_state:
1162 *
1163 * Destroy a state duplicated with @atomic_duplicate_state and release
1164 * or unreference all resources it references
1165 */
144ecb97 1166 void (*atomic_destroy_state)(struct drm_plane *plane,
cc4ceb48 1167 struct drm_plane_state *state);
88548636
DV
1168
1169 /**
1170 * @atomic_set_property:
1171 *
1172 * Decode a driver-private property value and store the decoded value
1173 * into the passed-in state structure. Since the atomic core decodes all
1174 * standardized properties (even for extensions beyond the core set of
1175 * properties which might not be implemented by all drivers) this
1176 * requires drivers to subclass the state structure.
1177 *
1178 * Such driver-private properties should really only be implemented for
1179 * truly hardware/vendor specific state. Instead it is preferred to
1180 * standardize atomic extension and decode the properties used to expose
1181 * such an extension in the core.
1182 *
1183 * Do not call this function directly, use
1184 * drm_atomic_plane_set_property() instead.
1185 *
1186 * This callback is optional if the driver does not support any
1187 * driver-private atomic properties.
1188 *
1189 * NOTE:
1190 *
1191 * This function is called in the state assembly phase of atomic
1192 * modesets, which can be aborted for any reason (including on
1193 * userspace's request to just check whether a configuration would be
1194 * possible). Drivers MUST NOT touch any persistent state (hardware or
1195 * software) or data structures except the passed in @state parameter.
1196 *
1197 * Also since userspace controls in which order properties are set this
1198 * function must not do any input validation (since the state update is
1199 * incomplete and hence likely inconsistent). Instead any such input
1200 * validation must be done in the various atomic_check callbacks.
1201 *
1202 * RETURNS:
1203 *
1204 * 0 if the property has been found, -EINVAL if the property isn't
1205 * implemented by the driver (which shouldn't ever happen, the core only
1206 * asks for properties attached to this plane). No other validation is
1207 * allowed by the driver. The core already checks that the property
1208 * value is within the range (integer, valid enum value, ...) the driver
1209 * set when registering the property.
1210 */
144ecb97
DV
1211 int (*atomic_set_property)(struct drm_plane *plane,
1212 struct drm_plane_state *state,
1213 struct drm_property *property,
1214 uint64_t val);
88548636
DV
1215
1216 /**
1217 * @atomic_get_property:
1218 *
1219 * Reads out the decoded driver-private property. This is used to
1220 * implement the GETPLANE ioctl.
1221 *
1222 * Do not call this function directly, use
1223 * drm_atomic_plane_get_property() instead.
1224 *
1225 * This callback is optional if the driver does not support any
1226 * driver-private atomic properties.
1227 *
1228 * RETURNS:
1229 *
1230 * 0 on success, -EINVAL if the property isn't implemented by the
1231 * driver (which should never happen, the core only asks for
1232 * properties attached to this plane).
1233 */
ac9c9256
RC
1234 int (*atomic_get_property)(struct drm_plane *plane,
1235 const struct drm_plane_state *state,
1236 struct drm_property *property,
1237 uint64_t *val);
8cf5c917
JB
1238};
1239
e27dde3e
MR
1240enum drm_plane_type {
1241 DRM_PLANE_TYPE_OVERLAY,
1242 DRM_PLANE_TYPE_PRIMARY,
1243 DRM_PLANE_TYPE_CURSOR,
1244};
1245
88548636 1246
8cf5c917 1247/**
3bf0401c 1248 * struct drm_plane - central DRM plane control structure
8cf5c917
JB
1249 * @dev: DRM device this plane belongs to
1250 * @head: for list management
1251 * @base: base mode object
1252 * @possible_crtcs: pipes this plane can be bound to
1253 * @format_types: array of formats supported by this plane
1254 * @format_count: number of formats supported
7eb5f302 1255 * @format_default: driver hasn't supplied supported formats for the plane
8cf5c917
JB
1256 * @crtc: currently bound CRTC
1257 * @fb: currently bound fb
2c0c33d4
DV
1258 * @old_fb: Temporary tracking of the old fb while a modeset is ongoing. Used by
1259 * drm_mode_set_config_internal() to implement correct refcounting.
8cf5c917 1260 * @funcs: helper functions
4d93914a 1261 * @properties: property tracking for this plane
e27dde3e 1262 * @type: type of plane (overlay, primary, cursor)
144ecb97 1263 * @state: current atomic state for this plane
8cf5c917
JB
1264 */
1265struct drm_plane {
1266 struct drm_device *dev;
1267 struct list_head head;
1268
4d02e2de
DV
1269 struct drm_modeset_lock mutex;
1270
8cf5c917
JB
1271 struct drm_mode_object base;
1272
1273 uint32_t possible_crtcs;
1274 uint32_t *format_types;
45e3743a 1275 unsigned int format_count;
7eb5f302 1276 bool format_default;
8cf5c917
JB
1277
1278 struct drm_crtc *crtc;
1279 struct drm_framebuffer *fb;
1280
3d30a59b
DV
1281 struct drm_framebuffer *old_fb;
1282
8cf5c917 1283 const struct drm_plane_funcs *funcs;
4d93914a
RC
1284
1285 struct drm_object_properties properties;
e27dde3e
MR
1286
1287 enum drm_plane_type type;
144ecb97 1288
4490d4c7 1289 const struct drm_plane_helper_funcs *helper_private;
c2fcd274 1290
144ecb97 1291 struct drm_plane_state *state;
8cf5c917
JB
1292};
1293
3b336ec4 1294/**
3bf0401c 1295 * struct drm_bridge_funcs - drm_bridge control functions
3d3f8b1f 1296 * @attach: Called during drm_bridge_attach
3b336ec4
SP
1297 */
1298struct drm_bridge_funcs {
3d3f8b1f 1299 int (*attach)(struct drm_bridge *bridge);
da024fe5
DV
1300
1301 /**
1302 * @mode_fixup:
1303 *
1304 * This callback is used to validate and adjust a mode. The paramater
1305 * mode is the display mode that should be fed to the next element in
1306 * the display chain, either the final &drm_connector or the next
1307 * &drm_bridge. The parameter adjusted_mode is the input mode the bridge
1308 * requires. It can be modified by this callback and does not need to
1309 * match mode.
1310 *
1311 * This is the only hook that allows a bridge to reject a modeset. If
1312 * this function passes all other callbacks must succeed for this
1313 * configuration.
1314 *
1315 * NOTE:
1316 *
1317 * This function is called in the check phase of atomic modesets, which
1318 * can be aborted for any reason (including on userspace's request to
1319 * just check whether a configuration would be possible). Drivers MUST
1320 * NOT touch any persistent state (hardware or software) or data
88548636 1321 * structures except the passed in @state parameter.
da024fe5
DV
1322 *
1323 * RETURNS:
1324 *
1325 * True if an acceptable configuration is possible, false if the modeset
1326 * operation should be rejected.
1327 */
3b336ec4
SP
1328 bool (*mode_fixup)(struct drm_bridge *bridge,
1329 const struct drm_display_mode *mode,
1330 struct drm_display_mode *adjusted_mode);
da024fe5
DV
1331 /**
1332 * @disable:
1333 *
1334 * This callback should disable the bridge. It is called right before
1335 * the preceding element in the display pipe is disabled. If the
1336 * preceding element is a bridge this means it's called before that
1337 * bridge's ->disable() function. If the preceding element is a
1338 * &drm_encoder it's called right before the encoder's ->disable(),
1339 * ->prepare() or ->dpms() hook from struct &drm_encoder_helper_funcs.
1340 *
1341 * The bridge can assume that the display pipe (i.e. clocks and timing
1342 * signals) feeding it is still running when this callback is called.
1343 */
3b336ec4 1344 void (*disable)(struct drm_bridge *bridge);
da024fe5
DV
1345
1346 /**
1347 * @post_disable:
1348 *
1349 * This callback should disable the bridge. It is called right after
1350 * the preceding element in the display pipe is disabled. If the
1351 * preceding element is a bridge this means it's called after that
1352 * bridge's ->post_disable() function. If the preceding element is a
1353 * &drm_encoder it's called right after the encoder's ->disable(),
1354 * ->prepare() or ->dpms() hook from struct &drm_encoder_helper_funcs.
1355 *
1356 * The bridge must assume that the display pipe (i.e. clocks and timing
1357 * singals) feeding it is no longer running when this callback is
1358 * called.
1359 */
3b336ec4 1360 void (*post_disable)(struct drm_bridge *bridge);
da024fe5
DV
1361
1362 /**
1363 * @mode_set:
1364 *
1365 * This callback should set the given mode on the bridge. It is called
1366 * after the ->mode_set() callback for the preceding element in the
1367 * display pipeline has been called already. The display pipe (i.e.
1368 * clocks and timing signals) is off when this function is called.
1369 */
3b336ec4
SP
1370 void (*mode_set)(struct drm_bridge *bridge,
1371 struct drm_display_mode *mode,
1372 struct drm_display_mode *adjusted_mode);
da024fe5
DV
1373 /**
1374 * @pre_enable:
1375 *
1376 * This callback should enable the bridge. It is called right before
1377 * the preceding element in the display pipe is enabled. If the
1378 * preceding element is a bridge this means it's called before that
1379 * bridge's ->pre_enable() function. If the preceding element is a
1380 * &drm_encoder it's called right before the encoder's ->enable(),
1381 * ->commit() or ->dpms() hook from struct &drm_encoder_helper_funcs.
1382 *
1383 * The display pipe (i.e. clocks and timing signals) feeding this bridge
1384 * will not yet be running when this callback is called. The bridge must
1385 * not enable the display link feeding the next bridge in the chain (if
1386 * there is one) when this callback is called.
1387 */
3b336ec4 1388 void (*pre_enable)(struct drm_bridge *bridge);
da024fe5
DV
1389
1390 /**
1391 * @enable:
1392 *
1393 * This callback should enable the bridge. It is called right after
1394 * the preceding element in the display pipe is enabled. If the
1395 * preceding element is a bridge this means it's called after that
1396 * bridge's ->enable() function. If the preceding element is a
1397 * &drm_encoder it's called right after the encoder's ->enable(),
1398 * ->commit() or ->dpms() hook from struct &drm_encoder_helper_funcs.
1399 *
1400 * The bridge can assume that the display pipe (i.e. clocks and timing
1401 * signals) feeding it is running when this callback is called. This
1402 * callback must enable the display link feeding the next bridge in the
1403 * chain if there is one.
1404 */
3b336ec4 1405 void (*enable)(struct drm_bridge *bridge);
3b336ec4
SP
1406};
1407
1408/**
3bf0401c 1409 * struct drm_bridge - central DRM bridge control structure
3b336ec4 1410 * @dev: DRM device this bridge belongs to
862e686c
AT
1411 * @encoder: encoder to which this bridge is connected
1412 * @next: the next bridge in the encoder chain
3d3f8b1f
AK
1413 * @of_node: device node pointer to the bridge
1414 * @list: to keep track of all added bridges
3b336ec4
SP
1415 * @funcs: control functions
1416 * @driver_private: pointer to the bridge driver's internal context
1417 */
1418struct drm_bridge {
1419 struct drm_device *dev;
3d3f8b1f 1420 struct drm_encoder *encoder;
862e686c 1421 struct drm_bridge *next;
3d3f8b1f
AK
1422#ifdef CONFIG_OF
1423 struct device_node *of_node;
1424#endif
1425 struct list_head list;
3b336ec4
SP
1426
1427 const struct drm_bridge_funcs *funcs;
1428 void *driver_private;
1429};
1430
cc4ceb48 1431/**
08855fae 1432 * struct drm_atomic_state - the global state object for atomic updates
cc4ceb48 1433 * @dev: parent DRM device
d34f20d6 1434 * @allow_modeset: allow full modeset
f02ad907 1435 * @legacy_cursor_update: hint to enforce legacy cursor ioctl semantics
cc4ceb48
DV
1436 * @planes: pointer to array of plane pointers
1437 * @plane_states: pointer to array of plane states pointers
1438 * @crtcs: pointer to array of CRTC pointers
1439 * @crtc_states: pointer to array of CRTC states pointers
f52b69f1 1440 * @num_connector: size of the @connectors and @connector_states arrays
cc4ceb48
DV
1441 * @connectors: pointer to array of connector pointers
1442 * @connector_states: pointer to array of connector states pointers
1443 * @acquire_ctx: acquire context for this atomic modeset state update
1444 */
1445struct drm_atomic_state {
1446 struct drm_device *dev;
d34f20d6 1447 bool allow_modeset : 1;
f02ad907 1448 bool legacy_cursor_update : 1;
cc4ceb48
DV
1449 struct drm_plane **planes;
1450 struct drm_plane_state **plane_states;
1451 struct drm_crtc **crtcs;
1452 struct drm_crtc_state **crtc_states;
f52b69f1 1453 int num_connector;
cc4ceb48
DV
1454 struct drm_connector **connectors;
1455 struct drm_connector_state **connector_states;
1456
1457 struct drm_modeset_acquire_ctx *acquire_ctx;
1458};
1459
1460
f453ba04 1461/**
3bf0401c 1462 * struct drm_mode_set - new values for a CRTC config change
ef27351a
JB
1463 * @fb: framebuffer to use for new config
1464 * @crtc: CRTC whose configuration we're about to change
1465 * @mode: mode timings to use
1466 * @x: position of this CRTC relative to @fb
1467 * @y: position of this CRTC relative to @fb
1468 * @connectors: array of connectors to drive with this CRTC if possible
1469 * @num_connectors: size of @connectors array
f453ba04
DA
1470 *
1471 * Represents a single crtc the connectors that it drives with what mode
1472 * and from which framebuffer it scans out from.
1473 *
1474 * This is used to set modes.
1475 */
1476struct drm_mode_set {
f453ba04
DA
1477 struct drm_framebuffer *fb;
1478 struct drm_crtc *crtc;
1479 struct drm_display_mode *mode;
1480
1481 uint32_t x;
1482 uint32_t y;
1483
1484 struct drm_connector **connectors;
1485 size_t num_connectors;
1486};
1487
1488/**
550cebcd
JB
1489 * struct drm_mode_config_funcs - basic driver provided mode setting functions
1490 * @fb_create: create a new framebuffer object
1491 * @output_poll_changed: function to handle output configuration changes
2b1193d5 1492 * @atomic_check: check whether a given atomic state update is possible
cc4ceb48
DV
1493 * @atomic_commit: commit an atomic state update previously verified with
1494 * atomic_check()
036ef573
ML
1495 * @atomic_state_alloc: allocate a new atomic state
1496 * @atomic_state_clear: clear the atomic state
1497 * @atomic_state_free: free the atomic state
550cebcd
JB
1498 *
1499 * Some global (i.e. not per-CRTC, connector, etc) mode setting functions that
1500 * involve drivers.
f453ba04
DA
1501 */
1502struct drm_mode_config_funcs {
550cebcd
JB
1503 struct drm_framebuffer *(*fb_create)(struct drm_device *dev,
1504 struct drm_file *file_priv,
1eb83451 1505 const struct drm_mode_fb_cmd2 *mode_cmd);
eb1f8e4f 1506 void (*output_poll_changed)(struct drm_device *dev);
cc4ceb48
DV
1507
1508 int (*atomic_check)(struct drm_device *dev,
1509 struct drm_atomic_state *a);
1510 int (*atomic_commit)(struct drm_device *dev,
1511 struct drm_atomic_state *a,
1512 bool async);
036ef573
ML
1513 struct drm_atomic_state *(*atomic_state_alloc)(struct drm_device *dev);
1514 void (*atomic_state_clear)(struct drm_atomic_state *state);
1515 void (*atomic_state_free)(struct drm_atomic_state *state);
f453ba04
DA
1516};
1517
f453ba04 1518/**
2c0c33d4 1519 * struct drm_mode_config - Mode configuration control structure
a62c93d5 1520 * @mutex: mutex protecting KMS related lists and structures
2c0c33d4
DV
1521 * @connection_mutex: ww mutex protecting connector state and routing
1522 * @acquire_ctx: global implicit acquire context used by atomic drivers for
1523 * legacy ioctls
a62c93d5
JB
1524 * @idr_mutex: mutex for KMS ID allocation and management
1525 * @crtc_idr: main KMS ID tracking object
2c0c33d4 1526 * @fb_lock: mutex to protect fb state and lists
a62c93d5
JB
1527 * @num_fb: number of fbs available
1528 * @fb_list: list of framebuffers available
1529 * @num_connector: number of connectors on this device
1530 * @connector_list: list of connector objects
1531 * @num_encoder: number of encoders on this device
1532 * @encoder_list: list of encoder objects
2c0c33d4
DV
1533 * @num_overlay_plane: number of overlay planes on this device
1534 * @num_total_plane: number of universal (i.e. with primary/curso) planes on this device
1535 * @plane_list: list of plane objects
a62c93d5
JB
1536 * @num_crtc: number of CRTCs on this device
1537 * @crtc_list: list of CRTC objects
2c0c33d4 1538 * @property_list: list of property objects
a62c93d5
JB
1539 * @min_width: minimum pixel width on this device
1540 * @min_height: minimum pixel height on this device
1541 * @max_width: maximum pixel width on this device
1542 * @max_height: maximum pixel height on this device
1543 * @funcs: core driver provided mode setting functions
1544 * @fb_base: base address of the framebuffer
2c0c33d4
DV
1545 * @poll_enabled: track polling support for this device
1546 * @poll_running: track polling status for this device
a62c93d5 1547 * @output_poll_work: delayed work for polling in process context
2c0c33d4 1548 * @property_blob_list: list of all the blob property objects
8fb6e7a5 1549 * @blob_lock: mutex for blob property allocation and management
a62c93d5 1550 * @*_property: core property tracking
2c0c33d4
DV
1551 * @preferred_depth: preferred RBG pixel depth, used by fb helpers
1552 * @prefer_shadow: hint to userspace to prefer shadow-fb rendering
1553 * @async_page_flip: does this device support async flips on the primary plane?
1554 * @cursor_width: hint to userspace for max cursor width
1555 * @cursor_height: hint to userspace for max cursor height
f453ba04 1556 *
a62c93d5
JB
1557 * Core mode resource tracking structure. All CRTC, encoders, and connectors
1558 * enumerated by the driver are added here, as are global properties. Some
1559 * global restrictions are also here, e.g. dimension restrictions.
f453ba04
DA
1560 */
1561struct drm_mode_config {
ad2563c2 1562 struct mutex mutex; /* protects configuration (mode lists etc.) */
51fd371b
RC
1563 struct drm_modeset_lock connection_mutex; /* protects connector->encoder and encoder->crtc links */
1564 struct drm_modeset_acquire_ctx *acquire_ctx; /* for legacy _lock_all() / _unlock_all() */
ad2563c2 1565 struct mutex idr_mutex; /* for IDR management */
f453ba04 1566 struct idr crtc_idr; /* use this idr for all IDs, fb, crtc, connector, modes - just makes life easier */
138f9ebb 1567 struct idr tile_idr; /* use this idr for all IDs, fb, crtc, connector, modes - just makes life easier */
f453ba04 1568 /* this is limited to one for now */
4b096ac1 1569
2c0c33d4 1570 struct mutex fb_lock; /* proctects global and per-file fb lists */
f453ba04
DA
1571 int num_fb;
1572 struct list_head fb_list;
4b096ac1 1573
f453ba04
DA
1574 int num_connector;
1575 struct list_head connector_list;
1576 int num_encoder;
1577 struct list_head encoder_list;
e27dde3e
MR
1578
1579 /*
1580 * Track # of overlay planes separately from # of total planes. By
1581 * default we only advertise overlay planes to userspace; if userspace
1582 * sets the "universal plane" capability bit, we'll go ahead and
1583 * expose all planes.
1584 */
1585 int num_overlay_plane;
1586 int num_total_plane;
8cf5c917 1587 struct list_head plane_list;
f453ba04
DA
1588
1589 int num_crtc;
1590 struct list_head crtc_list;
1591
1592 struct list_head property_list;
1593
f453ba04
DA
1594 int min_width, min_height;
1595 int max_width, max_height;
e6ecefaa 1596 const struct drm_mode_config_funcs *funcs;
d883f7f1 1597 resource_size_t fb_base;
f453ba04 1598
eb1f8e4f
DA
1599 /* output poll support */
1600 bool poll_enabled;
905bc9ff 1601 bool poll_running;
162b6a57 1602 bool delayed_event;
991ea75c 1603 struct delayed_work output_poll_work;
eb1f8e4f 1604
8fb6e7a5
DS
1605 struct mutex blob_lock;
1606
f453ba04
DA
1607 /* pointers to standard properties */
1608 struct list_head property_blob_list;
1609 struct drm_property *edid_property;
1610 struct drm_property *dpms_property;
43aba7eb 1611 struct drm_property *path_property;
6f134d7b 1612 struct drm_property *tile_property;
9922ab5a 1613 struct drm_property *plane_type_property;
2a297cce 1614 struct drm_property *rotation_property;
6b4959f4
RC
1615 struct drm_property *prop_src_x;
1616 struct drm_property *prop_src_y;
1617 struct drm_property *prop_src_w;
1618 struct drm_property *prop_src_h;
1619 struct drm_property *prop_crtc_x;
1620 struct drm_property *prop_crtc_y;
1621 struct drm_property *prop_crtc_w;
1622 struct drm_property *prop_crtc_h;
1623 struct drm_property *prop_fb_id;
1624 struct drm_property *prop_crtc_id;
eab3bbef 1625 struct drm_property *prop_active;
955f3c33 1626 struct drm_property *prop_mode_id;
f453ba04
DA
1627
1628 /* DVI-I properties */
1629 struct drm_property *dvi_i_subconnector_property;
1630 struct drm_property *dvi_i_select_subconnector_property;
1631
1632 /* TV properties */
1633 struct drm_property *tv_subconnector_property;
1634 struct drm_property *tv_select_subconnector_property;
1635 struct drm_property *tv_mode_property;
1636 struct drm_property *tv_left_margin_property;
1637 struct drm_property *tv_right_margin_property;
1638 struct drm_property *tv_top_margin_property;
1639 struct drm_property *tv_bottom_margin_property;
b6b7902e
FJ
1640 struct drm_property *tv_brightness_property;
1641 struct drm_property *tv_contrast_property;
1642 struct drm_property *tv_flicker_reduction_property;
a75f0236
FJ
1643 struct drm_property *tv_overscan_property;
1644 struct drm_property *tv_saturation_property;
1645 struct drm_property *tv_hue_property;
f453ba04
DA
1646
1647 /* Optional properties */
1648 struct drm_property *scaling_mode_property;
ff587e45 1649 struct drm_property *aspect_ratio_property;
884840aa 1650 struct drm_property *dirty_info_property;
019d96cb 1651
5bb2bbf5
DA
1652 /* properties for virtual machine layout */
1653 struct drm_property *suggested_x_property;
1654 struct drm_property *suggested_y_property;
1655
019d96cb
DA
1656 /* dumb ioctl parameters */
1657 uint32_t preferred_depth, prefer_shadow;
62f2104f
KP
1658
1659 /* whether async page flip is supported or not */
1660 bool async_page_flip;
8716ed4e 1661
e3eb3250
RC
1662 /* whether the driver supports fb modifiers */
1663 bool allow_fb_modifiers;
1664
8716ed4e
AD
1665 /* cursor size */
1666 uint32_t cursor_width, cursor_height;
f453ba04
DA
1667};
1668
dd275956
RC
1669/**
1670 * drm_for_each_plane_mask - iterate over planes specified by bitmask
1671 * @plane: the loop cursor
1672 * @dev: the DRM device
1673 * @plane_mask: bitmask of plane indices
1674 *
1675 * Iterate over all planes specified by bitmask.
1676 */
1677#define drm_for_each_plane_mask(plane, dev, plane_mask) \
1678 list_for_each_entry((plane), &(dev)->mode_config.plane_list, head) \
373701b1 1679 for_each_if ((plane_mask) & (1 << drm_plane_index(plane)))
dd275956
RC
1680
1681
f453ba04
DA
1682#define obj_to_crtc(x) container_of(x, struct drm_crtc, base)
1683#define obj_to_connector(x) container_of(x, struct drm_connector, base)
1684#define obj_to_encoder(x) container_of(x, struct drm_encoder, base)
1685#define obj_to_mode(x) container_of(x, struct drm_display_mode, base)
1686#define obj_to_fb(x) container_of(x, struct drm_framebuffer, base)
1687#define obj_to_property(x) container_of(x, struct drm_property, base)
1688#define obj_to_blob(x) container_of(x, struct drm_property_blob, base)
8cf5c917 1689#define obj_to_plane(x) container_of(x, struct drm_plane, base)
f453ba04 1690
4a67d391
SH
1691struct drm_prop_enum_list {
1692 int type;
1693 char *name;
1694};
f453ba04 1695
e13161af
MR
1696extern int drm_crtc_init_with_planes(struct drm_device *dev,
1697 struct drm_crtc *crtc,
1698 struct drm_plane *primary,
fc1d3e44 1699 struct drm_plane *cursor,
e13161af 1700 const struct drm_crtc_funcs *funcs);
f453ba04 1701extern void drm_crtc_cleanup(struct drm_crtc *crtc);
db5f7a6e
RK
1702extern unsigned int drm_crtc_index(struct drm_crtc *crtc);
1703
1704/**
1705 * drm_crtc_mask - find the mask of a registered CRTC
1706 * @crtc: CRTC to find mask for
1707 *
1708 * Given a registered CRTC, return the mask bit of that CRTC for an
1709 * encoder's possible_crtcs field.
1710 */
1711static inline uint32_t drm_crtc_mask(struct drm_crtc *crtc)
1712{
1713 return 1 << drm_crtc_index(crtc);
1714}
f453ba04 1715
b21e3afe
IM
1716extern void drm_connector_ida_init(void);
1717extern void drm_connector_ida_destroy(void);
6bfc56aa
VS
1718extern int drm_connector_init(struct drm_device *dev,
1719 struct drm_connector *connector,
1720 const struct drm_connector_funcs *funcs,
1721 int connector_type);
34ea3d38
TW
1722int drm_connector_register(struct drm_connector *connector);
1723void drm_connector_unregister(struct drm_connector *connector);
f453ba04
DA
1724
1725extern void drm_connector_cleanup(struct drm_connector *connector);
10f637bf 1726extern unsigned int drm_connector_index(struct drm_connector *connector);
cbc7e221
DA
1727/* helper to unplug all connectors from sysfs for device */
1728extern void drm_connector_unplug_all(struct drm_device *dev);
f453ba04 1729
3d3f8b1f
AK
1730extern int drm_bridge_add(struct drm_bridge *bridge);
1731extern void drm_bridge_remove(struct drm_bridge *bridge);
1732extern struct drm_bridge *of_drm_find_bridge(struct device_node *np);
1733extern int drm_bridge_attach(struct drm_device *dev, struct drm_bridge *bridge);
3b336ec4 1734
862e686c
AT
1735bool drm_bridge_mode_fixup(struct drm_bridge *bridge,
1736 const struct drm_display_mode *mode,
1737 struct drm_display_mode *adjusted_mode);
1738void drm_bridge_disable(struct drm_bridge *bridge);
1739void drm_bridge_post_disable(struct drm_bridge *bridge);
1740void drm_bridge_mode_set(struct drm_bridge *bridge,
1741 struct drm_display_mode *mode,
1742 struct drm_display_mode *adjusted_mode);
1743void drm_bridge_pre_enable(struct drm_bridge *bridge);
1744void drm_bridge_enable(struct drm_bridge *bridge);
1745
6bfc56aa
VS
1746extern int drm_encoder_init(struct drm_device *dev,
1747 struct drm_encoder *encoder,
1748 const struct drm_encoder_funcs *funcs,
1749 int encoder_type);
f453ba04 1750
3d887368
TR
1751/**
1752 * drm_encoder_crtc_ok - can a given crtc drive a given encoder?
1753 * @encoder: encoder to test
1754 * @crtc: crtc to test
1755 *
1756 * Return false if @encoder can't be driven by @crtc, true otherwise.
1757 */
1758static inline bool drm_encoder_crtc_ok(struct drm_encoder *encoder,
1759 struct drm_crtc *crtc)
1760{
1761 return !!(encoder->possible_crtcs & drm_crtc_mask(crtc));
1762}
1763
dc415ff9
MR
1764extern int drm_universal_plane_init(struct drm_device *dev,
1765 struct drm_plane *plane,
1766 unsigned long possible_crtcs,
1767 const struct drm_plane_funcs *funcs,
1768 const uint32_t *formats,
45e3743a 1769 unsigned int format_count,
dc415ff9 1770 enum drm_plane_type type);
8cf5c917
JB
1771extern int drm_plane_init(struct drm_device *dev,
1772 struct drm_plane *plane,
1773 unsigned long possible_crtcs,
1774 const struct drm_plane_funcs *funcs,
45e3743a 1775 const uint32_t *formats, unsigned int format_count,
dc415ff9 1776 bool is_primary);
8cf5c917 1777extern void drm_plane_cleanup(struct drm_plane *plane);
10f637bf 1778extern unsigned int drm_plane_index(struct drm_plane *plane);
f81338a5 1779extern struct drm_plane * drm_plane_from_index(struct drm_device *dev, int idx);
9125e618 1780extern void drm_plane_force_disable(struct drm_plane *plane);
ead8610d
LP
1781extern int drm_plane_check_pixel_format(const struct drm_plane *plane,
1782 u32 format);
ecb7e16b
GP
1783extern void drm_crtc_get_hv_timing(const struct drm_display_mode *mode,
1784 int *hdisplay, int *vdisplay);
af93629d
MR
1785extern int drm_crtc_check_viewport(const struct drm_crtc *crtc,
1786 int x, int y,
1787 const struct drm_display_mode *mode,
1788 const struct drm_framebuffer *fb);
8cf5c917 1789
f453ba04
DA
1790extern void drm_encoder_cleanup(struct drm_encoder *encoder);
1791
d20d3174 1792extern const char *drm_get_connector_status_name(enum drm_connector_status status);
ac1bb36c 1793extern const char *drm_get_subpixel_order_name(enum subpixel_order order);
d20d3174
VS
1794extern const char *drm_get_dpms_name(int val);
1795extern const char *drm_get_dvi_i_subconnector_name(int val);
1796extern const char *drm_get_dvi_i_select_name(int val);
1797extern const char *drm_get_tv_subconnector_name(int val);
1798extern const char *drm_get_tv_select_name(int val);
ea39f835 1799extern void drm_fb_release(struct drm_file *file_priv);
e2f5d2ea
DS
1800extern void drm_property_destroy_user_blobs(struct drm_device *dev,
1801 struct drm_file *file_priv);
fbff4690 1802extern bool drm_probe_ddc(struct i2c_adapter *adapter);
f453ba04
DA
1803extern struct edid *drm_get_edid(struct drm_connector *connector,
1804 struct i2c_adapter *adapter);
51f8da59 1805extern struct edid *drm_edid_duplicate(const struct edid *edid);
f453ba04 1806extern int drm_add_edid_modes(struct drm_connector *connector, struct edid *edid);
f453ba04 1807extern void drm_mode_config_init(struct drm_device *dev);
eb033556 1808extern void drm_mode_config_reset(struct drm_device *dev);
f453ba04 1809extern void drm_mode_config_cleanup(struct drm_device *dev);
55310008 1810
43aba7eb 1811extern int drm_mode_connector_set_path_property(struct drm_connector *connector,
12e6cecd 1812 const char *path);
6f134d7b 1813int drm_mode_connector_set_tile_property(struct drm_connector *connector);
f453ba04 1814extern int drm_mode_connector_update_edid_property(struct drm_connector *connector,
12e6cecd 1815 const struct edid *edid);
5ea22f24 1816
b5571e9d
BB
1817extern int drm_display_info_set_bus_formats(struct drm_display_info *info,
1818 const u32 *formats,
1819 unsigned int num_formats);
1820
5ea22f24
RC
1821static inline bool drm_property_type_is(struct drm_property *property,
1822 uint32_t type)
1823{
1824 /* instanceof for props.. handles extended type vs original types: */
1825 if (property->flags & DRM_MODE_PROP_EXTENDED_TYPE)
1826 return (property->flags & DRM_MODE_PROP_EXTENDED_TYPE) == type;
1827 return property->flags & type;
1828}
1829
1830static inline bool drm_property_type_valid(struct drm_property *property)
1831{
1832 if (property->flags & DRM_MODE_PROP_EXTENDED_TYPE)
1833 return !(property->flags & DRM_MODE_PROP_LEGACY_TYPE);
1834 return !!(property->flags & DRM_MODE_PROP_LEGACY_TYPE);
1835}
1836
c543188a
PZ
1837extern int drm_object_property_set_value(struct drm_mode_object *obj,
1838 struct drm_property *property,
1839 uint64_t val);
1840extern int drm_object_property_get_value(struct drm_mode_object *obj,
1841 struct drm_property *property,
1842 uint64_t *value);
f453ba04
DA
1843extern int drm_framebuffer_init(struct drm_device *dev,
1844 struct drm_framebuffer *fb,
1845 const struct drm_framebuffer_funcs *funcs);
786b99ed
DV
1846extern struct drm_framebuffer *drm_framebuffer_lookup(struct drm_device *dev,
1847 uint32_t id);
f7eff60e
RC
1848extern void drm_framebuffer_unreference(struct drm_framebuffer *fb);
1849extern void drm_framebuffer_reference(struct drm_framebuffer *fb);
1850extern void drm_framebuffer_remove(struct drm_framebuffer *fb);
f453ba04 1851extern void drm_framebuffer_cleanup(struct drm_framebuffer *fb);
36206361 1852extern void drm_framebuffer_unregister_private(struct drm_framebuffer *fb);
f453ba04 1853
c543188a
PZ
1854extern void drm_object_attach_property(struct drm_mode_object *obj,
1855 struct drm_property *property,
1856 uint64_t init_val);
f453ba04
DA
1857extern struct drm_property *drm_property_create(struct drm_device *dev, int flags,
1858 const char *name, int num_values);
4a67d391
SH
1859extern struct drm_property *drm_property_create_enum(struct drm_device *dev, int flags,
1860 const char *name,
49e27545
RC
1861 const struct drm_prop_enum_list *props,
1862 int num_values);
1863struct drm_property *drm_property_create_bitmask(struct drm_device *dev,
1864 int flags, const char *name,
4a67d391 1865 const struct drm_prop_enum_list *props,
7689ffb3
VS
1866 int num_props,
1867 uint64_t supported_bits);
d9bc3c02
SH
1868struct drm_property *drm_property_create_range(struct drm_device *dev, int flags,
1869 const char *name,
1870 uint64_t min, uint64_t max);
ebc44cf3
RC
1871struct drm_property *drm_property_create_signed_range(struct drm_device *dev,
1872 int flags, const char *name,
1873 int64_t min, int64_t max);
98f75de4
RC
1874struct drm_property *drm_property_create_object(struct drm_device *dev,
1875 int flags, const char *name, uint32_t type);
960cd9d4
DV
1876struct drm_property *drm_property_create_bool(struct drm_device *dev, int flags,
1877 const char *name);
6bcacf51
DS
1878struct drm_property_blob *drm_property_create_blob(struct drm_device *dev,
1879 size_t length,
1880 const void *data);
1881struct drm_property_blob *drm_property_lookup_blob(struct drm_device *dev,
1882 uint32_t id);
1883struct drm_property_blob *drm_property_reference_blob(struct drm_property_blob *blob);
1884void drm_property_unreference_blob(struct drm_property_blob *blob);
f453ba04
DA
1885extern void drm_property_destroy(struct drm_device *dev, struct drm_property *property);
1886extern int drm_property_add_enum(struct drm_property *property, int index,
1887 uint64_t value, const char *name);
1888extern int drm_mode_create_dvi_i_properties(struct drm_device *dev);
2f763312
TR
1889extern int drm_mode_create_tv_properties(struct drm_device *dev,
1890 unsigned int num_modes,
b7c914b3 1891 const char * const modes[]);
f453ba04 1892extern int drm_mode_create_scaling_mode_property(struct drm_device *dev);
ff587e45 1893extern int drm_mode_create_aspect_ratio_property(struct drm_device *dev);
884840aa 1894extern int drm_mode_create_dirty_info_property(struct drm_device *dev);
5bb2bbf5 1895extern int drm_mode_create_suggested_offset_properties(struct drm_device *dev);
d34f20d6
RC
1896extern bool drm_property_change_valid_get(struct drm_property *property,
1897 uint64_t value, struct drm_mode_object **ref);
1898extern void drm_property_change_valid_put(struct drm_property *property,
1899 struct drm_mode_object *ref);
f453ba04
DA
1900
1901extern int drm_mode_connector_attach_encoder(struct drm_connector *connector,
1902 struct drm_encoder *encoder);
4cae5b84 1903extern int drm_mode_crtc_set_gamma_size(struct drm_crtc *crtc,
f453ba04 1904 int gamma_size);
7a9c9060
DV
1905extern struct drm_mode_object *drm_mode_object_find(struct drm_device *dev,
1906 uint32_t id, uint32_t type);
98f75de4 1907
f453ba04
DA
1908/* IOCTLs */
1909extern int drm_mode_getresources(struct drm_device *dev,
1910 void *data, struct drm_file *file_priv);
8cf5c917
JB
1911extern int drm_mode_getplane_res(struct drm_device *dev, void *data,
1912 struct drm_file *file_priv);
f453ba04
DA
1913extern int drm_mode_getcrtc(struct drm_device *dev,
1914 void *data, struct drm_file *file_priv);
1915extern int drm_mode_getconnector(struct drm_device *dev,
1916 void *data, struct drm_file *file_priv);
2d13b679 1917extern int drm_mode_set_config_internal(struct drm_mode_set *set);
f453ba04
DA
1918extern int drm_mode_setcrtc(struct drm_device *dev,
1919 void *data, struct drm_file *file_priv);
8cf5c917
JB
1920extern int drm_mode_getplane(struct drm_device *dev,
1921 void *data, struct drm_file *file_priv);
1922extern int drm_mode_setplane(struct drm_device *dev,
1923 void *data, struct drm_file *file_priv);
f453ba04
DA
1924extern int drm_mode_cursor_ioctl(struct drm_device *dev,
1925 void *data, struct drm_file *file_priv);
4c813d4d
DA
1926extern int drm_mode_cursor2_ioctl(struct drm_device *dev,
1927 void *data, struct drm_file *file_priv);
f453ba04
DA
1928extern int drm_mode_addfb(struct drm_device *dev,
1929 void *data, struct drm_file *file_priv);
308e5bcb
JB
1930extern int drm_mode_addfb2(struct drm_device *dev,
1931 void *data, struct drm_file *file_priv);
1932extern uint32_t drm_mode_legacy_fb_format(uint32_t bpp, uint32_t depth);
f453ba04
DA
1933extern int drm_mode_rmfb(struct drm_device *dev,
1934 void *data, struct drm_file *file_priv);
1935extern int drm_mode_getfb(struct drm_device *dev,
1936 void *data, struct drm_file *file_priv);
884840aa
JB
1937extern int drm_mode_dirtyfb_ioctl(struct drm_device *dev,
1938 void *data, struct drm_file *file_priv);
f453ba04
DA
1939
1940extern int drm_mode_getproperty_ioctl(struct drm_device *dev,
1941 void *data, struct drm_file *file_priv);
1942extern int drm_mode_getblob_ioctl(struct drm_device *dev,
1943 void *data, struct drm_file *file_priv);
e2f5d2ea
DS
1944extern int drm_mode_createblob_ioctl(struct drm_device *dev,
1945 void *data, struct drm_file *file_priv);
1946extern int drm_mode_destroyblob_ioctl(struct drm_device *dev,
1947 void *data, struct drm_file *file_priv);
f453ba04
DA
1948extern int drm_mode_connector_property_set_ioctl(struct drm_device *dev,
1949 void *data, struct drm_file *file_priv);
f453ba04
DA
1950extern int drm_mode_getencoder(struct drm_device *dev,
1951 void *data, struct drm_file *file_priv);
1952extern int drm_mode_gamma_get_ioctl(struct drm_device *dev,
1953 void *data, struct drm_file *file_priv);
1954extern int drm_mode_gamma_set_ioctl(struct drm_device *dev,
1955 void *data, struct drm_file *file_priv);
18316c8c 1956extern u8 drm_match_cea_mode(const struct drm_display_mode *to_match);
0967e6a5 1957extern enum hdmi_picture_aspect drm_get_cea_aspect_ratio(const u8 video_code);
f23c20c8 1958extern bool drm_detect_hdmi_monitor(struct edid *edid);
8fe9790d 1959extern bool drm_detect_monitor_audio(struct edid *edid);
b1edd6a6 1960extern bool drm_rgb_quant_range_selectable(struct edid *edid);
d91d8a3f
KH
1961extern int drm_mode_page_flip_ioctl(struct drm_device *dev,
1962 void *data, struct drm_file *file_priv);
f0fda0a4
ZY
1963extern int drm_add_modes_noedid(struct drm_connector *connector,
1964 int hdisplay, int vdisplay);
3cf70daf
GH
1965extern void drm_set_preferred_mode(struct drm_connector *connector,
1966 int hpref, int vpref);
3c537889 1967
051963d4 1968extern int drm_edid_header_is_valid(const u8 *raw_edid);
6ba2bd3d
TP
1969extern bool drm_edid_block_valid(u8 *raw_edid, int block, bool print_bad_edid,
1970 bool *edid_corrupt);
3c537889 1971extern bool drm_edid_is_valid(struct edid *edid);
138f9ebb
DA
1972
1973extern struct drm_tile_group *drm_mode_create_tile_group(struct drm_device *dev,
1974 char topology[8]);
1975extern struct drm_tile_group *drm_mode_get_tile_group(struct drm_device *dev,
1976 char topology[8]);
1977extern void drm_mode_put_tile_group(struct drm_device *dev,
1978 struct drm_tile_group *tg);
1d42bbc8 1979struct drm_display_mode *drm_mode_find_dmt(struct drm_device *dev,
f6e252ba
AJ
1980 int hsize, int vsize, int fresh,
1981 bool rb);
ff72145b
DA
1982
1983extern int drm_mode_create_dumb_ioctl(struct drm_device *dev,
1984 void *data, struct drm_file *file_priv);
1985extern int drm_mode_mmap_dumb_ioctl(struct drm_device *dev,
1986 void *data, struct drm_file *file_priv);
1987extern int drm_mode_destroy_dumb_ioctl(struct drm_device *dev,
1988 void *data, struct drm_file *file_priv);
c543188a
PZ
1989extern int drm_mode_obj_get_properties_ioctl(struct drm_device *dev, void *data,
1990 struct drm_file *file_priv);
1991extern int drm_mode_obj_set_property_ioctl(struct drm_device *dev, void *data,
1992 struct drm_file *file_priv);
3a5f87c2
TW
1993extern int drm_mode_plane_set_obj_prop(struct drm_plane *plane,
1994 struct drm_property *property,
1995 uint64_t value);
d34f20d6
RC
1996extern int drm_mode_atomic_ioctl(struct drm_device *dev,
1997 void *data, struct drm_file *file_priv);
248dbc23
DA
1998
1999extern void drm_fb_get_bpp_depth(uint32_t format, unsigned int *depth,
2000 int *bpp);
141670e9 2001extern int drm_format_num_planes(uint32_t format);
5a86bd55 2002extern int drm_format_plane_cpp(uint32_t format, int plane);
01b68b04
VS
2003extern int drm_format_horz_chroma_subsampling(uint32_t format);
2004extern int drm_format_vert_chroma_subsampling(uint32_t format);
d20d3174 2005extern const char *drm_get_format_name(uint32_t format);
c1df5f3c
VS
2006extern struct drm_property *drm_mode_create_rotation_property(struct drm_device *dev,
2007 unsigned int supported_rotations);
3c9855f6
VS
2008extern unsigned int drm_rotation_simplify(unsigned int rotation,
2009 unsigned int supported_rotations);
141670e9 2010
96f60e37 2011/* Helpers */
a2b34e22
RC
2012
2013static inline struct drm_plane *drm_plane_find(struct drm_device *dev,
2014 uint32_t id)
2015{
2016 struct drm_mode_object *mo;
2017 mo = drm_mode_object_find(dev, id, DRM_MODE_OBJECT_PLANE);
2018 return mo ? obj_to_plane(mo) : NULL;
2019}
2020
96f60e37
RK
2021static inline struct drm_crtc *drm_crtc_find(struct drm_device *dev,
2022 uint32_t id)
2023{
2024 struct drm_mode_object *mo;
2025 mo = drm_mode_object_find(dev, id, DRM_MODE_OBJECT_CRTC);
2026 return mo ? obj_to_crtc(mo) : NULL;
2027}
2028
2029static inline struct drm_encoder *drm_encoder_find(struct drm_device *dev,
2030 uint32_t id)
2031{
2032 struct drm_mode_object *mo;
2033 mo = drm_mode_object_find(dev, id, DRM_MODE_OBJECT_ENCODER);
2034 return mo ? obj_to_encoder(mo) : NULL;
2035}
2036
a2b34e22
RC
2037static inline struct drm_connector *drm_connector_find(struct drm_device *dev,
2038 uint32_t id)
2039{
2040 struct drm_mode_object *mo;
2041 mo = drm_mode_object_find(dev, id, DRM_MODE_OBJECT_CONNECTOR);
2042 return mo ? obj_to_connector(mo) : NULL;
2043}
2044
2045static inline struct drm_property *drm_property_find(struct drm_device *dev,
2046 uint32_t id)
2047{
2048 struct drm_mode_object *mo;
2049 mo = drm_mode_object_find(dev, id, DRM_MODE_OBJECT_PROPERTY);
2050 return mo ? obj_to_property(mo) : NULL;
2051}
2052
e27dde3e 2053/* Plane list iterator for legacy (overlay only) planes. */
4ea50e99
DV
2054#define drm_for_each_legacy_plane(plane, dev) \
2055 list_for_each_entry(plane, &(dev)->mode_config.plane_list, head) \
373701b1 2056 for_each_if (plane->type == DRM_PLANE_TYPE_OVERLAY)
e27dde3e 2057
6295d607
DV
2058#define drm_for_each_plane(plane, dev) \
2059 list_for_each_entry(plane, &(dev)->mode_config.plane_list, head)
2060
2061#define drm_for_each_crtc(crtc, dev) \
2062 list_for_each_entry(crtc, &(dev)->mode_config.crtc_list, head)
2063
7a3f3d66
DV
2064static inline void
2065assert_drm_connector_list_read_locked(struct drm_mode_config *mode_config)
2066{
cff20ba2
DV
2067 /*
2068 * The connector hotadd/remove code currently grabs both locks when
2069 * updating lists. Hence readers need only hold either of them to be
2070 * safe and the check amounts to
2071 *
2072 * WARN_ON(not_holding(A) && not_holding(B)).
2073 */
2074 WARN_ON(!mutex_is_locked(&mode_config->mutex) &&
2075 !drm_modeset_is_locked(&mode_config->connection_mutex));
7a3f3d66
DV
2076}
2077
6295d607 2078#define drm_for_each_connector(connector, dev) \
7a3f3d66
DV
2079 for (assert_drm_connector_list_read_locked(&(dev)->mode_config), \
2080 connector = list_first_entry(&(dev)->mode_config.connector_list, \
2081 struct drm_connector, head); \
2082 &connector->head != (&(dev)->mode_config.connector_list); \
2083 connector = list_next_entry(connector, head))
6295d607
DV
2084
2085#define drm_for_each_encoder(encoder, dev) \
2086 list_for_each_entry(encoder, &(dev)->mode_config.encoder_list, head)
2087
2088#define drm_for_each_fb(fb, dev) \
4676ba0b
DV
2089 for (WARN_ON(!mutex_is_locked(&(dev)->mode_config.fb_lock)), \
2090 fb = list_first_entry(&(dev)->mode_config.fb_list, \
2091 struct drm_framebuffer, head); \
2092 &fb->head != (&(dev)->mode_config.fb_list); \
2093 fb = list_next_entry(fb, head))
6295d607 2094
f453ba04 2095#endif /* __DRM_CRTC_H__ */
This page took 0.397123 seconds and 5 git commands to generate.