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