blob: b618b506b04df8dd590baac5ee8ffbd0fc897741 [file] [log] [blame]
Dave Airlief453ba02008-11-07 14:05:41 -08001/*
2 * Copyright © 2006 Keith Packard
3 * Copyright © 2007-2008 Dave Airlie
4 * Copyright © 2007-2008 Intel Corporation
5 * Jesse Barnes <jesse.barnes@intel.com>
6 *
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the "Software"),
9 * to deal in the Software without restriction, including without limitation
10 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
11 * and/or sell copies of the Software, and to permit persons to whom the
12 * Software is furnished to do so, subject to the following conditions:
13 *
14 * The above copyright notice and this permission notice shall be included in
15 * all copies or substantial portions of the Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
21 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
22 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
23 * OTHER DEALINGS IN THE SOFTWARE.
24 */
25#ifndef __DRM_CRTC_H__
26#define __DRM_CRTC_H__
27
28#include <linux/i2c.h>
29#include <linux/spinlock.h>
30#include <linux/types.h>
31#include <linux/idr.h>
Dave Airlief453ba02008-11-07 14:05:41 -080032#include <linux/fb.h>
Vandana Kannan985e5dc2013-12-19 15:34:07 +053033#include <linux/hdmi.h>
Boris Brezillonb5571e92014-07-22 12:09:10 +020034#include <linux/media-bus-format.h>
David Herrmannd7d2c482014-08-29 12:12:40 +020035#include <uapi/drm/drm_mode.h>
36#include <uapi/drm/drm_fourcc.h>
Rob Clark51fd3712013-11-19 12:10:12 -050037#include <drm/drm_modeset_lock.h>
Ville Syrjäläd7da8242016-07-26 19:06:57 +030038#include <drm/drm_rect.h>
Jesse Barnes308e5bc2011-11-14 14:51:28 -080039
Dave Airlief453ba02008-11-07 14:05:41 -080040struct drm_device;
41struct drm_mode_set;
42struct drm_framebuffer;
Paulo Zanoni7e3bdf42012-05-15 18:09:01 -030043struct drm_object_properties;
Thierry Reding595887e2012-11-21 15:00:47 +010044struct drm_file;
45struct drm_clip_rect;
Russell King7e435aa2014-06-15 11:07:12 +010046struct device_node;
Daniel Vettere2330f02014-10-29 11:34:56 +010047struct fence;
Daniel Vetter81065542016-06-21 10:54:13 +020048struct edid;
Dave Airlief453ba02008-11-07 14:05:41 -080049
Dave Airlief453ba02008-11-07 14:05:41 -080050struct drm_mode_object {
51 uint32_t id;
52 uint32_t type;
Paulo Zanoni7e3bdf42012-05-15 18:09:01 -030053 struct drm_object_properties *properties;
Dave Airlied0f37cf62016-04-15 15:10:36 +100054 struct kref refcount;
55 void (*free_cb)(struct kref *kref);
Paulo Zanoni7e3bdf42012-05-15 18:09:01 -030056};
57
Paulo Zanonife456162012-06-12 11:27:01 -030058#define DRM_OBJECT_MAX_PROPERTY 24
Paulo Zanoni7e3bdf42012-05-15 18:09:01 -030059struct drm_object_properties {
Rob Clark88a48e22014-12-18 16:01:50 -050060 int count, atomic_count;
Rob Clarkb17cd752014-12-16 18:05:30 -050061 /* NOTE: if we ever start dynamically destroying properties (ie.
62 * not at drm_mode_config_cleanup() time), then we'd have to do
63 * a better job of detaching property from mode objects to avoid
64 * dangling property pointers:
65 */
66 struct drm_property *properties[DRM_OBJECT_MAX_PROPERTY];
Rob Clark22b8b132014-12-16 18:05:31 -050067 /* do not read/write values directly, but use drm_object_property_get_value()
68 * and drm_object_property_set_value():
69 */
Paulo Zanoni7e3bdf42012-05-15 18:09:01 -030070 uint64_t values[DRM_OBJECT_MAX_PROPERTY];
Dave Airlief453ba02008-11-07 14:05:41 -080071};
72
Rob Clarkebc44cf2012-09-12 22:22:31 -050073static inline int64_t U642I64(uint64_t val)
74{
75 return (int64_t)*((int64_t *)&val);
76}
77static inline uint64_t I642U64(int64_t val)
78{
79 return (uint64_t)*((uint64_t *)&val);
80}
81
Robert Feketed9c38242015-11-02 16:14:08 +010082/*
83 * Rotation property bits. DRM_ROTATE_<degrees> rotates the image by the
84 * specified amount in degrees in counter clockwise direction. DRM_REFLECT_X and
85 * DRM_REFLECT_Y reflects the image along the specified axis prior to rotation
86 */
Joonas Lahtinen31ad61e2016-07-29 08:50:05 +030087#define DRM_ROTATE_0 BIT(0)
88#define DRM_ROTATE_90 BIT(1)
89#define DRM_ROTATE_180 BIT(2)
90#define DRM_ROTATE_270 BIT(3)
91#define DRM_ROTATE_MASK (DRM_ROTATE_0 | DRM_ROTATE_90 | \
92 DRM_ROTATE_180 | DRM_ROTATE_270)
93#define DRM_REFLECT_X BIT(4)
94#define DRM_REFLECT_Y BIT(5)
95#define DRM_REFLECT_MASK (DRM_REFLECT_X | DRM_REFLECT_Y)
Ville Syrjälä06596962014-07-08 10:31:51 +053096
Daniel Vetter55310002014-01-23 15:52:20 +010097enum drm_connector_force {
98 DRM_FORCE_UNSPECIFIED,
99 DRM_FORCE_OFF,
100 DRM_FORCE_ON, /* force on analog part normally */
101 DRM_FORCE_ON_DIGITAL, /* for DVI-I use digital connector */
Dave Airlief453ba02008-11-07 14:05:41 -0800102};
103
Daniel Vetter55310002014-01-23 15:52:20 +0100104#include <drm/drm_modes.h>
Damien Lespiau4aa17cf2013-09-25 16:45:21 +0100105
Dave Airlief453ba02008-11-07 14:05:41 -0800106enum drm_connector_status {
107 connector_status_connected = 1,
108 connector_status_disconnected = 2,
109 connector_status_unknown = 3,
110};
111
112enum subpixel_order {
113 SubPixelUnknown = 0,
114 SubPixelHorizontalRGB,
115 SubPixelHorizontalBGR,
116 SubPixelVerticalRGB,
117 SubPixelVerticalBGR,
118 SubPixelNone,
119};
120
Jesse Barnesda05a5a72011-04-15 13:48:57 -0700121#define DRM_COLOR_FORMAT_RGB444 (1<<0)
122#define DRM_COLOR_FORMAT_YCRCB444 (1<<1)
123#define DRM_COLOR_FORMAT_YCRCB422 (1<<2)
Stefan Agnerf0aa0832016-02-08 11:38:14 -0800124
125#define DRM_BUS_FLAG_DE_LOW (1<<0)
126#define DRM_BUS_FLAG_DE_HIGH (1<<1)
127/* drive data on pos. edge */
128#define DRM_BUS_FLAG_PIXDATA_POSEDGE (1<<2)
129/* drive data on neg. edge */
130#define DRM_BUS_FLAG_PIXDATA_NEGEDGE (1<<3)
131
Dave Airlief453ba02008-11-07 14:05:41 -0800132/*
133 * Describes a given display (e.g. CRT or flat panel) and its limitations.
134 */
135struct drm_display_info {
136 char name[DRM_DISPLAY_INFO_LEN];
Adam Jacksonfb439642010-08-03 14:38:16 -0400137
Dave Airlief453ba02008-11-07 14:05:41 -0800138 /* Physical size */
139 unsigned int width_mm;
140 unsigned int height_mm;
141
Dave Airlief453ba02008-11-07 14:05:41 -0800142 /* Clock limits FIXME: storage format */
143 unsigned int min_vfreq, max_vfreq;
144 unsigned int min_hfreq, max_hfreq;
145 unsigned int pixel_clock;
Jesse Barnes3b112282011-04-15 12:49:23 -0700146 unsigned int bpc;
Dave Airlief453ba02008-11-07 14:05:41 -0800147
Dave Airlief453ba02008-11-07 14:05:41 -0800148 enum subpixel_order subpixel_order;
Jesse Barnesda05a5a72011-04-15 13:48:57 -0700149 u32 color_formats;
Dave Airlief453ba02008-11-07 14:05:41 -0800150
Boris Brezillonb5571e92014-07-22 12:09:10 +0200151 const u32 *bus_formats;
152 unsigned int num_bus_formats;
Stefan Agnerf0aa0832016-02-08 11:38:14 -0800153 u32 bus_flags;
Boris Brezillonb5571e92014-07-22 12:09:10 +0200154
Mario Kleiner5d02626d2014-06-05 09:52:10 -0400155 /* Mask of supported hdmi deep color modes */
156 u8 edid_hdmi_dc_modes;
157
Jesse Barnesebec9a7b2011-08-03 09:22:54 -0700158 u8 cea_rev;
Dave Airlief453ba02008-11-07 14:05:41 -0800159};
160
Dave Airlie138f9eb2014-10-20 16:17:17 +1000161/* data corresponds to displayid vend/prod/serial */
162struct drm_tile_group {
163 struct kref refcount;
164 struct drm_device *dev;
165 int id;
166 u8 group_data[8];
167};
168
Daniel Vetterc6b0ca32015-12-04 09:46:01 +0100169/**
170 * struct drm_framebuffer_funcs - framebuffer hooks
171 */
Dave Airlief453ba02008-11-07 14:05:41 -0800172struct drm_framebuffer_funcs {
Daniel Vetterc6b0ca32015-12-04 09:46:01 +0100173 /**
174 * @destroy:
175 *
176 * Clean up framebuffer resources, specifically also unreference the
177 * backing storage. The core guarantees to call this function for every
178 * framebuffer successfully created by ->fb_create() in
Daniel Vetterd55f5322015-12-08 09:49:19 +0100179 * &drm_mode_config_funcs. Drivers must also call
180 * drm_framebuffer_cleanup() to release DRM core resources for this
181 * framebuffer.
Daniel Vetterc6b0ca32015-12-04 09:46:01 +0100182 */
Dave Airlief453ba02008-11-07 14:05:41 -0800183 void (*destroy)(struct drm_framebuffer *framebuffer);
Daniel Vetterc6b0ca32015-12-04 09:46:01 +0100184
185 /**
186 * @create_handle:
187 *
188 * Create a buffer handle in the driver-specific buffer manager (either
189 * GEM or TTM) valid for the passed-in struct &drm_file. This is used by
190 * the core to implement the GETFB IOCTL, which returns (for
191 * sufficiently priviledged user) also a native buffer handle. This can
192 * be used for seamless transitions between modesetting clients by
193 * copying the current screen contents to a private buffer and blending
194 * between that and the new contents.
195 *
Daniel Vetterd55f5322015-12-08 09:49:19 +0100196 * GEM based drivers should call drm_gem_handle_create() to create the
197 * handle.
198 *
Daniel Vetterc6b0ca32015-12-04 09:46:01 +0100199 * RETURNS:
200 *
201 * 0 on success or a negative error code on failure.
202 */
Dave Airlief453ba02008-11-07 14:05:41 -0800203 int (*create_handle)(struct drm_framebuffer *fb,
204 struct drm_file *file_priv,
205 unsigned int *handle);
Daniel Vetterc6b0ca32015-12-04 09:46:01 +0100206 /**
207 * @dirty:
Jakob Bornecrantz884840a2009-12-03 23:25:47 +0000208 *
Daniel Vetterc6b0ca32015-12-04 09:46:01 +0100209 * Optional callback for the dirty fb IOCTL.
Jakob Bornecrantz884840a2009-12-03 23:25:47 +0000210 *
Daniel Vetterc6b0ca32015-12-04 09:46:01 +0100211 * Userspace can notify the driver via this callback that an area of the
212 * framebuffer has changed and should be flushed to the display
213 * hardware. This can also be used internally, e.g. by the fbdev
214 * emulation, though that's not the case currently.
215 *
216 * See documentation in drm_mode.h for the struct drm_mode_fb_dirty_cmd
217 * for more information as all the semantics and arguments have a one to
218 * one mapping on this function.
219 *
220 * RETURNS:
221 *
222 * 0 on success or a negative error code on failure.
Jakob Bornecrantz884840a2009-12-03 23:25:47 +0000223 */
Thomas Hellstrom02b00162010-10-05 12:43:02 +0200224 int (*dirty)(struct drm_framebuffer *framebuffer,
225 struct drm_file *file_priv, unsigned flags,
Jakob Bornecrantz884840a2009-12-03 23:25:47 +0000226 unsigned color, struct drm_clip_rect *clips,
227 unsigned num_clips);
Dave Airlief453ba02008-11-07 14:05:41 -0800228};
229
230struct drm_framebuffer {
231 struct drm_device *dev;
Rob Clarkf7eff602012-09-05 21:48:38 +0000232 /*
233 * Note that the fb is refcounted for the benefit of driver internals,
234 * for example some hw, disabling a CRTC/plane is asynchronous, and
235 * scanout does not actually complete until the next vblank. So some
236 * cleanup (like releasing the reference(s) on the backing GEM bo(s))
237 * should be deferred. In cases like this, the driver would like to
238 * hold a ref to the fb even though it has already been removed from
239 * userspace perspective.
Dave Airlied0f37cf62016-04-15 15:10:36 +1000240 * The refcount is stored inside the mode object.
Rob Clarkf7eff602012-09-05 21:48:38 +0000241 */
Daniel Vetter4b096ac2012-12-10 21:19:18 +0100242 /*
243 * Place on the dev->mode_config.fb_list, access protected by
244 * dev->mode_config.fb_lock.
245 */
Dave Airlief453ba02008-11-07 14:05:41 -0800246 struct list_head head;
247 struct drm_mode_object base;
248 const struct drm_framebuffer_funcs *funcs;
Ville Syrjälä01f2c772011-12-20 00:06:49 +0200249 unsigned int pitches[4];
250 unsigned int offsets[4];
Rob Clarke3eb3252015-02-05 14:41:52 +0000251 uint64_t modifier[4];
Dave Airlief453ba02008-11-07 14:05:41 -0800252 unsigned int width;
253 unsigned int height;
254 /* depth can be 15 or 16 */
255 unsigned int depth;
256 int bits_per_pixel;
257 int flags;
Jesse Barnes308e5bc2011-11-14 14:51:28 -0800258 uint32_t pixel_format; /* fourcc format */
Gerd Hoffmanndd546592016-05-31 08:54:52 +0200259 int hot_x;
260 int hot_y;
Dave Airlief453ba02008-11-07 14:05:41 -0800261 struct list_head filp_head;
262};
263
264struct drm_property_blob {
265 struct drm_mode_object base;
Daniel Stone6bcacf52015-04-20 19:22:55 +0100266 struct drm_device *dev;
Daniel Stonee2f5d2e2015-05-22 13:34:51 +0100267 struct list_head head_global;
268 struct list_head head_file;
Thierry Redingecbbe592014-05-13 11:36:13 +0200269 size_t length;
Ville Syrjäläd63f5e62012-03-13 12:35:49 +0200270 unsigned char data[];
Dave Airlief453ba02008-11-07 14:05:41 -0800271};
272
273struct drm_property_enum {
274 uint64_t value;
275 struct list_head head;
276 char name[DRM_PROP_NAME_LEN];
277};
278
279struct drm_property {
280 struct list_head head;
281 struct drm_mode_object base;
282 uint32_t flags;
283 char name[DRM_PROP_NAME_LEN];
284 uint32_t num_values;
285 uint64_t *values;
Rob Clark98f75de2014-05-30 11:37:03 -0400286 struct drm_device *dev;
Dave Airlief453ba02008-11-07 14:05:41 -0800287
Daniel Vetter3758b342014-11-19 18:38:10 +0100288 struct list_head enum_list;
Dave Airlief453ba02008-11-07 14:05:41 -0800289};
290
291struct drm_crtc;
292struct drm_connector;
293struct drm_encoder;
Kristian Høgsbergd91d8a32009-11-17 12:43:55 -0500294struct drm_pending_vblank_event;
Jesse Barnes8cf5c912011-11-14 14:51:27 -0800295struct drm_plane;
Sean Paul3b336ec2013-08-14 16:47:37 -0400296struct drm_bridge;
Daniel Vetter144ecb92014-10-27 20:28:44 +0100297struct drm_atomic_state;
298
Daniel Vetter4490d4c2015-12-04 09:45:45 +0100299struct drm_crtc_helper_funcs;
300struct drm_encoder_helper_funcs;
301struct drm_connector_helper_funcs;
302struct drm_plane_helper_funcs;
303
Daniel Vetter144ecb92014-10-27 20:28:44 +0100304/**
Daniel Vettercc4ceb42014-07-25 21:30:38 +0200305 * struct drm_crtc_state - mutable CRTC state
Daniel Vetter07cc0ef2014-11-27 15:49:39 +0100306 * @crtc: backpointer to the CRTC
Daniel Vetter144ecb92014-10-27 20:28:44 +0100307 * @enable: whether the CRTC should be enabled, gates all other state
Daniel Vetterd9b13622014-11-26 16:57:41 +0100308 * @active: whether the CRTC is actively displaying (used for DPMS)
Maarten Lankhorstfc596662015-07-21 13:28:57 +0200309 * @planes_changed: planes on this crtc are updated
310 * @mode_changed: crtc_state->mode or crtc_state->enable has been changed
311 * @active_changed: crtc_state->active has been toggled.
312 * @connectors_changed: connectors to this crtc have been updated
Marek Szyprowski44d1240d2016-06-13 11:11:26 +0200313 * @zpos_changed: zpos values of planes on this crtc have been updated
Lionel Landwerlin5488dc12016-02-26 17:05:00 +0000314 * @color_mgmt_changed: color management properties have changed (degamma or
315 * gamma LUT or CSC matrix)
Rob Clark6ddd3882014-11-21 15:28:31 -0500316 * @plane_mask: bitmask of (1 << drm_plane_index(plane)) of attached planes
Maarten Lankhorst4cd9fa52016-01-04 12:53:18 +0100317 * @connector_mask: bitmask of (1 << drm_connector_index(connector)) of attached connectors
Maarten Lankhorste87a52b2016-01-28 15:04:58 +0100318 * @encoder_mask: bitmask of (1 << drm_encoder_index(encoder)) of attached encoders
Daniel Vetter623369e2014-09-16 17:50:47 +0200319 * @last_vblank_count: for helpers and drivers to capture the vblank of the
320 * update to ensure framebuffer cleanup isn't done too early
Daniel Vetter2f324b42014-10-29 11:13:47 +0100321 * @adjusted_mode: for use by helpers and drivers to compute adjusted mode timings
Daniel Vetter144ecb92014-10-27 20:28:44 +0100322 * @mode: current mode timings
Daniel Vetterac3ba4a2016-05-31 23:11:10 +0200323 * @mode_blob: &drm_property_blob for @mode
Lionel Landwerlin5488dc12016-02-26 17:05:00 +0000324 * @degamma_lut: Lookup table for converting framebuffer pixel data
325 * before apply the conversion matrix
326 * @ctm: Transformation matrix
327 * @gamma_lut: Lookup table for converting pixel data after the
328 * conversion matrix
Daniel Vetter144ecb92014-10-27 20:28:44 +0100329 * @event: optional pointer to a DRM event to signal upon completion of the
330 * state update
331 * @state: backpointer to global drm_atomic_state
Daniel Vetterd9b13622014-11-26 16:57:41 +0100332 *
333 * Note that the distinction between @enable and @active is rather subtile:
334 * Flipping @active while @enable is set without changing anything else may
335 * never return in a failure from the ->atomic_check callback. Userspace assumes
336 * that a DPMS On will always succeed. In other words: @enable controls resource
337 * assignment, @active controls the actual hardware state.
Daniel Vetter144ecb92014-10-27 20:28:44 +0100338 */
339struct drm_crtc_state {
Daniel Vetter07cc0ef2014-11-27 15:49:39 +0100340 struct drm_crtc *crtc;
341
Daniel Vettercc4ceb42014-07-25 21:30:38 +0200342 bool enable;
Daniel Vetterd9b13622014-11-26 16:57:41 +0100343 bool active;
Daniel Vetter144ecb92014-10-27 20:28:44 +0100344
Daniel Vetterc2fcd272014-11-05 00:14:14 +0100345 /* computed state bits used by helpers and drivers */
346 bool planes_changed : 1;
Daniel Vetter623369e2014-09-16 17:50:47 +0200347 bool mode_changed : 1;
Daniel Vettereab3bbe2015-01-22 16:36:21 +0100348 bool active_changed : 1;
Maarten Lankhorstfc596662015-07-21 13:28:57 +0200349 bool connectors_changed : 1;
Marek Szyprowski44d1240d2016-06-13 11:11:26 +0200350 bool zpos_changed : 1;
Lionel Landwerlin5488dc12016-02-26 17:05:00 +0000351 bool color_mgmt_changed : 1;
Daniel Vetter623369e2014-09-16 17:50:47 +0200352
Rob Clark6ddd3882014-11-21 15:28:31 -0500353 /* attached planes bitmask:
354 * WARNING: transitional helpers do not maintain plane_mask so
355 * drivers not converted over to atomic helpers should not rely
356 * on plane_mask being accurate!
357 */
358 u32 plane_mask;
359
Maarten Lankhorst4cd9fa52016-01-04 12:53:18 +0100360 u32 connector_mask;
Maarten Lankhorste87a52b2016-01-28 15:04:58 +0100361 u32 encoder_mask;
Maarten Lankhorst4cd9fa52016-01-04 12:53:18 +0100362
Daniel Vetter623369e2014-09-16 17:50:47 +0200363 /* last_vblank_count: for vblank waits before cleanup */
364 u32 last_vblank_count;
Daniel Vetterc2fcd272014-11-05 00:14:14 +0100365
Daniel Vetter2f324b42014-10-29 11:13:47 +0100366 /* adjusted_mode: for use by helpers and drivers */
367 struct drm_display_mode adjusted_mode;
368
Daniel Vetter144ecb92014-10-27 20:28:44 +0100369 struct drm_display_mode mode;
370
Daniel Stone99cf4a22015-05-25 19:11:51 +0100371 /* blob property to expose current mode to atomic userspace */
372 struct drm_property_blob *mode_blob;
373
Lionel Landwerlin5488dc12016-02-26 17:05:00 +0000374 /* blob property to expose color management to userspace */
375 struct drm_property_blob *degamma_lut;
376 struct drm_property_blob *ctm;
377 struct drm_property_blob *gamma_lut;
378
Daniel Vetter144ecb92014-10-27 20:28:44 +0100379 struct drm_pending_vblank_event *event;
380
381 struct drm_atomic_state *state;
382};
Dave Airlief453ba02008-11-07 14:05:41 -0800383
384/**
Daniel Vetter3bf04012014-10-27 16:54:27 +0100385 * struct drm_crtc_funcs - control CRTCs for a given device
Dave Airlief453ba02008-11-07 14:05:41 -0800386 *
387 * The drm_crtc_funcs structure is the central CRTC management structure
388 * in the DRM. Each CRTC controls one or more connectors (note that the name
389 * CRTC is simply historical, a CRTC may control LVDS, VGA, DVI, TV out, etc.
390 * connectors, not just CRTs).
391 *
392 * Each driver is responsible for filling out this structure at startup time,
393 * in addition to providing other modesetting features, like i2c and DDC
394 * bus accessors.
395 */
396struct drm_crtc_funcs {
Daniel Vetter88548632015-12-04 09:45:48 +0100397 /**
398 * @reset:
399 *
400 * Reset CRTC hardware and software state to off. This function isn't
401 * called by the core directly, only through drm_mode_config_reset().
402 * It's not a helper hook only for historical reasons.
403 *
404 * Atomic drivers can use drm_atomic_helper_crtc_reset() to reset
405 * atomic state using this hook.
406 */
Chris Wilsoneb0335562011-01-24 15:11:08 +0000407 void (*reset)(struct drm_crtc *crtc);
Dave Airlief453ba02008-11-07 14:05:41 -0800408
Daniel Vetterf6da8c62015-12-04 09:46:00 +0100409 /**
410 * @cursor_set:
411 *
412 * Update the cursor image. The cursor position is relative to the CRTC
413 * and can be partially or fully outside of the visible area.
414 *
415 * Note that contrary to all other KMS functions the legacy cursor entry
416 * points don't take a framebuffer object, but instead take directly a
417 * raw buffer object id from the driver's buffer manager (which is
418 * either GEM or TTM for current drivers).
419 *
420 * This entry point is deprecated, drivers should instead implement
421 * universal plane support and register a proper cursor plane using
422 * drm_crtc_init_with_planes().
423 *
424 * This callback is optional
425 *
426 * RETURNS:
427 *
428 * 0 on success or a negative error code on failure.
429 */
Dave Airlief453ba02008-11-07 14:05:41 -0800430 int (*cursor_set)(struct drm_crtc *crtc, struct drm_file *file_priv,
431 uint32_t handle, uint32_t width, uint32_t height);
Daniel Vetterf6da8c62015-12-04 09:46:00 +0100432
433 /**
434 * @cursor_set2:
435 *
436 * Update the cursor image, including hotspot information. The hotspot
437 * must not affect the cursor position in CRTC coordinates, but is only
438 * meant as a hint for virtualized display hardware to coordinate the
439 * guests and hosts cursor position. The cursor hotspot is relative to
440 * the cursor image. Otherwise this works exactly like @cursor_set.
441 *
442 * This entry point is deprecated, drivers should instead implement
443 * universal plane support and register a proper cursor plane using
444 * drm_crtc_init_with_planes().
445 *
446 * This callback is optional.
447 *
448 * RETURNS:
449 *
450 * 0 on success or a negative error code on failure.
451 */
Dave Airlie4c813d42013-06-20 11:48:52 +1000452 int (*cursor_set2)(struct drm_crtc *crtc, struct drm_file *file_priv,
453 uint32_t handle, uint32_t width, uint32_t height,
454 int32_t hot_x, int32_t hot_y);
Daniel Vetterf6da8c62015-12-04 09:46:00 +0100455
456 /**
457 * @cursor_move:
458 *
459 * Update the cursor position. The cursor does not need to be visible
460 * when this hook is called.
461 *
462 * This entry point is deprecated, drivers should instead implement
463 * universal plane support and register a proper cursor plane using
464 * drm_crtc_init_with_planes().
465 *
466 * This callback is optional.
467 *
468 * RETURNS:
469 *
470 * 0 on success or a negative error code on failure.
471 */
Dave Airlief453ba02008-11-07 14:05:41 -0800472 int (*cursor_move)(struct drm_crtc *crtc, int x, int y);
473
Daniel Vetterf6da8c62015-12-04 09:46:00 +0100474 /**
475 * @gamma_set:
476 *
477 * Set gamma on the CRTC.
478 *
479 * This callback is optional.
480 *
481 * NOTE:
482 *
483 * Drivers that support gamma tables and also fbdev emulation through
484 * the provided helper library need to take care to fill out the gamma
485 * hooks for both. Currently there's a bit an unfortunate duplication
486 * going on, which should eventually be unified to just one set of
487 * hooks.
488 */
Maarten Lankhorst7ea77282016-06-07 12:49:30 +0200489 int (*gamma_set)(struct drm_crtc *crtc, u16 *r, u16 *g, u16 *b,
490 uint32_t size);
Daniel Vetter88548632015-12-04 09:45:48 +0100491
492 /**
493 * @destroy:
494 *
495 * Clean up plane resources. This is only called at driver unload time
496 * through drm_mode_config_cleanup() since a CRTC cannot be hotplugged
497 * in DRM.
498 */
Dave Airlief453ba02008-11-07 14:05:41 -0800499 void (*destroy)(struct drm_crtc *crtc);
500
Daniel Vetterf6da8c62015-12-04 09:46:00 +0100501 /**
502 * @set_config:
503 *
504 * This is the main legacy entry point to change the modeset state on a
505 * CRTC. All the details of the desired configuration are passed in a
506 * struct &drm_mode_set - see there for details.
507 *
508 * Drivers implementing atomic modeset should use
509 * drm_atomic_helper_set_config() to implement this hook.
510 *
511 * RETURNS:
512 *
513 * 0 on success or a negative error code on failure.
514 */
Dave Airlief453ba02008-11-07 14:05:41 -0800515 int (*set_config)(struct drm_mode_set *set);
Kristian Høgsbergd91d8a32009-11-17 12:43:55 -0500516
Daniel Vetterf6da8c62015-12-04 09:46:00 +0100517 /**
518 * @page_flip:
519 *
520 * Legacy entry point to schedule a flip to the given framebuffer.
521 *
522 * Page flipping is a synchronization mechanism that replaces the frame
523 * buffer being scanned out by the CRTC with a new frame buffer during
524 * vertical blanking, avoiding tearing (except when requested otherwise
525 * through the DRM_MODE_PAGE_FLIP_ASYNC flag). When an application
526 * requests a page flip the DRM core verifies that the new frame buffer
527 * is large enough to be scanned out by the CRTC in the currently
528 * configured mode and then calls the CRTC ->page_flip() operation with a
529 * pointer to the new frame buffer.
530 *
531 * The driver must wait for any pending rendering to the new framebuffer
532 * to complete before executing the flip. It should also wait for any
533 * pending rendering from other drivers if the underlying buffer is a
534 * shared dma-buf.
535 *
536 * An application can request to be notified when the page flip has
537 * completed. The drm core will supply a struct &drm_event in the event
538 * parameter in this case. This can be handled by the
539 * drm_crtc_send_vblank_event() function, which the driver should call on
540 * the provided event upon completion of the flip. Note that if
541 * the driver supports vblank signalling and timestamping the vblank
542 * counters and timestamps must agree with the ones returned from page
543 * flip events. With the current vblank helper infrastructure this can
544 * be achieved by holding a vblank reference while the page flip is
545 * pending, acquired through drm_crtc_vblank_get() and released with
546 * drm_crtc_vblank_put(). Drivers are free to implement their own vblank
547 * counter and timestamp tracking though, e.g. if they have accurate
548 * timestamp registers in hardware.
549 *
550 * FIXME:
551 *
552 * Up to that point drivers need to manage events themselves and can use
553 * even->base.list freely for that. Specifically they need to ensure
554 * that they don't send out page flip (or vblank) events for which the
555 * corresponding drm file has been closed already. The drm core
556 * unfortunately does not (yet) take care of that. Therefore drivers
557 * currently must clean up and release pending events in their
558 * ->preclose driver function.
559 *
560 * This callback is optional.
561 *
562 * NOTE:
563 *
564 * Very early versions of the KMS ABI mandated that the driver must
565 * block (but not reject) any rendering to the old framebuffer until the
566 * flip operation has completed and the old framebuffer is no longer
567 * visible. This requirement has been lifted, and userspace is instead
568 * expected to request delivery of an event and wait with recycling old
569 * buffers until such has been received.
570 *
571 * RETURNS:
572 *
573 * 0 on success or a negative error code on failure. Note that if a
574 * ->page_flip() operation is already pending the callback should return
575 * -EBUSY. Pageflips on a disabled CRTC (either by setting a NULL mode
576 * or just runtime disabled through DPMS respectively the new atomic
Daniel Vetter4cba6852015-12-08 09:49:20 +0100577 * "ACTIVE" state) should result in an -EINVAL error code. Note that
578 * drm_atomic_helper_page_flip() checks this already for atomic drivers.
Kristian Høgsbergd91d8a32009-11-17 12:43:55 -0500579 */
580 int (*page_flip)(struct drm_crtc *crtc,
581 struct drm_framebuffer *fb,
Keith Packarded8d1972013-07-22 18:49:58 -0700582 struct drm_pending_vblank_event *event,
583 uint32_t flags);
Paulo Zanonibffd9de02012-05-15 18:09:05 -0300584
Daniel Vetter88548632015-12-04 09:45:48 +0100585 /**
586 * @set_property:
587 *
588 * This is the legacy entry point to update a property attached to the
589 * CRTC.
590 *
591 * Drivers implementing atomic modeset should use
592 * drm_atomic_helper_crtc_set_property() to implement this hook.
593 *
594 * This callback is optional if the driver does not support any legacy
595 * driver-private properties.
596 *
597 * RETURNS:
598 *
599 * 0 on success or a negative error code on failure.
600 */
Paulo Zanonibffd9de02012-05-15 18:09:05 -0300601 int (*set_property)(struct drm_crtc *crtc,
602 struct drm_property *property, uint64_t val);
Daniel Vetter144ecb92014-10-27 20:28:44 +0100603
Daniel Vetter88548632015-12-04 09:45:48 +0100604 /**
605 * @atomic_duplicate_state:
606 *
607 * Duplicate the current atomic state for this CRTC and return it.
608 * The core and helpers gurantee that any atomic state duplicated with
609 * this hook and still owned by the caller (i.e. not transferred to the
610 * driver by calling ->atomic_commit() from struct
611 * &drm_mode_config_funcs) will be cleaned up by calling the
612 * @atomic_destroy_state hook in this structure.
613 *
614 * Atomic drivers which don't subclass struct &drm_crtc should use
615 * drm_atomic_helper_crtc_duplicate_state(). Drivers that subclass the
616 * state structure to extend it with driver-private state should use
617 * __drm_atomic_helper_crtc_duplicate_state() to make sure shared state is
618 * duplicated in a consistent fashion across drivers.
619 *
620 * It is an error to call this hook before crtc->state has been
621 * initialized correctly.
622 *
623 * NOTE:
624 *
625 * If the duplicate state references refcounted resources this hook must
626 * acquire a reference for each of them. The driver must release these
627 * references again in @atomic_destroy_state.
628 *
629 * RETURNS:
630 *
631 * Duplicated atomic state or NULL when the allocation failed.
632 */
Daniel Vetter144ecb92014-10-27 20:28:44 +0100633 struct drm_crtc_state *(*atomic_duplicate_state)(struct drm_crtc *crtc);
Daniel Vetter88548632015-12-04 09:45:48 +0100634
635 /**
636 * @atomic_destroy_state:
637 *
638 * Destroy a state duplicated with @atomic_duplicate_state and release
639 * or unreference all resources it references
640 */
Daniel Vetter144ecb92014-10-27 20:28:44 +0100641 void (*atomic_destroy_state)(struct drm_crtc *crtc,
Daniel Vettercc4ceb42014-07-25 21:30:38 +0200642 struct drm_crtc_state *state);
Daniel Vetter88548632015-12-04 09:45:48 +0100643
644 /**
645 * @atomic_set_property:
646 *
647 * Decode a driver-private property value and store the decoded value
648 * into the passed-in state structure. Since the atomic core decodes all
649 * standardized properties (even for extensions beyond the core set of
650 * properties which might not be implemented by all drivers) this
651 * requires drivers to subclass the state structure.
652 *
653 * Such driver-private properties should really only be implemented for
654 * truly hardware/vendor specific state. Instead it is preferred to
655 * standardize atomic extension and decode the properties used to expose
656 * such an extension in the core.
657 *
658 * Do not call this function directly, use
659 * drm_atomic_crtc_set_property() instead.
660 *
661 * This callback is optional if the driver does not support any
662 * driver-private atomic properties.
663 *
664 * NOTE:
665 *
666 * This function is called in the state assembly phase of atomic
667 * modesets, which can be aborted for any reason (including on
668 * userspace's request to just check whether a configuration would be
669 * possible). Drivers MUST NOT touch any persistent state (hardware or
670 * software) or data structures except the passed in @state parameter.
671 *
672 * Also since userspace controls in which order properties are set this
673 * function must not do any input validation (since the state update is
674 * incomplete and hence likely inconsistent). Instead any such input
675 * validation must be done in the various atomic_check callbacks.
676 *
677 * RETURNS:
678 *
679 * 0 if the property has been found, -EINVAL if the property isn't
680 * implemented by the driver (which should never happen, the core only
681 * asks for properties attached to this CRTC). No other validation is
682 * allowed by the driver. The core already checks that the property
683 * value is within the range (integer, valid enum value, ...) the driver
684 * set when registering the property.
685 */
Daniel Vetter144ecb92014-10-27 20:28:44 +0100686 int (*atomic_set_property)(struct drm_crtc *crtc,
687 struct drm_crtc_state *state,
688 struct drm_property *property,
689 uint64_t val);
Daniel Vetter88548632015-12-04 09:45:48 +0100690 /**
691 * @atomic_get_property:
692 *
693 * Reads out the decoded driver-private property. This is used to
Daniel Vetterc6b0ca32015-12-04 09:46:01 +0100694 * implement the GETCRTC IOCTL.
Daniel Vetter88548632015-12-04 09:45:48 +0100695 *
696 * Do not call this function directly, use
697 * drm_atomic_crtc_get_property() instead.
698 *
699 * This callback is optional if the driver does not support any
700 * driver-private atomic properties.
701 *
702 * RETURNS:
703 *
704 * 0 on success, -EINVAL if the property isn't implemented by the
705 * driver (which should never happen, the core only asks for
706 * properties attached to this CRTC).
707 */
Rob Clarkac9c9252014-12-18 16:01:47 -0500708 int (*atomic_get_property)(struct drm_crtc *crtc,
709 const struct drm_crtc_state *state,
710 struct drm_property *property,
711 uint64_t *val);
Benjamin Gaignard79190ea2016-06-21 16:37:09 +0200712
713 /**
714 * @late_register:
715 *
716 * This optional hook can be used to register additional userspace
717 * interfaces attached to the crtc like debugfs interfaces.
718 * It is called late in the driver load sequence from drm_dev_register().
719 * Everything added from this callback should be unregistered in
720 * the early_unregister callback.
721 *
722 * Returns:
723 *
724 * 0 on success, or a negative error code on failure.
725 */
726 int (*late_register)(struct drm_crtc *crtc);
727
728 /**
729 * @early_unregister:
730 *
731 * This optional hook should be used to unregister the additional
732 * userspace interfaces attached to the crtc from
733 * late_unregister(). It is called from drm_dev_unregister(),
734 * early in the driver unload sequence to disable userspace access
735 * before data structures are torndown.
736 */
737 void (*early_unregister)(struct drm_crtc *crtc);
Dave Airlief453ba02008-11-07 14:05:41 -0800738};
739
740/**
Daniel Vetter3bf04012014-10-27 16:54:27 +0100741 * struct drm_crtc - central CRTC control structure
Jesse Barnes77491632011-11-07 12:03:14 -0800742 * @dev: parent DRM device
Daniel Vetter2c0c33d2014-10-27 20:19:38 +0100743 * @port: OF node used by drm_of_find_possible_crtcs()
Jesse Barnes77491632011-11-07 12:03:14 -0800744 * @head: list management
Daniel Vetterac3ba4a2016-05-31 23:11:10 +0200745 * @name: human readable name, can be overwritten by the driver
Rob Clark51fd3712013-11-19 12:10:12 -0500746 * @mutex: per-CRTC locking
Jesse Barnes77491632011-11-07 12:03:14 -0800747 * @base: base KMS object for ID tracking etc.
Matt Ropere13161a2014-04-01 15:22:38 -0700748 * @primary: primary plane for this CRTC
749 * @cursor: cursor plane for this CRTC
Daniel Vetter2c0c33d2014-10-27 20:19:38 +0100750 * @cursor_x: current x position of the cursor, used for universal cursor planes
751 * @cursor_y: current y position of the cursor, used for universal cursor planes
Dave Airlief453ba02008-11-07 14:05:41 -0800752 * @enabled: is this CRTC enabled?
Jesse Barnes77491632011-11-07 12:03:14 -0800753 * @mode: current mode timings
754 * @hwmode: mode timings as programmed to hw regs
Dave Airlief453ba02008-11-07 14:05:41 -0800755 * @x: x position on screen
756 * @y: y position on screen
Dave Airlief453ba02008-11-07 14:05:41 -0800757 * @funcs: CRTC control functions
Jesse Barnes77491632011-11-07 12:03:14 -0800758 * @gamma_size: size of gamma ramp
759 * @gamma_store: gamma ramp values
Jesse Barnes77491632011-11-07 12:03:14 -0800760 * @helper_private: mid-layer private data
Paulo Zanonibffd9de02012-05-15 18:09:05 -0300761 * @properties: property tracking for this CRTC
Dave Airlief453ba02008-11-07 14:05:41 -0800762 *
763 * Each CRTC may have one or more connectors associated with it. This structure
764 * allows the CRTC to be controlled.
765 */
766struct drm_crtc {
767 struct drm_device *dev;
Russell King7e435aa2014-06-15 11:07:12 +0100768 struct device_node *port;
Dave Airlief453ba02008-11-07 14:05:41 -0800769 struct list_head head;
770
Ville Syrjäläfa3ab4c2015-12-08 18:41:53 +0200771 char *name;
772
Daniel Vetterac3ba4a2016-05-31 23:11:10 +0200773 /**
774 * @mutex:
Daniel Vetter29494c12012-12-02 02:18:25 +0100775 *
776 * This provides a read lock for the overall crtc state (mode, dpms
777 * state, ...) and a write lock for everything which can be update
Daniel Vetterac3ba4a2016-05-31 23:11:10 +0200778 * without a full modeset (fb, cursor data, crtc properties ...). Full
779 * modeset also need to grab dev->mode_config.connection_mutex.
Daniel Vetter29494c12012-12-02 02:18:25 +0100780 */
Rob Clark51fd3712013-11-19 12:10:12 -0500781 struct drm_modeset_lock mutex;
Daniel Vetter29494c12012-12-02 02:18:25 +0100782
Dave Airlief453ba02008-11-07 14:05:41 -0800783 struct drm_mode_object base;
784
Matt Ropere13161a2014-04-01 15:22:38 -0700785 /* primary and cursor planes for CRTC */
786 struct drm_plane *primary;
787 struct drm_plane *cursor;
788
Daniel Vetter96094082016-07-15 21:47:59 +0200789 /**
790 * @index: Position inside the mode_config.list, can be used as an array
791 * index. It is invariant over the lifetime of the CRTC.
792 */
Chris Wilson490d3d12016-05-27 20:05:00 +0100793 unsigned index;
794
Matt Roper161d0dc2014-06-10 08:28:10 -0700795 /* position of cursor plane on crtc */
796 int cursor_x;
797 int cursor_y;
798
Dave Airlief453ba02008-11-07 14:05:41 -0800799 bool enabled;
800
Mario Kleiner27641c32010-10-23 04:20:23 +0200801 /* Requested mode from modesetting. */
Dave Airlief453ba02008-11-07 14:05:41 -0800802 struct drm_display_mode mode;
803
Mario Kleiner27641c32010-10-23 04:20:23 +0200804 /* Programmed mode in hw, after adjustments for encoders,
805 * crtc, panel scaling etc. Needed for timestamping etc.
806 */
807 struct drm_display_mode hwmode;
808
Dave Airlief453ba02008-11-07 14:05:41 -0800809 int x, y;
Dave Airlief453ba02008-11-07 14:05:41 -0800810 const struct drm_crtc_funcs *funcs;
811
Lionel Landwerlin5488dc12016-02-26 17:05:00 +0000812 /* Legacy FB CRTC gamma size for reporting to userspace */
Dave Airlief453ba02008-11-07 14:05:41 -0800813 uint32_t gamma_size;
814 uint16_t *gamma_store;
815
816 /* if you are using the helper */
Daniel Vetter4490d4c2015-12-04 09:45:45 +0100817 const struct drm_crtc_helper_funcs *helper_private;
Paulo Zanonibffd9de02012-05-15 18:09:05 -0300818
819 struct drm_object_properties properties;
Daniel Vetterd059f652014-07-25 18:07:40 +0200820
Daniel Vetter3b24f7d2016-06-08 14:19:00 +0200821 /**
822 * @state:
823 *
824 * Current atomic state for this CRTC.
825 */
Daniel Vetter144ecb92014-10-27 20:28:44 +0100826 struct drm_crtc_state *state;
827
Daniel Vetter3b24f7d2016-06-08 14:19:00 +0200828 /**
829 * @commit_list:
830 *
831 * List of &drm_crtc_commit structures tracking pending commits.
832 * Protected by @commit_lock. This list doesn't hold its own full
833 * reference, but burrows it from the ongoing commit. Commit entries
834 * must be removed from this list once the commit is fully completed,
835 * but before it's correspoding &drm_atomic_state gets destroyed.
836 */
837 struct list_head commit_list;
838
839 /**
840 * @commit_lock:
841 *
842 * Spinlock to protect @commit_list.
843 */
844 spinlock_t commit_lock;
845
846 /**
847 * @acquire_ctx:
848 *
849 * Per-CRTC implicit acquire context used by atomic drivers for legacy
850 * IOCTLs, so that atomic drivers can get at the locking acquire
851 * context.
Daniel Vetterd059f652014-07-25 18:07:40 +0200852 */
853 struct drm_modeset_acquire_ctx *acquire_ctx;
Dave Airlief453ba02008-11-07 14:05:41 -0800854};
855
Daniel Vetter144ecb92014-10-27 20:28:44 +0100856/**
857 * struct drm_connector_state - mutable connector state
Daniel Vetter07cc0ef2014-11-27 15:49:39 +0100858 * @connector: backpointer to the connector
Daniel Vettercc4ceb42014-07-25 21:30:38 +0200859 * @crtc: CRTC to connect connector to, NULL if disabled
Daniel Vetter623369e2014-09-16 17:50:47 +0200860 * @best_encoder: can be used by helpers and drivers to select the encoder
Daniel Vetter144ecb92014-10-27 20:28:44 +0100861 * @state: backpointer to global drm_atomic_state
862 */
863struct drm_connector_state {
Daniel Vetter07cc0ef2014-11-27 15:49:39 +0100864 struct drm_connector *connector;
865
Rob Clark6ddd3882014-11-21 15:28:31 -0500866 struct drm_crtc *crtc; /* do not write directly, use drm_atomic_set_crtc_for_connector() */
Daniel Vetter144ecb92014-10-27 20:28:44 +0100867
Daniel Vetter623369e2014-09-16 17:50:47 +0200868 struct drm_encoder *best_encoder;
869
Daniel Vetter144ecb92014-10-27 20:28:44 +0100870 struct drm_atomic_state *state;
871};
Dave Airlief453ba02008-11-07 14:05:41 -0800872
873/**
Daniel Vetter3bf04012014-10-27 16:54:27 +0100874 * struct drm_connector_funcs - control connectors on a given device
Daniel Vetter144ecb92014-10-27 20:28:44 +0100875 *
Dave Airlief453ba02008-11-07 14:05:41 -0800876 * Each CRTC may have one or more connectors attached to it. The functions
877 * below allow the core DRM code to control connectors, enumerate available modes,
878 * etc.
879 */
880struct drm_connector_funcs {
Daniel Vetter6fe14ac2015-12-04 09:45:58 +0100881 /**
882 * @dpms:
883 *
884 * Legacy entry point to set the per-connector DPMS state. Legacy DPMS
885 * is exposed as a standard property on the connector, but diverted to
886 * this callback in the drm core. Note that atomic drivers don't
887 * implement the 4 level DPMS support on the connector any more, but
888 * instead only have an on/off "ACTIVE" property on the CRTC object.
889 *
890 * Drivers implementing atomic modeset should use
891 * drm_atomic_helper_connector_dpms() to implement this hook.
892 *
893 * RETURNS:
894 *
895 * 0 on success or a negative error code on failure.
896 */
Maarten Lankhorst9a69a9a2015-07-21 11:34:55 +0200897 int (*dpms)(struct drm_connector *connector, int mode);
Daniel Vetter88548632015-12-04 09:45:48 +0100898
899 /**
900 * @reset:
901 *
902 * Reset connector hardware and software state to off. This function isn't
903 * called by the core directly, only through drm_mode_config_reset().
904 * It's not a helper hook only for historical reasons.
905 *
906 * Atomic drivers can use drm_atomic_helper_connector_reset() to reset
907 * atomic state using this hook.
908 */
Chris Wilsoneb0335562011-01-24 15:11:08 +0000909 void (*reset)(struct drm_connector *connector);
Chris Wilson930a9e22010-09-14 11:07:23 +0100910
Daniel Vetter6fe14ac2015-12-04 09:45:58 +0100911 /**
912 * @detect:
913 *
914 * Check to see if anything is attached to the connector. The parameter
915 * force is set to false whilst polling, true when checking the
916 * connector due to a user request. force can be used by the driver to
917 * avoid expensive, destructive operations during automated probing.
918 *
919 * FIXME:
920 *
921 * Note that this hook is only called by the probe helper. It's not in
922 * the helper library vtable purely for historical reasons. The only DRM
923 * core entry point to probe connector state is @fill_modes.
924 *
925 * RETURNS:
926 *
927 * drm_connector_status indicating the connector's status.
Chris Wilson930a9e22010-09-14 11:07:23 +0100928 */
Chris Wilson7b334fc2010-09-09 23:51:02 +0100929 enum drm_connector_status (*detect)(struct drm_connector *connector,
Chris Wilson930a9e22010-09-14 11:07:23 +0100930 bool force);
Daniel Vetter6fe14ac2015-12-04 09:45:58 +0100931
932 /**
933 * @force:
934 *
935 * This function is called to update internal encoder state when the
936 * connector is forced to a certain state by userspace, either through
937 * the sysfs interfaces or on the kernel cmdline. In that case the
938 * @detect callback isn't called.
939 *
940 * FIXME:
941 *
942 * Note that this hook is only called by the probe helper. It's not in
943 * the helper library vtable purely for historical reasons. The only DRM
944 * core entry point to probe connector state is @fill_modes.
945 */
946 void (*force)(struct drm_connector *connector);
947
948 /**
949 * @fill_modes:
950 *
951 * Entry point for output detection and basic mode validation. The
952 * driver should reprobe the output if needed (e.g. when hotplug
953 * handling is unreliable), add all detected modes to connector->modes
954 * and filter out any the device can't support in any configuration. It
955 * also needs to filter out any modes wider or higher than the
956 * parameters max_width and max_height indicate.
957 *
958 * The drivers must also prune any modes no longer valid from
959 * connector->modes. Furthermore it must update connector->status and
960 * connector->edid. If no EDID has been received for this output
961 * connector->edid must be NULL.
962 *
963 * Drivers using the probe helpers should use
964 * drm_helper_probe_single_connector_modes() or
965 * drm_helper_probe_single_connector_modes_nomerge() to implement this
966 * function.
967 *
968 * RETURNS:
969 *
970 * The number of modes detected and filled into connector->modes.
971 */
Jesse Barnes40a518d2009-01-12 12:05:32 -0800972 int (*fill_modes)(struct drm_connector *connector, uint32_t max_width, uint32_t max_height);
Daniel Vetter88548632015-12-04 09:45:48 +0100973
974 /**
975 * @set_property:
976 *
977 * This is the legacy entry point to update a property attached to the
978 * connector.
979 *
980 * Drivers implementing atomic modeset should use
981 * drm_atomic_helper_connector_set_property() to implement this hook.
982 *
983 * This callback is optional if the driver does not support any legacy
984 * driver-private properties.
985 *
986 * RETURNS:
987 *
988 * 0 on success or a negative error code on failure.
989 */
Dave Airlief453ba02008-11-07 14:05:41 -0800990 int (*set_property)(struct drm_connector *connector, struct drm_property *property,
991 uint64_t val);
Daniel Vetter88548632015-12-04 09:45:48 +0100992
993 /**
Chris Wilsonaaf285e2016-06-15 13:17:47 +0100994 * @late_register:
995 *
996 * This optional hook can be used to register additional userspace
997 * interfaces attached to the connector, light backlight control, i2c,
998 * DP aux or similar interfaces. It is called late in the driver load
999 * sequence from drm_connector_register() when registering all the
1000 * core drm connector interfaces. Everything added from this callback
1001 * should be unregistered in the early_unregister callback.
1002 *
1003 * Returns:
1004 *
1005 * 0 on success, or a negative error code on failure.
1006 */
1007 int (*late_register)(struct drm_connector *connector);
1008
1009 /**
1010 * @early_unregister:
1011 *
1012 * This optional hook should be used to unregister the additional
1013 * userspace interfaces attached to the connector from
1014 * late_unregister(). It is called from drm_connector_unregister(),
1015 * early in the driver unload sequence to disable userspace access
1016 * before data structures are torndown.
1017 */
1018 void (*early_unregister)(struct drm_connector *connector);
1019
1020 /**
Daniel Vetter88548632015-12-04 09:45:48 +01001021 * @destroy:
1022 *
1023 * Clean up connector resources. This is called at driver unload time
1024 * through drm_mode_config_cleanup(). It can also be called at runtime
1025 * when a connector is being hot-unplugged for drivers that support
1026 * connector hotplugging (e.g. DisplayPort MST).
1027 */
Dave Airlief453ba02008-11-07 14:05:41 -08001028 void (*destroy)(struct drm_connector *connector);
Daniel Vetter144ecb92014-10-27 20:28:44 +01001029
Daniel Vetter88548632015-12-04 09:45:48 +01001030 /**
1031 * @atomic_duplicate_state:
1032 *
1033 * Duplicate the current atomic state for this connector and return it.
1034 * The core and helpers gurantee that any atomic state duplicated with
1035 * this hook and still owned by the caller (i.e. not transferred to the
1036 * driver by calling ->atomic_commit() from struct
1037 * &drm_mode_config_funcs) will be cleaned up by calling the
1038 * @atomic_destroy_state hook in this structure.
1039 *
1040 * Atomic drivers which don't subclass struct &drm_connector_state should use
1041 * drm_atomic_helper_connector_duplicate_state(). Drivers that subclass the
1042 * state structure to extend it with driver-private state should use
1043 * __drm_atomic_helper_connector_duplicate_state() to make sure shared state is
1044 * duplicated in a consistent fashion across drivers.
1045 *
1046 * It is an error to call this hook before connector->state has been
1047 * initialized correctly.
1048 *
1049 * NOTE:
1050 *
1051 * If the duplicate state references refcounted resources this hook must
1052 * acquire a reference for each of them. The driver must release these
1053 * references again in @atomic_destroy_state.
1054 *
1055 * RETURNS:
1056 *
1057 * Duplicated atomic state or NULL when the allocation failed.
1058 */
Daniel Vetter144ecb92014-10-27 20:28:44 +01001059 struct drm_connector_state *(*atomic_duplicate_state)(struct drm_connector *connector);
Daniel Vetter88548632015-12-04 09:45:48 +01001060
1061 /**
1062 * @atomic_destroy_state:
1063 *
1064 * Destroy a state duplicated with @atomic_duplicate_state and release
1065 * or unreference all resources it references
1066 */
Daniel Vetter144ecb92014-10-27 20:28:44 +01001067 void (*atomic_destroy_state)(struct drm_connector *connector,
Daniel Vettercc4ceb42014-07-25 21:30:38 +02001068 struct drm_connector_state *state);
Daniel Vetter88548632015-12-04 09:45:48 +01001069
1070 /**
1071 * @atomic_set_property:
1072 *
1073 * Decode a driver-private property value and store the decoded value
1074 * into the passed-in state structure. Since the atomic core decodes all
1075 * standardized properties (even for extensions beyond the core set of
1076 * properties which might not be implemented by all drivers) this
1077 * requires drivers to subclass the state structure.
1078 *
1079 * Such driver-private properties should really only be implemented for
1080 * truly hardware/vendor specific state. Instead it is preferred to
1081 * standardize atomic extension and decode the properties used to expose
1082 * such an extension in the core.
1083 *
1084 * Do not call this function directly, use
1085 * drm_atomic_connector_set_property() instead.
1086 *
1087 * This callback is optional if the driver does not support any
1088 * driver-private atomic properties.
1089 *
1090 * NOTE:
1091 *
1092 * This function is called in the state assembly phase of atomic
1093 * modesets, which can be aborted for any reason (including on
1094 * userspace's request to just check whether a configuration would be
1095 * possible). Drivers MUST NOT touch any persistent state (hardware or
1096 * software) or data structures except the passed in @state parameter.
1097 *
1098 * Also since userspace controls in which order properties are set this
1099 * function must not do any input validation (since the state update is
1100 * incomplete and hence likely inconsistent). Instead any such input
1101 * validation must be done in the various atomic_check callbacks.
1102 *
1103 * RETURNS:
1104 *
1105 * 0 if the property has been found, -EINVAL if the property isn't
1106 * implemented by the driver (which shouldn't ever happen, the core only
1107 * asks for properties attached to this connector). No other validation
1108 * is allowed by the driver. The core already checks that the property
1109 * value is within the range (integer, valid enum value, ...) the driver
1110 * set when registering the property.
1111 */
Daniel Vetter144ecb92014-10-27 20:28:44 +01001112 int (*atomic_set_property)(struct drm_connector *connector,
1113 struct drm_connector_state *state,
1114 struct drm_property *property,
1115 uint64_t val);
Daniel Vetter88548632015-12-04 09:45:48 +01001116
1117 /**
1118 * @atomic_get_property:
1119 *
1120 * Reads out the decoded driver-private property. This is used to
Daniel Vetterc6b0ca32015-12-04 09:46:01 +01001121 * implement the GETCONNECTOR IOCTL.
Daniel Vetter88548632015-12-04 09:45:48 +01001122 *
1123 * Do not call this function directly, use
1124 * drm_atomic_connector_get_property() instead.
1125 *
1126 * This callback is optional if the driver does not support any
1127 * driver-private atomic properties.
1128 *
1129 * RETURNS:
1130 *
1131 * 0 on success, -EINVAL if the property isn't implemented by the
1132 * driver (which shouldn't ever happen, the core only asks for
1133 * properties attached to this connector).
1134 */
Rob Clarkac9c9252014-12-18 16:01:47 -05001135 int (*atomic_get_property)(struct drm_connector *connector,
1136 const struct drm_connector_state *state,
1137 struct drm_property *property,
1138 uint64_t *val);
Dave Airlief453ba02008-11-07 14:05:41 -08001139};
1140
Jesse Barnes6c3db922011-11-07 12:03:16 -08001141/**
Daniel Vetter3bf04012014-10-27 16:54:27 +01001142 * struct drm_encoder_funcs - encoder controls
Jesse Barnes6c3db922011-11-07 12:03:16 -08001143 *
1144 * Encoders sit between CRTCs and connectors.
1145 */
Dave Airlief453ba02008-11-07 14:05:41 -08001146struct drm_encoder_funcs {
Daniel Vetter88548632015-12-04 09:45:48 +01001147 /**
1148 * @reset:
1149 *
1150 * Reset encoder hardware and software state to off. This function isn't
1151 * called by the core directly, only through drm_mode_config_reset().
1152 * It's not a helper hook only for historical reasons.
1153 */
Chris Wilsoneb0335562011-01-24 15:11:08 +00001154 void (*reset)(struct drm_encoder *encoder);
Daniel Vetter88548632015-12-04 09:45:48 +01001155
1156 /**
1157 * @destroy:
1158 *
1159 * Clean up encoder resources. This is only called at driver unload time
1160 * through drm_mode_config_cleanup() since an encoder cannot be
1161 * hotplugged in DRM.
1162 */
Dave Airlief453ba02008-11-07 14:05:41 -08001163 void (*destroy)(struct drm_encoder *encoder);
Benjamin Gaignard79190ea2016-06-21 16:37:09 +02001164
1165 /**
1166 * @late_register:
1167 *
1168 * This optional hook can be used to register additional userspace
1169 * interfaces attached to the encoder like debugfs interfaces.
1170 * It is called late in the driver load sequence from drm_dev_register().
1171 * Everything added from this callback should be unregistered in
1172 * the early_unregister callback.
1173 *
1174 * Returns:
1175 *
1176 * 0 on success, or a negative error code on failure.
1177 */
1178 int (*late_register)(struct drm_encoder *encoder);
1179
1180 /**
1181 * @early_unregister:
1182 *
1183 * This optional hook should be used to unregister the additional
1184 * userspace interfaces attached to the encoder from
1185 * late_unregister(). It is called from drm_dev_unregister(),
1186 * early in the driver unload sequence to disable userspace access
1187 * before data structures are torndown.
1188 */
1189 void (*early_unregister)(struct drm_encoder *encoder);
Dave Airlief453ba02008-11-07 14:05:41 -08001190};
1191
Ben Skeggsafe887d2012-01-12 16:00:57 +10001192#define DRM_CONNECTOR_MAX_ENCODER 3
Dave Airlief453ba02008-11-07 14:05:41 -08001193
1194/**
Daniel Vetter3bf04012014-10-27 16:54:27 +01001195 * struct drm_encoder - central DRM encoder structure
Jesse Barnesdb3e4492011-11-07 12:03:17 -08001196 * @dev: parent DRM device
1197 * @head: list management
1198 * @base: base KMS object
Daniel Vetterac3ba4a2016-05-31 23:11:10 +02001199 * @name: human readable name, can be overwritten by the driver
Jesse Barnesdb3e4492011-11-07 12:03:17 -08001200 * @encoder_type: one of the %DRM_MODE_ENCODER_<foo> types in drm_mode.h
1201 * @possible_crtcs: bitmask of potential CRTC bindings
1202 * @possible_clones: bitmask of potential sibling encoders for cloning
1203 * @crtc: currently bound CRTC
Sean Paul3b336ec2013-08-14 16:47:37 -04001204 * @bridge: bridge associated to the encoder
Jesse Barnesdb3e4492011-11-07 12:03:17 -08001205 * @funcs: control functions
1206 * @helper_private: mid-layer private data
1207 *
1208 * CRTCs drive pixels to encoders, which convert them into signals
1209 * appropriate for a given connector or set of connectors.
Dave Airlief453ba02008-11-07 14:05:41 -08001210 */
1211struct drm_encoder {
1212 struct drm_device *dev;
1213 struct list_head head;
1214
1215 struct drm_mode_object base;
Jani Nikulae5748942014-05-14 16:58:20 +03001216 char *name;
Dave Airlief453ba02008-11-07 14:05:41 -08001217 int encoder_type;
Chris Wilson490d3d12016-05-27 20:05:00 +01001218
Daniel Vetter96094082016-07-15 21:47:59 +02001219 /**
1220 * @index: Position inside the mode_config.list, can be used as an array
1221 * index. It is invariant over the lifetime of the encoder.
1222 */
Chris Wilson490d3d12016-05-27 20:05:00 +01001223 unsigned index;
1224
Dave Airlief453ba02008-11-07 14:05:41 -08001225 uint32_t possible_crtcs;
1226 uint32_t possible_clones;
1227
1228 struct drm_crtc *crtc;
Sean Paul3b336ec2013-08-14 16:47:37 -04001229 struct drm_bridge *bridge;
Dave Airlief453ba02008-11-07 14:05:41 -08001230 const struct drm_encoder_funcs *funcs;
Daniel Vetter4490d4c2015-12-04 09:45:45 +01001231 const struct drm_encoder_helper_funcs *helper_private;
Dave Airlief453ba02008-11-07 14:05:41 -08001232};
1233
Dave Airlieeb1f8e4f32010-05-07 06:42:51 +00001234/* should we poll this connector for connects and disconnects */
1235/* hot plug detectable */
1236#define DRM_CONNECTOR_POLL_HPD (1 << 0)
1237/* poll for connections */
1238#define DRM_CONNECTOR_POLL_CONNECT (1 << 1)
1239/* can cleanly poll for disconnections without flickering the screen */
1240/* DACs should rarely do this without a lot of testing */
1241#define DRM_CONNECTOR_POLL_DISCONNECT (1 << 2)
1242
Wu Fengguang76adaa342011-09-05 14:23:20 +08001243#define MAX_ELD_BYTES 128
1244
Dave Airlief453ba02008-11-07 14:05:41 -08001245/**
Daniel Vetter3bf04012014-10-27 16:54:27 +01001246 * struct drm_connector - central DRM connector control structure
Jesse Barnes72252542011-11-07 12:03:18 -08001247 * @dev: parent DRM device
1248 * @kdev: kernel device for sysfs attributes
1249 * @attr: sysfs attributes
1250 * @head: list management
1251 * @base: base KMS object
Daniel Vetterac3ba4a2016-05-31 23:11:10 +02001252 * @name: human readable name, can be overwritten by the driver
Jesse Barnes72252542011-11-07 12:03:18 -08001253 * @connector_type: one of the %DRM_MODE_CONNECTOR_<foo> types from drm_mode.h
1254 * @connector_type_id: index into connector type enum
Dave Airlief453ba02008-11-07 14:05:41 -08001255 * @interlace_allowed: can this connector handle interlaced modes?
1256 * @doublescan_allowed: can this connector handle doublescan?
Daniel Vetter2c0c33d2014-10-27 20:19:38 +01001257 * @stereo_allowed: can this connector handle stereo modes?
Chris Wilson40daac62016-06-15 13:17:48 +01001258 * @registered: is this connector exposed (registered) with userspace?
Jesse Barnes72252542011-11-07 12:03:18 -08001259 * @modes: modes available on this connector (from fill_modes() + user)
1260 * @status: one of the drm_connector_status enums (connected, not, or unknown)
1261 * @probed_modes: list of modes derived directly from the display
1262 * @display_info: information about attached display (e.g. from EDID)
Dave Airlief453ba02008-11-07 14:05:41 -08001263 * @funcs: connector control functions
Jesse Barnes72252542011-11-07 12:03:18 -08001264 * @edid_blob_ptr: DRM property containing EDID if present
Paulo Zanoni7e3bdf42012-05-15 18:09:01 -03001265 * @properties: property tracking for this connector
Jesse Barnes72252542011-11-07 12:03:18 -08001266 * @polled: a %DRM_CONNECTOR_POLL_<foo> value for core driven polling
1267 * @dpms: current dpms state
1268 * @helper_private: mid-layer private data
Daniel Vetter2c0c33d2014-10-27 20:19:38 +01001269 * @cmdline_mode: mode line parsed from the kernel cmdline for this connector
Jesse Barnes72252542011-11-07 12:03:18 -08001270 * @force: a %DRM_FORCE_<foo> state for forced mode sets
Daniel Vetter2c0c33d2014-10-27 20:19:38 +01001271 * @override_edid: has the EDID been overwritten through debugfs for testing?
Jesse Barnes72252542011-11-07 12:03:18 -08001272 * @encoder_ids: valid encoders for this connector
1273 * @encoder: encoder driving this connector, if any
1274 * @eld: EDID-like data, if present
1275 * @dvi_dual: dual link DVI, if found
1276 * @max_tmds_clock: max clock rate, if found
1277 * @latency_present: AV delay info from ELD, if found
1278 * @video_latency: video latency info from ELD, if found
1279 * @audio_latency: audio latency info from ELD, if found
1280 * @null_edid_counter: track sinks that give us all zeros for the EDID
Daniel Vetter2c0c33d2014-10-27 20:19:38 +01001281 * @bad_edid_counter: track sinks that give us an EDID with invalid checksum
Daniel Vetterac6f2e22015-05-08 16:15:41 +02001282 * @edid_corrupt: indicates whether the last read EDID was corrupt
Daniel Vetter2c0c33d2014-10-27 20:19:38 +01001283 * @debugfs_entry: debugfs directory for this connector
Daniel Vetter144ecb92014-10-27 20:28:44 +01001284 * @state: current atomic state for this connector
Dave Airlie40d9b042014-10-20 16:29:33 +10001285 * @has_tile: is this connector connected to a tiled monitor
1286 * @tile_group: tile group for the connected monitor
1287 * @tile_is_single_monitor: whether the tile is one monitor housing
1288 * @num_h_tile: number of horizontal tiles in the tile group
1289 * @num_v_tile: number of vertical tiles in the tile group
1290 * @tile_h_loc: horizontal location of this tile
1291 * @tile_v_loc: vertical location of this tile
1292 * @tile_h_size: horizontal size of this tile.
1293 * @tile_v_size: vertical size of this tile.
Dave Airlief453ba02008-11-07 14:05:41 -08001294 *
1295 * Each connector may be connected to one or more CRTCs, or may be clonable by
1296 * another connector if they can share a CRTC. Each connector also has a specific
1297 * position in the broader display (referred to as a 'screen' though it could
1298 * span multiple monitors).
1299 */
1300struct drm_connector {
1301 struct drm_device *dev;
Dave Airlie5bdebb12013-10-11 14:07:25 +10001302 struct device *kdev;
Dave Airlief453ba02008-11-07 14:05:41 -08001303 struct device_attribute *attr;
1304 struct list_head head;
1305
1306 struct drm_mode_object base;
1307
Jani Nikula2abdd312014-05-14 16:58:19 +03001308 char *name;
Daniel Vetter69425592016-07-19 18:25:01 +02001309
1310 /**
1311 * @index: Compacted connector index, which matches the position inside
1312 * the mode_config.list for drivers not supporting hot-add/removing. Can
1313 * be used as an array index. It is invariant over the lifetime of the
1314 * connector.
1315 */
1316 unsigned index;
1317
Dave Airlief453ba02008-11-07 14:05:41 -08001318 int connector_type;
1319 int connector_type_id;
1320 bool interlace_allowed;
1321 bool doublescan_allowed;
Damien Lespiau560a0672013-09-25 16:45:29 +01001322 bool stereo_allowed;
Chris Wilson40daac62016-06-15 13:17:48 +01001323 bool registered;
Dave Airlief453ba02008-11-07 14:05:41 -08001324 struct list_head modes; /* list of modes on this connector */
1325
Dave Airlief453ba02008-11-07 14:05:41 -08001326 enum drm_connector_status status;
1327
1328 /* these are modes added by probing with DDC or the BIOS */
1329 struct list_head probed_modes;
1330
1331 struct drm_display_info display_info;
1332 const struct drm_connector_funcs *funcs;
1333
Dave Airlief453ba02008-11-07 14:05:41 -08001334 struct drm_property_blob *edid_blob_ptr;
Paulo Zanoni7e3bdf42012-05-15 18:09:01 -03001335 struct drm_object_properties properties;
Dave Airlief453ba02008-11-07 14:05:41 -08001336
Daniel Vetterac3ba4a2016-05-31 23:11:10 +02001337 /**
1338 * @path_blob_ptr:
1339 *
1340 * DRM blob property data for the DP MST path property.
1341 */
Dave Airlie43aba7e2014-06-05 14:01:31 +10001342 struct drm_property_blob *path_blob_ptr;
1343
Daniel Vetterac3ba4a2016-05-31 23:11:10 +02001344 /**
1345 * @tile_blob_ptr:
1346 *
1347 * DRM blob property data for the tile property (used mostly by DP MST).
1348 * This is meant for screens which are driven through separate display
1349 * pipelines represented by &drm_crtc, which might not be running with
1350 * genlocked clocks. For tiled panels which are genlocked, like
1351 * dual-link LVDS or dual-link DSI, the driver should try to not expose
1352 * the tiling and virtualize both &drm_crtc and &drm_plane if needed.
1353 */
Dave Airlie6f134d72014-10-20 16:30:50 +10001354 struct drm_property_blob *tile_blob_ptr;
1355
Dave Airlieeb1f8e4f32010-05-07 06:42:51 +00001356 uint8_t polled; /* DRM_CONNECTOR_POLL_* */
1357
Keith Packardc9fb15f2009-05-30 20:42:28 -07001358 /* requested DPMS state */
1359 int dpms;
1360
Daniel Vetter4490d4c2015-12-04 09:45:45 +01001361 const struct drm_connector_helper_funcs *helper_private;
Dave Airlief453ba02008-11-07 14:05:41 -08001362
Dave Airlied50ba252009-09-23 14:44:08 +10001363 /* forced on connector */
Chris Wilsoneaf99c72014-08-06 10:08:32 +02001364 struct drm_cmdline_mode cmdline_mode;
Dave Airlied50ba252009-09-23 14:44:08 +10001365 enum drm_connector_force force;
Thomas Wood4cf2b282014-06-18 17:52:33 +01001366 bool override_edid;
Dave Airlief453ba02008-11-07 14:05:41 -08001367 uint32_t encoder_ids[DRM_CONNECTOR_MAX_ENCODER];
Dave Airlief453ba02008-11-07 14:05:41 -08001368 struct drm_encoder *encoder; /* currently active encoder */
Dave Airlie4a9a8b72011-06-14 06:13:55 +00001369
Wu Fengguang76adaa342011-09-05 14:23:20 +08001370 /* EDID bits */
1371 uint8_t eld[MAX_ELD_BYTES];
1372 bool dvi_dual;
1373 int max_tmds_clock; /* in MHz */
1374 bool latency_present[2];
1375 int video_latency[2]; /* [0]: progressive, [1]: interlaced */
1376 int audio_latency[2];
Dave Airlie4a9a8b72011-06-14 06:13:55 +00001377 int null_edid_counter; /* needed to workaround some HW bugs where we get all 0s */
Jerome Glisse0b2443e2012-08-09 11:25:51 -04001378 unsigned bad_edid_counter;
Thomas Wood30f65702014-06-18 17:52:32 +01001379
Todd Previte6ba2bd32015-04-21 11:09:41 -07001380 /* Flag for raw EDID header corruption - used in Displayport
1381 * compliance testing - * Displayport Link CTS Core 1.2 rev1.1 4.2.2.6
1382 */
1383 bool edid_corrupt;
1384
Thomas Wood30f65702014-06-18 17:52:32 +01001385 struct dentry *debugfs_entry;
Daniel Vetter144ecb92014-10-27 20:28:44 +01001386
1387 struct drm_connector_state *state;
Dave Airlie40d9b042014-10-20 16:29:33 +10001388
1389 /* DisplayID bits */
1390 bool has_tile;
1391 struct drm_tile_group *tile_group;
1392 bool tile_is_single_monitor;
1393
1394 uint8_t num_h_tile, num_v_tile;
1395 uint8_t tile_h_loc, tile_v_loc;
1396 uint16_t tile_h_size, tile_v_size;
Dave Airlief453ba02008-11-07 14:05:41 -08001397};
1398
1399/**
Daniel Vetter144ecb92014-10-27 20:28:44 +01001400 * struct drm_plane_state - mutable plane state
Daniel Vetter07cc0ef2014-11-27 15:49:39 +01001401 * @plane: backpointer to the plane
Daniel Vetter144ecb92014-10-27 20:28:44 +01001402 * @crtc: currently bound CRTC, NULL if disabled
Daniel Vettercc4ceb42014-07-25 21:30:38 +02001403 * @fb: currently bound framebuffer
Daniel Vettere2330f02014-10-29 11:34:56 +01001404 * @fence: optional fence to wait for before scanning out @fb
Daniel Vetter144ecb92014-10-27 20:28:44 +01001405 * @crtc_x: left position of visible portion of plane on crtc
1406 * @crtc_y: upper position of visible portion of plane on crtc
1407 * @crtc_w: width of visible portion of plane on crtc
1408 * @crtc_h: height of visible portion of plane on crtc
1409 * @src_x: left position of visible portion of plane within
1410 * plane (in 16.16)
1411 * @src_y: upper position of visible portion of plane within
1412 * plane (in 16.16)
1413 * @src_w: width of visible portion of plane (in 16.16)
1414 * @src_h: height of visible portion of plane (in 16.16)
Daniel Vetterac3ba4a2016-05-31 23:11:10 +02001415 * @rotation: rotation of the plane
Marek Szyprowski44d1240d2016-06-13 11:11:26 +02001416 * @zpos: priority of the given plane on crtc (optional)
1417 * @normalized_zpos: normalized value of zpos: unique, range from 0 to N-1
1418 * where N is the number of active planes for given crtc
Ville Syrjäläd7da8242016-07-26 19:06:57 +03001419 * @src: clipped source coordinates of the plane (in 16.16)
1420 * @dst: clipped destination coordinates of the plane
1421 * @visible: visibility of the plane
Daniel Vetter144ecb92014-10-27 20:28:44 +01001422 * @state: backpointer to global drm_atomic_state
1423 */
1424struct drm_plane_state {
Daniel Vetter07cc0ef2014-11-27 15:49:39 +01001425 struct drm_plane *plane;
1426
Rob Clark6ddd3882014-11-21 15:28:31 -05001427 struct drm_crtc *crtc; /* do not write directly, use drm_atomic_set_crtc_for_plane() */
1428 struct drm_framebuffer *fb; /* do not write directly, use drm_atomic_set_fb_for_plane() */
Daniel Vettere2330f02014-10-29 11:34:56 +01001429 struct fence *fence;
Daniel Vetter144ecb92014-10-27 20:28:44 +01001430
1431 /* Signed dest location allows it to be partially off screen */
1432 int32_t crtc_x, crtc_y;
1433 uint32_t crtc_w, crtc_h;
1434
1435 /* Source values are 16.16 fixed point */
1436 uint32_t src_x, src_y;
1437 uint32_t src_h, src_w;
1438
Matt Roper1da30622015-01-21 16:35:40 -08001439 /* Plane rotation */
1440 unsigned int rotation;
1441
Marek Szyprowski44d1240d2016-06-13 11:11:26 +02001442 /* Plane zpos */
1443 unsigned int zpos;
1444 unsigned int normalized_zpos;
1445
Ville Syrjäläd7da8242016-07-26 19:06:57 +03001446 /* Clipped coordinates */
1447 struct drm_rect src, dst;
1448
1449 /*
1450 * Is the plane actually visible? Can be false even
1451 * if fb!=NULL and crtc!=NULL, due to clipping.
1452 */
1453 bool visible;
1454
Daniel Vetter144ecb92014-10-27 20:28:44 +01001455 struct drm_atomic_state *state;
1456};
1457
1458
1459/**
Daniel Vetter3bf04012014-10-27 16:54:27 +01001460 * struct drm_plane_funcs - driver plane control functions
Jesse Barnes8cf5c912011-11-14 14:51:27 -08001461 */
1462struct drm_plane_funcs {
Daniel Vetter88548632015-12-04 09:45:48 +01001463 /**
1464 * @update_plane:
1465 *
1466 * This is the legacy entry point to enable and configure the plane for
1467 * the given CRTC and framebuffer. It is never called to disable the
1468 * plane, i.e. the passed-in crtc and fb paramters are never NULL.
1469 *
1470 * The source rectangle in frame buffer memory coordinates is given by
1471 * the src_x, src_y, src_w and src_h parameters (as 16.16 fixed point
1472 * values). Devices that don't support subpixel plane coordinates can
1473 * ignore the fractional part.
1474 *
1475 * The destination rectangle in CRTC coordinates is given by the
1476 * crtc_x, crtc_y, crtc_w and crtc_h parameters (as integer values).
1477 * Devices scale the source rectangle to the destination rectangle. If
1478 * scaling is not supported, and the source rectangle size doesn't match
1479 * the destination rectangle size, the driver must return a
1480 * -<errorname>EINVAL</errorname> error.
1481 *
1482 * Drivers implementing atomic modeset should use
1483 * drm_atomic_helper_update_plane() to implement this hook.
1484 *
1485 * RETURNS:
1486 *
1487 * 0 on success or a negative error code on failure.
1488 */
Jesse Barnes8cf5c912011-11-14 14:51:27 -08001489 int (*update_plane)(struct drm_plane *plane,
1490 struct drm_crtc *crtc, struct drm_framebuffer *fb,
1491 int crtc_x, int crtc_y,
1492 unsigned int crtc_w, unsigned int crtc_h,
1493 uint32_t src_x, uint32_t src_y,
1494 uint32_t src_w, uint32_t src_h);
Daniel Vetter88548632015-12-04 09:45:48 +01001495
1496 /**
1497 * @disable_plane:
1498 *
1499 * This is the legacy entry point to disable the plane. The DRM core
Daniel Vetterc6b0ca32015-12-04 09:46:01 +01001500 * calls this method in response to a DRM_IOCTL_MODE_SETPLANE IOCTL call
Daniel Vetter88548632015-12-04 09:45:48 +01001501 * with the frame buffer ID set to 0. Disabled planes must not be
1502 * processed by the CRTC.
1503 *
1504 * Drivers implementing atomic modeset should use
1505 * drm_atomic_helper_disable_plane() to implement this hook.
1506 *
1507 * RETURNS:
1508 *
1509 * 0 on success or a negative error code on failure.
1510 */
Jesse Barnes8cf5c912011-11-14 14:51:27 -08001511 int (*disable_plane)(struct drm_plane *plane);
Daniel Vetter88548632015-12-04 09:45:48 +01001512
1513 /**
1514 * @destroy:
1515 *
1516 * Clean up plane resources. This is only called at driver unload time
1517 * through drm_mode_config_cleanup() since a plane cannot be hotplugged
1518 * in DRM.
1519 */
Jesse Barnes8cf5c912011-11-14 14:51:27 -08001520 void (*destroy)(struct drm_plane *plane);
Daniel Vetter88548632015-12-04 09:45:48 +01001521
1522 /**
1523 * @reset:
1524 *
1525 * Reset plane hardware and software state to off. This function isn't
1526 * called by the core directly, only through drm_mode_config_reset().
1527 * It's not a helper hook only for historical reasons.
1528 *
1529 * Atomic drivers can use drm_atomic_helper_plane_reset() to reset
1530 * atomic state using this hook.
1531 */
Daniel Vetter2a0d7cf2014-07-29 15:32:37 +02001532 void (*reset)(struct drm_plane *plane);
Rob Clark4d939142012-05-17 02:23:27 -06001533
Daniel Vetter88548632015-12-04 09:45:48 +01001534 /**
1535 * @set_property:
1536 *
1537 * This is the legacy entry point to update a property attached to the
1538 * plane.
1539 *
1540 * Drivers implementing atomic modeset should use
1541 * drm_atomic_helper_plane_set_property() to implement this hook.
1542 *
1543 * This callback is optional if the driver does not support any legacy
1544 * driver-private properties.
1545 *
1546 * RETURNS:
1547 *
1548 * 0 on success or a negative error code on failure.
1549 */
Rob Clark4d939142012-05-17 02:23:27 -06001550 int (*set_property)(struct drm_plane *plane,
1551 struct drm_property *property, uint64_t val);
Daniel Vetter144ecb92014-10-27 20:28:44 +01001552
Daniel Vetter88548632015-12-04 09:45:48 +01001553 /**
1554 * @atomic_duplicate_state:
1555 *
1556 * Duplicate the current atomic state for this plane and return it.
1557 * The core and helpers gurantee that any atomic state duplicated with
1558 * this hook and still owned by the caller (i.e. not transferred to the
1559 * driver by calling ->atomic_commit() from struct
1560 * &drm_mode_config_funcs) will be cleaned up by calling the
1561 * @atomic_destroy_state hook in this structure.
1562 *
1563 * Atomic drivers which don't subclass struct &drm_plane_state should use
1564 * drm_atomic_helper_plane_duplicate_state(). Drivers that subclass the
1565 * state structure to extend it with driver-private state should use
1566 * __drm_atomic_helper_plane_duplicate_state() to make sure shared state is
1567 * duplicated in a consistent fashion across drivers.
1568 *
1569 * It is an error to call this hook before plane->state has been
1570 * initialized correctly.
1571 *
1572 * NOTE:
1573 *
1574 * If the duplicate state references refcounted resources this hook must
1575 * acquire a reference for each of them. The driver must release these
1576 * references again in @atomic_destroy_state.
1577 *
1578 * RETURNS:
1579 *
1580 * Duplicated atomic state or NULL when the allocation failed.
1581 */
Daniel Vetter144ecb92014-10-27 20:28:44 +01001582 struct drm_plane_state *(*atomic_duplicate_state)(struct drm_plane *plane);
Daniel Vetter88548632015-12-04 09:45:48 +01001583
1584 /**
1585 * @atomic_destroy_state:
1586 *
1587 * Destroy a state duplicated with @atomic_duplicate_state and release
1588 * or unreference all resources it references
1589 */
Daniel Vetter144ecb92014-10-27 20:28:44 +01001590 void (*atomic_destroy_state)(struct drm_plane *plane,
Daniel Vettercc4ceb42014-07-25 21:30:38 +02001591 struct drm_plane_state *state);
Daniel Vetter88548632015-12-04 09:45:48 +01001592
1593 /**
1594 * @atomic_set_property:
1595 *
1596 * Decode a driver-private property value and store the decoded value
1597 * into the passed-in state structure. Since the atomic core decodes all
1598 * standardized properties (even for extensions beyond the core set of
1599 * properties which might not be implemented by all drivers) this
1600 * requires drivers to subclass the state structure.
1601 *
1602 * Such driver-private properties should really only be implemented for
1603 * truly hardware/vendor specific state. Instead it is preferred to
1604 * standardize atomic extension and decode the properties used to expose
1605 * such an extension in the core.
1606 *
1607 * Do not call this function directly, use
1608 * drm_atomic_plane_set_property() instead.
1609 *
1610 * This callback is optional if the driver does not support any
1611 * driver-private atomic properties.
1612 *
1613 * NOTE:
1614 *
1615 * This function is called in the state assembly phase of atomic
1616 * modesets, which can be aborted for any reason (including on
1617 * userspace's request to just check whether a configuration would be
1618 * possible). Drivers MUST NOT touch any persistent state (hardware or
1619 * software) or data structures except the passed in @state parameter.
1620 *
1621 * Also since userspace controls in which order properties are set this
1622 * function must not do any input validation (since the state update is
1623 * incomplete and hence likely inconsistent). Instead any such input
1624 * validation must be done in the various atomic_check callbacks.
1625 *
1626 * RETURNS:
1627 *
1628 * 0 if the property has been found, -EINVAL if the property isn't
1629 * implemented by the driver (which shouldn't ever happen, the core only
1630 * asks for properties attached to this plane). No other validation is
1631 * allowed by the driver. The core already checks that the property
1632 * value is within the range (integer, valid enum value, ...) the driver
1633 * set when registering the property.
1634 */
Daniel Vetter144ecb92014-10-27 20:28:44 +01001635 int (*atomic_set_property)(struct drm_plane *plane,
1636 struct drm_plane_state *state,
1637 struct drm_property *property,
1638 uint64_t val);
Daniel Vetter88548632015-12-04 09:45:48 +01001639
1640 /**
1641 * @atomic_get_property:
1642 *
1643 * Reads out the decoded driver-private property. This is used to
Daniel Vetterc6b0ca32015-12-04 09:46:01 +01001644 * implement the GETPLANE IOCTL.
Daniel Vetter88548632015-12-04 09:45:48 +01001645 *
1646 * Do not call this function directly, use
1647 * drm_atomic_plane_get_property() instead.
1648 *
1649 * This callback is optional if the driver does not support any
1650 * driver-private atomic properties.
1651 *
1652 * RETURNS:
1653 *
1654 * 0 on success, -EINVAL if the property isn't implemented by the
1655 * driver (which should never happen, the core only asks for
1656 * properties attached to this plane).
1657 */
Rob Clarkac9c9252014-12-18 16:01:47 -05001658 int (*atomic_get_property)(struct drm_plane *plane,
1659 const struct drm_plane_state *state,
1660 struct drm_property *property,
1661 uint64_t *val);
Benjamin Gaignard79190ea2016-06-21 16:37:09 +02001662 /**
1663 * @late_register:
1664 *
1665 * This optional hook can be used to register additional userspace
1666 * interfaces attached to the plane like debugfs interfaces.
1667 * It is called late in the driver load sequence from drm_dev_register().
1668 * Everything added from this callback should be unregistered in
1669 * the early_unregister callback.
1670 *
1671 * Returns:
1672 *
1673 * 0 on success, or a negative error code on failure.
1674 */
1675 int (*late_register)(struct drm_plane *plane);
1676
1677 /**
1678 * @early_unregister:
1679 *
1680 * This optional hook should be used to unregister the additional
1681 * userspace interfaces attached to the plane from
1682 * late_unregister(). It is called from drm_dev_unregister(),
1683 * early in the driver unload sequence to disable userspace access
1684 * before data structures are torndown.
1685 */
1686 void (*early_unregister)(struct drm_plane *plane);
Jesse Barnes8cf5c912011-11-14 14:51:27 -08001687};
1688
Matt Ropere27dde32014-04-01 15:22:30 -07001689enum drm_plane_type {
1690 DRM_PLANE_TYPE_OVERLAY,
1691 DRM_PLANE_TYPE_PRIMARY,
1692 DRM_PLANE_TYPE_CURSOR,
1693};
1694
Daniel Vetter88548632015-12-04 09:45:48 +01001695
Jesse Barnes8cf5c912011-11-14 14:51:27 -08001696/**
Daniel Vetter3bf04012014-10-27 16:54:27 +01001697 * struct drm_plane - central DRM plane control structure
Jesse Barnes8cf5c912011-11-14 14:51:27 -08001698 * @dev: DRM device this plane belongs to
1699 * @head: for list management
Daniel Vetterac3ba4a2016-05-31 23:11:10 +02001700 * @name: human readable name, can be overwritten by the driver
Jesse Barnes8cf5c912011-11-14 14:51:27 -08001701 * @base: base mode object
1702 * @possible_crtcs: pipes this plane can be bound to
1703 * @format_types: array of formats supported by this plane
1704 * @format_count: number of formats supported
Laurent Pinchart7eb5f302015-03-09 10:41:07 +02001705 * @format_default: driver hasn't supplied supported formats for the plane
Jesse Barnes8cf5c912011-11-14 14:51:27 -08001706 * @crtc: currently bound CRTC
1707 * @fb: currently bound fb
Daniel Vetter2c0c33d2014-10-27 20:19:38 +01001708 * @old_fb: Temporary tracking of the old fb while a modeset is ongoing. Used by
1709 * drm_mode_set_config_internal() to implement correct refcounting.
Jesse Barnes8cf5c912011-11-14 14:51:27 -08001710 * @funcs: helper functions
Rob Clark4d939142012-05-17 02:23:27 -06001711 * @properties: property tracking for this plane
Matt Ropere27dde32014-04-01 15:22:30 -07001712 * @type: type of plane (overlay, primary, cursor)
Daniel Vetter144ecb92014-10-27 20:28:44 +01001713 * @state: current atomic state for this plane
Marek Szyprowski44d1240d2016-06-13 11:11:26 +02001714 * @zpos_property: zpos property for this plane
Daniel Vetterac3ba4a2016-05-31 23:11:10 +02001715 * @helper_private: mid-layer private data
Jesse Barnes8cf5c912011-11-14 14:51:27 -08001716 */
1717struct drm_plane {
1718 struct drm_device *dev;
1719 struct list_head head;
1720
Ville Syrjälä9f4c97a2015-12-08 18:41:54 +02001721 char *name;
1722
Daniel Vetterac3ba4a2016-05-31 23:11:10 +02001723 /**
1724 * @mutex:
1725 *
1726 * Protects modeset plane state, together with the mutex of &drm_crtc
1727 * this plane is linked to (when active, getting actived or getting
1728 * disabled).
1729 */
Daniel Vetter4d02e2d2014-11-11 10:12:00 +01001730 struct drm_modeset_lock mutex;
1731
Jesse Barnes8cf5c912011-11-14 14:51:27 -08001732 struct drm_mode_object base;
1733
1734 uint32_t possible_crtcs;
1735 uint32_t *format_types;
Thierry Reding45e37432015-08-12 16:54:28 +02001736 unsigned int format_count;
Laurent Pinchart7eb5f302015-03-09 10:41:07 +02001737 bool format_default;
Jesse Barnes8cf5c912011-11-14 14:51:27 -08001738
1739 struct drm_crtc *crtc;
1740 struct drm_framebuffer *fb;
1741
Daniel Vetter3d30a592014-07-27 13:42:42 +02001742 struct drm_framebuffer *old_fb;
1743
Jesse Barnes8cf5c912011-11-14 14:51:27 -08001744 const struct drm_plane_funcs *funcs;
Rob Clark4d939142012-05-17 02:23:27 -06001745
1746 struct drm_object_properties properties;
Matt Ropere27dde32014-04-01 15:22:30 -07001747
1748 enum drm_plane_type type;
Daniel Vetter144ecb92014-10-27 20:28:44 +01001749
Daniel Vetter96094082016-07-15 21:47:59 +02001750 /**
1751 * @index: Position inside the mode_config.list, can be used as an array
1752 * index. It is invariant over the lifetime of the plane.
1753 */
Chris Wilson490d3d12016-05-27 20:05:00 +01001754 unsigned index;
1755
Daniel Vetter4490d4c2015-12-04 09:45:45 +01001756 const struct drm_plane_helper_funcs *helper_private;
Daniel Vetterc2fcd272014-11-05 00:14:14 +01001757
Daniel Vetter144ecb92014-10-27 20:28:44 +01001758 struct drm_plane_state *state;
Marek Szyprowski44d1240d2016-06-13 11:11:26 +02001759
1760 struct drm_property *zpos_property;
Jesse Barnes8cf5c912011-11-14 14:51:27 -08001761};
1762
1763/**
Daniel Vetter3bf04012014-10-27 16:54:27 +01001764 * struct drm_bridge_funcs - drm_bridge control functions
Ajay Kumar3d3f8b12015-01-20 22:08:44 +05301765 * @attach: Called during drm_bridge_attach
Sean Paul3b336ec2013-08-14 16:47:37 -04001766 */
1767struct drm_bridge_funcs {
Ajay Kumar3d3f8b12015-01-20 22:08:44 +05301768 int (*attach)(struct drm_bridge *bridge);
Daniel Vetterda024fe2015-12-04 09:45:47 +01001769
1770 /**
1771 * @mode_fixup:
1772 *
1773 * This callback is used to validate and adjust a mode. The paramater
1774 * mode is the display mode that should be fed to the next element in
1775 * the display chain, either the final &drm_connector or the next
1776 * &drm_bridge. The parameter adjusted_mode is the input mode the bridge
1777 * requires. It can be modified by this callback and does not need to
1778 * match mode.
1779 *
1780 * This is the only hook that allows a bridge to reject a modeset. If
1781 * this function passes all other callbacks must succeed for this
1782 * configuration.
1783 *
1784 * NOTE:
1785 *
1786 * This function is called in the check phase of atomic modesets, which
1787 * can be aborted for any reason (including on userspace's request to
1788 * just check whether a configuration would be possible). Drivers MUST
1789 * NOT touch any persistent state (hardware or software) or data
Daniel Vetter88548632015-12-04 09:45:48 +01001790 * structures except the passed in @state parameter.
Daniel Vetterda024fe2015-12-04 09:45:47 +01001791 *
1792 * RETURNS:
1793 *
1794 * True if an acceptable configuration is possible, false if the modeset
1795 * operation should be rejected.
1796 */
Sean Paul3b336ec2013-08-14 16:47:37 -04001797 bool (*mode_fixup)(struct drm_bridge *bridge,
1798 const struct drm_display_mode *mode,
1799 struct drm_display_mode *adjusted_mode);
Daniel Vetterda024fe2015-12-04 09:45:47 +01001800 /**
1801 * @disable:
1802 *
1803 * This callback should disable the bridge. It is called right before
1804 * the preceding element in the display pipe is disabled. If the
1805 * preceding element is a bridge this means it's called before that
1806 * bridge's ->disable() function. If the preceding element is a
1807 * &drm_encoder it's called right before the encoder's ->disable(),
1808 * ->prepare() or ->dpms() hook from struct &drm_encoder_helper_funcs.
1809 *
1810 * The bridge can assume that the display pipe (i.e. clocks and timing
1811 * signals) feeding it is still running when this callback is called.
Laurent Pinchartc8a3b2a2016-02-26 11:51:06 +02001812 *
1813 * The disable callback is optional.
Daniel Vetterda024fe2015-12-04 09:45:47 +01001814 */
Sean Paul3b336ec2013-08-14 16:47:37 -04001815 void (*disable)(struct drm_bridge *bridge);
Daniel Vetterda024fe2015-12-04 09:45:47 +01001816
1817 /**
1818 * @post_disable:
1819 *
1820 * This callback should disable the bridge. It is called right after
1821 * the preceding element in the display pipe is disabled. If the
1822 * preceding element is a bridge this means it's called after that
1823 * bridge's ->post_disable() function. If the preceding element is a
1824 * &drm_encoder it's called right after the encoder's ->disable(),
1825 * ->prepare() or ->dpms() hook from struct &drm_encoder_helper_funcs.
1826 *
1827 * The bridge must assume that the display pipe (i.e. clocks and timing
1828 * singals) feeding it is no longer running when this callback is
1829 * called.
Laurent Pinchartc8a3b2a2016-02-26 11:51:06 +02001830 *
1831 * The post_disable callback is optional.
Daniel Vetterda024fe2015-12-04 09:45:47 +01001832 */
Sean Paul3b336ec2013-08-14 16:47:37 -04001833 void (*post_disable)(struct drm_bridge *bridge);
Daniel Vetterda024fe2015-12-04 09:45:47 +01001834
1835 /**
1836 * @mode_set:
1837 *
1838 * This callback should set the given mode on the bridge. It is called
1839 * after the ->mode_set() callback for the preceding element in the
1840 * display pipeline has been called already. The display pipe (i.e.
1841 * clocks and timing signals) is off when this function is called.
1842 */
Sean Paul3b336ec2013-08-14 16:47:37 -04001843 void (*mode_set)(struct drm_bridge *bridge,
1844 struct drm_display_mode *mode,
1845 struct drm_display_mode *adjusted_mode);
Daniel Vetterda024fe2015-12-04 09:45:47 +01001846 /**
1847 * @pre_enable:
1848 *
1849 * This callback should enable the bridge. It is called right before
1850 * the preceding element in the display pipe is enabled. If the
1851 * preceding element is a bridge this means it's called before that
1852 * bridge's ->pre_enable() function. If the preceding element is a
1853 * &drm_encoder it's called right before the encoder's ->enable(),
1854 * ->commit() or ->dpms() hook from struct &drm_encoder_helper_funcs.
1855 *
1856 * The display pipe (i.e. clocks and timing signals) feeding this bridge
1857 * will not yet be running when this callback is called. The bridge must
1858 * not enable the display link feeding the next bridge in the chain (if
1859 * there is one) when this callback is called.
Laurent Pinchartc8a3b2a2016-02-26 11:51:06 +02001860 *
1861 * The pre_enable callback is optional.
Daniel Vetterda024fe2015-12-04 09:45:47 +01001862 */
Sean Paul3b336ec2013-08-14 16:47:37 -04001863 void (*pre_enable)(struct drm_bridge *bridge);
Daniel Vetterda024fe2015-12-04 09:45:47 +01001864
1865 /**
1866 * @enable:
1867 *
1868 * This callback should enable the bridge. It is called right after
1869 * the preceding element in the display pipe is enabled. If the
1870 * preceding element is a bridge this means it's called after that
1871 * bridge's ->enable() function. If the preceding element is a
1872 * &drm_encoder it's called right after the encoder's ->enable(),
1873 * ->commit() or ->dpms() hook from struct &drm_encoder_helper_funcs.
1874 *
1875 * The bridge can assume that the display pipe (i.e. clocks and timing
1876 * signals) feeding it is running when this callback is called. This
1877 * callback must enable the display link feeding the next bridge in the
1878 * chain if there is one.
Laurent Pinchartc8a3b2a2016-02-26 11:51:06 +02001879 *
1880 * The enable callback is optional.
Daniel Vetterda024fe2015-12-04 09:45:47 +01001881 */
Sean Paul3b336ec2013-08-14 16:47:37 -04001882 void (*enable)(struct drm_bridge *bridge);
Sean Paul3b336ec2013-08-14 16:47:37 -04001883};
1884
1885/**
Daniel Vetter3bf04012014-10-27 16:54:27 +01001886 * struct drm_bridge - central DRM bridge control structure
Sean Paul3b336ec2013-08-14 16:47:37 -04001887 * @dev: DRM device this bridge belongs to
Archit Taneja862e6862015-05-21 11:03:16 +05301888 * @encoder: encoder to which this bridge is connected
1889 * @next: the next bridge in the encoder chain
Ajay Kumar3d3f8b12015-01-20 22:08:44 +05301890 * @of_node: device node pointer to the bridge
1891 * @list: to keep track of all added bridges
Sean Paul3b336ec2013-08-14 16:47:37 -04001892 * @funcs: control functions
1893 * @driver_private: pointer to the bridge driver's internal context
1894 */
1895struct drm_bridge {
1896 struct drm_device *dev;
Ajay Kumar3d3f8b12015-01-20 22:08:44 +05301897 struct drm_encoder *encoder;
Archit Taneja862e6862015-05-21 11:03:16 +05301898 struct drm_bridge *next;
Ajay Kumar3d3f8b12015-01-20 22:08:44 +05301899#ifdef CONFIG_OF
1900 struct device_node *of_node;
1901#endif
1902 struct list_head list;
Sean Paul3b336ec2013-08-14 16:47:37 -04001903
1904 const struct drm_bridge_funcs *funcs;
1905 void *driver_private;
1906};
1907
Daniel Vetter3b24f7d2016-06-08 14:19:00 +02001908/**
1909 * struct drm_crtc_commit - track modeset commits on a CRTC
1910 *
1911 * This structure is used to track pending modeset changes and atomic commit on
1912 * a per-CRTC basis. Since updating the list should never block this structure
1913 * is reference counted to allow waiters to safely wait on an event to complete,
1914 * without holding any locks.
1915 *
1916 * It has 3 different events in total to allow a fine-grained synchronization
1917 * between outstanding updates::
1918 *
1919 * atomic commit thread hardware
1920 *
1921 * write new state into hardware ----> ...
1922 * signal hw_done
1923 * switch to new state on next
1924 * ... v/hblank
1925 *
1926 * wait for buffers to show up ...
1927 *
1928 * ... send completion irq
1929 * irq handler signals flip_done
1930 * cleanup old buffers
1931 *
1932 * signal cleanup_done
1933 *
1934 * wait for flip_done <----
1935 * clean up atomic state
1936 *
1937 * The important bit to know is that cleanup_done is the terminal event, but the
1938 * ordering between flip_done and hw_done is entirely up to the specific driver
1939 * and modeset state change.
1940 *
1941 * For an implementation of how to use this look at
1942 * drm_atomic_helper_setup_commit() from the atomic helper library.
1943 */
1944struct drm_crtc_commit {
1945 /**
1946 * @crtc:
1947 *
1948 * DRM CRTC for this commit.
1949 */
1950 struct drm_crtc *crtc;
1951
1952 /**
1953 * @ref:
1954 *
1955 * Reference count for this structure. Needed to allow blocking on
1956 * completions without the risk of the completion disappearing
1957 * meanwhile.
1958 */
1959 struct kref ref;
1960
1961 /**
1962 * @flip_done:
1963 *
1964 * Will be signaled when the hardware has flipped to the new set of
1965 * buffers. Signals at the same time as when the drm event for this
1966 * commit is sent to userspace, or when an out-fence is singalled. Note
1967 * that for most hardware, in most cases this happens after @hw_done is
1968 * signalled.
1969 */
1970 struct completion flip_done;
1971
1972 /**
1973 * @hw_done:
1974 *
1975 * Will be signalled when all hw register changes for this commit have
1976 * been written out. Especially when disabling a pipe this can be much
1977 * later than than @flip_done, since that can signal already when the
1978 * screen goes black, whereas to fully shut down a pipe more register
1979 * I/O is required.
1980 *
1981 * Note that this does not need to include separately reference-counted
1982 * resources like backing storage buffer pinning, or runtime pm
1983 * management.
1984 */
1985 struct completion hw_done;
1986
1987 /**
1988 * @cleanup_done:
1989 *
1990 * Will be signalled after old buffers have been cleaned up by calling
1991 * drm_atomic_helper_cleanup_planes(). Since this can only happen after
1992 * a vblank wait completed it might be a bit later. This completion is
1993 * useful to throttle updates and avoid hardware updates getting ahead
1994 * of the buffer cleanup too much.
1995 */
1996 struct completion cleanup_done;
1997
1998 /**
1999 * @commit_entry:
2000 *
2001 * Entry on the per-CRTC commit_list. Protected by crtc->commit_lock.
2002 */
2003 struct list_head commit_entry;
2004
2005 /**
2006 * @event:
2007 *
2008 * &drm_pending_vblank_event pointer to clean up private events.
2009 */
2010 struct drm_pending_vblank_event *event;
2011};
2012
Daniel Vetterb8b53422016-06-02 00:06:33 +02002013struct __drm_planes_state {
2014 struct drm_plane *ptr;
2015 struct drm_plane_state *state;
2016};
2017
Daniel Vetter5d943aa62016-06-02 00:06:34 +02002018struct __drm_crtcs_state {
2019 struct drm_crtc *ptr;
2020 struct drm_crtc_state *state;
Daniel Vetter3b24f7d2016-06-08 14:19:00 +02002021 struct drm_crtc_commit *commit;
Daniel Vetter5d943aa62016-06-02 00:06:34 +02002022};
2023
Daniel Vetter63e83c12016-06-02 00:06:32 +02002024struct __drm_connnectors_state {
2025 struct drm_connector *ptr;
2026 struct drm_connector_state *state;
2027};
2028
Sean Paul3b336ec2013-08-14 16:47:37 -04002029/**
Rob Clark08855fa2015-03-11 10:23:09 -04002030 * struct drm_atomic_state - the global state object for atomic updates
Daniel Vettercc4ceb42014-07-25 21:30:38 +02002031 * @dev: parent DRM device
Rob Clarkd34f20d2014-12-18 16:01:56 -05002032 * @allow_modeset: allow full modeset
Daniel Vetterc6b0ca32015-12-04 09:46:01 +01002033 * @legacy_cursor_update: hint to enforce legacy cursor IOCTL semantics
Maarten Lankhorst40616a22016-03-03 10:17:39 +01002034 * @legacy_set_config: Disable conflicting encoders instead of failing with -EINVAL.
Daniel Vetterb8b53422016-06-02 00:06:33 +02002035 * @planes: pointer to array of structures with per-plane data
Daniel Vettercc4ceb42014-07-25 21:30:38 +02002036 * @crtcs: pointer to array of CRTC pointers
Daniel Vetterf52b69f12014-11-19 18:38:08 +01002037 * @num_connector: size of the @connectors and @connector_states arrays
Daniel Vetter63e83c12016-06-02 00:06:32 +02002038 * @connectors: pointer to array of structures with per-connector data
Daniel Vettercc4ceb42014-07-25 21:30:38 +02002039 * @acquire_ctx: acquire context for this atomic modeset state update
2040 */
2041struct drm_atomic_state {
2042 struct drm_device *dev;
Rob Clarkd34f20d2014-12-18 16:01:56 -05002043 bool allow_modeset : 1;
Daniel Vetterf02ad902015-01-22 16:36:23 +01002044 bool legacy_cursor_update : 1;
Maarten Lankhorst40616a22016-03-03 10:17:39 +01002045 bool legacy_set_config : 1;
Daniel Vetterb8b53422016-06-02 00:06:33 +02002046 struct __drm_planes_state *planes;
Daniel Vetter5d943aa62016-06-02 00:06:34 +02002047 struct __drm_crtcs_state *crtcs;
Daniel Vetterf52b69f12014-11-19 18:38:08 +01002048 int num_connector;
Daniel Vetter63e83c12016-06-02 00:06:32 +02002049 struct __drm_connnectors_state *connectors;
Daniel Vettercc4ceb42014-07-25 21:30:38 +02002050
2051 struct drm_modeset_acquire_ctx *acquire_ctx;
Daniel Vetter3b24f7d2016-06-08 14:19:00 +02002052
2053 /**
2054 * @commit_work:
2055 *
2056 * Work item which can be used by the driver or helpers to execute the
2057 * commit without blocking.
2058 */
2059 struct work_struct commit_work;
Daniel Vettercc4ceb42014-07-25 21:30:38 +02002060};
2061
2062
2063/**
Daniel Vetter3bf04012014-10-27 16:54:27 +01002064 * struct drm_mode_set - new values for a CRTC config change
Jesse Barnesef273512011-11-07 12:03:19 -08002065 * @fb: framebuffer to use for new config
2066 * @crtc: CRTC whose configuration we're about to change
2067 * @mode: mode timings to use
2068 * @x: position of this CRTC relative to @fb
2069 * @y: position of this CRTC relative to @fb
2070 * @connectors: array of connectors to drive with this CRTC if possible
2071 * @num_connectors: size of @connectors array
Dave Airlief453ba02008-11-07 14:05:41 -08002072 *
2073 * Represents a single crtc the connectors that it drives with what mode
2074 * and from which framebuffer it scans out from.
2075 *
2076 * This is used to set modes.
2077 */
2078struct drm_mode_set {
Dave Airlief453ba02008-11-07 14:05:41 -08002079 struct drm_framebuffer *fb;
2080 struct drm_crtc *crtc;
2081 struct drm_display_mode *mode;
2082
2083 uint32_t x;
2084 uint32_t y;
2085
2086 struct drm_connector **connectors;
2087 size_t num_connectors;
2088};
2089
2090/**
Jesse Barnes550cebc2011-11-07 12:03:20 -08002091 * struct drm_mode_config_funcs - basic driver provided mode setting functions
Jesse Barnes550cebc2011-11-07 12:03:20 -08002092 *
2093 * Some global (i.e. not per-CRTC, connector, etc) mode setting functions that
2094 * involve drivers.
Dave Airlief453ba02008-11-07 14:05:41 -08002095 */
2096struct drm_mode_config_funcs {
Daniel Vetter9953f412015-12-04 09:46:02 +01002097 /**
2098 * @fb_create:
2099 *
2100 * Create a new framebuffer object. The core does basic checks on the
2101 * requested metadata, but most of that is left to the driver. See
2102 * struct &drm_mode_fb_cmd2 for details.
2103 *
Daniel Vetterd55f5322015-12-08 09:49:19 +01002104 * If the parameters are deemed valid and the backing storage objects in
2105 * the underlying memory manager all exist, then the driver allocates
2106 * a new &drm_framebuffer structure, subclassed to contain
2107 * driver-specific information (like the internal native buffer object
2108 * references). It also needs to fill out all relevant metadata, which
2109 * should be done by calling drm_helper_mode_fill_fb_struct().
2110 *
2111 * The initialization is finalized by calling drm_framebuffer_init(),
2112 * which registers the framebuffer and makes it accessible to other
2113 * threads.
2114 *
Daniel Vetter9953f412015-12-04 09:46:02 +01002115 * RETURNS:
2116 *
2117 * A new framebuffer with an initial reference count of 1 or a negative
2118 * error code encoded with ERR_PTR().
2119 */
Jesse Barnes550cebc2011-11-07 12:03:20 -08002120 struct drm_framebuffer *(*fb_create)(struct drm_device *dev,
2121 struct drm_file *file_priv,
Ville Syrjälä1eb834512015-11-11 19:11:29 +02002122 const struct drm_mode_fb_cmd2 *mode_cmd);
Daniel Vetter9953f412015-12-04 09:46:02 +01002123
2124 /**
2125 * @output_poll_changed:
2126 *
2127 * Callback used by helpers to inform the driver of output configuration
2128 * changes.
2129 *
2130 * Drivers implementing fbdev emulation with the helpers can call
2131 * drm_fb_helper_hotplug_changed from this hook to inform the fbdev
2132 * helper of output changes.
2133 *
2134 * FIXME:
2135 *
2136 * Except that there's no vtable for device-level helper callbacks
2137 * there's no reason this is a core function.
2138 */
Dave Airlieeb1f8e4f32010-05-07 06:42:51 +00002139 void (*output_poll_changed)(struct drm_device *dev);
Daniel Vettercc4ceb42014-07-25 21:30:38 +02002140
Daniel Vetter9953f412015-12-04 09:46:02 +01002141 /**
2142 * @atomic_check:
2143 *
2144 * This is the only hook to validate an atomic modeset update. This
2145 * function must reject any modeset and state changes which the hardware
2146 * or driver doesn't support. This includes but is of course not limited
2147 * to:
2148 *
2149 * - Checking that the modes, framebuffers, scaling and placement
2150 * requirements and so on are within the limits of the hardware.
2151 *
2152 * - Checking that any hidden shared resources are not oversubscribed.
2153 * This can be shared PLLs, shared lanes, overall memory bandwidth,
2154 * display fifo space (where shared between planes or maybe even
2155 * CRTCs).
2156 *
2157 * - Checking that virtualized resources exported to userspace are not
2158 * oversubscribed. For various reasons it can make sense to expose
2159 * more planes, crtcs or encoders than which are physically there. One
2160 * example is dual-pipe operations (which generally should be hidden
2161 * from userspace if when lockstepped in hardware, exposed otherwise),
2162 * where a plane might need 1 hardware plane (if it's just on one
2163 * pipe), 2 hardware planes (when it spans both pipes) or maybe even
2164 * shared a hardware plane with a 2nd plane (if there's a compatible
2165 * plane requested on the area handled by the other pipe).
2166 *
2167 * - Check that any transitional state is possible and that if
2168 * requested, the update can indeed be done in the vblank period
2169 * without temporarily disabling some functions.
2170 *
2171 * - Check any other constraints the driver or hardware might have.
2172 *
2173 * - This callback also needs to correctly fill out the &drm_crtc_state
2174 * in this update to make sure that drm_atomic_crtc_needs_modeset()
2175 * reflects the nature of the possible update and returns true if and
2176 * only if the update cannot be applied without tearing within one
2177 * vblank on that CRTC. The core uses that information to reject
2178 * updates which require a full modeset (i.e. blanking the screen, or
2179 * at least pausing updates for a substantial amount of time) if
2180 * userspace has disallowed that in its request.
2181 *
2182 * - The driver also does not need to repeat basic input validation
2183 * like done for the corresponding legacy entry points. The core does
2184 * that before calling this hook.
2185 *
2186 * See the documentation of @atomic_commit for an exhaustive list of
2187 * error conditions which don't have to be checked at the
2188 * ->atomic_check() stage?
2189 *
2190 * See the documentation for struct &drm_atomic_state for how exactly
2191 * an atomic modeset update is described.
2192 *
2193 * Drivers using the atomic helpers can implement this hook using
2194 * drm_atomic_helper_check(), or one of the exported sub-functions of
2195 * it.
2196 *
2197 * RETURNS:
2198 *
2199 * 0 on success or one of the below negative error codes:
2200 *
2201 * - -EINVAL, if any of the above constraints are violated.
2202 *
2203 * - -EDEADLK, when returned from an attempt to acquire an additional
2204 * &drm_modeset_lock through drm_modeset_lock().
2205 *
2206 * - -ENOMEM, if allocating additional state sub-structures failed due
2207 * to lack of memory.
2208 *
2209 * - -EINTR, -EAGAIN or -ERESTARTSYS, if the IOCTL should be restarted.
2210 * This can either be due to a pending signal, or because the driver
2211 * needs to completely bail out to recover from an exceptional
2212 * situation like a GPU hang. From a userspace point all errors are
2213 * treated equally.
2214 */
Daniel Vettercc4ceb42014-07-25 21:30:38 +02002215 int (*atomic_check)(struct drm_device *dev,
Daniel Vetter9953f412015-12-04 09:46:02 +01002216 struct drm_atomic_state *state);
2217
2218 /**
2219 * @atomic_commit:
2220 *
2221 * This is the only hook to commit an atomic modeset update. The core
2222 * guarantees that @atomic_check has been called successfully before
2223 * calling this function, and that nothing has been changed in the
2224 * interim.
2225 *
2226 * See the documentation for struct &drm_atomic_state for how exactly
2227 * an atomic modeset update is described.
2228 *
2229 * Drivers using the atomic helpers can implement this hook using
2230 * drm_atomic_helper_commit(), or one of the exported sub-functions of
2231 * it.
2232 *
Maarten Lankhorst286dbb82016-04-26 16:11:34 +02002233 * Nonblocking commits (as indicated with the nonblock parameter) must
Daniel Vetter9953f412015-12-04 09:46:02 +01002234 * do any preparatory work which might result in an unsuccessful commit
2235 * in the context of this callback. The only exceptions are hardware
2236 * errors resulting in -EIO. But even in that case the driver must
2237 * ensure that the display pipe is at least running, to avoid
2238 * compositors crashing when pageflips don't work. Anything else,
2239 * specifically committing the update to the hardware, should be done
2240 * without blocking the caller. For updates which do not require a
2241 * modeset this must be guaranteed.
2242 *
2243 * The driver must wait for any pending rendering to the new
2244 * framebuffers to complete before executing the flip. It should also
2245 * wait for any pending rendering from other drivers if the underlying
Maarten Lankhorst286dbb82016-04-26 16:11:34 +02002246 * buffer is a shared dma-buf. Nonblocking commits must not wait for
Daniel Vetter9953f412015-12-04 09:46:02 +01002247 * rendering in the context of this callback.
2248 *
2249 * An application can request to be notified when the atomic commit has
2250 * completed. These events are per-CRTC and can be distinguished by the
2251 * CRTC index supplied in &drm_event to userspace.
2252 *
2253 * The drm core will supply a struct &drm_event in the event
2254 * member of each CRTC's &drm_crtc_state structure. This can be handled by the
2255 * drm_crtc_send_vblank_event() function, which the driver should call on
2256 * the provided event upon completion of the atomic commit. Note that if
2257 * the driver supports vblank signalling and timestamping the vblank
2258 * counters and timestamps must agree with the ones returned from page
2259 * flip events. With the current vblank helper infrastructure this can
2260 * be achieved by holding a vblank reference while the page flip is
2261 * pending, acquired through drm_crtc_vblank_get() and released with
2262 * drm_crtc_vblank_put(). Drivers are free to implement their own vblank
2263 * counter and timestamp tracking though, e.g. if they have accurate
2264 * timestamp registers in hardware.
2265 *
2266 * NOTE:
2267 *
2268 * Drivers are not allowed to shut down any display pipe successfully
2269 * enabled through an atomic commit on their own. Doing so can result in
2270 * compositors crashing if a page flip is suddenly rejected because the
2271 * pipe is off.
2272 *
2273 * RETURNS:
2274 *
2275 * 0 on success or one of the below negative error codes:
2276 *
Maarten Lankhorst286dbb82016-04-26 16:11:34 +02002277 * - -EBUSY, if a nonblocking updated is requested and there is
Daniel Vetter9953f412015-12-04 09:46:02 +01002278 * an earlier updated pending. Drivers are allowed to support a queue
2279 * of outstanding updates, but currently no driver supports that.
2280 * Note that drivers must wait for preceding updates to complete if a
2281 * synchronous update is requested, they are not allowed to fail the
2282 * commit in that case.
2283 *
2284 * - -ENOMEM, if the driver failed to allocate memory. Specifically
2285 * this can happen when trying to pin framebuffers, which must only
2286 * be done when committing the state.
2287 *
2288 * - -ENOSPC, as a refinement of the more generic -ENOMEM to indicate
2289 * that the driver has run out of vram, iommu space or similar GPU
2290 * address space needed for framebuffer.
2291 *
2292 * - -EIO, if the hardware completely died.
2293 *
2294 * - -EINTR, -EAGAIN or -ERESTARTSYS, if the IOCTL should be restarted.
2295 * This can either be due to a pending signal, or because the driver
2296 * needs to completely bail out to recover from an exceptional
2297 * situation like a GPU hang. From a userspace point of view all errors are
2298 * treated equally.
2299 *
2300 * This list is exhaustive. Specifically this hook is not allowed to
2301 * return -EINVAL (any invalid requests should be caught in
2302 * @atomic_check) or -EDEADLK (this function must not acquire
2303 * additional modeset locks).
2304 */
Daniel Vettercc4ceb42014-07-25 21:30:38 +02002305 int (*atomic_commit)(struct drm_device *dev,
Daniel Vetter9953f412015-12-04 09:46:02 +01002306 struct drm_atomic_state *state,
Maarten Lankhorst286dbb82016-04-26 16:11:34 +02002307 bool nonblock);
Daniel Vetter9953f412015-12-04 09:46:02 +01002308
2309 /**
2310 * @atomic_state_alloc:
2311 *
2312 * This optional hook can be used by drivers that want to subclass struct
2313 * &drm_atomic_state to be able to track their own driver-private global
2314 * state easily. If this hook is implemented, drivers must also
2315 * implement @atomic_state_clear and @atomic_state_free.
2316 *
2317 * RETURNS:
2318 *
2319 * A new &drm_atomic_state on success or NULL on failure.
2320 */
Maarten Lankhorst036ef572015-05-18 10:06:40 +02002321 struct drm_atomic_state *(*atomic_state_alloc)(struct drm_device *dev);
Daniel Vetter9953f412015-12-04 09:46:02 +01002322
2323 /**
2324 * @atomic_state_clear:
2325 *
2326 * This hook must clear any driver private state duplicated into the
2327 * passed-in &drm_atomic_state. This hook is called when the caller
2328 * encountered a &drm_modeset_lock deadlock and needs to drop all
2329 * already acquired locks as part of the deadlock avoidance dance
2330 * implemented in drm_modeset_lock_backoff().
2331 *
2332 * Any duplicated state must be invalidated since a concurrent atomic
2333 * update might change it, and the drm atomic interfaces always apply
2334 * updates as relative changes to the current state.
2335 *
2336 * Drivers that implement this must call drm_atomic_state_default_clear()
2337 * to clear common state.
2338 */
Maarten Lankhorst036ef572015-05-18 10:06:40 +02002339 void (*atomic_state_clear)(struct drm_atomic_state *state);
Daniel Vetter9953f412015-12-04 09:46:02 +01002340
2341 /**
2342 * @atomic_state_free:
2343 *
2344 * This hook needs driver private resources and the &drm_atomic_state
2345 * itself. Note that the core first calls drm_atomic_state_clear() to
2346 * avoid code duplicate between the clear and free hooks.
2347 *
2348 * Drivers that implement this must call drm_atomic_state_default_free()
2349 * to release common resources.
2350 */
Maarten Lankhorst036ef572015-05-18 10:06:40 +02002351 void (*atomic_state_free)(struct drm_atomic_state *state);
Dave Airlief453ba02008-11-07 14:05:41 -08002352};
2353
Jesse Barnesc1aaca22011-11-07 12:03:21 -08002354/**
Daniel Vetter2c0c33d2014-10-27 20:19:38 +01002355 * struct drm_mode_config - Mode configuration control structure
Jesse Barnesa62c93d2011-11-07 12:03:22 -08002356 * @mutex: mutex protecting KMS related lists and structures
Daniel Vetter2c0c33d2014-10-27 20:19:38 +01002357 * @connection_mutex: ww mutex protecting connector state and routing
2358 * @acquire_ctx: global implicit acquire context used by atomic drivers for
Daniel Vetterc6b0ca32015-12-04 09:46:01 +01002359 * legacy IOCTLs
Daniel Vetter2c0c33d2014-10-27 20:19:38 +01002360 * @fb_lock: mutex to protect fb state and lists
Jesse Barnesa62c93d2011-11-07 12:03:22 -08002361 * @num_fb: number of fbs available
2362 * @fb_list: list of framebuffers available
Jesse Barnesa62c93d2011-11-07 12:03:22 -08002363 * @num_encoder: number of encoders on this device
2364 * @encoder_list: list of encoder objects
Daniel Vetter2c0c33d2014-10-27 20:19:38 +01002365 * @num_overlay_plane: number of overlay planes on this device
2366 * @num_total_plane: number of universal (i.e. with primary/curso) planes on this device
2367 * @plane_list: list of plane objects
Jesse Barnesa62c93d2011-11-07 12:03:22 -08002368 * @num_crtc: number of CRTCs on this device
2369 * @crtc_list: list of CRTC objects
Daniel Vetter2c0c33d2014-10-27 20:19:38 +01002370 * @property_list: list of property objects
Jesse Barnesa62c93d2011-11-07 12:03:22 -08002371 * @min_width: minimum pixel width on this device
2372 * @min_height: minimum pixel height on this device
2373 * @max_width: maximum pixel width on this device
2374 * @max_height: maximum pixel height on this device
2375 * @funcs: core driver provided mode setting functions
2376 * @fb_base: base address of the framebuffer
Daniel Vetter2c0c33d2014-10-27 20:19:38 +01002377 * @poll_enabled: track polling support for this device
2378 * @poll_running: track polling status for this device
Daniel Vetterac3ba4a2016-05-31 23:11:10 +02002379 * @delayed_event: track delayed poll uevent deliver for this device
Jesse Barnesa62c93d2011-11-07 12:03:22 -08002380 * @output_poll_work: delayed work for polling in process context
Daniel Vetter2c0c33d2014-10-27 20:19:38 +01002381 * @property_blob_list: list of all the blob property objects
Daniel Stone8fb6e7a2015-04-20 19:22:54 +01002382 * @blob_lock: mutex for blob property allocation and management
Jesse Barnesa62c93d2011-11-07 12:03:22 -08002383 * @*_property: core property tracking
Daniel Vetter2c0c33d2014-10-27 20:19:38 +01002384 * @preferred_depth: preferred RBG pixel depth, used by fb helpers
2385 * @prefer_shadow: hint to userspace to prefer shadow-fb rendering
Daniel Vetter2c0c33d2014-10-27 20:19:38 +01002386 * @cursor_width: hint to userspace for max cursor width
2387 * @cursor_height: hint to userspace for max cursor height
Daniel Vetter9f2a7952016-06-08 14:19:02 +02002388 * @helper_private: mid-layer private data
Dave Airlief453ba02008-11-07 14:05:41 -08002389 *
Jesse Barnesa62c93d2011-11-07 12:03:22 -08002390 * Core mode resource tracking structure. All CRTC, encoders, and connectors
2391 * enumerated by the driver are added here, as are global properties. Some
2392 * global restrictions are also here, e.g. dimension restrictions.
Dave Airlief453ba02008-11-07 14:05:41 -08002393 */
2394struct drm_mode_config {
Jesse Barnesad2563c2009-01-19 17:21:45 +10002395 struct mutex mutex; /* protects configuration (mode lists etc.) */
Rob Clark51fd3712013-11-19 12:10:12 -05002396 struct drm_modeset_lock connection_mutex; /* protects connector->encoder and encoder->crtc links */
2397 struct drm_modeset_acquire_ctx *acquire_ctx; /* for legacy _lock_all() / _unlock_all() */
Daniel Vetterac3ba4a2016-05-31 23:11:10 +02002398
2399 /**
2400 * @idr_mutex:
2401 *
2402 * Mutex for KMS ID allocation and management. Protects both @crtc_idr
2403 * and @tile_idr.
2404 */
2405 struct mutex idr_mutex;
2406
2407 /**
2408 * @crtc_idr:
2409 *
2410 * Main KMS ID tracking object. Use this idr for all IDs, fb, crtc,
2411 * connector, modes - just makes life easier to have only one.
2412 */
2413 struct idr crtc_idr;
2414
2415 /**
2416 * @tile_idr:
2417 *
2418 * Use this idr for allocating new IDs for tiled sinks like use in some
2419 * high-res DP MST screens.
2420 */
2421 struct idr tile_idr;
Daniel Vetter4b096ac2012-12-10 21:19:18 +01002422
Daniel Vetter2c0c33d2014-10-27 20:19:38 +01002423 struct mutex fb_lock; /* proctects global and per-file fb lists */
Dave Airlief453ba02008-11-07 14:05:41 -08002424 int num_fb;
2425 struct list_head fb_list;
Daniel Vetter4b096ac2012-12-10 21:19:18 +01002426
Daniel Vetter96094082016-07-15 21:47:59 +02002427 /**
2428 * @num_connector: Number of connectors on this device.
2429 */
Dave Airlief453ba02008-11-07 14:05:41 -08002430 int num_connector;
Daniel Vetter96094082016-07-15 21:47:59 +02002431 /**
2432 * @connector_ida: ID allocator for connector indices.
2433 */
Maarten Lankhorst5fff80b2016-02-17 08:32:05 +01002434 struct ida connector_ida;
Daniel Vetter96094082016-07-15 21:47:59 +02002435 /**
2436 * @connector_list: List of connector objects.
2437 */
Dave Airlief453ba02008-11-07 14:05:41 -08002438 struct list_head connector_list;
2439 int num_encoder;
2440 struct list_head encoder_list;
Matt Ropere27dde32014-04-01 15:22:30 -07002441
2442 /*
2443 * Track # of overlay planes separately from # of total planes. By
2444 * default we only advertise overlay planes to userspace; if userspace
2445 * sets the "universal plane" capability bit, we'll go ahead and
2446 * expose all planes.
2447 */
2448 int num_overlay_plane;
2449 int num_total_plane;
Jesse Barnes8cf5c912011-11-14 14:51:27 -08002450 struct list_head plane_list;
Dave Airlief453ba02008-11-07 14:05:41 -08002451
2452 int num_crtc;
2453 struct list_head crtc_list;
2454
2455 struct list_head property_list;
2456
Dave Airlief453ba02008-11-07 14:05:41 -08002457 int min_width, min_height;
2458 int max_width, max_height;
Laurent Pincharte6ecefa2012-05-17 13:27:23 +02002459 const struct drm_mode_config_funcs *funcs;
Benjamin Herrenschmidtd883f7f2009-02-02 16:55:45 +11002460 resource_size_t fb_base;
Dave Airlief453ba02008-11-07 14:05:41 -08002461
Dave Airlieeb1f8e4f32010-05-07 06:42:51 +00002462 /* output poll support */
2463 bool poll_enabled;
Daniel Vetter905bc9f2012-10-23 18:23:36 +00002464 bool poll_running;
Daniel Vetter162b6a52015-01-21 08:45:21 +01002465 bool delayed_event;
Tejun Heo991ea752010-07-20 22:09:02 +02002466 struct delayed_work output_poll_work;
Dave Airlieeb1f8e4f32010-05-07 06:42:51 +00002467
Daniel Stone8fb6e7a2015-04-20 19:22:54 +01002468 struct mutex blob_lock;
2469
Dave Airlief453ba02008-11-07 14:05:41 -08002470 /* pointers to standard properties */
2471 struct list_head property_blob_list;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02002472 /**
2473 * @edid_property: Default connector property to hold the EDID of the
2474 * currently connected sink, if any.
2475 */
Dave Airlief453ba02008-11-07 14:05:41 -08002476 struct drm_property *edid_property;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02002477 /**
2478 * @dpms_property: Default connector property to control the
2479 * connector's DPMS state.
2480 */
Dave Airlief453ba02008-11-07 14:05:41 -08002481 struct drm_property *dpms_property;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02002482 /**
2483 * @path_property: Default connector property to hold the DP MST path
2484 * for the port.
2485 */
Dave Airlie43aba7e2014-06-05 14:01:31 +10002486 struct drm_property *path_property;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02002487 /**
2488 * @tile_property: Default connector property to store the tile
2489 * position of a tiled screen, for sinks which need to be driven with
2490 * multiple CRTCs.
2491 */
Dave Airlie6f134d72014-10-20 16:30:50 +10002492 struct drm_property *tile_property;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02002493 /**
2494 * @plane_type_property: Default plane property to differentiate
2495 * CURSOR, PRIMARY and OVERLAY legacy uses of planes.
2496 */
Rob Clark9922ab52014-04-01 20:16:57 -04002497 struct drm_property *plane_type_property;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02002498 /**
2499 * @rotation_property: Optional property for planes or CRTCs to specifiy
2500 * rotation.
2501 */
Sonika Jindal2a297cc2014-08-05 11:26:54 +05302502 struct drm_property *rotation_property;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02002503 /**
2504 * @prop_src_x: Default atomic plane property for the plane source
2505 * position in the connected &drm_framebuffer.
2506 */
Rob Clark6b4959f2014-12-18 16:01:53 -05002507 struct drm_property *prop_src_x;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02002508 /**
2509 * @prop_src_y: Default atomic plane property for the plane source
2510 * position in the connected &drm_framebuffer.
2511 */
Rob Clark6b4959f2014-12-18 16:01:53 -05002512 struct drm_property *prop_src_y;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02002513 /**
2514 * @prop_src_w: Default atomic plane property for the plane source
2515 * position in the connected &drm_framebuffer.
2516 */
Rob Clark6b4959f2014-12-18 16:01:53 -05002517 struct drm_property *prop_src_w;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02002518 /**
2519 * @prop_src_h: Default atomic plane property for the plane source
2520 * position in the connected &drm_framebuffer.
2521 */
Rob Clark6b4959f2014-12-18 16:01:53 -05002522 struct drm_property *prop_src_h;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02002523 /**
2524 * @prop_crtc_x: Default atomic plane property for the plane destination
2525 * position in the &drm_crtc is is being shown on.
2526 */
Rob Clark6b4959f2014-12-18 16:01:53 -05002527 struct drm_property *prop_crtc_x;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02002528 /**
2529 * @prop_crtc_y: Default atomic plane property for the plane destination
2530 * position in the &drm_crtc is is being shown on.
2531 */
Rob Clark6b4959f2014-12-18 16:01:53 -05002532 struct drm_property *prop_crtc_y;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02002533 /**
2534 * @prop_crtc_w: Default atomic plane property for the plane destination
2535 * position in the &drm_crtc is is being shown on.
2536 */
Rob Clark6b4959f2014-12-18 16:01:53 -05002537 struct drm_property *prop_crtc_w;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02002538 /**
2539 * @prop_crtc_h: Default atomic plane property for the plane destination
2540 * position in the &drm_crtc is is being shown on.
2541 */
Rob Clark6b4959f2014-12-18 16:01:53 -05002542 struct drm_property *prop_crtc_h;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02002543 /**
2544 * @prop_fb_id: Default atomic plane property to specify the
2545 * &drm_framebuffer.
2546 */
Rob Clark6b4959f2014-12-18 16:01:53 -05002547 struct drm_property *prop_fb_id;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02002548 /**
2549 * @prop_crtc_id: Default atomic plane property to specify the
2550 * &drm_crtc.
2551 */
Rob Clark6b4959f2014-12-18 16:01:53 -05002552 struct drm_property *prop_crtc_id;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02002553 /**
2554 * @prop_active: Default atomic CRTC property to control the active
2555 * state, which is the simplified implementation for DPMS in atomic
2556 * drivers.
2557 */
Daniel Vettereab3bbe2015-01-22 16:36:21 +01002558 struct drm_property *prop_active;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02002559 /**
2560 * @prop_mode_id: Default atomic CRTC property to set the mode for a
2561 * CRTC. A 0 mode implies that the CRTC is entirely disabled - all
2562 * connectors must be of and active must be set to disabled, too.
2563 */
Daniel Stone955f3c32015-05-25 19:11:52 +01002564 struct drm_property *prop_mode_id;
Dave Airlief453ba02008-11-07 14:05:41 -08002565
Daniel Vetter9a6bc032016-07-15 21:48:00 +02002566 /**
2567 * @dvi_i_subconnector_property: Optional DVI-I property to
2568 * differentiate between analog or digital mode.
2569 */
Dave Airlief453ba02008-11-07 14:05:41 -08002570 struct drm_property *dvi_i_subconnector_property;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02002571 /**
2572 * @dvi_i_select_subconnector_property: Optional DVI-I property to
2573 * select between analog or digital mode.
2574 */
Dave Airlief453ba02008-11-07 14:05:41 -08002575 struct drm_property *dvi_i_select_subconnector_property;
2576
Daniel Vetter9a6bc032016-07-15 21:48:00 +02002577 /**
2578 * @tv_subconnector_property: Optional TV property to differentiate
2579 * between different TV connector types.
2580 */
Dave Airlief453ba02008-11-07 14:05:41 -08002581 struct drm_property *tv_subconnector_property;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02002582 /**
2583 * @tv_select_subconnector_property: Optional TV property to select
2584 * between different TV connector types.
2585 */
Dave Airlief453ba02008-11-07 14:05:41 -08002586 struct drm_property *tv_select_subconnector_property;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02002587 /**
2588 * @tv_mode_property: Optional TV property to select
2589 * the output TV mode.
2590 */
Dave Airlief453ba02008-11-07 14:05:41 -08002591 struct drm_property *tv_mode_property;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02002592 /**
2593 * @tv_left_margin_property: Optional TV property to set the left
2594 * margin.
2595 */
Dave Airlief453ba02008-11-07 14:05:41 -08002596 struct drm_property *tv_left_margin_property;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02002597 /**
2598 * @tv_right_margin_property: Optional TV property to set the right
2599 * margin.
2600 */
Dave Airlief453ba02008-11-07 14:05:41 -08002601 struct drm_property *tv_right_margin_property;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02002602 /**
2603 * @tv_top_margin_property: Optional TV property to set the right
2604 * margin.
2605 */
Dave Airlief453ba02008-11-07 14:05:41 -08002606 struct drm_property *tv_top_margin_property;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02002607 /**
2608 * @tv_bottom_margin_property: Optional TV property to set the right
2609 * margin.
2610 */
Dave Airlief453ba02008-11-07 14:05:41 -08002611 struct drm_property *tv_bottom_margin_property;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02002612 /**
2613 * @tv_brightness_property: Optional TV property to set the
2614 * brightness.
2615 */
Francisco Jerezb6b79022009-08-02 04:19:20 +02002616 struct drm_property *tv_brightness_property;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02002617 /**
2618 * @tv_contrast_property: Optional TV property to set the
2619 * contrast.
2620 */
Francisco Jerezb6b79022009-08-02 04:19:20 +02002621 struct drm_property *tv_contrast_property;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02002622 /**
2623 * @tv_flicker_reduction_property: Optional TV property to control the
2624 * flicker reduction mode.
2625 */
Francisco Jerezb6b79022009-08-02 04:19:20 +02002626 struct drm_property *tv_flicker_reduction_property;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02002627 /**
2628 * @tv_overscan_property: Optional TV property to control the overscan
2629 * setting.
2630 */
Francisco Jereza75f0232009-08-12 02:30:10 +02002631 struct drm_property *tv_overscan_property;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02002632 /**
2633 * @tv_saturation_property: Optional TV property to set the
2634 * saturation.
2635 */
Francisco Jereza75f0232009-08-12 02:30:10 +02002636 struct drm_property *tv_saturation_property;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02002637 /**
2638 * @tv_hue_property: Optional TV property to set the hue.
2639 */
Francisco Jereza75f0232009-08-12 02:30:10 +02002640 struct drm_property *tv_hue_property;
Dave Airlief453ba02008-11-07 14:05:41 -08002641
Daniel Vetter9a6bc032016-07-15 21:48:00 +02002642 /**
2643 * @scaling_mode_property: Optional connector property to control the
2644 * upscaling, mostly used for built-in panels.
2645 */
Dave Airlief453ba02008-11-07 14:05:41 -08002646 struct drm_property *scaling_mode_property;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02002647 /**
2648 * @aspect_ratio_property: Optional connector property to control the
2649 * HDMI infoframe aspect ratio setting.
2650 */
Vandana Kannanff587e42014-06-11 10:46:48 +05302651 struct drm_property *aspect_ratio_property;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02002652 /**
2653 * @dirty_info_property: Optional connector property to give userspace a
2654 * hint that the DIRTY_FB ioctl should be used.
2655 */
Jakob Bornecrantz884840a2009-12-03 23:25:47 +00002656 struct drm_property *dirty_info_property;
Dave Airlie019d96c2011-09-29 16:20:42 +01002657
Daniel Vetter9a6bc032016-07-15 21:48:00 +02002658 /**
2659 * @degamma_lut_property: Optional CRTC property to set the LUT used to
2660 * convert the framebuffer's colors to linear gamma.
2661 */
Lionel Landwerlin5488dc12016-02-26 17:05:00 +00002662 struct drm_property *degamma_lut_property;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02002663 /**
2664 * @degamma_lut_size_property: Optional CRTC property for the size of
2665 * the degamma LUT as supported by the driver (read-only).
2666 */
Lionel Landwerlin5488dc12016-02-26 17:05:00 +00002667 struct drm_property *degamma_lut_size_property;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02002668 /**
2669 * @ctm_property: Optional CRTC property to set the
2670 * matrix used to convert colors after the lookup in the
2671 * degamma LUT.
2672 */
Lionel Landwerlin5488dc12016-02-26 17:05:00 +00002673 struct drm_property *ctm_property;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02002674 /**
2675 * @gamma_lut_property: Optional CRTC property to set the LUT used to
2676 * convert the colors, after the CTM matrix, to the gamma space of the
2677 * connected screen.
2678 */
Lionel Landwerlin5488dc12016-02-26 17:05:00 +00002679 struct drm_property *gamma_lut_property;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02002680 /**
2681 * @gamma_lut_size_property: Optional CRTC property for the size of the
2682 * gamma LUT as supported by the driver (read-only).
2683 */
Lionel Landwerlin5488dc12016-02-26 17:05:00 +00002684 struct drm_property *gamma_lut_size_property;
2685
Daniel Vetter9a6bc032016-07-15 21:48:00 +02002686 /**
2687 * @suggested_x_property: Optional connector property with a hint for
2688 * the position of the output on the host's screen.
2689 */
Dave Airlie5bb2bbf2014-11-10 10:18:15 +10002690 struct drm_property *suggested_x_property;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02002691 /**
2692 * @suggested_y_property: Optional connector property with a hint for
2693 * the position of the output on the host's screen.
2694 */
Dave Airlie5bb2bbf2014-11-10 10:18:15 +10002695 struct drm_property *suggested_y_property;
2696
Dave Airlie019d96c2011-09-29 16:20:42 +01002697 /* dumb ioctl parameters */
2698 uint32_t preferred_depth, prefer_shadow;
Keith Packard62f21042013-07-22 18:50:00 -07002699
Daniel Vetter9a6bc032016-07-15 21:48:00 +02002700 /**
2701 * @async_page_flip: Does this device support async flips on the primary
2702 * plane?
2703 */
Keith Packard62f21042013-07-22 18:50:00 -07002704 bool async_page_flip;
Alex Deucher8716ed42014-02-12 12:48:23 -05002705
Daniel Vetterac3ba4a2016-05-31 23:11:10 +02002706 /**
2707 * @allow_fb_modifiers:
2708 *
2709 * Whether the driver supports fb modifiers in the ADDFB2.1 ioctl call.
2710 */
Rob Clarke3eb3252015-02-05 14:41:52 +00002711 bool allow_fb_modifiers;
2712
Alex Deucher8716ed42014-02-12 12:48:23 -05002713 /* cursor size */
2714 uint32_t cursor_width, cursor_height;
Daniel Vetter9f2a7952016-06-08 14:19:02 +02002715
2716 struct drm_mode_config_helper_funcs *helper_private;
Dave Airlief453ba02008-11-07 14:05:41 -08002717};
2718
Rob Clarkdd275952014-11-25 20:29:46 -05002719/**
2720 * drm_for_each_plane_mask - iterate over planes specified by bitmask
2721 * @plane: the loop cursor
2722 * @dev: the DRM device
2723 * @plane_mask: bitmask of plane indices
2724 *
2725 * Iterate over all planes specified by bitmask.
2726 */
2727#define drm_for_each_plane_mask(plane, dev, plane_mask) \
2728 list_for_each_entry((plane), &(dev)->mode_config.plane_list, head) \
Jani Nikula373701b2015-11-24 21:21:55 +02002729 for_each_if ((plane_mask) & (1 << drm_plane_index(plane)))
Rob Clarkdd275952014-11-25 20:29:46 -05002730
Maarten Lankhorstead8b662016-01-07 10:59:19 +01002731/**
2732 * drm_for_each_encoder_mask - iterate over encoders specified by bitmask
2733 * @encoder: the loop cursor
2734 * @dev: the DRM device
2735 * @encoder_mask: bitmask of encoder indices
2736 *
2737 * Iterate over all encoders specified by bitmask.
2738 */
2739#define drm_for_each_encoder_mask(encoder, dev, encoder_mask) \
2740 list_for_each_entry((encoder), &(dev)->mode_config.encoder_list, head) \
2741 for_each_if ((encoder_mask) & (1 << drm_encoder_index(encoder)))
Rob Clarkdd275952014-11-25 20:29:46 -05002742
Dave Airlief453ba02008-11-07 14:05:41 -08002743#define obj_to_crtc(x) container_of(x, struct drm_crtc, base)
2744#define obj_to_connector(x) container_of(x, struct drm_connector, base)
2745#define obj_to_encoder(x) container_of(x, struct drm_encoder, base)
2746#define obj_to_mode(x) container_of(x, struct drm_display_mode, base)
2747#define obj_to_fb(x) container_of(x, struct drm_framebuffer, base)
2748#define obj_to_property(x) container_of(x, struct drm_property, base)
2749#define obj_to_blob(x) container_of(x, struct drm_property_blob, base)
Jesse Barnes8cf5c912011-11-14 14:51:27 -08002750#define obj_to_plane(x) container_of(x, struct drm_plane, base)
Dave Airlief453ba02008-11-07 14:05:41 -08002751
Sascha Hauer4a67d392012-02-06 10:58:17 +01002752struct drm_prop_enum_list {
2753 int type;
2754 char *name;
2755};
Dave Airlief453ba02008-11-07 14:05:41 -08002756
Ville Syrjäläf9882872015-12-09 16:19:31 +02002757extern __printf(6, 7)
2758int drm_crtc_init_with_planes(struct drm_device *dev,
2759 struct drm_crtc *crtc,
2760 struct drm_plane *primary,
2761 struct drm_plane *cursor,
2762 const struct drm_crtc_funcs *funcs,
2763 const char *name, ...);
Dave Airlief453ba02008-11-07 14:05:41 -08002764extern void drm_crtc_cleanup(struct drm_crtc *crtc);
Chris Wilson490d3d12016-05-27 20:05:00 +01002765
2766/**
2767 * drm_crtc_index - find the index of a registered CRTC
2768 * @crtc: CRTC to find index for
2769 *
2770 * Given a registered CRTC, return the index of that CRTC within a DRM
2771 * device's list of CRTCs.
2772 */
2773static inline unsigned int drm_crtc_index(struct drm_crtc *crtc)
2774{
2775 return crtc->index;
2776}
Russell Kingdb5f7a62014-01-02 21:27:33 +00002777
2778/**
2779 * drm_crtc_mask - find the mask of a registered CRTC
2780 * @crtc: CRTC to find mask for
2781 *
2782 * Given a registered CRTC, return the mask bit of that CRTC for an
2783 * encoder's possible_crtcs field.
2784 */
2785static inline uint32_t drm_crtc_mask(struct drm_crtc *crtc)
2786{
2787 return 1 << drm_crtc_index(crtc);
2788}
Dave Airlief453ba02008-11-07 14:05:41 -08002789
Daniel Vetter81065542016-06-21 10:54:13 +02002790int drm_connector_init(struct drm_device *dev,
2791 struct drm_connector *connector,
2792 const struct drm_connector_funcs *funcs,
2793 int connector_type);
Thomas Wood34ea3d32014-05-29 16:57:41 +01002794int drm_connector_register(struct drm_connector *connector);
2795void drm_connector_unregister(struct drm_connector *connector);
Dave Airlief453ba02008-11-07 14:05:41 -08002796
2797extern void drm_connector_cleanup(struct drm_connector *connector);
Maarten Lankhorst5fff80b2016-02-17 08:32:05 +01002798static inline unsigned drm_connector_index(struct drm_connector *connector)
2799{
Daniel Vetter69425592016-07-19 18:25:01 +02002800 return connector->index;
Maarten Lankhorst5fff80b2016-02-17 08:32:05 +01002801}
2802
Ville Syrjälä13a3d912015-12-09 16:20:18 +02002803extern __printf(5, 6)
2804int drm_encoder_init(struct drm_device *dev,
2805 struct drm_encoder *encoder,
2806 const struct drm_encoder_funcs *funcs,
2807 int encoder_type, const char *name, ...);
Chris Wilson490d3d12016-05-27 20:05:00 +01002808
2809/**
2810 * drm_encoder_index - find the index of a registered encoder
2811 * @encoder: encoder to find index for
2812 *
2813 * Given a registered encoder, return the index of that encoder within a DRM
2814 * device's list of encoders.
2815 */
2816static inline unsigned int drm_encoder_index(struct drm_encoder *encoder)
2817{
2818 return encoder->index;
2819}
Dave Airlief453ba02008-11-07 14:05:41 -08002820
Thierry Reding3d887362014-01-13 14:33:20 +01002821/**
2822 * drm_encoder_crtc_ok - can a given crtc drive a given encoder?
2823 * @encoder: encoder to test
2824 * @crtc: crtc to test
2825 *
2826 * Return false if @encoder can't be driven by @crtc, true otherwise.
2827 */
2828static inline bool drm_encoder_crtc_ok(struct drm_encoder *encoder,
2829 struct drm_crtc *crtc)
2830{
2831 return !!(encoder->possible_crtcs & drm_crtc_mask(crtc));
2832}
2833
Ville Syrjäläb0b3b792015-12-09 16:19:55 +02002834extern __printf(8, 9)
2835int drm_universal_plane_init(struct drm_device *dev,
2836 struct drm_plane *plane,
2837 unsigned long possible_crtcs,
2838 const struct drm_plane_funcs *funcs,
2839 const uint32_t *formats,
2840 unsigned int format_count,
2841 enum drm_plane_type type,
2842 const char *name, ...);
Jesse Barnes8cf5c912011-11-14 14:51:27 -08002843extern int drm_plane_init(struct drm_device *dev,
2844 struct drm_plane *plane,
2845 unsigned long possible_crtcs,
2846 const struct drm_plane_funcs *funcs,
Thierry Reding45e37432015-08-12 16:54:28 +02002847 const uint32_t *formats, unsigned int format_count,
Matt Roperdc415ff2014-04-01 15:22:36 -07002848 bool is_primary);
Jesse Barnes8cf5c912011-11-14 14:51:27 -08002849extern void drm_plane_cleanup(struct drm_plane *plane);
Chris Wilson490d3d12016-05-27 20:05:00 +01002850
2851/**
2852 * drm_plane_index - find the index of a registered plane
2853 * @plane: plane to find index for
2854 *
2855 * Given a registered plane, return the index of that plane within a DRM
2856 * device's list of planes.
2857 */
2858static inline unsigned int drm_plane_index(struct drm_plane *plane)
2859{
2860 return plane->index;
2861}
Chandra Konduruf81338a2015-04-09 17:36:21 -07002862extern struct drm_plane * drm_plane_from_index(struct drm_device *dev, int idx);
Ville Syrjälä9125e612013-06-03 16:10:40 +03002863extern void drm_plane_force_disable(struct drm_plane *plane);
Gustavo Padovanecb7e162014-12-01 15:40:09 -08002864extern void drm_crtc_get_hv_timing(const struct drm_display_mode *mode,
2865 int *hdisplay, int *vdisplay);
Lukas Wunner6a0d9522016-06-08 18:47:27 +02002866extern int drm_crtc_force_disable(struct drm_crtc *crtc);
2867extern int drm_crtc_force_disable_all(struct drm_device *dev);
Jesse Barnes8cf5c912011-11-14 14:51:27 -08002868
Dave Airlief453ba02008-11-07 14:05:41 -08002869extern void drm_encoder_cleanup(struct drm_encoder *encoder);
2870
Ville Syrjäläd20d3172013-06-07 15:43:07 +00002871extern const char *drm_get_connector_status_name(enum drm_connector_status status);
Jesse Barnesac1bb362014-02-10 15:32:44 -08002872extern const char *drm_get_subpixel_order_name(enum subpixel_order order);
Ville Syrjäläd20d3172013-06-07 15:43:07 +00002873extern const char *drm_get_dpms_name(int val);
2874extern const char *drm_get_dvi_i_subconnector_name(int val);
2875extern const char *drm_get_dvi_i_select_name(int val);
2876extern const char *drm_get_tv_subconnector_name(int val);
2877extern const char *drm_get_tv_select_name(int val);
Dave Airlief453ba02008-11-07 14:05:41 -08002878extern void drm_mode_config_init(struct drm_device *dev);
Chris Wilsoneb0335562011-01-24 15:11:08 +00002879extern void drm_mode_config_reset(struct drm_device *dev);
Dave Airlief453ba02008-11-07 14:05:41 -08002880extern void drm_mode_config_cleanup(struct drm_device *dev);
Dave Airlief453ba02008-11-07 14:05:41 -08002881
Dave Airlie43aba7e2014-06-05 14:01:31 +10002882extern int drm_mode_connector_set_path_property(struct drm_connector *connector,
Thierry Reding12e6cec2014-05-13 11:38:36 +02002883 const char *path);
Dave Airlie6f134d72014-10-20 16:30:50 +10002884int drm_mode_connector_set_tile_property(struct drm_connector *connector);
Dave Airlief453ba02008-11-07 14:05:41 -08002885extern int drm_mode_connector_update_edid_property(struct drm_connector *connector,
Thierry Reding12e6cec2014-05-13 11:38:36 +02002886 const struct edid *edid);
Rob Clark5ea22f22014-05-30 11:34:01 -04002887
Boris Brezillonb5571e92014-07-22 12:09:10 +02002888extern int drm_display_info_set_bus_formats(struct drm_display_info *info,
2889 const u32 *formats,
2890 unsigned int num_formats);
2891
Rob Clark5ea22f22014-05-30 11:34:01 -04002892static inline bool drm_property_type_is(struct drm_property *property,
2893 uint32_t type)
2894{
2895 /* instanceof for props.. handles extended type vs original types: */
2896 if (property->flags & DRM_MODE_PROP_EXTENDED_TYPE)
2897 return (property->flags & DRM_MODE_PROP_EXTENDED_TYPE) == type;
2898 return property->flags & type;
2899}
2900
Paulo Zanonic5431882012-05-15 18:09:02 -03002901extern int drm_object_property_set_value(struct drm_mode_object *obj,
2902 struct drm_property *property,
2903 uint64_t val);
2904extern int drm_object_property_get_value(struct drm_mode_object *obj,
2905 struct drm_property *property,
2906 uint64_t *value);
Dave Airlief453ba02008-11-07 14:05:41 -08002907extern int drm_framebuffer_init(struct drm_device *dev,
2908 struct drm_framebuffer *fb,
2909 const struct drm_framebuffer_funcs *funcs);
Daniel Vetter786b99e2012-12-02 21:53:40 +01002910extern struct drm_framebuffer *drm_framebuffer_lookup(struct drm_device *dev,
2911 uint32_t id);
Rob Clarkf7eff602012-09-05 21:48:38 +00002912extern void drm_framebuffer_remove(struct drm_framebuffer *fb);
Dave Airlief453ba02008-11-07 14:05:41 -08002913extern void drm_framebuffer_cleanup(struct drm_framebuffer *fb);
Daniel Vetter36206362012-12-10 20:42:17 +01002914extern void drm_framebuffer_unregister_private(struct drm_framebuffer *fb);
Dave Airlief453ba02008-11-07 14:05:41 -08002915
Paulo Zanonic5431882012-05-15 18:09:02 -03002916extern void drm_object_attach_property(struct drm_mode_object *obj,
2917 struct drm_property *property,
2918 uint64_t init_val);
Dave Airlief453ba02008-11-07 14:05:41 -08002919extern struct drm_property *drm_property_create(struct drm_device *dev, int flags,
2920 const char *name, int num_values);
Sascha Hauer4a67d392012-02-06 10:58:17 +01002921extern struct drm_property *drm_property_create_enum(struct drm_device *dev, int flags,
2922 const char *name,
2923 const struct drm_prop_enum_list *props,
2924 int num_values);
Rob Clark49e27542012-05-17 02:23:26 -06002925struct drm_property *drm_property_create_bitmask(struct drm_device *dev,
2926 int flags, const char *name,
2927 const struct drm_prop_enum_list *props,
Ville Syrjälä7689ffb2014-07-08 10:31:52 +05302928 int num_props,
2929 uint64_t supported_bits);
Sascha Hauerd9bc3c02012-02-06 10:58:18 +01002930struct drm_property *drm_property_create_range(struct drm_device *dev, int flags,
2931 const char *name,
2932 uint64_t min, uint64_t max);
Rob Clarkebc44cf2012-09-12 22:22:31 -05002933struct drm_property *drm_property_create_signed_range(struct drm_device *dev,
2934 int flags, const char *name,
2935 int64_t min, int64_t max);
Rob Clark98f75de2014-05-30 11:37:03 -04002936struct drm_property *drm_property_create_object(struct drm_device *dev,
2937 int flags, const char *name, uint32_t type);
Daniel Vetter960cd9d2015-01-21 08:47:38 +01002938struct drm_property *drm_property_create_bool(struct drm_device *dev, int flags,
2939 const char *name);
Daniel Stone6bcacf52015-04-20 19:22:55 +01002940struct drm_property_blob *drm_property_create_blob(struct drm_device *dev,
2941 size_t length,
2942 const void *data);
2943struct drm_property_blob *drm_property_lookup_blob(struct drm_device *dev,
2944 uint32_t id);
2945struct drm_property_blob *drm_property_reference_blob(struct drm_property_blob *blob);
2946void drm_property_unreference_blob(struct drm_property_blob *blob);
Dave Airlief453ba02008-11-07 14:05:41 -08002947extern void drm_property_destroy(struct drm_device *dev, struct drm_property *property);
2948extern int drm_property_add_enum(struct drm_property *property, int index,
2949 uint64_t value, const char *name);
2950extern int drm_mode_create_dvi_i_properties(struct drm_device *dev);
Thierry Reding2f763312014-10-13 12:45:57 +02002951extern int drm_mode_create_tv_properties(struct drm_device *dev,
2952 unsigned int num_modes,
Ville Syrjäläb7c914b2015-08-31 15:09:26 +03002953 const char * const modes[]);
Dave Airlief453ba02008-11-07 14:05:41 -08002954extern int drm_mode_create_scaling_mode_property(struct drm_device *dev);
Vandana Kannanff587e42014-06-11 10:46:48 +05302955extern int drm_mode_create_aspect_ratio_property(struct drm_device *dev);
Jakob Bornecrantz884840a2009-12-03 23:25:47 +00002956extern int drm_mode_create_dirty_info_property(struct drm_device *dev);
Dave Airlie5bb2bbf2014-11-10 10:18:15 +10002957extern int drm_mode_create_suggested_offset_properties(struct drm_device *dev);
Dave Airlief453ba02008-11-07 14:05:41 -08002958
2959extern int drm_mode_connector_attach_encoder(struct drm_connector *connector,
2960 struct drm_encoder *encoder);
Sascha Hauer4cae5b82012-02-01 11:38:23 +01002961extern int drm_mode_crtc_set_gamma_size(struct drm_crtc *crtc,
Dave Airlief453ba02008-11-07 14:05:41 -08002962 int gamma_size);
Rob Clark98f75de2014-05-30 11:37:03 -04002963
Daniel Vetter2d13b672012-12-11 13:47:23 +01002964extern int drm_mode_set_config_internal(struct drm_mode_set *set);
Daniel Vetter81065542016-06-21 10:54:13 +02002965
Jesse Barnes308e5bc2011-11-14 14:51:28 -08002966extern uint32_t drm_mode_legacy_fb_format(uint32_t bpp, uint32_t depth);
Dave Airlie138f9eb2014-10-20 16:17:17 +10002967
2968extern struct drm_tile_group *drm_mode_create_tile_group(struct drm_device *dev,
2969 char topology[8]);
2970extern struct drm_tile_group *drm_mode_get_tile_group(struct drm_device *dev,
2971 char topology[8]);
2972extern void drm_mode_put_tile_group(struct drm_device *dev,
2973 struct drm_tile_group *tg);
Dave Airlieff72145b2011-02-07 12:16:14 +10002974
Thomas Wood3a5f87c2014-08-20 14:45:00 +01002975extern int drm_mode_plane_set_obj_prop(struct drm_plane *plane,
2976 struct drm_property *property,
2977 uint64_t value);
Dave Airlie248dbc22011-11-29 20:02:54 +00002978
Ville Syrjäläc1df5f32014-07-08 10:31:53 +05302979extern struct drm_property *drm_mode_create_rotation_property(struct drm_device *dev,
2980 unsigned int supported_rotations);
Ville Syrjälä3c9855f2014-07-08 10:31:56 +05302981extern unsigned int drm_rotation_simplify(unsigned int rotation,
2982 unsigned int supported_rotations);
Jyri Sarhaf8ed34a2016-06-07 15:09:14 +03002983extern void drm_crtc_enable_color_mgmt(struct drm_crtc *crtc,
2984 uint degamma_lut_size,
2985 bool has_ctm,
2986 uint gamma_lut_size);
Marek Szyprowski44d1240d2016-06-13 11:11:26 +02002987
2988int drm_plane_create_zpos_property(struct drm_plane *plane,
2989 unsigned int zpos,
2990 unsigned int min, unsigned int max);
2991
2992int drm_plane_create_zpos_immutable_property(struct drm_plane *plane,
2993 unsigned int zpos);
2994
Russell King96f60e32012-08-15 13:59:49 +01002995/* Helpers */
Daniel Vetter81065542016-06-21 10:54:13 +02002996struct drm_mode_object *drm_mode_object_find(struct drm_device *dev,
2997 uint32_t id, uint32_t type);
2998void drm_mode_object_reference(struct drm_mode_object *obj);
2999void drm_mode_object_unreference(struct drm_mode_object *obj);
Rob Clarka2b34e22013-10-05 16:36:52 -04003000
3001static inline struct drm_plane *drm_plane_find(struct drm_device *dev,
3002 uint32_t id)
3003{
3004 struct drm_mode_object *mo;
3005 mo = drm_mode_object_find(dev, id, DRM_MODE_OBJECT_PLANE);
3006 return mo ? obj_to_plane(mo) : NULL;
3007}
3008
Russell King96f60e32012-08-15 13:59:49 +01003009static inline struct drm_crtc *drm_crtc_find(struct drm_device *dev,
3010 uint32_t id)
3011{
3012 struct drm_mode_object *mo;
3013 mo = drm_mode_object_find(dev, id, DRM_MODE_OBJECT_CRTC);
3014 return mo ? obj_to_crtc(mo) : NULL;
3015}
3016
3017static inline struct drm_encoder *drm_encoder_find(struct drm_device *dev,
3018 uint32_t id)
3019{
3020 struct drm_mode_object *mo;
3021 mo = drm_mode_object_find(dev, id, DRM_MODE_OBJECT_ENCODER);
3022 return mo ? obj_to_encoder(mo) : NULL;
3023}
3024
Dave Airlieb164d312016-04-27 11:10:09 +10003025/**
3026 * drm_connector_lookup - lookup connector object
3027 * @dev: DRM device
3028 * @id: connector object id
3029 *
3030 * This function looks up the connector object specified by id
3031 * add takes a reference to it.
3032 */
3033static inline struct drm_connector *drm_connector_lookup(struct drm_device *dev,
Rob Clarka2b34e22013-10-05 16:36:52 -04003034 uint32_t id)
3035{
3036 struct drm_mode_object *mo;
3037 mo = drm_mode_object_find(dev, id, DRM_MODE_OBJECT_CONNECTOR);
3038 return mo ? obj_to_connector(mo) : NULL;
3039}
3040
3041static inline struct drm_property *drm_property_find(struct drm_device *dev,
3042 uint32_t id)
3043{
3044 struct drm_mode_object *mo;
3045 mo = drm_mode_object_find(dev, id, DRM_MODE_OBJECT_PROPERTY);
3046 return mo ? obj_to_property(mo) : NULL;
3047}
3048
Lionel Landwerlin5488dc12016-02-26 17:05:00 +00003049/*
3050 * Extract a degamma/gamma LUT value provided by user and round it to the
3051 * precision supported by the hardware.
3052 */
3053static inline uint32_t drm_color_lut_extract(uint32_t user_input,
3054 uint32_t bit_precision)
3055{
Lionel Landwerlin644a8052016-03-22 14:10:33 +00003056 uint32_t val = user_input;
Lionel Landwerlin5488dc12016-02-26 17:05:00 +00003057 uint32_t max = 0xffff >> (16 - bit_precision);
3058
Lionel Landwerlin644a8052016-03-22 14:10:33 +00003059 /* Round only if we're not using full precision. */
3060 if (bit_precision < 16) {
3061 val += 1UL << (16 - bit_precision - 1);
3062 val >>= 16 - bit_precision;
3063 }
Lionel Landwerlin5488dc12016-02-26 17:05:00 +00003064
3065 return clamp_val(val, 0, max);
3066}
3067
Dave Airliee76d3992016-05-03 10:17:52 +10003068/**
Dave Airlied0f37cf62016-04-15 15:10:36 +10003069 * drm_framebuffer_reference - incr the fb refcnt
3070 * @fb: framebuffer
3071 *
3072 * This functions increments the fb's refcount.
3073 */
3074static inline void drm_framebuffer_reference(struct drm_framebuffer *fb)
3075{
3076 drm_mode_object_reference(&fb->base);
3077}
3078
3079/**
3080 * drm_framebuffer_unreference - unref a framebuffer
3081 * @fb: framebuffer to unref
3082 *
3083 * This functions decrements the fb's refcount and frees it if it drops to zero.
3084 */
3085static inline void drm_framebuffer_unreference(struct drm_framebuffer *fb)
3086{
3087 drm_mode_object_unreference(&fb->base);
3088}
3089
Dave Airlie747a5982016-04-15 15:10:35 +10003090/**
3091 * drm_framebuffer_read_refcount - read the framebuffer reference count.
3092 * @fb: framebuffer
3093 *
3094 * This functions returns the framebuffer's reference count.
3095 */
3096static inline uint32_t drm_framebuffer_read_refcount(struct drm_framebuffer *fb)
3097{
Dave Airlied0f37cf62016-04-15 15:10:36 +10003098 return atomic_read(&fb->base.refcount.refcount);
Dave Airlie747a5982016-04-15 15:10:35 +10003099}
3100
Dave Airlieb164d312016-04-27 11:10:09 +10003101/**
3102 * drm_connector_reference - incr the connector refcnt
3103 * @connector: connector
3104 *
3105 * This function increments the connector's refcount.
3106 */
3107static inline void drm_connector_reference(struct drm_connector *connector)
3108{
3109 drm_mode_object_reference(&connector->base);
3110}
3111
3112/**
3113 * drm_connector_unreference - unref a connector
3114 * @connector: connector to unref
3115 *
3116 * This function decrements the connector's refcount and frees it if it drops to zero.
3117 */
3118static inline void drm_connector_unreference(struct drm_connector *connector)
3119{
3120 drm_mode_object_unreference(&connector->base);
3121}
3122
Matt Ropere27dde32014-04-01 15:22:30 -07003123/* Plane list iterator for legacy (overlay only) planes. */
Daniel Vetter4ea50e92015-07-09 23:44:24 +02003124#define drm_for_each_legacy_plane(plane, dev) \
3125 list_for_each_entry(plane, &(dev)->mode_config.plane_list, head) \
Jani Nikula373701b2015-11-24 21:21:55 +02003126 for_each_if (plane->type == DRM_PLANE_TYPE_OVERLAY)
Matt Ropere27dde32014-04-01 15:22:30 -07003127
Daniel Vetter6295d602015-07-09 23:44:25 +02003128#define drm_for_each_plane(plane, dev) \
3129 list_for_each_entry(plane, &(dev)->mode_config.plane_list, head)
3130
3131#define drm_for_each_crtc(crtc, dev) \
3132 list_for_each_entry(crtc, &(dev)->mode_config.crtc_list, head)
3133
Daniel Vetter7a3f3d62015-07-09 23:44:28 +02003134static inline void
3135assert_drm_connector_list_read_locked(struct drm_mode_config *mode_config)
3136{
Daniel Vettercff20ba2015-07-09 23:44:33 +02003137 /*
3138 * The connector hotadd/remove code currently grabs both locks when
3139 * updating lists. Hence readers need only hold either of them to be
3140 * safe and the check amounts to
3141 *
3142 * WARN_ON(not_holding(A) && not_holding(B)).
3143 */
3144 WARN_ON(!mutex_is_locked(&mode_config->mutex) &&
3145 !drm_modeset_is_locked(&mode_config->connection_mutex));
Daniel Vetter7a3f3d62015-07-09 23:44:28 +02003146}
3147
Daniel Vetter6295d602015-07-09 23:44:25 +02003148#define drm_for_each_connector(connector, dev) \
Daniel Vetter7a3f3d62015-07-09 23:44:28 +02003149 for (assert_drm_connector_list_read_locked(&(dev)->mode_config), \
3150 connector = list_first_entry(&(dev)->mode_config.connector_list, \
3151 struct drm_connector, head); \
3152 &connector->head != (&(dev)->mode_config.connector_list); \
3153 connector = list_next_entry(connector, head))
Daniel Vetter6295d602015-07-09 23:44:25 +02003154
3155#define drm_for_each_encoder(encoder, dev) \
3156 list_for_each_entry(encoder, &(dev)->mode_config.encoder_list, head)
3157
3158#define drm_for_each_fb(fb, dev) \
Daniel Vetter4676ba02015-07-09 23:44:30 +02003159 for (WARN_ON(!mutex_is_locked(&(dev)->mode_config.fb_lock)), \
3160 fb = list_first_entry(&(dev)->mode_config.fb_list, \
3161 struct drm_framebuffer, head); \
3162 &fb->head != (&(dev)->mode_config.fb_list); \
3163 fb = list_next_entry(fb, head))
Daniel Vetter6295d602015-07-09 23:44:25 +02003164
Daniel Vetter81065542016-06-21 10:54:13 +02003165/* drm_edid.c */
3166bool drm_probe_ddc(struct i2c_adapter *adapter);
3167struct edid *drm_get_edid(struct drm_connector *connector,
3168 struct i2c_adapter *adapter);
3169struct edid *drm_get_edid_switcheroo(struct drm_connector *connector,
3170 struct i2c_adapter *adapter);
3171struct edid *drm_edid_duplicate(const struct edid *edid);
3172int drm_add_edid_modes(struct drm_connector *connector, struct edid *edid);
3173
3174u8 drm_match_cea_mode(const struct drm_display_mode *to_match);
3175enum hdmi_picture_aspect drm_get_cea_aspect_ratio(const u8 video_code);
3176bool drm_detect_hdmi_monitor(struct edid *edid);
3177bool drm_detect_monitor_audio(struct edid *edid);
3178bool drm_rgb_quant_range_selectable(struct edid *edid);
3179int drm_add_modes_noedid(struct drm_connector *connector,
3180 int hdisplay, int vdisplay);
3181void drm_set_preferred_mode(struct drm_connector *connector,
3182 int hpref, int vpref);
3183
3184int drm_edid_header_is_valid(const u8 *raw_edid);
3185bool drm_edid_block_valid(u8 *raw_edid, int block, bool print_bad_edid,
3186 bool *edid_corrupt);
3187bool drm_edid_is_valid(struct edid *edid);
3188void drm_edid_get_monitor_name(struct edid *edid, char *name,
3189 int buflen);
3190struct drm_display_mode *drm_mode_find_dmt(struct drm_device *dev,
3191 int hsize, int vsize, int fresh,
3192 bool rb);
3193
3194/* drm_bridge.c */
3195extern int drm_bridge_add(struct drm_bridge *bridge);
3196extern void drm_bridge_remove(struct drm_bridge *bridge);
3197extern struct drm_bridge *of_drm_find_bridge(struct device_node *np);
3198extern int drm_bridge_attach(struct drm_device *dev, struct drm_bridge *bridge);
3199
3200bool drm_bridge_mode_fixup(struct drm_bridge *bridge,
3201 const struct drm_display_mode *mode,
3202 struct drm_display_mode *adjusted_mode);
3203void drm_bridge_disable(struct drm_bridge *bridge);
3204void drm_bridge_post_disable(struct drm_bridge *bridge);
3205void drm_bridge_mode_set(struct drm_bridge *bridge,
3206 struct drm_display_mode *mode,
3207 struct drm_display_mode *adjusted_mode);
3208void drm_bridge_pre_enable(struct drm_bridge *bridge);
3209void drm_bridge_enable(struct drm_bridge *bridge);
3210
Dave Airlief453ba02008-11-07 14:05:41 -08003211#endif /* __DRM_CRTC_H__ */