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