]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blame - include/drm/drm_crtc.h
drm: Export drm_property_replace_global_blob
[mirror_ubuntu-bionic-kernel.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>
7520a277
DV
39#include <drm/drm_modeset.h>
40#include <drm/drm_framebuffer.h>
41#include <drm/drm_modes.h>
308e5bcb 42
f453ba04
DA
43struct drm_device;
44struct drm_mode_set;
7e3bdf4a 45struct drm_object_properties;
595887eb
TR
46struct drm_file;
47struct drm_clip_rect;
7e435aad 48struct device_node;
e2330f07 49struct fence;
81065548 50struct edid;
f453ba04 51
fe456168 52#define DRM_OBJECT_MAX_PROPERTY 24
7e3bdf4a 53struct drm_object_properties {
88a48e29 54 int count, atomic_count;
b17cd757
RC
55 /* NOTE: if we ever start dynamically destroying properties (ie.
56 * not at drm_mode_config_cleanup() time), then we'd have to do
57 * a better job of detaching property from mode objects to avoid
58 * dangling property pointers:
59 */
60 struct drm_property *properties[DRM_OBJECT_MAX_PROPERTY];
22b8b13b
RC
61 /* do not read/write values directly, but use drm_object_property_get_value()
62 * and drm_object_property_set_value():
63 */
7e3bdf4a 64 uint64_t values[DRM_OBJECT_MAX_PROPERTY];
f453ba04
DA
65};
66
ebc44cf3
RC
67static inline int64_t U642I64(uint64_t val)
68{
69 return (int64_t)*((int64_t *)&val);
70}
71static inline uint64_t I642U64(int64_t val)
72{
73 return (uint64_t)*((uint64_t *)&val);
74}
75
d9c38242
RF
76/*
77 * Rotation property bits. DRM_ROTATE_<degrees> rotates the image by the
78 * specified amount in degrees in counter clockwise direction. DRM_REFLECT_X and
79 * DRM_REFLECT_Y reflects the image along the specified axis prior to rotation
80 */
31ad61e4
JL
81#define DRM_ROTATE_0 BIT(0)
82#define DRM_ROTATE_90 BIT(1)
83#define DRM_ROTATE_180 BIT(2)
84#define DRM_ROTATE_270 BIT(3)
85#define DRM_ROTATE_MASK (DRM_ROTATE_0 | DRM_ROTATE_90 | \
86 DRM_ROTATE_180 | DRM_ROTATE_270)
87#define DRM_REFLECT_X BIT(4)
88#define DRM_REFLECT_Y BIT(5)
89#define DRM_REFLECT_MASK (DRM_REFLECT_X | DRM_REFLECT_Y)
06596961 90
f453ba04
DA
91enum drm_connector_status {
92 connector_status_connected = 1,
93 connector_status_disconnected = 2,
94 connector_status_unknown = 3,
95};
96
97enum subpixel_order {
98 SubPixelUnknown = 0,
99 SubPixelHorizontalRGB,
100 SubPixelHorizontalBGR,
101 SubPixelVerticalRGB,
102 SubPixelVerticalBGR,
103 SubPixelNone,
104};
105
da05a5a7
JB
106#define DRM_COLOR_FORMAT_RGB444 (1<<0)
107#define DRM_COLOR_FORMAT_YCRCB444 (1<<1)
108#define DRM_COLOR_FORMAT_YCRCB422 (1<<2)
f0aa0838
SA
109
110#define DRM_BUS_FLAG_DE_LOW (1<<0)
111#define DRM_BUS_FLAG_DE_HIGH (1<<1)
112/* drive data on pos. edge */
113#define DRM_BUS_FLAG_PIXDATA_POSEDGE (1<<2)
114/* drive data on neg. edge */
115#define DRM_BUS_FLAG_PIXDATA_NEGEDGE (1<<3)
116
f453ba04
DA
117/*
118 * Describes a given display (e.g. CRT or flat panel) and its limitations.
119 */
120struct drm_display_info {
121 char name[DRM_DISPLAY_INFO_LEN];
fb439640 122
f453ba04
DA
123 /* Physical size */
124 unsigned int width_mm;
125 unsigned int height_mm;
126
f453ba04
DA
127 /* Clock limits FIXME: storage format */
128 unsigned int min_vfreq, max_vfreq;
129 unsigned int min_hfreq, max_hfreq;
130 unsigned int pixel_clock;
3b11228b 131 unsigned int bpc;
f453ba04 132
f453ba04 133 enum subpixel_order subpixel_order;
da05a5a7 134 u32 color_formats;
f453ba04 135
b5571e9d
BB
136 const u32 *bus_formats;
137 unsigned int num_bus_formats;
f0aa0838 138 u32 bus_flags;
b5571e9d 139
5d02626d
MK
140 /* Mask of supported hdmi deep color modes */
141 u8 edid_hdmi_dc_modes;
142
ebec9a7b 143 u8 cea_rev;
f453ba04
DA
144};
145
138f9ebb
DA
146/* data corresponds to displayid vend/prod/serial */
147struct drm_tile_group {
148 struct kref refcount;
149 struct drm_device *dev;
150 int id;
151 u8 group_data[8];
152};
153
f453ba04
DA
154struct drm_property_blob {
155 struct drm_mode_object base;
6bcacf51 156 struct drm_device *dev;
e2f5d2ea
DS
157 struct list_head head_global;
158 struct list_head head_file;
ecbbe59b 159 size_t length;
d63f5e6b 160 unsigned char data[];
f453ba04
DA
161};
162
163struct drm_property_enum {
164 uint64_t value;
165 struct list_head head;
166 char name[DRM_PROP_NAME_LEN];
167};
168
169struct drm_property {
170 struct list_head head;
171 struct drm_mode_object base;
172 uint32_t flags;
173 char name[DRM_PROP_NAME_LEN];
174 uint32_t num_values;
175 uint64_t *values;
98f75de4 176 struct drm_device *dev;
f453ba04 177
3758b341 178 struct list_head enum_list;
f453ba04
DA
179};
180
181struct drm_crtc;
182struct drm_connector;
183struct drm_encoder;
d91d8a3f 184struct drm_pending_vblank_event;
8cf5c917 185struct drm_plane;
3b336ec4 186struct drm_bridge;
144ecb97
DV
187struct drm_atomic_state;
188
4490d4c7
DV
189struct drm_crtc_helper_funcs;
190struct drm_encoder_helper_funcs;
191struct drm_connector_helper_funcs;
192struct drm_plane_helper_funcs;
193
144ecb97 194/**
cc4ceb48 195 * struct drm_crtc_state - mutable CRTC state
07cc0ef6 196 * @crtc: backpointer to the CRTC
144ecb97 197 * @enable: whether the CRTC should be enabled, gates all other state
d9b13620 198 * @active: whether the CRTC is actively displaying (used for DPMS)
fc596660
ML
199 * @planes_changed: planes on this crtc are updated
200 * @mode_changed: crtc_state->mode or crtc_state->enable has been changed
201 * @active_changed: crtc_state->active has been toggled.
202 * @connectors_changed: connectors to this crtc have been updated
44d1240d 203 * @zpos_changed: zpos values of planes on this crtc have been updated
5488dc16
LL
204 * @color_mgmt_changed: color management properties have changed (degamma or
205 * gamma LUT or CSC matrix)
6ddd388a 206 * @plane_mask: bitmask of (1 << drm_plane_index(plane)) of attached planes
4cd9fa52 207 * @connector_mask: bitmask of (1 << drm_connector_index(connector)) of attached connectors
e87a52b3 208 * @encoder_mask: bitmask of (1 << drm_encoder_index(encoder)) of attached encoders
623369e5
DV
209 * @last_vblank_count: for helpers and drivers to capture the vblank of the
210 * update to ensure framebuffer cleanup isn't done too early
2f324b42 211 * @adjusted_mode: for use by helpers and drivers to compute adjusted mode timings
144ecb97 212 * @mode: current mode timings
ac3ba4a5 213 * @mode_blob: &drm_property_blob for @mode
5488dc16
LL
214 * @degamma_lut: Lookup table for converting framebuffer pixel data
215 * before apply the conversion matrix
216 * @ctm: Transformation matrix
217 * @gamma_lut: Lookup table for converting pixel data after the
218 * conversion matrix
144ecb97
DV
219 * @event: optional pointer to a DRM event to signal upon completion of the
220 * state update
221 * @state: backpointer to global drm_atomic_state
d9b13620
DV
222 *
223 * Note that the distinction between @enable and @active is rather subtile:
224 * Flipping @active while @enable is set without changing anything else may
225 * never return in a failure from the ->atomic_check callback. Userspace assumes
226 * that a DPMS On will always succeed. In other words: @enable controls resource
227 * assignment, @active controls the actual hardware state.
144ecb97
DV
228 */
229struct drm_crtc_state {
07cc0ef6
DV
230 struct drm_crtc *crtc;
231
cc4ceb48 232 bool enable;
d9b13620 233 bool active;
144ecb97 234
c2fcd274
DV
235 /* computed state bits used by helpers and drivers */
236 bool planes_changed : 1;
623369e5 237 bool mode_changed : 1;
eab3bbef 238 bool active_changed : 1;
fc596660 239 bool connectors_changed : 1;
44d1240d 240 bool zpos_changed : 1;
5488dc16 241 bool color_mgmt_changed : 1;
623369e5 242
6ddd388a
RC
243 /* attached planes bitmask:
244 * WARNING: transitional helpers do not maintain plane_mask so
245 * drivers not converted over to atomic helpers should not rely
246 * on plane_mask being accurate!
247 */
248 u32 plane_mask;
249
4cd9fa52 250 u32 connector_mask;
e87a52b3 251 u32 encoder_mask;
4cd9fa52 252
623369e5
DV
253 /* last_vblank_count: for vblank waits before cleanup */
254 u32 last_vblank_count;
c2fcd274 255
2f324b42
DV
256 /* adjusted_mode: for use by helpers and drivers */
257 struct drm_display_mode adjusted_mode;
258
144ecb97
DV
259 struct drm_display_mode mode;
260
99cf4a29
DS
261 /* blob property to expose current mode to atomic userspace */
262 struct drm_property_blob *mode_blob;
263
5488dc16
LL
264 /* blob property to expose color management to userspace */
265 struct drm_property_blob *degamma_lut;
266 struct drm_property_blob *ctm;
267 struct drm_property_blob *gamma_lut;
268
144ecb97
DV
269 struct drm_pending_vblank_event *event;
270
271 struct drm_atomic_state *state;
272};
f453ba04
DA
273
274/**
3bf0401c 275 * struct drm_crtc_funcs - control CRTCs for a given device
f453ba04
DA
276 *
277 * The drm_crtc_funcs structure is the central CRTC management structure
278 * in the DRM. Each CRTC controls one or more connectors (note that the name
279 * CRTC is simply historical, a CRTC may control LVDS, VGA, DVI, TV out, etc.
280 * connectors, not just CRTs).
281 *
282 * Each driver is responsible for filling out this structure at startup time,
283 * in addition to providing other modesetting features, like i2c and DDC
284 * bus accessors.
285 */
286struct drm_crtc_funcs {
88548636
DV
287 /**
288 * @reset:
289 *
290 * Reset CRTC hardware and software state to off. This function isn't
291 * called by the core directly, only through drm_mode_config_reset().
292 * It's not a helper hook only for historical reasons.
293 *
294 * Atomic drivers can use drm_atomic_helper_crtc_reset() to reset
295 * atomic state using this hook.
296 */
eb033556 297 void (*reset)(struct drm_crtc *crtc);
f453ba04 298
f6da8c6e
DV
299 /**
300 * @cursor_set:
301 *
302 * Update the cursor image. The cursor position is relative to the CRTC
303 * and can be partially or fully outside of the visible area.
304 *
305 * Note that contrary to all other KMS functions the legacy cursor entry
306 * points don't take a framebuffer object, but instead take directly a
307 * raw buffer object id from the driver's buffer manager (which is
308 * either GEM or TTM for current drivers).
309 *
310 * This entry point is deprecated, drivers should instead implement
311 * universal plane support and register a proper cursor plane using
312 * drm_crtc_init_with_planes().
313 *
314 * This callback is optional
315 *
316 * RETURNS:
317 *
318 * 0 on success or a negative error code on failure.
319 */
f453ba04
DA
320 int (*cursor_set)(struct drm_crtc *crtc, struct drm_file *file_priv,
321 uint32_t handle, uint32_t width, uint32_t height);
f6da8c6e
DV
322
323 /**
324 * @cursor_set2:
325 *
326 * Update the cursor image, including hotspot information. The hotspot
327 * must not affect the cursor position in CRTC coordinates, but is only
328 * meant as a hint for virtualized display hardware to coordinate the
329 * guests and hosts cursor position. The cursor hotspot is relative to
330 * the cursor image. Otherwise this works exactly like @cursor_set.
331 *
332 * This entry point is deprecated, drivers should instead implement
333 * universal plane support and register a proper cursor plane using
334 * drm_crtc_init_with_planes().
335 *
336 * This callback is optional.
337 *
338 * RETURNS:
339 *
340 * 0 on success or a negative error code on failure.
341 */
4c813d4d
DA
342 int (*cursor_set2)(struct drm_crtc *crtc, struct drm_file *file_priv,
343 uint32_t handle, uint32_t width, uint32_t height,
344 int32_t hot_x, int32_t hot_y);
f6da8c6e
DV
345
346 /**
347 * @cursor_move:
348 *
349 * Update the cursor position. The cursor does not need to be visible
350 * when this hook is called.
351 *
352 * This entry point is deprecated, drivers should instead implement
353 * universal plane support and register a proper cursor plane using
354 * drm_crtc_init_with_planes().
355 *
356 * This callback is optional.
357 *
358 * RETURNS:
359 *
360 * 0 on success or a negative error code on failure.
361 */
f453ba04
DA
362 int (*cursor_move)(struct drm_crtc *crtc, int x, int y);
363
f6da8c6e
DV
364 /**
365 * @gamma_set:
366 *
367 * Set gamma on the CRTC.
368 *
369 * This callback is optional.
370 *
371 * NOTE:
372 *
373 * Drivers that support gamma tables and also fbdev emulation through
374 * the provided helper library need to take care to fill out the gamma
375 * hooks for both. Currently there's a bit an unfortunate duplication
376 * going on, which should eventually be unified to just one set of
377 * hooks.
378 */
7ea77283
ML
379 int (*gamma_set)(struct drm_crtc *crtc, u16 *r, u16 *g, u16 *b,
380 uint32_t size);
88548636
DV
381
382 /**
383 * @destroy:
384 *
385 * Clean up plane resources. This is only called at driver unload time
386 * through drm_mode_config_cleanup() since a CRTC cannot be hotplugged
387 * in DRM.
388 */
f453ba04
DA
389 void (*destroy)(struct drm_crtc *crtc);
390
f6da8c6e
DV
391 /**
392 * @set_config:
393 *
394 * This is the main legacy entry point to change the modeset state on a
395 * CRTC. All the details of the desired configuration are passed in a
396 * struct &drm_mode_set - see there for details.
397 *
398 * Drivers implementing atomic modeset should use
399 * drm_atomic_helper_set_config() to implement this hook.
400 *
401 * RETURNS:
402 *
403 * 0 on success or a negative error code on failure.
404 */
f453ba04 405 int (*set_config)(struct drm_mode_set *set);
d91d8a3f 406
f6da8c6e
DV
407 /**
408 * @page_flip:
409 *
410 * Legacy entry point to schedule a flip to the given framebuffer.
411 *
412 * Page flipping is a synchronization mechanism that replaces the frame
413 * buffer being scanned out by the CRTC with a new frame buffer during
414 * vertical blanking, avoiding tearing (except when requested otherwise
415 * through the DRM_MODE_PAGE_FLIP_ASYNC flag). When an application
416 * requests a page flip the DRM core verifies that the new frame buffer
417 * is large enough to be scanned out by the CRTC in the currently
418 * configured mode and then calls the CRTC ->page_flip() operation with a
419 * pointer to the new frame buffer.
420 *
421 * The driver must wait for any pending rendering to the new framebuffer
422 * to complete before executing the flip. It should also wait for any
423 * pending rendering from other drivers if the underlying buffer is a
424 * shared dma-buf.
425 *
426 * An application can request to be notified when the page flip has
427 * completed. The drm core will supply a struct &drm_event in the event
428 * parameter in this case. This can be handled by the
429 * drm_crtc_send_vblank_event() function, which the driver should call on
430 * the provided event upon completion of the flip. Note that if
431 * the driver supports vblank signalling and timestamping the vblank
432 * counters and timestamps must agree with the ones returned from page
433 * flip events. With the current vblank helper infrastructure this can
434 * be achieved by holding a vblank reference while the page flip is
435 * pending, acquired through drm_crtc_vblank_get() and released with
436 * drm_crtc_vblank_put(). Drivers are free to implement their own vblank
437 * counter and timestamp tracking though, e.g. if they have accurate
438 * timestamp registers in hardware.
439 *
f6da8c6e
DV
440 * This callback is optional.
441 *
442 * NOTE:
443 *
444 * Very early versions of the KMS ABI mandated that the driver must
445 * block (but not reject) any rendering to the old framebuffer until the
446 * flip operation has completed and the old framebuffer is no longer
447 * visible. This requirement has been lifted, and userspace is instead
448 * expected to request delivery of an event and wait with recycling old
449 * buffers until such has been received.
450 *
451 * RETURNS:
452 *
453 * 0 on success or a negative error code on failure. Note that if a
454 * ->page_flip() operation is already pending the callback should return
455 * -EBUSY. Pageflips on a disabled CRTC (either by setting a NULL mode
456 * or just runtime disabled through DPMS respectively the new atomic
4cba6850
DV
457 * "ACTIVE" state) should result in an -EINVAL error code. Note that
458 * drm_atomic_helper_page_flip() checks this already for atomic drivers.
d91d8a3f
KH
459 */
460 int (*page_flip)(struct drm_crtc *crtc,
461 struct drm_framebuffer *fb,
ed8d1975
KP
462 struct drm_pending_vblank_event *event,
463 uint32_t flags);
bffd9de0 464
88548636
DV
465 /**
466 * @set_property:
467 *
468 * This is the legacy entry point to update a property attached to the
469 * CRTC.
470 *
471 * Drivers implementing atomic modeset should use
472 * drm_atomic_helper_crtc_set_property() to implement this hook.
473 *
474 * This callback is optional if the driver does not support any legacy
475 * driver-private properties.
476 *
477 * RETURNS:
478 *
479 * 0 on success or a negative error code on failure.
480 */
bffd9de0
PZ
481 int (*set_property)(struct drm_crtc *crtc,
482 struct drm_property *property, uint64_t val);
144ecb97 483
88548636
DV
484 /**
485 * @atomic_duplicate_state:
486 *
487 * Duplicate the current atomic state for this CRTC and return it.
488 * The core and helpers gurantee that any atomic state duplicated with
489 * this hook and still owned by the caller (i.e. not transferred to the
490 * driver by calling ->atomic_commit() from struct
491 * &drm_mode_config_funcs) will be cleaned up by calling the
492 * @atomic_destroy_state hook in this structure.
493 *
494 * Atomic drivers which don't subclass struct &drm_crtc should use
495 * drm_atomic_helper_crtc_duplicate_state(). Drivers that subclass the
496 * state structure to extend it with driver-private state should use
497 * __drm_atomic_helper_crtc_duplicate_state() to make sure shared state is
498 * duplicated in a consistent fashion across drivers.
499 *
500 * It is an error to call this hook before crtc->state has been
501 * initialized correctly.
502 *
503 * NOTE:
504 *
505 * If the duplicate state references refcounted resources this hook must
506 * acquire a reference for each of them. The driver must release these
507 * references again in @atomic_destroy_state.
508 *
509 * RETURNS:
510 *
511 * Duplicated atomic state or NULL when the allocation failed.
512 */
144ecb97 513 struct drm_crtc_state *(*atomic_duplicate_state)(struct drm_crtc *crtc);
88548636
DV
514
515 /**
516 * @atomic_destroy_state:
517 *
518 * Destroy a state duplicated with @atomic_duplicate_state and release
519 * or unreference all resources it references
520 */
144ecb97 521 void (*atomic_destroy_state)(struct drm_crtc *crtc,
cc4ceb48 522 struct drm_crtc_state *state);
88548636
DV
523
524 /**
525 * @atomic_set_property:
526 *
527 * Decode a driver-private property value and store the decoded value
528 * into the passed-in state structure. Since the atomic core decodes all
529 * standardized properties (even for extensions beyond the core set of
530 * properties which might not be implemented by all drivers) this
531 * requires drivers to subclass the state structure.
532 *
533 * Such driver-private properties should really only be implemented for
534 * truly hardware/vendor specific state. Instead it is preferred to
535 * standardize atomic extension and decode the properties used to expose
536 * such an extension in the core.
537 *
538 * Do not call this function directly, use
539 * drm_atomic_crtc_set_property() instead.
540 *
541 * This callback is optional if the driver does not support any
542 * driver-private atomic properties.
543 *
544 * NOTE:
545 *
546 * This function is called in the state assembly phase of atomic
547 * modesets, which can be aborted for any reason (including on
548 * userspace's request to just check whether a configuration would be
549 * possible). Drivers MUST NOT touch any persistent state (hardware or
550 * software) or data structures except the passed in @state parameter.
551 *
552 * Also since userspace controls in which order properties are set this
553 * function must not do any input validation (since the state update is
554 * incomplete and hence likely inconsistent). Instead any such input
555 * validation must be done in the various atomic_check callbacks.
556 *
557 * RETURNS:
558 *
559 * 0 if the property has been found, -EINVAL if the property isn't
560 * implemented by the driver (which should never happen, the core only
561 * asks for properties attached to this CRTC). No other validation is
562 * allowed by the driver. The core already checks that the property
563 * value is within the range (integer, valid enum value, ...) the driver
564 * set when registering the property.
565 */
144ecb97
DV
566 int (*atomic_set_property)(struct drm_crtc *crtc,
567 struct drm_crtc_state *state,
568 struct drm_property *property,
569 uint64_t val);
88548636
DV
570 /**
571 * @atomic_get_property:
572 *
573 * Reads out the decoded driver-private property. This is used to
c6b0ca3e 574 * implement the GETCRTC IOCTL.
88548636
DV
575 *
576 * Do not call this function directly, use
577 * drm_atomic_crtc_get_property() instead.
578 *
579 * This callback is optional if the driver does not support any
580 * driver-private atomic properties.
581 *
582 * RETURNS:
583 *
584 * 0 on success, -EINVAL if the property isn't implemented by the
585 * driver (which should never happen, the core only asks for
586 * properties attached to this CRTC).
587 */
ac9c9256
RC
588 int (*atomic_get_property)(struct drm_crtc *crtc,
589 const struct drm_crtc_state *state,
590 struct drm_property *property,
591 uint64_t *val);
79190ea2
BG
592
593 /**
594 * @late_register:
595 *
596 * This optional hook can be used to register additional userspace
597 * interfaces attached to the crtc like debugfs interfaces.
598 * It is called late in the driver load sequence from drm_dev_register().
599 * Everything added from this callback should be unregistered in
600 * the early_unregister callback.
601 *
602 * Returns:
603 *
604 * 0 on success, or a negative error code on failure.
605 */
606 int (*late_register)(struct drm_crtc *crtc);
607
608 /**
609 * @early_unregister:
610 *
611 * This optional hook should be used to unregister the additional
612 * userspace interfaces attached to the crtc from
613 * late_unregister(). It is called from drm_dev_unregister(),
614 * early in the driver unload sequence to disable userspace access
615 * before data structures are torndown.
616 */
617 void (*early_unregister)(struct drm_crtc *crtc);
f453ba04
DA
618};
619
620/**
3bf0401c 621 * struct drm_crtc - central CRTC control structure
7749163e 622 * @dev: parent DRM device
2c0c33d4 623 * @port: OF node used by drm_of_find_possible_crtcs()
7749163e 624 * @head: list management
ac3ba4a5 625 * @name: human readable name, can be overwritten by the driver
51fd371b 626 * @mutex: per-CRTC locking
7749163e 627 * @base: base KMS object for ID tracking etc.
e13161af
MR
628 * @primary: primary plane for this CRTC
629 * @cursor: cursor plane for this CRTC
2c0c33d4
DV
630 * @cursor_x: current x position of the cursor, used for universal cursor planes
631 * @cursor_y: current y position of the cursor, used for universal cursor planes
f453ba04 632 * @enabled: is this CRTC enabled?
7749163e
JB
633 * @mode: current mode timings
634 * @hwmode: mode timings as programmed to hw regs
f453ba04
DA
635 * @x: x position on screen
636 * @y: y position on screen
f453ba04 637 * @funcs: CRTC control functions
7749163e
JB
638 * @gamma_size: size of gamma ramp
639 * @gamma_store: gamma ramp values
7749163e 640 * @helper_private: mid-layer private data
bffd9de0 641 * @properties: property tracking for this CRTC
f453ba04
DA
642 *
643 * Each CRTC may have one or more connectors associated with it. This structure
644 * allows the CRTC to be controlled.
645 */
646struct drm_crtc {
647 struct drm_device *dev;
7e435aad 648 struct device_node *port;
f453ba04
DA
649 struct list_head head;
650
fa3ab4c2
VS
651 char *name;
652
ac3ba4a5
DV
653 /**
654 * @mutex:
29494c17
DV
655 *
656 * This provides a read lock for the overall crtc state (mode, dpms
657 * state, ...) and a write lock for everything which can be update
ac3ba4a5
DV
658 * without a full modeset (fb, cursor data, crtc properties ...). Full
659 * modeset also need to grab dev->mode_config.connection_mutex.
29494c17 660 */
51fd371b 661 struct drm_modeset_lock mutex;
29494c17 662
f453ba04
DA
663 struct drm_mode_object base;
664
e13161af
MR
665 /* primary and cursor planes for CRTC */
666 struct drm_plane *primary;
667 struct drm_plane *cursor;
668
96094081
DV
669 /**
670 * @index: Position inside the mode_config.list, can be used as an array
671 * index. It is invariant over the lifetime of the CRTC.
672 */
490d3d1b
CW
673 unsigned index;
674
161d0dc1
MR
675 /* position of cursor plane on crtc */
676 int cursor_x;
677 int cursor_y;
678
f453ba04
DA
679 bool enabled;
680
27641c3f 681 /* Requested mode from modesetting. */
f453ba04
DA
682 struct drm_display_mode mode;
683
27641c3f
MK
684 /* Programmed mode in hw, after adjustments for encoders,
685 * crtc, panel scaling etc. Needed for timestamping etc.
686 */
687 struct drm_display_mode hwmode;
688
f453ba04 689 int x, y;
f453ba04
DA
690 const struct drm_crtc_funcs *funcs;
691
5488dc16 692 /* Legacy FB CRTC gamma size for reporting to userspace */
f453ba04
DA
693 uint32_t gamma_size;
694 uint16_t *gamma_store;
695
696 /* if you are using the helper */
4490d4c7 697 const struct drm_crtc_helper_funcs *helper_private;
bffd9de0
PZ
698
699 struct drm_object_properties properties;
d059f652 700
3b24f7d6
DV
701 /**
702 * @state:
703 *
704 * Current atomic state for this CRTC.
705 */
144ecb97
DV
706 struct drm_crtc_state *state;
707
3b24f7d6
DV
708 /**
709 * @commit_list:
710 *
711 * List of &drm_crtc_commit structures tracking pending commits.
712 * Protected by @commit_lock. This list doesn't hold its own full
713 * reference, but burrows it from the ongoing commit. Commit entries
714 * must be removed from this list once the commit is fully completed,
715 * but before it's correspoding &drm_atomic_state gets destroyed.
716 */
717 struct list_head commit_list;
718
719 /**
720 * @commit_lock:
721 *
722 * Spinlock to protect @commit_list.
723 */
724 spinlock_t commit_lock;
725
726 /**
727 * @acquire_ctx:
728 *
729 * Per-CRTC implicit acquire context used by atomic drivers for legacy
730 * IOCTLs, so that atomic drivers can get at the locking acquire
731 * context.
d059f652
DV
732 */
733 struct drm_modeset_acquire_ctx *acquire_ctx;
f453ba04
DA
734};
735
144ecb97
DV
736/**
737 * struct drm_connector_state - mutable connector state
07cc0ef6 738 * @connector: backpointer to the connector
cc4ceb48 739 * @crtc: CRTC to connect connector to, NULL if disabled
623369e5 740 * @best_encoder: can be used by helpers and drivers to select the encoder
144ecb97
DV
741 * @state: backpointer to global drm_atomic_state
742 */
743struct drm_connector_state {
07cc0ef6
DV
744 struct drm_connector *connector;
745
6ddd388a 746 struct drm_crtc *crtc; /* do not write directly, use drm_atomic_set_crtc_for_connector() */
144ecb97 747
623369e5
DV
748 struct drm_encoder *best_encoder;
749
144ecb97
DV
750 struct drm_atomic_state *state;
751};
f453ba04
DA
752
753/**
3bf0401c 754 * struct drm_connector_funcs - control connectors on a given device
144ecb97 755 *
f453ba04
DA
756 * Each CRTC may have one or more connectors attached to it. The functions
757 * below allow the core DRM code to control connectors, enumerate available modes,
758 * etc.
759 */
760struct drm_connector_funcs {
6fe14acd
DV
761 /**
762 * @dpms:
763 *
764 * Legacy entry point to set the per-connector DPMS state. Legacy DPMS
765 * is exposed as a standard property on the connector, but diverted to
766 * this callback in the drm core. Note that atomic drivers don't
767 * implement the 4 level DPMS support on the connector any more, but
768 * instead only have an on/off "ACTIVE" property on the CRTC object.
769 *
770 * Drivers implementing atomic modeset should use
771 * drm_atomic_helper_connector_dpms() to implement this hook.
772 *
773 * RETURNS:
774 *
775 * 0 on success or a negative error code on failure.
776 */
9a69a9ac 777 int (*dpms)(struct drm_connector *connector, int mode);
88548636
DV
778
779 /**
780 * @reset:
781 *
782 * Reset connector hardware and software state to off. This function isn't
783 * called by the core directly, only through drm_mode_config_reset().
784 * It's not a helper hook only for historical reasons.
785 *
786 * Atomic drivers can use drm_atomic_helper_connector_reset() to reset
787 * atomic state using this hook.
788 */
eb033556 789 void (*reset)(struct drm_connector *connector);
930a9e28 790
6fe14acd
DV
791 /**
792 * @detect:
793 *
794 * Check to see if anything is attached to the connector. The parameter
795 * force is set to false whilst polling, true when checking the
796 * connector due to a user request. force can be used by the driver to
797 * avoid expensive, destructive operations during automated probing.
798 *
799 * FIXME:
800 *
801 * Note that this hook is only called by the probe helper. It's not in
802 * the helper library vtable purely for historical reasons. The only DRM
803 * core entry point to probe connector state is @fill_modes.
804 *
805 * RETURNS:
806 *
807 * drm_connector_status indicating the connector's status.
930a9e28 808 */
7b334fcb 809 enum drm_connector_status (*detect)(struct drm_connector *connector,
930a9e28 810 bool force);
6fe14acd
DV
811
812 /**
813 * @force:
814 *
815 * This function is called to update internal encoder state when the
816 * connector is forced to a certain state by userspace, either through
817 * the sysfs interfaces or on the kernel cmdline. In that case the
818 * @detect callback isn't called.
819 *
820 * FIXME:
821 *
822 * Note that this hook is only called by the probe helper. It's not in
823 * the helper library vtable purely for historical reasons. The only DRM
824 * core entry point to probe connector state is @fill_modes.
825 */
826 void (*force)(struct drm_connector *connector);
827
828 /**
829 * @fill_modes:
830 *
831 * Entry point for output detection and basic mode validation. The
832 * driver should reprobe the output if needed (e.g. when hotplug
833 * handling is unreliable), add all detected modes to connector->modes
834 * and filter out any the device can't support in any configuration. It
835 * also needs to filter out any modes wider or higher than the
836 * parameters max_width and max_height indicate.
837 *
838 * The drivers must also prune any modes no longer valid from
839 * connector->modes. Furthermore it must update connector->status and
840 * connector->edid. If no EDID has been received for this output
841 * connector->edid must be NULL.
842 *
843 * Drivers using the probe helpers should use
844 * drm_helper_probe_single_connector_modes() or
845 * drm_helper_probe_single_connector_modes_nomerge() to implement this
846 * function.
847 *
848 * RETURNS:
849 *
850 * The number of modes detected and filled into connector->modes.
851 */
40a518d9 852 int (*fill_modes)(struct drm_connector *connector, uint32_t max_width, uint32_t max_height);
88548636
DV
853
854 /**
855 * @set_property:
856 *
857 * This is the legacy entry point to update a property attached to the
858 * connector.
859 *
860 * Drivers implementing atomic modeset should use
861 * drm_atomic_helper_connector_set_property() to implement this hook.
862 *
863 * This callback is optional if the driver does not support any legacy
864 * driver-private properties.
865 *
866 * RETURNS:
867 *
868 * 0 on success or a negative error code on failure.
869 */
f453ba04
DA
870 int (*set_property)(struct drm_connector *connector, struct drm_property *property,
871 uint64_t val);
88548636 872
aaf285e2
CW
873 /**
874 * @late_register:
875 *
876 * This optional hook can be used to register additional userspace
877 * interfaces attached to the connector, light backlight control, i2c,
878 * DP aux or similar interfaces. It is called late in the driver load
879 * sequence from drm_connector_register() when registering all the
880 * core drm connector interfaces. Everything added from this callback
881 * should be unregistered in the early_unregister callback.
882 *
883 * Returns:
884 *
885 * 0 on success, or a negative error code on failure.
886 */
887 int (*late_register)(struct drm_connector *connector);
888
889 /**
890 * @early_unregister:
891 *
892 * This optional hook should be used to unregister the additional
893 * userspace interfaces attached to the connector from
894 * late_unregister(). It is called from drm_connector_unregister(),
895 * early in the driver unload sequence to disable userspace access
896 * before data structures are torndown.
897 */
898 void (*early_unregister)(struct drm_connector *connector);
899
88548636
DV
900 /**
901 * @destroy:
902 *
903 * Clean up connector resources. This is called at driver unload time
904 * through drm_mode_config_cleanup(). It can also be called at runtime
905 * when a connector is being hot-unplugged for drivers that support
906 * connector hotplugging (e.g. DisplayPort MST).
907 */
f453ba04 908 void (*destroy)(struct drm_connector *connector);
144ecb97 909
88548636
DV
910 /**
911 * @atomic_duplicate_state:
912 *
913 * Duplicate the current atomic state for this connector and return it.
914 * The core and helpers gurantee that any atomic state duplicated with
915 * this hook and still owned by the caller (i.e. not transferred to the
916 * driver by calling ->atomic_commit() from struct
917 * &drm_mode_config_funcs) will be cleaned up by calling the
918 * @atomic_destroy_state hook in this structure.
919 *
920 * Atomic drivers which don't subclass struct &drm_connector_state should use
921 * drm_atomic_helper_connector_duplicate_state(). Drivers that subclass the
922 * state structure to extend it with driver-private state should use
923 * __drm_atomic_helper_connector_duplicate_state() to make sure shared state is
924 * duplicated in a consistent fashion across drivers.
925 *
926 * It is an error to call this hook before connector->state has been
927 * initialized correctly.
928 *
929 * NOTE:
930 *
931 * If the duplicate state references refcounted resources this hook must
932 * acquire a reference for each of them. The driver must release these
933 * references again in @atomic_destroy_state.
934 *
935 * RETURNS:
936 *
937 * Duplicated atomic state or NULL when the allocation failed.
938 */
144ecb97 939 struct drm_connector_state *(*atomic_duplicate_state)(struct drm_connector *connector);
88548636
DV
940
941 /**
942 * @atomic_destroy_state:
943 *
944 * Destroy a state duplicated with @atomic_duplicate_state and release
945 * or unreference all resources it references
946 */
144ecb97 947 void (*atomic_destroy_state)(struct drm_connector *connector,
cc4ceb48 948 struct drm_connector_state *state);
88548636
DV
949
950 /**
951 * @atomic_set_property:
952 *
953 * Decode a driver-private property value and store the decoded value
954 * into the passed-in state structure. Since the atomic core decodes all
955 * standardized properties (even for extensions beyond the core set of
956 * properties which might not be implemented by all drivers) this
957 * requires drivers to subclass the state structure.
958 *
959 * Such driver-private properties should really only be implemented for
960 * truly hardware/vendor specific state. Instead it is preferred to
961 * standardize atomic extension and decode the properties used to expose
962 * such an extension in the core.
963 *
964 * Do not call this function directly, use
965 * drm_atomic_connector_set_property() instead.
966 *
967 * This callback is optional if the driver does not support any
968 * driver-private atomic properties.
969 *
970 * NOTE:
971 *
972 * This function is called in the state assembly phase of atomic
973 * modesets, which can be aborted for any reason (including on
974 * userspace's request to just check whether a configuration would be
975 * possible). Drivers MUST NOT touch any persistent state (hardware or
976 * software) or data structures except the passed in @state parameter.
977 *
978 * Also since userspace controls in which order properties are set this
979 * function must not do any input validation (since the state update is
980 * incomplete and hence likely inconsistent). Instead any such input
981 * validation must be done in the various atomic_check callbacks.
982 *
983 * RETURNS:
984 *
985 * 0 if the property has been found, -EINVAL if the property isn't
986 * implemented by the driver (which shouldn't ever happen, the core only
987 * asks for properties attached to this connector). No other validation
988 * is allowed by the driver. The core already checks that the property
989 * value is within the range (integer, valid enum value, ...) the driver
990 * set when registering the property.
991 */
144ecb97
DV
992 int (*atomic_set_property)(struct drm_connector *connector,
993 struct drm_connector_state *state,
994 struct drm_property *property,
995 uint64_t val);
88548636
DV
996
997 /**
998 * @atomic_get_property:
999 *
1000 * Reads out the decoded driver-private property. This is used to
c6b0ca3e 1001 * implement the GETCONNECTOR IOCTL.
88548636
DV
1002 *
1003 * Do not call this function directly, use
1004 * drm_atomic_connector_get_property() instead.
1005 *
1006 * This callback is optional if the driver does not support any
1007 * driver-private atomic properties.
1008 *
1009 * RETURNS:
1010 *
1011 * 0 on success, -EINVAL if the property isn't implemented by the
1012 * driver (which shouldn't ever happen, the core only asks for
1013 * properties attached to this connector).
1014 */
ac9c9256
RC
1015 int (*atomic_get_property)(struct drm_connector *connector,
1016 const struct drm_connector_state *state,
1017 struct drm_property *property,
1018 uint64_t *val);
f453ba04
DA
1019};
1020
6c3db920 1021/**
3bf0401c 1022 * struct drm_encoder_funcs - encoder controls
6c3db920
JB
1023 *
1024 * Encoders sit between CRTCs and connectors.
1025 */
f453ba04 1026struct drm_encoder_funcs {
88548636
DV
1027 /**
1028 * @reset:
1029 *
1030 * Reset encoder hardware and software state to off. This function isn't
1031 * called by the core directly, only through drm_mode_config_reset().
1032 * It's not a helper hook only for historical reasons.
1033 */
eb033556 1034 void (*reset)(struct drm_encoder *encoder);
88548636
DV
1035
1036 /**
1037 * @destroy:
1038 *
1039 * Clean up encoder resources. This is only called at driver unload time
1040 * through drm_mode_config_cleanup() since an encoder cannot be
1041 * hotplugged in DRM.
1042 */
f453ba04 1043 void (*destroy)(struct drm_encoder *encoder);
79190ea2
BG
1044
1045 /**
1046 * @late_register:
1047 *
1048 * This optional hook can be used to register additional userspace
1049 * interfaces attached to the encoder like debugfs interfaces.
1050 * It is called late in the driver load sequence from drm_dev_register().
1051 * Everything added from this callback should be unregistered in
1052 * the early_unregister callback.
1053 *
1054 * Returns:
1055 *
1056 * 0 on success, or a negative error code on failure.
1057 */
1058 int (*late_register)(struct drm_encoder *encoder);
1059
1060 /**
1061 * @early_unregister:
1062 *
1063 * This optional hook should be used to unregister the additional
1064 * userspace interfaces attached to the encoder from
1065 * late_unregister(). It is called from drm_dev_unregister(),
1066 * early in the driver unload sequence to disable userspace access
1067 * before data structures are torndown.
1068 */
1069 void (*early_unregister)(struct drm_encoder *encoder);
f453ba04
DA
1070};
1071
afe887df 1072#define DRM_CONNECTOR_MAX_ENCODER 3
f453ba04
DA
1073
1074/**
3bf0401c 1075 * struct drm_encoder - central DRM encoder structure
db3e4499
JB
1076 * @dev: parent DRM device
1077 * @head: list management
1078 * @base: base KMS object
ac3ba4a5 1079 * @name: human readable name, can be overwritten by the driver
62cacc79 1080 * @encoder_type: one of the DRM_MODE_ENCODER_<foo> types in drm_mode.h
db3e4499
JB
1081 * @possible_crtcs: bitmask of potential CRTC bindings
1082 * @possible_clones: bitmask of potential sibling encoders for cloning
1083 * @crtc: currently bound CRTC
3b336ec4 1084 * @bridge: bridge associated to the encoder
db3e4499
JB
1085 * @funcs: control functions
1086 * @helper_private: mid-layer private data
1087 *
1088 * CRTCs drive pixels to encoders, which convert them into signals
1089 * appropriate for a given connector or set of connectors.
f453ba04
DA
1090 */
1091struct drm_encoder {
1092 struct drm_device *dev;
1093 struct list_head head;
1094
1095 struct drm_mode_object base;
e5748946 1096 char *name;
f453ba04 1097 int encoder_type;
490d3d1b 1098
96094081
DV
1099 /**
1100 * @index: Position inside the mode_config.list, can be used as an array
1101 * index. It is invariant over the lifetime of the encoder.
1102 */
490d3d1b
CW
1103 unsigned index;
1104
f453ba04
DA
1105 uint32_t possible_crtcs;
1106 uint32_t possible_clones;
1107
1108 struct drm_crtc *crtc;
3b336ec4 1109 struct drm_bridge *bridge;
f453ba04 1110 const struct drm_encoder_funcs *funcs;
4490d4c7 1111 const struct drm_encoder_helper_funcs *helper_private;
f453ba04
DA
1112};
1113
eb1f8e4f
DA
1114/* should we poll this connector for connects and disconnects */
1115/* hot plug detectable */
1116#define DRM_CONNECTOR_POLL_HPD (1 << 0)
1117/* poll for connections */
1118#define DRM_CONNECTOR_POLL_CONNECT (1 << 1)
1119/* can cleanly poll for disconnections without flickering the screen */
1120/* DACs should rarely do this without a lot of testing */
1121#define DRM_CONNECTOR_POLL_DISCONNECT (1 << 2)
1122
76adaa34
WF
1123#define MAX_ELD_BYTES 128
1124
f453ba04 1125/**
3bf0401c 1126 * struct drm_connector - central DRM connector control structure
72252548
JB
1127 * @dev: parent DRM device
1128 * @kdev: kernel device for sysfs attributes
1129 * @attr: sysfs attributes
1130 * @head: list management
1131 * @base: base KMS object
ac3ba4a5 1132 * @name: human readable name, can be overwritten by the driver
62cacc79 1133 * @connector_type: one of the DRM_MODE_CONNECTOR_<foo> types from drm_mode.h
72252548 1134 * @connector_type_id: index into connector type enum
f453ba04
DA
1135 * @interlace_allowed: can this connector handle interlaced modes?
1136 * @doublescan_allowed: can this connector handle doublescan?
2c0c33d4 1137 * @stereo_allowed: can this connector handle stereo modes?
40daac61 1138 * @registered: is this connector exposed (registered) with userspace?
72252548
JB
1139 * @modes: modes available on this connector (from fill_modes() + user)
1140 * @status: one of the drm_connector_status enums (connected, not, or unknown)
1141 * @probed_modes: list of modes derived directly from the display
1142 * @display_info: information about attached display (e.g. from EDID)
f453ba04 1143 * @funcs: connector control functions
72252548 1144 * @edid_blob_ptr: DRM property containing EDID if present
7e3bdf4a 1145 * @properties: property tracking for this connector
62cacc79 1146 * @polled: a DRM_CONNECTOR_POLL_<foo> value for core driven polling
72252548
JB
1147 * @dpms: current dpms state
1148 * @helper_private: mid-layer private data
2c0c33d4 1149 * @cmdline_mode: mode line parsed from the kernel cmdline for this connector
62cacc79 1150 * @force: a DRM_FORCE_<foo> state for forced mode sets
2c0c33d4 1151 * @override_edid: has the EDID been overwritten through debugfs for testing?
72252548
JB
1152 * @encoder_ids: valid encoders for this connector
1153 * @encoder: encoder driving this connector, if any
1154 * @eld: EDID-like data, if present
1155 * @dvi_dual: dual link DVI, if found
1156 * @max_tmds_clock: max clock rate, if found
1157 * @latency_present: AV delay info from ELD, if found
1158 * @video_latency: video latency info from ELD, if found
1159 * @audio_latency: audio latency info from ELD, if found
1160 * @null_edid_counter: track sinks that give us all zeros for the EDID
2c0c33d4 1161 * @bad_edid_counter: track sinks that give us an EDID with invalid checksum
ac6f2e29 1162 * @edid_corrupt: indicates whether the last read EDID was corrupt
2c0c33d4 1163 * @debugfs_entry: debugfs directory for this connector
144ecb97 1164 * @state: current atomic state for this connector
40d9b043
DA
1165 * @has_tile: is this connector connected to a tiled monitor
1166 * @tile_group: tile group for the connected monitor
1167 * @tile_is_single_monitor: whether the tile is one monitor housing
1168 * @num_h_tile: number of horizontal tiles in the tile group
1169 * @num_v_tile: number of vertical tiles in the tile group
1170 * @tile_h_loc: horizontal location of this tile
1171 * @tile_v_loc: vertical location of this tile
1172 * @tile_h_size: horizontal size of this tile.
1173 * @tile_v_size: vertical size of this tile.
f453ba04
DA
1174 *
1175 * Each connector may be connected to one or more CRTCs, or may be clonable by
1176 * another connector if they can share a CRTC. Each connector also has a specific
1177 * position in the broader display (referred to as a 'screen' though it could
1178 * span multiple monitors).
1179 */
1180struct drm_connector {
1181 struct drm_device *dev;
5bdebb18 1182 struct device *kdev;
f453ba04
DA
1183 struct device_attribute *attr;
1184 struct list_head head;
1185
1186 struct drm_mode_object base;
1187
2abdd313 1188 char *name;
69425599
DV
1189
1190 /**
1191 * @index: Compacted connector index, which matches the position inside
1192 * the mode_config.list for drivers not supporting hot-add/removing. Can
1193 * be used as an array index. It is invariant over the lifetime of the
1194 * connector.
1195 */
1196 unsigned index;
1197
f453ba04
DA
1198 int connector_type;
1199 int connector_type_id;
1200 bool interlace_allowed;
1201 bool doublescan_allowed;
560a067a 1202 bool stereo_allowed;
40daac61 1203 bool registered;
f453ba04
DA
1204 struct list_head modes; /* list of modes on this connector */
1205
f453ba04
DA
1206 enum drm_connector_status status;
1207
1208 /* these are modes added by probing with DDC or the BIOS */
1209 struct list_head probed_modes;
1210
1211 struct drm_display_info display_info;
1212 const struct drm_connector_funcs *funcs;
1213
f453ba04 1214 struct drm_property_blob *edid_blob_ptr;
7e3bdf4a 1215 struct drm_object_properties properties;
f453ba04 1216
ac3ba4a5
DV
1217 /**
1218 * @path_blob_ptr:
1219 *
1220 * DRM blob property data for the DP MST path property.
1221 */
43aba7eb
DA
1222 struct drm_property_blob *path_blob_ptr;
1223
ac3ba4a5
DV
1224 /**
1225 * @tile_blob_ptr:
1226 *
1227 * DRM blob property data for the tile property (used mostly by DP MST).
1228 * This is meant for screens which are driven through separate display
1229 * pipelines represented by &drm_crtc, which might not be running with
1230 * genlocked clocks. For tiled panels which are genlocked, like
1231 * dual-link LVDS or dual-link DSI, the driver should try to not expose
1232 * the tiling and virtualize both &drm_crtc and &drm_plane if needed.
1233 */
6f134d7b
DA
1234 struct drm_property_blob *tile_blob_ptr;
1235
eb1f8e4f
DA
1236 uint8_t polled; /* DRM_CONNECTOR_POLL_* */
1237
c9fb15f6
KP
1238 /* requested DPMS state */
1239 int dpms;
1240
4490d4c7 1241 const struct drm_connector_helper_funcs *helper_private;
f453ba04 1242
d50ba256 1243 /* forced on connector */
eaf99c74 1244 struct drm_cmdline_mode cmdline_mode;
d50ba256 1245 enum drm_connector_force force;
4cf2b281 1246 bool override_edid;
f453ba04 1247 uint32_t encoder_ids[DRM_CONNECTOR_MAX_ENCODER];
f453ba04 1248 struct drm_encoder *encoder; /* currently active encoder */
4a9a8b71 1249
76adaa34
WF
1250 /* EDID bits */
1251 uint8_t eld[MAX_ELD_BYTES];
1252 bool dvi_dual;
1253 int max_tmds_clock; /* in MHz */
1254 bool latency_present[2];
1255 int video_latency[2]; /* [0]: progressive, [1]: interlaced */
1256 int audio_latency[2];
4a9a8b71 1257 int null_edid_counter; /* needed to workaround some HW bugs where we get all 0s */
0b2443ed 1258 unsigned bad_edid_counter;
30f65707 1259
6ba2bd3d
TP
1260 /* Flag for raw EDID header corruption - used in Displayport
1261 * compliance testing - * Displayport Link CTS Core 1.2 rev1.1 4.2.2.6
1262 */
1263 bool edid_corrupt;
1264
30f65707 1265 struct dentry *debugfs_entry;
144ecb97
DV
1266
1267 struct drm_connector_state *state;
40d9b043
DA
1268
1269 /* DisplayID bits */
1270 bool has_tile;
1271 struct drm_tile_group *tile_group;
1272 bool tile_is_single_monitor;
1273
1274 uint8_t num_h_tile, num_v_tile;
1275 uint8_t tile_h_loc, tile_v_loc;
1276 uint16_t tile_h_size, tile_v_size;
144ecb97
DV
1277};
1278
1279/**
1280 * struct drm_plane_state - mutable plane state
07cc0ef6 1281 * @plane: backpointer to the plane
144ecb97 1282 * @crtc: currently bound CRTC, NULL if disabled
cc4ceb48 1283 * @fb: currently bound framebuffer
e2330f07 1284 * @fence: optional fence to wait for before scanning out @fb
144ecb97
DV
1285 * @crtc_x: left position of visible portion of plane on crtc
1286 * @crtc_y: upper position of visible portion of plane on crtc
1287 * @crtc_w: width of visible portion of plane on crtc
1288 * @crtc_h: height of visible portion of plane on crtc
1289 * @src_x: left position of visible portion of plane within
1290 * plane (in 16.16)
1291 * @src_y: upper position of visible portion of plane within
1292 * plane (in 16.16)
1293 * @src_w: width of visible portion of plane (in 16.16)
1294 * @src_h: height of visible portion of plane (in 16.16)
ac3ba4a5 1295 * @rotation: rotation of the plane
44d1240d
MS
1296 * @zpos: priority of the given plane on crtc (optional)
1297 * @normalized_zpos: normalized value of zpos: unique, range from 0 to N-1
1298 * where N is the number of active planes for given crtc
d7da824d
VS
1299 * @src: clipped source coordinates of the plane (in 16.16)
1300 * @dst: clipped destination coordinates of the plane
1301 * @visible: visibility of the plane
144ecb97
DV
1302 * @state: backpointer to global drm_atomic_state
1303 */
1304struct drm_plane_state {
07cc0ef6
DV
1305 struct drm_plane *plane;
1306
6ddd388a
RC
1307 struct drm_crtc *crtc; /* do not write directly, use drm_atomic_set_crtc_for_plane() */
1308 struct drm_framebuffer *fb; /* do not write directly, use drm_atomic_set_fb_for_plane() */
e2330f07 1309 struct fence *fence;
144ecb97
DV
1310
1311 /* Signed dest location allows it to be partially off screen */
1312 int32_t crtc_x, crtc_y;
1313 uint32_t crtc_w, crtc_h;
1314
1315 /* Source values are 16.16 fixed point */
1316 uint32_t src_x, src_y;
1317 uint32_t src_h, src_w;
1318
1da30627
MR
1319 /* Plane rotation */
1320 unsigned int rotation;
1321
44d1240d
MS
1322 /* Plane zpos */
1323 unsigned int zpos;
1324 unsigned int normalized_zpos;
1325
d7da824d
VS
1326 /* Clipped coordinates */
1327 struct drm_rect src, dst;
1328
1329 /*
1330 * Is the plane actually visible? Can be false even
1331 * if fb!=NULL and crtc!=NULL, due to clipping.
1332 */
1333 bool visible;
1334
144ecb97 1335 struct drm_atomic_state *state;
f453ba04
DA
1336};
1337
144ecb97 1338
8cf5c917 1339/**
3bf0401c 1340 * struct drm_plane_funcs - driver plane control functions
8cf5c917
JB
1341 */
1342struct drm_plane_funcs {
88548636
DV
1343 /**
1344 * @update_plane:
1345 *
1346 * This is the legacy entry point to enable and configure the plane for
1347 * the given CRTC and framebuffer. It is never called to disable the
1348 * plane, i.e. the passed-in crtc and fb paramters are never NULL.
1349 *
1350 * The source rectangle in frame buffer memory coordinates is given by
1351 * the src_x, src_y, src_w and src_h parameters (as 16.16 fixed point
1352 * values). Devices that don't support subpixel plane coordinates can
1353 * ignore the fractional part.
1354 *
1355 * The destination rectangle in CRTC coordinates is given by the
1356 * crtc_x, crtc_y, crtc_w and crtc_h parameters (as integer values).
1357 * Devices scale the source rectangle to the destination rectangle. If
1358 * scaling is not supported, and the source rectangle size doesn't match
1359 * the destination rectangle size, the driver must return a
1360 * -<errorname>EINVAL</errorname> error.
1361 *
1362 * Drivers implementing atomic modeset should use
1363 * drm_atomic_helper_update_plane() to implement this hook.
1364 *
1365 * RETURNS:
1366 *
1367 * 0 on success or a negative error code on failure.
1368 */
8cf5c917
JB
1369 int (*update_plane)(struct drm_plane *plane,
1370 struct drm_crtc *crtc, struct drm_framebuffer *fb,
1371 int crtc_x, int crtc_y,
1372 unsigned int crtc_w, unsigned int crtc_h,
1373 uint32_t src_x, uint32_t src_y,
1374 uint32_t src_w, uint32_t src_h);
88548636
DV
1375
1376 /**
1377 * @disable_plane:
1378 *
1379 * This is the legacy entry point to disable the plane. The DRM core
c6b0ca3e 1380 * calls this method in response to a DRM_IOCTL_MODE_SETPLANE IOCTL call
88548636
DV
1381 * with the frame buffer ID set to 0. Disabled planes must not be
1382 * processed by the CRTC.
1383 *
1384 * Drivers implementing atomic modeset should use
1385 * drm_atomic_helper_disable_plane() to implement this hook.
1386 *
1387 * RETURNS:
1388 *
1389 * 0 on success or a negative error code on failure.
1390 */
8cf5c917 1391 int (*disable_plane)(struct drm_plane *plane);
88548636
DV
1392
1393 /**
1394 * @destroy:
1395 *
1396 * Clean up plane resources. This is only called at driver unload time
1397 * through drm_mode_config_cleanup() since a plane cannot be hotplugged
1398 * in DRM.
1399 */
8cf5c917 1400 void (*destroy)(struct drm_plane *plane);
88548636
DV
1401
1402 /**
1403 * @reset:
1404 *
1405 * Reset plane hardware and software state to off. This function isn't
1406 * called by the core directly, only through drm_mode_config_reset().
1407 * It's not a helper hook only for historical reasons.
1408 *
1409 * Atomic drivers can use drm_atomic_helper_plane_reset() to reset
1410 * atomic state using this hook.
1411 */
2a0d7cfd 1412 void (*reset)(struct drm_plane *plane);
4d93914a 1413
88548636
DV
1414 /**
1415 * @set_property:
1416 *
1417 * This is the legacy entry point to update a property attached to the
1418 * plane.
1419 *
1420 * Drivers implementing atomic modeset should use
1421 * drm_atomic_helper_plane_set_property() to implement this hook.
1422 *
1423 * This callback is optional if the driver does not support any legacy
1424 * driver-private properties.
1425 *
1426 * RETURNS:
1427 *
1428 * 0 on success or a negative error code on failure.
1429 */
4d93914a
RC
1430 int (*set_property)(struct drm_plane *plane,
1431 struct drm_property *property, uint64_t val);
144ecb97 1432
88548636
DV
1433 /**
1434 * @atomic_duplicate_state:
1435 *
1436 * Duplicate the current atomic state for this plane and return it.
1437 * The core and helpers gurantee that any atomic state duplicated with
1438 * this hook and still owned by the caller (i.e. not transferred to the
1439 * driver by calling ->atomic_commit() from struct
1440 * &drm_mode_config_funcs) will be cleaned up by calling the
1441 * @atomic_destroy_state hook in this structure.
1442 *
1443 * Atomic drivers which don't subclass struct &drm_plane_state should use
1444 * drm_atomic_helper_plane_duplicate_state(). Drivers that subclass the
1445 * state structure to extend it with driver-private state should use
1446 * __drm_atomic_helper_plane_duplicate_state() to make sure shared state is
1447 * duplicated in a consistent fashion across drivers.
1448 *
1449 * It is an error to call this hook before plane->state has been
1450 * initialized correctly.
1451 *
1452 * NOTE:
1453 *
1454 * If the duplicate state references refcounted resources this hook must
1455 * acquire a reference for each of them. The driver must release these
1456 * references again in @atomic_destroy_state.
1457 *
1458 * RETURNS:
1459 *
1460 * Duplicated atomic state or NULL when the allocation failed.
1461 */
144ecb97 1462 struct drm_plane_state *(*atomic_duplicate_state)(struct drm_plane *plane);
88548636
DV
1463
1464 /**
1465 * @atomic_destroy_state:
1466 *
1467 * Destroy a state duplicated with @atomic_duplicate_state and release
1468 * or unreference all resources it references
1469 */
144ecb97 1470 void (*atomic_destroy_state)(struct drm_plane *plane,
cc4ceb48 1471 struct drm_plane_state *state);
88548636
DV
1472
1473 /**
1474 * @atomic_set_property:
1475 *
1476 * Decode a driver-private property value and store the decoded value
1477 * into the passed-in state structure. Since the atomic core decodes all
1478 * standardized properties (even for extensions beyond the core set of
1479 * properties which might not be implemented by all drivers) this
1480 * requires drivers to subclass the state structure.
1481 *
1482 * Such driver-private properties should really only be implemented for
1483 * truly hardware/vendor specific state. Instead it is preferred to
1484 * standardize atomic extension and decode the properties used to expose
1485 * such an extension in the core.
1486 *
1487 * Do not call this function directly, use
1488 * drm_atomic_plane_set_property() instead.
1489 *
1490 * This callback is optional if the driver does not support any
1491 * driver-private atomic properties.
1492 *
1493 * NOTE:
1494 *
1495 * This function is called in the state assembly phase of atomic
1496 * modesets, which can be aborted for any reason (including on
1497 * userspace's request to just check whether a configuration would be
1498 * possible). Drivers MUST NOT touch any persistent state (hardware or
1499 * software) or data structures except the passed in @state parameter.
1500 *
1501 * Also since userspace controls in which order properties are set this
1502 * function must not do any input validation (since the state update is
1503 * incomplete and hence likely inconsistent). Instead any such input
1504 * validation must be done in the various atomic_check callbacks.
1505 *
1506 * RETURNS:
1507 *
1508 * 0 if the property has been found, -EINVAL if the property isn't
1509 * implemented by the driver (which shouldn't ever happen, the core only
1510 * asks for properties attached to this plane). No other validation is
1511 * allowed by the driver. The core already checks that the property
1512 * value is within the range (integer, valid enum value, ...) the driver
1513 * set when registering the property.
1514 */
144ecb97
DV
1515 int (*atomic_set_property)(struct drm_plane *plane,
1516 struct drm_plane_state *state,
1517 struct drm_property *property,
1518 uint64_t val);
88548636
DV
1519
1520 /**
1521 * @atomic_get_property:
1522 *
1523 * Reads out the decoded driver-private property. This is used to
c6b0ca3e 1524 * implement the GETPLANE IOCTL.
88548636
DV
1525 *
1526 * Do not call this function directly, use
1527 * drm_atomic_plane_get_property() instead.
1528 *
1529 * This callback is optional if the driver does not support any
1530 * driver-private atomic properties.
1531 *
1532 * RETURNS:
1533 *
1534 * 0 on success, -EINVAL if the property isn't implemented by the
1535 * driver (which should never happen, the core only asks for
1536 * properties attached to this plane).
1537 */
ac9c9256
RC
1538 int (*atomic_get_property)(struct drm_plane *plane,
1539 const struct drm_plane_state *state,
1540 struct drm_property *property,
1541 uint64_t *val);
79190ea2
BG
1542 /**
1543 * @late_register:
1544 *
1545 * This optional hook can be used to register additional userspace
1546 * interfaces attached to the plane like debugfs interfaces.
1547 * It is called late in the driver load sequence from drm_dev_register().
1548 * Everything added from this callback should be unregistered in
1549 * the early_unregister callback.
1550 *
1551 * Returns:
1552 *
1553 * 0 on success, or a negative error code on failure.
1554 */
1555 int (*late_register)(struct drm_plane *plane);
1556
1557 /**
1558 * @early_unregister:
1559 *
1560 * This optional hook should be used to unregister the additional
1561 * userspace interfaces attached to the plane from
1562 * late_unregister(). It is called from drm_dev_unregister(),
1563 * early in the driver unload sequence to disable userspace access
1564 * before data structures are torndown.
1565 */
1566 void (*early_unregister)(struct drm_plane *plane);
8cf5c917
JB
1567};
1568
e27dde3e
MR
1569enum drm_plane_type {
1570 DRM_PLANE_TYPE_OVERLAY,
1571 DRM_PLANE_TYPE_PRIMARY,
1572 DRM_PLANE_TYPE_CURSOR,
1573};
1574
88548636 1575
8cf5c917 1576/**
3bf0401c 1577 * struct drm_plane - central DRM plane control structure
8cf5c917
JB
1578 * @dev: DRM device this plane belongs to
1579 * @head: for list management
ac3ba4a5 1580 * @name: human readable name, can be overwritten by the driver
8cf5c917
JB
1581 * @base: base mode object
1582 * @possible_crtcs: pipes this plane can be bound to
1583 * @format_types: array of formats supported by this plane
1584 * @format_count: number of formats supported
7eb5f302 1585 * @format_default: driver hasn't supplied supported formats for the plane
8cf5c917
JB
1586 * @crtc: currently bound CRTC
1587 * @fb: currently bound fb
2c0c33d4
DV
1588 * @old_fb: Temporary tracking of the old fb while a modeset is ongoing. Used by
1589 * drm_mode_set_config_internal() to implement correct refcounting.
8cf5c917 1590 * @funcs: helper functions
4d93914a 1591 * @properties: property tracking for this plane
e27dde3e 1592 * @type: type of plane (overlay, primary, cursor)
144ecb97 1593 * @state: current atomic state for this plane
44d1240d 1594 * @zpos_property: zpos property for this plane
ac3ba4a5 1595 * @helper_private: mid-layer private data
8cf5c917
JB
1596 */
1597struct drm_plane {
1598 struct drm_device *dev;
1599 struct list_head head;
1600
9f4c97a2
VS
1601 char *name;
1602
ac3ba4a5
DV
1603 /**
1604 * @mutex:
1605 *
1606 * Protects modeset plane state, together with the mutex of &drm_crtc
1607 * this plane is linked to (when active, getting actived or getting
1608 * disabled).
1609 */
4d02e2de
DV
1610 struct drm_modeset_lock mutex;
1611
8cf5c917
JB
1612 struct drm_mode_object base;
1613
1614 uint32_t possible_crtcs;
1615 uint32_t *format_types;
45e3743a 1616 unsigned int format_count;
7eb5f302 1617 bool format_default;
8cf5c917
JB
1618
1619 struct drm_crtc *crtc;
1620 struct drm_framebuffer *fb;
1621
3d30a59b
DV
1622 struct drm_framebuffer *old_fb;
1623
8cf5c917 1624 const struct drm_plane_funcs *funcs;
4d93914a
RC
1625
1626 struct drm_object_properties properties;
e27dde3e
MR
1627
1628 enum drm_plane_type type;
144ecb97 1629
96094081
DV
1630 /**
1631 * @index: Position inside the mode_config.list, can be used as an array
1632 * index. It is invariant over the lifetime of the plane.
1633 */
490d3d1b
CW
1634 unsigned index;
1635
4490d4c7 1636 const struct drm_plane_helper_funcs *helper_private;
c2fcd274 1637
144ecb97 1638 struct drm_plane_state *state;
44d1240d
MS
1639
1640 struct drm_property *zpos_property;
8cf5c917
JB
1641};
1642
3b336ec4 1643/**
3bf0401c 1644 * struct drm_bridge_funcs - drm_bridge control functions
3d3f8b1f 1645 * @attach: Called during drm_bridge_attach
3b336ec4
SP
1646 */
1647struct drm_bridge_funcs {
3d3f8b1f 1648 int (*attach)(struct drm_bridge *bridge);
da024fe5
DV
1649
1650 /**
1651 * @mode_fixup:
1652 *
1653 * This callback is used to validate and adjust a mode. The paramater
1654 * mode is the display mode that should be fed to the next element in
1655 * the display chain, either the final &drm_connector or the next
1656 * &drm_bridge. The parameter adjusted_mode is the input mode the bridge
1657 * requires. It can be modified by this callback and does not need to
1658 * match mode.
1659 *
1660 * This is the only hook that allows a bridge to reject a modeset. If
1661 * this function passes all other callbacks must succeed for this
1662 * configuration.
1663 *
1664 * NOTE:
1665 *
1666 * This function is called in the check phase of atomic modesets, which
1667 * can be aborted for any reason (including on userspace's request to
1668 * just check whether a configuration would be possible). Drivers MUST
1669 * NOT touch any persistent state (hardware or software) or data
88548636 1670 * structures except the passed in @state parameter.
da024fe5
DV
1671 *
1672 * RETURNS:
1673 *
1674 * True if an acceptable configuration is possible, false if the modeset
1675 * operation should be rejected.
1676 */
3b336ec4
SP
1677 bool (*mode_fixup)(struct drm_bridge *bridge,
1678 const struct drm_display_mode *mode,
1679 struct drm_display_mode *adjusted_mode);
da024fe5
DV
1680 /**
1681 * @disable:
1682 *
1683 * This callback should disable the bridge. It is called right before
1684 * the preceding element in the display pipe is disabled. If the
1685 * preceding element is a bridge this means it's called before that
1686 * bridge's ->disable() function. If the preceding element is a
1687 * &drm_encoder it's called right before the encoder's ->disable(),
1688 * ->prepare() or ->dpms() hook from struct &drm_encoder_helper_funcs.
1689 *
1690 * The bridge can assume that the display pipe (i.e. clocks and timing
1691 * signals) feeding it is still running when this callback is called.
c8a3b2ae
LP
1692 *
1693 * The disable callback is optional.
da024fe5 1694 */
3b336ec4 1695 void (*disable)(struct drm_bridge *bridge);
da024fe5
DV
1696
1697 /**
1698 * @post_disable:
1699 *
1700 * This callback should disable the bridge. It is called right after
1701 * the preceding element in the display pipe is disabled. If the
1702 * preceding element is a bridge this means it's called after that
1703 * bridge's ->post_disable() function. If the preceding element is a
1704 * &drm_encoder it's called right after the encoder's ->disable(),
1705 * ->prepare() or ->dpms() hook from struct &drm_encoder_helper_funcs.
1706 *
1707 * The bridge must assume that the display pipe (i.e. clocks and timing
1708 * singals) feeding it is no longer running when this callback is
1709 * called.
c8a3b2ae
LP
1710 *
1711 * The post_disable callback is optional.
da024fe5 1712 */
3b336ec4 1713 void (*post_disable)(struct drm_bridge *bridge);
da024fe5
DV
1714
1715 /**
1716 * @mode_set:
1717 *
1718 * This callback should set the given mode on the bridge. It is called
1719 * after the ->mode_set() callback for the preceding element in the
1720 * display pipeline has been called already. The display pipe (i.e.
1721 * clocks and timing signals) is off when this function is called.
1722 */
3b336ec4
SP
1723 void (*mode_set)(struct drm_bridge *bridge,
1724 struct drm_display_mode *mode,
1725 struct drm_display_mode *adjusted_mode);
da024fe5
DV
1726 /**
1727 * @pre_enable:
1728 *
1729 * This callback should enable the bridge. It is called right before
1730 * the preceding element in the display pipe is enabled. If the
1731 * preceding element is a bridge this means it's called before that
1732 * bridge's ->pre_enable() function. If the preceding element is a
1733 * &drm_encoder it's called right before the encoder's ->enable(),
1734 * ->commit() or ->dpms() hook from struct &drm_encoder_helper_funcs.
1735 *
1736 * The display pipe (i.e. clocks and timing signals) feeding this bridge
1737 * will not yet be running when this callback is called. The bridge must
1738 * not enable the display link feeding the next bridge in the chain (if
1739 * there is one) when this callback is called.
c8a3b2ae
LP
1740 *
1741 * The pre_enable callback is optional.
da024fe5 1742 */
3b336ec4 1743 void (*pre_enable)(struct drm_bridge *bridge);
da024fe5
DV
1744
1745 /**
1746 * @enable:
1747 *
1748 * This callback should enable the bridge. It is called right after
1749 * the preceding element in the display pipe is enabled. If the
1750 * preceding element is a bridge this means it's called after that
1751 * bridge's ->enable() function. If the preceding element is a
1752 * &drm_encoder it's called right after the encoder's ->enable(),
1753 * ->commit() or ->dpms() hook from struct &drm_encoder_helper_funcs.
1754 *
1755 * The bridge can assume that the display pipe (i.e. clocks and timing
1756 * signals) feeding it is running when this callback is called. This
1757 * callback must enable the display link feeding the next bridge in the
1758 * chain if there is one.
c8a3b2ae
LP
1759 *
1760 * The enable callback is optional.
da024fe5 1761 */
3b336ec4 1762 void (*enable)(struct drm_bridge *bridge);
3b336ec4
SP
1763};
1764
1765/**
3bf0401c 1766 * struct drm_bridge - central DRM bridge control structure
3b336ec4 1767 * @dev: DRM device this bridge belongs to
862e686c
AT
1768 * @encoder: encoder to which this bridge is connected
1769 * @next: the next bridge in the encoder chain
3d3f8b1f
AK
1770 * @of_node: device node pointer to the bridge
1771 * @list: to keep track of all added bridges
3b336ec4
SP
1772 * @funcs: control functions
1773 * @driver_private: pointer to the bridge driver's internal context
1774 */
1775struct drm_bridge {
1776 struct drm_device *dev;
3d3f8b1f 1777 struct drm_encoder *encoder;
862e686c 1778 struct drm_bridge *next;
3d3f8b1f
AK
1779#ifdef CONFIG_OF
1780 struct device_node *of_node;
1781#endif
1782 struct list_head list;
3b336ec4
SP
1783
1784 const struct drm_bridge_funcs *funcs;
1785 void *driver_private;
1786};
1787
3b24f7d6
DV
1788/**
1789 * struct drm_crtc_commit - track modeset commits on a CRTC
1790 *
1791 * This structure is used to track pending modeset changes and atomic commit on
1792 * a per-CRTC basis. Since updating the list should never block this structure
1793 * is reference counted to allow waiters to safely wait on an event to complete,
1794 * without holding any locks.
1795 *
1796 * It has 3 different events in total to allow a fine-grained synchronization
1797 * between outstanding updates::
1798 *
1799 * atomic commit thread hardware
1800 *
1801 * write new state into hardware ----> ...
1802 * signal hw_done
1803 * switch to new state on next
1804 * ... v/hblank
1805 *
1806 * wait for buffers to show up ...
1807 *
1808 * ... send completion irq
1809 * irq handler signals flip_done
1810 * cleanup old buffers
1811 *
1812 * signal cleanup_done
1813 *
1814 * wait for flip_done <----
1815 * clean up atomic state
1816 *
1817 * The important bit to know is that cleanup_done is the terminal event, but the
1818 * ordering between flip_done and hw_done is entirely up to the specific driver
1819 * and modeset state change.
1820 *
1821 * For an implementation of how to use this look at
1822 * drm_atomic_helper_setup_commit() from the atomic helper library.
1823 */
1824struct drm_crtc_commit {
1825 /**
1826 * @crtc:
1827 *
1828 * DRM CRTC for this commit.
1829 */
1830 struct drm_crtc *crtc;
1831
1832 /**
1833 * @ref:
1834 *
1835 * Reference count for this structure. Needed to allow blocking on
1836 * completions without the risk of the completion disappearing
1837 * meanwhile.
1838 */
1839 struct kref ref;
1840
1841 /**
1842 * @flip_done:
1843 *
1844 * Will be signaled when the hardware has flipped to the new set of
1845 * buffers. Signals at the same time as when the drm event for this
1846 * commit is sent to userspace, or when an out-fence is singalled. Note
1847 * that for most hardware, in most cases this happens after @hw_done is
1848 * signalled.
1849 */
1850 struct completion flip_done;
1851
1852 /**
1853 * @hw_done:
1854 *
1855 * Will be signalled when all hw register changes for this commit have
1856 * been written out. Especially when disabling a pipe this can be much
1857 * later than than @flip_done, since that can signal already when the
1858 * screen goes black, whereas to fully shut down a pipe more register
1859 * I/O is required.
1860 *
1861 * Note that this does not need to include separately reference-counted
1862 * resources like backing storage buffer pinning, or runtime pm
1863 * management.
1864 */
1865 struct completion hw_done;
1866
1867 /**
1868 * @cleanup_done:
1869 *
1870 * Will be signalled after old buffers have been cleaned up by calling
1871 * drm_atomic_helper_cleanup_planes(). Since this can only happen after
1872 * a vblank wait completed it might be a bit later. This completion is
1873 * useful to throttle updates and avoid hardware updates getting ahead
1874 * of the buffer cleanup too much.
1875 */
1876 struct completion cleanup_done;
1877
1878 /**
1879 * @commit_entry:
1880 *
1881 * Entry on the per-CRTC commit_list. Protected by crtc->commit_lock.
1882 */
1883 struct list_head commit_entry;
1884
1885 /**
1886 * @event:
1887 *
1888 * &drm_pending_vblank_event pointer to clean up private events.
1889 */
1890 struct drm_pending_vblank_event *event;
1891};
1892
b8b5342b
DV
1893struct __drm_planes_state {
1894 struct drm_plane *ptr;
1895 struct drm_plane_state *state;
1896};
1897
5d943aa6
DV
1898struct __drm_crtcs_state {
1899 struct drm_crtc *ptr;
1900 struct drm_crtc_state *state;
3b24f7d6 1901 struct drm_crtc_commit *commit;
5d943aa6
DV
1902};
1903
63e83c1d
DV
1904struct __drm_connnectors_state {
1905 struct drm_connector *ptr;
1906 struct drm_connector_state *state;
1907};
1908
cc4ceb48 1909/**
08855fae 1910 * struct drm_atomic_state - the global state object for atomic updates
cc4ceb48 1911 * @dev: parent DRM device
d34f20d6 1912 * @allow_modeset: allow full modeset
c6b0ca3e 1913 * @legacy_cursor_update: hint to enforce legacy cursor IOCTL semantics
40616a26 1914 * @legacy_set_config: Disable conflicting encoders instead of failing with -EINVAL.
b8b5342b 1915 * @planes: pointer to array of structures with per-plane data
cc4ceb48 1916 * @crtcs: pointer to array of CRTC pointers
f52b69f1 1917 * @num_connector: size of the @connectors and @connector_states arrays
63e83c1d 1918 * @connectors: pointer to array of structures with per-connector data
cc4ceb48
DV
1919 * @acquire_ctx: acquire context for this atomic modeset state update
1920 */
1921struct drm_atomic_state {
1922 struct drm_device *dev;
d34f20d6 1923 bool allow_modeset : 1;
f02ad907 1924 bool legacy_cursor_update : 1;
40616a26 1925 bool legacy_set_config : 1;
b8b5342b 1926 struct __drm_planes_state *planes;
5d943aa6 1927 struct __drm_crtcs_state *crtcs;
f52b69f1 1928 int num_connector;
63e83c1d 1929 struct __drm_connnectors_state *connectors;
cc4ceb48
DV
1930
1931 struct drm_modeset_acquire_ctx *acquire_ctx;
3b24f7d6
DV
1932
1933 /**
1934 * @commit_work:
1935 *
1936 * Work item which can be used by the driver or helpers to execute the
1937 * commit without blocking.
1938 */
1939 struct work_struct commit_work;
cc4ceb48
DV
1940};
1941
1942
f453ba04 1943/**
3bf0401c 1944 * struct drm_mode_set - new values for a CRTC config change
ef27351a
JB
1945 * @fb: framebuffer to use for new config
1946 * @crtc: CRTC whose configuration we're about to change
1947 * @mode: mode timings to use
1948 * @x: position of this CRTC relative to @fb
1949 * @y: position of this CRTC relative to @fb
1950 * @connectors: array of connectors to drive with this CRTC if possible
1951 * @num_connectors: size of @connectors array
f453ba04
DA
1952 *
1953 * Represents a single crtc the connectors that it drives with what mode
1954 * and from which framebuffer it scans out from.
1955 *
1956 * This is used to set modes.
1957 */
1958struct drm_mode_set {
f453ba04
DA
1959 struct drm_framebuffer *fb;
1960 struct drm_crtc *crtc;
1961 struct drm_display_mode *mode;
1962
1963 uint32_t x;
1964 uint32_t y;
1965
1966 struct drm_connector **connectors;
1967 size_t num_connectors;
1968};
1969
1970/**
550cebcd 1971 * struct drm_mode_config_funcs - basic driver provided mode setting functions
550cebcd
JB
1972 *
1973 * Some global (i.e. not per-CRTC, connector, etc) mode setting functions that
1974 * involve drivers.
f453ba04
DA
1975 */
1976struct drm_mode_config_funcs {
9953f417
DV
1977 /**
1978 * @fb_create:
1979 *
1980 * Create a new framebuffer object. The core does basic checks on the
1981 * requested metadata, but most of that is left to the driver. See
1982 * struct &drm_mode_fb_cmd2 for details.
1983 *
d55f5320
DV
1984 * If the parameters are deemed valid and the backing storage objects in
1985 * the underlying memory manager all exist, then the driver allocates
1986 * a new &drm_framebuffer structure, subclassed to contain
1987 * driver-specific information (like the internal native buffer object
1988 * references). It also needs to fill out all relevant metadata, which
1989 * should be done by calling drm_helper_mode_fill_fb_struct().
1990 *
1991 * The initialization is finalized by calling drm_framebuffer_init(),
1992 * which registers the framebuffer and makes it accessible to other
1993 * threads.
1994 *
9953f417
DV
1995 * RETURNS:
1996 *
1997 * A new framebuffer with an initial reference count of 1 or a negative
1998 * error code encoded with ERR_PTR().
1999 */
550cebcd
JB
2000 struct drm_framebuffer *(*fb_create)(struct drm_device *dev,
2001 struct drm_file *file_priv,
1eb83451 2002 const struct drm_mode_fb_cmd2 *mode_cmd);
9953f417
DV
2003
2004 /**
2005 * @output_poll_changed:
2006 *
2007 * Callback used by helpers to inform the driver of output configuration
2008 * changes.
2009 *
2010 * Drivers implementing fbdev emulation with the helpers can call
2011 * drm_fb_helper_hotplug_changed from this hook to inform the fbdev
2012 * helper of output changes.
2013 *
2014 * FIXME:
2015 *
2016 * Except that there's no vtable for device-level helper callbacks
2017 * there's no reason this is a core function.
2018 */
eb1f8e4f 2019 void (*output_poll_changed)(struct drm_device *dev);
cc4ceb48 2020
9953f417
DV
2021 /**
2022 * @atomic_check:
2023 *
2024 * This is the only hook to validate an atomic modeset update. This
2025 * function must reject any modeset and state changes which the hardware
2026 * or driver doesn't support. This includes but is of course not limited
2027 * to:
2028 *
2029 * - Checking that the modes, framebuffers, scaling and placement
2030 * requirements and so on are within the limits of the hardware.
2031 *
2032 * - Checking that any hidden shared resources are not oversubscribed.
2033 * This can be shared PLLs, shared lanes, overall memory bandwidth,
2034 * display fifo space (where shared between planes or maybe even
2035 * CRTCs).
2036 *
2037 * - Checking that virtualized resources exported to userspace are not
2038 * oversubscribed. For various reasons it can make sense to expose
2039 * more planes, crtcs or encoders than which are physically there. One
2040 * example is dual-pipe operations (which generally should be hidden
2041 * from userspace if when lockstepped in hardware, exposed otherwise),
2042 * where a plane might need 1 hardware plane (if it's just on one
2043 * pipe), 2 hardware planes (when it spans both pipes) or maybe even
2044 * shared a hardware plane with a 2nd plane (if there's a compatible
2045 * plane requested on the area handled by the other pipe).
2046 *
2047 * - Check that any transitional state is possible and that if
2048 * requested, the update can indeed be done in the vblank period
2049 * without temporarily disabling some functions.
2050 *
2051 * - Check any other constraints the driver or hardware might have.
2052 *
2053 * - This callback also needs to correctly fill out the &drm_crtc_state
2054 * in this update to make sure that drm_atomic_crtc_needs_modeset()
2055 * reflects the nature of the possible update and returns true if and
2056 * only if the update cannot be applied without tearing within one
2057 * vblank on that CRTC. The core uses that information to reject
2058 * updates which require a full modeset (i.e. blanking the screen, or
2059 * at least pausing updates for a substantial amount of time) if
2060 * userspace has disallowed that in its request.
2061 *
2062 * - The driver also does not need to repeat basic input validation
2063 * like done for the corresponding legacy entry points. The core does
2064 * that before calling this hook.
2065 *
2066 * See the documentation of @atomic_commit for an exhaustive list of
2067 * error conditions which don't have to be checked at the
2068 * ->atomic_check() stage?
2069 *
2070 * See the documentation for struct &drm_atomic_state for how exactly
2071 * an atomic modeset update is described.
2072 *
2073 * Drivers using the atomic helpers can implement this hook using
2074 * drm_atomic_helper_check(), or one of the exported sub-functions of
2075 * it.
2076 *
2077 * RETURNS:
2078 *
2079 * 0 on success or one of the below negative error codes:
2080 *
2081 * - -EINVAL, if any of the above constraints are violated.
2082 *
2083 * - -EDEADLK, when returned from an attempt to acquire an additional
2084 * &drm_modeset_lock through drm_modeset_lock().
2085 *
2086 * - -ENOMEM, if allocating additional state sub-structures failed due
2087 * to lack of memory.
2088 *
2089 * - -EINTR, -EAGAIN or -ERESTARTSYS, if the IOCTL should be restarted.
2090 * This can either be due to a pending signal, or because the driver
2091 * needs to completely bail out to recover from an exceptional
2092 * situation like a GPU hang. From a userspace point all errors are
2093 * treated equally.
2094 */
cc4ceb48 2095 int (*atomic_check)(struct drm_device *dev,
9953f417
DV
2096 struct drm_atomic_state *state);
2097
2098 /**
2099 * @atomic_commit:
2100 *
2101 * This is the only hook to commit an atomic modeset update. The core
2102 * guarantees that @atomic_check has been called successfully before
2103 * calling this function, and that nothing has been changed in the
2104 * interim.
2105 *
2106 * See the documentation for struct &drm_atomic_state for how exactly
2107 * an atomic modeset update is described.
2108 *
2109 * Drivers using the atomic helpers can implement this hook using
2110 * drm_atomic_helper_commit(), or one of the exported sub-functions of
2111 * it.
2112 *
286dbb8d 2113 * Nonblocking commits (as indicated with the nonblock parameter) must
9953f417
DV
2114 * do any preparatory work which might result in an unsuccessful commit
2115 * in the context of this callback. The only exceptions are hardware
2116 * errors resulting in -EIO. But even in that case the driver must
2117 * ensure that the display pipe is at least running, to avoid
2118 * compositors crashing when pageflips don't work. Anything else,
2119 * specifically committing the update to the hardware, should be done
2120 * without blocking the caller. For updates which do not require a
2121 * modeset this must be guaranteed.
2122 *
2123 * The driver must wait for any pending rendering to the new
2124 * framebuffers to complete before executing the flip. It should also
2125 * wait for any pending rendering from other drivers if the underlying
286dbb8d 2126 * buffer is a shared dma-buf. Nonblocking commits must not wait for
9953f417
DV
2127 * rendering in the context of this callback.
2128 *
2129 * An application can request to be notified when the atomic commit has
2130 * completed. These events are per-CRTC and can be distinguished by the
2131 * CRTC index supplied in &drm_event to userspace.
2132 *
2133 * The drm core will supply a struct &drm_event in the event
2134 * member of each CRTC's &drm_crtc_state structure. This can be handled by the
2135 * drm_crtc_send_vblank_event() function, which the driver should call on
2136 * the provided event upon completion of the atomic commit. Note that if
2137 * the driver supports vblank signalling and timestamping the vblank
2138 * counters and timestamps must agree with the ones returned from page
2139 * flip events. With the current vblank helper infrastructure this can
2140 * be achieved by holding a vblank reference while the page flip is
2141 * pending, acquired through drm_crtc_vblank_get() and released with
2142 * drm_crtc_vblank_put(). Drivers are free to implement their own vblank
2143 * counter and timestamp tracking though, e.g. if they have accurate
2144 * timestamp registers in hardware.
2145 *
2146 * NOTE:
2147 *
2148 * Drivers are not allowed to shut down any display pipe successfully
2149 * enabled through an atomic commit on their own. Doing so can result in
2150 * compositors crashing if a page flip is suddenly rejected because the
2151 * pipe is off.
2152 *
2153 * RETURNS:
2154 *
2155 * 0 on success or one of the below negative error codes:
2156 *
286dbb8d 2157 * - -EBUSY, if a nonblocking updated is requested and there is
9953f417
DV
2158 * an earlier updated pending. Drivers are allowed to support a queue
2159 * of outstanding updates, but currently no driver supports that.
2160 * Note that drivers must wait for preceding updates to complete if a
2161 * synchronous update is requested, they are not allowed to fail the
2162 * commit in that case.
2163 *
2164 * - -ENOMEM, if the driver failed to allocate memory. Specifically
2165 * this can happen when trying to pin framebuffers, which must only
2166 * be done when committing the state.
2167 *
2168 * - -ENOSPC, as a refinement of the more generic -ENOMEM to indicate
2169 * that the driver has run out of vram, iommu space or similar GPU
2170 * address space needed for framebuffer.
2171 *
2172 * - -EIO, if the hardware completely died.
2173 *
2174 * - -EINTR, -EAGAIN or -ERESTARTSYS, if the IOCTL should be restarted.
2175 * This can either be due to a pending signal, or because the driver
2176 * needs to completely bail out to recover from an exceptional
2177 * situation like a GPU hang. From a userspace point of view all errors are
2178 * treated equally.
2179 *
2180 * This list is exhaustive. Specifically this hook is not allowed to
2181 * return -EINVAL (any invalid requests should be caught in
2182 * @atomic_check) or -EDEADLK (this function must not acquire
2183 * additional modeset locks).
2184 */
cc4ceb48 2185 int (*atomic_commit)(struct drm_device *dev,
9953f417 2186 struct drm_atomic_state *state,
286dbb8d 2187 bool nonblock);
9953f417
DV
2188
2189 /**
2190 * @atomic_state_alloc:
2191 *
2192 * This optional hook can be used by drivers that want to subclass struct
2193 * &drm_atomic_state to be able to track their own driver-private global
2194 * state easily. If this hook is implemented, drivers must also
2195 * implement @atomic_state_clear and @atomic_state_free.
2196 *
2197 * RETURNS:
2198 *
2199 * A new &drm_atomic_state on success or NULL on failure.
2200 */
036ef573 2201 struct drm_atomic_state *(*atomic_state_alloc)(struct drm_device *dev);
9953f417
DV
2202
2203 /**
2204 * @atomic_state_clear:
2205 *
2206 * This hook must clear any driver private state duplicated into the
2207 * passed-in &drm_atomic_state. This hook is called when the caller
2208 * encountered a &drm_modeset_lock deadlock and needs to drop all
2209 * already acquired locks as part of the deadlock avoidance dance
2210 * implemented in drm_modeset_lock_backoff().
2211 *
2212 * Any duplicated state must be invalidated since a concurrent atomic
2213 * update might change it, and the drm atomic interfaces always apply
2214 * updates as relative changes to the current state.
2215 *
2216 * Drivers that implement this must call drm_atomic_state_default_clear()
2217 * to clear common state.
2218 */
036ef573 2219 void (*atomic_state_clear)(struct drm_atomic_state *state);
9953f417
DV
2220
2221 /**
2222 * @atomic_state_free:
2223 *
2224 * This hook needs driver private resources and the &drm_atomic_state
2225 * itself. Note that the core first calls drm_atomic_state_clear() to
2226 * avoid code duplicate between the clear and free hooks.
2227 *
2228 * Drivers that implement this must call drm_atomic_state_default_free()
2229 * to release common resources.
2230 */
036ef573 2231 void (*atomic_state_free)(struct drm_atomic_state *state);
f453ba04
DA
2232};
2233
f453ba04 2234/**
2c0c33d4 2235 * struct drm_mode_config - Mode configuration control structure
a62c93d5 2236 * @mutex: mutex protecting KMS related lists and structures
2c0c33d4
DV
2237 * @connection_mutex: ww mutex protecting connector state and routing
2238 * @acquire_ctx: global implicit acquire context used by atomic drivers for
c6b0ca3e 2239 * legacy IOCTLs
2c0c33d4 2240 * @fb_lock: mutex to protect fb state and lists
a62c93d5
JB
2241 * @num_fb: number of fbs available
2242 * @fb_list: list of framebuffers available
a62c93d5
JB
2243 * @num_encoder: number of encoders on this device
2244 * @encoder_list: list of encoder objects
2c0c33d4
DV
2245 * @num_overlay_plane: number of overlay planes on this device
2246 * @num_total_plane: number of universal (i.e. with primary/curso) planes on this device
2247 * @plane_list: list of plane objects
a62c93d5
JB
2248 * @num_crtc: number of CRTCs on this device
2249 * @crtc_list: list of CRTC objects
2c0c33d4 2250 * @property_list: list of property objects
a62c93d5
JB
2251 * @min_width: minimum pixel width on this device
2252 * @min_height: minimum pixel height on this device
2253 * @max_width: maximum pixel width on this device
2254 * @max_height: maximum pixel height on this device
2255 * @funcs: core driver provided mode setting functions
2256 * @fb_base: base address of the framebuffer
2c0c33d4
DV
2257 * @poll_enabled: track polling support for this device
2258 * @poll_running: track polling status for this device
ac3ba4a5 2259 * @delayed_event: track delayed poll uevent deliver for this device
a62c93d5 2260 * @output_poll_work: delayed work for polling in process context
2c0c33d4 2261 * @property_blob_list: list of all the blob property objects
8fb6e7a5 2262 * @blob_lock: mutex for blob property allocation and management
a62c93d5 2263 * @*_property: core property tracking
2c0c33d4
DV
2264 * @preferred_depth: preferred RBG pixel depth, used by fb helpers
2265 * @prefer_shadow: hint to userspace to prefer shadow-fb rendering
2c0c33d4
DV
2266 * @cursor_width: hint to userspace for max cursor width
2267 * @cursor_height: hint to userspace for max cursor height
9f2a7950 2268 * @helper_private: mid-layer private data
f453ba04 2269 *
a62c93d5
JB
2270 * Core mode resource tracking structure. All CRTC, encoders, and connectors
2271 * enumerated by the driver are added here, as are global properties. Some
2272 * global restrictions are also here, e.g. dimension restrictions.
f453ba04
DA
2273 */
2274struct drm_mode_config {
ad2563c2 2275 struct mutex mutex; /* protects configuration (mode lists etc.) */
51fd371b
RC
2276 struct drm_modeset_lock connection_mutex; /* protects connector->encoder and encoder->crtc links */
2277 struct drm_modeset_acquire_ctx *acquire_ctx; /* for legacy _lock_all() / _unlock_all() */
ac3ba4a5
DV
2278
2279 /**
2280 * @idr_mutex:
2281 *
2282 * Mutex for KMS ID allocation and management. Protects both @crtc_idr
2283 * and @tile_idr.
2284 */
2285 struct mutex idr_mutex;
2286
2287 /**
2288 * @crtc_idr:
2289 *
2290 * Main KMS ID tracking object. Use this idr for all IDs, fb, crtc,
2291 * connector, modes - just makes life easier to have only one.
2292 */
2293 struct idr crtc_idr;
2294
2295 /**
2296 * @tile_idr:
2297 *
2298 * Use this idr for allocating new IDs for tiled sinks like use in some
2299 * high-res DP MST screens.
2300 */
2301 struct idr tile_idr;
4b096ac1 2302
2c0c33d4 2303 struct mutex fb_lock; /* proctects global and per-file fb lists */
f453ba04
DA
2304 int num_fb;
2305 struct list_head fb_list;
4b096ac1 2306
96094081
DV
2307 /**
2308 * @num_connector: Number of connectors on this device.
2309 */
f453ba04 2310 int num_connector;
96094081
DV
2311 /**
2312 * @connector_ida: ID allocator for connector indices.
2313 */
5fff80bb 2314 struct ida connector_ida;
96094081
DV
2315 /**
2316 * @connector_list: List of connector objects.
2317 */
f453ba04
DA
2318 struct list_head connector_list;
2319 int num_encoder;
2320 struct list_head encoder_list;
e27dde3e
MR
2321
2322 /*
2323 * Track # of overlay planes separately from # of total planes. By
2324 * default we only advertise overlay planes to userspace; if userspace
2325 * sets the "universal plane" capability bit, we'll go ahead and
2326 * expose all planes.
2327 */
2328 int num_overlay_plane;
2329 int num_total_plane;
8cf5c917 2330 struct list_head plane_list;
f453ba04
DA
2331
2332 int num_crtc;
2333 struct list_head crtc_list;
2334
2335 struct list_head property_list;
2336
f453ba04
DA
2337 int min_width, min_height;
2338 int max_width, max_height;
e6ecefaa 2339 const struct drm_mode_config_funcs *funcs;
d883f7f1 2340 resource_size_t fb_base;
f453ba04 2341
eb1f8e4f
DA
2342 /* output poll support */
2343 bool poll_enabled;
905bc9ff 2344 bool poll_running;
162b6a57 2345 bool delayed_event;
991ea75c 2346 struct delayed_work output_poll_work;
eb1f8e4f 2347
8fb6e7a5
DS
2348 struct mutex blob_lock;
2349
f453ba04
DA
2350 /* pointers to standard properties */
2351 struct list_head property_blob_list;
9a6bc03c
DV
2352 /**
2353 * @edid_property: Default connector property to hold the EDID of the
2354 * currently connected sink, if any.
2355 */
f453ba04 2356 struct drm_property *edid_property;
9a6bc03c
DV
2357 /**
2358 * @dpms_property: Default connector property to control the
2359 * connector's DPMS state.
2360 */
f453ba04 2361 struct drm_property *dpms_property;
9a6bc03c
DV
2362 /**
2363 * @path_property: Default connector property to hold the DP MST path
2364 * for the port.
2365 */
43aba7eb 2366 struct drm_property *path_property;
9a6bc03c
DV
2367 /**
2368 * @tile_property: Default connector property to store the tile
2369 * position of a tiled screen, for sinks which need to be driven with
2370 * multiple CRTCs.
2371 */
6f134d7b 2372 struct drm_property *tile_property;
9a6bc03c
DV
2373 /**
2374 * @plane_type_property: Default plane property to differentiate
2375 * CURSOR, PRIMARY and OVERLAY legacy uses of planes.
2376 */
9922ab5a 2377 struct drm_property *plane_type_property;
9a6bc03c
DV
2378 /**
2379 * @rotation_property: Optional property for planes or CRTCs to specifiy
2380 * rotation.
2381 */
2a297cce 2382 struct drm_property *rotation_property;
9a6bc03c
DV
2383 /**
2384 * @prop_src_x: Default atomic plane property for the plane source
2385 * position in the connected &drm_framebuffer.
2386 */
6b4959f4 2387 struct drm_property *prop_src_x;
9a6bc03c
DV
2388 /**
2389 * @prop_src_y: Default atomic plane property for the plane source
2390 * position in the connected &drm_framebuffer.
2391 */
6b4959f4 2392 struct drm_property *prop_src_y;
9a6bc03c
DV
2393 /**
2394 * @prop_src_w: Default atomic plane property for the plane source
2395 * position in the connected &drm_framebuffer.
2396 */
6b4959f4 2397 struct drm_property *prop_src_w;
9a6bc03c
DV
2398 /**
2399 * @prop_src_h: Default atomic plane property for the plane source
2400 * position in the connected &drm_framebuffer.
2401 */
6b4959f4 2402 struct drm_property *prop_src_h;
9a6bc03c
DV
2403 /**
2404 * @prop_crtc_x: Default atomic plane property for the plane destination
2405 * position in the &drm_crtc is is being shown on.
2406 */
6b4959f4 2407 struct drm_property *prop_crtc_x;
9a6bc03c
DV
2408 /**
2409 * @prop_crtc_y: Default atomic plane property for the plane destination
2410 * position in the &drm_crtc is is being shown on.
2411 */
6b4959f4 2412 struct drm_property *prop_crtc_y;
9a6bc03c
DV
2413 /**
2414 * @prop_crtc_w: Default atomic plane property for the plane destination
2415 * position in the &drm_crtc is is being shown on.
2416 */
6b4959f4 2417 struct drm_property *prop_crtc_w;
9a6bc03c
DV
2418 /**
2419 * @prop_crtc_h: Default atomic plane property for the plane destination
2420 * position in the &drm_crtc is is being shown on.
2421 */
6b4959f4 2422 struct drm_property *prop_crtc_h;
9a6bc03c
DV
2423 /**
2424 * @prop_fb_id: Default atomic plane property to specify the
2425 * &drm_framebuffer.
2426 */
6b4959f4 2427 struct drm_property *prop_fb_id;
9a6bc03c
DV
2428 /**
2429 * @prop_crtc_id: Default atomic plane property to specify the
2430 * &drm_crtc.
2431 */
6b4959f4 2432 struct drm_property *prop_crtc_id;
9a6bc03c
DV
2433 /**
2434 * @prop_active: Default atomic CRTC property to control the active
2435 * state, which is the simplified implementation for DPMS in atomic
2436 * drivers.
2437 */
eab3bbef 2438 struct drm_property *prop_active;
9a6bc03c
DV
2439 /**
2440 * @prop_mode_id: Default atomic CRTC property to set the mode for a
2441 * CRTC. A 0 mode implies that the CRTC is entirely disabled - all
2442 * connectors must be of and active must be set to disabled, too.
2443 */
955f3c33 2444 struct drm_property *prop_mode_id;
f453ba04 2445
9a6bc03c
DV
2446 /**
2447 * @dvi_i_subconnector_property: Optional DVI-I property to
2448 * differentiate between analog or digital mode.
2449 */
f453ba04 2450 struct drm_property *dvi_i_subconnector_property;
9a6bc03c
DV
2451 /**
2452 * @dvi_i_select_subconnector_property: Optional DVI-I property to
2453 * select between analog or digital mode.
2454 */
f453ba04
DA
2455 struct drm_property *dvi_i_select_subconnector_property;
2456
9a6bc03c
DV
2457 /**
2458 * @tv_subconnector_property: Optional TV property to differentiate
2459 * between different TV connector types.
2460 */
f453ba04 2461 struct drm_property *tv_subconnector_property;
9a6bc03c
DV
2462 /**
2463 * @tv_select_subconnector_property: Optional TV property to select
2464 * between different TV connector types.
2465 */
f453ba04 2466 struct drm_property *tv_select_subconnector_property;
9a6bc03c
DV
2467 /**
2468 * @tv_mode_property: Optional TV property to select
2469 * the output TV mode.
2470 */
f453ba04 2471 struct drm_property *tv_mode_property;
9a6bc03c
DV
2472 /**
2473 * @tv_left_margin_property: Optional TV property to set the left
2474 * margin.
2475 */
f453ba04 2476 struct drm_property *tv_left_margin_property;
9a6bc03c
DV
2477 /**
2478 * @tv_right_margin_property: Optional TV property to set the right
2479 * margin.
2480 */
f453ba04 2481 struct drm_property *tv_right_margin_property;
9a6bc03c
DV
2482 /**
2483 * @tv_top_margin_property: Optional TV property to set the right
2484 * margin.
2485 */
f453ba04 2486 struct drm_property *tv_top_margin_property;
9a6bc03c
DV
2487 /**
2488 * @tv_bottom_margin_property: Optional TV property to set the right
2489 * margin.
2490 */
f453ba04 2491 struct drm_property *tv_bottom_margin_property;
9a6bc03c
DV
2492 /**
2493 * @tv_brightness_property: Optional TV property to set the
2494 * brightness.
2495 */
b6b7902e 2496 struct drm_property *tv_brightness_property;
9a6bc03c
DV
2497 /**
2498 * @tv_contrast_property: Optional TV property to set the
2499 * contrast.
2500 */
b6b7902e 2501 struct drm_property *tv_contrast_property;
9a6bc03c
DV
2502 /**
2503 * @tv_flicker_reduction_property: Optional TV property to control the
2504 * flicker reduction mode.
2505 */
b6b7902e 2506 struct drm_property *tv_flicker_reduction_property;
9a6bc03c
DV
2507 /**
2508 * @tv_overscan_property: Optional TV property to control the overscan
2509 * setting.
2510 */
a75f0236 2511 struct drm_property *tv_overscan_property;
9a6bc03c
DV
2512 /**
2513 * @tv_saturation_property: Optional TV property to set the
2514 * saturation.
2515 */
a75f0236 2516 struct drm_property *tv_saturation_property;
9a6bc03c
DV
2517 /**
2518 * @tv_hue_property: Optional TV property to set the hue.
2519 */
a75f0236 2520 struct drm_property *tv_hue_property;
f453ba04 2521
9a6bc03c
DV
2522 /**
2523 * @scaling_mode_property: Optional connector property to control the
2524 * upscaling, mostly used for built-in panels.
2525 */
f453ba04 2526 struct drm_property *scaling_mode_property;
9a6bc03c
DV
2527 /**
2528 * @aspect_ratio_property: Optional connector property to control the
2529 * HDMI infoframe aspect ratio setting.
2530 */
ff587e45 2531 struct drm_property *aspect_ratio_property;
9a6bc03c
DV
2532 /**
2533 * @degamma_lut_property: Optional CRTC property to set the LUT used to
2534 * convert the framebuffer's colors to linear gamma.
2535 */
5488dc16 2536 struct drm_property *degamma_lut_property;
9a6bc03c
DV
2537 /**
2538 * @degamma_lut_size_property: Optional CRTC property for the size of
2539 * the degamma LUT as supported by the driver (read-only).
2540 */
5488dc16 2541 struct drm_property *degamma_lut_size_property;
9a6bc03c
DV
2542 /**
2543 * @ctm_property: Optional CRTC property to set the
2544 * matrix used to convert colors after the lookup in the
2545 * degamma LUT.
2546 */
5488dc16 2547 struct drm_property *ctm_property;
9a6bc03c
DV
2548 /**
2549 * @gamma_lut_property: Optional CRTC property to set the LUT used to
2550 * convert the colors, after the CTM matrix, to the gamma space of the
2551 * connected screen.
2552 */
5488dc16 2553 struct drm_property *gamma_lut_property;
9a6bc03c
DV
2554 /**
2555 * @gamma_lut_size_property: Optional CRTC property for the size of the
2556 * gamma LUT as supported by the driver (read-only).
2557 */
5488dc16
LL
2558 struct drm_property *gamma_lut_size_property;
2559
9a6bc03c
DV
2560 /**
2561 * @suggested_x_property: Optional connector property with a hint for
2562 * the position of the output on the host's screen.
2563 */
5bb2bbf5 2564 struct drm_property *suggested_x_property;
9a6bc03c
DV
2565 /**
2566 * @suggested_y_property: Optional connector property with a hint for
2567 * the position of the output on the host's screen.
2568 */
5bb2bbf5
DA
2569 struct drm_property *suggested_y_property;
2570
019d96cb
DA
2571 /* dumb ioctl parameters */
2572 uint32_t preferred_depth, prefer_shadow;
62f2104f 2573
9a6bc03c
DV
2574 /**
2575 * @async_page_flip: Does this device support async flips on the primary
2576 * plane?
2577 */
62f2104f 2578 bool async_page_flip;
8716ed4e 2579
ac3ba4a5
DV
2580 /**
2581 * @allow_fb_modifiers:
2582 *
2583 * Whether the driver supports fb modifiers in the ADDFB2.1 ioctl call.
2584 */
e3eb3250
RC
2585 bool allow_fb_modifiers;
2586
8716ed4e
AD
2587 /* cursor size */
2588 uint32_t cursor_width, cursor_height;
9f2a7950
DV
2589
2590 struct drm_mode_config_helper_funcs *helper_private;
f453ba04
DA
2591};
2592
dd275956
RC
2593/**
2594 * drm_for_each_plane_mask - iterate over planes specified by bitmask
2595 * @plane: the loop cursor
2596 * @dev: the DRM device
2597 * @plane_mask: bitmask of plane indices
2598 *
2599 * Iterate over all planes specified by bitmask.
2600 */
2601#define drm_for_each_plane_mask(plane, dev, plane_mask) \
2602 list_for_each_entry((plane), &(dev)->mode_config.plane_list, head) \
373701b1 2603 for_each_if ((plane_mask) & (1 << drm_plane_index(plane)))
dd275956 2604
ead8b665
ML
2605/**
2606 * drm_for_each_encoder_mask - iterate over encoders specified by bitmask
2607 * @encoder: the loop cursor
2608 * @dev: the DRM device
2609 * @encoder_mask: bitmask of encoder indices
2610 *
2611 * Iterate over all encoders specified by bitmask.
2612 */
2613#define drm_for_each_encoder_mask(encoder, dev, encoder_mask) \
2614 list_for_each_entry((encoder), &(dev)->mode_config.encoder_list, head) \
2615 for_each_if ((encoder_mask) & (1 << drm_encoder_index(encoder)))
dd275956 2616
f453ba04
DA
2617#define obj_to_crtc(x) container_of(x, struct drm_crtc, base)
2618#define obj_to_connector(x) container_of(x, struct drm_connector, base)
2619#define obj_to_encoder(x) container_of(x, struct drm_encoder, base)
2620#define obj_to_mode(x) container_of(x, struct drm_display_mode, base)
2621#define obj_to_fb(x) container_of(x, struct drm_framebuffer, base)
2622#define obj_to_property(x) container_of(x, struct drm_property, base)
2623#define obj_to_blob(x) container_of(x, struct drm_property_blob, base)
8cf5c917 2624#define obj_to_plane(x) container_of(x, struct drm_plane, base)
f453ba04 2625
4a67d391
SH
2626struct drm_prop_enum_list {
2627 int type;
2628 char *name;
2629};
f453ba04 2630
f9882876
VS
2631extern __printf(6, 7)
2632int drm_crtc_init_with_planes(struct drm_device *dev,
2633 struct drm_crtc *crtc,
2634 struct drm_plane *primary,
2635 struct drm_plane *cursor,
2636 const struct drm_crtc_funcs *funcs,
2637 const char *name, ...);
f453ba04 2638extern void drm_crtc_cleanup(struct drm_crtc *crtc);
490d3d1b
CW
2639
2640/**
2641 * drm_crtc_index - find the index of a registered CRTC
2642 * @crtc: CRTC to find index for
2643 *
2644 * Given a registered CRTC, return the index of that CRTC within a DRM
2645 * device's list of CRTCs.
2646 */
2647static inline unsigned int drm_crtc_index(struct drm_crtc *crtc)
2648{
2649 return crtc->index;
2650}
db5f7a6e
RK
2651
2652/**
2653 * drm_crtc_mask - find the mask of a registered CRTC
2654 * @crtc: CRTC to find mask for
2655 *
2656 * Given a registered CRTC, return the mask bit of that CRTC for an
2657 * encoder's possible_crtcs field.
2658 */
2659static inline uint32_t drm_crtc_mask(struct drm_crtc *crtc)
2660{
2661 return 1 << drm_crtc_index(crtc);
2662}
f453ba04 2663
81065548
DV
2664int drm_connector_init(struct drm_device *dev,
2665 struct drm_connector *connector,
2666 const struct drm_connector_funcs *funcs,
2667 int connector_type);
34ea3d38
TW
2668int drm_connector_register(struct drm_connector *connector);
2669void drm_connector_unregister(struct drm_connector *connector);
f453ba04
DA
2670
2671extern void drm_connector_cleanup(struct drm_connector *connector);
5fff80bb
ML
2672static inline unsigned drm_connector_index(struct drm_connector *connector)
2673{
69425599 2674 return connector->index;
5fff80bb
ML
2675}
2676
13a3d91f
VS
2677extern __printf(5, 6)
2678int drm_encoder_init(struct drm_device *dev,
2679 struct drm_encoder *encoder,
2680 const struct drm_encoder_funcs *funcs,
2681 int encoder_type, const char *name, ...);
490d3d1b
CW
2682
2683/**
2684 * drm_encoder_index - find the index of a registered encoder
2685 * @encoder: encoder to find index for
2686 *
2687 * Given a registered encoder, return the index of that encoder within a DRM
2688 * device's list of encoders.
2689 */
2690static inline unsigned int drm_encoder_index(struct drm_encoder *encoder)
2691{
2692 return encoder->index;
2693}
f453ba04 2694
3d887368
TR
2695/**
2696 * drm_encoder_crtc_ok - can a given crtc drive a given encoder?
2697 * @encoder: encoder to test
2698 * @crtc: crtc to test
2699 *
2700 * Return false if @encoder can't be driven by @crtc, true otherwise.
2701 */
2702static inline bool drm_encoder_crtc_ok(struct drm_encoder *encoder,
2703 struct drm_crtc *crtc)
2704{
2705 return !!(encoder->possible_crtcs & drm_crtc_mask(crtc));
2706}
2707
b0b3b795
VS
2708extern __printf(8, 9)
2709int drm_universal_plane_init(struct drm_device *dev,
2710 struct drm_plane *plane,
2711 unsigned long possible_crtcs,
2712 const struct drm_plane_funcs *funcs,
2713 const uint32_t *formats,
2714 unsigned int format_count,
2715 enum drm_plane_type type,
2716 const char *name, ...);
8cf5c917
JB
2717extern int drm_plane_init(struct drm_device *dev,
2718 struct drm_plane *plane,
2719 unsigned long possible_crtcs,
2720 const struct drm_plane_funcs *funcs,
45e3743a 2721 const uint32_t *formats, unsigned int format_count,
dc415ff9 2722 bool is_primary);
8cf5c917 2723extern void drm_plane_cleanup(struct drm_plane *plane);
490d3d1b
CW
2724
2725/**
2726 * drm_plane_index - find the index of a registered plane
2727 * @plane: plane to find index for
2728 *
2729 * Given a registered plane, return the index of that plane within a DRM
2730 * device's list of planes.
2731 */
2732static inline unsigned int drm_plane_index(struct drm_plane *plane)
2733{
2734 return plane->index;
2735}
f81338a5 2736extern struct drm_plane * drm_plane_from_index(struct drm_device *dev, int idx);
9125e618 2737extern void drm_plane_force_disable(struct drm_plane *plane);
ecb7e16b
GP
2738extern void drm_crtc_get_hv_timing(const struct drm_display_mode *mode,
2739 int *hdisplay, int *vdisplay);
6a0d9528
LW
2740extern int drm_crtc_force_disable(struct drm_crtc *crtc);
2741extern int drm_crtc_force_disable_all(struct drm_device *dev);
8cf5c917 2742
f453ba04
DA
2743extern void drm_encoder_cleanup(struct drm_encoder *encoder);
2744
d20d3174 2745extern const char *drm_get_connector_status_name(enum drm_connector_status status);
ac1bb36c 2746extern const char *drm_get_subpixel_order_name(enum subpixel_order order);
d20d3174
VS
2747extern const char *drm_get_dpms_name(int val);
2748extern const char *drm_get_dvi_i_subconnector_name(int val);
2749extern const char *drm_get_dvi_i_select_name(int val);
2750extern const char *drm_get_tv_subconnector_name(int val);
2751extern const char *drm_get_tv_select_name(int val);
f453ba04 2752extern void drm_mode_config_init(struct drm_device *dev);
eb033556 2753extern void drm_mode_config_reset(struct drm_device *dev);
f453ba04 2754extern void drm_mode_config_cleanup(struct drm_device *dev);
55310008 2755
43aba7eb 2756extern int drm_mode_connector_set_path_property(struct drm_connector *connector,
12e6cecd 2757 const char *path);
6f134d7b 2758int drm_mode_connector_set_tile_property(struct drm_connector *connector);
f453ba04 2759extern int drm_mode_connector_update_edid_property(struct drm_connector *connector,
12e6cecd 2760 const struct edid *edid);
5ea22f24 2761
b5571e9d
BB
2762extern int drm_display_info_set_bus_formats(struct drm_display_info *info,
2763 const u32 *formats,
2764 unsigned int num_formats);
2765
5ea22f24
RC
2766static inline bool drm_property_type_is(struct drm_property *property,
2767 uint32_t type)
2768{
2769 /* instanceof for props.. handles extended type vs original types: */
2770 if (property->flags & DRM_MODE_PROP_EXTENDED_TYPE)
2771 return (property->flags & DRM_MODE_PROP_EXTENDED_TYPE) == type;
2772 return property->flags & type;
2773}
2774
c543188a
PZ
2775extern int drm_object_property_set_value(struct drm_mode_object *obj,
2776 struct drm_property *property,
2777 uint64_t val);
2778extern int drm_object_property_get_value(struct drm_mode_object *obj,
2779 struct drm_property *property,
2780 uint64_t *value);
f453ba04 2781
c543188a
PZ
2782extern void drm_object_attach_property(struct drm_mode_object *obj,
2783 struct drm_property *property,
2784 uint64_t init_val);
f453ba04
DA
2785extern struct drm_property *drm_property_create(struct drm_device *dev, int flags,
2786 const char *name, int num_values);
4a67d391
SH
2787extern struct drm_property *drm_property_create_enum(struct drm_device *dev, int flags,
2788 const char *name,
49e27545
RC
2789 const struct drm_prop_enum_list *props,
2790 int num_values);
2791struct drm_property *drm_property_create_bitmask(struct drm_device *dev,
2792 int flags, const char *name,
4a67d391 2793 const struct drm_prop_enum_list *props,
7689ffb3
VS
2794 int num_props,
2795 uint64_t supported_bits);
d9bc3c02
SH
2796struct drm_property *drm_property_create_range(struct drm_device *dev, int flags,
2797 const char *name,
2798 uint64_t min, uint64_t max);
ebc44cf3
RC
2799struct drm_property *drm_property_create_signed_range(struct drm_device *dev,
2800 int flags, const char *name,
2801 int64_t min, int64_t max);
98f75de4
RC
2802struct drm_property *drm_property_create_object(struct drm_device *dev,
2803 int flags, const char *name, uint32_t type);
960cd9d4
DV
2804struct drm_property *drm_property_create_bool(struct drm_device *dev, int flags,
2805 const char *name);
6bcacf51
DS
2806struct drm_property_blob *drm_property_create_blob(struct drm_device *dev,
2807 size_t length,
2808 const void *data);
2809struct drm_property_blob *drm_property_lookup_blob(struct drm_device *dev,
2810 uint32_t id);
adebd6fe
DV
2811int drm_property_replace_global_blob(struct drm_device *dev,
2812 struct drm_property_blob **replace,
2813 size_t length,
2814 const void *data,
2815 struct drm_mode_object *obj_holds_id,
2816 struct drm_property *prop_holds_id);
6bcacf51
DS
2817struct drm_property_blob *drm_property_reference_blob(struct drm_property_blob *blob);
2818void drm_property_unreference_blob(struct drm_property_blob *blob);
f453ba04
DA
2819extern void drm_property_destroy(struct drm_device *dev, struct drm_property *property);
2820extern int drm_property_add_enum(struct drm_property *property, int index,
2821 uint64_t value, const char *name);
2822extern int drm_mode_create_dvi_i_properties(struct drm_device *dev);
2f763312
TR
2823extern int drm_mode_create_tv_properties(struct drm_device *dev,
2824 unsigned int num_modes,
b7c914b3 2825 const char * const modes[]);
f453ba04 2826extern int drm_mode_create_scaling_mode_property(struct drm_device *dev);
ff587e45 2827extern int drm_mode_create_aspect_ratio_property(struct drm_device *dev);
5bb2bbf5 2828extern int drm_mode_create_suggested_offset_properties(struct drm_device *dev);
f453ba04
DA
2829
2830extern int drm_mode_connector_attach_encoder(struct drm_connector *connector,
2831 struct drm_encoder *encoder);
4cae5b84 2832extern int drm_mode_crtc_set_gamma_size(struct drm_crtc *crtc,
f453ba04 2833 int gamma_size);
98f75de4 2834
2d13b679 2835extern int drm_mode_set_config_internal(struct drm_mode_set *set);
81065548 2836
308e5bcb 2837extern uint32_t drm_mode_legacy_fb_format(uint32_t bpp, uint32_t depth);
138f9ebb
DA
2838
2839extern struct drm_tile_group *drm_mode_create_tile_group(struct drm_device *dev,
2840 char topology[8]);
2841extern struct drm_tile_group *drm_mode_get_tile_group(struct drm_device *dev,
2842 char topology[8]);
2843extern void drm_mode_put_tile_group(struct drm_device *dev,
2844 struct drm_tile_group *tg);
ff72145b 2845
3a5f87c2
TW
2846extern int drm_mode_plane_set_obj_prop(struct drm_plane *plane,
2847 struct drm_property *property,
2848 uint64_t value);
248dbc23 2849
c1df5f3c
VS
2850extern struct drm_property *drm_mode_create_rotation_property(struct drm_device *dev,
2851 unsigned int supported_rotations);
3c9855f6
VS
2852extern unsigned int drm_rotation_simplify(unsigned int rotation,
2853 unsigned int supported_rotations);
f8ed34ac
JS
2854extern void drm_crtc_enable_color_mgmt(struct drm_crtc *crtc,
2855 uint degamma_lut_size,
2856 bool has_ctm,
2857 uint gamma_lut_size);
44d1240d
MS
2858
2859int drm_plane_create_zpos_property(struct drm_plane *plane,
2860 unsigned int zpos,
2861 unsigned int min, unsigned int max);
2862
2863int drm_plane_create_zpos_immutable_property(struct drm_plane *plane,
2864 unsigned int zpos);
2865
96f60e37 2866/* Helpers */
a2b34e22
RC
2867static inline struct drm_plane *drm_plane_find(struct drm_device *dev,
2868 uint32_t id)
2869{
2870 struct drm_mode_object *mo;
2871 mo = drm_mode_object_find(dev, id, DRM_MODE_OBJECT_PLANE);
2872 return mo ? obj_to_plane(mo) : NULL;
2873}
2874
96f60e37
RK
2875static inline struct drm_crtc *drm_crtc_find(struct drm_device *dev,
2876 uint32_t id)
2877{
2878 struct drm_mode_object *mo;
2879 mo = drm_mode_object_find(dev, id, DRM_MODE_OBJECT_CRTC);
2880 return mo ? obj_to_crtc(mo) : NULL;
2881}
2882
2883static inline struct drm_encoder *drm_encoder_find(struct drm_device *dev,
2884 uint32_t id)
2885{
2886 struct drm_mode_object *mo;
2887 mo = drm_mode_object_find(dev, id, DRM_MODE_OBJECT_ENCODER);
2888 return mo ? obj_to_encoder(mo) : NULL;
2889}
2890
b164d31f
DA
2891/**
2892 * drm_connector_lookup - lookup connector object
2893 * @dev: DRM device
2894 * @id: connector object id
2895 *
2896 * This function looks up the connector object specified by id
2897 * add takes a reference to it.
2898 */
2899static inline struct drm_connector *drm_connector_lookup(struct drm_device *dev,
a2b34e22
RC
2900 uint32_t id)
2901{
2902 struct drm_mode_object *mo;
2903 mo = drm_mode_object_find(dev, id, DRM_MODE_OBJECT_CONNECTOR);
2904 return mo ? obj_to_connector(mo) : NULL;
2905}
2906
2907static inline struct drm_property *drm_property_find(struct drm_device *dev,
2908 uint32_t id)
2909{
2910 struct drm_mode_object *mo;
2911 mo = drm_mode_object_find(dev, id, DRM_MODE_OBJECT_PROPERTY);
2912 return mo ? obj_to_property(mo) : NULL;
2913}
2914
5488dc16
LL
2915/*
2916 * Extract a degamma/gamma LUT value provided by user and round it to the
2917 * precision supported by the hardware.
2918 */
2919static inline uint32_t drm_color_lut_extract(uint32_t user_input,
2920 uint32_t bit_precision)
2921{
644a8050 2922 uint32_t val = user_input;
5488dc16
LL
2923 uint32_t max = 0xffff >> (16 - bit_precision);
2924
644a8050
LL
2925 /* Round only if we're not using full precision. */
2926 if (bit_precision < 16) {
2927 val += 1UL << (16 - bit_precision - 1);
2928 val >>= 16 - bit_precision;
2929 }
5488dc16
LL
2930
2931 return clamp_val(val, 0, max);
2932}
2933
b164d31f
DA
2934/**
2935 * drm_connector_reference - incr the connector refcnt
2936 * @connector: connector
2937 *
2938 * This function increments the connector's refcount.
2939 */
2940static inline void drm_connector_reference(struct drm_connector *connector)
2941{
2942 drm_mode_object_reference(&connector->base);
2943}
2944
2945/**
2946 * drm_connector_unreference - unref a connector
2947 * @connector: connector to unref
2948 *
2949 * This function decrements the connector's refcount and frees it if it drops to zero.
2950 */
2951static inline void drm_connector_unreference(struct drm_connector *connector)
2952{
2953 drm_mode_object_unreference(&connector->base);
2954}
2955
e27dde3e 2956/* Plane list iterator for legacy (overlay only) planes. */
4ea50e99
DV
2957#define drm_for_each_legacy_plane(plane, dev) \
2958 list_for_each_entry(plane, &(dev)->mode_config.plane_list, head) \
373701b1 2959 for_each_if (plane->type == DRM_PLANE_TYPE_OVERLAY)
e27dde3e 2960
6295d607
DV
2961#define drm_for_each_plane(plane, dev) \
2962 list_for_each_entry(plane, &(dev)->mode_config.plane_list, head)
2963
2964#define drm_for_each_crtc(crtc, dev) \
2965 list_for_each_entry(crtc, &(dev)->mode_config.crtc_list, head)
2966
7a3f3d66
DV
2967static inline void
2968assert_drm_connector_list_read_locked(struct drm_mode_config *mode_config)
2969{
cff20ba2
DV
2970 /*
2971 * The connector hotadd/remove code currently grabs both locks when
2972 * updating lists. Hence readers need only hold either of them to be
2973 * safe and the check amounts to
2974 *
2975 * WARN_ON(not_holding(A) && not_holding(B)).
2976 */
2977 WARN_ON(!mutex_is_locked(&mode_config->mutex) &&
2978 !drm_modeset_is_locked(&mode_config->connection_mutex));
7a3f3d66
DV
2979}
2980
6295d607 2981#define drm_for_each_connector(connector, dev) \
7a3f3d66
DV
2982 for (assert_drm_connector_list_read_locked(&(dev)->mode_config), \
2983 connector = list_first_entry(&(dev)->mode_config.connector_list, \
2984 struct drm_connector, head); \
2985 &connector->head != (&(dev)->mode_config.connector_list); \
2986 connector = list_next_entry(connector, head))
6295d607
DV
2987
2988#define drm_for_each_encoder(encoder, dev) \
2989 list_for_each_entry(encoder, &(dev)->mode_config.encoder_list, head)
2990
2991#define drm_for_each_fb(fb, dev) \
4676ba0b
DV
2992 for (WARN_ON(!mutex_is_locked(&(dev)->mode_config.fb_lock)), \
2993 fb = list_first_entry(&(dev)->mode_config.fb_list, \
2994 struct drm_framebuffer, head); \
2995 &fb->head != (&(dev)->mode_config.fb_list); \
2996 fb = list_next_entry(fb, head))
6295d607 2997
81065548
DV
2998/* drm_edid.c */
2999bool drm_probe_ddc(struct i2c_adapter *adapter);
3000struct edid *drm_get_edid(struct drm_connector *connector,
3001 struct i2c_adapter *adapter);
3002struct edid *drm_get_edid_switcheroo(struct drm_connector *connector,
3003 struct i2c_adapter *adapter);
3004struct edid *drm_edid_duplicate(const struct edid *edid);
3005int drm_add_edid_modes(struct drm_connector *connector, struct edid *edid);
3006
3007u8 drm_match_cea_mode(const struct drm_display_mode *to_match);
3008enum hdmi_picture_aspect drm_get_cea_aspect_ratio(const u8 video_code);
3009bool drm_detect_hdmi_monitor(struct edid *edid);
3010bool drm_detect_monitor_audio(struct edid *edid);
3011bool drm_rgb_quant_range_selectable(struct edid *edid);
3012int drm_add_modes_noedid(struct drm_connector *connector,
3013 int hdisplay, int vdisplay);
3014void drm_set_preferred_mode(struct drm_connector *connector,
3015 int hpref, int vpref);
3016
3017int drm_edid_header_is_valid(const u8 *raw_edid);
3018bool drm_edid_block_valid(u8 *raw_edid, int block, bool print_bad_edid,
3019 bool *edid_corrupt);
3020bool drm_edid_is_valid(struct edid *edid);
3021void drm_edid_get_monitor_name(struct edid *edid, char *name,
3022 int buflen);
3023struct drm_display_mode *drm_mode_find_dmt(struct drm_device *dev,
3024 int hsize, int vsize, int fresh,
3025 bool rb);
3026
3027/* drm_bridge.c */
3028extern int drm_bridge_add(struct drm_bridge *bridge);
3029extern void drm_bridge_remove(struct drm_bridge *bridge);
3030extern struct drm_bridge *of_drm_find_bridge(struct device_node *np);
3031extern int drm_bridge_attach(struct drm_device *dev, struct drm_bridge *bridge);
3032
3033bool drm_bridge_mode_fixup(struct drm_bridge *bridge,
3034 const struct drm_display_mode *mode,
3035 struct drm_display_mode *adjusted_mode);
3036void drm_bridge_disable(struct drm_bridge *bridge);
3037void drm_bridge_post_disable(struct drm_bridge *bridge);
3038void drm_bridge_mode_set(struct drm_bridge *bridge,
3039 struct drm_display_mode *mode,
3040 struct drm_display_mode *adjusted_mode);
3041void drm_bridge_pre_enable(struct drm_bridge *bridge);
3042void drm_bridge_enable(struct drm_bridge *bridge);
3043
f453ba04 3044#endif /* __DRM_CRTC_H__ */