blob: 8d06cabede5939ab05a4af9504ed34147689b98d [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>
Daniel Vetter18733802016-09-21 10:59:26 +020048#include <drm/drm_blend.h>
Jesse Barnes308e5bc2011-11-14 14:51:28 -080049
Dave Airlief453ba02008-11-07 14:05:41 -080050struct drm_device;
51struct drm_mode_set;
Thierry Reding595887e2012-11-21 15:00:47 +010052struct drm_file;
53struct drm_clip_rect;
Russell King7e435aa2014-06-15 11:07:12 +010054struct device_node;
Daniel Vettere2330f02014-10-29 11:34:56 +010055struct fence;
Daniel Vetter81065542016-06-21 10:54:13 +020056struct edid;
Dave Airlief453ba02008-11-07 14:05:41 -080057
Rob Clarkebc44cf2012-09-12 22:22:31 -050058static inline int64_t U642I64(uint64_t val)
59{
60 return (int64_t)*((int64_t *)&val);
61}
62static inline uint64_t I642U64(int64_t val)
63{
64 return (uint64_t)*((uint64_t *)&val);
65}
66
Dave Airlie138f9eb2014-10-20 16:17:17 +100067/* data corresponds to displayid vend/prod/serial */
68struct drm_tile_group {
69 struct kref refcount;
70 struct drm_device *dev;
71 int id;
72 u8 group_data[8];
73};
74
Dave Airlief453ba02008-11-07 14:05:41 -080075struct drm_crtc;
Dave Airlief453ba02008-11-07 14:05:41 -080076struct drm_encoder;
Kristian Høgsbergd91d8a32009-11-17 12:43:55 -050077struct drm_pending_vblank_event;
Jesse Barnes8cf5c912011-11-14 14:51:27 -080078struct drm_plane;
Sean Paul3b336ec2013-08-14 16:47:37 -040079struct drm_bridge;
Daniel Vetter144ecb92014-10-27 20:28:44 +010080struct drm_atomic_state;
81
Daniel Vetter4490d4c2015-12-04 09:45:45 +010082struct drm_crtc_helper_funcs;
83struct drm_encoder_helper_funcs;
Daniel Vetter4490d4c2015-12-04 09:45:45 +010084struct drm_plane_helper_funcs;
85
Daniel Vetter144ecb92014-10-27 20:28:44 +010086/**
Daniel Vettercc4ceb42014-07-25 21:30:38 +020087 * struct drm_crtc_state - mutable CRTC state
Daniel Vetter07cc0ef2014-11-27 15:49:39 +010088 * @crtc: backpointer to the CRTC
Daniel Vetter144ecb92014-10-27 20:28:44 +010089 * @enable: whether the CRTC should be enabled, gates all other state
Daniel Vetterd9b13622014-11-26 16:57:41 +010090 * @active: whether the CRTC is actively displaying (used for DPMS)
Maarten Lankhorstfc596662015-07-21 13:28:57 +020091 * @planes_changed: planes on this crtc are updated
92 * @mode_changed: crtc_state->mode or crtc_state->enable has been changed
93 * @active_changed: crtc_state->active has been toggled.
94 * @connectors_changed: connectors to this crtc have been updated
Marek Szyprowski44d1240d2016-06-13 11:11:26 +020095 * @zpos_changed: zpos values of planes on this crtc have been updated
Lionel Landwerlin5488dc12016-02-26 17:05:00 +000096 * @color_mgmt_changed: color management properties have changed (degamma or
97 * gamma LUT or CSC matrix)
Rob Clark6ddd3882014-11-21 15:28:31 -050098 * @plane_mask: bitmask of (1 << drm_plane_index(plane)) of attached planes
Maarten Lankhorst4cd9fa52016-01-04 12:53:18 +010099 * @connector_mask: bitmask of (1 << drm_connector_index(connector)) of attached connectors
Maarten Lankhorste87a52b2016-01-28 15:04:58 +0100100 * @encoder_mask: bitmask of (1 << drm_encoder_index(encoder)) of attached encoders
Daniel Vetter623369e2014-09-16 17:50:47 +0200101 * @last_vblank_count: for helpers and drivers to capture the vblank of the
102 * update to ensure framebuffer cleanup isn't done too early
Daniel Vetter2f324b42014-10-29 11:13:47 +0100103 * @adjusted_mode: for use by helpers and drivers to compute adjusted mode timings
Daniel Vetter144ecb92014-10-27 20:28:44 +0100104 * @mode: current mode timings
Daniel Vetterac3ba4a2016-05-31 23:11:10 +0200105 * @mode_blob: &drm_property_blob for @mode
Lionel Landwerlin5488dc12016-02-26 17:05:00 +0000106 * @degamma_lut: Lookup table for converting framebuffer pixel data
107 * before apply the conversion matrix
108 * @ctm: Transformation matrix
109 * @gamma_lut: Lookup table for converting pixel data after the
110 * conversion matrix
Daniel Vetter144ecb92014-10-27 20:28:44 +0100111 * @event: optional pointer to a DRM event to signal upon completion of the
112 * state update
113 * @state: backpointer to global drm_atomic_state
Daniel Vetterd9b13622014-11-26 16:57:41 +0100114 *
115 * Note that the distinction between @enable and @active is rather subtile:
116 * Flipping @active while @enable is set without changing anything else may
117 * never return in a failure from the ->atomic_check callback. Userspace assumes
118 * that a DPMS On will always succeed. In other words: @enable controls resource
119 * assignment, @active controls the actual hardware state.
Daniel Vetter144ecb92014-10-27 20:28:44 +0100120 */
121struct drm_crtc_state {
Daniel Vetter07cc0ef2014-11-27 15:49:39 +0100122 struct drm_crtc *crtc;
123
Daniel Vettercc4ceb42014-07-25 21:30:38 +0200124 bool enable;
Daniel Vetterd9b13622014-11-26 16:57:41 +0100125 bool active;
Daniel Vetter144ecb92014-10-27 20:28:44 +0100126
Daniel Vetterc2fcd272014-11-05 00:14:14 +0100127 /* computed state bits used by helpers and drivers */
128 bool planes_changed : 1;
Daniel Vetter623369e2014-09-16 17:50:47 +0200129 bool mode_changed : 1;
Daniel Vettereab3bbe2015-01-22 16:36:21 +0100130 bool active_changed : 1;
Maarten Lankhorstfc596662015-07-21 13:28:57 +0200131 bool connectors_changed : 1;
Marek Szyprowski44d1240d2016-06-13 11:11:26 +0200132 bool zpos_changed : 1;
Lionel Landwerlin5488dc12016-02-26 17:05:00 +0000133 bool color_mgmt_changed : 1;
Daniel Vetter623369e2014-09-16 17:50:47 +0200134
Rob Clark6ddd3882014-11-21 15:28:31 -0500135 /* attached planes bitmask:
136 * WARNING: transitional helpers do not maintain plane_mask so
137 * drivers not converted over to atomic helpers should not rely
138 * on plane_mask being accurate!
139 */
140 u32 plane_mask;
141
Maarten Lankhorst4cd9fa52016-01-04 12:53:18 +0100142 u32 connector_mask;
Maarten Lankhorste87a52b2016-01-28 15:04:58 +0100143 u32 encoder_mask;
Maarten Lankhorst4cd9fa52016-01-04 12:53:18 +0100144
Daniel Vetter623369e2014-09-16 17:50:47 +0200145 /* last_vblank_count: for vblank waits before cleanup */
146 u32 last_vblank_count;
Daniel Vetterc2fcd272014-11-05 00:14:14 +0100147
Daniel Vetter2f324b42014-10-29 11:13:47 +0100148 /* adjusted_mode: for use by helpers and drivers */
149 struct drm_display_mode adjusted_mode;
150
Daniel Vetter144ecb92014-10-27 20:28:44 +0100151 struct drm_display_mode mode;
152
Daniel Stone99cf4a22015-05-25 19:11:51 +0100153 /* blob property to expose current mode to atomic userspace */
154 struct drm_property_blob *mode_blob;
155
Lionel Landwerlin5488dc12016-02-26 17:05:00 +0000156 /* blob property to expose color management to userspace */
157 struct drm_property_blob *degamma_lut;
158 struct drm_property_blob *ctm;
159 struct drm_property_blob *gamma_lut;
160
Daniel Vetter144ecb92014-10-27 20:28:44 +0100161 struct drm_pending_vblank_event *event;
162
163 struct drm_atomic_state *state;
164};
Dave Airlief453ba02008-11-07 14:05:41 -0800165
166/**
Daniel Vetter3bf04012014-10-27 16:54:27 +0100167 * struct drm_crtc_funcs - control CRTCs for a given device
Dave Airlief453ba02008-11-07 14:05:41 -0800168 *
169 * The drm_crtc_funcs structure is the central CRTC management structure
170 * in the DRM. Each CRTC controls one or more connectors (note that the name
171 * CRTC is simply historical, a CRTC may control LVDS, VGA, DVI, TV out, etc.
172 * connectors, not just CRTs).
173 *
174 * Each driver is responsible for filling out this structure at startup time,
175 * in addition to providing other modesetting features, like i2c and DDC
176 * bus accessors.
177 */
178struct drm_crtc_funcs {
Daniel Vetter88548632015-12-04 09:45:48 +0100179 /**
180 * @reset:
181 *
182 * Reset CRTC hardware and software state to off. This function isn't
183 * called by the core directly, only through drm_mode_config_reset().
184 * It's not a helper hook only for historical reasons.
185 *
186 * Atomic drivers can use drm_atomic_helper_crtc_reset() to reset
187 * atomic state using this hook.
188 */
Chris Wilsoneb033552011-01-24 15:11:08 +0000189 void (*reset)(struct drm_crtc *crtc);
Dave Airlief453ba02008-11-07 14:05:41 -0800190
Daniel Vetterf6da8c62015-12-04 09:46:00 +0100191 /**
192 * @cursor_set:
193 *
194 * Update the cursor image. The cursor position is relative to the CRTC
195 * and can be partially or fully outside of the visible area.
196 *
197 * Note that contrary to all other KMS functions the legacy cursor entry
198 * points don't take a framebuffer object, but instead take directly a
199 * raw buffer object id from the driver's buffer manager (which is
200 * either GEM or TTM for current drivers).
201 *
202 * This entry point is deprecated, drivers should instead implement
203 * universal plane support and register a proper cursor plane using
204 * drm_crtc_init_with_planes().
205 *
206 * This callback is optional
207 *
208 * RETURNS:
209 *
210 * 0 on success or a negative error code on failure.
211 */
Dave Airlief453ba02008-11-07 14:05:41 -0800212 int (*cursor_set)(struct drm_crtc *crtc, struct drm_file *file_priv,
213 uint32_t handle, uint32_t width, uint32_t height);
Daniel Vetterf6da8c62015-12-04 09:46:00 +0100214
215 /**
216 * @cursor_set2:
217 *
218 * Update the cursor image, including hotspot information. The hotspot
219 * must not affect the cursor position in CRTC coordinates, but is only
220 * meant as a hint for virtualized display hardware to coordinate the
221 * guests and hosts cursor position. The cursor hotspot is relative to
222 * the cursor image. Otherwise this works exactly like @cursor_set.
223 *
224 * This entry point is deprecated, drivers should instead implement
225 * universal plane support and register a proper cursor plane using
226 * drm_crtc_init_with_planes().
227 *
228 * This callback is optional.
229 *
230 * RETURNS:
231 *
232 * 0 on success or a negative error code on failure.
233 */
Dave Airlie4c813d42013-06-20 11:48:52 +1000234 int (*cursor_set2)(struct drm_crtc *crtc, struct drm_file *file_priv,
235 uint32_t handle, uint32_t width, uint32_t height,
236 int32_t hot_x, int32_t hot_y);
Daniel Vetterf6da8c62015-12-04 09:46:00 +0100237
238 /**
239 * @cursor_move:
240 *
241 * Update the cursor position. The cursor does not need to be visible
242 * when this hook is called.
243 *
244 * This entry point is deprecated, drivers should instead implement
245 * universal plane support and register a proper cursor plane using
246 * drm_crtc_init_with_planes().
247 *
248 * This callback is optional.
249 *
250 * RETURNS:
251 *
252 * 0 on success or a negative error code on failure.
253 */
Dave Airlief453ba02008-11-07 14:05:41 -0800254 int (*cursor_move)(struct drm_crtc *crtc, int x, int y);
255
Daniel Vetterf6da8c62015-12-04 09:46:00 +0100256 /**
257 * @gamma_set:
258 *
259 * Set gamma on the CRTC.
260 *
261 * This callback is optional.
262 *
263 * NOTE:
264 *
265 * Drivers that support gamma tables and also fbdev emulation through
266 * the provided helper library need to take care to fill out the gamma
267 * hooks for both. Currently there's a bit an unfortunate duplication
268 * going on, which should eventually be unified to just one set of
269 * hooks.
270 */
Maarten Lankhorst7ea77282016-06-07 12:49:30 +0200271 int (*gamma_set)(struct drm_crtc *crtc, u16 *r, u16 *g, u16 *b,
272 uint32_t size);
Daniel Vetter88548632015-12-04 09:45:48 +0100273
274 /**
275 * @destroy:
276 *
277 * Clean up plane resources. This is only called at driver unload time
278 * through drm_mode_config_cleanup() since a CRTC cannot be hotplugged
279 * in DRM.
280 */
Dave Airlief453ba02008-11-07 14:05:41 -0800281 void (*destroy)(struct drm_crtc *crtc);
282
Daniel Vetterf6da8c62015-12-04 09:46:00 +0100283 /**
284 * @set_config:
285 *
286 * This is the main legacy entry point to change the modeset state on a
287 * CRTC. All the details of the desired configuration are passed in a
288 * struct &drm_mode_set - see there for details.
289 *
290 * Drivers implementing atomic modeset should use
291 * drm_atomic_helper_set_config() to implement this hook.
292 *
293 * RETURNS:
294 *
295 * 0 on success or a negative error code on failure.
296 */
Dave Airlief453ba02008-11-07 14:05:41 -0800297 int (*set_config)(struct drm_mode_set *set);
Kristian Høgsbergd91d8a32009-11-17 12:43:55 -0500298
Daniel Vetterf6da8c62015-12-04 09:46:00 +0100299 /**
300 * @page_flip:
301 *
302 * Legacy entry point to schedule a flip to the given framebuffer.
303 *
304 * Page flipping is a synchronization mechanism that replaces the frame
305 * buffer being scanned out by the CRTC with a new frame buffer during
306 * vertical blanking, avoiding tearing (except when requested otherwise
307 * through the DRM_MODE_PAGE_FLIP_ASYNC flag). When an application
308 * requests a page flip the DRM core verifies that the new frame buffer
309 * is large enough to be scanned out by the CRTC in the currently
310 * configured mode and then calls the CRTC ->page_flip() operation with a
311 * pointer to the new frame buffer.
312 *
313 * The driver must wait for any pending rendering to the new framebuffer
314 * to complete before executing the flip. It should also wait for any
315 * pending rendering from other drivers if the underlying buffer is a
316 * shared dma-buf.
317 *
318 * An application can request to be notified when the page flip has
319 * completed. The drm core will supply a struct &drm_event in the event
320 * parameter in this case. This can be handled by the
321 * drm_crtc_send_vblank_event() function, which the driver should call on
322 * the provided event upon completion of the flip. Note that if
323 * the driver supports vblank signalling and timestamping the vblank
324 * counters and timestamps must agree with the ones returned from page
325 * flip events. With the current vblank helper infrastructure this can
326 * be achieved by holding a vblank reference while the page flip is
327 * pending, acquired through drm_crtc_vblank_get() and released with
328 * drm_crtc_vblank_put(). Drivers are free to implement their own vblank
329 * counter and timestamp tracking though, e.g. if they have accurate
330 * timestamp registers in hardware.
331 *
Daniel Vetterf6da8c62015-12-04 09:46:00 +0100332 * This callback is optional.
333 *
334 * NOTE:
335 *
336 * Very early versions of the KMS ABI mandated that the driver must
337 * block (but not reject) any rendering to the old framebuffer until the
338 * flip operation has completed and the old framebuffer is no longer
339 * visible. This requirement has been lifted, and userspace is instead
340 * expected to request delivery of an event and wait with recycling old
341 * buffers until such has been received.
342 *
343 * RETURNS:
344 *
345 * 0 on success or a negative error code on failure. Note that if a
346 * ->page_flip() operation is already pending the callback should return
347 * -EBUSY. Pageflips on a disabled CRTC (either by setting a NULL mode
348 * or just runtime disabled through DPMS respectively the new atomic
Daniel Vetter4cba6852015-12-08 09:49:20 +0100349 * "ACTIVE" state) should result in an -EINVAL error code. Note that
350 * drm_atomic_helper_page_flip() checks this already for atomic drivers.
Kristian Høgsbergd91d8a32009-11-17 12:43:55 -0500351 */
352 int (*page_flip)(struct drm_crtc *crtc,
353 struct drm_framebuffer *fb,
Keith Packarded8d1972013-07-22 18:49:58 -0700354 struct drm_pending_vblank_event *event,
355 uint32_t flags);
Paulo Zanonibffd9de02012-05-15 18:09:05 -0300356
Daniel Vetter88548632015-12-04 09:45:48 +0100357 /**
Michel Dänzerc229bfb2016-08-08 16:23:03 +0900358 * @page_flip_target:
359 *
360 * Same as @page_flip but with an additional parameter specifying the
361 * absolute target vertical blank period (as reported by
362 * drm_crtc_vblank_count()) when the flip should take effect.
363 *
364 * Note that the core code calls drm_crtc_vblank_get before this entry
365 * point, and will call drm_crtc_vblank_put if this entry point returns
366 * any non-0 error code. It's the driver's responsibility to call
367 * drm_crtc_vblank_put after this entry point returns 0, typically when
368 * the flip completes.
369 */
370 int (*page_flip_target)(struct drm_crtc *crtc,
371 struct drm_framebuffer *fb,
372 struct drm_pending_vblank_event *event,
373 uint32_t flags, uint32_t target);
374
375 /**
Daniel Vetter88548632015-12-04 09:45:48 +0100376 * @set_property:
377 *
378 * This is the legacy entry point to update a property attached to the
379 * CRTC.
380 *
381 * Drivers implementing atomic modeset should use
382 * drm_atomic_helper_crtc_set_property() to implement this hook.
383 *
384 * This callback is optional if the driver does not support any legacy
385 * driver-private properties.
386 *
387 * RETURNS:
388 *
389 * 0 on success or a negative error code on failure.
390 */
Paulo Zanonibffd9de02012-05-15 18:09:05 -0300391 int (*set_property)(struct drm_crtc *crtc,
392 struct drm_property *property, uint64_t val);
Daniel Vetter144ecb92014-10-27 20:28:44 +0100393
Daniel Vetter88548632015-12-04 09:45:48 +0100394 /**
395 * @atomic_duplicate_state:
396 *
397 * Duplicate the current atomic state for this CRTC and return it.
398 * The core and helpers gurantee that any atomic state duplicated with
399 * this hook and still owned by the caller (i.e. not transferred to the
400 * driver by calling ->atomic_commit() from struct
401 * &drm_mode_config_funcs) will be cleaned up by calling the
402 * @atomic_destroy_state hook in this structure.
403 *
404 * Atomic drivers which don't subclass struct &drm_crtc should use
405 * drm_atomic_helper_crtc_duplicate_state(). Drivers that subclass the
406 * state structure to extend it with driver-private state should use
407 * __drm_atomic_helper_crtc_duplicate_state() to make sure shared state is
408 * duplicated in a consistent fashion across drivers.
409 *
410 * It is an error to call this hook before crtc->state has been
411 * initialized correctly.
412 *
413 * NOTE:
414 *
415 * If the duplicate state references refcounted resources this hook must
416 * acquire a reference for each of them. The driver must release these
417 * references again in @atomic_destroy_state.
418 *
419 * RETURNS:
420 *
421 * Duplicated atomic state or NULL when the allocation failed.
422 */
Daniel Vetter144ecb92014-10-27 20:28:44 +0100423 struct drm_crtc_state *(*atomic_duplicate_state)(struct drm_crtc *crtc);
Daniel Vetter88548632015-12-04 09:45:48 +0100424
425 /**
426 * @atomic_destroy_state:
427 *
428 * Destroy a state duplicated with @atomic_duplicate_state and release
429 * or unreference all resources it references
430 */
Daniel Vetter144ecb92014-10-27 20:28:44 +0100431 void (*atomic_destroy_state)(struct drm_crtc *crtc,
Daniel Vettercc4ceb42014-07-25 21:30:38 +0200432 struct drm_crtc_state *state);
Daniel Vetter88548632015-12-04 09:45:48 +0100433
434 /**
435 * @atomic_set_property:
436 *
437 * Decode a driver-private property value and store the decoded value
438 * into the passed-in state structure. Since the atomic core decodes all
439 * standardized properties (even for extensions beyond the core set of
440 * properties which might not be implemented by all drivers) this
441 * requires drivers to subclass the state structure.
442 *
443 * Such driver-private properties should really only be implemented for
444 * truly hardware/vendor specific state. Instead it is preferred to
445 * standardize atomic extension and decode the properties used to expose
446 * such an extension in the core.
447 *
448 * Do not call this function directly, use
449 * drm_atomic_crtc_set_property() instead.
450 *
451 * This callback is optional if the driver does not support any
452 * driver-private atomic properties.
453 *
454 * NOTE:
455 *
456 * This function is called in the state assembly phase of atomic
457 * modesets, which can be aborted for any reason (including on
458 * userspace's request to just check whether a configuration would be
459 * possible). Drivers MUST NOT touch any persistent state (hardware or
460 * software) or data structures except the passed in @state parameter.
461 *
462 * Also since userspace controls in which order properties are set this
463 * function must not do any input validation (since the state update is
464 * incomplete and hence likely inconsistent). Instead any such input
465 * validation must be done in the various atomic_check callbacks.
466 *
467 * RETURNS:
468 *
469 * 0 if the property has been found, -EINVAL if the property isn't
470 * implemented by the driver (which should never happen, the core only
471 * asks for properties attached to this CRTC). No other validation is
472 * allowed by the driver. The core already checks that the property
473 * value is within the range (integer, valid enum value, ...) the driver
474 * set when registering the property.
475 */
Daniel Vetter144ecb92014-10-27 20:28:44 +0100476 int (*atomic_set_property)(struct drm_crtc *crtc,
477 struct drm_crtc_state *state,
478 struct drm_property *property,
479 uint64_t val);
Daniel Vetter88548632015-12-04 09:45:48 +0100480 /**
481 * @atomic_get_property:
482 *
483 * Reads out the decoded driver-private property. This is used to
Daniel Vetterc6b0ca32015-12-04 09:46:01 +0100484 * implement the GETCRTC IOCTL.
Daniel Vetter88548632015-12-04 09:45:48 +0100485 *
486 * Do not call this function directly, use
487 * drm_atomic_crtc_get_property() instead.
488 *
489 * This callback is optional if the driver does not support any
490 * driver-private atomic properties.
491 *
492 * RETURNS:
493 *
494 * 0 on success, -EINVAL if the property isn't implemented by the
495 * driver (which should never happen, the core only asks for
496 * properties attached to this CRTC).
497 */
Rob Clarkac9c9252014-12-18 16:01:47 -0500498 int (*atomic_get_property)(struct drm_crtc *crtc,
499 const struct drm_crtc_state *state,
500 struct drm_property *property,
501 uint64_t *val);
Benjamin Gaignard79190ea2016-06-21 16:37:09 +0200502
503 /**
504 * @late_register:
505 *
506 * This optional hook can be used to register additional userspace
507 * interfaces attached to the crtc like debugfs interfaces.
508 * It is called late in the driver load sequence from drm_dev_register().
509 * Everything added from this callback should be unregistered in
510 * the early_unregister callback.
511 *
512 * Returns:
513 *
514 * 0 on success, or a negative error code on failure.
515 */
516 int (*late_register)(struct drm_crtc *crtc);
517
518 /**
519 * @early_unregister:
520 *
521 * This optional hook should be used to unregister the additional
522 * userspace interfaces attached to the crtc from
523 * late_unregister(). It is called from drm_dev_unregister(),
524 * early in the driver unload sequence to disable userspace access
525 * before data structures are torndown.
526 */
527 void (*early_unregister)(struct drm_crtc *crtc);
Dave Airlief453ba02008-11-07 14:05:41 -0800528};
529
530/**
Daniel Vetter3bf04012014-10-27 16:54:27 +0100531 * struct drm_crtc - central CRTC control structure
Jesse Barnes77491632011-11-07 12:03:14 -0800532 * @dev: parent DRM device
Daniel Vetter2c0c33d2014-10-27 20:19:38 +0100533 * @port: OF node used by drm_of_find_possible_crtcs()
Jesse Barnes77491632011-11-07 12:03:14 -0800534 * @head: list management
Daniel Vetterac3ba4a2016-05-31 23:11:10 +0200535 * @name: human readable name, can be overwritten by the driver
Rob Clark51fd3712013-11-19 12:10:12 -0500536 * @mutex: per-CRTC locking
Jesse Barnes77491632011-11-07 12:03:14 -0800537 * @base: base KMS object for ID tracking etc.
Matt Ropere13161a2014-04-01 15:22:38 -0700538 * @primary: primary plane for this CRTC
539 * @cursor: cursor plane for this CRTC
Daniel Vetter2c0c33d2014-10-27 20:19:38 +0100540 * @cursor_x: current x position of the cursor, used for universal cursor planes
541 * @cursor_y: current y position of the cursor, used for universal cursor planes
Dave Airlief453ba02008-11-07 14:05:41 -0800542 * @enabled: is this CRTC enabled?
Jesse Barnes77491632011-11-07 12:03:14 -0800543 * @mode: current mode timings
544 * @hwmode: mode timings as programmed to hw regs
Dave Airlief453ba02008-11-07 14:05:41 -0800545 * @x: x position on screen
546 * @y: y position on screen
Dave Airlief453ba02008-11-07 14:05:41 -0800547 * @funcs: CRTC control functions
Jesse Barnes77491632011-11-07 12:03:14 -0800548 * @gamma_size: size of gamma ramp
549 * @gamma_store: gamma ramp values
Jesse Barnes77491632011-11-07 12:03:14 -0800550 * @helper_private: mid-layer private data
Paulo Zanonibffd9de02012-05-15 18:09:05 -0300551 * @properties: property tracking for this CRTC
Dave Airlief453ba02008-11-07 14:05:41 -0800552 *
553 * Each CRTC may have one or more connectors associated with it. This structure
554 * allows the CRTC to be controlled.
555 */
556struct drm_crtc {
557 struct drm_device *dev;
Russell King7e435aa2014-06-15 11:07:12 +0100558 struct device_node *port;
Dave Airlief453ba02008-11-07 14:05:41 -0800559 struct list_head head;
560
Ville Syrjäläfa3ab4c2015-12-08 18:41:53 +0200561 char *name;
562
Daniel Vetterac3ba4a2016-05-31 23:11:10 +0200563 /**
564 * @mutex:
Daniel Vetter29494c12012-12-02 02:18:25 +0100565 *
566 * This provides a read lock for the overall crtc state (mode, dpms
567 * state, ...) and a write lock for everything which can be update
Daniel Vetterac3ba4a2016-05-31 23:11:10 +0200568 * without a full modeset (fb, cursor data, crtc properties ...). Full
569 * modeset also need to grab dev->mode_config.connection_mutex.
Daniel Vetter29494c12012-12-02 02:18:25 +0100570 */
Rob Clark51fd3712013-11-19 12:10:12 -0500571 struct drm_modeset_lock mutex;
Daniel Vetter29494c12012-12-02 02:18:25 +0100572
Dave Airlief453ba02008-11-07 14:05:41 -0800573 struct drm_mode_object base;
574
Matt Ropere13161a2014-04-01 15:22:38 -0700575 /* primary and cursor planes for CRTC */
576 struct drm_plane *primary;
577 struct drm_plane *cursor;
578
Daniel Vetter96094082016-07-15 21:47:59 +0200579 /**
580 * @index: Position inside the mode_config.list, can be used as an array
581 * index. It is invariant over the lifetime of the CRTC.
582 */
Chris Wilson490d3d12016-05-27 20:05:00 +0100583 unsigned index;
584
Matt Roper161d0dc2014-06-10 08:28:10 -0700585 /* position of cursor plane on crtc */
586 int cursor_x;
587 int cursor_y;
588
Dave Airlief453ba02008-11-07 14:05:41 -0800589 bool enabled;
590
Mario Kleiner27641c32010-10-23 04:20:23 +0200591 /* Requested mode from modesetting. */
Dave Airlief453ba02008-11-07 14:05:41 -0800592 struct drm_display_mode mode;
593
Mario Kleiner27641c32010-10-23 04:20:23 +0200594 /* Programmed mode in hw, after adjustments for encoders,
595 * crtc, panel scaling etc. Needed for timestamping etc.
596 */
597 struct drm_display_mode hwmode;
598
Dave Airlief453ba02008-11-07 14:05:41 -0800599 int x, y;
Dave Airlief453ba02008-11-07 14:05:41 -0800600 const struct drm_crtc_funcs *funcs;
601
Lionel Landwerlin5488dc12016-02-26 17:05:00 +0000602 /* Legacy FB CRTC gamma size for reporting to userspace */
Dave Airlief453ba02008-11-07 14:05:41 -0800603 uint32_t gamma_size;
604 uint16_t *gamma_store;
605
606 /* if you are using the helper */
Daniel Vetter4490d4c2015-12-04 09:45:45 +0100607 const struct drm_crtc_helper_funcs *helper_private;
Paulo Zanonibffd9de02012-05-15 18:09:05 -0300608
609 struct drm_object_properties properties;
Daniel Vetterd059f652014-07-25 18:07:40 +0200610
Daniel Vetter3b24f7d2016-06-08 14:19:00 +0200611 /**
612 * @state:
613 *
614 * Current atomic state for this CRTC.
615 */
Daniel Vetter144ecb92014-10-27 20:28:44 +0100616 struct drm_crtc_state *state;
617
Daniel Vetter3b24f7d2016-06-08 14:19:00 +0200618 /**
619 * @commit_list:
620 *
621 * List of &drm_crtc_commit structures tracking pending commits.
622 * Protected by @commit_lock. This list doesn't hold its own full
623 * reference, but burrows it from the ongoing commit. Commit entries
624 * must be removed from this list once the commit is fully completed,
625 * but before it's correspoding &drm_atomic_state gets destroyed.
626 */
627 struct list_head commit_list;
628
629 /**
630 * @commit_lock:
631 *
632 * Spinlock to protect @commit_list.
633 */
634 spinlock_t commit_lock;
635
636 /**
637 * @acquire_ctx:
638 *
639 * Per-CRTC implicit acquire context used by atomic drivers for legacy
640 * IOCTLs, so that atomic drivers can get at the locking acquire
641 * context.
Daniel Vetterd059f652014-07-25 18:07:40 +0200642 */
643 struct drm_modeset_acquire_ctx *acquire_ctx;
Dave Airlief453ba02008-11-07 14:05:41 -0800644};
645
Daniel Vetter144ecb92014-10-27 20:28:44 +0100646/**
Daniel Vetter3bf04012014-10-27 16:54:27 +0100647 * struct drm_mode_set - new values for a CRTC config change
Jesse Barnesef273512011-11-07 12:03:19 -0800648 * @fb: framebuffer to use for new config
649 * @crtc: CRTC whose configuration we're about to change
650 * @mode: mode timings to use
651 * @x: position of this CRTC relative to @fb
652 * @y: position of this CRTC relative to @fb
653 * @connectors: array of connectors to drive with this CRTC if possible
654 * @num_connectors: size of @connectors array
Dave Airlief453ba02008-11-07 14:05:41 -0800655 *
656 * Represents a single crtc the connectors that it drives with what mode
657 * and from which framebuffer it scans out from.
658 *
659 * This is used to set modes.
660 */
661struct drm_mode_set {
Dave Airlief453ba02008-11-07 14:05:41 -0800662 struct drm_framebuffer *fb;
663 struct drm_crtc *crtc;
664 struct drm_display_mode *mode;
665
666 uint32_t x;
667 uint32_t y;
668
669 struct drm_connector **connectors;
670 size_t num_connectors;
671};
672
673/**
Jesse Barnes550cebc2011-11-07 12:03:20 -0800674 * struct drm_mode_config_funcs - basic driver provided mode setting functions
Jesse Barnes550cebc2011-11-07 12:03:20 -0800675 *
676 * Some global (i.e. not per-CRTC, connector, etc) mode setting functions that
677 * involve drivers.
Dave Airlief453ba02008-11-07 14:05:41 -0800678 */
679struct drm_mode_config_funcs {
Daniel Vetter9953f412015-12-04 09:46:02 +0100680 /**
681 * @fb_create:
682 *
683 * Create a new framebuffer object. The core does basic checks on the
684 * requested metadata, but most of that is left to the driver. See
685 * struct &drm_mode_fb_cmd2 for details.
686 *
Daniel Vetterd55f5322015-12-08 09:49:19 +0100687 * If the parameters are deemed valid and the backing storage objects in
688 * the underlying memory manager all exist, then the driver allocates
689 * a new &drm_framebuffer structure, subclassed to contain
690 * driver-specific information (like the internal native buffer object
691 * references). It also needs to fill out all relevant metadata, which
692 * should be done by calling drm_helper_mode_fill_fb_struct().
693 *
694 * The initialization is finalized by calling drm_framebuffer_init(),
695 * which registers the framebuffer and makes it accessible to other
696 * threads.
697 *
Daniel Vetter9953f412015-12-04 09:46:02 +0100698 * RETURNS:
699 *
700 * A new framebuffer with an initial reference count of 1 or a negative
701 * error code encoded with ERR_PTR().
702 */
Jesse Barnes550cebc2011-11-07 12:03:20 -0800703 struct drm_framebuffer *(*fb_create)(struct drm_device *dev,
704 struct drm_file *file_priv,
Ville Syrjälä1eb83452015-11-11 19:11:29 +0200705 const struct drm_mode_fb_cmd2 *mode_cmd);
Daniel Vetter9953f412015-12-04 09:46:02 +0100706
707 /**
708 * @output_poll_changed:
709 *
710 * Callback used by helpers to inform the driver of output configuration
711 * changes.
712 *
713 * Drivers implementing fbdev emulation with the helpers can call
714 * drm_fb_helper_hotplug_changed from this hook to inform the fbdev
715 * helper of output changes.
716 *
717 * FIXME:
718 *
719 * Except that there's no vtable for device-level helper callbacks
720 * there's no reason this is a core function.
721 */
Dave Airlieeb1f8e42010-05-07 06:42:51 +0000722 void (*output_poll_changed)(struct drm_device *dev);
Daniel Vettercc4ceb42014-07-25 21:30:38 +0200723
Daniel Vetter9953f412015-12-04 09:46:02 +0100724 /**
725 * @atomic_check:
726 *
727 * This is the only hook to validate an atomic modeset update. This
728 * function must reject any modeset and state changes which the hardware
729 * or driver doesn't support. This includes but is of course not limited
730 * to:
731 *
732 * - Checking that the modes, framebuffers, scaling and placement
733 * requirements and so on are within the limits of the hardware.
734 *
735 * - Checking that any hidden shared resources are not oversubscribed.
736 * This can be shared PLLs, shared lanes, overall memory bandwidth,
737 * display fifo space (where shared between planes or maybe even
738 * CRTCs).
739 *
740 * - Checking that virtualized resources exported to userspace are not
741 * oversubscribed. For various reasons it can make sense to expose
742 * more planes, crtcs or encoders than which are physically there. One
743 * example is dual-pipe operations (which generally should be hidden
744 * from userspace if when lockstepped in hardware, exposed otherwise),
745 * where a plane might need 1 hardware plane (if it's just on one
746 * pipe), 2 hardware planes (when it spans both pipes) or maybe even
747 * shared a hardware plane with a 2nd plane (if there's a compatible
748 * plane requested on the area handled by the other pipe).
749 *
750 * - Check that any transitional state is possible and that if
751 * requested, the update can indeed be done in the vblank period
752 * without temporarily disabling some functions.
753 *
754 * - Check any other constraints the driver or hardware might have.
755 *
756 * - This callback also needs to correctly fill out the &drm_crtc_state
757 * in this update to make sure that drm_atomic_crtc_needs_modeset()
758 * reflects the nature of the possible update and returns true if and
759 * only if the update cannot be applied without tearing within one
760 * vblank on that CRTC. The core uses that information to reject
761 * updates which require a full modeset (i.e. blanking the screen, or
762 * at least pausing updates for a substantial amount of time) if
763 * userspace has disallowed that in its request.
764 *
765 * - The driver also does not need to repeat basic input validation
766 * like done for the corresponding legacy entry points. The core does
767 * that before calling this hook.
768 *
769 * See the documentation of @atomic_commit for an exhaustive list of
770 * error conditions which don't have to be checked at the
771 * ->atomic_check() stage?
772 *
773 * See the documentation for struct &drm_atomic_state for how exactly
774 * an atomic modeset update is described.
775 *
776 * Drivers using the atomic helpers can implement this hook using
777 * drm_atomic_helper_check(), or one of the exported sub-functions of
778 * it.
779 *
780 * RETURNS:
781 *
782 * 0 on success or one of the below negative error codes:
783 *
784 * - -EINVAL, if any of the above constraints are violated.
785 *
786 * - -EDEADLK, when returned from an attempt to acquire an additional
787 * &drm_modeset_lock through drm_modeset_lock().
788 *
789 * - -ENOMEM, if allocating additional state sub-structures failed due
790 * to lack of memory.
791 *
792 * - -EINTR, -EAGAIN or -ERESTARTSYS, if the IOCTL should be restarted.
793 * This can either be due to a pending signal, or because the driver
794 * needs to completely bail out to recover from an exceptional
795 * situation like a GPU hang. From a userspace point all errors are
796 * treated equally.
797 */
Daniel Vettercc4ceb42014-07-25 21:30:38 +0200798 int (*atomic_check)(struct drm_device *dev,
Daniel Vetter9953f412015-12-04 09:46:02 +0100799 struct drm_atomic_state *state);
800
801 /**
802 * @atomic_commit:
803 *
804 * This is the only hook to commit an atomic modeset update. The core
805 * guarantees that @atomic_check has been called successfully before
806 * calling this function, and that nothing has been changed in the
807 * interim.
808 *
809 * See the documentation for struct &drm_atomic_state for how exactly
810 * an atomic modeset update is described.
811 *
812 * Drivers using the atomic helpers can implement this hook using
813 * drm_atomic_helper_commit(), or one of the exported sub-functions of
814 * it.
815 *
Maarten Lankhorst286dbb82016-04-26 16:11:34 +0200816 * Nonblocking commits (as indicated with the nonblock parameter) must
Daniel Vetter9953f412015-12-04 09:46:02 +0100817 * do any preparatory work which might result in an unsuccessful commit
818 * in the context of this callback. The only exceptions are hardware
819 * errors resulting in -EIO. But even in that case the driver must
820 * ensure that the display pipe is at least running, to avoid
821 * compositors crashing when pageflips don't work. Anything else,
822 * specifically committing the update to the hardware, should be done
823 * without blocking the caller. For updates which do not require a
824 * modeset this must be guaranteed.
825 *
826 * The driver must wait for any pending rendering to the new
827 * framebuffers to complete before executing the flip. It should also
828 * wait for any pending rendering from other drivers if the underlying
Maarten Lankhorst286dbb82016-04-26 16:11:34 +0200829 * buffer is a shared dma-buf. Nonblocking commits must not wait for
Daniel Vetter9953f412015-12-04 09:46:02 +0100830 * rendering in the context of this callback.
831 *
832 * An application can request to be notified when the atomic commit has
833 * completed. These events are per-CRTC and can be distinguished by the
834 * CRTC index supplied in &drm_event to userspace.
835 *
836 * The drm core will supply a struct &drm_event in the event
837 * member of each CRTC's &drm_crtc_state structure. This can be handled by the
838 * drm_crtc_send_vblank_event() function, which the driver should call on
839 * the provided event upon completion of the atomic commit. Note that if
840 * the driver supports vblank signalling and timestamping the vblank
841 * counters and timestamps must agree with the ones returned from page
842 * flip events. With the current vblank helper infrastructure this can
843 * be achieved by holding a vblank reference while the page flip is
844 * pending, acquired through drm_crtc_vblank_get() and released with
845 * drm_crtc_vblank_put(). Drivers are free to implement their own vblank
846 * counter and timestamp tracking though, e.g. if they have accurate
847 * timestamp registers in hardware.
848 *
849 * NOTE:
850 *
851 * Drivers are not allowed to shut down any display pipe successfully
852 * enabled through an atomic commit on their own. Doing so can result in
853 * compositors crashing if a page flip is suddenly rejected because the
854 * pipe is off.
855 *
856 * RETURNS:
857 *
858 * 0 on success or one of the below negative error codes:
859 *
Maarten Lankhorst286dbb82016-04-26 16:11:34 +0200860 * - -EBUSY, if a nonblocking updated is requested and there is
Daniel Vetter9953f412015-12-04 09:46:02 +0100861 * an earlier updated pending. Drivers are allowed to support a queue
862 * of outstanding updates, but currently no driver supports that.
863 * Note that drivers must wait for preceding updates to complete if a
864 * synchronous update is requested, they are not allowed to fail the
865 * commit in that case.
866 *
867 * - -ENOMEM, if the driver failed to allocate memory. Specifically
868 * this can happen when trying to pin framebuffers, which must only
869 * be done when committing the state.
870 *
871 * - -ENOSPC, as a refinement of the more generic -ENOMEM to indicate
872 * that the driver has run out of vram, iommu space or similar GPU
873 * address space needed for framebuffer.
874 *
875 * - -EIO, if the hardware completely died.
876 *
877 * - -EINTR, -EAGAIN or -ERESTARTSYS, if the IOCTL should be restarted.
878 * This can either be due to a pending signal, or because the driver
879 * needs to completely bail out to recover from an exceptional
880 * situation like a GPU hang. From a userspace point of view all errors are
881 * treated equally.
882 *
883 * This list is exhaustive. Specifically this hook is not allowed to
884 * return -EINVAL (any invalid requests should be caught in
885 * @atomic_check) or -EDEADLK (this function must not acquire
886 * additional modeset locks).
887 */
Daniel Vettercc4ceb42014-07-25 21:30:38 +0200888 int (*atomic_commit)(struct drm_device *dev,
Daniel Vetter9953f412015-12-04 09:46:02 +0100889 struct drm_atomic_state *state,
Maarten Lankhorst286dbb82016-04-26 16:11:34 +0200890 bool nonblock);
Daniel Vetter9953f412015-12-04 09:46:02 +0100891
892 /**
893 * @atomic_state_alloc:
894 *
895 * This optional hook can be used by drivers that want to subclass struct
896 * &drm_atomic_state to be able to track their own driver-private global
897 * state easily. If this hook is implemented, drivers must also
898 * implement @atomic_state_clear and @atomic_state_free.
899 *
900 * RETURNS:
901 *
902 * A new &drm_atomic_state on success or NULL on failure.
903 */
Maarten Lankhorst036ef572015-05-18 10:06:40 +0200904 struct drm_atomic_state *(*atomic_state_alloc)(struct drm_device *dev);
Daniel Vetter9953f412015-12-04 09:46:02 +0100905
906 /**
907 * @atomic_state_clear:
908 *
909 * This hook must clear any driver private state duplicated into the
910 * passed-in &drm_atomic_state. This hook is called when the caller
911 * encountered a &drm_modeset_lock deadlock and needs to drop all
912 * already acquired locks as part of the deadlock avoidance dance
913 * implemented in drm_modeset_lock_backoff().
914 *
915 * Any duplicated state must be invalidated since a concurrent atomic
916 * update might change it, and the drm atomic interfaces always apply
917 * updates as relative changes to the current state.
918 *
919 * Drivers that implement this must call drm_atomic_state_default_clear()
920 * to clear common state.
921 */
Maarten Lankhorst036ef572015-05-18 10:06:40 +0200922 void (*atomic_state_clear)(struct drm_atomic_state *state);
Daniel Vetter9953f412015-12-04 09:46:02 +0100923
924 /**
925 * @atomic_state_free:
926 *
927 * This hook needs driver private resources and the &drm_atomic_state
928 * itself. Note that the core first calls drm_atomic_state_clear() to
929 * avoid code duplicate between the clear and free hooks.
930 *
931 * Drivers that implement this must call drm_atomic_state_default_free()
932 * to release common resources.
933 */
Maarten Lankhorst036ef572015-05-18 10:06:40 +0200934 void (*atomic_state_free)(struct drm_atomic_state *state);
Dave Airlief453ba02008-11-07 14:05:41 -0800935};
936
Jesse Barnesc1aaca22011-11-07 12:03:21 -0800937/**
Daniel Vetter2c0c33d2014-10-27 20:19:38 +0100938 * struct drm_mode_config - Mode configuration control structure
Jesse Barnesa62c93d2011-11-07 12:03:22 -0800939 * @mutex: mutex protecting KMS related lists and structures
Daniel Vetter2c0c33d2014-10-27 20:19:38 +0100940 * @connection_mutex: ww mutex protecting connector state and routing
941 * @acquire_ctx: global implicit acquire context used by atomic drivers for
Daniel Vetterc6b0ca32015-12-04 09:46:01 +0100942 * legacy IOCTLs
Daniel Vetter2c0c33d2014-10-27 20:19:38 +0100943 * @fb_lock: mutex to protect fb state and lists
Jesse Barnesa62c93d2011-11-07 12:03:22 -0800944 * @num_fb: number of fbs available
945 * @fb_list: list of framebuffers available
Jesse Barnesa62c93d2011-11-07 12:03:22 -0800946 * @num_encoder: number of encoders on this device
947 * @encoder_list: list of encoder objects
Daniel Vetter2c0c33d2014-10-27 20:19:38 +0100948 * @num_overlay_plane: number of overlay planes on this device
949 * @num_total_plane: number of universal (i.e. with primary/curso) planes on this device
950 * @plane_list: list of plane objects
Jesse Barnesa62c93d2011-11-07 12:03:22 -0800951 * @num_crtc: number of CRTCs on this device
952 * @crtc_list: list of CRTC objects
Daniel Vetter2c0c33d2014-10-27 20:19:38 +0100953 * @property_list: list of property objects
Jesse Barnesa62c93d2011-11-07 12:03:22 -0800954 * @min_width: minimum pixel width on this device
955 * @min_height: minimum pixel height on this device
956 * @max_width: maximum pixel width on this device
957 * @max_height: maximum pixel height on this device
958 * @funcs: core driver provided mode setting functions
959 * @fb_base: base address of the framebuffer
Daniel Vetter2c0c33d2014-10-27 20:19:38 +0100960 * @poll_enabled: track polling support for this device
961 * @poll_running: track polling status for this device
Daniel Vetterac3ba4a2016-05-31 23:11:10 +0200962 * @delayed_event: track delayed poll uevent deliver for this device
Jesse Barnesa62c93d2011-11-07 12:03:22 -0800963 * @output_poll_work: delayed work for polling in process context
Daniel Vetter2c0c33d2014-10-27 20:19:38 +0100964 * @property_blob_list: list of all the blob property objects
Daniel Stone8fb6e7a2015-04-20 19:22:54 +0100965 * @blob_lock: mutex for blob property allocation and management
Jesse Barnesa62c93d2011-11-07 12:03:22 -0800966 * @*_property: core property tracking
Daniel Vetter2c0c33d2014-10-27 20:19:38 +0100967 * @preferred_depth: preferred RBG pixel depth, used by fb helpers
968 * @prefer_shadow: hint to userspace to prefer shadow-fb rendering
Daniel Vetter2c0c33d2014-10-27 20:19:38 +0100969 * @cursor_width: hint to userspace for max cursor width
970 * @cursor_height: hint to userspace for max cursor height
Daniel Vetter9f2a7952016-06-08 14:19:02 +0200971 * @helper_private: mid-layer private data
Dave Airlief453ba02008-11-07 14:05:41 -0800972 *
Jesse Barnesa62c93d2011-11-07 12:03:22 -0800973 * Core mode resource tracking structure. All CRTC, encoders, and connectors
974 * enumerated by the driver are added here, as are global properties. Some
975 * global restrictions are also here, e.g. dimension restrictions.
Dave Airlief453ba02008-11-07 14:05:41 -0800976 */
977struct drm_mode_config {
Jesse Barnesad2563c2009-01-19 17:21:45 +1000978 struct mutex mutex; /* protects configuration (mode lists etc.) */
Rob Clark51fd3712013-11-19 12:10:12 -0500979 struct drm_modeset_lock connection_mutex; /* protects connector->encoder and encoder->crtc links */
980 struct drm_modeset_acquire_ctx *acquire_ctx; /* for legacy _lock_all() / _unlock_all() */
Daniel Vetterac3ba4a2016-05-31 23:11:10 +0200981
982 /**
983 * @idr_mutex:
984 *
985 * Mutex for KMS ID allocation and management. Protects both @crtc_idr
986 * and @tile_idr.
987 */
988 struct mutex idr_mutex;
989
990 /**
991 * @crtc_idr:
992 *
993 * Main KMS ID tracking object. Use this idr for all IDs, fb, crtc,
994 * connector, modes - just makes life easier to have only one.
995 */
996 struct idr crtc_idr;
997
998 /**
999 * @tile_idr:
1000 *
1001 * Use this idr for allocating new IDs for tiled sinks like use in some
1002 * high-res DP MST screens.
1003 */
1004 struct idr tile_idr;
Daniel Vetter4b096ac2012-12-10 21:19:18 +01001005
Daniel Vetter2c0c33d2014-10-27 20:19:38 +01001006 struct mutex fb_lock; /* proctects global and per-file fb lists */
Dave Airlief453ba02008-11-07 14:05:41 -08001007 int num_fb;
1008 struct list_head fb_list;
Daniel Vetter4b096ac2012-12-10 21:19:18 +01001009
Daniel Vetter96094082016-07-15 21:47:59 +02001010 /**
1011 * @num_connector: Number of connectors on this device.
1012 */
Dave Airlief453ba02008-11-07 14:05:41 -08001013 int num_connector;
Daniel Vetter96094082016-07-15 21:47:59 +02001014 /**
1015 * @connector_ida: ID allocator for connector indices.
1016 */
Maarten Lankhorst5fff80b2016-02-17 08:32:05 +01001017 struct ida connector_ida;
Daniel Vetter96094082016-07-15 21:47:59 +02001018 /**
1019 * @connector_list: List of connector objects.
1020 */
Dave Airlief453ba02008-11-07 14:05:41 -08001021 struct list_head connector_list;
1022 int num_encoder;
1023 struct list_head encoder_list;
Matt Ropere27dde32014-04-01 15:22:30 -07001024
1025 /*
1026 * Track # of overlay planes separately from # of total planes. By
1027 * default we only advertise overlay planes to userspace; if userspace
1028 * sets the "universal plane" capability bit, we'll go ahead and
1029 * expose all planes.
1030 */
1031 int num_overlay_plane;
1032 int num_total_plane;
Jesse Barnes8cf5c912011-11-14 14:51:27 -08001033 struct list_head plane_list;
Dave Airlief453ba02008-11-07 14:05:41 -08001034
1035 int num_crtc;
1036 struct list_head crtc_list;
1037
1038 struct list_head property_list;
1039
Dave Airlief453ba02008-11-07 14:05:41 -08001040 int min_width, min_height;
1041 int max_width, max_height;
Laurent Pincharte6ecefa2012-05-17 13:27:23 +02001042 const struct drm_mode_config_funcs *funcs;
Benjamin Herrenschmidtd883f7f2009-02-02 16:55:45 +11001043 resource_size_t fb_base;
Dave Airlief453ba02008-11-07 14:05:41 -08001044
Dave Airlieeb1f8e42010-05-07 06:42:51 +00001045 /* output poll support */
1046 bool poll_enabled;
Daniel Vetter905bc9f2012-10-23 18:23:36 +00001047 bool poll_running;
Daniel Vetter162b6a52015-01-21 08:45:21 +01001048 bool delayed_event;
Tejun Heo991ea752010-07-20 22:09:02 +02001049 struct delayed_work output_poll_work;
Dave Airlieeb1f8e42010-05-07 06:42:51 +00001050
Daniel Stone8fb6e7a2015-04-20 19:22:54 +01001051 struct mutex blob_lock;
1052
Dave Airlief453ba02008-11-07 14:05:41 -08001053 /* pointers to standard properties */
1054 struct list_head property_blob_list;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02001055 /**
1056 * @edid_property: Default connector property to hold the EDID of the
1057 * currently connected sink, if any.
1058 */
Dave Airlief453ba02008-11-07 14:05:41 -08001059 struct drm_property *edid_property;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02001060 /**
1061 * @dpms_property: Default connector property to control the
1062 * connector's DPMS state.
1063 */
Dave Airlief453ba02008-11-07 14:05:41 -08001064 struct drm_property *dpms_property;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02001065 /**
1066 * @path_property: Default connector property to hold the DP MST path
1067 * for the port.
1068 */
Dave Airlie43aba7e2014-06-05 14:01:31 +10001069 struct drm_property *path_property;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02001070 /**
1071 * @tile_property: Default connector property to store the tile
1072 * position of a tiled screen, for sinks which need to be driven with
1073 * multiple CRTCs.
1074 */
Dave Airlie6f134d72014-10-20 16:30:50 +10001075 struct drm_property *tile_property;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02001076 /**
1077 * @plane_type_property: Default plane property to differentiate
1078 * CURSOR, PRIMARY and OVERLAY legacy uses of planes.
1079 */
Rob Clark9922ab52014-04-01 20:16:57 -04001080 struct drm_property *plane_type_property;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02001081 /**
1082 * @rotation_property: Optional property for planes or CRTCs to specifiy
1083 * rotation.
1084 */
Sonika Jindal2a297cc2014-08-05 11:26:54 +05301085 struct drm_property *rotation_property;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02001086 /**
1087 * @prop_src_x: Default atomic plane property for the plane source
1088 * position in the connected &drm_framebuffer.
1089 */
Rob Clark6b4959f2014-12-18 16:01:53 -05001090 struct drm_property *prop_src_x;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02001091 /**
1092 * @prop_src_y: Default atomic plane property for the plane source
1093 * position in the connected &drm_framebuffer.
1094 */
Rob Clark6b4959f2014-12-18 16:01:53 -05001095 struct drm_property *prop_src_y;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02001096 /**
1097 * @prop_src_w: Default atomic plane property for the plane source
1098 * position in the connected &drm_framebuffer.
1099 */
Rob Clark6b4959f2014-12-18 16:01:53 -05001100 struct drm_property *prop_src_w;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02001101 /**
1102 * @prop_src_h: Default atomic plane property for the plane source
1103 * position in the connected &drm_framebuffer.
1104 */
Rob Clark6b4959f2014-12-18 16:01:53 -05001105 struct drm_property *prop_src_h;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02001106 /**
1107 * @prop_crtc_x: Default atomic plane property for the plane destination
1108 * position in the &drm_crtc is is being shown on.
1109 */
Rob Clark6b4959f2014-12-18 16:01:53 -05001110 struct drm_property *prop_crtc_x;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02001111 /**
1112 * @prop_crtc_y: Default atomic plane property for the plane destination
1113 * position in the &drm_crtc is is being shown on.
1114 */
Rob Clark6b4959f2014-12-18 16:01:53 -05001115 struct drm_property *prop_crtc_y;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02001116 /**
1117 * @prop_crtc_w: Default atomic plane property for the plane destination
1118 * position in the &drm_crtc is is being shown on.
1119 */
Rob Clark6b4959f2014-12-18 16:01:53 -05001120 struct drm_property *prop_crtc_w;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02001121 /**
1122 * @prop_crtc_h: Default atomic plane property for the plane destination
1123 * position in the &drm_crtc is is being shown on.
1124 */
Rob Clark6b4959f2014-12-18 16:01:53 -05001125 struct drm_property *prop_crtc_h;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02001126 /**
1127 * @prop_fb_id: Default atomic plane property to specify the
1128 * &drm_framebuffer.
1129 */
Rob Clark6b4959f2014-12-18 16:01:53 -05001130 struct drm_property *prop_fb_id;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02001131 /**
1132 * @prop_crtc_id: Default atomic plane property to specify the
1133 * &drm_crtc.
1134 */
Rob Clark6b4959f2014-12-18 16:01:53 -05001135 struct drm_property *prop_crtc_id;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02001136 /**
1137 * @prop_active: Default atomic CRTC property to control the active
1138 * state, which is the simplified implementation for DPMS in atomic
1139 * drivers.
1140 */
Daniel Vettereab3bbe2015-01-22 16:36:21 +01001141 struct drm_property *prop_active;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02001142 /**
1143 * @prop_mode_id: Default atomic CRTC property to set the mode for a
1144 * CRTC. A 0 mode implies that the CRTC is entirely disabled - all
1145 * connectors must be of and active must be set to disabled, too.
1146 */
Daniel Stone955f3c32015-05-25 19:11:52 +01001147 struct drm_property *prop_mode_id;
Dave Airlief453ba02008-11-07 14:05:41 -08001148
Daniel Vetter9a6bc032016-07-15 21:48:00 +02001149 /**
1150 * @dvi_i_subconnector_property: Optional DVI-I property to
1151 * differentiate between analog or digital mode.
1152 */
Dave Airlief453ba02008-11-07 14:05:41 -08001153 struct drm_property *dvi_i_subconnector_property;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02001154 /**
1155 * @dvi_i_select_subconnector_property: Optional DVI-I property to
1156 * select between analog or digital mode.
1157 */
Dave Airlief453ba02008-11-07 14:05:41 -08001158 struct drm_property *dvi_i_select_subconnector_property;
1159
Daniel Vetter9a6bc032016-07-15 21:48:00 +02001160 /**
1161 * @tv_subconnector_property: Optional TV property to differentiate
1162 * between different TV connector types.
1163 */
Dave Airlief453ba02008-11-07 14:05:41 -08001164 struct drm_property *tv_subconnector_property;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02001165 /**
1166 * @tv_select_subconnector_property: Optional TV property to select
1167 * between different TV connector types.
1168 */
Dave Airlief453ba02008-11-07 14:05:41 -08001169 struct drm_property *tv_select_subconnector_property;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02001170 /**
1171 * @tv_mode_property: Optional TV property to select
1172 * the output TV mode.
1173 */
Dave Airlief453ba02008-11-07 14:05:41 -08001174 struct drm_property *tv_mode_property;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02001175 /**
1176 * @tv_left_margin_property: Optional TV property to set the left
1177 * margin.
1178 */
Dave Airlief453ba02008-11-07 14:05:41 -08001179 struct drm_property *tv_left_margin_property;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02001180 /**
1181 * @tv_right_margin_property: Optional TV property to set the right
1182 * margin.
1183 */
Dave Airlief453ba02008-11-07 14:05:41 -08001184 struct drm_property *tv_right_margin_property;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02001185 /**
1186 * @tv_top_margin_property: Optional TV property to set the right
1187 * margin.
1188 */
Dave Airlief453ba02008-11-07 14:05:41 -08001189 struct drm_property *tv_top_margin_property;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02001190 /**
1191 * @tv_bottom_margin_property: Optional TV property to set the right
1192 * margin.
1193 */
Dave Airlief453ba02008-11-07 14:05:41 -08001194 struct drm_property *tv_bottom_margin_property;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02001195 /**
1196 * @tv_brightness_property: Optional TV property to set the
1197 * brightness.
1198 */
Francisco Jerezb6b79022009-08-02 04:19:20 +02001199 struct drm_property *tv_brightness_property;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02001200 /**
1201 * @tv_contrast_property: Optional TV property to set the
1202 * contrast.
1203 */
Francisco Jerezb6b79022009-08-02 04:19:20 +02001204 struct drm_property *tv_contrast_property;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02001205 /**
1206 * @tv_flicker_reduction_property: Optional TV property to control the
1207 * flicker reduction mode.
1208 */
Francisco Jerezb6b79022009-08-02 04:19:20 +02001209 struct drm_property *tv_flicker_reduction_property;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02001210 /**
1211 * @tv_overscan_property: Optional TV property to control the overscan
1212 * setting.
1213 */
Francisco Jereza75f0232009-08-12 02:30:10 +02001214 struct drm_property *tv_overscan_property;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02001215 /**
1216 * @tv_saturation_property: Optional TV property to set the
1217 * saturation.
1218 */
Francisco Jereza75f0232009-08-12 02:30:10 +02001219 struct drm_property *tv_saturation_property;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02001220 /**
1221 * @tv_hue_property: Optional TV property to set the hue.
1222 */
Francisco Jereza75f0232009-08-12 02:30:10 +02001223 struct drm_property *tv_hue_property;
Dave Airlief453ba02008-11-07 14:05:41 -08001224
Daniel Vetter9a6bc032016-07-15 21:48:00 +02001225 /**
1226 * @scaling_mode_property: Optional connector property to control the
1227 * upscaling, mostly used for built-in panels.
1228 */
Dave Airlief453ba02008-11-07 14:05:41 -08001229 struct drm_property *scaling_mode_property;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02001230 /**
1231 * @aspect_ratio_property: Optional connector property to control the
1232 * HDMI infoframe aspect ratio setting.
1233 */
Vandana Kannanff587e42014-06-11 10:46:48 +05301234 struct drm_property *aspect_ratio_property;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02001235 /**
Daniel Vetter9a6bc032016-07-15 21:48:00 +02001236 * @degamma_lut_property: Optional CRTC property to set the LUT used to
1237 * convert the framebuffer's colors to linear gamma.
1238 */
Lionel Landwerlin5488dc12016-02-26 17:05:00 +00001239 struct drm_property *degamma_lut_property;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02001240 /**
1241 * @degamma_lut_size_property: Optional CRTC property for the size of
1242 * the degamma LUT as supported by the driver (read-only).
1243 */
Lionel Landwerlin5488dc12016-02-26 17:05:00 +00001244 struct drm_property *degamma_lut_size_property;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02001245 /**
1246 * @ctm_property: Optional CRTC property to set the
1247 * matrix used to convert colors after the lookup in the
1248 * degamma LUT.
1249 */
Lionel Landwerlin5488dc12016-02-26 17:05:00 +00001250 struct drm_property *ctm_property;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02001251 /**
1252 * @gamma_lut_property: Optional CRTC property to set the LUT used to
1253 * convert the colors, after the CTM matrix, to the gamma space of the
1254 * connected screen.
1255 */
Lionel Landwerlin5488dc12016-02-26 17:05:00 +00001256 struct drm_property *gamma_lut_property;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02001257 /**
1258 * @gamma_lut_size_property: Optional CRTC property for the size of the
1259 * gamma LUT as supported by the driver (read-only).
1260 */
Lionel Landwerlin5488dc12016-02-26 17:05:00 +00001261 struct drm_property *gamma_lut_size_property;
1262
Daniel Vetter9a6bc032016-07-15 21:48:00 +02001263 /**
1264 * @suggested_x_property: Optional connector property with a hint for
1265 * the position of the output on the host's screen.
1266 */
Dave Airlie5bb2bbf2014-11-10 10:18:15 +10001267 struct drm_property *suggested_x_property;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02001268 /**
1269 * @suggested_y_property: Optional connector property with a hint for
1270 * the position of the output on the host's screen.
1271 */
Dave Airlie5bb2bbf2014-11-10 10:18:15 +10001272 struct drm_property *suggested_y_property;
1273
Dave Airlie019d96c2011-09-29 16:20:42 +01001274 /* dumb ioctl parameters */
1275 uint32_t preferred_depth, prefer_shadow;
Keith Packard62f21042013-07-22 18:50:00 -07001276
Daniel Vetter9a6bc032016-07-15 21:48:00 +02001277 /**
1278 * @async_page_flip: Does this device support async flips on the primary
1279 * plane?
1280 */
Keith Packard62f21042013-07-22 18:50:00 -07001281 bool async_page_flip;
Alex Deucher8716ed42014-02-12 12:48:23 -05001282
Daniel Vetterac3ba4a2016-05-31 23:11:10 +02001283 /**
1284 * @allow_fb_modifiers:
1285 *
1286 * Whether the driver supports fb modifiers in the ADDFB2.1 ioctl call.
1287 */
Rob Clarke3eb3252015-02-05 14:41:52 +00001288 bool allow_fb_modifiers;
1289
Alex Deucher8716ed42014-02-12 12:48:23 -05001290 /* cursor size */
1291 uint32_t cursor_width, cursor_height;
Daniel Vetter9f2a7952016-06-08 14:19:02 +02001292
1293 struct drm_mode_config_helper_funcs *helper_private;
Dave Airlief453ba02008-11-07 14:05:41 -08001294};
1295
1296#define obj_to_crtc(x) container_of(x, struct drm_crtc, base)
Dave Airlief453ba02008-11-07 14:05:41 -08001297
Ville Syrjäläf9882872015-12-09 16:19:31 +02001298extern __printf(6, 7)
1299int drm_crtc_init_with_planes(struct drm_device *dev,
1300 struct drm_crtc *crtc,
1301 struct drm_plane *primary,
1302 struct drm_plane *cursor,
1303 const struct drm_crtc_funcs *funcs,
1304 const char *name, ...);
Dave Airlief453ba02008-11-07 14:05:41 -08001305extern void drm_crtc_cleanup(struct drm_crtc *crtc);
Chris Wilson490d3d12016-05-27 20:05:00 +01001306
1307/**
1308 * drm_crtc_index - find the index of a registered CRTC
1309 * @crtc: CRTC to find index for
1310 *
1311 * Given a registered CRTC, return the index of that CRTC within a DRM
1312 * device's list of CRTCs.
1313 */
1314static inline unsigned int drm_crtc_index(struct drm_crtc *crtc)
1315{
1316 return crtc->index;
1317}
Russell Kingdb5f7a62014-01-02 21:27:33 +00001318
1319/**
1320 * drm_crtc_mask - find the mask of a registered CRTC
1321 * @crtc: CRTC to find mask for
1322 *
1323 * Given a registered CRTC, return the mask bit of that CRTC for an
1324 * encoder's possible_crtcs field.
1325 */
1326static inline uint32_t drm_crtc_mask(struct drm_crtc *crtc)
1327{
1328 return 1 << drm_crtc_index(crtc);
1329}
Dave Airlief453ba02008-11-07 14:05:41 -08001330
Gustavo Padovanecb7e162014-12-01 15:40:09 -08001331extern void drm_crtc_get_hv_timing(const struct drm_display_mode *mode,
1332 int *hdisplay, int *vdisplay);
Lukas Wunner6a0d9522016-06-08 18:47:27 +02001333extern int drm_crtc_force_disable(struct drm_crtc *crtc);
1334extern int drm_crtc_force_disable_all(struct drm_device *dev);
Jesse Barnes8cf5c912011-11-14 14:51:27 -08001335
Dave Airlief453ba02008-11-07 14:05:41 -08001336extern void drm_mode_config_init(struct drm_device *dev);
Chris Wilsoneb033552011-01-24 15:11:08 +00001337extern void drm_mode_config_reset(struct drm_device *dev);
Dave Airlief453ba02008-11-07 14:05:41 -08001338extern void drm_mode_config_cleanup(struct drm_device *dev);
Dave Airlief453ba02008-11-07 14:05:41 -08001339
Sascha Hauer4cae5b82012-02-01 11:38:23 +01001340extern int drm_mode_crtc_set_gamma_size(struct drm_crtc *crtc,
Dave Airlief453ba02008-11-07 14:05:41 -08001341 int gamma_size);
Rob Clark98f75de2014-05-30 11:37:03 -04001342
Daniel Vetter2d13b672012-12-11 13:47:23 +01001343extern int drm_mode_set_config_internal(struct drm_mode_set *set);
Daniel Vetter81065542016-06-21 10:54:13 +02001344
Dave Airlie138f9eb2014-10-20 16:17:17 +10001345extern struct drm_tile_group *drm_mode_create_tile_group(struct drm_device *dev,
1346 char topology[8]);
1347extern struct drm_tile_group *drm_mode_get_tile_group(struct drm_device *dev,
1348 char topology[8]);
1349extern void drm_mode_put_tile_group(struct drm_device *dev,
1350 struct drm_tile_group *tg);
Dave Airlieff72145b2011-02-07 12:16:14 +10001351
Jyri Sarhaf8ed34a2016-06-07 15:09:14 +03001352extern void drm_crtc_enable_color_mgmt(struct drm_crtc *crtc,
1353 uint degamma_lut_size,
1354 bool has_ctm,
1355 uint gamma_lut_size);
Marek Szyprowski44d1240d2016-06-13 11:11:26 +02001356
Russell King96f60e32012-08-15 13:59:49 +01001357/* Helpers */
1358static inline struct drm_crtc *drm_crtc_find(struct drm_device *dev,
1359 uint32_t id)
1360{
1361 struct drm_mode_object *mo;
1362 mo = drm_mode_object_find(dev, id, DRM_MODE_OBJECT_CRTC);
1363 return mo ? obj_to_crtc(mo) : NULL;
1364}
1365
Lionel Landwerlin5488dc12016-02-26 17:05:00 +00001366/*
1367 * Extract a degamma/gamma LUT value provided by user and round it to the
1368 * precision supported by the hardware.
1369 */
1370static inline uint32_t drm_color_lut_extract(uint32_t user_input,
1371 uint32_t bit_precision)
1372{
Lionel Landwerlin644a8052016-03-22 14:10:33 +00001373 uint32_t val = user_input;
Lionel Landwerlin5488dc12016-02-26 17:05:00 +00001374 uint32_t max = 0xffff >> (16 - bit_precision);
1375
Lionel Landwerlin644a8052016-03-22 14:10:33 +00001376 /* Round only if we're not using full precision. */
1377 if (bit_precision < 16) {
1378 val += 1UL << (16 - bit_precision - 1);
1379 val >>= 16 - bit_precision;
1380 }
Lionel Landwerlin5488dc12016-02-26 17:05:00 +00001381
1382 return clamp_val(val, 0, max);
1383}
1384
Daniel Vetter6295d602015-07-09 23:44:25 +02001385#define drm_for_each_crtc(crtc, dev) \
1386 list_for_each_entry(crtc, &(dev)->mode_config.crtc_list, head)
1387
Daniel Vetter7a3f3d62015-07-09 23:44:28 +02001388static inline void
1389assert_drm_connector_list_read_locked(struct drm_mode_config *mode_config)
1390{
Daniel Vettercff20ba2015-07-09 23:44:33 +02001391 /*
1392 * The connector hotadd/remove code currently grabs both locks when
1393 * updating lists. Hence readers need only hold either of them to be
1394 * safe and the check amounts to
1395 *
1396 * WARN_ON(not_holding(A) && not_holding(B)).
1397 */
1398 WARN_ON(!mutex_is_locked(&mode_config->mutex) &&
1399 !drm_modeset_is_locked(&mode_config->connection_mutex));
Daniel Vetter7a3f3d62015-07-09 23:44:28 +02001400}
1401
Dave Airlief453ba02008-11-07 14:05:41 -08001402#endif /* __DRM_CRTC_H__ */