blob: 3d33c90da9e5f3af503f0983a52d09405088893f [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 Vetter949619f2016-08-29 10:27:51 +020039#include <drm/drm_mode_object.h>
Daniel Vetter7520a272016-08-15 16:07:02 +020040#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>
Daniel Vetter59e71ee2016-08-29 10:27:55 +020044#include <drm/drm_property.h>
Jesse Barnes308e5bc2011-11-14 14:51:28 -080045
Dave Airlief453ba02008-11-07 14:05:41 -080046struct drm_device;
47struct drm_mode_set;
Thierry Reding595887e2012-11-21 15:00:47 +010048struct drm_file;
49struct drm_clip_rect;
Russell King7e435aa2014-06-15 11:07:12 +010050struct device_node;
Daniel Vettere2330f02014-10-29 11:34:56 +010051struct fence;
Daniel Vetter81065542016-06-21 10:54:13 +020052struct edid;
Dave Airlief453ba02008-11-07 14:05:41 -080053
Rob Clarkebc44cf2012-09-12 22:22:31 -050054static inline int64_t U642I64(uint64_t val)
55{
56 return (int64_t)*((int64_t *)&val);
57}
58static inline uint64_t I642U64(int64_t val)
59{
60 return (uint64_t)*((uint64_t *)&val);
61}
62
Robert Feketed9c38242015-11-02 16:14:08 +010063/*
64 * Rotation property bits. DRM_ROTATE_<degrees> rotates the image by the
65 * specified amount in degrees in counter clockwise direction. DRM_REFLECT_X and
66 * DRM_REFLECT_Y reflects the image along the specified axis prior to rotation
67 */
Joonas Lahtinen31ad61e2016-07-29 08:50:05 +030068#define DRM_ROTATE_0 BIT(0)
69#define DRM_ROTATE_90 BIT(1)
70#define DRM_ROTATE_180 BIT(2)
71#define DRM_ROTATE_270 BIT(3)
72#define DRM_ROTATE_MASK (DRM_ROTATE_0 | DRM_ROTATE_90 | \
73 DRM_ROTATE_180 | DRM_ROTATE_270)
74#define DRM_REFLECT_X BIT(4)
75#define DRM_REFLECT_Y BIT(5)
76#define DRM_REFLECT_MASK (DRM_REFLECT_X | DRM_REFLECT_Y)
Ville Syrjälä06596962014-07-08 10:31:51 +053077
Dave Airlie138f9eb2014-10-20 16:17:17 +100078/* data corresponds to displayid vend/prod/serial */
79struct drm_tile_group {
80 struct kref refcount;
81 struct drm_device *dev;
82 int id;
83 u8 group_data[8];
84};
85
Dave Airlief453ba02008-11-07 14:05:41 -080086struct drm_crtc;
Dave Airlief453ba02008-11-07 14:05:41 -080087struct drm_encoder;
Kristian Høgsbergd91d8a32009-11-17 12:43:55 -050088struct drm_pending_vblank_event;
Jesse Barnes8cf5c912011-11-14 14:51:27 -080089struct drm_plane;
Sean Paul3b336ec2013-08-14 16:47:37 -040090struct drm_bridge;
Daniel Vetter144ecb92014-10-27 20:28:44 +010091struct drm_atomic_state;
92
Daniel Vetter4490d4c2015-12-04 09:45:45 +010093struct drm_crtc_helper_funcs;
94struct drm_encoder_helper_funcs;
Daniel Vetter4490d4c2015-12-04 09:45:45 +010095struct drm_plane_helper_funcs;
96
Daniel Vetter144ecb92014-10-27 20:28:44 +010097/**
Daniel Vettercc4ceb42014-07-25 21:30:38 +020098 * struct drm_crtc_state - mutable CRTC state
Daniel Vetter07cc0ef2014-11-27 15:49:39 +010099 * @crtc: backpointer to the CRTC
Daniel Vetter144ecb92014-10-27 20:28:44 +0100100 * @enable: whether the CRTC should be enabled, gates all other state
Daniel Vetterd9b13622014-11-26 16:57:41 +0100101 * @active: whether the CRTC is actively displaying (used for DPMS)
Maarten Lankhorstfc596662015-07-21 13:28:57 +0200102 * @planes_changed: planes on this crtc are updated
103 * @mode_changed: crtc_state->mode or crtc_state->enable has been changed
104 * @active_changed: crtc_state->active has been toggled.
105 * @connectors_changed: connectors to this crtc have been updated
Marek Szyprowski44d1240d2016-06-13 11:11:26 +0200106 * @zpos_changed: zpos values of planes on this crtc have been updated
Lionel Landwerlin5488dc12016-02-26 17:05:00 +0000107 * @color_mgmt_changed: color management properties have changed (degamma or
108 * gamma LUT or CSC matrix)
Rob Clark6ddd3882014-11-21 15:28:31 -0500109 * @plane_mask: bitmask of (1 << drm_plane_index(plane)) of attached planes
Maarten Lankhorst4cd9fa52016-01-04 12:53:18 +0100110 * @connector_mask: bitmask of (1 << drm_connector_index(connector)) of attached connectors
Maarten Lankhorste87a52b2016-01-28 15:04:58 +0100111 * @encoder_mask: bitmask of (1 << drm_encoder_index(encoder)) of attached encoders
Daniel Vetter623369e2014-09-16 17:50:47 +0200112 * @last_vblank_count: for helpers and drivers to capture the vblank of the
113 * update to ensure framebuffer cleanup isn't done too early
Daniel Vetter2f324b42014-10-29 11:13:47 +0100114 * @adjusted_mode: for use by helpers and drivers to compute adjusted mode timings
Daniel Vetter144ecb92014-10-27 20:28:44 +0100115 * @mode: current mode timings
Daniel Vetterac3ba4a2016-05-31 23:11:10 +0200116 * @mode_blob: &drm_property_blob for @mode
Lionel Landwerlin5488dc12016-02-26 17:05:00 +0000117 * @degamma_lut: Lookup table for converting framebuffer pixel data
118 * before apply the conversion matrix
119 * @ctm: Transformation matrix
120 * @gamma_lut: Lookup table for converting pixel data after the
121 * conversion matrix
Daniel Vetter144ecb92014-10-27 20:28:44 +0100122 * @event: optional pointer to a DRM event to signal upon completion of the
123 * state update
124 * @state: backpointer to global drm_atomic_state
Daniel Vetterd9b13622014-11-26 16:57:41 +0100125 *
126 * Note that the distinction between @enable and @active is rather subtile:
127 * Flipping @active while @enable is set without changing anything else may
128 * never return in a failure from the ->atomic_check callback. Userspace assumes
129 * that a DPMS On will always succeed. In other words: @enable controls resource
130 * assignment, @active controls the actual hardware state.
Daniel Vetter144ecb92014-10-27 20:28:44 +0100131 */
132struct drm_crtc_state {
Daniel Vetter07cc0ef2014-11-27 15:49:39 +0100133 struct drm_crtc *crtc;
134
Daniel Vettercc4ceb42014-07-25 21:30:38 +0200135 bool enable;
Daniel Vetterd9b13622014-11-26 16:57:41 +0100136 bool active;
Daniel Vetter144ecb92014-10-27 20:28:44 +0100137
Daniel Vetterc2fcd272014-11-05 00:14:14 +0100138 /* computed state bits used by helpers and drivers */
139 bool planes_changed : 1;
Daniel Vetter623369e2014-09-16 17:50:47 +0200140 bool mode_changed : 1;
Daniel Vettereab3bbe2015-01-22 16:36:21 +0100141 bool active_changed : 1;
Maarten Lankhorstfc596662015-07-21 13:28:57 +0200142 bool connectors_changed : 1;
Marek Szyprowski44d1240d2016-06-13 11:11:26 +0200143 bool zpos_changed : 1;
Lionel Landwerlin5488dc12016-02-26 17:05:00 +0000144 bool color_mgmt_changed : 1;
Daniel Vetter623369e2014-09-16 17:50:47 +0200145
Rob Clark6ddd3882014-11-21 15:28:31 -0500146 /* attached planes bitmask:
147 * WARNING: transitional helpers do not maintain plane_mask so
148 * drivers not converted over to atomic helpers should not rely
149 * on plane_mask being accurate!
150 */
151 u32 plane_mask;
152
Maarten Lankhorst4cd9fa52016-01-04 12:53:18 +0100153 u32 connector_mask;
Maarten Lankhorste87a52b2016-01-28 15:04:58 +0100154 u32 encoder_mask;
Maarten Lankhorst4cd9fa52016-01-04 12:53:18 +0100155
Daniel Vetter623369e2014-09-16 17:50:47 +0200156 /* last_vblank_count: for vblank waits before cleanup */
157 u32 last_vblank_count;
Daniel Vetterc2fcd272014-11-05 00:14:14 +0100158
Daniel Vetter2f324b42014-10-29 11:13:47 +0100159 /* adjusted_mode: for use by helpers and drivers */
160 struct drm_display_mode adjusted_mode;
161
Daniel Vetter144ecb92014-10-27 20:28:44 +0100162 struct drm_display_mode mode;
163
Daniel Stone99cf4a22015-05-25 19:11:51 +0100164 /* blob property to expose current mode to atomic userspace */
165 struct drm_property_blob *mode_blob;
166
Lionel Landwerlin5488dc12016-02-26 17:05:00 +0000167 /* blob property to expose color management to userspace */
168 struct drm_property_blob *degamma_lut;
169 struct drm_property_blob *ctm;
170 struct drm_property_blob *gamma_lut;
171
Daniel Vetter144ecb92014-10-27 20:28:44 +0100172 struct drm_pending_vblank_event *event;
173
174 struct drm_atomic_state *state;
175};
Dave Airlief453ba02008-11-07 14:05:41 -0800176
177/**
Daniel Vetter3bf04012014-10-27 16:54:27 +0100178 * struct drm_crtc_funcs - control CRTCs for a given device
Dave Airlief453ba02008-11-07 14:05:41 -0800179 *
180 * The drm_crtc_funcs structure is the central CRTC management structure
181 * in the DRM. Each CRTC controls one or more connectors (note that the name
182 * CRTC is simply historical, a CRTC may control LVDS, VGA, DVI, TV out, etc.
183 * connectors, not just CRTs).
184 *
185 * Each driver is responsible for filling out this structure at startup time,
186 * in addition to providing other modesetting features, like i2c and DDC
187 * bus accessors.
188 */
189struct drm_crtc_funcs {
Daniel Vetter88548632015-12-04 09:45:48 +0100190 /**
191 * @reset:
192 *
193 * Reset CRTC hardware and software state to off. This function isn't
194 * called by the core directly, only through drm_mode_config_reset().
195 * It's not a helper hook only for historical reasons.
196 *
197 * Atomic drivers can use drm_atomic_helper_crtc_reset() to reset
198 * atomic state using this hook.
199 */
Chris Wilsoneb0335562011-01-24 15:11:08 +0000200 void (*reset)(struct drm_crtc *crtc);
Dave Airlief453ba02008-11-07 14:05:41 -0800201
Daniel Vetterf6da8c62015-12-04 09:46:00 +0100202 /**
203 * @cursor_set:
204 *
205 * Update the cursor image. The cursor position is relative to the CRTC
206 * and can be partially or fully outside of the visible area.
207 *
208 * Note that contrary to all other KMS functions the legacy cursor entry
209 * points don't take a framebuffer object, but instead take directly a
210 * raw buffer object id from the driver's buffer manager (which is
211 * either GEM or TTM for current drivers).
212 *
213 * This entry point is deprecated, drivers should instead implement
214 * universal plane support and register a proper cursor plane using
215 * drm_crtc_init_with_planes().
216 *
217 * This callback is optional
218 *
219 * RETURNS:
220 *
221 * 0 on success or a negative error code on failure.
222 */
Dave Airlief453ba02008-11-07 14:05:41 -0800223 int (*cursor_set)(struct drm_crtc *crtc, struct drm_file *file_priv,
224 uint32_t handle, uint32_t width, uint32_t height);
Daniel Vetterf6da8c62015-12-04 09:46:00 +0100225
226 /**
227 * @cursor_set2:
228 *
229 * Update the cursor image, including hotspot information. The hotspot
230 * must not affect the cursor position in CRTC coordinates, but is only
231 * meant as a hint for virtualized display hardware to coordinate the
232 * guests and hosts cursor position. The cursor hotspot is relative to
233 * the cursor image. Otherwise this works exactly like @cursor_set.
234 *
235 * This entry point is deprecated, drivers should instead implement
236 * universal plane support and register a proper cursor plane using
237 * drm_crtc_init_with_planes().
238 *
239 * This callback is optional.
240 *
241 * RETURNS:
242 *
243 * 0 on success or a negative error code on failure.
244 */
Dave Airlie4c813d42013-06-20 11:48:52 +1000245 int (*cursor_set2)(struct drm_crtc *crtc, struct drm_file *file_priv,
246 uint32_t handle, uint32_t width, uint32_t height,
247 int32_t hot_x, int32_t hot_y);
Daniel Vetterf6da8c62015-12-04 09:46:00 +0100248
249 /**
250 * @cursor_move:
251 *
252 * Update the cursor position. The cursor does not need to be visible
253 * when this hook is called.
254 *
255 * This entry point is deprecated, drivers should instead implement
256 * universal plane support and register a proper cursor plane using
257 * drm_crtc_init_with_planes().
258 *
259 * This callback is optional.
260 *
261 * RETURNS:
262 *
263 * 0 on success or a negative error code on failure.
264 */
Dave Airlief453ba02008-11-07 14:05:41 -0800265 int (*cursor_move)(struct drm_crtc *crtc, int x, int y);
266
Daniel Vetterf6da8c62015-12-04 09:46:00 +0100267 /**
268 * @gamma_set:
269 *
270 * Set gamma on the CRTC.
271 *
272 * This callback is optional.
273 *
274 * NOTE:
275 *
276 * Drivers that support gamma tables and also fbdev emulation through
277 * the provided helper library need to take care to fill out the gamma
278 * hooks for both. Currently there's a bit an unfortunate duplication
279 * going on, which should eventually be unified to just one set of
280 * hooks.
281 */
Maarten Lankhorst7ea77282016-06-07 12:49:30 +0200282 int (*gamma_set)(struct drm_crtc *crtc, u16 *r, u16 *g, u16 *b,
283 uint32_t size);
Daniel Vetter88548632015-12-04 09:45:48 +0100284
285 /**
286 * @destroy:
287 *
288 * Clean up plane resources. This is only called at driver unload time
289 * through drm_mode_config_cleanup() since a CRTC cannot be hotplugged
290 * in DRM.
291 */
Dave Airlief453ba02008-11-07 14:05:41 -0800292 void (*destroy)(struct drm_crtc *crtc);
293
Daniel Vetterf6da8c62015-12-04 09:46:00 +0100294 /**
295 * @set_config:
296 *
297 * This is the main legacy entry point to change the modeset state on a
298 * CRTC. All the details of the desired configuration are passed in a
299 * struct &drm_mode_set - see there for details.
300 *
301 * Drivers implementing atomic modeset should use
302 * drm_atomic_helper_set_config() to implement this hook.
303 *
304 * RETURNS:
305 *
306 * 0 on success or a negative error code on failure.
307 */
Dave Airlief453ba02008-11-07 14:05:41 -0800308 int (*set_config)(struct drm_mode_set *set);
Kristian Høgsbergd91d8a32009-11-17 12:43:55 -0500309
Daniel Vetterf6da8c62015-12-04 09:46:00 +0100310 /**
311 * @page_flip:
312 *
313 * Legacy entry point to schedule a flip to the given framebuffer.
314 *
315 * Page flipping is a synchronization mechanism that replaces the frame
316 * buffer being scanned out by the CRTC with a new frame buffer during
317 * vertical blanking, avoiding tearing (except when requested otherwise
318 * through the DRM_MODE_PAGE_FLIP_ASYNC flag). When an application
319 * requests a page flip the DRM core verifies that the new frame buffer
320 * is large enough to be scanned out by the CRTC in the currently
321 * configured mode and then calls the CRTC ->page_flip() operation with a
322 * pointer to the new frame buffer.
323 *
324 * The driver must wait for any pending rendering to the new framebuffer
325 * to complete before executing the flip. It should also wait for any
326 * pending rendering from other drivers if the underlying buffer is a
327 * shared dma-buf.
328 *
329 * An application can request to be notified when the page flip has
330 * completed. The drm core will supply a struct &drm_event in the event
331 * parameter in this case. This can be handled by the
332 * drm_crtc_send_vblank_event() function, which the driver should call on
333 * the provided event upon completion of the flip. Note that if
334 * the driver supports vblank signalling and timestamping the vblank
335 * counters and timestamps must agree with the ones returned from page
336 * flip events. With the current vblank helper infrastructure this can
337 * be achieved by holding a vblank reference while the page flip is
338 * pending, acquired through drm_crtc_vblank_get() and released with
339 * drm_crtc_vblank_put(). Drivers are free to implement their own vblank
340 * counter and timestamp tracking though, e.g. if they have accurate
341 * timestamp registers in hardware.
342 *
Daniel Vetterf6da8c62015-12-04 09:46:00 +0100343 * This callback is optional.
344 *
345 * NOTE:
346 *
347 * Very early versions of the KMS ABI mandated that the driver must
348 * block (but not reject) any rendering to the old framebuffer until the
349 * flip operation has completed and the old framebuffer is no longer
350 * visible. This requirement has been lifted, and userspace is instead
351 * expected to request delivery of an event and wait with recycling old
352 * buffers until such has been received.
353 *
354 * RETURNS:
355 *
356 * 0 on success or a negative error code on failure. Note that if a
357 * ->page_flip() operation is already pending the callback should return
358 * -EBUSY. Pageflips on a disabled CRTC (either by setting a NULL mode
359 * or just runtime disabled through DPMS respectively the new atomic
Daniel Vetter4cba6852015-12-08 09:49:20 +0100360 * "ACTIVE" state) should result in an -EINVAL error code. Note that
361 * drm_atomic_helper_page_flip() checks this already for atomic drivers.
Kristian Høgsbergd91d8a32009-11-17 12:43:55 -0500362 */
363 int (*page_flip)(struct drm_crtc *crtc,
364 struct drm_framebuffer *fb,
Keith Packarded8d1972013-07-22 18:49:58 -0700365 struct drm_pending_vblank_event *event,
366 uint32_t flags);
Paulo Zanonibffd9de02012-05-15 18:09:05 -0300367
Daniel Vetter88548632015-12-04 09:45:48 +0100368 /**
369 * @set_property:
370 *
371 * This is the legacy entry point to update a property attached to the
372 * CRTC.
373 *
374 * Drivers implementing atomic modeset should use
375 * drm_atomic_helper_crtc_set_property() to implement this hook.
376 *
377 * This callback is optional if the driver does not support any legacy
378 * driver-private properties.
379 *
380 * RETURNS:
381 *
382 * 0 on success or a negative error code on failure.
383 */
Paulo Zanonibffd9de02012-05-15 18:09:05 -0300384 int (*set_property)(struct drm_crtc *crtc,
385 struct drm_property *property, uint64_t val);
Daniel Vetter144ecb92014-10-27 20:28:44 +0100386
Daniel Vetter88548632015-12-04 09:45:48 +0100387 /**
388 * @atomic_duplicate_state:
389 *
390 * Duplicate the current atomic state for this CRTC and return it.
391 * The core and helpers gurantee that any atomic state duplicated with
392 * this hook and still owned by the caller (i.e. not transferred to the
393 * driver by calling ->atomic_commit() from struct
394 * &drm_mode_config_funcs) will be cleaned up by calling the
395 * @atomic_destroy_state hook in this structure.
396 *
397 * Atomic drivers which don't subclass struct &drm_crtc should use
398 * drm_atomic_helper_crtc_duplicate_state(). Drivers that subclass the
399 * state structure to extend it with driver-private state should use
400 * __drm_atomic_helper_crtc_duplicate_state() to make sure shared state is
401 * duplicated in a consistent fashion across drivers.
402 *
403 * It is an error to call this hook before crtc->state has been
404 * initialized correctly.
405 *
406 * NOTE:
407 *
408 * If the duplicate state references refcounted resources this hook must
409 * acquire a reference for each of them. The driver must release these
410 * references again in @atomic_destroy_state.
411 *
412 * RETURNS:
413 *
414 * Duplicated atomic state or NULL when the allocation failed.
415 */
Daniel Vetter144ecb92014-10-27 20:28:44 +0100416 struct drm_crtc_state *(*atomic_duplicate_state)(struct drm_crtc *crtc);
Daniel Vetter88548632015-12-04 09:45:48 +0100417
418 /**
419 * @atomic_destroy_state:
420 *
421 * Destroy a state duplicated with @atomic_duplicate_state and release
422 * or unreference all resources it references
423 */
Daniel Vetter144ecb92014-10-27 20:28:44 +0100424 void (*atomic_destroy_state)(struct drm_crtc *crtc,
Daniel Vettercc4ceb42014-07-25 21:30:38 +0200425 struct drm_crtc_state *state);
Daniel Vetter88548632015-12-04 09:45:48 +0100426
427 /**
428 * @atomic_set_property:
429 *
430 * Decode a driver-private property value and store the decoded value
431 * into the passed-in state structure. Since the atomic core decodes all
432 * standardized properties (even for extensions beyond the core set of
433 * properties which might not be implemented by all drivers) this
434 * requires drivers to subclass the state structure.
435 *
436 * Such driver-private properties should really only be implemented for
437 * truly hardware/vendor specific state. Instead it is preferred to
438 * standardize atomic extension and decode the properties used to expose
439 * such an extension in the core.
440 *
441 * Do not call this function directly, use
442 * drm_atomic_crtc_set_property() instead.
443 *
444 * This callback is optional if the driver does not support any
445 * driver-private atomic properties.
446 *
447 * NOTE:
448 *
449 * This function is called in the state assembly phase of atomic
450 * modesets, which can be aborted for any reason (including on
451 * userspace's request to just check whether a configuration would be
452 * possible). Drivers MUST NOT touch any persistent state (hardware or
453 * software) or data structures except the passed in @state parameter.
454 *
455 * Also since userspace controls in which order properties are set this
456 * function must not do any input validation (since the state update is
457 * incomplete and hence likely inconsistent). Instead any such input
458 * validation must be done in the various atomic_check callbacks.
459 *
460 * RETURNS:
461 *
462 * 0 if the property has been found, -EINVAL if the property isn't
463 * implemented by the driver (which should never happen, the core only
464 * asks for properties attached to this CRTC). No other validation is
465 * allowed by the driver. The core already checks that the property
466 * value is within the range (integer, valid enum value, ...) the driver
467 * set when registering the property.
468 */
Daniel Vetter144ecb92014-10-27 20:28:44 +0100469 int (*atomic_set_property)(struct drm_crtc *crtc,
470 struct drm_crtc_state *state,
471 struct drm_property *property,
472 uint64_t val);
Daniel Vetter88548632015-12-04 09:45:48 +0100473 /**
474 * @atomic_get_property:
475 *
476 * Reads out the decoded driver-private property. This is used to
Daniel Vetterc6b0ca32015-12-04 09:46:01 +0100477 * implement the GETCRTC IOCTL.
Daniel Vetter88548632015-12-04 09:45:48 +0100478 *
479 * Do not call this function directly, use
480 * drm_atomic_crtc_get_property() instead.
481 *
482 * This callback is optional if the driver does not support any
483 * driver-private atomic properties.
484 *
485 * RETURNS:
486 *
487 * 0 on success, -EINVAL if the property isn't implemented by the
488 * driver (which should never happen, the core only asks for
489 * properties attached to this CRTC).
490 */
Rob Clarkac9c9252014-12-18 16:01:47 -0500491 int (*atomic_get_property)(struct drm_crtc *crtc,
492 const struct drm_crtc_state *state,
493 struct drm_property *property,
494 uint64_t *val);
Benjamin Gaignard79190ea2016-06-21 16:37:09 +0200495
496 /**
497 * @late_register:
498 *
499 * This optional hook can be used to register additional userspace
500 * interfaces attached to the crtc like debugfs interfaces.
501 * It is called late in the driver load sequence from drm_dev_register().
502 * Everything added from this callback should be unregistered in
503 * the early_unregister callback.
504 *
505 * Returns:
506 *
507 * 0 on success, or a negative error code on failure.
508 */
509 int (*late_register)(struct drm_crtc *crtc);
510
511 /**
512 * @early_unregister:
513 *
514 * This optional hook should be used to unregister the additional
515 * userspace interfaces attached to the crtc from
516 * late_unregister(). It is called from drm_dev_unregister(),
517 * early in the driver unload sequence to disable userspace access
518 * before data structures are torndown.
519 */
520 void (*early_unregister)(struct drm_crtc *crtc);
Dave Airlief453ba02008-11-07 14:05:41 -0800521};
522
523/**
Daniel Vetter3bf04012014-10-27 16:54:27 +0100524 * struct drm_crtc - central CRTC control structure
Jesse Barnes77491632011-11-07 12:03:14 -0800525 * @dev: parent DRM device
Daniel Vetter2c0c33d2014-10-27 20:19:38 +0100526 * @port: OF node used by drm_of_find_possible_crtcs()
Jesse Barnes77491632011-11-07 12:03:14 -0800527 * @head: list management
Daniel Vetterac3ba4a2016-05-31 23:11:10 +0200528 * @name: human readable name, can be overwritten by the driver
Rob Clark51fd3712013-11-19 12:10:12 -0500529 * @mutex: per-CRTC locking
Jesse Barnes77491632011-11-07 12:03:14 -0800530 * @base: base KMS object for ID tracking etc.
Matt Ropere13161a2014-04-01 15:22:38 -0700531 * @primary: primary plane for this CRTC
532 * @cursor: cursor plane for this CRTC
Daniel Vetter2c0c33d2014-10-27 20:19:38 +0100533 * @cursor_x: current x position of the cursor, used for universal cursor planes
534 * @cursor_y: current y position of the cursor, used for universal cursor planes
Dave Airlief453ba02008-11-07 14:05:41 -0800535 * @enabled: is this CRTC enabled?
Jesse Barnes77491632011-11-07 12:03:14 -0800536 * @mode: current mode timings
537 * @hwmode: mode timings as programmed to hw regs
Dave Airlief453ba02008-11-07 14:05:41 -0800538 * @x: x position on screen
539 * @y: y position on screen
Dave Airlief453ba02008-11-07 14:05:41 -0800540 * @funcs: CRTC control functions
Jesse Barnes77491632011-11-07 12:03:14 -0800541 * @gamma_size: size of gamma ramp
542 * @gamma_store: gamma ramp values
Jesse Barnes77491632011-11-07 12:03:14 -0800543 * @helper_private: mid-layer private data
Paulo Zanonibffd9de02012-05-15 18:09:05 -0300544 * @properties: property tracking for this CRTC
Dave Airlief453ba02008-11-07 14:05:41 -0800545 *
546 * Each CRTC may have one or more connectors associated with it. This structure
547 * allows the CRTC to be controlled.
548 */
549struct drm_crtc {
550 struct drm_device *dev;
Russell King7e435aa2014-06-15 11:07:12 +0100551 struct device_node *port;
Dave Airlief453ba02008-11-07 14:05:41 -0800552 struct list_head head;
553
Ville Syrjäläfa3ab4c2015-12-08 18:41:53 +0200554 char *name;
555
Daniel Vetterac3ba4a2016-05-31 23:11:10 +0200556 /**
557 * @mutex:
Daniel Vetter29494c12012-12-02 02:18:25 +0100558 *
559 * This provides a read lock for the overall crtc state (mode, dpms
560 * state, ...) and a write lock for everything which can be update
Daniel Vetterac3ba4a2016-05-31 23:11:10 +0200561 * without a full modeset (fb, cursor data, crtc properties ...). Full
562 * modeset also need to grab dev->mode_config.connection_mutex.
Daniel Vetter29494c12012-12-02 02:18:25 +0100563 */
Rob Clark51fd3712013-11-19 12:10:12 -0500564 struct drm_modeset_lock mutex;
Daniel Vetter29494c12012-12-02 02:18:25 +0100565
Dave Airlief453ba02008-11-07 14:05:41 -0800566 struct drm_mode_object base;
567
Matt Ropere13161a2014-04-01 15:22:38 -0700568 /* primary and cursor planes for CRTC */
569 struct drm_plane *primary;
570 struct drm_plane *cursor;
571
Daniel Vetter96094082016-07-15 21:47:59 +0200572 /**
573 * @index: Position inside the mode_config.list, can be used as an array
574 * index. It is invariant over the lifetime of the CRTC.
575 */
Chris Wilson490d3d12016-05-27 20:05:00 +0100576 unsigned index;
577
Matt Roper161d0dc2014-06-10 08:28:10 -0700578 /* position of cursor plane on crtc */
579 int cursor_x;
580 int cursor_y;
581
Dave Airlief453ba02008-11-07 14:05:41 -0800582 bool enabled;
583
Mario Kleiner27641c32010-10-23 04:20:23 +0200584 /* Requested mode from modesetting. */
Dave Airlief453ba02008-11-07 14:05:41 -0800585 struct drm_display_mode mode;
586
Mario Kleiner27641c32010-10-23 04:20:23 +0200587 /* Programmed mode in hw, after adjustments for encoders,
588 * crtc, panel scaling etc. Needed for timestamping etc.
589 */
590 struct drm_display_mode hwmode;
591
Dave Airlief453ba02008-11-07 14:05:41 -0800592 int x, y;
Dave Airlief453ba02008-11-07 14:05:41 -0800593 const struct drm_crtc_funcs *funcs;
594
Lionel Landwerlin5488dc12016-02-26 17:05:00 +0000595 /* Legacy FB CRTC gamma size for reporting to userspace */
Dave Airlief453ba02008-11-07 14:05:41 -0800596 uint32_t gamma_size;
597 uint16_t *gamma_store;
598
599 /* if you are using the helper */
Daniel Vetter4490d4c2015-12-04 09:45:45 +0100600 const struct drm_crtc_helper_funcs *helper_private;
Paulo Zanonibffd9de02012-05-15 18:09:05 -0300601
602 struct drm_object_properties properties;
Daniel Vetterd059f652014-07-25 18:07:40 +0200603
Daniel Vetter3b24f7d2016-06-08 14:19:00 +0200604 /**
605 * @state:
606 *
607 * Current atomic state for this CRTC.
608 */
Daniel Vetter144ecb92014-10-27 20:28:44 +0100609 struct drm_crtc_state *state;
610
Daniel Vetter3b24f7d2016-06-08 14:19:00 +0200611 /**
612 * @commit_list:
613 *
614 * List of &drm_crtc_commit structures tracking pending commits.
615 * Protected by @commit_lock. This list doesn't hold its own full
616 * reference, but burrows it from the ongoing commit. Commit entries
617 * must be removed from this list once the commit is fully completed,
618 * but before it's correspoding &drm_atomic_state gets destroyed.
619 */
620 struct list_head commit_list;
621
622 /**
623 * @commit_lock:
624 *
625 * Spinlock to protect @commit_list.
626 */
627 spinlock_t commit_lock;
628
629 /**
630 * @acquire_ctx:
631 *
632 * Per-CRTC implicit acquire context used by atomic drivers for legacy
633 * IOCTLs, so that atomic drivers can get at the locking acquire
634 * context.
Daniel Vetterd059f652014-07-25 18:07:40 +0200635 */
636 struct drm_modeset_acquire_ctx *acquire_ctx;
Dave Airlief453ba02008-11-07 14:05:41 -0800637};
638
Daniel Vetter144ecb92014-10-27 20:28:44 +0100639/**
Daniel Vetter144ecb92014-10-27 20:28:44 +0100640 * struct drm_plane_state - mutable plane state
Daniel Vetter07cc0ef2014-11-27 15:49:39 +0100641 * @plane: backpointer to the plane
Daniel Vetter144ecb92014-10-27 20:28:44 +0100642 * @crtc: currently bound CRTC, NULL if disabled
Daniel Vettercc4ceb42014-07-25 21:30:38 +0200643 * @fb: currently bound framebuffer
Daniel Vettere2330f02014-10-29 11:34:56 +0100644 * @fence: optional fence to wait for before scanning out @fb
Daniel Vetter144ecb92014-10-27 20:28:44 +0100645 * @crtc_x: left position of visible portion of plane on crtc
646 * @crtc_y: upper position of visible portion of plane on crtc
647 * @crtc_w: width of visible portion of plane on crtc
648 * @crtc_h: height of visible portion of plane on crtc
649 * @src_x: left position of visible portion of plane within
650 * plane (in 16.16)
651 * @src_y: upper position of visible portion of plane within
652 * plane (in 16.16)
653 * @src_w: width of visible portion of plane (in 16.16)
654 * @src_h: height of visible portion of plane (in 16.16)
Daniel Vetterac3ba4a2016-05-31 23:11:10 +0200655 * @rotation: rotation of the plane
Marek Szyprowski44d1240d2016-06-13 11:11:26 +0200656 * @zpos: priority of the given plane on crtc (optional)
657 * @normalized_zpos: normalized value of zpos: unique, range from 0 to N-1
658 * where N is the number of active planes for given crtc
Ville Syrjäläd7da8242016-07-26 19:06:57 +0300659 * @src: clipped source coordinates of the plane (in 16.16)
660 * @dst: clipped destination coordinates of the plane
661 * @visible: visibility of the plane
Daniel Vetter144ecb92014-10-27 20:28:44 +0100662 * @state: backpointer to global drm_atomic_state
663 */
664struct drm_plane_state {
Daniel Vetter07cc0ef2014-11-27 15:49:39 +0100665 struct drm_plane *plane;
666
Rob Clark6ddd3882014-11-21 15:28:31 -0500667 struct drm_crtc *crtc; /* do not write directly, use drm_atomic_set_crtc_for_plane() */
668 struct drm_framebuffer *fb; /* do not write directly, use drm_atomic_set_fb_for_plane() */
Daniel Vettere2330f02014-10-29 11:34:56 +0100669 struct fence *fence;
Daniel Vetter144ecb92014-10-27 20:28:44 +0100670
671 /* Signed dest location allows it to be partially off screen */
672 int32_t crtc_x, crtc_y;
673 uint32_t crtc_w, crtc_h;
674
675 /* Source values are 16.16 fixed point */
676 uint32_t src_x, src_y;
677 uint32_t src_h, src_w;
678
Matt Roper1da30622015-01-21 16:35:40 -0800679 /* Plane rotation */
680 unsigned int rotation;
681
Marek Szyprowski44d1240d2016-06-13 11:11:26 +0200682 /* Plane zpos */
683 unsigned int zpos;
684 unsigned int normalized_zpos;
685
Ville Syrjäläd7da8242016-07-26 19:06:57 +0300686 /* Clipped coordinates */
687 struct drm_rect src, dst;
688
689 /*
690 * Is the plane actually visible? Can be false even
691 * if fb!=NULL and crtc!=NULL, due to clipping.
692 */
693 bool visible;
694
Daniel Vetter144ecb92014-10-27 20:28:44 +0100695 struct drm_atomic_state *state;
696};
697
698
699/**
Daniel Vetter3bf04012014-10-27 16:54:27 +0100700 * struct drm_plane_funcs - driver plane control functions
Jesse Barnes8cf5c912011-11-14 14:51:27 -0800701 */
702struct drm_plane_funcs {
Daniel Vetter88548632015-12-04 09:45:48 +0100703 /**
704 * @update_plane:
705 *
706 * This is the legacy entry point to enable and configure the plane for
707 * the given CRTC and framebuffer. It is never called to disable the
708 * plane, i.e. the passed-in crtc and fb paramters are never NULL.
709 *
710 * The source rectangle in frame buffer memory coordinates is given by
711 * the src_x, src_y, src_w and src_h parameters (as 16.16 fixed point
712 * values). Devices that don't support subpixel plane coordinates can
713 * ignore the fractional part.
714 *
715 * The destination rectangle in CRTC coordinates is given by the
716 * crtc_x, crtc_y, crtc_w and crtc_h parameters (as integer values).
717 * Devices scale the source rectangle to the destination rectangle. If
718 * scaling is not supported, and the source rectangle size doesn't match
719 * the destination rectangle size, the driver must return a
720 * -<errorname>EINVAL</errorname> error.
721 *
722 * Drivers implementing atomic modeset should use
723 * drm_atomic_helper_update_plane() to implement this hook.
724 *
725 * RETURNS:
726 *
727 * 0 on success or a negative error code on failure.
728 */
Jesse Barnes8cf5c912011-11-14 14:51:27 -0800729 int (*update_plane)(struct drm_plane *plane,
730 struct drm_crtc *crtc, struct drm_framebuffer *fb,
731 int crtc_x, int crtc_y,
732 unsigned int crtc_w, unsigned int crtc_h,
733 uint32_t src_x, uint32_t src_y,
734 uint32_t src_w, uint32_t src_h);
Daniel Vetter88548632015-12-04 09:45:48 +0100735
736 /**
737 * @disable_plane:
738 *
739 * This is the legacy entry point to disable the plane. The DRM core
Daniel Vetterc6b0ca32015-12-04 09:46:01 +0100740 * calls this method in response to a DRM_IOCTL_MODE_SETPLANE IOCTL call
Daniel Vetter88548632015-12-04 09:45:48 +0100741 * with the frame buffer ID set to 0. Disabled planes must not be
742 * processed by the CRTC.
743 *
744 * Drivers implementing atomic modeset should use
745 * drm_atomic_helper_disable_plane() to implement this hook.
746 *
747 * RETURNS:
748 *
749 * 0 on success or a negative error code on failure.
750 */
Jesse Barnes8cf5c912011-11-14 14:51:27 -0800751 int (*disable_plane)(struct drm_plane *plane);
Daniel Vetter88548632015-12-04 09:45:48 +0100752
753 /**
754 * @destroy:
755 *
756 * Clean up plane resources. This is only called at driver unload time
757 * through drm_mode_config_cleanup() since a plane cannot be hotplugged
758 * in DRM.
759 */
Jesse Barnes8cf5c912011-11-14 14:51:27 -0800760 void (*destroy)(struct drm_plane *plane);
Daniel Vetter88548632015-12-04 09:45:48 +0100761
762 /**
763 * @reset:
764 *
765 * Reset plane hardware and software state to off. This function isn't
766 * called by the core directly, only through drm_mode_config_reset().
767 * It's not a helper hook only for historical reasons.
768 *
769 * Atomic drivers can use drm_atomic_helper_plane_reset() to reset
770 * atomic state using this hook.
771 */
Daniel Vetter2a0d7cf2014-07-29 15:32:37 +0200772 void (*reset)(struct drm_plane *plane);
Rob Clark4d939142012-05-17 02:23:27 -0600773
Daniel Vetter88548632015-12-04 09:45:48 +0100774 /**
775 * @set_property:
776 *
777 * This is the legacy entry point to update a property attached to the
778 * plane.
779 *
780 * Drivers implementing atomic modeset should use
781 * drm_atomic_helper_plane_set_property() to implement this hook.
782 *
783 * This callback is optional if the driver does not support any legacy
784 * driver-private properties.
785 *
786 * RETURNS:
787 *
788 * 0 on success or a negative error code on failure.
789 */
Rob Clark4d939142012-05-17 02:23:27 -0600790 int (*set_property)(struct drm_plane *plane,
791 struct drm_property *property, uint64_t val);
Daniel Vetter144ecb92014-10-27 20:28:44 +0100792
Daniel Vetter88548632015-12-04 09:45:48 +0100793 /**
794 * @atomic_duplicate_state:
795 *
796 * Duplicate the current atomic state for this plane and return it.
797 * The core and helpers gurantee that any atomic state duplicated with
798 * this hook and still owned by the caller (i.e. not transferred to the
799 * driver by calling ->atomic_commit() from struct
800 * &drm_mode_config_funcs) will be cleaned up by calling the
801 * @atomic_destroy_state hook in this structure.
802 *
803 * Atomic drivers which don't subclass struct &drm_plane_state should use
804 * drm_atomic_helper_plane_duplicate_state(). Drivers that subclass the
805 * state structure to extend it with driver-private state should use
806 * __drm_atomic_helper_plane_duplicate_state() to make sure shared state is
807 * duplicated in a consistent fashion across drivers.
808 *
809 * It is an error to call this hook before plane->state has been
810 * initialized correctly.
811 *
812 * NOTE:
813 *
814 * If the duplicate state references refcounted resources this hook must
815 * acquire a reference for each of them. The driver must release these
816 * references again in @atomic_destroy_state.
817 *
818 * RETURNS:
819 *
820 * Duplicated atomic state or NULL when the allocation failed.
821 */
Daniel Vetter144ecb92014-10-27 20:28:44 +0100822 struct drm_plane_state *(*atomic_duplicate_state)(struct drm_plane *plane);
Daniel Vetter88548632015-12-04 09:45:48 +0100823
824 /**
825 * @atomic_destroy_state:
826 *
827 * Destroy a state duplicated with @atomic_duplicate_state and release
828 * or unreference all resources it references
829 */
Daniel Vetter144ecb92014-10-27 20:28:44 +0100830 void (*atomic_destroy_state)(struct drm_plane *plane,
Daniel Vettercc4ceb42014-07-25 21:30:38 +0200831 struct drm_plane_state *state);
Daniel Vetter88548632015-12-04 09:45:48 +0100832
833 /**
834 * @atomic_set_property:
835 *
836 * Decode a driver-private property value and store the decoded value
837 * into the passed-in state structure. Since the atomic core decodes all
838 * standardized properties (even for extensions beyond the core set of
839 * properties which might not be implemented by all drivers) this
840 * requires drivers to subclass the state structure.
841 *
842 * Such driver-private properties should really only be implemented for
843 * truly hardware/vendor specific state. Instead it is preferred to
844 * standardize atomic extension and decode the properties used to expose
845 * such an extension in the core.
846 *
847 * Do not call this function directly, use
848 * drm_atomic_plane_set_property() instead.
849 *
850 * This callback is optional if the driver does not support any
851 * driver-private atomic properties.
852 *
853 * NOTE:
854 *
855 * This function is called in the state assembly phase of atomic
856 * modesets, which can be aborted for any reason (including on
857 * userspace's request to just check whether a configuration would be
858 * possible). Drivers MUST NOT touch any persistent state (hardware or
859 * software) or data structures except the passed in @state parameter.
860 *
861 * Also since userspace controls in which order properties are set this
862 * function must not do any input validation (since the state update is
863 * incomplete and hence likely inconsistent). Instead any such input
864 * validation must be done in the various atomic_check callbacks.
865 *
866 * RETURNS:
867 *
868 * 0 if the property has been found, -EINVAL if the property isn't
869 * implemented by the driver (which shouldn't ever happen, the core only
870 * asks for properties attached to this plane). No other validation is
871 * allowed by the driver. The core already checks that the property
872 * value is within the range (integer, valid enum value, ...) the driver
873 * set when registering the property.
874 */
Daniel Vetter144ecb92014-10-27 20:28:44 +0100875 int (*atomic_set_property)(struct drm_plane *plane,
876 struct drm_plane_state *state,
877 struct drm_property *property,
878 uint64_t val);
Daniel Vetter88548632015-12-04 09:45:48 +0100879
880 /**
881 * @atomic_get_property:
882 *
883 * Reads out the decoded driver-private property. This is used to
Daniel Vetterc6b0ca32015-12-04 09:46:01 +0100884 * implement the GETPLANE IOCTL.
Daniel Vetter88548632015-12-04 09:45:48 +0100885 *
886 * Do not call this function directly, use
887 * drm_atomic_plane_get_property() instead.
888 *
889 * This callback is optional if the driver does not support any
890 * driver-private atomic properties.
891 *
892 * RETURNS:
893 *
894 * 0 on success, -EINVAL if the property isn't implemented by the
895 * driver (which should never happen, the core only asks for
896 * properties attached to this plane).
897 */
Rob Clarkac9c9252014-12-18 16:01:47 -0500898 int (*atomic_get_property)(struct drm_plane *plane,
899 const struct drm_plane_state *state,
900 struct drm_property *property,
901 uint64_t *val);
Benjamin Gaignard79190ea2016-06-21 16:37:09 +0200902 /**
903 * @late_register:
904 *
905 * This optional hook can be used to register additional userspace
906 * interfaces attached to the plane like debugfs interfaces.
907 * It is called late in the driver load sequence from drm_dev_register().
908 * Everything added from this callback should be unregistered in
909 * the early_unregister callback.
910 *
911 * Returns:
912 *
913 * 0 on success, or a negative error code on failure.
914 */
915 int (*late_register)(struct drm_plane *plane);
916
917 /**
918 * @early_unregister:
919 *
920 * This optional hook should be used to unregister the additional
921 * userspace interfaces attached to the plane from
922 * late_unregister(). It is called from drm_dev_unregister(),
923 * early in the driver unload sequence to disable userspace access
924 * before data structures are torndown.
925 */
926 void (*early_unregister)(struct drm_plane *plane);
Jesse Barnes8cf5c912011-11-14 14:51:27 -0800927};
928
Matt Ropere27dde32014-04-01 15:22:30 -0700929enum drm_plane_type {
930 DRM_PLANE_TYPE_OVERLAY,
931 DRM_PLANE_TYPE_PRIMARY,
932 DRM_PLANE_TYPE_CURSOR,
933};
934
Daniel Vetter88548632015-12-04 09:45:48 +0100935
Jesse Barnes8cf5c912011-11-14 14:51:27 -0800936/**
Daniel Vetter3bf04012014-10-27 16:54:27 +0100937 * struct drm_plane - central DRM plane control structure
Jesse Barnes8cf5c912011-11-14 14:51:27 -0800938 * @dev: DRM device this plane belongs to
939 * @head: for list management
Daniel Vetterac3ba4a2016-05-31 23:11:10 +0200940 * @name: human readable name, can be overwritten by the driver
Jesse Barnes8cf5c912011-11-14 14:51:27 -0800941 * @base: base mode object
942 * @possible_crtcs: pipes this plane can be bound to
943 * @format_types: array of formats supported by this plane
944 * @format_count: number of formats supported
Laurent Pinchart7eb5f302015-03-09 10:41:07 +0200945 * @format_default: driver hasn't supplied supported formats for the plane
Jesse Barnes8cf5c912011-11-14 14:51:27 -0800946 * @crtc: currently bound CRTC
947 * @fb: currently bound fb
Daniel Vetter2c0c33d2014-10-27 20:19:38 +0100948 * @old_fb: Temporary tracking of the old fb while a modeset is ongoing. Used by
949 * drm_mode_set_config_internal() to implement correct refcounting.
Jesse Barnes8cf5c912011-11-14 14:51:27 -0800950 * @funcs: helper functions
Rob Clark4d939142012-05-17 02:23:27 -0600951 * @properties: property tracking for this plane
Matt Ropere27dde32014-04-01 15:22:30 -0700952 * @type: type of plane (overlay, primary, cursor)
Daniel Vetter144ecb92014-10-27 20:28:44 +0100953 * @state: current atomic state for this plane
Marek Szyprowski44d1240d2016-06-13 11:11:26 +0200954 * @zpos_property: zpos property for this plane
Daniel Vetterac3ba4a2016-05-31 23:11:10 +0200955 * @helper_private: mid-layer private data
Jesse Barnes8cf5c912011-11-14 14:51:27 -0800956 */
957struct drm_plane {
958 struct drm_device *dev;
959 struct list_head head;
960
Ville Syrjälä9f4c97a2015-12-08 18:41:54 +0200961 char *name;
962
Daniel Vetterac3ba4a2016-05-31 23:11:10 +0200963 /**
964 * @mutex:
965 *
966 * Protects modeset plane state, together with the mutex of &drm_crtc
967 * this plane is linked to (when active, getting actived or getting
968 * disabled).
969 */
Daniel Vetter4d02e2d2014-11-11 10:12:00 +0100970 struct drm_modeset_lock mutex;
971
Jesse Barnes8cf5c912011-11-14 14:51:27 -0800972 struct drm_mode_object base;
973
974 uint32_t possible_crtcs;
975 uint32_t *format_types;
Thierry Reding45e37432015-08-12 16:54:28 +0200976 unsigned int format_count;
Laurent Pinchart7eb5f302015-03-09 10:41:07 +0200977 bool format_default;
Jesse Barnes8cf5c912011-11-14 14:51:27 -0800978
979 struct drm_crtc *crtc;
980 struct drm_framebuffer *fb;
981
Daniel Vetter3d30a592014-07-27 13:42:42 +0200982 struct drm_framebuffer *old_fb;
983
Jesse Barnes8cf5c912011-11-14 14:51:27 -0800984 const struct drm_plane_funcs *funcs;
Rob Clark4d939142012-05-17 02:23:27 -0600985
986 struct drm_object_properties properties;
Matt Ropere27dde32014-04-01 15:22:30 -0700987
988 enum drm_plane_type type;
Daniel Vetter144ecb92014-10-27 20:28:44 +0100989
Daniel Vetter96094082016-07-15 21:47:59 +0200990 /**
991 * @index: Position inside the mode_config.list, can be used as an array
992 * index. It is invariant over the lifetime of the plane.
993 */
Chris Wilson490d3d12016-05-27 20:05:00 +0100994 unsigned index;
995
Daniel Vetter4490d4c2015-12-04 09:45:45 +0100996 const struct drm_plane_helper_funcs *helper_private;
Daniel Vetterc2fcd272014-11-05 00:14:14 +0100997
Daniel Vetter144ecb92014-10-27 20:28:44 +0100998 struct drm_plane_state *state;
Marek Szyprowski44d1240d2016-06-13 11:11:26 +0200999
1000 struct drm_property *zpos_property;
Jesse Barnes8cf5c912011-11-14 14:51:27 -08001001};
1002
1003/**
Daniel Vetter3bf04012014-10-27 16:54:27 +01001004 * struct drm_bridge_funcs - drm_bridge control functions
Sean Paul3b336ec2013-08-14 16:47:37 -04001005 */
1006struct drm_bridge_funcs {
Andrea Merellocf3bef92016-08-25 11:04:32 +02001007 /**
1008 * @attach:
1009 *
1010 * This callback is invoked whenever our bridge is being attached to a
1011 * &drm_encoder.
1012 *
1013 * The attach callback is optional.
1014 *
1015 * RETURNS:
1016 *
1017 * Zero on success, error code on failure.
1018 */
Ajay Kumar3d3f8b12015-01-20 22:08:44 +05301019 int (*attach)(struct drm_bridge *bridge);
Daniel Vetterda024fe2015-12-04 09:45:47 +01001020
1021 /**
Andrea Merellocf3bef92016-08-25 11:04:32 +02001022 * @detach:
1023 *
1024 * This callback is invoked whenever our bridge is being detached from a
1025 * &drm_encoder.
1026 *
1027 * The detach callback is optional.
1028 */
1029 void (*detach)(struct drm_bridge *bridge);
1030
1031 /**
Daniel Vetterda024fe2015-12-04 09:45:47 +01001032 * @mode_fixup:
1033 *
1034 * This callback is used to validate and adjust a mode. The paramater
1035 * mode is the display mode that should be fed to the next element in
1036 * the display chain, either the final &drm_connector or the next
1037 * &drm_bridge. The parameter adjusted_mode is the input mode the bridge
1038 * requires. It can be modified by this callback and does not need to
1039 * match mode.
1040 *
1041 * This is the only hook that allows a bridge to reject a modeset. If
1042 * this function passes all other callbacks must succeed for this
1043 * configuration.
1044 *
Andrea Merellocf3bef92016-08-25 11:04:32 +02001045 * The mode_fixup callback is optional.
1046 *
Daniel Vetterda024fe2015-12-04 09:45:47 +01001047 * NOTE:
1048 *
1049 * This function is called in the check phase of atomic modesets, which
1050 * can be aborted for any reason (including on userspace's request to
1051 * just check whether a configuration would be possible). Drivers MUST
1052 * NOT touch any persistent state (hardware or software) or data
Daniel Vetter88548632015-12-04 09:45:48 +01001053 * structures except the passed in @state parameter.
Daniel Vetterda024fe2015-12-04 09:45:47 +01001054 *
1055 * RETURNS:
1056 *
1057 * True if an acceptable configuration is possible, false if the modeset
1058 * operation should be rejected.
1059 */
Sean Paul3b336ec2013-08-14 16:47:37 -04001060 bool (*mode_fixup)(struct drm_bridge *bridge,
1061 const struct drm_display_mode *mode,
1062 struct drm_display_mode *adjusted_mode);
Daniel Vetterda024fe2015-12-04 09:45:47 +01001063 /**
1064 * @disable:
1065 *
1066 * This callback should disable the bridge. It is called right before
1067 * the preceding element in the display pipe is disabled. If the
1068 * preceding element is a bridge this means it's called before that
1069 * bridge's ->disable() function. If the preceding element is a
1070 * &drm_encoder it's called right before the encoder's ->disable(),
1071 * ->prepare() or ->dpms() hook from struct &drm_encoder_helper_funcs.
1072 *
1073 * The bridge can assume that the display pipe (i.e. clocks and timing
1074 * signals) feeding it is still running when this callback is called.
Laurent Pinchartc8a3b2a2016-02-26 11:51:06 +02001075 *
1076 * The disable callback is optional.
Daniel Vetterda024fe2015-12-04 09:45:47 +01001077 */
Sean Paul3b336ec2013-08-14 16:47:37 -04001078 void (*disable)(struct drm_bridge *bridge);
Daniel Vetterda024fe2015-12-04 09:45:47 +01001079
1080 /**
1081 * @post_disable:
1082 *
1083 * This callback should disable the bridge. It is called right after
1084 * the preceding element in the display pipe is disabled. If the
1085 * preceding element is a bridge this means it's called after that
1086 * bridge's ->post_disable() function. If the preceding element is a
1087 * &drm_encoder it's called right after the encoder's ->disable(),
1088 * ->prepare() or ->dpms() hook from struct &drm_encoder_helper_funcs.
1089 *
1090 * The bridge must assume that the display pipe (i.e. clocks and timing
1091 * singals) feeding it is no longer running when this callback is
1092 * called.
Laurent Pinchartc8a3b2a2016-02-26 11:51:06 +02001093 *
1094 * The post_disable callback is optional.
Daniel Vetterda024fe2015-12-04 09:45:47 +01001095 */
Sean Paul3b336ec2013-08-14 16:47:37 -04001096 void (*post_disable)(struct drm_bridge *bridge);
Daniel Vetterda024fe2015-12-04 09:45:47 +01001097
1098 /**
1099 * @mode_set:
1100 *
1101 * This callback should set the given mode on the bridge. It is called
1102 * after the ->mode_set() callback for the preceding element in the
1103 * display pipeline has been called already. The display pipe (i.e.
1104 * clocks and timing signals) is off when this function is called.
1105 */
Sean Paul3b336ec2013-08-14 16:47:37 -04001106 void (*mode_set)(struct drm_bridge *bridge,
1107 struct drm_display_mode *mode,
1108 struct drm_display_mode *adjusted_mode);
Daniel Vetterda024fe2015-12-04 09:45:47 +01001109 /**
1110 * @pre_enable:
1111 *
1112 * This callback should enable the bridge. It is called right before
1113 * the preceding element in the display pipe is enabled. If the
1114 * preceding element is a bridge this means it's called before that
1115 * bridge's ->pre_enable() function. If the preceding element is a
1116 * &drm_encoder it's called right before the encoder's ->enable(),
1117 * ->commit() or ->dpms() hook from struct &drm_encoder_helper_funcs.
1118 *
1119 * The display pipe (i.e. clocks and timing signals) feeding this bridge
1120 * will not yet be running when this callback is called. The bridge must
1121 * not enable the display link feeding the next bridge in the chain (if
1122 * there is one) when this callback is called.
Laurent Pinchartc8a3b2a2016-02-26 11:51:06 +02001123 *
1124 * The pre_enable callback is optional.
Daniel Vetterda024fe2015-12-04 09:45:47 +01001125 */
Sean Paul3b336ec2013-08-14 16:47:37 -04001126 void (*pre_enable)(struct drm_bridge *bridge);
Daniel Vetterda024fe2015-12-04 09:45:47 +01001127
1128 /**
1129 * @enable:
1130 *
1131 * This callback should enable the bridge. It is called right after
1132 * the preceding element in the display pipe is enabled. If the
1133 * preceding element is a bridge this means it's called after that
1134 * bridge's ->enable() function. If the preceding element is a
1135 * &drm_encoder it's called right after the encoder's ->enable(),
1136 * ->commit() or ->dpms() hook from struct &drm_encoder_helper_funcs.
1137 *
1138 * The bridge can assume that the display pipe (i.e. clocks and timing
1139 * signals) feeding it is running when this callback is called. This
1140 * callback must enable the display link feeding the next bridge in the
1141 * chain if there is one.
Laurent Pinchartc8a3b2a2016-02-26 11:51:06 +02001142 *
1143 * The enable callback is optional.
Daniel Vetterda024fe2015-12-04 09:45:47 +01001144 */
Sean Paul3b336ec2013-08-14 16:47:37 -04001145 void (*enable)(struct drm_bridge *bridge);
Sean Paul3b336ec2013-08-14 16:47:37 -04001146};
1147
1148/**
Daniel Vetter3bf04012014-10-27 16:54:27 +01001149 * struct drm_bridge - central DRM bridge control structure
Sean Paul3b336ec2013-08-14 16:47:37 -04001150 * @dev: DRM device this bridge belongs to
Archit Taneja862e6862015-05-21 11:03:16 +05301151 * @encoder: encoder to which this bridge is connected
1152 * @next: the next bridge in the encoder chain
Ajay Kumar3d3f8b12015-01-20 22:08:44 +05301153 * @of_node: device node pointer to the bridge
1154 * @list: to keep track of all added bridges
Sean Paul3b336ec2013-08-14 16:47:37 -04001155 * @funcs: control functions
1156 * @driver_private: pointer to the bridge driver's internal context
1157 */
1158struct drm_bridge {
1159 struct drm_device *dev;
Ajay Kumar3d3f8b12015-01-20 22:08:44 +05301160 struct drm_encoder *encoder;
Archit Taneja862e6862015-05-21 11:03:16 +05301161 struct drm_bridge *next;
Ajay Kumar3d3f8b12015-01-20 22:08:44 +05301162#ifdef CONFIG_OF
1163 struct device_node *of_node;
1164#endif
1165 struct list_head list;
Sean Paul3b336ec2013-08-14 16:47:37 -04001166
1167 const struct drm_bridge_funcs *funcs;
1168 void *driver_private;
1169};
1170
Daniel Vetter3b24f7d2016-06-08 14:19:00 +02001171/**
1172 * struct drm_crtc_commit - track modeset commits on a CRTC
1173 *
1174 * This structure is used to track pending modeset changes and atomic commit on
1175 * a per-CRTC basis. Since updating the list should never block this structure
1176 * is reference counted to allow waiters to safely wait on an event to complete,
1177 * without holding any locks.
1178 *
1179 * It has 3 different events in total to allow a fine-grained synchronization
1180 * between outstanding updates::
1181 *
1182 * atomic commit thread hardware
1183 *
1184 * write new state into hardware ----> ...
1185 * signal hw_done
1186 * switch to new state on next
1187 * ... v/hblank
1188 *
1189 * wait for buffers to show up ...
1190 *
1191 * ... send completion irq
1192 * irq handler signals flip_done
1193 * cleanup old buffers
1194 *
1195 * signal cleanup_done
1196 *
1197 * wait for flip_done <----
1198 * clean up atomic state
1199 *
1200 * The important bit to know is that cleanup_done is the terminal event, but the
1201 * ordering between flip_done and hw_done is entirely up to the specific driver
1202 * and modeset state change.
1203 *
1204 * For an implementation of how to use this look at
1205 * drm_atomic_helper_setup_commit() from the atomic helper library.
1206 */
1207struct drm_crtc_commit {
1208 /**
1209 * @crtc:
1210 *
1211 * DRM CRTC for this commit.
1212 */
1213 struct drm_crtc *crtc;
1214
1215 /**
1216 * @ref:
1217 *
1218 * Reference count for this structure. Needed to allow blocking on
1219 * completions without the risk of the completion disappearing
1220 * meanwhile.
1221 */
1222 struct kref ref;
1223
1224 /**
1225 * @flip_done:
1226 *
1227 * Will be signaled when the hardware has flipped to the new set of
1228 * buffers. Signals at the same time as when the drm event for this
1229 * commit is sent to userspace, or when an out-fence is singalled. Note
1230 * that for most hardware, in most cases this happens after @hw_done is
1231 * signalled.
1232 */
1233 struct completion flip_done;
1234
1235 /**
1236 * @hw_done:
1237 *
1238 * Will be signalled when all hw register changes for this commit have
1239 * been written out. Especially when disabling a pipe this can be much
1240 * later than than @flip_done, since that can signal already when the
1241 * screen goes black, whereas to fully shut down a pipe more register
1242 * I/O is required.
1243 *
1244 * Note that this does not need to include separately reference-counted
1245 * resources like backing storage buffer pinning, or runtime pm
1246 * management.
1247 */
1248 struct completion hw_done;
1249
1250 /**
1251 * @cleanup_done:
1252 *
1253 * Will be signalled after old buffers have been cleaned up by calling
1254 * drm_atomic_helper_cleanup_planes(). Since this can only happen after
1255 * a vblank wait completed it might be a bit later. This completion is
1256 * useful to throttle updates and avoid hardware updates getting ahead
1257 * of the buffer cleanup too much.
1258 */
1259 struct completion cleanup_done;
1260
1261 /**
1262 * @commit_entry:
1263 *
1264 * Entry on the per-CRTC commit_list. Protected by crtc->commit_lock.
1265 */
1266 struct list_head commit_entry;
1267
1268 /**
1269 * @event:
1270 *
1271 * &drm_pending_vblank_event pointer to clean up private events.
1272 */
1273 struct drm_pending_vblank_event *event;
1274};
1275
Daniel Vetterb8b53422016-06-02 00:06:33 +02001276struct __drm_planes_state {
1277 struct drm_plane *ptr;
1278 struct drm_plane_state *state;
1279};
1280
Daniel Vetter5d943aa62016-06-02 00:06:34 +02001281struct __drm_crtcs_state {
1282 struct drm_crtc *ptr;
1283 struct drm_crtc_state *state;
Daniel Vetter3b24f7d2016-06-08 14:19:00 +02001284 struct drm_crtc_commit *commit;
Daniel Vetter5d943aa62016-06-02 00:06:34 +02001285};
1286
Daniel Vetter63e83c12016-06-02 00:06:32 +02001287struct __drm_connnectors_state {
1288 struct drm_connector *ptr;
1289 struct drm_connector_state *state;
1290};
1291
Sean Paul3b336ec2013-08-14 16:47:37 -04001292/**
Rob Clark08855fa2015-03-11 10:23:09 -04001293 * struct drm_atomic_state - the global state object for atomic updates
Daniel Vettercc4ceb42014-07-25 21:30:38 +02001294 * @dev: parent DRM device
Rob Clarkd34f20d2014-12-18 16:01:56 -05001295 * @allow_modeset: allow full modeset
Daniel Vetterc6b0ca32015-12-04 09:46:01 +01001296 * @legacy_cursor_update: hint to enforce legacy cursor IOCTL semantics
Maarten Lankhorst40616a22016-03-03 10:17:39 +01001297 * @legacy_set_config: Disable conflicting encoders instead of failing with -EINVAL.
Daniel Vetterb8b53422016-06-02 00:06:33 +02001298 * @planes: pointer to array of structures with per-plane data
Daniel Vettercc4ceb42014-07-25 21:30:38 +02001299 * @crtcs: pointer to array of CRTC pointers
Daniel Vetterf52b69f12014-11-19 18:38:08 +01001300 * @num_connector: size of the @connectors and @connector_states arrays
Daniel Vetter63e83c12016-06-02 00:06:32 +02001301 * @connectors: pointer to array of structures with per-connector data
Daniel Vettercc4ceb42014-07-25 21:30:38 +02001302 * @acquire_ctx: acquire context for this atomic modeset state update
1303 */
1304struct drm_atomic_state {
1305 struct drm_device *dev;
Rob Clarkd34f20d2014-12-18 16:01:56 -05001306 bool allow_modeset : 1;
Daniel Vetterf02ad902015-01-22 16:36:23 +01001307 bool legacy_cursor_update : 1;
Maarten Lankhorst40616a22016-03-03 10:17:39 +01001308 bool legacy_set_config : 1;
Daniel Vetterb8b53422016-06-02 00:06:33 +02001309 struct __drm_planes_state *planes;
Daniel Vetter5d943aa62016-06-02 00:06:34 +02001310 struct __drm_crtcs_state *crtcs;
Daniel Vetterf52b69f12014-11-19 18:38:08 +01001311 int num_connector;
Daniel Vetter63e83c12016-06-02 00:06:32 +02001312 struct __drm_connnectors_state *connectors;
Daniel Vettercc4ceb42014-07-25 21:30:38 +02001313
1314 struct drm_modeset_acquire_ctx *acquire_ctx;
Daniel Vetter3b24f7d2016-06-08 14:19:00 +02001315
1316 /**
1317 * @commit_work:
1318 *
1319 * Work item which can be used by the driver or helpers to execute the
1320 * commit without blocking.
1321 */
1322 struct work_struct commit_work;
Daniel Vettercc4ceb42014-07-25 21:30:38 +02001323};
1324
1325
1326/**
Daniel Vetter3bf04012014-10-27 16:54:27 +01001327 * struct drm_mode_set - new values for a CRTC config change
Jesse Barnesef273512011-11-07 12:03:19 -08001328 * @fb: framebuffer to use for new config
1329 * @crtc: CRTC whose configuration we're about to change
1330 * @mode: mode timings to use
1331 * @x: position of this CRTC relative to @fb
1332 * @y: position of this CRTC relative to @fb
1333 * @connectors: array of connectors to drive with this CRTC if possible
1334 * @num_connectors: size of @connectors array
Dave Airlief453ba02008-11-07 14:05:41 -08001335 *
1336 * Represents a single crtc the connectors that it drives with what mode
1337 * and from which framebuffer it scans out from.
1338 *
1339 * This is used to set modes.
1340 */
1341struct drm_mode_set {
Dave Airlief453ba02008-11-07 14:05:41 -08001342 struct drm_framebuffer *fb;
1343 struct drm_crtc *crtc;
1344 struct drm_display_mode *mode;
1345
1346 uint32_t x;
1347 uint32_t y;
1348
1349 struct drm_connector **connectors;
1350 size_t num_connectors;
1351};
1352
1353/**
Jesse Barnes550cebc2011-11-07 12:03:20 -08001354 * struct drm_mode_config_funcs - basic driver provided mode setting functions
Jesse Barnes550cebc2011-11-07 12:03:20 -08001355 *
1356 * Some global (i.e. not per-CRTC, connector, etc) mode setting functions that
1357 * involve drivers.
Dave Airlief453ba02008-11-07 14:05:41 -08001358 */
1359struct drm_mode_config_funcs {
Daniel Vetter9953f412015-12-04 09:46:02 +01001360 /**
1361 * @fb_create:
1362 *
1363 * Create a new framebuffer object. The core does basic checks on the
1364 * requested metadata, but most of that is left to the driver. See
1365 * struct &drm_mode_fb_cmd2 for details.
1366 *
Daniel Vetterd55f5322015-12-08 09:49:19 +01001367 * If the parameters are deemed valid and the backing storage objects in
1368 * the underlying memory manager all exist, then the driver allocates
1369 * a new &drm_framebuffer structure, subclassed to contain
1370 * driver-specific information (like the internal native buffer object
1371 * references). It also needs to fill out all relevant metadata, which
1372 * should be done by calling drm_helper_mode_fill_fb_struct().
1373 *
1374 * The initialization is finalized by calling drm_framebuffer_init(),
1375 * which registers the framebuffer and makes it accessible to other
1376 * threads.
1377 *
Daniel Vetter9953f412015-12-04 09:46:02 +01001378 * RETURNS:
1379 *
1380 * A new framebuffer with an initial reference count of 1 or a negative
1381 * error code encoded with ERR_PTR().
1382 */
Jesse Barnes550cebc2011-11-07 12:03:20 -08001383 struct drm_framebuffer *(*fb_create)(struct drm_device *dev,
1384 struct drm_file *file_priv,
Ville Syrjälä1eb834512015-11-11 19:11:29 +02001385 const struct drm_mode_fb_cmd2 *mode_cmd);
Daniel Vetter9953f412015-12-04 09:46:02 +01001386
1387 /**
1388 * @output_poll_changed:
1389 *
1390 * Callback used by helpers to inform the driver of output configuration
1391 * changes.
1392 *
1393 * Drivers implementing fbdev emulation with the helpers can call
1394 * drm_fb_helper_hotplug_changed from this hook to inform the fbdev
1395 * helper of output changes.
1396 *
1397 * FIXME:
1398 *
1399 * Except that there's no vtable for device-level helper callbacks
1400 * there's no reason this is a core function.
1401 */
Dave Airlieeb1f8e4f32010-05-07 06:42:51 +00001402 void (*output_poll_changed)(struct drm_device *dev);
Daniel Vettercc4ceb42014-07-25 21:30:38 +02001403
Daniel Vetter9953f412015-12-04 09:46:02 +01001404 /**
1405 * @atomic_check:
1406 *
1407 * This is the only hook to validate an atomic modeset update. This
1408 * function must reject any modeset and state changes which the hardware
1409 * or driver doesn't support. This includes but is of course not limited
1410 * to:
1411 *
1412 * - Checking that the modes, framebuffers, scaling and placement
1413 * requirements and so on are within the limits of the hardware.
1414 *
1415 * - Checking that any hidden shared resources are not oversubscribed.
1416 * This can be shared PLLs, shared lanes, overall memory bandwidth,
1417 * display fifo space (where shared between planes or maybe even
1418 * CRTCs).
1419 *
1420 * - Checking that virtualized resources exported to userspace are not
1421 * oversubscribed. For various reasons it can make sense to expose
1422 * more planes, crtcs or encoders than which are physically there. One
1423 * example is dual-pipe operations (which generally should be hidden
1424 * from userspace if when lockstepped in hardware, exposed otherwise),
1425 * where a plane might need 1 hardware plane (if it's just on one
1426 * pipe), 2 hardware planes (when it spans both pipes) or maybe even
1427 * shared a hardware plane with a 2nd plane (if there's a compatible
1428 * plane requested on the area handled by the other pipe).
1429 *
1430 * - Check that any transitional state is possible and that if
1431 * requested, the update can indeed be done in the vblank period
1432 * without temporarily disabling some functions.
1433 *
1434 * - Check any other constraints the driver or hardware might have.
1435 *
1436 * - This callback also needs to correctly fill out the &drm_crtc_state
1437 * in this update to make sure that drm_atomic_crtc_needs_modeset()
1438 * reflects the nature of the possible update and returns true if and
1439 * only if the update cannot be applied without tearing within one
1440 * vblank on that CRTC. The core uses that information to reject
1441 * updates which require a full modeset (i.e. blanking the screen, or
1442 * at least pausing updates for a substantial amount of time) if
1443 * userspace has disallowed that in its request.
1444 *
1445 * - The driver also does not need to repeat basic input validation
1446 * like done for the corresponding legacy entry points. The core does
1447 * that before calling this hook.
1448 *
1449 * See the documentation of @atomic_commit for an exhaustive list of
1450 * error conditions which don't have to be checked at the
1451 * ->atomic_check() stage?
1452 *
1453 * See the documentation for struct &drm_atomic_state for how exactly
1454 * an atomic modeset update is described.
1455 *
1456 * Drivers using the atomic helpers can implement this hook using
1457 * drm_atomic_helper_check(), or one of the exported sub-functions of
1458 * it.
1459 *
1460 * RETURNS:
1461 *
1462 * 0 on success or one of the below negative error codes:
1463 *
1464 * - -EINVAL, if any of the above constraints are violated.
1465 *
1466 * - -EDEADLK, when returned from an attempt to acquire an additional
1467 * &drm_modeset_lock through drm_modeset_lock().
1468 *
1469 * - -ENOMEM, if allocating additional state sub-structures failed due
1470 * to lack of memory.
1471 *
1472 * - -EINTR, -EAGAIN or -ERESTARTSYS, if the IOCTL should be restarted.
1473 * This can either be due to a pending signal, or because the driver
1474 * needs to completely bail out to recover from an exceptional
1475 * situation like a GPU hang. From a userspace point all errors are
1476 * treated equally.
1477 */
Daniel Vettercc4ceb42014-07-25 21:30:38 +02001478 int (*atomic_check)(struct drm_device *dev,
Daniel Vetter9953f412015-12-04 09:46:02 +01001479 struct drm_atomic_state *state);
1480
1481 /**
1482 * @atomic_commit:
1483 *
1484 * This is the only hook to commit an atomic modeset update. The core
1485 * guarantees that @atomic_check has been called successfully before
1486 * calling this function, and that nothing has been changed in the
1487 * interim.
1488 *
1489 * See the documentation for struct &drm_atomic_state for how exactly
1490 * an atomic modeset update is described.
1491 *
1492 * Drivers using the atomic helpers can implement this hook using
1493 * drm_atomic_helper_commit(), or one of the exported sub-functions of
1494 * it.
1495 *
Maarten Lankhorst286dbb82016-04-26 16:11:34 +02001496 * Nonblocking commits (as indicated with the nonblock parameter) must
Daniel Vetter9953f412015-12-04 09:46:02 +01001497 * do any preparatory work which might result in an unsuccessful commit
1498 * in the context of this callback. The only exceptions are hardware
1499 * errors resulting in -EIO. But even in that case the driver must
1500 * ensure that the display pipe is at least running, to avoid
1501 * compositors crashing when pageflips don't work. Anything else,
1502 * specifically committing the update to the hardware, should be done
1503 * without blocking the caller. For updates which do not require a
1504 * modeset this must be guaranteed.
1505 *
1506 * The driver must wait for any pending rendering to the new
1507 * framebuffers to complete before executing the flip. It should also
1508 * wait for any pending rendering from other drivers if the underlying
Maarten Lankhorst286dbb82016-04-26 16:11:34 +02001509 * buffer is a shared dma-buf. Nonblocking commits must not wait for
Daniel Vetter9953f412015-12-04 09:46:02 +01001510 * rendering in the context of this callback.
1511 *
1512 * An application can request to be notified when the atomic commit has
1513 * completed. These events are per-CRTC and can be distinguished by the
1514 * CRTC index supplied in &drm_event to userspace.
1515 *
1516 * The drm core will supply a struct &drm_event in the event
1517 * member of each CRTC's &drm_crtc_state structure. This can be handled by the
1518 * drm_crtc_send_vblank_event() function, which the driver should call on
1519 * the provided event upon completion of the atomic commit. Note that if
1520 * the driver supports vblank signalling and timestamping the vblank
1521 * counters and timestamps must agree with the ones returned from page
1522 * flip events. With the current vblank helper infrastructure this can
1523 * be achieved by holding a vblank reference while the page flip is
1524 * pending, acquired through drm_crtc_vblank_get() and released with
1525 * drm_crtc_vblank_put(). Drivers are free to implement their own vblank
1526 * counter and timestamp tracking though, e.g. if they have accurate
1527 * timestamp registers in hardware.
1528 *
1529 * NOTE:
1530 *
1531 * Drivers are not allowed to shut down any display pipe successfully
1532 * enabled through an atomic commit on their own. Doing so can result in
1533 * compositors crashing if a page flip is suddenly rejected because the
1534 * pipe is off.
1535 *
1536 * RETURNS:
1537 *
1538 * 0 on success or one of the below negative error codes:
1539 *
Maarten Lankhorst286dbb82016-04-26 16:11:34 +02001540 * - -EBUSY, if a nonblocking updated is requested and there is
Daniel Vetter9953f412015-12-04 09:46:02 +01001541 * an earlier updated pending. Drivers are allowed to support a queue
1542 * of outstanding updates, but currently no driver supports that.
1543 * Note that drivers must wait for preceding updates to complete if a
1544 * synchronous update is requested, they are not allowed to fail the
1545 * commit in that case.
1546 *
1547 * - -ENOMEM, if the driver failed to allocate memory. Specifically
1548 * this can happen when trying to pin framebuffers, which must only
1549 * be done when committing the state.
1550 *
1551 * - -ENOSPC, as a refinement of the more generic -ENOMEM to indicate
1552 * that the driver has run out of vram, iommu space or similar GPU
1553 * address space needed for framebuffer.
1554 *
1555 * - -EIO, if the hardware completely died.
1556 *
1557 * - -EINTR, -EAGAIN or -ERESTARTSYS, if the IOCTL should be restarted.
1558 * This can either be due to a pending signal, or because the driver
1559 * needs to completely bail out to recover from an exceptional
1560 * situation like a GPU hang. From a userspace point of view all errors are
1561 * treated equally.
1562 *
1563 * This list is exhaustive. Specifically this hook is not allowed to
1564 * return -EINVAL (any invalid requests should be caught in
1565 * @atomic_check) or -EDEADLK (this function must not acquire
1566 * additional modeset locks).
1567 */
Daniel Vettercc4ceb42014-07-25 21:30:38 +02001568 int (*atomic_commit)(struct drm_device *dev,
Daniel Vetter9953f412015-12-04 09:46:02 +01001569 struct drm_atomic_state *state,
Maarten Lankhorst286dbb82016-04-26 16:11:34 +02001570 bool nonblock);
Daniel Vetter9953f412015-12-04 09:46:02 +01001571
1572 /**
1573 * @atomic_state_alloc:
1574 *
1575 * This optional hook can be used by drivers that want to subclass struct
1576 * &drm_atomic_state to be able to track their own driver-private global
1577 * state easily. If this hook is implemented, drivers must also
1578 * implement @atomic_state_clear and @atomic_state_free.
1579 *
1580 * RETURNS:
1581 *
1582 * A new &drm_atomic_state on success or NULL on failure.
1583 */
Maarten Lankhorst036ef572015-05-18 10:06:40 +02001584 struct drm_atomic_state *(*atomic_state_alloc)(struct drm_device *dev);
Daniel Vetter9953f412015-12-04 09:46:02 +01001585
1586 /**
1587 * @atomic_state_clear:
1588 *
1589 * This hook must clear any driver private state duplicated into the
1590 * passed-in &drm_atomic_state. This hook is called when the caller
1591 * encountered a &drm_modeset_lock deadlock and needs to drop all
1592 * already acquired locks as part of the deadlock avoidance dance
1593 * implemented in drm_modeset_lock_backoff().
1594 *
1595 * Any duplicated state must be invalidated since a concurrent atomic
1596 * update might change it, and the drm atomic interfaces always apply
1597 * updates as relative changes to the current state.
1598 *
1599 * Drivers that implement this must call drm_atomic_state_default_clear()
1600 * to clear common state.
1601 */
Maarten Lankhorst036ef572015-05-18 10:06:40 +02001602 void (*atomic_state_clear)(struct drm_atomic_state *state);
Daniel Vetter9953f412015-12-04 09:46:02 +01001603
1604 /**
1605 * @atomic_state_free:
1606 *
1607 * This hook needs driver private resources and the &drm_atomic_state
1608 * itself. Note that the core first calls drm_atomic_state_clear() to
1609 * avoid code duplicate between the clear and free hooks.
1610 *
1611 * Drivers that implement this must call drm_atomic_state_default_free()
1612 * to release common resources.
1613 */
Maarten Lankhorst036ef572015-05-18 10:06:40 +02001614 void (*atomic_state_free)(struct drm_atomic_state *state);
Dave Airlief453ba02008-11-07 14:05:41 -08001615};
1616
Jesse Barnesc1aaca22011-11-07 12:03:21 -08001617/**
Daniel Vetter2c0c33d2014-10-27 20:19:38 +01001618 * struct drm_mode_config - Mode configuration control structure
Jesse Barnesa62c93d2011-11-07 12:03:22 -08001619 * @mutex: mutex protecting KMS related lists and structures
Daniel Vetter2c0c33d2014-10-27 20:19:38 +01001620 * @connection_mutex: ww mutex protecting connector state and routing
1621 * @acquire_ctx: global implicit acquire context used by atomic drivers for
Daniel Vetterc6b0ca32015-12-04 09:46:01 +01001622 * legacy IOCTLs
Daniel Vetter2c0c33d2014-10-27 20:19:38 +01001623 * @fb_lock: mutex to protect fb state and lists
Jesse Barnesa62c93d2011-11-07 12:03:22 -08001624 * @num_fb: number of fbs available
1625 * @fb_list: list of framebuffers available
Jesse Barnesa62c93d2011-11-07 12:03:22 -08001626 * @num_encoder: number of encoders on this device
1627 * @encoder_list: list of encoder objects
Daniel Vetter2c0c33d2014-10-27 20:19:38 +01001628 * @num_overlay_plane: number of overlay planes on this device
1629 * @num_total_plane: number of universal (i.e. with primary/curso) planes on this device
1630 * @plane_list: list of plane objects
Jesse Barnesa62c93d2011-11-07 12:03:22 -08001631 * @num_crtc: number of CRTCs on this device
1632 * @crtc_list: list of CRTC objects
Daniel Vetter2c0c33d2014-10-27 20:19:38 +01001633 * @property_list: list of property objects
Jesse Barnesa62c93d2011-11-07 12:03:22 -08001634 * @min_width: minimum pixel width on this device
1635 * @min_height: minimum pixel height on this device
1636 * @max_width: maximum pixel width on this device
1637 * @max_height: maximum pixel height on this device
1638 * @funcs: core driver provided mode setting functions
1639 * @fb_base: base address of the framebuffer
Daniel Vetter2c0c33d2014-10-27 20:19:38 +01001640 * @poll_enabled: track polling support for this device
1641 * @poll_running: track polling status for this device
Daniel Vetterac3ba4a2016-05-31 23:11:10 +02001642 * @delayed_event: track delayed poll uevent deliver for this device
Jesse Barnesa62c93d2011-11-07 12:03:22 -08001643 * @output_poll_work: delayed work for polling in process context
Daniel Vetter2c0c33d2014-10-27 20:19:38 +01001644 * @property_blob_list: list of all the blob property objects
Daniel Stone8fb6e7a2015-04-20 19:22:54 +01001645 * @blob_lock: mutex for blob property allocation and management
Jesse Barnesa62c93d2011-11-07 12:03:22 -08001646 * @*_property: core property tracking
Daniel Vetter2c0c33d2014-10-27 20:19:38 +01001647 * @preferred_depth: preferred RBG pixel depth, used by fb helpers
1648 * @prefer_shadow: hint to userspace to prefer shadow-fb rendering
Daniel Vetter2c0c33d2014-10-27 20:19:38 +01001649 * @cursor_width: hint to userspace for max cursor width
1650 * @cursor_height: hint to userspace for max cursor height
Daniel Vetter9f2a7952016-06-08 14:19:02 +02001651 * @helper_private: mid-layer private data
Dave Airlief453ba02008-11-07 14:05:41 -08001652 *
Jesse Barnesa62c93d2011-11-07 12:03:22 -08001653 * Core mode resource tracking structure. All CRTC, encoders, and connectors
1654 * enumerated by the driver are added here, as are global properties. Some
1655 * global restrictions are also here, e.g. dimension restrictions.
Dave Airlief453ba02008-11-07 14:05:41 -08001656 */
1657struct drm_mode_config {
Jesse Barnesad2563c2009-01-19 17:21:45 +10001658 struct mutex mutex; /* protects configuration (mode lists etc.) */
Rob Clark51fd3712013-11-19 12:10:12 -05001659 struct drm_modeset_lock connection_mutex; /* protects connector->encoder and encoder->crtc links */
1660 struct drm_modeset_acquire_ctx *acquire_ctx; /* for legacy _lock_all() / _unlock_all() */
Daniel Vetterac3ba4a2016-05-31 23:11:10 +02001661
1662 /**
1663 * @idr_mutex:
1664 *
1665 * Mutex for KMS ID allocation and management. Protects both @crtc_idr
1666 * and @tile_idr.
1667 */
1668 struct mutex idr_mutex;
1669
1670 /**
1671 * @crtc_idr:
1672 *
1673 * Main KMS ID tracking object. Use this idr for all IDs, fb, crtc,
1674 * connector, modes - just makes life easier to have only one.
1675 */
1676 struct idr crtc_idr;
1677
1678 /**
1679 * @tile_idr:
1680 *
1681 * Use this idr for allocating new IDs for tiled sinks like use in some
1682 * high-res DP MST screens.
1683 */
1684 struct idr tile_idr;
Daniel Vetter4b096ac2012-12-10 21:19:18 +01001685
Daniel Vetter2c0c33d2014-10-27 20:19:38 +01001686 struct mutex fb_lock; /* proctects global and per-file fb lists */
Dave Airlief453ba02008-11-07 14:05:41 -08001687 int num_fb;
1688 struct list_head fb_list;
Daniel Vetter4b096ac2012-12-10 21:19:18 +01001689
Daniel Vetter96094082016-07-15 21:47:59 +02001690 /**
1691 * @num_connector: Number of connectors on this device.
1692 */
Dave Airlief453ba02008-11-07 14:05:41 -08001693 int num_connector;
Daniel Vetter96094082016-07-15 21:47:59 +02001694 /**
1695 * @connector_ida: ID allocator for connector indices.
1696 */
Maarten Lankhorst5fff80b2016-02-17 08:32:05 +01001697 struct ida connector_ida;
Daniel Vetter96094082016-07-15 21:47:59 +02001698 /**
1699 * @connector_list: List of connector objects.
1700 */
Dave Airlief453ba02008-11-07 14:05:41 -08001701 struct list_head connector_list;
1702 int num_encoder;
1703 struct list_head encoder_list;
Matt Ropere27dde32014-04-01 15:22:30 -07001704
1705 /*
1706 * Track # of overlay planes separately from # of total planes. By
1707 * default we only advertise overlay planes to userspace; if userspace
1708 * sets the "universal plane" capability bit, we'll go ahead and
1709 * expose all planes.
1710 */
1711 int num_overlay_plane;
1712 int num_total_plane;
Jesse Barnes8cf5c912011-11-14 14:51:27 -08001713 struct list_head plane_list;
Dave Airlief453ba02008-11-07 14:05:41 -08001714
1715 int num_crtc;
1716 struct list_head crtc_list;
1717
1718 struct list_head property_list;
1719
Dave Airlief453ba02008-11-07 14:05:41 -08001720 int min_width, min_height;
1721 int max_width, max_height;
Laurent Pincharte6ecefa2012-05-17 13:27:23 +02001722 const struct drm_mode_config_funcs *funcs;
Benjamin Herrenschmidtd883f7f2009-02-02 16:55:45 +11001723 resource_size_t fb_base;
Dave Airlief453ba02008-11-07 14:05:41 -08001724
Dave Airlieeb1f8e4f32010-05-07 06:42:51 +00001725 /* output poll support */
1726 bool poll_enabled;
Daniel Vetter905bc9f2012-10-23 18:23:36 +00001727 bool poll_running;
Daniel Vetter162b6a52015-01-21 08:45:21 +01001728 bool delayed_event;
Tejun Heo991ea752010-07-20 22:09:02 +02001729 struct delayed_work output_poll_work;
Dave Airlieeb1f8e4f32010-05-07 06:42:51 +00001730
Daniel Stone8fb6e7a2015-04-20 19:22:54 +01001731 struct mutex blob_lock;
1732
Dave Airlief453ba02008-11-07 14:05:41 -08001733 /* pointers to standard properties */
1734 struct list_head property_blob_list;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02001735 /**
1736 * @edid_property: Default connector property to hold the EDID of the
1737 * currently connected sink, if any.
1738 */
Dave Airlief453ba02008-11-07 14:05:41 -08001739 struct drm_property *edid_property;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02001740 /**
1741 * @dpms_property: Default connector property to control the
1742 * connector's DPMS state.
1743 */
Dave Airlief453ba02008-11-07 14:05:41 -08001744 struct drm_property *dpms_property;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02001745 /**
1746 * @path_property: Default connector property to hold the DP MST path
1747 * for the port.
1748 */
Dave Airlie43aba7e2014-06-05 14:01:31 +10001749 struct drm_property *path_property;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02001750 /**
1751 * @tile_property: Default connector property to store the tile
1752 * position of a tiled screen, for sinks which need to be driven with
1753 * multiple CRTCs.
1754 */
Dave Airlie6f134d72014-10-20 16:30:50 +10001755 struct drm_property *tile_property;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02001756 /**
1757 * @plane_type_property: Default plane property to differentiate
1758 * CURSOR, PRIMARY and OVERLAY legacy uses of planes.
1759 */
Rob Clark9922ab52014-04-01 20:16:57 -04001760 struct drm_property *plane_type_property;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02001761 /**
1762 * @rotation_property: Optional property for planes or CRTCs to specifiy
1763 * rotation.
1764 */
Sonika Jindal2a297cc2014-08-05 11:26:54 +05301765 struct drm_property *rotation_property;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02001766 /**
1767 * @prop_src_x: Default atomic plane property for the plane source
1768 * position in the connected &drm_framebuffer.
1769 */
Rob Clark6b4959f2014-12-18 16:01:53 -05001770 struct drm_property *prop_src_x;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02001771 /**
1772 * @prop_src_y: Default atomic plane property for the plane source
1773 * position in the connected &drm_framebuffer.
1774 */
Rob Clark6b4959f2014-12-18 16:01:53 -05001775 struct drm_property *prop_src_y;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02001776 /**
1777 * @prop_src_w: Default atomic plane property for the plane source
1778 * position in the connected &drm_framebuffer.
1779 */
Rob Clark6b4959f2014-12-18 16:01:53 -05001780 struct drm_property *prop_src_w;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02001781 /**
1782 * @prop_src_h: Default atomic plane property for the plane source
1783 * position in the connected &drm_framebuffer.
1784 */
Rob Clark6b4959f2014-12-18 16:01:53 -05001785 struct drm_property *prop_src_h;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02001786 /**
1787 * @prop_crtc_x: Default atomic plane property for the plane destination
1788 * position in the &drm_crtc is is being shown on.
1789 */
Rob Clark6b4959f2014-12-18 16:01:53 -05001790 struct drm_property *prop_crtc_x;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02001791 /**
1792 * @prop_crtc_y: Default atomic plane property for the plane destination
1793 * position in the &drm_crtc is is being shown on.
1794 */
Rob Clark6b4959f2014-12-18 16:01:53 -05001795 struct drm_property *prop_crtc_y;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02001796 /**
1797 * @prop_crtc_w: Default atomic plane property for the plane destination
1798 * position in the &drm_crtc is is being shown on.
1799 */
Rob Clark6b4959f2014-12-18 16:01:53 -05001800 struct drm_property *prop_crtc_w;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02001801 /**
1802 * @prop_crtc_h: Default atomic plane property for the plane destination
1803 * position in the &drm_crtc is is being shown on.
1804 */
Rob Clark6b4959f2014-12-18 16:01:53 -05001805 struct drm_property *prop_crtc_h;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02001806 /**
1807 * @prop_fb_id: Default atomic plane property to specify the
1808 * &drm_framebuffer.
1809 */
Rob Clark6b4959f2014-12-18 16:01:53 -05001810 struct drm_property *prop_fb_id;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02001811 /**
1812 * @prop_crtc_id: Default atomic plane property to specify the
1813 * &drm_crtc.
1814 */
Rob Clark6b4959f2014-12-18 16:01:53 -05001815 struct drm_property *prop_crtc_id;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02001816 /**
1817 * @prop_active: Default atomic CRTC property to control the active
1818 * state, which is the simplified implementation for DPMS in atomic
1819 * drivers.
1820 */
Daniel Vettereab3bbe2015-01-22 16:36:21 +01001821 struct drm_property *prop_active;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02001822 /**
1823 * @prop_mode_id: Default atomic CRTC property to set the mode for a
1824 * CRTC. A 0 mode implies that the CRTC is entirely disabled - all
1825 * connectors must be of and active must be set to disabled, too.
1826 */
Daniel Stone955f3c32015-05-25 19:11:52 +01001827 struct drm_property *prop_mode_id;
Dave Airlief453ba02008-11-07 14:05:41 -08001828
Daniel Vetter9a6bc032016-07-15 21:48:00 +02001829 /**
1830 * @dvi_i_subconnector_property: Optional DVI-I property to
1831 * differentiate between analog or digital mode.
1832 */
Dave Airlief453ba02008-11-07 14:05:41 -08001833 struct drm_property *dvi_i_subconnector_property;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02001834 /**
1835 * @dvi_i_select_subconnector_property: Optional DVI-I property to
1836 * select between analog or digital mode.
1837 */
Dave Airlief453ba02008-11-07 14:05:41 -08001838 struct drm_property *dvi_i_select_subconnector_property;
1839
Daniel Vetter9a6bc032016-07-15 21:48:00 +02001840 /**
1841 * @tv_subconnector_property: Optional TV property to differentiate
1842 * between different TV connector types.
1843 */
Dave Airlief453ba02008-11-07 14:05:41 -08001844 struct drm_property *tv_subconnector_property;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02001845 /**
1846 * @tv_select_subconnector_property: Optional TV property to select
1847 * between different TV connector types.
1848 */
Dave Airlief453ba02008-11-07 14:05:41 -08001849 struct drm_property *tv_select_subconnector_property;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02001850 /**
1851 * @tv_mode_property: Optional TV property to select
1852 * the output TV mode.
1853 */
Dave Airlief453ba02008-11-07 14:05:41 -08001854 struct drm_property *tv_mode_property;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02001855 /**
1856 * @tv_left_margin_property: Optional TV property to set the left
1857 * margin.
1858 */
Dave Airlief453ba02008-11-07 14:05:41 -08001859 struct drm_property *tv_left_margin_property;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02001860 /**
1861 * @tv_right_margin_property: Optional TV property to set the right
1862 * margin.
1863 */
Dave Airlief453ba02008-11-07 14:05:41 -08001864 struct drm_property *tv_right_margin_property;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02001865 /**
1866 * @tv_top_margin_property: Optional TV property to set the right
1867 * margin.
1868 */
Dave Airlief453ba02008-11-07 14:05:41 -08001869 struct drm_property *tv_top_margin_property;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02001870 /**
1871 * @tv_bottom_margin_property: Optional TV property to set the right
1872 * margin.
1873 */
Dave Airlief453ba02008-11-07 14:05:41 -08001874 struct drm_property *tv_bottom_margin_property;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02001875 /**
1876 * @tv_brightness_property: Optional TV property to set the
1877 * brightness.
1878 */
Francisco Jerezb6b79022009-08-02 04:19:20 +02001879 struct drm_property *tv_brightness_property;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02001880 /**
1881 * @tv_contrast_property: Optional TV property to set the
1882 * contrast.
1883 */
Francisco Jerezb6b79022009-08-02 04:19:20 +02001884 struct drm_property *tv_contrast_property;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02001885 /**
1886 * @tv_flicker_reduction_property: Optional TV property to control the
1887 * flicker reduction mode.
1888 */
Francisco Jerezb6b79022009-08-02 04:19:20 +02001889 struct drm_property *tv_flicker_reduction_property;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02001890 /**
1891 * @tv_overscan_property: Optional TV property to control the overscan
1892 * setting.
1893 */
Francisco Jereza75f0232009-08-12 02:30:10 +02001894 struct drm_property *tv_overscan_property;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02001895 /**
1896 * @tv_saturation_property: Optional TV property to set the
1897 * saturation.
1898 */
Francisco Jereza75f0232009-08-12 02:30:10 +02001899 struct drm_property *tv_saturation_property;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02001900 /**
1901 * @tv_hue_property: Optional TV property to set the hue.
1902 */
Francisco Jereza75f0232009-08-12 02:30:10 +02001903 struct drm_property *tv_hue_property;
Dave Airlief453ba02008-11-07 14:05:41 -08001904
Daniel Vetter9a6bc032016-07-15 21:48:00 +02001905 /**
1906 * @scaling_mode_property: Optional connector property to control the
1907 * upscaling, mostly used for built-in panels.
1908 */
Dave Airlief453ba02008-11-07 14:05:41 -08001909 struct drm_property *scaling_mode_property;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02001910 /**
1911 * @aspect_ratio_property: Optional connector property to control the
1912 * HDMI infoframe aspect ratio setting.
1913 */
Vandana Kannanff587e42014-06-11 10:46:48 +05301914 struct drm_property *aspect_ratio_property;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02001915 /**
Daniel Vetter9a6bc032016-07-15 21:48:00 +02001916 * @degamma_lut_property: Optional CRTC property to set the LUT used to
1917 * convert the framebuffer's colors to linear gamma.
1918 */
Lionel Landwerlin5488dc12016-02-26 17:05:00 +00001919 struct drm_property *degamma_lut_property;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02001920 /**
1921 * @degamma_lut_size_property: Optional CRTC property for the size of
1922 * the degamma LUT as supported by the driver (read-only).
1923 */
Lionel Landwerlin5488dc12016-02-26 17:05:00 +00001924 struct drm_property *degamma_lut_size_property;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02001925 /**
1926 * @ctm_property: Optional CRTC property to set the
1927 * matrix used to convert colors after the lookup in the
1928 * degamma LUT.
1929 */
Lionel Landwerlin5488dc12016-02-26 17:05:00 +00001930 struct drm_property *ctm_property;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02001931 /**
1932 * @gamma_lut_property: Optional CRTC property to set the LUT used to
1933 * convert the colors, after the CTM matrix, to the gamma space of the
1934 * connected screen.
1935 */
Lionel Landwerlin5488dc12016-02-26 17:05:00 +00001936 struct drm_property *gamma_lut_property;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02001937 /**
1938 * @gamma_lut_size_property: Optional CRTC property for the size of the
1939 * gamma LUT as supported by the driver (read-only).
1940 */
Lionel Landwerlin5488dc12016-02-26 17:05:00 +00001941 struct drm_property *gamma_lut_size_property;
1942
Daniel Vetter9a6bc032016-07-15 21:48:00 +02001943 /**
1944 * @suggested_x_property: Optional connector property with a hint for
1945 * the position of the output on the host's screen.
1946 */
Dave Airlie5bb2bbf2014-11-10 10:18:15 +10001947 struct drm_property *suggested_x_property;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02001948 /**
1949 * @suggested_y_property: Optional connector property with a hint for
1950 * the position of the output on the host's screen.
1951 */
Dave Airlie5bb2bbf2014-11-10 10:18:15 +10001952 struct drm_property *suggested_y_property;
1953
Dave Airlie019d96c2011-09-29 16:20:42 +01001954 /* dumb ioctl parameters */
1955 uint32_t preferred_depth, prefer_shadow;
Keith Packard62f21042013-07-22 18:50:00 -07001956
Daniel Vetter9a6bc032016-07-15 21:48:00 +02001957 /**
1958 * @async_page_flip: Does this device support async flips on the primary
1959 * plane?
1960 */
Keith Packard62f21042013-07-22 18:50:00 -07001961 bool async_page_flip;
Alex Deucher8716ed42014-02-12 12:48:23 -05001962
Daniel Vetterac3ba4a2016-05-31 23:11:10 +02001963 /**
1964 * @allow_fb_modifiers:
1965 *
1966 * Whether the driver supports fb modifiers in the ADDFB2.1 ioctl call.
1967 */
Rob Clarke3eb3252015-02-05 14:41:52 +00001968 bool allow_fb_modifiers;
1969
Alex Deucher8716ed42014-02-12 12:48:23 -05001970 /* cursor size */
1971 uint32_t cursor_width, cursor_height;
Daniel Vetter9f2a7952016-06-08 14:19:02 +02001972
1973 struct drm_mode_config_helper_funcs *helper_private;
Dave Airlief453ba02008-11-07 14:05:41 -08001974};
1975
Rob Clarkdd275952014-11-25 20:29:46 -05001976/**
1977 * drm_for_each_plane_mask - iterate over planes specified by bitmask
1978 * @plane: the loop cursor
1979 * @dev: the DRM device
1980 * @plane_mask: bitmask of plane indices
1981 *
1982 * Iterate over all planes specified by bitmask.
1983 */
1984#define drm_for_each_plane_mask(plane, dev, plane_mask) \
1985 list_for_each_entry((plane), &(dev)->mode_config.plane_list, head) \
Jani Nikula373701b2015-11-24 21:21:55 +02001986 for_each_if ((plane_mask) & (1 << drm_plane_index(plane)))
Rob Clarkdd275952014-11-25 20:29:46 -05001987
Maarten Lankhorstead8b662016-01-07 10:59:19 +01001988/**
1989 * drm_for_each_encoder_mask - iterate over encoders specified by bitmask
1990 * @encoder: the loop cursor
1991 * @dev: the DRM device
1992 * @encoder_mask: bitmask of encoder indices
1993 *
1994 * Iterate over all encoders specified by bitmask.
1995 */
1996#define drm_for_each_encoder_mask(encoder, dev, encoder_mask) \
1997 list_for_each_entry((encoder), &(dev)->mode_config.encoder_list, head) \
1998 for_each_if ((encoder_mask) & (1 << drm_encoder_index(encoder)))
Rob Clarkdd275952014-11-25 20:29:46 -05001999
Dave Airlief453ba02008-11-07 14:05:41 -08002000#define obj_to_crtc(x) container_of(x, struct drm_crtc, base)
Dave Airlief453ba02008-11-07 14:05:41 -08002001#define obj_to_mode(x) container_of(x, struct drm_display_mode, base)
2002#define obj_to_fb(x) container_of(x, struct drm_framebuffer, base)
Dave Airlief453ba02008-11-07 14:05:41 -08002003#define obj_to_blob(x) container_of(x, struct drm_property_blob, base)
Jesse Barnes8cf5c912011-11-14 14:51:27 -08002004#define obj_to_plane(x) container_of(x, struct drm_plane, base)
Dave Airlief453ba02008-11-07 14:05:41 -08002005
Ville Syrjäläf9882872015-12-09 16:19:31 +02002006extern __printf(6, 7)
2007int drm_crtc_init_with_planes(struct drm_device *dev,
2008 struct drm_crtc *crtc,
2009 struct drm_plane *primary,
2010 struct drm_plane *cursor,
2011 const struct drm_crtc_funcs *funcs,
2012 const char *name, ...);
Dave Airlief453ba02008-11-07 14:05:41 -08002013extern void drm_crtc_cleanup(struct drm_crtc *crtc);
Chris Wilson490d3d12016-05-27 20:05:00 +01002014
2015/**
2016 * drm_crtc_index - find the index of a registered CRTC
2017 * @crtc: CRTC to find index for
2018 *
2019 * Given a registered CRTC, return the index of that CRTC within a DRM
2020 * device's list of CRTCs.
2021 */
2022static inline unsigned int drm_crtc_index(struct drm_crtc *crtc)
2023{
2024 return crtc->index;
2025}
Russell Kingdb5f7a62014-01-02 21:27:33 +00002026
2027/**
2028 * drm_crtc_mask - find the mask of a registered CRTC
2029 * @crtc: CRTC to find mask for
2030 *
2031 * Given a registered CRTC, return the mask bit of that CRTC for an
2032 * encoder's possible_crtcs field.
2033 */
2034static inline uint32_t drm_crtc_mask(struct drm_crtc *crtc)
2035{
2036 return 1 << drm_crtc_index(crtc);
2037}
Dave Airlief453ba02008-11-07 14:05:41 -08002038
Ville Syrjäläb0b3b792015-12-09 16:19:55 +02002039extern __printf(8, 9)
2040int drm_universal_plane_init(struct drm_device *dev,
2041 struct drm_plane *plane,
2042 unsigned long possible_crtcs,
2043 const struct drm_plane_funcs *funcs,
2044 const uint32_t *formats,
2045 unsigned int format_count,
2046 enum drm_plane_type type,
2047 const char *name, ...);
Jesse Barnes8cf5c912011-11-14 14:51:27 -08002048extern int drm_plane_init(struct drm_device *dev,
2049 struct drm_plane *plane,
2050 unsigned long possible_crtcs,
2051 const struct drm_plane_funcs *funcs,
Thierry Reding45e37432015-08-12 16:54:28 +02002052 const uint32_t *formats, unsigned int format_count,
Matt Roperdc415ff2014-04-01 15:22:36 -07002053 bool is_primary);
Jesse Barnes8cf5c912011-11-14 14:51:27 -08002054extern void drm_plane_cleanup(struct drm_plane *plane);
Chris Wilson490d3d12016-05-27 20:05:00 +01002055
2056/**
2057 * drm_plane_index - find the index of a registered plane
2058 * @plane: plane to find index for
2059 *
2060 * Given a registered plane, return the index of that plane within a DRM
2061 * device's list of planes.
2062 */
2063static inline unsigned int drm_plane_index(struct drm_plane *plane)
2064{
2065 return plane->index;
2066}
Chandra Konduruf81338a2015-04-09 17:36:21 -07002067extern struct drm_plane * drm_plane_from_index(struct drm_device *dev, int idx);
Ville Syrjälä9125e612013-06-03 16:10:40 +03002068extern void drm_plane_force_disable(struct drm_plane *plane);
Gustavo Padovanecb7e162014-12-01 15:40:09 -08002069extern void drm_crtc_get_hv_timing(const struct drm_display_mode *mode,
2070 int *hdisplay, int *vdisplay);
Lukas Wunner6a0d9522016-06-08 18:47:27 +02002071extern int drm_crtc_force_disable(struct drm_crtc *crtc);
2072extern int drm_crtc_force_disable_all(struct drm_device *dev);
Jesse Barnes8cf5c912011-11-14 14:51:27 -08002073
Dave Airlief453ba02008-11-07 14:05:41 -08002074extern void drm_mode_config_init(struct drm_device *dev);
Chris Wilsoneb0335562011-01-24 15:11:08 +00002075extern void drm_mode_config_reset(struct drm_device *dev);
Dave Airlief453ba02008-11-07 14:05:41 -08002076extern void drm_mode_config_cleanup(struct drm_device *dev);
Dave Airlief453ba02008-11-07 14:05:41 -08002077
Sascha Hauer4cae5b82012-02-01 11:38:23 +01002078extern int drm_mode_crtc_set_gamma_size(struct drm_crtc *crtc,
Dave Airlief453ba02008-11-07 14:05:41 -08002079 int gamma_size);
Rob Clark98f75de2014-05-30 11:37:03 -04002080
Daniel Vetter2d13b672012-12-11 13:47:23 +01002081extern int drm_mode_set_config_internal(struct drm_mode_set *set);
Daniel Vetter81065542016-06-21 10:54:13 +02002082
Dave Airlie138f9eb2014-10-20 16:17:17 +10002083extern struct drm_tile_group *drm_mode_create_tile_group(struct drm_device *dev,
2084 char topology[8]);
2085extern struct drm_tile_group *drm_mode_get_tile_group(struct drm_device *dev,
2086 char topology[8]);
2087extern void drm_mode_put_tile_group(struct drm_device *dev,
2088 struct drm_tile_group *tg);
Dave Airlieff72145b2011-02-07 12:16:14 +10002089
Thomas Wood3a5f87c2014-08-20 14:45:00 +01002090extern int drm_mode_plane_set_obj_prop(struct drm_plane *plane,
2091 struct drm_property *property,
2092 uint64_t value);
Dave Airlie248dbc22011-11-29 20:02:54 +00002093
Ville Syrjäläc1df5f32014-07-08 10:31:53 +05302094extern struct drm_property *drm_mode_create_rotation_property(struct drm_device *dev,
2095 unsigned int supported_rotations);
Ville Syrjälä3c9855f2014-07-08 10:31:56 +05302096extern unsigned int drm_rotation_simplify(unsigned int rotation,
2097 unsigned int supported_rotations);
Jyri Sarhaf8ed34a2016-06-07 15:09:14 +03002098extern void drm_crtc_enable_color_mgmt(struct drm_crtc *crtc,
2099 uint degamma_lut_size,
2100 bool has_ctm,
2101 uint gamma_lut_size);
Marek Szyprowski44d1240d2016-06-13 11:11:26 +02002102
2103int drm_plane_create_zpos_property(struct drm_plane *plane,
2104 unsigned int zpos,
2105 unsigned int min, unsigned int max);
2106
2107int drm_plane_create_zpos_immutable_property(struct drm_plane *plane,
2108 unsigned int zpos);
2109
Russell King96f60e32012-08-15 13:59:49 +01002110/* Helpers */
Rob Clarka2b34e22013-10-05 16:36:52 -04002111static inline struct drm_plane *drm_plane_find(struct drm_device *dev,
2112 uint32_t id)
2113{
2114 struct drm_mode_object *mo;
2115 mo = drm_mode_object_find(dev, id, DRM_MODE_OBJECT_PLANE);
2116 return mo ? obj_to_plane(mo) : NULL;
2117}
2118
Russell King96f60e32012-08-15 13:59:49 +01002119static inline struct drm_crtc *drm_crtc_find(struct drm_device *dev,
2120 uint32_t id)
2121{
2122 struct drm_mode_object *mo;
2123 mo = drm_mode_object_find(dev, id, DRM_MODE_OBJECT_CRTC);
2124 return mo ? obj_to_crtc(mo) : NULL;
2125}
2126
Lionel Landwerlin5488dc12016-02-26 17:05:00 +00002127/*
2128 * Extract a degamma/gamma LUT value provided by user and round it to the
2129 * precision supported by the hardware.
2130 */
2131static inline uint32_t drm_color_lut_extract(uint32_t user_input,
2132 uint32_t bit_precision)
2133{
Lionel Landwerlin644a8052016-03-22 14:10:33 +00002134 uint32_t val = user_input;
Lionel Landwerlin5488dc12016-02-26 17:05:00 +00002135 uint32_t max = 0xffff >> (16 - bit_precision);
2136
Lionel Landwerlin644a8052016-03-22 14:10:33 +00002137 /* Round only if we're not using full precision. */
2138 if (bit_precision < 16) {
2139 val += 1UL << (16 - bit_precision - 1);
2140 val >>= 16 - bit_precision;
2141 }
Lionel Landwerlin5488dc12016-02-26 17:05:00 +00002142
2143 return clamp_val(val, 0, max);
2144}
2145
Matt Ropere27dde32014-04-01 15:22:30 -07002146/* Plane list iterator for legacy (overlay only) planes. */
Daniel Vetter4ea50e92015-07-09 23:44:24 +02002147#define drm_for_each_legacy_plane(plane, dev) \
2148 list_for_each_entry(plane, &(dev)->mode_config.plane_list, head) \
Jani Nikula373701b2015-11-24 21:21:55 +02002149 for_each_if (plane->type == DRM_PLANE_TYPE_OVERLAY)
Matt Ropere27dde32014-04-01 15:22:30 -07002150
Daniel Vetter6295d602015-07-09 23:44:25 +02002151#define drm_for_each_plane(plane, dev) \
2152 list_for_each_entry(plane, &(dev)->mode_config.plane_list, head)
2153
2154#define drm_for_each_crtc(crtc, dev) \
2155 list_for_each_entry(crtc, &(dev)->mode_config.crtc_list, head)
2156
Daniel Vetter7a3f3d62015-07-09 23:44:28 +02002157static inline void
2158assert_drm_connector_list_read_locked(struct drm_mode_config *mode_config)
2159{
Daniel Vettercff20ba2015-07-09 23:44:33 +02002160 /*
2161 * The connector hotadd/remove code currently grabs both locks when
2162 * updating lists. Hence readers need only hold either of them to be
2163 * safe and the check amounts to
2164 *
2165 * WARN_ON(not_holding(A) && not_holding(B)).
2166 */
2167 WARN_ON(!mutex_is_locked(&mode_config->mutex) &&
2168 !drm_modeset_is_locked(&mode_config->connection_mutex));
Daniel Vetter7a3f3d62015-07-09 23:44:28 +02002169}
2170
Daniel Vetter6295d602015-07-09 23:44:25 +02002171#define drm_for_each_connector(connector, dev) \
Daniel Vetter7a3f3d62015-07-09 23:44:28 +02002172 for (assert_drm_connector_list_read_locked(&(dev)->mode_config), \
2173 connector = list_first_entry(&(dev)->mode_config.connector_list, \
2174 struct drm_connector, head); \
2175 &connector->head != (&(dev)->mode_config.connector_list); \
2176 connector = list_next_entry(connector, head))
Daniel Vetter6295d602015-07-09 23:44:25 +02002177
2178#define drm_for_each_encoder(encoder, dev) \
2179 list_for_each_entry(encoder, &(dev)->mode_config.encoder_list, head)
2180
2181#define drm_for_each_fb(fb, dev) \
Daniel Vetter4676ba02015-07-09 23:44:30 +02002182 for (WARN_ON(!mutex_is_locked(&(dev)->mode_config.fb_lock)), \
2183 fb = list_first_entry(&(dev)->mode_config.fb_list, \
2184 struct drm_framebuffer, head); \
2185 &fb->head != (&(dev)->mode_config.fb_list); \
2186 fb = list_next_entry(fb, head))
Daniel Vetter6295d602015-07-09 23:44:25 +02002187
Daniel Vetter81065542016-06-21 10:54:13 +02002188/* drm_edid.c */
2189bool drm_probe_ddc(struct i2c_adapter *adapter);
2190struct edid *drm_get_edid(struct drm_connector *connector,
2191 struct i2c_adapter *adapter);
2192struct edid *drm_get_edid_switcheroo(struct drm_connector *connector,
2193 struct i2c_adapter *adapter);
2194struct edid *drm_edid_duplicate(const struct edid *edid);
2195int drm_add_edid_modes(struct drm_connector *connector, struct edid *edid);
2196
2197u8 drm_match_cea_mode(const struct drm_display_mode *to_match);
2198enum hdmi_picture_aspect drm_get_cea_aspect_ratio(const u8 video_code);
2199bool drm_detect_hdmi_monitor(struct edid *edid);
2200bool drm_detect_monitor_audio(struct edid *edid);
2201bool drm_rgb_quant_range_selectable(struct edid *edid);
2202int drm_add_modes_noedid(struct drm_connector *connector,
2203 int hdisplay, int vdisplay);
2204void drm_set_preferred_mode(struct drm_connector *connector,
2205 int hpref, int vpref);
2206
2207int drm_edid_header_is_valid(const u8 *raw_edid);
2208bool drm_edid_block_valid(u8 *raw_edid, int block, bool print_bad_edid,
2209 bool *edid_corrupt);
2210bool drm_edid_is_valid(struct edid *edid);
2211void drm_edid_get_monitor_name(struct edid *edid, char *name,
2212 int buflen);
2213struct drm_display_mode *drm_mode_find_dmt(struct drm_device *dev,
2214 int hsize, int vsize, int fresh,
2215 bool rb);
2216
2217/* drm_bridge.c */
2218extern int drm_bridge_add(struct drm_bridge *bridge);
2219extern void drm_bridge_remove(struct drm_bridge *bridge);
2220extern struct drm_bridge *of_drm_find_bridge(struct device_node *np);
2221extern int drm_bridge_attach(struct drm_device *dev, struct drm_bridge *bridge);
Andrea Merellocf3bef92016-08-25 11:04:32 +02002222extern void drm_bridge_detach(struct drm_bridge *bridge);
Daniel Vetter81065542016-06-21 10:54:13 +02002223
2224bool drm_bridge_mode_fixup(struct drm_bridge *bridge,
2225 const struct drm_display_mode *mode,
2226 struct drm_display_mode *adjusted_mode);
2227void drm_bridge_disable(struct drm_bridge *bridge);
2228void drm_bridge_post_disable(struct drm_bridge *bridge);
2229void drm_bridge_mode_set(struct drm_bridge *bridge,
2230 struct drm_display_mode *mode,
2231 struct drm_display_mode *adjusted_mode);
2232void drm_bridge_pre_enable(struct drm_bridge *bridge);
2233void drm_bridge_enable(struct drm_bridge *bridge);
2234
Dave Airlief453ba02008-11-07 14:05:41 -08002235#endif /* __DRM_CRTC_H__ */