]> git.proxmox.com Git - mirror_ubuntu-jammy-kernel.git/blame - include/drm/drm_crtc.h
drm: Add drm_atomic_set_mode_for_crtc
[mirror_ubuntu-jammy-kernel.git] / include / drm / drm_crtc.h
CommitLineData
f453ba04
DA
1/*
2 * Copyright © 2006 Keith Packard
3 * Copyright © 2007-2008 Dave Airlie
4 * Copyright © 2007-2008 Intel Corporation
5 * Jesse Barnes <jesse.barnes@intel.com>
6 *
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the "Software"),
9 * to deal in the Software without restriction, including without limitation
10 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
11 * and/or sell copies of the Software, and to permit persons to whom the
12 * Software is furnished to do so, subject to the following conditions:
13 *
14 * The above copyright notice and this permission notice shall be included in
15 * all copies or substantial portions of the Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
21 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
22 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
23 * OTHER DEALINGS IN THE SOFTWARE.
24 */
25#ifndef __DRM_CRTC_H__
26#define __DRM_CRTC_H__
27
28#include <linux/i2c.h>
29#include <linux/spinlock.h>
30#include <linux/types.h>
31#include <linux/idr.h>
f453ba04 32#include <linux/fb.h>
985e5dc2 33#include <linux/hdmi.h>
b5571e9d 34#include <linux/media-bus-format.h>
d7d2c48e
DH
35#include <uapi/drm/drm_mode.h>
36#include <uapi/drm/drm_fourcc.h>
51fd371b 37#include <drm/drm_modeset_lock.h>
308e5bcb 38
f453ba04
DA
39struct drm_device;
40struct drm_mode_set;
41struct drm_framebuffer;
7e3bdf4a 42struct drm_object_properties;
595887eb
TR
43struct drm_file;
44struct drm_clip_rect;
7e435aad 45struct device_node;
e2330f07 46struct fence;
f453ba04
DA
47
48#define DRM_MODE_OBJECT_CRTC 0xcccccccc
49#define DRM_MODE_OBJECT_CONNECTOR 0xc0c0c0c0
50#define DRM_MODE_OBJECT_ENCODER 0xe0e0e0e0
51#define DRM_MODE_OBJECT_MODE 0xdededede
52#define DRM_MODE_OBJECT_PROPERTY 0xb0b0b0b0
53#define DRM_MODE_OBJECT_FB 0xfbfbfbfb
54#define DRM_MODE_OBJECT_BLOB 0xbbbbbbbb
8cf5c917 55#define DRM_MODE_OBJECT_PLANE 0xeeeeeeee
98f75de4 56#define DRM_MODE_OBJECT_ANY 0
f453ba04
DA
57
58struct drm_mode_object {
59 uint32_t id;
60 uint32_t type;
7e3bdf4a
PZ
61 struct drm_object_properties *properties;
62};
63
fe456168 64#define DRM_OBJECT_MAX_PROPERTY 24
7e3bdf4a 65struct drm_object_properties {
88a48e29 66 int count, atomic_count;
b17cd757
RC
67 /* NOTE: if we ever start dynamically destroying properties (ie.
68 * not at drm_mode_config_cleanup() time), then we'd have to do
69 * a better job of detaching property from mode objects to avoid
70 * dangling property pointers:
71 */
72 struct drm_property *properties[DRM_OBJECT_MAX_PROPERTY];
22b8b13b
RC
73 /* do not read/write values directly, but use drm_object_property_get_value()
74 * and drm_object_property_set_value():
75 */
7e3bdf4a 76 uint64_t values[DRM_OBJECT_MAX_PROPERTY];
f453ba04
DA
77};
78
ebc44cf3
RC
79static inline int64_t U642I64(uint64_t val)
80{
81 return (int64_t)*((int64_t *)&val);
82}
83static inline uint64_t I642U64(int64_t val)
84{
85 return (uint64_t)*((uint64_t *)&val);
86}
87
06596961
VS
88/* rotation property bits */
89#define DRM_ROTATE_0 0
90#define DRM_ROTATE_90 1
91#define DRM_ROTATE_180 2
92#define DRM_ROTATE_270 3
93#define DRM_REFLECT_X 4
94#define DRM_REFLECT_Y 5
95
55310008
DV
96enum drm_connector_force {
97 DRM_FORCE_UNSPECIFIED,
98 DRM_FORCE_OFF,
99 DRM_FORCE_ON, /* force on analog part normally */
100 DRM_FORCE_ON_DIGITAL, /* for DVI-I use digital connector */
f453ba04
DA
101};
102
55310008 103#include <drm/drm_modes.h>
4aa17cf0 104
f453ba04
DA
105enum drm_connector_status {
106 connector_status_connected = 1,
107 connector_status_disconnected = 2,
108 connector_status_unknown = 3,
109};
110
111enum subpixel_order {
112 SubPixelUnknown = 0,
113 SubPixelHorizontalRGB,
114 SubPixelHorizontalBGR,
115 SubPixelVerticalRGB,
116 SubPixelVerticalBGR,
117 SubPixelNone,
118};
119
da05a5a7
JB
120#define DRM_COLOR_FORMAT_RGB444 (1<<0)
121#define DRM_COLOR_FORMAT_YCRCB444 (1<<1)
122#define DRM_COLOR_FORMAT_YCRCB422 (1<<2)
f453ba04
DA
123/*
124 * Describes a given display (e.g. CRT or flat panel) and its limitations.
125 */
126struct drm_display_info {
127 char name[DRM_DISPLAY_INFO_LEN];
fb439640 128
f453ba04
DA
129 /* Physical size */
130 unsigned int width_mm;
131 unsigned int height_mm;
132
f453ba04
DA
133 /* Clock limits FIXME: storage format */
134 unsigned int min_vfreq, max_vfreq;
135 unsigned int min_hfreq, max_hfreq;
136 unsigned int pixel_clock;
3b11228b 137 unsigned int bpc;
f453ba04 138
f453ba04 139 enum subpixel_order subpixel_order;
da05a5a7 140 u32 color_formats;
f453ba04 141
b5571e9d
BB
142 const u32 *bus_formats;
143 unsigned int num_bus_formats;
144
5d02626d
MK
145 /* Mask of supported hdmi deep color modes */
146 u8 edid_hdmi_dc_modes;
147
ebec9a7b 148 u8 cea_rev;
f453ba04
DA
149};
150
138f9ebb
DA
151/* data corresponds to displayid vend/prod/serial */
152struct drm_tile_group {
153 struct kref refcount;
154 struct drm_device *dev;
155 int id;
156 u8 group_data[8];
157};
158
f453ba04 159struct drm_framebuffer_funcs {
f7eff60e 160 /* note: use drm_framebuffer_remove() */
f453ba04
DA
161 void (*destroy)(struct drm_framebuffer *framebuffer);
162 int (*create_handle)(struct drm_framebuffer *fb,
163 struct drm_file *file_priv,
164 unsigned int *handle);
3bf0401c
DV
165 /*
166 * Optional callback for the dirty fb ioctl.
884840aa
JB
167 *
168 * Userspace can notify the driver via this callback
169 * that a area of the framebuffer has changed and should
170 * be flushed to the display hardware.
171 *
172 * See documentation in drm_mode.h for the struct
173 * drm_mode_fb_dirty_cmd for more information as all
174 * the semantics and arguments have a one to one mapping
175 * on this function.
176 */
02b00162
TH
177 int (*dirty)(struct drm_framebuffer *framebuffer,
178 struct drm_file *file_priv, unsigned flags,
884840aa
JB
179 unsigned color, struct drm_clip_rect *clips,
180 unsigned num_clips);
f453ba04
DA
181};
182
183struct drm_framebuffer {
184 struct drm_device *dev;
f7eff60e
RC
185 /*
186 * Note that the fb is refcounted for the benefit of driver internals,
187 * for example some hw, disabling a CRTC/plane is asynchronous, and
188 * scanout does not actually complete until the next vblank. So some
189 * cleanup (like releasing the reference(s) on the backing GEM bo(s))
190 * should be deferred. In cases like this, the driver would like to
191 * hold a ref to the fb even though it has already been removed from
192 * userspace perspective.
193 */
194 struct kref refcount;
4b096ac1
DV
195 /*
196 * Place on the dev->mode_config.fb_list, access protected by
197 * dev->mode_config.fb_lock.
198 */
f453ba04
DA
199 struct list_head head;
200 struct drm_mode_object base;
201 const struct drm_framebuffer_funcs *funcs;
01f2c773
VS
202 unsigned int pitches[4];
203 unsigned int offsets[4];
e3eb3250 204 uint64_t modifier[4];
f453ba04
DA
205 unsigned int width;
206 unsigned int height;
207 /* depth can be 15 or 16 */
208 unsigned int depth;
209 int bits_per_pixel;
210 int flags;
308e5bcb 211 uint32_t pixel_format; /* fourcc format */
f453ba04 212 struct list_head filp_head;
785b93ef
DA
213 /* if you are using the helper */
214 void *helper_private;
f453ba04
DA
215};
216
217struct drm_property_blob {
218 struct drm_mode_object base;
6bcacf51
DS
219 struct drm_device *dev;
220 struct kref refcount;
e2f5d2ea
DS
221 struct list_head head_global;
222 struct list_head head_file;
ecbbe59b 223 size_t length;
d63f5e6b 224 unsigned char data[];
f453ba04
DA
225};
226
227struct drm_property_enum {
228 uint64_t value;
229 struct list_head head;
230 char name[DRM_PROP_NAME_LEN];
231};
232
233struct drm_property {
234 struct list_head head;
235 struct drm_mode_object base;
236 uint32_t flags;
237 char name[DRM_PROP_NAME_LEN];
238 uint32_t num_values;
239 uint64_t *values;
98f75de4 240 struct drm_device *dev;
f453ba04 241
3758b341 242 struct list_head enum_list;
f453ba04
DA
243};
244
245struct drm_crtc;
246struct drm_connector;
247struct drm_encoder;
d91d8a3f 248struct drm_pending_vblank_event;
8cf5c917 249struct drm_plane;
3b336ec4 250struct drm_bridge;
144ecb97
DV
251struct drm_atomic_state;
252
253/**
cc4ceb48 254 * struct drm_crtc_state - mutable CRTC state
07cc0ef6 255 * @crtc: backpointer to the CRTC
144ecb97 256 * @enable: whether the CRTC should be enabled, gates all other state
d9b13620 257 * @active: whether the CRTC is actively displaying (used for DPMS)
623369e5 258 * @mode_changed: for use by helpers and drivers when computing state updates
eab3bbef 259 * @active_changed: for use by helpers and drivers when computing state updates
6ddd388a 260 * @plane_mask: bitmask of (1 << drm_plane_index(plane)) of attached planes
623369e5
DV
261 * @last_vblank_count: for helpers and drivers to capture the vblank of the
262 * update to ensure framebuffer cleanup isn't done too early
c2fcd274 263 * @planes_changed: for use by helpers and drivers when computing state updates
2f324b42 264 * @adjusted_mode: for use by helpers and drivers to compute adjusted mode timings
144ecb97
DV
265 * @mode: current mode timings
266 * @event: optional pointer to a DRM event to signal upon completion of the
267 * state update
268 * @state: backpointer to global drm_atomic_state
d9b13620
DV
269 *
270 * Note that the distinction between @enable and @active is rather subtile:
271 * Flipping @active while @enable is set without changing anything else may
272 * never return in a failure from the ->atomic_check callback. Userspace assumes
273 * that a DPMS On will always succeed. In other words: @enable controls resource
274 * assignment, @active controls the actual hardware state.
144ecb97
DV
275 */
276struct drm_crtc_state {
07cc0ef6
DV
277 struct drm_crtc *crtc;
278
cc4ceb48 279 bool enable;
d9b13620 280 bool active;
144ecb97 281
c2fcd274
DV
282 /* computed state bits used by helpers and drivers */
283 bool planes_changed : 1;
623369e5 284 bool mode_changed : 1;
eab3bbef 285 bool active_changed : 1;
623369e5 286
6ddd388a
RC
287 /* attached planes bitmask:
288 * WARNING: transitional helpers do not maintain plane_mask so
289 * drivers not converted over to atomic helpers should not rely
290 * on plane_mask being accurate!
291 */
292 u32 plane_mask;
293
623369e5
DV
294 /* last_vblank_count: for vblank waits before cleanup */
295 u32 last_vblank_count;
c2fcd274 296
2f324b42
DV
297 /* adjusted_mode: for use by helpers and drivers */
298 struct drm_display_mode adjusted_mode;
299
144ecb97
DV
300 struct drm_display_mode mode;
301
302 struct drm_pending_vblank_event *event;
303
304 struct drm_atomic_state *state;
305};
f453ba04
DA
306
307/**
3bf0401c 308 * struct drm_crtc_funcs - control CRTCs for a given device
f453ba04 309 * @save: save CRTC state
3b02ab88 310 * @restore: restore CRTC state
715f59cc 311 * @reset: reset CRTC after state has been invalidated (e.g. resume)
3b02ab88 312 * @cursor_set: setup the cursor
2c0c33d4 313 * @cursor_set2: setup the cursor with hotspot, superseeds @cursor_set if set
3b02ab88 314 * @cursor_move: move the cursor
f453ba04 315 * @gamma_set: specify color ramp for CRTC
bffd9de0
PZ
316 * @destroy: deinit and free object
317 * @set_property: called when a property is changed
3b02ab88
LP
318 * @set_config: apply a new CRTC configuration
319 * @page_flip: initiate a page flip
144ecb97
DV
320 * @atomic_duplicate_state: duplicate the atomic state for this CRTC
321 * @atomic_destroy_state: destroy an atomic state for this CRTC
322 * @atomic_set_property: set a property on an atomic state for this CRTC
40ecc694 323 * (do not call directly, use drm_atomic_crtc_set_property())
ac9c9256
RC
324 * @atomic_get_property: get a property on an atomic state for this CRTC
325 * (do not call directly, use drm_atomic_crtc_get_property())
f453ba04
DA
326 *
327 * The drm_crtc_funcs structure is the central CRTC management structure
328 * in the DRM. Each CRTC controls one or more connectors (note that the name
329 * CRTC is simply historical, a CRTC may control LVDS, VGA, DVI, TV out, etc.
330 * connectors, not just CRTs).
331 *
332 * Each driver is responsible for filling out this structure at startup time,
333 * in addition to providing other modesetting features, like i2c and DDC
334 * bus accessors.
335 */
336struct drm_crtc_funcs {
337 /* Save CRTC state */
338 void (*save)(struct drm_crtc *crtc); /* suspend? */
339 /* Restore CRTC state */
340 void (*restore)(struct drm_crtc *crtc); /* resume? */
eb033556
CW
341 /* Reset CRTC state */
342 void (*reset)(struct drm_crtc *crtc);
f453ba04
DA
343
344 /* cursor controls */
345 int (*cursor_set)(struct drm_crtc *crtc, struct drm_file *file_priv,
346 uint32_t handle, uint32_t width, uint32_t height);
4c813d4d
DA
347 int (*cursor_set2)(struct drm_crtc *crtc, struct drm_file *file_priv,
348 uint32_t handle, uint32_t width, uint32_t height,
349 int32_t hot_x, int32_t hot_y);
f453ba04
DA
350 int (*cursor_move)(struct drm_crtc *crtc, int x, int y);
351
352 /* Set gamma on the CRTC */
353 void (*gamma_set)(struct drm_crtc *crtc, u16 *r, u16 *g, u16 *b,
7203425a 354 uint32_t start, uint32_t size);
f453ba04
DA
355 /* Object destroy routine */
356 void (*destroy)(struct drm_crtc *crtc);
357
358 int (*set_config)(struct drm_mode_set *set);
d91d8a3f
KH
359
360 /*
361 * Flip to the given framebuffer. This implements the page
25985edc 362 * flip ioctl described in drm_mode.h, specifically, the
d91d8a3f
KH
363 * implementation must return immediately and block all
364 * rendering to the current fb until the flip has completed.
365 * If userspace set the event flag in the ioctl, the event
366 * argument will point to an event to send back when the flip
367 * completes, otherwise it will be NULL.
368 */
369 int (*page_flip)(struct drm_crtc *crtc,
370 struct drm_framebuffer *fb,
ed8d1975
KP
371 struct drm_pending_vblank_event *event,
372 uint32_t flags);
bffd9de0
PZ
373
374 int (*set_property)(struct drm_crtc *crtc,
375 struct drm_property *property, uint64_t val);
144ecb97
DV
376
377 /* atomic update handling */
378 struct drm_crtc_state *(*atomic_duplicate_state)(struct drm_crtc *crtc);
379 void (*atomic_destroy_state)(struct drm_crtc *crtc,
cc4ceb48 380 struct drm_crtc_state *state);
144ecb97
DV
381 int (*atomic_set_property)(struct drm_crtc *crtc,
382 struct drm_crtc_state *state,
383 struct drm_property *property,
384 uint64_t val);
ac9c9256
RC
385 int (*atomic_get_property)(struct drm_crtc *crtc,
386 const struct drm_crtc_state *state,
387 struct drm_property *property,
388 uint64_t *val);
f453ba04
DA
389};
390
391/**
3bf0401c 392 * struct drm_crtc - central CRTC control structure
7749163e 393 * @dev: parent DRM device
2c0c33d4 394 * @port: OF node used by drm_of_find_possible_crtcs()
7749163e 395 * @head: list management
51fd371b 396 * @mutex: per-CRTC locking
7749163e 397 * @base: base KMS object for ID tracking etc.
e13161af
MR
398 * @primary: primary plane for this CRTC
399 * @cursor: cursor plane for this CRTC
2c0c33d4
DV
400 * @cursor_x: current x position of the cursor, used for universal cursor planes
401 * @cursor_y: current y position of the cursor, used for universal cursor planes
f453ba04 402 * @enabled: is this CRTC enabled?
7749163e
JB
403 * @mode: current mode timings
404 * @hwmode: mode timings as programmed to hw regs
7c80e128
RC
405 * @invert_dimensions: for purposes of error checking crtc vs fb sizes,
406 * invert the width/height of the crtc. This is used if the driver
407 * is performing 90 or 270 degree rotated scanout
f453ba04
DA
408 * @x: x position on screen
409 * @y: y position on screen
f453ba04 410 * @funcs: CRTC control functions
7749163e
JB
411 * @gamma_size: size of gamma ramp
412 * @gamma_store: gamma ramp values
413 * @framedur_ns: precise frame timing
2c0c33d4 414 * @linedur_ns: precise line timing
7749163e
JB
415 * @pixeldur_ns: precise pixel timing
416 * @helper_private: mid-layer private data
bffd9de0 417 * @properties: property tracking for this CRTC
144ecb97 418 * @state: current atomic state for this CRTC
2c0c33d4
DV
419 * @acquire_ctx: per-CRTC implicit acquire context used by atomic drivers for
420 * legacy ioctls
f453ba04
DA
421 *
422 * Each CRTC may have one or more connectors associated with it. This structure
423 * allows the CRTC to be controlled.
424 */
425struct drm_crtc {
426 struct drm_device *dev;
7e435aad 427 struct device_node *port;
f453ba04
DA
428 struct list_head head;
429
3bf0401c 430 /*
29494c17
DV
431 * crtc mutex
432 *
433 * This provides a read lock for the overall crtc state (mode, dpms
434 * state, ...) and a write lock for everything which can be update
435 * without a full modeset (fb, cursor data, ...)
436 */
51fd371b 437 struct drm_modeset_lock mutex;
29494c17 438
f453ba04
DA
439 struct drm_mode_object base;
440
e13161af
MR
441 /* primary and cursor planes for CRTC */
442 struct drm_plane *primary;
443 struct drm_plane *cursor;
444
161d0dc1
MR
445 /* position of cursor plane on crtc */
446 int cursor_x;
447 int cursor_y;
448
f453ba04
DA
449 bool enabled;
450
27641c3f 451 /* Requested mode from modesetting. */
f453ba04
DA
452 struct drm_display_mode mode;
453
27641c3f
MK
454 /* Programmed mode in hw, after adjustments for encoders,
455 * crtc, panel scaling etc. Needed for timestamping etc.
456 */
457 struct drm_display_mode hwmode;
458
7c80e128
RC
459 bool invert_dimensions;
460
f453ba04 461 int x, y;
f453ba04
DA
462 const struct drm_crtc_funcs *funcs;
463
464 /* CRTC gamma size for reporting to userspace */
465 uint32_t gamma_size;
466 uint16_t *gamma_store;
467
27641c3f 468 /* Constants needed for precise vblank and swap timestamping. */
3c184f69 469 int framedur_ns, linedur_ns, pixeldur_ns;
27641c3f 470
f453ba04 471 /* if you are using the helper */
9a436ee6 472 const void *helper_private;
bffd9de0
PZ
473
474 struct drm_object_properties properties;
d059f652 475
144ecb97
DV
476 struct drm_crtc_state *state;
477
d059f652
DV
478 /*
479 * For legacy crtc ioctls so that atomic drivers can get at the locking
480 * acquire context.
481 */
482 struct drm_modeset_acquire_ctx *acquire_ctx;
f453ba04
DA
483};
484
144ecb97
DV
485/**
486 * struct drm_connector_state - mutable connector state
07cc0ef6 487 * @connector: backpointer to the connector
cc4ceb48 488 * @crtc: CRTC to connect connector to, NULL if disabled
623369e5 489 * @best_encoder: can be used by helpers and drivers to select the encoder
144ecb97
DV
490 * @state: backpointer to global drm_atomic_state
491 */
492struct drm_connector_state {
07cc0ef6
DV
493 struct drm_connector *connector;
494
6ddd388a 495 struct drm_crtc *crtc; /* do not write directly, use drm_atomic_set_crtc_for_connector() */
144ecb97 496
623369e5
DV
497 struct drm_encoder *best_encoder;
498
144ecb97
DV
499 struct drm_atomic_state *state;
500};
f453ba04
DA
501
502/**
3bf0401c 503 * struct drm_connector_funcs - control connectors on a given device
261ea74f 504 * @dpms: set power state
f453ba04
DA
505 * @save: save connector state
506 * @restore: restore connector state
13bcf01b 507 * @reset: reset connector after state has been invalidated (e.g. resume)
f453ba04 508 * @detect: is this connector active?
3b02ab88 509 * @fill_modes: fill mode list for this connector
13bcf01b 510 * @set_property: property for this connector may need an update
f453ba04 511 * @destroy: make object go away
13bcf01b 512 * @force: notify the driver that the connector is forced on
144ecb97
DV
513 * @atomic_duplicate_state: duplicate the atomic state for this connector
514 * @atomic_destroy_state: destroy an atomic state for this connector
515 * @atomic_set_property: set a property on an atomic state for this connector
40ecc694 516 * (do not call directly, use drm_atomic_connector_set_property())
ac9c9256
RC
517 * @atomic_get_property: get a property on an atomic state for this connector
518 * (do not call directly, use drm_atomic_connector_get_property())
144ecb97 519 *
f453ba04
DA
520 * Each CRTC may have one or more connectors attached to it. The functions
521 * below allow the core DRM code to control connectors, enumerate available modes,
522 * etc.
523 */
524struct drm_connector_funcs {
525 void (*dpms)(struct drm_connector *connector, int mode);
526 void (*save)(struct drm_connector *connector);
527 void (*restore)(struct drm_connector *connector);
eb033556 528 void (*reset)(struct drm_connector *connector);
930a9e28
CW
529
530 /* Check to see if anything is attached to the connector.
531 * @force is set to false whilst polling, true when checking the
532 * connector due to user request. @force can be used by the driver
533 * to avoid expensive, destructive operations during automated
534 * probing.
535 */
7b334fcb 536 enum drm_connector_status (*detect)(struct drm_connector *connector,
930a9e28 537 bool force);
40a518d9 538 int (*fill_modes)(struct drm_connector *connector, uint32_t max_width, uint32_t max_height);
f453ba04
DA
539 int (*set_property)(struct drm_connector *connector, struct drm_property *property,
540 uint64_t val);
541 void (*destroy)(struct drm_connector *connector);
d50ba256 542 void (*force)(struct drm_connector *connector);
144ecb97
DV
543
544 /* atomic update handling */
545 struct drm_connector_state *(*atomic_duplicate_state)(struct drm_connector *connector);
546 void (*atomic_destroy_state)(struct drm_connector *connector,
cc4ceb48 547 struct drm_connector_state *state);
144ecb97
DV
548 int (*atomic_set_property)(struct drm_connector *connector,
549 struct drm_connector_state *state,
550 struct drm_property *property,
551 uint64_t val);
ac9c9256
RC
552 int (*atomic_get_property)(struct drm_connector *connector,
553 const struct drm_connector_state *state,
554 struct drm_property *property,
555 uint64_t *val);
f453ba04
DA
556};
557
6c3db920 558/**
3bf0401c 559 * struct drm_encoder_funcs - encoder controls
6c3db920
JB
560 * @reset: reset state (e.g. at init or resume time)
561 * @destroy: cleanup and free associated data
562 *
563 * Encoders sit between CRTCs and connectors.
564 */
f453ba04 565struct drm_encoder_funcs {
eb033556 566 void (*reset)(struct drm_encoder *encoder);
f453ba04
DA
567 void (*destroy)(struct drm_encoder *encoder);
568};
569
afe887df 570#define DRM_CONNECTOR_MAX_ENCODER 3
f453ba04
DA
571
572/**
3bf0401c 573 * struct drm_encoder - central DRM encoder structure
db3e4499
JB
574 * @dev: parent DRM device
575 * @head: list management
576 * @base: base KMS object
e5748946 577 * @name: encoder name
db3e4499
JB
578 * @encoder_type: one of the %DRM_MODE_ENCODER_<foo> types in drm_mode.h
579 * @possible_crtcs: bitmask of potential CRTC bindings
580 * @possible_clones: bitmask of potential sibling encoders for cloning
581 * @crtc: currently bound CRTC
3b336ec4 582 * @bridge: bridge associated to the encoder
db3e4499
JB
583 * @funcs: control functions
584 * @helper_private: mid-layer private data
585 *
586 * CRTCs drive pixels to encoders, which convert them into signals
587 * appropriate for a given connector or set of connectors.
f453ba04
DA
588 */
589struct drm_encoder {
590 struct drm_device *dev;
591 struct list_head head;
592
593 struct drm_mode_object base;
e5748946 594 char *name;
f453ba04
DA
595 int encoder_type;
596 uint32_t possible_crtcs;
597 uint32_t possible_clones;
598
599 struct drm_crtc *crtc;
3b336ec4 600 struct drm_bridge *bridge;
f453ba04 601 const struct drm_encoder_funcs *funcs;
9a436ee6 602 const void *helper_private;
f453ba04
DA
603};
604
eb1f8e4f
DA
605/* should we poll this connector for connects and disconnects */
606/* hot plug detectable */
607#define DRM_CONNECTOR_POLL_HPD (1 << 0)
608/* poll for connections */
609#define DRM_CONNECTOR_POLL_CONNECT (1 << 1)
610/* can cleanly poll for disconnections without flickering the screen */
611/* DACs should rarely do this without a lot of testing */
612#define DRM_CONNECTOR_POLL_DISCONNECT (1 << 2)
613
76adaa34
WF
614#define MAX_ELD_BYTES 128
615
f453ba04 616/**
3bf0401c 617 * struct drm_connector - central DRM connector control structure
72252548
JB
618 * @dev: parent DRM device
619 * @kdev: kernel device for sysfs attributes
620 * @attr: sysfs attributes
621 * @head: list management
622 * @base: base KMS object
2abdd313 623 * @name: connector name
72252548
JB
624 * @connector_type: one of the %DRM_MODE_CONNECTOR_<foo> types from drm_mode.h
625 * @connector_type_id: index into connector type enum
f453ba04
DA
626 * @interlace_allowed: can this connector handle interlaced modes?
627 * @doublescan_allowed: can this connector handle doublescan?
2c0c33d4 628 * @stereo_allowed: can this connector handle stereo modes?
72252548
JB
629 * @modes: modes available on this connector (from fill_modes() + user)
630 * @status: one of the drm_connector_status enums (connected, not, or unknown)
631 * @probed_modes: list of modes derived directly from the display
632 * @display_info: information about attached display (e.g. from EDID)
f453ba04 633 * @funcs: connector control functions
72252548 634 * @edid_blob_ptr: DRM property containing EDID if present
7e3bdf4a 635 * @properties: property tracking for this connector
2c0c33d4 636 * @path_blob_ptr: DRM blob property data for the DP MST path property
72252548
JB
637 * @polled: a %DRM_CONNECTOR_POLL_<foo> value for core driven polling
638 * @dpms: current dpms state
639 * @helper_private: mid-layer private data
2c0c33d4 640 * @cmdline_mode: mode line parsed from the kernel cmdline for this connector
72252548 641 * @force: a %DRM_FORCE_<foo> state for forced mode sets
2c0c33d4 642 * @override_edid: has the EDID been overwritten through debugfs for testing?
72252548
JB
643 * @encoder_ids: valid encoders for this connector
644 * @encoder: encoder driving this connector, if any
645 * @eld: EDID-like data, if present
646 * @dvi_dual: dual link DVI, if found
647 * @max_tmds_clock: max clock rate, if found
648 * @latency_present: AV delay info from ELD, if found
649 * @video_latency: video latency info from ELD, if found
650 * @audio_latency: audio latency info from ELD, if found
651 * @null_edid_counter: track sinks that give us all zeros for the EDID
2c0c33d4 652 * @bad_edid_counter: track sinks that give us an EDID with invalid checksum
ac6f2e29 653 * @edid_corrupt: indicates whether the last read EDID was corrupt
2c0c33d4 654 * @debugfs_entry: debugfs directory for this connector
144ecb97 655 * @state: current atomic state for this connector
40d9b043
DA
656 * @has_tile: is this connector connected to a tiled monitor
657 * @tile_group: tile group for the connected monitor
658 * @tile_is_single_monitor: whether the tile is one monitor housing
659 * @num_h_tile: number of horizontal tiles in the tile group
660 * @num_v_tile: number of vertical tiles in the tile group
661 * @tile_h_loc: horizontal location of this tile
662 * @tile_v_loc: vertical location of this tile
663 * @tile_h_size: horizontal size of this tile.
664 * @tile_v_size: vertical size of this tile.
f453ba04
DA
665 *
666 * Each connector may be connected to one or more CRTCs, or may be clonable by
667 * another connector if they can share a CRTC. Each connector also has a specific
668 * position in the broader display (referred to as a 'screen' though it could
669 * span multiple monitors).
670 */
671struct drm_connector {
672 struct drm_device *dev;
5bdebb18 673 struct device *kdev;
f453ba04
DA
674 struct device_attribute *attr;
675 struct list_head head;
676
677 struct drm_mode_object base;
678
2abdd313 679 char *name;
f453ba04
DA
680 int connector_type;
681 int connector_type_id;
682 bool interlace_allowed;
683 bool doublescan_allowed;
560a067a 684 bool stereo_allowed;
f453ba04
DA
685 struct list_head modes; /* list of modes on this connector */
686
f453ba04
DA
687 enum drm_connector_status status;
688
689 /* these are modes added by probing with DDC or the BIOS */
690 struct list_head probed_modes;
691
692 struct drm_display_info display_info;
693 const struct drm_connector_funcs *funcs;
694
f453ba04 695 struct drm_property_blob *edid_blob_ptr;
7e3bdf4a 696 struct drm_object_properties properties;
f453ba04 697
43aba7eb
DA
698 struct drm_property_blob *path_blob_ptr;
699
6f134d7b
DA
700 struct drm_property_blob *tile_blob_ptr;
701
eb1f8e4f
DA
702 uint8_t polled; /* DRM_CONNECTOR_POLL_* */
703
c9fb15f6
KP
704 /* requested DPMS state */
705 int dpms;
706
9a436ee6 707 const void *helper_private;
f453ba04 708
d50ba256 709 /* forced on connector */
eaf99c74 710 struct drm_cmdline_mode cmdline_mode;
d50ba256 711 enum drm_connector_force force;
4cf2b281 712 bool override_edid;
f453ba04 713 uint32_t encoder_ids[DRM_CONNECTOR_MAX_ENCODER];
f453ba04 714 struct drm_encoder *encoder; /* currently active encoder */
4a9a8b71 715
76adaa34
WF
716 /* EDID bits */
717 uint8_t eld[MAX_ELD_BYTES];
718 bool dvi_dual;
719 int max_tmds_clock; /* in MHz */
720 bool latency_present[2];
721 int video_latency[2]; /* [0]: progressive, [1]: interlaced */
722 int audio_latency[2];
4a9a8b71 723 int null_edid_counter; /* needed to workaround some HW bugs where we get all 0s */
0b2443ed 724 unsigned bad_edid_counter;
30f65707 725
6ba2bd3d
TP
726 /* Flag for raw EDID header corruption - used in Displayport
727 * compliance testing - * Displayport Link CTS Core 1.2 rev1.1 4.2.2.6
728 */
729 bool edid_corrupt;
730
30f65707 731 struct dentry *debugfs_entry;
144ecb97
DV
732
733 struct drm_connector_state *state;
40d9b043
DA
734
735 /* DisplayID bits */
736 bool has_tile;
737 struct drm_tile_group *tile_group;
738 bool tile_is_single_monitor;
739
740 uint8_t num_h_tile, num_v_tile;
741 uint8_t tile_h_loc, tile_v_loc;
742 uint16_t tile_h_size, tile_v_size;
144ecb97
DV
743};
744
745/**
746 * struct drm_plane_state - mutable plane state
07cc0ef6 747 * @plane: backpointer to the plane
144ecb97 748 * @crtc: currently bound CRTC, NULL if disabled
cc4ceb48 749 * @fb: currently bound framebuffer
e2330f07 750 * @fence: optional fence to wait for before scanning out @fb
144ecb97
DV
751 * @crtc_x: left position of visible portion of plane on crtc
752 * @crtc_y: upper position of visible portion of plane on crtc
753 * @crtc_w: width of visible portion of plane on crtc
754 * @crtc_h: height of visible portion of plane on crtc
755 * @src_x: left position of visible portion of plane within
756 * plane (in 16.16)
757 * @src_y: upper position of visible portion of plane within
758 * plane (in 16.16)
759 * @src_w: width of visible portion of plane (in 16.16)
760 * @src_h: height of visible portion of plane (in 16.16)
761 * @state: backpointer to global drm_atomic_state
762 */
763struct drm_plane_state {
07cc0ef6
DV
764 struct drm_plane *plane;
765
6ddd388a
RC
766 struct drm_crtc *crtc; /* do not write directly, use drm_atomic_set_crtc_for_plane() */
767 struct drm_framebuffer *fb; /* do not write directly, use drm_atomic_set_fb_for_plane() */
e2330f07 768 struct fence *fence;
144ecb97
DV
769
770 /* Signed dest location allows it to be partially off screen */
771 int32_t crtc_x, crtc_y;
772 uint32_t crtc_w, crtc_h;
773
774 /* Source values are 16.16 fixed point */
775 uint32_t src_x, src_y;
776 uint32_t src_h, src_w;
777
1da30627
MR
778 /* Plane rotation */
779 unsigned int rotation;
780
144ecb97 781 struct drm_atomic_state *state;
f453ba04
DA
782};
783
144ecb97 784
8cf5c917 785/**
3bf0401c 786 * struct drm_plane_funcs - driver plane control functions
8cf5c917
JB
787 * @update_plane: update the plane configuration
788 * @disable_plane: shut down the plane
789 * @destroy: clean up plane resources
2c0c33d4 790 * @reset: reset plane after state has been invalidated (e.g. resume)
4d93914a 791 * @set_property: called when a property is changed
144ecb97
DV
792 * @atomic_duplicate_state: duplicate the atomic state for this plane
793 * @atomic_destroy_state: destroy an atomic state for this plane
794 * @atomic_set_property: set a property on an atomic state for this plane
40ecc694 795 * (do not call directly, use drm_atomic_plane_set_property())
ac9c9256
RC
796 * @atomic_get_property: get a property on an atomic state for this plane
797 * (do not call directly, use drm_atomic_plane_get_property())
8cf5c917
JB
798 */
799struct drm_plane_funcs {
800 int (*update_plane)(struct drm_plane *plane,
801 struct drm_crtc *crtc, struct drm_framebuffer *fb,
802 int crtc_x, int crtc_y,
803 unsigned int crtc_w, unsigned int crtc_h,
804 uint32_t src_x, uint32_t src_y,
805 uint32_t src_w, uint32_t src_h);
806 int (*disable_plane)(struct drm_plane *plane);
807 void (*destroy)(struct drm_plane *plane);
2a0d7cfd 808 void (*reset)(struct drm_plane *plane);
4d93914a
RC
809
810 int (*set_property)(struct drm_plane *plane,
811 struct drm_property *property, uint64_t val);
144ecb97
DV
812
813 /* atomic update handling */
814 struct drm_plane_state *(*atomic_duplicate_state)(struct drm_plane *plane);
815 void (*atomic_destroy_state)(struct drm_plane *plane,
cc4ceb48 816 struct drm_plane_state *state);
144ecb97
DV
817 int (*atomic_set_property)(struct drm_plane *plane,
818 struct drm_plane_state *state,
819 struct drm_property *property,
820 uint64_t val);
ac9c9256
RC
821 int (*atomic_get_property)(struct drm_plane *plane,
822 const struct drm_plane_state *state,
823 struct drm_property *property,
824 uint64_t *val);
8cf5c917
JB
825};
826
e27dde3e
MR
827enum drm_plane_type {
828 DRM_PLANE_TYPE_OVERLAY,
829 DRM_PLANE_TYPE_PRIMARY,
830 DRM_PLANE_TYPE_CURSOR,
831};
832
8cf5c917 833/**
3bf0401c 834 * struct drm_plane - central DRM plane control structure
8cf5c917
JB
835 * @dev: DRM device this plane belongs to
836 * @head: for list management
837 * @base: base mode object
838 * @possible_crtcs: pipes this plane can be bound to
839 * @format_types: array of formats supported by this plane
840 * @format_count: number of formats supported
7eb5f302 841 * @format_default: driver hasn't supplied supported formats for the plane
8cf5c917
JB
842 * @crtc: currently bound CRTC
843 * @fb: currently bound fb
2c0c33d4
DV
844 * @old_fb: Temporary tracking of the old fb while a modeset is ongoing. Used by
845 * drm_mode_set_config_internal() to implement correct refcounting.
8cf5c917 846 * @funcs: helper functions
4d93914a 847 * @properties: property tracking for this plane
e27dde3e 848 * @type: type of plane (overlay, primary, cursor)
144ecb97 849 * @state: current atomic state for this plane
8cf5c917
JB
850 */
851struct drm_plane {
852 struct drm_device *dev;
853 struct list_head head;
854
4d02e2de
DV
855 struct drm_modeset_lock mutex;
856
8cf5c917
JB
857 struct drm_mode_object base;
858
859 uint32_t possible_crtcs;
860 uint32_t *format_types;
861 uint32_t format_count;
7eb5f302 862 bool format_default;
8cf5c917
JB
863
864 struct drm_crtc *crtc;
865 struct drm_framebuffer *fb;
866
3d30a59b
DV
867 struct drm_framebuffer *old_fb;
868
8cf5c917 869 const struct drm_plane_funcs *funcs;
4d93914a
RC
870
871 struct drm_object_properties properties;
e27dde3e
MR
872
873 enum drm_plane_type type;
144ecb97 874
9a436ee6 875 const void *helper_private;
c2fcd274 876
144ecb97 877 struct drm_plane_state *state;
8cf5c917
JB
878};
879
3b336ec4 880/**
3bf0401c 881 * struct drm_bridge_funcs - drm_bridge control functions
3d3f8b1f 882 * @attach: Called during drm_bridge_attach
3b336ec4
SP
883 * @mode_fixup: Try to fixup (or reject entirely) proposed mode for this bridge
884 * @disable: Called right before encoder prepare, disables the bridge
885 * @post_disable: Called right after encoder prepare, for lockstepped disable
886 * @mode_set: Set this mode to the bridge
887 * @pre_enable: Called right before encoder commit, for lockstepped commit
888 * @enable: Called right after encoder commit, enables the bridge
3b336ec4
SP
889 */
890struct drm_bridge_funcs {
3d3f8b1f 891 int (*attach)(struct drm_bridge *bridge);
3b336ec4
SP
892 bool (*mode_fixup)(struct drm_bridge *bridge,
893 const struct drm_display_mode *mode,
894 struct drm_display_mode *adjusted_mode);
895 void (*disable)(struct drm_bridge *bridge);
896 void (*post_disable)(struct drm_bridge *bridge);
897 void (*mode_set)(struct drm_bridge *bridge,
898 struct drm_display_mode *mode,
899 struct drm_display_mode *adjusted_mode);
900 void (*pre_enable)(struct drm_bridge *bridge);
901 void (*enable)(struct drm_bridge *bridge);
3b336ec4
SP
902};
903
904/**
3bf0401c 905 * struct drm_bridge - central DRM bridge control structure
3b336ec4 906 * @dev: DRM device this bridge belongs to
862e686c
AT
907 * @encoder: encoder to which this bridge is connected
908 * @next: the next bridge in the encoder chain
3d3f8b1f
AK
909 * @of_node: device node pointer to the bridge
910 * @list: to keep track of all added bridges
3b336ec4
SP
911 * @base: base mode object
912 * @funcs: control functions
913 * @driver_private: pointer to the bridge driver's internal context
914 */
915struct drm_bridge {
916 struct drm_device *dev;
3d3f8b1f 917 struct drm_encoder *encoder;
862e686c 918 struct drm_bridge *next;
3d3f8b1f
AK
919#ifdef CONFIG_OF
920 struct device_node *of_node;
921#endif
922 struct list_head list;
3b336ec4
SP
923
924 const struct drm_bridge_funcs *funcs;
925 void *driver_private;
926};
927
cc4ceb48 928/**
08855fae 929 * struct drm_atomic_state - the global state object for atomic updates
cc4ceb48 930 * @dev: parent DRM device
d34f20d6 931 * @allow_modeset: allow full modeset
f02ad907 932 * @legacy_cursor_update: hint to enforce legacy cursor ioctl semantics
cc4ceb48
DV
933 * @planes: pointer to array of plane pointers
934 * @plane_states: pointer to array of plane states pointers
935 * @crtcs: pointer to array of CRTC pointers
936 * @crtc_states: pointer to array of CRTC states pointers
f52b69f1 937 * @num_connector: size of the @connectors and @connector_states arrays
cc4ceb48
DV
938 * @connectors: pointer to array of connector pointers
939 * @connector_states: pointer to array of connector states pointers
940 * @acquire_ctx: acquire context for this atomic modeset state update
941 */
942struct drm_atomic_state {
943 struct drm_device *dev;
d34f20d6 944 bool allow_modeset : 1;
f02ad907 945 bool legacy_cursor_update : 1;
cc4ceb48
DV
946 struct drm_plane **planes;
947 struct drm_plane_state **plane_states;
948 struct drm_crtc **crtcs;
949 struct drm_crtc_state **crtc_states;
f52b69f1 950 int num_connector;
cc4ceb48
DV
951 struct drm_connector **connectors;
952 struct drm_connector_state **connector_states;
953
954 struct drm_modeset_acquire_ctx *acquire_ctx;
955};
956
957
f453ba04 958/**
3bf0401c 959 * struct drm_mode_set - new values for a CRTC config change
ef27351a
JB
960 * @fb: framebuffer to use for new config
961 * @crtc: CRTC whose configuration we're about to change
962 * @mode: mode timings to use
963 * @x: position of this CRTC relative to @fb
964 * @y: position of this CRTC relative to @fb
965 * @connectors: array of connectors to drive with this CRTC if possible
966 * @num_connectors: size of @connectors array
f453ba04
DA
967 *
968 * Represents a single crtc the connectors that it drives with what mode
969 * and from which framebuffer it scans out from.
970 *
971 * This is used to set modes.
972 */
973struct drm_mode_set {
f453ba04
DA
974 struct drm_framebuffer *fb;
975 struct drm_crtc *crtc;
976 struct drm_display_mode *mode;
977
978 uint32_t x;
979 uint32_t y;
980
981 struct drm_connector **connectors;
982 size_t num_connectors;
983};
984
985/**
550cebcd
JB
986 * struct drm_mode_config_funcs - basic driver provided mode setting functions
987 * @fb_create: create a new framebuffer object
988 * @output_poll_changed: function to handle output configuration changes
2b1193d5 989 * @atomic_check: check whether a given atomic state update is possible
cc4ceb48
DV
990 * @atomic_commit: commit an atomic state update previously verified with
991 * atomic_check()
036ef573
ML
992 * @atomic_state_alloc: allocate a new atomic state
993 * @atomic_state_clear: clear the atomic state
994 * @atomic_state_free: free the atomic state
550cebcd
JB
995 *
996 * Some global (i.e. not per-CRTC, connector, etc) mode setting functions that
997 * involve drivers.
f453ba04
DA
998 */
999struct drm_mode_config_funcs {
550cebcd
JB
1000 struct drm_framebuffer *(*fb_create)(struct drm_device *dev,
1001 struct drm_file *file_priv,
1002 struct drm_mode_fb_cmd2 *mode_cmd);
eb1f8e4f 1003 void (*output_poll_changed)(struct drm_device *dev);
cc4ceb48
DV
1004
1005 int (*atomic_check)(struct drm_device *dev,
1006 struct drm_atomic_state *a);
1007 int (*atomic_commit)(struct drm_device *dev,
1008 struct drm_atomic_state *a,
1009 bool async);
036ef573
ML
1010 struct drm_atomic_state *(*atomic_state_alloc)(struct drm_device *dev);
1011 void (*atomic_state_clear)(struct drm_atomic_state *state);
1012 void (*atomic_state_free)(struct drm_atomic_state *state);
f453ba04
DA
1013};
1014
c1aaca23 1015/**
2c0c33d4 1016 * struct drm_mode_group - group of mode setting resources for potential sub-grouping
c1aaca23
JB
1017 * @num_crtcs: CRTC count
1018 * @num_encoders: encoder count
1019 * @num_connectors: connector count
2c0c33d4 1020 * @num_bridges: bridge count
c1aaca23
JB
1021 * @id_list: list of KMS object IDs in this group
1022 *
1023 * Currently this simply tracks the global mode setting state. But in the
1024 * future it could allow groups of objects to be set aside into independent
1025 * control groups for use by different user level processes (e.g. two X servers
1026 * running simultaneously on different heads, each with their own mode
1027 * configuration and freedom of mode setting).
1028 */
f453ba04
DA
1029struct drm_mode_group {
1030 uint32_t num_crtcs;
1031 uint32_t num_encoders;
1032 uint32_t num_connectors;
1033
1034 /* list of object IDs for this group */
1035 uint32_t *id_list;
1036};
1037
1038/**
2c0c33d4 1039 * struct drm_mode_config - Mode configuration control structure
a62c93d5 1040 * @mutex: mutex protecting KMS related lists and structures
2c0c33d4
DV
1041 * @connection_mutex: ww mutex protecting connector state and routing
1042 * @acquire_ctx: global implicit acquire context used by atomic drivers for
1043 * legacy ioctls
a62c93d5
JB
1044 * @idr_mutex: mutex for KMS ID allocation and management
1045 * @crtc_idr: main KMS ID tracking object
2c0c33d4 1046 * @fb_lock: mutex to protect fb state and lists
a62c93d5
JB
1047 * @num_fb: number of fbs available
1048 * @fb_list: list of framebuffers available
1049 * @num_connector: number of connectors on this device
1050 * @connector_list: list of connector objects
1051 * @num_encoder: number of encoders on this device
1052 * @encoder_list: list of encoder objects
2c0c33d4
DV
1053 * @num_overlay_plane: number of overlay planes on this device
1054 * @num_total_plane: number of universal (i.e. with primary/curso) planes on this device
1055 * @plane_list: list of plane objects
a62c93d5
JB
1056 * @num_crtc: number of CRTCs on this device
1057 * @crtc_list: list of CRTC objects
2c0c33d4 1058 * @property_list: list of property objects
a62c93d5
JB
1059 * @min_width: minimum pixel width on this device
1060 * @min_height: minimum pixel height on this device
1061 * @max_width: maximum pixel width on this device
1062 * @max_height: maximum pixel height on this device
1063 * @funcs: core driver provided mode setting functions
1064 * @fb_base: base address of the framebuffer
2c0c33d4
DV
1065 * @poll_enabled: track polling support for this device
1066 * @poll_running: track polling status for this device
a62c93d5 1067 * @output_poll_work: delayed work for polling in process context
2c0c33d4 1068 * @property_blob_list: list of all the blob property objects
8fb6e7a5 1069 * @blob_lock: mutex for blob property allocation and management
a62c93d5 1070 * @*_property: core property tracking
2c0c33d4
DV
1071 * @preferred_depth: preferred RBG pixel depth, used by fb helpers
1072 * @prefer_shadow: hint to userspace to prefer shadow-fb rendering
1073 * @async_page_flip: does this device support async flips on the primary plane?
1074 * @cursor_width: hint to userspace for max cursor width
1075 * @cursor_height: hint to userspace for max cursor height
f453ba04 1076 *
a62c93d5
JB
1077 * Core mode resource tracking structure. All CRTC, encoders, and connectors
1078 * enumerated by the driver are added here, as are global properties. Some
1079 * global restrictions are also here, e.g. dimension restrictions.
f453ba04
DA
1080 */
1081struct drm_mode_config {
ad2563c2 1082 struct mutex mutex; /* protects configuration (mode lists etc.) */
51fd371b
RC
1083 struct drm_modeset_lock connection_mutex; /* protects connector->encoder and encoder->crtc links */
1084 struct drm_modeset_acquire_ctx *acquire_ctx; /* for legacy _lock_all() / _unlock_all() */
ad2563c2 1085 struct mutex idr_mutex; /* for IDR management */
f453ba04 1086 struct idr crtc_idr; /* use this idr for all IDs, fb, crtc, connector, modes - just makes life easier */
138f9ebb 1087 struct idr tile_idr; /* use this idr for all IDs, fb, crtc, connector, modes - just makes life easier */
f453ba04 1088 /* this is limited to one for now */
4b096ac1 1089
2c0c33d4 1090 struct mutex fb_lock; /* proctects global and per-file fb lists */
f453ba04
DA
1091 int num_fb;
1092 struct list_head fb_list;
4b096ac1 1093
f453ba04
DA
1094 int num_connector;
1095 struct list_head connector_list;
1096 int num_encoder;
1097 struct list_head encoder_list;
e27dde3e
MR
1098
1099 /*
1100 * Track # of overlay planes separately from # of total planes. By
1101 * default we only advertise overlay planes to userspace; if userspace
1102 * sets the "universal plane" capability bit, we'll go ahead and
1103 * expose all planes.
1104 */
1105 int num_overlay_plane;
1106 int num_total_plane;
8cf5c917 1107 struct list_head plane_list;
f453ba04
DA
1108
1109 int num_crtc;
1110 struct list_head crtc_list;
1111
1112 struct list_head property_list;
1113
f453ba04
DA
1114 int min_width, min_height;
1115 int max_width, max_height;
e6ecefaa 1116 const struct drm_mode_config_funcs *funcs;
d883f7f1 1117 resource_size_t fb_base;
f453ba04 1118
eb1f8e4f
DA
1119 /* output poll support */
1120 bool poll_enabled;
905bc9ff 1121 bool poll_running;
162b6a57 1122 bool delayed_event;
991ea75c 1123 struct delayed_work output_poll_work;
eb1f8e4f 1124
8fb6e7a5
DS
1125 struct mutex blob_lock;
1126
f453ba04
DA
1127 /* pointers to standard properties */
1128 struct list_head property_blob_list;
1129 struct drm_property *edid_property;
1130 struct drm_property *dpms_property;
43aba7eb 1131 struct drm_property *path_property;
6f134d7b 1132 struct drm_property *tile_property;
9922ab5a 1133 struct drm_property *plane_type_property;
2a297cce 1134 struct drm_property *rotation_property;
6b4959f4
RC
1135 struct drm_property *prop_src_x;
1136 struct drm_property *prop_src_y;
1137 struct drm_property *prop_src_w;
1138 struct drm_property *prop_src_h;
1139 struct drm_property *prop_crtc_x;
1140 struct drm_property *prop_crtc_y;
1141 struct drm_property *prop_crtc_w;
1142 struct drm_property *prop_crtc_h;
1143 struct drm_property *prop_fb_id;
1144 struct drm_property *prop_crtc_id;
eab3bbef 1145 struct drm_property *prop_active;
f453ba04
DA
1146
1147 /* DVI-I properties */
1148 struct drm_property *dvi_i_subconnector_property;
1149 struct drm_property *dvi_i_select_subconnector_property;
1150
1151 /* TV properties */
1152 struct drm_property *tv_subconnector_property;
1153 struct drm_property *tv_select_subconnector_property;
1154 struct drm_property *tv_mode_property;
1155 struct drm_property *tv_left_margin_property;
1156 struct drm_property *tv_right_margin_property;
1157 struct drm_property *tv_top_margin_property;
1158 struct drm_property *tv_bottom_margin_property;
b6b7902e
FJ
1159 struct drm_property *tv_brightness_property;
1160 struct drm_property *tv_contrast_property;
1161 struct drm_property *tv_flicker_reduction_property;
a75f0236
FJ
1162 struct drm_property *tv_overscan_property;
1163 struct drm_property *tv_saturation_property;
1164 struct drm_property *tv_hue_property;
f453ba04
DA
1165
1166 /* Optional properties */
1167 struct drm_property *scaling_mode_property;
ff587e45 1168 struct drm_property *aspect_ratio_property;
884840aa 1169 struct drm_property *dirty_info_property;
019d96cb 1170
5bb2bbf5
DA
1171 /* properties for virtual machine layout */
1172 struct drm_property *suggested_x_property;
1173 struct drm_property *suggested_y_property;
1174
019d96cb
DA
1175 /* dumb ioctl parameters */
1176 uint32_t preferred_depth, prefer_shadow;
62f2104f
KP
1177
1178 /* whether async page flip is supported or not */
1179 bool async_page_flip;
8716ed4e 1180
e3eb3250
RC
1181 /* whether the driver supports fb modifiers */
1182 bool allow_fb_modifiers;
1183
8716ed4e
AD
1184 /* cursor size */
1185 uint32_t cursor_width, cursor_height;
f453ba04
DA
1186};
1187
dd275956
RC
1188/**
1189 * drm_for_each_plane_mask - iterate over planes specified by bitmask
1190 * @plane: the loop cursor
1191 * @dev: the DRM device
1192 * @plane_mask: bitmask of plane indices
1193 *
1194 * Iterate over all planes specified by bitmask.
1195 */
1196#define drm_for_each_plane_mask(plane, dev, plane_mask) \
1197 list_for_each_entry((plane), &(dev)->mode_config.plane_list, head) \
1198 if ((plane_mask) & (1 << drm_plane_index(plane)))
1199
1200
f453ba04
DA
1201#define obj_to_crtc(x) container_of(x, struct drm_crtc, base)
1202#define obj_to_connector(x) container_of(x, struct drm_connector, base)
1203#define obj_to_encoder(x) container_of(x, struct drm_encoder, base)
1204#define obj_to_mode(x) container_of(x, struct drm_display_mode, base)
1205#define obj_to_fb(x) container_of(x, struct drm_framebuffer, base)
1206#define obj_to_property(x) container_of(x, struct drm_property, base)
1207#define obj_to_blob(x) container_of(x, struct drm_property_blob, base)
8cf5c917 1208#define obj_to_plane(x) container_of(x, struct drm_plane, base)
f453ba04 1209
4a67d391
SH
1210struct drm_prop_enum_list {
1211 int type;
1212 char *name;
1213};
f453ba04 1214
e13161af
MR
1215extern int drm_crtc_init_with_planes(struct drm_device *dev,
1216 struct drm_crtc *crtc,
1217 struct drm_plane *primary,
fc1d3e44 1218 struct drm_plane *cursor,
e13161af 1219 const struct drm_crtc_funcs *funcs);
f453ba04 1220extern void drm_crtc_cleanup(struct drm_crtc *crtc);
db5f7a6e
RK
1221extern unsigned int drm_crtc_index(struct drm_crtc *crtc);
1222
1223/**
1224 * drm_crtc_mask - find the mask of a registered CRTC
1225 * @crtc: CRTC to find mask for
1226 *
1227 * Given a registered CRTC, return the mask bit of that CRTC for an
1228 * encoder's possible_crtcs field.
1229 */
1230static inline uint32_t drm_crtc_mask(struct drm_crtc *crtc)
1231{
1232 return 1 << drm_crtc_index(crtc);
1233}
f453ba04 1234
b21e3afe
IM
1235extern void drm_connector_ida_init(void);
1236extern void drm_connector_ida_destroy(void);
6bfc56aa
VS
1237extern int drm_connector_init(struct drm_device *dev,
1238 struct drm_connector *connector,
1239 const struct drm_connector_funcs *funcs,
1240 int connector_type);
34ea3d38
TW
1241int drm_connector_register(struct drm_connector *connector);
1242void drm_connector_unregister(struct drm_connector *connector);
f453ba04
DA
1243
1244extern void drm_connector_cleanup(struct drm_connector *connector);
10f637bf 1245extern unsigned int drm_connector_index(struct drm_connector *connector);
cbc7e221
DA
1246/* helper to unplug all connectors from sysfs for device */
1247extern void drm_connector_unplug_all(struct drm_device *dev);
f453ba04 1248
3d3f8b1f
AK
1249extern int drm_bridge_add(struct drm_bridge *bridge);
1250extern void drm_bridge_remove(struct drm_bridge *bridge);
1251extern struct drm_bridge *of_drm_find_bridge(struct device_node *np);
1252extern int drm_bridge_attach(struct drm_device *dev, struct drm_bridge *bridge);
3b336ec4 1253
862e686c
AT
1254bool drm_bridge_mode_fixup(struct drm_bridge *bridge,
1255 const struct drm_display_mode *mode,
1256 struct drm_display_mode *adjusted_mode);
1257void drm_bridge_disable(struct drm_bridge *bridge);
1258void drm_bridge_post_disable(struct drm_bridge *bridge);
1259void drm_bridge_mode_set(struct drm_bridge *bridge,
1260 struct drm_display_mode *mode,
1261 struct drm_display_mode *adjusted_mode);
1262void drm_bridge_pre_enable(struct drm_bridge *bridge);
1263void drm_bridge_enable(struct drm_bridge *bridge);
1264
6bfc56aa
VS
1265extern int drm_encoder_init(struct drm_device *dev,
1266 struct drm_encoder *encoder,
1267 const struct drm_encoder_funcs *funcs,
1268 int encoder_type);
f453ba04 1269
3d887368
TR
1270/**
1271 * drm_encoder_crtc_ok - can a given crtc drive a given encoder?
1272 * @encoder: encoder to test
1273 * @crtc: crtc to test
1274 *
1275 * Return false if @encoder can't be driven by @crtc, true otherwise.
1276 */
1277static inline bool drm_encoder_crtc_ok(struct drm_encoder *encoder,
1278 struct drm_crtc *crtc)
1279{
1280 return !!(encoder->possible_crtcs & drm_crtc_mask(crtc));
1281}
1282
dc415ff9
MR
1283extern int drm_universal_plane_init(struct drm_device *dev,
1284 struct drm_plane *plane,
1285 unsigned long possible_crtcs,
1286 const struct drm_plane_funcs *funcs,
1287 const uint32_t *formats,
1288 uint32_t format_count,
1289 enum drm_plane_type type);
8cf5c917
JB
1290extern int drm_plane_init(struct drm_device *dev,
1291 struct drm_plane *plane,
1292 unsigned long possible_crtcs,
1293 const struct drm_plane_funcs *funcs,
0a7eb243 1294 const uint32_t *formats, uint32_t format_count,
dc415ff9 1295 bool is_primary);
8cf5c917 1296extern void drm_plane_cleanup(struct drm_plane *plane);
10f637bf 1297extern unsigned int drm_plane_index(struct drm_plane *plane);
f81338a5 1298extern struct drm_plane * drm_plane_from_index(struct drm_device *dev, int idx);
9125e618 1299extern void drm_plane_force_disable(struct drm_plane *plane);
ead8610d
LP
1300extern int drm_plane_check_pixel_format(const struct drm_plane *plane,
1301 u32 format);
ecb7e16b
GP
1302extern void drm_crtc_get_hv_timing(const struct drm_display_mode *mode,
1303 int *hdisplay, int *vdisplay);
af93629d
MR
1304extern int drm_crtc_check_viewport(const struct drm_crtc *crtc,
1305 int x, int y,
1306 const struct drm_display_mode *mode,
1307 const struct drm_framebuffer *fb);
8cf5c917 1308
f453ba04
DA
1309extern void drm_encoder_cleanup(struct drm_encoder *encoder);
1310
d20d3174 1311extern const char *drm_get_connector_status_name(enum drm_connector_status status);
ac1bb36c 1312extern const char *drm_get_subpixel_order_name(enum subpixel_order order);
d20d3174
VS
1313extern const char *drm_get_dpms_name(int val);
1314extern const char *drm_get_dvi_i_subconnector_name(int val);
1315extern const char *drm_get_dvi_i_select_name(int val);
1316extern const char *drm_get_tv_subconnector_name(int val);
1317extern const char *drm_get_tv_select_name(int val);
ea39f835 1318extern void drm_fb_release(struct drm_file *file_priv);
e2f5d2ea
DS
1319extern void drm_property_destroy_user_blobs(struct drm_device *dev,
1320 struct drm_file *file_priv);
f453ba04 1321extern int drm_mode_group_init_legacy_group(struct drm_device *dev, struct drm_mode_group *group);
ad222799 1322extern void drm_mode_group_destroy(struct drm_mode_group *group);
2390cd11 1323extern void drm_reinit_primary_mode_group(struct drm_device *dev);
fbff4690 1324extern bool drm_probe_ddc(struct i2c_adapter *adapter);
f453ba04
DA
1325extern struct edid *drm_get_edid(struct drm_connector *connector,
1326 struct i2c_adapter *adapter);
51f8da59 1327extern struct edid *drm_edid_duplicate(const struct edid *edid);
f453ba04 1328extern int drm_add_edid_modes(struct drm_connector *connector, struct edid *edid);
f453ba04 1329extern void drm_mode_config_init(struct drm_device *dev);
eb033556 1330extern void drm_mode_config_reset(struct drm_device *dev);
f453ba04 1331extern void drm_mode_config_cleanup(struct drm_device *dev);
55310008 1332
43aba7eb 1333extern int drm_mode_connector_set_path_property(struct drm_connector *connector,
12e6cecd 1334 const char *path);
6f134d7b 1335int drm_mode_connector_set_tile_property(struct drm_connector *connector);
f453ba04 1336extern int drm_mode_connector_update_edid_property(struct drm_connector *connector,
12e6cecd 1337 const struct edid *edid);
5ea22f24 1338
b5571e9d
BB
1339extern int drm_display_info_set_bus_formats(struct drm_display_info *info,
1340 const u32 *formats,
1341 unsigned int num_formats);
1342
5ea22f24
RC
1343static inline bool drm_property_type_is(struct drm_property *property,
1344 uint32_t type)
1345{
1346 /* instanceof for props.. handles extended type vs original types: */
1347 if (property->flags & DRM_MODE_PROP_EXTENDED_TYPE)
1348 return (property->flags & DRM_MODE_PROP_EXTENDED_TYPE) == type;
1349 return property->flags & type;
1350}
1351
1352static inline bool drm_property_type_valid(struct drm_property *property)
1353{
1354 if (property->flags & DRM_MODE_PROP_EXTENDED_TYPE)
1355 return !(property->flags & DRM_MODE_PROP_LEGACY_TYPE);
1356 return !!(property->flags & DRM_MODE_PROP_LEGACY_TYPE);
1357}
1358
c543188a
PZ
1359extern int drm_object_property_set_value(struct drm_mode_object *obj,
1360 struct drm_property *property,
1361 uint64_t val);
1362extern int drm_object_property_get_value(struct drm_mode_object *obj,
1363 struct drm_property *property,
1364 uint64_t *value);
f453ba04
DA
1365extern int drm_framebuffer_init(struct drm_device *dev,
1366 struct drm_framebuffer *fb,
1367 const struct drm_framebuffer_funcs *funcs);
786b99ed
DV
1368extern struct drm_framebuffer *drm_framebuffer_lookup(struct drm_device *dev,
1369 uint32_t id);
f7eff60e
RC
1370extern void drm_framebuffer_unreference(struct drm_framebuffer *fb);
1371extern void drm_framebuffer_reference(struct drm_framebuffer *fb);
1372extern void drm_framebuffer_remove(struct drm_framebuffer *fb);
f453ba04 1373extern void drm_framebuffer_cleanup(struct drm_framebuffer *fb);
36206361 1374extern void drm_framebuffer_unregister_private(struct drm_framebuffer *fb);
f453ba04 1375
c543188a
PZ
1376extern void drm_object_attach_property(struct drm_mode_object *obj,
1377 struct drm_property *property,
1378 uint64_t init_val);
f453ba04
DA
1379extern struct drm_property *drm_property_create(struct drm_device *dev, int flags,
1380 const char *name, int num_values);
4a67d391
SH
1381extern struct drm_property *drm_property_create_enum(struct drm_device *dev, int flags,
1382 const char *name,
49e27545
RC
1383 const struct drm_prop_enum_list *props,
1384 int num_values);
1385struct drm_property *drm_property_create_bitmask(struct drm_device *dev,
1386 int flags, const char *name,
4a67d391 1387 const struct drm_prop_enum_list *props,
7689ffb3
VS
1388 int num_props,
1389 uint64_t supported_bits);
d9bc3c02
SH
1390struct drm_property *drm_property_create_range(struct drm_device *dev, int flags,
1391 const char *name,
1392 uint64_t min, uint64_t max);
ebc44cf3
RC
1393struct drm_property *drm_property_create_signed_range(struct drm_device *dev,
1394 int flags, const char *name,
1395 int64_t min, int64_t max);
98f75de4
RC
1396struct drm_property *drm_property_create_object(struct drm_device *dev,
1397 int flags, const char *name, uint32_t type);
960cd9d4
DV
1398struct drm_property *drm_property_create_bool(struct drm_device *dev, int flags,
1399 const char *name);
6bcacf51
DS
1400struct drm_property_blob *drm_property_create_blob(struct drm_device *dev,
1401 size_t length,
1402 const void *data);
1403struct drm_property_blob *drm_property_lookup_blob(struct drm_device *dev,
1404 uint32_t id);
1405struct drm_property_blob *drm_property_reference_blob(struct drm_property_blob *blob);
1406void drm_property_unreference_blob(struct drm_property_blob *blob);
f453ba04
DA
1407extern void drm_property_destroy(struct drm_device *dev, struct drm_property *property);
1408extern int drm_property_add_enum(struct drm_property *property, int index,
1409 uint64_t value, const char *name);
1410extern int drm_mode_create_dvi_i_properties(struct drm_device *dev);
2f763312
TR
1411extern int drm_mode_create_tv_properties(struct drm_device *dev,
1412 unsigned int num_modes,
1413 char *modes[]);
f453ba04 1414extern int drm_mode_create_scaling_mode_property(struct drm_device *dev);
ff587e45 1415extern int drm_mode_create_aspect_ratio_property(struct drm_device *dev);
884840aa 1416extern int drm_mode_create_dirty_info_property(struct drm_device *dev);
5bb2bbf5 1417extern int drm_mode_create_suggested_offset_properties(struct drm_device *dev);
d34f20d6
RC
1418extern bool drm_property_change_valid_get(struct drm_property *property,
1419 uint64_t value, struct drm_mode_object **ref);
1420extern void drm_property_change_valid_put(struct drm_property *property,
1421 struct drm_mode_object *ref);
f453ba04
DA
1422
1423extern int drm_mode_connector_attach_encoder(struct drm_connector *connector,
1424 struct drm_encoder *encoder);
4cae5b84 1425extern int drm_mode_crtc_set_gamma_size(struct drm_crtc *crtc,
f453ba04 1426 int gamma_size);
7a9c9060
DV
1427extern struct drm_mode_object *drm_mode_object_find(struct drm_device *dev,
1428 uint32_t id, uint32_t type);
98f75de4 1429
f453ba04
DA
1430/* IOCTLs */
1431extern int drm_mode_getresources(struct drm_device *dev,
1432 void *data, struct drm_file *file_priv);
8cf5c917
JB
1433extern int drm_mode_getplane_res(struct drm_device *dev, void *data,
1434 struct drm_file *file_priv);
f453ba04
DA
1435extern int drm_mode_getcrtc(struct drm_device *dev,
1436 void *data, struct drm_file *file_priv);
1437extern int drm_mode_getconnector(struct drm_device *dev,
1438 void *data, struct drm_file *file_priv);
2d13b679 1439extern int drm_mode_set_config_internal(struct drm_mode_set *set);
f453ba04
DA
1440extern int drm_mode_setcrtc(struct drm_device *dev,
1441 void *data, struct drm_file *file_priv);
8cf5c917
JB
1442extern int drm_mode_getplane(struct drm_device *dev,
1443 void *data, struct drm_file *file_priv);
1444extern int drm_mode_setplane(struct drm_device *dev,
1445 void *data, struct drm_file *file_priv);
f453ba04
DA
1446extern int drm_mode_cursor_ioctl(struct drm_device *dev,
1447 void *data, struct drm_file *file_priv);
4c813d4d
DA
1448extern int drm_mode_cursor2_ioctl(struct drm_device *dev,
1449 void *data, struct drm_file *file_priv);
f453ba04
DA
1450extern int drm_mode_addfb(struct drm_device *dev,
1451 void *data, struct drm_file *file_priv);
308e5bcb
JB
1452extern int drm_mode_addfb2(struct drm_device *dev,
1453 void *data, struct drm_file *file_priv);
1454extern uint32_t drm_mode_legacy_fb_format(uint32_t bpp, uint32_t depth);
f453ba04
DA
1455extern int drm_mode_rmfb(struct drm_device *dev,
1456 void *data, struct drm_file *file_priv);
1457extern int drm_mode_getfb(struct drm_device *dev,
1458 void *data, struct drm_file *file_priv);
884840aa
JB
1459extern int drm_mode_dirtyfb_ioctl(struct drm_device *dev,
1460 void *data, struct drm_file *file_priv);
f453ba04
DA
1461
1462extern int drm_mode_getproperty_ioctl(struct drm_device *dev,
1463 void *data, struct drm_file *file_priv);
1464extern int drm_mode_getblob_ioctl(struct drm_device *dev,
1465 void *data, struct drm_file *file_priv);
e2f5d2ea
DS
1466extern int drm_mode_createblob_ioctl(struct drm_device *dev,
1467 void *data, struct drm_file *file_priv);
1468extern int drm_mode_destroyblob_ioctl(struct drm_device *dev,
1469 void *data, struct drm_file *file_priv);
f453ba04
DA
1470extern int drm_mode_connector_property_set_ioctl(struct drm_device *dev,
1471 void *data, struct drm_file *file_priv);
f453ba04
DA
1472extern int drm_mode_getencoder(struct drm_device *dev,
1473 void *data, struct drm_file *file_priv);
1474extern int drm_mode_gamma_get_ioctl(struct drm_device *dev,
1475 void *data, struct drm_file *file_priv);
1476extern int drm_mode_gamma_set_ioctl(struct drm_device *dev,
1477 void *data, struct drm_file *file_priv);
18316c8c 1478extern u8 drm_match_cea_mode(const struct drm_display_mode *to_match);
0967e6a5 1479extern enum hdmi_picture_aspect drm_get_cea_aspect_ratio(const u8 video_code);
f23c20c8 1480extern bool drm_detect_hdmi_monitor(struct edid *edid);
8fe9790d 1481extern bool drm_detect_monitor_audio(struct edid *edid);
b1edd6a6 1482extern bool drm_rgb_quant_range_selectable(struct edid *edid);
d91d8a3f
KH
1483extern int drm_mode_page_flip_ioctl(struct drm_device *dev,
1484 void *data, struct drm_file *file_priv);
f0fda0a4
ZY
1485extern int drm_add_modes_noedid(struct drm_connector *connector,
1486 int hdisplay, int vdisplay);
3cf70daf
GH
1487extern void drm_set_preferred_mode(struct drm_connector *connector,
1488 int hpref, int vpref);
3c537889 1489
051963d4 1490extern int drm_edid_header_is_valid(const u8 *raw_edid);
6ba2bd3d
TP
1491extern bool drm_edid_block_valid(u8 *raw_edid, int block, bool print_bad_edid,
1492 bool *edid_corrupt);
3c537889 1493extern bool drm_edid_is_valid(struct edid *edid);
138f9ebb
DA
1494
1495extern struct drm_tile_group *drm_mode_create_tile_group(struct drm_device *dev,
1496 char topology[8]);
1497extern struct drm_tile_group *drm_mode_get_tile_group(struct drm_device *dev,
1498 char topology[8]);
1499extern void drm_mode_put_tile_group(struct drm_device *dev,
1500 struct drm_tile_group *tg);
1d42bbc8 1501struct drm_display_mode *drm_mode_find_dmt(struct drm_device *dev,
f6e252ba
AJ
1502 int hsize, int vsize, int fresh,
1503 bool rb);
ff72145b
DA
1504
1505extern int drm_mode_create_dumb_ioctl(struct drm_device *dev,
1506 void *data, struct drm_file *file_priv);
1507extern int drm_mode_mmap_dumb_ioctl(struct drm_device *dev,
1508 void *data, struct drm_file *file_priv);
1509extern int drm_mode_destroy_dumb_ioctl(struct drm_device *dev,
1510 void *data, struct drm_file *file_priv);
c543188a
PZ
1511extern int drm_mode_obj_get_properties_ioctl(struct drm_device *dev, void *data,
1512 struct drm_file *file_priv);
1513extern int drm_mode_obj_set_property_ioctl(struct drm_device *dev, void *data,
1514 struct drm_file *file_priv);
3a5f87c2
TW
1515extern int drm_mode_plane_set_obj_prop(struct drm_plane *plane,
1516 struct drm_property *property,
1517 uint64_t value);
d34f20d6
RC
1518extern int drm_mode_atomic_ioctl(struct drm_device *dev,
1519 void *data, struct drm_file *file_priv);
248dbc23
DA
1520
1521extern void drm_fb_get_bpp_depth(uint32_t format, unsigned int *depth,
1522 int *bpp);
141670e9 1523extern int drm_format_num_planes(uint32_t format);
5a86bd55 1524extern int drm_format_plane_cpp(uint32_t format, int plane);
01b68b04
VS
1525extern int drm_format_horz_chroma_subsampling(uint32_t format);
1526extern int drm_format_vert_chroma_subsampling(uint32_t format);
d20d3174 1527extern const char *drm_get_format_name(uint32_t format);
c1df5f3c
VS
1528extern struct drm_property *drm_mode_create_rotation_property(struct drm_device *dev,
1529 unsigned int supported_rotations);
3c9855f6
VS
1530extern unsigned int drm_rotation_simplify(unsigned int rotation,
1531 unsigned int supported_rotations);
141670e9 1532
96f60e37 1533/* Helpers */
a2b34e22
RC
1534
1535static inline struct drm_plane *drm_plane_find(struct drm_device *dev,
1536 uint32_t id)
1537{
1538 struct drm_mode_object *mo;
1539 mo = drm_mode_object_find(dev, id, DRM_MODE_OBJECT_PLANE);
1540 return mo ? obj_to_plane(mo) : NULL;
1541}
1542
96f60e37
RK
1543static inline struct drm_crtc *drm_crtc_find(struct drm_device *dev,
1544 uint32_t id)
1545{
1546 struct drm_mode_object *mo;
1547 mo = drm_mode_object_find(dev, id, DRM_MODE_OBJECT_CRTC);
1548 return mo ? obj_to_crtc(mo) : NULL;
1549}
1550
1551static inline struct drm_encoder *drm_encoder_find(struct drm_device *dev,
1552 uint32_t id)
1553{
1554 struct drm_mode_object *mo;
1555 mo = drm_mode_object_find(dev, id, DRM_MODE_OBJECT_ENCODER);
1556 return mo ? obj_to_encoder(mo) : NULL;
1557}
1558
a2b34e22
RC
1559static inline struct drm_connector *drm_connector_find(struct drm_device *dev,
1560 uint32_t id)
1561{
1562 struct drm_mode_object *mo;
1563 mo = drm_mode_object_find(dev, id, DRM_MODE_OBJECT_CONNECTOR);
1564 return mo ? obj_to_connector(mo) : NULL;
1565}
1566
1567static inline struct drm_property *drm_property_find(struct drm_device *dev,
1568 uint32_t id)
1569{
1570 struct drm_mode_object *mo;
1571 mo = drm_mode_object_find(dev, id, DRM_MODE_OBJECT_PROPERTY);
1572 return mo ? obj_to_property(mo) : NULL;
1573}
1574
e27dde3e
MR
1575/* Plane list iterator for legacy (overlay only) planes. */
1576#define drm_for_each_legacy_plane(plane, planelist) \
1577 list_for_each_entry(plane, planelist, head) \
1578 if (plane->type == DRM_PLANE_TYPE_OVERLAY)
1579
f453ba04 1580#endif /* __DRM_CRTC_H__ */