blob: e30ea0be641738bcd01cf94fe62e01592a7c181e [file] [log] [blame]
Dave Airlief453ba02008-11-07 14:05:41 -08001/*
2 * Copyright © 2006 Keith Packard
3 * Copyright © 2007-2008 Dave Airlie
4 * Copyright © 2007-2008 Intel Corporation
5 * Jesse Barnes <jesse.barnes@intel.com>
6 *
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the "Software"),
9 * to deal in the Software without restriction, including without limitation
10 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
11 * and/or sell copies of the Software, and to permit persons to whom the
12 * Software is furnished to do so, subject to the following conditions:
13 *
14 * The above copyright notice and this permission notice shall be included in
15 * all copies or substantial portions of the Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
21 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
22 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
23 * OTHER DEALINGS IN THE SOFTWARE.
24 */
25#ifndef __DRM_CRTC_H__
26#define __DRM_CRTC_H__
27
28#include <linux/i2c.h>
29#include <linux/spinlock.h>
30#include <linux/types.h>
31#include <linux/idr.h>
Dave Airlief453ba02008-11-07 14:05:41 -080032#include <linux/fb.h>
Vandana Kannan985e5dc2013-12-19 15:34:07 +053033#include <linux/hdmi.h>
Boris Brezillonb5571e92014-07-22 12:09:10 +020034#include <linux/media-bus-format.h>
David Herrmannd7d2c482014-08-29 12:12:40 +020035#include <uapi/drm/drm_mode.h>
36#include <uapi/drm/drm_fourcc.h>
Rob Clark51fd3712013-11-19 12:10:12 -050037#include <drm/drm_modeset_lock.h>
Ville Syrjäläd7da8242016-07-26 19:06:57 +030038#include <drm/drm_rect.h>
Daniel Vetter7520a272016-08-15 16:07:02 +020039#include <drm/drm_modeset.h>
40#include <drm/drm_framebuffer.h>
41#include <drm/drm_modes.h>
Daniel Vetter52217192016-08-12 22:48:50 +020042#include <drm/drm_connector.h>
Jesse Barnes308e5bc2011-11-14 14:51:28 -080043
Dave Airlief453ba02008-11-07 14:05:41 -080044struct drm_device;
45struct drm_mode_set;
Thierry Reding595887e2012-11-21 15:00:47 +010046struct drm_file;
47struct drm_clip_rect;
Russell King7e435aa2014-06-15 11:07:12 +010048struct device_node;
Daniel Vettere2330f02014-10-29 11:34:56 +010049struct fence;
Daniel Vetter81065542016-06-21 10:54:13 +020050struct edid;
Dave Airlief453ba02008-11-07 14:05:41 -080051
Rob Clarkebc44cf2012-09-12 22:22:31 -050052static inline int64_t U642I64(uint64_t val)
53{
54 return (int64_t)*((int64_t *)&val);
55}
56static inline uint64_t I642U64(int64_t val)
57{
58 return (uint64_t)*((uint64_t *)&val);
59}
60
Robert Feketed9c38242015-11-02 16:14:08 +010061/*
62 * Rotation property bits. DRM_ROTATE_<degrees> rotates the image by the
63 * specified amount in degrees in counter clockwise direction. DRM_REFLECT_X and
64 * DRM_REFLECT_Y reflects the image along the specified axis prior to rotation
65 */
Joonas Lahtinen31ad61e2016-07-29 08:50:05 +030066#define DRM_ROTATE_0 BIT(0)
67#define DRM_ROTATE_90 BIT(1)
68#define DRM_ROTATE_180 BIT(2)
69#define DRM_ROTATE_270 BIT(3)
70#define DRM_ROTATE_MASK (DRM_ROTATE_0 | DRM_ROTATE_90 | \
71 DRM_ROTATE_180 | DRM_ROTATE_270)
72#define DRM_REFLECT_X BIT(4)
73#define DRM_REFLECT_Y BIT(5)
74#define DRM_REFLECT_MASK (DRM_REFLECT_X | DRM_REFLECT_Y)
Ville Syrjälä06596962014-07-08 10:31:51 +053075
Dave Airlie138f9eb2014-10-20 16:17:17 +100076/* data corresponds to displayid vend/prod/serial */
77struct drm_tile_group {
78 struct kref refcount;
79 struct drm_device *dev;
80 int id;
81 u8 group_data[8];
82};
83
Dave Airlief453ba02008-11-07 14:05:41 -080084struct drm_property_blob {
85 struct drm_mode_object base;
Daniel Stone6bcacf52015-04-20 19:22:55 +010086 struct drm_device *dev;
Daniel Stonee2f5d2e2015-05-22 13:34:51 +010087 struct list_head head_global;
88 struct list_head head_file;
Thierry Redingecbbe592014-05-13 11:36:13 +020089 size_t length;
Ville Syrjäläd63f5e62012-03-13 12:35:49 +020090 unsigned char data[];
Dave Airlief453ba02008-11-07 14:05:41 -080091};
92
93struct drm_property_enum {
94 uint64_t value;
95 struct list_head head;
96 char name[DRM_PROP_NAME_LEN];
97};
98
99struct drm_property {
100 struct list_head head;
101 struct drm_mode_object base;
102 uint32_t flags;
103 char name[DRM_PROP_NAME_LEN];
104 uint32_t num_values;
105 uint64_t *values;
Rob Clark98f75de2014-05-30 11:37:03 -0400106 struct drm_device *dev;
Dave Airlief453ba02008-11-07 14:05:41 -0800107
Daniel Vetter3758b342014-11-19 18:38:10 +0100108 struct list_head enum_list;
Dave Airlief453ba02008-11-07 14:05:41 -0800109};
110
111struct drm_crtc;
Dave Airlief453ba02008-11-07 14:05:41 -0800112struct drm_encoder;
Kristian Høgsbergd91d8a32009-11-17 12:43:55 -0500113struct drm_pending_vblank_event;
Jesse Barnes8cf5c912011-11-14 14:51:27 -0800114struct drm_plane;
Sean Paul3b336ec2013-08-14 16:47:37 -0400115struct drm_bridge;
Daniel Vetter144ecb92014-10-27 20:28:44 +0100116struct drm_atomic_state;
117
Daniel Vetter4490d4c2015-12-04 09:45:45 +0100118struct drm_crtc_helper_funcs;
119struct drm_encoder_helper_funcs;
Daniel Vetter4490d4c2015-12-04 09:45:45 +0100120struct drm_plane_helper_funcs;
121
Daniel Vetter144ecb92014-10-27 20:28:44 +0100122/**
Daniel Vettercc4ceb42014-07-25 21:30:38 +0200123 * struct drm_crtc_state - mutable CRTC state
Daniel Vetter07cc0ef2014-11-27 15:49:39 +0100124 * @crtc: backpointer to the CRTC
Daniel Vetter144ecb92014-10-27 20:28:44 +0100125 * @enable: whether the CRTC should be enabled, gates all other state
Daniel Vetterd9b13622014-11-26 16:57:41 +0100126 * @active: whether the CRTC is actively displaying (used for DPMS)
Maarten Lankhorstfc596662015-07-21 13:28:57 +0200127 * @planes_changed: planes on this crtc are updated
128 * @mode_changed: crtc_state->mode or crtc_state->enable has been changed
129 * @active_changed: crtc_state->active has been toggled.
130 * @connectors_changed: connectors to this crtc have been updated
Marek Szyprowski44d1240d2016-06-13 11:11:26 +0200131 * @zpos_changed: zpos values of planes on this crtc have been updated
Lionel Landwerlin5488dc12016-02-26 17:05:00 +0000132 * @color_mgmt_changed: color management properties have changed (degamma or
133 * gamma LUT or CSC matrix)
Rob Clark6ddd3882014-11-21 15:28:31 -0500134 * @plane_mask: bitmask of (1 << drm_plane_index(plane)) of attached planes
Maarten Lankhorst4cd9fa52016-01-04 12:53:18 +0100135 * @connector_mask: bitmask of (1 << drm_connector_index(connector)) of attached connectors
Maarten Lankhorste87a52b2016-01-28 15:04:58 +0100136 * @encoder_mask: bitmask of (1 << drm_encoder_index(encoder)) of attached encoders
Daniel Vetter623369e2014-09-16 17:50:47 +0200137 * @last_vblank_count: for helpers and drivers to capture the vblank of the
138 * update to ensure framebuffer cleanup isn't done too early
Daniel Vetter2f324b42014-10-29 11:13:47 +0100139 * @adjusted_mode: for use by helpers and drivers to compute adjusted mode timings
Daniel Vetter144ecb92014-10-27 20:28:44 +0100140 * @mode: current mode timings
Daniel Vetterac3ba4a2016-05-31 23:11:10 +0200141 * @mode_blob: &drm_property_blob for @mode
Lionel Landwerlin5488dc12016-02-26 17:05:00 +0000142 * @degamma_lut: Lookup table for converting framebuffer pixel data
143 * before apply the conversion matrix
144 * @ctm: Transformation matrix
145 * @gamma_lut: Lookup table for converting pixel data after the
146 * conversion matrix
Daniel Vetter144ecb92014-10-27 20:28:44 +0100147 * @event: optional pointer to a DRM event to signal upon completion of the
148 * state update
149 * @state: backpointer to global drm_atomic_state
Daniel Vetterd9b13622014-11-26 16:57:41 +0100150 *
151 * Note that the distinction between @enable and @active is rather subtile:
152 * Flipping @active while @enable is set without changing anything else may
153 * never return in a failure from the ->atomic_check callback. Userspace assumes
154 * that a DPMS On will always succeed. In other words: @enable controls resource
155 * assignment, @active controls the actual hardware state.
Daniel Vetter144ecb92014-10-27 20:28:44 +0100156 */
157struct drm_crtc_state {
Daniel Vetter07cc0ef2014-11-27 15:49:39 +0100158 struct drm_crtc *crtc;
159
Daniel Vettercc4ceb42014-07-25 21:30:38 +0200160 bool enable;
Daniel Vetterd9b13622014-11-26 16:57:41 +0100161 bool active;
Daniel Vetter144ecb92014-10-27 20:28:44 +0100162
Daniel Vetterc2fcd272014-11-05 00:14:14 +0100163 /* computed state bits used by helpers and drivers */
164 bool planes_changed : 1;
Daniel Vetter623369e2014-09-16 17:50:47 +0200165 bool mode_changed : 1;
Daniel Vettereab3bbe2015-01-22 16:36:21 +0100166 bool active_changed : 1;
Maarten Lankhorstfc596662015-07-21 13:28:57 +0200167 bool connectors_changed : 1;
Marek Szyprowski44d1240d2016-06-13 11:11:26 +0200168 bool zpos_changed : 1;
Lionel Landwerlin5488dc12016-02-26 17:05:00 +0000169 bool color_mgmt_changed : 1;
Daniel Vetter623369e2014-09-16 17:50:47 +0200170
Rob Clark6ddd3882014-11-21 15:28:31 -0500171 /* attached planes bitmask:
172 * WARNING: transitional helpers do not maintain plane_mask so
173 * drivers not converted over to atomic helpers should not rely
174 * on plane_mask being accurate!
175 */
176 u32 plane_mask;
177
Maarten Lankhorst4cd9fa52016-01-04 12:53:18 +0100178 u32 connector_mask;
Maarten Lankhorste87a52b2016-01-28 15:04:58 +0100179 u32 encoder_mask;
Maarten Lankhorst4cd9fa52016-01-04 12:53:18 +0100180
Daniel Vetter623369e2014-09-16 17:50:47 +0200181 /* last_vblank_count: for vblank waits before cleanup */
182 u32 last_vblank_count;
Daniel Vetterc2fcd272014-11-05 00:14:14 +0100183
Daniel Vetter2f324b42014-10-29 11:13:47 +0100184 /* adjusted_mode: for use by helpers and drivers */
185 struct drm_display_mode adjusted_mode;
186
Daniel Vetter144ecb92014-10-27 20:28:44 +0100187 struct drm_display_mode mode;
188
Daniel Stone99cf4a22015-05-25 19:11:51 +0100189 /* blob property to expose current mode to atomic userspace */
190 struct drm_property_blob *mode_blob;
191
Lionel Landwerlin5488dc12016-02-26 17:05:00 +0000192 /* blob property to expose color management to userspace */
193 struct drm_property_blob *degamma_lut;
194 struct drm_property_blob *ctm;
195 struct drm_property_blob *gamma_lut;
196
Daniel Vetter144ecb92014-10-27 20:28:44 +0100197 struct drm_pending_vblank_event *event;
198
199 struct drm_atomic_state *state;
200};
Dave Airlief453ba02008-11-07 14:05:41 -0800201
202/**
Daniel Vetter3bf04012014-10-27 16:54:27 +0100203 * struct drm_crtc_funcs - control CRTCs for a given device
Dave Airlief453ba02008-11-07 14:05:41 -0800204 *
205 * The drm_crtc_funcs structure is the central CRTC management structure
206 * in the DRM. Each CRTC controls one or more connectors (note that the name
207 * CRTC is simply historical, a CRTC may control LVDS, VGA, DVI, TV out, etc.
208 * connectors, not just CRTs).
209 *
210 * Each driver is responsible for filling out this structure at startup time,
211 * in addition to providing other modesetting features, like i2c and DDC
212 * bus accessors.
213 */
214struct drm_crtc_funcs {
Daniel Vetter88548632015-12-04 09:45:48 +0100215 /**
216 * @reset:
217 *
218 * Reset CRTC hardware and software state to off. This function isn't
219 * called by the core directly, only through drm_mode_config_reset().
220 * It's not a helper hook only for historical reasons.
221 *
222 * Atomic drivers can use drm_atomic_helper_crtc_reset() to reset
223 * atomic state using this hook.
224 */
Chris Wilsoneb033552011-01-24 15:11:08 +0000225 void (*reset)(struct drm_crtc *crtc);
Dave Airlief453ba02008-11-07 14:05:41 -0800226
Daniel Vetterf6da8c62015-12-04 09:46:00 +0100227 /**
228 * @cursor_set:
229 *
230 * Update the cursor image. The cursor position is relative to the CRTC
231 * and can be partially or fully outside of the visible area.
232 *
233 * Note that contrary to all other KMS functions the legacy cursor entry
234 * points don't take a framebuffer object, but instead take directly a
235 * raw buffer object id from the driver's buffer manager (which is
236 * either GEM or TTM for current drivers).
237 *
238 * This entry point is deprecated, drivers should instead implement
239 * universal plane support and register a proper cursor plane using
240 * drm_crtc_init_with_planes().
241 *
242 * This callback is optional
243 *
244 * RETURNS:
245 *
246 * 0 on success or a negative error code on failure.
247 */
Dave Airlief453ba02008-11-07 14:05:41 -0800248 int (*cursor_set)(struct drm_crtc *crtc, struct drm_file *file_priv,
249 uint32_t handle, uint32_t width, uint32_t height);
Daniel Vetterf6da8c62015-12-04 09:46:00 +0100250
251 /**
252 * @cursor_set2:
253 *
254 * Update the cursor image, including hotspot information. The hotspot
255 * must not affect the cursor position in CRTC coordinates, but is only
256 * meant as a hint for virtualized display hardware to coordinate the
257 * guests and hosts cursor position. The cursor hotspot is relative to
258 * the cursor image. Otherwise this works exactly like @cursor_set.
259 *
260 * This entry point is deprecated, drivers should instead implement
261 * universal plane support and register a proper cursor plane using
262 * drm_crtc_init_with_planes().
263 *
264 * This callback is optional.
265 *
266 * RETURNS:
267 *
268 * 0 on success or a negative error code on failure.
269 */
Dave Airlie4c813d42013-06-20 11:48:52 +1000270 int (*cursor_set2)(struct drm_crtc *crtc, struct drm_file *file_priv,
271 uint32_t handle, uint32_t width, uint32_t height,
272 int32_t hot_x, int32_t hot_y);
Daniel Vetterf6da8c62015-12-04 09:46:00 +0100273
274 /**
275 * @cursor_move:
276 *
277 * Update the cursor position. The cursor does not need to be visible
278 * when this hook is called.
279 *
280 * This entry point is deprecated, drivers should instead implement
281 * universal plane support and register a proper cursor plane using
282 * drm_crtc_init_with_planes().
283 *
284 * This callback is optional.
285 *
286 * RETURNS:
287 *
288 * 0 on success or a negative error code on failure.
289 */
Dave Airlief453ba02008-11-07 14:05:41 -0800290 int (*cursor_move)(struct drm_crtc *crtc, int x, int y);
291
Daniel Vetterf6da8c62015-12-04 09:46:00 +0100292 /**
293 * @gamma_set:
294 *
295 * Set gamma on the CRTC.
296 *
297 * This callback is optional.
298 *
299 * NOTE:
300 *
301 * Drivers that support gamma tables and also fbdev emulation through
302 * the provided helper library need to take care to fill out the gamma
303 * hooks for both. Currently there's a bit an unfortunate duplication
304 * going on, which should eventually be unified to just one set of
305 * hooks.
306 */
Maarten Lankhorst7ea77282016-06-07 12:49:30 +0200307 int (*gamma_set)(struct drm_crtc *crtc, u16 *r, u16 *g, u16 *b,
308 uint32_t size);
Daniel Vetter88548632015-12-04 09:45:48 +0100309
310 /**
311 * @destroy:
312 *
313 * Clean up plane resources. This is only called at driver unload time
314 * through drm_mode_config_cleanup() since a CRTC cannot be hotplugged
315 * in DRM.
316 */
Dave Airlief453ba02008-11-07 14:05:41 -0800317 void (*destroy)(struct drm_crtc *crtc);
318
Daniel Vetterf6da8c62015-12-04 09:46:00 +0100319 /**
320 * @set_config:
321 *
322 * This is the main legacy entry point to change the modeset state on a
323 * CRTC. All the details of the desired configuration are passed in a
324 * struct &drm_mode_set - see there for details.
325 *
326 * Drivers implementing atomic modeset should use
327 * drm_atomic_helper_set_config() to implement this hook.
328 *
329 * RETURNS:
330 *
331 * 0 on success or a negative error code on failure.
332 */
Dave Airlief453ba02008-11-07 14:05:41 -0800333 int (*set_config)(struct drm_mode_set *set);
Kristian Høgsbergd91d8a32009-11-17 12:43:55 -0500334
Daniel Vetterf6da8c62015-12-04 09:46:00 +0100335 /**
336 * @page_flip:
337 *
338 * Legacy entry point to schedule a flip to the given framebuffer.
339 *
340 * Page flipping is a synchronization mechanism that replaces the frame
341 * buffer being scanned out by the CRTC with a new frame buffer during
342 * vertical blanking, avoiding tearing (except when requested otherwise
343 * through the DRM_MODE_PAGE_FLIP_ASYNC flag). When an application
344 * requests a page flip the DRM core verifies that the new frame buffer
345 * is large enough to be scanned out by the CRTC in the currently
346 * configured mode and then calls the CRTC ->page_flip() operation with a
347 * pointer to the new frame buffer.
348 *
349 * The driver must wait for any pending rendering to the new framebuffer
350 * to complete before executing the flip. It should also wait for any
351 * pending rendering from other drivers if the underlying buffer is a
352 * shared dma-buf.
353 *
354 * An application can request to be notified when the page flip has
355 * completed. The drm core will supply a struct &drm_event in the event
356 * parameter in this case. This can be handled by the
357 * drm_crtc_send_vblank_event() function, which the driver should call on
358 * the provided event upon completion of the flip. Note that if
359 * the driver supports vblank signalling and timestamping the vblank
360 * counters and timestamps must agree with the ones returned from page
361 * flip events. With the current vblank helper infrastructure this can
362 * be achieved by holding a vblank reference while the page flip is
363 * pending, acquired through drm_crtc_vblank_get() and released with
364 * drm_crtc_vblank_put(). Drivers are free to implement their own vblank
365 * counter and timestamp tracking though, e.g. if they have accurate
366 * timestamp registers in hardware.
367 *
Daniel Vetterf6da8c62015-12-04 09:46:00 +0100368 * This callback is optional.
369 *
370 * NOTE:
371 *
372 * Very early versions of the KMS ABI mandated that the driver must
373 * block (but not reject) any rendering to the old framebuffer until the
374 * flip operation has completed and the old framebuffer is no longer
375 * visible. This requirement has been lifted, and userspace is instead
376 * expected to request delivery of an event and wait with recycling old
377 * buffers until such has been received.
378 *
379 * RETURNS:
380 *
381 * 0 on success or a negative error code on failure. Note that if a
382 * ->page_flip() operation is already pending the callback should return
383 * -EBUSY. Pageflips on a disabled CRTC (either by setting a NULL mode
384 * or just runtime disabled through DPMS respectively the new atomic
Daniel Vetter4cba6852015-12-08 09:49:20 +0100385 * "ACTIVE" state) should result in an -EINVAL error code. Note that
386 * drm_atomic_helper_page_flip() checks this already for atomic drivers.
Kristian Høgsbergd91d8a32009-11-17 12:43:55 -0500387 */
388 int (*page_flip)(struct drm_crtc *crtc,
389 struct drm_framebuffer *fb,
Keith Packarded8d1972013-07-22 18:49:58 -0700390 struct drm_pending_vblank_event *event,
391 uint32_t flags);
Paulo Zanonibffd9de02012-05-15 18:09:05 -0300392
Daniel Vetter88548632015-12-04 09:45:48 +0100393 /**
394 * @set_property:
395 *
396 * This is the legacy entry point to update a property attached to the
397 * CRTC.
398 *
399 * Drivers implementing atomic modeset should use
400 * drm_atomic_helper_crtc_set_property() to implement this hook.
401 *
402 * This callback is optional if the driver does not support any legacy
403 * driver-private properties.
404 *
405 * RETURNS:
406 *
407 * 0 on success or a negative error code on failure.
408 */
Paulo Zanonibffd9de02012-05-15 18:09:05 -0300409 int (*set_property)(struct drm_crtc *crtc,
410 struct drm_property *property, uint64_t val);
Daniel Vetter144ecb92014-10-27 20:28:44 +0100411
Daniel Vetter88548632015-12-04 09:45:48 +0100412 /**
413 * @atomic_duplicate_state:
414 *
415 * Duplicate the current atomic state for this CRTC and return it.
416 * The core and helpers gurantee that any atomic state duplicated with
417 * this hook and still owned by the caller (i.e. not transferred to the
418 * driver by calling ->atomic_commit() from struct
419 * &drm_mode_config_funcs) will be cleaned up by calling the
420 * @atomic_destroy_state hook in this structure.
421 *
422 * Atomic drivers which don't subclass struct &drm_crtc should use
423 * drm_atomic_helper_crtc_duplicate_state(). Drivers that subclass the
424 * state structure to extend it with driver-private state should use
425 * __drm_atomic_helper_crtc_duplicate_state() to make sure shared state is
426 * duplicated in a consistent fashion across drivers.
427 *
428 * It is an error to call this hook before crtc->state has been
429 * initialized correctly.
430 *
431 * NOTE:
432 *
433 * If the duplicate state references refcounted resources this hook must
434 * acquire a reference for each of them. The driver must release these
435 * references again in @atomic_destroy_state.
436 *
437 * RETURNS:
438 *
439 * Duplicated atomic state or NULL when the allocation failed.
440 */
Daniel Vetter144ecb92014-10-27 20:28:44 +0100441 struct drm_crtc_state *(*atomic_duplicate_state)(struct drm_crtc *crtc);
Daniel Vetter88548632015-12-04 09:45:48 +0100442
443 /**
444 * @atomic_destroy_state:
445 *
446 * Destroy a state duplicated with @atomic_duplicate_state and release
447 * or unreference all resources it references
448 */
Daniel Vetter144ecb92014-10-27 20:28:44 +0100449 void (*atomic_destroy_state)(struct drm_crtc *crtc,
Daniel Vettercc4ceb42014-07-25 21:30:38 +0200450 struct drm_crtc_state *state);
Daniel Vetter88548632015-12-04 09:45:48 +0100451
452 /**
453 * @atomic_set_property:
454 *
455 * Decode a driver-private property value and store the decoded value
456 * into the passed-in state structure. Since the atomic core decodes all
457 * standardized properties (even for extensions beyond the core set of
458 * properties which might not be implemented by all drivers) this
459 * requires drivers to subclass the state structure.
460 *
461 * Such driver-private properties should really only be implemented for
462 * truly hardware/vendor specific state. Instead it is preferred to
463 * standardize atomic extension and decode the properties used to expose
464 * such an extension in the core.
465 *
466 * Do not call this function directly, use
467 * drm_atomic_crtc_set_property() instead.
468 *
469 * This callback is optional if the driver does not support any
470 * driver-private atomic properties.
471 *
472 * NOTE:
473 *
474 * This function is called in the state assembly phase of atomic
475 * modesets, which can be aborted for any reason (including on
476 * userspace's request to just check whether a configuration would be
477 * possible). Drivers MUST NOT touch any persistent state (hardware or
478 * software) or data structures except the passed in @state parameter.
479 *
480 * Also since userspace controls in which order properties are set this
481 * function must not do any input validation (since the state update is
482 * incomplete and hence likely inconsistent). Instead any such input
483 * validation must be done in the various atomic_check callbacks.
484 *
485 * RETURNS:
486 *
487 * 0 if the property has been found, -EINVAL if the property isn't
488 * implemented by the driver (which should never happen, the core only
489 * asks for properties attached to this CRTC). No other validation is
490 * allowed by the driver. The core already checks that the property
491 * value is within the range (integer, valid enum value, ...) the driver
492 * set when registering the property.
493 */
Daniel Vetter144ecb92014-10-27 20:28:44 +0100494 int (*atomic_set_property)(struct drm_crtc *crtc,
495 struct drm_crtc_state *state,
496 struct drm_property *property,
497 uint64_t val);
Daniel Vetter88548632015-12-04 09:45:48 +0100498 /**
499 * @atomic_get_property:
500 *
501 * Reads out the decoded driver-private property. This is used to
Daniel Vetterc6b0ca32015-12-04 09:46:01 +0100502 * implement the GETCRTC IOCTL.
Daniel Vetter88548632015-12-04 09:45:48 +0100503 *
504 * Do not call this function directly, use
505 * drm_atomic_crtc_get_property() instead.
506 *
507 * This callback is optional if the driver does not support any
508 * driver-private atomic properties.
509 *
510 * RETURNS:
511 *
512 * 0 on success, -EINVAL if the property isn't implemented by the
513 * driver (which should never happen, the core only asks for
514 * properties attached to this CRTC).
515 */
Rob Clarkac9c9252014-12-18 16:01:47 -0500516 int (*atomic_get_property)(struct drm_crtc *crtc,
517 const struct drm_crtc_state *state,
518 struct drm_property *property,
519 uint64_t *val);
Benjamin Gaignard79190ea2016-06-21 16:37:09 +0200520
521 /**
522 * @late_register:
523 *
524 * This optional hook can be used to register additional userspace
525 * interfaces attached to the crtc like debugfs interfaces.
526 * It is called late in the driver load sequence from drm_dev_register().
527 * Everything added from this callback should be unregistered in
528 * the early_unregister callback.
529 *
530 * Returns:
531 *
532 * 0 on success, or a negative error code on failure.
533 */
534 int (*late_register)(struct drm_crtc *crtc);
535
536 /**
537 * @early_unregister:
538 *
539 * This optional hook should be used to unregister the additional
540 * userspace interfaces attached to the crtc from
541 * late_unregister(). It is called from drm_dev_unregister(),
542 * early in the driver unload sequence to disable userspace access
543 * before data structures are torndown.
544 */
545 void (*early_unregister)(struct drm_crtc *crtc);
Dave Airlief453ba02008-11-07 14:05:41 -0800546};
547
548/**
Daniel Vetter3bf04012014-10-27 16:54:27 +0100549 * struct drm_crtc - central CRTC control structure
Jesse Barnes77491632011-11-07 12:03:14 -0800550 * @dev: parent DRM device
Daniel Vetter2c0c33d2014-10-27 20:19:38 +0100551 * @port: OF node used by drm_of_find_possible_crtcs()
Jesse Barnes77491632011-11-07 12:03:14 -0800552 * @head: list management
Daniel Vetterac3ba4a2016-05-31 23:11:10 +0200553 * @name: human readable name, can be overwritten by the driver
Rob Clark51fd3712013-11-19 12:10:12 -0500554 * @mutex: per-CRTC locking
Jesse Barnes77491632011-11-07 12:03:14 -0800555 * @base: base KMS object for ID tracking etc.
Matt Ropere13161a2014-04-01 15:22:38 -0700556 * @primary: primary plane for this CRTC
557 * @cursor: cursor plane for this CRTC
Daniel Vetter2c0c33d2014-10-27 20:19:38 +0100558 * @cursor_x: current x position of the cursor, used for universal cursor planes
559 * @cursor_y: current y position of the cursor, used for universal cursor planes
Dave Airlief453ba02008-11-07 14:05:41 -0800560 * @enabled: is this CRTC enabled?
Jesse Barnes77491632011-11-07 12:03:14 -0800561 * @mode: current mode timings
562 * @hwmode: mode timings as programmed to hw regs
Dave Airlief453ba02008-11-07 14:05:41 -0800563 * @x: x position on screen
564 * @y: y position on screen
Dave Airlief453ba02008-11-07 14:05:41 -0800565 * @funcs: CRTC control functions
Jesse Barnes77491632011-11-07 12:03:14 -0800566 * @gamma_size: size of gamma ramp
567 * @gamma_store: gamma ramp values
Jesse Barnes77491632011-11-07 12:03:14 -0800568 * @helper_private: mid-layer private data
Paulo Zanonibffd9de02012-05-15 18:09:05 -0300569 * @properties: property tracking for this CRTC
Dave Airlief453ba02008-11-07 14:05:41 -0800570 *
571 * Each CRTC may have one or more connectors associated with it. This structure
572 * allows the CRTC to be controlled.
573 */
574struct drm_crtc {
575 struct drm_device *dev;
Russell King7e435aa2014-06-15 11:07:12 +0100576 struct device_node *port;
Dave Airlief453ba02008-11-07 14:05:41 -0800577 struct list_head head;
578
Ville Syrjäläfa3ab4c2015-12-08 18:41:53 +0200579 char *name;
580
Daniel Vetterac3ba4a2016-05-31 23:11:10 +0200581 /**
582 * @mutex:
Daniel Vetter29494c12012-12-02 02:18:25 +0100583 *
584 * This provides a read lock for the overall crtc state (mode, dpms
585 * state, ...) and a write lock for everything which can be update
Daniel Vetterac3ba4a2016-05-31 23:11:10 +0200586 * without a full modeset (fb, cursor data, crtc properties ...). Full
587 * modeset also need to grab dev->mode_config.connection_mutex.
Daniel Vetter29494c12012-12-02 02:18:25 +0100588 */
Rob Clark51fd3712013-11-19 12:10:12 -0500589 struct drm_modeset_lock mutex;
Daniel Vetter29494c12012-12-02 02:18:25 +0100590
Dave Airlief453ba02008-11-07 14:05:41 -0800591 struct drm_mode_object base;
592
Matt Ropere13161a2014-04-01 15:22:38 -0700593 /* primary and cursor planes for CRTC */
594 struct drm_plane *primary;
595 struct drm_plane *cursor;
596
Daniel Vetter96094082016-07-15 21:47:59 +0200597 /**
598 * @index: Position inside the mode_config.list, can be used as an array
599 * index. It is invariant over the lifetime of the CRTC.
600 */
Chris Wilson490d3d12016-05-27 20:05:00 +0100601 unsigned index;
602
Matt Roper161d0dc2014-06-10 08:28:10 -0700603 /* position of cursor plane on crtc */
604 int cursor_x;
605 int cursor_y;
606
Dave Airlief453ba02008-11-07 14:05:41 -0800607 bool enabled;
608
Mario Kleiner27641c32010-10-23 04:20:23 +0200609 /* Requested mode from modesetting. */
Dave Airlief453ba02008-11-07 14:05:41 -0800610 struct drm_display_mode mode;
611
Mario Kleiner27641c32010-10-23 04:20:23 +0200612 /* Programmed mode in hw, after adjustments for encoders,
613 * crtc, panel scaling etc. Needed for timestamping etc.
614 */
615 struct drm_display_mode hwmode;
616
Dave Airlief453ba02008-11-07 14:05:41 -0800617 int x, y;
Dave Airlief453ba02008-11-07 14:05:41 -0800618 const struct drm_crtc_funcs *funcs;
619
Lionel Landwerlin5488dc12016-02-26 17:05:00 +0000620 /* Legacy FB CRTC gamma size for reporting to userspace */
Dave Airlief453ba02008-11-07 14:05:41 -0800621 uint32_t gamma_size;
622 uint16_t *gamma_store;
623
624 /* if you are using the helper */
Daniel Vetter4490d4c2015-12-04 09:45:45 +0100625 const struct drm_crtc_helper_funcs *helper_private;
Paulo Zanonibffd9de02012-05-15 18:09:05 -0300626
627 struct drm_object_properties properties;
Daniel Vetterd059f652014-07-25 18:07:40 +0200628
Daniel Vetter3b24f7d2016-06-08 14:19:00 +0200629 /**
630 * @state:
631 *
632 * Current atomic state for this CRTC.
633 */
Daniel Vetter144ecb92014-10-27 20:28:44 +0100634 struct drm_crtc_state *state;
635
Daniel Vetter3b24f7d2016-06-08 14:19:00 +0200636 /**
637 * @commit_list:
638 *
639 * List of &drm_crtc_commit structures tracking pending commits.
640 * Protected by @commit_lock. This list doesn't hold its own full
641 * reference, but burrows it from the ongoing commit. Commit entries
642 * must be removed from this list once the commit is fully completed,
643 * but before it's correspoding &drm_atomic_state gets destroyed.
644 */
645 struct list_head commit_list;
646
647 /**
648 * @commit_lock:
649 *
650 * Spinlock to protect @commit_list.
651 */
652 spinlock_t commit_lock;
653
654 /**
655 * @acquire_ctx:
656 *
657 * Per-CRTC implicit acquire context used by atomic drivers for legacy
658 * IOCTLs, so that atomic drivers can get at the locking acquire
659 * context.
Daniel Vetterd059f652014-07-25 18:07:40 +0200660 */
661 struct drm_modeset_acquire_ctx *acquire_ctx;
Dave Airlief453ba02008-11-07 14:05:41 -0800662};
663
Daniel Vetter144ecb92014-10-27 20:28:44 +0100664/**
Daniel Vetter3bf04012014-10-27 16:54:27 +0100665 * struct drm_encoder_funcs - encoder controls
Jesse Barnes6c3db922011-11-07 12:03:16 -0800666 *
667 * Encoders sit between CRTCs and connectors.
668 */
Dave Airlief453ba02008-11-07 14:05:41 -0800669struct drm_encoder_funcs {
Daniel Vetter88548632015-12-04 09:45:48 +0100670 /**
671 * @reset:
672 *
673 * Reset encoder hardware and software state to off. This function isn't
674 * called by the core directly, only through drm_mode_config_reset().
675 * It's not a helper hook only for historical reasons.
676 */
Chris Wilsoneb033552011-01-24 15:11:08 +0000677 void (*reset)(struct drm_encoder *encoder);
Daniel Vetter88548632015-12-04 09:45:48 +0100678
679 /**
680 * @destroy:
681 *
682 * Clean up encoder resources. This is only called at driver unload time
683 * through drm_mode_config_cleanup() since an encoder cannot be
684 * hotplugged in DRM.
685 */
Dave Airlief453ba02008-11-07 14:05:41 -0800686 void (*destroy)(struct drm_encoder *encoder);
Benjamin Gaignard79190ea2016-06-21 16:37:09 +0200687
688 /**
689 * @late_register:
690 *
691 * This optional hook can be used to register additional userspace
692 * interfaces attached to the encoder like debugfs interfaces.
693 * It is called late in the driver load sequence from drm_dev_register().
694 * Everything added from this callback should be unregistered in
695 * the early_unregister callback.
696 *
697 * Returns:
698 *
699 * 0 on success, or a negative error code on failure.
700 */
701 int (*late_register)(struct drm_encoder *encoder);
702
703 /**
704 * @early_unregister:
705 *
706 * This optional hook should be used to unregister the additional
707 * userspace interfaces attached to the encoder from
708 * late_unregister(). It is called from drm_dev_unregister(),
709 * early in the driver unload sequence to disable userspace access
710 * before data structures are torndown.
711 */
712 void (*early_unregister)(struct drm_encoder *encoder);
Dave Airlief453ba02008-11-07 14:05:41 -0800713};
714
Dave Airlief453ba02008-11-07 14:05:41 -0800715/**
Daniel Vetter3bf04012014-10-27 16:54:27 +0100716 * struct drm_encoder - central DRM encoder structure
Jesse Barnesdb3e4492011-11-07 12:03:17 -0800717 * @dev: parent DRM device
718 * @head: list management
719 * @base: base KMS object
Daniel Vetterac3ba4a2016-05-31 23:11:10 +0200720 * @name: human readable name, can be overwritten by the driver
Daniel Vetter62cacc72016-08-12 22:48:37 +0200721 * @encoder_type: one of the DRM_MODE_ENCODER_<foo> types in drm_mode.h
Jesse Barnesdb3e4492011-11-07 12:03:17 -0800722 * @possible_crtcs: bitmask of potential CRTC bindings
723 * @possible_clones: bitmask of potential sibling encoders for cloning
724 * @crtc: currently bound CRTC
Sean Paul3b336ec2013-08-14 16:47:37 -0400725 * @bridge: bridge associated to the encoder
Jesse Barnesdb3e4492011-11-07 12:03:17 -0800726 * @funcs: control functions
727 * @helper_private: mid-layer private data
728 *
729 * CRTCs drive pixels to encoders, which convert them into signals
730 * appropriate for a given connector or set of connectors.
Dave Airlief453ba02008-11-07 14:05:41 -0800731 */
732struct drm_encoder {
733 struct drm_device *dev;
734 struct list_head head;
735
736 struct drm_mode_object base;
Jani Nikulae5748942014-05-14 16:58:20 +0300737 char *name;
Dave Airlief453ba02008-11-07 14:05:41 -0800738 int encoder_type;
Chris Wilson490d3d12016-05-27 20:05:00 +0100739
Daniel Vetter96094082016-07-15 21:47:59 +0200740 /**
741 * @index: Position inside the mode_config.list, can be used as an array
742 * index. It is invariant over the lifetime of the encoder.
743 */
Chris Wilson490d3d12016-05-27 20:05:00 +0100744 unsigned index;
745
Dave Airlief453ba02008-11-07 14:05:41 -0800746 uint32_t possible_crtcs;
747 uint32_t possible_clones;
748
749 struct drm_crtc *crtc;
Sean Paul3b336ec2013-08-14 16:47:37 -0400750 struct drm_bridge *bridge;
Dave Airlief453ba02008-11-07 14:05:41 -0800751 const struct drm_encoder_funcs *funcs;
Daniel Vetter4490d4c2015-12-04 09:45:45 +0100752 const struct drm_encoder_helper_funcs *helper_private;
Dave Airlief453ba02008-11-07 14:05:41 -0800753};
754
Dave Airlief453ba02008-11-07 14:05:41 -0800755/**
Daniel Vetter144ecb92014-10-27 20:28:44 +0100756 * struct drm_plane_state - mutable plane state
Daniel Vetter07cc0ef2014-11-27 15:49:39 +0100757 * @plane: backpointer to the plane
Daniel Vetter144ecb92014-10-27 20:28:44 +0100758 * @crtc: currently bound CRTC, NULL if disabled
Daniel Vettercc4ceb42014-07-25 21:30:38 +0200759 * @fb: currently bound framebuffer
Daniel Vettere2330f02014-10-29 11:34:56 +0100760 * @fence: optional fence to wait for before scanning out @fb
Daniel Vetter144ecb92014-10-27 20:28:44 +0100761 * @crtc_x: left position of visible portion of plane on crtc
762 * @crtc_y: upper position of visible portion of plane on crtc
763 * @crtc_w: width of visible portion of plane on crtc
764 * @crtc_h: height of visible portion of plane on crtc
765 * @src_x: left position of visible portion of plane within
766 * plane (in 16.16)
767 * @src_y: upper position of visible portion of plane within
768 * plane (in 16.16)
769 * @src_w: width of visible portion of plane (in 16.16)
770 * @src_h: height of visible portion of plane (in 16.16)
Daniel Vetterac3ba4a2016-05-31 23:11:10 +0200771 * @rotation: rotation of the plane
Marek Szyprowski44d1240d2016-06-13 11:11:26 +0200772 * @zpos: priority of the given plane on crtc (optional)
773 * @normalized_zpos: normalized value of zpos: unique, range from 0 to N-1
774 * where N is the number of active planes for given crtc
Ville Syrjäläd7da8242016-07-26 19:06:57 +0300775 * @src: clipped source coordinates of the plane (in 16.16)
776 * @dst: clipped destination coordinates of the plane
777 * @visible: visibility of the plane
Daniel Vetter144ecb92014-10-27 20:28:44 +0100778 * @state: backpointer to global drm_atomic_state
779 */
780struct drm_plane_state {
Daniel Vetter07cc0ef2014-11-27 15:49:39 +0100781 struct drm_plane *plane;
782
Rob Clark6ddd3882014-11-21 15:28:31 -0500783 struct drm_crtc *crtc; /* do not write directly, use drm_atomic_set_crtc_for_plane() */
784 struct drm_framebuffer *fb; /* do not write directly, use drm_atomic_set_fb_for_plane() */
Daniel Vettere2330f02014-10-29 11:34:56 +0100785 struct fence *fence;
Daniel Vetter144ecb92014-10-27 20:28:44 +0100786
787 /* Signed dest location allows it to be partially off screen */
788 int32_t crtc_x, crtc_y;
789 uint32_t crtc_w, crtc_h;
790
791 /* Source values are 16.16 fixed point */
792 uint32_t src_x, src_y;
793 uint32_t src_h, src_w;
794
Matt Roper1da30622015-01-21 16:35:40 -0800795 /* Plane rotation */
796 unsigned int rotation;
797
Marek Szyprowski44d1240d2016-06-13 11:11:26 +0200798 /* Plane zpos */
799 unsigned int zpos;
800 unsigned int normalized_zpos;
801
Ville Syrjäläd7da8242016-07-26 19:06:57 +0300802 /* Clipped coordinates */
803 struct drm_rect src, dst;
804
805 /*
806 * Is the plane actually visible? Can be false even
807 * if fb!=NULL and crtc!=NULL, due to clipping.
808 */
809 bool visible;
810
Daniel Vetter144ecb92014-10-27 20:28:44 +0100811 struct drm_atomic_state *state;
812};
813
814
815/**
Daniel Vetter3bf04012014-10-27 16:54:27 +0100816 * struct drm_plane_funcs - driver plane control functions
Jesse Barnes8cf5c912011-11-14 14:51:27 -0800817 */
818struct drm_plane_funcs {
Daniel Vetter88548632015-12-04 09:45:48 +0100819 /**
820 * @update_plane:
821 *
822 * This is the legacy entry point to enable and configure the plane for
823 * the given CRTC and framebuffer. It is never called to disable the
824 * plane, i.e. the passed-in crtc and fb paramters are never NULL.
825 *
826 * The source rectangle in frame buffer memory coordinates is given by
827 * the src_x, src_y, src_w and src_h parameters (as 16.16 fixed point
828 * values). Devices that don't support subpixel plane coordinates can
829 * ignore the fractional part.
830 *
831 * The destination rectangle in CRTC coordinates is given by the
832 * crtc_x, crtc_y, crtc_w and crtc_h parameters (as integer values).
833 * Devices scale the source rectangle to the destination rectangle. If
834 * scaling is not supported, and the source rectangle size doesn't match
835 * the destination rectangle size, the driver must return a
836 * -<errorname>EINVAL</errorname> error.
837 *
838 * Drivers implementing atomic modeset should use
839 * drm_atomic_helper_update_plane() to implement this hook.
840 *
841 * RETURNS:
842 *
843 * 0 on success or a negative error code on failure.
844 */
Jesse Barnes8cf5c912011-11-14 14:51:27 -0800845 int (*update_plane)(struct drm_plane *plane,
846 struct drm_crtc *crtc, struct drm_framebuffer *fb,
847 int crtc_x, int crtc_y,
848 unsigned int crtc_w, unsigned int crtc_h,
849 uint32_t src_x, uint32_t src_y,
850 uint32_t src_w, uint32_t src_h);
Daniel Vetter88548632015-12-04 09:45:48 +0100851
852 /**
853 * @disable_plane:
854 *
855 * This is the legacy entry point to disable the plane. The DRM core
Daniel Vetterc6b0ca32015-12-04 09:46:01 +0100856 * calls this method in response to a DRM_IOCTL_MODE_SETPLANE IOCTL call
Daniel Vetter88548632015-12-04 09:45:48 +0100857 * with the frame buffer ID set to 0. Disabled planes must not be
858 * processed by the CRTC.
859 *
860 * Drivers implementing atomic modeset should use
861 * drm_atomic_helper_disable_plane() to implement this hook.
862 *
863 * RETURNS:
864 *
865 * 0 on success or a negative error code on failure.
866 */
Jesse Barnes8cf5c912011-11-14 14:51:27 -0800867 int (*disable_plane)(struct drm_plane *plane);
Daniel Vetter88548632015-12-04 09:45:48 +0100868
869 /**
870 * @destroy:
871 *
872 * Clean up plane resources. This is only called at driver unload time
873 * through drm_mode_config_cleanup() since a plane cannot be hotplugged
874 * in DRM.
875 */
Jesse Barnes8cf5c912011-11-14 14:51:27 -0800876 void (*destroy)(struct drm_plane *plane);
Daniel Vetter88548632015-12-04 09:45:48 +0100877
878 /**
879 * @reset:
880 *
881 * Reset plane hardware and software state to off. This function isn't
882 * called by the core directly, only through drm_mode_config_reset().
883 * It's not a helper hook only for historical reasons.
884 *
885 * Atomic drivers can use drm_atomic_helper_plane_reset() to reset
886 * atomic state using this hook.
887 */
Daniel Vetter2a0d7cf2014-07-29 15:32:37 +0200888 void (*reset)(struct drm_plane *plane);
Rob Clark4d939142012-05-17 02:23:27 -0600889
Daniel Vetter88548632015-12-04 09:45:48 +0100890 /**
891 * @set_property:
892 *
893 * This is the legacy entry point to update a property attached to the
894 * plane.
895 *
896 * Drivers implementing atomic modeset should use
897 * drm_atomic_helper_plane_set_property() to implement this hook.
898 *
899 * This callback is optional if the driver does not support any legacy
900 * driver-private properties.
901 *
902 * RETURNS:
903 *
904 * 0 on success or a negative error code on failure.
905 */
Rob Clark4d939142012-05-17 02:23:27 -0600906 int (*set_property)(struct drm_plane *plane,
907 struct drm_property *property, uint64_t val);
Daniel Vetter144ecb92014-10-27 20:28:44 +0100908
Daniel Vetter88548632015-12-04 09:45:48 +0100909 /**
910 * @atomic_duplicate_state:
911 *
912 * Duplicate the current atomic state for this plane and return it.
913 * The core and helpers gurantee that any atomic state duplicated with
914 * this hook and still owned by the caller (i.e. not transferred to the
915 * driver by calling ->atomic_commit() from struct
916 * &drm_mode_config_funcs) will be cleaned up by calling the
917 * @atomic_destroy_state hook in this structure.
918 *
919 * Atomic drivers which don't subclass struct &drm_plane_state should use
920 * drm_atomic_helper_plane_duplicate_state(). Drivers that subclass the
921 * state structure to extend it with driver-private state should use
922 * __drm_atomic_helper_plane_duplicate_state() to make sure shared state is
923 * duplicated in a consistent fashion across drivers.
924 *
925 * It is an error to call this hook before plane->state has been
926 * initialized correctly.
927 *
928 * NOTE:
929 *
930 * If the duplicate state references refcounted resources this hook must
931 * acquire a reference for each of them. The driver must release these
932 * references again in @atomic_destroy_state.
933 *
934 * RETURNS:
935 *
936 * Duplicated atomic state or NULL when the allocation failed.
937 */
Daniel Vetter144ecb92014-10-27 20:28:44 +0100938 struct drm_plane_state *(*atomic_duplicate_state)(struct drm_plane *plane);
Daniel Vetter88548632015-12-04 09:45:48 +0100939
940 /**
941 * @atomic_destroy_state:
942 *
943 * Destroy a state duplicated with @atomic_duplicate_state and release
944 * or unreference all resources it references
945 */
Daniel Vetter144ecb92014-10-27 20:28:44 +0100946 void (*atomic_destroy_state)(struct drm_plane *plane,
Daniel Vettercc4ceb42014-07-25 21:30:38 +0200947 struct drm_plane_state *state);
Daniel Vetter88548632015-12-04 09:45:48 +0100948
949 /**
950 * @atomic_set_property:
951 *
952 * Decode a driver-private property value and store the decoded value
953 * into the passed-in state structure. Since the atomic core decodes all
954 * standardized properties (even for extensions beyond the core set of
955 * properties which might not be implemented by all drivers) this
956 * requires drivers to subclass the state structure.
957 *
958 * Such driver-private properties should really only be implemented for
959 * truly hardware/vendor specific state. Instead it is preferred to
960 * standardize atomic extension and decode the properties used to expose
961 * such an extension in the core.
962 *
963 * Do not call this function directly, use
964 * drm_atomic_plane_set_property() instead.
965 *
966 * This callback is optional if the driver does not support any
967 * driver-private atomic properties.
968 *
969 * NOTE:
970 *
971 * This function is called in the state assembly phase of atomic
972 * modesets, which can be aborted for any reason (including on
973 * userspace's request to just check whether a configuration would be
974 * possible). Drivers MUST NOT touch any persistent state (hardware or
975 * software) or data structures except the passed in @state parameter.
976 *
977 * Also since userspace controls in which order properties are set this
978 * function must not do any input validation (since the state update is
979 * incomplete and hence likely inconsistent). Instead any such input
980 * validation must be done in the various atomic_check callbacks.
981 *
982 * RETURNS:
983 *
984 * 0 if the property has been found, -EINVAL if the property isn't
985 * implemented by the driver (which shouldn't ever happen, the core only
986 * asks for properties attached to this plane). No other validation is
987 * allowed by the driver. The core already checks that the property
988 * value is within the range (integer, valid enum value, ...) the driver
989 * set when registering the property.
990 */
Daniel Vetter144ecb92014-10-27 20:28:44 +0100991 int (*atomic_set_property)(struct drm_plane *plane,
992 struct drm_plane_state *state,
993 struct drm_property *property,
994 uint64_t val);
Daniel Vetter88548632015-12-04 09:45:48 +0100995
996 /**
997 * @atomic_get_property:
998 *
999 * Reads out the decoded driver-private property. This is used to
Daniel Vetterc6b0ca32015-12-04 09:46:01 +01001000 * implement the GETPLANE IOCTL.
Daniel Vetter88548632015-12-04 09:45:48 +01001001 *
1002 * Do not call this function directly, use
1003 * drm_atomic_plane_get_property() instead.
1004 *
1005 * This callback is optional if the driver does not support any
1006 * driver-private atomic properties.
1007 *
1008 * RETURNS:
1009 *
1010 * 0 on success, -EINVAL if the property isn't implemented by the
1011 * driver (which should never happen, the core only asks for
1012 * properties attached to this plane).
1013 */
Rob Clarkac9c9252014-12-18 16:01:47 -05001014 int (*atomic_get_property)(struct drm_plane *plane,
1015 const struct drm_plane_state *state,
1016 struct drm_property *property,
1017 uint64_t *val);
Benjamin Gaignard79190ea2016-06-21 16:37:09 +02001018 /**
1019 * @late_register:
1020 *
1021 * This optional hook can be used to register additional userspace
1022 * interfaces attached to the plane like debugfs interfaces.
1023 * It is called late in the driver load sequence from drm_dev_register().
1024 * Everything added from this callback should be unregistered in
1025 * the early_unregister callback.
1026 *
1027 * Returns:
1028 *
1029 * 0 on success, or a negative error code on failure.
1030 */
1031 int (*late_register)(struct drm_plane *plane);
1032
1033 /**
1034 * @early_unregister:
1035 *
1036 * This optional hook should be used to unregister the additional
1037 * userspace interfaces attached to the plane from
1038 * late_unregister(). It is called from drm_dev_unregister(),
1039 * early in the driver unload sequence to disable userspace access
1040 * before data structures are torndown.
1041 */
1042 void (*early_unregister)(struct drm_plane *plane);
Jesse Barnes8cf5c912011-11-14 14:51:27 -08001043};
1044
Matt Ropere27dde32014-04-01 15:22:30 -07001045enum drm_plane_type {
1046 DRM_PLANE_TYPE_OVERLAY,
1047 DRM_PLANE_TYPE_PRIMARY,
1048 DRM_PLANE_TYPE_CURSOR,
1049};
1050
Daniel Vetter88548632015-12-04 09:45:48 +01001051
Jesse Barnes8cf5c912011-11-14 14:51:27 -08001052/**
Daniel Vetter3bf04012014-10-27 16:54:27 +01001053 * struct drm_plane - central DRM plane control structure
Jesse Barnes8cf5c912011-11-14 14:51:27 -08001054 * @dev: DRM device this plane belongs to
1055 * @head: for list management
Daniel Vetterac3ba4a2016-05-31 23:11:10 +02001056 * @name: human readable name, can be overwritten by the driver
Jesse Barnes8cf5c912011-11-14 14:51:27 -08001057 * @base: base mode object
1058 * @possible_crtcs: pipes this plane can be bound to
1059 * @format_types: array of formats supported by this plane
1060 * @format_count: number of formats supported
Laurent Pinchart7eb5f302015-03-09 10:41:07 +02001061 * @format_default: driver hasn't supplied supported formats for the plane
Jesse Barnes8cf5c912011-11-14 14:51:27 -08001062 * @crtc: currently bound CRTC
1063 * @fb: currently bound fb
Daniel Vetter2c0c33d2014-10-27 20:19:38 +01001064 * @old_fb: Temporary tracking of the old fb while a modeset is ongoing. Used by
1065 * drm_mode_set_config_internal() to implement correct refcounting.
Jesse Barnes8cf5c912011-11-14 14:51:27 -08001066 * @funcs: helper functions
Rob Clark4d939142012-05-17 02:23:27 -06001067 * @properties: property tracking for this plane
Matt Ropere27dde32014-04-01 15:22:30 -07001068 * @type: type of plane (overlay, primary, cursor)
Daniel Vetter144ecb92014-10-27 20:28:44 +01001069 * @state: current atomic state for this plane
Marek Szyprowski44d1240d2016-06-13 11:11:26 +02001070 * @zpos_property: zpos property for this plane
Daniel Vetterac3ba4a2016-05-31 23:11:10 +02001071 * @helper_private: mid-layer private data
Jesse Barnes8cf5c912011-11-14 14:51:27 -08001072 */
1073struct drm_plane {
1074 struct drm_device *dev;
1075 struct list_head head;
1076
Ville Syrjälä9f4c97a2015-12-08 18:41:54 +02001077 char *name;
1078
Daniel Vetterac3ba4a2016-05-31 23:11:10 +02001079 /**
1080 * @mutex:
1081 *
1082 * Protects modeset plane state, together with the mutex of &drm_crtc
1083 * this plane is linked to (when active, getting actived or getting
1084 * disabled).
1085 */
Daniel Vetter4d02e2d2014-11-11 10:12:00 +01001086 struct drm_modeset_lock mutex;
1087
Jesse Barnes8cf5c912011-11-14 14:51:27 -08001088 struct drm_mode_object base;
1089
1090 uint32_t possible_crtcs;
1091 uint32_t *format_types;
Thierry Reding45e37432015-08-12 16:54:28 +02001092 unsigned int format_count;
Laurent Pinchart7eb5f302015-03-09 10:41:07 +02001093 bool format_default;
Jesse Barnes8cf5c912011-11-14 14:51:27 -08001094
1095 struct drm_crtc *crtc;
1096 struct drm_framebuffer *fb;
1097
Daniel Vetter3d30a592014-07-27 13:42:42 +02001098 struct drm_framebuffer *old_fb;
1099
Jesse Barnes8cf5c912011-11-14 14:51:27 -08001100 const struct drm_plane_funcs *funcs;
Rob Clark4d939142012-05-17 02:23:27 -06001101
1102 struct drm_object_properties properties;
Matt Ropere27dde32014-04-01 15:22:30 -07001103
1104 enum drm_plane_type type;
Daniel Vetter144ecb92014-10-27 20:28:44 +01001105
Daniel Vetter96094082016-07-15 21:47:59 +02001106 /**
1107 * @index: Position inside the mode_config.list, can be used as an array
1108 * index. It is invariant over the lifetime of the plane.
1109 */
Chris Wilson490d3d12016-05-27 20:05:00 +01001110 unsigned index;
1111
Daniel Vetter4490d4c2015-12-04 09:45:45 +01001112 const struct drm_plane_helper_funcs *helper_private;
Daniel Vetterc2fcd272014-11-05 00:14:14 +01001113
Daniel Vetter144ecb92014-10-27 20:28:44 +01001114 struct drm_plane_state *state;
Marek Szyprowski44d1240d2016-06-13 11:11:26 +02001115
1116 struct drm_property *zpos_property;
Jesse Barnes8cf5c912011-11-14 14:51:27 -08001117};
1118
1119/**
Daniel Vetter3bf04012014-10-27 16:54:27 +01001120 * struct drm_bridge_funcs - drm_bridge control functions
Ajay Kumar3d3f8b12015-01-20 22:08:44 +05301121 * @attach: Called during drm_bridge_attach
Sean Paul3b336ec2013-08-14 16:47:37 -04001122 */
1123struct drm_bridge_funcs {
Ajay Kumar3d3f8b12015-01-20 22:08:44 +05301124 int (*attach)(struct drm_bridge *bridge);
Daniel Vetterda024fe2015-12-04 09:45:47 +01001125
1126 /**
1127 * @mode_fixup:
1128 *
1129 * This callback is used to validate and adjust a mode. The paramater
1130 * mode is the display mode that should be fed to the next element in
1131 * the display chain, either the final &drm_connector or the next
1132 * &drm_bridge. The parameter adjusted_mode is the input mode the bridge
1133 * requires. It can be modified by this callback and does not need to
1134 * match mode.
1135 *
1136 * This is the only hook that allows a bridge to reject a modeset. If
1137 * this function passes all other callbacks must succeed for this
1138 * configuration.
1139 *
1140 * NOTE:
1141 *
1142 * This function is called in the check phase of atomic modesets, which
1143 * can be aborted for any reason (including on userspace's request to
1144 * just check whether a configuration would be possible). Drivers MUST
1145 * NOT touch any persistent state (hardware or software) or data
Daniel Vetter88548632015-12-04 09:45:48 +01001146 * structures except the passed in @state parameter.
Daniel Vetterda024fe2015-12-04 09:45:47 +01001147 *
1148 * RETURNS:
1149 *
1150 * True if an acceptable configuration is possible, false if the modeset
1151 * operation should be rejected.
1152 */
Sean Paul3b336ec2013-08-14 16:47:37 -04001153 bool (*mode_fixup)(struct drm_bridge *bridge,
1154 const struct drm_display_mode *mode,
1155 struct drm_display_mode *adjusted_mode);
Daniel Vetterda024fe2015-12-04 09:45:47 +01001156 /**
1157 * @disable:
1158 *
1159 * This callback should disable the bridge. It is called right before
1160 * the preceding element in the display pipe is disabled. If the
1161 * preceding element is a bridge this means it's called before that
1162 * bridge's ->disable() function. If the preceding element is a
1163 * &drm_encoder it's called right before the encoder's ->disable(),
1164 * ->prepare() or ->dpms() hook from struct &drm_encoder_helper_funcs.
1165 *
1166 * The bridge can assume that the display pipe (i.e. clocks and timing
1167 * signals) feeding it is still running when this callback is called.
Laurent Pinchartc8a3b2a2016-02-26 11:51:06 +02001168 *
1169 * The disable callback is optional.
Daniel Vetterda024fe2015-12-04 09:45:47 +01001170 */
Sean Paul3b336ec2013-08-14 16:47:37 -04001171 void (*disable)(struct drm_bridge *bridge);
Daniel Vetterda024fe2015-12-04 09:45:47 +01001172
1173 /**
1174 * @post_disable:
1175 *
1176 * This callback should disable the bridge. It is called right after
1177 * the preceding element in the display pipe is disabled. If the
1178 * preceding element is a bridge this means it's called after that
1179 * bridge's ->post_disable() function. If the preceding element is a
1180 * &drm_encoder it's called right after the encoder's ->disable(),
1181 * ->prepare() or ->dpms() hook from struct &drm_encoder_helper_funcs.
1182 *
1183 * The bridge must assume that the display pipe (i.e. clocks and timing
1184 * singals) feeding it is no longer running when this callback is
1185 * called.
Laurent Pinchartc8a3b2a2016-02-26 11:51:06 +02001186 *
1187 * The post_disable callback is optional.
Daniel Vetterda024fe2015-12-04 09:45:47 +01001188 */
Sean Paul3b336ec2013-08-14 16:47:37 -04001189 void (*post_disable)(struct drm_bridge *bridge);
Daniel Vetterda024fe2015-12-04 09:45:47 +01001190
1191 /**
1192 * @mode_set:
1193 *
1194 * This callback should set the given mode on the bridge. It is called
1195 * after the ->mode_set() callback for the preceding element in the
1196 * display pipeline has been called already. The display pipe (i.e.
1197 * clocks and timing signals) is off when this function is called.
1198 */
Sean Paul3b336ec2013-08-14 16:47:37 -04001199 void (*mode_set)(struct drm_bridge *bridge,
1200 struct drm_display_mode *mode,
1201 struct drm_display_mode *adjusted_mode);
Daniel Vetterda024fe2015-12-04 09:45:47 +01001202 /**
1203 * @pre_enable:
1204 *
1205 * This callback should enable the bridge. It is called right before
1206 * the preceding element in the display pipe is enabled. If the
1207 * preceding element is a bridge this means it's called before that
1208 * bridge's ->pre_enable() function. If the preceding element is a
1209 * &drm_encoder it's called right before the encoder's ->enable(),
1210 * ->commit() or ->dpms() hook from struct &drm_encoder_helper_funcs.
1211 *
1212 * The display pipe (i.e. clocks and timing signals) feeding this bridge
1213 * will not yet be running when this callback is called. The bridge must
1214 * not enable the display link feeding the next bridge in the chain (if
1215 * there is one) when this callback is called.
Laurent Pinchartc8a3b2a2016-02-26 11:51:06 +02001216 *
1217 * The pre_enable callback is optional.
Daniel Vetterda024fe2015-12-04 09:45:47 +01001218 */
Sean Paul3b336ec2013-08-14 16:47:37 -04001219 void (*pre_enable)(struct drm_bridge *bridge);
Daniel Vetterda024fe2015-12-04 09:45:47 +01001220
1221 /**
1222 * @enable:
1223 *
1224 * This callback should enable the bridge. It is called right after
1225 * the preceding element in the display pipe is enabled. If the
1226 * preceding element is a bridge this means it's called after that
1227 * bridge's ->enable() function. If the preceding element is a
1228 * &drm_encoder it's called right after the encoder's ->enable(),
1229 * ->commit() or ->dpms() hook from struct &drm_encoder_helper_funcs.
1230 *
1231 * The bridge can assume that the display pipe (i.e. clocks and timing
1232 * signals) feeding it is running when this callback is called. This
1233 * callback must enable the display link feeding the next bridge in the
1234 * chain if there is one.
Laurent Pinchartc8a3b2a2016-02-26 11:51:06 +02001235 *
1236 * The enable callback is optional.
Daniel Vetterda024fe2015-12-04 09:45:47 +01001237 */
Sean Paul3b336ec2013-08-14 16:47:37 -04001238 void (*enable)(struct drm_bridge *bridge);
Sean Paul3b336ec2013-08-14 16:47:37 -04001239};
1240
1241/**
Daniel Vetter3bf04012014-10-27 16:54:27 +01001242 * struct drm_bridge - central DRM bridge control structure
Sean Paul3b336ec2013-08-14 16:47:37 -04001243 * @dev: DRM device this bridge belongs to
Archit Taneja862e6862015-05-21 11:03:16 +05301244 * @encoder: encoder to which this bridge is connected
1245 * @next: the next bridge in the encoder chain
Ajay Kumar3d3f8b12015-01-20 22:08:44 +05301246 * @of_node: device node pointer to the bridge
1247 * @list: to keep track of all added bridges
Sean Paul3b336ec2013-08-14 16:47:37 -04001248 * @funcs: control functions
1249 * @driver_private: pointer to the bridge driver's internal context
1250 */
1251struct drm_bridge {
1252 struct drm_device *dev;
Ajay Kumar3d3f8b12015-01-20 22:08:44 +05301253 struct drm_encoder *encoder;
Archit Taneja862e6862015-05-21 11:03:16 +05301254 struct drm_bridge *next;
Ajay Kumar3d3f8b12015-01-20 22:08:44 +05301255#ifdef CONFIG_OF
1256 struct device_node *of_node;
1257#endif
1258 struct list_head list;
Sean Paul3b336ec2013-08-14 16:47:37 -04001259
1260 const struct drm_bridge_funcs *funcs;
1261 void *driver_private;
1262};
1263
Daniel Vetter3b24f7d2016-06-08 14:19:00 +02001264/**
1265 * struct drm_crtc_commit - track modeset commits on a CRTC
1266 *
1267 * This structure is used to track pending modeset changes and atomic commit on
1268 * a per-CRTC basis. Since updating the list should never block this structure
1269 * is reference counted to allow waiters to safely wait on an event to complete,
1270 * without holding any locks.
1271 *
1272 * It has 3 different events in total to allow a fine-grained synchronization
1273 * between outstanding updates::
1274 *
1275 * atomic commit thread hardware
1276 *
1277 * write new state into hardware ----> ...
1278 * signal hw_done
1279 * switch to new state on next
1280 * ... v/hblank
1281 *
1282 * wait for buffers to show up ...
1283 *
1284 * ... send completion irq
1285 * irq handler signals flip_done
1286 * cleanup old buffers
1287 *
1288 * signal cleanup_done
1289 *
1290 * wait for flip_done <----
1291 * clean up atomic state
1292 *
1293 * The important bit to know is that cleanup_done is the terminal event, but the
1294 * ordering between flip_done and hw_done is entirely up to the specific driver
1295 * and modeset state change.
1296 *
1297 * For an implementation of how to use this look at
1298 * drm_atomic_helper_setup_commit() from the atomic helper library.
1299 */
1300struct drm_crtc_commit {
1301 /**
1302 * @crtc:
1303 *
1304 * DRM CRTC for this commit.
1305 */
1306 struct drm_crtc *crtc;
1307
1308 /**
1309 * @ref:
1310 *
1311 * Reference count for this structure. Needed to allow blocking on
1312 * completions without the risk of the completion disappearing
1313 * meanwhile.
1314 */
1315 struct kref ref;
1316
1317 /**
1318 * @flip_done:
1319 *
1320 * Will be signaled when the hardware has flipped to the new set of
1321 * buffers. Signals at the same time as when the drm event for this
1322 * commit is sent to userspace, or when an out-fence is singalled. Note
1323 * that for most hardware, in most cases this happens after @hw_done is
1324 * signalled.
1325 */
1326 struct completion flip_done;
1327
1328 /**
1329 * @hw_done:
1330 *
1331 * Will be signalled when all hw register changes for this commit have
1332 * been written out. Especially when disabling a pipe this can be much
1333 * later than than @flip_done, since that can signal already when the
1334 * screen goes black, whereas to fully shut down a pipe more register
1335 * I/O is required.
1336 *
1337 * Note that this does not need to include separately reference-counted
1338 * resources like backing storage buffer pinning, or runtime pm
1339 * management.
1340 */
1341 struct completion hw_done;
1342
1343 /**
1344 * @cleanup_done:
1345 *
1346 * Will be signalled after old buffers have been cleaned up by calling
1347 * drm_atomic_helper_cleanup_planes(). Since this can only happen after
1348 * a vblank wait completed it might be a bit later. This completion is
1349 * useful to throttle updates and avoid hardware updates getting ahead
1350 * of the buffer cleanup too much.
1351 */
1352 struct completion cleanup_done;
1353
1354 /**
1355 * @commit_entry:
1356 *
1357 * Entry on the per-CRTC commit_list. Protected by crtc->commit_lock.
1358 */
1359 struct list_head commit_entry;
1360
1361 /**
1362 * @event:
1363 *
1364 * &drm_pending_vblank_event pointer to clean up private events.
1365 */
1366 struct drm_pending_vblank_event *event;
1367};
1368
Daniel Vetterb8b53422016-06-02 00:06:33 +02001369struct __drm_planes_state {
1370 struct drm_plane *ptr;
1371 struct drm_plane_state *state;
1372};
1373
Daniel Vetter5d943aa62016-06-02 00:06:34 +02001374struct __drm_crtcs_state {
1375 struct drm_crtc *ptr;
1376 struct drm_crtc_state *state;
Daniel Vetter3b24f7d2016-06-08 14:19:00 +02001377 struct drm_crtc_commit *commit;
Daniel Vetter5d943aa62016-06-02 00:06:34 +02001378};
1379
Daniel Vetter63e83c12016-06-02 00:06:32 +02001380struct __drm_connnectors_state {
1381 struct drm_connector *ptr;
1382 struct drm_connector_state *state;
1383};
1384
Sean Paul3b336ec2013-08-14 16:47:37 -04001385/**
Rob Clark08855fa2015-03-11 10:23:09 -04001386 * struct drm_atomic_state - the global state object for atomic updates
Daniel Vettercc4ceb42014-07-25 21:30:38 +02001387 * @dev: parent DRM device
Rob Clarkd34f20d2014-12-18 16:01:56 -05001388 * @allow_modeset: allow full modeset
Daniel Vetterc6b0ca32015-12-04 09:46:01 +01001389 * @legacy_cursor_update: hint to enforce legacy cursor IOCTL semantics
Maarten Lankhorst40616a22016-03-03 10:17:39 +01001390 * @legacy_set_config: Disable conflicting encoders instead of failing with -EINVAL.
Daniel Vetterb8b53422016-06-02 00:06:33 +02001391 * @planes: pointer to array of structures with per-plane data
Daniel Vettercc4ceb42014-07-25 21:30:38 +02001392 * @crtcs: pointer to array of CRTC pointers
Daniel Vetterf52b69f12014-11-19 18:38:08 +01001393 * @num_connector: size of the @connectors and @connector_states arrays
Daniel Vetter63e83c12016-06-02 00:06:32 +02001394 * @connectors: pointer to array of structures with per-connector data
Daniel Vettercc4ceb42014-07-25 21:30:38 +02001395 * @acquire_ctx: acquire context for this atomic modeset state update
1396 */
1397struct drm_atomic_state {
1398 struct drm_device *dev;
Rob Clarkd34f20d2014-12-18 16:01:56 -05001399 bool allow_modeset : 1;
Daniel Vetterf02ad902015-01-22 16:36:23 +01001400 bool legacy_cursor_update : 1;
Maarten Lankhorst40616a22016-03-03 10:17:39 +01001401 bool legacy_set_config : 1;
Daniel Vetterb8b53422016-06-02 00:06:33 +02001402 struct __drm_planes_state *planes;
Daniel Vetter5d943aa62016-06-02 00:06:34 +02001403 struct __drm_crtcs_state *crtcs;
Daniel Vetterf52b69f12014-11-19 18:38:08 +01001404 int num_connector;
Daniel Vetter63e83c12016-06-02 00:06:32 +02001405 struct __drm_connnectors_state *connectors;
Daniel Vettercc4ceb42014-07-25 21:30:38 +02001406
1407 struct drm_modeset_acquire_ctx *acquire_ctx;
Daniel Vetter3b24f7d2016-06-08 14:19:00 +02001408
1409 /**
1410 * @commit_work:
1411 *
1412 * Work item which can be used by the driver or helpers to execute the
1413 * commit without blocking.
1414 */
1415 struct work_struct commit_work;
Daniel Vettercc4ceb42014-07-25 21:30:38 +02001416};
1417
1418
1419/**
Daniel Vetter3bf04012014-10-27 16:54:27 +01001420 * struct drm_mode_set - new values for a CRTC config change
Jesse Barnesef273512011-11-07 12:03:19 -08001421 * @fb: framebuffer to use for new config
1422 * @crtc: CRTC whose configuration we're about to change
1423 * @mode: mode timings to use
1424 * @x: position of this CRTC relative to @fb
1425 * @y: position of this CRTC relative to @fb
1426 * @connectors: array of connectors to drive with this CRTC if possible
1427 * @num_connectors: size of @connectors array
Dave Airlief453ba02008-11-07 14:05:41 -08001428 *
1429 * Represents a single crtc the connectors that it drives with what mode
1430 * and from which framebuffer it scans out from.
1431 *
1432 * This is used to set modes.
1433 */
1434struct drm_mode_set {
Dave Airlief453ba02008-11-07 14:05:41 -08001435 struct drm_framebuffer *fb;
1436 struct drm_crtc *crtc;
1437 struct drm_display_mode *mode;
1438
1439 uint32_t x;
1440 uint32_t y;
1441
1442 struct drm_connector **connectors;
1443 size_t num_connectors;
1444};
1445
1446/**
Jesse Barnes550cebc2011-11-07 12:03:20 -08001447 * struct drm_mode_config_funcs - basic driver provided mode setting functions
Jesse Barnes550cebc2011-11-07 12:03:20 -08001448 *
1449 * Some global (i.e. not per-CRTC, connector, etc) mode setting functions that
1450 * involve drivers.
Dave Airlief453ba02008-11-07 14:05:41 -08001451 */
1452struct drm_mode_config_funcs {
Daniel Vetter9953f412015-12-04 09:46:02 +01001453 /**
1454 * @fb_create:
1455 *
1456 * Create a new framebuffer object. The core does basic checks on the
1457 * requested metadata, but most of that is left to the driver. See
1458 * struct &drm_mode_fb_cmd2 for details.
1459 *
Daniel Vetterd55f5322015-12-08 09:49:19 +01001460 * If the parameters are deemed valid and the backing storage objects in
1461 * the underlying memory manager all exist, then the driver allocates
1462 * a new &drm_framebuffer structure, subclassed to contain
1463 * driver-specific information (like the internal native buffer object
1464 * references). It also needs to fill out all relevant metadata, which
1465 * should be done by calling drm_helper_mode_fill_fb_struct().
1466 *
1467 * The initialization is finalized by calling drm_framebuffer_init(),
1468 * which registers the framebuffer and makes it accessible to other
1469 * threads.
1470 *
Daniel Vetter9953f412015-12-04 09:46:02 +01001471 * RETURNS:
1472 *
1473 * A new framebuffer with an initial reference count of 1 or a negative
1474 * error code encoded with ERR_PTR().
1475 */
Jesse Barnes550cebc2011-11-07 12:03:20 -08001476 struct drm_framebuffer *(*fb_create)(struct drm_device *dev,
1477 struct drm_file *file_priv,
Ville Syrjälä1eb83452015-11-11 19:11:29 +02001478 const struct drm_mode_fb_cmd2 *mode_cmd);
Daniel Vetter9953f412015-12-04 09:46:02 +01001479
1480 /**
1481 * @output_poll_changed:
1482 *
1483 * Callback used by helpers to inform the driver of output configuration
1484 * changes.
1485 *
1486 * Drivers implementing fbdev emulation with the helpers can call
1487 * drm_fb_helper_hotplug_changed from this hook to inform the fbdev
1488 * helper of output changes.
1489 *
1490 * FIXME:
1491 *
1492 * Except that there's no vtable for device-level helper callbacks
1493 * there's no reason this is a core function.
1494 */
Dave Airlieeb1f8e42010-05-07 06:42:51 +00001495 void (*output_poll_changed)(struct drm_device *dev);
Daniel Vettercc4ceb42014-07-25 21:30:38 +02001496
Daniel Vetter9953f412015-12-04 09:46:02 +01001497 /**
1498 * @atomic_check:
1499 *
1500 * This is the only hook to validate an atomic modeset update. This
1501 * function must reject any modeset and state changes which the hardware
1502 * or driver doesn't support. This includes but is of course not limited
1503 * to:
1504 *
1505 * - Checking that the modes, framebuffers, scaling and placement
1506 * requirements and so on are within the limits of the hardware.
1507 *
1508 * - Checking that any hidden shared resources are not oversubscribed.
1509 * This can be shared PLLs, shared lanes, overall memory bandwidth,
1510 * display fifo space (where shared between planes or maybe even
1511 * CRTCs).
1512 *
1513 * - Checking that virtualized resources exported to userspace are not
1514 * oversubscribed. For various reasons it can make sense to expose
1515 * more planes, crtcs or encoders than which are physically there. One
1516 * example is dual-pipe operations (which generally should be hidden
1517 * from userspace if when lockstepped in hardware, exposed otherwise),
1518 * where a plane might need 1 hardware plane (if it's just on one
1519 * pipe), 2 hardware planes (when it spans both pipes) or maybe even
1520 * shared a hardware plane with a 2nd plane (if there's a compatible
1521 * plane requested on the area handled by the other pipe).
1522 *
1523 * - Check that any transitional state is possible and that if
1524 * requested, the update can indeed be done in the vblank period
1525 * without temporarily disabling some functions.
1526 *
1527 * - Check any other constraints the driver or hardware might have.
1528 *
1529 * - This callback also needs to correctly fill out the &drm_crtc_state
1530 * in this update to make sure that drm_atomic_crtc_needs_modeset()
1531 * reflects the nature of the possible update and returns true if and
1532 * only if the update cannot be applied without tearing within one
1533 * vblank on that CRTC. The core uses that information to reject
1534 * updates which require a full modeset (i.e. blanking the screen, or
1535 * at least pausing updates for a substantial amount of time) if
1536 * userspace has disallowed that in its request.
1537 *
1538 * - The driver also does not need to repeat basic input validation
1539 * like done for the corresponding legacy entry points. The core does
1540 * that before calling this hook.
1541 *
1542 * See the documentation of @atomic_commit for an exhaustive list of
1543 * error conditions which don't have to be checked at the
1544 * ->atomic_check() stage?
1545 *
1546 * See the documentation for struct &drm_atomic_state for how exactly
1547 * an atomic modeset update is described.
1548 *
1549 * Drivers using the atomic helpers can implement this hook using
1550 * drm_atomic_helper_check(), or one of the exported sub-functions of
1551 * it.
1552 *
1553 * RETURNS:
1554 *
1555 * 0 on success or one of the below negative error codes:
1556 *
1557 * - -EINVAL, if any of the above constraints are violated.
1558 *
1559 * - -EDEADLK, when returned from an attempt to acquire an additional
1560 * &drm_modeset_lock through drm_modeset_lock().
1561 *
1562 * - -ENOMEM, if allocating additional state sub-structures failed due
1563 * to lack of memory.
1564 *
1565 * - -EINTR, -EAGAIN or -ERESTARTSYS, if the IOCTL should be restarted.
1566 * This can either be due to a pending signal, or because the driver
1567 * needs to completely bail out to recover from an exceptional
1568 * situation like a GPU hang. From a userspace point all errors are
1569 * treated equally.
1570 */
Daniel Vettercc4ceb42014-07-25 21:30:38 +02001571 int (*atomic_check)(struct drm_device *dev,
Daniel Vetter9953f412015-12-04 09:46:02 +01001572 struct drm_atomic_state *state);
1573
1574 /**
1575 * @atomic_commit:
1576 *
1577 * This is the only hook to commit an atomic modeset update. The core
1578 * guarantees that @atomic_check has been called successfully before
1579 * calling this function, and that nothing has been changed in the
1580 * interim.
1581 *
1582 * See the documentation for struct &drm_atomic_state for how exactly
1583 * an atomic modeset update is described.
1584 *
1585 * Drivers using the atomic helpers can implement this hook using
1586 * drm_atomic_helper_commit(), or one of the exported sub-functions of
1587 * it.
1588 *
Maarten Lankhorst286dbb82016-04-26 16:11:34 +02001589 * Nonblocking commits (as indicated with the nonblock parameter) must
Daniel Vetter9953f412015-12-04 09:46:02 +01001590 * do any preparatory work which might result in an unsuccessful commit
1591 * in the context of this callback. The only exceptions are hardware
1592 * errors resulting in -EIO. But even in that case the driver must
1593 * ensure that the display pipe is at least running, to avoid
1594 * compositors crashing when pageflips don't work. Anything else,
1595 * specifically committing the update to the hardware, should be done
1596 * without blocking the caller. For updates which do not require a
1597 * modeset this must be guaranteed.
1598 *
1599 * The driver must wait for any pending rendering to the new
1600 * framebuffers to complete before executing the flip. It should also
1601 * wait for any pending rendering from other drivers if the underlying
Maarten Lankhorst286dbb82016-04-26 16:11:34 +02001602 * buffer is a shared dma-buf. Nonblocking commits must not wait for
Daniel Vetter9953f412015-12-04 09:46:02 +01001603 * rendering in the context of this callback.
1604 *
1605 * An application can request to be notified when the atomic commit has
1606 * completed. These events are per-CRTC and can be distinguished by the
1607 * CRTC index supplied in &drm_event to userspace.
1608 *
1609 * The drm core will supply a struct &drm_event in the event
1610 * member of each CRTC's &drm_crtc_state structure. This can be handled by the
1611 * drm_crtc_send_vblank_event() function, which the driver should call on
1612 * the provided event upon completion of the atomic commit. Note that if
1613 * the driver supports vblank signalling and timestamping the vblank
1614 * counters and timestamps must agree with the ones returned from page
1615 * flip events. With the current vblank helper infrastructure this can
1616 * be achieved by holding a vblank reference while the page flip is
1617 * pending, acquired through drm_crtc_vblank_get() and released with
1618 * drm_crtc_vblank_put(). Drivers are free to implement their own vblank
1619 * counter and timestamp tracking though, e.g. if they have accurate
1620 * timestamp registers in hardware.
1621 *
1622 * NOTE:
1623 *
1624 * Drivers are not allowed to shut down any display pipe successfully
1625 * enabled through an atomic commit on their own. Doing so can result in
1626 * compositors crashing if a page flip is suddenly rejected because the
1627 * pipe is off.
1628 *
1629 * RETURNS:
1630 *
1631 * 0 on success or one of the below negative error codes:
1632 *
Maarten Lankhorst286dbb82016-04-26 16:11:34 +02001633 * - -EBUSY, if a nonblocking updated is requested and there is
Daniel Vetter9953f412015-12-04 09:46:02 +01001634 * an earlier updated pending. Drivers are allowed to support a queue
1635 * of outstanding updates, but currently no driver supports that.
1636 * Note that drivers must wait for preceding updates to complete if a
1637 * synchronous update is requested, they are not allowed to fail the
1638 * commit in that case.
1639 *
1640 * - -ENOMEM, if the driver failed to allocate memory. Specifically
1641 * this can happen when trying to pin framebuffers, which must only
1642 * be done when committing the state.
1643 *
1644 * - -ENOSPC, as a refinement of the more generic -ENOMEM to indicate
1645 * that the driver has run out of vram, iommu space or similar GPU
1646 * address space needed for framebuffer.
1647 *
1648 * - -EIO, if the hardware completely died.
1649 *
1650 * - -EINTR, -EAGAIN or -ERESTARTSYS, if the IOCTL should be restarted.
1651 * This can either be due to a pending signal, or because the driver
1652 * needs to completely bail out to recover from an exceptional
1653 * situation like a GPU hang. From a userspace point of view all errors are
1654 * treated equally.
1655 *
1656 * This list is exhaustive. Specifically this hook is not allowed to
1657 * return -EINVAL (any invalid requests should be caught in
1658 * @atomic_check) or -EDEADLK (this function must not acquire
1659 * additional modeset locks).
1660 */
Daniel Vettercc4ceb42014-07-25 21:30:38 +02001661 int (*atomic_commit)(struct drm_device *dev,
Daniel Vetter9953f412015-12-04 09:46:02 +01001662 struct drm_atomic_state *state,
Maarten Lankhorst286dbb82016-04-26 16:11:34 +02001663 bool nonblock);
Daniel Vetter9953f412015-12-04 09:46:02 +01001664
1665 /**
1666 * @atomic_state_alloc:
1667 *
1668 * This optional hook can be used by drivers that want to subclass struct
1669 * &drm_atomic_state to be able to track their own driver-private global
1670 * state easily. If this hook is implemented, drivers must also
1671 * implement @atomic_state_clear and @atomic_state_free.
1672 *
1673 * RETURNS:
1674 *
1675 * A new &drm_atomic_state on success or NULL on failure.
1676 */
Maarten Lankhorst036ef572015-05-18 10:06:40 +02001677 struct drm_atomic_state *(*atomic_state_alloc)(struct drm_device *dev);
Daniel Vetter9953f412015-12-04 09:46:02 +01001678
1679 /**
1680 * @atomic_state_clear:
1681 *
1682 * This hook must clear any driver private state duplicated into the
1683 * passed-in &drm_atomic_state. This hook is called when the caller
1684 * encountered a &drm_modeset_lock deadlock and needs to drop all
1685 * already acquired locks as part of the deadlock avoidance dance
1686 * implemented in drm_modeset_lock_backoff().
1687 *
1688 * Any duplicated state must be invalidated since a concurrent atomic
1689 * update might change it, and the drm atomic interfaces always apply
1690 * updates as relative changes to the current state.
1691 *
1692 * Drivers that implement this must call drm_atomic_state_default_clear()
1693 * to clear common state.
1694 */
Maarten Lankhorst036ef572015-05-18 10:06:40 +02001695 void (*atomic_state_clear)(struct drm_atomic_state *state);
Daniel Vetter9953f412015-12-04 09:46:02 +01001696
1697 /**
1698 * @atomic_state_free:
1699 *
1700 * This hook needs driver private resources and the &drm_atomic_state
1701 * itself. Note that the core first calls drm_atomic_state_clear() to
1702 * avoid code duplicate between the clear and free hooks.
1703 *
1704 * Drivers that implement this must call drm_atomic_state_default_free()
1705 * to release common resources.
1706 */
Maarten Lankhorst036ef572015-05-18 10:06:40 +02001707 void (*atomic_state_free)(struct drm_atomic_state *state);
Dave Airlief453ba02008-11-07 14:05:41 -08001708};
1709
Jesse Barnesc1aaca22011-11-07 12:03:21 -08001710/**
Daniel Vetter2c0c33d2014-10-27 20:19:38 +01001711 * struct drm_mode_config - Mode configuration control structure
Jesse Barnesa62c93d2011-11-07 12:03:22 -08001712 * @mutex: mutex protecting KMS related lists and structures
Daniel Vetter2c0c33d2014-10-27 20:19:38 +01001713 * @connection_mutex: ww mutex protecting connector state and routing
1714 * @acquire_ctx: global implicit acquire context used by atomic drivers for
Daniel Vetterc6b0ca32015-12-04 09:46:01 +01001715 * legacy IOCTLs
Daniel Vetter2c0c33d2014-10-27 20:19:38 +01001716 * @fb_lock: mutex to protect fb state and lists
Jesse Barnesa62c93d2011-11-07 12:03:22 -08001717 * @num_fb: number of fbs available
1718 * @fb_list: list of framebuffers available
Jesse Barnesa62c93d2011-11-07 12:03:22 -08001719 * @num_encoder: number of encoders on this device
1720 * @encoder_list: list of encoder objects
Daniel Vetter2c0c33d2014-10-27 20:19:38 +01001721 * @num_overlay_plane: number of overlay planes on this device
1722 * @num_total_plane: number of universal (i.e. with primary/curso) planes on this device
1723 * @plane_list: list of plane objects
Jesse Barnesa62c93d2011-11-07 12:03:22 -08001724 * @num_crtc: number of CRTCs on this device
1725 * @crtc_list: list of CRTC objects
Daniel Vetter2c0c33d2014-10-27 20:19:38 +01001726 * @property_list: list of property objects
Jesse Barnesa62c93d2011-11-07 12:03:22 -08001727 * @min_width: minimum pixel width on this device
1728 * @min_height: minimum pixel height on this device
1729 * @max_width: maximum pixel width on this device
1730 * @max_height: maximum pixel height on this device
1731 * @funcs: core driver provided mode setting functions
1732 * @fb_base: base address of the framebuffer
Daniel Vetter2c0c33d2014-10-27 20:19:38 +01001733 * @poll_enabled: track polling support for this device
1734 * @poll_running: track polling status for this device
Daniel Vetterac3ba4a2016-05-31 23:11:10 +02001735 * @delayed_event: track delayed poll uevent deliver for this device
Jesse Barnesa62c93d2011-11-07 12:03:22 -08001736 * @output_poll_work: delayed work for polling in process context
Daniel Vetter2c0c33d2014-10-27 20:19:38 +01001737 * @property_blob_list: list of all the blob property objects
Daniel Stone8fb6e7a2015-04-20 19:22:54 +01001738 * @blob_lock: mutex for blob property allocation and management
Jesse Barnesa62c93d2011-11-07 12:03:22 -08001739 * @*_property: core property tracking
Daniel Vetter2c0c33d2014-10-27 20:19:38 +01001740 * @preferred_depth: preferred RBG pixel depth, used by fb helpers
1741 * @prefer_shadow: hint to userspace to prefer shadow-fb rendering
Daniel Vetter2c0c33d2014-10-27 20:19:38 +01001742 * @cursor_width: hint to userspace for max cursor width
1743 * @cursor_height: hint to userspace for max cursor height
Daniel Vetter9f2a7952016-06-08 14:19:02 +02001744 * @helper_private: mid-layer private data
Dave Airlief453ba02008-11-07 14:05:41 -08001745 *
Jesse Barnesa62c93d2011-11-07 12:03:22 -08001746 * Core mode resource tracking structure. All CRTC, encoders, and connectors
1747 * enumerated by the driver are added here, as are global properties. Some
1748 * global restrictions are also here, e.g. dimension restrictions.
Dave Airlief453ba02008-11-07 14:05:41 -08001749 */
1750struct drm_mode_config {
Jesse Barnesad2563c2009-01-19 17:21:45 +10001751 struct mutex mutex; /* protects configuration (mode lists etc.) */
Rob Clark51fd3712013-11-19 12:10:12 -05001752 struct drm_modeset_lock connection_mutex; /* protects connector->encoder and encoder->crtc links */
1753 struct drm_modeset_acquire_ctx *acquire_ctx; /* for legacy _lock_all() / _unlock_all() */
Daniel Vetterac3ba4a2016-05-31 23:11:10 +02001754
1755 /**
1756 * @idr_mutex:
1757 *
1758 * Mutex for KMS ID allocation and management. Protects both @crtc_idr
1759 * and @tile_idr.
1760 */
1761 struct mutex idr_mutex;
1762
1763 /**
1764 * @crtc_idr:
1765 *
1766 * Main KMS ID tracking object. Use this idr for all IDs, fb, crtc,
1767 * connector, modes - just makes life easier to have only one.
1768 */
1769 struct idr crtc_idr;
1770
1771 /**
1772 * @tile_idr:
1773 *
1774 * Use this idr for allocating new IDs for tiled sinks like use in some
1775 * high-res DP MST screens.
1776 */
1777 struct idr tile_idr;
Daniel Vetter4b096ac2012-12-10 21:19:18 +01001778
Daniel Vetter2c0c33d2014-10-27 20:19:38 +01001779 struct mutex fb_lock; /* proctects global and per-file fb lists */
Dave Airlief453ba02008-11-07 14:05:41 -08001780 int num_fb;
1781 struct list_head fb_list;
Daniel Vetter4b096ac2012-12-10 21:19:18 +01001782
Daniel Vetter96094082016-07-15 21:47:59 +02001783 /**
1784 * @num_connector: Number of connectors on this device.
1785 */
Dave Airlief453ba02008-11-07 14:05:41 -08001786 int num_connector;
Daniel Vetter96094082016-07-15 21:47:59 +02001787 /**
1788 * @connector_ida: ID allocator for connector indices.
1789 */
Maarten Lankhorst5fff80b2016-02-17 08:32:05 +01001790 struct ida connector_ida;
Daniel Vetter96094082016-07-15 21:47:59 +02001791 /**
1792 * @connector_list: List of connector objects.
1793 */
Dave Airlief453ba02008-11-07 14:05:41 -08001794 struct list_head connector_list;
1795 int num_encoder;
1796 struct list_head encoder_list;
Matt Ropere27dde32014-04-01 15:22:30 -07001797
1798 /*
1799 * Track # of overlay planes separately from # of total planes. By
1800 * default we only advertise overlay planes to userspace; if userspace
1801 * sets the "universal plane" capability bit, we'll go ahead and
1802 * expose all planes.
1803 */
1804 int num_overlay_plane;
1805 int num_total_plane;
Jesse Barnes8cf5c912011-11-14 14:51:27 -08001806 struct list_head plane_list;
Dave Airlief453ba02008-11-07 14:05:41 -08001807
1808 int num_crtc;
1809 struct list_head crtc_list;
1810
1811 struct list_head property_list;
1812
Dave Airlief453ba02008-11-07 14:05:41 -08001813 int min_width, min_height;
1814 int max_width, max_height;
Laurent Pincharte6ecefa2012-05-17 13:27:23 +02001815 const struct drm_mode_config_funcs *funcs;
Benjamin Herrenschmidtd883f7f2009-02-02 16:55:45 +11001816 resource_size_t fb_base;
Dave Airlief453ba02008-11-07 14:05:41 -08001817
Dave Airlieeb1f8e42010-05-07 06:42:51 +00001818 /* output poll support */
1819 bool poll_enabled;
Daniel Vetter905bc9f2012-10-23 18:23:36 +00001820 bool poll_running;
Daniel Vetter162b6a52015-01-21 08:45:21 +01001821 bool delayed_event;
Tejun Heo991ea752010-07-20 22:09:02 +02001822 struct delayed_work output_poll_work;
Dave Airlieeb1f8e42010-05-07 06:42:51 +00001823
Daniel Stone8fb6e7a2015-04-20 19:22:54 +01001824 struct mutex blob_lock;
1825
Dave Airlief453ba02008-11-07 14:05:41 -08001826 /* pointers to standard properties */
1827 struct list_head property_blob_list;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02001828 /**
1829 * @edid_property: Default connector property to hold the EDID of the
1830 * currently connected sink, if any.
1831 */
Dave Airlief453ba02008-11-07 14:05:41 -08001832 struct drm_property *edid_property;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02001833 /**
1834 * @dpms_property: Default connector property to control the
1835 * connector's DPMS state.
1836 */
Dave Airlief453ba02008-11-07 14:05:41 -08001837 struct drm_property *dpms_property;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02001838 /**
1839 * @path_property: Default connector property to hold the DP MST path
1840 * for the port.
1841 */
Dave Airlie43aba7e2014-06-05 14:01:31 +10001842 struct drm_property *path_property;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02001843 /**
1844 * @tile_property: Default connector property to store the tile
1845 * position of a tiled screen, for sinks which need to be driven with
1846 * multiple CRTCs.
1847 */
Dave Airlie6f134d72014-10-20 16:30:50 +10001848 struct drm_property *tile_property;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02001849 /**
1850 * @plane_type_property: Default plane property to differentiate
1851 * CURSOR, PRIMARY and OVERLAY legacy uses of planes.
1852 */
Rob Clark9922ab52014-04-01 20:16:57 -04001853 struct drm_property *plane_type_property;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02001854 /**
1855 * @rotation_property: Optional property for planes or CRTCs to specifiy
1856 * rotation.
1857 */
Sonika Jindal2a297cc2014-08-05 11:26:54 +05301858 struct drm_property *rotation_property;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02001859 /**
1860 * @prop_src_x: Default atomic plane property for the plane source
1861 * position in the connected &drm_framebuffer.
1862 */
Rob Clark6b4959f2014-12-18 16:01:53 -05001863 struct drm_property *prop_src_x;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02001864 /**
1865 * @prop_src_y: Default atomic plane property for the plane source
1866 * position in the connected &drm_framebuffer.
1867 */
Rob Clark6b4959f2014-12-18 16:01:53 -05001868 struct drm_property *prop_src_y;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02001869 /**
1870 * @prop_src_w: Default atomic plane property for the plane source
1871 * position in the connected &drm_framebuffer.
1872 */
Rob Clark6b4959f2014-12-18 16:01:53 -05001873 struct drm_property *prop_src_w;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02001874 /**
1875 * @prop_src_h: Default atomic plane property for the plane source
1876 * position in the connected &drm_framebuffer.
1877 */
Rob Clark6b4959f2014-12-18 16:01:53 -05001878 struct drm_property *prop_src_h;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02001879 /**
1880 * @prop_crtc_x: Default atomic plane property for the plane destination
1881 * position in the &drm_crtc is is being shown on.
1882 */
Rob Clark6b4959f2014-12-18 16:01:53 -05001883 struct drm_property *prop_crtc_x;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02001884 /**
1885 * @prop_crtc_y: Default atomic plane property for the plane destination
1886 * position in the &drm_crtc is is being shown on.
1887 */
Rob Clark6b4959f2014-12-18 16:01:53 -05001888 struct drm_property *prop_crtc_y;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02001889 /**
1890 * @prop_crtc_w: Default atomic plane property for the plane destination
1891 * position in the &drm_crtc is is being shown on.
1892 */
Rob Clark6b4959f2014-12-18 16:01:53 -05001893 struct drm_property *prop_crtc_w;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02001894 /**
1895 * @prop_crtc_h: Default atomic plane property for the plane destination
1896 * position in the &drm_crtc is is being shown on.
1897 */
Rob Clark6b4959f2014-12-18 16:01:53 -05001898 struct drm_property *prop_crtc_h;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02001899 /**
1900 * @prop_fb_id: Default atomic plane property to specify the
1901 * &drm_framebuffer.
1902 */
Rob Clark6b4959f2014-12-18 16:01:53 -05001903 struct drm_property *prop_fb_id;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02001904 /**
1905 * @prop_crtc_id: Default atomic plane property to specify the
1906 * &drm_crtc.
1907 */
Rob Clark6b4959f2014-12-18 16:01:53 -05001908 struct drm_property *prop_crtc_id;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02001909 /**
1910 * @prop_active: Default atomic CRTC property to control the active
1911 * state, which is the simplified implementation for DPMS in atomic
1912 * drivers.
1913 */
Daniel Vettereab3bbe2015-01-22 16:36:21 +01001914 struct drm_property *prop_active;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02001915 /**
1916 * @prop_mode_id: Default atomic CRTC property to set the mode for a
1917 * CRTC. A 0 mode implies that the CRTC is entirely disabled - all
1918 * connectors must be of and active must be set to disabled, too.
1919 */
Daniel Stone955f3c32015-05-25 19:11:52 +01001920 struct drm_property *prop_mode_id;
Dave Airlief453ba02008-11-07 14:05:41 -08001921
Daniel Vetter9a6bc032016-07-15 21:48:00 +02001922 /**
1923 * @dvi_i_subconnector_property: Optional DVI-I property to
1924 * differentiate between analog or digital mode.
1925 */
Dave Airlief453ba02008-11-07 14:05:41 -08001926 struct drm_property *dvi_i_subconnector_property;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02001927 /**
1928 * @dvi_i_select_subconnector_property: Optional DVI-I property to
1929 * select between analog or digital mode.
1930 */
Dave Airlief453ba02008-11-07 14:05:41 -08001931 struct drm_property *dvi_i_select_subconnector_property;
1932
Daniel Vetter9a6bc032016-07-15 21:48:00 +02001933 /**
1934 * @tv_subconnector_property: Optional TV property to differentiate
1935 * between different TV connector types.
1936 */
Dave Airlief453ba02008-11-07 14:05:41 -08001937 struct drm_property *tv_subconnector_property;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02001938 /**
1939 * @tv_select_subconnector_property: Optional TV property to select
1940 * between different TV connector types.
1941 */
Dave Airlief453ba02008-11-07 14:05:41 -08001942 struct drm_property *tv_select_subconnector_property;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02001943 /**
1944 * @tv_mode_property: Optional TV property to select
1945 * the output TV mode.
1946 */
Dave Airlief453ba02008-11-07 14:05:41 -08001947 struct drm_property *tv_mode_property;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02001948 /**
1949 * @tv_left_margin_property: Optional TV property to set the left
1950 * margin.
1951 */
Dave Airlief453ba02008-11-07 14:05:41 -08001952 struct drm_property *tv_left_margin_property;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02001953 /**
1954 * @tv_right_margin_property: Optional TV property to set the right
1955 * margin.
1956 */
Dave Airlief453ba02008-11-07 14:05:41 -08001957 struct drm_property *tv_right_margin_property;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02001958 /**
1959 * @tv_top_margin_property: Optional TV property to set the right
1960 * margin.
1961 */
Dave Airlief453ba02008-11-07 14:05:41 -08001962 struct drm_property *tv_top_margin_property;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02001963 /**
1964 * @tv_bottom_margin_property: Optional TV property to set the right
1965 * margin.
1966 */
Dave Airlief453ba02008-11-07 14:05:41 -08001967 struct drm_property *tv_bottom_margin_property;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02001968 /**
1969 * @tv_brightness_property: Optional TV property to set the
1970 * brightness.
1971 */
Francisco Jerezb6b79022009-08-02 04:19:20 +02001972 struct drm_property *tv_brightness_property;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02001973 /**
1974 * @tv_contrast_property: Optional TV property to set the
1975 * contrast.
1976 */
Francisco Jerezb6b79022009-08-02 04:19:20 +02001977 struct drm_property *tv_contrast_property;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02001978 /**
1979 * @tv_flicker_reduction_property: Optional TV property to control the
1980 * flicker reduction mode.
1981 */
Francisco Jerezb6b79022009-08-02 04:19:20 +02001982 struct drm_property *tv_flicker_reduction_property;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02001983 /**
1984 * @tv_overscan_property: Optional TV property to control the overscan
1985 * setting.
1986 */
Francisco Jereza75f0232009-08-12 02:30:10 +02001987 struct drm_property *tv_overscan_property;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02001988 /**
1989 * @tv_saturation_property: Optional TV property to set the
1990 * saturation.
1991 */
Francisco Jereza75f0232009-08-12 02:30:10 +02001992 struct drm_property *tv_saturation_property;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02001993 /**
1994 * @tv_hue_property: Optional TV property to set the hue.
1995 */
Francisco Jereza75f0232009-08-12 02:30:10 +02001996 struct drm_property *tv_hue_property;
Dave Airlief453ba02008-11-07 14:05:41 -08001997
Daniel Vetter9a6bc032016-07-15 21:48:00 +02001998 /**
1999 * @scaling_mode_property: Optional connector property to control the
2000 * upscaling, mostly used for built-in panels.
2001 */
Dave Airlief453ba02008-11-07 14:05:41 -08002002 struct drm_property *scaling_mode_property;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02002003 /**
2004 * @aspect_ratio_property: Optional connector property to control the
2005 * HDMI infoframe aspect ratio setting.
2006 */
Vandana Kannanff587e42014-06-11 10:46:48 +05302007 struct drm_property *aspect_ratio_property;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02002008 /**
Daniel Vetter9a6bc032016-07-15 21:48:00 +02002009 * @degamma_lut_property: Optional CRTC property to set the LUT used to
2010 * convert the framebuffer's colors to linear gamma.
2011 */
Lionel Landwerlin5488dc12016-02-26 17:05:00 +00002012 struct drm_property *degamma_lut_property;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02002013 /**
2014 * @degamma_lut_size_property: Optional CRTC property for the size of
2015 * the degamma LUT as supported by the driver (read-only).
2016 */
Lionel Landwerlin5488dc12016-02-26 17:05:00 +00002017 struct drm_property *degamma_lut_size_property;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02002018 /**
2019 * @ctm_property: Optional CRTC property to set the
2020 * matrix used to convert colors after the lookup in the
2021 * degamma LUT.
2022 */
Lionel Landwerlin5488dc12016-02-26 17:05:00 +00002023 struct drm_property *ctm_property;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02002024 /**
2025 * @gamma_lut_property: Optional CRTC property to set the LUT used to
2026 * convert the colors, after the CTM matrix, to the gamma space of the
2027 * connected screen.
2028 */
Lionel Landwerlin5488dc12016-02-26 17:05:00 +00002029 struct drm_property *gamma_lut_property;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02002030 /**
2031 * @gamma_lut_size_property: Optional CRTC property for the size of the
2032 * gamma LUT as supported by the driver (read-only).
2033 */
Lionel Landwerlin5488dc12016-02-26 17:05:00 +00002034 struct drm_property *gamma_lut_size_property;
2035
Daniel Vetter9a6bc032016-07-15 21:48:00 +02002036 /**
2037 * @suggested_x_property: Optional connector property with a hint for
2038 * the position of the output on the host's screen.
2039 */
Dave Airlie5bb2bbf2014-11-10 10:18:15 +10002040 struct drm_property *suggested_x_property;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02002041 /**
2042 * @suggested_y_property: Optional connector property with a hint for
2043 * the position of the output on the host's screen.
2044 */
Dave Airlie5bb2bbf2014-11-10 10:18:15 +10002045 struct drm_property *suggested_y_property;
2046
Dave Airlie019d96c2011-09-29 16:20:42 +01002047 /* dumb ioctl parameters */
2048 uint32_t preferred_depth, prefer_shadow;
Keith Packard62f21042013-07-22 18:50:00 -07002049
Daniel Vetter9a6bc032016-07-15 21:48:00 +02002050 /**
2051 * @async_page_flip: Does this device support async flips on the primary
2052 * plane?
2053 */
Keith Packard62f21042013-07-22 18:50:00 -07002054 bool async_page_flip;
Alex Deucher8716ed42014-02-12 12:48:23 -05002055
Daniel Vetterac3ba4a2016-05-31 23:11:10 +02002056 /**
2057 * @allow_fb_modifiers:
2058 *
2059 * Whether the driver supports fb modifiers in the ADDFB2.1 ioctl call.
2060 */
Rob Clarke3eb3252015-02-05 14:41:52 +00002061 bool allow_fb_modifiers;
2062
Alex Deucher8716ed42014-02-12 12:48:23 -05002063 /* cursor size */
2064 uint32_t cursor_width, cursor_height;
Daniel Vetter9f2a7952016-06-08 14:19:02 +02002065
2066 struct drm_mode_config_helper_funcs *helper_private;
Dave Airlief453ba02008-11-07 14:05:41 -08002067};
2068
Rob Clarkdd275952014-11-25 20:29:46 -05002069/**
2070 * drm_for_each_plane_mask - iterate over planes specified by bitmask
2071 * @plane: the loop cursor
2072 * @dev: the DRM device
2073 * @plane_mask: bitmask of plane indices
2074 *
2075 * Iterate over all planes specified by bitmask.
2076 */
2077#define drm_for_each_plane_mask(plane, dev, plane_mask) \
2078 list_for_each_entry((plane), &(dev)->mode_config.plane_list, head) \
Jani Nikula373701b2015-11-24 21:21:55 +02002079 for_each_if ((plane_mask) & (1 << drm_plane_index(plane)))
Rob Clarkdd275952014-11-25 20:29:46 -05002080
Maarten Lankhorstead8b662016-01-07 10:59:19 +01002081/**
2082 * drm_for_each_encoder_mask - iterate over encoders specified by bitmask
2083 * @encoder: the loop cursor
2084 * @dev: the DRM device
2085 * @encoder_mask: bitmask of encoder indices
2086 *
2087 * Iterate over all encoders specified by bitmask.
2088 */
2089#define drm_for_each_encoder_mask(encoder, dev, encoder_mask) \
2090 list_for_each_entry((encoder), &(dev)->mode_config.encoder_list, head) \
2091 for_each_if ((encoder_mask) & (1 << drm_encoder_index(encoder)))
Rob Clarkdd275952014-11-25 20:29:46 -05002092
Dave Airlief453ba02008-11-07 14:05:41 -08002093#define obj_to_crtc(x) container_of(x, struct drm_crtc, base)
Dave Airlief453ba02008-11-07 14:05:41 -08002094#define obj_to_encoder(x) container_of(x, struct drm_encoder, base)
2095#define obj_to_mode(x) container_of(x, struct drm_display_mode, base)
2096#define obj_to_fb(x) container_of(x, struct drm_framebuffer, base)
2097#define obj_to_property(x) container_of(x, struct drm_property, base)
2098#define obj_to_blob(x) container_of(x, struct drm_property_blob, base)
Jesse Barnes8cf5c912011-11-14 14:51:27 -08002099#define obj_to_plane(x) container_of(x, struct drm_plane, base)
Dave Airlief453ba02008-11-07 14:05:41 -08002100
Sascha Hauer4a67d392012-02-06 10:58:17 +01002101struct drm_prop_enum_list {
2102 int type;
2103 char *name;
2104};
Dave Airlief453ba02008-11-07 14:05:41 -08002105
Ville Syrjäläf9882872015-12-09 16:19:31 +02002106extern __printf(6, 7)
2107int drm_crtc_init_with_planes(struct drm_device *dev,
2108 struct drm_crtc *crtc,
2109 struct drm_plane *primary,
2110 struct drm_plane *cursor,
2111 const struct drm_crtc_funcs *funcs,
2112 const char *name, ...);
Dave Airlief453ba02008-11-07 14:05:41 -08002113extern void drm_crtc_cleanup(struct drm_crtc *crtc);
Chris Wilson490d3d12016-05-27 20:05:00 +01002114
2115/**
2116 * drm_crtc_index - find the index of a registered CRTC
2117 * @crtc: CRTC to find index for
2118 *
2119 * Given a registered CRTC, return the index of that CRTC within a DRM
2120 * device's list of CRTCs.
2121 */
2122static inline unsigned int drm_crtc_index(struct drm_crtc *crtc)
2123{
2124 return crtc->index;
2125}
Russell Kingdb5f7a62014-01-02 21:27:33 +00002126
2127/**
2128 * drm_crtc_mask - find the mask of a registered CRTC
2129 * @crtc: CRTC to find mask for
2130 *
2131 * Given a registered CRTC, return the mask bit of that CRTC for an
2132 * encoder's possible_crtcs field.
2133 */
2134static inline uint32_t drm_crtc_mask(struct drm_crtc *crtc)
2135{
2136 return 1 << drm_crtc_index(crtc);
2137}
Dave Airlief453ba02008-11-07 14:05:41 -08002138
Ville Syrjälä13a3d912015-12-09 16:20:18 +02002139extern __printf(5, 6)
2140int drm_encoder_init(struct drm_device *dev,
2141 struct drm_encoder *encoder,
2142 const struct drm_encoder_funcs *funcs,
2143 int encoder_type, const char *name, ...);
Chris Wilson490d3d12016-05-27 20:05:00 +01002144
2145/**
2146 * drm_encoder_index - find the index of a registered encoder
2147 * @encoder: encoder to find index for
2148 *
2149 * Given a registered encoder, return the index of that encoder within a DRM
2150 * device's list of encoders.
2151 */
2152static inline unsigned int drm_encoder_index(struct drm_encoder *encoder)
2153{
2154 return encoder->index;
2155}
Dave Airlief453ba02008-11-07 14:05:41 -08002156
Thierry Reding3d887362014-01-13 14:33:20 +01002157/**
2158 * drm_encoder_crtc_ok - can a given crtc drive a given encoder?
2159 * @encoder: encoder to test
2160 * @crtc: crtc to test
2161 *
2162 * Return false if @encoder can't be driven by @crtc, true otherwise.
2163 */
2164static inline bool drm_encoder_crtc_ok(struct drm_encoder *encoder,
2165 struct drm_crtc *crtc)
2166{
2167 return !!(encoder->possible_crtcs & drm_crtc_mask(crtc));
2168}
2169
Ville Syrjäläb0b3b792015-12-09 16:19:55 +02002170extern __printf(8, 9)
2171int drm_universal_plane_init(struct drm_device *dev,
2172 struct drm_plane *plane,
2173 unsigned long possible_crtcs,
2174 const struct drm_plane_funcs *funcs,
2175 const uint32_t *formats,
2176 unsigned int format_count,
2177 enum drm_plane_type type,
2178 const char *name, ...);
Jesse Barnes8cf5c912011-11-14 14:51:27 -08002179extern int drm_plane_init(struct drm_device *dev,
2180 struct drm_plane *plane,
2181 unsigned long possible_crtcs,
2182 const struct drm_plane_funcs *funcs,
Thierry Reding45e37432015-08-12 16:54:28 +02002183 const uint32_t *formats, unsigned int format_count,
Matt Roperdc415ff2014-04-01 15:22:36 -07002184 bool is_primary);
Jesse Barnes8cf5c912011-11-14 14:51:27 -08002185extern void drm_plane_cleanup(struct drm_plane *plane);
Chris Wilson490d3d12016-05-27 20:05:00 +01002186
2187/**
2188 * drm_plane_index - find the index of a registered plane
2189 * @plane: plane to find index for
2190 *
2191 * Given a registered plane, return the index of that plane within a DRM
2192 * device's list of planes.
2193 */
2194static inline unsigned int drm_plane_index(struct drm_plane *plane)
2195{
2196 return plane->index;
2197}
Chandra Konduruf81338a2015-04-09 17:36:21 -07002198extern struct drm_plane * drm_plane_from_index(struct drm_device *dev, int idx);
Ville Syrjälä9125e612013-06-03 16:10:40 +03002199extern void drm_plane_force_disable(struct drm_plane *plane);
Gustavo Padovanecb7e162014-12-01 15:40:09 -08002200extern void drm_crtc_get_hv_timing(const struct drm_display_mode *mode,
2201 int *hdisplay, int *vdisplay);
Lukas Wunner6a0d9522016-06-08 18:47:27 +02002202extern int drm_crtc_force_disable(struct drm_crtc *crtc);
2203extern int drm_crtc_force_disable_all(struct drm_device *dev);
Jesse Barnes8cf5c912011-11-14 14:51:27 -08002204
Dave Airlief453ba02008-11-07 14:05:41 -08002205extern void drm_encoder_cleanup(struct drm_encoder *encoder);
2206
Dave Airlief453ba02008-11-07 14:05:41 -08002207extern void drm_mode_config_init(struct drm_device *dev);
Chris Wilsoneb033552011-01-24 15:11:08 +00002208extern void drm_mode_config_reset(struct drm_device *dev);
Dave Airlief453ba02008-11-07 14:05:41 -08002209extern void drm_mode_config_cleanup(struct drm_device *dev);
Dave Airlief453ba02008-11-07 14:05:41 -08002210
Boris Brezillonb5571e92014-07-22 12:09:10 +02002211extern int drm_display_info_set_bus_formats(struct drm_display_info *info,
2212 const u32 *formats,
2213 unsigned int num_formats);
2214
Rob Clark5ea22f22014-05-30 11:34:01 -04002215static inline bool drm_property_type_is(struct drm_property *property,
2216 uint32_t type)
2217{
2218 /* instanceof for props.. handles extended type vs original types: */
2219 if (property->flags & DRM_MODE_PROP_EXTENDED_TYPE)
2220 return (property->flags & DRM_MODE_PROP_EXTENDED_TYPE) == type;
2221 return property->flags & type;
2222}
2223
Paulo Zanonic5431882012-05-15 18:09:02 -03002224extern int drm_object_property_set_value(struct drm_mode_object *obj,
2225 struct drm_property *property,
2226 uint64_t val);
2227extern int drm_object_property_get_value(struct drm_mode_object *obj,
2228 struct drm_property *property,
2229 uint64_t *value);
Dave Airlief453ba02008-11-07 14:05:41 -08002230
Paulo Zanonic5431882012-05-15 18:09:02 -03002231extern void drm_object_attach_property(struct drm_mode_object *obj,
2232 struct drm_property *property,
2233 uint64_t init_val);
Dave Airlief453ba02008-11-07 14:05:41 -08002234extern struct drm_property *drm_property_create(struct drm_device *dev, int flags,
2235 const char *name, int num_values);
Sascha Hauer4a67d392012-02-06 10:58:17 +01002236extern struct drm_property *drm_property_create_enum(struct drm_device *dev, int flags,
2237 const char *name,
2238 const struct drm_prop_enum_list *props,
2239 int num_values);
Rob Clark49e27542012-05-17 02:23:26 -06002240struct drm_property *drm_property_create_bitmask(struct drm_device *dev,
2241 int flags, const char *name,
2242 const struct drm_prop_enum_list *props,
Ville Syrjälä7689ffb2014-07-08 10:31:52 +05302243 int num_props,
2244 uint64_t supported_bits);
Sascha Hauerd9bc3c02012-02-06 10:58:18 +01002245struct drm_property *drm_property_create_range(struct drm_device *dev, int flags,
2246 const char *name,
2247 uint64_t min, uint64_t max);
Rob Clarkebc44cf2012-09-12 22:22:31 -05002248struct drm_property *drm_property_create_signed_range(struct drm_device *dev,
2249 int flags, const char *name,
2250 int64_t min, int64_t max);
Rob Clark98f75de2014-05-30 11:37:03 -04002251struct drm_property *drm_property_create_object(struct drm_device *dev,
2252 int flags, const char *name, uint32_t type);
Daniel Vetter960cd9d2015-01-21 08:47:38 +01002253struct drm_property *drm_property_create_bool(struct drm_device *dev, int flags,
2254 const char *name);
Daniel Stone6bcacf52015-04-20 19:22:55 +01002255struct drm_property_blob *drm_property_create_blob(struct drm_device *dev,
2256 size_t length,
2257 const void *data);
2258struct drm_property_blob *drm_property_lookup_blob(struct drm_device *dev,
2259 uint32_t id);
Daniel Vetteradebd6f2016-08-12 22:48:49 +02002260int drm_property_replace_global_blob(struct drm_device *dev,
2261 struct drm_property_blob **replace,
2262 size_t length,
2263 const void *data,
2264 struct drm_mode_object *obj_holds_id,
2265 struct drm_property *prop_holds_id);
Daniel Stone6bcacf52015-04-20 19:22:55 +01002266struct drm_property_blob *drm_property_reference_blob(struct drm_property_blob *blob);
2267void drm_property_unreference_blob(struct drm_property_blob *blob);
Dave Airlief453ba02008-11-07 14:05:41 -08002268extern void drm_property_destroy(struct drm_device *dev, struct drm_property *property);
2269extern int drm_property_add_enum(struct drm_property *property, int index,
2270 uint64_t value, const char *name);
Sascha Hauer4cae5b82012-02-01 11:38:23 +01002271extern int drm_mode_crtc_set_gamma_size(struct drm_crtc *crtc,
Dave Airlief453ba02008-11-07 14:05:41 -08002272 int gamma_size);
Rob Clark98f75de2014-05-30 11:37:03 -04002273
Daniel Vetter2d13b672012-12-11 13:47:23 +01002274extern int drm_mode_set_config_internal(struct drm_mode_set *set);
Daniel Vetter81065542016-06-21 10:54:13 +02002275
Jesse Barnes308e5bc2011-11-14 14:51:28 -08002276extern uint32_t drm_mode_legacy_fb_format(uint32_t bpp, uint32_t depth);
Dave Airlie138f9eb2014-10-20 16:17:17 +10002277
2278extern struct drm_tile_group *drm_mode_create_tile_group(struct drm_device *dev,
2279 char topology[8]);
2280extern struct drm_tile_group *drm_mode_get_tile_group(struct drm_device *dev,
2281 char topology[8]);
2282extern void drm_mode_put_tile_group(struct drm_device *dev,
2283 struct drm_tile_group *tg);
Dave Airlieff72145b2011-02-07 12:16:14 +10002284
Thomas Wood3a5f87c2014-08-20 14:45:00 +01002285extern int drm_mode_plane_set_obj_prop(struct drm_plane *plane,
2286 struct drm_property *property,
2287 uint64_t value);
Dave Airlie248dbc22011-11-29 20:02:54 +00002288
Ville Syrjäläc1df5f32014-07-08 10:31:53 +05302289extern struct drm_property *drm_mode_create_rotation_property(struct drm_device *dev,
2290 unsigned int supported_rotations);
Ville Syrjälä3c9855f2014-07-08 10:31:56 +05302291extern unsigned int drm_rotation_simplify(unsigned int rotation,
2292 unsigned int supported_rotations);
Jyri Sarhaf8ed34a2016-06-07 15:09:14 +03002293extern void drm_crtc_enable_color_mgmt(struct drm_crtc *crtc,
2294 uint degamma_lut_size,
2295 bool has_ctm,
2296 uint gamma_lut_size);
Marek Szyprowski44d1240d2016-06-13 11:11:26 +02002297
2298int drm_plane_create_zpos_property(struct drm_plane *plane,
2299 unsigned int zpos,
2300 unsigned int min, unsigned int max);
2301
2302int drm_plane_create_zpos_immutable_property(struct drm_plane *plane,
2303 unsigned int zpos);
2304
Russell King96f60e32012-08-15 13:59:49 +01002305/* Helpers */
Rob Clarka2b34e22013-10-05 16:36:52 -04002306static inline struct drm_plane *drm_plane_find(struct drm_device *dev,
2307 uint32_t id)
2308{
2309 struct drm_mode_object *mo;
2310 mo = drm_mode_object_find(dev, id, DRM_MODE_OBJECT_PLANE);
2311 return mo ? obj_to_plane(mo) : NULL;
2312}
2313
Russell King96f60e32012-08-15 13:59:49 +01002314static inline struct drm_crtc *drm_crtc_find(struct drm_device *dev,
2315 uint32_t id)
2316{
2317 struct drm_mode_object *mo;
2318 mo = drm_mode_object_find(dev, id, DRM_MODE_OBJECT_CRTC);
2319 return mo ? obj_to_crtc(mo) : NULL;
2320}
2321
2322static inline struct drm_encoder *drm_encoder_find(struct drm_device *dev,
2323 uint32_t id)
2324{
2325 struct drm_mode_object *mo;
2326 mo = drm_mode_object_find(dev, id, DRM_MODE_OBJECT_ENCODER);
2327 return mo ? obj_to_encoder(mo) : NULL;
2328}
2329
Rob Clarka2b34e22013-10-05 16:36:52 -04002330static inline struct drm_property *drm_property_find(struct drm_device *dev,
2331 uint32_t id)
2332{
2333 struct drm_mode_object *mo;
2334 mo = drm_mode_object_find(dev, id, DRM_MODE_OBJECT_PROPERTY);
2335 return mo ? obj_to_property(mo) : NULL;
2336}
2337
Lionel Landwerlin5488dc12016-02-26 17:05:00 +00002338/*
2339 * Extract a degamma/gamma LUT value provided by user and round it to the
2340 * precision supported by the hardware.
2341 */
2342static inline uint32_t drm_color_lut_extract(uint32_t user_input,
2343 uint32_t bit_precision)
2344{
Lionel Landwerlin644a8052016-03-22 14:10:33 +00002345 uint32_t val = user_input;
Lionel Landwerlin5488dc12016-02-26 17:05:00 +00002346 uint32_t max = 0xffff >> (16 - bit_precision);
2347
Lionel Landwerlin644a8052016-03-22 14:10:33 +00002348 /* Round only if we're not using full precision. */
2349 if (bit_precision < 16) {
2350 val += 1UL << (16 - bit_precision - 1);
2351 val >>= 16 - bit_precision;
2352 }
Lionel Landwerlin5488dc12016-02-26 17:05:00 +00002353
2354 return clamp_val(val, 0, max);
2355}
2356
Matt Ropere27dde32014-04-01 15:22:30 -07002357/* Plane list iterator for legacy (overlay only) planes. */
Daniel Vetter4ea50e92015-07-09 23:44:24 +02002358#define drm_for_each_legacy_plane(plane, dev) \
2359 list_for_each_entry(plane, &(dev)->mode_config.plane_list, head) \
Jani Nikula373701b2015-11-24 21:21:55 +02002360 for_each_if (plane->type == DRM_PLANE_TYPE_OVERLAY)
Matt Ropere27dde32014-04-01 15:22:30 -07002361
Daniel Vetter6295d602015-07-09 23:44:25 +02002362#define drm_for_each_plane(plane, dev) \
2363 list_for_each_entry(plane, &(dev)->mode_config.plane_list, head)
2364
2365#define drm_for_each_crtc(crtc, dev) \
2366 list_for_each_entry(crtc, &(dev)->mode_config.crtc_list, head)
2367
Daniel Vetter7a3f3d62015-07-09 23:44:28 +02002368static inline void
2369assert_drm_connector_list_read_locked(struct drm_mode_config *mode_config)
2370{
Daniel Vettercff20ba2015-07-09 23:44:33 +02002371 /*
2372 * The connector hotadd/remove code currently grabs both locks when
2373 * updating lists. Hence readers need only hold either of them to be
2374 * safe and the check amounts to
2375 *
2376 * WARN_ON(not_holding(A) && not_holding(B)).
2377 */
2378 WARN_ON(!mutex_is_locked(&mode_config->mutex) &&
2379 !drm_modeset_is_locked(&mode_config->connection_mutex));
Daniel Vetter7a3f3d62015-07-09 23:44:28 +02002380}
2381
Daniel Vetter6295d602015-07-09 23:44:25 +02002382#define drm_for_each_connector(connector, dev) \
Daniel Vetter7a3f3d62015-07-09 23:44:28 +02002383 for (assert_drm_connector_list_read_locked(&(dev)->mode_config), \
2384 connector = list_first_entry(&(dev)->mode_config.connector_list, \
2385 struct drm_connector, head); \
2386 &connector->head != (&(dev)->mode_config.connector_list); \
2387 connector = list_next_entry(connector, head))
Daniel Vetter6295d602015-07-09 23:44:25 +02002388
2389#define drm_for_each_encoder(encoder, dev) \
2390 list_for_each_entry(encoder, &(dev)->mode_config.encoder_list, head)
2391
2392#define drm_for_each_fb(fb, dev) \
Daniel Vetter4676ba02015-07-09 23:44:30 +02002393 for (WARN_ON(!mutex_is_locked(&(dev)->mode_config.fb_lock)), \
2394 fb = list_first_entry(&(dev)->mode_config.fb_list, \
2395 struct drm_framebuffer, head); \
2396 &fb->head != (&(dev)->mode_config.fb_list); \
2397 fb = list_next_entry(fb, head))
Daniel Vetter6295d602015-07-09 23:44:25 +02002398
Daniel Vetter81065542016-06-21 10:54:13 +02002399/* drm_edid.c */
2400bool drm_probe_ddc(struct i2c_adapter *adapter);
2401struct edid *drm_get_edid(struct drm_connector *connector,
2402 struct i2c_adapter *adapter);
2403struct edid *drm_get_edid_switcheroo(struct drm_connector *connector,
2404 struct i2c_adapter *adapter);
2405struct edid *drm_edid_duplicate(const struct edid *edid);
2406int drm_add_edid_modes(struct drm_connector *connector, struct edid *edid);
2407
2408u8 drm_match_cea_mode(const struct drm_display_mode *to_match);
2409enum hdmi_picture_aspect drm_get_cea_aspect_ratio(const u8 video_code);
2410bool drm_detect_hdmi_monitor(struct edid *edid);
2411bool drm_detect_monitor_audio(struct edid *edid);
2412bool drm_rgb_quant_range_selectable(struct edid *edid);
2413int drm_add_modes_noedid(struct drm_connector *connector,
2414 int hdisplay, int vdisplay);
2415void drm_set_preferred_mode(struct drm_connector *connector,
2416 int hpref, int vpref);
2417
2418int drm_edid_header_is_valid(const u8 *raw_edid);
2419bool drm_edid_block_valid(u8 *raw_edid, int block, bool print_bad_edid,
2420 bool *edid_corrupt);
2421bool drm_edid_is_valid(struct edid *edid);
2422void drm_edid_get_monitor_name(struct edid *edid, char *name,
2423 int buflen);
2424struct drm_display_mode *drm_mode_find_dmt(struct drm_device *dev,
2425 int hsize, int vsize, int fresh,
2426 bool rb);
2427
2428/* drm_bridge.c */
2429extern int drm_bridge_add(struct drm_bridge *bridge);
2430extern void drm_bridge_remove(struct drm_bridge *bridge);
2431extern struct drm_bridge *of_drm_find_bridge(struct device_node *np);
2432extern int drm_bridge_attach(struct drm_device *dev, struct drm_bridge *bridge);
2433
2434bool drm_bridge_mode_fixup(struct drm_bridge *bridge,
2435 const struct drm_display_mode *mode,
2436 struct drm_display_mode *adjusted_mode);
2437void drm_bridge_disable(struct drm_bridge *bridge);
2438void drm_bridge_post_disable(struct drm_bridge *bridge);
2439void drm_bridge_mode_set(struct drm_bridge *bridge,
2440 struct drm_display_mode *mode,
2441 struct drm_display_mode *adjusted_mode);
2442void drm_bridge_pre_enable(struct drm_bridge *bridge);
2443void drm_bridge_enable(struct drm_bridge *bridge);
2444
Dave Airlief453ba02008-11-07 14:05:41 -08002445#endif /* __DRM_CRTC_H__ */