blob: b10eba23a7446660d58a45e498d4dbf88d778e6d [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>
Jesse Barnes308e5bc2011-11-14 14:51:28 -080038
Dave Airlief453ba02008-11-07 14:05:41 -080039struct drm_device;
40struct drm_mode_set;
41struct drm_framebuffer;
Paulo Zanoni7e3bdf42012-05-15 18:09:01 -030042struct drm_object_properties;
Thierry Reding595887e2012-11-21 15:00:47 +010043struct drm_file;
44struct drm_clip_rect;
Russell King7e435aa2014-06-15 11:07:12 +010045struct device_node;
Daniel Vettere2330f02014-10-29 11:34:56 +010046struct fence;
Dave Airlief453ba02008-11-07 14:05:41 -080047
48#define DRM_MODE_OBJECT_CRTC 0xcccccccc
49#define DRM_MODE_OBJECT_CONNECTOR 0xc0c0c0c0
50#define DRM_MODE_OBJECT_ENCODER 0xe0e0e0e0
51#define DRM_MODE_OBJECT_MODE 0xdededede
52#define DRM_MODE_OBJECT_PROPERTY 0xb0b0b0b0
53#define DRM_MODE_OBJECT_FB 0xfbfbfbfb
54#define DRM_MODE_OBJECT_BLOB 0xbbbbbbbb
Jesse Barnes8cf5c912011-11-14 14:51:27 -080055#define DRM_MODE_OBJECT_PLANE 0xeeeeeeee
Rob Clark98f75de2014-05-30 11:37:03 -040056#define DRM_MODE_OBJECT_ANY 0
Dave Airlief453ba02008-11-07 14:05:41 -080057
58struct drm_mode_object {
59 uint32_t id;
60 uint32_t type;
Paulo Zanoni7e3bdf42012-05-15 18:09:01 -030061 struct drm_object_properties *properties;
62};
63
Paulo Zanonife456162012-06-12 11:27:01 -030064#define DRM_OBJECT_MAX_PROPERTY 24
Paulo Zanoni7e3bdf42012-05-15 18:09:01 -030065struct drm_object_properties {
Rob Clark88a48e22014-12-18 16:01:50 -050066 int count, atomic_count;
Rob Clarkb17cd752014-12-16 18:05:30 -050067 /* NOTE: if we ever start dynamically destroying properties (ie.
68 * not at drm_mode_config_cleanup() time), then we'd have to do
69 * a better job of detaching property from mode objects to avoid
70 * dangling property pointers:
71 */
72 struct drm_property *properties[DRM_OBJECT_MAX_PROPERTY];
Rob Clark22b8b132014-12-16 18:05:31 -050073 /* do not read/write values directly, but use drm_object_property_get_value()
74 * and drm_object_property_set_value():
75 */
Paulo Zanoni7e3bdf42012-05-15 18:09:01 -030076 uint64_t values[DRM_OBJECT_MAX_PROPERTY];
Dave Airlief453ba02008-11-07 14:05:41 -080077};
78
Rob Clarkebc44cf2012-09-12 22:22:31 -050079static inline int64_t U642I64(uint64_t val)
80{
81 return (int64_t)*((int64_t *)&val);
82}
83static inline uint64_t I642U64(int64_t val)
84{
85 return (uint64_t)*((uint64_t *)&val);
86}
87
Robert Feketed9c38242015-11-02 16:14:08 +010088/*
89 * Rotation property bits. DRM_ROTATE_<degrees> rotates the image by the
90 * specified amount in degrees in counter clockwise direction. DRM_REFLECT_X and
91 * DRM_REFLECT_Y reflects the image along the specified axis prior to rotation
92 */
Joonas Lahtinen62209072015-10-01 10:00:57 +030093#define DRM_ROTATE_MASK 0x0f
Ville Syrjälä06596962014-07-08 10:31:51 +053094#define DRM_ROTATE_0 0
95#define DRM_ROTATE_90 1
96#define DRM_ROTATE_180 2
97#define DRM_ROTATE_270 3
Joonas Lahtinen62209072015-10-01 10:00:57 +030098#define DRM_REFLECT_MASK (~DRM_ROTATE_MASK)
Ville Syrjälä06596962014-07-08 10:31:51 +053099#define DRM_REFLECT_X 4
100#define DRM_REFLECT_Y 5
101
Daniel Vetter55310002014-01-23 15:52:20 +0100102enum drm_connector_force {
103 DRM_FORCE_UNSPECIFIED,
104 DRM_FORCE_OFF,
105 DRM_FORCE_ON, /* force on analog part normally */
106 DRM_FORCE_ON_DIGITAL, /* for DVI-I use digital connector */
Dave Airlief453ba02008-11-07 14:05:41 -0800107};
108
Daniel Vetter55310002014-01-23 15:52:20 +0100109#include <drm/drm_modes.h>
Damien Lespiau4aa17cf2013-09-25 16:45:21 +0100110
Dave Airlief453ba02008-11-07 14:05:41 -0800111enum drm_connector_status {
112 connector_status_connected = 1,
113 connector_status_disconnected = 2,
114 connector_status_unknown = 3,
115};
116
117enum subpixel_order {
118 SubPixelUnknown = 0,
119 SubPixelHorizontalRGB,
120 SubPixelHorizontalBGR,
121 SubPixelVerticalRGB,
122 SubPixelVerticalBGR,
123 SubPixelNone,
124};
125
Jesse Barnesda05a5a72011-04-15 13:48:57 -0700126#define DRM_COLOR_FORMAT_RGB444 (1<<0)
127#define DRM_COLOR_FORMAT_YCRCB444 (1<<1)
128#define DRM_COLOR_FORMAT_YCRCB422 (1<<2)
Dave Airlief453ba02008-11-07 14:05:41 -0800129/*
130 * Describes a given display (e.g. CRT or flat panel) and its limitations.
131 */
132struct drm_display_info {
133 char name[DRM_DISPLAY_INFO_LEN];
Adam Jacksonfb439642010-08-03 14:38:16 -0400134
Dave Airlief453ba02008-11-07 14:05:41 -0800135 /* Physical size */
136 unsigned int width_mm;
137 unsigned int height_mm;
138
Dave Airlief453ba02008-11-07 14:05:41 -0800139 /* Clock limits FIXME: storage format */
140 unsigned int min_vfreq, max_vfreq;
141 unsigned int min_hfreq, max_hfreq;
142 unsigned int pixel_clock;
Jesse Barnes3b112282011-04-15 12:49:23 -0700143 unsigned int bpc;
Dave Airlief453ba02008-11-07 14:05:41 -0800144
Dave Airlief453ba02008-11-07 14:05:41 -0800145 enum subpixel_order subpixel_order;
Jesse Barnesda05a5a72011-04-15 13:48:57 -0700146 u32 color_formats;
Dave Airlief453ba02008-11-07 14:05:41 -0800147
Boris Brezillonb5571e92014-07-22 12:09:10 +0200148 const u32 *bus_formats;
149 unsigned int num_bus_formats;
150
Mario Kleiner5d02626d2014-06-05 09:52:10 -0400151 /* Mask of supported hdmi deep color modes */
152 u8 edid_hdmi_dc_modes;
153
Jesse Barnesebec9a7b2011-08-03 09:22:54 -0700154 u8 cea_rev;
Dave Airlief453ba02008-11-07 14:05:41 -0800155};
156
Dave Airlie138f9eb2014-10-20 16:17:17 +1000157/* data corresponds to displayid vend/prod/serial */
158struct drm_tile_group {
159 struct kref refcount;
160 struct drm_device *dev;
161 int id;
162 u8 group_data[8];
163};
164
Daniel Vetterc6b0ca32015-12-04 09:46:01 +0100165/**
166 * struct drm_framebuffer_funcs - framebuffer hooks
167 */
Dave Airlief453ba02008-11-07 14:05:41 -0800168struct drm_framebuffer_funcs {
Daniel Vetterc6b0ca32015-12-04 09:46:01 +0100169 /**
170 * @destroy:
171 *
172 * Clean up framebuffer resources, specifically also unreference the
173 * backing storage. The core guarantees to call this function for every
174 * framebuffer successfully created by ->fb_create() in
Daniel Vetterd55f5322015-12-08 09:49:19 +0100175 * &drm_mode_config_funcs. Drivers must also call
176 * drm_framebuffer_cleanup() to release DRM core resources for this
177 * framebuffer.
Daniel Vetterc6b0ca32015-12-04 09:46:01 +0100178 */
Dave Airlief453ba02008-11-07 14:05:41 -0800179 void (*destroy)(struct drm_framebuffer *framebuffer);
Daniel Vetterc6b0ca32015-12-04 09:46:01 +0100180
181 /**
182 * @create_handle:
183 *
184 * Create a buffer handle in the driver-specific buffer manager (either
185 * GEM or TTM) valid for the passed-in struct &drm_file. This is used by
186 * the core to implement the GETFB IOCTL, which returns (for
187 * sufficiently priviledged user) also a native buffer handle. This can
188 * be used for seamless transitions between modesetting clients by
189 * copying the current screen contents to a private buffer and blending
190 * between that and the new contents.
191 *
Daniel Vetterd55f5322015-12-08 09:49:19 +0100192 * GEM based drivers should call drm_gem_handle_create() to create the
193 * handle.
194 *
Daniel Vetterc6b0ca32015-12-04 09:46:01 +0100195 * RETURNS:
196 *
197 * 0 on success or a negative error code on failure.
198 */
Dave Airlief453ba02008-11-07 14:05:41 -0800199 int (*create_handle)(struct drm_framebuffer *fb,
200 struct drm_file *file_priv,
201 unsigned int *handle);
Daniel Vetterc6b0ca32015-12-04 09:46:01 +0100202 /**
203 * @dirty:
Jakob Bornecrantz884840a2009-12-03 23:25:47 +0000204 *
Daniel Vetterc6b0ca32015-12-04 09:46:01 +0100205 * Optional callback for the dirty fb IOCTL.
Jakob Bornecrantz884840a2009-12-03 23:25:47 +0000206 *
Daniel Vetterc6b0ca32015-12-04 09:46:01 +0100207 * Userspace can notify the driver via this callback that an area of the
208 * framebuffer has changed and should be flushed to the display
209 * hardware. This can also be used internally, e.g. by the fbdev
210 * emulation, though that's not the case currently.
211 *
212 * See documentation in drm_mode.h for the struct drm_mode_fb_dirty_cmd
213 * for more information as all the semantics and arguments have a one to
214 * one mapping on this function.
215 *
216 * RETURNS:
217 *
218 * 0 on success or a negative error code on failure.
Jakob Bornecrantz884840a2009-12-03 23:25:47 +0000219 */
Thomas Hellstrom02b00162010-10-05 12:43:02 +0200220 int (*dirty)(struct drm_framebuffer *framebuffer,
221 struct drm_file *file_priv, unsigned flags,
Jakob Bornecrantz884840a2009-12-03 23:25:47 +0000222 unsigned color, struct drm_clip_rect *clips,
223 unsigned num_clips);
Dave Airlief453ba02008-11-07 14:05:41 -0800224};
225
226struct drm_framebuffer {
227 struct drm_device *dev;
Rob Clarkf7eff602012-09-05 21:48:38 +0000228 /*
229 * Note that the fb is refcounted for the benefit of driver internals,
230 * for example some hw, disabling a CRTC/plane is asynchronous, and
231 * scanout does not actually complete until the next vblank. So some
232 * cleanup (like releasing the reference(s) on the backing GEM bo(s))
233 * should be deferred. In cases like this, the driver would like to
234 * hold a ref to the fb even though it has already been removed from
235 * userspace perspective.
236 */
237 struct kref refcount;
Daniel Vetter4b096ac2012-12-10 21:19:18 +0100238 /*
239 * Place on the dev->mode_config.fb_list, access protected by
240 * dev->mode_config.fb_lock.
241 */
Dave Airlief453ba02008-11-07 14:05:41 -0800242 struct list_head head;
243 struct drm_mode_object base;
244 const struct drm_framebuffer_funcs *funcs;
Ville Syrjälä01f2c772011-12-20 00:06:49 +0200245 unsigned int pitches[4];
246 unsigned int offsets[4];
Rob Clarke3eb3252015-02-05 14:41:52 +0000247 uint64_t modifier[4];
Dave Airlief453ba02008-11-07 14:05:41 -0800248 unsigned int width;
249 unsigned int height;
250 /* depth can be 15 or 16 */
251 unsigned int depth;
252 int bits_per_pixel;
253 int flags;
Jesse Barnes308e5bc2011-11-14 14:51:28 -0800254 uint32_t pixel_format; /* fourcc format */
Dave Airlief453ba02008-11-07 14:05:41 -0800255 struct list_head filp_head;
256};
257
258struct drm_property_blob {
259 struct drm_mode_object base;
Daniel Stone6bcacf52015-04-20 19:22:55 +0100260 struct drm_device *dev;
261 struct kref refcount;
Daniel Stonee2f5d2e2015-05-22 13:34:51 +0100262 struct list_head head_global;
263 struct list_head head_file;
Thierry Redingecbbe592014-05-13 11:36:13 +0200264 size_t length;
Ville Syrjäläd63f5e62012-03-13 12:35:49 +0200265 unsigned char data[];
Dave Airlief453ba02008-11-07 14:05:41 -0800266};
267
268struct drm_property_enum {
269 uint64_t value;
270 struct list_head head;
271 char name[DRM_PROP_NAME_LEN];
272};
273
274struct drm_property {
275 struct list_head head;
276 struct drm_mode_object base;
277 uint32_t flags;
278 char name[DRM_PROP_NAME_LEN];
279 uint32_t num_values;
280 uint64_t *values;
Rob Clark98f75de2014-05-30 11:37:03 -0400281 struct drm_device *dev;
Dave Airlief453ba02008-11-07 14:05:41 -0800282
Daniel Vetter3758b342014-11-19 18:38:10 +0100283 struct list_head enum_list;
Dave Airlief453ba02008-11-07 14:05:41 -0800284};
285
286struct drm_crtc;
287struct drm_connector;
288struct drm_encoder;
Kristian Høgsbergd91d8a32009-11-17 12:43:55 -0500289struct drm_pending_vblank_event;
Jesse Barnes8cf5c912011-11-14 14:51:27 -0800290struct drm_plane;
Sean Paul3b336ec2013-08-14 16:47:37 -0400291struct drm_bridge;
Daniel Vetter144ecb92014-10-27 20:28:44 +0100292struct drm_atomic_state;
293
Daniel Vetter4490d4c2015-12-04 09:45:45 +0100294struct drm_crtc_helper_funcs;
295struct drm_encoder_helper_funcs;
296struct drm_connector_helper_funcs;
297struct drm_plane_helper_funcs;
298
Daniel Vetter144ecb92014-10-27 20:28:44 +0100299/**
Daniel Vettercc4ceb42014-07-25 21:30:38 +0200300 * struct drm_crtc_state - mutable CRTC state
Daniel Vetter07cc0ef2014-11-27 15:49:39 +0100301 * @crtc: backpointer to the CRTC
Daniel Vetter144ecb92014-10-27 20:28:44 +0100302 * @enable: whether the CRTC should be enabled, gates all other state
Daniel Vetterd9b13622014-11-26 16:57:41 +0100303 * @active: whether the CRTC is actively displaying (used for DPMS)
Maarten Lankhorstfc596662015-07-21 13:28:57 +0200304 * @planes_changed: planes on this crtc are updated
305 * @mode_changed: crtc_state->mode or crtc_state->enable has been changed
306 * @active_changed: crtc_state->active has been toggled.
307 * @connectors_changed: connectors to this crtc have been updated
Lionel Landwerlin5488dc12016-02-26 17:05:00 +0000308 * @color_mgmt_changed: color management properties have changed (degamma or
309 * gamma LUT or CSC matrix)
Rob Clark6ddd3882014-11-21 15:28:31 -0500310 * @plane_mask: bitmask of (1 << drm_plane_index(plane)) of attached planes
Maarten Lankhorst4cd9fa52016-01-04 12:53:18 +0100311 * @connector_mask: bitmask of (1 << drm_connector_index(connector)) of attached connectors
Maarten Lankhorste87a52b2016-01-28 15:04:58 +0100312 * @encoder_mask: bitmask of (1 << drm_encoder_index(encoder)) of attached encoders
Daniel Vetter623369e2014-09-16 17:50:47 +0200313 * @last_vblank_count: for helpers and drivers to capture the vblank of the
314 * update to ensure framebuffer cleanup isn't done too early
Daniel Vetter2f324b42014-10-29 11:13:47 +0100315 * @adjusted_mode: for use by helpers and drivers to compute adjusted mode timings
Daniel Vetter144ecb92014-10-27 20:28:44 +0100316 * @mode: current mode timings
Lionel Landwerlin5488dc12016-02-26 17:05:00 +0000317 * @degamma_lut: Lookup table for converting framebuffer pixel data
318 * before apply the conversion matrix
319 * @ctm: Transformation matrix
320 * @gamma_lut: Lookup table for converting pixel data after the
321 * conversion matrix
Daniel Vetter144ecb92014-10-27 20:28:44 +0100322 * @event: optional pointer to a DRM event to signal upon completion of the
323 * state update
324 * @state: backpointer to global drm_atomic_state
Daniel Vetterd9b13622014-11-26 16:57:41 +0100325 *
326 * Note that the distinction between @enable and @active is rather subtile:
327 * Flipping @active while @enable is set without changing anything else may
328 * never return in a failure from the ->atomic_check callback. Userspace assumes
329 * that a DPMS On will always succeed. In other words: @enable controls resource
330 * assignment, @active controls the actual hardware state.
Daniel Vetter144ecb92014-10-27 20:28:44 +0100331 */
332struct drm_crtc_state {
Daniel Vetter07cc0ef2014-11-27 15:49:39 +0100333 struct drm_crtc *crtc;
334
Daniel Vettercc4ceb42014-07-25 21:30:38 +0200335 bool enable;
Daniel Vetterd9b13622014-11-26 16:57:41 +0100336 bool active;
Daniel Vetter144ecb92014-10-27 20:28:44 +0100337
Daniel Vetterc2fcd272014-11-05 00:14:14 +0100338 /* computed state bits used by helpers and drivers */
339 bool planes_changed : 1;
Daniel Vetter623369e2014-09-16 17:50:47 +0200340 bool mode_changed : 1;
Daniel Vettereab3bbe2015-01-22 16:36:21 +0100341 bool active_changed : 1;
Maarten Lankhorstfc596662015-07-21 13:28:57 +0200342 bool connectors_changed : 1;
Lionel Landwerlin5488dc12016-02-26 17:05:00 +0000343 bool color_mgmt_changed : 1;
Daniel Vetter623369e2014-09-16 17:50:47 +0200344
Rob Clark6ddd3882014-11-21 15:28:31 -0500345 /* attached planes bitmask:
346 * WARNING: transitional helpers do not maintain plane_mask so
347 * drivers not converted over to atomic helpers should not rely
348 * on plane_mask being accurate!
349 */
350 u32 plane_mask;
351
Maarten Lankhorst4cd9fa52016-01-04 12:53:18 +0100352 u32 connector_mask;
Maarten Lankhorste87a52b2016-01-28 15:04:58 +0100353 u32 encoder_mask;
Maarten Lankhorst4cd9fa52016-01-04 12:53:18 +0100354
Daniel Vetter623369e2014-09-16 17:50:47 +0200355 /* last_vblank_count: for vblank waits before cleanup */
356 u32 last_vblank_count;
Daniel Vetterc2fcd272014-11-05 00:14:14 +0100357
Daniel Vetter2f324b42014-10-29 11:13:47 +0100358 /* adjusted_mode: for use by helpers and drivers */
359 struct drm_display_mode adjusted_mode;
360
Daniel Vetter144ecb92014-10-27 20:28:44 +0100361 struct drm_display_mode mode;
362
Daniel Stone99cf4a22015-05-25 19:11:51 +0100363 /* blob property to expose current mode to atomic userspace */
364 struct drm_property_blob *mode_blob;
365
Lionel Landwerlin5488dc12016-02-26 17:05:00 +0000366 /* blob property to expose color management to userspace */
367 struct drm_property_blob *degamma_lut;
368 struct drm_property_blob *ctm;
369 struct drm_property_blob *gamma_lut;
370
Daniel Vetter144ecb92014-10-27 20:28:44 +0100371 struct drm_pending_vblank_event *event;
372
373 struct drm_atomic_state *state;
374};
Dave Airlief453ba02008-11-07 14:05:41 -0800375
376/**
Daniel Vetter3bf04012014-10-27 16:54:27 +0100377 * struct drm_crtc_funcs - control CRTCs for a given device
Dave Airlief453ba02008-11-07 14:05:41 -0800378 *
379 * The drm_crtc_funcs structure is the central CRTC management structure
380 * in the DRM. Each CRTC controls one or more connectors (note that the name
381 * CRTC is simply historical, a CRTC may control LVDS, VGA, DVI, TV out, etc.
382 * connectors, not just CRTs).
383 *
384 * Each driver is responsible for filling out this structure at startup time,
385 * in addition to providing other modesetting features, like i2c and DDC
386 * bus accessors.
387 */
388struct drm_crtc_funcs {
Daniel Vetter88548632015-12-04 09:45:48 +0100389 /**
390 * @reset:
391 *
392 * Reset CRTC hardware and software state to off. This function isn't
393 * called by the core directly, only through drm_mode_config_reset().
394 * It's not a helper hook only for historical reasons.
395 *
396 * Atomic drivers can use drm_atomic_helper_crtc_reset() to reset
397 * atomic state using this hook.
398 */
Chris Wilsoneb0335562011-01-24 15:11:08 +0000399 void (*reset)(struct drm_crtc *crtc);
Dave Airlief453ba02008-11-07 14:05:41 -0800400
Daniel Vetterf6da8c62015-12-04 09:46:00 +0100401 /**
402 * @cursor_set:
403 *
404 * Update the cursor image. The cursor position is relative to the CRTC
405 * and can be partially or fully outside of the visible area.
406 *
407 * Note that contrary to all other KMS functions the legacy cursor entry
408 * points don't take a framebuffer object, but instead take directly a
409 * raw buffer object id from the driver's buffer manager (which is
410 * either GEM or TTM for current drivers).
411 *
412 * This entry point is deprecated, drivers should instead implement
413 * universal plane support and register a proper cursor plane using
414 * drm_crtc_init_with_planes().
415 *
416 * This callback is optional
417 *
418 * RETURNS:
419 *
420 * 0 on success or a negative error code on failure.
421 */
Dave Airlief453ba02008-11-07 14:05:41 -0800422 int (*cursor_set)(struct drm_crtc *crtc, struct drm_file *file_priv,
423 uint32_t handle, uint32_t width, uint32_t height);
Daniel Vetterf6da8c62015-12-04 09:46:00 +0100424
425 /**
426 * @cursor_set2:
427 *
428 * Update the cursor image, including hotspot information. The hotspot
429 * must not affect the cursor position in CRTC coordinates, but is only
430 * meant as a hint for virtualized display hardware to coordinate the
431 * guests and hosts cursor position. The cursor hotspot is relative to
432 * the cursor image. Otherwise this works exactly like @cursor_set.
433 *
434 * This entry point is deprecated, drivers should instead implement
435 * universal plane support and register a proper cursor plane using
436 * drm_crtc_init_with_planes().
437 *
438 * This callback is optional.
439 *
440 * RETURNS:
441 *
442 * 0 on success or a negative error code on failure.
443 */
Dave Airlie4c813d42013-06-20 11:48:52 +1000444 int (*cursor_set2)(struct drm_crtc *crtc, struct drm_file *file_priv,
445 uint32_t handle, uint32_t width, uint32_t height,
446 int32_t hot_x, int32_t hot_y);
Daniel Vetterf6da8c62015-12-04 09:46:00 +0100447
448 /**
449 * @cursor_move:
450 *
451 * Update the cursor position. The cursor does not need to be visible
452 * when this hook is called.
453 *
454 * This entry point is deprecated, drivers should instead implement
455 * universal plane support and register a proper cursor plane using
456 * drm_crtc_init_with_planes().
457 *
458 * This callback is optional.
459 *
460 * RETURNS:
461 *
462 * 0 on success or a negative error code on failure.
463 */
Dave Airlief453ba02008-11-07 14:05:41 -0800464 int (*cursor_move)(struct drm_crtc *crtc, int x, int y);
465
Daniel Vetterf6da8c62015-12-04 09:46:00 +0100466 /**
467 * @gamma_set:
468 *
469 * Set gamma on the CRTC.
470 *
471 * This callback is optional.
472 *
473 * NOTE:
474 *
475 * Drivers that support gamma tables and also fbdev emulation through
476 * the provided helper library need to take care to fill out the gamma
477 * hooks for both. Currently there's a bit an unfortunate duplication
478 * going on, which should eventually be unified to just one set of
479 * hooks.
480 */
Dave Airlief453ba02008-11-07 14:05:41 -0800481 void (*gamma_set)(struct drm_crtc *crtc, u16 *r, u16 *g, u16 *b,
James Simmons72034252010-08-03 01:33:19 +0100482 uint32_t start, uint32_t size);
Daniel Vetter88548632015-12-04 09:45:48 +0100483
484 /**
485 * @destroy:
486 *
487 * Clean up plane resources. This is only called at driver unload time
488 * through drm_mode_config_cleanup() since a CRTC cannot be hotplugged
489 * in DRM.
490 */
Dave Airlief453ba02008-11-07 14:05:41 -0800491 void (*destroy)(struct drm_crtc *crtc);
492
Daniel Vetterf6da8c62015-12-04 09:46:00 +0100493 /**
494 * @set_config:
495 *
496 * This is the main legacy entry point to change the modeset state on a
497 * CRTC. All the details of the desired configuration are passed in a
498 * struct &drm_mode_set - see there for details.
499 *
500 * Drivers implementing atomic modeset should use
501 * drm_atomic_helper_set_config() to implement this hook.
502 *
503 * RETURNS:
504 *
505 * 0 on success or a negative error code on failure.
506 */
Dave Airlief453ba02008-11-07 14:05:41 -0800507 int (*set_config)(struct drm_mode_set *set);
Kristian Høgsbergd91d8a32009-11-17 12:43:55 -0500508
Daniel Vetterf6da8c62015-12-04 09:46:00 +0100509 /**
510 * @page_flip:
511 *
512 * Legacy entry point to schedule a flip to the given framebuffer.
513 *
514 * Page flipping is a synchronization mechanism that replaces the frame
515 * buffer being scanned out by the CRTC with a new frame buffer during
516 * vertical blanking, avoiding tearing (except when requested otherwise
517 * through the DRM_MODE_PAGE_FLIP_ASYNC flag). When an application
518 * requests a page flip the DRM core verifies that the new frame buffer
519 * is large enough to be scanned out by the CRTC in the currently
520 * configured mode and then calls the CRTC ->page_flip() operation with a
521 * pointer to the new frame buffer.
522 *
523 * The driver must wait for any pending rendering to the new framebuffer
524 * to complete before executing the flip. It should also wait for any
525 * pending rendering from other drivers if the underlying buffer is a
526 * shared dma-buf.
527 *
528 * An application can request to be notified when the page flip has
529 * completed. The drm core will supply a struct &drm_event in the event
530 * parameter in this case. This can be handled by the
531 * drm_crtc_send_vblank_event() function, which the driver should call on
532 * the provided event upon completion of the flip. Note that if
533 * the driver supports vblank signalling and timestamping the vblank
534 * counters and timestamps must agree with the ones returned from page
535 * flip events. With the current vblank helper infrastructure this can
536 * be achieved by holding a vblank reference while the page flip is
537 * pending, acquired through drm_crtc_vblank_get() and released with
538 * drm_crtc_vblank_put(). Drivers are free to implement their own vblank
539 * counter and timestamp tracking though, e.g. if they have accurate
540 * timestamp registers in hardware.
541 *
542 * FIXME:
543 *
544 * Up to that point drivers need to manage events themselves and can use
545 * even->base.list freely for that. Specifically they need to ensure
546 * that they don't send out page flip (or vblank) events for which the
547 * corresponding drm file has been closed already. The drm core
548 * unfortunately does not (yet) take care of that. Therefore drivers
549 * currently must clean up and release pending events in their
550 * ->preclose driver function.
551 *
552 * This callback is optional.
553 *
554 * NOTE:
555 *
556 * Very early versions of the KMS ABI mandated that the driver must
557 * block (but not reject) any rendering to the old framebuffer until the
558 * flip operation has completed and the old framebuffer is no longer
559 * visible. This requirement has been lifted, and userspace is instead
560 * expected to request delivery of an event and wait with recycling old
561 * buffers until such has been received.
562 *
563 * RETURNS:
564 *
565 * 0 on success or a negative error code on failure. Note that if a
566 * ->page_flip() operation is already pending the callback should return
567 * -EBUSY. Pageflips on a disabled CRTC (either by setting a NULL mode
568 * or just runtime disabled through DPMS respectively the new atomic
Daniel Vetter4cba6852015-12-08 09:49:20 +0100569 * "ACTIVE" state) should result in an -EINVAL error code. Note that
570 * drm_atomic_helper_page_flip() checks this already for atomic drivers.
Kristian Høgsbergd91d8a32009-11-17 12:43:55 -0500571 */
572 int (*page_flip)(struct drm_crtc *crtc,
573 struct drm_framebuffer *fb,
Keith Packarded8d1972013-07-22 18:49:58 -0700574 struct drm_pending_vblank_event *event,
575 uint32_t flags);
Paulo Zanonibffd9de02012-05-15 18:09:05 -0300576
Daniel Vetter88548632015-12-04 09:45:48 +0100577 /**
578 * @set_property:
579 *
580 * This is the legacy entry point to update a property attached to the
581 * CRTC.
582 *
583 * Drivers implementing atomic modeset should use
584 * drm_atomic_helper_crtc_set_property() to implement this hook.
585 *
586 * This callback is optional if the driver does not support any legacy
587 * driver-private properties.
588 *
589 * RETURNS:
590 *
591 * 0 on success or a negative error code on failure.
592 */
Paulo Zanonibffd9de02012-05-15 18:09:05 -0300593 int (*set_property)(struct drm_crtc *crtc,
594 struct drm_property *property, uint64_t val);
Daniel Vetter144ecb92014-10-27 20:28:44 +0100595
Daniel Vetter88548632015-12-04 09:45:48 +0100596 /**
597 * @atomic_duplicate_state:
598 *
599 * Duplicate the current atomic state for this CRTC and return it.
600 * The core and helpers gurantee that any atomic state duplicated with
601 * this hook and still owned by the caller (i.e. not transferred to the
602 * driver by calling ->atomic_commit() from struct
603 * &drm_mode_config_funcs) will be cleaned up by calling the
604 * @atomic_destroy_state hook in this structure.
605 *
606 * Atomic drivers which don't subclass struct &drm_crtc should use
607 * drm_atomic_helper_crtc_duplicate_state(). Drivers that subclass the
608 * state structure to extend it with driver-private state should use
609 * __drm_atomic_helper_crtc_duplicate_state() to make sure shared state is
610 * duplicated in a consistent fashion across drivers.
611 *
612 * It is an error to call this hook before crtc->state has been
613 * initialized correctly.
614 *
615 * NOTE:
616 *
617 * If the duplicate state references refcounted resources this hook must
618 * acquire a reference for each of them. The driver must release these
619 * references again in @atomic_destroy_state.
620 *
621 * RETURNS:
622 *
623 * Duplicated atomic state or NULL when the allocation failed.
624 */
Daniel Vetter144ecb92014-10-27 20:28:44 +0100625 struct drm_crtc_state *(*atomic_duplicate_state)(struct drm_crtc *crtc);
Daniel Vetter88548632015-12-04 09:45:48 +0100626
627 /**
628 * @atomic_destroy_state:
629 *
630 * Destroy a state duplicated with @atomic_duplicate_state and release
631 * or unreference all resources it references
632 */
Daniel Vetter144ecb92014-10-27 20:28:44 +0100633 void (*atomic_destroy_state)(struct drm_crtc *crtc,
Daniel Vettercc4ceb42014-07-25 21:30:38 +0200634 struct drm_crtc_state *state);
Daniel Vetter88548632015-12-04 09:45:48 +0100635
636 /**
637 * @atomic_set_property:
638 *
639 * Decode a driver-private property value and store the decoded value
640 * into the passed-in state structure. Since the atomic core decodes all
641 * standardized properties (even for extensions beyond the core set of
642 * properties which might not be implemented by all drivers) this
643 * requires drivers to subclass the state structure.
644 *
645 * Such driver-private properties should really only be implemented for
646 * truly hardware/vendor specific state. Instead it is preferred to
647 * standardize atomic extension and decode the properties used to expose
648 * such an extension in the core.
649 *
650 * Do not call this function directly, use
651 * drm_atomic_crtc_set_property() instead.
652 *
653 * This callback is optional if the driver does not support any
654 * driver-private atomic properties.
655 *
656 * NOTE:
657 *
658 * This function is called in the state assembly phase of atomic
659 * modesets, which can be aborted for any reason (including on
660 * userspace's request to just check whether a configuration would be
661 * possible). Drivers MUST NOT touch any persistent state (hardware or
662 * software) or data structures except the passed in @state parameter.
663 *
664 * Also since userspace controls in which order properties are set this
665 * function must not do any input validation (since the state update is
666 * incomplete and hence likely inconsistent). Instead any such input
667 * validation must be done in the various atomic_check callbacks.
668 *
669 * RETURNS:
670 *
671 * 0 if the property has been found, -EINVAL if the property isn't
672 * implemented by the driver (which should never happen, the core only
673 * asks for properties attached to this CRTC). No other validation is
674 * allowed by the driver. The core already checks that the property
675 * value is within the range (integer, valid enum value, ...) the driver
676 * set when registering the property.
677 */
Daniel Vetter144ecb92014-10-27 20:28:44 +0100678 int (*atomic_set_property)(struct drm_crtc *crtc,
679 struct drm_crtc_state *state,
680 struct drm_property *property,
681 uint64_t val);
Daniel Vetter88548632015-12-04 09:45:48 +0100682 /**
683 * @atomic_get_property:
684 *
685 * Reads out the decoded driver-private property. This is used to
Daniel Vetterc6b0ca32015-12-04 09:46:01 +0100686 * implement the GETCRTC IOCTL.
Daniel Vetter88548632015-12-04 09:45:48 +0100687 *
688 * Do not call this function directly, use
689 * drm_atomic_crtc_get_property() instead.
690 *
691 * This callback is optional if the driver does not support any
692 * driver-private atomic properties.
693 *
694 * RETURNS:
695 *
696 * 0 on success, -EINVAL if the property isn't implemented by the
697 * driver (which should never happen, the core only asks for
698 * properties attached to this CRTC).
699 */
Rob Clarkac9c9252014-12-18 16:01:47 -0500700 int (*atomic_get_property)(struct drm_crtc *crtc,
701 const struct drm_crtc_state *state,
702 struct drm_property *property,
703 uint64_t *val);
Dave Airlief453ba02008-11-07 14:05:41 -0800704};
705
706/**
Daniel Vetter3bf04012014-10-27 16:54:27 +0100707 * struct drm_crtc - central CRTC control structure
Jesse Barnes77491632011-11-07 12:03:14 -0800708 * @dev: parent DRM device
Daniel Vetter2c0c33d2014-10-27 20:19:38 +0100709 * @port: OF node used by drm_of_find_possible_crtcs()
Jesse Barnes77491632011-11-07 12:03:14 -0800710 * @head: list management
Rob Clark51fd3712013-11-19 12:10:12 -0500711 * @mutex: per-CRTC locking
Jesse Barnes77491632011-11-07 12:03:14 -0800712 * @base: base KMS object for ID tracking etc.
Matt Ropere13161a2014-04-01 15:22:38 -0700713 * @primary: primary plane for this CRTC
714 * @cursor: cursor plane for this CRTC
Daniel Vetter2c0c33d2014-10-27 20:19:38 +0100715 * @cursor_x: current x position of the cursor, used for universal cursor planes
716 * @cursor_y: current y position of the cursor, used for universal cursor planes
Dave Airlief453ba02008-11-07 14:05:41 -0800717 * @enabled: is this CRTC enabled?
Jesse Barnes77491632011-11-07 12:03:14 -0800718 * @mode: current mode timings
719 * @hwmode: mode timings as programmed to hw regs
Dave Airlief453ba02008-11-07 14:05:41 -0800720 * @x: x position on screen
721 * @y: y position on screen
Dave Airlief453ba02008-11-07 14:05:41 -0800722 * @funcs: CRTC control functions
Jesse Barnes77491632011-11-07 12:03:14 -0800723 * @gamma_size: size of gamma ramp
724 * @gamma_store: gamma ramp values
Jesse Barnes77491632011-11-07 12:03:14 -0800725 * @helper_private: mid-layer private data
Paulo Zanonibffd9de02012-05-15 18:09:05 -0300726 * @properties: property tracking for this CRTC
Daniel Vetter144ecb92014-10-27 20:28:44 +0100727 * @state: current atomic state for this CRTC
Daniel Vetter2c0c33d2014-10-27 20:19:38 +0100728 * @acquire_ctx: per-CRTC implicit acquire context used by atomic drivers for
Daniel Vetterc6b0ca32015-12-04 09:46:01 +0100729 * legacy IOCTLs
Dave Airlief453ba02008-11-07 14:05:41 -0800730 *
731 * Each CRTC may have one or more connectors associated with it. This structure
732 * allows the CRTC to be controlled.
733 */
734struct drm_crtc {
735 struct drm_device *dev;
Russell King7e435aa2014-06-15 11:07:12 +0100736 struct device_node *port;
Dave Airlief453ba02008-11-07 14:05:41 -0800737 struct list_head head;
738
Ville Syrjäläfa3ab4c2015-12-08 18:41:53 +0200739 char *name;
740
Daniel Vetter3bf04012014-10-27 16:54:27 +0100741 /*
Daniel Vetter29494c12012-12-02 02:18:25 +0100742 * crtc mutex
743 *
744 * This provides a read lock for the overall crtc state (mode, dpms
745 * state, ...) and a write lock for everything which can be update
746 * without a full modeset (fb, cursor data, ...)
747 */
Rob Clark51fd3712013-11-19 12:10:12 -0500748 struct drm_modeset_lock mutex;
Daniel Vetter29494c12012-12-02 02:18:25 +0100749
Dave Airlief453ba02008-11-07 14:05:41 -0800750 struct drm_mode_object base;
751
Matt Ropere13161a2014-04-01 15:22:38 -0700752 /* primary and cursor planes for CRTC */
753 struct drm_plane *primary;
754 struct drm_plane *cursor;
755
Matt Roper161d0dc2014-06-10 08:28:10 -0700756 /* position of cursor plane on crtc */
757 int cursor_x;
758 int cursor_y;
759
Dave Airlief453ba02008-11-07 14:05:41 -0800760 bool enabled;
761
Mario Kleiner27641c32010-10-23 04:20:23 +0200762 /* Requested mode from modesetting. */
Dave Airlief453ba02008-11-07 14:05:41 -0800763 struct drm_display_mode mode;
764
Mario Kleiner27641c32010-10-23 04:20:23 +0200765 /* Programmed mode in hw, after adjustments for encoders,
766 * crtc, panel scaling etc. Needed for timestamping etc.
767 */
768 struct drm_display_mode hwmode;
769
Dave Airlief453ba02008-11-07 14:05:41 -0800770 int x, y;
Dave Airlief453ba02008-11-07 14:05:41 -0800771 const struct drm_crtc_funcs *funcs;
772
Lionel Landwerlin5488dc12016-02-26 17:05:00 +0000773 /* Legacy FB CRTC gamma size for reporting to userspace */
Dave Airlief453ba02008-11-07 14:05:41 -0800774 uint32_t gamma_size;
775 uint16_t *gamma_store;
776
777 /* if you are using the helper */
Daniel Vetter4490d4c2015-12-04 09:45:45 +0100778 const struct drm_crtc_helper_funcs *helper_private;
Paulo Zanonibffd9de02012-05-15 18:09:05 -0300779
780 struct drm_object_properties properties;
Daniel Vetterd059f652014-07-25 18:07:40 +0200781
Daniel Vetter144ecb92014-10-27 20:28:44 +0100782 struct drm_crtc_state *state;
783
Daniel Vetterd059f652014-07-25 18:07:40 +0200784 /*
Daniel Vetterc6b0ca32015-12-04 09:46:01 +0100785 * For legacy crtc IOCTLs so that atomic drivers can get at the locking
Daniel Vetterd059f652014-07-25 18:07:40 +0200786 * acquire context.
787 */
788 struct drm_modeset_acquire_ctx *acquire_ctx;
Dave Airlief453ba02008-11-07 14:05:41 -0800789};
790
Daniel Vetter144ecb92014-10-27 20:28:44 +0100791/**
792 * struct drm_connector_state - mutable connector state
Daniel Vetter07cc0ef2014-11-27 15:49:39 +0100793 * @connector: backpointer to the connector
Daniel Vettercc4ceb42014-07-25 21:30:38 +0200794 * @crtc: CRTC to connect connector to, NULL if disabled
Daniel Vetter623369e2014-09-16 17:50:47 +0200795 * @best_encoder: can be used by helpers and drivers to select the encoder
Daniel Vetter144ecb92014-10-27 20:28:44 +0100796 * @state: backpointer to global drm_atomic_state
797 */
798struct drm_connector_state {
Daniel Vetter07cc0ef2014-11-27 15:49:39 +0100799 struct drm_connector *connector;
800
Rob Clark6ddd3882014-11-21 15:28:31 -0500801 struct drm_crtc *crtc; /* do not write directly, use drm_atomic_set_crtc_for_connector() */
Daniel Vetter144ecb92014-10-27 20:28:44 +0100802
Daniel Vetter623369e2014-09-16 17:50:47 +0200803 struct drm_encoder *best_encoder;
804
Daniel Vetter144ecb92014-10-27 20:28:44 +0100805 struct drm_atomic_state *state;
806};
Dave Airlief453ba02008-11-07 14:05:41 -0800807
808/**
Daniel Vetter3bf04012014-10-27 16:54:27 +0100809 * struct drm_connector_funcs - control connectors on a given device
Daniel Vetter144ecb92014-10-27 20:28:44 +0100810 *
Dave Airlief453ba02008-11-07 14:05:41 -0800811 * Each CRTC may have one or more connectors attached to it. The functions
812 * below allow the core DRM code to control connectors, enumerate available modes,
813 * etc.
814 */
815struct drm_connector_funcs {
Daniel Vetter6fe14ac2015-12-04 09:45:58 +0100816 /**
817 * @dpms:
818 *
819 * Legacy entry point to set the per-connector DPMS state. Legacy DPMS
820 * is exposed as a standard property on the connector, but diverted to
821 * this callback in the drm core. Note that atomic drivers don't
822 * implement the 4 level DPMS support on the connector any more, but
823 * instead only have an on/off "ACTIVE" property on the CRTC object.
824 *
825 * Drivers implementing atomic modeset should use
826 * drm_atomic_helper_connector_dpms() to implement this hook.
827 *
828 * RETURNS:
829 *
830 * 0 on success or a negative error code on failure.
831 */
Maarten Lankhorst9a69a9a2015-07-21 11:34:55 +0200832 int (*dpms)(struct drm_connector *connector, int mode);
Daniel Vetter88548632015-12-04 09:45:48 +0100833
834 /**
835 * @reset:
836 *
837 * Reset connector hardware and software state to off. This function isn't
838 * called by the core directly, only through drm_mode_config_reset().
839 * It's not a helper hook only for historical reasons.
840 *
841 * Atomic drivers can use drm_atomic_helper_connector_reset() to reset
842 * atomic state using this hook.
843 */
Chris Wilsoneb0335562011-01-24 15:11:08 +0000844 void (*reset)(struct drm_connector *connector);
Chris Wilson930a9e22010-09-14 11:07:23 +0100845
Daniel Vetter6fe14ac2015-12-04 09:45:58 +0100846 /**
847 * @detect:
848 *
849 * Check to see if anything is attached to the connector. The parameter
850 * force is set to false whilst polling, true when checking the
851 * connector due to a user request. force can be used by the driver to
852 * avoid expensive, destructive operations during automated probing.
853 *
854 * FIXME:
855 *
856 * Note that this hook is only called by the probe helper. It's not in
857 * the helper library vtable purely for historical reasons. The only DRM
858 * core entry point to probe connector state is @fill_modes.
859 *
860 * RETURNS:
861 *
862 * drm_connector_status indicating the connector's status.
Chris Wilson930a9e22010-09-14 11:07:23 +0100863 */
Chris Wilson7b334fc2010-09-09 23:51:02 +0100864 enum drm_connector_status (*detect)(struct drm_connector *connector,
Chris Wilson930a9e22010-09-14 11:07:23 +0100865 bool force);
Daniel Vetter6fe14ac2015-12-04 09:45:58 +0100866
867 /**
868 * @force:
869 *
870 * This function is called to update internal encoder state when the
871 * connector is forced to a certain state by userspace, either through
872 * the sysfs interfaces or on the kernel cmdline. In that case the
873 * @detect callback isn't called.
874 *
875 * FIXME:
876 *
877 * Note that this hook is only called by the probe helper. It's not in
878 * the helper library vtable purely for historical reasons. The only DRM
879 * core entry point to probe connector state is @fill_modes.
880 */
881 void (*force)(struct drm_connector *connector);
882
883 /**
884 * @fill_modes:
885 *
886 * Entry point for output detection and basic mode validation. The
887 * driver should reprobe the output if needed (e.g. when hotplug
888 * handling is unreliable), add all detected modes to connector->modes
889 * and filter out any the device can't support in any configuration. It
890 * also needs to filter out any modes wider or higher than the
891 * parameters max_width and max_height indicate.
892 *
893 * The drivers must also prune any modes no longer valid from
894 * connector->modes. Furthermore it must update connector->status and
895 * connector->edid. If no EDID has been received for this output
896 * connector->edid must be NULL.
897 *
898 * Drivers using the probe helpers should use
899 * drm_helper_probe_single_connector_modes() or
900 * drm_helper_probe_single_connector_modes_nomerge() to implement this
901 * function.
902 *
903 * RETURNS:
904 *
905 * The number of modes detected and filled into connector->modes.
906 */
Jesse Barnes40a518d2009-01-12 12:05:32 -0800907 int (*fill_modes)(struct drm_connector *connector, uint32_t max_width, uint32_t max_height);
Daniel Vetter88548632015-12-04 09:45:48 +0100908
909 /**
910 * @set_property:
911 *
912 * This is the legacy entry point to update a property attached to the
913 * connector.
914 *
915 * Drivers implementing atomic modeset should use
916 * drm_atomic_helper_connector_set_property() to implement this hook.
917 *
918 * This callback is optional if the driver does not support any legacy
919 * driver-private properties.
920 *
921 * RETURNS:
922 *
923 * 0 on success or a negative error code on failure.
924 */
Dave Airlief453ba02008-11-07 14:05:41 -0800925 int (*set_property)(struct drm_connector *connector, struct drm_property *property,
926 uint64_t val);
Daniel Vetter88548632015-12-04 09:45:48 +0100927
928 /**
929 * @destroy:
930 *
931 * Clean up connector resources. This is called at driver unload time
932 * through drm_mode_config_cleanup(). It can also be called at runtime
933 * when a connector is being hot-unplugged for drivers that support
934 * connector hotplugging (e.g. DisplayPort MST).
935 */
Dave Airlief453ba02008-11-07 14:05:41 -0800936 void (*destroy)(struct drm_connector *connector);
Daniel Vetter144ecb92014-10-27 20:28:44 +0100937
Daniel Vetter88548632015-12-04 09:45:48 +0100938 /**
939 * @atomic_duplicate_state:
940 *
941 * Duplicate the current atomic state for this connector and return it.
942 * The core and helpers gurantee that any atomic state duplicated with
943 * this hook and still owned by the caller (i.e. not transferred to the
944 * driver by calling ->atomic_commit() from struct
945 * &drm_mode_config_funcs) will be cleaned up by calling the
946 * @atomic_destroy_state hook in this structure.
947 *
948 * Atomic drivers which don't subclass struct &drm_connector_state should use
949 * drm_atomic_helper_connector_duplicate_state(). Drivers that subclass the
950 * state structure to extend it with driver-private state should use
951 * __drm_atomic_helper_connector_duplicate_state() to make sure shared state is
952 * duplicated in a consistent fashion across drivers.
953 *
954 * It is an error to call this hook before connector->state has been
955 * initialized correctly.
956 *
957 * NOTE:
958 *
959 * If the duplicate state references refcounted resources this hook must
960 * acquire a reference for each of them. The driver must release these
961 * references again in @atomic_destroy_state.
962 *
963 * RETURNS:
964 *
965 * Duplicated atomic state or NULL when the allocation failed.
966 */
Daniel Vetter144ecb92014-10-27 20:28:44 +0100967 struct drm_connector_state *(*atomic_duplicate_state)(struct drm_connector *connector);
Daniel Vetter88548632015-12-04 09:45:48 +0100968
969 /**
970 * @atomic_destroy_state:
971 *
972 * Destroy a state duplicated with @atomic_duplicate_state and release
973 * or unreference all resources it references
974 */
Daniel Vetter144ecb92014-10-27 20:28:44 +0100975 void (*atomic_destroy_state)(struct drm_connector *connector,
Daniel Vettercc4ceb42014-07-25 21:30:38 +0200976 struct drm_connector_state *state);
Daniel Vetter88548632015-12-04 09:45:48 +0100977
978 /**
979 * @atomic_set_property:
980 *
981 * Decode a driver-private property value and store the decoded value
982 * into the passed-in state structure. Since the atomic core decodes all
983 * standardized properties (even for extensions beyond the core set of
984 * properties which might not be implemented by all drivers) this
985 * requires drivers to subclass the state structure.
986 *
987 * Such driver-private properties should really only be implemented for
988 * truly hardware/vendor specific state. Instead it is preferred to
989 * standardize atomic extension and decode the properties used to expose
990 * such an extension in the core.
991 *
992 * Do not call this function directly, use
993 * drm_atomic_connector_set_property() instead.
994 *
995 * This callback is optional if the driver does not support any
996 * driver-private atomic properties.
997 *
998 * NOTE:
999 *
1000 * This function is called in the state assembly phase of atomic
1001 * modesets, which can be aborted for any reason (including on
1002 * userspace's request to just check whether a configuration would be
1003 * possible). Drivers MUST NOT touch any persistent state (hardware or
1004 * software) or data structures except the passed in @state parameter.
1005 *
1006 * Also since userspace controls in which order properties are set this
1007 * function must not do any input validation (since the state update is
1008 * incomplete and hence likely inconsistent). Instead any such input
1009 * validation must be done in the various atomic_check callbacks.
1010 *
1011 * RETURNS:
1012 *
1013 * 0 if the property has been found, -EINVAL if the property isn't
1014 * implemented by the driver (which shouldn't ever happen, the core only
1015 * asks for properties attached to this connector). No other validation
1016 * is allowed by the driver. The core already checks that the property
1017 * value is within the range (integer, valid enum value, ...) the driver
1018 * set when registering the property.
1019 */
Daniel Vetter144ecb92014-10-27 20:28:44 +01001020 int (*atomic_set_property)(struct drm_connector *connector,
1021 struct drm_connector_state *state,
1022 struct drm_property *property,
1023 uint64_t val);
Daniel Vetter88548632015-12-04 09:45:48 +01001024
1025 /**
1026 * @atomic_get_property:
1027 *
1028 * Reads out the decoded driver-private property. This is used to
Daniel Vetterc6b0ca32015-12-04 09:46:01 +01001029 * implement the GETCONNECTOR IOCTL.
Daniel Vetter88548632015-12-04 09:45:48 +01001030 *
1031 * Do not call this function directly, use
1032 * drm_atomic_connector_get_property() instead.
1033 *
1034 * This callback is optional if the driver does not support any
1035 * driver-private atomic properties.
1036 *
1037 * RETURNS:
1038 *
1039 * 0 on success, -EINVAL if the property isn't implemented by the
1040 * driver (which shouldn't ever happen, the core only asks for
1041 * properties attached to this connector).
1042 */
Rob Clarkac9c9252014-12-18 16:01:47 -05001043 int (*atomic_get_property)(struct drm_connector *connector,
1044 const struct drm_connector_state *state,
1045 struct drm_property *property,
1046 uint64_t *val);
Dave Airlief453ba02008-11-07 14:05:41 -08001047};
1048
Jesse Barnes6c3db922011-11-07 12:03:16 -08001049/**
Daniel Vetter3bf04012014-10-27 16:54:27 +01001050 * struct drm_encoder_funcs - encoder controls
Jesse Barnes6c3db922011-11-07 12:03:16 -08001051 *
1052 * Encoders sit between CRTCs and connectors.
1053 */
Dave Airlief453ba02008-11-07 14:05:41 -08001054struct drm_encoder_funcs {
Daniel Vetter88548632015-12-04 09:45:48 +01001055 /**
1056 * @reset:
1057 *
1058 * Reset encoder hardware and software state to off. This function isn't
1059 * called by the core directly, only through drm_mode_config_reset().
1060 * It's not a helper hook only for historical reasons.
1061 */
Chris Wilsoneb0335562011-01-24 15:11:08 +00001062 void (*reset)(struct drm_encoder *encoder);
Daniel Vetter88548632015-12-04 09:45:48 +01001063
1064 /**
1065 * @destroy:
1066 *
1067 * Clean up encoder resources. This is only called at driver unload time
1068 * through drm_mode_config_cleanup() since an encoder cannot be
1069 * hotplugged in DRM.
1070 */
Dave Airlief453ba02008-11-07 14:05:41 -08001071 void (*destroy)(struct drm_encoder *encoder);
1072};
1073
Ben Skeggsafe887d2012-01-12 16:00:57 +10001074#define DRM_CONNECTOR_MAX_ENCODER 3
Dave Airlief453ba02008-11-07 14:05:41 -08001075
1076/**
Daniel Vetter3bf04012014-10-27 16:54:27 +01001077 * struct drm_encoder - central DRM encoder structure
Jesse Barnesdb3e4492011-11-07 12:03:17 -08001078 * @dev: parent DRM device
1079 * @head: list management
1080 * @base: base KMS object
Jani Nikulae5748942014-05-14 16:58:20 +03001081 * @name: encoder name
Jesse Barnesdb3e4492011-11-07 12:03:17 -08001082 * @encoder_type: one of the %DRM_MODE_ENCODER_<foo> types in drm_mode.h
1083 * @possible_crtcs: bitmask of potential CRTC bindings
1084 * @possible_clones: bitmask of potential sibling encoders for cloning
1085 * @crtc: currently bound CRTC
Sean Paul3b336ec2013-08-14 16:47:37 -04001086 * @bridge: bridge associated to the encoder
Jesse Barnesdb3e4492011-11-07 12:03:17 -08001087 * @funcs: control functions
1088 * @helper_private: mid-layer private data
1089 *
1090 * CRTCs drive pixels to encoders, which convert them into signals
1091 * appropriate for a given connector or set of connectors.
Dave Airlief453ba02008-11-07 14:05:41 -08001092 */
1093struct drm_encoder {
1094 struct drm_device *dev;
1095 struct list_head head;
1096
1097 struct drm_mode_object base;
Jani Nikulae5748942014-05-14 16:58:20 +03001098 char *name;
Dave Airlief453ba02008-11-07 14:05:41 -08001099 int encoder_type;
1100 uint32_t possible_crtcs;
1101 uint32_t possible_clones;
1102
1103 struct drm_crtc *crtc;
Sean Paul3b336ec2013-08-14 16:47:37 -04001104 struct drm_bridge *bridge;
Dave Airlief453ba02008-11-07 14:05:41 -08001105 const struct drm_encoder_funcs *funcs;
Daniel Vetter4490d4c2015-12-04 09:45:45 +01001106 const struct drm_encoder_helper_funcs *helper_private;
Dave Airlief453ba02008-11-07 14:05:41 -08001107};
1108
Dave Airlieeb1f8e4f32010-05-07 06:42:51 +00001109/* should we poll this connector for connects and disconnects */
1110/* hot plug detectable */
1111#define DRM_CONNECTOR_POLL_HPD (1 << 0)
1112/* poll for connections */
1113#define DRM_CONNECTOR_POLL_CONNECT (1 << 1)
1114/* can cleanly poll for disconnections without flickering the screen */
1115/* DACs should rarely do this without a lot of testing */
1116#define DRM_CONNECTOR_POLL_DISCONNECT (1 << 2)
1117
Wu Fengguang76adaa342011-09-05 14:23:20 +08001118#define MAX_ELD_BYTES 128
1119
Dave Airlief453ba02008-11-07 14:05:41 -08001120/**
Daniel Vetter3bf04012014-10-27 16:54:27 +01001121 * struct drm_connector - central DRM connector control structure
Jesse Barnes72252542011-11-07 12:03:18 -08001122 * @dev: parent DRM device
1123 * @kdev: kernel device for sysfs attributes
1124 * @attr: sysfs attributes
1125 * @head: list management
1126 * @base: base KMS object
Jani Nikula2abdd312014-05-14 16:58:19 +03001127 * @name: connector name
Jesse Barnes72252542011-11-07 12:03:18 -08001128 * @connector_type: one of the %DRM_MODE_CONNECTOR_<foo> types from drm_mode.h
1129 * @connector_type_id: index into connector type enum
Dave Airlief453ba02008-11-07 14:05:41 -08001130 * @interlace_allowed: can this connector handle interlaced modes?
1131 * @doublescan_allowed: can this connector handle doublescan?
Daniel Vetter2c0c33d2014-10-27 20:19:38 +01001132 * @stereo_allowed: can this connector handle stereo modes?
Jesse Barnes72252542011-11-07 12:03:18 -08001133 * @modes: modes available on this connector (from fill_modes() + user)
1134 * @status: one of the drm_connector_status enums (connected, not, or unknown)
1135 * @probed_modes: list of modes derived directly from the display
1136 * @display_info: information about attached display (e.g. from EDID)
Dave Airlief453ba02008-11-07 14:05:41 -08001137 * @funcs: connector control functions
Jesse Barnes72252542011-11-07 12:03:18 -08001138 * @edid_blob_ptr: DRM property containing EDID if present
Paulo Zanoni7e3bdf42012-05-15 18:09:01 -03001139 * @properties: property tracking for this connector
Daniel Vetter2c0c33d2014-10-27 20:19:38 +01001140 * @path_blob_ptr: DRM blob property data for the DP MST path property
Jesse Barnes72252542011-11-07 12:03:18 -08001141 * @polled: a %DRM_CONNECTOR_POLL_<foo> value for core driven polling
1142 * @dpms: current dpms state
1143 * @helper_private: mid-layer private data
Daniel Vetter2c0c33d2014-10-27 20:19:38 +01001144 * @cmdline_mode: mode line parsed from the kernel cmdline for this connector
Jesse Barnes72252542011-11-07 12:03:18 -08001145 * @force: a %DRM_FORCE_<foo> state for forced mode sets
Daniel Vetter2c0c33d2014-10-27 20:19:38 +01001146 * @override_edid: has the EDID been overwritten through debugfs for testing?
Jesse Barnes72252542011-11-07 12:03:18 -08001147 * @encoder_ids: valid encoders for this connector
1148 * @encoder: encoder driving this connector, if any
1149 * @eld: EDID-like data, if present
1150 * @dvi_dual: dual link DVI, if found
1151 * @max_tmds_clock: max clock rate, if found
1152 * @latency_present: AV delay info from ELD, if found
1153 * @video_latency: video latency info from ELD, if found
1154 * @audio_latency: audio latency info from ELD, if found
1155 * @null_edid_counter: track sinks that give us all zeros for the EDID
Daniel Vetter2c0c33d2014-10-27 20:19:38 +01001156 * @bad_edid_counter: track sinks that give us an EDID with invalid checksum
Daniel Vetterac6f2e22015-05-08 16:15:41 +02001157 * @edid_corrupt: indicates whether the last read EDID was corrupt
Daniel Vetter2c0c33d2014-10-27 20:19:38 +01001158 * @debugfs_entry: debugfs directory for this connector
Daniel Vetter144ecb92014-10-27 20:28:44 +01001159 * @state: current atomic state for this connector
Dave Airlie40d9b042014-10-20 16:29:33 +10001160 * @has_tile: is this connector connected to a tiled monitor
1161 * @tile_group: tile group for the connected monitor
1162 * @tile_is_single_monitor: whether the tile is one monitor housing
1163 * @num_h_tile: number of horizontal tiles in the tile group
1164 * @num_v_tile: number of vertical tiles in the tile group
1165 * @tile_h_loc: horizontal location of this tile
1166 * @tile_v_loc: vertical location of this tile
1167 * @tile_h_size: horizontal size of this tile.
1168 * @tile_v_size: vertical size of this tile.
Dave Airlief453ba02008-11-07 14:05:41 -08001169 *
1170 * Each connector may be connected to one or more CRTCs, or may be clonable by
1171 * another connector if they can share a CRTC. Each connector also has a specific
1172 * position in the broader display (referred to as a 'screen' though it could
1173 * span multiple monitors).
1174 */
1175struct drm_connector {
1176 struct drm_device *dev;
Dave Airlie5bdebb12013-10-11 14:07:25 +10001177 struct device *kdev;
Dave Airlief453ba02008-11-07 14:05:41 -08001178 struct device_attribute *attr;
1179 struct list_head head;
1180
1181 struct drm_mode_object base;
1182
Jani Nikula2abdd312014-05-14 16:58:19 +03001183 char *name;
Dave Airlief453ba02008-11-07 14:05:41 -08001184 int connector_type;
1185 int connector_type_id;
1186 bool interlace_allowed;
1187 bool doublescan_allowed;
Damien Lespiau560a0672013-09-25 16:45:29 +01001188 bool stereo_allowed;
Dave Airlief453ba02008-11-07 14:05:41 -08001189 struct list_head modes; /* list of modes on this connector */
1190
Dave Airlief453ba02008-11-07 14:05:41 -08001191 enum drm_connector_status status;
1192
1193 /* these are modes added by probing with DDC or the BIOS */
1194 struct list_head probed_modes;
1195
1196 struct drm_display_info display_info;
1197 const struct drm_connector_funcs *funcs;
1198
Dave Airlief453ba02008-11-07 14:05:41 -08001199 struct drm_property_blob *edid_blob_ptr;
Paulo Zanoni7e3bdf42012-05-15 18:09:01 -03001200 struct drm_object_properties properties;
Dave Airlief453ba02008-11-07 14:05:41 -08001201
Dave Airlie43aba7e2014-06-05 14:01:31 +10001202 struct drm_property_blob *path_blob_ptr;
1203
Dave Airlie6f134d72014-10-20 16:30:50 +10001204 struct drm_property_blob *tile_blob_ptr;
1205
Dave Airlieeb1f8e4f32010-05-07 06:42:51 +00001206 uint8_t polled; /* DRM_CONNECTOR_POLL_* */
1207
Keith Packardc9fb15f2009-05-30 20:42:28 -07001208 /* requested DPMS state */
1209 int dpms;
1210
Daniel Vetter4490d4c2015-12-04 09:45:45 +01001211 const struct drm_connector_helper_funcs *helper_private;
Dave Airlief453ba02008-11-07 14:05:41 -08001212
Dave Airlied50ba252009-09-23 14:44:08 +10001213 /* forced on connector */
Chris Wilsoneaf99c72014-08-06 10:08:32 +02001214 struct drm_cmdline_mode cmdline_mode;
Dave Airlied50ba252009-09-23 14:44:08 +10001215 enum drm_connector_force force;
Thomas Wood4cf2b282014-06-18 17:52:33 +01001216 bool override_edid;
Dave Airlief453ba02008-11-07 14:05:41 -08001217 uint32_t encoder_ids[DRM_CONNECTOR_MAX_ENCODER];
Dave Airlief453ba02008-11-07 14:05:41 -08001218 struct drm_encoder *encoder; /* currently active encoder */
Dave Airlie4a9a8b72011-06-14 06:13:55 +00001219
Wu Fengguang76adaa342011-09-05 14:23:20 +08001220 /* EDID bits */
1221 uint8_t eld[MAX_ELD_BYTES];
1222 bool dvi_dual;
1223 int max_tmds_clock; /* in MHz */
1224 bool latency_present[2];
1225 int video_latency[2]; /* [0]: progressive, [1]: interlaced */
1226 int audio_latency[2];
Dave Airlie4a9a8b72011-06-14 06:13:55 +00001227 int null_edid_counter; /* needed to workaround some HW bugs where we get all 0s */
Jerome Glisse0b2443e2012-08-09 11:25:51 -04001228 unsigned bad_edid_counter;
Thomas Wood30f65702014-06-18 17:52:32 +01001229
Todd Previte6ba2bd32015-04-21 11:09:41 -07001230 /* Flag for raw EDID header corruption - used in Displayport
1231 * compliance testing - * Displayport Link CTS Core 1.2 rev1.1 4.2.2.6
1232 */
1233 bool edid_corrupt;
1234
Thomas Wood30f65702014-06-18 17:52:32 +01001235 struct dentry *debugfs_entry;
Daniel Vetter144ecb92014-10-27 20:28:44 +01001236
1237 struct drm_connector_state *state;
Dave Airlie40d9b042014-10-20 16:29:33 +10001238
1239 /* DisplayID bits */
1240 bool has_tile;
1241 struct drm_tile_group *tile_group;
1242 bool tile_is_single_monitor;
1243
1244 uint8_t num_h_tile, num_v_tile;
1245 uint8_t tile_h_loc, tile_v_loc;
1246 uint16_t tile_h_size, tile_v_size;
Dave Airlief453ba02008-11-07 14:05:41 -08001247};
1248
1249/**
Daniel Vetter144ecb92014-10-27 20:28:44 +01001250 * struct drm_plane_state - mutable plane state
Daniel Vetter07cc0ef2014-11-27 15:49:39 +01001251 * @plane: backpointer to the plane
Daniel Vetter144ecb92014-10-27 20:28:44 +01001252 * @crtc: currently bound CRTC, NULL if disabled
Daniel Vettercc4ceb42014-07-25 21:30:38 +02001253 * @fb: currently bound framebuffer
Daniel Vettere2330f02014-10-29 11:34:56 +01001254 * @fence: optional fence to wait for before scanning out @fb
Daniel Vetter144ecb92014-10-27 20:28:44 +01001255 * @crtc_x: left position of visible portion of plane on crtc
1256 * @crtc_y: upper position of visible portion of plane on crtc
1257 * @crtc_w: width of visible portion of plane on crtc
1258 * @crtc_h: height of visible portion of plane on crtc
1259 * @src_x: left position of visible portion of plane within
1260 * plane (in 16.16)
1261 * @src_y: upper position of visible portion of plane within
1262 * plane (in 16.16)
1263 * @src_w: width of visible portion of plane (in 16.16)
1264 * @src_h: height of visible portion of plane (in 16.16)
1265 * @state: backpointer to global drm_atomic_state
1266 */
1267struct drm_plane_state {
Daniel Vetter07cc0ef2014-11-27 15:49:39 +01001268 struct drm_plane *plane;
1269
Rob Clark6ddd3882014-11-21 15:28:31 -05001270 struct drm_crtc *crtc; /* do not write directly, use drm_atomic_set_crtc_for_plane() */
1271 struct drm_framebuffer *fb; /* do not write directly, use drm_atomic_set_fb_for_plane() */
Daniel Vettere2330f02014-10-29 11:34:56 +01001272 struct fence *fence;
Daniel Vetter144ecb92014-10-27 20:28:44 +01001273
1274 /* Signed dest location allows it to be partially off screen */
1275 int32_t crtc_x, crtc_y;
1276 uint32_t crtc_w, crtc_h;
1277
1278 /* Source values are 16.16 fixed point */
1279 uint32_t src_x, src_y;
1280 uint32_t src_h, src_w;
1281
Matt Roper1da30622015-01-21 16:35:40 -08001282 /* Plane rotation */
1283 unsigned int rotation;
1284
Daniel Vetter144ecb92014-10-27 20:28:44 +01001285 struct drm_atomic_state *state;
1286};
1287
1288
1289/**
Daniel Vetter3bf04012014-10-27 16:54:27 +01001290 * struct drm_plane_funcs - driver plane control functions
Jesse Barnes8cf5c912011-11-14 14:51:27 -08001291 */
1292struct drm_plane_funcs {
Daniel Vetter88548632015-12-04 09:45:48 +01001293 /**
1294 * @update_plane:
1295 *
1296 * This is the legacy entry point to enable and configure the plane for
1297 * the given CRTC and framebuffer. It is never called to disable the
1298 * plane, i.e. the passed-in crtc and fb paramters are never NULL.
1299 *
1300 * The source rectangle in frame buffer memory coordinates is given by
1301 * the src_x, src_y, src_w and src_h parameters (as 16.16 fixed point
1302 * values). Devices that don't support subpixel plane coordinates can
1303 * ignore the fractional part.
1304 *
1305 * The destination rectangle in CRTC coordinates is given by the
1306 * crtc_x, crtc_y, crtc_w and crtc_h parameters (as integer values).
1307 * Devices scale the source rectangle to the destination rectangle. If
1308 * scaling is not supported, and the source rectangle size doesn't match
1309 * the destination rectangle size, the driver must return a
1310 * -<errorname>EINVAL</errorname> error.
1311 *
1312 * Drivers implementing atomic modeset should use
1313 * drm_atomic_helper_update_plane() to implement this hook.
1314 *
1315 * RETURNS:
1316 *
1317 * 0 on success or a negative error code on failure.
1318 */
Jesse Barnes8cf5c912011-11-14 14:51:27 -08001319 int (*update_plane)(struct drm_plane *plane,
1320 struct drm_crtc *crtc, struct drm_framebuffer *fb,
1321 int crtc_x, int crtc_y,
1322 unsigned int crtc_w, unsigned int crtc_h,
1323 uint32_t src_x, uint32_t src_y,
1324 uint32_t src_w, uint32_t src_h);
Daniel Vetter88548632015-12-04 09:45:48 +01001325
1326 /**
1327 * @disable_plane:
1328 *
1329 * This is the legacy entry point to disable the plane. The DRM core
Daniel Vetterc6b0ca32015-12-04 09:46:01 +01001330 * calls this method in response to a DRM_IOCTL_MODE_SETPLANE IOCTL call
Daniel Vetter88548632015-12-04 09:45:48 +01001331 * with the frame buffer ID set to 0. Disabled planes must not be
1332 * processed by the CRTC.
1333 *
1334 * Drivers implementing atomic modeset should use
1335 * drm_atomic_helper_disable_plane() to implement this hook.
1336 *
1337 * RETURNS:
1338 *
1339 * 0 on success or a negative error code on failure.
1340 */
Jesse Barnes8cf5c912011-11-14 14:51:27 -08001341 int (*disable_plane)(struct drm_plane *plane);
Daniel Vetter88548632015-12-04 09:45:48 +01001342
1343 /**
1344 * @destroy:
1345 *
1346 * Clean up plane resources. This is only called at driver unload time
1347 * through drm_mode_config_cleanup() since a plane cannot be hotplugged
1348 * in DRM.
1349 */
Jesse Barnes8cf5c912011-11-14 14:51:27 -08001350 void (*destroy)(struct drm_plane *plane);
Daniel Vetter88548632015-12-04 09:45:48 +01001351
1352 /**
1353 * @reset:
1354 *
1355 * Reset plane hardware and software state to off. This function isn't
1356 * called by the core directly, only through drm_mode_config_reset().
1357 * It's not a helper hook only for historical reasons.
1358 *
1359 * Atomic drivers can use drm_atomic_helper_plane_reset() to reset
1360 * atomic state using this hook.
1361 */
Daniel Vetter2a0d7cf2014-07-29 15:32:37 +02001362 void (*reset)(struct drm_plane *plane);
Rob Clark4d939142012-05-17 02:23:27 -06001363
Daniel Vetter88548632015-12-04 09:45:48 +01001364 /**
1365 * @set_property:
1366 *
1367 * This is the legacy entry point to update a property attached to the
1368 * plane.
1369 *
1370 * Drivers implementing atomic modeset should use
1371 * drm_atomic_helper_plane_set_property() to implement this hook.
1372 *
1373 * This callback is optional if the driver does not support any legacy
1374 * driver-private properties.
1375 *
1376 * RETURNS:
1377 *
1378 * 0 on success or a negative error code on failure.
1379 */
Rob Clark4d939142012-05-17 02:23:27 -06001380 int (*set_property)(struct drm_plane *plane,
1381 struct drm_property *property, uint64_t val);
Daniel Vetter144ecb92014-10-27 20:28:44 +01001382
Daniel Vetter88548632015-12-04 09:45:48 +01001383 /**
1384 * @atomic_duplicate_state:
1385 *
1386 * Duplicate the current atomic state for this plane and return it.
1387 * The core and helpers gurantee that any atomic state duplicated with
1388 * this hook and still owned by the caller (i.e. not transferred to the
1389 * driver by calling ->atomic_commit() from struct
1390 * &drm_mode_config_funcs) will be cleaned up by calling the
1391 * @atomic_destroy_state hook in this structure.
1392 *
1393 * Atomic drivers which don't subclass struct &drm_plane_state should use
1394 * drm_atomic_helper_plane_duplicate_state(). Drivers that subclass the
1395 * state structure to extend it with driver-private state should use
1396 * __drm_atomic_helper_plane_duplicate_state() to make sure shared state is
1397 * duplicated in a consistent fashion across drivers.
1398 *
1399 * It is an error to call this hook before plane->state has been
1400 * initialized correctly.
1401 *
1402 * NOTE:
1403 *
1404 * If the duplicate state references refcounted resources this hook must
1405 * acquire a reference for each of them. The driver must release these
1406 * references again in @atomic_destroy_state.
1407 *
1408 * RETURNS:
1409 *
1410 * Duplicated atomic state or NULL when the allocation failed.
1411 */
Daniel Vetter144ecb92014-10-27 20:28:44 +01001412 struct drm_plane_state *(*atomic_duplicate_state)(struct drm_plane *plane);
Daniel Vetter88548632015-12-04 09:45:48 +01001413
1414 /**
1415 * @atomic_destroy_state:
1416 *
1417 * Destroy a state duplicated with @atomic_duplicate_state and release
1418 * or unreference all resources it references
1419 */
Daniel Vetter144ecb92014-10-27 20:28:44 +01001420 void (*atomic_destroy_state)(struct drm_plane *plane,
Daniel Vettercc4ceb42014-07-25 21:30:38 +02001421 struct drm_plane_state *state);
Daniel Vetter88548632015-12-04 09:45:48 +01001422
1423 /**
1424 * @atomic_set_property:
1425 *
1426 * Decode a driver-private property value and store the decoded value
1427 * into the passed-in state structure. Since the atomic core decodes all
1428 * standardized properties (even for extensions beyond the core set of
1429 * properties which might not be implemented by all drivers) this
1430 * requires drivers to subclass the state structure.
1431 *
1432 * Such driver-private properties should really only be implemented for
1433 * truly hardware/vendor specific state. Instead it is preferred to
1434 * standardize atomic extension and decode the properties used to expose
1435 * such an extension in the core.
1436 *
1437 * Do not call this function directly, use
1438 * drm_atomic_plane_set_property() instead.
1439 *
1440 * This callback is optional if the driver does not support any
1441 * driver-private atomic properties.
1442 *
1443 * NOTE:
1444 *
1445 * This function is called in the state assembly phase of atomic
1446 * modesets, which can be aborted for any reason (including on
1447 * userspace's request to just check whether a configuration would be
1448 * possible). Drivers MUST NOT touch any persistent state (hardware or
1449 * software) or data structures except the passed in @state parameter.
1450 *
1451 * Also since userspace controls in which order properties are set this
1452 * function must not do any input validation (since the state update is
1453 * incomplete and hence likely inconsistent). Instead any such input
1454 * validation must be done in the various atomic_check callbacks.
1455 *
1456 * RETURNS:
1457 *
1458 * 0 if the property has been found, -EINVAL if the property isn't
1459 * implemented by the driver (which shouldn't ever happen, the core only
1460 * asks for properties attached to this plane). No other validation is
1461 * allowed by the driver. The core already checks that the property
1462 * value is within the range (integer, valid enum value, ...) the driver
1463 * set when registering the property.
1464 */
Daniel Vetter144ecb92014-10-27 20:28:44 +01001465 int (*atomic_set_property)(struct drm_plane *plane,
1466 struct drm_plane_state *state,
1467 struct drm_property *property,
1468 uint64_t val);
Daniel Vetter88548632015-12-04 09:45:48 +01001469
1470 /**
1471 * @atomic_get_property:
1472 *
1473 * Reads out the decoded driver-private property. This is used to
Daniel Vetterc6b0ca32015-12-04 09:46:01 +01001474 * implement the GETPLANE IOCTL.
Daniel Vetter88548632015-12-04 09:45:48 +01001475 *
1476 * Do not call this function directly, use
1477 * drm_atomic_plane_get_property() instead.
1478 *
1479 * This callback is optional if the driver does not support any
1480 * driver-private atomic properties.
1481 *
1482 * RETURNS:
1483 *
1484 * 0 on success, -EINVAL if the property isn't implemented by the
1485 * driver (which should never happen, the core only asks for
1486 * properties attached to this plane).
1487 */
Rob Clarkac9c9252014-12-18 16:01:47 -05001488 int (*atomic_get_property)(struct drm_plane *plane,
1489 const struct drm_plane_state *state,
1490 struct drm_property *property,
1491 uint64_t *val);
Jesse Barnes8cf5c912011-11-14 14:51:27 -08001492};
1493
Matt Ropere27dde32014-04-01 15:22:30 -07001494enum drm_plane_type {
1495 DRM_PLANE_TYPE_OVERLAY,
1496 DRM_PLANE_TYPE_PRIMARY,
1497 DRM_PLANE_TYPE_CURSOR,
1498};
1499
Daniel Vetter88548632015-12-04 09:45:48 +01001500
Jesse Barnes8cf5c912011-11-14 14:51:27 -08001501/**
Daniel Vetter3bf04012014-10-27 16:54:27 +01001502 * struct drm_plane - central DRM plane control structure
Jesse Barnes8cf5c912011-11-14 14:51:27 -08001503 * @dev: DRM device this plane belongs to
1504 * @head: for list management
1505 * @base: base mode object
1506 * @possible_crtcs: pipes this plane can be bound to
1507 * @format_types: array of formats supported by this plane
1508 * @format_count: number of formats supported
Laurent Pinchart7eb5f302015-03-09 10:41:07 +02001509 * @format_default: driver hasn't supplied supported formats for the plane
Jesse Barnes8cf5c912011-11-14 14:51:27 -08001510 * @crtc: currently bound CRTC
1511 * @fb: currently bound fb
Daniel Vetter2c0c33d2014-10-27 20:19:38 +01001512 * @old_fb: Temporary tracking of the old fb while a modeset is ongoing. Used by
1513 * drm_mode_set_config_internal() to implement correct refcounting.
Jesse Barnes8cf5c912011-11-14 14:51:27 -08001514 * @funcs: helper functions
Rob Clark4d939142012-05-17 02:23:27 -06001515 * @properties: property tracking for this plane
Matt Ropere27dde32014-04-01 15:22:30 -07001516 * @type: type of plane (overlay, primary, cursor)
Daniel Vetter144ecb92014-10-27 20:28:44 +01001517 * @state: current atomic state for this plane
Jesse Barnes8cf5c912011-11-14 14:51:27 -08001518 */
1519struct drm_plane {
1520 struct drm_device *dev;
1521 struct list_head head;
1522
Ville Syrjälä9f4c97a2015-12-08 18:41:54 +02001523 char *name;
1524
Daniel Vetter4d02e2d2014-11-11 10:12:00 +01001525 struct drm_modeset_lock mutex;
1526
Jesse Barnes8cf5c912011-11-14 14:51:27 -08001527 struct drm_mode_object base;
1528
1529 uint32_t possible_crtcs;
1530 uint32_t *format_types;
Thierry Reding45e37432015-08-12 16:54:28 +02001531 unsigned int format_count;
Laurent Pinchart7eb5f302015-03-09 10:41:07 +02001532 bool format_default;
Jesse Barnes8cf5c912011-11-14 14:51:27 -08001533
1534 struct drm_crtc *crtc;
1535 struct drm_framebuffer *fb;
1536
Daniel Vetter3d30a592014-07-27 13:42:42 +02001537 struct drm_framebuffer *old_fb;
1538
Jesse Barnes8cf5c912011-11-14 14:51:27 -08001539 const struct drm_plane_funcs *funcs;
Rob Clark4d939142012-05-17 02:23:27 -06001540
1541 struct drm_object_properties properties;
Matt Ropere27dde32014-04-01 15:22:30 -07001542
1543 enum drm_plane_type type;
Daniel Vetter144ecb92014-10-27 20:28:44 +01001544
Daniel Vetter4490d4c2015-12-04 09:45:45 +01001545 const struct drm_plane_helper_funcs *helper_private;
Daniel Vetterc2fcd272014-11-05 00:14:14 +01001546
Daniel Vetter144ecb92014-10-27 20:28:44 +01001547 struct drm_plane_state *state;
Jesse Barnes8cf5c912011-11-14 14:51:27 -08001548};
1549
1550/**
Daniel Vetter3bf04012014-10-27 16:54:27 +01001551 * struct drm_bridge_funcs - drm_bridge control functions
Ajay Kumar3d3f8b12015-01-20 22:08:44 +05301552 * @attach: Called during drm_bridge_attach
Sean Paul3b336ec2013-08-14 16:47:37 -04001553 */
1554struct drm_bridge_funcs {
Ajay Kumar3d3f8b12015-01-20 22:08:44 +05301555 int (*attach)(struct drm_bridge *bridge);
Daniel Vetterda024fe2015-12-04 09:45:47 +01001556
1557 /**
1558 * @mode_fixup:
1559 *
1560 * This callback is used to validate and adjust a mode. The paramater
1561 * mode is the display mode that should be fed to the next element in
1562 * the display chain, either the final &drm_connector or the next
1563 * &drm_bridge. The parameter adjusted_mode is the input mode the bridge
1564 * requires. It can be modified by this callback and does not need to
1565 * match mode.
1566 *
1567 * This is the only hook that allows a bridge to reject a modeset. If
1568 * this function passes all other callbacks must succeed for this
1569 * configuration.
1570 *
1571 * NOTE:
1572 *
1573 * This function is called in the check phase of atomic modesets, which
1574 * can be aborted for any reason (including on userspace's request to
1575 * just check whether a configuration would be possible). Drivers MUST
1576 * NOT touch any persistent state (hardware or software) or data
Daniel Vetter88548632015-12-04 09:45:48 +01001577 * structures except the passed in @state parameter.
Daniel Vetterda024fe2015-12-04 09:45:47 +01001578 *
1579 * RETURNS:
1580 *
1581 * True if an acceptable configuration is possible, false if the modeset
1582 * operation should be rejected.
1583 */
Sean Paul3b336ec2013-08-14 16:47:37 -04001584 bool (*mode_fixup)(struct drm_bridge *bridge,
1585 const struct drm_display_mode *mode,
1586 struct drm_display_mode *adjusted_mode);
Daniel Vetterda024fe2015-12-04 09:45:47 +01001587 /**
1588 * @disable:
1589 *
1590 * This callback should disable the bridge. It is called right before
1591 * the preceding element in the display pipe is disabled. If the
1592 * preceding element is a bridge this means it's called before that
1593 * bridge's ->disable() function. If the preceding element is a
1594 * &drm_encoder it's called right before the encoder's ->disable(),
1595 * ->prepare() or ->dpms() hook from struct &drm_encoder_helper_funcs.
1596 *
1597 * The bridge can assume that the display pipe (i.e. clocks and timing
1598 * signals) feeding it is still running when this callback is called.
1599 */
Sean Paul3b336ec2013-08-14 16:47:37 -04001600 void (*disable)(struct drm_bridge *bridge);
Daniel Vetterda024fe2015-12-04 09:45:47 +01001601
1602 /**
1603 * @post_disable:
1604 *
1605 * This callback should disable the bridge. It is called right after
1606 * the preceding element in the display pipe is disabled. If the
1607 * preceding element is a bridge this means it's called after that
1608 * bridge's ->post_disable() function. If the preceding element is a
1609 * &drm_encoder it's called right after the encoder's ->disable(),
1610 * ->prepare() or ->dpms() hook from struct &drm_encoder_helper_funcs.
1611 *
1612 * The bridge must assume that the display pipe (i.e. clocks and timing
1613 * singals) feeding it is no longer running when this callback is
1614 * called.
1615 */
Sean Paul3b336ec2013-08-14 16:47:37 -04001616 void (*post_disable)(struct drm_bridge *bridge);
Daniel Vetterda024fe2015-12-04 09:45:47 +01001617
1618 /**
1619 * @mode_set:
1620 *
1621 * This callback should set the given mode on the bridge. It is called
1622 * after the ->mode_set() callback for the preceding element in the
1623 * display pipeline has been called already. The display pipe (i.e.
1624 * clocks and timing signals) is off when this function is called.
1625 */
Sean Paul3b336ec2013-08-14 16:47:37 -04001626 void (*mode_set)(struct drm_bridge *bridge,
1627 struct drm_display_mode *mode,
1628 struct drm_display_mode *adjusted_mode);
Daniel Vetterda024fe2015-12-04 09:45:47 +01001629 /**
1630 * @pre_enable:
1631 *
1632 * This callback should enable the bridge. It is called right before
1633 * the preceding element in the display pipe is enabled. If the
1634 * preceding element is a bridge this means it's called before that
1635 * bridge's ->pre_enable() function. If the preceding element is a
1636 * &drm_encoder it's called right before the encoder's ->enable(),
1637 * ->commit() or ->dpms() hook from struct &drm_encoder_helper_funcs.
1638 *
1639 * The display pipe (i.e. clocks and timing signals) feeding this bridge
1640 * will not yet be running when this callback is called. The bridge must
1641 * not enable the display link feeding the next bridge in the chain (if
1642 * there is one) when this callback is called.
1643 */
Sean Paul3b336ec2013-08-14 16:47:37 -04001644 void (*pre_enable)(struct drm_bridge *bridge);
Daniel Vetterda024fe2015-12-04 09:45:47 +01001645
1646 /**
1647 * @enable:
1648 *
1649 * This callback should enable the bridge. It is called right after
1650 * the preceding element in the display pipe is enabled. If the
1651 * preceding element is a bridge this means it's called after that
1652 * bridge's ->enable() function. If the preceding element is a
1653 * &drm_encoder it's called right after the encoder's ->enable(),
1654 * ->commit() or ->dpms() hook from struct &drm_encoder_helper_funcs.
1655 *
1656 * The bridge can assume that the display pipe (i.e. clocks and timing
1657 * signals) feeding it is running when this callback is called. This
1658 * callback must enable the display link feeding the next bridge in the
1659 * chain if there is one.
1660 */
Sean Paul3b336ec2013-08-14 16:47:37 -04001661 void (*enable)(struct drm_bridge *bridge);
Sean Paul3b336ec2013-08-14 16:47:37 -04001662};
1663
1664/**
Daniel Vetter3bf04012014-10-27 16:54:27 +01001665 * struct drm_bridge - central DRM bridge control structure
Sean Paul3b336ec2013-08-14 16:47:37 -04001666 * @dev: DRM device this bridge belongs to
Archit Taneja862e6862015-05-21 11:03:16 +05301667 * @encoder: encoder to which this bridge is connected
1668 * @next: the next bridge in the encoder chain
Ajay Kumar3d3f8b12015-01-20 22:08:44 +05301669 * @of_node: device node pointer to the bridge
1670 * @list: to keep track of all added bridges
Sean Paul3b336ec2013-08-14 16:47:37 -04001671 * @funcs: control functions
1672 * @driver_private: pointer to the bridge driver's internal context
1673 */
1674struct drm_bridge {
1675 struct drm_device *dev;
Ajay Kumar3d3f8b12015-01-20 22:08:44 +05301676 struct drm_encoder *encoder;
Archit Taneja862e6862015-05-21 11:03:16 +05301677 struct drm_bridge *next;
Ajay Kumar3d3f8b12015-01-20 22:08:44 +05301678#ifdef CONFIG_OF
1679 struct device_node *of_node;
1680#endif
1681 struct list_head list;
Sean Paul3b336ec2013-08-14 16:47:37 -04001682
1683 const struct drm_bridge_funcs *funcs;
1684 void *driver_private;
1685};
1686
1687/**
Rob Clark08855fa2015-03-11 10:23:09 -04001688 * struct drm_atomic_state - the global state object for atomic updates
Daniel Vettercc4ceb42014-07-25 21:30:38 +02001689 * @dev: parent DRM device
Rob Clarkd34f20d2014-12-18 16:01:56 -05001690 * @allow_modeset: allow full modeset
Daniel Vetterc6b0ca32015-12-04 09:46:01 +01001691 * @legacy_cursor_update: hint to enforce legacy cursor IOCTL semantics
Maarten Lankhorst40616a22016-03-03 10:17:39 +01001692 * @legacy_set_config: Disable conflicting encoders instead of failing with -EINVAL.
Daniel Vettercc4ceb42014-07-25 21:30:38 +02001693 * @planes: pointer to array of plane pointers
1694 * @plane_states: pointer to array of plane states pointers
1695 * @crtcs: pointer to array of CRTC pointers
1696 * @crtc_states: pointer to array of CRTC states pointers
Daniel Vetterf52b69f12014-11-19 18:38:08 +01001697 * @num_connector: size of the @connectors and @connector_states arrays
Daniel Vettercc4ceb42014-07-25 21:30:38 +02001698 * @connectors: pointer to array of connector pointers
1699 * @connector_states: pointer to array of connector states pointers
1700 * @acquire_ctx: acquire context for this atomic modeset state update
1701 */
1702struct drm_atomic_state {
1703 struct drm_device *dev;
Rob Clarkd34f20d2014-12-18 16:01:56 -05001704 bool allow_modeset : 1;
Daniel Vetterf02ad902015-01-22 16:36:23 +01001705 bool legacy_cursor_update : 1;
Maarten Lankhorst40616a22016-03-03 10:17:39 +01001706 bool legacy_set_config : 1;
Daniel Vettercc4ceb42014-07-25 21:30:38 +02001707 struct drm_plane **planes;
1708 struct drm_plane_state **plane_states;
1709 struct drm_crtc **crtcs;
1710 struct drm_crtc_state **crtc_states;
Daniel Vetterf52b69f12014-11-19 18:38:08 +01001711 int num_connector;
Daniel Vettercc4ceb42014-07-25 21:30:38 +02001712 struct drm_connector **connectors;
1713 struct drm_connector_state **connector_states;
1714
1715 struct drm_modeset_acquire_ctx *acquire_ctx;
1716};
1717
1718
1719/**
Daniel Vetter3bf04012014-10-27 16:54:27 +01001720 * struct drm_mode_set - new values for a CRTC config change
Jesse Barnesef273512011-11-07 12:03:19 -08001721 * @fb: framebuffer to use for new config
1722 * @crtc: CRTC whose configuration we're about to change
1723 * @mode: mode timings to use
1724 * @x: position of this CRTC relative to @fb
1725 * @y: position of this CRTC relative to @fb
1726 * @connectors: array of connectors to drive with this CRTC if possible
1727 * @num_connectors: size of @connectors array
Dave Airlief453ba02008-11-07 14:05:41 -08001728 *
1729 * Represents a single crtc the connectors that it drives with what mode
1730 * and from which framebuffer it scans out from.
1731 *
1732 * This is used to set modes.
1733 */
1734struct drm_mode_set {
Dave Airlief453ba02008-11-07 14:05:41 -08001735 struct drm_framebuffer *fb;
1736 struct drm_crtc *crtc;
1737 struct drm_display_mode *mode;
1738
1739 uint32_t x;
1740 uint32_t y;
1741
1742 struct drm_connector **connectors;
1743 size_t num_connectors;
1744};
1745
1746/**
Jesse Barnes550cebc2011-11-07 12:03:20 -08001747 * struct drm_mode_config_funcs - basic driver provided mode setting functions
Jesse Barnes550cebc2011-11-07 12:03:20 -08001748 *
1749 * Some global (i.e. not per-CRTC, connector, etc) mode setting functions that
1750 * involve drivers.
Dave Airlief453ba02008-11-07 14:05:41 -08001751 */
1752struct drm_mode_config_funcs {
Daniel Vetter9953f412015-12-04 09:46:02 +01001753 /**
1754 * @fb_create:
1755 *
1756 * Create a new framebuffer object. The core does basic checks on the
1757 * requested metadata, but most of that is left to the driver. See
1758 * struct &drm_mode_fb_cmd2 for details.
1759 *
Daniel Vetterd55f5322015-12-08 09:49:19 +01001760 * If the parameters are deemed valid and the backing storage objects in
1761 * the underlying memory manager all exist, then the driver allocates
1762 * a new &drm_framebuffer structure, subclassed to contain
1763 * driver-specific information (like the internal native buffer object
1764 * references). It also needs to fill out all relevant metadata, which
1765 * should be done by calling drm_helper_mode_fill_fb_struct().
1766 *
1767 * The initialization is finalized by calling drm_framebuffer_init(),
1768 * which registers the framebuffer and makes it accessible to other
1769 * threads.
1770 *
Daniel Vetter9953f412015-12-04 09:46:02 +01001771 * RETURNS:
1772 *
1773 * A new framebuffer with an initial reference count of 1 or a negative
1774 * error code encoded with ERR_PTR().
1775 */
Jesse Barnes550cebc2011-11-07 12:03:20 -08001776 struct drm_framebuffer *(*fb_create)(struct drm_device *dev,
1777 struct drm_file *file_priv,
Ville Syrjälä1eb834512015-11-11 19:11:29 +02001778 const struct drm_mode_fb_cmd2 *mode_cmd);
Daniel Vetter9953f412015-12-04 09:46:02 +01001779
1780 /**
1781 * @output_poll_changed:
1782 *
1783 * Callback used by helpers to inform the driver of output configuration
1784 * changes.
1785 *
1786 * Drivers implementing fbdev emulation with the helpers can call
1787 * drm_fb_helper_hotplug_changed from this hook to inform the fbdev
1788 * helper of output changes.
1789 *
1790 * FIXME:
1791 *
1792 * Except that there's no vtable for device-level helper callbacks
1793 * there's no reason this is a core function.
1794 */
Dave Airlieeb1f8e4f32010-05-07 06:42:51 +00001795 void (*output_poll_changed)(struct drm_device *dev);
Daniel Vettercc4ceb42014-07-25 21:30:38 +02001796
Daniel Vetter9953f412015-12-04 09:46:02 +01001797 /**
1798 * @atomic_check:
1799 *
1800 * This is the only hook to validate an atomic modeset update. This
1801 * function must reject any modeset and state changes which the hardware
1802 * or driver doesn't support. This includes but is of course not limited
1803 * to:
1804 *
1805 * - Checking that the modes, framebuffers, scaling and placement
1806 * requirements and so on are within the limits of the hardware.
1807 *
1808 * - Checking that any hidden shared resources are not oversubscribed.
1809 * This can be shared PLLs, shared lanes, overall memory bandwidth,
1810 * display fifo space (where shared between planes or maybe even
1811 * CRTCs).
1812 *
1813 * - Checking that virtualized resources exported to userspace are not
1814 * oversubscribed. For various reasons it can make sense to expose
1815 * more planes, crtcs or encoders than which are physically there. One
1816 * example is dual-pipe operations (which generally should be hidden
1817 * from userspace if when lockstepped in hardware, exposed otherwise),
1818 * where a plane might need 1 hardware plane (if it's just on one
1819 * pipe), 2 hardware planes (when it spans both pipes) or maybe even
1820 * shared a hardware plane with a 2nd plane (if there's a compatible
1821 * plane requested on the area handled by the other pipe).
1822 *
1823 * - Check that any transitional state is possible and that if
1824 * requested, the update can indeed be done in the vblank period
1825 * without temporarily disabling some functions.
1826 *
1827 * - Check any other constraints the driver or hardware might have.
1828 *
1829 * - This callback also needs to correctly fill out the &drm_crtc_state
1830 * in this update to make sure that drm_atomic_crtc_needs_modeset()
1831 * reflects the nature of the possible update and returns true if and
1832 * only if the update cannot be applied without tearing within one
1833 * vblank on that CRTC. The core uses that information to reject
1834 * updates which require a full modeset (i.e. blanking the screen, or
1835 * at least pausing updates for a substantial amount of time) if
1836 * userspace has disallowed that in its request.
1837 *
1838 * - The driver also does not need to repeat basic input validation
1839 * like done for the corresponding legacy entry points. The core does
1840 * that before calling this hook.
1841 *
1842 * See the documentation of @atomic_commit for an exhaustive list of
1843 * error conditions which don't have to be checked at the
1844 * ->atomic_check() stage?
1845 *
1846 * See the documentation for struct &drm_atomic_state for how exactly
1847 * an atomic modeset update is described.
1848 *
1849 * Drivers using the atomic helpers can implement this hook using
1850 * drm_atomic_helper_check(), or one of the exported sub-functions of
1851 * it.
1852 *
1853 * RETURNS:
1854 *
1855 * 0 on success or one of the below negative error codes:
1856 *
1857 * - -EINVAL, if any of the above constraints are violated.
1858 *
1859 * - -EDEADLK, when returned from an attempt to acquire an additional
1860 * &drm_modeset_lock through drm_modeset_lock().
1861 *
1862 * - -ENOMEM, if allocating additional state sub-structures failed due
1863 * to lack of memory.
1864 *
1865 * - -EINTR, -EAGAIN or -ERESTARTSYS, if the IOCTL should be restarted.
1866 * This can either be due to a pending signal, or because the driver
1867 * needs to completely bail out to recover from an exceptional
1868 * situation like a GPU hang. From a userspace point all errors are
1869 * treated equally.
1870 */
Daniel Vettercc4ceb42014-07-25 21:30:38 +02001871 int (*atomic_check)(struct drm_device *dev,
Daniel Vetter9953f412015-12-04 09:46:02 +01001872 struct drm_atomic_state *state);
1873
1874 /**
1875 * @atomic_commit:
1876 *
1877 * This is the only hook to commit an atomic modeset update. The core
1878 * guarantees that @atomic_check has been called successfully before
1879 * calling this function, and that nothing has been changed in the
1880 * interim.
1881 *
1882 * See the documentation for struct &drm_atomic_state for how exactly
1883 * an atomic modeset update is described.
1884 *
1885 * Drivers using the atomic helpers can implement this hook using
1886 * drm_atomic_helper_commit(), or one of the exported sub-functions of
1887 * it.
1888 *
1889 * Asynchronous commits (as indicated with the async parameter) must
1890 * do any preparatory work which might result in an unsuccessful commit
1891 * in the context of this callback. The only exceptions are hardware
1892 * errors resulting in -EIO. But even in that case the driver must
1893 * ensure that the display pipe is at least running, to avoid
1894 * compositors crashing when pageflips don't work. Anything else,
1895 * specifically committing the update to the hardware, should be done
1896 * without blocking the caller. For updates which do not require a
1897 * modeset this must be guaranteed.
1898 *
1899 * The driver must wait for any pending rendering to the new
1900 * framebuffers to complete before executing the flip. It should also
1901 * wait for any pending rendering from other drivers if the underlying
1902 * buffer is a shared dma-buf. Asynchronous commits must not wait for
1903 * rendering in the context of this callback.
1904 *
1905 * An application can request to be notified when the atomic commit has
1906 * completed. These events are per-CRTC and can be distinguished by the
1907 * CRTC index supplied in &drm_event to userspace.
1908 *
1909 * The drm core will supply a struct &drm_event in the event
1910 * member of each CRTC's &drm_crtc_state structure. This can be handled by the
1911 * drm_crtc_send_vblank_event() function, which the driver should call on
1912 * the provided event upon completion of the atomic commit. Note that if
1913 * the driver supports vblank signalling and timestamping the vblank
1914 * counters and timestamps must agree with the ones returned from page
1915 * flip events. With the current vblank helper infrastructure this can
1916 * be achieved by holding a vblank reference while the page flip is
1917 * pending, acquired through drm_crtc_vblank_get() and released with
1918 * drm_crtc_vblank_put(). Drivers are free to implement their own vblank
1919 * counter and timestamp tracking though, e.g. if they have accurate
1920 * timestamp registers in hardware.
1921 *
1922 * NOTE:
1923 *
1924 * Drivers are not allowed to shut down any display pipe successfully
1925 * enabled through an atomic commit on their own. Doing so can result in
1926 * compositors crashing if a page flip is suddenly rejected because the
1927 * pipe is off.
1928 *
1929 * RETURNS:
1930 *
1931 * 0 on success or one of the below negative error codes:
1932 *
1933 * - -EBUSY, if an asynchronous updated is requested and there is
1934 * an earlier updated pending. Drivers are allowed to support a queue
1935 * of outstanding updates, but currently no driver supports that.
1936 * Note that drivers must wait for preceding updates to complete if a
1937 * synchronous update is requested, they are not allowed to fail the
1938 * commit in that case.
1939 *
1940 * - -ENOMEM, if the driver failed to allocate memory. Specifically
1941 * this can happen when trying to pin framebuffers, which must only
1942 * be done when committing the state.
1943 *
1944 * - -ENOSPC, as a refinement of the more generic -ENOMEM to indicate
1945 * that the driver has run out of vram, iommu space or similar GPU
1946 * address space needed for framebuffer.
1947 *
1948 * - -EIO, if the hardware completely died.
1949 *
1950 * - -EINTR, -EAGAIN or -ERESTARTSYS, if the IOCTL should be restarted.
1951 * This can either be due to a pending signal, or because the driver
1952 * needs to completely bail out to recover from an exceptional
1953 * situation like a GPU hang. From a userspace point of view all errors are
1954 * treated equally.
1955 *
1956 * This list is exhaustive. Specifically this hook is not allowed to
1957 * return -EINVAL (any invalid requests should be caught in
1958 * @atomic_check) or -EDEADLK (this function must not acquire
1959 * additional modeset locks).
1960 */
Daniel Vettercc4ceb42014-07-25 21:30:38 +02001961 int (*atomic_commit)(struct drm_device *dev,
Daniel Vetter9953f412015-12-04 09:46:02 +01001962 struct drm_atomic_state *state,
Daniel Vettercc4ceb42014-07-25 21:30:38 +02001963 bool async);
Daniel Vetter9953f412015-12-04 09:46:02 +01001964
1965 /**
1966 * @atomic_state_alloc:
1967 *
1968 * This optional hook can be used by drivers that want to subclass struct
1969 * &drm_atomic_state to be able to track their own driver-private global
1970 * state easily. If this hook is implemented, drivers must also
1971 * implement @atomic_state_clear and @atomic_state_free.
1972 *
1973 * RETURNS:
1974 *
1975 * A new &drm_atomic_state on success or NULL on failure.
1976 */
Maarten Lankhorst036ef572015-05-18 10:06:40 +02001977 struct drm_atomic_state *(*atomic_state_alloc)(struct drm_device *dev);
Daniel Vetter9953f412015-12-04 09:46:02 +01001978
1979 /**
1980 * @atomic_state_clear:
1981 *
1982 * This hook must clear any driver private state duplicated into the
1983 * passed-in &drm_atomic_state. This hook is called when the caller
1984 * encountered a &drm_modeset_lock deadlock and needs to drop all
1985 * already acquired locks as part of the deadlock avoidance dance
1986 * implemented in drm_modeset_lock_backoff().
1987 *
1988 * Any duplicated state must be invalidated since a concurrent atomic
1989 * update might change it, and the drm atomic interfaces always apply
1990 * updates as relative changes to the current state.
1991 *
1992 * Drivers that implement this must call drm_atomic_state_default_clear()
1993 * to clear common state.
1994 */
Maarten Lankhorst036ef572015-05-18 10:06:40 +02001995 void (*atomic_state_clear)(struct drm_atomic_state *state);
Daniel Vetter9953f412015-12-04 09:46:02 +01001996
1997 /**
1998 * @atomic_state_free:
1999 *
2000 * This hook needs driver private resources and the &drm_atomic_state
2001 * itself. Note that the core first calls drm_atomic_state_clear() to
2002 * avoid code duplicate between the clear and free hooks.
2003 *
2004 * Drivers that implement this must call drm_atomic_state_default_free()
2005 * to release common resources.
2006 */
Maarten Lankhorst036ef572015-05-18 10:06:40 +02002007 void (*atomic_state_free)(struct drm_atomic_state *state);
Dave Airlief453ba02008-11-07 14:05:41 -08002008};
2009
Jesse Barnesc1aaca22011-11-07 12:03:21 -08002010/**
Daniel Vetter2c0c33d2014-10-27 20:19:38 +01002011 * struct drm_mode_config - Mode configuration control structure
Jesse Barnesa62c93d2011-11-07 12:03:22 -08002012 * @mutex: mutex protecting KMS related lists and structures
Daniel Vetter2c0c33d2014-10-27 20:19:38 +01002013 * @connection_mutex: ww mutex protecting connector state and routing
2014 * @acquire_ctx: global implicit acquire context used by atomic drivers for
Daniel Vetterc6b0ca32015-12-04 09:46:01 +01002015 * legacy IOCTLs
Jesse Barnesa62c93d2011-11-07 12:03:22 -08002016 * @idr_mutex: mutex for KMS ID allocation and management
2017 * @crtc_idr: main KMS ID tracking object
Daniel Vetter2c0c33d2014-10-27 20:19:38 +01002018 * @fb_lock: mutex to protect fb state and lists
Jesse Barnesa62c93d2011-11-07 12:03:22 -08002019 * @num_fb: number of fbs available
2020 * @fb_list: list of framebuffers available
2021 * @num_connector: number of connectors on this device
2022 * @connector_list: list of connector objects
2023 * @num_encoder: number of encoders on this device
2024 * @encoder_list: list of encoder objects
Daniel Vetter2c0c33d2014-10-27 20:19:38 +01002025 * @num_overlay_plane: number of overlay planes on this device
2026 * @num_total_plane: number of universal (i.e. with primary/curso) planes on this device
2027 * @plane_list: list of plane objects
Jesse Barnesa62c93d2011-11-07 12:03:22 -08002028 * @num_crtc: number of CRTCs on this device
2029 * @crtc_list: list of CRTC objects
Daniel Vetter2c0c33d2014-10-27 20:19:38 +01002030 * @property_list: list of property objects
Jesse Barnesa62c93d2011-11-07 12:03:22 -08002031 * @min_width: minimum pixel width on this device
2032 * @min_height: minimum pixel height on this device
2033 * @max_width: maximum pixel width on this device
2034 * @max_height: maximum pixel height on this device
2035 * @funcs: core driver provided mode setting functions
2036 * @fb_base: base address of the framebuffer
Daniel Vetter2c0c33d2014-10-27 20:19:38 +01002037 * @poll_enabled: track polling support for this device
2038 * @poll_running: track polling status for this device
Jesse Barnesa62c93d2011-11-07 12:03:22 -08002039 * @output_poll_work: delayed work for polling in process context
Daniel Vetter2c0c33d2014-10-27 20:19:38 +01002040 * @property_blob_list: list of all the blob property objects
Daniel Stone8fb6e7a2015-04-20 19:22:54 +01002041 * @blob_lock: mutex for blob property allocation and management
Jesse Barnesa62c93d2011-11-07 12:03:22 -08002042 * @*_property: core property tracking
Lionel Landwerlin5488dc12016-02-26 17:05:00 +00002043 * @degamma_lut_property: LUT used to convert the framebuffer's colors to linear
2044 * gamma
2045 * @degamma_lut_size_property: size of the degamma LUT as supported by the
2046 * driver (read-only)
2047 * @ctm_property: Matrix used to convert colors after the lookup in the
2048 * degamma LUT
2049 * @gamma_lut_property: LUT used to convert the colors, after the CSC matrix, to
2050 * the gamma space of the connected screen (read-only)
2051 * @gamma_lut_size_property: size of the gamma LUT as supported by the driver
Daniel Vetter2c0c33d2014-10-27 20:19:38 +01002052 * @preferred_depth: preferred RBG pixel depth, used by fb helpers
2053 * @prefer_shadow: hint to userspace to prefer shadow-fb rendering
2054 * @async_page_flip: does this device support async flips on the primary plane?
2055 * @cursor_width: hint to userspace for max cursor width
2056 * @cursor_height: hint to userspace for max cursor height
Dave Airlief453ba02008-11-07 14:05:41 -08002057 *
Jesse Barnesa62c93d2011-11-07 12:03:22 -08002058 * Core mode resource tracking structure. All CRTC, encoders, and connectors
2059 * enumerated by the driver are added here, as are global properties. Some
2060 * global restrictions are also here, e.g. dimension restrictions.
Dave Airlief453ba02008-11-07 14:05:41 -08002061 */
2062struct drm_mode_config {
Jesse Barnesad2563c2009-01-19 17:21:45 +10002063 struct mutex mutex; /* protects configuration (mode lists etc.) */
Rob Clark51fd3712013-11-19 12:10:12 -05002064 struct drm_modeset_lock connection_mutex; /* protects connector->encoder and encoder->crtc links */
2065 struct drm_modeset_acquire_ctx *acquire_ctx; /* for legacy _lock_all() / _unlock_all() */
Jesse Barnesad2563c2009-01-19 17:21:45 +10002066 struct mutex idr_mutex; /* for IDR management */
Dave Airlief453ba02008-11-07 14:05:41 -08002067 struct idr crtc_idr; /* use this idr for all IDs, fb, crtc, connector, modes - just makes life easier */
Dave Airlie138f9eb2014-10-20 16:17:17 +10002068 struct idr tile_idr; /* use this idr for all IDs, fb, crtc, connector, modes - just makes life easier */
Dave Airlief453ba02008-11-07 14:05:41 -08002069 /* this is limited to one for now */
Daniel Vetter4b096ac2012-12-10 21:19:18 +01002070
Daniel Vetter2c0c33d2014-10-27 20:19:38 +01002071 struct mutex fb_lock; /* proctects global and per-file fb lists */
Dave Airlief453ba02008-11-07 14:05:41 -08002072 int num_fb;
2073 struct list_head fb_list;
Daniel Vetter4b096ac2012-12-10 21:19:18 +01002074
Dave Airlief453ba02008-11-07 14:05:41 -08002075 int num_connector;
2076 struct list_head connector_list;
2077 int num_encoder;
2078 struct list_head encoder_list;
Matt Ropere27dde32014-04-01 15:22:30 -07002079
2080 /*
2081 * Track # of overlay planes separately from # of total planes. By
2082 * default we only advertise overlay planes to userspace; if userspace
2083 * sets the "universal plane" capability bit, we'll go ahead and
2084 * expose all planes.
2085 */
2086 int num_overlay_plane;
2087 int num_total_plane;
Jesse Barnes8cf5c912011-11-14 14:51:27 -08002088 struct list_head plane_list;
Dave Airlief453ba02008-11-07 14:05:41 -08002089
2090 int num_crtc;
2091 struct list_head crtc_list;
2092
2093 struct list_head property_list;
2094
Dave Airlief453ba02008-11-07 14:05:41 -08002095 int min_width, min_height;
2096 int max_width, max_height;
Laurent Pincharte6ecefa2012-05-17 13:27:23 +02002097 const struct drm_mode_config_funcs *funcs;
Benjamin Herrenschmidtd883f7f2009-02-02 16:55:45 +11002098 resource_size_t fb_base;
Dave Airlief453ba02008-11-07 14:05:41 -08002099
Dave Airlieeb1f8e4f32010-05-07 06:42:51 +00002100 /* output poll support */
2101 bool poll_enabled;
Daniel Vetter905bc9f2012-10-23 18:23:36 +00002102 bool poll_running;
Daniel Vetter162b6a52015-01-21 08:45:21 +01002103 bool delayed_event;
Tejun Heo991ea752010-07-20 22:09:02 +02002104 struct delayed_work output_poll_work;
Dave Airlieeb1f8e4f32010-05-07 06:42:51 +00002105
Daniel Stone8fb6e7a2015-04-20 19:22:54 +01002106 struct mutex blob_lock;
2107
Dave Airlief453ba02008-11-07 14:05:41 -08002108 /* pointers to standard properties */
2109 struct list_head property_blob_list;
2110 struct drm_property *edid_property;
2111 struct drm_property *dpms_property;
Dave Airlie43aba7e2014-06-05 14:01:31 +10002112 struct drm_property *path_property;
Dave Airlie6f134d72014-10-20 16:30:50 +10002113 struct drm_property *tile_property;
Rob Clark9922ab52014-04-01 20:16:57 -04002114 struct drm_property *plane_type_property;
Sonika Jindal2a297cc2014-08-05 11:26:54 +05302115 struct drm_property *rotation_property;
Rob Clark6b4959f2014-12-18 16:01:53 -05002116 struct drm_property *prop_src_x;
2117 struct drm_property *prop_src_y;
2118 struct drm_property *prop_src_w;
2119 struct drm_property *prop_src_h;
2120 struct drm_property *prop_crtc_x;
2121 struct drm_property *prop_crtc_y;
2122 struct drm_property *prop_crtc_w;
2123 struct drm_property *prop_crtc_h;
2124 struct drm_property *prop_fb_id;
2125 struct drm_property *prop_crtc_id;
Daniel Vettereab3bbe2015-01-22 16:36:21 +01002126 struct drm_property *prop_active;
Daniel Stone955f3c32015-05-25 19:11:52 +01002127 struct drm_property *prop_mode_id;
Dave Airlief453ba02008-11-07 14:05:41 -08002128
2129 /* DVI-I properties */
2130 struct drm_property *dvi_i_subconnector_property;
2131 struct drm_property *dvi_i_select_subconnector_property;
2132
2133 /* TV properties */
2134 struct drm_property *tv_subconnector_property;
2135 struct drm_property *tv_select_subconnector_property;
2136 struct drm_property *tv_mode_property;
2137 struct drm_property *tv_left_margin_property;
2138 struct drm_property *tv_right_margin_property;
2139 struct drm_property *tv_top_margin_property;
2140 struct drm_property *tv_bottom_margin_property;
Francisco Jerezb6b79022009-08-02 04:19:20 +02002141 struct drm_property *tv_brightness_property;
2142 struct drm_property *tv_contrast_property;
2143 struct drm_property *tv_flicker_reduction_property;
Francisco Jereza75f0232009-08-12 02:30:10 +02002144 struct drm_property *tv_overscan_property;
2145 struct drm_property *tv_saturation_property;
2146 struct drm_property *tv_hue_property;
Dave Airlief453ba02008-11-07 14:05:41 -08002147
2148 /* Optional properties */
2149 struct drm_property *scaling_mode_property;
Vandana Kannanff587e42014-06-11 10:46:48 +05302150 struct drm_property *aspect_ratio_property;
Jakob Bornecrantz884840a2009-12-03 23:25:47 +00002151 struct drm_property *dirty_info_property;
Dave Airlie019d96c2011-09-29 16:20:42 +01002152
Lionel Landwerlin5488dc12016-02-26 17:05:00 +00002153 /* Optional color correction properties */
2154 struct drm_property *degamma_lut_property;
2155 struct drm_property *degamma_lut_size_property;
2156 struct drm_property *ctm_property;
2157 struct drm_property *gamma_lut_property;
2158 struct drm_property *gamma_lut_size_property;
2159
Dave Airlie5bb2bbf2014-11-10 10:18:15 +10002160 /* properties for virtual machine layout */
2161 struct drm_property *suggested_x_property;
2162 struct drm_property *suggested_y_property;
2163
Dave Airlie019d96c2011-09-29 16:20:42 +01002164 /* dumb ioctl parameters */
2165 uint32_t preferred_depth, prefer_shadow;
Keith Packard62f21042013-07-22 18:50:00 -07002166
2167 /* whether async page flip is supported or not */
2168 bool async_page_flip;
Alex Deucher8716ed42014-02-12 12:48:23 -05002169
Rob Clarke3eb3252015-02-05 14:41:52 +00002170 /* whether the driver supports fb modifiers */
2171 bool allow_fb_modifiers;
2172
Alex Deucher8716ed42014-02-12 12:48:23 -05002173 /* cursor size */
2174 uint32_t cursor_width, cursor_height;
Dave Airlief453ba02008-11-07 14:05:41 -08002175};
2176
Rob Clarkdd275952014-11-25 20:29:46 -05002177/**
2178 * drm_for_each_plane_mask - iterate over planes specified by bitmask
2179 * @plane: the loop cursor
2180 * @dev: the DRM device
2181 * @plane_mask: bitmask of plane indices
2182 *
2183 * Iterate over all planes specified by bitmask.
2184 */
2185#define drm_for_each_plane_mask(plane, dev, plane_mask) \
2186 list_for_each_entry((plane), &(dev)->mode_config.plane_list, head) \
Jani Nikula373701b2015-11-24 21:21:55 +02002187 for_each_if ((plane_mask) & (1 << drm_plane_index(plane)))
Rob Clarkdd275952014-11-25 20:29:46 -05002188
Maarten Lankhorstead8b662016-01-07 10:59:19 +01002189/**
2190 * drm_for_each_encoder_mask - iterate over encoders specified by bitmask
2191 * @encoder: the loop cursor
2192 * @dev: the DRM device
2193 * @encoder_mask: bitmask of encoder indices
2194 *
2195 * Iterate over all encoders specified by bitmask.
2196 */
2197#define drm_for_each_encoder_mask(encoder, dev, encoder_mask) \
2198 list_for_each_entry((encoder), &(dev)->mode_config.encoder_list, head) \
2199 for_each_if ((encoder_mask) & (1 << drm_encoder_index(encoder)))
Rob Clarkdd275952014-11-25 20:29:46 -05002200
Dave Airlief453ba02008-11-07 14:05:41 -08002201#define obj_to_crtc(x) container_of(x, struct drm_crtc, base)
2202#define obj_to_connector(x) container_of(x, struct drm_connector, base)
2203#define obj_to_encoder(x) container_of(x, struct drm_encoder, base)
2204#define obj_to_mode(x) container_of(x, struct drm_display_mode, base)
2205#define obj_to_fb(x) container_of(x, struct drm_framebuffer, base)
2206#define obj_to_property(x) container_of(x, struct drm_property, base)
2207#define obj_to_blob(x) container_of(x, struct drm_property_blob, base)
Jesse Barnes8cf5c912011-11-14 14:51:27 -08002208#define obj_to_plane(x) container_of(x, struct drm_plane, base)
Dave Airlief453ba02008-11-07 14:05:41 -08002209
Sascha Hauer4a67d392012-02-06 10:58:17 +01002210struct drm_prop_enum_list {
2211 int type;
2212 char *name;
2213};
Dave Airlief453ba02008-11-07 14:05:41 -08002214
Ville Syrjäläf9882872015-12-09 16:19:31 +02002215extern __printf(6, 7)
2216int drm_crtc_init_with_planes(struct drm_device *dev,
2217 struct drm_crtc *crtc,
2218 struct drm_plane *primary,
2219 struct drm_plane *cursor,
2220 const struct drm_crtc_funcs *funcs,
2221 const char *name, ...);
Dave Airlief453ba02008-11-07 14:05:41 -08002222extern void drm_crtc_cleanup(struct drm_crtc *crtc);
Russell Kingdb5f7a62014-01-02 21:27:33 +00002223extern unsigned int drm_crtc_index(struct drm_crtc *crtc);
2224
2225/**
2226 * drm_crtc_mask - find the mask of a registered CRTC
2227 * @crtc: CRTC to find mask for
2228 *
2229 * Given a registered CRTC, return the mask bit of that CRTC for an
2230 * encoder's possible_crtcs field.
2231 */
2232static inline uint32_t drm_crtc_mask(struct drm_crtc *crtc)
2233{
2234 return 1 << drm_crtc_index(crtc);
2235}
Dave Airlief453ba02008-11-07 14:05:41 -08002236
Ilia Mirkinb21e3af2013-08-07 22:34:48 -04002237extern void drm_connector_ida_init(void);
2238extern void drm_connector_ida_destroy(void);
Ville Syrjälä6bfc56a2012-03-13 12:35:48 +02002239extern int drm_connector_init(struct drm_device *dev,
2240 struct drm_connector *connector,
2241 const struct drm_connector_funcs *funcs,
2242 int connector_type);
Thomas Wood34ea3d32014-05-29 16:57:41 +01002243int drm_connector_register(struct drm_connector *connector);
2244void drm_connector_unregister(struct drm_connector *connector);
Dave Airlief453ba02008-11-07 14:05:41 -08002245
2246extern void drm_connector_cleanup(struct drm_connector *connector);
Daniel Vetter10f637b2014-07-29 13:47:11 +02002247extern unsigned int drm_connector_index(struct drm_connector *connector);
Dave Airliecbc7e222012-02-20 14:16:40 +00002248/* helper to unplug all connectors from sysfs for device */
2249extern void drm_connector_unplug_all(struct drm_device *dev);
Dave Airlief453ba02008-11-07 14:05:41 -08002250
Ajay Kumar3d3f8b12015-01-20 22:08:44 +05302251extern int drm_bridge_add(struct drm_bridge *bridge);
2252extern void drm_bridge_remove(struct drm_bridge *bridge);
2253extern struct drm_bridge *of_drm_find_bridge(struct device_node *np);
2254extern int drm_bridge_attach(struct drm_device *dev, struct drm_bridge *bridge);
Sean Paul3b336ec2013-08-14 16:47:37 -04002255
Archit Taneja862e6862015-05-21 11:03:16 +05302256bool drm_bridge_mode_fixup(struct drm_bridge *bridge,
2257 const struct drm_display_mode *mode,
2258 struct drm_display_mode *adjusted_mode);
2259void drm_bridge_disable(struct drm_bridge *bridge);
2260void drm_bridge_post_disable(struct drm_bridge *bridge);
2261void drm_bridge_mode_set(struct drm_bridge *bridge,
2262 struct drm_display_mode *mode,
2263 struct drm_display_mode *adjusted_mode);
2264void drm_bridge_pre_enable(struct drm_bridge *bridge);
2265void drm_bridge_enable(struct drm_bridge *bridge);
2266
Ville Syrjälä13a3d912015-12-09 16:20:18 +02002267extern __printf(5, 6)
2268int drm_encoder_init(struct drm_device *dev,
2269 struct drm_encoder *encoder,
2270 const struct drm_encoder_funcs *funcs,
2271 int encoder_type, const char *name, ...);
Maarten Lankhorst47d77772016-01-07 10:59:18 +01002272extern unsigned int drm_encoder_index(struct drm_encoder *encoder);
Dave Airlief453ba02008-11-07 14:05:41 -08002273
Thierry Reding3d887362014-01-13 14:33:20 +01002274/**
2275 * drm_encoder_crtc_ok - can a given crtc drive a given encoder?
2276 * @encoder: encoder to test
2277 * @crtc: crtc to test
2278 *
2279 * Return false if @encoder can't be driven by @crtc, true otherwise.
2280 */
2281static inline bool drm_encoder_crtc_ok(struct drm_encoder *encoder,
2282 struct drm_crtc *crtc)
2283{
2284 return !!(encoder->possible_crtcs & drm_crtc_mask(crtc));
2285}
2286
Ville Syrjäläb0b3b792015-12-09 16:19:55 +02002287extern __printf(8, 9)
2288int drm_universal_plane_init(struct drm_device *dev,
2289 struct drm_plane *plane,
2290 unsigned long possible_crtcs,
2291 const struct drm_plane_funcs *funcs,
2292 const uint32_t *formats,
2293 unsigned int format_count,
2294 enum drm_plane_type type,
2295 const char *name, ...);
Jesse Barnes8cf5c912011-11-14 14:51:27 -08002296extern int drm_plane_init(struct drm_device *dev,
2297 struct drm_plane *plane,
2298 unsigned long possible_crtcs,
2299 const struct drm_plane_funcs *funcs,
Thierry Reding45e37432015-08-12 16:54:28 +02002300 const uint32_t *formats, unsigned int format_count,
Matt Roperdc415ff2014-04-01 15:22:36 -07002301 bool is_primary);
Jesse Barnes8cf5c912011-11-14 14:51:27 -08002302extern void drm_plane_cleanup(struct drm_plane *plane);
Daniel Vetter10f637b2014-07-29 13:47:11 +02002303extern unsigned int drm_plane_index(struct drm_plane *plane);
Chandra Konduruf81338a2015-04-09 17:36:21 -07002304extern struct drm_plane * drm_plane_from_index(struct drm_device *dev, int idx);
Ville Syrjälä9125e612013-06-03 16:10:40 +03002305extern void drm_plane_force_disable(struct drm_plane *plane);
Laurent Pinchartead86102015-03-05 02:25:43 +02002306extern int drm_plane_check_pixel_format(const struct drm_plane *plane,
2307 u32 format);
Gustavo Padovanecb7e162014-12-01 15:40:09 -08002308extern void drm_crtc_get_hv_timing(const struct drm_display_mode *mode,
2309 int *hdisplay, int *vdisplay);
Matt Roperaf936292014-04-01 15:22:34 -07002310extern int drm_crtc_check_viewport(const struct drm_crtc *crtc,
2311 int x, int y,
2312 const struct drm_display_mode *mode,
2313 const struct drm_framebuffer *fb);
Jesse Barnes8cf5c912011-11-14 14:51:27 -08002314
Dave Airlief453ba02008-11-07 14:05:41 -08002315extern void drm_encoder_cleanup(struct drm_encoder *encoder);
2316
Ville Syrjäläd20d3172013-06-07 15:43:07 +00002317extern const char *drm_get_connector_status_name(enum drm_connector_status status);
Jesse Barnesac1bb362014-02-10 15:32:44 -08002318extern const char *drm_get_subpixel_order_name(enum subpixel_order order);
Ville Syrjäläd20d3172013-06-07 15:43:07 +00002319extern const char *drm_get_dpms_name(int val);
2320extern const char *drm_get_dvi_i_subconnector_name(int val);
2321extern const char *drm_get_dvi_i_select_name(int val);
2322extern const char *drm_get_tv_subconnector_name(int val);
2323extern const char *drm_get_tv_select_name(int val);
Kristian Høgsbergea39f832009-02-12 14:37:56 -05002324extern void drm_fb_release(struct drm_file *file_priv);
Daniel Stonee2f5d2e2015-05-22 13:34:51 +01002325extern void drm_property_destroy_user_blobs(struct drm_device *dev,
2326 struct drm_file *file_priv);
Adam Jacksonfbff4692012-09-18 10:58:47 -04002327extern bool drm_probe_ddc(struct i2c_adapter *adapter);
Dave Airlief453ba02008-11-07 14:05:41 -08002328extern struct edid *drm_get_edid(struct drm_connector *connector,
2329 struct i2c_adapter *adapter);
Lukas Wunner5cb8eaa22016-01-11 20:09:20 +01002330extern struct edid *drm_get_edid_switcheroo(struct drm_connector *connector,
2331 struct i2c_adapter *adapter);
Jani Nikula51f8da52013-09-27 15:08:27 +03002332extern struct edid *drm_edid_duplicate(const struct edid *edid);
Dave Airlief453ba02008-11-07 14:05:41 -08002333extern int drm_add_edid_modes(struct drm_connector *connector, struct edid *edid);
Dave Airlief453ba02008-11-07 14:05:41 -08002334extern void drm_mode_config_init(struct drm_device *dev);
Chris Wilsoneb0335562011-01-24 15:11:08 +00002335extern void drm_mode_config_reset(struct drm_device *dev);
Dave Airlief453ba02008-11-07 14:05:41 -08002336extern void drm_mode_config_cleanup(struct drm_device *dev);
Dave Airlief453ba02008-11-07 14:05:41 -08002337
Dave Airlie43aba7e2014-06-05 14:01:31 +10002338extern int drm_mode_connector_set_path_property(struct drm_connector *connector,
Thierry Reding12e6cec2014-05-13 11:38:36 +02002339 const char *path);
Dave Airlie6f134d72014-10-20 16:30:50 +10002340int drm_mode_connector_set_tile_property(struct drm_connector *connector);
Dave Airlief453ba02008-11-07 14:05:41 -08002341extern int drm_mode_connector_update_edid_property(struct drm_connector *connector,
Thierry Reding12e6cec2014-05-13 11:38:36 +02002342 const struct edid *edid);
Rob Clark5ea22f22014-05-30 11:34:01 -04002343
Boris Brezillonb5571e92014-07-22 12:09:10 +02002344extern int drm_display_info_set_bus_formats(struct drm_display_info *info,
2345 const u32 *formats,
2346 unsigned int num_formats);
2347
Rob Clark5ea22f22014-05-30 11:34:01 -04002348static inline bool drm_property_type_is(struct drm_property *property,
2349 uint32_t type)
2350{
2351 /* instanceof for props.. handles extended type vs original types: */
2352 if (property->flags & DRM_MODE_PROP_EXTENDED_TYPE)
2353 return (property->flags & DRM_MODE_PROP_EXTENDED_TYPE) == type;
2354 return property->flags & type;
2355}
2356
2357static inline bool drm_property_type_valid(struct drm_property *property)
2358{
2359 if (property->flags & DRM_MODE_PROP_EXTENDED_TYPE)
2360 return !(property->flags & DRM_MODE_PROP_LEGACY_TYPE);
2361 return !!(property->flags & DRM_MODE_PROP_LEGACY_TYPE);
2362}
2363
Paulo Zanonic5431882012-05-15 18:09:02 -03002364extern int drm_object_property_set_value(struct drm_mode_object *obj,
2365 struct drm_property *property,
2366 uint64_t val);
2367extern int drm_object_property_get_value(struct drm_mode_object *obj,
2368 struct drm_property *property,
2369 uint64_t *value);
Dave Airlief453ba02008-11-07 14:05:41 -08002370extern int drm_framebuffer_init(struct drm_device *dev,
2371 struct drm_framebuffer *fb,
2372 const struct drm_framebuffer_funcs *funcs);
Daniel Vetter786b99e2012-12-02 21:53:40 +01002373extern struct drm_framebuffer *drm_framebuffer_lookup(struct drm_device *dev,
2374 uint32_t id);
Rob Clarkf7eff602012-09-05 21:48:38 +00002375extern void drm_framebuffer_unreference(struct drm_framebuffer *fb);
2376extern void drm_framebuffer_reference(struct drm_framebuffer *fb);
2377extern void drm_framebuffer_remove(struct drm_framebuffer *fb);
Dave Airlief453ba02008-11-07 14:05:41 -08002378extern void drm_framebuffer_cleanup(struct drm_framebuffer *fb);
Daniel Vetter36206362012-12-10 20:42:17 +01002379extern void drm_framebuffer_unregister_private(struct drm_framebuffer *fb);
Dave Airlief453ba02008-11-07 14:05:41 -08002380
Paulo Zanonic5431882012-05-15 18:09:02 -03002381extern void drm_object_attach_property(struct drm_mode_object *obj,
2382 struct drm_property *property,
2383 uint64_t init_val);
Dave Airlief453ba02008-11-07 14:05:41 -08002384extern struct drm_property *drm_property_create(struct drm_device *dev, int flags,
2385 const char *name, int num_values);
Sascha Hauer4a67d392012-02-06 10:58:17 +01002386extern struct drm_property *drm_property_create_enum(struct drm_device *dev, int flags,
2387 const char *name,
2388 const struct drm_prop_enum_list *props,
2389 int num_values);
Rob Clark49e27542012-05-17 02:23:26 -06002390struct drm_property *drm_property_create_bitmask(struct drm_device *dev,
2391 int flags, const char *name,
2392 const struct drm_prop_enum_list *props,
Ville Syrjälä7689ffb2014-07-08 10:31:52 +05302393 int num_props,
2394 uint64_t supported_bits);
Sascha Hauerd9bc3c02012-02-06 10:58:18 +01002395struct drm_property *drm_property_create_range(struct drm_device *dev, int flags,
2396 const char *name,
2397 uint64_t min, uint64_t max);
Rob Clarkebc44cf2012-09-12 22:22:31 -05002398struct drm_property *drm_property_create_signed_range(struct drm_device *dev,
2399 int flags, const char *name,
2400 int64_t min, int64_t max);
Rob Clark98f75de2014-05-30 11:37:03 -04002401struct drm_property *drm_property_create_object(struct drm_device *dev,
2402 int flags, const char *name, uint32_t type);
Daniel Vetter960cd9d2015-01-21 08:47:38 +01002403struct drm_property *drm_property_create_bool(struct drm_device *dev, int flags,
2404 const char *name);
Daniel Stone6bcacf52015-04-20 19:22:55 +01002405struct drm_property_blob *drm_property_create_blob(struct drm_device *dev,
2406 size_t length,
2407 const void *data);
2408struct drm_property_blob *drm_property_lookup_blob(struct drm_device *dev,
2409 uint32_t id);
2410struct drm_property_blob *drm_property_reference_blob(struct drm_property_blob *blob);
2411void drm_property_unreference_blob(struct drm_property_blob *blob);
Dave Airlief453ba02008-11-07 14:05:41 -08002412extern void drm_property_destroy(struct drm_device *dev, struct drm_property *property);
2413extern int drm_property_add_enum(struct drm_property *property, int index,
2414 uint64_t value, const char *name);
2415extern int drm_mode_create_dvi_i_properties(struct drm_device *dev);
Thierry Reding2f763312014-10-13 12:45:57 +02002416extern int drm_mode_create_tv_properties(struct drm_device *dev,
2417 unsigned int num_modes,
Ville Syrjäläb7c914b2015-08-31 15:09:26 +03002418 const char * const modes[]);
Dave Airlief453ba02008-11-07 14:05:41 -08002419extern int drm_mode_create_scaling_mode_property(struct drm_device *dev);
Vandana Kannanff587e42014-06-11 10:46:48 +05302420extern int drm_mode_create_aspect_ratio_property(struct drm_device *dev);
Jakob Bornecrantz884840a2009-12-03 23:25:47 +00002421extern int drm_mode_create_dirty_info_property(struct drm_device *dev);
Dave Airlie5bb2bbf2014-11-10 10:18:15 +10002422extern int drm_mode_create_suggested_offset_properties(struct drm_device *dev);
Rob Clarkd34f20d2014-12-18 16:01:56 -05002423extern bool drm_property_change_valid_get(struct drm_property *property,
2424 uint64_t value, struct drm_mode_object **ref);
2425extern void drm_property_change_valid_put(struct drm_property *property,
2426 struct drm_mode_object *ref);
Dave Airlief453ba02008-11-07 14:05:41 -08002427
2428extern int drm_mode_connector_attach_encoder(struct drm_connector *connector,
2429 struct drm_encoder *encoder);
Sascha Hauer4cae5b82012-02-01 11:38:23 +01002430extern int drm_mode_crtc_set_gamma_size(struct drm_crtc *crtc,
Dave Airlief453ba02008-11-07 14:05:41 -08002431 int gamma_size);
Daniel Vetter7a9c9062009-09-15 22:57:31 +02002432extern struct drm_mode_object *drm_mode_object_find(struct drm_device *dev,
2433 uint32_t id, uint32_t type);
Rob Clark98f75de2014-05-30 11:37:03 -04002434
Dave Airlief453ba02008-11-07 14:05:41 -08002435/* IOCTLs */
2436extern int drm_mode_getresources(struct drm_device *dev,
2437 void *data, struct drm_file *file_priv);
Jesse Barnes8cf5c912011-11-14 14:51:27 -08002438extern int drm_mode_getplane_res(struct drm_device *dev, void *data,
2439 struct drm_file *file_priv);
Dave Airlief453ba02008-11-07 14:05:41 -08002440extern int drm_mode_getcrtc(struct drm_device *dev,
2441 void *data, struct drm_file *file_priv);
2442extern int drm_mode_getconnector(struct drm_device *dev,
2443 void *data, struct drm_file *file_priv);
Daniel Vetter2d13b672012-12-11 13:47:23 +01002444extern int drm_mode_set_config_internal(struct drm_mode_set *set);
Dave Airlief453ba02008-11-07 14:05:41 -08002445extern int drm_mode_setcrtc(struct drm_device *dev,
2446 void *data, struct drm_file *file_priv);
Jesse Barnes8cf5c912011-11-14 14:51:27 -08002447extern int drm_mode_getplane(struct drm_device *dev,
2448 void *data, struct drm_file *file_priv);
2449extern int drm_mode_setplane(struct drm_device *dev,
2450 void *data, struct drm_file *file_priv);
Dave Airlief453ba02008-11-07 14:05:41 -08002451extern int drm_mode_cursor_ioctl(struct drm_device *dev,
2452 void *data, struct drm_file *file_priv);
Dave Airlie4c813d42013-06-20 11:48:52 +10002453extern int drm_mode_cursor2_ioctl(struct drm_device *dev,
2454 void *data, struct drm_file *file_priv);
Dave Airlief453ba02008-11-07 14:05:41 -08002455extern int drm_mode_addfb(struct drm_device *dev,
2456 void *data, struct drm_file *file_priv);
Jesse Barnes308e5bc2011-11-14 14:51:28 -08002457extern int drm_mode_addfb2(struct drm_device *dev,
2458 void *data, struct drm_file *file_priv);
2459extern uint32_t drm_mode_legacy_fb_format(uint32_t bpp, uint32_t depth);
Dave Airlief453ba02008-11-07 14:05:41 -08002460extern int drm_mode_rmfb(struct drm_device *dev,
2461 void *data, struct drm_file *file_priv);
2462extern int drm_mode_getfb(struct drm_device *dev,
2463 void *data, struct drm_file *file_priv);
Jakob Bornecrantz884840a2009-12-03 23:25:47 +00002464extern int drm_mode_dirtyfb_ioctl(struct drm_device *dev,
2465 void *data, struct drm_file *file_priv);
Dave Airlief453ba02008-11-07 14:05:41 -08002466
2467extern int drm_mode_getproperty_ioctl(struct drm_device *dev,
2468 void *data, struct drm_file *file_priv);
2469extern int drm_mode_getblob_ioctl(struct drm_device *dev,
2470 void *data, struct drm_file *file_priv);
Daniel Stonee2f5d2e2015-05-22 13:34:51 +01002471extern int drm_mode_createblob_ioctl(struct drm_device *dev,
2472 void *data, struct drm_file *file_priv);
2473extern int drm_mode_destroyblob_ioctl(struct drm_device *dev,
2474 void *data, struct drm_file *file_priv);
Dave Airlief453ba02008-11-07 14:05:41 -08002475extern int drm_mode_connector_property_set_ioctl(struct drm_device *dev,
2476 void *data, struct drm_file *file_priv);
Dave Airlief453ba02008-11-07 14:05:41 -08002477extern int drm_mode_getencoder(struct drm_device *dev,
2478 void *data, struct drm_file *file_priv);
2479extern int drm_mode_gamma_get_ioctl(struct drm_device *dev,
2480 void *data, struct drm_file *file_priv);
2481extern int drm_mode_gamma_set_ioctl(struct drm_device *dev,
2482 void *data, struct drm_file *file_priv);
Thierry Reding18316c82012-12-20 15:41:44 +01002483extern u8 drm_match_cea_mode(const struct drm_display_mode *to_match);
Vandana Kannan0967e6a2014-04-01 16:26:59 +05302484extern enum hdmi_picture_aspect drm_get_cea_aspect_ratio(const u8 video_code);
Ma Lingf23c20c2009-03-26 19:26:23 +08002485extern bool drm_detect_hdmi_monitor(struct edid *edid);
Zhenyu Wang8fe97902010-09-19 14:27:28 +08002486extern bool drm_detect_monitor_audio(struct edid *edid);
Ville Syrjäläb1edd6a2013-01-17 16:31:30 +02002487extern bool drm_rgb_quant_range_selectable(struct edid *edid);
Kristian Høgsbergd91d8a32009-11-17 12:43:55 -05002488extern int drm_mode_page_flip_ioctl(struct drm_device *dev,
2489 void *data, struct drm_file *file_priv);
Zhao Yakuif0fda0a2009-09-03 09:33:48 +08002490extern int drm_add_modes_noedid(struct drm_connector *connector,
2491 int hdisplay, int vdisplay);
Gerd Hoffmann3cf70da2013-10-11 10:01:08 +02002492extern void drm_set_preferred_mode(struct drm_connector *connector,
2493 int hpref, int vpref);
Alex Deucher3c537882010-02-05 04:21:19 -05002494
Thomas Reim051963d2011-07-29 14:28:57 +00002495extern int drm_edid_header_is_valid(const u8 *raw_edid);
Todd Previte6ba2bd32015-04-21 11:09:41 -07002496extern bool drm_edid_block_valid(u8 *raw_edid, int block, bool print_bad_edid,
2497 bool *edid_corrupt);
Alex Deucher3c537882010-02-05 04:21:19 -05002498extern bool drm_edid_is_valid(struct edid *edid);
Dave Airlie138f9eb2014-10-20 16:17:17 +10002499
2500extern struct drm_tile_group *drm_mode_create_tile_group(struct drm_device *dev,
2501 char topology[8]);
2502extern struct drm_tile_group *drm_mode_get_tile_group(struct drm_device *dev,
2503 char topology[8]);
2504extern void drm_mode_put_tile_group(struct drm_device *dev,
2505 struct drm_tile_group *tg);
Dave Airlie1d42bbc2010-05-07 05:02:30 +00002506struct drm_display_mode *drm_mode_find_dmt(struct drm_device *dev,
Adam Jacksonf6e252b2012-04-13 16:33:31 -04002507 int hsize, int vsize, int fresh,
2508 bool rb);
Dave Airlieff72145b2011-02-07 12:16:14 +10002509
2510extern int drm_mode_create_dumb_ioctl(struct drm_device *dev,
2511 void *data, struct drm_file *file_priv);
2512extern int drm_mode_mmap_dumb_ioctl(struct drm_device *dev,
2513 void *data, struct drm_file *file_priv);
2514extern int drm_mode_destroy_dumb_ioctl(struct drm_device *dev,
2515 void *data, struct drm_file *file_priv);
Paulo Zanonic5431882012-05-15 18:09:02 -03002516extern int drm_mode_obj_get_properties_ioctl(struct drm_device *dev, void *data,
2517 struct drm_file *file_priv);
2518extern int drm_mode_obj_set_property_ioctl(struct drm_device *dev, void *data,
2519 struct drm_file *file_priv);
Thomas Wood3a5f87c2014-08-20 14:45:00 +01002520extern int drm_mode_plane_set_obj_prop(struct drm_plane *plane,
2521 struct drm_property *property,
2522 uint64_t value);
Rob Clarkd34f20d2014-12-18 16:01:56 -05002523extern int drm_mode_atomic_ioctl(struct drm_device *dev,
2524 void *data, struct drm_file *file_priv);
Dave Airlie248dbc22011-11-29 20:02:54 +00002525
2526extern void drm_fb_get_bpp_depth(uint32_t format, unsigned int *depth,
2527 int *bpp);
Ville Syrjälä141670e2012-04-05 21:35:15 +03002528extern int drm_format_num_planes(uint32_t format);
Ville Syrjälä5a86bd52012-04-05 21:35:16 +03002529extern int drm_format_plane_cpp(uint32_t format, int plane);
Ville Syrjälä01b68b02012-04-05 21:35:17 +03002530extern int drm_format_horz_chroma_subsampling(uint32_t format);
2531extern int drm_format_vert_chroma_subsampling(uint32_t format);
Ville Syrjälä4c617162016-02-09 17:29:44 +02002532extern int drm_format_plane_width(int width, uint32_t format, int plane);
2533extern int drm_format_plane_height(int height, uint32_t format, int plane);
Ville Syrjäläd20d3172013-06-07 15:43:07 +00002534extern const char *drm_get_format_name(uint32_t format);
Ville Syrjäläc1df5f32014-07-08 10:31:53 +05302535extern struct drm_property *drm_mode_create_rotation_property(struct drm_device *dev,
2536 unsigned int supported_rotations);
Ville Syrjälä3c9855f2014-07-08 10:31:56 +05302537extern unsigned int drm_rotation_simplify(unsigned int rotation,
2538 unsigned int supported_rotations);
Ville Syrjälä141670e2012-04-05 21:35:15 +03002539
Russell King96f60e32012-08-15 13:59:49 +01002540/* Helpers */
Rob Clarka2b34e22013-10-05 16:36:52 -04002541
2542static inline struct drm_plane *drm_plane_find(struct drm_device *dev,
2543 uint32_t id)
2544{
2545 struct drm_mode_object *mo;
2546 mo = drm_mode_object_find(dev, id, DRM_MODE_OBJECT_PLANE);
2547 return mo ? obj_to_plane(mo) : NULL;
2548}
2549
Russell King96f60e32012-08-15 13:59:49 +01002550static inline struct drm_crtc *drm_crtc_find(struct drm_device *dev,
2551 uint32_t id)
2552{
2553 struct drm_mode_object *mo;
2554 mo = drm_mode_object_find(dev, id, DRM_MODE_OBJECT_CRTC);
2555 return mo ? obj_to_crtc(mo) : NULL;
2556}
2557
2558static inline struct drm_encoder *drm_encoder_find(struct drm_device *dev,
2559 uint32_t id)
2560{
2561 struct drm_mode_object *mo;
2562 mo = drm_mode_object_find(dev, id, DRM_MODE_OBJECT_ENCODER);
2563 return mo ? obj_to_encoder(mo) : NULL;
2564}
2565
Rob Clarka2b34e22013-10-05 16:36:52 -04002566static inline struct drm_connector *drm_connector_find(struct drm_device *dev,
2567 uint32_t id)
2568{
2569 struct drm_mode_object *mo;
2570 mo = drm_mode_object_find(dev, id, DRM_MODE_OBJECT_CONNECTOR);
2571 return mo ? obj_to_connector(mo) : NULL;
2572}
2573
2574static inline struct drm_property *drm_property_find(struct drm_device *dev,
2575 uint32_t id)
2576{
2577 struct drm_mode_object *mo;
2578 mo = drm_mode_object_find(dev, id, DRM_MODE_OBJECT_PROPERTY);
2579 return mo ? obj_to_property(mo) : NULL;
2580}
2581
Lionel Landwerlin5488dc12016-02-26 17:05:00 +00002582/*
2583 * Extract a degamma/gamma LUT value provided by user and round it to the
2584 * precision supported by the hardware.
2585 */
2586static inline uint32_t drm_color_lut_extract(uint32_t user_input,
2587 uint32_t bit_precision)
2588{
2589 uint32_t val = user_input + (1 << (16 - bit_precision - 1));
2590 uint32_t max = 0xffff >> (16 - bit_precision);
2591
2592 val >>= 16 - bit_precision;
2593
2594 return clamp_val(val, 0, max);
2595}
2596
Matt Ropere27dde32014-04-01 15:22:30 -07002597/* Plane list iterator for legacy (overlay only) planes. */
Daniel Vetter4ea50e92015-07-09 23:44:24 +02002598#define drm_for_each_legacy_plane(plane, dev) \
2599 list_for_each_entry(plane, &(dev)->mode_config.plane_list, head) \
Jani Nikula373701b2015-11-24 21:21:55 +02002600 for_each_if (plane->type == DRM_PLANE_TYPE_OVERLAY)
Matt Ropere27dde32014-04-01 15:22:30 -07002601
Daniel Vetter6295d602015-07-09 23:44:25 +02002602#define drm_for_each_plane(plane, dev) \
2603 list_for_each_entry(plane, &(dev)->mode_config.plane_list, head)
2604
2605#define drm_for_each_crtc(crtc, dev) \
2606 list_for_each_entry(crtc, &(dev)->mode_config.crtc_list, head)
2607
Daniel Vetter7a3f3d62015-07-09 23:44:28 +02002608static inline void
2609assert_drm_connector_list_read_locked(struct drm_mode_config *mode_config)
2610{
Daniel Vettercff20ba2015-07-09 23:44:33 +02002611 /*
2612 * The connector hotadd/remove code currently grabs both locks when
2613 * updating lists. Hence readers need only hold either of them to be
2614 * safe and the check amounts to
2615 *
2616 * WARN_ON(not_holding(A) && not_holding(B)).
2617 */
2618 WARN_ON(!mutex_is_locked(&mode_config->mutex) &&
2619 !drm_modeset_is_locked(&mode_config->connection_mutex));
Daniel Vetter7a3f3d62015-07-09 23:44:28 +02002620}
2621
Daniel Vetter6295d602015-07-09 23:44:25 +02002622#define drm_for_each_connector(connector, dev) \
Daniel Vetter7a3f3d62015-07-09 23:44:28 +02002623 for (assert_drm_connector_list_read_locked(&(dev)->mode_config), \
2624 connector = list_first_entry(&(dev)->mode_config.connector_list, \
2625 struct drm_connector, head); \
2626 &connector->head != (&(dev)->mode_config.connector_list); \
2627 connector = list_next_entry(connector, head))
Daniel Vetter6295d602015-07-09 23:44:25 +02002628
2629#define drm_for_each_encoder(encoder, dev) \
2630 list_for_each_entry(encoder, &(dev)->mode_config.encoder_list, head)
2631
2632#define drm_for_each_fb(fb, dev) \
Daniel Vetter4676ba02015-07-09 23:44:30 +02002633 for (WARN_ON(!mutex_is_locked(&(dev)->mode_config.fb_lock)), \
2634 fb = list_first_entry(&(dev)->mode_config.fb_list, \
2635 struct drm_framebuffer, head); \
2636 &fb->head != (&(dev)->mode_config.fb_list); \
2637 fb = list_next_entry(fb, head))
Daniel Vetter6295d602015-07-09 23:44:25 +02002638
Dave Airlief453ba02008-11-07 14:05:41 -08002639#endif /* __DRM_CRTC_H__ */