blob: 9375e5c9cddb0bd95e8f190a453ee82b4c788bdb [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>
Daniel Vettercdc3d092016-08-31 18:09:06 +020046#include <drm/drm_edid.h>
Daniel Vetter43968d72016-09-21 10:59:24 +020047#include <drm/drm_plane.h>
Jesse Barnes308e5bc2011-11-14 14:51:28 -080048
Dave Airlief453ba02008-11-07 14:05:41 -080049struct drm_device;
50struct drm_mode_set;
Thierry Reding595887e2012-11-21 15:00:47 +010051struct drm_file;
52struct drm_clip_rect;
Russell King7e435aa2014-06-15 11:07:12 +010053struct device_node;
Daniel Vettere2330f02014-10-29 11:34:56 +010054struct fence;
Daniel Vetter81065542016-06-21 10:54:13 +020055struct edid;
Dave Airlief453ba02008-11-07 14:05:41 -080056
Rob Clarkebc44cf2012-09-12 22:22:31 -050057static inline int64_t U642I64(uint64_t val)
58{
59 return (int64_t)*((int64_t *)&val);
60}
61static inline uint64_t I642U64(int64_t val)
62{
63 return (uint64_t)*((uint64_t *)&val);
64}
65
Robert Feketed9c38242015-11-02 16:14:08 +010066/*
67 * Rotation property bits. DRM_ROTATE_<degrees> rotates the image by the
68 * specified amount in degrees in counter clockwise direction. DRM_REFLECT_X and
69 * DRM_REFLECT_Y reflects the image along the specified axis prior to rotation
70 */
Joonas Lahtinen31ad61e2016-07-29 08:50:05 +030071#define DRM_ROTATE_0 BIT(0)
72#define DRM_ROTATE_90 BIT(1)
73#define DRM_ROTATE_180 BIT(2)
74#define DRM_ROTATE_270 BIT(3)
75#define DRM_ROTATE_MASK (DRM_ROTATE_0 | DRM_ROTATE_90 | \
76 DRM_ROTATE_180 | DRM_ROTATE_270)
77#define DRM_REFLECT_X BIT(4)
78#define DRM_REFLECT_Y BIT(5)
79#define DRM_REFLECT_MASK (DRM_REFLECT_X | DRM_REFLECT_Y)
Ville Syrjälä06596962014-07-08 10:31:51 +053080
Dave Airlie138f9eb2014-10-20 16:17:17 +100081/* data corresponds to displayid vend/prod/serial */
82struct drm_tile_group {
83 struct kref refcount;
84 struct drm_device *dev;
85 int id;
86 u8 group_data[8];
87};
88
Dave Airlief453ba02008-11-07 14:05:41 -080089struct drm_crtc;
Dave Airlief453ba02008-11-07 14:05:41 -080090struct drm_encoder;
Kristian Høgsbergd91d8a32009-11-17 12:43:55 -050091struct drm_pending_vblank_event;
Jesse Barnes8cf5c912011-11-14 14:51:27 -080092struct drm_plane;
Sean Paul3b336ec2013-08-14 16:47:37 -040093struct drm_bridge;
Daniel Vetter144ecb92014-10-27 20:28:44 +010094struct drm_atomic_state;
95
Daniel Vetter4490d4c2015-12-04 09:45:45 +010096struct drm_crtc_helper_funcs;
97struct drm_encoder_helper_funcs;
Daniel Vetter4490d4c2015-12-04 09:45:45 +010098struct drm_plane_helper_funcs;
99
Daniel Vetter144ecb92014-10-27 20:28:44 +0100100/**
Daniel Vettercc4ceb42014-07-25 21:30:38 +0200101 * struct drm_crtc_state - mutable CRTC state
Daniel Vetter07cc0ef2014-11-27 15:49:39 +0100102 * @crtc: backpointer to the CRTC
Daniel Vetter144ecb92014-10-27 20:28:44 +0100103 * @enable: whether the CRTC should be enabled, gates all other state
Daniel Vetterd9b13622014-11-26 16:57:41 +0100104 * @active: whether the CRTC is actively displaying (used for DPMS)
Maarten Lankhorstfc596662015-07-21 13:28:57 +0200105 * @planes_changed: planes on this crtc are updated
106 * @mode_changed: crtc_state->mode or crtc_state->enable has been changed
107 * @active_changed: crtc_state->active has been toggled.
108 * @connectors_changed: connectors to this crtc have been updated
Marek Szyprowski44d1240d2016-06-13 11:11:26 +0200109 * @zpos_changed: zpos values of planes on this crtc have been updated
Lionel Landwerlin5488dc12016-02-26 17:05:00 +0000110 * @color_mgmt_changed: color management properties have changed (degamma or
111 * gamma LUT or CSC matrix)
Rob Clark6ddd3882014-11-21 15:28:31 -0500112 * @plane_mask: bitmask of (1 << drm_plane_index(plane)) of attached planes
Maarten Lankhorst4cd9fa52016-01-04 12:53:18 +0100113 * @connector_mask: bitmask of (1 << drm_connector_index(connector)) of attached connectors
Maarten Lankhorste87a52b2016-01-28 15:04:58 +0100114 * @encoder_mask: bitmask of (1 << drm_encoder_index(encoder)) of attached encoders
Daniel Vetter623369e2014-09-16 17:50:47 +0200115 * @last_vblank_count: for helpers and drivers to capture the vblank of the
116 * update to ensure framebuffer cleanup isn't done too early
Daniel Vetter2f324b42014-10-29 11:13:47 +0100117 * @adjusted_mode: for use by helpers and drivers to compute adjusted mode timings
Daniel Vetter144ecb92014-10-27 20:28:44 +0100118 * @mode: current mode timings
Daniel Vetterac3ba4a2016-05-31 23:11:10 +0200119 * @mode_blob: &drm_property_blob for @mode
Lionel Landwerlin5488dc12016-02-26 17:05:00 +0000120 * @degamma_lut: Lookup table for converting framebuffer pixel data
121 * before apply the conversion matrix
122 * @ctm: Transformation matrix
123 * @gamma_lut: Lookup table for converting pixel data after the
124 * conversion matrix
Daniel Vetter144ecb92014-10-27 20:28:44 +0100125 * @event: optional pointer to a DRM event to signal upon completion of the
126 * state update
127 * @state: backpointer to global drm_atomic_state
Daniel Vetterd9b13622014-11-26 16:57:41 +0100128 *
129 * Note that the distinction between @enable and @active is rather subtile:
130 * Flipping @active while @enable is set without changing anything else may
131 * never return in a failure from the ->atomic_check callback. Userspace assumes
132 * that a DPMS On will always succeed. In other words: @enable controls resource
133 * assignment, @active controls the actual hardware state.
Daniel Vetter144ecb92014-10-27 20:28:44 +0100134 */
135struct drm_crtc_state {
Daniel Vetter07cc0ef2014-11-27 15:49:39 +0100136 struct drm_crtc *crtc;
137
Daniel Vettercc4ceb42014-07-25 21:30:38 +0200138 bool enable;
Daniel Vetterd9b13622014-11-26 16:57:41 +0100139 bool active;
Daniel Vetter144ecb92014-10-27 20:28:44 +0100140
Daniel Vetterc2fcd272014-11-05 00:14:14 +0100141 /* computed state bits used by helpers and drivers */
142 bool planes_changed : 1;
Daniel Vetter623369e2014-09-16 17:50:47 +0200143 bool mode_changed : 1;
Daniel Vettereab3bbe2015-01-22 16:36:21 +0100144 bool active_changed : 1;
Maarten Lankhorstfc596662015-07-21 13:28:57 +0200145 bool connectors_changed : 1;
Marek Szyprowski44d1240d2016-06-13 11:11:26 +0200146 bool zpos_changed : 1;
Lionel Landwerlin5488dc12016-02-26 17:05:00 +0000147 bool color_mgmt_changed : 1;
Daniel Vetter623369e2014-09-16 17:50:47 +0200148
Rob Clark6ddd3882014-11-21 15:28:31 -0500149 /* attached planes bitmask:
150 * WARNING: transitional helpers do not maintain plane_mask so
151 * drivers not converted over to atomic helpers should not rely
152 * on plane_mask being accurate!
153 */
154 u32 plane_mask;
155
Maarten Lankhorst4cd9fa52016-01-04 12:53:18 +0100156 u32 connector_mask;
Maarten Lankhorste87a52b2016-01-28 15:04:58 +0100157 u32 encoder_mask;
Maarten Lankhorst4cd9fa52016-01-04 12:53:18 +0100158
Daniel Vetter623369e2014-09-16 17:50:47 +0200159 /* last_vblank_count: for vblank waits before cleanup */
160 u32 last_vblank_count;
Daniel Vetterc2fcd272014-11-05 00:14:14 +0100161
Daniel Vetter2f324b42014-10-29 11:13:47 +0100162 /* adjusted_mode: for use by helpers and drivers */
163 struct drm_display_mode adjusted_mode;
164
Daniel Vetter144ecb92014-10-27 20:28:44 +0100165 struct drm_display_mode mode;
166
Daniel Stone99cf4a22015-05-25 19:11:51 +0100167 /* blob property to expose current mode to atomic userspace */
168 struct drm_property_blob *mode_blob;
169
Lionel Landwerlin5488dc12016-02-26 17:05:00 +0000170 /* blob property to expose color management to userspace */
171 struct drm_property_blob *degamma_lut;
172 struct drm_property_blob *ctm;
173 struct drm_property_blob *gamma_lut;
174
Daniel Vetter144ecb92014-10-27 20:28:44 +0100175 struct drm_pending_vblank_event *event;
176
177 struct drm_atomic_state *state;
178};
Dave Airlief453ba02008-11-07 14:05:41 -0800179
180/**
Daniel Vetter3bf04012014-10-27 16:54:27 +0100181 * struct drm_crtc_funcs - control CRTCs for a given device
Dave Airlief453ba02008-11-07 14:05:41 -0800182 *
183 * The drm_crtc_funcs structure is the central CRTC management structure
184 * in the DRM. Each CRTC controls one or more connectors (note that the name
185 * CRTC is simply historical, a CRTC may control LVDS, VGA, DVI, TV out, etc.
186 * connectors, not just CRTs).
187 *
188 * Each driver is responsible for filling out this structure at startup time,
189 * in addition to providing other modesetting features, like i2c and DDC
190 * bus accessors.
191 */
192struct drm_crtc_funcs {
Daniel Vetter88548632015-12-04 09:45:48 +0100193 /**
194 * @reset:
195 *
196 * Reset CRTC hardware and software state to off. This function isn't
197 * called by the core directly, only through drm_mode_config_reset().
198 * It's not a helper hook only for historical reasons.
199 *
200 * Atomic drivers can use drm_atomic_helper_crtc_reset() to reset
201 * atomic state using this hook.
202 */
Chris Wilsoneb033552011-01-24 15:11:08 +0000203 void (*reset)(struct drm_crtc *crtc);
Dave Airlief453ba02008-11-07 14:05:41 -0800204
Daniel Vetterf6da8c62015-12-04 09:46:00 +0100205 /**
206 * @cursor_set:
207 *
208 * Update the cursor image. The cursor position is relative to the CRTC
209 * and can be partially or fully outside of the visible area.
210 *
211 * Note that contrary to all other KMS functions the legacy cursor entry
212 * points don't take a framebuffer object, but instead take directly a
213 * raw buffer object id from the driver's buffer manager (which is
214 * either GEM or TTM for current drivers).
215 *
216 * This entry point is deprecated, drivers should instead implement
217 * universal plane support and register a proper cursor plane using
218 * drm_crtc_init_with_planes().
219 *
220 * This callback is optional
221 *
222 * RETURNS:
223 *
224 * 0 on success or a negative error code on failure.
225 */
Dave Airlief453ba02008-11-07 14:05:41 -0800226 int (*cursor_set)(struct drm_crtc *crtc, struct drm_file *file_priv,
227 uint32_t handle, uint32_t width, uint32_t height);
Daniel Vetterf6da8c62015-12-04 09:46:00 +0100228
229 /**
230 * @cursor_set2:
231 *
232 * Update the cursor image, including hotspot information. The hotspot
233 * must not affect the cursor position in CRTC coordinates, but is only
234 * meant as a hint for virtualized display hardware to coordinate the
235 * guests and hosts cursor position. The cursor hotspot is relative to
236 * the cursor image. Otherwise this works exactly like @cursor_set.
237 *
238 * This entry point is deprecated, drivers should instead implement
239 * universal plane support and register a proper cursor plane using
240 * drm_crtc_init_with_planes().
241 *
242 * This callback is optional.
243 *
244 * RETURNS:
245 *
246 * 0 on success or a negative error code on failure.
247 */
Dave Airlie4c813d42013-06-20 11:48:52 +1000248 int (*cursor_set2)(struct drm_crtc *crtc, struct drm_file *file_priv,
249 uint32_t handle, uint32_t width, uint32_t height,
250 int32_t hot_x, int32_t hot_y);
Daniel Vetterf6da8c62015-12-04 09:46:00 +0100251
252 /**
253 * @cursor_move:
254 *
255 * Update the cursor position. The cursor does not need to be visible
256 * when this hook is called.
257 *
258 * This entry point is deprecated, drivers should instead implement
259 * universal plane support and register a proper cursor plane using
260 * drm_crtc_init_with_planes().
261 *
262 * This callback is optional.
263 *
264 * RETURNS:
265 *
266 * 0 on success or a negative error code on failure.
267 */
Dave Airlief453ba02008-11-07 14:05:41 -0800268 int (*cursor_move)(struct drm_crtc *crtc, int x, int y);
269
Daniel Vetterf6da8c62015-12-04 09:46:00 +0100270 /**
271 * @gamma_set:
272 *
273 * Set gamma on the CRTC.
274 *
275 * This callback is optional.
276 *
277 * NOTE:
278 *
279 * Drivers that support gamma tables and also fbdev emulation through
280 * the provided helper library need to take care to fill out the gamma
281 * hooks for both. Currently there's a bit an unfortunate duplication
282 * going on, which should eventually be unified to just one set of
283 * hooks.
284 */
Maarten Lankhorst7ea77282016-06-07 12:49:30 +0200285 int (*gamma_set)(struct drm_crtc *crtc, u16 *r, u16 *g, u16 *b,
286 uint32_t size);
Daniel Vetter88548632015-12-04 09:45:48 +0100287
288 /**
289 * @destroy:
290 *
291 * Clean up plane resources. This is only called at driver unload time
292 * through drm_mode_config_cleanup() since a CRTC cannot be hotplugged
293 * in DRM.
294 */
Dave Airlief453ba02008-11-07 14:05:41 -0800295 void (*destroy)(struct drm_crtc *crtc);
296
Daniel Vetterf6da8c62015-12-04 09:46:00 +0100297 /**
298 * @set_config:
299 *
300 * This is the main legacy entry point to change the modeset state on a
301 * CRTC. All the details of the desired configuration are passed in a
302 * struct &drm_mode_set - see there for details.
303 *
304 * Drivers implementing atomic modeset should use
305 * drm_atomic_helper_set_config() to implement this hook.
306 *
307 * RETURNS:
308 *
309 * 0 on success or a negative error code on failure.
310 */
Dave Airlief453ba02008-11-07 14:05:41 -0800311 int (*set_config)(struct drm_mode_set *set);
Kristian Høgsbergd91d8a32009-11-17 12:43:55 -0500312
Daniel Vetterf6da8c62015-12-04 09:46:00 +0100313 /**
314 * @page_flip:
315 *
316 * Legacy entry point to schedule a flip to the given framebuffer.
317 *
318 * Page flipping is a synchronization mechanism that replaces the frame
319 * buffer being scanned out by the CRTC with a new frame buffer during
320 * vertical blanking, avoiding tearing (except when requested otherwise
321 * through the DRM_MODE_PAGE_FLIP_ASYNC flag). When an application
322 * requests a page flip the DRM core verifies that the new frame buffer
323 * is large enough to be scanned out by the CRTC in the currently
324 * configured mode and then calls the CRTC ->page_flip() operation with a
325 * pointer to the new frame buffer.
326 *
327 * The driver must wait for any pending rendering to the new framebuffer
328 * to complete before executing the flip. It should also wait for any
329 * pending rendering from other drivers if the underlying buffer is a
330 * shared dma-buf.
331 *
332 * An application can request to be notified when the page flip has
333 * completed. The drm core will supply a struct &drm_event in the event
334 * parameter in this case. This can be handled by the
335 * drm_crtc_send_vblank_event() function, which the driver should call on
336 * the provided event upon completion of the flip. Note that if
337 * the driver supports vblank signalling and timestamping the vblank
338 * counters and timestamps must agree with the ones returned from page
339 * flip events. With the current vblank helper infrastructure this can
340 * be achieved by holding a vblank reference while the page flip is
341 * pending, acquired through drm_crtc_vblank_get() and released with
342 * drm_crtc_vblank_put(). Drivers are free to implement their own vblank
343 * counter and timestamp tracking though, e.g. if they have accurate
344 * timestamp registers in hardware.
345 *
Daniel Vetterf6da8c62015-12-04 09:46:00 +0100346 * This callback is optional.
347 *
348 * NOTE:
349 *
350 * Very early versions of the KMS ABI mandated that the driver must
351 * block (but not reject) any rendering to the old framebuffer until the
352 * flip operation has completed and the old framebuffer is no longer
353 * visible. This requirement has been lifted, and userspace is instead
354 * expected to request delivery of an event and wait with recycling old
355 * buffers until such has been received.
356 *
357 * RETURNS:
358 *
359 * 0 on success or a negative error code on failure. Note that if a
360 * ->page_flip() operation is already pending the callback should return
361 * -EBUSY. Pageflips on a disabled CRTC (either by setting a NULL mode
362 * or just runtime disabled through DPMS respectively the new atomic
Daniel Vetter4cba6852015-12-08 09:49:20 +0100363 * "ACTIVE" state) should result in an -EINVAL error code. Note that
364 * drm_atomic_helper_page_flip() checks this already for atomic drivers.
Kristian Høgsbergd91d8a32009-11-17 12:43:55 -0500365 */
366 int (*page_flip)(struct drm_crtc *crtc,
367 struct drm_framebuffer *fb,
Keith Packarded8d1972013-07-22 18:49:58 -0700368 struct drm_pending_vblank_event *event,
369 uint32_t flags);
Paulo Zanonibffd9de02012-05-15 18:09:05 -0300370
Daniel Vetter88548632015-12-04 09:45:48 +0100371 /**
Michel Dänzerc229bfb2016-08-08 16:23:03 +0900372 * @page_flip_target:
373 *
374 * Same as @page_flip but with an additional parameter specifying the
375 * absolute target vertical blank period (as reported by
376 * drm_crtc_vblank_count()) when the flip should take effect.
377 *
378 * Note that the core code calls drm_crtc_vblank_get before this entry
379 * point, and will call drm_crtc_vblank_put if this entry point returns
380 * any non-0 error code. It's the driver's responsibility to call
381 * drm_crtc_vblank_put after this entry point returns 0, typically when
382 * the flip completes.
383 */
384 int (*page_flip_target)(struct drm_crtc *crtc,
385 struct drm_framebuffer *fb,
386 struct drm_pending_vblank_event *event,
387 uint32_t flags, uint32_t target);
388
389 /**
Daniel Vetter88548632015-12-04 09:45:48 +0100390 * @set_property:
391 *
392 * This is the legacy entry point to update a property attached to the
393 * CRTC.
394 *
395 * Drivers implementing atomic modeset should use
396 * drm_atomic_helper_crtc_set_property() to implement this hook.
397 *
398 * This callback is optional if the driver does not support any legacy
399 * driver-private properties.
400 *
401 * RETURNS:
402 *
403 * 0 on success or a negative error code on failure.
404 */
Paulo Zanonibffd9de02012-05-15 18:09:05 -0300405 int (*set_property)(struct drm_crtc *crtc,
406 struct drm_property *property, uint64_t val);
Daniel Vetter144ecb92014-10-27 20:28:44 +0100407
Daniel Vetter88548632015-12-04 09:45:48 +0100408 /**
409 * @atomic_duplicate_state:
410 *
411 * Duplicate the current atomic state for this CRTC and return it.
412 * The core and helpers gurantee that any atomic state duplicated with
413 * this hook and still owned by the caller (i.e. not transferred to the
414 * driver by calling ->atomic_commit() from struct
415 * &drm_mode_config_funcs) will be cleaned up by calling the
416 * @atomic_destroy_state hook in this structure.
417 *
418 * Atomic drivers which don't subclass struct &drm_crtc should use
419 * drm_atomic_helper_crtc_duplicate_state(). Drivers that subclass the
420 * state structure to extend it with driver-private state should use
421 * __drm_atomic_helper_crtc_duplicate_state() to make sure shared state is
422 * duplicated in a consistent fashion across drivers.
423 *
424 * It is an error to call this hook before crtc->state has been
425 * initialized correctly.
426 *
427 * NOTE:
428 *
429 * If the duplicate state references refcounted resources this hook must
430 * acquire a reference for each of them. The driver must release these
431 * references again in @atomic_destroy_state.
432 *
433 * RETURNS:
434 *
435 * Duplicated atomic state or NULL when the allocation failed.
436 */
Daniel Vetter144ecb92014-10-27 20:28:44 +0100437 struct drm_crtc_state *(*atomic_duplicate_state)(struct drm_crtc *crtc);
Daniel Vetter88548632015-12-04 09:45:48 +0100438
439 /**
440 * @atomic_destroy_state:
441 *
442 * Destroy a state duplicated with @atomic_duplicate_state and release
443 * or unreference all resources it references
444 */
Daniel Vetter144ecb92014-10-27 20:28:44 +0100445 void (*atomic_destroy_state)(struct drm_crtc *crtc,
Daniel Vettercc4ceb42014-07-25 21:30:38 +0200446 struct drm_crtc_state *state);
Daniel Vetter88548632015-12-04 09:45:48 +0100447
448 /**
449 * @atomic_set_property:
450 *
451 * Decode a driver-private property value and store the decoded value
452 * into the passed-in state structure. Since the atomic core decodes all
453 * standardized properties (even for extensions beyond the core set of
454 * properties which might not be implemented by all drivers) this
455 * requires drivers to subclass the state structure.
456 *
457 * Such driver-private properties should really only be implemented for
458 * truly hardware/vendor specific state. Instead it is preferred to
459 * standardize atomic extension and decode the properties used to expose
460 * such an extension in the core.
461 *
462 * Do not call this function directly, use
463 * drm_atomic_crtc_set_property() instead.
464 *
465 * This callback is optional if the driver does not support any
466 * driver-private atomic properties.
467 *
468 * NOTE:
469 *
470 * This function is called in the state assembly phase of atomic
471 * modesets, which can be aborted for any reason (including on
472 * userspace's request to just check whether a configuration would be
473 * possible). Drivers MUST NOT touch any persistent state (hardware or
474 * software) or data structures except the passed in @state parameter.
475 *
476 * Also since userspace controls in which order properties are set this
477 * function must not do any input validation (since the state update is
478 * incomplete and hence likely inconsistent). Instead any such input
479 * validation must be done in the various atomic_check callbacks.
480 *
481 * RETURNS:
482 *
483 * 0 if the property has been found, -EINVAL if the property isn't
484 * implemented by the driver (which should never happen, the core only
485 * asks for properties attached to this CRTC). No other validation is
486 * allowed by the driver. The core already checks that the property
487 * value is within the range (integer, valid enum value, ...) the driver
488 * set when registering the property.
489 */
Daniel Vetter144ecb92014-10-27 20:28:44 +0100490 int (*atomic_set_property)(struct drm_crtc *crtc,
491 struct drm_crtc_state *state,
492 struct drm_property *property,
493 uint64_t val);
Daniel Vetter88548632015-12-04 09:45:48 +0100494 /**
495 * @atomic_get_property:
496 *
497 * Reads out the decoded driver-private property. This is used to
Daniel Vetterc6b0ca32015-12-04 09:46:01 +0100498 * implement the GETCRTC IOCTL.
Daniel Vetter88548632015-12-04 09:45:48 +0100499 *
500 * Do not call this function directly, use
501 * drm_atomic_crtc_get_property() instead.
502 *
503 * This callback is optional if the driver does not support any
504 * driver-private atomic properties.
505 *
506 * RETURNS:
507 *
508 * 0 on success, -EINVAL if the property isn't implemented by the
509 * driver (which should never happen, the core only asks for
510 * properties attached to this CRTC).
511 */
Rob Clarkac9c9252014-12-18 16:01:47 -0500512 int (*atomic_get_property)(struct drm_crtc *crtc,
513 const struct drm_crtc_state *state,
514 struct drm_property *property,
515 uint64_t *val);
Benjamin Gaignard79190ea2016-06-21 16:37:09 +0200516
517 /**
518 * @late_register:
519 *
520 * This optional hook can be used to register additional userspace
521 * interfaces attached to the crtc like debugfs interfaces.
522 * It is called late in the driver load sequence from drm_dev_register().
523 * Everything added from this callback should be unregistered in
524 * the early_unregister callback.
525 *
526 * Returns:
527 *
528 * 0 on success, or a negative error code on failure.
529 */
530 int (*late_register)(struct drm_crtc *crtc);
531
532 /**
533 * @early_unregister:
534 *
535 * This optional hook should be used to unregister the additional
536 * userspace interfaces attached to the crtc from
537 * late_unregister(). It is called from drm_dev_unregister(),
538 * early in the driver unload sequence to disable userspace access
539 * before data structures are torndown.
540 */
541 void (*early_unregister)(struct drm_crtc *crtc);
Dave Airlief453ba02008-11-07 14:05:41 -0800542};
543
544/**
Daniel Vetter3bf04012014-10-27 16:54:27 +0100545 * struct drm_crtc - central CRTC control structure
Jesse Barnes77491632011-11-07 12:03:14 -0800546 * @dev: parent DRM device
Daniel Vetter2c0c33d2014-10-27 20:19:38 +0100547 * @port: OF node used by drm_of_find_possible_crtcs()
Jesse Barnes77491632011-11-07 12:03:14 -0800548 * @head: list management
Daniel Vetterac3ba4a2016-05-31 23:11:10 +0200549 * @name: human readable name, can be overwritten by the driver
Rob Clark51fd3712013-11-19 12:10:12 -0500550 * @mutex: per-CRTC locking
Jesse Barnes77491632011-11-07 12:03:14 -0800551 * @base: base KMS object for ID tracking etc.
Matt Ropere13161a2014-04-01 15:22:38 -0700552 * @primary: primary plane for this CRTC
553 * @cursor: cursor plane for this CRTC
Daniel Vetter2c0c33d2014-10-27 20:19:38 +0100554 * @cursor_x: current x position of the cursor, used for universal cursor planes
555 * @cursor_y: current y position of the cursor, used for universal cursor planes
Dave Airlief453ba02008-11-07 14:05:41 -0800556 * @enabled: is this CRTC enabled?
Jesse Barnes77491632011-11-07 12:03:14 -0800557 * @mode: current mode timings
558 * @hwmode: mode timings as programmed to hw regs
Dave Airlief453ba02008-11-07 14:05:41 -0800559 * @x: x position on screen
560 * @y: y position on screen
Dave Airlief453ba02008-11-07 14:05:41 -0800561 * @funcs: CRTC control functions
Jesse Barnes77491632011-11-07 12:03:14 -0800562 * @gamma_size: size of gamma ramp
563 * @gamma_store: gamma ramp values
Jesse Barnes77491632011-11-07 12:03:14 -0800564 * @helper_private: mid-layer private data
Paulo Zanonibffd9de02012-05-15 18:09:05 -0300565 * @properties: property tracking for this CRTC
Dave Airlief453ba02008-11-07 14:05:41 -0800566 *
567 * Each CRTC may have one or more connectors associated with it. This structure
568 * allows the CRTC to be controlled.
569 */
570struct drm_crtc {
571 struct drm_device *dev;
Russell King7e435aa2014-06-15 11:07:12 +0100572 struct device_node *port;
Dave Airlief453ba02008-11-07 14:05:41 -0800573 struct list_head head;
574
Ville Syrjäläfa3ab4c2015-12-08 18:41:53 +0200575 char *name;
576
Daniel Vetterac3ba4a2016-05-31 23:11:10 +0200577 /**
578 * @mutex:
Daniel Vetter29494c12012-12-02 02:18:25 +0100579 *
580 * This provides a read lock for the overall crtc state (mode, dpms
581 * state, ...) and a write lock for everything which can be update
Daniel Vetterac3ba4a2016-05-31 23:11:10 +0200582 * without a full modeset (fb, cursor data, crtc properties ...). Full
583 * modeset also need to grab dev->mode_config.connection_mutex.
Daniel Vetter29494c12012-12-02 02:18:25 +0100584 */
Rob Clark51fd3712013-11-19 12:10:12 -0500585 struct drm_modeset_lock mutex;
Daniel Vetter29494c12012-12-02 02:18:25 +0100586
Dave Airlief453ba02008-11-07 14:05:41 -0800587 struct drm_mode_object base;
588
Matt Ropere13161a2014-04-01 15:22:38 -0700589 /* primary and cursor planes for CRTC */
590 struct drm_plane *primary;
591 struct drm_plane *cursor;
592
Daniel Vetter96094082016-07-15 21:47:59 +0200593 /**
594 * @index: Position inside the mode_config.list, can be used as an array
595 * index. It is invariant over the lifetime of the CRTC.
596 */
Chris Wilson490d3d12016-05-27 20:05:00 +0100597 unsigned index;
598
Matt Roper161d0dc2014-06-10 08:28:10 -0700599 /* position of cursor plane on crtc */
600 int cursor_x;
601 int cursor_y;
602
Dave Airlief453ba02008-11-07 14:05:41 -0800603 bool enabled;
604
Mario Kleiner27641c32010-10-23 04:20:23 +0200605 /* Requested mode from modesetting. */
Dave Airlief453ba02008-11-07 14:05:41 -0800606 struct drm_display_mode mode;
607
Mario Kleiner27641c32010-10-23 04:20:23 +0200608 /* Programmed mode in hw, after adjustments for encoders,
609 * crtc, panel scaling etc. Needed for timestamping etc.
610 */
611 struct drm_display_mode hwmode;
612
Dave Airlief453ba02008-11-07 14:05:41 -0800613 int x, y;
Dave Airlief453ba02008-11-07 14:05:41 -0800614 const struct drm_crtc_funcs *funcs;
615
Lionel Landwerlin5488dc12016-02-26 17:05:00 +0000616 /* Legacy FB CRTC gamma size for reporting to userspace */
Dave Airlief453ba02008-11-07 14:05:41 -0800617 uint32_t gamma_size;
618 uint16_t *gamma_store;
619
620 /* if you are using the helper */
Daniel Vetter4490d4c2015-12-04 09:45:45 +0100621 const struct drm_crtc_helper_funcs *helper_private;
Paulo Zanonibffd9de02012-05-15 18:09:05 -0300622
623 struct drm_object_properties properties;
Daniel Vetterd059f652014-07-25 18:07:40 +0200624
Daniel Vetter3b24f7d2016-06-08 14:19:00 +0200625 /**
626 * @state:
627 *
628 * Current atomic state for this CRTC.
629 */
Daniel Vetter144ecb92014-10-27 20:28:44 +0100630 struct drm_crtc_state *state;
631
Daniel Vetter3b24f7d2016-06-08 14:19:00 +0200632 /**
633 * @commit_list:
634 *
635 * List of &drm_crtc_commit structures tracking pending commits.
636 * Protected by @commit_lock. This list doesn't hold its own full
637 * reference, but burrows it from the ongoing commit. Commit entries
638 * must be removed from this list once the commit is fully completed,
639 * but before it's correspoding &drm_atomic_state gets destroyed.
640 */
641 struct list_head commit_list;
642
643 /**
644 * @commit_lock:
645 *
646 * Spinlock to protect @commit_list.
647 */
648 spinlock_t commit_lock;
649
650 /**
651 * @acquire_ctx:
652 *
653 * Per-CRTC implicit acquire context used by atomic drivers for legacy
654 * IOCTLs, so that atomic drivers can get at the locking acquire
655 * context.
Daniel Vetterd059f652014-07-25 18:07:40 +0200656 */
657 struct drm_modeset_acquire_ctx *acquire_ctx;
Dave Airlief453ba02008-11-07 14:05:41 -0800658};
659
Daniel Vetter144ecb92014-10-27 20:28:44 +0100660/**
Daniel Vetter3bf04012014-10-27 16:54:27 +0100661 * struct drm_mode_set - new values for a CRTC config change
Jesse Barnesef273512011-11-07 12:03:19 -0800662 * @fb: framebuffer to use for new config
663 * @crtc: CRTC whose configuration we're about to change
664 * @mode: mode timings to use
665 * @x: position of this CRTC relative to @fb
666 * @y: position of this CRTC relative to @fb
667 * @connectors: array of connectors to drive with this CRTC if possible
668 * @num_connectors: size of @connectors array
Dave Airlief453ba02008-11-07 14:05:41 -0800669 *
670 * Represents a single crtc the connectors that it drives with what mode
671 * and from which framebuffer it scans out from.
672 *
673 * This is used to set modes.
674 */
675struct drm_mode_set {
Dave Airlief453ba02008-11-07 14:05:41 -0800676 struct drm_framebuffer *fb;
677 struct drm_crtc *crtc;
678 struct drm_display_mode *mode;
679
680 uint32_t x;
681 uint32_t y;
682
683 struct drm_connector **connectors;
684 size_t num_connectors;
685};
686
687/**
Jesse Barnes550cebc2011-11-07 12:03:20 -0800688 * struct drm_mode_config_funcs - basic driver provided mode setting functions
Jesse Barnes550cebc2011-11-07 12:03:20 -0800689 *
690 * Some global (i.e. not per-CRTC, connector, etc) mode setting functions that
691 * involve drivers.
Dave Airlief453ba02008-11-07 14:05:41 -0800692 */
693struct drm_mode_config_funcs {
Daniel Vetter9953f412015-12-04 09:46:02 +0100694 /**
695 * @fb_create:
696 *
697 * Create a new framebuffer object. The core does basic checks on the
698 * requested metadata, but most of that is left to the driver. See
699 * struct &drm_mode_fb_cmd2 for details.
700 *
Daniel Vetterd55f5322015-12-08 09:49:19 +0100701 * If the parameters are deemed valid and the backing storage objects in
702 * the underlying memory manager all exist, then the driver allocates
703 * a new &drm_framebuffer structure, subclassed to contain
704 * driver-specific information (like the internal native buffer object
705 * references). It also needs to fill out all relevant metadata, which
706 * should be done by calling drm_helper_mode_fill_fb_struct().
707 *
708 * The initialization is finalized by calling drm_framebuffer_init(),
709 * which registers the framebuffer and makes it accessible to other
710 * threads.
711 *
Daniel Vetter9953f412015-12-04 09:46:02 +0100712 * RETURNS:
713 *
714 * A new framebuffer with an initial reference count of 1 or a negative
715 * error code encoded with ERR_PTR().
716 */
Jesse Barnes550cebc2011-11-07 12:03:20 -0800717 struct drm_framebuffer *(*fb_create)(struct drm_device *dev,
718 struct drm_file *file_priv,
Ville Syrjälä1eb83452015-11-11 19:11:29 +0200719 const struct drm_mode_fb_cmd2 *mode_cmd);
Daniel Vetter9953f412015-12-04 09:46:02 +0100720
721 /**
722 * @output_poll_changed:
723 *
724 * Callback used by helpers to inform the driver of output configuration
725 * changes.
726 *
727 * Drivers implementing fbdev emulation with the helpers can call
728 * drm_fb_helper_hotplug_changed from this hook to inform the fbdev
729 * helper of output changes.
730 *
731 * FIXME:
732 *
733 * Except that there's no vtable for device-level helper callbacks
734 * there's no reason this is a core function.
735 */
Dave Airlieeb1f8e42010-05-07 06:42:51 +0000736 void (*output_poll_changed)(struct drm_device *dev);
Daniel Vettercc4ceb42014-07-25 21:30:38 +0200737
Daniel Vetter9953f412015-12-04 09:46:02 +0100738 /**
739 * @atomic_check:
740 *
741 * This is the only hook to validate an atomic modeset update. This
742 * function must reject any modeset and state changes which the hardware
743 * or driver doesn't support. This includes but is of course not limited
744 * to:
745 *
746 * - Checking that the modes, framebuffers, scaling and placement
747 * requirements and so on are within the limits of the hardware.
748 *
749 * - Checking that any hidden shared resources are not oversubscribed.
750 * This can be shared PLLs, shared lanes, overall memory bandwidth,
751 * display fifo space (where shared between planes or maybe even
752 * CRTCs).
753 *
754 * - Checking that virtualized resources exported to userspace are not
755 * oversubscribed. For various reasons it can make sense to expose
756 * more planes, crtcs or encoders than which are physically there. One
757 * example is dual-pipe operations (which generally should be hidden
758 * from userspace if when lockstepped in hardware, exposed otherwise),
759 * where a plane might need 1 hardware plane (if it's just on one
760 * pipe), 2 hardware planes (when it spans both pipes) or maybe even
761 * shared a hardware plane with a 2nd plane (if there's a compatible
762 * plane requested on the area handled by the other pipe).
763 *
764 * - Check that any transitional state is possible and that if
765 * requested, the update can indeed be done in the vblank period
766 * without temporarily disabling some functions.
767 *
768 * - Check any other constraints the driver or hardware might have.
769 *
770 * - This callback also needs to correctly fill out the &drm_crtc_state
771 * in this update to make sure that drm_atomic_crtc_needs_modeset()
772 * reflects the nature of the possible update and returns true if and
773 * only if the update cannot be applied without tearing within one
774 * vblank on that CRTC. The core uses that information to reject
775 * updates which require a full modeset (i.e. blanking the screen, or
776 * at least pausing updates for a substantial amount of time) if
777 * userspace has disallowed that in its request.
778 *
779 * - The driver also does not need to repeat basic input validation
780 * like done for the corresponding legacy entry points. The core does
781 * that before calling this hook.
782 *
783 * See the documentation of @atomic_commit for an exhaustive list of
784 * error conditions which don't have to be checked at the
785 * ->atomic_check() stage?
786 *
787 * See the documentation for struct &drm_atomic_state for how exactly
788 * an atomic modeset update is described.
789 *
790 * Drivers using the atomic helpers can implement this hook using
791 * drm_atomic_helper_check(), or one of the exported sub-functions of
792 * it.
793 *
794 * RETURNS:
795 *
796 * 0 on success or one of the below negative error codes:
797 *
798 * - -EINVAL, if any of the above constraints are violated.
799 *
800 * - -EDEADLK, when returned from an attempt to acquire an additional
801 * &drm_modeset_lock through drm_modeset_lock().
802 *
803 * - -ENOMEM, if allocating additional state sub-structures failed due
804 * to lack of memory.
805 *
806 * - -EINTR, -EAGAIN or -ERESTARTSYS, if the IOCTL should be restarted.
807 * This can either be due to a pending signal, or because the driver
808 * needs to completely bail out to recover from an exceptional
809 * situation like a GPU hang. From a userspace point all errors are
810 * treated equally.
811 */
Daniel Vettercc4ceb42014-07-25 21:30:38 +0200812 int (*atomic_check)(struct drm_device *dev,
Daniel Vetter9953f412015-12-04 09:46:02 +0100813 struct drm_atomic_state *state);
814
815 /**
816 * @atomic_commit:
817 *
818 * This is the only hook to commit an atomic modeset update. The core
819 * guarantees that @atomic_check has been called successfully before
820 * calling this function, and that nothing has been changed in the
821 * interim.
822 *
823 * See the documentation for struct &drm_atomic_state for how exactly
824 * an atomic modeset update is described.
825 *
826 * Drivers using the atomic helpers can implement this hook using
827 * drm_atomic_helper_commit(), or one of the exported sub-functions of
828 * it.
829 *
Maarten Lankhorst286dbb82016-04-26 16:11:34 +0200830 * Nonblocking commits (as indicated with the nonblock parameter) must
Daniel Vetter9953f412015-12-04 09:46:02 +0100831 * do any preparatory work which might result in an unsuccessful commit
832 * in the context of this callback. The only exceptions are hardware
833 * errors resulting in -EIO. But even in that case the driver must
834 * ensure that the display pipe is at least running, to avoid
835 * compositors crashing when pageflips don't work. Anything else,
836 * specifically committing the update to the hardware, should be done
837 * without blocking the caller. For updates which do not require a
838 * modeset this must be guaranteed.
839 *
840 * The driver must wait for any pending rendering to the new
841 * framebuffers to complete before executing the flip. It should also
842 * wait for any pending rendering from other drivers if the underlying
Maarten Lankhorst286dbb82016-04-26 16:11:34 +0200843 * buffer is a shared dma-buf. Nonblocking commits must not wait for
Daniel Vetter9953f412015-12-04 09:46:02 +0100844 * rendering in the context of this callback.
845 *
846 * An application can request to be notified when the atomic commit has
847 * completed. These events are per-CRTC and can be distinguished by the
848 * CRTC index supplied in &drm_event to userspace.
849 *
850 * The drm core will supply a struct &drm_event in the event
851 * member of each CRTC's &drm_crtc_state structure. This can be handled by the
852 * drm_crtc_send_vblank_event() function, which the driver should call on
853 * the provided event upon completion of the atomic commit. Note that if
854 * the driver supports vblank signalling and timestamping the vblank
855 * counters and timestamps must agree with the ones returned from page
856 * flip events. With the current vblank helper infrastructure this can
857 * be achieved by holding a vblank reference while the page flip is
858 * pending, acquired through drm_crtc_vblank_get() and released with
859 * drm_crtc_vblank_put(). Drivers are free to implement their own vblank
860 * counter and timestamp tracking though, e.g. if they have accurate
861 * timestamp registers in hardware.
862 *
863 * NOTE:
864 *
865 * Drivers are not allowed to shut down any display pipe successfully
866 * enabled through an atomic commit on their own. Doing so can result in
867 * compositors crashing if a page flip is suddenly rejected because the
868 * pipe is off.
869 *
870 * RETURNS:
871 *
872 * 0 on success or one of the below negative error codes:
873 *
Maarten Lankhorst286dbb82016-04-26 16:11:34 +0200874 * - -EBUSY, if a nonblocking updated is requested and there is
Daniel Vetter9953f412015-12-04 09:46:02 +0100875 * an earlier updated pending. Drivers are allowed to support a queue
876 * of outstanding updates, but currently no driver supports that.
877 * Note that drivers must wait for preceding updates to complete if a
878 * synchronous update is requested, they are not allowed to fail the
879 * commit in that case.
880 *
881 * - -ENOMEM, if the driver failed to allocate memory. Specifically
882 * this can happen when trying to pin framebuffers, which must only
883 * be done when committing the state.
884 *
885 * - -ENOSPC, as a refinement of the more generic -ENOMEM to indicate
886 * that the driver has run out of vram, iommu space or similar GPU
887 * address space needed for framebuffer.
888 *
889 * - -EIO, if the hardware completely died.
890 *
891 * - -EINTR, -EAGAIN or -ERESTARTSYS, if the IOCTL should be restarted.
892 * This can either be due to a pending signal, or because the driver
893 * needs to completely bail out to recover from an exceptional
894 * situation like a GPU hang. From a userspace point of view all errors are
895 * treated equally.
896 *
897 * This list is exhaustive. Specifically this hook is not allowed to
898 * return -EINVAL (any invalid requests should be caught in
899 * @atomic_check) or -EDEADLK (this function must not acquire
900 * additional modeset locks).
901 */
Daniel Vettercc4ceb42014-07-25 21:30:38 +0200902 int (*atomic_commit)(struct drm_device *dev,
Daniel Vetter9953f412015-12-04 09:46:02 +0100903 struct drm_atomic_state *state,
Maarten Lankhorst286dbb82016-04-26 16:11:34 +0200904 bool nonblock);
Daniel Vetter9953f412015-12-04 09:46:02 +0100905
906 /**
907 * @atomic_state_alloc:
908 *
909 * This optional hook can be used by drivers that want to subclass struct
910 * &drm_atomic_state to be able to track their own driver-private global
911 * state easily. If this hook is implemented, drivers must also
912 * implement @atomic_state_clear and @atomic_state_free.
913 *
914 * RETURNS:
915 *
916 * A new &drm_atomic_state on success or NULL on failure.
917 */
Maarten Lankhorst036ef572015-05-18 10:06:40 +0200918 struct drm_atomic_state *(*atomic_state_alloc)(struct drm_device *dev);
Daniel Vetter9953f412015-12-04 09:46:02 +0100919
920 /**
921 * @atomic_state_clear:
922 *
923 * This hook must clear any driver private state duplicated into the
924 * passed-in &drm_atomic_state. This hook is called when the caller
925 * encountered a &drm_modeset_lock deadlock and needs to drop all
926 * already acquired locks as part of the deadlock avoidance dance
927 * implemented in drm_modeset_lock_backoff().
928 *
929 * Any duplicated state must be invalidated since a concurrent atomic
930 * update might change it, and the drm atomic interfaces always apply
931 * updates as relative changes to the current state.
932 *
933 * Drivers that implement this must call drm_atomic_state_default_clear()
934 * to clear common state.
935 */
Maarten Lankhorst036ef572015-05-18 10:06:40 +0200936 void (*atomic_state_clear)(struct drm_atomic_state *state);
Daniel Vetter9953f412015-12-04 09:46:02 +0100937
938 /**
939 * @atomic_state_free:
940 *
941 * This hook needs driver private resources and the &drm_atomic_state
942 * itself. Note that the core first calls drm_atomic_state_clear() to
943 * avoid code duplicate between the clear and free hooks.
944 *
945 * Drivers that implement this must call drm_atomic_state_default_free()
946 * to release common resources.
947 */
Maarten Lankhorst036ef572015-05-18 10:06:40 +0200948 void (*atomic_state_free)(struct drm_atomic_state *state);
Dave Airlief453ba02008-11-07 14:05:41 -0800949};
950
Jesse Barnesc1aaca22011-11-07 12:03:21 -0800951/**
Daniel Vetter2c0c33d2014-10-27 20:19:38 +0100952 * struct drm_mode_config - Mode configuration control structure
Jesse Barnesa62c93d2011-11-07 12:03:22 -0800953 * @mutex: mutex protecting KMS related lists and structures
Daniel Vetter2c0c33d2014-10-27 20:19:38 +0100954 * @connection_mutex: ww mutex protecting connector state and routing
955 * @acquire_ctx: global implicit acquire context used by atomic drivers for
Daniel Vetterc6b0ca32015-12-04 09:46:01 +0100956 * legacy IOCTLs
Daniel Vetter2c0c33d2014-10-27 20:19:38 +0100957 * @fb_lock: mutex to protect fb state and lists
Jesse Barnesa62c93d2011-11-07 12:03:22 -0800958 * @num_fb: number of fbs available
959 * @fb_list: list of framebuffers available
Jesse Barnesa62c93d2011-11-07 12:03:22 -0800960 * @num_encoder: number of encoders on this device
961 * @encoder_list: list of encoder objects
Daniel Vetter2c0c33d2014-10-27 20:19:38 +0100962 * @num_overlay_plane: number of overlay planes on this device
963 * @num_total_plane: number of universal (i.e. with primary/curso) planes on this device
964 * @plane_list: list of plane objects
Jesse Barnesa62c93d2011-11-07 12:03:22 -0800965 * @num_crtc: number of CRTCs on this device
966 * @crtc_list: list of CRTC objects
Daniel Vetter2c0c33d2014-10-27 20:19:38 +0100967 * @property_list: list of property objects
Jesse Barnesa62c93d2011-11-07 12:03:22 -0800968 * @min_width: minimum pixel width on this device
969 * @min_height: minimum pixel height on this device
970 * @max_width: maximum pixel width on this device
971 * @max_height: maximum pixel height on this device
972 * @funcs: core driver provided mode setting functions
973 * @fb_base: base address of the framebuffer
Daniel Vetter2c0c33d2014-10-27 20:19:38 +0100974 * @poll_enabled: track polling support for this device
975 * @poll_running: track polling status for this device
Daniel Vetterac3ba4a2016-05-31 23:11:10 +0200976 * @delayed_event: track delayed poll uevent deliver for this device
Jesse Barnesa62c93d2011-11-07 12:03:22 -0800977 * @output_poll_work: delayed work for polling in process context
Daniel Vetter2c0c33d2014-10-27 20:19:38 +0100978 * @property_blob_list: list of all the blob property objects
Daniel Stone8fb6e7a2015-04-20 19:22:54 +0100979 * @blob_lock: mutex for blob property allocation and management
Jesse Barnesa62c93d2011-11-07 12:03:22 -0800980 * @*_property: core property tracking
Daniel Vetter2c0c33d2014-10-27 20:19:38 +0100981 * @preferred_depth: preferred RBG pixel depth, used by fb helpers
982 * @prefer_shadow: hint to userspace to prefer shadow-fb rendering
Daniel Vetter2c0c33d2014-10-27 20:19:38 +0100983 * @cursor_width: hint to userspace for max cursor width
984 * @cursor_height: hint to userspace for max cursor height
Daniel Vetter9f2a7952016-06-08 14:19:02 +0200985 * @helper_private: mid-layer private data
Dave Airlief453ba02008-11-07 14:05:41 -0800986 *
Jesse Barnesa62c93d2011-11-07 12:03:22 -0800987 * Core mode resource tracking structure. All CRTC, encoders, and connectors
988 * enumerated by the driver are added here, as are global properties. Some
989 * global restrictions are also here, e.g. dimension restrictions.
Dave Airlief453ba02008-11-07 14:05:41 -0800990 */
991struct drm_mode_config {
Jesse Barnesad2563c2009-01-19 17:21:45 +1000992 struct mutex mutex; /* protects configuration (mode lists etc.) */
Rob Clark51fd3712013-11-19 12:10:12 -0500993 struct drm_modeset_lock connection_mutex; /* protects connector->encoder and encoder->crtc links */
994 struct drm_modeset_acquire_ctx *acquire_ctx; /* for legacy _lock_all() / _unlock_all() */
Daniel Vetterac3ba4a2016-05-31 23:11:10 +0200995
996 /**
997 * @idr_mutex:
998 *
999 * Mutex for KMS ID allocation and management. Protects both @crtc_idr
1000 * and @tile_idr.
1001 */
1002 struct mutex idr_mutex;
1003
1004 /**
1005 * @crtc_idr:
1006 *
1007 * Main KMS ID tracking object. Use this idr for all IDs, fb, crtc,
1008 * connector, modes - just makes life easier to have only one.
1009 */
1010 struct idr crtc_idr;
1011
1012 /**
1013 * @tile_idr:
1014 *
1015 * Use this idr for allocating new IDs for tiled sinks like use in some
1016 * high-res DP MST screens.
1017 */
1018 struct idr tile_idr;
Daniel Vetter4b096ac2012-12-10 21:19:18 +01001019
Daniel Vetter2c0c33d2014-10-27 20:19:38 +01001020 struct mutex fb_lock; /* proctects global and per-file fb lists */
Dave Airlief453ba02008-11-07 14:05:41 -08001021 int num_fb;
1022 struct list_head fb_list;
Daniel Vetter4b096ac2012-12-10 21:19:18 +01001023
Daniel Vetter96094082016-07-15 21:47:59 +02001024 /**
1025 * @num_connector: Number of connectors on this device.
1026 */
Dave Airlief453ba02008-11-07 14:05:41 -08001027 int num_connector;
Daniel Vetter96094082016-07-15 21:47:59 +02001028 /**
1029 * @connector_ida: ID allocator for connector indices.
1030 */
Maarten Lankhorst5fff80b2016-02-17 08:32:05 +01001031 struct ida connector_ida;
Daniel Vetter96094082016-07-15 21:47:59 +02001032 /**
1033 * @connector_list: List of connector objects.
1034 */
Dave Airlief453ba02008-11-07 14:05:41 -08001035 struct list_head connector_list;
1036 int num_encoder;
1037 struct list_head encoder_list;
Matt Ropere27dde32014-04-01 15:22:30 -07001038
1039 /*
1040 * Track # of overlay planes separately from # of total planes. By
1041 * default we only advertise overlay planes to userspace; if userspace
1042 * sets the "universal plane" capability bit, we'll go ahead and
1043 * expose all planes.
1044 */
1045 int num_overlay_plane;
1046 int num_total_plane;
Jesse Barnes8cf5c912011-11-14 14:51:27 -08001047 struct list_head plane_list;
Dave Airlief453ba02008-11-07 14:05:41 -08001048
1049 int num_crtc;
1050 struct list_head crtc_list;
1051
1052 struct list_head property_list;
1053
Dave Airlief453ba02008-11-07 14:05:41 -08001054 int min_width, min_height;
1055 int max_width, max_height;
Laurent Pincharte6ecefa2012-05-17 13:27:23 +02001056 const struct drm_mode_config_funcs *funcs;
Benjamin Herrenschmidtd883f7f2009-02-02 16:55:45 +11001057 resource_size_t fb_base;
Dave Airlief453ba02008-11-07 14:05:41 -08001058
Dave Airlieeb1f8e42010-05-07 06:42:51 +00001059 /* output poll support */
1060 bool poll_enabled;
Daniel Vetter905bc9f2012-10-23 18:23:36 +00001061 bool poll_running;
Daniel Vetter162b6a52015-01-21 08:45:21 +01001062 bool delayed_event;
Tejun Heo991ea752010-07-20 22:09:02 +02001063 struct delayed_work output_poll_work;
Dave Airlieeb1f8e42010-05-07 06:42:51 +00001064
Daniel Stone8fb6e7a2015-04-20 19:22:54 +01001065 struct mutex blob_lock;
1066
Dave Airlief453ba02008-11-07 14:05:41 -08001067 /* pointers to standard properties */
1068 struct list_head property_blob_list;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02001069 /**
1070 * @edid_property: Default connector property to hold the EDID of the
1071 * currently connected sink, if any.
1072 */
Dave Airlief453ba02008-11-07 14:05:41 -08001073 struct drm_property *edid_property;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02001074 /**
1075 * @dpms_property: Default connector property to control the
1076 * connector's DPMS state.
1077 */
Dave Airlief453ba02008-11-07 14:05:41 -08001078 struct drm_property *dpms_property;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02001079 /**
1080 * @path_property: Default connector property to hold the DP MST path
1081 * for the port.
1082 */
Dave Airlie43aba7e2014-06-05 14:01:31 +10001083 struct drm_property *path_property;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02001084 /**
1085 * @tile_property: Default connector property to store the tile
1086 * position of a tiled screen, for sinks which need to be driven with
1087 * multiple CRTCs.
1088 */
Dave Airlie6f134d72014-10-20 16:30:50 +10001089 struct drm_property *tile_property;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02001090 /**
1091 * @plane_type_property: Default plane property to differentiate
1092 * CURSOR, PRIMARY and OVERLAY legacy uses of planes.
1093 */
Rob Clark9922ab52014-04-01 20:16:57 -04001094 struct drm_property *plane_type_property;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02001095 /**
1096 * @rotation_property: Optional property for planes or CRTCs to specifiy
1097 * rotation.
1098 */
Sonika Jindal2a297cc2014-08-05 11:26:54 +05301099 struct drm_property *rotation_property;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02001100 /**
1101 * @prop_src_x: Default atomic plane property for the plane source
1102 * position in the connected &drm_framebuffer.
1103 */
Rob Clark6b4959f2014-12-18 16:01:53 -05001104 struct drm_property *prop_src_x;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02001105 /**
1106 * @prop_src_y: Default atomic plane property for the plane source
1107 * position in the connected &drm_framebuffer.
1108 */
Rob Clark6b4959f2014-12-18 16:01:53 -05001109 struct drm_property *prop_src_y;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02001110 /**
1111 * @prop_src_w: Default atomic plane property for the plane source
1112 * position in the connected &drm_framebuffer.
1113 */
Rob Clark6b4959f2014-12-18 16:01:53 -05001114 struct drm_property *prop_src_w;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02001115 /**
1116 * @prop_src_h: Default atomic plane property for the plane source
1117 * position in the connected &drm_framebuffer.
1118 */
Rob Clark6b4959f2014-12-18 16:01:53 -05001119 struct drm_property *prop_src_h;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02001120 /**
1121 * @prop_crtc_x: Default atomic plane property for the plane destination
1122 * position in the &drm_crtc is is being shown on.
1123 */
Rob Clark6b4959f2014-12-18 16:01:53 -05001124 struct drm_property *prop_crtc_x;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02001125 /**
1126 * @prop_crtc_y: Default atomic plane property for the plane destination
1127 * position in the &drm_crtc is is being shown on.
1128 */
Rob Clark6b4959f2014-12-18 16:01:53 -05001129 struct drm_property *prop_crtc_y;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02001130 /**
1131 * @prop_crtc_w: Default atomic plane property for the plane destination
1132 * position in the &drm_crtc is is being shown on.
1133 */
Rob Clark6b4959f2014-12-18 16:01:53 -05001134 struct drm_property *prop_crtc_w;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02001135 /**
1136 * @prop_crtc_h: Default atomic plane property for the plane destination
1137 * position in the &drm_crtc is is being shown on.
1138 */
Rob Clark6b4959f2014-12-18 16:01:53 -05001139 struct drm_property *prop_crtc_h;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02001140 /**
1141 * @prop_fb_id: Default atomic plane property to specify the
1142 * &drm_framebuffer.
1143 */
Rob Clark6b4959f2014-12-18 16:01:53 -05001144 struct drm_property *prop_fb_id;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02001145 /**
1146 * @prop_crtc_id: Default atomic plane property to specify the
1147 * &drm_crtc.
1148 */
Rob Clark6b4959f2014-12-18 16:01:53 -05001149 struct drm_property *prop_crtc_id;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02001150 /**
1151 * @prop_active: Default atomic CRTC property to control the active
1152 * state, which is the simplified implementation for DPMS in atomic
1153 * drivers.
1154 */
Daniel Vettereab3bbe2015-01-22 16:36:21 +01001155 struct drm_property *prop_active;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02001156 /**
1157 * @prop_mode_id: Default atomic CRTC property to set the mode for a
1158 * CRTC. A 0 mode implies that the CRTC is entirely disabled - all
1159 * connectors must be of and active must be set to disabled, too.
1160 */
Daniel Stone955f3c32015-05-25 19:11:52 +01001161 struct drm_property *prop_mode_id;
Dave Airlief453ba02008-11-07 14:05:41 -08001162
Daniel Vetter9a6bc032016-07-15 21:48:00 +02001163 /**
1164 * @dvi_i_subconnector_property: Optional DVI-I property to
1165 * differentiate between analog or digital mode.
1166 */
Dave Airlief453ba02008-11-07 14:05:41 -08001167 struct drm_property *dvi_i_subconnector_property;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02001168 /**
1169 * @dvi_i_select_subconnector_property: Optional DVI-I property to
1170 * select between analog or digital mode.
1171 */
Dave Airlief453ba02008-11-07 14:05:41 -08001172 struct drm_property *dvi_i_select_subconnector_property;
1173
Daniel Vetter9a6bc032016-07-15 21:48:00 +02001174 /**
1175 * @tv_subconnector_property: Optional TV property to differentiate
1176 * between different TV connector types.
1177 */
Dave Airlief453ba02008-11-07 14:05:41 -08001178 struct drm_property *tv_subconnector_property;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02001179 /**
1180 * @tv_select_subconnector_property: Optional TV property to select
1181 * between different TV connector types.
1182 */
Dave Airlief453ba02008-11-07 14:05:41 -08001183 struct drm_property *tv_select_subconnector_property;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02001184 /**
1185 * @tv_mode_property: Optional TV property to select
1186 * the output TV mode.
1187 */
Dave Airlief453ba02008-11-07 14:05:41 -08001188 struct drm_property *tv_mode_property;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02001189 /**
1190 * @tv_left_margin_property: Optional TV property to set the left
1191 * margin.
1192 */
Dave Airlief453ba02008-11-07 14:05:41 -08001193 struct drm_property *tv_left_margin_property;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02001194 /**
1195 * @tv_right_margin_property: Optional TV property to set the right
1196 * margin.
1197 */
Dave Airlief453ba02008-11-07 14:05:41 -08001198 struct drm_property *tv_right_margin_property;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02001199 /**
1200 * @tv_top_margin_property: Optional TV property to set the right
1201 * margin.
1202 */
Dave Airlief453ba02008-11-07 14:05:41 -08001203 struct drm_property *tv_top_margin_property;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02001204 /**
1205 * @tv_bottom_margin_property: Optional TV property to set the right
1206 * margin.
1207 */
Dave Airlief453ba02008-11-07 14:05:41 -08001208 struct drm_property *tv_bottom_margin_property;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02001209 /**
1210 * @tv_brightness_property: Optional TV property to set the
1211 * brightness.
1212 */
Francisco Jerezb6b79022009-08-02 04:19:20 +02001213 struct drm_property *tv_brightness_property;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02001214 /**
1215 * @tv_contrast_property: Optional TV property to set the
1216 * contrast.
1217 */
Francisco Jerezb6b79022009-08-02 04:19:20 +02001218 struct drm_property *tv_contrast_property;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02001219 /**
1220 * @tv_flicker_reduction_property: Optional TV property to control the
1221 * flicker reduction mode.
1222 */
Francisco Jerezb6b79022009-08-02 04:19:20 +02001223 struct drm_property *tv_flicker_reduction_property;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02001224 /**
1225 * @tv_overscan_property: Optional TV property to control the overscan
1226 * setting.
1227 */
Francisco Jereza75f0232009-08-12 02:30:10 +02001228 struct drm_property *tv_overscan_property;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02001229 /**
1230 * @tv_saturation_property: Optional TV property to set the
1231 * saturation.
1232 */
Francisco Jereza75f0232009-08-12 02:30:10 +02001233 struct drm_property *tv_saturation_property;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02001234 /**
1235 * @tv_hue_property: Optional TV property to set the hue.
1236 */
Francisco Jereza75f0232009-08-12 02:30:10 +02001237 struct drm_property *tv_hue_property;
Dave Airlief453ba02008-11-07 14:05:41 -08001238
Daniel Vetter9a6bc032016-07-15 21:48:00 +02001239 /**
1240 * @scaling_mode_property: Optional connector property to control the
1241 * upscaling, mostly used for built-in panels.
1242 */
Dave Airlief453ba02008-11-07 14:05:41 -08001243 struct drm_property *scaling_mode_property;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02001244 /**
1245 * @aspect_ratio_property: Optional connector property to control the
1246 * HDMI infoframe aspect ratio setting.
1247 */
Vandana Kannanff587e42014-06-11 10:46:48 +05301248 struct drm_property *aspect_ratio_property;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02001249 /**
Daniel Vetter9a6bc032016-07-15 21:48:00 +02001250 * @degamma_lut_property: Optional CRTC property to set the LUT used to
1251 * convert the framebuffer's colors to linear gamma.
1252 */
Lionel Landwerlin5488dc12016-02-26 17:05:00 +00001253 struct drm_property *degamma_lut_property;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02001254 /**
1255 * @degamma_lut_size_property: Optional CRTC property for the size of
1256 * the degamma LUT as supported by the driver (read-only).
1257 */
Lionel Landwerlin5488dc12016-02-26 17:05:00 +00001258 struct drm_property *degamma_lut_size_property;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02001259 /**
1260 * @ctm_property: Optional CRTC property to set the
1261 * matrix used to convert colors after the lookup in the
1262 * degamma LUT.
1263 */
Lionel Landwerlin5488dc12016-02-26 17:05:00 +00001264 struct drm_property *ctm_property;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02001265 /**
1266 * @gamma_lut_property: Optional CRTC property to set the LUT used to
1267 * convert the colors, after the CTM matrix, to the gamma space of the
1268 * connected screen.
1269 */
Lionel Landwerlin5488dc12016-02-26 17:05:00 +00001270 struct drm_property *gamma_lut_property;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02001271 /**
1272 * @gamma_lut_size_property: Optional CRTC property for the size of the
1273 * gamma LUT as supported by the driver (read-only).
1274 */
Lionel Landwerlin5488dc12016-02-26 17:05:00 +00001275 struct drm_property *gamma_lut_size_property;
1276
Daniel Vetter9a6bc032016-07-15 21:48:00 +02001277 /**
1278 * @suggested_x_property: Optional connector property with a hint for
1279 * the position of the output on the host's screen.
1280 */
Dave Airlie5bb2bbf2014-11-10 10:18:15 +10001281 struct drm_property *suggested_x_property;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02001282 /**
1283 * @suggested_y_property: Optional connector property with a hint for
1284 * the position of the output on the host's screen.
1285 */
Dave Airlie5bb2bbf2014-11-10 10:18:15 +10001286 struct drm_property *suggested_y_property;
1287
Dave Airlie019d96c2011-09-29 16:20:42 +01001288 /* dumb ioctl parameters */
1289 uint32_t preferred_depth, prefer_shadow;
Keith Packard62f21042013-07-22 18:50:00 -07001290
Daniel Vetter9a6bc032016-07-15 21:48:00 +02001291 /**
1292 * @async_page_flip: Does this device support async flips on the primary
1293 * plane?
1294 */
Keith Packard62f21042013-07-22 18:50:00 -07001295 bool async_page_flip;
Alex Deucher8716ed42014-02-12 12:48:23 -05001296
Daniel Vetterac3ba4a2016-05-31 23:11:10 +02001297 /**
1298 * @allow_fb_modifiers:
1299 *
1300 * Whether the driver supports fb modifiers in the ADDFB2.1 ioctl call.
1301 */
Rob Clarke3eb3252015-02-05 14:41:52 +00001302 bool allow_fb_modifiers;
1303
Alex Deucher8716ed42014-02-12 12:48:23 -05001304 /* cursor size */
1305 uint32_t cursor_width, cursor_height;
Daniel Vetter9f2a7952016-06-08 14:19:02 +02001306
1307 struct drm_mode_config_helper_funcs *helper_private;
Dave Airlief453ba02008-11-07 14:05:41 -08001308};
1309
1310#define obj_to_crtc(x) container_of(x, struct drm_crtc, base)
Dave Airlief453ba02008-11-07 14:05:41 -08001311
Ville Syrjäläf9882872015-12-09 16:19:31 +02001312extern __printf(6, 7)
1313int drm_crtc_init_with_planes(struct drm_device *dev,
1314 struct drm_crtc *crtc,
1315 struct drm_plane *primary,
1316 struct drm_plane *cursor,
1317 const struct drm_crtc_funcs *funcs,
1318 const char *name, ...);
Dave Airlief453ba02008-11-07 14:05:41 -08001319extern void drm_crtc_cleanup(struct drm_crtc *crtc);
Chris Wilson490d3d12016-05-27 20:05:00 +01001320
1321/**
1322 * drm_crtc_index - find the index of a registered CRTC
1323 * @crtc: CRTC to find index for
1324 *
1325 * Given a registered CRTC, return the index of that CRTC within a DRM
1326 * device's list of CRTCs.
1327 */
1328static inline unsigned int drm_crtc_index(struct drm_crtc *crtc)
1329{
1330 return crtc->index;
1331}
Russell Kingdb5f7a62014-01-02 21:27:33 +00001332
1333/**
1334 * drm_crtc_mask - find the mask of a registered CRTC
1335 * @crtc: CRTC to find mask for
1336 *
1337 * Given a registered CRTC, return the mask bit of that CRTC for an
1338 * encoder's possible_crtcs field.
1339 */
1340static inline uint32_t drm_crtc_mask(struct drm_crtc *crtc)
1341{
1342 return 1 << drm_crtc_index(crtc);
1343}
Dave Airlief453ba02008-11-07 14:05:41 -08001344
Gustavo Padovanecb7e162014-12-01 15:40:09 -08001345extern void drm_crtc_get_hv_timing(const struct drm_display_mode *mode,
1346 int *hdisplay, int *vdisplay);
Lukas Wunner6a0d9522016-06-08 18:47:27 +02001347extern int drm_crtc_force_disable(struct drm_crtc *crtc);
1348extern int drm_crtc_force_disable_all(struct drm_device *dev);
Jesse Barnes8cf5c912011-11-14 14:51:27 -08001349
Dave Airlief453ba02008-11-07 14:05:41 -08001350extern void drm_mode_config_init(struct drm_device *dev);
Chris Wilsoneb033552011-01-24 15:11:08 +00001351extern void drm_mode_config_reset(struct drm_device *dev);
Dave Airlief453ba02008-11-07 14:05:41 -08001352extern void drm_mode_config_cleanup(struct drm_device *dev);
Dave Airlief453ba02008-11-07 14:05:41 -08001353
Sascha Hauer4cae5b82012-02-01 11:38:23 +01001354extern int drm_mode_crtc_set_gamma_size(struct drm_crtc *crtc,
Dave Airlief453ba02008-11-07 14:05:41 -08001355 int gamma_size);
Rob Clark98f75de2014-05-30 11:37:03 -04001356
Daniel Vetter2d13b672012-12-11 13:47:23 +01001357extern int drm_mode_set_config_internal(struct drm_mode_set *set);
Daniel Vetter81065542016-06-21 10:54:13 +02001358
Dave Airlie138f9eb2014-10-20 16:17:17 +10001359extern struct drm_tile_group *drm_mode_create_tile_group(struct drm_device *dev,
1360 char topology[8]);
1361extern struct drm_tile_group *drm_mode_get_tile_group(struct drm_device *dev,
1362 char topology[8]);
1363extern void drm_mode_put_tile_group(struct drm_device *dev,
1364 struct drm_tile_group *tg);
Dave Airlieff72145b2011-02-07 12:16:14 +10001365
Ville Syrjäläc1df5f32014-07-08 10:31:53 +05301366extern struct drm_property *drm_mode_create_rotation_property(struct drm_device *dev,
1367 unsigned int supported_rotations);
Ville Syrjälä3c9855f2014-07-08 10:31:56 +05301368extern unsigned int drm_rotation_simplify(unsigned int rotation,
1369 unsigned int supported_rotations);
Jyri Sarhaf8ed34a2016-06-07 15:09:14 +03001370extern void drm_crtc_enable_color_mgmt(struct drm_crtc *crtc,
1371 uint degamma_lut_size,
1372 bool has_ctm,
1373 uint gamma_lut_size);
Marek Szyprowski44d1240d2016-06-13 11:11:26 +02001374
1375int drm_plane_create_zpos_property(struct drm_plane *plane,
1376 unsigned int zpos,
1377 unsigned int min, unsigned int max);
1378
1379int drm_plane_create_zpos_immutable_property(struct drm_plane *plane,
1380 unsigned int zpos);
1381
Russell King96f60e32012-08-15 13:59:49 +01001382/* Helpers */
1383static inline struct drm_crtc *drm_crtc_find(struct drm_device *dev,
1384 uint32_t id)
1385{
1386 struct drm_mode_object *mo;
1387 mo = drm_mode_object_find(dev, id, DRM_MODE_OBJECT_CRTC);
1388 return mo ? obj_to_crtc(mo) : NULL;
1389}
1390
Lionel Landwerlin5488dc12016-02-26 17:05:00 +00001391/*
1392 * Extract a degamma/gamma LUT value provided by user and round it to the
1393 * precision supported by the hardware.
1394 */
1395static inline uint32_t drm_color_lut_extract(uint32_t user_input,
1396 uint32_t bit_precision)
1397{
Lionel Landwerlin644a8052016-03-22 14:10:33 +00001398 uint32_t val = user_input;
Lionel Landwerlin5488dc12016-02-26 17:05:00 +00001399 uint32_t max = 0xffff >> (16 - bit_precision);
1400
Lionel Landwerlin644a8052016-03-22 14:10:33 +00001401 /* Round only if we're not using full precision. */
1402 if (bit_precision < 16) {
1403 val += 1UL << (16 - bit_precision - 1);
1404 val >>= 16 - bit_precision;
1405 }
Lionel Landwerlin5488dc12016-02-26 17:05:00 +00001406
1407 return clamp_val(val, 0, max);
1408}
1409
Daniel Vetter6295d602015-07-09 23:44:25 +02001410#define drm_for_each_crtc(crtc, dev) \
1411 list_for_each_entry(crtc, &(dev)->mode_config.crtc_list, head)
1412
Daniel Vetter7a3f3d62015-07-09 23:44:28 +02001413static inline void
1414assert_drm_connector_list_read_locked(struct drm_mode_config *mode_config)
1415{
Daniel Vettercff20ba2015-07-09 23:44:33 +02001416 /*
1417 * The connector hotadd/remove code currently grabs both locks when
1418 * updating lists. Hence readers need only hold either of them to be
1419 * safe and the check amounts to
1420 *
1421 * WARN_ON(not_holding(A) && not_holding(B)).
1422 */
1423 WARN_ON(!mutex_is_locked(&mode_config->mutex) &&
1424 !drm_modeset_is_locked(&mode_config->connection_mutex));
Daniel Vetter7a3f3d62015-07-09 23:44:28 +02001425}
1426
Dave Airlief453ba02008-11-07 14:05:41 -08001427#endif /* __DRM_CRTC_H__ */