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