blob: c459867ecb9ce9dd1cd25b544b28fbfeb13061a1 [file] [log] [blame]
Dave Airlief453ba02008-11-07 14:05:41 -08001/*
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>
Dave Airlief453ba02008-11-07 14:05:41 -080032#include <linux/fb.h>
Vandana Kannan985e5dc2013-12-19 15:34:07 +053033#include <linux/hdmi.h>
Boris Brezillonb5571e92014-07-22 12:09:10 +020034#include <linux/media-bus-format.h>
David Herrmannd7d2c482014-08-29 12:12:40 +020035#include <uapi/drm/drm_mode.h>
36#include <uapi/drm/drm_fourcc.h>
Rob Clark51fd3712013-11-19 12:10:12 -050037#include <drm/drm_modeset_lock.h>
Ville Syrjäläd7da8242016-07-26 19:06:57 +030038#include <drm/drm_rect.h>
Daniel Vetter7520a272016-08-15 16:07:02 +020039#include <drm/drm_modeset.h>
40#include <drm/drm_framebuffer.h>
41#include <drm/drm_modes.h>
Daniel Vetter52217192016-08-12 22:48:50 +020042#include <drm/drm_connector.h>
Daniel Vetter321a95a2016-08-29 10:27:49 +020043#include <drm/drm_encoder.h>
Jesse Barnes308e5bc2011-11-14 14:51:28 -080044
Dave Airlief453ba02008-11-07 14:05:41 -080045struct drm_device;
46struct drm_mode_set;
Thierry Reding595887e2012-11-21 15:00:47 +010047struct drm_file;
48struct drm_clip_rect;
Russell King7e435aa2014-06-15 11:07:12 +010049struct device_node;
Daniel Vettere2330f02014-10-29 11:34:56 +010050struct fence;
Daniel Vetter81065542016-06-21 10:54:13 +020051struct edid;
Dave Airlief453ba02008-11-07 14:05:41 -080052
Rob Clarkebc44cf2012-09-12 22:22:31 -050053static inline int64_t U642I64(uint64_t val)
54{
55 return (int64_t)*((int64_t *)&val);
56}
57static inline uint64_t I642U64(int64_t val)
58{
59 return (uint64_t)*((uint64_t *)&val);
60}
61
Robert Feketed9c38242015-11-02 16:14:08 +010062/*
63 * Rotation property bits. DRM_ROTATE_<degrees> rotates the image by the
64 * specified amount in degrees in counter clockwise direction. DRM_REFLECT_X and
65 * DRM_REFLECT_Y reflects the image along the specified axis prior to rotation
66 */
Joonas Lahtinen31ad61e2016-07-29 08:50:05 +030067#define DRM_ROTATE_0 BIT(0)
68#define DRM_ROTATE_90 BIT(1)
69#define DRM_ROTATE_180 BIT(2)
70#define DRM_ROTATE_270 BIT(3)
71#define DRM_ROTATE_MASK (DRM_ROTATE_0 | DRM_ROTATE_90 | \
72 DRM_ROTATE_180 | DRM_ROTATE_270)
73#define DRM_REFLECT_X BIT(4)
74#define DRM_REFLECT_Y BIT(5)
75#define DRM_REFLECT_MASK (DRM_REFLECT_X | DRM_REFLECT_Y)
Ville Syrjälä06596962014-07-08 10:31:51 +053076
Dave Airlie138f9eb2014-10-20 16:17:17 +100077/* data corresponds to displayid vend/prod/serial */
78struct drm_tile_group {
79 struct kref refcount;
80 struct drm_device *dev;
81 int id;
82 u8 group_data[8];
83};
84
Dave Airlief453ba02008-11-07 14:05:41 -080085struct drm_property_blob {
86 struct drm_mode_object base;
Daniel Stone6bcacf52015-04-20 19:22:55 +010087 struct drm_device *dev;
Daniel Stonee2f5d2e2015-05-22 13:34:51 +010088 struct list_head head_global;
89 struct list_head head_file;
Thierry Redingecbbe592014-05-13 11:36:13 +020090 size_t length;
Ville Syrjäläd63f5e62012-03-13 12:35:49 +020091 unsigned char data[];
Dave Airlief453ba02008-11-07 14:05:41 -080092};
93
94struct drm_property_enum {
95 uint64_t value;
96 struct list_head head;
97 char name[DRM_PROP_NAME_LEN];
98};
99
100struct drm_property {
101 struct list_head head;
102 struct drm_mode_object base;
103 uint32_t flags;
104 char name[DRM_PROP_NAME_LEN];
105 uint32_t num_values;
106 uint64_t *values;
Rob Clark98f75de2014-05-30 11:37:03 -0400107 struct drm_device *dev;
Dave Airlief453ba02008-11-07 14:05:41 -0800108
Daniel Vetter3758b342014-11-19 18:38:10 +0100109 struct list_head enum_list;
Dave Airlief453ba02008-11-07 14:05:41 -0800110};
111
112struct drm_crtc;
Dave Airlief453ba02008-11-07 14:05:41 -0800113struct drm_encoder;
Kristian Høgsbergd91d8a32009-11-17 12:43:55 -0500114struct drm_pending_vblank_event;
Jesse Barnes8cf5c912011-11-14 14:51:27 -0800115struct drm_plane;
Sean Paul3b336ec2013-08-14 16:47:37 -0400116struct drm_bridge;
Daniel Vetter144ecb92014-10-27 20:28:44 +0100117struct drm_atomic_state;
118
Daniel Vetter4490d4c2015-12-04 09:45:45 +0100119struct drm_crtc_helper_funcs;
120struct drm_encoder_helper_funcs;
Daniel Vetter4490d4c2015-12-04 09:45:45 +0100121struct drm_plane_helper_funcs;
122
Daniel Vetter144ecb92014-10-27 20:28:44 +0100123/**
Daniel Vettercc4ceb42014-07-25 21:30:38 +0200124 * struct drm_crtc_state - mutable CRTC state
Daniel Vetter07cc0ef2014-11-27 15:49:39 +0100125 * @crtc: backpointer to the CRTC
Daniel Vetter144ecb92014-10-27 20:28:44 +0100126 * @enable: whether the CRTC should be enabled, gates all other state
Daniel Vetterd9b13622014-11-26 16:57:41 +0100127 * @active: whether the CRTC is actively displaying (used for DPMS)
Maarten Lankhorstfc596662015-07-21 13:28:57 +0200128 * @planes_changed: planes on this crtc are updated
129 * @mode_changed: crtc_state->mode or crtc_state->enable has been changed
130 * @active_changed: crtc_state->active has been toggled.
131 * @connectors_changed: connectors to this crtc have been updated
Marek Szyprowski44d1240d2016-06-13 11:11:26 +0200132 * @zpos_changed: zpos values of planes on this crtc have been updated
Lionel Landwerlin5488dc12016-02-26 17:05:00 +0000133 * @color_mgmt_changed: color management properties have changed (degamma or
134 * gamma LUT or CSC matrix)
Rob Clark6ddd3882014-11-21 15:28:31 -0500135 * @plane_mask: bitmask of (1 << drm_plane_index(plane)) of attached planes
Maarten Lankhorst4cd9fa52016-01-04 12:53:18 +0100136 * @connector_mask: bitmask of (1 << drm_connector_index(connector)) of attached connectors
Maarten Lankhorste87a52b2016-01-28 15:04:58 +0100137 * @encoder_mask: bitmask of (1 << drm_encoder_index(encoder)) of attached encoders
Daniel Vetter623369e2014-09-16 17:50:47 +0200138 * @last_vblank_count: for helpers and drivers to capture the vblank of the
139 * update to ensure framebuffer cleanup isn't done too early
Daniel Vetter2f324b42014-10-29 11:13:47 +0100140 * @adjusted_mode: for use by helpers and drivers to compute adjusted mode timings
Daniel Vetter144ecb92014-10-27 20:28:44 +0100141 * @mode: current mode timings
Daniel Vetterac3ba4a2016-05-31 23:11:10 +0200142 * @mode_blob: &drm_property_blob for @mode
Lionel Landwerlin5488dc12016-02-26 17:05:00 +0000143 * @degamma_lut: Lookup table for converting framebuffer pixel data
144 * before apply the conversion matrix
145 * @ctm: Transformation matrix
146 * @gamma_lut: Lookup table for converting pixel data after the
147 * conversion matrix
Daniel Vetter144ecb92014-10-27 20:28:44 +0100148 * @event: optional pointer to a DRM event to signal upon completion of the
149 * state update
150 * @state: backpointer to global drm_atomic_state
Daniel Vetterd9b13622014-11-26 16:57:41 +0100151 *
152 * Note that the distinction between @enable and @active is rather subtile:
153 * Flipping @active while @enable is set without changing anything else may
154 * never return in a failure from the ->atomic_check callback. Userspace assumes
155 * that a DPMS On will always succeed. In other words: @enable controls resource
156 * assignment, @active controls the actual hardware state.
Daniel Vetter144ecb92014-10-27 20:28:44 +0100157 */
158struct drm_crtc_state {
Daniel Vetter07cc0ef2014-11-27 15:49:39 +0100159 struct drm_crtc *crtc;
160
Daniel Vettercc4ceb42014-07-25 21:30:38 +0200161 bool enable;
Daniel Vetterd9b13622014-11-26 16:57:41 +0100162 bool active;
Daniel Vetter144ecb92014-10-27 20:28:44 +0100163
Daniel Vetterc2fcd272014-11-05 00:14:14 +0100164 /* computed state bits used by helpers and drivers */
165 bool planes_changed : 1;
Daniel Vetter623369e2014-09-16 17:50:47 +0200166 bool mode_changed : 1;
Daniel Vettereab3bbe2015-01-22 16:36:21 +0100167 bool active_changed : 1;
Maarten Lankhorstfc596662015-07-21 13:28:57 +0200168 bool connectors_changed : 1;
Marek Szyprowski44d1240d2016-06-13 11:11:26 +0200169 bool zpos_changed : 1;
Lionel Landwerlin5488dc12016-02-26 17:05:00 +0000170 bool color_mgmt_changed : 1;
Daniel Vetter623369e2014-09-16 17:50:47 +0200171
Rob Clark6ddd3882014-11-21 15:28:31 -0500172 /* attached planes bitmask:
173 * WARNING: transitional helpers do not maintain plane_mask so
174 * drivers not converted over to atomic helpers should not rely
175 * on plane_mask being accurate!
176 */
177 u32 plane_mask;
178
Maarten Lankhorst4cd9fa52016-01-04 12:53:18 +0100179 u32 connector_mask;
Maarten Lankhorste87a52b2016-01-28 15:04:58 +0100180 u32 encoder_mask;
Maarten Lankhorst4cd9fa52016-01-04 12:53:18 +0100181
Daniel Vetter623369e2014-09-16 17:50:47 +0200182 /* last_vblank_count: for vblank waits before cleanup */
183 u32 last_vblank_count;
Daniel Vetterc2fcd272014-11-05 00:14:14 +0100184
Daniel Vetter2f324b42014-10-29 11:13:47 +0100185 /* adjusted_mode: for use by helpers and drivers */
186 struct drm_display_mode adjusted_mode;
187
Daniel Vetter144ecb92014-10-27 20:28:44 +0100188 struct drm_display_mode mode;
189
Daniel Stone99cf4a22015-05-25 19:11:51 +0100190 /* blob property to expose current mode to atomic userspace */
191 struct drm_property_blob *mode_blob;
192
Lionel Landwerlin5488dc12016-02-26 17:05:00 +0000193 /* blob property to expose color management to userspace */
194 struct drm_property_blob *degamma_lut;
195 struct drm_property_blob *ctm;
196 struct drm_property_blob *gamma_lut;
197
Daniel Vetter144ecb92014-10-27 20:28:44 +0100198 struct drm_pending_vblank_event *event;
199
200 struct drm_atomic_state *state;
201};
Dave Airlief453ba02008-11-07 14:05:41 -0800202
203/**
Daniel Vetter3bf04012014-10-27 16:54:27 +0100204 * struct drm_crtc_funcs - control CRTCs for a given device
Dave Airlief453ba02008-11-07 14:05:41 -0800205 *
206 * The drm_crtc_funcs structure is the central CRTC management structure
207 * in the DRM. Each CRTC controls one or more connectors (note that the name
208 * CRTC is simply historical, a CRTC may control LVDS, VGA, DVI, TV out, etc.
209 * connectors, not just CRTs).
210 *
211 * Each driver is responsible for filling out this structure at startup time,
212 * in addition to providing other modesetting features, like i2c and DDC
213 * bus accessors.
214 */
215struct drm_crtc_funcs {
Daniel Vetter88548632015-12-04 09:45:48 +0100216 /**
217 * @reset:
218 *
219 * Reset CRTC hardware and software state to off. This function isn't
220 * called by the core directly, only through drm_mode_config_reset().
221 * It's not a helper hook only for historical reasons.
222 *
223 * Atomic drivers can use drm_atomic_helper_crtc_reset() to reset
224 * atomic state using this hook.
225 */
Chris Wilsoneb033552011-01-24 15:11:08 +0000226 void (*reset)(struct drm_crtc *crtc);
Dave Airlief453ba02008-11-07 14:05:41 -0800227
Daniel Vetterf6da8c62015-12-04 09:46:00 +0100228 /**
229 * @cursor_set:
230 *
231 * Update the cursor image. The cursor position is relative to the CRTC
232 * and can be partially or fully outside of the visible area.
233 *
234 * Note that contrary to all other KMS functions the legacy cursor entry
235 * points don't take a framebuffer object, but instead take directly a
236 * raw buffer object id from the driver's buffer manager (which is
237 * either GEM or TTM for current drivers).
238 *
239 * This entry point is deprecated, drivers should instead implement
240 * universal plane support and register a proper cursor plane using
241 * drm_crtc_init_with_planes().
242 *
243 * This callback is optional
244 *
245 * RETURNS:
246 *
247 * 0 on success or a negative error code on failure.
248 */
Dave Airlief453ba02008-11-07 14:05:41 -0800249 int (*cursor_set)(struct drm_crtc *crtc, struct drm_file *file_priv,
250 uint32_t handle, uint32_t width, uint32_t height);
Daniel Vetterf6da8c62015-12-04 09:46:00 +0100251
252 /**
253 * @cursor_set2:
254 *
255 * Update the cursor image, including hotspot information. The hotspot
256 * must not affect the cursor position in CRTC coordinates, but is only
257 * meant as a hint for virtualized display hardware to coordinate the
258 * guests and hosts cursor position. The cursor hotspot is relative to
259 * the cursor image. Otherwise this works exactly like @cursor_set.
260 *
261 * This entry point is deprecated, drivers should instead implement
262 * universal plane support and register a proper cursor plane using
263 * drm_crtc_init_with_planes().
264 *
265 * This callback is optional.
266 *
267 * RETURNS:
268 *
269 * 0 on success or a negative error code on failure.
270 */
Dave Airlie4c813d42013-06-20 11:48:52 +1000271 int (*cursor_set2)(struct drm_crtc *crtc, struct drm_file *file_priv,
272 uint32_t handle, uint32_t width, uint32_t height,
273 int32_t hot_x, int32_t hot_y);
Daniel Vetterf6da8c62015-12-04 09:46:00 +0100274
275 /**
276 * @cursor_move:
277 *
278 * Update the cursor position. The cursor does not need to be visible
279 * when this hook is called.
280 *
281 * This entry point is deprecated, drivers should instead implement
282 * universal plane support and register a proper cursor plane using
283 * drm_crtc_init_with_planes().
284 *
285 * This callback is optional.
286 *
287 * RETURNS:
288 *
289 * 0 on success or a negative error code on failure.
290 */
Dave Airlief453ba02008-11-07 14:05:41 -0800291 int (*cursor_move)(struct drm_crtc *crtc, int x, int y);
292
Daniel Vetterf6da8c62015-12-04 09:46:00 +0100293 /**
294 * @gamma_set:
295 *
296 * Set gamma on the CRTC.
297 *
298 * This callback is optional.
299 *
300 * NOTE:
301 *
302 * Drivers that support gamma tables and also fbdev emulation through
303 * the provided helper library need to take care to fill out the gamma
304 * hooks for both. Currently there's a bit an unfortunate duplication
305 * going on, which should eventually be unified to just one set of
306 * hooks.
307 */
Maarten Lankhorst7ea77282016-06-07 12:49:30 +0200308 int (*gamma_set)(struct drm_crtc *crtc, u16 *r, u16 *g, u16 *b,
309 uint32_t size);
Daniel Vetter88548632015-12-04 09:45:48 +0100310
311 /**
312 * @destroy:
313 *
314 * Clean up plane resources. This is only called at driver unload time
315 * through drm_mode_config_cleanup() since a CRTC cannot be hotplugged
316 * in DRM.
317 */
Dave Airlief453ba02008-11-07 14:05:41 -0800318 void (*destroy)(struct drm_crtc *crtc);
319
Daniel Vetterf6da8c62015-12-04 09:46:00 +0100320 /**
321 * @set_config:
322 *
323 * This is the main legacy entry point to change the modeset state on a
324 * CRTC. All the details of the desired configuration are passed in a
325 * struct &drm_mode_set - see there for details.
326 *
327 * Drivers implementing atomic modeset should use
328 * drm_atomic_helper_set_config() to implement this hook.
329 *
330 * RETURNS:
331 *
332 * 0 on success or a negative error code on failure.
333 */
Dave Airlief453ba02008-11-07 14:05:41 -0800334 int (*set_config)(struct drm_mode_set *set);
Kristian Høgsbergd91d8a32009-11-17 12:43:55 -0500335
Daniel Vetterf6da8c62015-12-04 09:46:00 +0100336 /**
337 * @page_flip:
338 *
339 * Legacy entry point to schedule a flip to the given framebuffer.
340 *
341 * Page flipping is a synchronization mechanism that replaces the frame
342 * buffer being scanned out by the CRTC with a new frame buffer during
343 * vertical blanking, avoiding tearing (except when requested otherwise
344 * through the DRM_MODE_PAGE_FLIP_ASYNC flag). When an application
345 * requests a page flip the DRM core verifies that the new frame buffer
346 * is large enough to be scanned out by the CRTC in the currently
347 * configured mode and then calls the CRTC ->page_flip() operation with a
348 * pointer to the new frame buffer.
349 *
350 * The driver must wait for any pending rendering to the new framebuffer
351 * to complete before executing the flip. It should also wait for any
352 * pending rendering from other drivers if the underlying buffer is a
353 * shared dma-buf.
354 *
355 * An application can request to be notified when the page flip has
356 * completed. The drm core will supply a struct &drm_event in the event
357 * parameter in this case. This can be handled by the
358 * drm_crtc_send_vblank_event() function, which the driver should call on
359 * the provided event upon completion of the flip. Note that if
360 * the driver supports vblank signalling and timestamping the vblank
361 * counters and timestamps must agree with the ones returned from page
362 * flip events. With the current vblank helper infrastructure this can
363 * be achieved by holding a vblank reference while the page flip is
364 * pending, acquired through drm_crtc_vblank_get() and released with
365 * drm_crtc_vblank_put(). Drivers are free to implement their own vblank
366 * counter and timestamp tracking though, e.g. if they have accurate
367 * timestamp registers in hardware.
368 *
Daniel Vetterf6da8c62015-12-04 09:46:00 +0100369 * This callback is optional.
370 *
371 * NOTE:
372 *
373 * Very early versions of the KMS ABI mandated that the driver must
374 * block (but not reject) any rendering to the old framebuffer until the
375 * flip operation has completed and the old framebuffer is no longer
376 * visible. This requirement has been lifted, and userspace is instead
377 * expected to request delivery of an event and wait with recycling old
378 * buffers until such has been received.
379 *
380 * RETURNS:
381 *
382 * 0 on success or a negative error code on failure. Note that if a
383 * ->page_flip() operation is already pending the callback should return
384 * -EBUSY. Pageflips on a disabled CRTC (either by setting a NULL mode
385 * or just runtime disabled through DPMS respectively the new atomic
Daniel Vetter4cba6852015-12-08 09:49:20 +0100386 * "ACTIVE" state) should result in an -EINVAL error code. Note that
387 * drm_atomic_helper_page_flip() checks this already for atomic drivers.
Kristian Høgsbergd91d8a32009-11-17 12:43:55 -0500388 */
389 int (*page_flip)(struct drm_crtc *crtc,
390 struct drm_framebuffer *fb,
Keith Packarded8d1972013-07-22 18:49:58 -0700391 struct drm_pending_vblank_event *event,
392 uint32_t flags);
Paulo Zanonibffd9de02012-05-15 18:09:05 -0300393
Daniel Vetter88548632015-12-04 09:45:48 +0100394 /**
395 * @set_property:
396 *
397 * This is the legacy entry point to update a property attached to the
398 * CRTC.
399 *
400 * Drivers implementing atomic modeset should use
401 * drm_atomic_helper_crtc_set_property() to implement this hook.
402 *
403 * This callback is optional if the driver does not support any legacy
404 * driver-private properties.
405 *
406 * RETURNS:
407 *
408 * 0 on success or a negative error code on failure.
409 */
Paulo Zanonibffd9de02012-05-15 18:09:05 -0300410 int (*set_property)(struct drm_crtc *crtc,
411 struct drm_property *property, uint64_t val);
Daniel Vetter144ecb92014-10-27 20:28:44 +0100412
Daniel Vetter88548632015-12-04 09:45:48 +0100413 /**
414 * @atomic_duplicate_state:
415 *
416 * Duplicate the current atomic state for this CRTC and return it.
417 * The core and helpers gurantee that any atomic state duplicated with
418 * this hook and still owned by the caller (i.e. not transferred to the
419 * driver by calling ->atomic_commit() from struct
420 * &drm_mode_config_funcs) will be cleaned up by calling the
421 * @atomic_destroy_state hook in this structure.
422 *
423 * Atomic drivers which don't subclass struct &drm_crtc should use
424 * drm_atomic_helper_crtc_duplicate_state(). Drivers that subclass the
425 * state structure to extend it with driver-private state should use
426 * __drm_atomic_helper_crtc_duplicate_state() to make sure shared state is
427 * duplicated in a consistent fashion across drivers.
428 *
429 * It is an error to call this hook before crtc->state has been
430 * initialized correctly.
431 *
432 * NOTE:
433 *
434 * If the duplicate state references refcounted resources this hook must
435 * acquire a reference for each of them. The driver must release these
436 * references again in @atomic_destroy_state.
437 *
438 * RETURNS:
439 *
440 * Duplicated atomic state or NULL when the allocation failed.
441 */
Daniel Vetter144ecb92014-10-27 20:28:44 +0100442 struct drm_crtc_state *(*atomic_duplicate_state)(struct drm_crtc *crtc);
Daniel Vetter88548632015-12-04 09:45:48 +0100443
444 /**
445 * @atomic_destroy_state:
446 *
447 * Destroy a state duplicated with @atomic_duplicate_state and release
448 * or unreference all resources it references
449 */
Daniel Vetter144ecb92014-10-27 20:28:44 +0100450 void (*atomic_destroy_state)(struct drm_crtc *crtc,
Daniel Vettercc4ceb42014-07-25 21:30:38 +0200451 struct drm_crtc_state *state);
Daniel Vetter88548632015-12-04 09:45:48 +0100452
453 /**
454 * @atomic_set_property:
455 *
456 * Decode a driver-private property value and store the decoded value
457 * into the passed-in state structure. Since the atomic core decodes all
458 * standardized properties (even for extensions beyond the core set of
459 * properties which might not be implemented by all drivers) this
460 * requires drivers to subclass the state structure.
461 *
462 * Such driver-private properties should really only be implemented for
463 * truly hardware/vendor specific state. Instead it is preferred to
464 * standardize atomic extension and decode the properties used to expose
465 * such an extension in the core.
466 *
467 * Do not call this function directly, use
468 * drm_atomic_crtc_set_property() instead.
469 *
470 * This callback is optional if the driver does not support any
471 * driver-private atomic properties.
472 *
473 * NOTE:
474 *
475 * This function is called in the state assembly phase of atomic
476 * modesets, which can be aborted for any reason (including on
477 * userspace's request to just check whether a configuration would be
478 * possible). Drivers MUST NOT touch any persistent state (hardware or
479 * software) or data structures except the passed in @state parameter.
480 *
481 * Also since userspace controls in which order properties are set this
482 * function must not do any input validation (since the state update is
483 * incomplete and hence likely inconsistent). Instead any such input
484 * validation must be done in the various atomic_check callbacks.
485 *
486 * RETURNS:
487 *
488 * 0 if the property has been found, -EINVAL if the property isn't
489 * implemented by the driver (which should never happen, the core only
490 * asks for properties attached to this CRTC). No other validation is
491 * allowed by the driver. The core already checks that the property
492 * value is within the range (integer, valid enum value, ...) the driver
493 * set when registering the property.
494 */
Daniel Vetter144ecb92014-10-27 20:28:44 +0100495 int (*atomic_set_property)(struct drm_crtc *crtc,
496 struct drm_crtc_state *state,
497 struct drm_property *property,
498 uint64_t val);
Daniel Vetter88548632015-12-04 09:45:48 +0100499 /**
500 * @atomic_get_property:
501 *
502 * Reads out the decoded driver-private property. This is used to
Daniel Vetterc6b0ca32015-12-04 09:46:01 +0100503 * implement the GETCRTC IOCTL.
Daniel Vetter88548632015-12-04 09:45:48 +0100504 *
505 * Do not call this function directly, use
506 * drm_atomic_crtc_get_property() instead.
507 *
508 * This callback is optional if the driver does not support any
509 * driver-private atomic properties.
510 *
511 * RETURNS:
512 *
513 * 0 on success, -EINVAL if the property isn't implemented by the
514 * driver (which should never happen, the core only asks for
515 * properties attached to this CRTC).
516 */
Rob Clarkac9c9252014-12-18 16:01:47 -0500517 int (*atomic_get_property)(struct drm_crtc *crtc,
518 const struct drm_crtc_state *state,
519 struct drm_property *property,
520 uint64_t *val);
Benjamin Gaignard79190ea2016-06-21 16:37:09 +0200521
522 /**
523 * @late_register:
524 *
525 * This optional hook can be used to register additional userspace
526 * interfaces attached to the crtc like debugfs interfaces.
527 * It is called late in the driver load sequence from drm_dev_register().
528 * Everything added from this callback should be unregistered in
529 * the early_unregister callback.
530 *
531 * Returns:
532 *
533 * 0 on success, or a negative error code on failure.
534 */
535 int (*late_register)(struct drm_crtc *crtc);
536
537 /**
538 * @early_unregister:
539 *
540 * This optional hook should be used to unregister the additional
541 * userspace interfaces attached to the crtc from
542 * late_unregister(). It is called from drm_dev_unregister(),
543 * early in the driver unload sequence to disable userspace access
544 * before data structures are torndown.
545 */
546 void (*early_unregister)(struct drm_crtc *crtc);
Dave Airlief453ba02008-11-07 14:05:41 -0800547};
548
549/**
Daniel Vetter3bf04012014-10-27 16:54:27 +0100550 * struct drm_crtc - central CRTC control structure
Jesse Barnes77491632011-11-07 12:03:14 -0800551 * @dev: parent DRM device
Daniel Vetter2c0c33d2014-10-27 20:19:38 +0100552 * @port: OF node used by drm_of_find_possible_crtcs()
Jesse Barnes77491632011-11-07 12:03:14 -0800553 * @head: list management
Daniel Vetterac3ba4a2016-05-31 23:11:10 +0200554 * @name: human readable name, can be overwritten by the driver
Rob Clark51fd3712013-11-19 12:10:12 -0500555 * @mutex: per-CRTC locking
Jesse Barnes77491632011-11-07 12:03:14 -0800556 * @base: base KMS object for ID tracking etc.
Matt Ropere13161a2014-04-01 15:22:38 -0700557 * @primary: primary plane for this CRTC
558 * @cursor: cursor plane for this CRTC
Daniel Vetter2c0c33d2014-10-27 20:19:38 +0100559 * @cursor_x: current x position of the cursor, used for universal cursor planes
560 * @cursor_y: current y position of the cursor, used for universal cursor planes
Dave Airlief453ba02008-11-07 14:05:41 -0800561 * @enabled: is this CRTC enabled?
Jesse Barnes77491632011-11-07 12:03:14 -0800562 * @mode: current mode timings
563 * @hwmode: mode timings as programmed to hw regs
Dave Airlief453ba02008-11-07 14:05:41 -0800564 * @x: x position on screen
565 * @y: y position on screen
Dave Airlief453ba02008-11-07 14:05:41 -0800566 * @funcs: CRTC control functions
Jesse Barnes77491632011-11-07 12:03:14 -0800567 * @gamma_size: size of gamma ramp
568 * @gamma_store: gamma ramp values
Jesse Barnes77491632011-11-07 12:03:14 -0800569 * @helper_private: mid-layer private data
Paulo Zanonibffd9de02012-05-15 18:09:05 -0300570 * @properties: property tracking for this CRTC
Dave Airlief453ba02008-11-07 14:05:41 -0800571 *
572 * Each CRTC may have one or more connectors associated with it. This structure
573 * allows the CRTC to be controlled.
574 */
575struct drm_crtc {
576 struct drm_device *dev;
Russell King7e435aa2014-06-15 11:07:12 +0100577 struct device_node *port;
Dave Airlief453ba02008-11-07 14:05:41 -0800578 struct list_head head;
579
Ville Syrjäläfa3ab4c2015-12-08 18:41:53 +0200580 char *name;
581
Daniel Vetterac3ba4a2016-05-31 23:11:10 +0200582 /**
583 * @mutex:
Daniel Vetter29494c12012-12-02 02:18:25 +0100584 *
585 * This provides a read lock for the overall crtc state (mode, dpms
586 * state, ...) and a write lock for everything which can be update
Daniel Vetterac3ba4a2016-05-31 23:11:10 +0200587 * without a full modeset (fb, cursor data, crtc properties ...). Full
588 * modeset also need to grab dev->mode_config.connection_mutex.
Daniel Vetter29494c12012-12-02 02:18:25 +0100589 */
Rob Clark51fd3712013-11-19 12:10:12 -0500590 struct drm_modeset_lock mutex;
Daniel Vetter29494c12012-12-02 02:18:25 +0100591
Dave Airlief453ba02008-11-07 14:05:41 -0800592 struct drm_mode_object base;
593
Matt Ropere13161a2014-04-01 15:22:38 -0700594 /* primary and cursor planes for CRTC */
595 struct drm_plane *primary;
596 struct drm_plane *cursor;
597
Daniel Vetter96094082016-07-15 21:47:59 +0200598 /**
599 * @index: Position inside the mode_config.list, can be used as an array
600 * index. It is invariant over the lifetime of the CRTC.
601 */
Chris Wilson490d3d12016-05-27 20:05:00 +0100602 unsigned index;
603
Matt Roper161d0dc2014-06-10 08:28:10 -0700604 /* position of cursor plane on crtc */
605 int cursor_x;
606 int cursor_y;
607
Dave Airlief453ba02008-11-07 14:05:41 -0800608 bool enabled;
609
Mario Kleiner27641c32010-10-23 04:20:23 +0200610 /* Requested mode from modesetting. */
Dave Airlief453ba02008-11-07 14:05:41 -0800611 struct drm_display_mode mode;
612
Mario Kleiner27641c32010-10-23 04:20:23 +0200613 /* Programmed mode in hw, after adjustments for encoders,
614 * crtc, panel scaling etc. Needed for timestamping etc.
615 */
616 struct drm_display_mode hwmode;
617
Dave Airlief453ba02008-11-07 14:05:41 -0800618 int x, y;
Dave Airlief453ba02008-11-07 14:05:41 -0800619 const struct drm_crtc_funcs *funcs;
620
Lionel Landwerlin5488dc12016-02-26 17:05:00 +0000621 /* Legacy FB CRTC gamma size for reporting to userspace */
Dave Airlief453ba02008-11-07 14:05:41 -0800622 uint32_t gamma_size;
623 uint16_t *gamma_store;
624
625 /* if you are using the helper */
Daniel Vetter4490d4c2015-12-04 09:45:45 +0100626 const struct drm_crtc_helper_funcs *helper_private;
Paulo Zanonibffd9de02012-05-15 18:09:05 -0300627
628 struct drm_object_properties properties;
Daniel Vetterd059f652014-07-25 18:07:40 +0200629
Daniel Vetter3b24f7d2016-06-08 14:19:00 +0200630 /**
631 * @state:
632 *
633 * Current atomic state for this CRTC.
634 */
Daniel Vetter144ecb92014-10-27 20:28:44 +0100635 struct drm_crtc_state *state;
636
Daniel Vetter3b24f7d2016-06-08 14:19:00 +0200637 /**
638 * @commit_list:
639 *
640 * List of &drm_crtc_commit structures tracking pending commits.
641 * Protected by @commit_lock. This list doesn't hold its own full
642 * reference, but burrows it from the ongoing commit. Commit entries
643 * must be removed from this list once the commit is fully completed,
644 * but before it's correspoding &drm_atomic_state gets destroyed.
645 */
646 struct list_head commit_list;
647
648 /**
649 * @commit_lock:
650 *
651 * Spinlock to protect @commit_list.
652 */
653 spinlock_t commit_lock;
654
655 /**
656 * @acquire_ctx:
657 *
658 * Per-CRTC implicit acquire context used by atomic drivers for legacy
659 * IOCTLs, so that atomic drivers can get at the locking acquire
660 * context.
Daniel Vetterd059f652014-07-25 18:07:40 +0200661 */
662 struct drm_modeset_acquire_ctx *acquire_ctx;
Dave Airlief453ba02008-11-07 14:05:41 -0800663};
664
Daniel Vetter144ecb92014-10-27 20:28:44 +0100665/**
Daniel Vetter144ecb92014-10-27 20:28:44 +0100666 * struct drm_plane_state - mutable plane state
Daniel Vetter07cc0ef2014-11-27 15:49:39 +0100667 * @plane: backpointer to the plane
Daniel Vetter144ecb92014-10-27 20:28:44 +0100668 * @crtc: currently bound CRTC, NULL if disabled
Daniel Vettercc4ceb42014-07-25 21:30:38 +0200669 * @fb: currently bound framebuffer
Daniel Vettere2330f02014-10-29 11:34:56 +0100670 * @fence: optional fence to wait for before scanning out @fb
Daniel Vetter144ecb92014-10-27 20:28:44 +0100671 * @crtc_x: left position of visible portion of plane on crtc
672 * @crtc_y: upper position of visible portion of plane on crtc
673 * @crtc_w: width of visible portion of plane on crtc
674 * @crtc_h: height of visible portion of plane on crtc
675 * @src_x: left position of visible portion of plane within
676 * plane (in 16.16)
677 * @src_y: upper position of visible portion of plane within
678 * plane (in 16.16)
679 * @src_w: width of visible portion of plane (in 16.16)
680 * @src_h: height of visible portion of plane (in 16.16)
Daniel Vetterac3ba4a2016-05-31 23:11:10 +0200681 * @rotation: rotation of the plane
Marek Szyprowski44d1240d2016-06-13 11:11:26 +0200682 * @zpos: priority of the given plane on crtc (optional)
683 * @normalized_zpos: normalized value of zpos: unique, range from 0 to N-1
684 * where N is the number of active planes for given crtc
Ville Syrjäläd7da8242016-07-26 19:06:57 +0300685 * @src: clipped source coordinates of the plane (in 16.16)
686 * @dst: clipped destination coordinates of the plane
687 * @visible: visibility of the plane
Daniel Vetter144ecb92014-10-27 20:28:44 +0100688 * @state: backpointer to global drm_atomic_state
689 */
690struct drm_plane_state {
Daniel Vetter07cc0ef2014-11-27 15:49:39 +0100691 struct drm_plane *plane;
692
Rob Clark6ddd3882014-11-21 15:28:31 -0500693 struct drm_crtc *crtc; /* do not write directly, use drm_atomic_set_crtc_for_plane() */
694 struct drm_framebuffer *fb; /* do not write directly, use drm_atomic_set_fb_for_plane() */
Daniel Vettere2330f02014-10-29 11:34:56 +0100695 struct fence *fence;
Daniel Vetter144ecb92014-10-27 20:28:44 +0100696
697 /* Signed dest location allows it to be partially off screen */
698 int32_t crtc_x, crtc_y;
699 uint32_t crtc_w, crtc_h;
700
701 /* Source values are 16.16 fixed point */
702 uint32_t src_x, src_y;
703 uint32_t src_h, src_w;
704
Matt Roper1da30622015-01-21 16:35:40 -0800705 /* Plane rotation */
706 unsigned int rotation;
707
Marek Szyprowski44d1240d2016-06-13 11:11:26 +0200708 /* Plane zpos */
709 unsigned int zpos;
710 unsigned int normalized_zpos;
711
Ville Syrjäläd7da8242016-07-26 19:06:57 +0300712 /* Clipped coordinates */
713 struct drm_rect src, dst;
714
715 /*
716 * Is the plane actually visible? Can be false even
717 * if fb!=NULL and crtc!=NULL, due to clipping.
718 */
719 bool visible;
720
Daniel Vetter144ecb92014-10-27 20:28:44 +0100721 struct drm_atomic_state *state;
722};
723
724
725/**
Daniel Vetter3bf04012014-10-27 16:54:27 +0100726 * struct drm_plane_funcs - driver plane control functions
Jesse Barnes8cf5c912011-11-14 14:51:27 -0800727 */
728struct drm_plane_funcs {
Daniel Vetter88548632015-12-04 09:45:48 +0100729 /**
730 * @update_plane:
731 *
732 * This is the legacy entry point to enable and configure the plane for
733 * the given CRTC and framebuffer. It is never called to disable the
734 * plane, i.e. the passed-in crtc and fb paramters are never NULL.
735 *
736 * The source rectangle in frame buffer memory coordinates is given by
737 * the src_x, src_y, src_w and src_h parameters (as 16.16 fixed point
738 * values). Devices that don't support subpixel plane coordinates can
739 * ignore the fractional part.
740 *
741 * The destination rectangle in CRTC coordinates is given by the
742 * crtc_x, crtc_y, crtc_w and crtc_h parameters (as integer values).
743 * Devices scale the source rectangle to the destination rectangle. If
744 * scaling is not supported, and the source rectangle size doesn't match
745 * the destination rectangle size, the driver must return a
746 * -<errorname>EINVAL</errorname> error.
747 *
748 * Drivers implementing atomic modeset should use
749 * drm_atomic_helper_update_plane() to implement this hook.
750 *
751 * RETURNS:
752 *
753 * 0 on success or a negative error code on failure.
754 */
Jesse Barnes8cf5c912011-11-14 14:51:27 -0800755 int (*update_plane)(struct drm_plane *plane,
756 struct drm_crtc *crtc, struct drm_framebuffer *fb,
757 int crtc_x, int crtc_y,
758 unsigned int crtc_w, unsigned int crtc_h,
759 uint32_t src_x, uint32_t src_y,
760 uint32_t src_w, uint32_t src_h);
Daniel Vetter88548632015-12-04 09:45:48 +0100761
762 /**
763 * @disable_plane:
764 *
765 * This is the legacy entry point to disable the plane. The DRM core
Daniel Vetterc6b0ca32015-12-04 09:46:01 +0100766 * calls this method in response to a DRM_IOCTL_MODE_SETPLANE IOCTL call
Daniel Vetter88548632015-12-04 09:45:48 +0100767 * with the frame buffer ID set to 0. Disabled planes must not be
768 * processed by the CRTC.
769 *
770 * Drivers implementing atomic modeset should use
771 * drm_atomic_helper_disable_plane() to implement this hook.
772 *
773 * RETURNS:
774 *
775 * 0 on success or a negative error code on failure.
776 */
Jesse Barnes8cf5c912011-11-14 14:51:27 -0800777 int (*disable_plane)(struct drm_plane *plane);
Daniel Vetter88548632015-12-04 09:45:48 +0100778
779 /**
780 * @destroy:
781 *
782 * Clean up plane resources. This is only called at driver unload time
783 * through drm_mode_config_cleanup() since a plane cannot be hotplugged
784 * in DRM.
785 */
Jesse Barnes8cf5c912011-11-14 14:51:27 -0800786 void (*destroy)(struct drm_plane *plane);
Daniel Vetter88548632015-12-04 09:45:48 +0100787
788 /**
789 * @reset:
790 *
791 * Reset plane hardware and software state to off. This function isn't
792 * called by the core directly, only through drm_mode_config_reset().
793 * It's not a helper hook only for historical reasons.
794 *
795 * Atomic drivers can use drm_atomic_helper_plane_reset() to reset
796 * atomic state using this hook.
797 */
Daniel Vetter2a0d7cf2014-07-29 15:32:37 +0200798 void (*reset)(struct drm_plane *plane);
Rob Clark4d939142012-05-17 02:23:27 -0600799
Daniel Vetter88548632015-12-04 09:45:48 +0100800 /**
801 * @set_property:
802 *
803 * This is the legacy entry point to update a property attached to the
804 * plane.
805 *
806 * Drivers implementing atomic modeset should use
807 * drm_atomic_helper_plane_set_property() to implement this hook.
808 *
809 * This callback is optional if the driver does not support any legacy
810 * driver-private properties.
811 *
812 * RETURNS:
813 *
814 * 0 on success or a negative error code on failure.
815 */
Rob Clark4d939142012-05-17 02:23:27 -0600816 int (*set_property)(struct drm_plane *plane,
817 struct drm_property *property, uint64_t val);
Daniel Vetter144ecb92014-10-27 20:28:44 +0100818
Daniel Vetter88548632015-12-04 09:45:48 +0100819 /**
820 * @atomic_duplicate_state:
821 *
822 * Duplicate the current atomic state for this plane and return it.
823 * The core and helpers gurantee that any atomic state duplicated with
824 * this hook and still owned by the caller (i.e. not transferred to the
825 * driver by calling ->atomic_commit() from struct
826 * &drm_mode_config_funcs) will be cleaned up by calling the
827 * @atomic_destroy_state hook in this structure.
828 *
829 * Atomic drivers which don't subclass struct &drm_plane_state should use
830 * drm_atomic_helper_plane_duplicate_state(). Drivers that subclass the
831 * state structure to extend it with driver-private state should use
832 * __drm_atomic_helper_plane_duplicate_state() to make sure shared state is
833 * duplicated in a consistent fashion across drivers.
834 *
835 * It is an error to call this hook before plane->state has been
836 * initialized correctly.
837 *
838 * NOTE:
839 *
840 * If the duplicate state references refcounted resources this hook must
841 * acquire a reference for each of them. The driver must release these
842 * references again in @atomic_destroy_state.
843 *
844 * RETURNS:
845 *
846 * Duplicated atomic state or NULL when the allocation failed.
847 */
Daniel Vetter144ecb92014-10-27 20:28:44 +0100848 struct drm_plane_state *(*atomic_duplicate_state)(struct drm_plane *plane);
Daniel Vetter88548632015-12-04 09:45:48 +0100849
850 /**
851 * @atomic_destroy_state:
852 *
853 * Destroy a state duplicated with @atomic_duplicate_state and release
854 * or unreference all resources it references
855 */
Daniel Vetter144ecb92014-10-27 20:28:44 +0100856 void (*atomic_destroy_state)(struct drm_plane *plane,
Daniel Vettercc4ceb42014-07-25 21:30:38 +0200857 struct drm_plane_state *state);
Daniel Vetter88548632015-12-04 09:45:48 +0100858
859 /**
860 * @atomic_set_property:
861 *
862 * Decode a driver-private property value and store the decoded value
863 * into the passed-in state structure. Since the atomic core decodes all
864 * standardized properties (even for extensions beyond the core set of
865 * properties which might not be implemented by all drivers) this
866 * requires drivers to subclass the state structure.
867 *
868 * Such driver-private properties should really only be implemented for
869 * truly hardware/vendor specific state. Instead it is preferred to
870 * standardize atomic extension and decode the properties used to expose
871 * such an extension in the core.
872 *
873 * Do not call this function directly, use
874 * drm_atomic_plane_set_property() instead.
875 *
876 * This callback is optional if the driver does not support any
877 * driver-private atomic properties.
878 *
879 * NOTE:
880 *
881 * This function is called in the state assembly phase of atomic
882 * modesets, which can be aborted for any reason (including on
883 * userspace's request to just check whether a configuration would be
884 * possible). Drivers MUST NOT touch any persistent state (hardware or
885 * software) or data structures except the passed in @state parameter.
886 *
887 * Also since userspace controls in which order properties are set this
888 * function must not do any input validation (since the state update is
889 * incomplete and hence likely inconsistent). Instead any such input
890 * validation must be done in the various atomic_check callbacks.
891 *
892 * RETURNS:
893 *
894 * 0 if the property has been found, -EINVAL if the property isn't
895 * implemented by the driver (which shouldn't ever happen, the core only
896 * asks for properties attached to this plane). No other validation is
897 * allowed by the driver. The core already checks that the property
898 * value is within the range (integer, valid enum value, ...) the driver
899 * set when registering the property.
900 */
Daniel Vetter144ecb92014-10-27 20:28:44 +0100901 int (*atomic_set_property)(struct drm_plane *plane,
902 struct drm_plane_state *state,
903 struct drm_property *property,
904 uint64_t val);
Daniel Vetter88548632015-12-04 09:45:48 +0100905
906 /**
907 * @atomic_get_property:
908 *
909 * Reads out the decoded driver-private property. This is used to
Daniel Vetterc6b0ca32015-12-04 09:46:01 +0100910 * implement the GETPLANE IOCTL.
Daniel Vetter88548632015-12-04 09:45:48 +0100911 *
912 * Do not call this function directly, use
913 * drm_atomic_plane_get_property() instead.
914 *
915 * This callback is optional if the driver does not support any
916 * driver-private atomic properties.
917 *
918 * RETURNS:
919 *
920 * 0 on success, -EINVAL if the property isn't implemented by the
921 * driver (which should never happen, the core only asks for
922 * properties attached to this plane).
923 */
Rob Clarkac9c9252014-12-18 16:01:47 -0500924 int (*atomic_get_property)(struct drm_plane *plane,
925 const struct drm_plane_state *state,
926 struct drm_property *property,
927 uint64_t *val);
Benjamin Gaignard79190ea2016-06-21 16:37:09 +0200928 /**
929 * @late_register:
930 *
931 * This optional hook can be used to register additional userspace
932 * interfaces attached to the plane like debugfs interfaces.
933 * It is called late in the driver load sequence from drm_dev_register().
934 * Everything added from this callback should be unregistered in
935 * the early_unregister callback.
936 *
937 * Returns:
938 *
939 * 0 on success, or a negative error code on failure.
940 */
941 int (*late_register)(struct drm_plane *plane);
942
943 /**
944 * @early_unregister:
945 *
946 * This optional hook should be used to unregister the additional
947 * userspace interfaces attached to the plane from
948 * late_unregister(). It is called from drm_dev_unregister(),
949 * early in the driver unload sequence to disable userspace access
950 * before data structures are torndown.
951 */
952 void (*early_unregister)(struct drm_plane *plane);
Jesse Barnes8cf5c912011-11-14 14:51:27 -0800953};
954
Matt Ropere27dde32014-04-01 15:22:30 -0700955enum drm_plane_type {
956 DRM_PLANE_TYPE_OVERLAY,
957 DRM_PLANE_TYPE_PRIMARY,
958 DRM_PLANE_TYPE_CURSOR,
959};
960
Daniel Vetter88548632015-12-04 09:45:48 +0100961
Jesse Barnes8cf5c912011-11-14 14:51:27 -0800962/**
Daniel Vetter3bf04012014-10-27 16:54:27 +0100963 * struct drm_plane - central DRM plane control structure
Jesse Barnes8cf5c912011-11-14 14:51:27 -0800964 * @dev: DRM device this plane belongs to
965 * @head: for list management
Daniel Vetterac3ba4a2016-05-31 23:11:10 +0200966 * @name: human readable name, can be overwritten by the driver
Jesse Barnes8cf5c912011-11-14 14:51:27 -0800967 * @base: base mode object
968 * @possible_crtcs: pipes this plane can be bound to
969 * @format_types: array of formats supported by this plane
970 * @format_count: number of formats supported
Laurent Pinchart7eb5f302015-03-09 10:41:07 +0200971 * @format_default: driver hasn't supplied supported formats for the plane
Jesse Barnes8cf5c912011-11-14 14:51:27 -0800972 * @crtc: currently bound CRTC
973 * @fb: currently bound fb
Daniel Vetter2c0c33d2014-10-27 20:19:38 +0100974 * @old_fb: Temporary tracking of the old fb while a modeset is ongoing. Used by
975 * drm_mode_set_config_internal() to implement correct refcounting.
Jesse Barnes8cf5c912011-11-14 14:51:27 -0800976 * @funcs: helper functions
Rob Clark4d939142012-05-17 02:23:27 -0600977 * @properties: property tracking for this plane
Matt Ropere27dde32014-04-01 15:22:30 -0700978 * @type: type of plane (overlay, primary, cursor)
Daniel Vetter144ecb92014-10-27 20:28:44 +0100979 * @state: current atomic state for this plane
Marek Szyprowski44d1240d2016-06-13 11:11:26 +0200980 * @zpos_property: zpos property for this plane
Daniel Vetterac3ba4a2016-05-31 23:11:10 +0200981 * @helper_private: mid-layer private data
Jesse Barnes8cf5c912011-11-14 14:51:27 -0800982 */
983struct drm_plane {
984 struct drm_device *dev;
985 struct list_head head;
986
Ville Syrjälä9f4c97a2015-12-08 18:41:54 +0200987 char *name;
988
Daniel Vetterac3ba4a2016-05-31 23:11:10 +0200989 /**
990 * @mutex:
991 *
992 * Protects modeset plane state, together with the mutex of &drm_crtc
993 * this plane is linked to (when active, getting actived or getting
994 * disabled).
995 */
Daniel Vetter4d02e2d2014-11-11 10:12:00 +0100996 struct drm_modeset_lock mutex;
997
Jesse Barnes8cf5c912011-11-14 14:51:27 -0800998 struct drm_mode_object base;
999
1000 uint32_t possible_crtcs;
1001 uint32_t *format_types;
Thierry Reding45e37432015-08-12 16:54:28 +02001002 unsigned int format_count;
Laurent Pinchart7eb5f302015-03-09 10:41:07 +02001003 bool format_default;
Jesse Barnes8cf5c912011-11-14 14:51:27 -08001004
1005 struct drm_crtc *crtc;
1006 struct drm_framebuffer *fb;
1007
Daniel Vetter3d30a592014-07-27 13:42:42 +02001008 struct drm_framebuffer *old_fb;
1009
Jesse Barnes8cf5c912011-11-14 14:51:27 -08001010 const struct drm_plane_funcs *funcs;
Rob Clark4d939142012-05-17 02:23:27 -06001011
1012 struct drm_object_properties properties;
Matt Ropere27dde32014-04-01 15:22:30 -07001013
1014 enum drm_plane_type type;
Daniel Vetter144ecb92014-10-27 20:28:44 +01001015
Daniel Vetter96094082016-07-15 21:47:59 +02001016 /**
1017 * @index: Position inside the mode_config.list, can be used as an array
1018 * index. It is invariant over the lifetime of the plane.
1019 */
Chris Wilson490d3d12016-05-27 20:05:00 +01001020 unsigned index;
1021
Daniel Vetter4490d4c2015-12-04 09:45:45 +01001022 const struct drm_plane_helper_funcs *helper_private;
Daniel Vetterc2fcd272014-11-05 00:14:14 +01001023
Daniel Vetter144ecb92014-10-27 20:28:44 +01001024 struct drm_plane_state *state;
Marek Szyprowski44d1240d2016-06-13 11:11:26 +02001025
1026 struct drm_property *zpos_property;
Jesse Barnes8cf5c912011-11-14 14:51:27 -08001027};
1028
1029/**
Daniel Vetter3bf04012014-10-27 16:54:27 +01001030 * struct drm_bridge_funcs - drm_bridge control functions
Sean Paul3b336ec2013-08-14 16:47:37 -04001031 */
1032struct drm_bridge_funcs {
Andrea Merellocf3bef92016-08-25 11:04:32 +02001033 /**
1034 * @attach:
1035 *
1036 * This callback is invoked whenever our bridge is being attached to a
1037 * &drm_encoder.
1038 *
1039 * The attach callback is optional.
1040 *
1041 * RETURNS:
1042 *
1043 * Zero on success, error code on failure.
1044 */
Ajay Kumar3d3f8b12015-01-20 22:08:44 +05301045 int (*attach)(struct drm_bridge *bridge);
Daniel Vetterda024fe2015-12-04 09:45:47 +01001046
1047 /**
Andrea Merellocf3bef92016-08-25 11:04:32 +02001048 * @detach:
1049 *
1050 * This callback is invoked whenever our bridge is being detached from a
1051 * &drm_encoder.
1052 *
1053 * The detach callback is optional.
1054 */
1055 void (*detach)(struct drm_bridge *bridge);
1056
1057 /**
Daniel Vetterda024fe2015-12-04 09:45:47 +01001058 * @mode_fixup:
1059 *
1060 * This callback is used to validate and adjust a mode. The paramater
1061 * mode is the display mode that should be fed to the next element in
1062 * the display chain, either the final &drm_connector or the next
1063 * &drm_bridge. The parameter adjusted_mode is the input mode the bridge
1064 * requires. It can be modified by this callback and does not need to
1065 * match mode.
1066 *
1067 * This is the only hook that allows a bridge to reject a modeset. If
1068 * this function passes all other callbacks must succeed for this
1069 * configuration.
1070 *
Andrea Merellocf3bef92016-08-25 11:04:32 +02001071 * The mode_fixup callback is optional.
1072 *
Daniel Vetterda024fe2015-12-04 09:45:47 +01001073 * NOTE:
1074 *
1075 * This function is called in the check phase of atomic modesets, which
1076 * can be aborted for any reason (including on userspace's request to
1077 * just check whether a configuration would be possible). Drivers MUST
1078 * NOT touch any persistent state (hardware or software) or data
Daniel Vetter88548632015-12-04 09:45:48 +01001079 * structures except the passed in @state parameter.
Daniel Vetterda024fe2015-12-04 09:45:47 +01001080 *
1081 * RETURNS:
1082 *
1083 * True if an acceptable configuration is possible, false if the modeset
1084 * operation should be rejected.
1085 */
Sean Paul3b336ec2013-08-14 16:47:37 -04001086 bool (*mode_fixup)(struct drm_bridge *bridge,
1087 const struct drm_display_mode *mode,
1088 struct drm_display_mode *adjusted_mode);
Daniel Vetterda024fe2015-12-04 09:45:47 +01001089 /**
1090 * @disable:
1091 *
1092 * This callback should disable the bridge. It is called right before
1093 * the preceding element in the display pipe is disabled. If the
1094 * preceding element is a bridge this means it's called before that
1095 * bridge's ->disable() function. If the preceding element is a
1096 * &drm_encoder it's called right before the encoder's ->disable(),
1097 * ->prepare() or ->dpms() hook from struct &drm_encoder_helper_funcs.
1098 *
1099 * The bridge can assume that the display pipe (i.e. clocks and timing
1100 * signals) feeding it is still running when this callback is called.
Laurent Pinchartc8a3b2a2016-02-26 11:51:06 +02001101 *
1102 * The disable callback is optional.
Daniel Vetterda024fe2015-12-04 09:45:47 +01001103 */
Sean Paul3b336ec2013-08-14 16:47:37 -04001104 void (*disable)(struct drm_bridge *bridge);
Daniel Vetterda024fe2015-12-04 09:45:47 +01001105
1106 /**
1107 * @post_disable:
1108 *
1109 * This callback should disable the bridge. It is called right after
1110 * the preceding element in the display pipe is disabled. If the
1111 * preceding element is a bridge this means it's called after that
1112 * bridge's ->post_disable() function. If the preceding element is a
1113 * &drm_encoder it's called right after the encoder's ->disable(),
1114 * ->prepare() or ->dpms() hook from struct &drm_encoder_helper_funcs.
1115 *
1116 * The bridge must assume that the display pipe (i.e. clocks and timing
1117 * singals) feeding it is no longer running when this callback is
1118 * called.
Laurent Pinchartc8a3b2a2016-02-26 11:51:06 +02001119 *
1120 * The post_disable callback is optional.
Daniel Vetterda024fe2015-12-04 09:45:47 +01001121 */
Sean Paul3b336ec2013-08-14 16:47:37 -04001122 void (*post_disable)(struct drm_bridge *bridge);
Daniel Vetterda024fe2015-12-04 09:45:47 +01001123
1124 /**
1125 * @mode_set:
1126 *
1127 * This callback should set the given mode on the bridge. It is called
1128 * after the ->mode_set() callback for the preceding element in the
1129 * display pipeline has been called already. The display pipe (i.e.
1130 * clocks and timing signals) is off when this function is called.
1131 */
Sean Paul3b336ec2013-08-14 16:47:37 -04001132 void (*mode_set)(struct drm_bridge *bridge,
1133 struct drm_display_mode *mode,
1134 struct drm_display_mode *adjusted_mode);
Daniel Vetterda024fe2015-12-04 09:45:47 +01001135 /**
1136 * @pre_enable:
1137 *
1138 * This callback should enable the bridge. It is called right before
1139 * the preceding element in the display pipe is enabled. If the
1140 * preceding element is a bridge this means it's called before that
1141 * bridge's ->pre_enable() function. If the preceding element is a
1142 * &drm_encoder it's called right before the encoder's ->enable(),
1143 * ->commit() or ->dpms() hook from struct &drm_encoder_helper_funcs.
1144 *
1145 * The display pipe (i.e. clocks and timing signals) feeding this bridge
1146 * will not yet be running when this callback is called. The bridge must
1147 * not enable the display link feeding the next bridge in the chain (if
1148 * there is one) when this callback is called.
Laurent Pinchartc8a3b2a2016-02-26 11:51:06 +02001149 *
1150 * The pre_enable callback is optional.
Daniel Vetterda024fe2015-12-04 09:45:47 +01001151 */
Sean Paul3b336ec2013-08-14 16:47:37 -04001152 void (*pre_enable)(struct drm_bridge *bridge);
Daniel Vetterda024fe2015-12-04 09:45:47 +01001153
1154 /**
1155 * @enable:
1156 *
1157 * This callback should enable the bridge. It is called right after
1158 * the preceding element in the display pipe is enabled. If the
1159 * preceding element is a bridge this means it's called after that
1160 * bridge's ->enable() function. If the preceding element is a
1161 * &drm_encoder it's called right after the encoder's ->enable(),
1162 * ->commit() or ->dpms() hook from struct &drm_encoder_helper_funcs.
1163 *
1164 * The bridge can assume that the display pipe (i.e. clocks and timing
1165 * signals) feeding it is running when this callback is called. This
1166 * callback must enable the display link feeding the next bridge in the
1167 * chain if there is one.
Laurent Pinchartc8a3b2a2016-02-26 11:51:06 +02001168 *
1169 * The enable callback is optional.
Daniel Vetterda024fe2015-12-04 09:45:47 +01001170 */
Sean Paul3b336ec2013-08-14 16:47:37 -04001171 void (*enable)(struct drm_bridge *bridge);
Sean Paul3b336ec2013-08-14 16:47:37 -04001172};
1173
1174/**
Daniel Vetter3bf04012014-10-27 16:54:27 +01001175 * struct drm_bridge - central DRM bridge control structure
Sean Paul3b336ec2013-08-14 16:47:37 -04001176 * @dev: DRM device this bridge belongs to
Archit Taneja862e6862015-05-21 11:03:16 +05301177 * @encoder: encoder to which this bridge is connected
1178 * @next: the next bridge in the encoder chain
Ajay Kumar3d3f8b12015-01-20 22:08:44 +05301179 * @of_node: device node pointer to the bridge
1180 * @list: to keep track of all added bridges
Sean Paul3b336ec2013-08-14 16:47:37 -04001181 * @funcs: control functions
1182 * @driver_private: pointer to the bridge driver's internal context
1183 */
1184struct drm_bridge {
1185 struct drm_device *dev;
Ajay Kumar3d3f8b12015-01-20 22:08:44 +05301186 struct drm_encoder *encoder;
Archit Taneja862e6862015-05-21 11:03:16 +05301187 struct drm_bridge *next;
Ajay Kumar3d3f8b12015-01-20 22:08:44 +05301188#ifdef CONFIG_OF
1189 struct device_node *of_node;
1190#endif
1191 struct list_head list;
Sean Paul3b336ec2013-08-14 16:47:37 -04001192
1193 const struct drm_bridge_funcs *funcs;
1194 void *driver_private;
1195};
1196
Daniel Vetter3b24f7d2016-06-08 14:19:00 +02001197/**
1198 * struct drm_crtc_commit - track modeset commits on a CRTC
1199 *
1200 * This structure is used to track pending modeset changes and atomic commit on
1201 * a per-CRTC basis. Since updating the list should never block this structure
1202 * is reference counted to allow waiters to safely wait on an event to complete,
1203 * without holding any locks.
1204 *
1205 * It has 3 different events in total to allow a fine-grained synchronization
1206 * between outstanding updates::
1207 *
1208 * atomic commit thread hardware
1209 *
1210 * write new state into hardware ----> ...
1211 * signal hw_done
1212 * switch to new state on next
1213 * ... v/hblank
1214 *
1215 * wait for buffers to show up ...
1216 *
1217 * ... send completion irq
1218 * irq handler signals flip_done
1219 * cleanup old buffers
1220 *
1221 * signal cleanup_done
1222 *
1223 * wait for flip_done <----
1224 * clean up atomic state
1225 *
1226 * The important bit to know is that cleanup_done is the terminal event, but the
1227 * ordering between flip_done and hw_done is entirely up to the specific driver
1228 * and modeset state change.
1229 *
1230 * For an implementation of how to use this look at
1231 * drm_atomic_helper_setup_commit() from the atomic helper library.
1232 */
1233struct drm_crtc_commit {
1234 /**
1235 * @crtc:
1236 *
1237 * DRM CRTC for this commit.
1238 */
1239 struct drm_crtc *crtc;
1240
1241 /**
1242 * @ref:
1243 *
1244 * Reference count for this structure. Needed to allow blocking on
1245 * completions without the risk of the completion disappearing
1246 * meanwhile.
1247 */
1248 struct kref ref;
1249
1250 /**
1251 * @flip_done:
1252 *
1253 * Will be signaled when the hardware has flipped to the new set of
1254 * buffers. Signals at the same time as when the drm event for this
1255 * commit is sent to userspace, or when an out-fence is singalled. Note
1256 * that for most hardware, in most cases this happens after @hw_done is
1257 * signalled.
1258 */
1259 struct completion flip_done;
1260
1261 /**
1262 * @hw_done:
1263 *
1264 * Will be signalled when all hw register changes for this commit have
1265 * been written out. Especially when disabling a pipe this can be much
1266 * later than than @flip_done, since that can signal already when the
1267 * screen goes black, whereas to fully shut down a pipe more register
1268 * I/O is required.
1269 *
1270 * Note that this does not need to include separately reference-counted
1271 * resources like backing storage buffer pinning, or runtime pm
1272 * management.
1273 */
1274 struct completion hw_done;
1275
1276 /**
1277 * @cleanup_done:
1278 *
1279 * Will be signalled after old buffers have been cleaned up by calling
1280 * drm_atomic_helper_cleanup_planes(). Since this can only happen after
1281 * a vblank wait completed it might be a bit later. This completion is
1282 * useful to throttle updates and avoid hardware updates getting ahead
1283 * of the buffer cleanup too much.
1284 */
1285 struct completion cleanup_done;
1286
1287 /**
1288 * @commit_entry:
1289 *
1290 * Entry on the per-CRTC commit_list. Protected by crtc->commit_lock.
1291 */
1292 struct list_head commit_entry;
1293
1294 /**
1295 * @event:
1296 *
1297 * &drm_pending_vblank_event pointer to clean up private events.
1298 */
1299 struct drm_pending_vblank_event *event;
1300};
1301
Daniel Vetterb8b53422016-06-02 00:06:33 +02001302struct __drm_planes_state {
1303 struct drm_plane *ptr;
1304 struct drm_plane_state *state;
1305};
1306
Daniel Vetter5d943aa62016-06-02 00:06:34 +02001307struct __drm_crtcs_state {
1308 struct drm_crtc *ptr;
1309 struct drm_crtc_state *state;
Daniel Vetter3b24f7d2016-06-08 14:19:00 +02001310 struct drm_crtc_commit *commit;
Daniel Vetter5d943aa62016-06-02 00:06:34 +02001311};
1312
Daniel Vetter63e83c12016-06-02 00:06:32 +02001313struct __drm_connnectors_state {
1314 struct drm_connector *ptr;
1315 struct drm_connector_state *state;
1316};
1317
Sean Paul3b336ec2013-08-14 16:47:37 -04001318/**
Rob Clark08855fa2015-03-11 10:23:09 -04001319 * struct drm_atomic_state - the global state object for atomic updates
Daniel Vettercc4ceb42014-07-25 21:30:38 +02001320 * @dev: parent DRM device
Rob Clarkd34f20d2014-12-18 16:01:56 -05001321 * @allow_modeset: allow full modeset
Daniel Vetterc6b0ca32015-12-04 09:46:01 +01001322 * @legacy_cursor_update: hint to enforce legacy cursor IOCTL semantics
Maarten Lankhorst40616a22016-03-03 10:17:39 +01001323 * @legacy_set_config: Disable conflicting encoders instead of failing with -EINVAL.
Daniel Vetterb8b53422016-06-02 00:06:33 +02001324 * @planes: pointer to array of structures with per-plane data
Daniel Vettercc4ceb42014-07-25 21:30:38 +02001325 * @crtcs: pointer to array of CRTC pointers
Daniel Vetterf52b69f12014-11-19 18:38:08 +01001326 * @num_connector: size of the @connectors and @connector_states arrays
Daniel Vetter63e83c12016-06-02 00:06:32 +02001327 * @connectors: pointer to array of structures with per-connector data
Daniel Vettercc4ceb42014-07-25 21:30:38 +02001328 * @acquire_ctx: acquire context for this atomic modeset state update
1329 */
1330struct drm_atomic_state {
1331 struct drm_device *dev;
Rob Clarkd34f20d2014-12-18 16:01:56 -05001332 bool allow_modeset : 1;
Daniel Vetterf02ad902015-01-22 16:36:23 +01001333 bool legacy_cursor_update : 1;
Maarten Lankhorst40616a22016-03-03 10:17:39 +01001334 bool legacy_set_config : 1;
Daniel Vetterb8b53422016-06-02 00:06:33 +02001335 struct __drm_planes_state *planes;
Daniel Vetter5d943aa62016-06-02 00:06:34 +02001336 struct __drm_crtcs_state *crtcs;
Daniel Vetterf52b69f12014-11-19 18:38:08 +01001337 int num_connector;
Daniel Vetter63e83c12016-06-02 00:06:32 +02001338 struct __drm_connnectors_state *connectors;
Daniel Vettercc4ceb42014-07-25 21:30:38 +02001339
1340 struct drm_modeset_acquire_ctx *acquire_ctx;
Daniel Vetter3b24f7d2016-06-08 14:19:00 +02001341
1342 /**
1343 * @commit_work:
1344 *
1345 * Work item which can be used by the driver or helpers to execute the
1346 * commit without blocking.
1347 */
1348 struct work_struct commit_work;
Daniel Vettercc4ceb42014-07-25 21:30:38 +02001349};
1350
1351
1352/**
Daniel Vetter3bf04012014-10-27 16:54:27 +01001353 * struct drm_mode_set - new values for a CRTC config change
Jesse Barnesef273512011-11-07 12:03:19 -08001354 * @fb: framebuffer to use for new config
1355 * @crtc: CRTC whose configuration we're about to change
1356 * @mode: mode timings to use
1357 * @x: position of this CRTC relative to @fb
1358 * @y: position of this CRTC relative to @fb
1359 * @connectors: array of connectors to drive with this CRTC if possible
1360 * @num_connectors: size of @connectors array
Dave Airlief453ba02008-11-07 14:05:41 -08001361 *
1362 * Represents a single crtc the connectors that it drives with what mode
1363 * and from which framebuffer it scans out from.
1364 *
1365 * This is used to set modes.
1366 */
1367struct drm_mode_set {
Dave Airlief453ba02008-11-07 14:05:41 -08001368 struct drm_framebuffer *fb;
1369 struct drm_crtc *crtc;
1370 struct drm_display_mode *mode;
1371
1372 uint32_t x;
1373 uint32_t y;
1374
1375 struct drm_connector **connectors;
1376 size_t num_connectors;
1377};
1378
1379/**
Jesse Barnes550cebc2011-11-07 12:03:20 -08001380 * struct drm_mode_config_funcs - basic driver provided mode setting functions
Jesse Barnes550cebc2011-11-07 12:03:20 -08001381 *
1382 * Some global (i.e. not per-CRTC, connector, etc) mode setting functions that
1383 * involve drivers.
Dave Airlief453ba02008-11-07 14:05:41 -08001384 */
1385struct drm_mode_config_funcs {
Daniel Vetter9953f412015-12-04 09:46:02 +01001386 /**
1387 * @fb_create:
1388 *
1389 * Create a new framebuffer object. The core does basic checks on the
1390 * requested metadata, but most of that is left to the driver. See
1391 * struct &drm_mode_fb_cmd2 for details.
1392 *
Daniel Vetterd55f5322015-12-08 09:49:19 +01001393 * If the parameters are deemed valid and the backing storage objects in
1394 * the underlying memory manager all exist, then the driver allocates
1395 * a new &drm_framebuffer structure, subclassed to contain
1396 * driver-specific information (like the internal native buffer object
1397 * references). It also needs to fill out all relevant metadata, which
1398 * should be done by calling drm_helper_mode_fill_fb_struct().
1399 *
1400 * The initialization is finalized by calling drm_framebuffer_init(),
1401 * which registers the framebuffer and makes it accessible to other
1402 * threads.
1403 *
Daniel Vetter9953f412015-12-04 09:46:02 +01001404 * RETURNS:
1405 *
1406 * A new framebuffer with an initial reference count of 1 or a negative
1407 * error code encoded with ERR_PTR().
1408 */
Jesse Barnes550cebc2011-11-07 12:03:20 -08001409 struct drm_framebuffer *(*fb_create)(struct drm_device *dev,
1410 struct drm_file *file_priv,
Ville Syrjälä1eb83452015-11-11 19:11:29 +02001411 const struct drm_mode_fb_cmd2 *mode_cmd);
Daniel Vetter9953f412015-12-04 09:46:02 +01001412
1413 /**
1414 * @output_poll_changed:
1415 *
1416 * Callback used by helpers to inform the driver of output configuration
1417 * changes.
1418 *
1419 * Drivers implementing fbdev emulation with the helpers can call
1420 * drm_fb_helper_hotplug_changed from this hook to inform the fbdev
1421 * helper of output changes.
1422 *
1423 * FIXME:
1424 *
1425 * Except that there's no vtable for device-level helper callbacks
1426 * there's no reason this is a core function.
1427 */
Dave Airlieeb1f8e42010-05-07 06:42:51 +00001428 void (*output_poll_changed)(struct drm_device *dev);
Daniel Vettercc4ceb42014-07-25 21:30:38 +02001429
Daniel Vetter9953f412015-12-04 09:46:02 +01001430 /**
1431 * @atomic_check:
1432 *
1433 * This is the only hook to validate an atomic modeset update. This
1434 * function must reject any modeset and state changes which the hardware
1435 * or driver doesn't support. This includes but is of course not limited
1436 * to:
1437 *
1438 * - Checking that the modes, framebuffers, scaling and placement
1439 * requirements and so on are within the limits of the hardware.
1440 *
1441 * - Checking that any hidden shared resources are not oversubscribed.
1442 * This can be shared PLLs, shared lanes, overall memory bandwidth,
1443 * display fifo space (where shared between planes or maybe even
1444 * CRTCs).
1445 *
1446 * - Checking that virtualized resources exported to userspace are not
1447 * oversubscribed. For various reasons it can make sense to expose
1448 * more planes, crtcs or encoders than which are physically there. One
1449 * example is dual-pipe operations (which generally should be hidden
1450 * from userspace if when lockstepped in hardware, exposed otherwise),
1451 * where a plane might need 1 hardware plane (if it's just on one
1452 * pipe), 2 hardware planes (when it spans both pipes) or maybe even
1453 * shared a hardware plane with a 2nd plane (if there's a compatible
1454 * plane requested on the area handled by the other pipe).
1455 *
1456 * - Check that any transitional state is possible and that if
1457 * requested, the update can indeed be done in the vblank period
1458 * without temporarily disabling some functions.
1459 *
1460 * - Check any other constraints the driver or hardware might have.
1461 *
1462 * - This callback also needs to correctly fill out the &drm_crtc_state
1463 * in this update to make sure that drm_atomic_crtc_needs_modeset()
1464 * reflects the nature of the possible update and returns true if and
1465 * only if the update cannot be applied without tearing within one
1466 * vblank on that CRTC. The core uses that information to reject
1467 * updates which require a full modeset (i.e. blanking the screen, or
1468 * at least pausing updates for a substantial amount of time) if
1469 * userspace has disallowed that in its request.
1470 *
1471 * - The driver also does not need to repeat basic input validation
1472 * like done for the corresponding legacy entry points. The core does
1473 * that before calling this hook.
1474 *
1475 * See the documentation of @atomic_commit for an exhaustive list of
1476 * error conditions which don't have to be checked at the
1477 * ->atomic_check() stage?
1478 *
1479 * See the documentation for struct &drm_atomic_state for how exactly
1480 * an atomic modeset update is described.
1481 *
1482 * Drivers using the atomic helpers can implement this hook using
1483 * drm_atomic_helper_check(), or one of the exported sub-functions of
1484 * it.
1485 *
1486 * RETURNS:
1487 *
1488 * 0 on success or one of the below negative error codes:
1489 *
1490 * - -EINVAL, if any of the above constraints are violated.
1491 *
1492 * - -EDEADLK, when returned from an attempt to acquire an additional
1493 * &drm_modeset_lock through drm_modeset_lock().
1494 *
1495 * - -ENOMEM, if allocating additional state sub-structures failed due
1496 * to lack of memory.
1497 *
1498 * - -EINTR, -EAGAIN or -ERESTARTSYS, if the IOCTL should be restarted.
1499 * This can either be due to a pending signal, or because the driver
1500 * needs to completely bail out to recover from an exceptional
1501 * situation like a GPU hang. From a userspace point all errors are
1502 * treated equally.
1503 */
Daniel Vettercc4ceb42014-07-25 21:30:38 +02001504 int (*atomic_check)(struct drm_device *dev,
Daniel Vetter9953f412015-12-04 09:46:02 +01001505 struct drm_atomic_state *state);
1506
1507 /**
1508 * @atomic_commit:
1509 *
1510 * This is the only hook to commit an atomic modeset update. The core
1511 * guarantees that @atomic_check has been called successfully before
1512 * calling this function, and that nothing has been changed in the
1513 * interim.
1514 *
1515 * See the documentation for struct &drm_atomic_state for how exactly
1516 * an atomic modeset update is described.
1517 *
1518 * Drivers using the atomic helpers can implement this hook using
1519 * drm_atomic_helper_commit(), or one of the exported sub-functions of
1520 * it.
1521 *
Maarten Lankhorst286dbb82016-04-26 16:11:34 +02001522 * Nonblocking commits (as indicated with the nonblock parameter) must
Daniel Vetter9953f412015-12-04 09:46:02 +01001523 * do any preparatory work which might result in an unsuccessful commit
1524 * in the context of this callback. The only exceptions are hardware
1525 * errors resulting in -EIO. But even in that case the driver must
1526 * ensure that the display pipe is at least running, to avoid
1527 * compositors crashing when pageflips don't work. Anything else,
1528 * specifically committing the update to the hardware, should be done
1529 * without blocking the caller. For updates which do not require a
1530 * modeset this must be guaranteed.
1531 *
1532 * The driver must wait for any pending rendering to the new
1533 * framebuffers to complete before executing the flip. It should also
1534 * wait for any pending rendering from other drivers if the underlying
Maarten Lankhorst286dbb82016-04-26 16:11:34 +02001535 * buffer is a shared dma-buf. Nonblocking commits must not wait for
Daniel Vetter9953f412015-12-04 09:46:02 +01001536 * rendering in the context of this callback.
1537 *
1538 * An application can request to be notified when the atomic commit has
1539 * completed. These events are per-CRTC and can be distinguished by the
1540 * CRTC index supplied in &drm_event to userspace.
1541 *
1542 * The drm core will supply a struct &drm_event in the event
1543 * member of each CRTC's &drm_crtc_state structure. This can be handled by the
1544 * drm_crtc_send_vblank_event() function, which the driver should call on
1545 * the provided event upon completion of the atomic commit. Note that if
1546 * the driver supports vblank signalling and timestamping the vblank
1547 * counters and timestamps must agree with the ones returned from page
1548 * flip events. With the current vblank helper infrastructure this can
1549 * be achieved by holding a vblank reference while the page flip is
1550 * pending, acquired through drm_crtc_vblank_get() and released with
1551 * drm_crtc_vblank_put(). Drivers are free to implement their own vblank
1552 * counter and timestamp tracking though, e.g. if they have accurate
1553 * timestamp registers in hardware.
1554 *
1555 * NOTE:
1556 *
1557 * Drivers are not allowed to shut down any display pipe successfully
1558 * enabled through an atomic commit on their own. Doing so can result in
1559 * compositors crashing if a page flip is suddenly rejected because the
1560 * pipe is off.
1561 *
1562 * RETURNS:
1563 *
1564 * 0 on success or one of the below negative error codes:
1565 *
Maarten Lankhorst286dbb82016-04-26 16:11:34 +02001566 * - -EBUSY, if a nonblocking updated is requested and there is
Daniel Vetter9953f412015-12-04 09:46:02 +01001567 * an earlier updated pending. Drivers are allowed to support a queue
1568 * of outstanding updates, but currently no driver supports that.
1569 * Note that drivers must wait for preceding updates to complete if a
1570 * synchronous update is requested, they are not allowed to fail the
1571 * commit in that case.
1572 *
1573 * - -ENOMEM, if the driver failed to allocate memory. Specifically
1574 * this can happen when trying to pin framebuffers, which must only
1575 * be done when committing the state.
1576 *
1577 * - -ENOSPC, as a refinement of the more generic -ENOMEM to indicate
1578 * that the driver has run out of vram, iommu space or similar GPU
1579 * address space needed for framebuffer.
1580 *
1581 * - -EIO, if the hardware completely died.
1582 *
1583 * - -EINTR, -EAGAIN or -ERESTARTSYS, if the IOCTL should be restarted.
1584 * This can either be due to a pending signal, or because the driver
1585 * needs to completely bail out to recover from an exceptional
1586 * situation like a GPU hang. From a userspace point of view all errors are
1587 * treated equally.
1588 *
1589 * This list is exhaustive. Specifically this hook is not allowed to
1590 * return -EINVAL (any invalid requests should be caught in
1591 * @atomic_check) or -EDEADLK (this function must not acquire
1592 * additional modeset locks).
1593 */
Daniel Vettercc4ceb42014-07-25 21:30:38 +02001594 int (*atomic_commit)(struct drm_device *dev,
Daniel Vetter9953f412015-12-04 09:46:02 +01001595 struct drm_atomic_state *state,
Maarten Lankhorst286dbb82016-04-26 16:11:34 +02001596 bool nonblock);
Daniel Vetter9953f412015-12-04 09:46:02 +01001597
1598 /**
1599 * @atomic_state_alloc:
1600 *
1601 * This optional hook can be used by drivers that want to subclass struct
1602 * &drm_atomic_state to be able to track their own driver-private global
1603 * state easily. If this hook is implemented, drivers must also
1604 * implement @atomic_state_clear and @atomic_state_free.
1605 *
1606 * RETURNS:
1607 *
1608 * A new &drm_atomic_state on success or NULL on failure.
1609 */
Maarten Lankhorst036ef572015-05-18 10:06:40 +02001610 struct drm_atomic_state *(*atomic_state_alloc)(struct drm_device *dev);
Daniel Vetter9953f412015-12-04 09:46:02 +01001611
1612 /**
1613 * @atomic_state_clear:
1614 *
1615 * This hook must clear any driver private state duplicated into the
1616 * passed-in &drm_atomic_state. This hook is called when the caller
1617 * encountered a &drm_modeset_lock deadlock and needs to drop all
1618 * already acquired locks as part of the deadlock avoidance dance
1619 * implemented in drm_modeset_lock_backoff().
1620 *
1621 * Any duplicated state must be invalidated since a concurrent atomic
1622 * update might change it, and the drm atomic interfaces always apply
1623 * updates as relative changes to the current state.
1624 *
1625 * Drivers that implement this must call drm_atomic_state_default_clear()
1626 * to clear common state.
1627 */
Maarten Lankhorst036ef572015-05-18 10:06:40 +02001628 void (*atomic_state_clear)(struct drm_atomic_state *state);
Daniel Vetter9953f412015-12-04 09:46:02 +01001629
1630 /**
1631 * @atomic_state_free:
1632 *
1633 * This hook needs driver private resources and the &drm_atomic_state
1634 * itself. Note that the core first calls drm_atomic_state_clear() to
1635 * avoid code duplicate between the clear and free hooks.
1636 *
1637 * Drivers that implement this must call drm_atomic_state_default_free()
1638 * to release common resources.
1639 */
Maarten Lankhorst036ef572015-05-18 10:06:40 +02001640 void (*atomic_state_free)(struct drm_atomic_state *state);
Dave Airlief453ba02008-11-07 14:05:41 -08001641};
1642
Jesse Barnesc1aaca22011-11-07 12:03:21 -08001643/**
Daniel Vetter2c0c33d2014-10-27 20:19:38 +01001644 * struct drm_mode_config - Mode configuration control structure
Jesse Barnesa62c93d2011-11-07 12:03:22 -08001645 * @mutex: mutex protecting KMS related lists and structures
Daniel Vetter2c0c33d2014-10-27 20:19:38 +01001646 * @connection_mutex: ww mutex protecting connector state and routing
1647 * @acquire_ctx: global implicit acquire context used by atomic drivers for
Daniel Vetterc6b0ca32015-12-04 09:46:01 +01001648 * legacy IOCTLs
Daniel Vetter2c0c33d2014-10-27 20:19:38 +01001649 * @fb_lock: mutex to protect fb state and lists
Jesse Barnesa62c93d2011-11-07 12:03:22 -08001650 * @num_fb: number of fbs available
1651 * @fb_list: list of framebuffers available
Jesse Barnesa62c93d2011-11-07 12:03:22 -08001652 * @num_encoder: number of encoders on this device
1653 * @encoder_list: list of encoder objects
Daniel Vetter2c0c33d2014-10-27 20:19:38 +01001654 * @num_overlay_plane: number of overlay planes on this device
1655 * @num_total_plane: number of universal (i.e. with primary/curso) planes on this device
1656 * @plane_list: list of plane objects
Jesse Barnesa62c93d2011-11-07 12:03:22 -08001657 * @num_crtc: number of CRTCs on this device
1658 * @crtc_list: list of CRTC objects
Daniel Vetter2c0c33d2014-10-27 20:19:38 +01001659 * @property_list: list of property objects
Jesse Barnesa62c93d2011-11-07 12:03:22 -08001660 * @min_width: minimum pixel width on this device
1661 * @min_height: minimum pixel height on this device
1662 * @max_width: maximum pixel width on this device
1663 * @max_height: maximum pixel height on this device
1664 * @funcs: core driver provided mode setting functions
1665 * @fb_base: base address of the framebuffer
Daniel Vetter2c0c33d2014-10-27 20:19:38 +01001666 * @poll_enabled: track polling support for this device
1667 * @poll_running: track polling status for this device
Daniel Vetterac3ba4a2016-05-31 23:11:10 +02001668 * @delayed_event: track delayed poll uevent deliver for this device
Jesse Barnesa62c93d2011-11-07 12:03:22 -08001669 * @output_poll_work: delayed work for polling in process context
Daniel Vetter2c0c33d2014-10-27 20:19:38 +01001670 * @property_blob_list: list of all the blob property objects
Daniel Stone8fb6e7a2015-04-20 19:22:54 +01001671 * @blob_lock: mutex for blob property allocation and management
Jesse Barnesa62c93d2011-11-07 12:03:22 -08001672 * @*_property: core property tracking
Daniel Vetter2c0c33d2014-10-27 20:19:38 +01001673 * @preferred_depth: preferred RBG pixel depth, used by fb helpers
1674 * @prefer_shadow: hint to userspace to prefer shadow-fb rendering
Daniel Vetter2c0c33d2014-10-27 20:19:38 +01001675 * @cursor_width: hint to userspace for max cursor width
1676 * @cursor_height: hint to userspace for max cursor height
Daniel Vetter9f2a7952016-06-08 14:19:02 +02001677 * @helper_private: mid-layer private data
Dave Airlief453ba02008-11-07 14:05:41 -08001678 *
Jesse Barnesa62c93d2011-11-07 12:03:22 -08001679 * Core mode resource tracking structure. All CRTC, encoders, and connectors
1680 * enumerated by the driver are added here, as are global properties. Some
1681 * global restrictions are also here, e.g. dimension restrictions.
Dave Airlief453ba02008-11-07 14:05:41 -08001682 */
1683struct drm_mode_config {
Jesse Barnesad2563c2009-01-19 17:21:45 +10001684 struct mutex mutex; /* protects configuration (mode lists etc.) */
Rob Clark51fd3712013-11-19 12:10:12 -05001685 struct drm_modeset_lock connection_mutex; /* protects connector->encoder and encoder->crtc links */
1686 struct drm_modeset_acquire_ctx *acquire_ctx; /* for legacy _lock_all() / _unlock_all() */
Daniel Vetterac3ba4a2016-05-31 23:11:10 +02001687
1688 /**
1689 * @idr_mutex:
1690 *
1691 * Mutex for KMS ID allocation and management. Protects both @crtc_idr
1692 * and @tile_idr.
1693 */
1694 struct mutex idr_mutex;
1695
1696 /**
1697 * @crtc_idr:
1698 *
1699 * Main KMS ID tracking object. Use this idr for all IDs, fb, crtc,
1700 * connector, modes - just makes life easier to have only one.
1701 */
1702 struct idr crtc_idr;
1703
1704 /**
1705 * @tile_idr:
1706 *
1707 * Use this idr for allocating new IDs for tiled sinks like use in some
1708 * high-res DP MST screens.
1709 */
1710 struct idr tile_idr;
Daniel Vetter4b096ac2012-12-10 21:19:18 +01001711
Daniel Vetter2c0c33d2014-10-27 20:19:38 +01001712 struct mutex fb_lock; /* proctects global and per-file fb lists */
Dave Airlief453ba02008-11-07 14:05:41 -08001713 int num_fb;
1714 struct list_head fb_list;
Daniel Vetter4b096ac2012-12-10 21:19:18 +01001715
Daniel Vetter96094082016-07-15 21:47:59 +02001716 /**
1717 * @num_connector: Number of connectors on this device.
1718 */
Dave Airlief453ba02008-11-07 14:05:41 -08001719 int num_connector;
Daniel Vetter96094082016-07-15 21:47:59 +02001720 /**
1721 * @connector_ida: ID allocator for connector indices.
1722 */
Maarten Lankhorst5fff80b2016-02-17 08:32:05 +01001723 struct ida connector_ida;
Daniel Vetter96094082016-07-15 21:47:59 +02001724 /**
1725 * @connector_list: List of connector objects.
1726 */
Dave Airlief453ba02008-11-07 14:05:41 -08001727 struct list_head connector_list;
1728 int num_encoder;
1729 struct list_head encoder_list;
Matt Ropere27dde32014-04-01 15:22:30 -07001730
1731 /*
1732 * Track # of overlay planes separately from # of total planes. By
1733 * default we only advertise overlay planes to userspace; if userspace
1734 * sets the "universal plane" capability bit, we'll go ahead and
1735 * expose all planes.
1736 */
1737 int num_overlay_plane;
1738 int num_total_plane;
Jesse Barnes8cf5c912011-11-14 14:51:27 -08001739 struct list_head plane_list;
Dave Airlief453ba02008-11-07 14:05:41 -08001740
1741 int num_crtc;
1742 struct list_head crtc_list;
1743
1744 struct list_head property_list;
1745
Dave Airlief453ba02008-11-07 14:05:41 -08001746 int min_width, min_height;
1747 int max_width, max_height;
Laurent Pincharte6ecefa2012-05-17 13:27:23 +02001748 const struct drm_mode_config_funcs *funcs;
Benjamin Herrenschmidtd883f7f2009-02-02 16:55:45 +11001749 resource_size_t fb_base;
Dave Airlief453ba02008-11-07 14:05:41 -08001750
Dave Airlieeb1f8e42010-05-07 06:42:51 +00001751 /* output poll support */
1752 bool poll_enabled;
Daniel Vetter905bc9f2012-10-23 18:23:36 +00001753 bool poll_running;
Daniel Vetter162b6a52015-01-21 08:45:21 +01001754 bool delayed_event;
Tejun Heo991ea752010-07-20 22:09:02 +02001755 struct delayed_work output_poll_work;
Dave Airlieeb1f8e42010-05-07 06:42:51 +00001756
Daniel Stone8fb6e7a2015-04-20 19:22:54 +01001757 struct mutex blob_lock;
1758
Dave Airlief453ba02008-11-07 14:05:41 -08001759 /* pointers to standard properties */
1760 struct list_head property_blob_list;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02001761 /**
1762 * @edid_property: Default connector property to hold the EDID of the
1763 * currently connected sink, if any.
1764 */
Dave Airlief453ba02008-11-07 14:05:41 -08001765 struct drm_property *edid_property;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02001766 /**
1767 * @dpms_property: Default connector property to control the
1768 * connector's DPMS state.
1769 */
Dave Airlief453ba02008-11-07 14:05:41 -08001770 struct drm_property *dpms_property;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02001771 /**
1772 * @path_property: Default connector property to hold the DP MST path
1773 * for the port.
1774 */
Dave Airlie43aba7e2014-06-05 14:01:31 +10001775 struct drm_property *path_property;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02001776 /**
1777 * @tile_property: Default connector property to store the tile
1778 * position of a tiled screen, for sinks which need to be driven with
1779 * multiple CRTCs.
1780 */
Dave Airlie6f134d72014-10-20 16:30:50 +10001781 struct drm_property *tile_property;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02001782 /**
1783 * @plane_type_property: Default plane property to differentiate
1784 * CURSOR, PRIMARY and OVERLAY legacy uses of planes.
1785 */
Rob Clark9922ab52014-04-01 20:16:57 -04001786 struct drm_property *plane_type_property;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02001787 /**
1788 * @rotation_property: Optional property for planes or CRTCs to specifiy
1789 * rotation.
1790 */
Sonika Jindal2a297cc2014-08-05 11:26:54 +05301791 struct drm_property *rotation_property;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02001792 /**
1793 * @prop_src_x: Default atomic plane property for the plane source
1794 * position in the connected &drm_framebuffer.
1795 */
Rob Clark6b4959f2014-12-18 16:01:53 -05001796 struct drm_property *prop_src_x;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02001797 /**
1798 * @prop_src_y: Default atomic plane property for the plane source
1799 * position in the connected &drm_framebuffer.
1800 */
Rob Clark6b4959f2014-12-18 16:01:53 -05001801 struct drm_property *prop_src_y;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02001802 /**
1803 * @prop_src_w: Default atomic plane property for the plane source
1804 * position in the connected &drm_framebuffer.
1805 */
Rob Clark6b4959f2014-12-18 16:01:53 -05001806 struct drm_property *prop_src_w;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02001807 /**
1808 * @prop_src_h: Default atomic plane property for the plane source
1809 * position in the connected &drm_framebuffer.
1810 */
Rob Clark6b4959f2014-12-18 16:01:53 -05001811 struct drm_property *prop_src_h;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02001812 /**
1813 * @prop_crtc_x: Default atomic plane property for the plane destination
1814 * position in the &drm_crtc is is being shown on.
1815 */
Rob Clark6b4959f2014-12-18 16:01:53 -05001816 struct drm_property *prop_crtc_x;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02001817 /**
1818 * @prop_crtc_y: Default atomic plane property for the plane destination
1819 * position in the &drm_crtc is is being shown on.
1820 */
Rob Clark6b4959f2014-12-18 16:01:53 -05001821 struct drm_property *prop_crtc_y;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02001822 /**
1823 * @prop_crtc_w: Default atomic plane property for the plane destination
1824 * position in the &drm_crtc is is being shown on.
1825 */
Rob Clark6b4959f2014-12-18 16:01:53 -05001826 struct drm_property *prop_crtc_w;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02001827 /**
1828 * @prop_crtc_h: Default atomic plane property for the plane destination
1829 * position in the &drm_crtc is is being shown on.
1830 */
Rob Clark6b4959f2014-12-18 16:01:53 -05001831 struct drm_property *prop_crtc_h;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02001832 /**
1833 * @prop_fb_id: Default atomic plane property to specify the
1834 * &drm_framebuffer.
1835 */
Rob Clark6b4959f2014-12-18 16:01:53 -05001836 struct drm_property *prop_fb_id;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02001837 /**
1838 * @prop_crtc_id: Default atomic plane property to specify the
1839 * &drm_crtc.
1840 */
Rob Clark6b4959f2014-12-18 16:01:53 -05001841 struct drm_property *prop_crtc_id;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02001842 /**
1843 * @prop_active: Default atomic CRTC property to control the active
1844 * state, which is the simplified implementation for DPMS in atomic
1845 * drivers.
1846 */
Daniel Vettereab3bbe2015-01-22 16:36:21 +01001847 struct drm_property *prop_active;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02001848 /**
1849 * @prop_mode_id: Default atomic CRTC property to set the mode for a
1850 * CRTC. A 0 mode implies that the CRTC is entirely disabled - all
1851 * connectors must be of and active must be set to disabled, too.
1852 */
Daniel Stone955f3c32015-05-25 19:11:52 +01001853 struct drm_property *prop_mode_id;
Dave Airlief453ba02008-11-07 14:05:41 -08001854
Daniel Vetter9a6bc032016-07-15 21:48:00 +02001855 /**
1856 * @dvi_i_subconnector_property: Optional DVI-I property to
1857 * differentiate between analog or digital mode.
1858 */
Dave Airlief453ba02008-11-07 14:05:41 -08001859 struct drm_property *dvi_i_subconnector_property;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02001860 /**
1861 * @dvi_i_select_subconnector_property: Optional DVI-I property to
1862 * select between analog or digital mode.
1863 */
Dave Airlief453ba02008-11-07 14:05:41 -08001864 struct drm_property *dvi_i_select_subconnector_property;
1865
Daniel Vetter9a6bc032016-07-15 21:48:00 +02001866 /**
1867 * @tv_subconnector_property: Optional TV property to differentiate
1868 * between different TV connector types.
1869 */
Dave Airlief453ba02008-11-07 14:05:41 -08001870 struct drm_property *tv_subconnector_property;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02001871 /**
1872 * @tv_select_subconnector_property: Optional TV property to select
1873 * between different TV connector types.
1874 */
Dave Airlief453ba02008-11-07 14:05:41 -08001875 struct drm_property *tv_select_subconnector_property;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02001876 /**
1877 * @tv_mode_property: Optional TV property to select
1878 * the output TV mode.
1879 */
Dave Airlief453ba02008-11-07 14:05:41 -08001880 struct drm_property *tv_mode_property;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02001881 /**
1882 * @tv_left_margin_property: Optional TV property to set the left
1883 * margin.
1884 */
Dave Airlief453ba02008-11-07 14:05:41 -08001885 struct drm_property *tv_left_margin_property;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02001886 /**
1887 * @tv_right_margin_property: Optional TV property to set the right
1888 * margin.
1889 */
Dave Airlief453ba02008-11-07 14:05:41 -08001890 struct drm_property *tv_right_margin_property;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02001891 /**
1892 * @tv_top_margin_property: Optional TV property to set the right
1893 * margin.
1894 */
Dave Airlief453ba02008-11-07 14:05:41 -08001895 struct drm_property *tv_top_margin_property;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02001896 /**
1897 * @tv_bottom_margin_property: Optional TV property to set the right
1898 * margin.
1899 */
Dave Airlief453ba02008-11-07 14:05:41 -08001900 struct drm_property *tv_bottom_margin_property;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02001901 /**
1902 * @tv_brightness_property: Optional TV property to set the
1903 * brightness.
1904 */
Francisco Jerezb6b79022009-08-02 04:19:20 +02001905 struct drm_property *tv_brightness_property;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02001906 /**
1907 * @tv_contrast_property: Optional TV property to set the
1908 * contrast.
1909 */
Francisco Jerezb6b79022009-08-02 04:19:20 +02001910 struct drm_property *tv_contrast_property;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02001911 /**
1912 * @tv_flicker_reduction_property: Optional TV property to control the
1913 * flicker reduction mode.
1914 */
Francisco Jerezb6b79022009-08-02 04:19:20 +02001915 struct drm_property *tv_flicker_reduction_property;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02001916 /**
1917 * @tv_overscan_property: Optional TV property to control the overscan
1918 * setting.
1919 */
Francisco Jereza75f0232009-08-12 02:30:10 +02001920 struct drm_property *tv_overscan_property;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02001921 /**
1922 * @tv_saturation_property: Optional TV property to set the
1923 * saturation.
1924 */
Francisco Jereza75f0232009-08-12 02:30:10 +02001925 struct drm_property *tv_saturation_property;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02001926 /**
1927 * @tv_hue_property: Optional TV property to set the hue.
1928 */
Francisco Jereza75f0232009-08-12 02:30:10 +02001929 struct drm_property *tv_hue_property;
Dave Airlief453ba02008-11-07 14:05:41 -08001930
Daniel Vetter9a6bc032016-07-15 21:48:00 +02001931 /**
1932 * @scaling_mode_property: Optional connector property to control the
1933 * upscaling, mostly used for built-in panels.
1934 */
Dave Airlief453ba02008-11-07 14:05:41 -08001935 struct drm_property *scaling_mode_property;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02001936 /**
1937 * @aspect_ratio_property: Optional connector property to control the
1938 * HDMI infoframe aspect ratio setting.
1939 */
Vandana Kannanff587e42014-06-11 10:46:48 +05301940 struct drm_property *aspect_ratio_property;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02001941 /**
Daniel Vetter9a6bc032016-07-15 21:48:00 +02001942 * @degamma_lut_property: Optional CRTC property to set the LUT used to
1943 * convert the framebuffer's colors to linear gamma.
1944 */
Lionel Landwerlin5488dc12016-02-26 17:05:00 +00001945 struct drm_property *degamma_lut_property;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02001946 /**
1947 * @degamma_lut_size_property: Optional CRTC property for the size of
1948 * the degamma LUT as supported by the driver (read-only).
1949 */
Lionel Landwerlin5488dc12016-02-26 17:05:00 +00001950 struct drm_property *degamma_lut_size_property;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02001951 /**
1952 * @ctm_property: Optional CRTC property to set the
1953 * matrix used to convert colors after the lookup in the
1954 * degamma LUT.
1955 */
Lionel Landwerlin5488dc12016-02-26 17:05:00 +00001956 struct drm_property *ctm_property;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02001957 /**
1958 * @gamma_lut_property: Optional CRTC property to set the LUT used to
1959 * convert the colors, after the CTM matrix, to the gamma space of the
1960 * connected screen.
1961 */
Lionel Landwerlin5488dc12016-02-26 17:05:00 +00001962 struct drm_property *gamma_lut_property;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02001963 /**
1964 * @gamma_lut_size_property: Optional CRTC property for the size of the
1965 * gamma LUT as supported by the driver (read-only).
1966 */
Lionel Landwerlin5488dc12016-02-26 17:05:00 +00001967 struct drm_property *gamma_lut_size_property;
1968
Daniel Vetter9a6bc032016-07-15 21:48:00 +02001969 /**
1970 * @suggested_x_property: Optional connector property with a hint for
1971 * the position of the output on the host's screen.
1972 */
Dave Airlie5bb2bbf2014-11-10 10:18:15 +10001973 struct drm_property *suggested_x_property;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02001974 /**
1975 * @suggested_y_property: Optional connector property with a hint for
1976 * the position of the output on the host's screen.
1977 */
Dave Airlie5bb2bbf2014-11-10 10:18:15 +10001978 struct drm_property *suggested_y_property;
1979
Dave Airlie019d96c2011-09-29 16:20:42 +01001980 /* dumb ioctl parameters */
1981 uint32_t preferred_depth, prefer_shadow;
Keith Packard62f21042013-07-22 18:50:00 -07001982
Daniel Vetter9a6bc032016-07-15 21:48:00 +02001983 /**
1984 * @async_page_flip: Does this device support async flips on the primary
1985 * plane?
1986 */
Keith Packard62f21042013-07-22 18:50:00 -07001987 bool async_page_flip;
Alex Deucher8716ed42014-02-12 12:48:23 -05001988
Daniel Vetterac3ba4a2016-05-31 23:11:10 +02001989 /**
1990 * @allow_fb_modifiers:
1991 *
1992 * Whether the driver supports fb modifiers in the ADDFB2.1 ioctl call.
1993 */
Rob Clarke3eb3252015-02-05 14:41:52 +00001994 bool allow_fb_modifiers;
1995
Alex Deucher8716ed42014-02-12 12:48:23 -05001996 /* cursor size */
1997 uint32_t cursor_width, cursor_height;
Daniel Vetter9f2a7952016-06-08 14:19:02 +02001998
1999 struct drm_mode_config_helper_funcs *helper_private;
Dave Airlief453ba02008-11-07 14:05:41 -08002000};
2001
Rob Clarkdd275952014-11-25 20:29:46 -05002002/**
2003 * drm_for_each_plane_mask - iterate over planes specified by bitmask
2004 * @plane: the loop cursor
2005 * @dev: the DRM device
2006 * @plane_mask: bitmask of plane indices
2007 *
2008 * Iterate over all planes specified by bitmask.
2009 */
2010#define drm_for_each_plane_mask(plane, dev, plane_mask) \
2011 list_for_each_entry((plane), &(dev)->mode_config.plane_list, head) \
Jani Nikula373701b2015-11-24 21:21:55 +02002012 for_each_if ((plane_mask) & (1 << drm_plane_index(plane)))
Rob Clarkdd275952014-11-25 20:29:46 -05002013
Maarten Lankhorstead8b662016-01-07 10:59:19 +01002014/**
2015 * drm_for_each_encoder_mask - iterate over encoders specified by bitmask
2016 * @encoder: the loop cursor
2017 * @dev: the DRM device
2018 * @encoder_mask: bitmask of encoder indices
2019 *
2020 * Iterate over all encoders specified by bitmask.
2021 */
2022#define drm_for_each_encoder_mask(encoder, dev, encoder_mask) \
2023 list_for_each_entry((encoder), &(dev)->mode_config.encoder_list, head) \
2024 for_each_if ((encoder_mask) & (1 << drm_encoder_index(encoder)))
Rob Clarkdd275952014-11-25 20:29:46 -05002025
Dave Airlief453ba02008-11-07 14:05:41 -08002026#define obj_to_crtc(x) container_of(x, struct drm_crtc, base)
Dave Airlief453ba02008-11-07 14:05:41 -08002027#define obj_to_mode(x) container_of(x, struct drm_display_mode, base)
2028#define obj_to_fb(x) container_of(x, struct drm_framebuffer, base)
2029#define obj_to_property(x) container_of(x, struct drm_property, base)
2030#define obj_to_blob(x) container_of(x, struct drm_property_blob, base)
Jesse Barnes8cf5c912011-11-14 14:51:27 -08002031#define obj_to_plane(x) container_of(x, struct drm_plane, base)
Dave Airlief453ba02008-11-07 14:05:41 -08002032
Sascha Hauer4a67d392012-02-06 10:58:17 +01002033struct drm_prop_enum_list {
2034 int type;
2035 char *name;
2036};
Dave Airlief453ba02008-11-07 14:05:41 -08002037
Ville Syrjäläf9882872015-12-09 16:19:31 +02002038extern __printf(6, 7)
2039int drm_crtc_init_with_planes(struct drm_device *dev,
2040 struct drm_crtc *crtc,
2041 struct drm_plane *primary,
2042 struct drm_plane *cursor,
2043 const struct drm_crtc_funcs *funcs,
2044 const char *name, ...);
Dave Airlief453ba02008-11-07 14:05:41 -08002045extern void drm_crtc_cleanup(struct drm_crtc *crtc);
Chris Wilson490d3d12016-05-27 20:05:00 +01002046
2047/**
2048 * drm_crtc_index - find the index of a registered CRTC
2049 * @crtc: CRTC to find index for
2050 *
2051 * Given a registered CRTC, return the index of that CRTC within a DRM
2052 * device's list of CRTCs.
2053 */
2054static inline unsigned int drm_crtc_index(struct drm_crtc *crtc)
2055{
2056 return crtc->index;
2057}
Russell Kingdb5f7a62014-01-02 21:27:33 +00002058
2059/**
2060 * drm_crtc_mask - find the mask of a registered CRTC
2061 * @crtc: CRTC to find mask for
2062 *
2063 * Given a registered CRTC, return the mask bit of that CRTC for an
2064 * encoder's possible_crtcs field.
2065 */
2066static inline uint32_t drm_crtc_mask(struct drm_crtc *crtc)
2067{
2068 return 1 << drm_crtc_index(crtc);
2069}
Dave Airlief453ba02008-11-07 14:05:41 -08002070
Ville Syrjäläb0b3b792015-12-09 16:19:55 +02002071extern __printf(8, 9)
2072int drm_universal_plane_init(struct drm_device *dev,
2073 struct drm_plane *plane,
2074 unsigned long possible_crtcs,
2075 const struct drm_plane_funcs *funcs,
2076 const uint32_t *formats,
2077 unsigned int format_count,
2078 enum drm_plane_type type,
2079 const char *name, ...);
Jesse Barnes8cf5c912011-11-14 14:51:27 -08002080extern int drm_plane_init(struct drm_device *dev,
2081 struct drm_plane *plane,
2082 unsigned long possible_crtcs,
2083 const struct drm_plane_funcs *funcs,
Thierry Reding45e37432015-08-12 16:54:28 +02002084 const uint32_t *formats, unsigned int format_count,
Matt Roperdc415ff2014-04-01 15:22:36 -07002085 bool is_primary);
Jesse Barnes8cf5c912011-11-14 14:51:27 -08002086extern void drm_plane_cleanup(struct drm_plane *plane);
Chris Wilson490d3d12016-05-27 20:05:00 +01002087
2088/**
2089 * drm_plane_index - find the index of a registered plane
2090 * @plane: plane to find index for
2091 *
2092 * Given a registered plane, return the index of that plane within a DRM
2093 * device's list of planes.
2094 */
2095static inline unsigned int drm_plane_index(struct drm_plane *plane)
2096{
2097 return plane->index;
2098}
Chandra Konduruf81338a2015-04-09 17:36:21 -07002099extern struct drm_plane * drm_plane_from_index(struct drm_device *dev, int idx);
Ville Syrjälä9125e612013-06-03 16:10:40 +03002100extern void drm_plane_force_disable(struct drm_plane *plane);
Gustavo Padovanecb7e162014-12-01 15:40:09 -08002101extern void drm_crtc_get_hv_timing(const struct drm_display_mode *mode,
2102 int *hdisplay, int *vdisplay);
Lukas Wunner6a0d9522016-06-08 18:47:27 +02002103extern int drm_crtc_force_disable(struct drm_crtc *crtc);
2104extern int drm_crtc_force_disable_all(struct drm_device *dev);
Jesse Barnes8cf5c912011-11-14 14:51:27 -08002105
Dave Airlief453ba02008-11-07 14:05:41 -08002106extern void drm_mode_config_init(struct drm_device *dev);
Chris Wilsoneb033552011-01-24 15:11:08 +00002107extern void drm_mode_config_reset(struct drm_device *dev);
Dave Airlief453ba02008-11-07 14:05:41 -08002108extern void drm_mode_config_cleanup(struct drm_device *dev);
Dave Airlief453ba02008-11-07 14:05:41 -08002109
Rob Clark5ea22f22014-05-30 11:34:01 -04002110static inline bool drm_property_type_is(struct drm_property *property,
2111 uint32_t type)
2112{
2113 /* instanceof for props.. handles extended type vs original types: */
2114 if (property->flags & DRM_MODE_PROP_EXTENDED_TYPE)
2115 return (property->flags & DRM_MODE_PROP_EXTENDED_TYPE) == type;
2116 return property->flags & type;
2117}
2118
Paulo Zanonic5431882012-05-15 18:09:02 -03002119extern int drm_object_property_set_value(struct drm_mode_object *obj,
2120 struct drm_property *property,
2121 uint64_t val);
2122extern int drm_object_property_get_value(struct drm_mode_object *obj,
2123 struct drm_property *property,
2124 uint64_t *value);
Dave Airlief453ba02008-11-07 14:05:41 -08002125
Paulo Zanonic5431882012-05-15 18:09:02 -03002126extern void drm_object_attach_property(struct drm_mode_object *obj,
2127 struct drm_property *property,
2128 uint64_t init_val);
Dave Airlief453ba02008-11-07 14:05:41 -08002129extern struct drm_property *drm_property_create(struct drm_device *dev, int flags,
2130 const char *name, int num_values);
Sascha Hauer4a67d392012-02-06 10:58:17 +01002131extern struct drm_property *drm_property_create_enum(struct drm_device *dev, int flags,
2132 const char *name,
2133 const struct drm_prop_enum_list *props,
2134 int num_values);
Rob Clark49e27542012-05-17 02:23:26 -06002135struct drm_property *drm_property_create_bitmask(struct drm_device *dev,
2136 int flags, const char *name,
2137 const struct drm_prop_enum_list *props,
Ville Syrjälä7689ffb2014-07-08 10:31:52 +05302138 int num_props,
2139 uint64_t supported_bits);
Sascha Hauerd9bc3c02012-02-06 10:58:18 +01002140struct drm_property *drm_property_create_range(struct drm_device *dev, int flags,
2141 const char *name,
2142 uint64_t min, uint64_t max);
Rob Clarkebc44cf2012-09-12 22:22:31 -05002143struct drm_property *drm_property_create_signed_range(struct drm_device *dev,
2144 int flags, const char *name,
2145 int64_t min, int64_t max);
Rob Clark98f75de2014-05-30 11:37:03 -04002146struct drm_property *drm_property_create_object(struct drm_device *dev,
2147 int flags, const char *name, uint32_t type);
Daniel Vetter960cd9d2015-01-21 08:47:38 +01002148struct drm_property *drm_property_create_bool(struct drm_device *dev, int flags,
2149 const char *name);
Daniel Stone6bcacf52015-04-20 19:22:55 +01002150struct drm_property_blob *drm_property_create_blob(struct drm_device *dev,
2151 size_t length,
2152 const void *data);
2153struct drm_property_blob *drm_property_lookup_blob(struct drm_device *dev,
2154 uint32_t id);
Daniel Vetteradebd6f2016-08-12 22:48:49 +02002155int drm_property_replace_global_blob(struct drm_device *dev,
2156 struct drm_property_blob **replace,
2157 size_t length,
2158 const void *data,
2159 struct drm_mode_object *obj_holds_id,
2160 struct drm_property *prop_holds_id);
Daniel Stone6bcacf52015-04-20 19:22:55 +01002161struct drm_property_blob *drm_property_reference_blob(struct drm_property_blob *blob);
2162void drm_property_unreference_blob(struct drm_property_blob *blob);
Dave Airlief453ba02008-11-07 14:05:41 -08002163extern void drm_property_destroy(struct drm_device *dev, struct drm_property *property);
2164extern int drm_property_add_enum(struct drm_property *property, int index,
2165 uint64_t value, const char *name);
Sascha Hauer4cae5b82012-02-01 11:38:23 +01002166extern int drm_mode_crtc_set_gamma_size(struct drm_crtc *crtc,
Dave Airlief453ba02008-11-07 14:05:41 -08002167 int gamma_size);
Rob Clark98f75de2014-05-30 11:37:03 -04002168
Daniel Vetter2d13b672012-12-11 13:47:23 +01002169extern int drm_mode_set_config_internal(struct drm_mode_set *set);
Daniel Vetter81065542016-06-21 10:54:13 +02002170
Jesse Barnes308e5bc2011-11-14 14:51:28 -08002171extern uint32_t drm_mode_legacy_fb_format(uint32_t bpp, uint32_t depth);
Dave Airlie138f9eb2014-10-20 16:17:17 +10002172
2173extern struct drm_tile_group *drm_mode_create_tile_group(struct drm_device *dev,
2174 char topology[8]);
2175extern struct drm_tile_group *drm_mode_get_tile_group(struct drm_device *dev,
2176 char topology[8]);
2177extern void drm_mode_put_tile_group(struct drm_device *dev,
2178 struct drm_tile_group *tg);
Dave Airlieff72145b2011-02-07 12:16:14 +10002179
Thomas Wood3a5f87c2014-08-20 14:45:00 +01002180extern int drm_mode_plane_set_obj_prop(struct drm_plane *plane,
2181 struct drm_property *property,
2182 uint64_t value);
Dave Airlie248dbc22011-11-29 20:02:54 +00002183
Ville Syrjäläc1df5f32014-07-08 10:31:53 +05302184extern struct drm_property *drm_mode_create_rotation_property(struct drm_device *dev,
2185 unsigned int supported_rotations);
Ville Syrjälä3c9855f2014-07-08 10:31:56 +05302186extern unsigned int drm_rotation_simplify(unsigned int rotation,
2187 unsigned int supported_rotations);
Jyri Sarhaf8ed34a2016-06-07 15:09:14 +03002188extern void drm_crtc_enable_color_mgmt(struct drm_crtc *crtc,
2189 uint degamma_lut_size,
2190 bool has_ctm,
2191 uint gamma_lut_size);
Marek Szyprowski44d1240d2016-06-13 11:11:26 +02002192
2193int drm_plane_create_zpos_property(struct drm_plane *plane,
2194 unsigned int zpos,
2195 unsigned int min, unsigned int max);
2196
2197int drm_plane_create_zpos_immutable_property(struct drm_plane *plane,
2198 unsigned int zpos);
2199
Russell King96f60e32012-08-15 13:59:49 +01002200/* Helpers */
Rob Clarka2b34e22013-10-05 16:36:52 -04002201static inline struct drm_plane *drm_plane_find(struct drm_device *dev,
2202 uint32_t id)
2203{
2204 struct drm_mode_object *mo;
2205 mo = drm_mode_object_find(dev, id, DRM_MODE_OBJECT_PLANE);
2206 return mo ? obj_to_plane(mo) : NULL;
2207}
2208
Russell King96f60e32012-08-15 13:59:49 +01002209static inline struct drm_crtc *drm_crtc_find(struct drm_device *dev,
2210 uint32_t id)
2211{
2212 struct drm_mode_object *mo;
2213 mo = drm_mode_object_find(dev, id, DRM_MODE_OBJECT_CRTC);
2214 return mo ? obj_to_crtc(mo) : NULL;
2215}
2216
Rob Clarka2b34e22013-10-05 16:36:52 -04002217static inline struct drm_property *drm_property_find(struct drm_device *dev,
2218 uint32_t id)
2219{
2220 struct drm_mode_object *mo;
2221 mo = drm_mode_object_find(dev, id, DRM_MODE_OBJECT_PROPERTY);
2222 return mo ? obj_to_property(mo) : NULL;
2223}
2224
Lionel Landwerlin5488dc12016-02-26 17:05:00 +00002225/*
2226 * Extract a degamma/gamma LUT value provided by user and round it to the
2227 * precision supported by the hardware.
2228 */
2229static inline uint32_t drm_color_lut_extract(uint32_t user_input,
2230 uint32_t bit_precision)
2231{
Lionel Landwerlin644a8052016-03-22 14:10:33 +00002232 uint32_t val = user_input;
Lionel Landwerlin5488dc12016-02-26 17:05:00 +00002233 uint32_t max = 0xffff >> (16 - bit_precision);
2234
Lionel Landwerlin644a8052016-03-22 14:10:33 +00002235 /* Round only if we're not using full precision. */
2236 if (bit_precision < 16) {
2237 val += 1UL << (16 - bit_precision - 1);
2238 val >>= 16 - bit_precision;
2239 }
Lionel Landwerlin5488dc12016-02-26 17:05:00 +00002240
2241 return clamp_val(val, 0, max);
2242}
2243
Matt Ropere27dde32014-04-01 15:22:30 -07002244/* Plane list iterator for legacy (overlay only) planes. */
Daniel Vetter4ea50e92015-07-09 23:44:24 +02002245#define drm_for_each_legacy_plane(plane, dev) \
2246 list_for_each_entry(plane, &(dev)->mode_config.plane_list, head) \
Jani Nikula373701b2015-11-24 21:21:55 +02002247 for_each_if (plane->type == DRM_PLANE_TYPE_OVERLAY)
Matt Ropere27dde32014-04-01 15:22:30 -07002248
Daniel Vetter6295d602015-07-09 23:44:25 +02002249#define drm_for_each_plane(plane, dev) \
2250 list_for_each_entry(plane, &(dev)->mode_config.plane_list, head)
2251
2252#define drm_for_each_crtc(crtc, dev) \
2253 list_for_each_entry(crtc, &(dev)->mode_config.crtc_list, head)
2254
Daniel Vetter7a3f3d62015-07-09 23:44:28 +02002255static inline void
2256assert_drm_connector_list_read_locked(struct drm_mode_config *mode_config)
2257{
Daniel Vettercff20ba2015-07-09 23:44:33 +02002258 /*
2259 * The connector hotadd/remove code currently grabs both locks when
2260 * updating lists. Hence readers need only hold either of them to be
2261 * safe and the check amounts to
2262 *
2263 * WARN_ON(not_holding(A) && not_holding(B)).
2264 */
2265 WARN_ON(!mutex_is_locked(&mode_config->mutex) &&
2266 !drm_modeset_is_locked(&mode_config->connection_mutex));
Daniel Vetter7a3f3d62015-07-09 23:44:28 +02002267}
2268
Daniel Vetter6295d602015-07-09 23:44:25 +02002269#define drm_for_each_connector(connector, dev) \
Daniel Vetter7a3f3d62015-07-09 23:44:28 +02002270 for (assert_drm_connector_list_read_locked(&(dev)->mode_config), \
2271 connector = list_first_entry(&(dev)->mode_config.connector_list, \
2272 struct drm_connector, head); \
2273 &connector->head != (&(dev)->mode_config.connector_list); \
2274 connector = list_next_entry(connector, head))
Daniel Vetter6295d602015-07-09 23:44:25 +02002275
2276#define drm_for_each_encoder(encoder, dev) \
2277 list_for_each_entry(encoder, &(dev)->mode_config.encoder_list, head)
2278
2279#define drm_for_each_fb(fb, dev) \
Daniel Vetter4676ba02015-07-09 23:44:30 +02002280 for (WARN_ON(!mutex_is_locked(&(dev)->mode_config.fb_lock)), \
2281 fb = list_first_entry(&(dev)->mode_config.fb_list, \
2282 struct drm_framebuffer, head); \
2283 &fb->head != (&(dev)->mode_config.fb_list); \
2284 fb = list_next_entry(fb, head))
Daniel Vetter6295d602015-07-09 23:44:25 +02002285
Daniel Vetter81065542016-06-21 10:54:13 +02002286/* drm_edid.c */
2287bool drm_probe_ddc(struct i2c_adapter *adapter);
2288struct edid *drm_get_edid(struct drm_connector *connector,
2289 struct i2c_adapter *adapter);
2290struct edid *drm_get_edid_switcheroo(struct drm_connector *connector,
2291 struct i2c_adapter *adapter);
2292struct edid *drm_edid_duplicate(const struct edid *edid);
2293int drm_add_edid_modes(struct drm_connector *connector, struct edid *edid);
2294
2295u8 drm_match_cea_mode(const struct drm_display_mode *to_match);
2296enum hdmi_picture_aspect drm_get_cea_aspect_ratio(const u8 video_code);
2297bool drm_detect_hdmi_monitor(struct edid *edid);
2298bool drm_detect_monitor_audio(struct edid *edid);
2299bool drm_rgb_quant_range_selectable(struct edid *edid);
2300int drm_add_modes_noedid(struct drm_connector *connector,
2301 int hdisplay, int vdisplay);
2302void drm_set_preferred_mode(struct drm_connector *connector,
2303 int hpref, int vpref);
2304
2305int drm_edid_header_is_valid(const u8 *raw_edid);
2306bool drm_edid_block_valid(u8 *raw_edid, int block, bool print_bad_edid,
2307 bool *edid_corrupt);
2308bool drm_edid_is_valid(struct edid *edid);
2309void drm_edid_get_monitor_name(struct edid *edid, char *name,
2310 int buflen);
2311struct drm_display_mode *drm_mode_find_dmt(struct drm_device *dev,
2312 int hsize, int vsize, int fresh,
2313 bool rb);
2314
2315/* drm_bridge.c */
2316extern int drm_bridge_add(struct drm_bridge *bridge);
2317extern void drm_bridge_remove(struct drm_bridge *bridge);
2318extern struct drm_bridge *of_drm_find_bridge(struct device_node *np);
2319extern int drm_bridge_attach(struct drm_device *dev, struct drm_bridge *bridge);
Andrea Merellocf3bef92016-08-25 11:04:32 +02002320extern void drm_bridge_detach(struct drm_bridge *bridge);
Daniel Vetter81065542016-06-21 10:54:13 +02002321
2322bool drm_bridge_mode_fixup(struct drm_bridge *bridge,
2323 const struct drm_display_mode *mode,
2324 struct drm_display_mode *adjusted_mode);
2325void drm_bridge_disable(struct drm_bridge *bridge);
2326void drm_bridge_post_disable(struct drm_bridge *bridge);
2327void drm_bridge_mode_set(struct drm_bridge *bridge,
2328 struct drm_display_mode *mode,
2329 struct drm_display_mode *adjusted_mode);
2330void drm_bridge_pre_enable(struct drm_bridge *bridge);
2331void drm_bridge_enable(struct drm_bridge *bridge);
2332
Dave Airlief453ba02008-11-07 14:05:41 -08002333#endif /* __DRM_CRTC_H__ */