blob: a2d1108c7c2cb9fe46ecbecc8c1412b6a7dbe32d [file] [log] [blame]
Dave Airlief453ba02008-11-07 14:05:41 -08001/*
2 * Copyright © 2006 Keith Packard
3 * Copyright © 2007-2008 Dave Airlie
4 * Copyright © 2007-2008 Intel Corporation
5 * Jesse Barnes <jesse.barnes@intel.com>
6 *
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the "Software"),
9 * to deal in the Software without restriction, including without limitation
10 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
11 * and/or sell copies of the Software, and to permit persons to whom the
12 * Software is furnished to do so, subject to the following conditions:
13 *
14 * The above copyright notice and this permission notice shall be included in
15 * all copies or substantial portions of the Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
21 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
22 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
23 * OTHER DEALINGS IN THE SOFTWARE.
24 */
25#ifndef __DRM_CRTC_H__
26#define __DRM_CRTC_H__
27
28#include <linux/i2c.h>
29#include <linux/spinlock.h>
30#include <linux/types.h>
31#include <linux/idr.h>
Dave Airlief453ba02008-11-07 14:05:41 -080032#include <linux/fb.h>
Vandana Kannan985e5dc2013-12-19 15:34:07 +053033#include <linux/hdmi.h>
Boris Brezillonb5571e92014-07-22 12:09:10 +020034#include <linux/media-bus-format.h>
David Herrmannd7d2c482014-08-29 12:12:40 +020035#include <uapi/drm/drm_mode.h>
36#include <uapi/drm/drm_fourcc.h>
Rob Clark51fd3712013-11-19 12:10:12 -050037#include <drm/drm_modeset_lock.h>
Ville Syrjäläd7da8242016-07-26 19:06:57 +030038#include <drm/drm_rect.h>
Daniel Vetter949619f2016-08-29 10:27:51 +020039#include <drm/drm_mode_object.h>
Daniel Vetter7520a272016-08-15 16:07:02 +020040#include <drm/drm_framebuffer.h>
41#include <drm/drm_modes.h>
Daniel Vetter52217192016-08-12 22:48:50 +020042#include <drm/drm_connector.h>
Daniel Vetter321a95a2016-08-29 10:27:49 +020043#include <drm/drm_encoder.h>
Daniel Vetter59e71ee2016-08-29 10:27:55 +020044#include <drm/drm_property.h>
Daniel Vetter199e4e92016-08-31 18:09:05 +020045#include <drm/drm_bridge.h>
Jesse Barnes308e5bc2011-11-14 14:51:28 -080046
Dave Airlief453ba02008-11-07 14:05:41 -080047struct drm_device;
48struct drm_mode_set;
Thierry Reding595887e2012-11-21 15:00:47 +010049struct drm_file;
50struct drm_clip_rect;
Russell King7e435aa2014-06-15 11:07:12 +010051struct device_node;
Daniel Vettere2330f02014-10-29 11:34:56 +010052struct fence;
Daniel Vetter81065542016-06-21 10:54:13 +020053struct edid;
Dave Airlief453ba02008-11-07 14:05:41 -080054
Rob Clarkebc44cf2012-09-12 22:22:31 -050055static inline int64_t U642I64(uint64_t val)
56{
57 return (int64_t)*((int64_t *)&val);
58}
59static inline uint64_t I642U64(int64_t val)
60{
61 return (uint64_t)*((uint64_t *)&val);
62}
63
Robert Feketed9c38242015-11-02 16:14:08 +010064/*
65 * Rotation property bits. DRM_ROTATE_<degrees> rotates the image by the
66 * specified amount in degrees in counter clockwise direction. DRM_REFLECT_X and
67 * DRM_REFLECT_Y reflects the image along the specified axis prior to rotation
68 */
Joonas Lahtinen31ad61e2016-07-29 08:50:05 +030069#define DRM_ROTATE_0 BIT(0)
70#define DRM_ROTATE_90 BIT(1)
71#define DRM_ROTATE_180 BIT(2)
72#define DRM_ROTATE_270 BIT(3)
73#define DRM_ROTATE_MASK (DRM_ROTATE_0 | DRM_ROTATE_90 | \
74 DRM_ROTATE_180 | DRM_ROTATE_270)
75#define DRM_REFLECT_X BIT(4)
76#define DRM_REFLECT_Y BIT(5)
77#define DRM_REFLECT_MASK (DRM_REFLECT_X | DRM_REFLECT_Y)
Ville Syrjälä06596962014-07-08 10:31:51 +053078
Dave Airlie138f9eb2014-10-20 16:17:17 +100079/* data corresponds to displayid vend/prod/serial */
80struct drm_tile_group {
81 struct kref refcount;
82 struct drm_device *dev;
83 int id;
84 u8 group_data[8];
85};
86
Dave Airlief453ba02008-11-07 14:05:41 -080087struct drm_crtc;
Dave Airlief453ba02008-11-07 14:05:41 -080088struct drm_encoder;
Kristian Høgsbergd91d8a32009-11-17 12:43:55 -050089struct drm_pending_vblank_event;
Jesse Barnes8cf5c912011-11-14 14:51:27 -080090struct drm_plane;
Sean Paul3b336ec2013-08-14 16:47:37 -040091struct drm_bridge;
Daniel Vetter144ecb92014-10-27 20:28:44 +010092struct drm_atomic_state;
93
Daniel Vetter4490d4c2015-12-04 09:45:45 +010094struct drm_crtc_helper_funcs;
95struct drm_encoder_helper_funcs;
Daniel Vetter4490d4c2015-12-04 09:45:45 +010096struct drm_plane_helper_funcs;
97
Daniel Vetter144ecb92014-10-27 20:28:44 +010098/**
Daniel Vettercc4ceb42014-07-25 21:30:38 +020099 * struct drm_crtc_state - mutable CRTC state
Daniel Vetter07cc0ef2014-11-27 15:49:39 +0100100 * @crtc: backpointer to the CRTC
Daniel Vetter144ecb92014-10-27 20:28:44 +0100101 * @enable: whether the CRTC should be enabled, gates all other state
Daniel Vetterd9b13622014-11-26 16:57:41 +0100102 * @active: whether the CRTC is actively displaying (used for DPMS)
Maarten Lankhorstfc596662015-07-21 13:28:57 +0200103 * @planes_changed: planes on this crtc are updated
104 * @mode_changed: crtc_state->mode or crtc_state->enable has been changed
105 * @active_changed: crtc_state->active has been toggled.
106 * @connectors_changed: connectors to this crtc have been updated
Marek Szyprowski44d1240d2016-06-13 11:11:26 +0200107 * @zpos_changed: zpos values of planes on this crtc have been updated
Lionel Landwerlin5488dc12016-02-26 17:05:00 +0000108 * @color_mgmt_changed: color management properties have changed (degamma or
109 * gamma LUT or CSC matrix)
Rob Clark6ddd3882014-11-21 15:28:31 -0500110 * @plane_mask: bitmask of (1 << drm_plane_index(plane)) of attached planes
Maarten Lankhorst4cd9fa52016-01-04 12:53:18 +0100111 * @connector_mask: bitmask of (1 << drm_connector_index(connector)) of attached connectors
Maarten Lankhorste87a52b2016-01-28 15:04:58 +0100112 * @encoder_mask: bitmask of (1 << drm_encoder_index(encoder)) of attached encoders
Daniel Vetter623369e2014-09-16 17:50:47 +0200113 * @last_vblank_count: for helpers and drivers to capture the vblank of the
114 * update to ensure framebuffer cleanup isn't done too early
Daniel Vetter2f324b42014-10-29 11:13:47 +0100115 * @adjusted_mode: for use by helpers and drivers to compute adjusted mode timings
Daniel Vetter144ecb92014-10-27 20:28:44 +0100116 * @mode: current mode timings
Daniel Vetterac3ba4a2016-05-31 23:11:10 +0200117 * @mode_blob: &drm_property_blob for @mode
Lionel Landwerlin5488dc12016-02-26 17:05:00 +0000118 * @degamma_lut: Lookup table for converting framebuffer pixel data
119 * before apply the conversion matrix
120 * @ctm: Transformation matrix
121 * @gamma_lut: Lookup table for converting pixel data after the
122 * conversion matrix
Daniel Vetter144ecb92014-10-27 20:28:44 +0100123 * @event: optional pointer to a DRM event to signal upon completion of the
124 * state update
125 * @state: backpointer to global drm_atomic_state
Daniel Vetterd9b13622014-11-26 16:57:41 +0100126 *
127 * Note that the distinction between @enable and @active is rather subtile:
128 * Flipping @active while @enable is set without changing anything else may
129 * never return in a failure from the ->atomic_check callback. Userspace assumes
130 * that a DPMS On will always succeed. In other words: @enable controls resource
131 * assignment, @active controls the actual hardware state.
Daniel Vetter144ecb92014-10-27 20:28:44 +0100132 */
133struct drm_crtc_state {
Daniel Vetter07cc0ef2014-11-27 15:49:39 +0100134 struct drm_crtc *crtc;
135
Daniel Vettercc4ceb42014-07-25 21:30:38 +0200136 bool enable;
Daniel Vetterd9b13622014-11-26 16:57:41 +0100137 bool active;
Daniel Vetter144ecb92014-10-27 20:28:44 +0100138
Daniel Vetterc2fcd272014-11-05 00:14:14 +0100139 /* computed state bits used by helpers and drivers */
140 bool planes_changed : 1;
Daniel Vetter623369e2014-09-16 17:50:47 +0200141 bool mode_changed : 1;
Daniel Vettereab3bbe2015-01-22 16:36:21 +0100142 bool active_changed : 1;
Maarten Lankhorstfc596662015-07-21 13:28:57 +0200143 bool connectors_changed : 1;
Marek Szyprowski44d1240d2016-06-13 11:11:26 +0200144 bool zpos_changed : 1;
Lionel Landwerlin5488dc12016-02-26 17:05:00 +0000145 bool color_mgmt_changed : 1;
Daniel Vetter623369e2014-09-16 17:50:47 +0200146
Rob Clark6ddd3882014-11-21 15:28:31 -0500147 /* attached planes bitmask:
148 * WARNING: transitional helpers do not maintain plane_mask so
149 * drivers not converted over to atomic helpers should not rely
150 * on plane_mask being accurate!
151 */
152 u32 plane_mask;
153
Maarten Lankhorst4cd9fa52016-01-04 12:53:18 +0100154 u32 connector_mask;
Maarten Lankhorste87a52b2016-01-28 15:04:58 +0100155 u32 encoder_mask;
Maarten Lankhorst4cd9fa52016-01-04 12:53:18 +0100156
Daniel Vetter623369e2014-09-16 17:50:47 +0200157 /* last_vblank_count: for vblank waits before cleanup */
158 u32 last_vblank_count;
Daniel Vetterc2fcd272014-11-05 00:14:14 +0100159
Daniel Vetter2f324b42014-10-29 11:13:47 +0100160 /* adjusted_mode: for use by helpers and drivers */
161 struct drm_display_mode adjusted_mode;
162
Daniel Vetter144ecb92014-10-27 20:28:44 +0100163 struct drm_display_mode mode;
164
Daniel Stone99cf4a22015-05-25 19:11:51 +0100165 /* blob property to expose current mode to atomic userspace */
166 struct drm_property_blob *mode_blob;
167
Lionel Landwerlin5488dc12016-02-26 17:05:00 +0000168 /* blob property to expose color management to userspace */
169 struct drm_property_blob *degamma_lut;
170 struct drm_property_blob *ctm;
171 struct drm_property_blob *gamma_lut;
172
Daniel Vetter144ecb92014-10-27 20:28:44 +0100173 struct drm_pending_vblank_event *event;
174
175 struct drm_atomic_state *state;
176};
Dave Airlief453ba02008-11-07 14:05:41 -0800177
178/**
Daniel Vetter3bf04012014-10-27 16:54:27 +0100179 * struct drm_crtc_funcs - control CRTCs for a given device
Dave Airlief453ba02008-11-07 14:05:41 -0800180 *
181 * The drm_crtc_funcs structure is the central CRTC management structure
182 * in the DRM. Each CRTC controls one or more connectors (note that the name
183 * CRTC is simply historical, a CRTC may control LVDS, VGA, DVI, TV out, etc.
184 * connectors, not just CRTs).
185 *
186 * Each driver is responsible for filling out this structure at startup time,
187 * in addition to providing other modesetting features, like i2c and DDC
188 * bus accessors.
189 */
190struct drm_crtc_funcs {
Daniel Vetter88548632015-12-04 09:45:48 +0100191 /**
192 * @reset:
193 *
194 * Reset CRTC hardware and software state to off. This function isn't
195 * called by the core directly, only through drm_mode_config_reset().
196 * It's not a helper hook only for historical reasons.
197 *
198 * Atomic drivers can use drm_atomic_helper_crtc_reset() to reset
199 * atomic state using this hook.
200 */
Chris Wilsoneb033552011-01-24 15:11:08 +0000201 void (*reset)(struct drm_crtc *crtc);
Dave Airlief453ba02008-11-07 14:05:41 -0800202
Daniel Vetterf6da8c62015-12-04 09:46:00 +0100203 /**
204 * @cursor_set:
205 *
206 * Update the cursor image. The cursor position is relative to the CRTC
207 * and can be partially or fully outside of the visible area.
208 *
209 * Note that contrary to all other KMS functions the legacy cursor entry
210 * points don't take a framebuffer object, but instead take directly a
211 * raw buffer object id from the driver's buffer manager (which is
212 * either GEM or TTM for current drivers).
213 *
214 * This entry point is deprecated, drivers should instead implement
215 * universal plane support and register a proper cursor plane using
216 * drm_crtc_init_with_planes().
217 *
218 * This callback is optional
219 *
220 * RETURNS:
221 *
222 * 0 on success or a negative error code on failure.
223 */
Dave Airlief453ba02008-11-07 14:05:41 -0800224 int (*cursor_set)(struct drm_crtc *crtc, struct drm_file *file_priv,
225 uint32_t handle, uint32_t width, uint32_t height);
Daniel Vetterf6da8c62015-12-04 09:46:00 +0100226
227 /**
228 * @cursor_set2:
229 *
230 * Update the cursor image, including hotspot information. The hotspot
231 * must not affect the cursor position in CRTC coordinates, but is only
232 * meant as a hint for virtualized display hardware to coordinate the
233 * guests and hosts cursor position. The cursor hotspot is relative to
234 * the cursor image. Otherwise this works exactly like @cursor_set.
235 *
236 * This entry point is deprecated, drivers should instead implement
237 * universal plane support and register a proper cursor plane using
238 * drm_crtc_init_with_planes().
239 *
240 * This callback is optional.
241 *
242 * RETURNS:
243 *
244 * 0 on success or a negative error code on failure.
245 */
Dave Airlie4c813d42013-06-20 11:48:52 +1000246 int (*cursor_set2)(struct drm_crtc *crtc, struct drm_file *file_priv,
247 uint32_t handle, uint32_t width, uint32_t height,
248 int32_t hot_x, int32_t hot_y);
Daniel Vetterf6da8c62015-12-04 09:46:00 +0100249
250 /**
251 * @cursor_move:
252 *
253 * Update the cursor position. The cursor does not need to be visible
254 * when this hook is called.
255 *
256 * This entry point is deprecated, drivers should instead implement
257 * universal plane support and register a proper cursor plane using
258 * drm_crtc_init_with_planes().
259 *
260 * This callback is optional.
261 *
262 * RETURNS:
263 *
264 * 0 on success or a negative error code on failure.
265 */
Dave Airlief453ba02008-11-07 14:05:41 -0800266 int (*cursor_move)(struct drm_crtc *crtc, int x, int y);
267
Daniel Vetterf6da8c62015-12-04 09:46:00 +0100268 /**
269 * @gamma_set:
270 *
271 * Set gamma on the CRTC.
272 *
273 * This callback is optional.
274 *
275 * NOTE:
276 *
277 * Drivers that support gamma tables and also fbdev emulation through
278 * the provided helper library need to take care to fill out the gamma
279 * hooks for both. Currently there's a bit an unfortunate duplication
280 * going on, which should eventually be unified to just one set of
281 * hooks.
282 */
Maarten Lankhorst7ea77282016-06-07 12:49:30 +0200283 int (*gamma_set)(struct drm_crtc *crtc, u16 *r, u16 *g, u16 *b,
284 uint32_t size);
Daniel Vetter88548632015-12-04 09:45:48 +0100285
286 /**
287 * @destroy:
288 *
289 * Clean up plane resources. This is only called at driver unload time
290 * through drm_mode_config_cleanup() since a CRTC cannot be hotplugged
291 * in DRM.
292 */
Dave Airlief453ba02008-11-07 14:05:41 -0800293 void (*destroy)(struct drm_crtc *crtc);
294
Daniel Vetterf6da8c62015-12-04 09:46:00 +0100295 /**
296 * @set_config:
297 *
298 * This is the main legacy entry point to change the modeset state on a
299 * CRTC. All the details of the desired configuration are passed in a
300 * struct &drm_mode_set - see there for details.
301 *
302 * Drivers implementing atomic modeset should use
303 * drm_atomic_helper_set_config() to implement this hook.
304 *
305 * RETURNS:
306 *
307 * 0 on success or a negative error code on failure.
308 */
Dave Airlief453ba02008-11-07 14:05:41 -0800309 int (*set_config)(struct drm_mode_set *set);
Kristian Høgsbergd91d8a32009-11-17 12:43:55 -0500310
Daniel Vetterf6da8c62015-12-04 09:46:00 +0100311 /**
312 * @page_flip:
313 *
314 * Legacy entry point to schedule a flip to the given framebuffer.
315 *
316 * Page flipping is a synchronization mechanism that replaces the frame
317 * buffer being scanned out by the CRTC with a new frame buffer during
318 * vertical blanking, avoiding tearing (except when requested otherwise
319 * through the DRM_MODE_PAGE_FLIP_ASYNC flag). When an application
320 * requests a page flip the DRM core verifies that the new frame buffer
321 * is large enough to be scanned out by the CRTC in the currently
322 * configured mode and then calls the CRTC ->page_flip() operation with a
323 * pointer to the new frame buffer.
324 *
325 * The driver must wait for any pending rendering to the new framebuffer
326 * to complete before executing the flip. It should also wait for any
327 * pending rendering from other drivers if the underlying buffer is a
328 * shared dma-buf.
329 *
330 * An application can request to be notified when the page flip has
331 * completed. The drm core will supply a struct &drm_event in the event
332 * parameter in this case. This can be handled by the
333 * drm_crtc_send_vblank_event() function, which the driver should call on
334 * the provided event upon completion of the flip. Note that if
335 * the driver supports vblank signalling and timestamping the vblank
336 * counters and timestamps must agree with the ones returned from page
337 * flip events. With the current vblank helper infrastructure this can
338 * be achieved by holding a vblank reference while the page flip is
339 * pending, acquired through drm_crtc_vblank_get() and released with
340 * drm_crtc_vblank_put(). Drivers are free to implement their own vblank
341 * counter and timestamp tracking though, e.g. if they have accurate
342 * timestamp registers in hardware.
343 *
Daniel Vetterf6da8c62015-12-04 09:46:00 +0100344 * This callback is optional.
345 *
346 * NOTE:
347 *
348 * Very early versions of the KMS ABI mandated that the driver must
349 * block (but not reject) any rendering to the old framebuffer until the
350 * flip operation has completed and the old framebuffer is no longer
351 * visible. This requirement has been lifted, and userspace is instead
352 * expected to request delivery of an event and wait with recycling old
353 * buffers until such has been received.
354 *
355 * RETURNS:
356 *
357 * 0 on success or a negative error code on failure. Note that if a
358 * ->page_flip() operation is already pending the callback should return
359 * -EBUSY. Pageflips on a disabled CRTC (either by setting a NULL mode
360 * or just runtime disabled through DPMS respectively the new atomic
Daniel Vetter4cba6852015-12-08 09:49:20 +0100361 * "ACTIVE" state) should result in an -EINVAL error code. Note that
362 * drm_atomic_helper_page_flip() checks this already for atomic drivers.
Kristian Høgsbergd91d8a32009-11-17 12:43:55 -0500363 */
364 int (*page_flip)(struct drm_crtc *crtc,
365 struct drm_framebuffer *fb,
Keith Packarded8d1972013-07-22 18:49:58 -0700366 struct drm_pending_vblank_event *event,
367 uint32_t flags);
Paulo Zanonibffd9de02012-05-15 18:09:05 -0300368
Daniel Vetter88548632015-12-04 09:45:48 +0100369 /**
Michel Dänzerc229bfb2016-08-08 16:23:03 +0900370 * @page_flip_target:
371 *
372 * Same as @page_flip but with an additional parameter specifying the
373 * absolute target vertical blank period (as reported by
374 * drm_crtc_vblank_count()) when the flip should take effect.
375 *
376 * Note that the core code calls drm_crtc_vblank_get before this entry
377 * point, and will call drm_crtc_vblank_put if this entry point returns
378 * any non-0 error code. It's the driver's responsibility to call
379 * drm_crtc_vblank_put after this entry point returns 0, typically when
380 * the flip completes.
381 */
382 int (*page_flip_target)(struct drm_crtc *crtc,
383 struct drm_framebuffer *fb,
384 struct drm_pending_vblank_event *event,
385 uint32_t flags, uint32_t target);
386
387 /**
Daniel Vetter88548632015-12-04 09:45:48 +0100388 * @set_property:
389 *
390 * This is the legacy entry point to update a property attached to the
391 * CRTC.
392 *
393 * Drivers implementing atomic modeset should use
394 * drm_atomic_helper_crtc_set_property() to implement this hook.
395 *
396 * This callback is optional if the driver does not support any legacy
397 * driver-private properties.
398 *
399 * RETURNS:
400 *
401 * 0 on success or a negative error code on failure.
402 */
Paulo Zanonibffd9de02012-05-15 18:09:05 -0300403 int (*set_property)(struct drm_crtc *crtc,
404 struct drm_property *property, uint64_t val);
Daniel Vetter144ecb92014-10-27 20:28:44 +0100405
Daniel Vetter88548632015-12-04 09:45:48 +0100406 /**
407 * @atomic_duplicate_state:
408 *
409 * Duplicate the current atomic state for this CRTC and return it.
410 * The core and helpers gurantee that any atomic state duplicated with
411 * this hook and still owned by the caller (i.e. not transferred to the
412 * driver by calling ->atomic_commit() from struct
413 * &drm_mode_config_funcs) will be cleaned up by calling the
414 * @atomic_destroy_state hook in this structure.
415 *
416 * Atomic drivers which don't subclass struct &drm_crtc should use
417 * drm_atomic_helper_crtc_duplicate_state(). Drivers that subclass the
418 * state structure to extend it with driver-private state should use
419 * __drm_atomic_helper_crtc_duplicate_state() to make sure shared state is
420 * duplicated in a consistent fashion across drivers.
421 *
422 * It is an error to call this hook before crtc->state has been
423 * initialized correctly.
424 *
425 * NOTE:
426 *
427 * If the duplicate state references refcounted resources this hook must
428 * acquire a reference for each of them. The driver must release these
429 * references again in @atomic_destroy_state.
430 *
431 * RETURNS:
432 *
433 * Duplicated atomic state or NULL when the allocation failed.
434 */
Daniel Vetter144ecb92014-10-27 20:28:44 +0100435 struct drm_crtc_state *(*atomic_duplicate_state)(struct drm_crtc *crtc);
Daniel Vetter88548632015-12-04 09:45:48 +0100436
437 /**
438 * @atomic_destroy_state:
439 *
440 * Destroy a state duplicated with @atomic_duplicate_state and release
441 * or unreference all resources it references
442 */
Daniel Vetter144ecb92014-10-27 20:28:44 +0100443 void (*atomic_destroy_state)(struct drm_crtc *crtc,
Daniel Vettercc4ceb42014-07-25 21:30:38 +0200444 struct drm_crtc_state *state);
Daniel Vetter88548632015-12-04 09:45:48 +0100445
446 /**
447 * @atomic_set_property:
448 *
449 * Decode a driver-private property value and store the decoded value
450 * into the passed-in state structure. Since the atomic core decodes all
451 * standardized properties (even for extensions beyond the core set of
452 * properties which might not be implemented by all drivers) this
453 * requires drivers to subclass the state structure.
454 *
455 * Such driver-private properties should really only be implemented for
456 * truly hardware/vendor specific state. Instead it is preferred to
457 * standardize atomic extension and decode the properties used to expose
458 * such an extension in the core.
459 *
460 * Do not call this function directly, use
461 * drm_atomic_crtc_set_property() instead.
462 *
463 * This callback is optional if the driver does not support any
464 * driver-private atomic properties.
465 *
466 * NOTE:
467 *
468 * This function is called in the state assembly phase of atomic
469 * modesets, which can be aborted for any reason (including on
470 * userspace's request to just check whether a configuration would be
471 * possible). Drivers MUST NOT touch any persistent state (hardware or
472 * software) or data structures except the passed in @state parameter.
473 *
474 * Also since userspace controls in which order properties are set this
475 * function must not do any input validation (since the state update is
476 * incomplete and hence likely inconsistent). Instead any such input
477 * validation must be done in the various atomic_check callbacks.
478 *
479 * RETURNS:
480 *
481 * 0 if the property has been found, -EINVAL if the property isn't
482 * implemented by the driver (which should never happen, the core only
483 * asks for properties attached to this CRTC). No other validation is
484 * allowed by the driver. The core already checks that the property
485 * value is within the range (integer, valid enum value, ...) the driver
486 * set when registering the property.
487 */
Daniel Vetter144ecb92014-10-27 20:28:44 +0100488 int (*atomic_set_property)(struct drm_crtc *crtc,
489 struct drm_crtc_state *state,
490 struct drm_property *property,
491 uint64_t val);
Daniel Vetter88548632015-12-04 09:45:48 +0100492 /**
493 * @atomic_get_property:
494 *
495 * Reads out the decoded driver-private property. This is used to
Daniel Vetterc6b0ca32015-12-04 09:46:01 +0100496 * implement the GETCRTC IOCTL.
Daniel Vetter88548632015-12-04 09:45:48 +0100497 *
498 * Do not call this function directly, use
499 * drm_atomic_crtc_get_property() instead.
500 *
501 * This callback is optional if the driver does not support any
502 * driver-private atomic properties.
503 *
504 * RETURNS:
505 *
506 * 0 on success, -EINVAL if the property isn't implemented by the
507 * driver (which should never happen, the core only asks for
508 * properties attached to this CRTC).
509 */
Rob Clarkac9c9252014-12-18 16:01:47 -0500510 int (*atomic_get_property)(struct drm_crtc *crtc,
511 const struct drm_crtc_state *state,
512 struct drm_property *property,
513 uint64_t *val);
Benjamin Gaignard79190ea2016-06-21 16:37:09 +0200514
515 /**
516 * @late_register:
517 *
518 * This optional hook can be used to register additional userspace
519 * interfaces attached to the crtc like debugfs interfaces.
520 * It is called late in the driver load sequence from drm_dev_register().
521 * Everything added from this callback should be unregistered in
522 * the early_unregister callback.
523 *
524 * Returns:
525 *
526 * 0 on success, or a negative error code on failure.
527 */
528 int (*late_register)(struct drm_crtc *crtc);
529
530 /**
531 * @early_unregister:
532 *
533 * This optional hook should be used to unregister the additional
534 * userspace interfaces attached to the crtc from
535 * late_unregister(). It is called from drm_dev_unregister(),
536 * early in the driver unload sequence to disable userspace access
537 * before data structures are torndown.
538 */
539 void (*early_unregister)(struct drm_crtc *crtc);
Dave Airlief453ba02008-11-07 14:05:41 -0800540};
541
542/**
Daniel Vetter3bf04012014-10-27 16:54:27 +0100543 * struct drm_crtc - central CRTC control structure
Jesse Barnes77491632011-11-07 12:03:14 -0800544 * @dev: parent DRM device
Daniel Vetter2c0c33d2014-10-27 20:19:38 +0100545 * @port: OF node used by drm_of_find_possible_crtcs()
Jesse Barnes77491632011-11-07 12:03:14 -0800546 * @head: list management
Daniel Vetterac3ba4a2016-05-31 23:11:10 +0200547 * @name: human readable name, can be overwritten by the driver
Rob Clark51fd3712013-11-19 12:10:12 -0500548 * @mutex: per-CRTC locking
Jesse Barnes77491632011-11-07 12:03:14 -0800549 * @base: base KMS object for ID tracking etc.
Matt Ropere13161a2014-04-01 15:22:38 -0700550 * @primary: primary plane for this CRTC
551 * @cursor: cursor plane for this CRTC
Daniel Vetter2c0c33d2014-10-27 20:19:38 +0100552 * @cursor_x: current x position of the cursor, used for universal cursor planes
553 * @cursor_y: current y position of the cursor, used for universal cursor planes
Dave Airlief453ba02008-11-07 14:05:41 -0800554 * @enabled: is this CRTC enabled?
Jesse Barnes77491632011-11-07 12:03:14 -0800555 * @mode: current mode timings
556 * @hwmode: mode timings as programmed to hw regs
Dave Airlief453ba02008-11-07 14:05:41 -0800557 * @x: x position on screen
558 * @y: y position on screen
Dave Airlief453ba02008-11-07 14:05:41 -0800559 * @funcs: CRTC control functions
Jesse Barnes77491632011-11-07 12:03:14 -0800560 * @gamma_size: size of gamma ramp
561 * @gamma_store: gamma ramp values
Jesse Barnes77491632011-11-07 12:03:14 -0800562 * @helper_private: mid-layer private data
Paulo Zanonibffd9de02012-05-15 18:09:05 -0300563 * @properties: property tracking for this CRTC
Dave Airlief453ba02008-11-07 14:05:41 -0800564 *
565 * Each CRTC may have one or more connectors associated with it. This structure
566 * allows the CRTC to be controlled.
567 */
568struct drm_crtc {
569 struct drm_device *dev;
Russell King7e435aa2014-06-15 11:07:12 +0100570 struct device_node *port;
Dave Airlief453ba02008-11-07 14:05:41 -0800571 struct list_head head;
572
Ville Syrjäläfa3ab4c2015-12-08 18:41:53 +0200573 char *name;
574
Daniel Vetterac3ba4a2016-05-31 23:11:10 +0200575 /**
576 * @mutex:
Daniel Vetter29494c12012-12-02 02:18:25 +0100577 *
578 * This provides a read lock for the overall crtc state (mode, dpms
579 * state, ...) and a write lock for everything which can be update
Daniel Vetterac3ba4a2016-05-31 23:11:10 +0200580 * without a full modeset (fb, cursor data, crtc properties ...). Full
581 * modeset also need to grab dev->mode_config.connection_mutex.
Daniel Vetter29494c12012-12-02 02:18:25 +0100582 */
Rob Clark51fd3712013-11-19 12:10:12 -0500583 struct drm_modeset_lock mutex;
Daniel Vetter29494c12012-12-02 02:18:25 +0100584
Dave Airlief453ba02008-11-07 14:05:41 -0800585 struct drm_mode_object base;
586
Matt Ropere13161a2014-04-01 15:22:38 -0700587 /* primary and cursor planes for CRTC */
588 struct drm_plane *primary;
589 struct drm_plane *cursor;
590
Daniel Vetter96094082016-07-15 21:47:59 +0200591 /**
592 * @index: Position inside the mode_config.list, can be used as an array
593 * index. It is invariant over the lifetime of the CRTC.
594 */
Chris Wilson490d3d12016-05-27 20:05:00 +0100595 unsigned index;
596
Matt Roper161d0dc2014-06-10 08:28:10 -0700597 /* position of cursor plane on crtc */
598 int cursor_x;
599 int cursor_y;
600
Dave Airlief453ba02008-11-07 14:05:41 -0800601 bool enabled;
602
Mario Kleiner27641c32010-10-23 04:20:23 +0200603 /* Requested mode from modesetting. */
Dave Airlief453ba02008-11-07 14:05:41 -0800604 struct drm_display_mode mode;
605
Mario Kleiner27641c32010-10-23 04:20:23 +0200606 /* Programmed mode in hw, after adjustments for encoders,
607 * crtc, panel scaling etc. Needed for timestamping etc.
608 */
609 struct drm_display_mode hwmode;
610
Dave Airlief453ba02008-11-07 14:05:41 -0800611 int x, y;
Dave Airlief453ba02008-11-07 14:05:41 -0800612 const struct drm_crtc_funcs *funcs;
613
Lionel Landwerlin5488dc12016-02-26 17:05:00 +0000614 /* Legacy FB CRTC gamma size for reporting to userspace */
Dave Airlief453ba02008-11-07 14:05:41 -0800615 uint32_t gamma_size;
616 uint16_t *gamma_store;
617
618 /* if you are using the helper */
Daniel Vetter4490d4c2015-12-04 09:45:45 +0100619 const struct drm_crtc_helper_funcs *helper_private;
Paulo Zanonibffd9de02012-05-15 18:09:05 -0300620
621 struct drm_object_properties properties;
Daniel Vetterd059f652014-07-25 18:07:40 +0200622
Daniel Vetter3b24f7d2016-06-08 14:19:00 +0200623 /**
624 * @state:
625 *
626 * Current atomic state for this CRTC.
627 */
Daniel Vetter144ecb92014-10-27 20:28:44 +0100628 struct drm_crtc_state *state;
629
Daniel Vetter3b24f7d2016-06-08 14:19:00 +0200630 /**
631 * @commit_list:
632 *
633 * List of &drm_crtc_commit structures tracking pending commits.
634 * Protected by @commit_lock. This list doesn't hold its own full
635 * reference, but burrows it from the ongoing commit. Commit entries
636 * must be removed from this list once the commit is fully completed,
637 * but before it's correspoding &drm_atomic_state gets destroyed.
638 */
639 struct list_head commit_list;
640
641 /**
642 * @commit_lock:
643 *
644 * Spinlock to protect @commit_list.
645 */
646 spinlock_t commit_lock;
647
648 /**
649 * @acquire_ctx:
650 *
651 * Per-CRTC implicit acquire context used by atomic drivers for legacy
652 * IOCTLs, so that atomic drivers can get at the locking acquire
653 * context.
Daniel Vetterd059f652014-07-25 18:07:40 +0200654 */
655 struct drm_modeset_acquire_ctx *acquire_ctx;
Dave Airlief453ba02008-11-07 14:05:41 -0800656};
657
Daniel Vetter144ecb92014-10-27 20:28:44 +0100658/**
Daniel Vetter144ecb92014-10-27 20:28:44 +0100659 * struct drm_plane_state - mutable plane state
Daniel Vetter07cc0ef2014-11-27 15:49:39 +0100660 * @plane: backpointer to the plane
Daniel Vetter144ecb92014-10-27 20:28:44 +0100661 * @crtc: currently bound CRTC, NULL if disabled
Daniel Vettercc4ceb42014-07-25 21:30:38 +0200662 * @fb: currently bound framebuffer
Daniel Vettere2330f02014-10-29 11:34:56 +0100663 * @fence: optional fence to wait for before scanning out @fb
Daniel Vetter144ecb92014-10-27 20:28:44 +0100664 * @crtc_x: left position of visible portion of plane on crtc
665 * @crtc_y: upper position of visible portion of plane on crtc
666 * @crtc_w: width of visible portion of plane on crtc
667 * @crtc_h: height of visible portion of plane on crtc
668 * @src_x: left position of visible portion of plane within
669 * plane (in 16.16)
670 * @src_y: upper position of visible portion of plane within
671 * plane (in 16.16)
672 * @src_w: width of visible portion of plane (in 16.16)
673 * @src_h: height of visible portion of plane (in 16.16)
Daniel Vetterac3ba4a2016-05-31 23:11:10 +0200674 * @rotation: rotation of the plane
Marek Szyprowski44d1240d2016-06-13 11:11:26 +0200675 * @zpos: priority of the given plane on crtc (optional)
676 * @normalized_zpos: normalized value of zpos: unique, range from 0 to N-1
677 * where N is the number of active planes for given crtc
Ville Syrjäläd7da8242016-07-26 19:06:57 +0300678 * @src: clipped source coordinates of the plane (in 16.16)
679 * @dst: clipped destination coordinates of the plane
680 * @visible: visibility of the plane
Daniel Vetter144ecb92014-10-27 20:28:44 +0100681 * @state: backpointer to global drm_atomic_state
682 */
683struct drm_plane_state {
Daniel Vetter07cc0ef2014-11-27 15:49:39 +0100684 struct drm_plane *plane;
685
Rob Clark6ddd3882014-11-21 15:28:31 -0500686 struct drm_crtc *crtc; /* do not write directly, use drm_atomic_set_crtc_for_plane() */
687 struct drm_framebuffer *fb; /* do not write directly, use drm_atomic_set_fb_for_plane() */
Daniel Vettere2330f02014-10-29 11:34:56 +0100688 struct fence *fence;
Daniel Vetter144ecb92014-10-27 20:28:44 +0100689
690 /* Signed dest location allows it to be partially off screen */
691 int32_t crtc_x, crtc_y;
692 uint32_t crtc_w, crtc_h;
693
694 /* Source values are 16.16 fixed point */
695 uint32_t src_x, src_y;
696 uint32_t src_h, src_w;
697
Matt Roper1da30622015-01-21 16:35:40 -0800698 /* Plane rotation */
699 unsigned int rotation;
700
Marek Szyprowski44d1240d2016-06-13 11:11:26 +0200701 /* Plane zpos */
702 unsigned int zpos;
703 unsigned int normalized_zpos;
704
Ville Syrjäläd7da8242016-07-26 19:06:57 +0300705 /* Clipped coordinates */
706 struct drm_rect src, dst;
707
708 /*
709 * Is the plane actually visible? Can be false even
710 * if fb!=NULL and crtc!=NULL, due to clipping.
711 */
712 bool visible;
713
Daniel Vetter144ecb92014-10-27 20:28:44 +0100714 struct drm_atomic_state *state;
715};
716
717
718/**
Daniel Vetter3bf04012014-10-27 16:54:27 +0100719 * struct drm_plane_funcs - driver plane control functions
Jesse Barnes8cf5c912011-11-14 14:51:27 -0800720 */
721struct drm_plane_funcs {
Daniel Vetter88548632015-12-04 09:45:48 +0100722 /**
723 * @update_plane:
724 *
725 * This is the legacy entry point to enable and configure the plane for
726 * the given CRTC and framebuffer. It is never called to disable the
727 * plane, i.e. the passed-in crtc and fb paramters are never NULL.
728 *
729 * The source rectangle in frame buffer memory coordinates is given by
730 * the src_x, src_y, src_w and src_h parameters (as 16.16 fixed point
731 * values). Devices that don't support subpixel plane coordinates can
732 * ignore the fractional part.
733 *
734 * The destination rectangle in CRTC coordinates is given by the
735 * crtc_x, crtc_y, crtc_w and crtc_h parameters (as integer values).
736 * Devices scale the source rectangle to the destination rectangle. If
737 * scaling is not supported, and the source rectangle size doesn't match
738 * the destination rectangle size, the driver must return a
739 * -<errorname>EINVAL</errorname> error.
740 *
741 * Drivers implementing atomic modeset should use
742 * drm_atomic_helper_update_plane() to implement this hook.
743 *
744 * RETURNS:
745 *
746 * 0 on success or a negative error code on failure.
747 */
Jesse Barnes8cf5c912011-11-14 14:51:27 -0800748 int (*update_plane)(struct drm_plane *plane,
749 struct drm_crtc *crtc, struct drm_framebuffer *fb,
750 int crtc_x, int crtc_y,
751 unsigned int crtc_w, unsigned int crtc_h,
752 uint32_t src_x, uint32_t src_y,
753 uint32_t src_w, uint32_t src_h);
Daniel Vetter88548632015-12-04 09:45:48 +0100754
755 /**
756 * @disable_plane:
757 *
758 * This is the legacy entry point to disable the plane. The DRM core
Daniel Vetterc6b0ca32015-12-04 09:46:01 +0100759 * calls this method in response to a DRM_IOCTL_MODE_SETPLANE IOCTL call
Daniel Vetter88548632015-12-04 09:45:48 +0100760 * with the frame buffer ID set to 0. Disabled planes must not be
761 * processed by the CRTC.
762 *
763 * Drivers implementing atomic modeset should use
764 * drm_atomic_helper_disable_plane() to implement this hook.
765 *
766 * RETURNS:
767 *
768 * 0 on success or a negative error code on failure.
769 */
Jesse Barnes8cf5c912011-11-14 14:51:27 -0800770 int (*disable_plane)(struct drm_plane *plane);
Daniel Vetter88548632015-12-04 09:45:48 +0100771
772 /**
773 * @destroy:
774 *
775 * Clean up plane resources. This is only called at driver unload time
776 * through drm_mode_config_cleanup() since a plane cannot be hotplugged
777 * in DRM.
778 */
Jesse Barnes8cf5c912011-11-14 14:51:27 -0800779 void (*destroy)(struct drm_plane *plane);
Daniel Vetter88548632015-12-04 09:45:48 +0100780
781 /**
782 * @reset:
783 *
784 * Reset plane hardware and software state to off. This function isn't
785 * called by the core directly, only through drm_mode_config_reset().
786 * It's not a helper hook only for historical reasons.
787 *
788 * Atomic drivers can use drm_atomic_helper_plane_reset() to reset
789 * atomic state using this hook.
790 */
Daniel Vetter2a0d7cf2014-07-29 15:32:37 +0200791 void (*reset)(struct drm_plane *plane);
Rob Clark4d939142012-05-17 02:23:27 -0600792
Daniel Vetter88548632015-12-04 09:45:48 +0100793 /**
794 * @set_property:
795 *
796 * This is the legacy entry point to update a property attached to the
797 * plane.
798 *
799 * Drivers implementing atomic modeset should use
800 * drm_atomic_helper_plane_set_property() to implement this hook.
801 *
802 * This callback is optional if the driver does not support any legacy
803 * driver-private properties.
804 *
805 * RETURNS:
806 *
807 * 0 on success or a negative error code on failure.
808 */
Rob Clark4d939142012-05-17 02:23:27 -0600809 int (*set_property)(struct drm_plane *plane,
810 struct drm_property *property, uint64_t val);
Daniel Vetter144ecb92014-10-27 20:28:44 +0100811
Daniel Vetter88548632015-12-04 09:45:48 +0100812 /**
813 * @atomic_duplicate_state:
814 *
815 * Duplicate the current atomic state for this plane and return it.
816 * The core and helpers gurantee that any atomic state duplicated with
817 * this hook and still owned by the caller (i.e. not transferred to the
818 * driver by calling ->atomic_commit() from struct
819 * &drm_mode_config_funcs) will be cleaned up by calling the
820 * @atomic_destroy_state hook in this structure.
821 *
822 * Atomic drivers which don't subclass struct &drm_plane_state should use
823 * drm_atomic_helper_plane_duplicate_state(). Drivers that subclass the
824 * state structure to extend it with driver-private state should use
825 * __drm_atomic_helper_plane_duplicate_state() to make sure shared state is
826 * duplicated in a consistent fashion across drivers.
827 *
828 * It is an error to call this hook before plane->state has been
829 * initialized correctly.
830 *
831 * NOTE:
832 *
833 * If the duplicate state references refcounted resources this hook must
834 * acquire a reference for each of them. The driver must release these
835 * references again in @atomic_destroy_state.
836 *
837 * RETURNS:
838 *
839 * Duplicated atomic state or NULL when the allocation failed.
840 */
Daniel Vetter144ecb92014-10-27 20:28:44 +0100841 struct drm_plane_state *(*atomic_duplicate_state)(struct drm_plane *plane);
Daniel Vetter88548632015-12-04 09:45:48 +0100842
843 /**
844 * @atomic_destroy_state:
845 *
846 * Destroy a state duplicated with @atomic_duplicate_state and release
847 * or unreference all resources it references
848 */
Daniel Vetter144ecb92014-10-27 20:28:44 +0100849 void (*atomic_destroy_state)(struct drm_plane *plane,
Daniel Vettercc4ceb42014-07-25 21:30:38 +0200850 struct drm_plane_state *state);
Daniel Vetter88548632015-12-04 09:45:48 +0100851
852 /**
853 * @atomic_set_property:
854 *
855 * Decode a driver-private property value and store the decoded value
856 * into the passed-in state structure. Since the atomic core decodes all
857 * standardized properties (even for extensions beyond the core set of
858 * properties which might not be implemented by all drivers) this
859 * requires drivers to subclass the state structure.
860 *
861 * Such driver-private properties should really only be implemented for
862 * truly hardware/vendor specific state. Instead it is preferred to
863 * standardize atomic extension and decode the properties used to expose
864 * such an extension in the core.
865 *
866 * Do not call this function directly, use
867 * drm_atomic_plane_set_property() instead.
868 *
869 * This callback is optional if the driver does not support any
870 * driver-private atomic properties.
871 *
872 * NOTE:
873 *
874 * This function is called in the state assembly phase of atomic
875 * modesets, which can be aborted for any reason (including on
876 * userspace's request to just check whether a configuration would be
877 * possible). Drivers MUST NOT touch any persistent state (hardware or
878 * software) or data structures except the passed in @state parameter.
879 *
880 * Also since userspace controls in which order properties are set this
881 * function must not do any input validation (since the state update is
882 * incomplete and hence likely inconsistent). Instead any such input
883 * validation must be done in the various atomic_check callbacks.
884 *
885 * RETURNS:
886 *
887 * 0 if the property has been found, -EINVAL if the property isn't
888 * implemented by the driver (which shouldn't ever happen, the core only
889 * asks for properties attached to this plane). No other validation is
890 * allowed by the driver. The core already checks that the property
891 * value is within the range (integer, valid enum value, ...) the driver
892 * set when registering the property.
893 */
Daniel Vetter144ecb92014-10-27 20:28:44 +0100894 int (*atomic_set_property)(struct drm_plane *plane,
895 struct drm_plane_state *state,
896 struct drm_property *property,
897 uint64_t val);
Daniel Vetter88548632015-12-04 09:45:48 +0100898
899 /**
900 * @atomic_get_property:
901 *
902 * Reads out the decoded driver-private property. This is used to
Daniel Vetterc6b0ca32015-12-04 09:46:01 +0100903 * implement the GETPLANE IOCTL.
Daniel Vetter88548632015-12-04 09:45:48 +0100904 *
905 * Do not call this function directly, use
906 * drm_atomic_plane_get_property() instead.
907 *
908 * This callback is optional if the driver does not support any
909 * driver-private atomic properties.
910 *
911 * RETURNS:
912 *
913 * 0 on success, -EINVAL if the property isn't implemented by the
914 * driver (which should never happen, the core only asks for
915 * properties attached to this plane).
916 */
Rob Clarkac9c9252014-12-18 16:01:47 -0500917 int (*atomic_get_property)(struct drm_plane *plane,
918 const struct drm_plane_state *state,
919 struct drm_property *property,
920 uint64_t *val);
Benjamin Gaignard79190ea2016-06-21 16:37:09 +0200921 /**
922 * @late_register:
923 *
924 * This optional hook can be used to register additional userspace
925 * interfaces attached to the plane like debugfs interfaces.
926 * It is called late in the driver load sequence from drm_dev_register().
927 * Everything added from this callback should be unregistered in
928 * the early_unregister callback.
929 *
930 * Returns:
931 *
932 * 0 on success, or a negative error code on failure.
933 */
934 int (*late_register)(struct drm_plane *plane);
935
936 /**
937 * @early_unregister:
938 *
939 * This optional hook should be used to unregister the additional
940 * userspace interfaces attached to the plane from
941 * late_unregister(). It is called from drm_dev_unregister(),
942 * early in the driver unload sequence to disable userspace access
943 * before data structures are torndown.
944 */
945 void (*early_unregister)(struct drm_plane *plane);
Jesse Barnes8cf5c912011-11-14 14:51:27 -0800946};
947
Matt Ropere27dde32014-04-01 15:22:30 -0700948enum drm_plane_type {
949 DRM_PLANE_TYPE_OVERLAY,
950 DRM_PLANE_TYPE_PRIMARY,
951 DRM_PLANE_TYPE_CURSOR,
952};
953
Daniel Vetter88548632015-12-04 09:45:48 +0100954
Jesse Barnes8cf5c912011-11-14 14:51:27 -0800955/**
Daniel Vetter3bf04012014-10-27 16:54:27 +0100956 * struct drm_plane - central DRM plane control structure
Jesse Barnes8cf5c912011-11-14 14:51:27 -0800957 * @dev: DRM device this plane belongs to
958 * @head: for list management
Daniel Vetterac3ba4a2016-05-31 23:11:10 +0200959 * @name: human readable name, can be overwritten by the driver
Jesse Barnes8cf5c912011-11-14 14:51:27 -0800960 * @base: base mode object
961 * @possible_crtcs: pipes this plane can be bound to
962 * @format_types: array of formats supported by this plane
963 * @format_count: number of formats supported
Laurent Pinchart7eb5f302015-03-09 10:41:07 +0200964 * @format_default: driver hasn't supplied supported formats for the plane
Jesse Barnes8cf5c912011-11-14 14:51:27 -0800965 * @crtc: currently bound CRTC
966 * @fb: currently bound fb
Daniel Vetter2c0c33d2014-10-27 20:19:38 +0100967 * @old_fb: Temporary tracking of the old fb while a modeset is ongoing. Used by
968 * drm_mode_set_config_internal() to implement correct refcounting.
Jesse Barnes8cf5c912011-11-14 14:51:27 -0800969 * @funcs: helper functions
Rob Clark4d939142012-05-17 02:23:27 -0600970 * @properties: property tracking for this plane
Matt Ropere27dde32014-04-01 15:22:30 -0700971 * @type: type of plane (overlay, primary, cursor)
Daniel Vetter144ecb92014-10-27 20:28:44 +0100972 * @state: current atomic state for this plane
Marek Szyprowski44d1240d2016-06-13 11:11:26 +0200973 * @zpos_property: zpos property for this plane
Daniel Vetterac3ba4a2016-05-31 23:11:10 +0200974 * @helper_private: mid-layer private data
Jesse Barnes8cf5c912011-11-14 14:51:27 -0800975 */
976struct drm_plane {
977 struct drm_device *dev;
978 struct list_head head;
979
Ville Syrjälä9f4c97a2015-12-08 18:41:54 +0200980 char *name;
981
Daniel Vetterac3ba4a2016-05-31 23:11:10 +0200982 /**
983 * @mutex:
984 *
985 * Protects modeset plane state, together with the mutex of &drm_crtc
986 * this plane is linked to (when active, getting actived or getting
987 * disabled).
988 */
Daniel Vetter4d02e2d2014-11-11 10:12:00 +0100989 struct drm_modeset_lock mutex;
990
Jesse Barnes8cf5c912011-11-14 14:51:27 -0800991 struct drm_mode_object base;
992
993 uint32_t possible_crtcs;
994 uint32_t *format_types;
Thierry Reding45e37432015-08-12 16:54:28 +0200995 unsigned int format_count;
Laurent Pinchart7eb5f302015-03-09 10:41:07 +0200996 bool format_default;
Jesse Barnes8cf5c912011-11-14 14:51:27 -0800997
998 struct drm_crtc *crtc;
999 struct drm_framebuffer *fb;
1000
Daniel Vetter3d30a592014-07-27 13:42:42 +02001001 struct drm_framebuffer *old_fb;
1002
Jesse Barnes8cf5c912011-11-14 14:51:27 -08001003 const struct drm_plane_funcs *funcs;
Rob Clark4d939142012-05-17 02:23:27 -06001004
1005 struct drm_object_properties properties;
Matt Ropere27dde32014-04-01 15:22:30 -07001006
1007 enum drm_plane_type type;
Daniel Vetter144ecb92014-10-27 20:28:44 +01001008
Daniel Vetter96094082016-07-15 21:47:59 +02001009 /**
1010 * @index: Position inside the mode_config.list, can be used as an array
1011 * index. It is invariant over the lifetime of the plane.
1012 */
Chris Wilson490d3d12016-05-27 20:05:00 +01001013 unsigned index;
1014
Daniel Vetter4490d4c2015-12-04 09:45:45 +01001015 const struct drm_plane_helper_funcs *helper_private;
Daniel Vetterc2fcd272014-11-05 00:14:14 +01001016
Daniel Vetter144ecb92014-10-27 20:28:44 +01001017 struct drm_plane_state *state;
Marek Szyprowski44d1240d2016-06-13 11:11:26 +02001018
1019 struct drm_property *zpos_property;
Jesse Barnes8cf5c912011-11-14 14:51:27 -08001020};
1021
1022/**
Daniel Vetter3b24f7d2016-06-08 14:19:00 +02001023 * struct drm_crtc_commit - track modeset commits on a CRTC
1024 *
1025 * This structure is used to track pending modeset changes and atomic commit on
1026 * a per-CRTC basis. Since updating the list should never block this structure
1027 * is reference counted to allow waiters to safely wait on an event to complete,
1028 * without holding any locks.
1029 *
1030 * It has 3 different events in total to allow a fine-grained synchronization
1031 * between outstanding updates::
1032 *
1033 * atomic commit thread hardware
1034 *
1035 * write new state into hardware ----> ...
1036 * signal hw_done
1037 * switch to new state on next
1038 * ... v/hblank
1039 *
1040 * wait for buffers to show up ...
1041 *
1042 * ... send completion irq
1043 * irq handler signals flip_done
1044 * cleanup old buffers
1045 *
1046 * signal cleanup_done
1047 *
1048 * wait for flip_done <----
1049 * clean up atomic state
1050 *
1051 * The important bit to know is that cleanup_done is the terminal event, but the
1052 * ordering between flip_done and hw_done is entirely up to the specific driver
1053 * and modeset state change.
1054 *
1055 * For an implementation of how to use this look at
1056 * drm_atomic_helper_setup_commit() from the atomic helper library.
1057 */
1058struct drm_crtc_commit {
1059 /**
1060 * @crtc:
1061 *
1062 * DRM CRTC for this commit.
1063 */
1064 struct drm_crtc *crtc;
1065
1066 /**
1067 * @ref:
1068 *
1069 * Reference count for this structure. Needed to allow blocking on
1070 * completions without the risk of the completion disappearing
1071 * meanwhile.
1072 */
1073 struct kref ref;
1074
1075 /**
1076 * @flip_done:
1077 *
1078 * Will be signaled when the hardware has flipped to the new set of
1079 * buffers. Signals at the same time as when the drm event for this
1080 * commit is sent to userspace, or when an out-fence is singalled. Note
1081 * that for most hardware, in most cases this happens after @hw_done is
1082 * signalled.
1083 */
1084 struct completion flip_done;
1085
1086 /**
1087 * @hw_done:
1088 *
1089 * Will be signalled when all hw register changes for this commit have
1090 * been written out. Especially when disabling a pipe this can be much
1091 * later than than @flip_done, since that can signal already when the
1092 * screen goes black, whereas to fully shut down a pipe more register
1093 * I/O is required.
1094 *
1095 * Note that this does not need to include separately reference-counted
1096 * resources like backing storage buffer pinning, or runtime pm
1097 * management.
1098 */
1099 struct completion hw_done;
1100
1101 /**
1102 * @cleanup_done:
1103 *
1104 * Will be signalled after old buffers have been cleaned up by calling
1105 * drm_atomic_helper_cleanup_planes(). Since this can only happen after
1106 * a vblank wait completed it might be a bit later. This completion is
1107 * useful to throttle updates and avoid hardware updates getting ahead
1108 * of the buffer cleanup too much.
1109 */
1110 struct completion cleanup_done;
1111
1112 /**
1113 * @commit_entry:
1114 *
1115 * Entry on the per-CRTC commit_list. Protected by crtc->commit_lock.
1116 */
1117 struct list_head commit_entry;
1118
1119 /**
1120 * @event:
1121 *
1122 * &drm_pending_vblank_event pointer to clean up private events.
1123 */
1124 struct drm_pending_vblank_event *event;
1125};
1126
Daniel Vetterb8b53422016-06-02 00:06:33 +02001127struct __drm_planes_state {
1128 struct drm_plane *ptr;
1129 struct drm_plane_state *state;
1130};
1131
Daniel Vetter5d943aa62016-06-02 00:06:34 +02001132struct __drm_crtcs_state {
1133 struct drm_crtc *ptr;
1134 struct drm_crtc_state *state;
Daniel Vetter3b24f7d2016-06-08 14:19:00 +02001135 struct drm_crtc_commit *commit;
Daniel Vetter5d943aa62016-06-02 00:06:34 +02001136};
1137
Daniel Vetter63e83c12016-06-02 00:06:32 +02001138struct __drm_connnectors_state {
1139 struct drm_connector *ptr;
1140 struct drm_connector_state *state;
1141};
1142
Sean Paul3b336ec2013-08-14 16:47:37 -04001143/**
Rob Clark08855fa2015-03-11 10:23:09 -04001144 * struct drm_atomic_state - the global state object for atomic updates
Daniel Vettercc4ceb42014-07-25 21:30:38 +02001145 * @dev: parent DRM device
Rob Clarkd34f20d2014-12-18 16:01:56 -05001146 * @allow_modeset: allow full modeset
Daniel Vetterc6b0ca32015-12-04 09:46:01 +01001147 * @legacy_cursor_update: hint to enforce legacy cursor IOCTL semantics
Maarten Lankhorst40616a22016-03-03 10:17:39 +01001148 * @legacy_set_config: Disable conflicting encoders instead of failing with -EINVAL.
Daniel Vetterb8b53422016-06-02 00:06:33 +02001149 * @planes: pointer to array of structures with per-plane data
Daniel Vettercc4ceb42014-07-25 21:30:38 +02001150 * @crtcs: pointer to array of CRTC pointers
Daniel Vetterf52b69f12014-11-19 18:38:08 +01001151 * @num_connector: size of the @connectors and @connector_states arrays
Daniel Vetter63e83c12016-06-02 00:06:32 +02001152 * @connectors: pointer to array of structures with per-connector data
Daniel Vettercc4ceb42014-07-25 21:30:38 +02001153 * @acquire_ctx: acquire context for this atomic modeset state update
1154 */
1155struct drm_atomic_state {
1156 struct drm_device *dev;
Rob Clarkd34f20d2014-12-18 16:01:56 -05001157 bool allow_modeset : 1;
Daniel Vetterf02ad902015-01-22 16:36:23 +01001158 bool legacy_cursor_update : 1;
Maarten Lankhorst40616a22016-03-03 10:17:39 +01001159 bool legacy_set_config : 1;
Daniel Vetterb8b53422016-06-02 00:06:33 +02001160 struct __drm_planes_state *planes;
Daniel Vetter5d943aa62016-06-02 00:06:34 +02001161 struct __drm_crtcs_state *crtcs;
Daniel Vetterf52b69f12014-11-19 18:38:08 +01001162 int num_connector;
Daniel Vetter63e83c12016-06-02 00:06:32 +02001163 struct __drm_connnectors_state *connectors;
Daniel Vettercc4ceb42014-07-25 21:30:38 +02001164
1165 struct drm_modeset_acquire_ctx *acquire_ctx;
Daniel Vetter3b24f7d2016-06-08 14:19:00 +02001166
1167 /**
1168 * @commit_work:
1169 *
1170 * Work item which can be used by the driver or helpers to execute the
1171 * commit without blocking.
1172 */
1173 struct work_struct commit_work;
Daniel Vettercc4ceb42014-07-25 21:30:38 +02001174};
1175
1176
1177/**
Daniel Vetter3bf04012014-10-27 16:54:27 +01001178 * struct drm_mode_set - new values for a CRTC config change
Jesse Barnesef273512011-11-07 12:03:19 -08001179 * @fb: framebuffer to use for new config
1180 * @crtc: CRTC whose configuration we're about to change
1181 * @mode: mode timings to use
1182 * @x: position of this CRTC relative to @fb
1183 * @y: position of this CRTC relative to @fb
1184 * @connectors: array of connectors to drive with this CRTC if possible
1185 * @num_connectors: size of @connectors array
Dave Airlief453ba02008-11-07 14:05:41 -08001186 *
1187 * Represents a single crtc the connectors that it drives with what mode
1188 * and from which framebuffer it scans out from.
1189 *
1190 * This is used to set modes.
1191 */
1192struct drm_mode_set {
Dave Airlief453ba02008-11-07 14:05:41 -08001193 struct drm_framebuffer *fb;
1194 struct drm_crtc *crtc;
1195 struct drm_display_mode *mode;
1196
1197 uint32_t x;
1198 uint32_t y;
1199
1200 struct drm_connector **connectors;
1201 size_t num_connectors;
1202};
1203
1204/**
Jesse Barnes550cebc2011-11-07 12:03:20 -08001205 * struct drm_mode_config_funcs - basic driver provided mode setting functions
Jesse Barnes550cebc2011-11-07 12:03:20 -08001206 *
1207 * Some global (i.e. not per-CRTC, connector, etc) mode setting functions that
1208 * involve drivers.
Dave Airlief453ba02008-11-07 14:05:41 -08001209 */
1210struct drm_mode_config_funcs {
Daniel Vetter9953f412015-12-04 09:46:02 +01001211 /**
1212 * @fb_create:
1213 *
1214 * Create a new framebuffer object. The core does basic checks on the
1215 * requested metadata, but most of that is left to the driver. See
1216 * struct &drm_mode_fb_cmd2 for details.
1217 *
Daniel Vetterd55f5322015-12-08 09:49:19 +01001218 * If the parameters are deemed valid and the backing storage objects in
1219 * the underlying memory manager all exist, then the driver allocates
1220 * a new &drm_framebuffer structure, subclassed to contain
1221 * driver-specific information (like the internal native buffer object
1222 * references). It also needs to fill out all relevant metadata, which
1223 * should be done by calling drm_helper_mode_fill_fb_struct().
1224 *
1225 * The initialization is finalized by calling drm_framebuffer_init(),
1226 * which registers the framebuffer and makes it accessible to other
1227 * threads.
1228 *
Daniel Vetter9953f412015-12-04 09:46:02 +01001229 * RETURNS:
1230 *
1231 * A new framebuffer with an initial reference count of 1 or a negative
1232 * error code encoded with ERR_PTR().
1233 */
Jesse Barnes550cebc2011-11-07 12:03:20 -08001234 struct drm_framebuffer *(*fb_create)(struct drm_device *dev,
1235 struct drm_file *file_priv,
Ville Syrjälä1eb83452015-11-11 19:11:29 +02001236 const struct drm_mode_fb_cmd2 *mode_cmd);
Daniel Vetter9953f412015-12-04 09:46:02 +01001237
1238 /**
1239 * @output_poll_changed:
1240 *
1241 * Callback used by helpers to inform the driver of output configuration
1242 * changes.
1243 *
1244 * Drivers implementing fbdev emulation with the helpers can call
1245 * drm_fb_helper_hotplug_changed from this hook to inform the fbdev
1246 * helper of output changes.
1247 *
1248 * FIXME:
1249 *
1250 * Except that there's no vtable for device-level helper callbacks
1251 * there's no reason this is a core function.
1252 */
Dave Airlieeb1f8e42010-05-07 06:42:51 +00001253 void (*output_poll_changed)(struct drm_device *dev);
Daniel Vettercc4ceb42014-07-25 21:30:38 +02001254
Daniel Vetter9953f412015-12-04 09:46:02 +01001255 /**
1256 * @atomic_check:
1257 *
1258 * This is the only hook to validate an atomic modeset update. This
1259 * function must reject any modeset and state changes which the hardware
1260 * or driver doesn't support. This includes but is of course not limited
1261 * to:
1262 *
1263 * - Checking that the modes, framebuffers, scaling and placement
1264 * requirements and so on are within the limits of the hardware.
1265 *
1266 * - Checking that any hidden shared resources are not oversubscribed.
1267 * This can be shared PLLs, shared lanes, overall memory bandwidth,
1268 * display fifo space (where shared between planes or maybe even
1269 * CRTCs).
1270 *
1271 * - Checking that virtualized resources exported to userspace are not
1272 * oversubscribed. For various reasons it can make sense to expose
1273 * more planes, crtcs or encoders than which are physically there. One
1274 * example is dual-pipe operations (which generally should be hidden
1275 * from userspace if when lockstepped in hardware, exposed otherwise),
1276 * where a plane might need 1 hardware plane (if it's just on one
1277 * pipe), 2 hardware planes (when it spans both pipes) or maybe even
1278 * shared a hardware plane with a 2nd plane (if there's a compatible
1279 * plane requested on the area handled by the other pipe).
1280 *
1281 * - Check that any transitional state is possible and that if
1282 * requested, the update can indeed be done in the vblank period
1283 * without temporarily disabling some functions.
1284 *
1285 * - Check any other constraints the driver or hardware might have.
1286 *
1287 * - This callback also needs to correctly fill out the &drm_crtc_state
1288 * in this update to make sure that drm_atomic_crtc_needs_modeset()
1289 * reflects the nature of the possible update and returns true if and
1290 * only if the update cannot be applied without tearing within one
1291 * vblank on that CRTC. The core uses that information to reject
1292 * updates which require a full modeset (i.e. blanking the screen, or
1293 * at least pausing updates for a substantial amount of time) if
1294 * userspace has disallowed that in its request.
1295 *
1296 * - The driver also does not need to repeat basic input validation
1297 * like done for the corresponding legacy entry points. The core does
1298 * that before calling this hook.
1299 *
1300 * See the documentation of @atomic_commit for an exhaustive list of
1301 * error conditions which don't have to be checked at the
1302 * ->atomic_check() stage?
1303 *
1304 * See the documentation for struct &drm_atomic_state for how exactly
1305 * an atomic modeset update is described.
1306 *
1307 * Drivers using the atomic helpers can implement this hook using
1308 * drm_atomic_helper_check(), or one of the exported sub-functions of
1309 * it.
1310 *
1311 * RETURNS:
1312 *
1313 * 0 on success or one of the below negative error codes:
1314 *
1315 * - -EINVAL, if any of the above constraints are violated.
1316 *
1317 * - -EDEADLK, when returned from an attempt to acquire an additional
1318 * &drm_modeset_lock through drm_modeset_lock().
1319 *
1320 * - -ENOMEM, if allocating additional state sub-structures failed due
1321 * to lack of memory.
1322 *
1323 * - -EINTR, -EAGAIN or -ERESTARTSYS, if the IOCTL should be restarted.
1324 * This can either be due to a pending signal, or because the driver
1325 * needs to completely bail out to recover from an exceptional
1326 * situation like a GPU hang. From a userspace point all errors are
1327 * treated equally.
1328 */
Daniel Vettercc4ceb42014-07-25 21:30:38 +02001329 int (*atomic_check)(struct drm_device *dev,
Daniel Vetter9953f412015-12-04 09:46:02 +01001330 struct drm_atomic_state *state);
1331
1332 /**
1333 * @atomic_commit:
1334 *
1335 * This is the only hook to commit an atomic modeset update. The core
1336 * guarantees that @atomic_check has been called successfully before
1337 * calling this function, and that nothing has been changed in the
1338 * interim.
1339 *
1340 * See the documentation for struct &drm_atomic_state for how exactly
1341 * an atomic modeset update is described.
1342 *
1343 * Drivers using the atomic helpers can implement this hook using
1344 * drm_atomic_helper_commit(), or one of the exported sub-functions of
1345 * it.
1346 *
Maarten Lankhorst286dbb82016-04-26 16:11:34 +02001347 * Nonblocking commits (as indicated with the nonblock parameter) must
Daniel Vetter9953f412015-12-04 09:46:02 +01001348 * do any preparatory work which might result in an unsuccessful commit
1349 * in the context of this callback. The only exceptions are hardware
1350 * errors resulting in -EIO. But even in that case the driver must
1351 * ensure that the display pipe is at least running, to avoid
1352 * compositors crashing when pageflips don't work. Anything else,
1353 * specifically committing the update to the hardware, should be done
1354 * without blocking the caller. For updates which do not require a
1355 * modeset this must be guaranteed.
1356 *
1357 * The driver must wait for any pending rendering to the new
1358 * framebuffers to complete before executing the flip. It should also
1359 * wait for any pending rendering from other drivers if the underlying
Maarten Lankhorst286dbb82016-04-26 16:11:34 +02001360 * buffer is a shared dma-buf. Nonblocking commits must not wait for
Daniel Vetter9953f412015-12-04 09:46:02 +01001361 * rendering in the context of this callback.
1362 *
1363 * An application can request to be notified when the atomic commit has
1364 * completed. These events are per-CRTC and can be distinguished by the
1365 * CRTC index supplied in &drm_event to userspace.
1366 *
1367 * The drm core will supply a struct &drm_event in the event
1368 * member of each CRTC's &drm_crtc_state structure. This can be handled by the
1369 * drm_crtc_send_vblank_event() function, which the driver should call on
1370 * the provided event upon completion of the atomic commit. Note that if
1371 * the driver supports vblank signalling and timestamping the vblank
1372 * counters and timestamps must agree with the ones returned from page
1373 * flip events. With the current vblank helper infrastructure this can
1374 * be achieved by holding a vblank reference while the page flip is
1375 * pending, acquired through drm_crtc_vblank_get() and released with
1376 * drm_crtc_vblank_put(). Drivers are free to implement their own vblank
1377 * counter and timestamp tracking though, e.g. if they have accurate
1378 * timestamp registers in hardware.
1379 *
1380 * NOTE:
1381 *
1382 * Drivers are not allowed to shut down any display pipe successfully
1383 * enabled through an atomic commit on their own. Doing so can result in
1384 * compositors crashing if a page flip is suddenly rejected because the
1385 * pipe is off.
1386 *
1387 * RETURNS:
1388 *
1389 * 0 on success or one of the below negative error codes:
1390 *
Maarten Lankhorst286dbb82016-04-26 16:11:34 +02001391 * - -EBUSY, if a nonblocking updated is requested and there is
Daniel Vetter9953f412015-12-04 09:46:02 +01001392 * an earlier updated pending. Drivers are allowed to support a queue
1393 * of outstanding updates, but currently no driver supports that.
1394 * Note that drivers must wait for preceding updates to complete if a
1395 * synchronous update is requested, they are not allowed to fail the
1396 * commit in that case.
1397 *
1398 * - -ENOMEM, if the driver failed to allocate memory. Specifically
1399 * this can happen when trying to pin framebuffers, which must only
1400 * be done when committing the state.
1401 *
1402 * - -ENOSPC, as a refinement of the more generic -ENOMEM to indicate
1403 * that the driver has run out of vram, iommu space or similar GPU
1404 * address space needed for framebuffer.
1405 *
1406 * - -EIO, if the hardware completely died.
1407 *
1408 * - -EINTR, -EAGAIN or -ERESTARTSYS, if the IOCTL should be restarted.
1409 * This can either be due to a pending signal, or because the driver
1410 * needs to completely bail out to recover from an exceptional
1411 * situation like a GPU hang. From a userspace point of view all errors are
1412 * treated equally.
1413 *
1414 * This list is exhaustive. Specifically this hook is not allowed to
1415 * return -EINVAL (any invalid requests should be caught in
1416 * @atomic_check) or -EDEADLK (this function must not acquire
1417 * additional modeset locks).
1418 */
Daniel Vettercc4ceb42014-07-25 21:30:38 +02001419 int (*atomic_commit)(struct drm_device *dev,
Daniel Vetter9953f412015-12-04 09:46:02 +01001420 struct drm_atomic_state *state,
Maarten Lankhorst286dbb82016-04-26 16:11:34 +02001421 bool nonblock);
Daniel Vetter9953f412015-12-04 09:46:02 +01001422
1423 /**
1424 * @atomic_state_alloc:
1425 *
1426 * This optional hook can be used by drivers that want to subclass struct
1427 * &drm_atomic_state to be able to track their own driver-private global
1428 * state easily. If this hook is implemented, drivers must also
1429 * implement @atomic_state_clear and @atomic_state_free.
1430 *
1431 * RETURNS:
1432 *
1433 * A new &drm_atomic_state on success or NULL on failure.
1434 */
Maarten Lankhorst036ef572015-05-18 10:06:40 +02001435 struct drm_atomic_state *(*atomic_state_alloc)(struct drm_device *dev);
Daniel Vetter9953f412015-12-04 09:46:02 +01001436
1437 /**
1438 * @atomic_state_clear:
1439 *
1440 * This hook must clear any driver private state duplicated into the
1441 * passed-in &drm_atomic_state. This hook is called when the caller
1442 * encountered a &drm_modeset_lock deadlock and needs to drop all
1443 * already acquired locks as part of the deadlock avoidance dance
1444 * implemented in drm_modeset_lock_backoff().
1445 *
1446 * Any duplicated state must be invalidated since a concurrent atomic
1447 * update might change it, and the drm atomic interfaces always apply
1448 * updates as relative changes to the current state.
1449 *
1450 * Drivers that implement this must call drm_atomic_state_default_clear()
1451 * to clear common state.
1452 */
Maarten Lankhorst036ef572015-05-18 10:06:40 +02001453 void (*atomic_state_clear)(struct drm_atomic_state *state);
Daniel Vetter9953f412015-12-04 09:46:02 +01001454
1455 /**
1456 * @atomic_state_free:
1457 *
1458 * This hook needs driver private resources and the &drm_atomic_state
1459 * itself. Note that the core first calls drm_atomic_state_clear() to
1460 * avoid code duplicate between the clear and free hooks.
1461 *
1462 * Drivers that implement this must call drm_atomic_state_default_free()
1463 * to release common resources.
1464 */
Maarten Lankhorst036ef572015-05-18 10:06:40 +02001465 void (*atomic_state_free)(struct drm_atomic_state *state);
Dave Airlief453ba02008-11-07 14:05:41 -08001466};
1467
Jesse Barnesc1aaca22011-11-07 12:03:21 -08001468/**
Daniel Vetter2c0c33d2014-10-27 20:19:38 +01001469 * struct drm_mode_config - Mode configuration control structure
Jesse Barnesa62c93d2011-11-07 12:03:22 -08001470 * @mutex: mutex protecting KMS related lists and structures
Daniel Vetter2c0c33d2014-10-27 20:19:38 +01001471 * @connection_mutex: ww mutex protecting connector state and routing
1472 * @acquire_ctx: global implicit acquire context used by atomic drivers for
Daniel Vetterc6b0ca32015-12-04 09:46:01 +01001473 * legacy IOCTLs
Daniel Vetter2c0c33d2014-10-27 20:19:38 +01001474 * @fb_lock: mutex to protect fb state and lists
Jesse Barnesa62c93d2011-11-07 12:03:22 -08001475 * @num_fb: number of fbs available
1476 * @fb_list: list of framebuffers available
Jesse Barnesa62c93d2011-11-07 12:03:22 -08001477 * @num_encoder: number of encoders on this device
1478 * @encoder_list: list of encoder objects
Daniel Vetter2c0c33d2014-10-27 20:19:38 +01001479 * @num_overlay_plane: number of overlay planes on this device
1480 * @num_total_plane: number of universal (i.e. with primary/curso) planes on this device
1481 * @plane_list: list of plane objects
Jesse Barnesa62c93d2011-11-07 12:03:22 -08001482 * @num_crtc: number of CRTCs on this device
1483 * @crtc_list: list of CRTC objects
Daniel Vetter2c0c33d2014-10-27 20:19:38 +01001484 * @property_list: list of property objects
Jesse Barnesa62c93d2011-11-07 12:03:22 -08001485 * @min_width: minimum pixel width on this device
1486 * @min_height: minimum pixel height on this device
1487 * @max_width: maximum pixel width on this device
1488 * @max_height: maximum pixel height on this device
1489 * @funcs: core driver provided mode setting functions
1490 * @fb_base: base address of the framebuffer
Daniel Vetter2c0c33d2014-10-27 20:19:38 +01001491 * @poll_enabled: track polling support for this device
1492 * @poll_running: track polling status for this device
Daniel Vetterac3ba4a2016-05-31 23:11:10 +02001493 * @delayed_event: track delayed poll uevent deliver for this device
Jesse Barnesa62c93d2011-11-07 12:03:22 -08001494 * @output_poll_work: delayed work for polling in process context
Daniel Vetter2c0c33d2014-10-27 20:19:38 +01001495 * @property_blob_list: list of all the blob property objects
Daniel Stone8fb6e7a2015-04-20 19:22:54 +01001496 * @blob_lock: mutex for blob property allocation and management
Jesse Barnesa62c93d2011-11-07 12:03:22 -08001497 * @*_property: core property tracking
Daniel Vetter2c0c33d2014-10-27 20:19:38 +01001498 * @preferred_depth: preferred RBG pixel depth, used by fb helpers
1499 * @prefer_shadow: hint to userspace to prefer shadow-fb rendering
Daniel Vetter2c0c33d2014-10-27 20:19:38 +01001500 * @cursor_width: hint to userspace for max cursor width
1501 * @cursor_height: hint to userspace for max cursor height
Daniel Vetter9f2a7952016-06-08 14:19:02 +02001502 * @helper_private: mid-layer private data
Dave Airlief453ba02008-11-07 14:05:41 -08001503 *
Jesse Barnesa62c93d2011-11-07 12:03:22 -08001504 * Core mode resource tracking structure. All CRTC, encoders, and connectors
1505 * enumerated by the driver are added here, as are global properties. Some
1506 * global restrictions are also here, e.g. dimension restrictions.
Dave Airlief453ba02008-11-07 14:05:41 -08001507 */
1508struct drm_mode_config {
Jesse Barnesad2563c2009-01-19 17:21:45 +10001509 struct mutex mutex; /* protects configuration (mode lists etc.) */
Rob Clark51fd3712013-11-19 12:10:12 -05001510 struct drm_modeset_lock connection_mutex; /* protects connector->encoder and encoder->crtc links */
1511 struct drm_modeset_acquire_ctx *acquire_ctx; /* for legacy _lock_all() / _unlock_all() */
Daniel Vetterac3ba4a2016-05-31 23:11:10 +02001512
1513 /**
1514 * @idr_mutex:
1515 *
1516 * Mutex for KMS ID allocation and management. Protects both @crtc_idr
1517 * and @tile_idr.
1518 */
1519 struct mutex idr_mutex;
1520
1521 /**
1522 * @crtc_idr:
1523 *
1524 * Main KMS ID tracking object. Use this idr for all IDs, fb, crtc,
1525 * connector, modes - just makes life easier to have only one.
1526 */
1527 struct idr crtc_idr;
1528
1529 /**
1530 * @tile_idr:
1531 *
1532 * Use this idr for allocating new IDs for tiled sinks like use in some
1533 * high-res DP MST screens.
1534 */
1535 struct idr tile_idr;
Daniel Vetter4b096ac2012-12-10 21:19:18 +01001536
Daniel Vetter2c0c33d2014-10-27 20:19:38 +01001537 struct mutex fb_lock; /* proctects global and per-file fb lists */
Dave Airlief453ba02008-11-07 14:05:41 -08001538 int num_fb;
1539 struct list_head fb_list;
Daniel Vetter4b096ac2012-12-10 21:19:18 +01001540
Daniel Vetter96094082016-07-15 21:47:59 +02001541 /**
1542 * @num_connector: Number of connectors on this device.
1543 */
Dave Airlief453ba02008-11-07 14:05:41 -08001544 int num_connector;
Daniel Vetter96094082016-07-15 21:47:59 +02001545 /**
1546 * @connector_ida: ID allocator for connector indices.
1547 */
Maarten Lankhorst5fff80b2016-02-17 08:32:05 +01001548 struct ida connector_ida;
Daniel Vetter96094082016-07-15 21:47:59 +02001549 /**
1550 * @connector_list: List of connector objects.
1551 */
Dave Airlief453ba02008-11-07 14:05:41 -08001552 struct list_head connector_list;
1553 int num_encoder;
1554 struct list_head encoder_list;
Matt Ropere27dde32014-04-01 15:22:30 -07001555
1556 /*
1557 * Track # of overlay planes separately from # of total planes. By
1558 * default we only advertise overlay planes to userspace; if userspace
1559 * sets the "universal plane" capability bit, we'll go ahead and
1560 * expose all planes.
1561 */
1562 int num_overlay_plane;
1563 int num_total_plane;
Jesse Barnes8cf5c912011-11-14 14:51:27 -08001564 struct list_head plane_list;
Dave Airlief453ba02008-11-07 14:05:41 -08001565
1566 int num_crtc;
1567 struct list_head crtc_list;
1568
1569 struct list_head property_list;
1570
Dave Airlief453ba02008-11-07 14:05:41 -08001571 int min_width, min_height;
1572 int max_width, max_height;
Laurent Pincharte6ecefa2012-05-17 13:27:23 +02001573 const struct drm_mode_config_funcs *funcs;
Benjamin Herrenschmidtd883f7f2009-02-02 16:55:45 +11001574 resource_size_t fb_base;
Dave Airlief453ba02008-11-07 14:05:41 -08001575
Dave Airlieeb1f8e42010-05-07 06:42:51 +00001576 /* output poll support */
1577 bool poll_enabled;
Daniel Vetter905bc9f2012-10-23 18:23:36 +00001578 bool poll_running;
Daniel Vetter162b6a52015-01-21 08:45:21 +01001579 bool delayed_event;
Tejun Heo991ea752010-07-20 22:09:02 +02001580 struct delayed_work output_poll_work;
Dave Airlieeb1f8e42010-05-07 06:42:51 +00001581
Daniel Stone8fb6e7a2015-04-20 19:22:54 +01001582 struct mutex blob_lock;
1583
Dave Airlief453ba02008-11-07 14:05:41 -08001584 /* pointers to standard properties */
1585 struct list_head property_blob_list;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02001586 /**
1587 * @edid_property: Default connector property to hold the EDID of the
1588 * currently connected sink, if any.
1589 */
Dave Airlief453ba02008-11-07 14:05:41 -08001590 struct drm_property *edid_property;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02001591 /**
1592 * @dpms_property: Default connector property to control the
1593 * connector's DPMS state.
1594 */
Dave Airlief453ba02008-11-07 14:05:41 -08001595 struct drm_property *dpms_property;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02001596 /**
1597 * @path_property: Default connector property to hold the DP MST path
1598 * for the port.
1599 */
Dave Airlie43aba7e2014-06-05 14:01:31 +10001600 struct drm_property *path_property;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02001601 /**
1602 * @tile_property: Default connector property to store the tile
1603 * position of a tiled screen, for sinks which need to be driven with
1604 * multiple CRTCs.
1605 */
Dave Airlie6f134d72014-10-20 16:30:50 +10001606 struct drm_property *tile_property;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02001607 /**
1608 * @plane_type_property: Default plane property to differentiate
1609 * CURSOR, PRIMARY and OVERLAY legacy uses of planes.
1610 */
Rob Clark9922ab52014-04-01 20:16:57 -04001611 struct drm_property *plane_type_property;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02001612 /**
1613 * @rotation_property: Optional property for planes or CRTCs to specifiy
1614 * rotation.
1615 */
Sonika Jindal2a297cc2014-08-05 11:26:54 +05301616 struct drm_property *rotation_property;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02001617 /**
1618 * @prop_src_x: Default atomic plane property for the plane source
1619 * position in the connected &drm_framebuffer.
1620 */
Rob Clark6b4959f2014-12-18 16:01:53 -05001621 struct drm_property *prop_src_x;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02001622 /**
1623 * @prop_src_y: Default atomic plane property for the plane source
1624 * position in the connected &drm_framebuffer.
1625 */
Rob Clark6b4959f2014-12-18 16:01:53 -05001626 struct drm_property *prop_src_y;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02001627 /**
1628 * @prop_src_w: Default atomic plane property for the plane source
1629 * position in the connected &drm_framebuffer.
1630 */
Rob Clark6b4959f2014-12-18 16:01:53 -05001631 struct drm_property *prop_src_w;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02001632 /**
1633 * @prop_src_h: Default atomic plane property for the plane source
1634 * position in the connected &drm_framebuffer.
1635 */
Rob Clark6b4959f2014-12-18 16:01:53 -05001636 struct drm_property *prop_src_h;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02001637 /**
1638 * @prop_crtc_x: Default atomic plane property for the plane destination
1639 * position in the &drm_crtc is is being shown on.
1640 */
Rob Clark6b4959f2014-12-18 16:01:53 -05001641 struct drm_property *prop_crtc_x;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02001642 /**
1643 * @prop_crtc_y: Default atomic plane property for the plane destination
1644 * position in the &drm_crtc is is being shown on.
1645 */
Rob Clark6b4959f2014-12-18 16:01:53 -05001646 struct drm_property *prop_crtc_y;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02001647 /**
1648 * @prop_crtc_w: Default atomic plane property for the plane destination
1649 * position in the &drm_crtc is is being shown on.
1650 */
Rob Clark6b4959f2014-12-18 16:01:53 -05001651 struct drm_property *prop_crtc_w;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02001652 /**
1653 * @prop_crtc_h: Default atomic plane property for the plane destination
1654 * position in the &drm_crtc is is being shown on.
1655 */
Rob Clark6b4959f2014-12-18 16:01:53 -05001656 struct drm_property *prop_crtc_h;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02001657 /**
1658 * @prop_fb_id: Default atomic plane property to specify the
1659 * &drm_framebuffer.
1660 */
Rob Clark6b4959f2014-12-18 16:01:53 -05001661 struct drm_property *prop_fb_id;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02001662 /**
1663 * @prop_crtc_id: Default atomic plane property to specify the
1664 * &drm_crtc.
1665 */
Rob Clark6b4959f2014-12-18 16:01:53 -05001666 struct drm_property *prop_crtc_id;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02001667 /**
1668 * @prop_active: Default atomic CRTC property to control the active
1669 * state, which is the simplified implementation for DPMS in atomic
1670 * drivers.
1671 */
Daniel Vettereab3bbe2015-01-22 16:36:21 +01001672 struct drm_property *prop_active;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02001673 /**
1674 * @prop_mode_id: Default atomic CRTC property to set the mode for a
1675 * CRTC. A 0 mode implies that the CRTC is entirely disabled - all
1676 * connectors must be of and active must be set to disabled, too.
1677 */
Daniel Stone955f3c32015-05-25 19:11:52 +01001678 struct drm_property *prop_mode_id;
Dave Airlief453ba02008-11-07 14:05:41 -08001679
Daniel Vetter9a6bc032016-07-15 21:48:00 +02001680 /**
1681 * @dvi_i_subconnector_property: Optional DVI-I property to
1682 * differentiate between analog or digital mode.
1683 */
Dave Airlief453ba02008-11-07 14:05:41 -08001684 struct drm_property *dvi_i_subconnector_property;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02001685 /**
1686 * @dvi_i_select_subconnector_property: Optional DVI-I property to
1687 * select between analog or digital mode.
1688 */
Dave Airlief453ba02008-11-07 14:05:41 -08001689 struct drm_property *dvi_i_select_subconnector_property;
1690
Daniel Vetter9a6bc032016-07-15 21:48:00 +02001691 /**
1692 * @tv_subconnector_property: Optional TV property to differentiate
1693 * between different TV connector types.
1694 */
Dave Airlief453ba02008-11-07 14:05:41 -08001695 struct drm_property *tv_subconnector_property;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02001696 /**
1697 * @tv_select_subconnector_property: Optional TV property to select
1698 * between different TV connector types.
1699 */
Dave Airlief453ba02008-11-07 14:05:41 -08001700 struct drm_property *tv_select_subconnector_property;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02001701 /**
1702 * @tv_mode_property: Optional TV property to select
1703 * the output TV mode.
1704 */
Dave Airlief453ba02008-11-07 14:05:41 -08001705 struct drm_property *tv_mode_property;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02001706 /**
1707 * @tv_left_margin_property: Optional TV property to set the left
1708 * margin.
1709 */
Dave Airlief453ba02008-11-07 14:05:41 -08001710 struct drm_property *tv_left_margin_property;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02001711 /**
1712 * @tv_right_margin_property: Optional TV property to set the right
1713 * margin.
1714 */
Dave Airlief453ba02008-11-07 14:05:41 -08001715 struct drm_property *tv_right_margin_property;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02001716 /**
1717 * @tv_top_margin_property: Optional TV property to set the right
1718 * margin.
1719 */
Dave Airlief453ba02008-11-07 14:05:41 -08001720 struct drm_property *tv_top_margin_property;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02001721 /**
1722 * @tv_bottom_margin_property: Optional TV property to set the right
1723 * margin.
1724 */
Dave Airlief453ba02008-11-07 14:05:41 -08001725 struct drm_property *tv_bottom_margin_property;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02001726 /**
1727 * @tv_brightness_property: Optional TV property to set the
1728 * brightness.
1729 */
Francisco Jerezb6b79022009-08-02 04:19:20 +02001730 struct drm_property *tv_brightness_property;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02001731 /**
1732 * @tv_contrast_property: Optional TV property to set the
1733 * contrast.
1734 */
Francisco Jerezb6b79022009-08-02 04:19:20 +02001735 struct drm_property *tv_contrast_property;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02001736 /**
1737 * @tv_flicker_reduction_property: Optional TV property to control the
1738 * flicker reduction mode.
1739 */
Francisco Jerezb6b79022009-08-02 04:19:20 +02001740 struct drm_property *tv_flicker_reduction_property;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02001741 /**
1742 * @tv_overscan_property: Optional TV property to control the overscan
1743 * setting.
1744 */
Francisco Jereza75f0232009-08-12 02:30:10 +02001745 struct drm_property *tv_overscan_property;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02001746 /**
1747 * @tv_saturation_property: Optional TV property to set the
1748 * saturation.
1749 */
Francisco Jereza75f0232009-08-12 02:30:10 +02001750 struct drm_property *tv_saturation_property;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02001751 /**
1752 * @tv_hue_property: Optional TV property to set the hue.
1753 */
Francisco Jereza75f0232009-08-12 02:30:10 +02001754 struct drm_property *tv_hue_property;
Dave Airlief453ba02008-11-07 14:05:41 -08001755
Daniel Vetter9a6bc032016-07-15 21:48:00 +02001756 /**
1757 * @scaling_mode_property: Optional connector property to control the
1758 * upscaling, mostly used for built-in panels.
1759 */
Dave Airlief453ba02008-11-07 14:05:41 -08001760 struct drm_property *scaling_mode_property;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02001761 /**
1762 * @aspect_ratio_property: Optional connector property to control the
1763 * HDMI infoframe aspect ratio setting.
1764 */
Vandana Kannanff587e42014-06-11 10:46:48 +05301765 struct drm_property *aspect_ratio_property;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02001766 /**
Daniel Vetter9a6bc032016-07-15 21:48:00 +02001767 * @degamma_lut_property: Optional CRTC property to set the LUT used to
1768 * convert the framebuffer's colors to linear gamma.
1769 */
Lionel Landwerlin5488dc12016-02-26 17:05:00 +00001770 struct drm_property *degamma_lut_property;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02001771 /**
1772 * @degamma_lut_size_property: Optional CRTC property for the size of
1773 * the degamma LUT as supported by the driver (read-only).
1774 */
Lionel Landwerlin5488dc12016-02-26 17:05:00 +00001775 struct drm_property *degamma_lut_size_property;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02001776 /**
1777 * @ctm_property: Optional CRTC property to set the
1778 * matrix used to convert colors after the lookup in the
1779 * degamma LUT.
1780 */
Lionel Landwerlin5488dc12016-02-26 17:05:00 +00001781 struct drm_property *ctm_property;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02001782 /**
1783 * @gamma_lut_property: Optional CRTC property to set the LUT used to
1784 * convert the colors, after the CTM matrix, to the gamma space of the
1785 * connected screen.
1786 */
Lionel Landwerlin5488dc12016-02-26 17:05:00 +00001787 struct drm_property *gamma_lut_property;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02001788 /**
1789 * @gamma_lut_size_property: Optional CRTC property for the size of the
1790 * gamma LUT as supported by the driver (read-only).
1791 */
Lionel Landwerlin5488dc12016-02-26 17:05:00 +00001792 struct drm_property *gamma_lut_size_property;
1793
Daniel Vetter9a6bc032016-07-15 21:48:00 +02001794 /**
1795 * @suggested_x_property: Optional connector property with a hint for
1796 * the position of the output on the host's screen.
1797 */
Dave Airlie5bb2bbf2014-11-10 10:18:15 +10001798 struct drm_property *suggested_x_property;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02001799 /**
1800 * @suggested_y_property: Optional connector property with a hint for
1801 * the position of the output on the host's screen.
1802 */
Dave Airlie5bb2bbf2014-11-10 10:18:15 +10001803 struct drm_property *suggested_y_property;
1804
Dave Airlie019d96c2011-09-29 16:20:42 +01001805 /* dumb ioctl parameters */
1806 uint32_t preferred_depth, prefer_shadow;
Keith Packard62f21042013-07-22 18:50:00 -07001807
Daniel Vetter9a6bc032016-07-15 21:48:00 +02001808 /**
1809 * @async_page_flip: Does this device support async flips on the primary
1810 * plane?
1811 */
Keith Packard62f21042013-07-22 18:50:00 -07001812 bool async_page_flip;
Alex Deucher8716ed42014-02-12 12:48:23 -05001813
Daniel Vetterac3ba4a2016-05-31 23:11:10 +02001814 /**
1815 * @allow_fb_modifiers:
1816 *
1817 * Whether the driver supports fb modifiers in the ADDFB2.1 ioctl call.
1818 */
Rob Clarke3eb3252015-02-05 14:41:52 +00001819 bool allow_fb_modifiers;
1820
Alex Deucher8716ed42014-02-12 12:48:23 -05001821 /* cursor size */
1822 uint32_t cursor_width, cursor_height;
Daniel Vetter9f2a7952016-06-08 14:19:02 +02001823
1824 struct drm_mode_config_helper_funcs *helper_private;
Dave Airlief453ba02008-11-07 14:05:41 -08001825};
1826
Rob Clarkdd275952014-11-25 20:29:46 -05001827/**
1828 * drm_for_each_plane_mask - iterate over planes specified by bitmask
1829 * @plane: the loop cursor
1830 * @dev: the DRM device
1831 * @plane_mask: bitmask of plane indices
1832 *
1833 * Iterate over all planes specified by bitmask.
1834 */
1835#define drm_for_each_plane_mask(plane, dev, plane_mask) \
1836 list_for_each_entry((plane), &(dev)->mode_config.plane_list, head) \
Jani Nikula373701b2015-11-24 21:21:55 +02001837 for_each_if ((plane_mask) & (1 << drm_plane_index(plane)))
Rob Clarkdd275952014-11-25 20:29:46 -05001838
Dave Airlief453ba02008-11-07 14:05:41 -08001839#define obj_to_crtc(x) container_of(x, struct drm_crtc, base)
Jesse Barnes8cf5c912011-11-14 14:51:27 -08001840#define obj_to_plane(x) container_of(x, struct drm_plane, base)
Dave Airlief453ba02008-11-07 14:05:41 -08001841
Ville Syrjäläf9882872015-12-09 16:19:31 +02001842extern __printf(6, 7)
1843int drm_crtc_init_with_planes(struct drm_device *dev,
1844 struct drm_crtc *crtc,
1845 struct drm_plane *primary,
1846 struct drm_plane *cursor,
1847 const struct drm_crtc_funcs *funcs,
1848 const char *name, ...);
Dave Airlief453ba02008-11-07 14:05:41 -08001849extern void drm_crtc_cleanup(struct drm_crtc *crtc);
Chris Wilson490d3d12016-05-27 20:05:00 +01001850
1851/**
1852 * drm_crtc_index - find the index of a registered CRTC
1853 * @crtc: CRTC to find index for
1854 *
1855 * Given a registered CRTC, return the index of that CRTC within a DRM
1856 * device's list of CRTCs.
1857 */
1858static inline unsigned int drm_crtc_index(struct drm_crtc *crtc)
1859{
1860 return crtc->index;
1861}
Russell Kingdb5f7a62014-01-02 21:27:33 +00001862
1863/**
1864 * drm_crtc_mask - find the mask of a registered CRTC
1865 * @crtc: CRTC to find mask for
1866 *
1867 * Given a registered CRTC, return the mask bit of that CRTC for an
1868 * encoder's possible_crtcs field.
1869 */
1870static inline uint32_t drm_crtc_mask(struct drm_crtc *crtc)
1871{
1872 return 1 << drm_crtc_index(crtc);
1873}
Dave Airlief453ba02008-11-07 14:05:41 -08001874
Ville Syrjäläb0b3b792015-12-09 16:19:55 +02001875extern __printf(8, 9)
1876int drm_universal_plane_init(struct drm_device *dev,
1877 struct drm_plane *plane,
1878 unsigned long possible_crtcs,
1879 const struct drm_plane_funcs *funcs,
1880 const uint32_t *formats,
1881 unsigned int format_count,
1882 enum drm_plane_type type,
1883 const char *name, ...);
Jesse Barnes8cf5c912011-11-14 14:51:27 -08001884extern int drm_plane_init(struct drm_device *dev,
1885 struct drm_plane *plane,
1886 unsigned long possible_crtcs,
1887 const struct drm_plane_funcs *funcs,
Thierry Reding45e37432015-08-12 16:54:28 +02001888 const uint32_t *formats, unsigned int format_count,
Matt Roperdc415ff2014-04-01 15:22:36 -07001889 bool is_primary);
Jesse Barnes8cf5c912011-11-14 14:51:27 -08001890extern void drm_plane_cleanup(struct drm_plane *plane);
Chris Wilson490d3d12016-05-27 20:05:00 +01001891
1892/**
1893 * drm_plane_index - find the index of a registered plane
1894 * @plane: plane to find index for
1895 *
1896 * Given a registered plane, return the index of that plane within a DRM
1897 * device's list of planes.
1898 */
1899static inline unsigned int drm_plane_index(struct drm_plane *plane)
1900{
1901 return plane->index;
1902}
Chandra Konduruf81338a2015-04-09 17:36:21 -07001903extern struct drm_plane * drm_plane_from_index(struct drm_device *dev, int idx);
Ville Syrjälä9125e612013-06-03 16:10:40 +03001904extern void drm_plane_force_disable(struct drm_plane *plane);
Gustavo Padovanecb7e162014-12-01 15:40:09 -08001905extern void drm_crtc_get_hv_timing(const struct drm_display_mode *mode,
1906 int *hdisplay, int *vdisplay);
Lukas Wunner6a0d9522016-06-08 18:47:27 +02001907extern int drm_crtc_force_disable(struct drm_crtc *crtc);
1908extern int drm_crtc_force_disable_all(struct drm_device *dev);
Jesse Barnes8cf5c912011-11-14 14:51:27 -08001909
Dave Airlief453ba02008-11-07 14:05:41 -08001910extern void drm_mode_config_init(struct drm_device *dev);
Chris Wilsoneb033552011-01-24 15:11:08 +00001911extern void drm_mode_config_reset(struct drm_device *dev);
Dave Airlief453ba02008-11-07 14:05:41 -08001912extern void drm_mode_config_cleanup(struct drm_device *dev);
Dave Airlief453ba02008-11-07 14:05:41 -08001913
Sascha Hauer4cae5b82012-02-01 11:38:23 +01001914extern int drm_mode_crtc_set_gamma_size(struct drm_crtc *crtc,
Dave Airlief453ba02008-11-07 14:05:41 -08001915 int gamma_size);
Rob Clark98f75de2014-05-30 11:37:03 -04001916
Daniel Vetter2d13b672012-12-11 13:47:23 +01001917extern int drm_mode_set_config_internal(struct drm_mode_set *set);
Daniel Vetter81065542016-06-21 10:54:13 +02001918
Dave Airlie138f9eb2014-10-20 16:17:17 +10001919extern struct drm_tile_group *drm_mode_create_tile_group(struct drm_device *dev,
1920 char topology[8]);
1921extern struct drm_tile_group *drm_mode_get_tile_group(struct drm_device *dev,
1922 char topology[8]);
1923extern void drm_mode_put_tile_group(struct drm_device *dev,
1924 struct drm_tile_group *tg);
Dave Airlieff72145b2011-02-07 12:16:14 +10001925
Thomas Wood3a5f87c2014-08-20 14:45:00 +01001926extern int drm_mode_plane_set_obj_prop(struct drm_plane *plane,
1927 struct drm_property *property,
1928 uint64_t value);
Dave Airlie248dbc22011-11-29 20:02:54 +00001929
Ville Syrjäläc1df5f32014-07-08 10:31:53 +05301930extern struct drm_property *drm_mode_create_rotation_property(struct drm_device *dev,
1931 unsigned int supported_rotations);
Ville Syrjälä3c9855f2014-07-08 10:31:56 +05301932extern unsigned int drm_rotation_simplify(unsigned int rotation,
1933 unsigned int supported_rotations);
Jyri Sarhaf8ed34a2016-06-07 15:09:14 +03001934extern void drm_crtc_enable_color_mgmt(struct drm_crtc *crtc,
1935 uint degamma_lut_size,
1936 bool has_ctm,
1937 uint gamma_lut_size);
Marek Szyprowski44d1240d2016-06-13 11:11:26 +02001938
1939int drm_plane_create_zpos_property(struct drm_plane *plane,
1940 unsigned int zpos,
1941 unsigned int min, unsigned int max);
1942
1943int drm_plane_create_zpos_immutable_property(struct drm_plane *plane,
1944 unsigned int zpos);
1945
Russell King96f60e32012-08-15 13:59:49 +01001946/* Helpers */
Rob Clarka2b34e22013-10-05 16:36:52 -04001947static inline struct drm_plane *drm_plane_find(struct drm_device *dev,
1948 uint32_t id)
1949{
1950 struct drm_mode_object *mo;
1951 mo = drm_mode_object_find(dev, id, DRM_MODE_OBJECT_PLANE);
1952 return mo ? obj_to_plane(mo) : NULL;
1953}
1954
Russell King96f60e32012-08-15 13:59:49 +01001955static inline struct drm_crtc *drm_crtc_find(struct drm_device *dev,
1956 uint32_t id)
1957{
1958 struct drm_mode_object *mo;
1959 mo = drm_mode_object_find(dev, id, DRM_MODE_OBJECT_CRTC);
1960 return mo ? obj_to_crtc(mo) : NULL;
1961}
1962
Lionel Landwerlin5488dc12016-02-26 17:05:00 +00001963/*
1964 * Extract a degamma/gamma LUT value provided by user and round it to the
1965 * precision supported by the hardware.
1966 */
1967static inline uint32_t drm_color_lut_extract(uint32_t user_input,
1968 uint32_t bit_precision)
1969{
Lionel Landwerlin644a8052016-03-22 14:10:33 +00001970 uint32_t val = user_input;
Lionel Landwerlin5488dc12016-02-26 17:05:00 +00001971 uint32_t max = 0xffff >> (16 - bit_precision);
1972
Lionel Landwerlin644a8052016-03-22 14:10:33 +00001973 /* Round only if we're not using full precision. */
1974 if (bit_precision < 16) {
1975 val += 1UL << (16 - bit_precision - 1);
1976 val >>= 16 - bit_precision;
1977 }
Lionel Landwerlin5488dc12016-02-26 17:05:00 +00001978
1979 return clamp_val(val, 0, max);
1980}
1981
Matt Ropere27dde32014-04-01 15:22:30 -07001982/* Plane list iterator for legacy (overlay only) planes. */
Daniel Vetter4ea50e92015-07-09 23:44:24 +02001983#define drm_for_each_legacy_plane(plane, dev) \
1984 list_for_each_entry(plane, &(dev)->mode_config.plane_list, head) \
Jani Nikula373701b2015-11-24 21:21:55 +02001985 for_each_if (plane->type == DRM_PLANE_TYPE_OVERLAY)
Matt Ropere27dde32014-04-01 15:22:30 -07001986
Daniel Vetter6295d602015-07-09 23:44:25 +02001987#define drm_for_each_plane(plane, dev) \
1988 list_for_each_entry(plane, &(dev)->mode_config.plane_list, head)
1989
1990#define drm_for_each_crtc(crtc, dev) \
1991 list_for_each_entry(crtc, &(dev)->mode_config.crtc_list, head)
1992
Daniel Vetter7a3f3d62015-07-09 23:44:28 +02001993static inline void
1994assert_drm_connector_list_read_locked(struct drm_mode_config *mode_config)
1995{
Daniel Vettercff20ba2015-07-09 23:44:33 +02001996 /*
1997 * The connector hotadd/remove code currently grabs both locks when
1998 * updating lists. Hence readers need only hold either of them to be
1999 * safe and the check amounts to
2000 *
2001 * WARN_ON(not_holding(A) && not_holding(B)).
2002 */
2003 WARN_ON(!mutex_is_locked(&mode_config->mutex) &&
2004 !drm_modeset_is_locked(&mode_config->connection_mutex));
Daniel Vetter7a3f3d62015-07-09 23:44:28 +02002005}
2006
Daniel Vetter81065542016-06-21 10:54:13 +02002007/* drm_edid.c */
2008bool drm_probe_ddc(struct i2c_adapter *adapter);
2009struct edid *drm_get_edid(struct drm_connector *connector,
2010 struct i2c_adapter *adapter);
2011struct edid *drm_get_edid_switcheroo(struct drm_connector *connector,
2012 struct i2c_adapter *adapter);
2013struct edid *drm_edid_duplicate(const struct edid *edid);
2014int drm_add_edid_modes(struct drm_connector *connector, struct edid *edid);
2015
2016u8 drm_match_cea_mode(const struct drm_display_mode *to_match);
2017enum hdmi_picture_aspect drm_get_cea_aspect_ratio(const u8 video_code);
2018bool drm_detect_hdmi_monitor(struct edid *edid);
2019bool drm_detect_monitor_audio(struct edid *edid);
2020bool drm_rgb_quant_range_selectable(struct edid *edid);
2021int drm_add_modes_noedid(struct drm_connector *connector,
2022 int hdisplay, int vdisplay);
2023void drm_set_preferred_mode(struct drm_connector *connector,
2024 int hpref, int vpref);
2025
2026int drm_edid_header_is_valid(const u8 *raw_edid);
2027bool drm_edid_block_valid(u8 *raw_edid, int block, bool print_bad_edid,
2028 bool *edid_corrupt);
2029bool drm_edid_is_valid(struct edid *edid);
2030void drm_edid_get_monitor_name(struct edid *edid, char *name,
2031 int buflen);
2032struct drm_display_mode *drm_mode_find_dmt(struct drm_device *dev,
2033 int hsize, int vsize, int fresh,
2034 bool rb);
2035
Dave Airlief453ba02008-11-07 14:05:41 -08002036#endif /* __DRM_CRTC_H__ */