drm/tilcdc: Add atomic and crtc headers to crtc.c
[linux-2.6-block.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>
d7da824d 38#include <drm/drm_rect.h>
949619f3 39#include <drm/drm_mode_object.h>
7520a277
DV
40#include <drm/drm_framebuffer.h>
41#include <drm/drm_modes.h>
52217195 42#include <drm/drm_connector.h>
321a95ae 43#include <drm/drm_encoder.h>
59e71ee7 44#include <drm/drm_property.h>
199e4e96 45#include <drm/drm_bridge.h>
cdc3d09f 46#include <drm/drm_edid.h>
308e5bcb 47
f453ba04
DA
48struct drm_device;
49struct drm_mode_set;
595887eb
TR
50struct drm_file;
51struct drm_clip_rect;
7e435aad 52struct device_node;
e2330f07 53struct fence;
81065548 54struct edid;
f453ba04 55
ebc44cf3
RC
56static inline int64_t U642I64(uint64_t val)
57{
58 return (int64_t)*((int64_t *)&val);
59}
60static inline uint64_t I642U64(int64_t val)
61{
62 return (uint64_t)*((uint64_t *)&val);
63}
64
d9c38242
RF
65/*
66 * Rotation property bits. DRM_ROTATE_<degrees> rotates the image by the
67 * specified amount in degrees in counter clockwise direction. DRM_REFLECT_X and
68 * DRM_REFLECT_Y reflects the image along the specified axis prior to rotation
69 */
31ad61e4
JL
70#define DRM_ROTATE_0 BIT(0)
71#define DRM_ROTATE_90 BIT(1)
72#define DRM_ROTATE_180 BIT(2)
73#define DRM_ROTATE_270 BIT(3)
74#define DRM_ROTATE_MASK (DRM_ROTATE_0 | DRM_ROTATE_90 | \
75 DRM_ROTATE_180 | DRM_ROTATE_270)
76#define DRM_REFLECT_X BIT(4)
77#define DRM_REFLECT_Y BIT(5)
78#define DRM_REFLECT_MASK (DRM_REFLECT_X | DRM_REFLECT_Y)
06596961 79
138f9ebb
DA
80/* data corresponds to displayid vend/prod/serial */
81struct drm_tile_group {
82 struct kref refcount;
83 struct drm_device *dev;
84 int id;
85 u8 group_data[8];
86};
87
f453ba04 88struct drm_crtc;
f453ba04 89struct drm_encoder;
d91d8a3f 90struct drm_pending_vblank_event;
8cf5c917 91struct drm_plane;
3b336ec4 92struct drm_bridge;
144ecb97
DV
93struct drm_atomic_state;
94
4490d4c7
DV
95struct drm_crtc_helper_funcs;
96struct drm_encoder_helper_funcs;
4490d4c7
DV
97struct drm_plane_helper_funcs;
98
144ecb97 99/**
cc4ceb48 100 * struct drm_crtc_state - mutable CRTC state
07cc0ef6 101 * @crtc: backpointer to the CRTC
144ecb97 102 * @enable: whether the CRTC should be enabled, gates all other state
d9b13620 103 * @active: whether the CRTC is actively displaying (used for DPMS)
fc596660
ML
104 * @planes_changed: planes on this crtc are updated
105 * @mode_changed: crtc_state->mode or crtc_state->enable has been changed
106 * @active_changed: crtc_state->active has been toggled.
107 * @connectors_changed: connectors to this crtc have been updated
44d1240d 108 * @zpos_changed: zpos values of planes on this crtc have been updated
5488dc16
LL
109 * @color_mgmt_changed: color management properties have changed (degamma or
110 * gamma LUT or CSC matrix)
6ddd388a 111 * @plane_mask: bitmask of (1 << drm_plane_index(plane)) of attached planes
4cd9fa52 112 * @connector_mask: bitmask of (1 << drm_connector_index(connector)) of attached connectors
e87a52b3 113 * @encoder_mask: bitmask of (1 << drm_encoder_index(encoder)) of attached encoders
623369e5
DV
114 * @last_vblank_count: for helpers and drivers to capture the vblank of the
115 * update to ensure framebuffer cleanup isn't done too early
2f324b42 116 * @adjusted_mode: for use by helpers and drivers to compute adjusted mode timings
144ecb97 117 * @mode: current mode timings
ac3ba4a5 118 * @mode_blob: &drm_property_blob for @mode
5488dc16
LL
119 * @degamma_lut: Lookup table for converting framebuffer pixel data
120 * before apply the conversion matrix
121 * @ctm: Transformation matrix
122 * @gamma_lut: Lookup table for converting pixel data after the
123 * conversion matrix
144ecb97
DV
124 * @event: optional pointer to a DRM event to signal upon completion of the
125 * state update
126 * @state: backpointer to global drm_atomic_state
d9b13620
DV
127 *
128 * Note that the distinction between @enable and @active is rather subtile:
129 * Flipping @active while @enable is set without changing anything else may
130 * never return in a failure from the ->atomic_check callback. Userspace assumes
131 * that a DPMS On will always succeed. In other words: @enable controls resource
132 * assignment, @active controls the actual hardware state.
144ecb97
DV
133 */
134struct drm_crtc_state {
07cc0ef6
DV
135 struct drm_crtc *crtc;
136
cc4ceb48 137 bool enable;
d9b13620 138 bool active;
144ecb97 139
c2fcd274
DV
140 /* computed state bits used by helpers and drivers */
141 bool planes_changed : 1;
623369e5 142 bool mode_changed : 1;
eab3bbef 143 bool active_changed : 1;
fc596660 144 bool connectors_changed : 1;
44d1240d 145 bool zpos_changed : 1;
5488dc16 146 bool color_mgmt_changed : 1;
623369e5 147
6ddd388a
RC
148 /* attached planes bitmask:
149 * WARNING: transitional helpers do not maintain plane_mask so
150 * drivers not converted over to atomic helpers should not rely
151 * on plane_mask being accurate!
152 */
153 u32 plane_mask;
154
4cd9fa52 155 u32 connector_mask;
e87a52b3 156 u32 encoder_mask;
4cd9fa52 157
623369e5
DV
158 /* last_vblank_count: for vblank waits before cleanup */
159 u32 last_vblank_count;
c2fcd274 160
2f324b42
DV
161 /* adjusted_mode: for use by helpers and drivers */
162 struct drm_display_mode adjusted_mode;
163
144ecb97
DV
164 struct drm_display_mode mode;
165
99cf4a29
DS
166 /* blob property to expose current mode to atomic userspace */
167 struct drm_property_blob *mode_blob;
168
5488dc16
LL
169 /* blob property to expose color management to userspace */
170 struct drm_property_blob *degamma_lut;
171 struct drm_property_blob *ctm;
172 struct drm_property_blob *gamma_lut;
173
144ecb97
DV
174 struct drm_pending_vblank_event *event;
175
176 struct drm_atomic_state *state;
177};
f453ba04
DA
178
179/**
3bf0401c 180 * struct drm_crtc_funcs - control CRTCs for a given device
f453ba04
DA
181 *
182 * The drm_crtc_funcs structure is the central CRTC management structure
183 * in the DRM. Each CRTC controls one or more connectors (note that the name
184 * CRTC is simply historical, a CRTC may control LVDS, VGA, DVI, TV out, etc.
185 * connectors, not just CRTs).
186 *
187 * Each driver is responsible for filling out this structure at startup time,
188 * in addition to providing other modesetting features, like i2c and DDC
189 * bus accessors.
190 */
191struct drm_crtc_funcs {
88548636
DV
192 /**
193 * @reset:
194 *
195 * Reset CRTC hardware and software state to off. This function isn't
196 * called by the core directly, only through drm_mode_config_reset().
197 * It's not a helper hook only for historical reasons.
198 *
199 * Atomic drivers can use drm_atomic_helper_crtc_reset() to reset
200 * atomic state using this hook.
201 */
eb033556 202 void (*reset)(struct drm_crtc *crtc);
f453ba04 203
f6da8c6e
DV
204 /**
205 * @cursor_set:
206 *
207 * Update the cursor image. The cursor position is relative to the CRTC
208 * and can be partially or fully outside of the visible area.
209 *
210 * Note that contrary to all other KMS functions the legacy cursor entry
211 * points don't take a framebuffer object, but instead take directly a
212 * raw buffer object id from the driver's buffer manager (which is
213 * either GEM or TTM for current drivers).
214 *
215 * This entry point is deprecated, drivers should instead implement
216 * universal plane support and register a proper cursor plane using
217 * drm_crtc_init_with_planes().
218 *
219 * This callback is optional
220 *
221 * RETURNS:
222 *
223 * 0 on success or a negative error code on failure.
224 */
f453ba04
DA
225 int (*cursor_set)(struct drm_crtc *crtc, struct drm_file *file_priv,
226 uint32_t handle, uint32_t width, uint32_t height);
f6da8c6e
DV
227
228 /**
229 * @cursor_set2:
230 *
231 * Update the cursor image, including hotspot information. The hotspot
232 * must not affect the cursor position in CRTC coordinates, but is only
233 * meant as a hint for virtualized display hardware to coordinate the
234 * guests and hosts cursor position. The cursor hotspot is relative to
235 * the cursor image. Otherwise this works exactly like @cursor_set.
236 *
237 * This entry point is deprecated, drivers should instead implement
238 * universal plane support and register a proper cursor plane using
239 * drm_crtc_init_with_planes().
240 *
241 * This callback is optional.
242 *
243 * RETURNS:
244 *
245 * 0 on success or a negative error code on failure.
246 */
4c813d4d
DA
247 int (*cursor_set2)(struct drm_crtc *crtc, struct drm_file *file_priv,
248 uint32_t handle, uint32_t width, uint32_t height,
249 int32_t hot_x, int32_t hot_y);
f6da8c6e
DV
250
251 /**
252 * @cursor_move:
253 *
254 * Update the cursor position. The cursor does not need to be visible
255 * when this hook is called.
256 *
257 * This entry point is deprecated, drivers should instead implement
258 * universal plane support and register a proper cursor plane using
259 * drm_crtc_init_with_planes().
260 *
261 * This callback is optional.
262 *
263 * RETURNS:
264 *
265 * 0 on success or a negative error code on failure.
266 */
f453ba04
DA
267 int (*cursor_move)(struct drm_crtc *crtc, int x, int y);
268
f6da8c6e
DV
269 /**
270 * @gamma_set:
271 *
272 * Set gamma on the CRTC.
273 *
274 * This callback is optional.
275 *
276 * NOTE:
277 *
278 * Drivers that support gamma tables and also fbdev emulation through
279 * the provided helper library need to take care to fill out the gamma
280 * hooks for both. Currently there's a bit an unfortunate duplication
281 * going on, which should eventually be unified to just one set of
282 * hooks.
283 */
7ea77283
ML
284 int (*gamma_set)(struct drm_crtc *crtc, u16 *r, u16 *g, u16 *b,
285 uint32_t size);
88548636
DV
286
287 /**
288 * @destroy:
289 *
290 * Clean up plane resources. This is only called at driver unload time
291 * through drm_mode_config_cleanup() since a CRTC cannot be hotplugged
292 * in DRM.
293 */
f453ba04
DA
294 void (*destroy)(struct drm_crtc *crtc);
295
f6da8c6e
DV
296 /**
297 * @set_config:
298 *
299 * This is the main legacy entry point to change the modeset state on a
300 * CRTC. All the details of the desired configuration are passed in a
301 * struct &drm_mode_set - see there for details.
302 *
303 * Drivers implementing atomic modeset should use
304 * drm_atomic_helper_set_config() to implement this hook.
305 *
306 * RETURNS:
307 *
308 * 0 on success or a negative error code on failure.
309 */
f453ba04 310 int (*set_config)(struct drm_mode_set *set);
d91d8a3f 311
f6da8c6e
DV
312 /**
313 * @page_flip:
314 *
315 * Legacy entry point to schedule a flip to the given framebuffer.
316 *
317 * Page flipping is a synchronization mechanism that replaces the frame
318 * buffer being scanned out by the CRTC with a new frame buffer during
319 * vertical blanking, avoiding tearing (except when requested otherwise
320 * through the DRM_MODE_PAGE_FLIP_ASYNC flag). When an application
321 * requests a page flip the DRM core verifies that the new frame buffer
322 * is large enough to be scanned out by the CRTC in the currently
323 * configured mode and then calls the CRTC ->page_flip() operation with a
324 * pointer to the new frame buffer.
325 *
326 * The driver must wait for any pending rendering to the new framebuffer
327 * to complete before executing the flip. It should also wait for any
328 * pending rendering from other drivers if the underlying buffer is a
329 * shared dma-buf.
330 *
331 * An application can request to be notified when the page flip has
332 * completed. The drm core will supply a struct &drm_event in the event
333 * parameter in this case. This can be handled by the
334 * drm_crtc_send_vblank_event() function, which the driver should call on
335 * the provided event upon completion of the flip. Note that if
336 * the driver supports vblank signalling and timestamping the vblank
337 * counters and timestamps must agree with the ones returned from page
338 * flip events. With the current vblank helper infrastructure this can
339 * be achieved by holding a vblank reference while the page flip is
340 * pending, acquired through drm_crtc_vblank_get() and released with
341 * drm_crtc_vblank_put(). Drivers are free to implement their own vblank
342 * counter and timestamp tracking though, e.g. if they have accurate
343 * timestamp registers in hardware.
344 *
f6da8c6e
DV
345 * This callback is optional.
346 *
347 * NOTE:
348 *
349 * Very early versions of the KMS ABI mandated that the driver must
350 * block (but not reject) any rendering to the old framebuffer until the
351 * flip operation has completed and the old framebuffer is no longer
352 * visible. This requirement has been lifted, and userspace is instead
353 * expected to request delivery of an event and wait with recycling old
354 * buffers until such has been received.
355 *
356 * RETURNS:
357 *
358 * 0 on success or a negative error code on failure. Note that if a
359 * ->page_flip() operation is already pending the callback should return
360 * -EBUSY. Pageflips on a disabled CRTC (either by setting a NULL mode
361 * or just runtime disabled through DPMS respectively the new atomic
4cba6850
DV
362 * "ACTIVE" state) should result in an -EINVAL error code. Note that
363 * drm_atomic_helper_page_flip() checks this already for atomic drivers.
d91d8a3f
KH
364 */
365 int (*page_flip)(struct drm_crtc *crtc,
366 struct drm_framebuffer *fb,
ed8d1975
KP
367 struct drm_pending_vblank_event *event,
368 uint32_t flags);
bffd9de0 369
c229bfbb
MD
370 /**
371 * @page_flip_target:
372 *
373 * Same as @page_flip but with an additional parameter specifying the
374 * absolute target vertical blank period (as reported by
375 * drm_crtc_vblank_count()) when the flip should take effect.
376 *
377 * Note that the core code calls drm_crtc_vblank_get before this entry
378 * point, and will call drm_crtc_vblank_put if this entry point returns
379 * any non-0 error code. It's the driver's responsibility to call
380 * drm_crtc_vblank_put after this entry point returns 0, typically when
381 * the flip completes.
382 */
383 int (*page_flip_target)(struct drm_crtc *crtc,
384 struct drm_framebuffer *fb,
385 struct drm_pending_vblank_event *event,
386 uint32_t flags, uint32_t target);
387
88548636
DV
388 /**
389 * @set_property:
390 *
391 * This is the legacy entry point to update a property attached to the
392 * CRTC.
393 *
394 * Drivers implementing atomic modeset should use
395 * drm_atomic_helper_crtc_set_property() to implement this hook.
396 *
397 * This callback is optional if the driver does not support any legacy
398 * driver-private properties.
399 *
400 * RETURNS:
401 *
402 * 0 on success or a negative error code on failure.
403 */
bffd9de0
PZ
404 int (*set_property)(struct drm_crtc *crtc,
405 struct drm_property *property, uint64_t val);
144ecb97 406
88548636
DV
407 /**
408 * @atomic_duplicate_state:
409 *
410 * Duplicate the current atomic state for this CRTC and return it.
411 * The core and helpers gurantee that any atomic state duplicated with
412 * this hook and still owned by the caller (i.e. not transferred to the
413 * driver by calling ->atomic_commit() from struct
414 * &drm_mode_config_funcs) will be cleaned up by calling the
415 * @atomic_destroy_state hook in this structure.
416 *
417 * Atomic drivers which don't subclass struct &drm_crtc should use
418 * drm_atomic_helper_crtc_duplicate_state(). Drivers that subclass the
419 * state structure to extend it with driver-private state should use
420 * __drm_atomic_helper_crtc_duplicate_state() to make sure shared state is
421 * duplicated in a consistent fashion across drivers.
422 *
423 * It is an error to call this hook before crtc->state has been
424 * initialized correctly.
425 *
426 * NOTE:
427 *
428 * If the duplicate state references refcounted resources this hook must
429 * acquire a reference for each of them. The driver must release these
430 * references again in @atomic_destroy_state.
431 *
432 * RETURNS:
433 *
434 * Duplicated atomic state or NULL when the allocation failed.
435 */
144ecb97 436 struct drm_crtc_state *(*atomic_duplicate_state)(struct drm_crtc *crtc);
88548636
DV
437
438 /**
439 * @atomic_destroy_state:
440 *
441 * Destroy a state duplicated with @atomic_duplicate_state and release
442 * or unreference all resources it references
443 */
144ecb97 444 void (*atomic_destroy_state)(struct drm_crtc *crtc,
cc4ceb48 445 struct drm_crtc_state *state);
88548636
DV
446
447 /**
448 * @atomic_set_property:
449 *
450 * Decode a driver-private property value and store the decoded value
451 * into the passed-in state structure. Since the atomic core decodes all
452 * standardized properties (even for extensions beyond the core set of
453 * properties which might not be implemented by all drivers) this
454 * requires drivers to subclass the state structure.
455 *
456 * Such driver-private properties should really only be implemented for
457 * truly hardware/vendor specific state. Instead it is preferred to
458 * standardize atomic extension and decode the properties used to expose
459 * such an extension in the core.
460 *
461 * Do not call this function directly, use
462 * drm_atomic_crtc_set_property() instead.
463 *
464 * This callback is optional if the driver does not support any
465 * driver-private atomic properties.
466 *
467 * NOTE:
468 *
469 * This function is called in the state assembly phase of atomic
470 * modesets, which can be aborted for any reason (including on
471 * userspace's request to just check whether a configuration would be
472 * possible). Drivers MUST NOT touch any persistent state (hardware or
473 * software) or data structures except the passed in @state parameter.
474 *
475 * Also since userspace controls in which order properties are set this
476 * function must not do any input validation (since the state update is
477 * incomplete and hence likely inconsistent). Instead any such input
478 * validation must be done in the various atomic_check callbacks.
479 *
480 * RETURNS:
481 *
482 * 0 if the property has been found, -EINVAL if the property isn't
483 * implemented by the driver (which should never happen, the core only
484 * asks for properties attached to this CRTC). No other validation is
485 * allowed by the driver. The core already checks that the property
486 * value is within the range (integer, valid enum value, ...) the driver
487 * set when registering the property.
488 */
144ecb97
DV
489 int (*atomic_set_property)(struct drm_crtc *crtc,
490 struct drm_crtc_state *state,
491 struct drm_property *property,
492 uint64_t val);
88548636
DV
493 /**
494 * @atomic_get_property:
495 *
496 * Reads out the decoded driver-private property. This is used to
c6b0ca3e 497 * implement the GETCRTC IOCTL.
88548636
DV
498 *
499 * Do not call this function directly, use
500 * drm_atomic_crtc_get_property() instead.
501 *
502 * This callback is optional if the driver does not support any
503 * driver-private atomic properties.
504 *
505 * RETURNS:
506 *
507 * 0 on success, -EINVAL if the property isn't implemented by the
508 * driver (which should never happen, the core only asks for
509 * properties attached to this CRTC).
510 */
ac9c9256
RC
511 int (*atomic_get_property)(struct drm_crtc *crtc,
512 const struct drm_crtc_state *state,
513 struct drm_property *property,
514 uint64_t *val);
79190ea2
BG
515
516 /**
517 * @late_register:
518 *
519 * This optional hook can be used to register additional userspace
520 * interfaces attached to the crtc like debugfs interfaces.
521 * It is called late in the driver load sequence from drm_dev_register().
522 * Everything added from this callback should be unregistered in
523 * the early_unregister callback.
524 *
525 * Returns:
526 *
527 * 0 on success, or a negative error code on failure.
528 */
529 int (*late_register)(struct drm_crtc *crtc);
530
531 /**
532 * @early_unregister:
533 *
534 * This optional hook should be used to unregister the additional
535 * userspace interfaces attached to the crtc from
536 * late_unregister(). It is called from drm_dev_unregister(),
537 * early in the driver unload sequence to disable userspace access
538 * before data structures are torndown.
539 */
540 void (*early_unregister)(struct drm_crtc *crtc);
f453ba04
DA
541};
542
543/**
3bf0401c 544 * struct drm_crtc - central CRTC control structure
7749163e 545 * @dev: parent DRM device
2c0c33d4 546 * @port: OF node used by drm_of_find_possible_crtcs()
7749163e 547 * @head: list management
ac3ba4a5 548 * @name: human readable name, can be overwritten by the driver
51fd371b 549 * @mutex: per-CRTC locking
7749163e 550 * @base: base KMS object for ID tracking etc.
e13161af
MR
551 * @primary: primary plane for this CRTC
552 * @cursor: cursor plane for this CRTC
2c0c33d4
DV
553 * @cursor_x: current x position of the cursor, used for universal cursor planes
554 * @cursor_y: current y position of the cursor, used for universal cursor planes
f453ba04 555 * @enabled: is this CRTC enabled?
7749163e
JB
556 * @mode: current mode timings
557 * @hwmode: mode timings as programmed to hw regs
f453ba04
DA
558 * @x: x position on screen
559 * @y: y position on screen
f453ba04 560 * @funcs: CRTC control functions
7749163e
JB
561 * @gamma_size: size of gamma ramp
562 * @gamma_store: gamma ramp values
7749163e 563 * @helper_private: mid-layer private data
bffd9de0 564 * @properties: property tracking for this CRTC
f453ba04
DA
565 *
566 * Each CRTC may have one or more connectors associated with it. This structure
567 * allows the CRTC to be controlled.
568 */
569struct drm_crtc {
570 struct drm_device *dev;
7e435aad 571 struct device_node *port;
f453ba04
DA
572 struct list_head head;
573
fa3ab4c2
VS
574 char *name;
575
ac3ba4a5
DV
576 /**
577 * @mutex:
29494c17
DV
578 *
579 * This provides a read lock for the overall crtc state (mode, dpms
580 * state, ...) and a write lock for everything which can be update
ac3ba4a5
DV
581 * without a full modeset (fb, cursor data, crtc properties ...). Full
582 * modeset also need to grab dev->mode_config.connection_mutex.
29494c17 583 */
51fd371b 584 struct drm_modeset_lock mutex;
29494c17 585
f453ba04
DA
586 struct drm_mode_object base;
587
e13161af
MR
588 /* primary and cursor planes for CRTC */
589 struct drm_plane *primary;
590 struct drm_plane *cursor;
591
96094081
DV
592 /**
593 * @index: Position inside the mode_config.list, can be used as an array
594 * index. It is invariant over the lifetime of the CRTC.
595 */
490d3d1b
CW
596 unsigned index;
597
161d0dc1
MR
598 /* position of cursor plane on crtc */
599 int cursor_x;
600 int cursor_y;
601
f453ba04
DA
602 bool enabled;
603
27641c3f 604 /* Requested mode from modesetting. */
f453ba04
DA
605 struct drm_display_mode mode;
606
27641c3f
MK
607 /* Programmed mode in hw, after adjustments for encoders,
608 * crtc, panel scaling etc. Needed for timestamping etc.
609 */
610 struct drm_display_mode hwmode;
611
f453ba04 612 int x, y;
f453ba04
DA
613 const struct drm_crtc_funcs *funcs;
614
5488dc16 615 /* Legacy FB CRTC gamma size for reporting to userspace */
f453ba04
DA
616 uint32_t gamma_size;
617 uint16_t *gamma_store;
618
619 /* if you are using the helper */
4490d4c7 620 const struct drm_crtc_helper_funcs *helper_private;
bffd9de0
PZ
621
622 struct drm_object_properties properties;
d059f652 623
3b24f7d6
DV
624 /**
625 * @state:
626 *
627 * Current atomic state for this CRTC.
628 */
144ecb97
DV
629 struct drm_crtc_state *state;
630
3b24f7d6
DV
631 /**
632 * @commit_list:
633 *
634 * List of &drm_crtc_commit structures tracking pending commits.
635 * Protected by @commit_lock. This list doesn't hold its own full
636 * reference, but burrows it from the ongoing commit. Commit entries
637 * must be removed from this list once the commit is fully completed,
638 * but before it's correspoding &drm_atomic_state gets destroyed.
639 */
640 struct list_head commit_list;
641
642 /**
643 * @commit_lock:
644 *
645 * Spinlock to protect @commit_list.
646 */
647 spinlock_t commit_lock;
648
649 /**
650 * @acquire_ctx:
651 *
652 * Per-CRTC implicit acquire context used by atomic drivers for legacy
653 * IOCTLs, so that atomic drivers can get at the locking acquire
654 * context.
d059f652
DV
655 */
656 struct drm_modeset_acquire_ctx *acquire_ctx;
f453ba04
DA
657};
658
144ecb97
DV
659/**
660 * struct drm_plane_state - mutable plane state
07cc0ef6 661 * @plane: backpointer to the plane
144ecb97 662 * @crtc: currently bound CRTC, NULL if disabled
cc4ceb48 663 * @fb: currently bound framebuffer
e2330f07 664 * @fence: optional fence to wait for before scanning out @fb
144ecb97
DV
665 * @crtc_x: left position of visible portion of plane on crtc
666 * @crtc_y: upper position of visible portion of plane on crtc
667 * @crtc_w: width of visible portion of plane on crtc
668 * @crtc_h: height of visible portion of plane on crtc
669 * @src_x: left position of visible portion of plane within
670 * plane (in 16.16)
671 * @src_y: upper position of visible portion of plane within
672 * plane (in 16.16)
673 * @src_w: width of visible portion of plane (in 16.16)
674 * @src_h: height of visible portion of plane (in 16.16)
ac3ba4a5 675 * @rotation: rotation of the plane
44d1240d
MS
676 * @zpos: priority of the given plane on crtc (optional)
677 * @normalized_zpos: normalized value of zpos: unique, range from 0 to N-1
678 * where N is the number of active planes for given crtc
d7da824d
VS
679 * @src: clipped source coordinates of the plane (in 16.16)
680 * @dst: clipped destination coordinates of the plane
681 * @visible: visibility of the plane
144ecb97
DV
682 * @state: backpointer to global drm_atomic_state
683 */
684struct drm_plane_state {
07cc0ef6
DV
685 struct drm_plane *plane;
686
6ddd388a
RC
687 struct drm_crtc *crtc; /* do not write directly, use drm_atomic_set_crtc_for_plane() */
688 struct drm_framebuffer *fb; /* do not write directly, use drm_atomic_set_fb_for_plane() */
e2330f07 689 struct fence *fence;
144ecb97
DV
690
691 /* Signed dest location allows it to be partially off screen */
692 int32_t crtc_x, crtc_y;
693 uint32_t crtc_w, crtc_h;
694
695 /* Source values are 16.16 fixed point */
696 uint32_t src_x, src_y;
697 uint32_t src_h, src_w;
698
1da30627
MR
699 /* Plane rotation */
700 unsigned int rotation;
701
44d1240d
MS
702 /* Plane zpos */
703 unsigned int zpos;
704 unsigned int normalized_zpos;
705
d7da824d
VS
706 /* Clipped coordinates */
707 struct drm_rect src, dst;
708
709 /*
710 * Is the plane actually visible? Can be false even
711 * if fb!=NULL and crtc!=NULL, due to clipping.
712 */
713 bool visible;
714
144ecb97 715 struct drm_atomic_state *state;
f453ba04
DA
716};
717
144ecb97 718
8cf5c917 719/**
3bf0401c 720 * struct drm_plane_funcs - driver plane control functions
8cf5c917
JB
721 */
722struct drm_plane_funcs {
88548636
DV
723 /**
724 * @update_plane:
725 *
726 * This is the legacy entry point to enable and configure the plane for
727 * the given CRTC and framebuffer. It is never called to disable the
728 * plane, i.e. the passed-in crtc and fb paramters are never NULL.
729 *
730 * The source rectangle in frame buffer memory coordinates is given by
731 * the src_x, src_y, src_w and src_h parameters (as 16.16 fixed point
732 * values). Devices that don't support subpixel plane coordinates can
733 * ignore the fractional part.
734 *
735 * The destination rectangle in CRTC coordinates is given by the
736 * crtc_x, crtc_y, crtc_w and crtc_h parameters (as integer values).
737 * Devices scale the source rectangle to the destination rectangle. If
738 * scaling is not supported, and the source rectangle size doesn't match
739 * the destination rectangle size, the driver must return a
740 * -<errorname>EINVAL</errorname> error.
741 *
742 * Drivers implementing atomic modeset should use
743 * drm_atomic_helper_update_plane() to implement this hook.
744 *
745 * RETURNS:
746 *
747 * 0 on success or a negative error code on failure.
748 */
8cf5c917
JB
749 int (*update_plane)(struct drm_plane *plane,
750 struct drm_crtc *crtc, struct drm_framebuffer *fb,
751 int crtc_x, int crtc_y,
752 unsigned int crtc_w, unsigned int crtc_h,
753 uint32_t src_x, uint32_t src_y,
754 uint32_t src_w, uint32_t src_h);
88548636
DV
755
756 /**
757 * @disable_plane:
758 *
759 * This is the legacy entry point to disable the plane. The DRM core
c6b0ca3e 760 * calls this method in response to a DRM_IOCTL_MODE_SETPLANE IOCTL call
88548636
DV
761 * with the frame buffer ID set to 0. Disabled planes must not be
762 * processed by the CRTC.
763 *
764 * Drivers implementing atomic modeset should use
765 * drm_atomic_helper_disable_plane() to implement this hook.
766 *
767 * RETURNS:
768 *
769 * 0 on success or a negative error code on failure.
770 */
8cf5c917 771 int (*disable_plane)(struct drm_plane *plane);
88548636
DV
772
773 /**
774 * @destroy:
775 *
776 * Clean up plane resources. This is only called at driver unload time
777 * through drm_mode_config_cleanup() since a plane cannot be hotplugged
778 * in DRM.
779 */
8cf5c917 780 void (*destroy)(struct drm_plane *plane);
88548636
DV
781
782 /**
783 * @reset:
784 *
785 * Reset plane hardware and software state to off. This function isn't
786 * called by the core directly, only through drm_mode_config_reset().
787 * It's not a helper hook only for historical reasons.
788 *
789 * Atomic drivers can use drm_atomic_helper_plane_reset() to reset
790 * atomic state using this hook.
791 */
2a0d7cfd 792 void (*reset)(struct drm_plane *plane);
4d93914a 793
88548636
DV
794 /**
795 * @set_property:
796 *
797 * This is the legacy entry point to update a property attached to the
798 * plane.
799 *
800 * Drivers implementing atomic modeset should use
801 * drm_atomic_helper_plane_set_property() to implement this hook.
802 *
803 * This callback is optional if the driver does not support any legacy
804 * driver-private properties.
805 *
806 * RETURNS:
807 *
808 * 0 on success or a negative error code on failure.
809 */
4d93914a
RC
810 int (*set_property)(struct drm_plane *plane,
811 struct drm_property *property, uint64_t val);
144ecb97 812
88548636
DV
813 /**
814 * @atomic_duplicate_state:
815 *
816 * Duplicate the current atomic state for this plane and return it.
817 * The core and helpers gurantee that any atomic state duplicated with
818 * this hook and still owned by the caller (i.e. not transferred to the
819 * driver by calling ->atomic_commit() from struct
820 * &drm_mode_config_funcs) will be cleaned up by calling the
821 * @atomic_destroy_state hook in this structure.
822 *
823 * Atomic drivers which don't subclass struct &drm_plane_state should use
824 * drm_atomic_helper_plane_duplicate_state(). Drivers that subclass the
825 * state structure to extend it with driver-private state should use
826 * __drm_atomic_helper_plane_duplicate_state() to make sure shared state is
827 * duplicated in a consistent fashion across drivers.
828 *
829 * It is an error to call this hook before plane->state has been
830 * initialized correctly.
831 *
832 * NOTE:
833 *
834 * If the duplicate state references refcounted resources this hook must
835 * acquire a reference for each of them. The driver must release these
836 * references again in @atomic_destroy_state.
837 *
838 * RETURNS:
839 *
840 * Duplicated atomic state or NULL when the allocation failed.
841 */
144ecb97 842 struct drm_plane_state *(*atomic_duplicate_state)(struct drm_plane *plane);
88548636
DV
843
844 /**
845 * @atomic_destroy_state:
846 *
847 * Destroy a state duplicated with @atomic_duplicate_state and release
848 * or unreference all resources it references
849 */
144ecb97 850 void (*atomic_destroy_state)(struct drm_plane *plane,
cc4ceb48 851 struct drm_plane_state *state);
88548636
DV
852
853 /**
854 * @atomic_set_property:
855 *
856 * Decode a driver-private property value and store the decoded value
857 * into the passed-in state structure. Since the atomic core decodes all
858 * standardized properties (even for extensions beyond the core set of
859 * properties which might not be implemented by all drivers) this
860 * requires drivers to subclass the state structure.
861 *
862 * Such driver-private properties should really only be implemented for
863 * truly hardware/vendor specific state. Instead it is preferred to
864 * standardize atomic extension and decode the properties used to expose
865 * such an extension in the core.
866 *
867 * Do not call this function directly, use
868 * drm_atomic_plane_set_property() instead.
869 *
870 * This callback is optional if the driver does not support any
871 * driver-private atomic properties.
872 *
873 * NOTE:
874 *
875 * This function is called in the state assembly phase of atomic
876 * modesets, which can be aborted for any reason (including on
877 * userspace's request to just check whether a configuration would be
878 * possible). Drivers MUST NOT touch any persistent state (hardware or
879 * software) or data structures except the passed in @state parameter.
880 *
881 * Also since userspace controls in which order properties are set this
882 * function must not do any input validation (since the state update is
883 * incomplete and hence likely inconsistent). Instead any such input
884 * validation must be done in the various atomic_check callbacks.
885 *
886 * RETURNS:
887 *
888 * 0 if the property has been found, -EINVAL if the property isn't
889 * implemented by the driver (which shouldn't ever happen, the core only
890 * asks for properties attached to this plane). No other validation is
891 * allowed by the driver. The core already checks that the property
892 * value is within the range (integer, valid enum value, ...) the driver
893 * set when registering the property.
894 */
144ecb97
DV
895 int (*atomic_set_property)(struct drm_plane *plane,
896 struct drm_plane_state *state,
897 struct drm_property *property,
898 uint64_t val);
88548636
DV
899
900 /**
901 * @atomic_get_property:
902 *
903 * Reads out the decoded driver-private property. This is used to
c6b0ca3e 904 * implement the GETPLANE IOCTL.
88548636
DV
905 *
906 * Do not call this function directly, use
907 * drm_atomic_plane_get_property() instead.
908 *
909 * This callback is optional if the driver does not support any
910 * driver-private atomic properties.
911 *
912 * RETURNS:
913 *
914 * 0 on success, -EINVAL if the property isn't implemented by the
915 * driver (which should never happen, the core only asks for
916 * properties attached to this plane).
917 */
ac9c9256
RC
918 int (*atomic_get_property)(struct drm_plane *plane,
919 const struct drm_plane_state *state,
920 struct drm_property *property,
921 uint64_t *val);
79190ea2
BG
922 /**
923 * @late_register:
924 *
925 * This optional hook can be used to register additional userspace
926 * interfaces attached to the plane like debugfs interfaces.
927 * It is called late in the driver load sequence from drm_dev_register().
928 * Everything added from this callback should be unregistered in
929 * the early_unregister callback.
930 *
931 * Returns:
932 *
933 * 0 on success, or a negative error code on failure.
934 */
935 int (*late_register)(struct drm_plane *plane);
936
937 /**
938 * @early_unregister:
939 *
940 * This optional hook should be used to unregister the additional
941 * userspace interfaces attached to the plane from
942 * late_unregister(). It is called from drm_dev_unregister(),
943 * early in the driver unload sequence to disable userspace access
944 * before data structures are torndown.
945 */
946 void (*early_unregister)(struct drm_plane *plane);
8cf5c917
JB
947};
948
e27dde3e
MR
949enum drm_plane_type {
950 DRM_PLANE_TYPE_OVERLAY,
951 DRM_PLANE_TYPE_PRIMARY,
952 DRM_PLANE_TYPE_CURSOR,
953};
954
88548636 955
8cf5c917 956/**
3bf0401c 957 * struct drm_plane - central DRM plane control structure
8cf5c917
JB
958 * @dev: DRM device this plane belongs to
959 * @head: for list management
ac3ba4a5 960 * @name: human readable name, can be overwritten by the driver
8cf5c917
JB
961 * @base: base mode object
962 * @possible_crtcs: pipes this plane can be bound to
963 * @format_types: array of formats supported by this plane
964 * @format_count: number of formats supported
7eb5f302 965 * @format_default: driver hasn't supplied supported formats for the plane
8cf5c917
JB
966 * @crtc: currently bound CRTC
967 * @fb: currently bound fb
2c0c33d4
DV
968 * @old_fb: Temporary tracking of the old fb while a modeset is ongoing. Used by
969 * drm_mode_set_config_internal() to implement correct refcounting.
8cf5c917 970 * @funcs: helper functions
4d93914a 971 * @properties: property tracking for this plane
e27dde3e 972 * @type: type of plane (overlay, primary, cursor)
144ecb97 973 * @state: current atomic state for this plane
44d1240d 974 * @zpos_property: zpos property for this plane
ac3ba4a5 975 * @helper_private: mid-layer private data
8cf5c917
JB
976 */
977struct drm_plane {
978 struct drm_device *dev;
979 struct list_head head;
980
9f4c97a2
VS
981 char *name;
982
ac3ba4a5
DV
983 /**
984 * @mutex:
985 *
986 * Protects modeset plane state, together with the mutex of &drm_crtc
987 * this plane is linked to (when active, getting actived or getting
988 * disabled).
989 */
4d02e2de
DV
990 struct drm_modeset_lock mutex;
991
8cf5c917
JB
992 struct drm_mode_object base;
993
994 uint32_t possible_crtcs;
995 uint32_t *format_types;
45e3743a 996 unsigned int format_count;
7eb5f302 997 bool format_default;
8cf5c917
JB
998
999 struct drm_crtc *crtc;
1000 struct drm_framebuffer *fb;
1001
3d30a59b
DV
1002 struct drm_framebuffer *old_fb;
1003
8cf5c917 1004 const struct drm_plane_funcs *funcs;
4d93914a
RC
1005
1006 struct drm_object_properties properties;
e27dde3e
MR
1007
1008 enum drm_plane_type type;
144ecb97 1009
96094081
DV
1010 /**
1011 * @index: Position inside the mode_config.list, can be used as an array
1012 * index. It is invariant over the lifetime of the plane.
1013 */
490d3d1b
CW
1014 unsigned index;
1015
4490d4c7 1016 const struct drm_plane_helper_funcs *helper_private;
c2fcd274 1017
144ecb97 1018 struct drm_plane_state *state;
44d1240d
MS
1019
1020 struct drm_property *zpos_property;
8cf5c917
JB
1021};
1022
3b24f7d6
DV
1023/**
1024 * struct drm_crtc_commit - track modeset commits on a CRTC
1025 *
1026 * This structure is used to track pending modeset changes and atomic commit on
1027 * a per-CRTC basis. Since updating the list should never block this structure
1028 * is reference counted to allow waiters to safely wait on an event to complete,
1029 * without holding any locks.
1030 *
1031 * It has 3 different events in total to allow a fine-grained synchronization
1032 * between outstanding updates::
1033 *
1034 * atomic commit thread hardware
1035 *
1036 * write new state into hardware ----> ...
1037 * signal hw_done
1038 * switch to new state on next
1039 * ... v/hblank
1040 *
1041 * wait for buffers to show up ...
1042 *
1043 * ... send completion irq
1044 * irq handler signals flip_done
1045 * cleanup old buffers
1046 *
1047 * signal cleanup_done
1048 *
1049 * wait for flip_done <----
1050 * clean up atomic state
1051 *
1052 * The important bit to know is that cleanup_done is the terminal event, but the
1053 * ordering between flip_done and hw_done is entirely up to the specific driver
1054 * and modeset state change.
1055 *
1056 * For an implementation of how to use this look at
1057 * drm_atomic_helper_setup_commit() from the atomic helper library.
1058 */
1059struct drm_crtc_commit {
1060 /**
1061 * @crtc:
1062 *
1063 * DRM CRTC for this commit.
1064 */
1065 struct drm_crtc *crtc;
1066
1067 /**
1068 * @ref:
1069 *
1070 * Reference count for this structure. Needed to allow blocking on
1071 * completions without the risk of the completion disappearing
1072 * meanwhile.
1073 */
1074 struct kref ref;
1075
1076 /**
1077 * @flip_done:
1078 *
1079 * Will be signaled when the hardware has flipped to the new set of
1080 * buffers. Signals at the same time as when the drm event for this
1081 * commit is sent to userspace, or when an out-fence is singalled. Note
1082 * that for most hardware, in most cases this happens after @hw_done is
1083 * signalled.
1084 */
1085 struct completion flip_done;
1086
1087 /**
1088 * @hw_done:
1089 *
1090 * Will be signalled when all hw register changes for this commit have
1091 * been written out. Especially when disabling a pipe this can be much
1092 * later than than @flip_done, since that can signal already when the
1093 * screen goes black, whereas to fully shut down a pipe more register
1094 * I/O is required.
1095 *
1096 * Note that this does not need to include separately reference-counted
1097 * resources like backing storage buffer pinning, or runtime pm
1098 * management.
1099 */
1100 struct completion hw_done;
1101
1102 /**
1103 * @cleanup_done:
1104 *
1105 * Will be signalled after old buffers have been cleaned up by calling
1106 * drm_atomic_helper_cleanup_planes(). Since this can only happen after
1107 * a vblank wait completed it might be a bit later. This completion is
1108 * useful to throttle updates and avoid hardware updates getting ahead
1109 * of the buffer cleanup too much.
1110 */
1111 struct completion cleanup_done;
1112
1113 /**
1114 * @commit_entry:
1115 *
1116 * Entry on the per-CRTC commit_list. Protected by crtc->commit_lock.
1117 */
1118 struct list_head commit_entry;
1119
1120 /**
1121 * @event:
1122 *
1123 * &drm_pending_vblank_event pointer to clean up private events.
1124 */
1125 struct drm_pending_vblank_event *event;
1126};
1127
b8b5342b
DV
1128struct __drm_planes_state {
1129 struct drm_plane *ptr;
1130 struct drm_plane_state *state;
1131};
1132
5d943aa6
DV
1133struct __drm_crtcs_state {
1134 struct drm_crtc *ptr;
1135 struct drm_crtc_state *state;
3b24f7d6 1136 struct drm_crtc_commit *commit;
5d943aa6
DV
1137};
1138
63e83c1d
DV
1139struct __drm_connnectors_state {
1140 struct drm_connector *ptr;
1141 struct drm_connector_state *state;
1142};
1143
cc4ceb48 1144/**
08855fae 1145 * struct drm_atomic_state - the global state object for atomic updates
cc4ceb48 1146 * @dev: parent DRM device
d34f20d6 1147 * @allow_modeset: allow full modeset
c6b0ca3e 1148 * @legacy_cursor_update: hint to enforce legacy cursor IOCTL semantics
40616a26 1149 * @legacy_set_config: Disable conflicting encoders instead of failing with -EINVAL.
b8b5342b 1150 * @planes: pointer to array of structures with per-plane data
cc4ceb48 1151 * @crtcs: pointer to array of CRTC pointers
f52b69f1 1152 * @num_connector: size of the @connectors and @connector_states arrays
63e83c1d 1153 * @connectors: pointer to array of structures with per-connector data
cc4ceb48
DV
1154 * @acquire_ctx: acquire context for this atomic modeset state update
1155 */
1156struct drm_atomic_state {
1157 struct drm_device *dev;
d34f20d6 1158 bool allow_modeset : 1;
f02ad907 1159 bool legacy_cursor_update : 1;
40616a26 1160 bool legacy_set_config : 1;
b8b5342b 1161 struct __drm_planes_state *planes;
5d943aa6 1162 struct __drm_crtcs_state *crtcs;
f52b69f1 1163 int num_connector;
63e83c1d 1164 struct __drm_connnectors_state *connectors;
cc4ceb48
DV
1165
1166 struct drm_modeset_acquire_ctx *acquire_ctx;
3b24f7d6
DV
1167
1168 /**
1169 * @commit_work:
1170 *
1171 * Work item which can be used by the driver or helpers to execute the
1172 * commit without blocking.
1173 */
1174 struct work_struct commit_work;
cc4ceb48
DV
1175};
1176
1177
f453ba04 1178/**
3bf0401c 1179 * struct drm_mode_set - new values for a CRTC config change
ef27351a
JB
1180 * @fb: framebuffer to use for new config
1181 * @crtc: CRTC whose configuration we're about to change
1182 * @mode: mode timings to use
1183 * @x: position of this CRTC relative to @fb
1184 * @y: position of this CRTC relative to @fb
1185 * @connectors: array of connectors to drive with this CRTC if possible
1186 * @num_connectors: size of @connectors array
f453ba04
DA
1187 *
1188 * Represents a single crtc the connectors that it drives with what mode
1189 * and from which framebuffer it scans out from.
1190 *
1191 * This is used to set modes.
1192 */
1193struct drm_mode_set {
f453ba04
DA
1194 struct drm_framebuffer *fb;
1195 struct drm_crtc *crtc;
1196 struct drm_display_mode *mode;
1197
1198 uint32_t x;
1199 uint32_t y;
1200
1201 struct drm_connector **connectors;
1202 size_t num_connectors;
1203};
1204
1205/**
550cebcd 1206 * struct drm_mode_config_funcs - basic driver provided mode setting functions
550cebcd
JB
1207 *
1208 * Some global (i.e. not per-CRTC, connector, etc) mode setting functions that
1209 * involve drivers.
f453ba04
DA
1210 */
1211struct drm_mode_config_funcs {
9953f417
DV
1212 /**
1213 * @fb_create:
1214 *
1215 * Create a new framebuffer object. The core does basic checks on the
1216 * requested metadata, but most of that is left to the driver. See
1217 * struct &drm_mode_fb_cmd2 for details.
1218 *
d55f5320
DV
1219 * If the parameters are deemed valid and the backing storage objects in
1220 * the underlying memory manager all exist, then the driver allocates
1221 * a new &drm_framebuffer structure, subclassed to contain
1222 * driver-specific information (like the internal native buffer object
1223 * references). It also needs to fill out all relevant metadata, which
1224 * should be done by calling drm_helper_mode_fill_fb_struct().
1225 *
1226 * The initialization is finalized by calling drm_framebuffer_init(),
1227 * which registers the framebuffer and makes it accessible to other
1228 * threads.
1229 *
9953f417
DV
1230 * RETURNS:
1231 *
1232 * A new framebuffer with an initial reference count of 1 or a negative
1233 * error code encoded with ERR_PTR().
1234 */
550cebcd
JB
1235 struct drm_framebuffer *(*fb_create)(struct drm_device *dev,
1236 struct drm_file *file_priv,
1eb83451 1237 const struct drm_mode_fb_cmd2 *mode_cmd);
9953f417
DV
1238
1239 /**
1240 * @output_poll_changed:
1241 *
1242 * Callback used by helpers to inform the driver of output configuration
1243 * changes.
1244 *
1245 * Drivers implementing fbdev emulation with the helpers can call
1246 * drm_fb_helper_hotplug_changed from this hook to inform the fbdev
1247 * helper of output changes.
1248 *
1249 * FIXME:
1250 *
1251 * Except that there's no vtable for device-level helper callbacks
1252 * there's no reason this is a core function.
1253 */
eb1f8e4f 1254 void (*output_poll_changed)(struct drm_device *dev);
cc4ceb48 1255
9953f417
DV
1256 /**
1257 * @atomic_check:
1258 *
1259 * This is the only hook to validate an atomic modeset update. This
1260 * function must reject any modeset and state changes which the hardware
1261 * or driver doesn't support. This includes but is of course not limited
1262 * to:
1263 *
1264 * - Checking that the modes, framebuffers, scaling and placement
1265 * requirements and so on are within the limits of the hardware.
1266 *
1267 * - Checking that any hidden shared resources are not oversubscribed.
1268 * This can be shared PLLs, shared lanes, overall memory bandwidth,
1269 * display fifo space (where shared between planes or maybe even
1270 * CRTCs).
1271 *
1272 * - Checking that virtualized resources exported to userspace are not
1273 * oversubscribed. For various reasons it can make sense to expose
1274 * more planes, crtcs or encoders than which are physically there. One
1275 * example is dual-pipe operations (which generally should be hidden
1276 * from userspace if when lockstepped in hardware, exposed otherwise),
1277 * where a plane might need 1 hardware plane (if it's just on one
1278 * pipe), 2 hardware planes (when it spans both pipes) or maybe even
1279 * shared a hardware plane with a 2nd plane (if there's a compatible
1280 * plane requested on the area handled by the other pipe).
1281 *
1282 * - Check that any transitional state is possible and that if
1283 * requested, the update can indeed be done in the vblank period
1284 * without temporarily disabling some functions.
1285 *
1286 * - Check any other constraints the driver or hardware might have.
1287 *
1288 * - This callback also needs to correctly fill out the &drm_crtc_state
1289 * in this update to make sure that drm_atomic_crtc_needs_modeset()
1290 * reflects the nature of the possible update and returns true if and
1291 * only if the update cannot be applied without tearing within one
1292 * vblank on that CRTC. The core uses that information to reject
1293 * updates which require a full modeset (i.e. blanking the screen, or
1294 * at least pausing updates for a substantial amount of time) if
1295 * userspace has disallowed that in its request.
1296 *
1297 * - The driver also does not need to repeat basic input validation
1298 * like done for the corresponding legacy entry points. The core does
1299 * that before calling this hook.
1300 *
1301 * See the documentation of @atomic_commit for an exhaustive list of
1302 * error conditions which don't have to be checked at the
1303 * ->atomic_check() stage?
1304 *
1305 * See the documentation for struct &drm_atomic_state for how exactly
1306 * an atomic modeset update is described.
1307 *
1308 * Drivers using the atomic helpers can implement this hook using
1309 * drm_atomic_helper_check(), or one of the exported sub-functions of
1310 * it.
1311 *
1312 * RETURNS:
1313 *
1314 * 0 on success or one of the below negative error codes:
1315 *
1316 * - -EINVAL, if any of the above constraints are violated.
1317 *
1318 * - -EDEADLK, when returned from an attempt to acquire an additional
1319 * &drm_modeset_lock through drm_modeset_lock().
1320 *
1321 * - -ENOMEM, if allocating additional state sub-structures failed due
1322 * to lack of memory.
1323 *
1324 * - -EINTR, -EAGAIN or -ERESTARTSYS, if the IOCTL should be restarted.
1325 * This can either be due to a pending signal, or because the driver
1326 * needs to completely bail out to recover from an exceptional
1327 * situation like a GPU hang. From a userspace point all errors are
1328 * treated equally.
1329 */
cc4ceb48 1330 int (*atomic_check)(struct drm_device *dev,
9953f417
DV
1331 struct drm_atomic_state *state);
1332
1333 /**
1334 * @atomic_commit:
1335 *
1336 * This is the only hook to commit an atomic modeset update. The core
1337 * guarantees that @atomic_check has been called successfully before
1338 * calling this function, and that nothing has been changed in the
1339 * interim.
1340 *
1341 * See the documentation for struct &drm_atomic_state for how exactly
1342 * an atomic modeset update is described.
1343 *
1344 * Drivers using the atomic helpers can implement this hook using
1345 * drm_atomic_helper_commit(), or one of the exported sub-functions of
1346 * it.
1347 *
286dbb8d 1348 * Nonblocking commits (as indicated with the nonblock parameter) must
9953f417
DV
1349 * do any preparatory work which might result in an unsuccessful commit
1350 * in the context of this callback. The only exceptions are hardware
1351 * errors resulting in -EIO. But even in that case the driver must
1352 * ensure that the display pipe is at least running, to avoid
1353 * compositors crashing when pageflips don't work. Anything else,
1354 * specifically committing the update to the hardware, should be done
1355 * without blocking the caller. For updates which do not require a
1356 * modeset this must be guaranteed.
1357 *
1358 * The driver must wait for any pending rendering to the new
1359 * framebuffers to complete before executing the flip. It should also
1360 * wait for any pending rendering from other drivers if the underlying
286dbb8d 1361 * buffer is a shared dma-buf. Nonblocking commits must not wait for
9953f417
DV
1362 * rendering in the context of this callback.
1363 *
1364 * An application can request to be notified when the atomic commit has
1365 * completed. These events are per-CRTC and can be distinguished by the
1366 * CRTC index supplied in &drm_event to userspace.
1367 *
1368 * The drm core will supply a struct &drm_event in the event
1369 * member of each CRTC's &drm_crtc_state structure. This can be handled by the
1370 * drm_crtc_send_vblank_event() function, which the driver should call on
1371 * the provided event upon completion of the atomic commit. Note that if
1372 * the driver supports vblank signalling and timestamping the vblank
1373 * counters and timestamps must agree with the ones returned from page
1374 * flip events. With the current vblank helper infrastructure this can
1375 * be achieved by holding a vblank reference while the page flip is
1376 * pending, acquired through drm_crtc_vblank_get() and released with
1377 * drm_crtc_vblank_put(). Drivers are free to implement their own vblank
1378 * counter and timestamp tracking though, e.g. if they have accurate
1379 * timestamp registers in hardware.
1380 *
1381 * NOTE:
1382 *
1383 * Drivers are not allowed to shut down any display pipe successfully
1384 * enabled through an atomic commit on their own. Doing so can result in
1385 * compositors crashing if a page flip is suddenly rejected because the
1386 * pipe is off.
1387 *
1388 * RETURNS:
1389 *
1390 * 0 on success or one of the below negative error codes:
1391 *
286dbb8d 1392 * - -EBUSY, if a nonblocking updated is requested and there is
9953f417
DV
1393 * an earlier updated pending. Drivers are allowed to support a queue
1394 * of outstanding updates, but currently no driver supports that.
1395 * Note that drivers must wait for preceding updates to complete if a
1396 * synchronous update is requested, they are not allowed to fail the
1397 * commit in that case.
1398 *
1399 * - -ENOMEM, if the driver failed to allocate memory. Specifically
1400 * this can happen when trying to pin framebuffers, which must only
1401 * be done when committing the state.
1402 *
1403 * - -ENOSPC, as a refinement of the more generic -ENOMEM to indicate
1404 * that the driver has run out of vram, iommu space or similar GPU
1405 * address space needed for framebuffer.
1406 *
1407 * - -EIO, if the hardware completely died.
1408 *
1409 * - -EINTR, -EAGAIN or -ERESTARTSYS, if the IOCTL should be restarted.
1410 * This can either be due to a pending signal, or because the driver
1411 * needs to completely bail out to recover from an exceptional
1412 * situation like a GPU hang. From a userspace point of view all errors are
1413 * treated equally.
1414 *
1415 * This list is exhaustive. Specifically this hook is not allowed to
1416 * return -EINVAL (any invalid requests should be caught in
1417 * @atomic_check) or -EDEADLK (this function must not acquire
1418 * additional modeset locks).
1419 */
cc4ceb48 1420 int (*atomic_commit)(struct drm_device *dev,
9953f417 1421 struct drm_atomic_state *state,
286dbb8d 1422 bool nonblock);
9953f417
DV
1423
1424 /**
1425 * @atomic_state_alloc:
1426 *
1427 * This optional hook can be used by drivers that want to subclass struct
1428 * &drm_atomic_state to be able to track their own driver-private global
1429 * state easily. If this hook is implemented, drivers must also
1430 * implement @atomic_state_clear and @atomic_state_free.
1431 *
1432 * RETURNS:
1433 *
1434 * A new &drm_atomic_state on success or NULL on failure.
1435 */
036ef573 1436 struct drm_atomic_state *(*atomic_state_alloc)(struct drm_device *dev);
9953f417
DV
1437
1438 /**
1439 * @atomic_state_clear:
1440 *
1441 * This hook must clear any driver private state duplicated into the
1442 * passed-in &drm_atomic_state. This hook is called when the caller
1443 * encountered a &drm_modeset_lock deadlock and needs to drop all
1444 * already acquired locks as part of the deadlock avoidance dance
1445 * implemented in drm_modeset_lock_backoff().
1446 *
1447 * Any duplicated state must be invalidated since a concurrent atomic
1448 * update might change it, and the drm atomic interfaces always apply
1449 * updates as relative changes to the current state.
1450 *
1451 * Drivers that implement this must call drm_atomic_state_default_clear()
1452 * to clear common state.
1453 */
036ef573 1454 void (*atomic_state_clear)(struct drm_atomic_state *state);
9953f417
DV
1455
1456 /**
1457 * @atomic_state_free:
1458 *
1459 * This hook needs driver private resources and the &drm_atomic_state
1460 * itself. Note that the core first calls drm_atomic_state_clear() to
1461 * avoid code duplicate between the clear and free hooks.
1462 *
1463 * Drivers that implement this must call drm_atomic_state_default_free()
1464 * to release common resources.
1465 */
036ef573 1466 void (*atomic_state_free)(struct drm_atomic_state *state);
f453ba04
DA
1467};
1468
f453ba04 1469/**
2c0c33d4 1470 * struct drm_mode_config - Mode configuration control structure
a62c93d5 1471 * @mutex: mutex protecting KMS related lists and structures
2c0c33d4
DV
1472 * @connection_mutex: ww mutex protecting connector state and routing
1473 * @acquire_ctx: global implicit acquire context used by atomic drivers for
c6b0ca3e 1474 * legacy IOCTLs
2c0c33d4 1475 * @fb_lock: mutex to protect fb state and lists
a62c93d5
JB
1476 * @num_fb: number of fbs available
1477 * @fb_list: list of framebuffers available
a62c93d5
JB
1478 * @num_encoder: number of encoders on this device
1479 * @encoder_list: list of encoder objects
2c0c33d4
DV
1480 * @num_overlay_plane: number of overlay planes on this device
1481 * @num_total_plane: number of universal (i.e. with primary/curso) planes on this device
1482 * @plane_list: list of plane objects
a62c93d5
JB
1483 * @num_crtc: number of CRTCs on this device
1484 * @crtc_list: list of CRTC objects
2c0c33d4 1485 * @property_list: list of property objects
a62c93d5
JB
1486 * @min_width: minimum pixel width on this device
1487 * @min_height: minimum pixel height on this device
1488 * @max_width: maximum pixel width on this device
1489 * @max_height: maximum pixel height on this device
1490 * @funcs: core driver provided mode setting functions
1491 * @fb_base: base address of the framebuffer
2c0c33d4
DV
1492 * @poll_enabled: track polling support for this device
1493 * @poll_running: track polling status for this device
ac3ba4a5 1494 * @delayed_event: track delayed poll uevent deliver for this device
a62c93d5 1495 * @output_poll_work: delayed work for polling in process context
2c0c33d4 1496 * @property_blob_list: list of all the blob property objects
8fb6e7a5 1497 * @blob_lock: mutex for blob property allocation and management
a62c93d5 1498 * @*_property: core property tracking
2c0c33d4
DV
1499 * @preferred_depth: preferred RBG pixel depth, used by fb helpers
1500 * @prefer_shadow: hint to userspace to prefer shadow-fb rendering
2c0c33d4
DV
1501 * @cursor_width: hint to userspace for max cursor width
1502 * @cursor_height: hint to userspace for max cursor height
9f2a7950 1503 * @helper_private: mid-layer private data
f453ba04 1504 *
a62c93d5
JB
1505 * Core mode resource tracking structure. All CRTC, encoders, and connectors
1506 * enumerated by the driver are added here, as are global properties. Some
1507 * global restrictions are also here, e.g. dimension restrictions.
f453ba04
DA
1508 */
1509struct drm_mode_config {
ad2563c2 1510 struct mutex mutex; /* protects configuration (mode lists etc.) */
51fd371b
RC
1511 struct drm_modeset_lock connection_mutex; /* protects connector->encoder and encoder->crtc links */
1512 struct drm_modeset_acquire_ctx *acquire_ctx; /* for legacy _lock_all() / _unlock_all() */
ac3ba4a5
DV
1513
1514 /**
1515 * @idr_mutex:
1516 *
1517 * Mutex for KMS ID allocation and management. Protects both @crtc_idr
1518 * and @tile_idr.
1519 */
1520 struct mutex idr_mutex;
1521
1522 /**
1523 * @crtc_idr:
1524 *
1525 * Main KMS ID tracking object. Use this idr for all IDs, fb, crtc,
1526 * connector, modes - just makes life easier to have only one.
1527 */
1528 struct idr crtc_idr;
1529
1530 /**
1531 * @tile_idr:
1532 *
1533 * Use this idr for allocating new IDs for tiled sinks like use in some
1534 * high-res DP MST screens.
1535 */
1536 struct idr tile_idr;
4b096ac1 1537
2c0c33d4 1538 struct mutex fb_lock; /* proctects global and per-file fb lists */
f453ba04
DA
1539 int num_fb;
1540 struct list_head fb_list;
4b096ac1 1541
96094081
DV
1542 /**
1543 * @num_connector: Number of connectors on this device.
1544 */
f453ba04 1545 int num_connector;
96094081
DV
1546 /**
1547 * @connector_ida: ID allocator for connector indices.
1548 */
5fff80bb 1549 struct ida connector_ida;
96094081
DV
1550 /**
1551 * @connector_list: List of connector objects.
1552 */
f453ba04
DA
1553 struct list_head connector_list;
1554 int num_encoder;
1555 struct list_head encoder_list;
e27dde3e
MR
1556
1557 /*
1558 * Track # of overlay planes separately from # of total planes. By
1559 * default we only advertise overlay planes to userspace; if userspace
1560 * sets the "universal plane" capability bit, we'll go ahead and
1561 * expose all planes.
1562 */
1563 int num_overlay_plane;
1564 int num_total_plane;
8cf5c917 1565 struct list_head plane_list;
f453ba04
DA
1566
1567 int num_crtc;
1568 struct list_head crtc_list;
1569
1570 struct list_head property_list;
1571
f453ba04
DA
1572 int min_width, min_height;
1573 int max_width, max_height;
e6ecefaa 1574 const struct drm_mode_config_funcs *funcs;
d883f7f1 1575 resource_size_t fb_base;
f453ba04 1576
eb1f8e4f
DA
1577 /* output poll support */
1578 bool poll_enabled;
905bc9ff 1579 bool poll_running;
162b6a57 1580 bool delayed_event;
991ea75c 1581 struct delayed_work output_poll_work;
eb1f8e4f 1582
8fb6e7a5
DS
1583 struct mutex blob_lock;
1584
f453ba04
DA
1585 /* pointers to standard properties */
1586 struct list_head property_blob_list;
9a6bc03c
DV
1587 /**
1588 * @edid_property: Default connector property to hold the EDID of the
1589 * currently connected sink, if any.
1590 */
f453ba04 1591 struct drm_property *edid_property;
9a6bc03c
DV
1592 /**
1593 * @dpms_property: Default connector property to control the
1594 * connector's DPMS state.
1595 */
f453ba04 1596 struct drm_property *dpms_property;
9a6bc03c
DV
1597 /**
1598 * @path_property: Default connector property to hold the DP MST path
1599 * for the port.
1600 */
43aba7eb 1601 struct drm_property *path_property;
9a6bc03c
DV
1602 /**
1603 * @tile_property: Default connector property to store the tile
1604 * position of a tiled screen, for sinks which need to be driven with
1605 * multiple CRTCs.
1606 */
6f134d7b 1607 struct drm_property *tile_property;
9a6bc03c
DV
1608 /**
1609 * @plane_type_property: Default plane property to differentiate
1610 * CURSOR, PRIMARY and OVERLAY legacy uses of planes.
1611 */
9922ab5a 1612 struct drm_property *plane_type_property;
9a6bc03c
DV
1613 /**
1614 * @rotation_property: Optional property for planes or CRTCs to specifiy
1615 * rotation.
1616 */
2a297cce 1617 struct drm_property *rotation_property;
9a6bc03c
DV
1618 /**
1619 * @prop_src_x: Default atomic plane property for the plane source
1620 * position in the connected &drm_framebuffer.
1621 */
6b4959f4 1622 struct drm_property *prop_src_x;
9a6bc03c
DV
1623 /**
1624 * @prop_src_y: Default atomic plane property for the plane source
1625 * position in the connected &drm_framebuffer.
1626 */
6b4959f4 1627 struct drm_property *prop_src_y;
9a6bc03c
DV
1628 /**
1629 * @prop_src_w: Default atomic plane property for the plane source
1630 * position in the connected &drm_framebuffer.
1631 */
6b4959f4 1632 struct drm_property *prop_src_w;
9a6bc03c
DV
1633 /**
1634 * @prop_src_h: Default atomic plane property for the plane source
1635 * position in the connected &drm_framebuffer.
1636 */
6b4959f4 1637 struct drm_property *prop_src_h;
9a6bc03c
DV
1638 /**
1639 * @prop_crtc_x: Default atomic plane property for the plane destination
1640 * position in the &drm_crtc is is being shown on.
1641 */
6b4959f4 1642 struct drm_property *prop_crtc_x;
9a6bc03c
DV
1643 /**
1644 * @prop_crtc_y: Default atomic plane property for the plane destination
1645 * position in the &drm_crtc is is being shown on.
1646 */
6b4959f4 1647 struct drm_property *prop_crtc_y;
9a6bc03c
DV
1648 /**
1649 * @prop_crtc_w: Default atomic plane property for the plane destination
1650 * position in the &drm_crtc is is being shown on.
1651 */
6b4959f4 1652 struct drm_property *prop_crtc_w;
9a6bc03c
DV
1653 /**
1654 * @prop_crtc_h: Default atomic plane property for the plane destination
1655 * position in the &drm_crtc is is being shown on.
1656 */
6b4959f4 1657 struct drm_property *prop_crtc_h;
9a6bc03c
DV
1658 /**
1659 * @prop_fb_id: Default atomic plane property to specify the
1660 * &drm_framebuffer.
1661 */
6b4959f4 1662 struct drm_property *prop_fb_id;
9a6bc03c
DV
1663 /**
1664 * @prop_crtc_id: Default atomic plane property to specify the
1665 * &drm_crtc.
1666 */
6b4959f4 1667 struct drm_property *prop_crtc_id;
9a6bc03c
DV
1668 /**
1669 * @prop_active: Default atomic CRTC property to control the active
1670 * state, which is the simplified implementation for DPMS in atomic
1671 * drivers.
1672 */
eab3bbef 1673 struct drm_property *prop_active;
9a6bc03c
DV
1674 /**
1675 * @prop_mode_id: Default atomic CRTC property to set the mode for a
1676 * CRTC. A 0 mode implies that the CRTC is entirely disabled - all
1677 * connectors must be of and active must be set to disabled, too.
1678 */
955f3c33 1679 struct drm_property *prop_mode_id;
f453ba04 1680
9a6bc03c
DV
1681 /**
1682 * @dvi_i_subconnector_property: Optional DVI-I property to
1683 * differentiate between analog or digital mode.
1684 */
f453ba04 1685 struct drm_property *dvi_i_subconnector_property;
9a6bc03c
DV
1686 /**
1687 * @dvi_i_select_subconnector_property: Optional DVI-I property to
1688 * select between analog or digital mode.
1689 */
f453ba04
DA
1690 struct drm_property *dvi_i_select_subconnector_property;
1691
9a6bc03c
DV
1692 /**
1693 * @tv_subconnector_property: Optional TV property to differentiate
1694 * between different TV connector types.
1695 */
f453ba04 1696 struct drm_property *tv_subconnector_property;
9a6bc03c
DV
1697 /**
1698 * @tv_select_subconnector_property: Optional TV property to select
1699 * between different TV connector types.
1700 */
f453ba04 1701 struct drm_property *tv_select_subconnector_property;
9a6bc03c
DV
1702 /**
1703 * @tv_mode_property: Optional TV property to select
1704 * the output TV mode.
1705 */
f453ba04 1706 struct drm_property *tv_mode_property;
9a6bc03c
DV
1707 /**
1708 * @tv_left_margin_property: Optional TV property to set the left
1709 * margin.
1710 */
f453ba04 1711 struct drm_property *tv_left_margin_property;
9a6bc03c
DV
1712 /**
1713 * @tv_right_margin_property: Optional TV property to set the right
1714 * margin.
1715 */
f453ba04 1716 struct drm_property *tv_right_margin_property;
9a6bc03c
DV
1717 /**
1718 * @tv_top_margin_property: Optional TV property to set the right
1719 * margin.
1720 */
f453ba04 1721 struct drm_property *tv_top_margin_property;
9a6bc03c
DV
1722 /**
1723 * @tv_bottom_margin_property: Optional TV property to set the right
1724 * margin.
1725 */
f453ba04 1726 struct drm_property *tv_bottom_margin_property;
9a6bc03c
DV
1727 /**
1728 * @tv_brightness_property: Optional TV property to set the
1729 * brightness.
1730 */
b6b7902e 1731 struct drm_property *tv_brightness_property;
9a6bc03c
DV
1732 /**
1733 * @tv_contrast_property: Optional TV property to set the
1734 * contrast.
1735 */
b6b7902e 1736 struct drm_property *tv_contrast_property;
9a6bc03c
DV
1737 /**
1738 * @tv_flicker_reduction_property: Optional TV property to control the
1739 * flicker reduction mode.
1740 */
b6b7902e 1741 struct drm_property *tv_flicker_reduction_property;
9a6bc03c
DV
1742 /**
1743 * @tv_overscan_property: Optional TV property to control the overscan
1744 * setting.
1745 */
a75f0236 1746 struct drm_property *tv_overscan_property;
9a6bc03c
DV
1747 /**
1748 * @tv_saturation_property: Optional TV property to set the
1749 * saturation.
1750 */
a75f0236 1751 struct drm_property *tv_saturation_property;
9a6bc03c
DV
1752 /**
1753 * @tv_hue_property: Optional TV property to set the hue.
1754 */
a75f0236 1755 struct drm_property *tv_hue_property;
f453ba04 1756
9a6bc03c
DV
1757 /**
1758 * @scaling_mode_property: Optional connector property to control the
1759 * upscaling, mostly used for built-in panels.
1760 */
f453ba04 1761 struct drm_property *scaling_mode_property;
9a6bc03c
DV
1762 /**
1763 * @aspect_ratio_property: Optional connector property to control the
1764 * HDMI infoframe aspect ratio setting.
1765 */
ff587e45 1766 struct drm_property *aspect_ratio_property;
9a6bc03c
DV
1767 /**
1768 * @degamma_lut_property: Optional CRTC property to set the LUT used to
1769 * convert the framebuffer's colors to linear gamma.
1770 */
5488dc16 1771 struct drm_property *degamma_lut_property;
9a6bc03c
DV
1772 /**
1773 * @degamma_lut_size_property: Optional CRTC property for the size of
1774 * the degamma LUT as supported by the driver (read-only).
1775 */
5488dc16 1776 struct drm_property *degamma_lut_size_property;
9a6bc03c
DV
1777 /**
1778 * @ctm_property: Optional CRTC property to set the
1779 * matrix used to convert colors after the lookup in the
1780 * degamma LUT.
1781 */
5488dc16 1782 struct drm_property *ctm_property;
9a6bc03c
DV
1783 /**
1784 * @gamma_lut_property: Optional CRTC property to set the LUT used to
1785 * convert the colors, after the CTM matrix, to the gamma space of the
1786 * connected screen.
1787 */
5488dc16 1788 struct drm_property *gamma_lut_property;
9a6bc03c
DV
1789 /**
1790 * @gamma_lut_size_property: Optional CRTC property for the size of the
1791 * gamma LUT as supported by the driver (read-only).
1792 */
5488dc16
LL
1793 struct drm_property *gamma_lut_size_property;
1794
9a6bc03c
DV
1795 /**
1796 * @suggested_x_property: Optional connector property with a hint for
1797 * the position of the output on the host's screen.
1798 */
5bb2bbf5 1799 struct drm_property *suggested_x_property;
9a6bc03c
DV
1800 /**
1801 * @suggested_y_property: Optional connector property with a hint for
1802 * the position of the output on the host's screen.
1803 */
5bb2bbf5
DA
1804 struct drm_property *suggested_y_property;
1805
019d96cb
DA
1806 /* dumb ioctl parameters */
1807 uint32_t preferred_depth, prefer_shadow;
62f2104f 1808
9a6bc03c
DV
1809 /**
1810 * @async_page_flip: Does this device support async flips on the primary
1811 * plane?
1812 */
62f2104f 1813 bool async_page_flip;
8716ed4e 1814
ac3ba4a5
DV
1815 /**
1816 * @allow_fb_modifiers:
1817 *
1818 * Whether the driver supports fb modifiers in the ADDFB2.1 ioctl call.
1819 */
e3eb3250
RC
1820 bool allow_fb_modifiers;
1821
8716ed4e
AD
1822 /* cursor size */
1823 uint32_t cursor_width, cursor_height;
9f2a7950
DV
1824
1825 struct drm_mode_config_helper_funcs *helper_private;
f453ba04
DA
1826};
1827
dd275956
RC
1828/**
1829 * drm_for_each_plane_mask - iterate over planes specified by bitmask
1830 * @plane: the loop cursor
1831 * @dev: the DRM device
1832 * @plane_mask: bitmask of plane indices
1833 *
1834 * Iterate over all planes specified by bitmask.
1835 */
1836#define drm_for_each_plane_mask(plane, dev, plane_mask) \
1837 list_for_each_entry((plane), &(dev)->mode_config.plane_list, head) \
373701b1 1838 for_each_if ((plane_mask) & (1 << drm_plane_index(plane)))
dd275956 1839
f453ba04 1840#define obj_to_crtc(x) container_of(x, struct drm_crtc, base)
8cf5c917 1841#define obj_to_plane(x) container_of(x, struct drm_plane, base)
f453ba04 1842
f9882876
VS
1843extern __printf(6, 7)
1844int drm_crtc_init_with_planes(struct drm_device *dev,
1845 struct drm_crtc *crtc,
1846 struct drm_plane *primary,
1847 struct drm_plane *cursor,
1848 const struct drm_crtc_funcs *funcs,
1849 const char *name, ...);
f453ba04 1850extern void drm_crtc_cleanup(struct drm_crtc *crtc);
490d3d1b
CW
1851
1852/**
1853 * drm_crtc_index - find the index of a registered CRTC
1854 * @crtc: CRTC to find index for
1855 *
1856 * Given a registered CRTC, return the index of that CRTC within a DRM
1857 * device's list of CRTCs.
1858 */
1859static inline unsigned int drm_crtc_index(struct drm_crtc *crtc)
1860{
1861 return crtc->index;
1862}
db5f7a6e
RK
1863
1864/**
1865 * drm_crtc_mask - find the mask of a registered CRTC
1866 * @crtc: CRTC to find mask for
1867 *
1868 * Given a registered CRTC, return the mask bit of that CRTC for an
1869 * encoder's possible_crtcs field.
1870 */
1871static inline uint32_t drm_crtc_mask(struct drm_crtc *crtc)
1872{
1873 return 1 << drm_crtc_index(crtc);
1874}
f453ba04 1875
b0b3b795
VS
1876extern __printf(8, 9)
1877int drm_universal_plane_init(struct drm_device *dev,
1878 struct drm_plane *plane,
1879 unsigned long possible_crtcs,
1880 const struct drm_plane_funcs *funcs,
1881 const uint32_t *formats,
1882 unsigned int format_count,
1883 enum drm_plane_type type,
1884 const char *name, ...);
8cf5c917
JB
1885extern int drm_plane_init(struct drm_device *dev,
1886 struct drm_plane *plane,
1887 unsigned long possible_crtcs,
1888 const struct drm_plane_funcs *funcs,
45e3743a 1889 const uint32_t *formats, unsigned int format_count,
dc415ff9 1890 bool is_primary);
8cf5c917 1891extern void drm_plane_cleanup(struct drm_plane *plane);
490d3d1b
CW
1892
1893/**
1894 * drm_plane_index - find the index of a registered plane
1895 * @plane: plane to find index for
1896 *
1897 * Given a registered plane, return the index of that plane within a DRM
1898 * device's list of planes.
1899 */
1900static inline unsigned int drm_plane_index(struct drm_plane *plane)
1901{
1902 return plane->index;
1903}
f81338a5 1904extern struct drm_plane * drm_plane_from_index(struct drm_device *dev, int idx);
9125e618 1905extern void drm_plane_force_disable(struct drm_plane *plane);
ecb7e16b
GP
1906extern void drm_crtc_get_hv_timing(const struct drm_display_mode *mode,
1907 int *hdisplay, int *vdisplay);
6a0d9528
LW
1908extern int drm_crtc_force_disable(struct drm_crtc *crtc);
1909extern int drm_crtc_force_disable_all(struct drm_device *dev);
8cf5c917 1910
f453ba04 1911extern void drm_mode_config_init(struct drm_device *dev);
eb033556 1912extern void drm_mode_config_reset(struct drm_device *dev);
f453ba04 1913extern void drm_mode_config_cleanup(struct drm_device *dev);
55310008 1914
4cae5b84 1915extern int drm_mode_crtc_set_gamma_size(struct drm_crtc *crtc,
f453ba04 1916 int gamma_size);
98f75de4 1917
2d13b679 1918extern int drm_mode_set_config_internal(struct drm_mode_set *set);
81065548 1919
138f9ebb
DA
1920extern struct drm_tile_group *drm_mode_create_tile_group(struct drm_device *dev,
1921 char topology[8]);
1922extern struct drm_tile_group *drm_mode_get_tile_group(struct drm_device *dev,
1923 char topology[8]);
1924extern void drm_mode_put_tile_group(struct drm_device *dev,
1925 struct drm_tile_group *tg);
ff72145b 1926
3a5f87c2
TW
1927extern int drm_mode_plane_set_obj_prop(struct drm_plane *plane,
1928 struct drm_property *property,
1929 uint64_t value);
248dbc23 1930
c1df5f3c
VS
1931extern struct drm_property *drm_mode_create_rotation_property(struct drm_device *dev,
1932 unsigned int supported_rotations);
3c9855f6
VS
1933extern unsigned int drm_rotation_simplify(unsigned int rotation,
1934 unsigned int supported_rotations);
f8ed34ac
JS
1935extern void drm_crtc_enable_color_mgmt(struct drm_crtc *crtc,
1936 uint degamma_lut_size,
1937 bool has_ctm,
1938 uint gamma_lut_size);
44d1240d
MS
1939
1940int drm_plane_create_zpos_property(struct drm_plane *plane,
1941 unsigned int zpos,
1942 unsigned int min, unsigned int max);
1943
1944int drm_plane_create_zpos_immutable_property(struct drm_plane *plane,
1945 unsigned int zpos);
1946
96f60e37 1947/* Helpers */
a2b34e22
RC
1948static inline struct drm_plane *drm_plane_find(struct drm_device *dev,
1949 uint32_t id)
1950{
1951 struct drm_mode_object *mo;
1952 mo = drm_mode_object_find(dev, id, DRM_MODE_OBJECT_PLANE);
1953 return mo ? obj_to_plane(mo) : NULL;
1954}
1955
96f60e37
RK
1956static inline struct drm_crtc *drm_crtc_find(struct drm_device *dev,
1957 uint32_t id)
1958{
1959 struct drm_mode_object *mo;
1960 mo = drm_mode_object_find(dev, id, DRM_MODE_OBJECT_CRTC);
1961 return mo ? obj_to_crtc(mo) : NULL;
1962}
1963
5488dc16
LL
1964/*
1965 * Extract a degamma/gamma LUT value provided by user and round it to the
1966 * precision supported by the hardware.
1967 */
1968static inline uint32_t drm_color_lut_extract(uint32_t user_input,
1969 uint32_t bit_precision)
1970{
644a8050 1971 uint32_t val = user_input;
5488dc16
LL
1972 uint32_t max = 0xffff >> (16 - bit_precision);
1973
644a8050
LL
1974 /* Round only if we're not using full precision. */
1975 if (bit_precision < 16) {
1976 val += 1UL << (16 - bit_precision - 1);
1977 val >>= 16 - bit_precision;
1978 }
5488dc16
LL
1979
1980 return clamp_val(val, 0, max);
1981}
1982
e27dde3e 1983/* Plane list iterator for legacy (overlay only) planes. */
4ea50e99
DV
1984#define drm_for_each_legacy_plane(plane, dev) \
1985 list_for_each_entry(plane, &(dev)->mode_config.plane_list, head) \
373701b1 1986 for_each_if (plane->type == DRM_PLANE_TYPE_OVERLAY)
e27dde3e 1987
6295d607
DV
1988#define drm_for_each_plane(plane, dev) \
1989 list_for_each_entry(plane, &(dev)->mode_config.plane_list, head)
1990
1991#define drm_for_each_crtc(crtc, dev) \
1992 list_for_each_entry(crtc, &(dev)->mode_config.crtc_list, head)
1993
7a3f3d66
DV
1994static inline void
1995assert_drm_connector_list_read_locked(struct drm_mode_config *mode_config)
1996{
cff20ba2
DV
1997 /*
1998 * The connector hotadd/remove code currently grabs both locks when
1999 * updating lists. Hence readers need only hold either of them to be
2000 * safe and the check amounts to
2001 *
2002 * WARN_ON(not_holding(A) && not_holding(B)).
2003 */
2004 WARN_ON(!mutex_is_locked(&mode_config->mutex) &&
2005 !drm_modeset_is_locked(&mode_config->connection_mutex));
7a3f3d66
DV
2006}
2007
f453ba04 2008#endif /* __DRM_CRTC_H__ */