blob: 6d4684242a00b12487c6714250f3963b15103250 [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
Dave Airlief453ba02008-11-07 14:05:41 -080048struct drm_mode_object {
49 uint32_t id;
50 uint32_t type;
Paulo Zanoni7e3bdf42012-05-15 18:09:01 -030051 struct drm_object_properties *properties;
52};
53
Paulo Zanonife456162012-06-12 11:27:01 -030054#define DRM_OBJECT_MAX_PROPERTY 24
Paulo Zanoni7e3bdf42012-05-15 18:09:01 -030055struct drm_object_properties {
Rob Clark88a48e22014-12-18 16:01:50 -050056 int count, atomic_count;
Rob Clarkb17cd752014-12-16 18:05:30 -050057 /* NOTE: if we ever start dynamically destroying properties (ie.
58 * not at drm_mode_config_cleanup() time), then we'd have to do
59 * a better job of detaching property from mode objects to avoid
60 * dangling property pointers:
61 */
62 struct drm_property *properties[DRM_OBJECT_MAX_PROPERTY];
Rob Clark22b8b132014-12-16 18:05:31 -050063 /* do not read/write values directly, but use drm_object_property_get_value()
64 * and drm_object_property_set_value():
65 */
Paulo Zanoni7e3bdf42012-05-15 18:09:01 -030066 uint64_t values[DRM_OBJECT_MAX_PROPERTY];
Dave Airlief453ba02008-11-07 14:05:41 -080067};
68
Rob Clarkebc44cf2012-09-12 22:22:31 -050069static inline int64_t U642I64(uint64_t val)
70{
71 return (int64_t)*((int64_t *)&val);
72}
73static inline uint64_t I642U64(int64_t val)
74{
75 return (uint64_t)*((uint64_t *)&val);
76}
77
Robert Feketed9c38242015-11-02 16:14:08 +010078/*
79 * Rotation property bits. DRM_ROTATE_<degrees> rotates the image by the
80 * specified amount in degrees in counter clockwise direction. DRM_REFLECT_X and
81 * DRM_REFLECT_Y reflects the image along the specified axis prior to rotation
82 */
Joonas Lahtinen62209072015-10-01 10:00:57 +030083#define DRM_ROTATE_MASK 0x0f
Ville Syrjälä06596962014-07-08 10:31:51 +053084#define DRM_ROTATE_0 0
85#define DRM_ROTATE_90 1
86#define DRM_ROTATE_180 2
87#define DRM_ROTATE_270 3
Joonas Lahtinen62209072015-10-01 10:00:57 +030088#define DRM_REFLECT_MASK (~DRM_ROTATE_MASK)
Ville Syrjälä06596962014-07-08 10:31:51 +053089#define DRM_REFLECT_X 4
90#define DRM_REFLECT_Y 5
91
Daniel Vetter55310002014-01-23 15:52:20 +010092enum drm_connector_force {
93 DRM_FORCE_UNSPECIFIED,
94 DRM_FORCE_OFF,
95 DRM_FORCE_ON, /* force on analog part normally */
96 DRM_FORCE_ON_DIGITAL, /* for DVI-I use digital connector */
Dave Airlief453ba02008-11-07 14:05:41 -080097};
98
Daniel Vetter55310002014-01-23 15:52:20 +010099#include <drm/drm_modes.h>
Damien Lespiau4aa17cf2013-09-25 16:45:21 +0100100
Dave Airlief453ba02008-11-07 14:05:41 -0800101enum drm_connector_status {
102 connector_status_connected = 1,
103 connector_status_disconnected = 2,
104 connector_status_unknown = 3,
105};
106
107enum subpixel_order {
108 SubPixelUnknown = 0,
109 SubPixelHorizontalRGB,
110 SubPixelHorizontalBGR,
111 SubPixelVerticalRGB,
112 SubPixelVerticalBGR,
113 SubPixelNone,
114};
115
Jesse Barnesda05a5a72011-04-15 13:48:57 -0700116#define DRM_COLOR_FORMAT_RGB444 (1<<0)
117#define DRM_COLOR_FORMAT_YCRCB444 (1<<1)
118#define DRM_COLOR_FORMAT_YCRCB422 (1<<2)
Dave Airlief453ba02008-11-07 14:05:41 -0800119/*
120 * Describes a given display (e.g. CRT or flat panel) and its limitations.
121 */
122struct drm_display_info {
123 char name[DRM_DISPLAY_INFO_LEN];
Adam Jacksonfb439642010-08-03 14:38:16 -0400124
Dave Airlief453ba02008-11-07 14:05:41 -0800125 /* Physical size */
126 unsigned int width_mm;
127 unsigned int height_mm;
128
Dave Airlief453ba02008-11-07 14:05:41 -0800129 /* Clock limits FIXME: storage format */
130 unsigned int min_vfreq, max_vfreq;
131 unsigned int min_hfreq, max_hfreq;
132 unsigned int pixel_clock;
Jesse Barnes3b112282011-04-15 12:49:23 -0700133 unsigned int bpc;
Dave Airlief453ba02008-11-07 14:05:41 -0800134
Dave Airlief453ba02008-11-07 14:05:41 -0800135 enum subpixel_order subpixel_order;
Jesse Barnesda05a5a72011-04-15 13:48:57 -0700136 u32 color_formats;
Dave Airlief453ba02008-11-07 14:05:41 -0800137
Boris Brezillonb5571e92014-07-22 12:09:10 +0200138 const u32 *bus_formats;
139 unsigned int num_bus_formats;
140
Mario Kleiner5d02626d2014-06-05 09:52:10 -0400141 /* Mask of supported hdmi deep color modes */
142 u8 edid_hdmi_dc_modes;
143
Jesse Barnesebec9a72011-08-03 09:22:54 -0700144 u8 cea_rev;
Dave Airlief453ba02008-11-07 14:05:41 -0800145};
146
Dave Airlie138f9eb2014-10-20 16:17:17 +1000147/* data corresponds to displayid vend/prod/serial */
148struct drm_tile_group {
149 struct kref refcount;
150 struct drm_device *dev;
151 int id;
152 u8 group_data[8];
153};
154
Daniel Vetterc6b0ca32015-12-04 09:46:01 +0100155/**
156 * struct drm_framebuffer_funcs - framebuffer hooks
157 */
Dave Airlief453ba02008-11-07 14:05:41 -0800158struct drm_framebuffer_funcs {
Daniel Vetterc6b0ca32015-12-04 09:46:01 +0100159 /**
160 * @destroy:
161 *
162 * Clean up framebuffer resources, specifically also unreference the
163 * backing storage. The core guarantees to call this function for every
164 * framebuffer successfully created by ->fb_create() in
Daniel Vetterd55f5322015-12-08 09:49:19 +0100165 * &drm_mode_config_funcs. Drivers must also call
166 * drm_framebuffer_cleanup() to release DRM core resources for this
167 * framebuffer.
Daniel Vetterc6b0ca32015-12-04 09:46:01 +0100168 */
Dave Airlief453ba02008-11-07 14:05:41 -0800169 void (*destroy)(struct drm_framebuffer *framebuffer);
Daniel Vetterc6b0ca32015-12-04 09:46:01 +0100170
171 /**
172 * @create_handle:
173 *
174 * Create a buffer handle in the driver-specific buffer manager (either
175 * GEM or TTM) valid for the passed-in struct &drm_file. This is used by
176 * the core to implement the GETFB IOCTL, which returns (for
177 * sufficiently priviledged user) also a native buffer handle. This can
178 * be used for seamless transitions between modesetting clients by
179 * copying the current screen contents to a private buffer and blending
180 * between that and the new contents.
181 *
Daniel Vetterd55f5322015-12-08 09:49:19 +0100182 * GEM based drivers should call drm_gem_handle_create() to create the
183 * handle.
184 *
Daniel Vetterc6b0ca32015-12-04 09:46:01 +0100185 * RETURNS:
186 *
187 * 0 on success or a negative error code on failure.
188 */
Dave Airlief453ba02008-11-07 14:05:41 -0800189 int (*create_handle)(struct drm_framebuffer *fb,
190 struct drm_file *file_priv,
191 unsigned int *handle);
Daniel Vetterc6b0ca32015-12-04 09:46:01 +0100192 /**
193 * @dirty:
Jakob Bornecrantz884840a2009-12-03 23:25:47 +0000194 *
Daniel Vetterc6b0ca32015-12-04 09:46:01 +0100195 * Optional callback for the dirty fb IOCTL.
Jakob Bornecrantz884840a2009-12-03 23:25:47 +0000196 *
Daniel Vetterc6b0ca32015-12-04 09:46:01 +0100197 * Userspace can notify the driver via this callback that an area of the
198 * framebuffer has changed and should be flushed to the display
199 * hardware. This can also be used internally, e.g. by the fbdev
200 * emulation, though that's not the case currently.
201 *
202 * See documentation in drm_mode.h for the struct drm_mode_fb_dirty_cmd
203 * for more information as all the semantics and arguments have a one to
204 * one mapping on this function.
205 *
206 * RETURNS:
207 *
208 * 0 on success or a negative error code on failure.
Jakob Bornecrantz884840a2009-12-03 23:25:47 +0000209 */
Thomas Hellstrom02b00162010-10-05 12:43:02 +0200210 int (*dirty)(struct drm_framebuffer *framebuffer,
211 struct drm_file *file_priv, unsigned flags,
Jakob Bornecrantz884840a2009-12-03 23:25:47 +0000212 unsigned color, struct drm_clip_rect *clips,
213 unsigned num_clips);
Dave Airlief453ba02008-11-07 14:05:41 -0800214};
215
216struct drm_framebuffer {
217 struct drm_device *dev;
Rob Clarkf7eff602012-09-05 21:48:38 +0000218 /*
219 * Note that the fb is refcounted for the benefit of driver internals,
220 * for example some hw, disabling a CRTC/plane is asynchronous, and
221 * scanout does not actually complete until the next vblank. So some
222 * cleanup (like releasing the reference(s) on the backing GEM bo(s))
223 * should be deferred. In cases like this, the driver would like to
224 * hold a ref to the fb even though it has already been removed from
225 * userspace perspective.
226 */
227 struct kref refcount;
Daniel Vetter4b096ac2012-12-10 21:19:18 +0100228 /*
229 * Place on the dev->mode_config.fb_list, access protected by
230 * dev->mode_config.fb_lock.
231 */
Dave Airlief453ba02008-11-07 14:05:41 -0800232 struct list_head head;
233 struct drm_mode_object base;
234 const struct drm_framebuffer_funcs *funcs;
Ville Syrjälä01f2c772011-12-20 00:06:49 +0200235 unsigned int pitches[4];
236 unsigned int offsets[4];
Rob Clarke3eb3252015-02-05 14:41:52 +0000237 uint64_t modifier[4];
Dave Airlief453ba02008-11-07 14:05:41 -0800238 unsigned int width;
239 unsigned int height;
240 /* depth can be 15 or 16 */
241 unsigned int depth;
242 int bits_per_pixel;
243 int flags;
Jesse Barnes308e5bc2011-11-14 14:51:28 -0800244 uint32_t pixel_format; /* fourcc format */
Dave Airlief453ba02008-11-07 14:05:41 -0800245 struct list_head filp_head;
246};
247
248struct drm_property_blob {
249 struct drm_mode_object base;
Daniel Stone6bcacf52015-04-20 19:22:55 +0100250 struct drm_device *dev;
251 struct kref refcount;
Daniel Stonee2f5d2e2015-05-22 13:34:51 +0100252 struct list_head head_global;
253 struct list_head head_file;
Thierry Redingecbbe592014-05-13 11:36:13 +0200254 size_t length;
Ville Syrjäläd63f5e62012-03-13 12:35:49 +0200255 unsigned char data[];
Dave Airlief453ba02008-11-07 14:05:41 -0800256};
257
258struct drm_property_enum {
259 uint64_t value;
260 struct list_head head;
261 char name[DRM_PROP_NAME_LEN];
262};
263
264struct drm_property {
265 struct list_head head;
266 struct drm_mode_object base;
267 uint32_t flags;
268 char name[DRM_PROP_NAME_LEN];
269 uint32_t num_values;
270 uint64_t *values;
Rob Clark98f75de2014-05-30 11:37:03 -0400271 struct drm_device *dev;
Dave Airlief453ba02008-11-07 14:05:41 -0800272
Daniel Vetter3758b342014-11-19 18:38:10 +0100273 struct list_head enum_list;
Dave Airlief453ba02008-11-07 14:05:41 -0800274};
275
276struct drm_crtc;
277struct drm_connector;
278struct drm_encoder;
Kristian Høgsbergd91d8a32009-11-17 12:43:55 -0500279struct drm_pending_vblank_event;
Jesse Barnes8cf5c912011-11-14 14:51:27 -0800280struct drm_plane;
Sean Paul3b336ec2013-08-14 16:47:37 -0400281struct drm_bridge;
Daniel Vetter144ecb92014-10-27 20:28:44 +0100282struct drm_atomic_state;
283
Daniel Vetter4490d4c2015-12-04 09:45:45 +0100284struct drm_crtc_helper_funcs;
285struct drm_encoder_helper_funcs;
286struct drm_connector_helper_funcs;
287struct drm_plane_helper_funcs;
288
Daniel Vetter144ecb92014-10-27 20:28:44 +0100289/**
Daniel Vettercc4ceb42014-07-25 21:30:38 +0200290 * struct drm_crtc_state - mutable CRTC state
Daniel Vetter07cc0ef2014-11-27 15:49:39 +0100291 * @crtc: backpointer to the CRTC
Daniel Vetter144ecb92014-10-27 20:28:44 +0100292 * @enable: whether the CRTC should be enabled, gates all other state
Daniel Vetterd9b13622014-11-26 16:57:41 +0100293 * @active: whether the CRTC is actively displaying (used for DPMS)
Maarten Lankhorstfc596662015-07-21 13:28:57 +0200294 * @planes_changed: planes on this crtc are updated
295 * @mode_changed: crtc_state->mode or crtc_state->enable has been changed
296 * @active_changed: crtc_state->active has been toggled.
297 * @connectors_changed: connectors to this crtc have been updated
Lionel Landwerlin5488dc12016-02-26 17:05:00 +0000298 * @color_mgmt_changed: color management properties have changed (degamma or
299 * gamma LUT or CSC matrix)
Rob Clark6ddd3882014-11-21 15:28:31 -0500300 * @plane_mask: bitmask of (1 << drm_plane_index(plane)) of attached planes
Maarten Lankhorst4cd9fa52016-01-04 12:53:18 +0100301 * @connector_mask: bitmask of (1 << drm_connector_index(connector)) of attached connectors
Maarten Lankhorste87a52b2016-01-28 15:04:58 +0100302 * @encoder_mask: bitmask of (1 << drm_encoder_index(encoder)) of attached encoders
Daniel Vetter623369e2014-09-16 17:50:47 +0200303 * @last_vblank_count: for helpers and drivers to capture the vblank of the
304 * update to ensure framebuffer cleanup isn't done too early
Daniel Vetter2f324b42014-10-29 11:13:47 +0100305 * @adjusted_mode: for use by helpers and drivers to compute adjusted mode timings
Daniel Vetter144ecb92014-10-27 20:28:44 +0100306 * @mode: current mode timings
Lionel Landwerlin5488dc12016-02-26 17:05:00 +0000307 * @degamma_lut: Lookup table for converting framebuffer pixel data
308 * before apply the conversion matrix
309 * @ctm: Transformation matrix
310 * @gamma_lut: Lookup table for converting pixel data after the
311 * conversion matrix
Daniel Vetter144ecb92014-10-27 20:28:44 +0100312 * @event: optional pointer to a DRM event to signal upon completion of the
313 * state update
314 * @state: backpointer to global drm_atomic_state
Daniel Vetterd9b13622014-11-26 16:57:41 +0100315 *
316 * Note that the distinction between @enable and @active is rather subtile:
317 * Flipping @active while @enable is set without changing anything else may
318 * never return in a failure from the ->atomic_check callback. Userspace assumes
319 * that a DPMS On will always succeed. In other words: @enable controls resource
320 * assignment, @active controls the actual hardware state.
Daniel Vetter144ecb92014-10-27 20:28:44 +0100321 */
322struct drm_crtc_state {
Daniel Vetter07cc0ef2014-11-27 15:49:39 +0100323 struct drm_crtc *crtc;
324
Daniel Vettercc4ceb42014-07-25 21:30:38 +0200325 bool enable;
Daniel Vetterd9b13622014-11-26 16:57:41 +0100326 bool active;
Daniel Vetter144ecb92014-10-27 20:28:44 +0100327
Daniel Vetterc2fcd272014-11-05 00:14:14 +0100328 /* computed state bits used by helpers and drivers */
329 bool planes_changed : 1;
Daniel Vetter623369e2014-09-16 17:50:47 +0200330 bool mode_changed : 1;
Daniel Vettereab3bbe2015-01-22 16:36:21 +0100331 bool active_changed : 1;
Maarten Lankhorstfc596662015-07-21 13:28:57 +0200332 bool connectors_changed : 1;
Lionel Landwerlin5488dc12016-02-26 17:05:00 +0000333 bool color_mgmt_changed : 1;
Daniel Vetter623369e2014-09-16 17:50:47 +0200334
Rob Clark6ddd3882014-11-21 15:28:31 -0500335 /* attached planes bitmask:
336 * WARNING: transitional helpers do not maintain plane_mask so
337 * drivers not converted over to atomic helpers should not rely
338 * on plane_mask being accurate!
339 */
340 u32 plane_mask;
341
Maarten Lankhorst4cd9fa52016-01-04 12:53:18 +0100342 u32 connector_mask;
Maarten Lankhorste87a52b2016-01-28 15:04:58 +0100343 u32 encoder_mask;
Maarten Lankhorst4cd9fa52016-01-04 12:53:18 +0100344
Daniel Vetter623369e2014-09-16 17:50:47 +0200345 /* last_vblank_count: for vblank waits before cleanup */
346 u32 last_vblank_count;
Daniel Vetterc2fcd272014-11-05 00:14:14 +0100347
Daniel Vetter2f324b42014-10-29 11:13:47 +0100348 /* adjusted_mode: for use by helpers and drivers */
349 struct drm_display_mode adjusted_mode;
350
Daniel Vetter144ecb92014-10-27 20:28:44 +0100351 struct drm_display_mode mode;
352
Daniel Stone99cf4a22015-05-25 19:11:51 +0100353 /* blob property to expose current mode to atomic userspace */
354 struct drm_property_blob *mode_blob;
355
Lionel Landwerlin5488dc12016-02-26 17:05:00 +0000356 /* blob property to expose color management to userspace */
357 struct drm_property_blob *degamma_lut;
358 struct drm_property_blob *ctm;
359 struct drm_property_blob *gamma_lut;
360
Daniel Vetter144ecb92014-10-27 20:28:44 +0100361 struct drm_pending_vblank_event *event;
362
363 struct drm_atomic_state *state;
364};
Dave Airlief453ba02008-11-07 14:05:41 -0800365
366/**
Daniel Vetter3bf04012014-10-27 16:54:27 +0100367 * struct drm_crtc_funcs - control CRTCs for a given device
Dave Airlief453ba02008-11-07 14:05:41 -0800368 *
369 * The drm_crtc_funcs structure is the central CRTC management structure
370 * in the DRM. Each CRTC controls one or more connectors (note that the name
371 * CRTC is simply historical, a CRTC may control LVDS, VGA, DVI, TV out, etc.
372 * connectors, not just CRTs).
373 *
374 * Each driver is responsible for filling out this structure at startup time,
375 * in addition to providing other modesetting features, like i2c and DDC
376 * bus accessors.
377 */
378struct drm_crtc_funcs {
Daniel Vetter88548632015-12-04 09:45:48 +0100379 /**
380 * @reset:
381 *
382 * Reset CRTC hardware and software state to off. This function isn't
383 * called by the core directly, only through drm_mode_config_reset().
384 * It's not a helper hook only for historical reasons.
385 *
386 * Atomic drivers can use drm_atomic_helper_crtc_reset() to reset
387 * atomic state using this hook.
388 */
Chris Wilsoneb033552011-01-24 15:11:08 +0000389 void (*reset)(struct drm_crtc *crtc);
Dave Airlief453ba02008-11-07 14:05:41 -0800390
Daniel Vetterf6da8c62015-12-04 09:46:00 +0100391 /**
392 * @cursor_set:
393 *
394 * Update the cursor image. The cursor position is relative to the CRTC
395 * and can be partially or fully outside of the visible area.
396 *
397 * Note that contrary to all other KMS functions the legacy cursor entry
398 * points don't take a framebuffer object, but instead take directly a
399 * raw buffer object id from the driver's buffer manager (which is
400 * either GEM or TTM for current drivers).
401 *
402 * This entry point is deprecated, drivers should instead implement
403 * universal plane support and register a proper cursor plane using
404 * drm_crtc_init_with_planes().
405 *
406 * This callback is optional
407 *
408 * RETURNS:
409 *
410 * 0 on success or a negative error code on failure.
411 */
Dave Airlief453ba02008-11-07 14:05:41 -0800412 int (*cursor_set)(struct drm_crtc *crtc, struct drm_file *file_priv,
413 uint32_t handle, uint32_t width, uint32_t height);
Daniel Vetterf6da8c62015-12-04 09:46:00 +0100414
415 /**
416 * @cursor_set2:
417 *
418 * Update the cursor image, including hotspot information. The hotspot
419 * must not affect the cursor position in CRTC coordinates, but is only
420 * meant as a hint for virtualized display hardware to coordinate the
421 * guests and hosts cursor position. The cursor hotspot is relative to
422 * the cursor image. Otherwise this works exactly like @cursor_set.
423 *
424 * This entry point is deprecated, drivers should instead implement
425 * universal plane support and register a proper cursor plane using
426 * drm_crtc_init_with_planes().
427 *
428 * This callback is optional.
429 *
430 * RETURNS:
431 *
432 * 0 on success or a negative error code on failure.
433 */
Dave Airlie4c813d42013-06-20 11:48:52 +1000434 int (*cursor_set2)(struct drm_crtc *crtc, struct drm_file *file_priv,
435 uint32_t handle, uint32_t width, uint32_t height,
436 int32_t hot_x, int32_t hot_y);
Daniel Vetterf6da8c62015-12-04 09:46:00 +0100437
438 /**
439 * @cursor_move:
440 *
441 * Update the cursor position. The cursor does not need to be visible
442 * when this hook is called.
443 *
444 * This entry point is deprecated, drivers should instead implement
445 * universal plane support and register a proper cursor plane using
446 * drm_crtc_init_with_planes().
447 *
448 * This callback is optional.
449 *
450 * RETURNS:
451 *
452 * 0 on success or a negative error code on failure.
453 */
Dave Airlief453ba02008-11-07 14:05:41 -0800454 int (*cursor_move)(struct drm_crtc *crtc, int x, int y);
455
Daniel Vetterf6da8c62015-12-04 09:46:00 +0100456 /**
457 * @gamma_set:
458 *
459 * Set gamma on the CRTC.
460 *
461 * This callback is optional.
462 *
463 * NOTE:
464 *
465 * Drivers that support gamma tables and also fbdev emulation through
466 * the provided helper library need to take care to fill out the gamma
467 * hooks for both. Currently there's a bit an unfortunate duplication
468 * going on, which should eventually be unified to just one set of
469 * hooks.
470 */
Dave Airlief453ba02008-11-07 14:05:41 -0800471 void (*gamma_set)(struct drm_crtc *crtc, u16 *r, u16 *g, u16 *b,
James Simmons72034252010-08-03 01:33:19 +0100472 uint32_t start, uint32_t size);
Daniel Vetter88548632015-12-04 09:45:48 +0100473
474 /**
475 * @destroy:
476 *
477 * Clean up plane resources. This is only called at driver unload time
478 * through drm_mode_config_cleanup() since a CRTC cannot be hotplugged
479 * in DRM.
480 */
Dave Airlief453ba02008-11-07 14:05:41 -0800481 void (*destroy)(struct drm_crtc *crtc);
482
Daniel Vetterf6da8c62015-12-04 09:46:00 +0100483 /**
484 * @set_config:
485 *
486 * This is the main legacy entry point to change the modeset state on a
487 * CRTC. All the details of the desired configuration are passed in a
488 * struct &drm_mode_set - see there for details.
489 *
490 * Drivers implementing atomic modeset should use
491 * drm_atomic_helper_set_config() to implement this hook.
492 *
493 * RETURNS:
494 *
495 * 0 on success or a negative error code on failure.
496 */
Dave Airlief453ba02008-11-07 14:05:41 -0800497 int (*set_config)(struct drm_mode_set *set);
Kristian Høgsbergd91d8a32009-11-17 12:43:55 -0500498
Daniel Vetterf6da8c62015-12-04 09:46:00 +0100499 /**
500 * @page_flip:
501 *
502 * Legacy entry point to schedule a flip to the given framebuffer.
503 *
504 * Page flipping is a synchronization mechanism that replaces the frame
505 * buffer being scanned out by the CRTC with a new frame buffer during
506 * vertical blanking, avoiding tearing (except when requested otherwise
507 * through the DRM_MODE_PAGE_FLIP_ASYNC flag). When an application
508 * requests a page flip the DRM core verifies that the new frame buffer
509 * is large enough to be scanned out by the CRTC in the currently
510 * configured mode and then calls the CRTC ->page_flip() operation with a
511 * pointer to the new frame buffer.
512 *
513 * The driver must wait for any pending rendering to the new framebuffer
514 * to complete before executing the flip. It should also wait for any
515 * pending rendering from other drivers if the underlying buffer is a
516 * shared dma-buf.
517 *
518 * An application can request to be notified when the page flip has
519 * completed. The drm core will supply a struct &drm_event in the event
520 * parameter in this case. This can be handled by the
521 * drm_crtc_send_vblank_event() function, which the driver should call on
522 * the provided event upon completion of the flip. Note that if
523 * the driver supports vblank signalling and timestamping the vblank
524 * counters and timestamps must agree with the ones returned from page
525 * flip events. With the current vblank helper infrastructure this can
526 * be achieved by holding a vblank reference while the page flip is
527 * pending, acquired through drm_crtc_vblank_get() and released with
528 * drm_crtc_vblank_put(). Drivers are free to implement their own vblank
529 * counter and timestamp tracking though, e.g. if they have accurate
530 * timestamp registers in hardware.
531 *
532 * FIXME:
533 *
534 * Up to that point drivers need to manage events themselves and can use
535 * even->base.list freely for that. Specifically they need to ensure
536 * that they don't send out page flip (or vblank) events for which the
537 * corresponding drm file has been closed already. The drm core
538 * unfortunately does not (yet) take care of that. Therefore drivers
539 * currently must clean up and release pending events in their
540 * ->preclose driver function.
541 *
542 * This callback is optional.
543 *
544 * NOTE:
545 *
546 * Very early versions of the KMS ABI mandated that the driver must
547 * block (but not reject) any rendering to the old framebuffer until the
548 * flip operation has completed and the old framebuffer is no longer
549 * visible. This requirement has been lifted, and userspace is instead
550 * expected to request delivery of an event and wait with recycling old
551 * buffers until such has been received.
552 *
553 * RETURNS:
554 *
555 * 0 on success or a negative error code on failure. Note that if a
556 * ->page_flip() operation is already pending the callback should return
557 * -EBUSY. Pageflips on a disabled CRTC (either by setting a NULL mode
558 * or just runtime disabled through DPMS respectively the new atomic
Daniel Vetter4cba6852015-12-08 09:49:20 +0100559 * "ACTIVE" state) should result in an -EINVAL error code. Note that
560 * drm_atomic_helper_page_flip() checks this already for atomic drivers.
Kristian Høgsbergd91d8a32009-11-17 12:43:55 -0500561 */
562 int (*page_flip)(struct drm_crtc *crtc,
563 struct drm_framebuffer *fb,
Keith Packarded8d1972013-07-22 18:49:58 -0700564 struct drm_pending_vblank_event *event,
565 uint32_t flags);
Paulo Zanonibffd9de02012-05-15 18:09:05 -0300566
Daniel Vetter88548632015-12-04 09:45:48 +0100567 /**
568 * @set_property:
569 *
570 * This is the legacy entry point to update a property attached to the
571 * CRTC.
572 *
573 * Drivers implementing atomic modeset should use
574 * drm_atomic_helper_crtc_set_property() to implement this hook.
575 *
576 * This callback is optional if the driver does not support any legacy
577 * driver-private properties.
578 *
579 * RETURNS:
580 *
581 * 0 on success or a negative error code on failure.
582 */
Paulo Zanonibffd9de02012-05-15 18:09:05 -0300583 int (*set_property)(struct drm_crtc *crtc,
584 struct drm_property *property, uint64_t val);
Daniel Vetter144ecb92014-10-27 20:28:44 +0100585
Daniel Vetter88548632015-12-04 09:45:48 +0100586 /**
587 * @atomic_duplicate_state:
588 *
589 * Duplicate the current atomic state for this CRTC and return it.
590 * The core and helpers gurantee that any atomic state duplicated with
591 * this hook and still owned by the caller (i.e. not transferred to the
592 * driver by calling ->atomic_commit() from struct
593 * &drm_mode_config_funcs) will be cleaned up by calling the
594 * @atomic_destroy_state hook in this structure.
595 *
596 * Atomic drivers which don't subclass struct &drm_crtc should use
597 * drm_atomic_helper_crtc_duplicate_state(). Drivers that subclass the
598 * state structure to extend it with driver-private state should use
599 * __drm_atomic_helper_crtc_duplicate_state() to make sure shared state is
600 * duplicated in a consistent fashion across drivers.
601 *
602 * It is an error to call this hook before crtc->state has been
603 * initialized correctly.
604 *
605 * NOTE:
606 *
607 * If the duplicate state references refcounted resources this hook must
608 * acquire a reference for each of them. The driver must release these
609 * references again in @atomic_destroy_state.
610 *
611 * RETURNS:
612 *
613 * Duplicated atomic state or NULL when the allocation failed.
614 */
Daniel Vetter144ecb92014-10-27 20:28:44 +0100615 struct drm_crtc_state *(*atomic_duplicate_state)(struct drm_crtc *crtc);
Daniel Vetter88548632015-12-04 09:45:48 +0100616
617 /**
618 * @atomic_destroy_state:
619 *
620 * Destroy a state duplicated with @atomic_duplicate_state and release
621 * or unreference all resources it references
622 */
Daniel Vetter144ecb92014-10-27 20:28:44 +0100623 void (*atomic_destroy_state)(struct drm_crtc *crtc,
Daniel Vettercc4ceb42014-07-25 21:30:38 +0200624 struct drm_crtc_state *state);
Daniel Vetter88548632015-12-04 09:45:48 +0100625
626 /**
627 * @atomic_set_property:
628 *
629 * Decode a driver-private property value and store the decoded value
630 * into the passed-in state structure. Since the atomic core decodes all
631 * standardized properties (even for extensions beyond the core set of
632 * properties which might not be implemented by all drivers) this
633 * requires drivers to subclass the state structure.
634 *
635 * Such driver-private properties should really only be implemented for
636 * truly hardware/vendor specific state. Instead it is preferred to
637 * standardize atomic extension and decode the properties used to expose
638 * such an extension in the core.
639 *
640 * Do not call this function directly, use
641 * drm_atomic_crtc_set_property() instead.
642 *
643 * This callback is optional if the driver does not support any
644 * driver-private atomic properties.
645 *
646 * NOTE:
647 *
648 * This function is called in the state assembly phase of atomic
649 * modesets, which can be aborted for any reason (including on
650 * userspace's request to just check whether a configuration would be
651 * possible). Drivers MUST NOT touch any persistent state (hardware or
652 * software) or data structures except the passed in @state parameter.
653 *
654 * Also since userspace controls in which order properties are set this
655 * function must not do any input validation (since the state update is
656 * incomplete and hence likely inconsistent). Instead any such input
657 * validation must be done in the various atomic_check callbacks.
658 *
659 * RETURNS:
660 *
661 * 0 if the property has been found, -EINVAL if the property isn't
662 * implemented by the driver (which should never happen, the core only
663 * asks for properties attached to this CRTC). No other validation is
664 * allowed by the driver. The core already checks that the property
665 * value is within the range (integer, valid enum value, ...) the driver
666 * set when registering the property.
667 */
Daniel Vetter144ecb92014-10-27 20:28:44 +0100668 int (*atomic_set_property)(struct drm_crtc *crtc,
669 struct drm_crtc_state *state,
670 struct drm_property *property,
671 uint64_t val);
Daniel Vetter88548632015-12-04 09:45:48 +0100672 /**
673 * @atomic_get_property:
674 *
675 * Reads out the decoded driver-private property. This is used to
Daniel Vetterc6b0ca32015-12-04 09:46:01 +0100676 * implement the GETCRTC IOCTL.
Daniel Vetter88548632015-12-04 09:45:48 +0100677 *
678 * Do not call this function directly, use
679 * drm_atomic_crtc_get_property() instead.
680 *
681 * This callback is optional if the driver does not support any
682 * driver-private atomic properties.
683 *
684 * RETURNS:
685 *
686 * 0 on success, -EINVAL if the property isn't implemented by the
687 * driver (which should never happen, the core only asks for
688 * properties attached to this CRTC).
689 */
Rob Clarkac9c9252014-12-18 16:01:47 -0500690 int (*atomic_get_property)(struct drm_crtc *crtc,
691 const struct drm_crtc_state *state,
692 struct drm_property *property,
693 uint64_t *val);
Dave Airlief453ba02008-11-07 14:05:41 -0800694};
695
696/**
Daniel Vetter3bf04012014-10-27 16:54:27 +0100697 * struct drm_crtc - central CRTC control structure
Jesse Barnes77491632011-11-07 12:03:14 -0800698 * @dev: parent DRM device
Daniel Vetter2c0c33d2014-10-27 20:19:38 +0100699 * @port: OF node used by drm_of_find_possible_crtcs()
Jesse Barnes77491632011-11-07 12:03:14 -0800700 * @head: list management
Rob Clark51fd3712013-11-19 12:10:12 -0500701 * @mutex: per-CRTC locking
Jesse Barnes77491632011-11-07 12:03:14 -0800702 * @base: base KMS object for ID tracking etc.
Matt Ropere13161a2014-04-01 15:22:38 -0700703 * @primary: primary plane for this CRTC
704 * @cursor: cursor plane for this CRTC
Daniel Vetter2c0c33d2014-10-27 20:19:38 +0100705 * @cursor_x: current x position of the cursor, used for universal cursor planes
706 * @cursor_y: current y position of the cursor, used for universal cursor planes
Dave Airlief453ba02008-11-07 14:05:41 -0800707 * @enabled: is this CRTC enabled?
Jesse Barnes77491632011-11-07 12:03:14 -0800708 * @mode: current mode timings
709 * @hwmode: mode timings as programmed to hw regs
Dave Airlief453ba02008-11-07 14:05:41 -0800710 * @x: x position on screen
711 * @y: y position on screen
Dave Airlief453ba02008-11-07 14:05:41 -0800712 * @funcs: CRTC control functions
Jesse Barnes77491632011-11-07 12:03:14 -0800713 * @gamma_size: size of gamma ramp
714 * @gamma_store: gamma ramp values
Jesse Barnes77491632011-11-07 12:03:14 -0800715 * @helper_private: mid-layer private data
Paulo Zanonibffd9de02012-05-15 18:09:05 -0300716 * @properties: property tracking for this CRTC
Daniel Vetter144ecb92014-10-27 20:28:44 +0100717 * @state: current atomic state for this CRTC
Daniel Vetter2c0c33d2014-10-27 20:19:38 +0100718 * @acquire_ctx: per-CRTC implicit acquire context used by atomic drivers for
Daniel Vetterc6b0ca32015-12-04 09:46:01 +0100719 * legacy IOCTLs
Dave Airlief453ba02008-11-07 14:05:41 -0800720 *
721 * Each CRTC may have one or more connectors associated with it. This structure
722 * allows the CRTC to be controlled.
723 */
724struct drm_crtc {
725 struct drm_device *dev;
Russell King7e435aa2014-06-15 11:07:12 +0100726 struct device_node *port;
Dave Airlief453ba02008-11-07 14:05:41 -0800727 struct list_head head;
728
Ville Syrjäläfa3ab4c2015-12-08 18:41:53 +0200729 char *name;
730
Daniel Vetter3bf04012014-10-27 16:54:27 +0100731 /*
Daniel Vetter29494c12012-12-02 02:18:25 +0100732 * crtc mutex
733 *
734 * This provides a read lock for the overall crtc state (mode, dpms
735 * state, ...) and a write lock for everything which can be update
736 * without a full modeset (fb, cursor data, ...)
737 */
Rob Clark51fd3712013-11-19 12:10:12 -0500738 struct drm_modeset_lock mutex;
Daniel Vetter29494c12012-12-02 02:18:25 +0100739
Dave Airlief453ba02008-11-07 14:05:41 -0800740 struct drm_mode_object base;
741
Matt Ropere13161a2014-04-01 15:22:38 -0700742 /* primary and cursor planes for CRTC */
743 struct drm_plane *primary;
744 struct drm_plane *cursor;
745
Matt Roper161d0dc2014-06-10 08:28:10 -0700746 /* position of cursor plane on crtc */
747 int cursor_x;
748 int cursor_y;
749
Dave Airlief453ba02008-11-07 14:05:41 -0800750 bool enabled;
751
Mario Kleiner27641c32010-10-23 04:20:23 +0200752 /* Requested mode from modesetting. */
Dave Airlief453ba02008-11-07 14:05:41 -0800753 struct drm_display_mode mode;
754
Mario Kleiner27641c32010-10-23 04:20:23 +0200755 /* Programmed mode in hw, after adjustments for encoders,
756 * crtc, panel scaling etc. Needed for timestamping etc.
757 */
758 struct drm_display_mode hwmode;
759
Dave Airlief453ba02008-11-07 14:05:41 -0800760 int x, y;
Dave Airlief453ba02008-11-07 14:05:41 -0800761 const struct drm_crtc_funcs *funcs;
762
Lionel Landwerlin5488dc12016-02-26 17:05:00 +0000763 /* Legacy FB CRTC gamma size for reporting to userspace */
Dave Airlief453ba02008-11-07 14:05:41 -0800764 uint32_t gamma_size;
765 uint16_t *gamma_store;
766
767 /* if you are using the helper */
Daniel Vetter4490d4c2015-12-04 09:45:45 +0100768 const struct drm_crtc_helper_funcs *helper_private;
Paulo Zanonibffd9de02012-05-15 18:09:05 -0300769
770 struct drm_object_properties properties;
Daniel Vetterd059f652014-07-25 18:07:40 +0200771
Daniel Vetter144ecb92014-10-27 20:28:44 +0100772 struct drm_crtc_state *state;
773
Daniel Vetterd059f652014-07-25 18:07:40 +0200774 /*
Daniel Vetterc6b0ca32015-12-04 09:46:01 +0100775 * For legacy crtc IOCTLs so that atomic drivers can get at the locking
Daniel Vetterd059f652014-07-25 18:07:40 +0200776 * acquire context.
777 */
778 struct drm_modeset_acquire_ctx *acquire_ctx;
Dave Airlief453ba02008-11-07 14:05:41 -0800779};
780
Daniel Vetter144ecb92014-10-27 20:28:44 +0100781/**
782 * struct drm_connector_state - mutable connector state
Daniel Vetter07cc0ef2014-11-27 15:49:39 +0100783 * @connector: backpointer to the connector
Daniel Vettercc4ceb42014-07-25 21:30:38 +0200784 * @crtc: CRTC to connect connector to, NULL if disabled
Daniel Vetter623369e2014-09-16 17:50:47 +0200785 * @best_encoder: can be used by helpers and drivers to select the encoder
Daniel Vetter144ecb92014-10-27 20:28:44 +0100786 * @state: backpointer to global drm_atomic_state
787 */
788struct drm_connector_state {
Daniel Vetter07cc0ef2014-11-27 15:49:39 +0100789 struct drm_connector *connector;
790
Rob Clark6ddd3882014-11-21 15:28:31 -0500791 struct drm_crtc *crtc; /* do not write directly, use drm_atomic_set_crtc_for_connector() */
Daniel Vetter144ecb92014-10-27 20:28:44 +0100792
Daniel Vetter623369e2014-09-16 17:50:47 +0200793 struct drm_encoder *best_encoder;
794
Daniel Vetter144ecb92014-10-27 20:28:44 +0100795 struct drm_atomic_state *state;
796};
Dave Airlief453ba02008-11-07 14:05:41 -0800797
798/**
Daniel Vetter3bf04012014-10-27 16:54:27 +0100799 * struct drm_connector_funcs - control connectors on a given device
Daniel Vetter144ecb92014-10-27 20:28:44 +0100800 *
Dave Airlief453ba02008-11-07 14:05:41 -0800801 * Each CRTC may have one or more connectors attached to it. The functions
802 * below allow the core DRM code to control connectors, enumerate available modes,
803 * etc.
804 */
805struct drm_connector_funcs {
Daniel Vetter6fe14ac2015-12-04 09:45:58 +0100806 /**
807 * @dpms:
808 *
809 * Legacy entry point to set the per-connector DPMS state. Legacy DPMS
810 * is exposed as a standard property on the connector, but diverted to
811 * this callback in the drm core. Note that atomic drivers don't
812 * implement the 4 level DPMS support on the connector any more, but
813 * instead only have an on/off "ACTIVE" property on the CRTC object.
814 *
815 * Drivers implementing atomic modeset should use
816 * drm_atomic_helper_connector_dpms() to implement this hook.
817 *
818 * RETURNS:
819 *
820 * 0 on success or a negative error code on failure.
821 */
Maarten Lankhorst9a69a9a2015-07-21 11:34:55 +0200822 int (*dpms)(struct drm_connector *connector, int mode);
Daniel Vetter88548632015-12-04 09:45:48 +0100823
824 /**
825 * @reset:
826 *
827 * Reset connector hardware and software state to off. This function isn't
828 * called by the core directly, only through drm_mode_config_reset().
829 * It's not a helper hook only for historical reasons.
830 *
831 * Atomic drivers can use drm_atomic_helper_connector_reset() to reset
832 * atomic state using this hook.
833 */
Chris Wilsoneb033552011-01-24 15:11:08 +0000834 void (*reset)(struct drm_connector *connector);
Chris Wilson930a9e22010-09-14 11:07:23 +0100835
Daniel Vetter6fe14ac2015-12-04 09:45:58 +0100836 /**
837 * @detect:
838 *
839 * Check to see if anything is attached to the connector. The parameter
840 * force is set to false whilst polling, true when checking the
841 * connector due to a user request. force can be used by the driver to
842 * avoid expensive, destructive operations during automated probing.
843 *
844 * FIXME:
845 *
846 * Note that this hook is only called by the probe helper. It's not in
847 * the helper library vtable purely for historical reasons. The only DRM
848 * core entry point to probe connector state is @fill_modes.
849 *
850 * RETURNS:
851 *
852 * drm_connector_status indicating the connector's status.
Chris Wilson930a9e22010-09-14 11:07:23 +0100853 */
Chris Wilson7b334fc2010-09-09 23:51:02 +0100854 enum drm_connector_status (*detect)(struct drm_connector *connector,
Chris Wilson930a9e22010-09-14 11:07:23 +0100855 bool force);
Daniel Vetter6fe14ac2015-12-04 09:45:58 +0100856
857 /**
858 * @force:
859 *
860 * This function is called to update internal encoder state when the
861 * connector is forced to a certain state by userspace, either through
862 * the sysfs interfaces or on the kernel cmdline. In that case the
863 * @detect callback isn't called.
864 *
865 * FIXME:
866 *
867 * Note that this hook is only called by the probe helper. It's not in
868 * the helper library vtable purely for historical reasons. The only DRM
869 * core entry point to probe connector state is @fill_modes.
870 */
871 void (*force)(struct drm_connector *connector);
872
873 /**
874 * @fill_modes:
875 *
876 * Entry point for output detection and basic mode validation. The
877 * driver should reprobe the output if needed (e.g. when hotplug
878 * handling is unreliable), add all detected modes to connector->modes
879 * and filter out any the device can't support in any configuration. It
880 * also needs to filter out any modes wider or higher than the
881 * parameters max_width and max_height indicate.
882 *
883 * The drivers must also prune any modes no longer valid from
884 * connector->modes. Furthermore it must update connector->status and
885 * connector->edid. If no EDID has been received for this output
886 * connector->edid must be NULL.
887 *
888 * Drivers using the probe helpers should use
889 * drm_helper_probe_single_connector_modes() or
890 * drm_helper_probe_single_connector_modes_nomerge() to implement this
891 * function.
892 *
893 * RETURNS:
894 *
895 * The number of modes detected and filled into connector->modes.
896 */
Jesse Barnes40a518d2009-01-12 12:05:32 -0800897 int (*fill_modes)(struct drm_connector *connector, uint32_t max_width, uint32_t max_height);
Daniel Vetter88548632015-12-04 09:45:48 +0100898
899 /**
900 * @set_property:
901 *
902 * This is the legacy entry point to update a property attached to the
903 * connector.
904 *
905 * Drivers implementing atomic modeset should use
906 * drm_atomic_helper_connector_set_property() to implement this hook.
907 *
908 * This callback is optional if the driver does not support any legacy
909 * driver-private properties.
910 *
911 * RETURNS:
912 *
913 * 0 on success or a negative error code on failure.
914 */
Dave Airlief453ba02008-11-07 14:05:41 -0800915 int (*set_property)(struct drm_connector *connector, struct drm_property *property,
916 uint64_t val);
Daniel Vetter88548632015-12-04 09:45:48 +0100917
918 /**
919 * @destroy:
920 *
921 * Clean up connector resources. This is called at driver unload time
922 * through drm_mode_config_cleanup(). It can also be called at runtime
923 * when a connector is being hot-unplugged for drivers that support
924 * connector hotplugging (e.g. DisplayPort MST).
925 */
Dave Airlief453ba02008-11-07 14:05:41 -0800926 void (*destroy)(struct drm_connector *connector);
Daniel Vetter144ecb92014-10-27 20:28:44 +0100927
Daniel Vetter88548632015-12-04 09:45:48 +0100928 /**
929 * @atomic_duplicate_state:
930 *
931 * Duplicate the current atomic state for this connector and return it.
932 * The core and helpers gurantee that any atomic state duplicated with
933 * this hook and still owned by the caller (i.e. not transferred to the
934 * driver by calling ->atomic_commit() from struct
935 * &drm_mode_config_funcs) will be cleaned up by calling the
936 * @atomic_destroy_state hook in this structure.
937 *
938 * Atomic drivers which don't subclass struct &drm_connector_state should use
939 * drm_atomic_helper_connector_duplicate_state(). Drivers that subclass the
940 * state structure to extend it with driver-private state should use
941 * __drm_atomic_helper_connector_duplicate_state() to make sure shared state is
942 * duplicated in a consistent fashion across drivers.
943 *
944 * It is an error to call this hook before connector->state has been
945 * initialized correctly.
946 *
947 * NOTE:
948 *
949 * If the duplicate state references refcounted resources this hook must
950 * acquire a reference for each of them. The driver must release these
951 * references again in @atomic_destroy_state.
952 *
953 * RETURNS:
954 *
955 * Duplicated atomic state or NULL when the allocation failed.
956 */
Daniel Vetter144ecb92014-10-27 20:28:44 +0100957 struct drm_connector_state *(*atomic_duplicate_state)(struct drm_connector *connector);
Daniel Vetter88548632015-12-04 09:45:48 +0100958
959 /**
960 * @atomic_destroy_state:
961 *
962 * Destroy a state duplicated with @atomic_duplicate_state and release
963 * or unreference all resources it references
964 */
Daniel Vetter144ecb92014-10-27 20:28:44 +0100965 void (*atomic_destroy_state)(struct drm_connector *connector,
Daniel Vettercc4ceb42014-07-25 21:30:38 +0200966 struct drm_connector_state *state);
Daniel Vetter88548632015-12-04 09:45:48 +0100967
968 /**
969 * @atomic_set_property:
970 *
971 * Decode a driver-private property value and store the decoded value
972 * into the passed-in state structure. Since the atomic core decodes all
973 * standardized properties (even for extensions beyond the core set of
974 * properties which might not be implemented by all drivers) this
975 * requires drivers to subclass the state structure.
976 *
977 * Such driver-private properties should really only be implemented for
978 * truly hardware/vendor specific state. Instead it is preferred to
979 * standardize atomic extension and decode the properties used to expose
980 * such an extension in the core.
981 *
982 * Do not call this function directly, use
983 * drm_atomic_connector_set_property() instead.
984 *
985 * This callback is optional if the driver does not support any
986 * driver-private atomic properties.
987 *
988 * NOTE:
989 *
990 * This function is called in the state assembly phase of atomic
991 * modesets, which can be aborted for any reason (including on
992 * userspace's request to just check whether a configuration would be
993 * possible). Drivers MUST NOT touch any persistent state (hardware or
994 * software) or data structures except the passed in @state parameter.
995 *
996 * Also since userspace controls in which order properties are set this
997 * function must not do any input validation (since the state update is
998 * incomplete and hence likely inconsistent). Instead any such input
999 * validation must be done in the various atomic_check callbacks.
1000 *
1001 * RETURNS:
1002 *
1003 * 0 if the property has been found, -EINVAL if the property isn't
1004 * implemented by the driver (which shouldn't ever happen, the core only
1005 * asks for properties attached to this connector). No other validation
1006 * is allowed by the driver. The core already checks that the property
1007 * value is within the range (integer, valid enum value, ...) the driver
1008 * set when registering the property.
1009 */
Daniel Vetter144ecb92014-10-27 20:28:44 +01001010 int (*atomic_set_property)(struct drm_connector *connector,
1011 struct drm_connector_state *state,
1012 struct drm_property *property,
1013 uint64_t val);
Daniel Vetter88548632015-12-04 09:45:48 +01001014
1015 /**
1016 * @atomic_get_property:
1017 *
1018 * Reads out the decoded driver-private property. This is used to
Daniel Vetterc6b0ca32015-12-04 09:46:01 +01001019 * implement the GETCONNECTOR IOCTL.
Daniel Vetter88548632015-12-04 09:45:48 +01001020 *
1021 * Do not call this function directly, use
1022 * drm_atomic_connector_get_property() instead.
1023 *
1024 * This callback is optional if the driver does not support any
1025 * driver-private atomic properties.
1026 *
1027 * RETURNS:
1028 *
1029 * 0 on success, -EINVAL if the property isn't implemented by the
1030 * driver (which shouldn't ever happen, the core only asks for
1031 * properties attached to this connector).
1032 */
Rob Clarkac9c9252014-12-18 16:01:47 -05001033 int (*atomic_get_property)(struct drm_connector *connector,
1034 const struct drm_connector_state *state,
1035 struct drm_property *property,
1036 uint64_t *val);
Dave Airlief453ba02008-11-07 14:05:41 -08001037};
1038
Jesse Barnes6c3db922011-11-07 12:03:16 -08001039/**
Daniel Vetter3bf04012014-10-27 16:54:27 +01001040 * struct drm_encoder_funcs - encoder controls
Jesse Barnes6c3db922011-11-07 12:03:16 -08001041 *
1042 * Encoders sit between CRTCs and connectors.
1043 */
Dave Airlief453ba02008-11-07 14:05:41 -08001044struct drm_encoder_funcs {
Daniel Vetter88548632015-12-04 09:45:48 +01001045 /**
1046 * @reset:
1047 *
1048 * Reset encoder hardware and software state to off. This function isn't
1049 * called by the core directly, only through drm_mode_config_reset().
1050 * It's not a helper hook only for historical reasons.
1051 */
Chris Wilsoneb033552011-01-24 15:11:08 +00001052 void (*reset)(struct drm_encoder *encoder);
Daniel Vetter88548632015-12-04 09:45:48 +01001053
1054 /**
1055 * @destroy:
1056 *
1057 * Clean up encoder resources. This is only called at driver unload time
1058 * through drm_mode_config_cleanup() since an encoder cannot be
1059 * hotplugged in DRM.
1060 */
Dave Airlief453ba02008-11-07 14:05:41 -08001061 void (*destroy)(struct drm_encoder *encoder);
1062};
1063
Ben Skeggsafe887d2012-01-12 16:00:57 +10001064#define DRM_CONNECTOR_MAX_ENCODER 3
Dave Airlief453ba02008-11-07 14:05:41 -08001065
1066/**
Daniel Vetter3bf04012014-10-27 16:54:27 +01001067 * struct drm_encoder - central DRM encoder structure
Jesse Barnesdb3e4492011-11-07 12:03:17 -08001068 * @dev: parent DRM device
1069 * @head: list management
1070 * @base: base KMS object
Jani Nikulae5748942014-05-14 16:58:20 +03001071 * @name: encoder name
Jesse Barnesdb3e4492011-11-07 12:03:17 -08001072 * @encoder_type: one of the %DRM_MODE_ENCODER_<foo> types in drm_mode.h
1073 * @possible_crtcs: bitmask of potential CRTC bindings
1074 * @possible_clones: bitmask of potential sibling encoders for cloning
1075 * @crtc: currently bound CRTC
Sean Paul3b336ec2013-08-14 16:47:37 -04001076 * @bridge: bridge associated to the encoder
Jesse Barnesdb3e4492011-11-07 12:03:17 -08001077 * @funcs: control functions
1078 * @helper_private: mid-layer private data
1079 *
1080 * CRTCs drive pixels to encoders, which convert them into signals
1081 * appropriate for a given connector or set of connectors.
Dave Airlief453ba02008-11-07 14:05:41 -08001082 */
1083struct drm_encoder {
1084 struct drm_device *dev;
1085 struct list_head head;
1086
1087 struct drm_mode_object base;
Jani Nikulae5748942014-05-14 16:58:20 +03001088 char *name;
Dave Airlief453ba02008-11-07 14:05:41 -08001089 int encoder_type;
1090 uint32_t possible_crtcs;
1091 uint32_t possible_clones;
1092
1093 struct drm_crtc *crtc;
Sean Paul3b336ec2013-08-14 16:47:37 -04001094 struct drm_bridge *bridge;
Dave Airlief453ba02008-11-07 14:05:41 -08001095 const struct drm_encoder_funcs *funcs;
Daniel Vetter4490d4c2015-12-04 09:45:45 +01001096 const struct drm_encoder_helper_funcs *helper_private;
Dave Airlief453ba02008-11-07 14:05:41 -08001097};
1098
Dave Airlieeb1f8e42010-05-07 06:42:51 +00001099/* should we poll this connector for connects and disconnects */
1100/* hot plug detectable */
1101#define DRM_CONNECTOR_POLL_HPD (1 << 0)
1102/* poll for connections */
1103#define DRM_CONNECTOR_POLL_CONNECT (1 << 1)
1104/* can cleanly poll for disconnections without flickering the screen */
1105/* DACs should rarely do this without a lot of testing */
1106#define DRM_CONNECTOR_POLL_DISCONNECT (1 << 2)
1107
Wu Fengguang76adaa342011-09-05 14:23:20 +08001108#define MAX_ELD_BYTES 128
1109
Dave Airlief453ba02008-11-07 14:05:41 -08001110/**
Daniel Vetter3bf04012014-10-27 16:54:27 +01001111 * struct drm_connector - central DRM connector control structure
Jesse Barnes72252542011-11-07 12:03:18 -08001112 * @dev: parent DRM device
1113 * @kdev: kernel device for sysfs attributes
1114 * @attr: sysfs attributes
1115 * @head: list management
1116 * @base: base KMS object
Jani Nikula2abdd312014-05-14 16:58:19 +03001117 * @name: connector name
Jesse Barnes72252542011-11-07 12:03:18 -08001118 * @connector_type: one of the %DRM_MODE_CONNECTOR_<foo> types from drm_mode.h
1119 * @connector_type_id: index into connector type enum
Dave Airlief453ba02008-11-07 14:05:41 -08001120 * @interlace_allowed: can this connector handle interlaced modes?
1121 * @doublescan_allowed: can this connector handle doublescan?
Daniel Vetter2c0c33d2014-10-27 20:19:38 +01001122 * @stereo_allowed: can this connector handle stereo modes?
Jesse Barnes72252542011-11-07 12:03:18 -08001123 * @modes: modes available on this connector (from fill_modes() + user)
1124 * @status: one of the drm_connector_status enums (connected, not, or unknown)
1125 * @probed_modes: list of modes derived directly from the display
1126 * @display_info: information about attached display (e.g. from EDID)
Dave Airlief453ba02008-11-07 14:05:41 -08001127 * @funcs: connector control functions
Jesse Barnes72252542011-11-07 12:03:18 -08001128 * @edid_blob_ptr: DRM property containing EDID if present
Paulo Zanoni7e3bdf42012-05-15 18:09:01 -03001129 * @properties: property tracking for this connector
Daniel Vetter2c0c33d2014-10-27 20:19:38 +01001130 * @path_blob_ptr: DRM blob property data for the DP MST path property
Jesse Barnes72252542011-11-07 12:03:18 -08001131 * @polled: a %DRM_CONNECTOR_POLL_<foo> value for core driven polling
1132 * @dpms: current dpms state
1133 * @helper_private: mid-layer private data
Daniel Vetter2c0c33d2014-10-27 20:19:38 +01001134 * @cmdline_mode: mode line parsed from the kernel cmdline for this connector
Jesse Barnes72252542011-11-07 12:03:18 -08001135 * @force: a %DRM_FORCE_<foo> state for forced mode sets
Daniel Vetter2c0c33d2014-10-27 20:19:38 +01001136 * @override_edid: has the EDID been overwritten through debugfs for testing?
Jesse Barnes72252542011-11-07 12:03:18 -08001137 * @encoder_ids: valid encoders for this connector
1138 * @encoder: encoder driving this connector, if any
1139 * @eld: EDID-like data, if present
1140 * @dvi_dual: dual link DVI, if found
1141 * @max_tmds_clock: max clock rate, if found
1142 * @latency_present: AV delay info from ELD, if found
1143 * @video_latency: video latency info from ELD, if found
1144 * @audio_latency: audio latency info from ELD, if found
1145 * @null_edid_counter: track sinks that give us all zeros for the EDID
Daniel Vetter2c0c33d2014-10-27 20:19:38 +01001146 * @bad_edid_counter: track sinks that give us an EDID with invalid checksum
Daniel Vetterac6f2e22015-05-08 16:15:41 +02001147 * @edid_corrupt: indicates whether the last read EDID was corrupt
Daniel Vetter2c0c33d2014-10-27 20:19:38 +01001148 * @debugfs_entry: debugfs directory for this connector
Daniel Vetter144ecb92014-10-27 20:28:44 +01001149 * @state: current atomic state for this connector
Dave Airlie40d9b042014-10-20 16:29:33 +10001150 * @has_tile: is this connector connected to a tiled monitor
1151 * @tile_group: tile group for the connected monitor
1152 * @tile_is_single_monitor: whether the tile is one monitor housing
1153 * @num_h_tile: number of horizontal tiles in the tile group
1154 * @num_v_tile: number of vertical tiles in the tile group
1155 * @tile_h_loc: horizontal location of this tile
1156 * @tile_v_loc: vertical location of this tile
1157 * @tile_h_size: horizontal size of this tile.
1158 * @tile_v_size: vertical size of this tile.
Dave Airlief453ba02008-11-07 14:05:41 -08001159 *
1160 * Each connector may be connected to one or more CRTCs, or may be clonable by
1161 * another connector if they can share a CRTC. Each connector also has a specific
1162 * position in the broader display (referred to as a 'screen' though it could
1163 * span multiple monitors).
1164 */
1165struct drm_connector {
1166 struct drm_device *dev;
Dave Airlie5bdebb12013-10-11 14:07:25 +10001167 struct device *kdev;
Dave Airlief453ba02008-11-07 14:05:41 -08001168 struct device_attribute *attr;
1169 struct list_head head;
1170
1171 struct drm_mode_object base;
1172
Jani Nikula2abdd312014-05-14 16:58:19 +03001173 char *name;
Maarten Lankhorst5fff80b2016-02-17 08:32:05 +01001174 int connector_id;
Dave Airlief453ba02008-11-07 14:05:41 -08001175 int connector_type;
1176 int connector_type_id;
1177 bool interlace_allowed;
1178 bool doublescan_allowed;
Damien Lespiau560a0672013-09-25 16:45:29 +01001179 bool stereo_allowed;
Dave Airlief453ba02008-11-07 14:05:41 -08001180 struct list_head modes; /* list of modes on this connector */
1181
Dave Airlief453ba02008-11-07 14:05:41 -08001182 enum drm_connector_status status;
1183
1184 /* these are modes added by probing with DDC or the BIOS */
1185 struct list_head probed_modes;
1186
1187 struct drm_display_info display_info;
1188 const struct drm_connector_funcs *funcs;
1189
Dave Airlief453ba02008-11-07 14:05:41 -08001190 struct drm_property_blob *edid_blob_ptr;
Paulo Zanoni7e3bdf42012-05-15 18:09:01 -03001191 struct drm_object_properties properties;
Dave Airlief453ba02008-11-07 14:05:41 -08001192
Dave Airlie43aba7e2014-06-05 14:01:31 +10001193 struct drm_property_blob *path_blob_ptr;
1194
Dave Airlie6f134d72014-10-20 16:30:50 +10001195 struct drm_property_blob *tile_blob_ptr;
1196
Dave Airlieeb1f8e42010-05-07 06:42:51 +00001197 uint8_t polled; /* DRM_CONNECTOR_POLL_* */
1198
Keith Packardc9fb15f2009-05-30 20:42:28 -07001199 /* requested DPMS state */
1200 int dpms;
1201
Daniel Vetter4490d4c2015-12-04 09:45:45 +01001202 const struct drm_connector_helper_funcs *helper_private;
Dave Airlief453ba02008-11-07 14:05:41 -08001203
Dave Airlied50ba252009-09-23 14:44:08 +10001204 /* forced on connector */
Chris Wilsoneaf99c72014-08-06 10:08:32 +02001205 struct drm_cmdline_mode cmdline_mode;
Dave Airlied50ba252009-09-23 14:44:08 +10001206 enum drm_connector_force force;
Thomas Wood4cf2b282014-06-18 17:52:33 +01001207 bool override_edid;
Dave Airlief453ba02008-11-07 14:05:41 -08001208 uint32_t encoder_ids[DRM_CONNECTOR_MAX_ENCODER];
Dave Airlief453ba02008-11-07 14:05:41 -08001209 struct drm_encoder *encoder; /* currently active encoder */
Dave Airlie4a9a8b72011-06-14 06:13:55 +00001210
Wu Fengguang76adaa342011-09-05 14:23:20 +08001211 /* EDID bits */
1212 uint8_t eld[MAX_ELD_BYTES];
1213 bool dvi_dual;
1214 int max_tmds_clock; /* in MHz */
1215 bool latency_present[2];
1216 int video_latency[2]; /* [0]: progressive, [1]: interlaced */
1217 int audio_latency[2];
Dave Airlie4a9a8b72011-06-14 06:13:55 +00001218 int null_edid_counter; /* needed to workaround some HW bugs where we get all 0s */
Jerome Glisse0b2443e2012-08-09 11:25:51 -04001219 unsigned bad_edid_counter;
Thomas Wood30f65702014-06-18 17:52:32 +01001220
Todd Previte6ba2bd32015-04-21 11:09:41 -07001221 /* Flag for raw EDID header corruption - used in Displayport
1222 * compliance testing - * Displayport Link CTS Core 1.2 rev1.1 4.2.2.6
1223 */
1224 bool edid_corrupt;
1225
Thomas Wood30f65702014-06-18 17:52:32 +01001226 struct dentry *debugfs_entry;
Daniel Vetter144ecb92014-10-27 20:28:44 +01001227
1228 struct drm_connector_state *state;
Dave Airlie40d9b042014-10-20 16:29:33 +10001229
1230 /* DisplayID bits */
1231 bool has_tile;
1232 struct drm_tile_group *tile_group;
1233 bool tile_is_single_monitor;
1234
1235 uint8_t num_h_tile, num_v_tile;
1236 uint8_t tile_h_loc, tile_v_loc;
1237 uint16_t tile_h_size, tile_v_size;
Dave Airlief453ba02008-11-07 14:05:41 -08001238};
1239
1240/**
Daniel Vetter144ecb92014-10-27 20:28:44 +01001241 * struct drm_plane_state - mutable plane state
Daniel Vetter07cc0ef2014-11-27 15:49:39 +01001242 * @plane: backpointer to the plane
Daniel Vetter144ecb92014-10-27 20:28:44 +01001243 * @crtc: currently bound CRTC, NULL if disabled
Daniel Vettercc4ceb42014-07-25 21:30:38 +02001244 * @fb: currently bound framebuffer
Daniel Vettere2330f02014-10-29 11:34:56 +01001245 * @fence: optional fence to wait for before scanning out @fb
Daniel Vetter144ecb92014-10-27 20:28:44 +01001246 * @crtc_x: left position of visible portion of plane on crtc
1247 * @crtc_y: upper position of visible portion of plane on crtc
1248 * @crtc_w: width of visible portion of plane on crtc
1249 * @crtc_h: height of visible portion of plane on crtc
1250 * @src_x: left position of visible portion of plane within
1251 * plane (in 16.16)
1252 * @src_y: upper position of visible portion of plane within
1253 * plane (in 16.16)
1254 * @src_w: width of visible portion of plane (in 16.16)
1255 * @src_h: height of visible portion of plane (in 16.16)
1256 * @state: backpointer to global drm_atomic_state
1257 */
1258struct drm_plane_state {
Daniel Vetter07cc0ef2014-11-27 15:49:39 +01001259 struct drm_plane *plane;
1260
Rob Clark6ddd3882014-11-21 15:28:31 -05001261 struct drm_crtc *crtc; /* do not write directly, use drm_atomic_set_crtc_for_plane() */
1262 struct drm_framebuffer *fb; /* do not write directly, use drm_atomic_set_fb_for_plane() */
Daniel Vettere2330f02014-10-29 11:34:56 +01001263 struct fence *fence;
Daniel Vetter144ecb92014-10-27 20:28:44 +01001264
1265 /* Signed dest location allows it to be partially off screen */
1266 int32_t crtc_x, crtc_y;
1267 uint32_t crtc_w, crtc_h;
1268
1269 /* Source values are 16.16 fixed point */
1270 uint32_t src_x, src_y;
1271 uint32_t src_h, src_w;
1272
Matt Roper1da30622015-01-21 16:35:40 -08001273 /* Plane rotation */
1274 unsigned int rotation;
1275
Daniel Vetter144ecb92014-10-27 20:28:44 +01001276 struct drm_atomic_state *state;
1277};
1278
1279
1280/**
Daniel Vetter3bf04012014-10-27 16:54:27 +01001281 * struct drm_plane_funcs - driver plane control functions
Jesse Barnes8cf5c912011-11-14 14:51:27 -08001282 */
1283struct drm_plane_funcs {
Daniel Vetter88548632015-12-04 09:45:48 +01001284 /**
1285 * @update_plane:
1286 *
1287 * This is the legacy entry point to enable and configure the plane for
1288 * the given CRTC and framebuffer. It is never called to disable the
1289 * plane, i.e. the passed-in crtc and fb paramters are never NULL.
1290 *
1291 * The source rectangle in frame buffer memory coordinates is given by
1292 * the src_x, src_y, src_w and src_h parameters (as 16.16 fixed point
1293 * values). Devices that don't support subpixel plane coordinates can
1294 * ignore the fractional part.
1295 *
1296 * The destination rectangle in CRTC coordinates is given by the
1297 * crtc_x, crtc_y, crtc_w and crtc_h parameters (as integer values).
1298 * Devices scale the source rectangle to the destination rectangle. If
1299 * scaling is not supported, and the source rectangle size doesn't match
1300 * the destination rectangle size, the driver must return a
1301 * -<errorname>EINVAL</errorname> error.
1302 *
1303 * Drivers implementing atomic modeset should use
1304 * drm_atomic_helper_update_plane() to implement this hook.
1305 *
1306 * RETURNS:
1307 *
1308 * 0 on success or a negative error code on failure.
1309 */
Jesse Barnes8cf5c912011-11-14 14:51:27 -08001310 int (*update_plane)(struct drm_plane *plane,
1311 struct drm_crtc *crtc, struct drm_framebuffer *fb,
1312 int crtc_x, int crtc_y,
1313 unsigned int crtc_w, unsigned int crtc_h,
1314 uint32_t src_x, uint32_t src_y,
1315 uint32_t src_w, uint32_t src_h);
Daniel Vetter88548632015-12-04 09:45:48 +01001316
1317 /**
1318 * @disable_plane:
1319 *
1320 * This is the legacy entry point to disable the plane. The DRM core
Daniel Vetterc6b0ca32015-12-04 09:46:01 +01001321 * calls this method in response to a DRM_IOCTL_MODE_SETPLANE IOCTL call
Daniel Vetter88548632015-12-04 09:45:48 +01001322 * with the frame buffer ID set to 0. Disabled planes must not be
1323 * processed by the CRTC.
1324 *
1325 * Drivers implementing atomic modeset should use
1326 * drm_atomic_helper_disable_plane() to implement this hook.
1327 *
1328 * RETURNS:
1329 *
1330 * 0 on success or a negative error code on failure.
1331 */
Jesse Barnes8cf5c912011-11-14 14:51:27 -08001332 int (*disable_plane)(struct drm_plane *plane);
Daniel Vetter88548632015-12-04 09:45:48 +01001333
1334 /**
1335 * @destroy:
1336 *
1337 * Clean up plane resources. This is only called at driver unload time
1338 * through drm_mode_config_cleanup() since a plane cannot be hotplugged
1339 * in DRM.
1340 */
Jesse Barnes8cf5c912011-11-14 14:51:27 -08001341 void (*destroy)(struct drm_plane *plane);
Daniel Vetter88548632015-12-04 09:45:48 +01001342
1343 /**
1344 * @reset:
1345 *
1346 * Reset plane hardware and software state to off. This function isn't
1347 * called by the core directly, only through drm_mode_config_reset().
1348 * It's not a helper hook only for historical reasons.
1349 *
1350 * Atomic drivers can use drm_atomic_helper_plane_reset() to reset
1351 * atomic state using this hook.
1352 */
Daniel Vetter2a0d7cf2014-07-29 15:32:37 +02001353 void (*reset)(struct drm_plane *plane);
Rob Clark4d939142012-05-17 02:23:27 -06001354
Daniel Vetter88548632015-12-04 09:45:48 +01001355 /**
1356 * @set_property:
1357 *
1358 * This is the legacy entry point to update a property attached to the
1359 * plane.
1360 *
1361 * Drivers implementing atomic modeset should use
1362 * drm_atomic_helper_plane_set_property() to implement this hook.
1363 *
1364 * This callback is optional if the driver does not support any legacy
1365 * driver-private properties.
1366 *
1367 * RETURNS:
1368 *
1369 * 0 on success or a negative error code on failure.
1370 */
Rob Clark4d939142012-05-17 02:23:27 -06001371 int (*set_property)(struct drm_plane *plane,
1372 struct drm_property *property, uint64_t val);
Daniel Vetter144ecb92014-10-27 20:28:44 +01001373
Daniel Vetter88548632015-12-04 09:45:48 +01001374 /**
1375 * @atomic_duplicate_state:
1376 *
1377 * Duplicate the current atomic state for this plane and return it.
1378 * The core and helpers gurantee that any atomic state duplicated with
1379 * this hook and still owned by the caller (i.e. not transferred to the
1380 * driver by calling ->atomic_commit() from struct
1381 * &drm_mode_config_funcs) will be cleaned up by calling the
1382 * @atomic_destroy_state hook in this structure.
1383 *
1384 * Atomic drivers which don't subclass struct &drm_plane_state should use
1385 * drm_atomic_helper_plane_duplicate_state(). Drivers that subclass the
1386 * state structure to extend it with driver-private state should use
1387 * __drm_atomic_helper_plane_duplicate_state() to make sure shared state is
1388 * duplicated in a consistent fashion across drivers.
1389 *
1390 * It is an error to call this hook before plane->state has been
1391 * initialized correctly.
1392 *
1393 * NOTE:
1394 *
1395 * If the duplicate state references refcounted resources this hook must
1396 * acquire a reference for each of them. The driver must release these
1397 * references again in @atomic_destroy_state.
1398 *
1399 * RETURNS:
1400 *
1401 * Duplicated atomic state or NULL when the allocation failed.
1402 */
Daniel Vetter144ecb92014-10-27 20:28:44 +01001403 struct drm_plane_state *(*atomic_duplicate_state)(struct drm_plane *plane);
Daniel Vetter88548632015-12-04 09:45:48 +01001404
1405 /**
1406 * @atomic_destroy_state:
1407 *
1408 * Destroy a state duplicated with @atomic_duplicate_state and release
1409 * or unreference all resources it references
1410 */
Daniel Vetter144ecb92014-10-27 20:28:44 +01001411 void (*atomic_destroy_state)(struct drm_plane *plane,
Daniel Vettercc4ceb42014-07-25 21:30:38 +02001412 struct drm_plane_state *state);
Daniel Vetter88548632015-12-04 09:45:48 +01001413
1414 /**
1415 * @atomic_set_property:
1416 *
1417 * Decode a driver-private property value and store the decoded value
1418 * into the passed-in state structure. Since the atomic core decodes all
1419 * standardized properties (even for extensions beyond the core set of
1420 * properties which might not be implemented by all drivers) this
1421 * requires drivers to subclass the state structure.
1422 *
1423 * Such driver-private properties should really only be implemented for
1424 * truly hardware/vendor specific state. Instead it is preferred to
1425 * standardize atomic extension and decode the properties used to expose
1426 * such an extension in the core.
1427 *
1428 * Do not call this function directly, use
1429 * drm_atomic_plane_set_property() instead.
1430 *
1431 * This callback is optional if the driver does not support any
1432 * driver-private atomic properties.
1433 *
1434 * NOTE:
1435 *
1436 * This function is called in the state assembly phase of atomic
1437 * modesets, which can be aborted for any reason (including on
1438 * userspace's request to just check whether a configuration would be
1439 * possible). Drivers MUST NOT touch any persistent state (hardware or
1440 * software) or data structures except the passed in @state parameter.
1441 *
1442 * Also since userspace controls in which order properties are set this
1443 * function must not do any input validation (since the state update is
1444 * incomplete and hence likely inconsistent). Instead any such input
1445 * validation must be done in the various atomic_check callbacks.
1446 *
1447 * RETURNS:
1448 *
1449 * 0 if the property has been found, -EINVAL if the property isn't
1450 * implemented by the driver (which shouldn't ever happen, the core only
1451 * asks for properties attached to this plane). No other validation is
1452 * allowed by the driver. The core already checks that the property
1453 * value is within the range (integer, valid enum value, ...) the driver
1454 * set when registering the property.
1455 */
Daniel Vetter144ecb92014-10-27 20:28:44 +01001456 int (*atomic_set_property)(struct drm_plane *plane,
1457 struct drm_plane_state *state,
1458 struct drm_property *property,
1459 uint64_t val);
Daniel Vetter88548632015-12-04 09:45:48 +01001460
1461 /**
1462 * @atomic_get_property:
1463 *
1464 * Reads out the decoded driver-private property. This is used to
Daniel Vetterc6b0ca32015-12-04 09:46:01 +01001465 * implement the GETPLANE IOCTL.
Daniel Vetter88548632015-12-04 09:45:48 +01001466 *
1467 * Do not call this function directly, use
1468 * drm_atomic_plane_get_property() instead.
1469 *
1470 * This callback is optional if the driver does not support any
1471 * driver-private atomic properties.
1472 *
1473 * RETURNS:
1474 *
1475 * 0 on success, -EINVAL if the property isn't implemented by the
1476 * driver (which should never happen, the core only asks for
1477 * properties attached to this plane).
1478 */
Rob Clarkac9c9252014-12-18 16:01:47 -05001479 int (*atomic_get_property)(struct drm_plane *plane,
1480 const struct drm_plane_state *state,
1481 struct drm_property *property,
1482 uint64_t *val);
Jesse Barnes8cf5c912011-11-14 14:51:27 -08001483};
1484
Matt Ropere27dde32014-04-01 15:22:30 -07001485enum drm_plane_type {
1486 DRM_PLANE_TYPE_OVERLAY,
1487 DRM_PLANE_TYPE_PRIMARY,
1488 DRM_PLANE_TYPE_CURSOR,
1489};
1490
Daniel Vetter88548632015-12-04 09:45:48 +01001491
Jesse Barnes8cf5c912011-11-14 14:51:27 -08001492/**
Daniel Vetter3bf04012014-10-27 16:54:27 +01001493 * struct drm_plane - central DRM plane control structure
Jesse Barnes8cf5c912011-11-14 14:51:27 -08001494 * @dev: DRM device this plane belongs to
1495 * @head: for list management
1496 * @base: base mode object
1497 * @possible_crtcs: pipes this plane can be bound to
1498 * @format_types: array of formats supported by this plane
1499 * @format_count: number of formats supported
Laurent Pinchart7eb5f302015-03-09 10:41:07 +02001500 * @format_default: driver hasn't supplied supported formats for the plane
Jesse Barnes8cf5c912011-11-14 14:51:27 -08001501 * @crtc: currently bound CRTC
1502 * @fb: currently bound fb
Daniel Vetter2c0c33d2014-10-27 20:19:38 +01001503 * @old_fb: Temporary tracking of the old fb while a modeset is ongoing. Used by
1504 * drm_mode_set_config_internal() to implement correct refcounting.
Jesse Barnes8cf5c912011-11-14 14:51:27 -08001505 * @funcs: helper functions
Rob Clark4d939142012-05-17 02:23:27 -06001506 * @properties: property tracking for this plane
Matt Ropere27dde32014-04-01 15:22:30 -07001507 * @type: type of plane (overlay, primary, cursor)
Daniel Vetter144ecb92014-10-27 20:28:44 +01001508 * @state: current atomic state for this plane
Jesse Barnes8cf5c912011-11-14 14:51:27 -08001509 */
1510struct drm_plane {
1511 struct drm_device *dev;
1512 struct list_head head;
1513
Ville Syrjälä9f4c97a2015-12-08 18:41:54 +02001514 char *name;
1515
Daniel Vetter4d02e2d2014-11-11 10:12:00 +01001516 struct drm_modeset_lock mutex;
1517
Jesse Barnes8cf5c912011-11-14 14:51:27 -08001518 struct drm_mode_object base;
1519
1520 uint32_t possible_crtcs;
1521 uint32_t *format_types;
Thierry Reding45e37432015-08-12 16:54:28 +02001522 unsigned int format_count;
Laurent Pinchart7eb5f302015-03-09 10:41:07 +02001523 bool format_default;
Jesse Barnes8cf5c912011-11-14 14:51:27 -08001524
1525 struct drm_crtc *crtc;
1526 struct drm_framebuffer *fb;
1527
Daniel Vetter3d30a592014-07-27 13:42:42 +02001528 struct drm_framebuffer *old_fb;
1529
Jesse Barnes8cf5c912011-11-14 14:51:27 -08001530 const struct drm_plane_funcs *funcs;
Rob Clark4d939142012-05-17 02:23:27 -06001531
1532 struct drm_object_properties properties;
Matt Ropere27dde32014-04-01 15:22:30 -07001533
1534 enum drm_plane_type type;
Daniel Vetter144ecb92014-10-27 20:28:44 +01001535
Daniel Vetter4490d4c2015-12-04 09:45:45 +01001536 const struct drm_plane_helper_funcs *helper_private;
Daniel Vetterc2fcd272014-11-05 00:14:14 +01001537
Daniel Vetter144ecb92014-10-27 20:28:44 +01001538 struct drm_plane_state *state;
Jesse Barnes8cf5c912011-11-14 14:51:27 -08001539};
1540
1541/**
Daniel Vetter3bf04012014-10-27 16:54:27 +01001542 * struct drm_bridge_funcs - drm_bridge control functions
Ajay Kumar3d3f8b12015-01-20 22:08:44 +05301543 * @attach: Called during drm_bridge_attach
Sean Paul3b336ec2013-08-14 16:47:37 -04001544 */
1545struct drm_bridge_funcs {
Ajay Kumar3d3f8b12015-01-20 22:08:44 +05301546 int (*attach)(struct drm_bridge *bridge);
Daniel Vetterda024fe2015-12-04 09:45:47 +01001547
1548 /**
1549 * @mode_fixup:
1550 *
1551 * This callback is used to validate and adjust a mode. The paramater
1552 * mode is the display mode that should be fed to the next element in
1553 * the display chain, either the final &drm_connector or the next
1554 * &drm_bridge. The parameter adjusted_mode is the input mode the bridge
1555 * requires. It can be modified by this callback and does not need to
1556 * match mode.
1557 *
1558 * This is the only hook that allows a bridge to reject a modeset. If
1559 * this function passes all other callbacks must succeed for this
1560 * configuration.
1561 *
1562 * NOTE:
1563 *
1564 * This function is called in the check phase of atomic modesets, which
1565 * can be aborted for any reason (including on userspace's request to
1566 * just check whether a configuration would be possible). Drivers MUST
1567 * NOT touch any persistent state (hardware or software) or data
Daniel Vetter88548632015-12-04 09:45:48 +01001568 * structures except the passed in @state parameter.
Daniel Vetterda024fe2015-12-04 09:45:47 +01001569 *
1570 * RETURNS:
1571 *
1572 * True if an acceptable configuration is possible, false if the modeset
1573 * operation should be rejected.
1574 */
Sean Paul3b336ec2013-08-14 16:47:37 -04001575 bool (*mode_fixup)(struct drm_bridge *bridge,
1576 const struct drm_display_mode *mode,
1577 struct drm_display_mode *adjusted_mode);
Daniel Vetterda024fe2015-12-04 09:45:47 +01001578 /**
1579 * @disable:
1580 *
1581 * This callback should disable the bridge. It is called right before
1582 * the preceding element in the display pipe is disabled. If the
1583 * preceding element is a bridge this means it's called before that
1584 * bridge's ->disable() function. If the preceding element is a
1585 * &drm_encoder it's called right before the encoder's ->disable(),
1586 * ->prepare() or ->dpms() hook from struct &drm_encoder_helper_funcs.
1587 *
1588 * The bridge can assume that the display pipe (i.e. clocks and timing
1589 * signals) feeding it is still running when this callback is called.
Laurent Pinchartc8a3b2a2016-02-26 11:51:06 +02001590 *
1591 * The disable callback is optional.
Daniel Vetterda024fe2015-12-04 09:45:47 +01001592 */
Sean Paul3b336ec2013-08-14 16:47:37 -04001593 void (*disable)(struct drm_bridge *bridge);
Daniel Vetterda024fe2015-12-04 09:45:47 +01001594
1595 /**
1596 * @post_disable:
1597 *
1598 * This callback should disable the bridge. It is called right after
1599 * the preceding element in the display pipe is disabled. If the
1600 * preceding element is a bridge this means it's called after that
1601 * bridge's ->post_disable() function. If the preceding element is a
1602 * &drm_encoder it's called right after the encoder's ->disable(),
1603 * ->prepare() or ->dpms() hook from struct &drm_encoder_helper_funcs.
1604 *
1605 * The bridge must assume that the display pipe (i.e. clocks and timing
1606 * singals) feeding it is no longer running when this callback is
1607 * called.
Laurent Pinchartc8a3b2a2016-02-26 11:51:06 +02001608 *
1609 * The post_disable callback is optional.
Daniel Vetterda024fe2015-12-04 09:45:47 +01001610 */
Sean Paul3b336ec2013-08-14 16:47:37 -04001611 void (*post_disable)(struct drm_bridge *bridge);
Daniel Vetterda024fe2015-12-04 09:45:47 +01001612
1613 /**
1614 * @mode_set:
1615 *
1616 * This callback should set the given mode on the bridge. It is called
1617 * after the ->mode_set() callback for the preceding element in the
1618 * display pipeline has been called already. The display pipe (i.e.
1619 * clocks and timing signals) is off when this function is called.
1620 */
Sean Paul3b336ec2013-08-14 16:47:37 -04001621 void (*mode_set)(struct drm_bridge *bridge,
1622 struct drm_display_mode *mode,
1623 struct drm_display_mode *adjusted_mode);
Daniel Vetterda024fe2015-12-04 09:45:47 +01001624 /**
1625 * @pre_enable:
1626 *
1627 * This callback should enable the bridge. It is called right before
1628 * the preceding element in the display pipe is enabled. If the
1629 * preceding element is a bridge this means it's called before that
1630 * bridge's ->pre_enable() function. If the preceding element is a
1631 * &drm_encoder it's called right before the encoder's ->enable(),
1632 * ->commit() or ->dpms() hook from struct &drm_encoder_helper_funcs.
1633 *
1634 * The display pipe (i.e. clocks and timing signals) feeding this bridge
1635 * will not yet be running when this callback is called. The bridge must
1636 * not enable the display link feeding the next bridge in the chain (if
1637 * there is one) when this callback is called.
Laurent Pinchartc8a3b2a2016-02-26 11:51:06 +02001638 *
1639 * The pre_enable callback is optional.
Daniel Vetterda024fe2015-12-04 09:45:47 +01001640 */
Sean Paul3b336ec2013-08-14 16:47:37 -04001641 void (*pre_enable)(struct drm_bridge *bridge);
Daniel Vetterda024fe2015-12-04 09:45:47 +01001642
1643 /**
1644 * @enable:
1645 *
1646 * This callback should enable the bridge. It is called right after
1647 * the preceding element in the display pipe is enabled. If the
1648 * preceding element is a bridge this means it's called after that
1649 * bridge's ->enable() function. If the preceding element is a
1650 * &drm_encoder it's called right after the encoder's ->enable(),
1651 * ->commit() or ->dpms() hook from struct &drm_encoder_helper_funcs.
1652 *
1653 * The bridge can assume that the display pipe (i.e. clocks and timing
1654 * signals) feeding it is running when this callback is called. This
1655 * callback must enable the display link feeding the next bridge in the
1656 * chain if there is one.
Laurent Pinchartc8a3b2a2016-02-26 11:51:06 +02001657 *
1658 * The enable callback is optional.
Daniel Vetterda024fe2015-12-04 09:45:47 +01001659 */
Sean Paul3b336ec2013-08-14 16:47:37 -04001660 void (*enable)(struct drm_bridge *bridge);
Sean Paul3b336ec2013-08-14 16:47:37 -04001661};
1662
1663/**
Daniel Vetter3bf04012014-10-27 16:54:27 +01001664 * struct drm_bridge - central DRM bridge control structure
Sean Paul3b336ec2013-08-14 16:47:37 -04001665 * @dev: DRM device this bridge belongs to
Archit Taneja862e6862015-05-21 11:03:16 +05301666 * @encoder: encoder to which this bridge is connected
1667 * @next: the next bridge in the encoder chain
Ajay Kumar3d3f8b12015-01-20 22:08:44 +05301668 * @of_node: device node pointer to the bridge
1669 * @list: to keep track of all added bridges
Sean Paul3b336ec2013-08-14 16:47:37 -04001670 * @funcs: control functions
1671 * @driver_private: pointer to the bridge driver's internal context
1672 */
1673struct drm_bridge {
1674 struct drm_device *dev;
Ajay Kumar3d3f8b12015-01-20 22:08:44 +05301675 struct drm_encoder *encoder;
Archit Taneja862e6862015-05-21 11:03:16 +05301676 struct drm_bridge *next;
Ajay Kumar3d3f8b12015-01-20 22:08:44 +05301677#ifdef CONFIG_OF
1678 struct device_node *of_node;
1679#endif
1680 struct list_head list;
Sean Paul3b336ec2013-08-14 16:47:37 -04001681
1682 const struct drm_bridge_funcs *funcs;
1683 void *driver_private;
1684};
1685
1686/**
Rob Clark08855fa2015-03-11 10:23:09 -04001687 * struct drm_atomic_state - the global state object for atomic updates
Daniel Vettercc4ceb42014-07-25 21:30:38 +02001688 * @dev: parent DRM device
Rob Clarkd34f20d2014-12-18 16:01:56 -05001689 * @allow_modeset: allow full modeset
Daniel Vetterc6b0ca32015-12-04 09:46:01 +01001690 * @legacy_cursor_update: hint to enforce legacy cursor IOCTL semantics
Maarten Lankhorst40616a22016-03-03 10:17:39 +01001691 * @legacy_set_config: Disable conflicting encoders instead of failing with -EINVAL.
Daniel Vettercc4ceb42014-07-25 21:30:38 +02001692 * @planes: pointer to array of plane pointers
1693 * @plane_states: pointer to array of plane states pointers
1694 * @crtcs: pointer to array of CRTC pointers
1695 * @crtc_states: pointer to array of CRTC states pointers
Daniel Vetterf52b69f12014-11-19 18:38:08 +01001696 * @num_connector: size of the @connectors and @connector_states arrays
Daniel Vettercc4ceb42014-07-25 21:30:38 +02001697 * @connectors: pointer to array of connector pointers
1698 * @connector_states: pointer to array of connector states pointers
1699 * @acquire_ctx: acquire context for this atomic modeset state update
1700 */
1701struct drm_atomic_state {
1702 struct drm_device *dev;
Rob Clarkd34f20d2014-12-18 16:01:56 -05001703 bool allow_modeset : 1;
Daniel Vetterf02ad902015-01-22 16:36:23 +01001704 bool legacy_cursor_update : 1;
Maarten Lankhorst40616a22016-03-03 10:17:39 +01001705 bool legacy_set_config : 1;
Daniel Vettercc4ceb42014-07-25 21:30:38 +02001706 struct drm_plane **planes;
1707 struct drm_plane_state **plane_states;
1708 struct drm_crtc **crtcs;
1709 struct drm_crtc_state **crtc_states;
Daniel Vetterf52b69f12014-11-19 18:38:08 +01001710 int num_connector;
Daniel Vettercc4ceb42014-07-25 21:30:38 +02001711 struct drm_connector **connectors;
1712 struct drm_connector_state **connector_states;
1713
1714 struct drm_modeset_acquire_ctx *acquire_ctx;
1715};
1716
1717
1718/**
Daniel Vetter3bf04012014-10-27 16:54:27 +01001719 * struct drm_mode_set - new values for a CRTC config change
Jesse Barnesef273512011-11-07 12:03:19 -08001720 * @fb: framebuffer to use for new config
1721 * @crtc: CRTC whose configuration we're about to change
1722 * @mode: mode timings to use
1723 * @x: position of this CRTC relative to @fb
1724 * @y: position of this CRTC relative to @fb
1725 * @connectors: array of connectors to drive with this CRTC if possible
1726 * @num_connectors: size of @connectors array
Dave Airlief453ba02008-11-07 14:05:41 -08001727 *
1728 * Represents a single crtc the connectors that it drives with what mode
1729 * and from which framebuffer it scans out from.
1730 *
1731 * This is used to set modes.
1732 */
1733struct drm_mode_set {
Dave Airlief453ba02008-11-07 14:05:41 -08001734 struct drm_framebuffer *fb;
1735 struct drm_crtc *crtc;
1736 struct drm_display_mode *mode;
1737
1738 uint32_t x;
1739 uint32_t y;
1740
1741 struct drm_connector **connectors;
1742 size_t num_connectors;
1743};
1744
1745/**
Jesse Barnes550cebc2011-11-07 12:03:20 -08001746 * struct drm_mode_config_funcs - basic driver provided mode setting functions
Jesse Barnes550cebc2011-11-07 12:03:20 -08001747 *
1748 * Some global (i.e. not per-CRTC, connector, etc) mode setting functions that
1749 * involve drivers.
Dave Airlief453ba02008-11-07 14:05:41 -08001750 */
1751struct drm_mode_config_funcs {
Daniel Vetter9953f412015-12-04 09:46:02 +01001752 /**
1753 * @fb_create:
1754 *
1755 * Create a new framebuffer object. The core does basic checks on the
1756 * requested metadata, but most of that is left to the driver. See
1757 * struct &drm_mode_fb_cmd2 for details.
1758 *
Daniel Vetterd55f5322015-12-08 09:49:19 +01001759 * If the parameters are deemed valid and the backing storage objects in
1760 * the underlying memory manager all exist, then the driver allocates
1761 * a new &drm_framebuffer structure, subclassed to contain
1762 * driver-specific information (like the internal native buffer object
1763 * references). It also needs to fill out all relevant metadata, which
1764 * should be done by calling drm_helper_mode_fill_fb_struct().
1765 *
1766 * The initialization is finalized by calling drm_framebuffer_init(),
1767 * which registers the framebuffer and makes it accessible to other
1768 * threads.
1769 *
Daniel Vetter9953f412015-12-04 09:46:02 +01001770 * RETURNS:
1771 *
1772 * A new framebuffer with an initial reference count of 1 or a negative
1773 * error code encoded with ERR_PTR().
1774 */
Jesse Barnes550cebc2011-11-07 12:03:20 -08001775 struct drm_framebuffer *(*fb_create)(struct drm_device *dev,
1776 struct drm_file *file_priv,
Ville Syrjälä1eb83452015-11-11 19:11:29 +02001777 const struct drm_mode_fb_cmd2 *mode_cmd);
Daniel Vetter9953f412015-12-04 09:46:02 +01001778
1779 /**
1780 * @output_poll_changed:
1781 *
1782 * Callback used by helpers to inform the driver of output configuration
1783 * changes.
1784 *
1785 * Drivers implementing fbdev emulation with the helpers can call
1786 * drm_fb_helper_hotplug_changed from this hook to inform the fbdev
1787 * helper of output changes.
1788 *
1789 * FIXME:
1790 *
1791 * Except that there's no vtable for device-level helper callbacks
1792 * there's no reason this is a core function.
1793 */
Dave Airlieeb1f8e42010-05-07 06:42:51 +00001794 void (*output_poll_changed)(struct drm_device *dev);
Daniel Vettercc4ceb42014-07-25 21:30:38 +02001795
Daniel Vetter9953f412015-12-04 09:46:02 +01001796 /**
1797 * @atomic_check:
1798 *
1799 * This is the only hook to validate an atomic modeset update. This
1800 * function must reject any modeset and state changes which the hardware
1801 * or driver doesn't support. This includes but is of course not limited
1802 * to:
1803 *
1804 * - Checking that the modes, framebuffers, scaling and placement
1805 * requirements and so on are within the limits of the hardware.
1806 *
1807 * - Checking that any hidden shared resources are not oversubscribed.
1808 * This can be shared PLLs, shared lanes, overall memory bandwidth,
1809 * display fifo space (where shared between planes or maybe even
1810 * CRTCs).
1811 *
1812 * - Checking that virtualized resources exported to userspace are not
1813 * oversubscribed. For various reasons it can make sense to expose
1814 * more planes, crtcs or encoders than which are physically there. One
1815 * example is dual-pipe operations (which generally should be hidden
1816 * from userspace if when lockstepped in hardware, exposed otherwise),
1817 * where a plane might need 1 hardware plane (if it's just on one
1818 * pipe), 2 hardware planes (when it spans both pipes) or maybe even
1819 * shared a hardware plane with a 2nd plane (if there's a compatible
1820 * plane requested on the area handled by the other pipe).
1821 *
1822 * - Check that any transitional state is possible and that if
1823 * requested, the update can indeed be done in the vblank period
1824 * without temporarily disabling some functions.
1825 *
1826 * - Check any other constraints the driver or hardware might have.
1827 *
1828 * - This callback also needs to correctly fill out the &drm_crtc_state
1829 * in this update to make sure that drm_atomic_crtc_needs_modeset()
1830 * reflects the nature of the possible update and returns true if and
1831 * only if the update cannot be applied without tearing within one
1832 * vblank on that CRTC. The core uses that information to reject
1833 * updates which require a full modeset (i.e. blanking the screen, or
1834 * at least pausing updates for a substantial amount of time) if
1835 * userspace has disallowed that in its request.
1836 *
1837 * - The driver also does not need to repeat basic input validation
1838 * like done for the corresponding legacy entry points. The core does
1839 * that before calling this hook.
1840 *
1841 * See the documentation of @atomic_commit for an exhaustive list of
1842 * error conditions which don't have to be checked at the
1843 * ->atomic_check() stage?
1844 *
1845 * See the documentation for struct &drm_atomic_state for how exactly
1846 * an atomic modeset update is described.
1847 *
1848 * Drivers using the atomic helpers can implement this hook using
1849 * drm_atomic_helper_check(), or one of the exported sub-functions of
1850 * it.
1851 *
1852 * RETURNS:
1853 *
1854 * 0 on success or one of the below negative error codes:
1855 *
1856 * - -EINVAL, if any of the above constraints are violated.
1857 *
1858 * - -EDEADLK, when returned from an attempt to acquire an additional
1859 * &drm_modeset_lock through drm_modeset_lock().
1860 *
1861 * - -ENOMEM, if allocating additional state sub-structures failed due
1862 * to lack of memory.
1863 *
1864 * - -EINTR, -EAGAIN or -ERESTARTSYS, if the IOCTL should be restarted.
1865 * This can either be due to a pending signal, or because the driver
1866 * needs to completely bail out to recover from an exceptional
1867 * situation like a GPU hang. From a userspace point all errors are
1868 * treated equally.
1869 */
Daniel Vettercc4ceb42014-07-25 21:30:38 +02001870 int (*atomic_check)(struct drm_device *dev,
Daniel Vetter9953f412015-12-04 09:46:02 +01001871 struct drm_atomic_state *state);
1872
1873 /**
1874 * @atomic_commit:
1875 *
1876 * This is the only hook to commit an atomic modeset update. The core
1877 * guarantees that @atomic_check has been called successfully before
1878 * calling this function, and that nothing has been changed in the
1879 * interim.
1880 *
1881 * See the documentation for struct &drm_atomic_state for how exactly
1882 * an atomic modeset update is described.
1883 *
1884 * Drivers using the atomic helpers can implement this hook using
1885 * drm_atomic_helper_commit(), or one of the exported sub-functions of
1886 * it.
1887 *
1888 * Asynchronous commits (as indicated with the async parameter) must
1889 * do any preparatory work which might result in an unsuccessful commit
1890 * in the context of this callback. The only exceptions are hardware
1891 * errors resulting in -EIO. But even in that case the driver must
1892 * ensure that the display pipe is at least running, to avoid
1893 * compositors crashing when pageflips don't work. Anything else,
1894 * specifically committing the update to the hardware, should be done
1895 * without blocking the caller. For updates which do not require a
1896 * modeset this must be guaranteed.
1897 *
1898 * The driver must wait for any pending rendering to the new
1899 * framebuffers to complete before executing the flip. It should also
1900 * wait for any pending rendering from other drivers if the underlying
1901 * buffer is a shared dma-buf. Asynchronous commits must not wait for
1902 * rendering in the context of this callback.
1903 *
1904 * An application can request to be notified when the atomic commit has
1905 * completed. These events are per-CRTC and can be distinguished by the
1906 * CRTC index supplied in &drm_event to userspace.
1907 *
1908 * The drm core will supply a struct &drm_event in the event
1909 * member of each CRTC's &drm_crtc_state structure. This can be handled by the
1910 * drm_crtc_send_vblank_event() function, which the driver should call on
1911 * the provided event upon completion of the atomic commit. Note that if
1912 * the driver supports vblank signalling and timestamping the vblank
1913 * counters and timestamps must agree with the ones returned from page
1914 * flip events. With the current vblank helper infrastructure this can
1915 * be achieved by holding a vblank reference while the page flip is
1916 * pending, acquired through drm_crtc_vblank_get() and released with
1917 * drm_crtc_vblank_put(). Drivers are free to implement their own vblank
1918 * counter and timestamp tracking though, e.g. if they have accurate
1919 * timestamp registers in hardware.
1920 *
1921 * NOTE:
1922 *
1923 * Drivers are not allowed to shut down any display pipe successfully
1924 * enabled through an atomic commit on their own. Doing so can result in
1925 * compositors crashing if a page flip is suddenly rejected because the
1926 * pipe is off.
1927 *
1928 * RETURNS:
1929 *
1930 * 0 on success or one of the below negative error codes:
1931 *
1932 * - -EBUSY, if an asynchronous updated is requested and there is
1933 * an earlier updated pending. Drivers are allowed to support a queue
1934 * of outstanding updates, but currently no driver supports that.
1935 * Note that drivers must wait for preceding updates to complete if a
1936 * synchronous update is requested, they are not allowed to fail the
1937 * commit in that case.
1938 *
1939 * - -ENOMEM, if the driver failed to allocate memory. Specifically
1940 * this can happen when trying to pin framebuffers, which must only
1941 * be done when committing the state.
1942 *
1943 * - -ENOSPC, as a refinement of the more generic -ENOMEM to indicate
1944 * that the driver has run out of vram, iommu space or similar GPU
1945 * address space needed for framebuffer.
1946 *
1947 * - -EIO, if the hardware completely died.
1948 *
1949 * - -EINTR, -EAGAIN or -ERESTARTSYS, if the IOCTL should be restarted.
1950 * This can either be due to a pending signal, or because the driver
1951 * needs to completely bail out to recover from an exceptional
1952 * situation like a GPU hang. From a userspace point of view all errors are
1953 * treated equally.
1954 *
1955 * This list is exhaustive. Specifically this hook is not allowed to
1956 * return -EINVAL (any invalid requests should be caught in
1957 * @atomic_check) or -EDEADLK (this function must not acquire
1958 * additional modeset locks).
1959 */
Daniel Vettercc4ceb42014-07-25 21:30:38 +02001960 int (*atomic_commit)(struct drm_device *dev,
Daniel Vetter9953f412015-12-04 09:46:02 +01001961 struct drm_atomic_state *state,
Daniel Vettercc4ceb42014-07-25 21:30:38 +02001962 bool async);
Daniel Vetter9953f412015-12-04 09:46:02 +01001963
1964 /**
1965 * @atomic_state_alloc:
1966 *
1967 * This optional hook can be used by drivers that want to subclass struct
1968 * &drm_atomic_state to be able to track their own driver-private global
1969 * state easily. If this hook is implemented, drivers must also
1970 * implement @atomic_state_clear and @atomic_state_free.
1971 *
1972 * RETURNS:
1973 *
1974 * A new &drm_atomic_state on success or NULL on failure.
1975 */
Maarten Lankhorst036ef572015-05-18 10:06:40 +02001976 struct drm_atomic_state *(*atomic_state_alloc)(struct drm_device *dev);
Daniel Vetter9953f412015-12-04 09:46:02 +01001977
1978 /**
1979 * @atomic_state_clear:
1980 *
1981 * This hook must clear any driver private state duplicated into the
1982 * passed-in &drm_atomic_state. This hook is called when the caller
1983 * encountered a &drm_modeset_lock deadlock and needs to drop all
1984 * already acquired locks as part of the deadlock avoidance dance
1985 * implemented in drm_modeset_lock_backoff().
1986 *
1987 * Any duplicated state must be invalidated since a concurrent atomic
1988 * update might change it, and the drm atomic interfaces always apply
1989 * updates as relative changes to the current state.
1990 *
1991 * Drivers that implement this must call drm_atomic_state_default_clear()
1992 * to clear common state.
1993 */
Maarten Lankhorst036ef572015-05-18 10:06:40 +02001994 void (*atomic_state_clear)(struct drm_atomic_state *state);
Daniel Vetter9953f412015-12-04 09:46:02 +01001995
1996 /**
1997 * @atomic_state_free:
1998 *
1999 * This hook needs driver private resources and the &drm_atomic_state
2000 * itself. Note that the core first calls drm_atomic_state_clear() to
2001 * avoid code duplicate between the clear and free hooks.
2002 *
2003 * Drivers that implement this must call drm_atomic_state_default_free()
2004 * to release common resources.
2005 */
Maarten Lankhorst036ef572015-05-18 10:06:40 +02002006 void (*atomic_state_free)(struct drm_atomic_state *state);
Dave Airlief453ba02008-11-07 14:05:41 -08002007};
2008
Jesse Barnesc1aaca22011-11-07 12:03:21 -08002009/**
Daniel Vetter2c0c33d2014-10-27 20:19:38 +01002010 * struct drm_mode_config - Mode configuration control structure
Jesse Barnesa62c93d2011-11-07 12:03:22 -08002011 * @mutex: mutex protecting KMS related lists and structures
Daniel Vetter2c0c33d2014-10-27 20:19:38 +01002012 * @connection_mutex: ww mutex protecting connector state and routing
2013 * @acquire_ctx: global implicit acquire context used by atomic drivers for
Daniel Vetterc6b0ca32015-12-04 09:46:01 +01002014 * legacy IOCTLs
Jesse Barnesa62c93d2011-11-07 12:03:22 -08002015 * @idr_mutex: mutex for KMS ID allocation and management
2016 * @crtc_idr: main KMS ID tracking object
Daniel Vetter2c0c33d2014-10-27 20:19:38 +01002017 * @fb_lock: mutex to protect fb state and lists
Jesse Barnesa62c93d2011-11-07 12:03:22 -08002018 * @num_fb: number of fbs available
2019 * @fb_list: list of framebuffers available
2020 * @num_connector: number of connectors on this device
2021 * @connector_list: list of connector objects
2022 * @num_encoder: number of encoders on this device
2023 * @encoder_list: list of encoder objects
Daniel Vetter2c0c33d2014-10-27 20:19:38 +01002024 * @num_overlay_plane: number of overlay planes on this device
2025 * @num_total_plane: number of universal (i.e. with primary/curso) planes on this device
2026 * @plane_list: list of plane objects
Jesse Barnesa62c93d2011-11-07 12:03:22 -08002027 * @num_crtc: number of CRTCs on this device
2028 * @crtc_list: list of CRTC objects
Daniel Vetter2c0c33d2014-10-27 20:19:38 +01002029 * @property_list: list of property objects
Jesse Barnesa62c93d2011-11-07 12:03:22 -08002030 * @min_width: minimum pixel width on this device
2031 * @min_height: minimum pixel height on this device
2032 * @max_width: maximum pixel width on this device
2033 * @max_height: maximum pixel height on this device
2034 * @funcs: core driver provided mode setting functions
2035 * @fb_base: base address of the framebuffer
Daniel Vetter2c0c33d2014-10-27 20:19:38 +01002036 * @poll_enabled: track polling support for this device
2037 * @poll_running: track polling status for this device
Jesse Barnesa62c93d2011-11-07 12:03:22 -08002038 * @output_poll_work: delayed work for polling in process context
Daniel Vetter2c0c33d2014-10-27 20:19:38 +01002039 * @property_blob_list: list of all the blob property objects
Daniel Stone8fb6e7a2015-04-20 19:22:54 +01002040 * @blob_lock: mutex for blob property allocation and management
Jesse Barnesa62c93d2011-11-07 12:03:22 -08002041 * @*_property: core property tracking
Lionel Landwerlin5488dc12016-02-26 17:05:00 +00002042 * @degamma_lut_property: LUT used to convert the framebuffer's colors to linear
2043 * gamma
2044 * @degamma_lut_size_property: size of the degamma LUT as supported by the
2045 * driver (read-only)
2046 * @ctm_property: Matrix used to convert colors after the lookup in the
2047 * degamma LUT
2048 * @gamma_lut_property: LUT used to convert the colors, after the CSC matrix, to
2049 * the gamma space of the connected screen (read-only)
2050 * @gamma_lut_size_property: size of the gamma LUT as supported by the driver
Daniel Vetter2c0c33d2014-10-27 20:19:38 +01002051 * @preferred_depth: preferred RBG pixel depth, used by fb helpers
2052 * @prefer_shadow: hint to userspace to prefer shadow-fb rendering
2053 * @async_page_flip: does this device support async flips on the primary plane?
2054 * @cursor_width: hint to userspace for max cursor width
2055 * @cursor_height: hint to userspace for max cursor height
Dave Airlief453ba02008-11-07 14:05:41 -08002056 *
Jesse Barnesa62c93d2011-11-07 12:03:22 -08002057 * Core mode resource tracking structure. All CRTC, encoders, and connectors
2058 * enumerated by the driver are added here, as are global properties. Some
2059 * global restrictions are also here, e.g. dimension restrictions.
Dave Airlief453ba02008-11-07 14:05:41 -08002060 */
2061struct drm_mode_config {
Jesse Barnesad2563c2009-01-19 17:21:45 +10002062 struct mutex mutex; /* protects configuration (mode lists etc.) */
Rob Clark51fd3712013-11-19 12:10:12 -05002063 struct drm_modeset_lock connection_mutex; /* protects connector->encoder and encoder->crtc links */
2064 struct drm_modeset_acquire_ctx *acquire_ctx; /* for legacy _lock_all() / _unlock_all() */
Jesse Barnesad2563c2009-01-19 17:21:45 +10002065 struct mutex idr_mutex; /* for IDR management */
Dave Airlief453ba02008-11-07 14:05:41 -08002066 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 +10002067 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 -08002068 /* this is limited to one for now */
Daniel Vetter4b096ac2012-12-10 21:19:18 +01002069
Daniel Vetter2c0c33d2014-10-27 20:19:38 +01002070 struct mutex fb_lock; /* proctects global and per-file fb lists */
Dave Airlief453ba02008-11-07 14:05:41 -08002071 int num_fb;
2072 struct list_head fb_list;
Daniel Vetter4b096ac2012-12-10 21:19:18 +01002073
Dave Airlief453ba02008-11-07 14:05:41 -08002074 int num_connector;
Maarten Lankhorst5fff80b2016-02-17 08:32:05 +01002075 struct ida connector_ida;
Dave Airlief453ba02008-11-07 14:05:41 -08002076 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 Airlieeb1f8e42010-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 Airlieeb1f8e42010-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);
Maarten Lankhorst5fff80b2016-02-17 08:32:05 +01002247static inline unsigned drm_connector_index(struct drm_connector *connector)
2248{
2249 return connector->connector_id;
2250}
2251
Alexey Brodkin6c87e5c2016-03-23 11:42:54 +03002252/* helper to unregister all connectors from sysfs for device */
2253extern void drm_connector_unregister_all(struct drm_device *dev);
Dave Airlief453ba02008-11-07 14:05:41 -08002254
Ajay Kumar3d3f8b12015-01-20 22:08:44 +05302255extern int drm_bridge_add(struct drm_bridge *bridge);
2256extern void drm_bridge_remove(struct drm_bridge *bridge);
2257extern struct drm_bridge *of_drm_find_bridge(struct device_node *np);
2258extern int drm_bridge_attach(struct drm_device *dev, struct drm_bridge *bridge);
Sean Paul3b336ec2013-08-14 16:47:37 -04002259
Archit Taneja862e6862015-05-21 11:03:16 +05302260bool drm_bridge_mode_fixup(struct drm_bridge *bridge,
2261 const struct drm_display_mode *mode,
2262 struct drm_display_mode *adjusted_mode);
2263void drm_bridge_disable(struct drm_bridge *bridge);
2264void drm_bridge_post_disable(struct drm_bridge *bridge);
2265void drm_bridge_mode_set(struct drm_bridge *bridge,
2266 struct drm_display_mode *mode,
2267 struct drm_display_mode *adjusted_mode);
2268void drm_bridge_pre_enable(struct drm_bridge *bridge);
2269void drm_bridge_enable(struct drm_bridge *bridge);
2270
Ville Syrjälä13a3d912015-12-09 16:20:18 +02002271extern __printf(5, 6)
2272int drm_encoder_init(struct drm_device *dev,
2273 struct drm_encoder *encoder,
2274 const struct drm_encoder_funcs *funcs,
2275 int encoder_type, const char *name, ...);
Maarten Lankhorst47d77772016-01-07 10:59:18 +01002276extern unsigned int drm_encoder_index(struct drm_encoder *encoder);
Dave Airlief453ba02008-11-07 14:05:41 -08002277
Thierry Reding3d887362014-01-13 14:33:20 +01002278/**
2279 * drm_encoder_crtc_ok - can a given crtc drive a given encoder?
2280 * @encoder: encoder to test
2281 * @crtc: crtc to test
2282 *
2283 * Return false if @encoder can't be driven by @crtc, true otherwise.
2284 */
2285static inline bool drm_encoder_crtc_ok(struct drm_encoder *encoder,
2286 struct drm_crtc *crtc)
2287{
2288 return !!(encoder->possible_crtcs & drm_crtc_mask(crtc));
2289}
2290
Ville Syrjäläb0b3b792015-12-09 16:19:55 +02002291extern __printf(8, 9)
2292int drm_universal_plane_init(struct drm_device *dev,
2293 struct drm_plane *plane,
2294 unsigned long possible_crtcs,
2295 const struct drm_plane_funcs *funcs,
2296 const uint32_t *formats,
2297 unsigned int format_count,
2298 enum drm_plane_type type,
2299 const char *name, ...);
Jesse Barnes8cf5c912011-11-14 14:51:27 -08002300extern int drm_plane_init(struct drm_device *dev,
2301 struct drm_plane *plane,
2302 unsigned long possible_crtcs,
2303 const struct drm_plane_funcs *funcs,
Thierry Reding45e37432015-08-12 16:54:28 +02002304 const uint32_t *formats, unsigned int format_count,
Matt Roperdc415ff2014-04-01 15:22:36 -07002305 bool is_primary);
Jesse Barnes8cf5c912011-11-14 14:51:27 -08002306extern void drm_plane_cleanup(struct drm_plane *plane);
Daniel Vetter10f637b2014-07-29 13:47:11 +02002307extern unsigned int drm_plane_index(struct drm_plane *plane);
Chandra Konduruf81338a2015-04-09 17:36:21 -07002308extern struct drm_plane * drm_plane_from_index(struct drm_device *dev, int idx);
Ville Syrjälä9125e612013-06-03 16:10:40 +03002309extern void drm_plane_force_disable(struct drm_plane *plane);
Laurent Pinchartead86102015-03-05 02:25:43 +02002310extern int drm_plane_check_pixel_format(const struct drm_plane *plane,
2311 u32 format);
Gustavo Padovanecb7e162014-12-01 15:40:09 -08002312extern void drm_crtc_get_hv_timing(const struct drm_display_mode *mode,
2313 int *hdisplay, int *vdisplay);
Matt Roperaf936292014-04-01 15:22:34 -07002314extern int drm_crtc_check_viewport(const struct drm_crtc *crtc,
2315 int x, int y,
2316 const struct drm_display_mode *mode,
2317 const struct drm_framebuffer *fb);
Jesse Barnes8cf5c912011-11-14 14:51:27 -08002318
Dave Airlief453ba02008-11-07 14:05:41 -08002319extern void drm_encoder_cleanup(struct drm_encoder *encoder);
2320
Ville Syrjäläd20d3172013-06-07 15:43:07 +00002321extern const char *drm_get_connector_status_name(enum drm_connector_status status);
Jesse Barnesac1bb362014-02-10 15:32:44 -08002322extern const char *drm_get_subpixel_order_name(enum subpixel_order order);
Ville Syrjäläd20d3172013-06-07 15:43:07 +00002323extern const char *drm_get_dpms_name(int val);
2324extern const char *drm_get_dvi_i_subconnector_name(int val);
2325extern const char *drm_get_dvi_i_select_name(int val);
2326extern const char *drm_get_tv_subconnector_name(int val);
2327extern const char *drm_get_tv_select_name(int val);
Kristian Høgsbergea39f832009-02-12 14:37:56 -05002328extern void drm_fb_release(struct drm_file *file_priv);
Daniel Stonee2f5d2e2015-05-22 13:34:51 +01002329extern void drm_property_destroy_user_blobs(struct drm_device *dev,
2330 struct drm_file *file_priv);
Adam Jacksonfbff4692012-09-18 10:58:47 -04002331extern bool drm_probe_ddc(struct i2c_adapter *adapter);
Dave Airlief453ba02008-11-07 14:05:41 -08002332extern struct edid *drm_get_edid(struct drm_connector *connector,
2333 struct i2c_adapter *adapter);
Lukas Wunner5cb8eaa2016-01-11 20:09:20 +01002334extern struct edid *drm_get_edid_switcheroo(struct drm_connector *connector,
2335 struct i2c_adapter *adapter);
Jani Nikula51f8da52013-09-27 15:08:27 +03002336extern struct edid *drm_edid_duplicate(const struct edid *edid);
Dave Airlief453ba02008-11-07 14:05:41 -08002337extern int drm_add_edid_modes(struct drm_connector *connector, struct edid *edid);
Dave Airlief453ba02008-11-07 14:05:41 -08002338extern void drm_mode_config_init(struct drm_device *dev);
Chris Wilsoneb033552011-01-24 15:11:08 +00002339extern void drm_mode_config_reset(struct drm_device *dev);
Dave Airlief453ba02008-11-07 14:05:41 -08002340extern void drm_mode_config_cleanup(struct drm_device *dev);
Dave Airlief453ba02008-11-07 14:05:41 -08002341
Dave Airlie43aba7e2014-06-05 14:01:31 +10002342extern int drm_mode_connector_set_path_property(struct drm_connector *connector,
Thierry Reding12e6cec2014-05-13 11:38:36 +02002343 const char *path);
Dave Airlie6f134d72014-10-20 16:30:50 +10002344int drm_mode_connector_set_tile_property(struct drm_connector *connector);
Dave Airlief453ba02008-11-07 14:05:41 -08002345extern int drm_mode_connector_update_edid_property(struct drm_connector *connector,
Thierry Reding12e6cec2014-05-13 11:38:36 +02002346 const struct edid *edid);
Rob Clark5ea22f22014-05-30 11:34:01 -04002347
Boris Brezillonb5571e92014-07-22 12:09:10 +02002348extern int drm_display_info_set_bus_formats(struct drm_display_info *info,
2349 const u32 *formats,
2350 unsigned int num_formats);
2351
Rob Clark5ea22f22014-05-30 11:34:01 -04002352static inline bool drm_property_type_is(struct drm_property *property,
2353 uint32_t type)
2354{
2355 /* instanceof for props.. handles extended type vs original types: */
2356 if (property->flags & DRM_MODE_PROP_EXTENDED_TYPE)
2357 return (property->flags & DRM_MODE_PROP_EXTENDED_TYPE) == type;
2358 return property->flags & type;
2359}
2360
2361static inline bool drm_property_type_valid(struct drm_property *property)
2362{
2363 if (property->flags & DRM_MODE_PROP_EXTENDED_TYPE)
2364 return !(property->flags & DRM_MODE_PROP_LEGACY_TYPE);
2365 return !!(property->flags & DRM_MODE_PROP_LEGACY_TYPE);
2366}
2367
Paulo Zanonic5431882012-05-15 18:09:02 -03002368extern int drm_object_property_set_value(struct drm_mode_object *obj,
2369 struct drm_property *property,
2370 uint64_t val);
2371extern int drm_object_property_get_value(struct drm_mode_object *obj,
2372 struct drm_property *property,
2373 uint64_t *value);
Dave Airlief453ba02008-11-07 14:05:41 -08002374extern int drm_framebuffer_init(struct drm_device *dev,
2375 struct drm_framebuffer *fb,
2376 const struct drm_framebuffer_funcs *funcs);
Daniel Vetter786b99e2012-12-02 21:53:40 +01002377extern struct drm_framebuffer *drm_framebuffer_lookup(struct drm_device *dev,
2378 uint32_t id);
Rob Clarkf7eff602012-09-05 21:48:38 +00002379extern void drm_framebuffer_unreference(struct drm_framebuffer *fb);
2380extern void drm_framebuffer_reference(struct drm_framebuffer *fb);
2381extern void drm_framebuffer_remove(struct drm_framebuffer *fb);
Dave Airlief453ba02008-11-07 14:05:41 -08002382extern void drm_framebuffer_cleanup(struct drm_framebuffer *fb);
Daniel Vetter36206362012-12-10 20:42:17 +01002383extern void drm_framebuffer_unregister_private(struct drm_framebuffer *fb);
Dave Airlief453ba02008-11-07 14:05:41 -08002384
Paulo Zanonic5431882012-05-15 18:09:02 -03002385extern void drm_object_attach_property(struct drm_mode_object *obj,
2386 struct drm_property *property,
2387 uint64_t init_val);
Dave Airlief453ba02008-11-07 14:05:41 -08002388extern struct drm_property *drm_property_create(struct drm_device *dev, int flags,
2389 const char *name, int num_values);
Sascha Hauer4a67d392012-02-06 10:58:17 +01002390extern struct drm_property *drm_property_create_enum(struct drm_device *dev, int flags,
2391 const char *name,
2392 const struct drm_prop_enum_list *props,
2393 int num_values);
Rob Clark49e27542012-05-17 02:23:26 -06002394struct drm_property *drm_property_create_bitmask(struct drm_device *dev,
2395 int flags, const char *name,
2396 const struct drm_prop_enum_list *props,
Ville Syrjälä7689ffb2014-07-08 10:31:52 +05302397 int num_props,
2398 uint64_t supported_bits);
Sascha Hauerd9bc3c02012-02-06 10:58:18 +01002399struct drm_property *drm_property_create_range(struct drm_device *dev, int flags,
2400 const char *name,
2401 uint64_t min, uint64_t max);
Rob Clarkebc44cf2012-09-12 22:22:31 -05002402struct drm_property *drm_property_create_signed_range(struct drm_device *dev,
2403 int flags, const char *name,
2404 int64_t min, int64_t max);
Rob Clark98f75de2014-05-30 11:37:03 -04002405struct drm_property *drm_property_create_object(struct drm_device *dev,
2406 int flags, const char *name, uint32_t type);
Daniel Vetter960cd9d2015-01-21 08:47:38 +01002407struct drm_property *drm_property_create_bool(struct drm_device *dev, int flags,
2408 const char *name);
Daniel Stone6bcacf52015-04-20 19:22:55 +01002409struct drm_property_blob *drm_property_create_blob(struct drm_device *dev,
2410 size_t length,
2411 const void *data);
2412struct drm_property_blob *drm_property_lookup_blob(struct drm_device *dev,
2413 uint32_t id);
2414struct drm_property_blob *drm_property_reference_blob(struct drm_property_blob *blob);
2415void drm_property_unreference_blob(struct drm_property_blob *blob);
Dave Airlief453ba02008-11-07 14:05:41 -08002416extern void drm_property_destroy(struct drm_device *dev, struct drm_property *property);
2417extern int drm_property_add_enum(struct drm_property *property, int index,
2418 uint64_t value, const char *name);
2419extern int drm_mode_create_dvi_i_properties(struct drm_device *dev);
Thierry Reding2f763312014-10-13 12:45:57 +02002420extern int drm_mode_create_tv_properties(struct drm_device *dev,
2421 unsigned int num_modes,
Ville Syrjäläb7c914b2015-08-31 15:09:26 +03002422 const char * const modes[]);
Dave Airlief453ba02008-11-07 14:05:41 -08002423extern int drm_mode_create_scaling_mode_property(struct drm_device *dev);
Vandana Kannanff587e42014-06-11 10:46:48 +05302424extern int drm_mode_create_aspect_ratio_property(struct drm_device *dev);
Jakob Bornecrantz884840a2009-12-03 23:25:47 +00002425extern int drm_mode_create_dirty_info_property(struct drm_device *dev);
Dave Airlie5bb2bbf2014-11-10 10:18:15 +10002426extern int drm_mode_create_suggested_offset_properties(struct drm_device *dev);
Rob Clarkd34f20d2014-12-18 16:01:56 -05002427extern bool drm_property_change_valid_get(struct drm_property *property,
2428 uint64_t value, struct drm_mode_object **ref);
2429extern void drm_property_change_valid_put(struct drm_property *property,
2430 struct drm_mode_object *ref);
Dave Airlief453ba02008-11-07 14:05:41 -08002431
2432extern int drm_mode_connector_attach_encoder(struct drm_connector *connector,
2433 struct drm_encoder *encoder);
Sascha Hauer4cae5b82012-02-01 11:38:23 +01002434extern int drm_mode_crtc_set_gamma_size(struct drm_crtc *crtc,
Dave Airlief453ba02008-11-07 14:05:41 -08002435 int gamma_size);
Daniel Vetter7a9c9062009-09-15 22:57:31 +02002436extern struct drm_mode_object *drm_mode_object_find(struct drm_device *dev,
2437 uint32_t id, uint32_t type);
Rob Clark98f75de2014-05-30 11:37:03 -04002438
Dave Airlief453ba02008-11-07 14:05:41 -08002439/* IOCTLs */
2440extern int drm_mode_getresources(struct drm_device *dev,
2441 void *data, struct drm_file *file_priv);
Jesse Barnes8cf5c912011-11-14 14:51:27 -08002442extern int drm_mode_getplane_res(struct drm_device *dev, void *data,
2443 struct drm_file *file_priv);
Dave Airlief453ba02008-11-07 14:05:41 -08002444extern int drm_mode_getcrtc(struct drm_device *dev,
2445 void *data, struct drm_file *file_priv);
2446extern int drm_mode_getconnector(struct drm_device *dev,
2447 void *data, struct drm_file *file_priv);
Daniel Vetter2d13b672012-12-11 13:47:23 +01002448extern int drm_mode_set_config_internal(struct drm_mode_set *set);
Dave Airlief453ba02008-11-07 14:05:41 -08002449extern int drm_mode_setcrtc(struct drm_device *dev,
2450 void *data, struct drm_file *file_priv);
Jesse Barnes8cf5c912011-11-14 14:51:27 -08002451extern int drm_mode_getplane(struct drm_device *dev,
2452 void *data, struct drm_file *file_priv);
2453extern int drm_mode_setplane(struct drm_device *dev,
2454 void *data, struct drm_file *file_priv);
Dave Airlief453ba02008-11-07 14:05:41 -08002455extern int drm_mode_cursor_ioctl(struct drm_device *dev,
2456 void *data, struct drm_file *file_priv);
Dave Airlie4c813d42013-06-20 11:48:52 +10002457extern int drm_mode_cursor2_ioctl(struct drm_device *dev,
2458 void *data, struct drm_file *file_priv);
Dave Airlief453ba02008-11-07 14:05:41 -08002459extern int drm_mode_addfb(struct drm_device *dev,
2460 void *data, struct drm_file *file_priv);
Jesse Barnes308e5bc2011-11-14 14:51:28 -08002461extern int drm_mode_addfb2(struct drm_device *dev,
2462 void *data, struct drm_file *file_priv);
2463extern uint32_t drm_mode_legacy_fb_format(uint32_t bpp, uint32_t depth);
Dave Airlief453ba02008-11-07 14:05:41 -08002464extern int drm_mode_rmfb(struct drm_device *dev,
2465 void *data, struct drm_file *file_priv);
2466extern int drm_mode_getfb(struct drm_device *dev,
2467 void *data, struct drm_file *file_priv);
Jakob Bornecrantz884840a2009-12-03 23:25:47 +00002468extern int drm_mode_dirtyfb_ioctl(struct drm_device *dev,
2469 void *data, struct drm_file *file_priv);
Dave Airlief453ba02008-11-07 14:05:41 -08002470
2471extern int drm_mode_getproperty_ioctl(struct drm_device *dev,
2472 void *data, struct drm_file *file_priv);
2473extern int drm_mode_getblob_ioctl(struct drm_device *dev,
2474 void *data, struct drm_file *file_priv);
Daniel Stonee2f5d2e2015-05-22 13:34:51 +01002475extern int drm_mode_createblob_ioctl(struct drm_device *dev,
2476 void *data, struct drm_file *file_priv);
2477extern int drm_mode_destroyblob_ioctl(struct drm_device *dev,
2478 void *data, struct drm_file *file_priv);
Dave Airlief453ba02008-11-07 14:05:41 -08002479extern int drm_mode_connector_property_set_ioctl(struct drm_device *dev,
2480 void *data, struct drm_file *file_priv);
Dave Airlief453ba02008-11-07 14:05:41 -08002481extern int drm_mode_getencoder(struct drm_device *dev,
2482 void *data, struct drm_file *file_priv);
2483extern int drm_mode_gamma_get_ioctl(struct drm_device *dev,
2484 void *data, struct drm_file *file_priv);
2485extern int drm_mode_gamma_set_ioctl(struct drm_device *dev,
2486 void *data, struct drm_file *file_priv);
Thierry Reding18316c82012-12-20 15:41:44 +01002487extern u8 drm_match_cea_mode(const struct drm_display_mode *to_match);
Vandana Kannan0967e6a2014-04-01 16:26:59 +05302488extern enum hdmi_picture_aspect drm_get_cea_aspect_ratio(const u8 video_code);
Ma Lingf23c20c2009-03-26 19:26:23 +08002489extern bool drm_detect_hdmi_monitor(struct edid *edid);
Zhenyu Wang8fe97902010-09-19 14:27:28 +08002490extern bool drm_detect_monitor_audio(struct edid *edid);
Ville Syrjäläb1edd6a2013-01-17 16:31:30 +02002491extern bool drm_rgb_quant_range_selectable(struct edid *edid);
Kristian Høgsbergd91d8a32009-11-17 12:43:55 -05002492extern int drm_mode_page_flip_ioctl(struct drm_device *dev,
2493 void *data, struct drm_file *file_priv);
Zhao Yakuif0fda0a2009-09-03 09:33:48 +08002494extern int drm_add_modes_noedid(struct drm_connector *connector,
2495 int hdisplay, int vdisplay);
Gerd Hoffmann3cf70da2013-10-11 10:01:08 +02002496extern void drm_set_preferred_mode(struct drm_connector *connector,
2497 int hpref, int vpref);
Alex Deucher3c537882010-02-05 04:21:19 -05002498
Thomas Reim051963d2011-07-29 14:28:57 +00002499extern int drm_edid_header_is_valid(const u8 *raw_edid);
Todd Previte6ba2bd32015-04-21 11:09:41 -07002500extern bool drm_edid_block_valid(u8 *raw_edid, int block, bool print_bad_edid,
2501 bool *edid_corrupt);
Alex Deucher3c537882010-02-05 04:21:19 -05002502extern bool drm_edid_is_valid(struct edid *edid);
Jim Bride59f7c0f2016-04-14 10:18:35 -07002503extern void drm_edid_get_monitor_name(struct edid *edid, char *name,
2504 int buflen);
Dave Airlie138f9eb2014-10-20 16:17:17 +10002505
2506extern struct drm_tile_group *drm_mode_create_tile_group(struct drm_device *dev,
2507 char topology[8]);
2508extern struct drm_tile_group *drm_mode_get_tile_group(struct drm_device *dev,
2509 char topology[8]);
2510extern void drm_mode_put_tile_group(struct drm_device *dev,
2511 struct drm_tile_group *tg);
Dave Airlie1d42bbc2010-05-07 05:02:30 +00002512struct drm_display_mode *drm_mode_find_dmt(struct drm_device *dev,
Adam Jacksonf6e252b2012-04-13 16:33:31 -04002513 int hsize, int vsize, int fresh,
2514 bool rb);
Dave Airlieff72145b2011-02-07 12:16:14 +10002515
2516extern int drm_mode_create_dumb_ioctl(struct drm_device *dev,
2517 void *data, struct drm_file *file_priv);
2518extern int drm_mode_mmap_dumb_ioctl(struct drm_device *dev,
2519 void *data, struct drm_file *file_priv);
2520extern int drm_mode_destroy_dumb_ioctl(struct drm_device *dev,
2521 void *data, struct drm_file *file_priv);
Paulo Zanonic5431882012-05-15 18:09:02 -03002522extern int drm_mode_obj_get_properties_ioctl(struct drm_device *dev, void *data,
2523 struct drm_file *file_priv);
2524extern int drm_mode_obj_set_property_ioctl(struct drm_device *dev, void *data,
2525 struct drm_file *file_priv);
Thomas Wood3a5f87c2014-08-20 14:45:00 +01002526extern int drm_mode_plane_set_obj_prop(struct drm_plane *plane,
2527 struct drm_property *property,
2528 uint64_t value);
Rob Clarkd34f20d2014-12-18 16:01:56 -05002529extern int drm_mode_atomic_ioctl(struct drm_device *dev,
2530 void *data, struct drm_file *file_priv);
Dave Airlie248dbc22011-11-29 20:02:54 +00002531
2532extern void drm_fb_get_bpp_depth(uint32_t format, unsigned int *depth,
2533 int *bpp);
Ville Syrjälä141670e2012-04-05 21:35:15 +03002534extern int drm_format_num_planes(uint32_t format);
Ville Syrjälä5a86bd52012-04-05 21:35:16 +03002535extern int drm_format_plane_cpp(uint32_t format, int plane);
Ville Syrjälä01b68b02012-04-05 21:35:17 +03002536extern int drm_format_horz_chroma_subsampling(uint32_t format);
2537extern int drm_format_vert_chroma_subsampling(uint32_t format);
Ville Syrjälä4c617162016-02-09 17:29:44 +02002538extern int drm_format_plane_width(int width, uint32_t format, int plane);
2539extern int drm_format_plane_height(int height, uint32_t format, int plane);
Ville Syrjäläd20d3172013-06-07 15:43:07 +00002540extern const char *drm_get_format_name(uint32_t format);
Ville Syrjäläc1df5f32014-07-08 10:31:53 +05302541extern struct drm_property *drm_mode_create_rotation_property(struct drm_device *dev,
2542 unsigned int supported_rotations);
Ville Syrjälä3c9855f2014-07-08 10:31:56 +05302543extern unsigned int drm_rotation_simplify(unsigned int rotation,
2544 unsigned int supported_rotations);
Ville Syrjälä141670e2012-04-05 21:35:15 +03002545
Russell King96f60e32012-08-15 13:59:49 +01002546/* Helpers */
Rob Clarka2b34e22013-10-05 16:36:52 -04002547
2548static inline struct drm_plane *drm_plane_find(struct drm_device *dev,
2549 uint32_t id)
2550{
2551 struct drm_mode_object *mo;
2552 mo = drm_mode_object_find(dev, id, DRM_MODE_OBJECT_PLANE);
2553 return mo ? obj_to_plane(mo) : NULL;
2554}
2555
Russell King96f60e32012-08-15 13:59:49 +01002556static inline struct drm_crtc *drm_crtc_find(struct drm_device *dev,
2557 uint32_t id)
2558{
2559 struct drm_mode_object *mo;
2560 mo = drm_mode_object_find(dev, id, DRM_MODE_OBJECT_CRTC);
2561 return mo ? obj_to_crtc(mo) : NULL;
2562}
2563
2564static inline struct drm_encoder *drm_encoder_find(struct drm_device *dev,
2565 uint32_t id)
2566{
2567 struct drm_mode_object *mo;
2568 mo = drm_mode_object_find(dev, id, DRM_MODE_OBJECT_ENCODER);
2569 return mo ? obj_to_encoder(mo) : NULL;
2570}
2571
Rob Clarka2b34e22013-10-05 16:36:52 -04002572static inline struct drm_connector *drm_connector_find(struct drm_device *dev,
2573 uint32_t id)
2574{
2575 struct drm_mode_object *mo;
2576 mo = drm_mode_object_find(dev, id, DRM_MODE_OBJECT_CONNECTOR);
2577 return mo ? obj_to_connector(mo) : NULL;
2578}
2579
2580static inline struct drm_property *drm_property_find(struct drm_device *dev,
2581 uint32_t id)
2582{
2583 struct drm_mode_object *mo;
2584 mo = drm_mode_object_find(dev, id, DRM_MODE_OBJECT_PROPERTY);
2585 return mo ? obj_to_property(mo) : NULL;
2586}
2587
Lionel Landwerlin5488dc12016-02-26 17:05:00 +00002588/*
2589 * Extract a degamma/gamma LUT value provided by user and round it to the
2590 * precision supported by the hardware.
2591 */
2592static inline uint32_t drm_color_lut_extract(uint32_t user_input,
2593 uint32_t bit_precision)
2594{
2595 uint32_t val = user_input + (1 << (16 - bit_precision - 1));
2596 uint32_t max = 0xffff >> (16 - bit_precision);
2597
2598 val >>= 16 - bit_precision;
2599
2600 return clamp_val(val, 0, max);
2601}
2602
Matt Ropere27dde32014-04-01 15:22:30 -07002603/* Plane list iterator for legacy (overlay only) planes. */
Daniel Vetter4ea50e92015-07-09 23:44:24 +02002604#define drm_for_each_legacy_plane(plane, dev) \
2605 list_for_each_entry(plane, &(dev)->mode_config.plane_list, head) \
Jani Nikula373701b2015-11-24 21:21:55 +02002606 for_each_if (plane->type == DRM_PLANE_TYPE_OVERLAY)
Matt Ropere27dde32014-04-01 15:22:30 -07002607
Daniel Vetter6295d602015-07-09 23:44:25 +02002608#define drm_for_each_plane(plane, dev) \
2609 list_for_each_entry(plane, &(dev)->mode_config.plane_list, head)
2610
2611#define drm_for_each_crtc(crtc, dev) \
2612 list_for_each_entry(crtc, &(dev)->mode_config.crtc_list, head)
2613
Daniel Vetter7a3f3d62015-07-09 23:44:28 +02002614static inline void
2615assert_drm_connector_list_read_locked(struct drm_mode_config *mode_config)
2616{
Daniel Vettercff20ba2015-07-09 23:44:33 +02002617 /*
2618 * The connector hotadd/remove code currently grabs both locks when
2619 * updating lists. Hence readers need only hold either of them to be
2620 * safe and the check amounts to
2621 *
2622 * WARN_ON(not_holding(A) && not_holding(B)).
2623 */
2624 WARN_ON(!mutex_is_locked(&mode_config->mutex) &&
2625 !drm_modeset_is_locked(&mode_config->connection_mutex));
Daniel Vetter7a3f3d62015-07-09 23:44:28 +02002626}
2627
Daniel Vetter6295d602015-07-09 23:44:25 +02002628#define drm_for_each_connector(connector, dev) \
Daniel Vetter7a3f3d62015-07-09 23:44:28 +02002629 for (assert_drm_connector_list_read_locked(&(dev)->mode_config), \
2630 connector = list_first_entry(&(dev)->mode_config.connector_list, \
2631 struct drm_connector, head); \
2632 &connector->head != (&(dev)->mode_config.connector_list); \
2633 connector = list_next_entry(connector, head))
Daniel Vetter6295d602015-07-09 23:44:25 +02002634
2635#define drm_for_each_encoder(encoder, dev) \
2636 list_for_each_entry(encoder, &(dev)->mode_config.encoder_list, head)
2637
2638#define drm_for_each_fb(fb, dev) \
Daniel Vetter4676ba02015-07-09 23:44:30 +02002639 for (WARN_ON(!mutex_is_locked(&(dev)->mode_config.fb_lock)), \
2640 fb = list_first_entry(&(dev)->mode_config.fb_list, \
2641 struct drm_framebuffer, head); \
2642 &fb->head != (&(dev)->mode_config.fb_list); \
2643 fb = list_next_entry(fb, head))
Daniel Vetter6295d602015-07-09 23:44:25 +02002644
Dave Airlief453ba02008-11-07 14:05:41 -08002645#endif /* __DRM_CRTC_H__ */