blob: 3c90563e1a546ffc13a1e6e55202eb84c17d59e9 [file] [log] [blame]
Dave Airlief453ba02008-11-07 14:05:41 -08001/*
2 * Copyright © 2006 Keith Packard
3 * Copyright © 2007-2008 Dave Airlie
4 * Copyright © 2007-2008 Intel Corporation
5 * Jesse Barnes <jesse.barnes@intel.com>
6 *
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the "Software"),
9 * to deal in the Software without restriction, including without limitation
10 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
11 * and/or sell copies of the Software, and to permit persons to whom the
12 * Software is furnished to do so, subject to the following conditions:
13 *
14 * The above copyright notice and this permission notice shall be included in
15 * all copies or substantial portions of the Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
21 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
22 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
23 * OTHER DEALINGS IN THE SOFTWARE.
24 */
25#ifndef __DRM_CRTC_H__
26#define __DRM_CRTC_H__
27
28#include <linux/i2c.h>
29#include <linux/spinlock.h>
30#include <linux/types.h>
31#include <linux/idr.h>
Dave Airlief453ba02008-11-07 14:05:41 -080032#include <linux/fb.h>
Vandana Kannan985e5dc2013-12-19 15:34:07 +053033#include <linux/hdmi.h>
Boris Brezillonb5571e92014-07-22 12:09:10 +020034#include <linux/media-bus-format.h>
David Herrmannd7d2c482014-08-29 12:12:40 +020035#include <uapi/drm/drm_mode.h>
36#include <uapi/drm/drm_fourcc.h>
Rob Clark51fd3712013-11-19 12:10:12 -050037#include <drm/drm_modeset_lock.h>
Jesse Barnes308e5bc2011-11-14 14:51:28 -080038
Dave Airlief453ba02008-11-07 14:05:41 -080039struct drm_device;
40struct drm_mode_set;
41struct drm_framebuffer;
Paulo Zanoni7e3bdf42012-05-15 18:09:01 -030042struct drm_object_properties;
Thierry Reding595887e2012-11-21 15:00:47 +010043struct drm_file;
44struct drm_clip_rect;
Russell King7e435aa2014-06-15 11:07:12 +010045struct device_node;
Daniel Vettere2330f02014-10-29 11:34:56 +010046struct fence;
Daniel Vetter81065542016-06-21 10:54:13 +020047struct edid;
Dave Airlief453ba02008-11-07 14:05:41 -080048
Dave Airlief453ba02008-11-07 14:05:41 -080049struct drm_mode_object {
50 uint32_t id;
51 uint32_t type;
Paulo Zanoni7e3bdf42012-05-15 18:09:01 -030052 struct drm_object_properties *properties;
Dave Airlied0f37cf62016-04-15 15:10:36 +100053 struct kref refcount;
54 void (*free_cb)(struct kref *kref);
Paulo Zanoni7e3bdf42012-05-15 18:09:01 -030055};
56
Paulo Zanonife456162012-06-12 11:27:01 -030057#define DRM_OBJECT_MAX_PROPERTY 24
Paulo Zanoni7e3bdf42012-05-15 18:09:01 -030058struct drm_object_properties {
Rob Clark88a48e22014-12-18 16:01:50 -050059 int count, atomic_count;
Rob Clarkb17cd752014-12-16 18:05:30 -050060 /* NOTE: if we ever start dynamically destroying properties (ie.
61 * not at drm_mode_config_cleanup() time), then we'd have to do
62 * a better job of detaching property from mode objects to avoid
63 * dangling property pointers:
64 */
65 struct drm_property *properties[DRM_OBJECT_MAX_PROPERTY];
Rob Clark22b8b132014-12-16 18:05:31 -050066 /* do not read/write values directly, but use drm_object_property_get_value()
67 * and drm_object_property_set_value():
68 */
Paulo Zanoni7e3bdf42012-05-15 18:09:01 -030069 uint64_t values[DRM_OBJECT_MAX_PROPERTY];
Dave Airlief453ba02008-11-07 14:05:41 -080070};
71
Rob Clarkebc44cf2012-09-12 22:22:31 -050072static inline int64_t U642I64(uint64_t val)
73{
74 return (int64_t)*((int64_t *)&val);
75}
76static inline uint64_t I642U64(int64_t val)
77{
78 return (uint64_t)*((uint64_t *)&val);
79}
80
Robert Feketed9c38242015-11-02 16:14:08 +010081/*
82 * Rotation property bits. DRM_ROTATE_<degrees> rotates the image by the
83 * specified amount in degrees in counter clockwise direction. DRM_REFLECT_X and
84 * DRM_REFLECT_Y reflects the image along the specified axis prior to rotation
85 */
Joonas Lahtinen62209072015-10-01 10:00:57 +030086#define DRM_ROTATE_MASK 0x0f
Ville Syrjälä06596962014-07-08 10:31:51 +053087#define DRM_ROTATE_0 0
88#define DRM_ROTATE_90 1
89#define DRM_ROTATE_180 2
90#define DRM_ROTATE_270 3
Joonas Lahtinen62209072015-10-01 10:00:57 +030091#define DRM_REFLECT_MASK (~DRM_ROTATE_MASK)
Ville Syrjälä06596962014-07-08 10:31:51 +053092#define DRM_REFLECT_X 4
93#define DRM_REFLECT_Y 5
94
Daniel Vetter55310002014-01-23 15:52:20 +010095enum drm_connector_force {
96 DRM_FORCE_UNSPECIFIED,
97 DRM_FORCE_OFF,
98 DRM_FORCE_ON, /* force on analog part normally */
99 DRM_FORCE_ON_DIGITAL, /* for DVI-I use digital connector */
Dave Airlief453ba02008-11-07 14:05:41 -0800100};
101
Daniel Vetter55310002014-01-23 15:52:20 +0100102#include <drm/drm_modes.h>
Damien Lespiau4aa17cf2013-09-25 16:45:21 +0100103
Dave Airlief453ba02008-11-07 14:05:41 -0800104enum drm_connector_status {
105 connector_status_connected = 1,
106 connector_status_disconnected = 2,
107 connector_status_unknown = 3,
108};
109
110enum subpixel_order {
111 SubPixelUnknown = 0,
112 SubPixelHorizontalRGB,
113 SubPixelHorizontalBGR,
114 SubPixelVerticalRGB,
115 SubPixelVerticalBGR,
116 SubPixelNone,
117};
118
Jesse Barnesda05a5a72011-04-15 13:48:57 -0700119#define DRM_COLOR_FORMAT_RGB444 (1<<0)
120#define DRM_COLOR_FORMAT_YCRCB444 (1<<1)
121#define DRM_COLOR_FORMAT_YCRCB422 (1<<2)
Stefan Agnerf0aa0832016-02-08 11:38:14 -0800122
123#define DRM_BUS_FLAG_DE_LOW (1<<0)
124#define DRM_BUS_FLAG_DE_HIGH (1<<1)
125/* drive data on pos. edge */
126#define DRM_BUS_FLAG_PIXDATA_POSEDGE (1<<2)
127/* drive data on neg. edge */
128#define DRM_BUS_FLAG_PIXDATA_NEGEDGE (1<<3)
129
Dave Airlief453ba02008-11-07 14:05:41 -0800130/*
131 * Describes a given display (e.g. CRT or flat panel) and its limitations.
132 */
133struct drm_display_info {
134 char name[DRM_DISPLAY_INFO_LEN];
Adam Jacksonfb439642010-08-03 14:38:16 -0400135
Dave Airlief453ba02008-11-07 14:05:41 -0800136 /* Physical size */
137 unsigned int width_mm;
138 unsigned int height_mm;
139
Dave Airlief453ba02008-11-07 14:05:41 -0800140 /* Clock limits FIXME: storage format */
141 unsigned int min_vfreq, max_vfreq;
142 unsigned int min_hfreq, max_hfreq;
143 unsigned int pixel_clock;
Jesse Barnes3b112282011-04-15 12:49:23 -0700144 unsigned int bpc;
Dave Airlief453ba02008-11-07 14:05:41 -0800145
Dave Airlief453ba02008-11-07 14:05:41 -0800146 enum subpixel_order subpixel_order;
Jesse Barnesda05a5a72011-04-15 13:48:57 -0700147 u32 color_formats;
Dave Airlief453ba02008-11-07 14:05:41 -0800148
Boris Brezillonb5571e92014-07-22 12:09:10 +0200149 const u32 *bus_formats;
150 unsigned int num_bus_formats;
Stefan Agnerf0aa0832016-02-08 11:38:14 -0800151 u32 bus_flags;
Boris Brezillonb5571e92014-07-22 12:09:10 +0200152
Mario Kleiner5d02626d2014-06-05 09:52:10 -0400153 /* Mask of supported hdmi deep color modes */
154 u8 edid_hdmi_dc_modes;
155
Jesse Barnesebec9a7b2011-08-03 09:22:54 -0700156 u8 cea_rev;
Dave Airlief453ba02008-11-07 14:05:41 -0800157};
158
Dave Airlie138f9eb2014-10-20 16:17:17 +1000159/* data corresponds to displayid vend/prod/serial */
160struct drm_tile_group {
161 struct kref refcount;
162 struct drm_device *dev;
163 int id;
164 u8 group_data[8];
165};
166
Daniel Vetterc6b0ca32015-12-04 09:46:01 +0100167/**
168 * struct drm_framebuffer_funcs - framebuffer hooks
169 */
Dave Airlief453ba02008-11-07 14:05:41 -0800170struct drm_framebuffer_funcs {
Daniel Vetterc6b0ca32015-12-04 09:46:01 +0100171 /**
172 * @destroy:
173 *
174 * Clean up framebuffer resources, specifically also unreference the
175 * backing storage. The core guarantees to call this function for every
176 * framebuffer successfully created by ->fb_create() in
Daniel Vetterd55f5322015-12-08 09:49:19 +0100177 * &drm_mode_config_funcs. Drivers must also call
178 * drm_framebuffer_cleanup() to release DRM core resources for this
179 * framebuffer.
Daniel Vetterc6b0ca32015-12-04 09:46:01 +0100180 */
Dave Airlief453ba02008-11-07 14:05:41 -0800181 void (*destroy)(struct drm_framebuffer *framebuffer);
Daniel Vetterc6b0ca32015-12-04 09:46:01 +0100182
183 /**
184 * @create_handle:
185 *
186 * Create a buffer handle in the driver-specific buffer manager (either
187 * GEM or TTM) valid for the passed-in struct &drm_file. This is used by
188 * the core to implement the GETFB IOCTL, which returns (for
189 * sufficiently priviledged user) also a native buffer handle. This can
190 * be used for seamless transitions between modesetting clients by
191 * copying the current screen contents to a private buffer and blending
192 * between that and the new contents.
193 *
Daniel Vetterd55f5322015-12-08 09:49:19 +0100194 * GEM based drivers should call drm_gem_handle_create() to create the
195 * handle.
196 *
Daniel Vetterc6b0ca32015-12-04 09:46:01 +0100197 * RETURNS:
198 *
199 * 0 on success or a negative error code on failure.
200 */
Dave Airlief453ba02008-11-07 14:05:41 -0800201 int (*create_handle)(struct drm_framebuffer *fb,
202 struct drm_file *file_priv,
203 unsigned int *handle);
Daniel Vetterc6b0ca32015-12-04 09:46:01 +0100204 /**
205 * @dirty:
Jakob Bornecrantz884840a2009-12-03 23:25:47 +0000206 *
Daniel Vetterc6b0ca32015-12-04 09:46:01 +0100207 * Optional callback for the dirty fb IOCTL.
Jakob Bornecrantz884840a2009-12-03 23:25:47 +0000208 *
Daniel Vetterc6b0ca32015-12-04 09:46:01 +0100209 * Userspace can notify the driver via this callback that an area of the
210 * framebuffer has changed and should be flushed to the display
211 * hardware. This can also be used internally, e.g. by the fbdev
212 * emulation, though that's not the case currently.
213 *
214 * See documentation in drm_mode.h for the struct drm_mode_fb_dirty_cmd
215 * for more information as all the semantics and arguments have a one to
216 * one mapping on this function.
217 *
218 * RETURNS:
219 *
220 * 0 on success or a negative error code on failure.
Jakob Bornecrantz884840a2009-12-03 23:25:47 +0000221 */
Thomas Hellstrom02b00162010-10-05 12:43:02 +0200222 int (*dirty)(struct drm_framebuffer *framebuffer,
223 struct drm_file *file_priv, unsigned flags,
Jakob Bornecrantz884840a2009-12-03 23:25:47 +0000224 unsigned color, struct drm_clip_rect *clips,
225 unsigned num_clips);
Dave Airlief453ba02008-11-07 14:05:41 -0800226};
227
228struct drm_framebuffer {
229 struct drm_device *dev;
Rob Clarkf7eff602012-09-05 21:48:38 +0000230 /*
231 * Note that the fb is refcounted for the benefit of driver internals,
232 * for example some hw, disabling a CRTC/plane is asynchronous, and
233 * scanout does not actually complete until the next vblank. So some
234 * cleanup (like releasing the reference(s) on the backing GEM bo(s))
235 * should be deferred. In cases like this, the driver would like to
236 * hold a ref to the fb even though it has already been removed from
237 * userspace perspective.
Dave Airlied0f37cf62016-04-15 15:10:36 +1000238 * The refcount is stored inside the mode object.
Rob Clarkf7eff602012-09-05 21:48:38 +0000239 */
Daniel Vetter4b096ac2012-12-10 21:19:18 +0100240 /*
241 * Place on the dev->mode_config.fb_list, access protected by
242 * dev->mode_config.fb_lock.
243 */
Dave Airlief453ba02008-11-07 14:05:41 -0800244 struct list_head head;
245 struct drm_mode_object base;
246 const struct drm_framebuffer_funcs *funcs;
Ville Syrjälä01f2c772011-12-20 00:06:49 +0200247 unsigned int pitches[4];
248 unsigned int offsets[4];
Rob Clarke3eb3252015-02-05 14:41:52 +0000249 uint64_t modifier[4];
Dave Airlief453ba02008-11-07 14:05:41 -0800250 unsigned int width;
251 unsigned int height;
252 /* depth can be 15 or 16 */
253 unsigned int depth;
254 int bits_per_pixel;
255 int flags;
Jesse Barnes308e5bc2011-11-14 14:51:28 -0800256 uint32_t pixel_format; /* fourcc format */
Gerd Hoffmanndd546592016-05-31 08:54:52 +0200257 int hot_x;
258 int hot_y;
Dave Airlief453ba02008-11-07 14:05:41 -0800259 struct list_head filp_head;
260};
261
262struct drm_property_blob {
263 struct drm_mode_object base;
Daniel Stone6bcacf52015-04-20 19:22:55 +0100264 struct drm_device *dev;
Daniel Stonee2f5d2e2015-05-22 13:34:51 +0100265 struct list_head head_global;
266 struct list_head head_file;
Thierry Redingecbbe592014-05-13 11:36:13 +0200267 size_t length;
Ville Syrjäläd63f5e62012-03-13 12:35:49 +0200268 unsigned char data[];
Dave Airlief453ba02008-11-07 14:05:41 -0800269};
270
271struct drm_property_enum {
272 uint64_t value;
273 struct list_head head;
274 char name[DRM_PROP_NAME_LEN];
275};
276
277struct drm_property {
278 struct list_head head;
279 struct drm_mode_object base;
280 uint32_t flags;
281 char name[DRM_PROP_NAME_LEN];
282 uint32_t num_values;
283 uint64_t *values;
Rob Clark98f75de2014-05-30 11:37:03 -0400284 struct drm_device *dev;
Dave Airlief453ba02008-11-07 14:05:41 -0800285
Daniel Vetter3758b342014-11-19 18:38:10 +0100286 struct list_head enum_list;
Dave Airlief453ba02008-11-07 14:05:41 -0800287};
288
289struct drm_crtc;
290struct drm_connector;
291struct drm_encoder;
Kristian Høgsbergd91d8a32009-11-17 12:43:55 -0500292struct drm_pending_vblank_event;
Jesse Barnes8cf5c912011-11-14 14:51:27 -0800293struct drm_plane;
Sean Paul3b336ec2013-08-14 16:47:37 -0400294struct drm_bridge;
Daniel Vetter144ecb92014-10-27 20:28:44 +0100295struct drm_atomic_state;
296
Daniel Vetter4490d4c2015-12-04 09:45:45 +0100297struct drm_crtc_helper_funcs;
298struct drm_encoder_helper_funcs;
299struct drm_connector_helper_funcs;
300struct drm_plane_helper_funcs;
301
Daniel Vetter144ecb92014-10-27 20:28:44 +0100302/**
Daniel Vettercc4ceb42014-07-25 21:30:38 +0200303 * struct drm_crtc_state - mutable CRTC state
Daniel Vetter07cc0ef2014-11-27 15:49:39 +0100304 * @crtc: backpointer to the CRTC
Daniel Vetter144ecb92014-10-27 20:28:44 +0100305 * @enable: whether the CRTC should be enabled, gates all other state
Daniel Vetterd9b13622014-11-26 16:57:41 +0100306 * @active: whether the CRTC is actively displaying (used for DPMS)
Maarten Lankhorstfc596662015-07-21 13:28:57 +0200307 * @planes_changed: planes on this crtc are updated
308 * @mode_changed: crtc_state->mode or crtc_state->enable has been changed
309 * @active_changed: crtc_state->active has been toggled.
310 * @connectors_changed: connectors to this crtc have been updated
Marek Szyprowski44d1240d2016-06-13 11:11:26 +0200311 * @zpos_changed: zpos values of planes on this crtc have been updated
Lionel Landwerlin5488dc12016-02-26 17:05:00 +0000312 * @color_mgmt_changed: color management properties have changed (degamma or
313 * gamma LUT or CSC matrix)
Rob Clark6ddd3882014-11-21 15:28:31 -0500314 * @plane_mask: bitmask of (1 << drm_plane_index(plane)) of attached planes
Maarten Lankhorst4cd9fa52016-01-04 12:53:18 +0100315 * @connector_mask: bitmask of (1 << drm_connector_index(connector)) of attached connectors
Maarten Lankhorste87a52b2016-01-28 15:04:58 +0100316 * @encoder_mask: bitmask of (1 << drm_encoder_index(encoder)) of attached encoders
Daniel Vetter623369e2014-09-16 17:50:47 +0200317 * @last_vblank_count: for helpers and drivers to capture the vblank of the
318 * update to ensure framebuffer cleanup isn't done too early
Daniel Vetter2f324b42014-10-29 11:13:47 +0100319 * @adjusted_mode: for use by helpers and drivers to compute adjusted mode timings
Daniel Vetter144ecb92014-10-27 20:28:44 +0100320 * @mode: current mode timings
Daniel Vetterac3ba4a2016-05-31 23:11:10 +0200321 * @mode_blob: &drm_property_blob for @mode
Lionel Landwerlin5488dc12016-02-26 17:05:00 +0000322 * @degamma_lut: Lookup table for converting framebuffer pixel data
323 * before apply the conversion matrix
324 * @ctm: Transformation matrix
325 * @gamma_lut: Lookup table for converting pixel data after the
326 * conversion matrix
Daniel Vetter144ecb92014-10-27 20:28:44 +0100327 * @event: optional pointer to a DRM event to signal upon completion of the
328 * state update
329 * @state: backpointer to global drm_atomic_state
Daniel Vetterd9b13622014-11-26 16:57:41 +0100330 *
331 * Note that the distinction between @enable and @active is rather subtile:
332 * Flipping @active while @enable is set without changing anything else may
333 * never return in a failure from the ->atomic_check callback. Userspace assumes
334 * that a DPMS On will always succeed. In other words: @enable controls resource
335 * assignment, @active controls the actual hardware state.
Daniel Vetter144ecb92014-10-27 20:28:44 +0100336 */
337struct drm_crtc_state {
Daniel Vetter07cc0ef2014-11-27 15:49:39 +0100338 struct drm_crtc *crtc;
339
Daniel Vettercc4ceb42014-07-25 21:30:38 +0200340 bool enable;
Daniel Vetterd9b13622014-11-26 16:57:41 +0100341 bool active;
Daniel Vetter144ecb92014-10-27 20:28:44 +0100342
Daniel Vetterc2fcd272014-11-05 00:14:14 +0100343 /* computed state bits used by helpers and drivers */
344 bool planes_changed : 1;
Daniel Vetter623369e2014-09-16 17:50:47 +0200345 bool mode_changed : 1;
Daniel Vettereab3bbe2015-01-22 16:36:21 +0100346 bool active_changed : 1;
Maarten Lankhorstfc596662015-07-21 13:28:57 +0200347 bool connectors_changed : 1;
Marek Szyprowski44d1240d2016-06-13 11:11:26 +0200348 bool zpos_changed : 1;
Lionel Landwerlin5488dc12016-02-26 17:05:00 +0000349 bool color_mgmt_changed : 1;
Daniel Vetter623369e2014-09-16 17:50:47 +0200350
Rob Clark6ddd3882014-11-21 15:28:31 -0500351 /* attached planes bitmask:
352 * WARNING: transitional helpers do not maintain plane_mask so
353 * drivers not converted over to atomic helpers should not rely
354 * on plane_mask being accurate!
355 */
356 u32 plane_mask;
357
Maarten Lankhorst4cd9fa52016-01-04 12:53:18 +0100358 u32 connector_mask;
Maarten Lankhorste87a52b2016-01-28 15:04:58 +0100359 u32 encoder_mask;
Maarten Lankhorst4cd9fa52016-01-04 12:53:18 +0100360
Daniel Vetter623369e2014-09-16 17:50:47 +0200361 /* last_vblank_count: for vblank waits before cleanup */
362 u32 last_vblank_count;
Daniel Vetterc2fcd272014-11-05 00:14:14 +0100363
Daniel Vetter2f324b42014-10-29 11:13:47 +0100364 /* adjusted_mode: for use by helpers and drivers */
365 struct drm_display_mode adjusted_mode;
366
Daniel Vetter144ecb92014-10-27 20:28:44 +0100367 struct drm_display_mode mode;
368
Daniel Stone99cf4a22015-05-25 19:11:51 +0100369 /* blob property to expose current mode to atomic userspace */
370 struct drm_property_blob *mode_blob;
371
Lionel Landwerlin5488dc12016-02-26 17:05:00 +0000372 /* blob property to expose color management to userspace */
373 struct drm_property_blob *degamma_lut;
374 struct drm_property_blob *ctm;
375 struct drm_property_blob *gamma_lut;
376
Daniel Vetter144ecb92014-10-27 20:28:44 +0100377 struct drm_pending_vblank_event *event;
378
379 struct drm_atomic_state *state;
380};
Dave Airlief453ba02008-11-07 14:05:41 -0800381
382/**
Daniel Vetter3bf04012014-10-27 16:54:27 +0100383 * struct drm_crtc_funcs - control CRTCs for a given device
Dave Airlief453ba02008-11-07 14:05:41 -0800384 *
385 * The drm_crtc_funcs structure is the central CRTC management structure
386 * in the DRM. Each CRTC controls one or more connectors (note that the name
387 * CRTC is simply historical, a CRTC may control LVDS, VGA, DVI, TV out, etc.
388 * connectors, not just CRTs).
389 *
390 * Each driver is responsible for filling out this structure at startup time,
391 * in addition to providing other modesetting features, like i2c and DDC
392 * bus accessors.
393 */
394struct drm_crtc_funcs {
Daniel Vetter88548632015-12-04 09:45:48 +0100395 /**
396 * @reset:
397 *
398 * Reset CRTC hardware and software state to off. This function isn't
399 * called by the core directly, only through drm_mode_config_reset().
400 * It's not a helper hook only for historical reasons.
401 *
402 * Atomic drivers can use drm_atomic_helper_crtc_reset() to reset
403 * atomic state using this hook.
404 */
Chris Wilsoneb0335562011-01-24 15:11:08 +0000405 void (*reset)(struct drm_crtc *crtc);
Dave Airlief453ba02008-11-07 14:05:41 -0800406
Daniel Vetterf6da8c62015-12-04 09:46:00 +0100407 /**
408 * @cursor_set:
409 *
410 * Update the cursor image. The cursor position is relative to the CRTC
411 * and can be partially or fully outside of the visible area.
412 *
413 * Note that contrary to all other KMS functions the legacy cursor entry
414 * points don't take a framebuffer object, but instead take directly a
415 * raw buffer object id from the driver's buffer manager (which is
416 * either GEM or TTM for current drivers).
417 *
418 * This entry point is deprecated, drivers should instead implement
419 * universal plane support and register a proper cursor plane using
420 * drm_crtc_init_with_planes().
421 *
422 * This callback is optional
423 *
424 * RETURNS:
425 *
426 * 0 on success or a negative error code on failure.
427 */
Dave Airlief453ba02008-11-07 14:05:41 -0800428 int (*cursor_set)(struct drm_crtc *crtc, struct drm_file *file_priv,
429 uint32_t handle, uint32_t width, uint32_t height);
Daniel Vetterf6da8c62015-12-04 09:46:00 +0100430
431 /**
432 * @cursor_set2:
433 *
434 * Update the cursor image, including hotspot information. The hotspot
435 * must not affect the cursor position in CRTC coordinates, but is only
436 * meant as a hint for virtualized display hardware to coordinate the
437 * guests and hosts cursor position. The cursor hotspot is relative to
438 * the cursor image. Otherwise this works exactly like @cursor_set.
439 *
440 * This entry point is deprecated, drivers should instead implement
441 * universal plane support and register a proper cursor plane using
442 * drm_crtc_init_with_planes().
443 *
444 * This callback is optional.
445 *
446 * RETURNS:
447 *
448 * 0 on success or a negative error code on failure.
449 */
Dave Airlie4c813d42013-06-20 11:48:52 +1000450 int (*cursor_set2)(struct drm_crtc *crtc, struct drm_file *file_priv,
451 uint32_t handle, uint32_t width, uint32_t height,
452 int32_t hot_x, int32_t hot_y);
Daniel Vetterf6da8c62015-12-04 09:46:00 +0100453
454 /**
455 * @cursor_move:
456 *
457 * Update the cursor position. The cursor does not need to be visible
458 * when this hook is called.
459 *
460 * This entry point is deprecated, drivers should instead implement
461 * universal plane support and register a proper cursor plane using
462 * drm_crtc_init_with_planes().
463 *
464 * This callback is optional.
465 *
466 * RETURNS:
467 *
468 * 0 on success or a negative error code on failure.
469 */
Dave Airlief453ba02008-11-07 14:05:41 -0800470 int (*cursor_move)(struct drm_crtc *crtc, int x, int y);
471
Daniel Vetterf6da8c62015-12-04 09:46:00 +0100472 /**
473 * @gamma_set:
474 *
475 * Set gamma on the CRTC.
476 *
477 * This callback is optional.
478 *
479 * NOTE:
480 *
481 * Drivers that support gamma tables and also fbdev emulation through
482 * the provided helper library need to take care to fill out the gamma
483 * hooks for both. Currently there's a bit an unfortunate duplication
484 * going on, which should eventually be unified to just one set of
485 * hooks.
486 */
Maarten Lankhorst7ea77282016-06-07 12:49:30 +0200487 int (*gamma_set)(struct drm_crtc *crtc, u16 *r, u16 *g, u16 *b,
488 uint32_t size);
Daniel Vetter88548632015-12-04 09:45:48 +0100489
490 /**
491 * @destroy:
492 *
493 * Clean up plane resources. This is only called at driver unload time
494 * through drm_mode_config_cleanup() since a CRTC cannot be hotplugged
495 * in DRM.
496 */
Dave Airlief453ba02008-11-07 14:05:41 -0800497 void (*destroy)(struct drm_crtc *crtc);
498
Daniel Vetterf6da8c62015-12-04 09:46:00 +0100499 /**
500 * @set_config:
501 *
502 * This is the main legacy entry point to change the modeset state on a
503 * CRTC. All the details of the desired configuration are passed in a
504 * struct &drm_mode_set - see there for details.
505 *
506 * Drivers implementing atomic modeset should use
507 * drm_atomic_helper_set_config() to implement this hook.
508 *
509 * RETURNS:
510 *
511 * 0 on success or a negative error code on failure.
512 */
Dave Airlief453ba02008-11-07 14:05:41 -0800513 int (*set_config)(struct drm_mode_set *set);
Kristian Høgsbergd91d8a32009-11-17 12:43:55 -0500514
Daniel Vetterf6da8c62015-12-04 09:46:00 +0100515 /**
516 * @page_flip:
517 *
518 * Legacy entry point to schedule a flip to the given framebuffer.
519 *
520 * Page flipping is a synchronization mechanism that replaces the frame
521 * buffer being scanned out by the CRTC with a new frame buffer during
522 * vertical blanking, avoiding tearing (except when requested otherwise
523 * through the DRM_MODE_PAGE_FLIP_ASYNC flag). When an application
524 * requests a page flip the DRM core verifies that the new frame buffer
525 * is large enough to be scanned out by the CRTC in the currently
526 * configured mode and then calls the CRTC ->page_flip() operation with a
527 * pointer to the new frame buffer.
528 *
529 * The driver must wait for any pending rendering to the new framebuffer
530 * to complete before executing the flip. It should also wait for any
531 * pending rendering from other drivers if the underlying buffer is a
532 * shared dma-buf.
533 *
534 * An application can request to be notified when the page flip has
535 * completed. The drm core will supply a struct &drm_event in the event
536 * parameter in this case. This can be handled by the
537 * drm_crtc_send_vblank_event() function, which the driver should call on
538 * the provided event upon completion of the flip. Note that if
539 * the driver supports vblank signalling and timestamping the vblank
540 * counters and timestamps must agree with the ones returned from page
541 * flip events. With the current vblank helper infrastructure this can
542 * be achieved by holding a vblank reference while the page flip is
543 * pending, acquired through drm_crtc_vblank_get() and released with
544 * drm_crtc_vblank_put(). Drivers are free to implement their own vblank
545 * counter and timestamp tracking though, e.g. if they have accurate
546 * timestamp registers in hardware.
547 *
548 * FIXME:
549 *
550 * Up to that point drivers need to manage events themselves and can use
551 * even->base.list freely for that. Specifically they need to ensure
552 * that they don't send out page flip (or vblank) events for which the
553 * corresponding drm file has been closed already. The drm core
554 * unfortunately does not (yet) take care of that. Therefore drivers
555 * currently must clean up and release pending events in their
556 * ->preclose driver function.
557 *
558 * This callback is optional.
559 *
560 * NOTE:
561 *
562 * Very early versions of the KMS ABI mandated that the driver must
563 * block (but not reject) any rendering to the old framebuffer until the
564 * flip operation has completed and the old framebuffer is no longer
565 * visible. This requirement has been lifted, and userspace is instead
566 * expected to request delivery of an event and wait with recycling old
567 * buffers until such has been received.
568 *
569 * RETURNS:
570 *
571 * 0 on success or a negative error code on failure. Note that if a
572 * ->page_flip() operation is already pending the callback should return
573 * -EBUSY. Pageflips on a disabled CRTC (either by setting a NULL mode
574 * or just runtime disabled through DPMS respectively the new atomic
Daniel Vetter4cba6852015-12-08 09:49:20 +0100575 * "ACTIVE" state) should result in an -EINVAL error code. Note that
576 * drm_atomic_helper_page_flip() checks this already for atomic drivers.
Kristian Høgsbergd91d8a32009-11-17 12:43:55 -0500577 */
578 int (*page_flip)(struct drm_crtc *crtc,
579 struct drm_framebuffer *fb,
Keith Packarded8d1972013-07-22 18:49:58 -0700580 struct drm_pending_vblank_event *event,
581 uint32_t flags);
Paulo Zanonibffd9de02012-05-15 18:09:05 -0300582
Daniel Vetter88548632015-12-04 09:45:48 +0100583 /**
Michel Dänzerc229bfb2016-08-08 16:23:03 +0900584 * @page_flip_target:
585 *
586 * Same as @page_flip but with an additional parameter specifying the
587 * absolute target vertical blank period (as reported by
588 * drm_crtc_vblank_count()) when the flip should take effect.
589 *
590 * Note that the core code calls drm_crtc_vblank_get before this entry
591 * point, and will call drm_crtc_vblank_put if this entry point returns
592 * any non-0 error code. It's the driver's responsibility to call
593 * drm_crtc_vblank_put after this entry point returns 0, typically when
594 * the flip completes.
595 */
596 int (*page_flip_target)(struct drm_crtc *crtc,
597 struct drm_framebuffer *fb,
598 struct drm_pending_vblank_event *event,
599 uint32_t flags, uint32_t target);
600
601 /**
Daniel Vetter88548632015-12-04 09:45:48 +0100602 * @set_property:
603 *
604 * This is the legacy entry point to update a property attached to the
605 * CRTC.
606 *
607 * Drivers implementing atomic modeset should use
608 * drm_atomic_helper_crtc_set_property() to implement this hook.
609 *
610 * This callback is optional if the driver does not support any legacy
611 * driver-private properties.
612 *
613 * RETURNS:
614 *
615 * 0 on success or a negative error code on failure.
616 */
Paulo Zanonibffd9de02012-05-15 18:09:05 -0300617 int (*set_property)(struct drm_crtc *crtc,
618 struct drm_property *property, uint64_t val);
Daniel Vetter144ecb92014-10-27 20:28:44 +0100619
Daniel Vetter88548632015-12-04 09:45:48 +0100620 /**
621 * @atomic_duplicate_state:
622 *
623 * Duplicate the current atomic state for this CRTC and return it.
624 * The core and helpers gurantee that any atomic state duplicated with
625 * this hook and still owned by the caller (i.e. not transferred to the
626 * driver by calling ->atomic_commit() from struct
627 * &drm_mode_config_funcs) will be cleaned up by calling the
628 * @atomic_destroy_state hook in this structure.
629 *
630 * Atomic drivers which don't subclass struct &drm_crtc should use
631 * drm_atomic_helper_crtc_duplicate_state(). Drivers that subclass the
632 * state structure to extend it with driver-private state should use
633 * __drm_atomic_helper_crtc_duplicate_state() to make sure shared state is
634 * duplicated in a consistent fashion across drivers.
635 *
636 * It is an error to call this hook before crtc->state has been
637 * initialized correctly.
638 *
639 * NOTE:
640 *
641 * If the duplicate state references refcounted resources this hook must
642 * acquire a reference for each of them. The driver must release these
643 * references again in @atomic_destroy_state.
644 *
645 * RETURNS:
646 *
647 * Duplicated atomic state or NULL when the allocation failed.
648 */
Daniel Vetter144ecb92014-10-27 20:28:44 +0100649 struct drm_crtc_state *(*atomic_duplicate_state)(struct drm_crtc *crtc);
Daniel Vetter88548632015-12-04 09:45:48 +0100650
651 /**
652 * @atomic_destroy_state:
653 *
654 * Destroy a state duplicated with @atomic_duplicate_state and release
655 * or unreference all resources it references
656 */
Daniel Vetter144ecb92014-10-27 20:28:44 +0100657 void (*atomic_destroy_state)(struct drm_crtc *crtc,
Daniel Vettercc4ceb42014-07-25 21:30:38 +0200658 struct drm_crtc_state *state);
Daniel Vetter88548632015-12-04 09:45:48 +0100659
660 /**
661 * @atomic_set_property:
662 *
663 * Decode a driver-private property value and store the decoded value
664 * into the passed-in state structure. Since the atomic core decodes all
665 * standardized properties (even for extensions beyond the core set of
666 * properties which might not be implemented by all drivers) this
667 * requires drivers to subclass the state structure.
668 *
669 * Such driver-private properties should really only be implemented for
670 * truly hardware/vendor specific state. Instead it is preferred to
671 * standardize atomic extension and decode the properties used to expose
672 * such an extension in the core.
673 *
674 * Do not call this function directly, use
675 * drm_atomic_crtc_set_property() instead.
676 *
677 * This callback is optional if the driver does not support any
678 * driver-private atomic properties.
679 *
680 * NOTE:
681 *
682 * This function is called in the state assembly phase of atomic
683 * modesets, which can be aborted for any reason (including on
684 * userspace's request to just check whether a configuration would be
685 * possible). Drivers MUST NOT touch any persistent state (hardware or
686 * software) or data structures except the passed in @state parameter.
687 *
688 * Also since userspace controls in which order properties are set this
689 * function must not do any input validation (since the state update is
690 * incomplete and hence likely inconsistent). Instead any such input
691 * validation must be done in the various atomic_check callbacks.
692 *
693 * RETURNS:
694 *
695 * 0 if the property has been found, -EINVAL if the property isn't
696 * implemented by the driver (which should never happen, the core only
697 * asks for properties attached to this CRTC). No other validation is
698 * allowed by the driver. The core already checks that the property
699 * value is within the range (integer, valid enum value, ...) the driver
700 * set when registering the property.
701 */
Daniel Vetter144ecb92014-10-27 20:28:44 +0100702 int (*atomic_set_property)(struct drm_crtc *crtc,
703 struct drm_crtc_state *state,
704 struct drm_property *property,
705 uint64_t val);
Daniel Vetter88548632015-12-04 09:45:48 +0100706 /**
707 * @atomic_get_property:
708 *
709 * Reads out the decoded driver-private property. This is used to
Daniel Vetterc6b0ca32015-12-04 09:46:01 +0100710 * implement the GETCRTC IOCTL.
Daniel Vetter88548632015-12-04 09:45:48 +0100711 *
712 * Do not call this function directly, use
713 * drm_atomic_crtc_get_property() instead.
714 *
715 * This callback is optional if the driver does not support any
716 * driver-private atomic properties.
717 *
718 * RETURNS:
719 *
720 * 0 on success, -EINVAL if the property isn't implemented by the
721 * driver (which should never happen, the core only asks for
722 * properties attached to this CRTC).
723 */
Rob Clarkac9c9252014-12-18 16:01:47 -0500724 int (*atomic_get_property)(struct drm_crtc *crtc,
725 const struct drm_crtc_state *state,
726 struct drm_property *property,
727 uint64_t *val);
Benjamin Gaignard79190ea2016-06-21 16:37:09 +0200728
729 /**
730 * @late_register:
731 *
732 * This optional hook can be used to register additional userspace
733 * interfaces attached to the crtc like debugfs interfaces.
734 * It is called late in the driver load sequence from drm_dev_register().
735 * Everything added from this callback should be unregistered in
736 * the early_unregister callback.
737 *
738 * Returns:
739 *
740 * 0 on success, or a negative error code on failure.
741 */
742 int (*late_register)(struct drm_crtc *crtc);
743
744 /**
745 * @early_unregister:
746 *
747 * This optional hook should be used to unregister the additional
748 * userspace interfaces attached to the crtc from
749 * late_unregister(). It is called from drm_dev_unregister(),
750 * early in the driver unload sequence to disable userspace access
751 * before data structures are torndown.
752 */
753 void (*early_unregister)(struct drm_crtc *crtc);
Dave Airlief453ba02008-11-07 14:05:41 -0800754};
755
756/**
Daniel Vetter3bf04012014-10-27 16:54:27 +0100757 * struct drm_crtc - central CRTC control structure
Jesse Barnes77491632011-11-07 12:03:14 -0800758 * @dev: parent DRM device
Daniel Vetter2c0c33d2014-10-27 20:19:38 +0100759 * @port: OF node used by drm_of_find_possible_crtcs()
Jesse Barnes77491632011-11-07 12:03:14 -0800760 * @head: list management
Daniel Vetterac3ba4a2016-05-31 23:11:10 +0200761 * @name: human readable name, can be overwritten by the driver
Rob Clark51fd3712013-11-19 12:10:12 -0500762 * @mutex: per-CRTC locking
Jesse Barnes77491632011-11-07 12:03:14 -0800763 * @base: base KMS object for ID tracking etc.
Matt Ropere13161a2014-04-01 15:22:38 -0700764 * @primary: primary plane for this CRTC
765 * @cursor: cursor plane for this CRTC
Daniel Vetter2c0c33d2014-10-27 20:19:38 +0100766 * @cursor_x: current x position of the cursor, used for universal cursor planes
767 * @cursor_y: current y position of the cursor, used for universal cursor planes
Dave Airlief453ba02008-11-07 14:05:41 -0800768 * @enabled: is this CRTC enabled?
Jesse Barnes77491632011-11-07 12:03:14 -0800769 * @mode: current mode timings
770 * @hwmode: mode timings as programmed to hw regs
Dave Airlief453ba02008-11-07 14:05:41 -0800771 * @x: x position on screen
772 * @y: y position on screen
Dave Airlief453ba02008-11-07 14:05:41 -0800773 * @funcs: CRTC control functions
Jesse Barnes77491632011-11-07 12:03:14 -0800774 * @gamma_size: size of gamma ramp
775 * @gamma_store: gamma ramp values
Jesse Barnes77491632011-11-07 12:03:14 -0800776 * @helper_private: mid-layer private data
Paulo Zanonibffd9de02012-05-15 18:09:05 -0300777 * @properties: property tracking for this CRTC
Dave Airlief453ba02008-11-07 14:05:41 -0800778 *
779 * Each CRTC may have one or more connectors associated with it. This structure
780 * allows the CRTC to be controlled.
781 */
782struct drm_crtc {
783 struct drm_device *dev;
Russell King7e435aa2014-06-15 11:07:12 +0100784 struct device_node *port;
Dave Airlief453ba02008-11-07 14:05:41 -0800785 struct list_head head;
786
Ville Syrjäläfa3ab4c2015-12-08 18:41:53 +0200787 char *name;
788
Daniel Vetterac3ba4a2016-05-31 23:11:10 +0200789 /**
790 * @mutex:
Daniel Vetter29494c12012-12-02 02:18:25 +0100791 *
792 * This provides a read lock for the overall crtc state (mode, dpms
793 * state, ...) and a write lock for everything which can be update
Daniel Vetterac3ba4a2016-05-31 23:11:10 +0200794 * without a full modeset (fb, cursor data, crtc properties ...). Full
795 * modeset also need to grab dev->mode_config.connection_mutex.
Daniel Vetter29494c12012-12-02 02:18:25 +0100796 */
Rob Clark51fd3712013-11-19 12:10:12 -0500797 struct drm_modeset_lock mutex;
Daniel Vetter29494c12012-12-02 02:18:25 +0100798
Dave Airlief453ba02008-11-07 14:05:41 -0800799 struct drm_mode_object base;
800
Matt Ropere13161a2014-04-01 15:22:38 -0700801 /* primary and cursor planes for CRTC */
802 struct drm_plane *primary;
803 struct drm_plane *cursor;
804
Daniel Vetter96094082016-07-15 21:47:59 +0200805 /**
806 * @index: Position inside the mode_config.list, can be used as an array
807 * index. It is invariant over the lifetime of the CRTC.
808 */
Chris Wilson490d3d12016-05-27 20:05:00 +0100809 unsigned index;
810
Matt Roper161d0dc2014-06-10 08:28:10 -0700811 /* position of cursor plane on crtc */
812 int cursor_x;
813 int cursor_y;
814
Dave Airlief453ba02008-11-07 14:05:41 -0800815 bool enabled;
816
Mario Kleiner27641c32010-10-23 04:20:23 +0200817 /* Requested mode from modesetting. */
Dave Airlief453ba02008-11-07 14:05:41 -0800818 struct drm_display_mode mode;
819
Mario Kleiner27641c32010-10-23 04:20:23 +0200820 /* Programmed mode in hw, after adjustments for encoders,
821 * crtc, panel scaling etc. Needed for timestamping etc.
822 */
823 struct drm_display_mode hwmode;
824
Dave Airlief453ba02008-11-07 14:05:41 -0800825 int x, y;
Dave Airlief453ba02008-11-07 14:05:41 -0800826 const struct drm_crtc_funcs *funcs;
827
Lionel Landwerlin5488dc12016-02-26 17:05:00 +0000828 /* Legacy FB CRTC gamma size for reporting to userspace */
Dave Airlief453ba02008-11-07 14:05:41 -0800829 uint32_t gamma_size;
830 uint16_t *gamma_store;
831
832 /* if you are using the helper */
Daniel Vetter4490d4c2015-12-04 09:45:45 +0100833 const struct drm_crtc_helper_funcs *helper_private;
Paulo Zanonibffd9de02012-05-15 18:09:05 -0300834
835 struct drm_object_properties properties;
Daniel Vetterd059f652014-07-25 18:07:40 +0200836
Daniel Vetter3b24f7d2016-06-08 14:19:00 +0200837 /**
838 * @state:
839 *
840 * Current atomic state for this CRTC.
841 */
Daniel Vetter144ecb92014-10-27 20:28:44 +0100842 struct drm_crtc_state *state;
843
Daniel Vetter3b24f7d2016-06-08 14:19:00 +0200844 /**
845 * @commit_list:
846 *
847 * List of &drm_crtc_commit structures tracking pending commits.
848 * Protected by @commit_lock. This list doesn't hold its own full
849 * reference, but burrows it from the ongoing commit. Commit entries
850 * must be removed from this list once the commit is fully completed,
851 * but before it's correspoding &drm_atomic_state gets destroyed.
852 */
853 struct list_head commit_list;
854
855 /**
856 * @commit_lock:
857 *
858 * Spinlock to protect @commit_list.
859 */
860 spinlock_t commit_lock;
861
862 /**
863 * @acquire_ctx:
864 *
865 * Per-CRTC implicit acquire context used by atomic drivers for legacy
866 * IOCTLs, so that atomic drivers can get at the locking acquire
867 * context.
Daniel Vetterd059f652014-07-25 18:07:40 +0200868 */
869 struct drm_modeset_acquire_ctx *acquire_ctx;
Dave Airlief453ba02008-11-07 14:05:41 -0800870};
871
Daniel Vetter144ecb92014-10-27 20:28:44 +0100872/**
873 * struct drm_connector_state - mutable connector state
Daniel Vetter07cc0ef2014-11-27 15:49:39 +0100874 * @connector: backpointer to the connector
Daniel Vettercc4ceb42014-07-25 21:30:38 +0200875 * @crtc: CRTC to connect connector to, NULL if disabled
Daniel Vetter623369e2014-09-16 17:50:47 +0200876 * @best_encoder: can be used by helpers and drivers to select the encoder
Daniel Vetter144ecb92014-10-27 20:28:44 +0100877 * @state: backpointer to global drm_atomic_state
878 */
879struct drm_connector_state {
Daniel Vetter07cc0ef2014-11-27 15:49:39 +0100880 struct drm_connector *connector;
881
Rob Clark6ddd3882014-11-21 15:28:31 -0500882 struct drm_crtc *crtc; /* do not write directly, use drm_atomic_set_crtc_for_connector() */
Daniel Vetter144ecb92014-10-27 20:28:44 +0100883
Daniel Vetter623369e2014-09-16 17:50:47 +0200884 struct drm_encoder *best_encoder;
885
Daniel Vetter144ecb92014-10-27 20:28:44 +0100886 struct drm_atomic_state *state;
887};
Dave Airlief453ba02008-11-07 14:05:41 -0800888
889/**
Daniel Vetter3bf04012014-10-27 16:54:27 +0100890 * struct drm_connector_funcs - control connectors on a given device
Daniel Vetter144ecb92014-10-27 20:28:44 +0100891 *
Dave Airlief453ba02008-11-07 14:05:41 -0800892 * Each CRTC may have one or more connectors attached to it. The functions
893 * below allow the core DRM code to control connectors, enumerate available modes,
894 * etc.
895 */
896struct drm_connector_funcs {
Daniel Vetter6fe14ac2015-12-04 09:45:58 +0100897 /**
898 * @dpms:
899 *
900 * Legacy entry point to set the per-connector DPMS state. Legacy DPMS
901 * is exposed as a standard property on the connector, but diverted to
902 * this callback in the drm core. Note that atomic drivers don't
903 * implement the 4 level DPMS support on the connector any more, but
904 * instead only have an on/off "ACTIVE" property on the CRTC object.
905 *
906 * Drivers implementing atomic modeset should use
907 * drm_atomic_helper_connector_dpms() to implement this hook.
908 *
909 * RETURNS:
910 *
911 * 0 on success or a negative error code on failure.
912 */
Maarten Lankhorst9a69a9a2015-07-21 11:34:55 +0200913 int (*dpms)(struct drm_connector *connector, int mode);
Daniel Vetter88548632015-12-04 09:45:48 +0100914
915 /**
916 * @reset:
917 *
918 * Reset connector hardware and software state to off. This function isn't
919 * called by the core directly, only through drm_mode_config_reset().
920 * It's not a helper hook only for historical reasons.
921 *
922 * Atomic drivers can use drm_atomic_helper_connector_reset() to reset
923 * atomic state using this hook.
924 */
Chris Wilsoneb0335562011-01-24 15:11:08 +0000925 void (*reset)(struct drm_connector *connector);
Chris Wilson930a9e22010-09-14 11:07:23 +0100926
Daniel Vetter6fe14ac2015-12-04 09:45:58 +0100927 /**
928 * @detect:
929 *
930 * Check to see if anything is attached to the connector. The parameter
931 * force is set to false whilst polling, true when checking the
932 * connector due to a user request. force can be used by the driver to
933 * avoid expensive, destructive operations during automated probing.
934 *
935 * FIXME:
936 *
937 * Note that this hook is only called by the probe helper. It's not in
938 * the helper library vtable purely for historical reasons. The only DRM
939 * core entry point to probe connector state is @fill_modes.
940 *
941 * RETURNS:
942 *
943 * drm_connector_status indicating the connector's status.
Chris Wilson930a9e22010-09-14 11:07:23 +0100944 */
Chris Wilson7b334fc2010-09-09 23:51:02 +0100945 enum drm_connector_status (*detect)(struct drm_connector *connector,
Chris Wilson930a9e22010-09-14 11:07:23 +0100946 bool force);
Daniel Vetter6fe14ac2015-12-04 09:45:58 +0100947
948 /**
949 * @force:
950 *
951 * This function is called to update internal encoder state when the
952 * connector is forced to a certain state by userspace, either through
953 * the sysfs interfaces or on the kernel cmdline. In that case the
954 * @detect callback isn't called.
955 *
956 * FIXME:
957 *
958 * Note that this hook is only called by the probe helper. It's not in
959 * the helper library vtable purely for historical reasons. The only DRM
960 * core entry point to probe connector state is @fill_modes.
961 */
962 void (*force)(struct drm_connector *connector);
963
964 /**
965 * @fill_modes:
966 *
967 * Entry point for output detection and basic mode validation. The
968 * driver should reprobe the output if needed (e.g. when hotplug
969 * handling is unreliable), add all detected modes to connector->modes
970 * and filter out any the device can't support in any configuration. It
971 * also needs to filter out any modes wider or higher than the
972 * parameters max_width and max_height indicate.
973 *
974 * The drivers must also prune any modes no longer valid from
975 * connector->modes. Furthermore it must update connector->status and
976 * connector->edid. If no EDID has been received for this output
977 * connector->edid must be NULL.
978 *
979 * Drivers using the probe helpers should use
980 * drm_helper_probe_single_connector_modes() or
981 * drm_helper_probe_single_connector_modes_nomerge() to implement this
982 * function.
983 *
984 * RETURNS:
985 *
986 * The number of modes detected and filled into connector->modes.
987 */
Jesse Barnes40a518d2009-01-12 12:05:32 -0800988 int (*fill_modes)(struct drm_connector *connector, uint32_t max_width, uint32_t max_height);
Daniel Vetter88548632015-12-04 09:45:48 +0100989
990 /**
991 * @set_property:
992 *
993 * This is the legacy entry point to update a property attached to the
994 * connector.
995 *
996 * Drivers implementing atomic modeset should use
997 * drm_atomic_helper_connector_set_property() to implement this hook.
998 *
999 * This callback is optional if the driver does not support any legacy
1000 * driver-private properties.
1001 *
1002 * RETURNS:
1003 *
1004 * 0 on success or a negative error code on failure.
1005 */
Dave Airlief453ba02008-11-07 14:05:41 -08001006 int (*set_property)(struct drm_connector *connector, struct drm_property *property,
1007 uint64_t val);
Daniel Vetter88548632015-12-04 09:45:48 +01001008
1009 /**
Chris Wilsonaaf285e2016-06-15 13:17:47 +01001010 * @late_register:
1011 *
1012 * This optional hook can be used to register additional userspace
1013 * interfaces attached to the connector, light backlight control, i2c,
1014 * DP aux or similar interfaces. It is called late in the driver load
1015 * sequence from drm_connector_register() when registering all the
1016 * core drm connector interfaces. Everything added from this callback
1017 * should be unregistered in the early_unregister callback.
1018 *
1019 * Returns:
1020 *
1021 * 0 on success, or a negative error code on failure.
1022 */
1023 int (*late_register)(struct drm_connector *connector);
1024
1025 /**
1026 * @early_unregister:
1027 *
1028 * This optional hook should be used to unregister the additional
1029 * userspace interfaces attached to the connector from
1030 * late_unregister(). It is called from drm_connector_unregister(),
1031 * early in the driver unload sequence to disable userspace access
1032 * before data structures are torndown.
1033 */
1034 void (*early_unregister)(struct drm_connector *connector);
1035
1036 /**
Daniel Vetter88548632015-12-04 09:45:48 +01001037 * @destroy:
1038 *
1039 * Clean up connector resources. This is called at driver unload time
1040 * through drm_mode_config_cleanup(). It can also be called at runtime
1041 * when a connector is being hot-unplugged for drivers that support
1042 * connector hotplugging (e.g. DisplayPort MST).
1043 */
Dave Airlief453ba02008-11-07 14:05:41 -08001044 void (*destroy)(struct drm_connector *connector);
Daniel Vetter144ecb92014-10-27 20:28:44 +01001045
Daniel Vetter88548632015-12-04 09:45:48 +01001046 /**
1047 * @atomic_duplicate_state:
1048 *
1049 * Duplicate the current atomic state for this connector and return it.
1050 * The core and helpers gurantee that any atomic state duplicated with
1051 * this hook and still owned by the caller (i.e. not transferred to the
1052 * driver by calling ->atomic_commit() from struct
1053 * &drm_mode_config_funcs) will be cleaned up by calling the
1054 * @atomic_destroy_state hook in this structure.
1055 *
1056 * Atomic drivers which don't subclass struct &drm_connector_state should use
1057 * drm_atomic_helper_connector_duplicate_state(). Drivers that subclass the
1058 * state structure to extend it with driver-private state should use
1059 * __drm_atomic_helper_connector_duplicate_state() to make sure shared state is
1060 * duplicated in a consistent fashion across drivers.
1061 *
1062 * It is an error to call this hook before connector->state has been
1063 * initialized correctly.
1064 *
1065 * NOTE:
1066 *
1067 * If the duplicate state references refcounted resources this hook must
1068 * acquire a reference for each of them. The driver must release these
1069 * references again in @atomic_destroy_state.
1070 *
1071 * RETURNS:
1072 *
1073 * Duplicated atomic state or NULL when the allocation failed.
1074 */
Daniel Vetter144ecb92014-10-27 20:28:44 +01001075 struct drm_connector_state *(*atomic_duplicate_state)(struct drm_connector *connector);
Daniel Vetter88548632015-12-04 09:45:48 +01001076
1077 /**
1078 * @atomic_destroy_state:
1079 *
1080 * Destroy a state duplicated with @atomic_duplicate_state and release
1081 * or unreference all resources it references
1082 */
Daniel Vetter144ecb92014-10-27 20:28:44 +01001083 void (*atomic_destroy_state)(struct drm_connector *connector,
Daniel Vettercc4ceb42014-07-25 21:30:38 +02001084 struct drm_connector_state *state);
Daniel Vetter88548632015-12-04 09:45:48 +01001085
1086 /**
1087 * @atomic_set_property:
1088 *
1089 * Decode a driver-private property value and store the decoded value
1090 * into the passed-in state structure. Since the atomic core decodes all
1091 * standardized properties (even for extensions beyond the core set of
1092 * properties which might not be implemented by all drivers) this
1093 * requires drivers to subclass the state structure.
1094 *
1095 * Such driver-private properties should really only be implemented for
1096 * truly hardware/vendor specific state. Instead it is preferred to
1097 * standardize atomic extension and decode the properties used to expose
1098 * such an extension in the core.
1099 *
1100 * Do not call this function directly, use
1101 * drm_atomic_connector_set_property() instead.
1102 *
1103 * This callback is optional if the driver does not support any
1104 * driver-private atomic properties.
1105 *
1106 * NOTE:
1107 *
1108 * This function is called in the state assembly phase of atomic
1109 * modesets, which can be aborted for any reason (including on
1110 * userspace's request to just check whether a configuration would be
1111 * possible). Drivers MUST NOT touch any persistent state (hardware or
1112 * software) or data structures except the passed in @state parameter.
1113 *
1114 * Also since userspace controls in which order properties are set this
1115 * function must not do any input validation (since the state update is
1116 * incomplete and hence likely inconsistent). Instead any such input
1117 * validation must be done in the various atomic_check callbacks.
1118 *
1119 * RETURNS:
1120 *
1121 * 0 if the property has been found, -EINVAL if the property isn't
1122 * implemented by the driver (which shouldn't ever happen, the core only
1123 * asks for properties attached to this connector). No other validation
1124 * is allowed by the driver. The core already checks that the property
1125 * value is within the range (integer, valid enum value, ...) the driver
1126 * set when registering the property.
1127 */
Daniel Vetter144ecb92014-10-27 20:28:44 +01001128 int (*atomic_set_property)(struct drm_connector *connector,
1129 struct drm_connector_state *state,
1130 struct drm_property *property,
1131 uint64_t val);
Daniel Vetter88548632015-12-04 09:45:48 +01001132
1133 /**
1134 * @atomic_get_property:
1135 *
1136 * Reads out the decoded driver-private property. This is used to
Daniel Vetterc6b0ca32015-12-04 09:46:01 +01001137 * implement the GETCONNECTOR IOCTL.
Daniel Vetter88548632015-12-04 09:45:48 +01001138 *
1139 * Do not call this function directly, use
1140 * drm_atomic_connector_get_property() instead.
1141 *
1142 * This callback is optional if the driver does not support any
1143 * driver-private atomic properties.
1144 *
1145 * RETURNS:
1146 *
1147 * 0 on success, -EINVAL if the property isn't implemented by the
1148 * driver (which shouldn't ever happen, the core only asks for
1149 * properties attached to this connector).
1150 */
Rob Clarkac9c9252014-12-18 16:01:47 -05001151 int (*atomic_get_property)(struct drm_connector *connector,
1152 const struct drm_connector_state *state,
1153 struct drm_property *property,
1154 uint64_t *val);
Dave Airlief453ba02008-11-07 14:05:41 -08001155};
1156
Jesse Barnes6c3db922011-11-07 12:03:16 -08001157/**
Daniel Vetter3bf04012014-10-27 16:54:27 +01001158 * struct drm_encoder_funcs - encoder controls
Jesse Barnes6c3db922011-11-07 12:03:16 -08001159 *
1160 * Encoders sit between CRTCs and connectors.
1161 */
Dave Airlief453ba02008-11-07 14:05:41 -08001162struct drm_encoder_funcs {
Daniel Vetter88548632015-12-04 09:45:48 +01001163 /**
1164 * @reset:
1165 *
1166 * Reset encoder hardware and software state to off. This function isn't
1167 * called by the core directly, only through drm_mode_config_reset().
1168 * It's not a helper hook only for historical reasons.
1169 */
Chris Wilsoneb0335562011-01-24 15:11:08 +00001170 void (*reset)(struct drm_encoder *encoder);
Daniel Vetter88548632015-12-04 09:45:48 +01001171
1172 /**
1173 * @destroy:
1174 *
1175 * Clean up encoder resources. This is only called at driver unload time
1176 * through drm_mode_config_cleanup() since an encoder cannot be
1177 * hotplugged in DRM.
1178 */
Dave Airlief453ba02008-11-07 14:05:41 -08001179 void (*destroy)(struct drm_encoder *encoder);
Benjamin Gaignard79190ea2016-06-21 16:37:09 +02001180
1181 /**
1182 * @late_register:
1183 *
1184 * This optional hook can be used to register additional userspace
1185 * interfaces attached to the encoder like debugfs interfaces.
1186 * It is called late in the driver load sequence from drm_dev_register().
1187 * Everything added from this callback should be unregistered in
1188 * the early_unregister callback.
1189 *
1190 * Returns:
1191 *
1192 * 0 on success, or a negative error code on failure.
1193 */
1194 int (*late_register)(struct drm_encoder *encoder);
1195
1196 /**
1197 * @early_unregister:
1198 *
1199 * This optional hook should be used to unregister the additional
1200 * userspace interfaces attached to the encoder from
1201 * late_unregister(). It is called from drm_dev_unregister(),
1202 * early in the driver unload sequence to disable userspace access
1203 * before data structures are torndown.
1204 */
1205 void (*early_unregister)(struct drm_encoder *encoder);
Dave Airlief453ba02008-11-07 14:05:41 -08001206};
1207
Ben Skeggsafe887d2012-01-12 16:00:57 +10001208#define DRM_CONNECTOR_MAX_ENCODER 3
Dave Airlief453ba02008-11-07 14:05:41 -08001209
1210/**
Daniel Vetter3bf04012014-10-27 16:54:27 +01001211 * struct drm_encoder - central DRM encoder structure
Jesse Barnesdb3e4492011-11-07 12:03:17 -08001212 * @dev: parent DRM device
1213 * @head: list management
1214 * @base: base KMS object
Daniel Vetterac3ba4a2016-05-31 23:11:10 +02001215 * @name: human readable name, can be overwritten by the driver
Jesse Barnesdb3e4492011-11-07 12:03:17 -08001216 * @encoder_type: one of the %DRM_MODE_ENCODER_<foo> types in drm_mode.h
1217 * @possible_crtcs: bitmask of potential CRTC bindings
1218 * @possible_clones: bitmask of potential sibling encoders for cloning
1219 * @crtc: currently bound CRTC
Sean Paul3b336ec2013-08-14 16:47:37 -04001220 * @bridge: bridge associated to the encoder
Jesse Barnesdb3e4492011-11-07 12:03:17 -08001221 * @funcs: control functions
1222 * @helper_private: mid-layer private data
1223 *
1224 * CRTCs drive pixels to encoders, which convert them into signals
1225 * appropriate for a given connector or set of connectors.
Dave Airlief453ba02008-11-07 14:05:41 -08001226 */
1227struct drm_encoder {
1228 struct drm_device *dev;
1229 struct list_head head;
1230
1231 struct drm_mode_object base;
Jani Nikulae5748942014-05-14 16:58:20 +03001232 char *name;
Dave Airlief453ba02008-11-07 14:05:41 -08001233 int encoder_type;
Chris Wilson490d3d12016-05-27 20:05:00 +01001234
Daniel Vetter96094082016-07-15 21:47:59 +02001235 /**
1236 * @index: Position inside the mode_config.list, can be used as an array
1237 * index. It is invariant over the lifetime of the encoder.
1238 */
Chris Wilson490d3d12016-05-27 20:05:00 +01001239 unsigned index;
1240
Dave Airlief453ba02008-11-07 14:05:41 -08001241 uint32_t possible_crtcs;
1242 uint32_t possible_clones;
1243
1244 struct drm_crtc *crtc;
Sean Paul3b336ec2013-08-14 16:47:37 -04001245 struct drm_bridge *bridge;
Dave Airlief453ba02008-11-07 14:05:41 -08001246 const struct drm_encoder_funcs *funcs;
Daniel Vetter4490d4c2015-12-04 09:45:45 +01001247 const struct drm_encoder_helper_funcs *helper_private;
Dave Airlief453ba02008-11-07 14:05:41 -08001248};
1249
Dave Airlieeb1f8e4f32010-05-07 06:42:51 +00001250/* should we poll this connector for connects and disconnects */
1251/* hot plug detectable */
1252#define DRM_CONNECTOR_POLL_HPD (1 << 0)
1253/* poll for connections */
1254#define DRM_CONNECTOR_POLL_CONNECT (1 << 1)
1255/* can cleanly poll for disconnections without flickering the screen */
1256/* DACs should rarely do this without a lot of testing */
1257#define DRM_CONNECTOR_POLL_DISCONNECT (1 << 2)
1258
Wu Fengguang76adaa342011-09-05 14:23:20 +08001259#define MAX_ELD_BYTES 128
1260
Dave Airlief453ba02008-11-07 14:05:41 -08001261/**
Daniel Vetter3bf04012014-10-27 16:54:27 +01001262 * struct drm_connector - central DRM connector control structure
Jesse Barnes72252542011-11-07 12:03:18 -08001263 * @dev: parent DRM device
1264 * @kdev: kernel device for sysfs attributes
1265 * @attr: sysfs attributes
1266 * @head: list management
1267 * @base: base KMS object
Daniel Vetterac3ba4a2016-05-31 23:11:10 +02001268 * @name: human readable name, can be overwritten by the driver
Jesse Barnes72252542011-11-07 12:03:18 -08001269 * @connector_type: one of the %DRM_MODE_CONNECTOR_<foo> types from drm_mode.h
1270 * @connector_type_id: index into connector type enum
Dave Airlief453ba02008-11-07 14:05:41 -08001271 * @interlace_allowed: can this connector handle interlaced modes?
1272 * @doublescan_allowed: can this connector handle doublescan?
Daniel Vetter2c0c33d2014-10-27 20:19:38 +01001273 * @stereo_allowed: can this connector handle stereo modes?
Chris Wilson40daac62016-06-15 13:17:48 +01001274 * @registered: is this connector exposed (registered) with userspace?
Jesse Barnes72252542011-11-07 12:03:18 -08001275 * @modes: modes available on this connector (from fill_modes() + user)
1276 * @status: one of the drm_connector_status enums (connected, not, or unknown)
1277 * @probed_modes: list of modes derived directly from the display
1278 * @display_info: information about attached display (e.g. from EDID)
Dave Airlief453ba02008-11-07 14:05:41 -08001279 * @funcs: connector control functions
Jesse Barnes72252542011-11-07 12:03:18 -08001280 * @edid_blob_ptr: DRM property containing EDID if present
Paulo Zanoni7e3bdf42012-05-15 18:09:01 -03001281 * @properties: property tracking for this connector
Jesse Barnes72252542011-11-07 12:03:18 -08001282 * @polled: a %DRM_CONNECTOR_POLL_<foo> value for core driven polling
1283 * @dpms: current dpms state
1284 * @helper_private: mid-layer private data
Daniel Vetter2c0c33d2014-10-27 20:19:38 +01001285 * @cmdline_mode: mode line parsed from the kernel cmdline for this connector
Jesse Barnes72252542011-11-07 12:03:18 -08001286 * @force: a %DRM_FORCE_<foo> state for forced mode sets
Daniel Vetter2c0c33d2014-10-27 20:19:38 +01001287 * @override_edid: has the EDID been overwritten through debugfs for testing?
Jesse Barnes72252542011-11-07 12:03:18 -08001288 * @encoder_ids: valid encoders for this connector
1289 * @encoder: encoder driving this connector, if any
1290 * @eld: EDID-like data, if present
1291 * @dvi_dual: dual link DVI, if found
1292 * @max_tmds_clock: max clock rate, if found
1293 * @latency_present: AV delay info from ELD, if found
1294 * @video_latency: video latency info from ELD, if found
1295 * @audio_latency: audio latency info from ELD, if found
1296 * @null_edid_counter: track sinks that give us all zeros for the EDID
Daniel Vetter2c0c33d2014-10-27 20:19:38 +01001297 * @bad_edid_counter: track sinks that give us an EDID with invalid checksum
Daniel Vetterac6f2e22015-05-08 16:15:41 +02001298 * @edid_corrupt: indicates whether the last read EDID was corrupt
Daniel Vetter2c0c33d2014-10-27 20:19:38 +01001299 * @debugfs_entry: debugfs directory for this connector
Daniel Vetter144ecb92014-10-27 20:28:44 +01001300 * @state: current atomic state for this connector
Dave Airlie40d9b042014-10-20 16:29:33 +10001301 * @has_tile: is this connector connected to a tiled monitor
1302 * @tile_group: tile group for the connected monitor
1303 * @tile_is_single_monitor: whether the tile is one monitor housing
1304 * @num_h_tile: number of horizontal tiles in the tile group
1305 * @num_v_tile: number of vertical tiles in the tile group
1306 * @tile_h_loc: horizontal location of this tile
1307 * @tile_v_loc: vertical location of this tile
1308 * @tile_h_size: horizontal size of this tile.
1309 * @tile_v_size: vertical size of this tile.
Dave Airlief453ba02008-11-07 14:05:41 -08001310 *
1311 * Each connector may be connected to one or more CRTCs, or may be clonable by
1312 * another connector if they can share a CRTC. Each connector also has a specific
1313 * position in the broader display (referred to as a 'screen' though it could
1314 * span multiple monitors).
1315 */
1316struct drm_connector {
1317 struct drm_device *dev;
Dave Airlie5bdebb12013-10-11 14:07:25 +10001318 struct device *kdev;
Dave Airlief453ba02008-11-07 14:05:41 -08001319 struct device_attribute *attr;
1320 struct list_head head;
1321
1322 struct drm_mode_object base;
1323
Jani Nikula2abdd312014-05-14 16:58:19 +03001324 char *name;
Daniel Vetter69425592016-07-19 18:25:01 +02001325
1326 /**
1327 * @index: Compacted connector index, which matches the position inside
1328 * the mode_config.list for drivers not supporting hot-add/removing. Can
1329 * be used as an array index. It is invariant over the lifetime of the
1330 * connector.
1331 */
1332 unsigned index;
1333
Dave Airlief453ba02008-11-07 14:05:41 -08001334 int connector_type;
1335 int connector_type_id;
1336 bool interlace_allowed;
1337 bool doublescan_allowed;
Damien Lespiau560a0672013-09-25 16:45:29 +01001338 bool stereo_allowed;
Chris Wilson40daac62016-06-15 13:17:48 +01001339 bool registered;
Dave Airlief453ba02008-11-07 14:05:41 -08001340 struct list_head modes; /* list of modes on this connector */
1341
Dave Airlief453ba02008-11-07 14:05:41 -08001342 enum drm_connector_status status;
1343
1344 /* these are modes added by probing with DDC or the BIOS */
1345 struct list_head probed_modes;
1346
1347 struct drm_display_info display_info;
1348 const struct drm_connector_funcs *funcs;
1349
Dave Airlief453ba02008-11-07 14:05:41 -08001350 struct drm_property_blob *edid_blob_ptr;
Paulo Zanoni7e3bdf42012-05-15 18:09:01 -03001351 struct drm_object_properties properties;
Dave Airlief453ba02008-11-07 14:05:41 -08001352
Daniel Vetterac3ba4a2016-05-31 23:11:10 +02001353 /**
1354 * @path_blob_ptr:
1355 *
1356 * DRM blob property data for the DP MST path property.
1357 */
Dave Airlie43aba7e2014-06-05 14:01:31 +10001358 struct drm_property_blob *path_blob_ptr;
1359
Daniel Vetterac3ba4a2016-05-31 23:11:10 +02001360 /**
1361 * @tile_blob_ptr:
1362 *
1363 * DRM blob property data for the tile property (used mostly by DP MST).
1364 * This is meant for screens which are driven through separate display
1365 * pipelines represented by &drm_crtc, which might not be running with
1366 * genlocked clocks. For tiled panels which are genlocked, like
1367 * dual-link LVDS or dual-link DSI, the driver should try to not expose
1368 * the tiling and virtualize both &drm_crtc and &drm_plane if needed.
1369 */
Dave Airlie6f134d72014-10-20 16:30:50 +10001370 struct drm_property_blob *tile_blob_ptr;
1371
Dave Airlieeb1f8e4f32010-05-07 06:42:51 +00001372 uint8_t polled; /* DRM_CONNECTOR_POLL_* */
1373
Keith Packardc9fb15f2009-05-30 20:42:28 -07001374 /* requested DPMS state */
1375 int dpms;
1376
Daniel Vetter4490d4c2015-12-04 09:45:45 +01001377 const struct drm_connector_helper_funcs *helper_private;
Dave Airlief453ba02008-11-07 14:05:41 -08001378
Dave Airlied50ba252009-09-23 14:44:08 +10001379 /* forced on connector */
Chris Wilsoneaf99c72014-08-06 10:08:32 +02001380 struct drm_cmdline_mode cmdline_mode;
Dave Airlied50ba252009-09-23 14:44:08 +10001381 enum drm_connector_force force;
Thomas Wood4cf2b282014-06-18 17:52:33 +01001382 bool override_edid;
Dave Airlief453ba02008-11-07 14:05:41 -08001383 uint32_t encoder_ids[DRM_CONNECTOR_MAX_ENCODER];
Dave Airlief453ba02008-11-07 14:05:41 -08001384 struct drm_encoder *encoder; /* currently active encoder */
Dave Airlie4a9a8b72011-06-14 06:13:55 +00001385
Wu Fengguang76adaa342011-09-05 14:23:20 +08001386 /* EDID bits */
1387 uint8_t eld[MAX_ELD_BYTES];
1388 bool dvi_dual;
1389 int max_tmds_clock; /* in MHz */
1390 bool latency_present[2];
1391 int video_latency[2]; /* [0]: progressive, [1]: interlaced */
1392 int audio_latency[2];
Dave Airlie4a9a8b72011-06-14 06:13:55 +00001393 int null_edid_counter; /* needed to workaround some HW bugs where we get all 0s */
Jerome Glisse0b2443e2012-08-09 11:25:51 -04001394 unsigned bad_edid_counter;
Thomas Wood30f65702014-06-18 17:52:32 +01001395
Todd Previte6ba2bd32015-04-21 11:09:41 -07001396 /* Flag for raw EDID header corruption - used in Displayport
1397 * compliance testing - * Displayport Link CTS Core 1.2 rev1.1 4.2.2.6
1398 */
1399 bool edid_corrupt;
1400
Thomas Wood30f65702014-06-18 17:52:32 +01001401 struct dentry *debugfs_entry;
Daniel Vetter144ecb92014-10-27 20:28:44 +01001402
1403 struct drm_connector_state *state;
Dave Airlie40d9b042014-10-20 16:29:33 +10001404
1405 /* DisplayID bits */
1406 bool has_tile;
1407 struct drm_tile_group *tile_group;
1408 bool tile_is_single_monitor;
1409
1410 uint8_t num_h_tile, num_v_tile;
1411 uint8_t tile_h_loc, tile_v_loc;
1412 uint16_t tile_h_size, tile_v_size;
Dave Airlief453ba02008-11-07 14:05:41 -08001413};
1414
1415/**
Daniel Vetter144ecb92014-10-27 20:28:44 +01001416 * struct drm_plane_state - mutable plane state
Daniel Vetter07cc0ef2014-11-27 15:49:39 +01001417 * @plane: backpointer to the plane
Daniel Vetter144ecb92014-10-27 20:28:44 +01001418 * @crtc: currently bound CRTC, NULL if disabled
Daniel Vettercc4ceb42014-07-25 21:30:38 +02001419 * @fb: currently bound framebuffer
Daniel Vettere2330f02014-10-29 11:34:56 +01001420 * @fence: optional fence to wait for before scanning out @fb
Daniel Vetter144ecb92014-10-27 20:28:44 +01001421 * @crtc_x: left position of visible portion of plane on crtc
1422 * @crtc_y: upper position of visible portion of plane on crtc
1423 * @crtc_w: width of visible portion of plane on crtc
1424 * @crtc_h: height of visible portion of plane on crtc
1425 * @src_x: left position of visible portion of plane within
1426 * plane (in 16.16)
1427 * @src_y: upper position of visible portion of plane within
1428 * plane (in 16.16)
1429 * @src_w: width of visible portion of plane (in 16.16)
1430 * @src_h: height of visible portion of plane (in 16.16)
Daniel Vetterac3ba4a2016-05-31 23:11:10 +02001431 * @rotation: rotation of the plane
Marek Szyprowski44d1240d2016-06-13 11:11:26 +02001432 * @zpos: priority of the given plane on crtc (optional)
1433 * @normalized_zpos: normalized value of zpos: unique, range from 0 to N-1
1434 * where N is the number of active planes for given crtc
Daniel Vetter144ecb92014-10-27 20:28:44 +01001435 * @state: backpointer to global drm_atomic_state
1436 */
1437struct drm_plane_state {
Daniel Vetter07cc0ef2014-11-27 15:49:39 +01001438 struct drm_plane *plane;
1439
Rob Clark6ddd3882014-11-21 15:28:31 -05001440 struct drm_crtc *crtc; /* do not write directly, use drm_atomic_set_crtc_for_plane() */
1441 struct drm_framebuffer *fb; /* do not write directly, use drm_atomic_set_fb_for_plane() */
Daniel Vettere2330f02014-10-29 11:34:56 +01001442 struct fence *fence;
Daniel Vetter144ecb92014-10-27 20:28:44 +01001443
1444 /* Signed dest location allows it to be partially off screen */
1445 int32_t crtc_x, crtc_y;
1446 uint32_t crtc_w, crtc_h;
1447
1448 /* Source values are 16.16 fixed point */
1449 uint32_t src_x, src_y;
1450 uint32_t src_h, src_w;
1451
Matt Roper1da30622015-01-21 16:35:40 -08001452 /* Plane rotation */
1453 unsigned int rotation;
1454
Marek Szyprowski44d1240d2016-06-13 11:11:26 +02001455 /* Plane zpos */
1456 unsigned int zpos;
1457 unsigned int normalized_zpos;
1458
Daniel Vetter144ecb92014-10-27 20:28:44 +01001459 struct drm_atomic_state *state;
1460};
1461
1462
1463/**
Daniel Vetter3bf04012014-10-27 16:54:27 +01001464 * struct drm_plane_funcs - driver plane control functions
Jesse Barnes8cf5c912011-11-14 14:51:27 -08001465 */
1466struct drm_plane_funcs {
Daniel Vetter88548632015-12-04 09:45:48 +01001467 /**
1468 * @update_plane:
1469 *
1470 * This is the legacy entry point to enable and configure the plane for
1471 * the given CRTC and framebuffer. It is never called to disable the
1472 * plane, i.e. the passed-in crtc and fb paramters are never NULL.
1473 *
1474 * The source rectangle in frame buffer memory coordinates is given by
1475 * the src_x, src_y, src_w and src_h parameters (as 16.16 fixed point
1476 * values). Devices that don't support subpixel plane coordinates can
1477 * ignore the fractional part.
1478 *
1479 * The destination rectangle in CRTC coordinates is given by the
1480 * crtc_x, crtc_y, crtc_w and crtc_h parameters (as integer values).
1481 * Devices scale the source rectangle to the destination rectangle. If
1482 * scaling is not supported, and the source rectangle size doesn't match
1483 * the destination rectangle size, the driver must return a
1484 * -<errorname>EINVAL</errorname> error.
1485 *
1486 * Drivers implementing atomic modeset should use
1487 * drm_atomic_helper_update_plane() to implement this hook.
1488 *
1489 * RETURNS:
1490 *
1491 * 0 on success or a negative error code on failure.
1492 */
Jesse Barnes8cf5c912011-11-14 14:51:27 -08001493 int (*update_plane)(struct drm_plane *plane,
1494 struct drm_crtc *crtc, struct drm_framebuffer *fb,
1495 int crtc_x, int crtc_y,
1496 unsigned int crtc_w, unsigned int crtc_h,
1497 uint32_t src_x, uint32_t src_y,
1498 uint32_t src_w, uint32_t src_h);
Daniel Vetter88548632015-12-04 09:45:48 +01001499
1500 /**
1501 * @disable_plane:
1502 *
1503 * This is the legacy entry point to disable the plane. The DRM core
Daniel Vetterc6b0ca32015-12-04 09:46:01 +01001504 * calls this method in response to a DRM_IOCTL_MODE_SETPLANE IOCTL call
Daniel Vetter88548632015-12-04 09:45:48 +01001505 * with the frame buffer ID set to 0. Disabled planes must not be
1506 * processed by the CRTC.
1507 *
1508 * Drivers implementing atomic modeset should use
1509 * drm_atomic_helper_disable_plane() to implement this hook.
1510 *
1511 * RETURNS:
1512 *
1513 * 0 on success or a negative error code on failure.
1514 */
Jesse Barnes8cf5c912011-11-14 14:51:27 -08001515 int (*disable_plane)(struct drm_plane *plane);
Daniel Vetter88548632015-12-04 09:45:48 +01001516
1517 /**
1518 * @destroy:
1519 *
1520 * Clean up plane resources. This is only called at driver unload time
1521 * through drm_mode_config_cleanup() since a plane cannot be hotplugged
1522 * in DRM.
1523 */
Jesse Barnes8cf5c912011-11-14 14:51:27 -08001524 void (*destroy)(struct drm_plane *plane);
Daniel Vetter88548632015-12-04 09:45:48 +01001525
1526 /**
1527 * @reset:
1528 *
1529 * Reset plane hardware and software state to off. This function isn't
1530 * called by the core directly, only through drm_mode_config_reset().
1531 * It's not a helper hook only for historical reasons.
1532 *
1533 * Atomic drivers can use drm_atomic_helper_plane_reset() to reset
1534 * atomic state using this hook.
1535 */
Daniel Vetter2a0d7cf2014-07-29 15:32:37 +02001536 void (*reset)(struct drm_plane *plane);
Rob Clark4d939142012-05-17 02:23:27 -06001537
Daniel Vetter88548632015-12-04 09:45:48 +01001538 /**
1539 * @set_property:
1540 *
1541 * This is the legacy entry point to update a property attached to the
1542 * plane.
1543 *
1544 * Drivers implementing atomic modeset should use
1545 * drm_atomic_helper_plane_set_property() to implement this hook.
1546 *
1547 * This callback is optional if the driver does not support any legacy
1548 * driver-private properties.
1549 *
1550 * RETURNS:
1551 *
1552 * 0 on success or a negative error code on failure.
1553 */
Rob Clark4d939142012-05-17 02:23:27 -06001554 int (*set_property)(struct drm_plane *plane,
1555 struct drm_property *property, uint64_t val);
Daniel Vetter144ecb92014-10-27 20:28:44 +01001556
Daniel Vetter88548632015-12-04 09:45:48 +01001557 /**
1558 * @atomic_duplicate_state:
1559 *
1560 * Duplicate the current atomic state for this plane and return it.
1561 * The core and helpers gurantee that any atomic state duplicated with
1562 * this hook and still owned by the caller (i.e. not transferred to the
1563 * driver by calling ->atomic_commit() from struct
1564 * &drm_mode_config_funcs) will be cleaned up by calling the
1565 * @atomic_destroy_state hook in this structure.
1566 *
1567 * Atomic drivers which don't subclass struct &drm_plane_state should use
1568 * drm_atomic_helper_plane_duplicate_state(). Drivers that subclass the
1569 * state structure to extend it with driver-private state should use
1570 * __drm_atomic_helper_plane_duplicate_state() to make sure shared state is
1571 * duplicated in a consistent fashion across drivers.
1572 *
1573 * It is an error to call this hook before plane->state has been
1574 * initialized correctly.
1575 *
1576 * NOTE:
1577 *
1578 * If the duplicate state references refcounted resources this hook must
1579 * acquire a reference for each of them. The driver must release these
1580 * references again in @atomic_destroy_state.
1581 *
1582 * RETURNS:
1583 *
1584 * Duplicated atomic state or NULL when the allocation failed.
1585 */
Daniel Vetter144ecb92014-10-27 20:28:44 +01001586 struct drm_plane_state *(*atomic_duplicate_state)(struct drm_plane *plane);
Daniel Vetter88548632015-12-04 09:45:48 +01001587
1588 /**
1589 * @atomic_destroy_state:
1590 *
1591 * Destroy a state duplicated with @atomic_duplicate_state and release
1592 * or unreference all resources it references
1593 */
Daniel Vetter144ecb92014-10-27 20:28:44 +01001594 void (*atomic_destroy_state)(struct drm_plane *plane,
Daniel Vettercc4ceb42014-07-25 21:30:38 +02001595 struct drm_plane_state *state);
Daniel Vetter88548632015-12-04 09:45:48 +01001596
1597 /**
1598 * @atomic_set_property:
1599 *
1600 * Decode a driver-private property value and store the decoded value
1601 * into the passed-in state structure. Since the atomic core decodes all
1602 * standardized properties (even for extensions beyond the core set of
1603 * properties which might not be implemented by all drivers) this
1604 * requires drivers to subclass the state structure.
1605 *
1606 * Such driver-private properties should really only be implemented for
1607 * truly hardware/vendor specific state. Instead it is preferred to
1608 * standardize atomic extension and decode the properties used to expose
1609 * such an extension in the core.
1610 *
1611 * Do not call this function directly, use
1612 * drm_atomic_plane_set_property() instead.
1613 *
1614 * This callback is optional if the driver does not support any
1615 * driver-private atomic properties.
1616 *
1617 * NOTE:
1618 *
1619 * This function is called in the state assembly phase of atomic
1620 * modesets, which can be aborted for any reason (including on
1621 * userspace's request to just check whether a configuration would be
1622 * possible). Drivers MUST NOT touch any persistent state (hardware or
1623 * software) or data structures except the passed in @state parameter.
1624 *
1625 * Also since userspace controls in which order properties are set this
1626 * function must not do any input validation (since the state update is
1627 * incomplete and hence likely inconsistent). Instead any such input
1628 * validation must be done in the various atomic_check callbacks.
1629 *
1630 * RETURNS:
1631 *
1632 * 0 if the property has been found, -EINVAL if the property isn't
1633 * implemented by the driver (which shouldn't ever happen, the core only
1634 * asks for properties attached to this plane). No other validation is
1635 * allowed by the driver. The core already checks that the property
1636 * value is within the range (integer, valid enum value, ...) the driver
1637 * set when registering the property.
1638 */
Daniel Vetter144ecb92014-10-27 20:28:44 +01001639 int (*atomic_set_property)(struct drm_plane *plane,
1640 struct drm_plane_state *state,
1641 struct drm_property *property,
1642 uint64_t val);
Daniel Vetter88548632015-12-04 09:45:48 +01001643
1644 /**
1645 * @atomic_get_property:
1646 *
1647 * Reads out the decoded driver-private property. This is used to
Daniel Vetterc6b0ca32015-12-04 09:46:01 +01001648 * implement the GETPLANE IOCTL.
Daniel Vetter88548632015-12-04 09:45:48 +01001649 *
1650 * Do not call this function directly, use
1651 * drm_atomic_plane_get_property() instead.
1652 *
1653 * This callback is optional if the driver does not support any
1654 * driver-private atomic properties.
1655 *
1656 * RETURNS:
1657 *
1658 * 0 on success, -EINVAL if the property isn't implemented by the
1659 * driver (which should never happen, the core only asks for
1660 * properties attached to this plane).
1661 */
Rob Clarkac9c9252014-12-18 16:01:47 -05001662 int (*atomic_get_property)(struct drm_plane *plane,
1663 const struct drm_plane_state *state,
1664 struct drm_property *property,
1665 uint64_t *val);
Benjamin Gaignard79190ea2016-06-21 16:37:09 +02001666 /**
1667 * @late_register:
1668 *
1669 * This optional hook can be used to register additional userspace
1670 * interfaces attached to the plane like debugfs interfaces.
1671 * It is called late in the driver load sequence from drm_dev_register().
1672 * Everything added from this callback should be unregistered in
1673 * the early_unregister callback.
1674 *
1675 * Returns:
1676 *
1677 * 0 on success, or a negative error code on failure.
1678 */
1679 int (*late_register)(struct drm_plane *plane);
1680
1681 /**
1682 * @early_unregister:
1683 *
1684 * This optional hook should be used to unregister the additional
1685 * userspace interfaces attached to the plane from
1686 * late_unregister(). It is called from drm_dev_unregister(),
1687 * early in the driver unload sequence to disable userspace access
1688 * before data structures are torndown.
1689 */
1690 void (*early_unregister)(struct drm_plane *plane);
Jesse Barnes8cf5c912011-11-14 14:51:27 -08001691};
1692
Matt Ropere27dde32014-04-01 15:22:30 -07001693enum drm_plane_type {
1694 DRM_PLANE_TYPE_OVERLAY,
1695 DRM_PLANE_TYPE_PRIMARY,
1696 DRM_PLANE_TYPE_CURSOR,
1697};
1698
Daniel Vetter88548632015-12-04 09:45:48 +01001699
Jesse Barnes8cf5c912011-11-14 14:51:27 -08001700/**
Daniel Vetter3bf04012014-10-27 16:54:27 +01001701 * struct drm_plane - central DRM plane control structure
Jesse Barnes8cf5c912011-11-14 14:51:27 -08001702 * @dev: DRM device this plane belongs to
1703 * @head: for list management
Daniel Vetterac3ba4a2016-05-31 23:11:10 +02001704 * @name: human readable name, can be overwritten by the driver
Jesse Barnes8cf5c912011-11-14 14:51:27 -08001705 * @base: base mode object
1706 * @possible_crtcs: pipes this plane can be bound to
1707 * @format_types: array of formats supported by this plane
1708 * @format_count: number of formats supported
Laurent Pinchart7eb5f302015-03-09 10:41:07 +02001709 * @format_default: driver hasn't supplied supported formats for the plane
Jesse Barnes8cf5c912011-11-14 14:51:27 -08001710 * @crtc: currently bound CRTC
1711 * @fb: currently bound fb
Daniel Vetter2c0c33d2014-10-27 20:19:38 +01001712 * @old_fb: Temporary tracking of the old fb while a modeset is ongoing. Used by
1713 * drm_mode_set_config_internal() to implement correct refcounting.
Jesse Barnes8cf5c912011-11-14 14:51:27 -08001714 * @funcs: helper functions
Rob Clark4d939142012-05-17 02:23:27 -06001715 * @properties: property tracking for this plane
Matt Ropere27dde32014-04-01 15:22:30 -07001716 * @type: type of plane (overlay, primary, cursor)
Daniel Vetter144ecb92014-10-27 20:28:44 +01001717 * @state: current atomic state for this plane
Marek Szyprowski44d1240d2016-06-13 11:11:26 +02001718 * @zpos_property: zpos property for this plane
Daniel Vetterac3ba4a2016-05-31 23:11:10 +02001719 * @helper_private: mid-layer private data
Jesse Barnes8cf5c912011-11-14 14:51:27 -08001720 */
1721struct drm_plane {
1722 struct drm_device *dev;
1723 struct list_head head;
1724
Ville Syrjälä9f4c97a2015-12-08 18:41:54 +02001725 char *name;
1726
Daniel Vetterac3ba4a2016-05-31 23:11:10 +02001727 /**
1728 * @mutex:
1729 *
1730 * Protects modeset plane state, together with the mutex of &drm_crtc
1731 * this plane is linked to (when active, getting actived or getting
1732 * disabled).
1733 */
Daniel Vetter4d02e2d2014-11-11 10:12:00 +01001734 struct drm_modeset_lock mutex;
1735
Jesse Barnes8cf5c912011-11-14 14:51:27 -08001736 struct drm_mode_object base;
1737
1738 uint32_t possible_crtcs;
1739 uint32_t *format_types;
Thierry Reding45e37432015-08-12 16:54:28 +02001740 unsigned int format_count;
Laurent Pinchart7eb5f302015-03-09 10:41:07 +02001741 bool format_default;
Jesse Barnes8cf5c912011-11-14 14:51:27 -08001742
1743 struct drm_crtc *crtc;
1744 struct drm_framebuffer *fb;
1745
Daniel Vetter3d30a592014-07-27 13:42:42 +02001746 struct drm_framebuffer *old_fb;
1747
Jesse Barnes8cf5c912011-11-14 14:51:27 -08001748 const struct drm_plane_funcs *funcs;
Rob Clark4d939142012-05-17 02:23:27 -06001749
1750 struct drm_object_properties properties;
Matt Ropere27dde32014-04-01 15:22:30 -07001751
1752 enum drm_plane_type type;
Daniel Vetter144ecb92014-10-27 20:28:44 +01001753
Daniel Vetter96094082016-07-15 21:47:59 +02001754 /**
1755 * @index: Position inside the mode_config.list, can be used as an array
1756 * index. It is invariant over the lifetime of the plane.
1757 */
Chris Wilson490d3d12016-05-27 20:05:00 +01001758 unsigned index;
1759
Daniel Vetter4490d4c2015-12-04 09:45:45 +01001760 const struct drm_plane_helper_funcs *helper_private;
Daniel Vetterc2fcd272014-11-05 00:14:14 +01001761
Daniel Vetter144ecb92014-10-27 20:28:44 +01001762 struct drm_plane_state *state;
Marek Szyprowski44d1240d2016-06-13 11:11:26 +02001763
1764 struct drm_property *zpos_property;
Jesse Barnes8cf5c912011-11-14 14:51:27 -08001765};
1766
1767/**
Daniel Vetter3bf04012014-10-27 16:54:27 +01001768 * struct drm_bridge_funcs - drm_bridge control functions
Ajay Kumar3d3f8b12015-01-20 22:08:44 +05301769 * @attach: Called during drm_bridge_attach
Sean Paul3b336ec2013-08-14 16:47:37 -04001770 */
1771struct drm_bridge_funcs {
Ajay Kumar3d3f8b12015-01-20 22:08:44 +05301772 int (*attach)(struct drm_bridge *bridge);
Daniel Vetterda024fe2015-12-04 09:45:47 +01001773
1774 /**
1775 * @mode_fixup:
1776 *
1777 * This callback is used to validate and adjust a mode. The paramater
1778 * mode is the display mode that should be fed to the next element in
1779 * the display chain, either the final &drm_connector or the next
1780 * &drm_bridge. The parameter adjusted_mode is the input mode the bridge
1781 * requires. It can be modified by this callback and does not need to
1782 * match mode.
1783 *
1784 * This is the only hook that allows a bridge to reject a modeset. If
1785 * this function passes all other callbacks must succeed for this
1786 * configuration.
1787 *
1788 * NOTE:
1789 *
1790 * This function is called in the check phase of atomic modesets, which
1791 * can be aborted for any reason (including on userspace's request to
1792 * just check whether a configuration would be possible). Drivers MUST
1793 * NOT touch any persistent state (hardware or software) or data
Daniel Vetter88548632015-12-04 09:45:48 +01001794 * structures except the passed in @state parameter.
Daniel Vetterda024fe2015-12-04 09:45:47 +01001795 *
1796 * RETURNS:
1797 *
1798 * True if an acceptable configuration is possible, false if the modeset
1799 * operation should be rejected.
1800 */
Sean Paul3b336ec2013-08-14 16:47:37 -04001801 bool (*mode_fixup)(struct drm_bridge *bridge,
1802 const struct drm_display_mode *mode,
1803 struct drm_display_mode *adjusted_mode);
Daniel Vetterda024fe2015-12-04 09:45:47 +01001804 /**
1805 * @disable:
1806 *
1807 * This callback should disable the bridge. It is called right before
1808 * the preceding element in the display pipe is disabled. If the
1809 * preceding element is a bridge this means it's called before that
1810 * bridge's ->disable() function. If the preceding element is a
1811 * &drm_encoder it's called right before the encoder's ->disable(),
1812 * ->prepare() or ->dpms() hook from struct &drm_encoder_helper_funcs.
1813 *
1814 * The bridge can assume that the display pipe (i.e. clocks and timing
1815 * signals) feeding it is still running when this callback is called.
Laurent Pinchartc8a3b2a2016-02-26 11:51:06 +02001816 *
1817 * The disable callback is optional.
Daniel Vetterda024fe2015-12-04 09:45:47 +01001818 */
Sean Paul3b336ec2013-08-14 16:47:37 -04001819 void (*disable)(struct drm_bridge *bridge);
Daniel Vetterda024fe2015-12-04 09:45:47 +01001820
1821 /**
1822 * @post_disable:
1823 *
1824 * This callback should disable the bridge. It is called right after
1825 * the preceding element in the display pipe is disabled. If the
1826 * preceding element is a bridge this means it's called after that
1827 * bridge's ->post_disable() function. If the preceding element is a
1828 * &drm_encoder it's called right after the encoder's ->disable(),
1829 * ->prepare() or ->dpms() hook from struct &drm_encoder_helper_funcs.
1830 *
1831 * The bridge must assume that the display pipe (i.e. clocks and timing
1832 * singals) feeding it is no longer running when this callback is
1833 * called.
Laurent Pinchartc8a3b2a2016-02-26 11:51:06 +02001834 *
1835 * The post_disable callback is optional.
Daniel Vetterda024fe2015-12-04 09:45:47 +01001836 */
Sean Paul3b336ec2013-08-14 16:47:37 -04001837 void (*post_disable)(struct drm_bridge *bridge);
Daniel Vetterda024fe2015-12-04 09:45:47 +01001838
1839 /**
1840 * @mode_set:
1841 *
1842 * This callback should set the given mode on the bridge. It is called
1843 * after the ->mode_set() callback for the preceding element in the
1844 * display pipeline has been called already. The display pipe (i.e.
1845 * clocks and timing signals) is off when this function is called.
1846 */
Sean Paul3b336ec2013-08-14 16:47:37 -04001847 void (*mode_set)(struct drm_bridge *bridge,
1848 struct drm_display_mode *mode,
1849 struct drm_display_mode *adjusted_mode);
Daniel Vetterda024fe2015-12-04 09:45:47 +01001850 /**
1851 * @pre_enable:
1852 *
1853 * This callback should enable the bridge. It is called right before
1854 * the preceding element in the display pipe is enabled. If the
1855 * preceding element is a bridge this means it's called before that
1856 * bridge's ->pre_enable() function. If the preceding element is a
1857 * &drm_encoder it's called right before the encoder's ->enable(),
1858 * ->commit() or ->dpms() hook from struct &drm_encoder_helper_funcs.
1859 *
1860 * The display pipe (i.e. clocks and timing signals) feeding this bridge
1861 * will not yet be running when this callback is called. The bridge must
1862 * not enable the display link feeding the next bridge in the chain (if
1863 * there is one) when this callback is called.
Laurent Pinchartc8a3b2a2016-02-26 11:51:06 +02001864 *
1865 * The pre_enable callback is optional.
Daniel Vetterda024fe2015-12-04 09:45:47 +01001866 */
Sean Paul3b336ec2013-08-14 16:47:37 -04001867 void (*pre_enable)(struct drm_bridge *bridge);
Daniel Vetterda024fe2015-12-04 09:45:47 +01001868
1869 /**
1870 * @enable:
1871 *
1872 * This callback should enable the bridge. It is called right after
1873 * the preceding element in the display pipe is enabled. If the
1874 * preceding element is a bridge this means it's called after that
1875 * bridge's ->enable() function. If the preceding element is a
1876 * &drm_encoder it's called right after the encoder's ->enable(),
1877 * ->commit() or ->dpms() hook from struct &drm_encoder_helper_funcs.
1878 *
1879 * The bridge can assume that the display pipe (i.e. clocks and timing
1880 * signals) feeding it is running when this callback is called. This
1881 * callback must enable the display link feeding the next bridge in the
1882 * chain if there is one.
Laurent Pinchartc8a3b2a2016-02-26 11:51:06 +02001883 *
1884 * The enable callback is optional.
Daniel Vetterda024fe2015-12-04 09:45:47 +01001885 */
Sean Paul3b336ec2013-08-14 16:47:37 -04001886 void (*enable)(struct drm_bridge *bridge);
Sean Paul3b336ec2013-08-14 16:47:37 -04001887};
1888
1889/**
Daniel Vetter3bf04012014-10-27 16:54:27 +01001890 * struct drm_bridge - central DRM bridge control structure
Sean Paul3b336ec2013-08-14 16:47:37 -04001891 * @dev: DRM device this bridge belongs to
Archit Taneja862e6862015-05-21 11:03:16 +05301892 * @encoder: encoder to which this bridge is connected
1893 * @next: the next bridge in the encoder chain
Ajay Kumar3d3f8b12015-01-20 22:08:44 +05301894 * @of_node: device node pointer to the bridge
1895 * @list: to keep track of all added bridges
Sean Paul3b336ec2013-08-14 16:47:37 -04001896 * @funcs: control functions
1897 * @driver_private: pointer to the bridge driver's internal context
1898 */
1899struct drm_bridge {
1900 struct drm_device *dev;
Ajay Kumar3d3f8b12015-01-20 22:08:44 +05301901 struct drm_encoder *encoder;
Archit Taneja862e6862015-05-21 11:03:16 +05301902 struct drm_bridge *next;
Ajay Kumar3d3f8b12015-01-20 22:08:44 +05301903#ifdef CONFIG_OF
1904 struct device_node *of_node;
1905#endif
1906 struct list_head list;
Sean Paul3b336ec2013-08-14 16:47:37 -04001907
1908 const struct drm_bridge_funcs *funcs;
1909 void *driver_private;
1910};
1911
Daniel Vetter3b24f7d2016-06-08 14:19:00 +02001912/**
1913 * struct drm_crtc_commit - track modeset commits on a CRTC
1914 *
1915 * This structure is used to track pending modeset changes and atomic commit on
1916 * a per-CRTC basis. Since updating the list should never block this structure
1917 * is reference counted to allow waiters to safely wait on an event to complete,
1918 * without holding any locks.
1919 *
1920 * It has 3 different events in total to allow a fine-grained synchronization
1921 * between outstanding updates::
1922 *
1923 * atomic commit thread hardware
1924 *
1925 * write new state into hardware ----> ...
1926 * signal hw_done
1927 * switch to new state on next
1928 * ... v/hblank
1929 *
1930 * wait for buffers to show up ...
1931 *
1932 * ... send completion irq
1933 * irq handler signals flip_done
1934 * cleanup old buffers
1935 *
1936 * signal cleanup_done
1937 *
1938 * wait for flip_done <----
1939 * clean up atomic state
1940 *
1941 * The important bit to know is that cleanup_done is the terminal event, but the
1942 * ordering between flip_done and hw_done is entirely up to the specific driver
1943 * and modeset state change.
1944 *
1945 * For an implementation of how to use this look at
1946 * drm_atomic_helper_setup_commit() from the atomic helper library.
1947 */
1948struct drm_crtc_commit {
1949 /**
1950 * @crtc:
1951 *
1952 * DRM CRTC for this commit.
1953 */
1954 struct drm_crtc *crtc;
1955
1956 /**
1957 * @ref:
1958 *
1959 * Reference count for this structure. Needed to allow blocking on
1960 * completions without the risk of the completion disappearing
1961 * meanwhile.
1962 */
1963 struct kref ref;
1964
1965 /**
1966 * @flip_done:
1967 *
1968 * Will be signaled when the hardware has flipped to the new set of
1969 * buffers. Signals at the same time as when the drm event for this
1970 * commit is sent to userspace, or when an out-fence is singalled. Note
1971 * that for most hardware, in most cases this happens after @hw_done is
1972 * signalled.
1973 */
1974 struct completion flip_done;
1975
1976 /**
1977 * @hw_done:
1978 *
1979 * Will be signalled when all hw register changes for this commit have
1980 * been written out. Especially when disabling a pipe this can be much
1981 * later than than @flip_done, since that can signal already when the
1982 * screen goes black, whereas to fully shut down a pipe more register
1983 * I/O is required.
1984 *
1985 * Note that this does not need to include separately reference-counted
1986 * resources like backing storage buffer pinning, or runtime pm
1987 * management.
1988 */
1989 struct completion hw_done;
1990
1991 /**
1992 * @cleanup_done:
1993 *
1994 * Will be signalled after old buffers have been cleaned up by calling
1995 * drm_atomic_helper_cleanup_planes(). Since this can only happen after
1996 * a vblank wait completed it might be a bit later. This completion is
1997 * useful to throttle updates and avoid hardware updates getting ahead
1998 * of the buffer cleanup too much.
1999 */
2000 struct completion cleanup_done;
2001
2002 /**
2003 * @commit_entry:
2004 *
2005 * Entry on the per-CRTC commit_list. Protected by crtc->commit_lock.
2006 */
2007 struct list_head commit_entry;
2008
2009 /**
2010 * @event:
2011 *
2012 * &drm_pending_vblank_event pointer to clean up private events.
2013 */
2014 struct drm_pending_vblank_event *event;
2015};
2016
Daniel Vetterb8b53422016-06-02 00:06:33 +02002017struct __drm_planes_state {
2018 struct drm_plane *ptr;
2019 struct drm_plane_state *state;
2020};
2021
Daniel Vetter5d943aa62016-06-02 00:06:34 +02002022struct __drm_crtcs_state {
2023 struct drm_crtc *ptr;
2024 struct drm_crtc_state *state;
Daniel Vetter3b24f7d2016-06-08 14:19:00 +02002025 struct drm_crtc_commit *commit;
Daniel Vetter5d943aa62016-06-02 00:06:34 +02002026};
2027
Daniel Vetter63e83c12016-06-02 00:06:32 +02002028struct __drm_connnectors_state {
2029 struct drm_connector *ptr;
2030 struct drm_connector_state *state;
2031};
2032
Sean Paul3b336ec2013-08-14 16:47:37 -04002033/**
Rob Clark08855fa2015-03-11 10:23:09 -04002034 * struct drm_atomic_state - the global state object for atomic updates
Daniel Vettercc4ceb42014-07-25 21:30:38 +02002035 * @dev: parent DRM device
Rob Clarkd34f20d2014-12-18 16:01:56 -05002036 * @allow_modeset: allow full modeset
Daniel Vetterc6b0ca32015-12-04 09:46:01 +01002037 * @legacy_cursor_update: hint to enforce legacy cursor IOCTL semantics
Maarten Lankhorst40616a22016-03-03 10:17:39 +01002038 * @legacy_set_config: Disable conflicting encoders instead of failing with -EINVAL.
Daniel Vetterb8b53422016-06-02 00:06:33 +02002039 * @planes: pointer to array of structures with per-plane data
Daniel Vettercc4ceb42014-07-25 21:30:38 +02002040 * @crtcs: pointer to array of CRTC pointers
Daniel Vetterf52b69f12014-11-19 18:38:08 +01002041 * @num_connector: size of the @connectors and @connector_states arrays
Daniel Vetter63e83c12016-06-02 00:06:32 +02002042 * @connectors: pointer to array of structures with per-connector data
Daniel Vettercc4ceb42014-07-25 21:30:38 +02002043 * @acquire_ctx: acquire context for this atomic modeset state update
2044 */
2045struct drm_atomic_state {
2046 struct drm_device *dev;
Rob Clarkd34f20d2014-12-18 16:01:56 -05002047 bool allow_modeset : 1;
Daniel Vetterf02ad902015-01-22 16:36:23 +01002048 bool legacy_cursor_update : 1;
Maarten Lankhorst40616a22016-03-03 10:17:39 +01002049 bool legacy_set_config : 1;
Daniel Vetterb8b53422016-06-02 00:06:33 +02002050 struct __drm_planes_state *planes;
Daniel Vetter5d943aa62016-06-02 00:06:34 +02002051 struct __drm_crtcs_state *crtcs;
Daniel Vetterf52b69f12014-11-19 18:38:08 +01002052 int num_connector;
Daniel Vetter63e83c12016-06-02 00:06:32 +02002053 struct __drm_connnectors_state *connectors;
Daniel Vettercc4ceb42014-07-25 21:30:38 +02002054
2055 struct drm_modeset_acquire_ctx *acquire_ctx;
Daniel Vetter3b24f7d2016-06-08 14:19:00 +02002056
2057 /**
2058 * @commit_work:
2059 *
2060 * Work item which can be used by the driver or helpers to execute the
2061 * commit without blocking.
2062 */
2063 struct work_struct commit_work;
Daniel Vettercc4ceb42014-07-25 21:30:38 +02002064};
2065
2066
2067/**
Daniel Vetter3bf04012014-10-27 16:54:27 +01002068 * struct drm_mode_set - new values for a CRTC config change
Jesse Barnesef273512011-11-07 12:03:19 -08002069 * @fb: framebuffer to use for new config
2070 * @crtc: CRTC whose configuration we're about to change
2071 * @mode: mode timings to use
2072 * @x: position of this CRTC relative to @fb
2073 * @y: position of this CRTC relative to @fb
2074 * @connectors: array of connectors to drive with this CRTC if possible
2075 * @num_connectors: size of @connectors array
Dave Airlief453ba02008-11-07 14:05:41 -08002076 *
2077 * Represents a single crtc the connectors that it drives with what mode
2078 * and from which framebuffer it scans out from.
2079 *
2080 * This is used to set modes.
2081 */
2082struct drm_mode_set {
Dave Airlief453ba02008-11-07 14:05:41 -08002083 struct drm_framebuffer *fb;
2084 struct drm_crtc *crtc;
2085 struct drm_display_mode *mode;
2086
2087 uint32_t x;
2088 uint32_t y;
2089
2090 struct drm_connector **connectors;
2091 size_t num_connectors;
2092};
2093
2094/**
Jesse Barnes550cebc2011-11-07 12:03:20 -08002095 * struct drm_mode_config_funcs - basic driver provided mode setting functions
Jesse Barnes550cebc2011-11-07 12:03:20 -08002096 *
2097 * Some global (i.e. not per-CRTC, connector, etc) mode setting functions that
2098 * involve drivers.
Dave Airlief453ba02008-11-07 14:05:41 -08002099 */
2100struct drm_mode_config_funcs {
Daniel Vetter9953f412015-12-04 09:46:02 +01002101 /**
2102 * @fb_create:
2103 *
2104 * Create a new framebuffer object. The core does basic checks on the
2105 * requested metadata, but most of that is left to the driver. See
2106 * struct &drm_mode_fb_cmd2 for details.
2107 *
Daniel Vetterd55f5322015-12-08 09:49:19 +01002108 * If the parameters are deemed valid and the backing storage objects in
2109 * the underlying memory manager all exist, then the driver allocates
2110 * a new &drm_framebuffer structure, subclassed to contain
2111 * driver-specific information (like the internal native buffer object
2112 * references). It also needs to fill out all relevant metadata, which
2113 * should be done by calling drm_helper_mode_fill_fb_struct().
2114 *
2115 * The initialization is finalized by calling drm_framebuffer_init(),
2116 * which registers the framebuffer and makes it accessible to other
2117 * threads.
2118 *
Daniel Vetter9953f412015-12-04 09:46:02 +01002119 * RETURNS:
2120 *
2121 * A new framebuffer with an initial reference count of 1 or a negative
2122 * error code encoded with ERR_PTR().
2123 */
Jesse Barnes550cebc2011-11-07 12:03:20 -08002124 struct drm_framebuffer *(*fb_create)(struct drm_device *dev,
2125 struct drm_file *file_priv,
Ville Syrjälä1eb834512015-11-11 19:11:29 +02002126 const struct drm_mode_fb_cmd2 *mode_cmd);
Daniel Vetter9953f412015-12-04 09:46:02 +01002127
2128 /**
2129 * @output_poll_changed:
2130 *
2131 * Callback used by helpers to inform the driver of output configuration
2132 * changes.
2133 *
2134 * Drivers implementing fbdev emulation with the helpers can call
2135 * drm_fb_helper_hotplug_changed from this hook to inform the fbdev
2136 * helper of output changes.
2137 *
2138 * FIXME:
2139 *
2140 * Except that there's no vtable for device-level helper callbacks
2141 * there's no reason this is a core function.
2142 */
Dave Airlieeb1f8e4f32010-05-07 06:42:51 +00002143 void (*output_poll_changed)(struct drm_device *dev);
Daniel Vettercc4ceb42014-07-25 21:30:38 +02002144
Daniel Vetter9953f412015-12-04 09:46:02 +01002145 /**
2146 * @atomic_check:
2147 *
2148 * This is the only hook to validate an atomic modeset update. This
2149 * function must reject any modeset and state changes which the hardware
2150 * or driver doesn't support. This includes but is of course not limited
2151 * to:
2152 *
2153 * - Checking that the modes, framebuffers, scaling and placement
2154 * requirements and so on are within the limits of the hardware.
2155 *
2156 * - Checking that any hidden shared resources are not oversubscribed.
2157 * This can be shared PLLs, shared lanes, overall memory bandwidth,
2158 * display fifo space (where shared between planes or maybe even
2159 * CRTCs).
2160 *
2161 * - Checking that virtualized resources exported to userspace are not
2162 * oversubscribed. For various reasons it can make sense to expose
2163 * more planes, crtcs or encoders than which are physically there. One
2164 * example is dual-pipe operations (which generally should be hidden
2165 * from userspace if when lockstepped in hardware, exposed otherwise),
2166 * where a plane might need 1 hardware plane (if it's just on one
2167 * pipe), 2 hardware planes (when it spans both pipes) or maybe even
2168 * shared a hardware plane with a 2nd plane (if there's a compatible
2169 * plane requested on the area handled by the other pipe).
2170 *
2171 * - Check that any transitional state is possible and that if
2172 * requested, the update can indeed be done in the vblank period
2173 * without temporarily disabling some functions.
2174 *
2175 * - Check any other constraints the driver or hardware might have.
2176 *
2177 * - This callback also needs to correctly fill out the &drm_crtc_state
2178 * in this update to make sure that drm_atomic_crtc_needs_modeset()
2179 * reflects the nature of the possible update and returns true if and
2180 * only if the update cannot be applied without tearing within one
2181 * vblank on that CRTC. The core uses that information to reject
2182 * updates which require a full modeset (i.e. blanking the screen, or
2183 * at least pausing updates for a substantial amount of time) if
2184 * userspace has disallowed that in its request.
2185 *
2186 * - The driver also does not need to repeat basic input validation
2187 * like done for the corresponding legacy entry points. The core does
2188 * that before calling this hook.
2189 *
2190 * See the documentation of @atomic_commit for an exhaustive list of
2191 * error conditions which don't have to be checked at the
2192 * ->atomic_check() stage?
2193 *
2194 * See the documentation for struct &drm_atomic_state for how exactly
2195 * an atomic modeset update is described.
2196 *
2197 * Drivers using the atomic helpers can implement this hook using
2198 * drm_atomic_helper_check(), or one of the exported sub-functions of
2199 * it.
2200 *
2201 * RETURNS:
2202 *
2203 * 0 on success or one of the below negative error codes:
2204 *
2205 * - -EINVAL, if any of the above constraints are violated.
2206 *
2207 * - -EDEADLK, when returned from an attempt to acquire an additional
2208 * &drm_modeset_lock through drm_modeset_lock().
2209 *
2210 * - -ENOMEM, if allocating additional state sub-structures failed due
2211 * to lack of memory.
2212 *
2213 * - -EINTR, -EAGAIN or -ERESTARTSYS, if the IOCTL should be restarted.
2214 * This can either be due to a pending signal, or because the driver
2215 * needs to completely bail out to recover from an exceptional
2216 * situation like a GPU hang. From a userspace point all errors are
2217 * treated equally.
2218 */
Daniel Vettercc4ceb42014-07-25 21:30:38 +02002219 int (*atomic_check)(struct drm_device *dev,
Daniel Vetter9953f412015-12-04 09:46:02 +01002220 struct drm_atomic_state *state);
2221
2222 /**
2223 * @atomic_commit:
2224 *
2225 * This is the only hook to commit an atomic modeset update. The core
2226 * guarantees that @atomic_check has been called successfully before
2227 * calling this function, and that nothing has been changed in the
2228 * interim.
2229 *
2230 * See the documentation for struct &drm_atomic_state for how exactly
2231 * an atomic modeset update is described.
2232 *
2233 * Drivers using the atomic helpers can implement this hook using
2234 * drm_atomic_helper_commit(), or one of the exported sub-functions of
2235 * it.
2236 *
Maarten Lankhorst286dbb82016-04-26 16:11:34 +02002237 * Nonblocking commits (as indicated with the nonblock parameter) must
Daniel Vetter9953f412015-12-04 09:46:02 +01002238 * do any preparatory work which might result in an unsuccessful commit
2239 * in the context of this callback. The only exceptions are hardware
2240 * errors resulting in -EIO. But even in that case the driver must
2241 * ensure that the display pipe is at least running, to avoid
2242 * compositors crashing when pageflips don't work. Anything else,
2243 * specifically committing the update to the hardware, should be done
2244 * without blocking the caller. For updates which do not require a
2245 * modeset this must be guaranteed.
2246 *
2247 * The driver must wait for any pending rendering to the new
2248 * framebuffers to complete before executing the flip. It should also
2249 * wait for any pending rendering from other drivers if the underlying
Maarten Lankhorst286dbb82016-04-26 16:11:34 +02002250 * buffer is a shared dma-buf. Nonblocking commits must not wait for
Daniel Vetter9953f412015-12-04 09:46:02 +01002251 * rendering in the context of this callback.
2252 *
2253 * An application can request to be notified when the atomic commit has
2254 * completed. These events are per-CRTC and can be distinguished by the
2255 * CRTC index supplied in &drm_event to userspace.
2256 *
2257 * The drm core will supply a struct &drm_event in the event
2258 * member of each CRTC's &drm_crtc_state structure. This can be handled by the
2259 * drm_crtc_send_vblank_event() function, which the driver should call on
2260 * the provided event upon completion of the atomic commit. Note that if
2261 * the driver supports vblank signalling and timestamping the vblank
2262 * counters and timestamps must agree with the ones returned from page
2263 * flip events. With the current vblank helper infrastructure this can
2264 * be achieved by holding a vblank reference while the page flip is
2265 * pending, acquired through drm_crtc_vblank_get() and released with
2266 * drm_crtc_vblank_put(). Drivers are free to implement their own vblank
2267 * counter and timestamp tracking though, e.g. if they have accurate
2268 * timestamp registers in hardware.
2269 *
2270 * NOTE:
2271 *
2272 * Drivers are not allowed to shut down any display pipe successfully
2273 * enabled through an atomic commit on their own. Doing so can result in
2274 * compositors crashing if a page flip is suddenly rejected because the
2275 * pipe is off.
2276 *
2277 * RETURNS:
2278 *
2279 * 0 on success or one of the below negative error codes:
2280 *
Maarten Lankhorst286dbb82016-04-26 16:11:34 +02002281 * - -EBUSY, if a nonblocking updated is requested and there is
Daniel Vetter9953f412015-12-04 09:46:02 +01002282 * an earlier updated pending. Drivers are allowed to support a queue
2283 * of outstanding updates, but currently no driver supports that.
2284 * Note that drivers must wait for preceding updates to complete if a
2285 * synchronous update is requested, they are not allowed to fail the
2286 * commit in that case.
2287 *
2288 * - -ENOMEM, if the driver failed to allocate memory. Specifically
2289 * this can happen when trying to pin framebuffers, which must only
2290 * be done when committing the state.
2291 *
2292 * - -ENOSPC, as a refinement of the more generic -ENOMEM to indicate
2293 * that the driver has run out of vram, iommu space or similar GPU
2294 * address space needed for framebuffer.
2295 *
2296 * - -EIO, if the hardware completely died.
2297 *
2298 * - -EINTR, -EAGAIN or -ERESTARTSYS, if the IOCTL should be restarted.
2299 * This can either be due to a pending signal, or because the driver
2300 * needs to completely bail out to recover from an exceptional
2301 * situation like a GPU hang. From a userspace point of view all errors are
2302 * treated equally.
2303 *
2304 * This list is exhaustive. Specifically this hook is not allowed to
2305 * return -EINVAL (any invalid requests should be caught in
2306 * @atomic_check) or -EDEADLK (this function must not acquire
2307 * additional modeset locks).
2308 */
Daniel Vettercc4ceb42014-07-25 21:30:38 +02002309 int (*atomic_commit)(struct drm_device *dev,
Daniel Vetter9953f412015-12-04 09:46:02 +01002310 struct drm_atomic_state *state,
Maarten Lankhorst286dbb82016-04-26 16:11:34 +02002311 bool nonblock);
Daniel Vetter9953f412015-12-04 09:46:02 +01002312
2313 /**
2314 * @atomic_state_alloc:
2315 *
2316 * This optional hook can be used by drivers that want to subclass struct
2317 * &drm_atomic_state to be able to track their own driver-private global
2318 * state easily. If this hook is implemented, drivers must also
2319 * implement @atomic_state_clear and @atomic_state_free.
2320 *
2321 * RETURNS:
2322 *
2323 * A new &drm_atomic_state on success or NULL on failure.
2324 */
Maarten Lankhorst036ef572015-05-18 10:06:40 +02002325 struct drm_atomic_state *(*atomic_state_alloc)(struct drm_device *dev);
Daniel Vetter9953f412015-12-04 09:46:02 +01002326
2327 /**
2328 * @atomic_state_clear:
2329 *
2330 * This hook must clear any driver private state duplicated into the
2331 * passed-in &drm_atomic_state. This hook is called when the caller
2332 * encountered a &drm_modeset_lock deadlock and needs to drop all
2333 * already acquired locks as part of the deadlock avoidance dance
2334 * implemented in drm_modeset_lock_backoff().
2335 *
2336 * Any duplicated state must be invalidated since a concurrent atomic
2337 * update might change it, and the drm atomic interfaces always apply
2338 * updates as relative changes to the current state.
2339 *
2340 * Drivers that implement this must call drm_atomic_state_default_clear()
2341 * to clear common state.
2342 */
Maarten Lankhorst036ef572015-05-18 10:06:40 +02002343 void (*atomic_state_clear)(struct drm_atomic_state *state);
Daniel Vetter9953f412015-12-04 09:46:02 +01002344
2345 /**
2346 * @atomic_state_free:
2347 *
2348 * This hook needs driver private resources and the &drm_atomic_state
2349 * itself. Note that the core first calls drm_atomic_state_clear() to
2350 * avoid code duplicate between the clear and free hooks.
2351 *
2352 * Drivers that implement this must call drm_atomic_state_default_free()
2353 * to release common resources.
2354 */
Maarten Lankhorst036ef572015-05-18 10:06:40 +02002355 void (*atomic_state_free)(struct drm_atomic_state *state);
Dave Airlief453ba02008-11-07 14:05:41 -08002356};
2357
Jesse Barnesc1aaca22011-11-07 12:03:21 -08002358/**
Daniel Vetter2c0c33d2014-10-27 20:19:38 +01002359 * struct drm_mode_config - Mode configuration control structure
Jesse Barnesa62c93d2011-11-07 12:03:22 -08002360 * @mutex: mutex protecting KMS related lists and structures
Daniel Vetter2c0c33d2014-10-27 20:19:38 +01002361 * @connection_mutex: ww mutex protecting connector state and routing
2362 * @acquire_ctx: global implicit acquire context used by atomic drivers for
Daniel Vetterc6b0ca32015-12-04 09:46:01 +01002363 * legacy IOCTLs
Daniel Vetter2c0c33d2014-10-27 20:19:38 +01002364 * @fb_lock: mutex to protect fb state and lists
Jesse Barnesa62c93d2011-11-07 12:03:22 -08002365 * @num_fb: number of fbs available
2366 * @fb_list: list of framebuffers available
Jesse Barnesa62c93d2011-11-07 12:03:22 -08002367 * @num_encoder: number of encoders on this device
2368 * @encoder_list: list of encoder objects
Daniel Vetter2c0c33d2014-10-27 20:19:38 +01002369 * @num_overlay_plane: number of overlay planes on this device
2370 * @num_total_plane: number of universal (i.e. with primary/curso) planes on this device
2371 * @plane_list: list of plane objects
Jesse Barnesa62c93d2011-11-07 12:03:22 -08002372 * @num_crtc: number of CRTCs on this device
2373 * @crtc_list: list of CRTC objects
Daniel Vetter2c0c33d2014-10-27 20:19:38 +01002374 * @property_list: list of property objects
Jesse Barnesa62c93d2011-11-07 12:03:22 -08002375 * @min_width: minimum pixel width on this device
2376 * @min_height: minimum pixel height on this device
2377 * @max_width: maximum pixel width on this device
2378 * @max_height: maximum pixel height on this device
2379 * @funcs: core driver provided mode setting functions
2380 * @fb_base: base address of the framebuffer
Daniel Vetter2c0c33d2014-10-27 20:19:38 +01002381 * @poll_enabled: track polling support for this device
2382 * @poll_running: track polling status for this device
Daniel Vetterac3ba4a2016-05-31 23:11:10 +02002383 * @delayed_event: track delayed poll uevent deliver for this device
Jesse Barnesa62c93d2011-11-07 12:03:22 -08002384 * @output_poll_work: delayed work for polling in process context
Daniel Vetter2c0c33d2014-10-27 20:19:38 +01002385 * @property_blob_list: list of all the blob property objects
Daniel Stone8fb6e7a2015-04-20 19:22:54 +01002386 * @blob_lock: mutex for blob property allocation and management
Jesse Barnesa62c93d2011-11-07 12:03:22 -08002387 * @*_property: core property tracking
Daniel Vetter2c0c33d2014-10-27 20:19:38 +01002388 * @preferred_depth: preferred RBG pixel depth, used by fb helpers
2389 * @prefer_shadow: hint to userspace to prefer shadow-fb rendering
Daniel Vetter2c0c33d2014-10-27 20:19:38 +01002390 * @cursor_width: hint to userspace for max cursor width
2391 * @cursor_height: hint to userspace for max cursor height
Daniel Vetter9f2a7952016-06-08 14:19:02 +02002392 * @helper_private: mid-layer private data
Dave Airlief453ba02008-11-07 14:05:41 -08002393 *
Jesse Barnesa62c93d2011-11-07 12:03:22 -08002394 * Core mode resource tracking structure. All CRTC, encoders, and connectors
2395 * enumerated by the driver are added here, as are global properties. Some
2396 * global restrictions are also here, e.g. dimension restrictions.
Dave Airlief453ba02008-11-07 14:05:41 -08002397 */
2398struct drm_mode_config {
Jesse Barnesad2563c2009-01-19 17:21:45 +10002399 struct mutex mutex; /* protects configuration (mode lists etc.) */
Rob Clark51fd3712013-11-19 12:10:12 -05002400 struct drm_modeset_lock connection_mutex; /* protects connector->encoder and encoder->crtc links */
2401 struct drm_modeset_acquire_ctx *acquire_ctx; /* for legacy _lock_all() / _unlock_all() */
Daniel Vetterac3ba4a2016-05-31 23:11:10 +02002402
2403 /**
2404 * @idr_mutex:
2405 *
2406 * Mutex for KMS ID allocation and management. Protects both @crtc_idr
2407 * and @tile_idr.
2408 */
2409 struct mutex idr_mutex;
2410
2411 /**
2412 * @crtc_idr:
2413 *
2414 * Main KMS ID tracking object. Use this idr for all IDs, fb, crtc,
2415 * connector, modes - just makes life easier to have only one.
2416 */
2417 struct idr crtc_idr;
2418
2419 /**
2420 * @tile_idr:
2421 *
2422 * Use this idr for allocating new IDs for tiled sinks like use in some
2423 * high-res DP MST screens.
2424 */
2425 struct idr tile_idr;
Daniel Vetter4b096ac2012-12-10 21:19:18 +01002426
Daniel Vetter2c0c33d2014-10-27 20:19:38 +01002427 struct mutex fb_lock; /* proctects global and per-file fb lists */
Dave Airlief453ba02008-11-07 14:05:41 -08002428 int num_fb;
2429 struct list_head fb_list;
Daniel Vetter4b096ac2012-12-10 21:19:18 +01002430
Daniel Vetter96094082016-07-15 21:47:59 +02002431 /**
2432 * @num_connector: Number of connectors on this device.
2433 */
Dave Airlief453ba02008-11-07 14:05:41 -08002434 int num_connector;
Daniel Vetter96094082016-07-15 21:47:59 +02002435 /**
2436 * @connector_ida: ID allocator for connector indices.
2437 */
Maarten Lankhorst5fff80b2016-02-17 08:32:05 +01002438 struct ida connector_ida;
Daniel Vetter96094082016-07-15 21:47:59 +02002439 /**
2440 * @connector_list: List of connector objects.
2441 */
Dave Airlief453ba02008-11-07 14:05:41 -08002442 struct list_head connector_list;
2443 int num_encoder;
2444 struct list_head encoder_list;
Matt Ropere27dde32014-04-01 15:22:30 -07002445
2446 /*
2447 * Track # of overlay planes separately from # of total planes. By
2448 * default we only advertise overlay planes to userspace; if userspace
2449 * sets the "universal plane" capability bit, we'll go ahead and
2450 * expose all planes.
2451 */
2452 int num_overlay_plane;
2453 int num_total_plane;
Jesse Barnes8cf5c912011-11-14 14:51:27 -08002454 struct list_head plane_list;
Dave Airlief453ba02008-11-07 14:05:41 -08002455
2456 int num_crtc;
2457 struct list_head crtc_list;
2458
2459 struct list_head property_list;
2460
Dave Airlief453ba02008-11-07 14:05:41 -08002461 int min_width, min_height;
2462 int max_width, max_height;
Laurent Pincharte6ecefa2012-05-17 13:27:23 +02002463 const struct drm_mode_config_funcs *funcs;
Benjamin Herrenschmidtd883f7f2009-02-02 16:55:45 +11002464 resource_size_t fb_base;
Dave Airlief453ba02008-11-07 14:05:41 -08002465
Dave Airlieeb1f8e4f32010-05-07 06:42:51 +00002466 /* output poll support */
2467 bool poll_enabled;
Daniel Vetter905bc9f2012-10-23 18:23:36 +00002468 bool poll_running;
Daniel Vetter162b6a52015-01-21 08:45:21 +01002469 bool delayed_event;
Tejun Heo991ea752010-07-20 22:09:02 +02002470 struct delayed_work output_poll_work;
Dave Airlieeb1f8e4f32010-05-07 06:42:51 +00002471
Daniel Stone8fb6e7a2015-04-20 19:22:54 +01002472 struct mutex blob_lock;
2473
Dave Airlief453ba02008-11-07 14:05:41 -08002474 /* pointers to standard properties */
2475 struct list_head property_blob_list;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02002476 /**
2477 * @edid_property: Default connector property to hold the EDID of the
2478 * currently connected sink, if any.
2479 */
Dave Airlief453ba02008-11-07 14:05:41 -08002480 struct drm_property *edid_property;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02002481 /**
2482 * @dpms_property: Default connector property to control the
2483 * connector's DPMS state.
2484 */
Dave Airlief453ba02008-11-07 14:05:41 -08002485 struct drm_property *dpms_property;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02002486 /**
2487 * @path_property: Default connector property to hold the DP MST path
2488 * for the port.
2489 */
Dave Airlie43aba7e2014-06-05 14:01:31 +10002490 struct drm_property *path_property;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02002491 /**
2492 * @tile_property: Default connector property to store the tile
2493 * position of a tiled screen, for sinks which need to be driven with
2494 * multiple CRTCs.
2495 */
Dave Airlie6f134d72014-10-20 16:30:50 +10002496 struct drm_property *tile_property;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02002497 /**
2498 * @plane_type_property: Default plane property to differentiate
2499 * CURSOR, PRIMARY and OVERLAY legacy uses of planes.
2500 */
Rob Clark9922ab52014-04-01 20:16:57 -04002501 struct drm_property *plane_type_property;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02002502 /**
2503 * @rotation_property: Optional property for planes or CRTCs to specifiy
2504 * rotation.
2505 */
Sonika Jindal2a297cc2014-08-05 11:26:54 +05302506 struct drm_property *rotation_property;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02002507 /**
2508 * @prop_src_x: Default atomic plane property for the plane source
2509 * position in the connected &drm_framebuffer.
2510 */
Rob Clark6b4959f2014-12-18 16:01:53 -05002511 struct drm_property *prop_src_x;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02002512 /**
2513 * @prop_src_y: Default atomic plane property for the plane source
2514 * position in the connected &drm_framebuffer.
2515 */
Rob Clark6b4959f2014-12-18 16:01:53 -05002516 struct drm_property *prop_src_y;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02002517 /**
2518 * @prop_src_w: Default atomic plane property for the plane source
2519 * position in the connected &drm_framebuffer.
2520 */
Rob Clark6b4959f2014-12-18 16:01:53 -05002521 struct drm_property *prop_src_w;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02002522 /**
2523 * @prop_src_h: Default atomic plane property for the plane source
2524 * position in the connected &drm_framebuffer.
2525 */
Rob Clark6b4959f2014-12-18 16:01:53 -05002526 struct drm_property *prop_src_h;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02002527 /**
2528 * @prop_crtc_x: Default atomic plane property for the plane destination
2529 * position in the &drm_crtc is is being shown on.
2530 */
Rob Clark6b4959f2014-12-18 16:01:53 -05002531 struct drm_property *prop_crtc_x;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02002532 /**
2533 * @prop_crtc_y: Default atomic plane property for the plane destination
2534 * position in the &drm_crtc is is being shown on.
2535 */
Rob Clark6b4959f2014-12-18 16:01:53 -05002536 struct drm_property *prop_crtc_y;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02002537 /**
2538 * @prop_crtc_w: Default atomic plane property for the plane destination
2539 * position in the &drm_crtc is is being shown on.
2540 */
Rob Clark6b4959f2014-12-18 16:01:53 -05002541 struct drm_property *prop_crtc_w;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02002542 /**
2543 * @prop_crtc_h: Default atomic plane property for the plane destination
2544 * position in the &drm_crtc is is being shown on.
2545 */
Rob Clark6b4959f2014-12-18 16:01:53 -05002546 struct drm_property *prop_crtc_h;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02002547 /**
2548 * @prop_fb_id: Default atomic plane property to specify the
2549 * &drm_framebuffer.
2550 */
Rob Clark6b4959f2014-12-18 16:01:53 -05002551 struct drm_property *prop_fb_id;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02002552 /**
2553 * @prop_crtc_id: Default atomic plane property to specify the
2554 * &drm_crtc.
2555 */
Rob Clark6b4959f2014-12-18 16:01:53 -05002556 struct drm_property *prop_crtc_id;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02002557 /**
2558 * @prop_active: Default atomic CRTC property to control the active
2559 * state, which is the simplified implementation for DPMS in atomic
2560 * drivers.
2561 */
Daniel Vettereab3bbe2015-01-22 16:36:21 +01002562 struct drm_property *prop_active;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02002563 /**
2564 * @prop_mode_id: Default atomic CRTC property to set the mode for a
2565 * CRTC. A 0 mode implies that the CRTC is entirely disabled - all
2566 * connectors must be of and active must be set to disabled, too.
2567 */
Daniel Stone955f3c32015-05-25 19:11:52 +01002568 struct drm_property *prop_mode_id;
Dave Airlief453ba02008-11-07 14:05:41 -08002569
Daniel Vetter9a6bc032016-07-15 21:48:00 +02002570 /**
2571 * @dvi_i_subconnector_property: Optional DVI-I property to
2572 * differentiate between analog or digital mode.
2573 */
Dave Airlief453ba02008-11-07 14:05:41 -08002574 struct drm_property *dvi_i_subconnector_property;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02002575 /**
2576 * @dvi_i_select_subconnector_property: Optional DVI-I property to
2577 * select between analog or digital mode.
2578 */
Dave Airlief453ba02008-11-07 14:05:41 -08002579 struct drm_property *dvi_i_select_subconnector_property;
2580
Daniel Vetter9a6bc032016-07-15 21:48:00 +02002581 /**
2582 * @tv_subconnector_property: Optional TV property to differentiate
2583 * between different TV connector types.
2584 */
Dave Airlief453ba02008-11-07 14:05:41 -08002585 struct drm_property *tv_subconnector_property;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02002586 /**
2587 * @tv_select_subconnector_property: Optional TV property to select
2588 * between different TV connector types.
2589 */
Dave Airlief453ba02008-11-07 14:05:41 -08002590 struct drm_property *tv_select_subconnector_property;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02002591 /**
2592 * @tv_mode_property: Optional TV property to select
2593 * the output TV mode.
2594 */
Dave Airlief453ba02008-11-07 14:05:41 -08002595 struct drm_property *tv_mode_property;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02002596 /**
2597 * @tv_left_margin_property: Optional TV property to set the left
2598 * margin.
2599 */
Dave Airlief453ba02008-11-07 14:05:41 -08002600 struct drm_property *tv_left_margin_property;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02002601 /**
2602 * @tv_right_margin_property: Optional TV property to set the right
2603 * margin.
2604 */
Dave Airlief453ba02008-11-07 14:05:41 -08002605 struct drm_property *tv_right_margin_property;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02002606 /**
2607 * @tv_top_margin_property: Optional TV property to set the right
2608 * margin.
2609 */
Dave Airlief453ba02008-11-07 14:05:41 -08002610 struct drm_property *tv_top_margin_property;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02002611 /**
2612 * @tv_bottom_margin_property: Optional TV property to set the right
2613 * margin.
2614 */
Dave Airlief453ba02008-11-07 14:05:41 -08002615 struct drm_property *tv_bottom_margin_property;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02002616 /**
2617 * @tv_brightness_property: Optional TV property to set the
2618 * brightness.
2619 */
Francisco Jerezb6b79022009-08-02 04:19:20 +02002620 struct drm_property *tv_brightness_property;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02002621 /**
2622 * @tv_contrast_property: Optional TV property to set the
2623 * contrast.
2624 */
Francisco Jerezb6b79022009-08-02 04:19:20 +02002625 struct drm_property *tv_contrast_property;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02002626 /**
2627 * @tv_flicker_reduction_property: Optional TV property to control the
2628 * flicker reduction mode.
2629 */
Francisco Jerezb6b79022009-08-02 04:19:20 +02002630 struct drm_property *tv_flicker_reduction_property;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02002631 /**
2632 * @tv_overscan_property: Optional TV property to control the overscan
2633 * setting.
2634 */
Francisco Jereza75f0232009-08-12 02:30:10 +02002635 struct drm_property *tv_overscan_property;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02002636 /**
2637 * @tv_saturation_property: Optional TV property to set the
2638 * saturation.
2639 */
Francisco Jereza75f0232009-08-12 02:30:10 +02002640 struct drm_property *tv_saturation_property;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02002641 /**
2642 * @tv_hue_property: Optional TV property to set the hue.
2643 */
Francisco Jereza75f0232009-08-12 02:30:10 +02002644 struct drm_property *tv_hue_property;
Dave Airlief453ba02008-11-07 14:05:41 -08002645
Daniel Vetter9a6bc032016-07-15 21:48:00 +02002646 /**
2647 * @scaling_mode_property: Optional connector property to control the
2648 * upscaling, mostly used for built-in panels.
2649 */
Dave Airlief453ba02008-11-07 14:05:41 -08002650 struct drm_property *scaling_mode_property;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02002651 /**
2652 * @aspect_ratio_property: Optional connector property to control the
2653 * HDMI infoframe aspect ratio setting.
2654 */
Vandana Kannanff587e42014-06-11 10:46:48 +05302655 struct drm_property *aspect_ratio_property;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02002656 /**
2657 * @dirty_info_property: Optional connector property to give userspace a
2658 * hint that the DIRTY_FB ioctl should be used.
2659 */
Jakob Bornecrantz884840a2009-12-03 23:25:47 +00002660 struct drm_property *dirty_info_property;
Dave Airlie019d96c2011-09-29 16:20:42 +01002661
Daniel Vetter9a6bc032016-07-15 21:48:00 +02002662 /**
2663 * @degamma_lut_property: Optional CRTC property to set the LUT used to
2664 * convert the framebuffer's colors to linear gamma.
2665 */
Lionel Landwerlin5488dc12016-02-26 17:05:00 +00002666 struct drm_property *degamma_lut_property;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02002667 /**
2668 * @degamma_lut_size_property: Optional CRTC property for the size of
2669 * the degamma LUT as supported by the driver (read-only).
2670 */
Lionel Landwerlin5488dc12016-02-26 17:05:00 +00002671 struct drm_property *degamma_lut_size_property;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02002672 /**
2673 * @ctm_property: Optional CRTC property to set the
2674 * matrix used to convert colors after the lookup in the
2675 * degamma LUT.
2676 */
Lionel Landwerlin5488dc12016-02-26 17:05:00 +00002677 struct drm_property *ctm_property;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02002678 /**
2679 * @gamma_lut_property: Optional CRTC property to set the LUT used to
2680 * convert the colors, after the CTM matrix, to the gamma space of the
2681 * connected screen.
2682 */
Lionel Landwerlin5488dc12016-02-26 17:05:00 +00002683 struct drm_property *gamma_lut_property;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02002684 /**
2685 * @gamma_lut_size_property: Optional CRTC property for the size of the
2686 * gamma LUT as supported by the driver (read-only).
2687 */
Lionel Landwerlin5488dc12016-02-26 17:05:00 +00002688 struct drm_property *gamma_lut_size_property;
2689
Daniel Vetter9a6bc032016-07-15 21:48:00 +02002690 /**
2691 * @suggested_x_property: Optional connector property with a hint for
2692 * the position of the output on the host's screen.
2693 */
Dave Airlie5bb2bbf2014-11-10 10:18:15 +10002694 struct drm_property *suggested_x_property;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02002695 /**
2696 * @suggested_y_property: Optional connector property with a hint for
2697 * the position of the output on the host's screen.
2698 */
Dave Airlie5bb2bbf2014-11-10 10:18:15 +10002699 struct drm_property *suggested_y_property;
2700
Dave Airlie019d96c2011-09-29 16:20:42 +01002701 /* dumb ioctl parameters */
2702 uint32_t preferred_depth, prefer_shadow;
Keith Packard62f21042013-07-22 18:50:00 -07002703
Daniel Vetter9a6bc032016-07-15 21:48:00 +02002704 /**
2705 * @async_page_flip: Does this device support async flips on the primary
2706 * plane?
2707 */
Keith Packard62f21042013-07-22 18:50:00 -07002708 bool async_page_flip;
Alex Deucher8716ed42014-02-12 12:48:23 -05002709
Daniel Vetterac3ba4a2016-05-31 23:11:10 +02002710 /**
2711 * @allow_fb_modifiers:
2712 *
2713 * Whether the driver supports fb modifiers in the ADDFB2.1 ioctl call.
2714 */
Rob Clarke3eb3252015-02-05 14:41:52 +00002715 bool allow_fb_modifiers;
2716
Alex Deucher8716ed42014-02-12 12:48:23 -05002717 /* cursor size */
2718 uint32_t cursor_width, cursor_height;
Daniel Vetter9f2a7952016-06-08 14:19:02 +02002719
2720 struct drm_mode_config_helper_funcs *helper_private;
Dave Airlief453ba02008-11-07 14:05:41 -08002721};
2722
Rob Clarkdd275952014-11-25 20:29:46 -05002723/**
2724 * drm_for_each_plane_mask - iterate over planes specified by bitmask
2725 * @plane: the loop cursor
2726 * @dev: the DRM device
2727 * @plane_mask: bitmask of plane indices
2728 *
2729 * Iterate over all planes specified by bitmask.
2730 */
2731#define drm_for_each_plane_mask(plane, dev, plane_mask) \
2732 list_for_each_entry((plane), &(dev)->mode_config.plane_list, head) \
Jani Nikula373701b2015-11-24 21:21:55 +02002733 for_each_if ((plane_mask) & (1 << drm_plane_index(plane)))
Rob Clarkdd275952014-11-25 20:29:46 -05002734
Maarten Lankhorstead8b662016-01-07 10:59:19 +01002735/**
2736 * drm_for_each_encoder_mask - iterate over encoders specified by bitmask
2737 * @encoder: the loop cursor
2738 * @dev: the DRM device
2739 * @encoder_mask: bitmask of encoder indices
2740 *
2741 * Iterate over all encoders specified by bitmask.
2742 */
2743#define drm_for_each_encoder_mask(encoder, dev, encoder_mask) \
2744 list_for_each_entry((encoder), &(dev)->mode_config.encoder_list, head) \
2745 for_each_if ((encoder_mask) & (1 << drm_encoder_index(encoder)))
Rob Clarkdd275952014-11-25 20:29:46 -05002746
Dave Airlief453ba02008-11-07 14:05:41 -08002747#define obj_to_crtc(x) container_of(x, struct drm_crtc, base)
2748#define obj_to_connector(x) container_of(x, struct drm_connector, base)
2749#define obj_to_encoder(x) container_of(x, struct drm_encoder, base)
2750#define obj_to_mode(x) container_of(x, struct drm_display_mode, base)
2751#define obj_to_fb(x) container_of(x, struct drm_framebuffer, base)
2752#define obj_to_property(x) container_of(x, struct drm_property, base)
2753#define obj_to_blob(x) container_of(x, struct drm_property_blob, base)
Jesse Barnes8cf5c912011-11-14 14:51:27 -08002754#define obj_to_plane(x) container_of(x, struct drm_plane, base)
Dave Airlief453ba02008-11-07 14:05:41 -08002755
Sascha Hauer4a67d392012-02-06 10:58:17 +01002756struct drm_prop_enum_list {
2757 int type;
2758 char *name;
2759};
Dave Airlief453ba02008-11-07 14:05:41 -08002760
Ville Syrjäläf9882872015-12-09 16:19:31 +02002761extern __printf(6, 7)
2762int drm_crtc_init_with_planes(struct drm_device *dev,
2763 struct drm_crtc *crtc,
2764 struct drm_plane *primary,
2765 struct drm_plane *cursor,
2766 const struct drm_crtc_funcs *funcs,
2767 const char *name, ...);
Dave Airlief453ba02008-11-07 14:05:41 -08002768extern void drm_crtc_cleanup(struct drm_crtc *crtc);
Chris Wilson490d3d12016-05-27 20:05:00 +01002769
2770/**
2771 * drm_crtc_index - find the index of a registered CRTC
2772 * @crtc: CRTC to find index for
2773 *
2774 * Given a registered CRTC, return the index of that CRTC within a DRM
2775 * device's list of CRTCs.
2776 */
2777static inline unsigned int drm_crtc_index(struct drm_crtc *crtc)
2778{
2779 return crtc->index;
2780}
Russell Kingdb5f7a62014-01-02 21:27:33 +00002781
2782/**
2783 * drm_crtc_mask - find the mask of a registered CRTC
2784 * @crtc: CRTC to find mask for
2785 *
2786 * Given a registered CRTC, return the mask bit of that CRTC for an
2787 * encoder's possible_crtcs field.
2788 */
2789static inline uint32_t drm_crtc_mask(struct drm_crtc *crtc)
2790{
2791 return 1 << drm_crtc_index(crtc);
2792}
Dave Airlief453ba02008-11-07 14:05:41 -08002793
Daniel Vetter81065542016-06-21 10:54:13 +02002794int drm_connector_init(struct drm_device *dev,
2795 struct drm_connector *connector,
2796 const struct drm_connector_funcs *funcs,
2797 int connector_type);
Thomas Wood34ea3d32014-05-29 16:57:41 +01002798int drm_connector_register(struct drm_connector *connector);
2799void drm_connector_unregister(struct drm_connector *connector);
Dave Airlief453ba02008-11-07 14:05:41 -08002800
2801extern void drm_connector_cleanup(struct drm_connector *connector);
Maarten Lankhorst5fff80b2016-02-17 08:32:05 +01002802static inline unsigned drm_connector_index(struct drm_connector *connector)
2803{
Daniel Vetter69425592016-07-19 18:25:01 +02002804 return connector->index;
Maarten Lankhorst5fff80b2016-02-17 08:32:05 +01002805}
2806
Ville Syrjälä13a3d912015-12-09 16:20:18 +02002807extern __printf(5, 6)
2808int drm_encoder_init(struct drm_device *dev,
2809 struct drm_encoder *encoder,
2810 const struct drm_encoder_funcs *funcs,
2811 int encoder_type, const char *name, ...);
Chris Wilson490d3d12016-05-27 20:05:00 +01002812
2813/**
2814 * drm_encoder_index - find the index of a registered encoder
2815 * @encoder: encoder to find index for
2816 *
2817 * Given a registered encoder, return the index of that encoder within a DRM
2818 * device's list of encoders.
2819 */
2820static inline unsigned int drm_encoder_index(struct drm_encoder *encoder)
2821{
2822 return encoder->index;
2823}
Dave Airlief453ba02008-11-07 14:05:41 -08002824
Thierry Reding3d887362014-01-13 14:33:20 +01002825/**
2826 * drm_encoder_crtc_ok - can a given crtc drive a given encoder?
2827 * @encoder: encoder to test
2828 * @crtc: crtc to test
2829 *
2830 * Return false if @encoder can't be driven by @crtc, true otherwise.
2831 */
2832static inline bool drm_encoder_crtc_ok(struct drm_encoder *encoder,
2833 struct drm_crtc *crtc)
2834{
2835 return !!(encoder->possible_crtcs & drm_crtc_mask(crtc));
2836}
2837
Ville Syrjäläb0b3b792015-12-09 16:19:55 +02002838extern __printf(8, 9)
2839int drm_universal_plane_init(struct drm_device *dev,
2840 struct drm_plane *plane,
2841 unsigned long possible_crtcs,
2842 const struct drm_plane_funcs *funcs,
2843 const uint32_t *formats,
2844 unsigned int format_count,
2845 enum drm_plane_type type,
2846 const char *name, ...);
Jesse Barnes8cf5c912011-11-14 14:51:27 -08002847extern int drm_plane_init(struct drm_device *dev,
2848 struct drm_plane *plane,
2849 unsigned long possible_crtcs,
2850 const struct drm_plane_funcs *funcs,
Thierry Reding45e37432015-08-12 16:54:28 +02002851 const uint32_t *formats, unsigned int format_count,
Matt Roperdc415ff2014-04-01 15:22:36 -07002852 bool is_primary);
Jesse Barnes8cf5c912011-11-14 14:51:27 -08002853extern void drm_plane_cleanup(struct drm_plane *plane);
Chris Wilson490d3d12016-05-27 20:05:00 +01002854
2855/**
2856 * drm_plane_index - find the index of a registered plane
2857 * @plane: plane to find index for
2858 *
2859 * Given a registered plane, return the index of that plane within a DRM
2860 * device's list of planes.
2861 */
2862static inline unsigned int drm_plane_index(struct drm_plane *plane)
2863{
2864 return plane->index;
2865}
Chandra Konduruf81338a2015-04-09 17:36:21 -07002866extern struct drm_plane * drm_plane_from_index(struct drm_device *dev, int idx);
Ville Syrjälä9125e612013-06-03 16:10:40 +03002867extern void drm_plane_force_disable(struct drm_plane *plane);
Gustavo Padovanecb7e162014-12-01 15:40:09 -08002868extern void drm_crtc_get_hv_timing(const struct drm_display_mode *mode,
2869 int *hdisplay, int *vdisplay);
Lukas Wunner6a0d9522016-06-08 18:47:27 +02002870extern int drm_crtc_force_disable(struct drm_crtc *crtc);
2871extern int drm_crtc_force_disable_all(struct drm_device *dev);
Jesse Barnes8cf5c912011-11-14 14:51:27 -08002872
Dave Airlief453ba02008-11-07 14:05:41 -08002873extern void drm_encoder_cleanup(struct drm_encoder *encoder);
2874
Ville Syrjäläd20d3172013-06-07 15:43:07 +00002875extern const char *drm_get_connector_status_name(enum drm_connector_status status);
Jesse Barnesac1bb362014-02-10 15:32:44 -08002876extern const char *drm_get_subpixel_order_name(enum subpixel_order order);
Ville Syrjäläd20d3172013-06-07 15:43:07 +00002877extern const char *drm_get_dpms_name(int val);
2878extern const char *drm_get_dvi_i_subconnector_name(int val);
2879extern const char *drm_get_dvi_i_select_name(int val);
2880extern const char *drm_get_tv_subconnector_name(int val);
2881extern const char *drm_get_tv_select_name(int val);
Dave Airlief453ba02008-11-07 14:05:41 -08002882extern void drm_mode_config_init(struct drm_device *dev);
Chris Wilsoneb0335562011-01-24 15:11:08 +00002883extern void drm_mode_config_reset(struct drm_device *dev);
Dave Airlief453ba02008-11-07 14:05:41 -08002884extern void drm_mode_config_cleanup(struct drm_device *dev);
Dave Airlief453ba02008-11-07 14:05:41 -08002885
Dave Airlie43aba7e2014-06-05 14:01:31 +10002886extern int drm_mode_connector_set_path_property(struct drm_connector *connector,
Thierry Reding12e6cec2014-05-13 11:38:36 +02002887 const char *path);
Dave Airlie6f134d72014-10-20 16:30:50 +10002888int drm_mode_connector_set_tile_property(struct drm_connector *connector);
Dave Airlief453ba02008-11-07 14:05:41 -08002889extern int drm_mode_connector_update_edid_property(struct drm_connector *connector,
Thierry Reding12e6cec2014-05-13 11:38:36 +02002890 const struct edid *edid);
Rob Clark5ea22f22014-05-30 11:34:01 -04002891
Boris Brezillonb5571e92014-07-22 12:09:10 +02002892extern int drm_display_info_set_bus_formats(struct drm_display_info *info,
2893 const u32 *formats,
2894 unsigned int num_formats);
2895
Rob Clark5ea22f22014-05-30 11:34:01 -04002896static inline bool drm_property_type_is(struct drm_property *property,
2897 uint32_t type)
2898{
2899 /* instanceof for props.. handles extended type vs original types: */
2900 if (property->flags & DRM_MODE_PROP_EXTENDED_TYPE)
2901 return (property->flags & DRM_MODE_PROP_EXTENDED_TYPE) == type;
2902 return property->flags & type;
2903}
2904
Paulo Zanonic5431882012-05-15 18:09:02 -03002905extern int drm_object_property_set_value(struct drm_mode_object *obj,
2906 struct drm_property *property,
2907 uint64_t val);
2908extern int drm_object_property_get_value(struct drm_mode_object *obj,
2909 struct drm_property *property,
2910 uint64_t *value);
Dave Airlief453ba02008-11-07 14:05:41 -08002911extern int drm_framebuffer_init(struct drm_device *dev,
2912 struct drm_framebuffer *fb,
2913 const struct drm_framebuffer_funcs *funcs);
Daniel Vetter786b99e2012-12-02 21:53:40 +01002914extern struct drm_framebuffer *drm_framebuffer_lookup(struct drm_device *dev,
2915 uint32_t id);
Rob Clarkf7eff602012-09-05 21:48:38 +00002916extern void drm_framebuffer_remove(struct drm_framebuffer *fb);
Dave Airlief453ba02008-11-07 14:05:41 -08002917extern void drm_framebuffer_cleanup(struct drm_framebuffer *fb);
Daniel Vetter36206362012-12-10 20:42:17 +01002918extern void drm_framebuffer_unregister_private(struct drm_framebuffer *fb);
Dave Airlief453ba02008-11-07 14:05:41 -08002919
Paulo Zanonic5431882012-05-15 18:09:02 -03002920extern void drm_object_attach_property(struct drm_mode_object *obj,
2921 struct drm_property *property,
2922 uint64_t init_val);
Dave Airlief453ba02008-11-07 14:05:41 -08002923extern struct drm_property *drm_property_create(struct drm_device *dev, int flags,
2924 const char *name, int num_values);
Sascha Hauer4a67d392012-02-06 10:58:17 +01002925extern struct drm_property *drm_property_create_enum(struct drm_device *dev, int flags,
2926 const char *name,
2927 const struct drm_prop_enum_list *props,
2928 int num_values);
Rob Clark49e27542012-05-17 02:23:26 -06002929struct drm_property *drm_property_create_bitmask(struct drm_device *dev,
2930 int flags, const char *name,
2931 const struct drm_prop_enum_list *props,
Ville Syrjälä7689ffb2014-07-08 10:31:52 +05302932 int num_props,
2933 uint64_t supported_bits);
Sascha Hauerd9bc3c02012-02-06 10:58:18 +01002934struct drm_property *drm_property_create_range(struct drm_device *dev, int flags,
2935 const char *name,
2936 uint64_t min, uint64_t max);
Rob Clarkebc44cf2012-09-12 22:22:31 -05002937struct drm_property *drm_property_create_signed_range(struct drm_device *dev,
2938 int flags, const char *name,
2939 int64_t min, int64_t max);
Rob Clark98f75de2014-05-30 11:37:03 -04002940struct drm_property *drm_property_create_object(struct drm_device *dev,
2941 int flags, const char *name, uint32_t type);
Daniel Vetter960cd9d2015-01-21 08:47:38 +01002942struct drm_property *drm_property_create_bool(struct drm_device *dev, int flags,
2943 const char *name);
Daniel Stone6bcacf52015-04-20 19:22:55 +01002944struct drm_property_blob *drm_property_create_blob(struct drm_device *dev,
2945 size_t length,
2946 const void *data);
2947struct drm_property_blob *drm_property_lookup_blob(struct drm_device *dev,
2948 uint32_t id);
2949struct drm_property_blob *drm_property_reference_blob(struct drm_property_blob *blob);
2950void drm_property_unreference_blob(struct drm_property_blob *blob);
Dave Airlief453ba02008-11-07 14:05:41 -08002951extern void drm_property_destroy(struct drm_device *dev, struct drm_property *property);
2952extern int drm_property_add_enum(struct drm_property *property, int index,
2953 uint64_t value, const char *name);
2954extern int drm_mode_create_dvi_i_properties(struct drm_device *dev);
Thierry Reding2f763312014-10-13 12:45:57 +02002955extern int drm_mode_create_tv_properties(struct drm_device *dev,
2956 unsigned int num_modes,
Ville Syrjäläb7c914b2015-08-31 15:09:26 +03002957 const char * const modes[]);
Dave Airlief453ba02008-11-07 14:05:41 -08002958extern int drm_mode_create_scaling_mode_property(struct drm_device *dev);
Vandana Kannanff587e42014-06-11 10:46:48 +05302959extern int drm_mode_create_aspect_ratio_property(struct drm_device *dev);
Jakob Bornecrantz884840a2009-12-03 23:25:47 +00002960extern int drm_mode_create_dirty_info_property(struct drm_device *dev);
Dave Airlie5bb2bbf2014-11-10 10:18:15 +10002961extern int drm_mode_create_suggested_offset_properties(struct drm_device *dev);
Dave Airlief453ba02008-11-07 14:05:41 -08002962
2963extern int drm_mode_connector_attach_encoder(struct drm_connector *connector,
2964 struct drm_encoder *encoder);
Sascha Hauer4cae5b82012-02-01 11:38:23 +01002965extern int drm_mode_crtc_set_gamma_size(struct drm_crtc *crtc,
Dave Airlief453ba02008-11-07 14:05:41 -08002966 int gamma_size);
Rob Clark98f75de2014-05-30 11:37:03 -04002967
Daniel Vetter2d13b672012-12-11 13:47:23 +01002968extern int drm_mode_set_config_internal(struct drm_mode_set *set);
Daniel Vetter81065542016-06-21 10:54:13 +02002969
Jesse Barnes308e5bc2011-11-14 14:51:28 -08002970extern uint32_t drm_mode_legacy_fb_format(uint32_t bpp, uint32_t depth);
Dave Airlie138f9eb2014-10-20 16:17:17 +10002971
2972extern struct drm_tile_group *drm_mode_create_tile_group(struct drm_device *dev,
2973 char topology[8]);
2974extern struct drm_tile_group *drm_mode_get_tile_group(struct drm_device *dev,
2975 char topology[8]);
2976extern void drm_mode_put_tile_group(struct drm_device *dev,
2977 struct drm_tile_group *tg);
Dave Airlieff72145b2011-02-07 12:16:14 +10002978
Thomas Wood3a5f87c2014-08-20 14:45:00 +01002979extern int drm_mode_plane_set_obj_prop(struct drm_plane *plane,
2980 struct drm_property *property,
2981 uint64_t value);
Dave Airlie248dbc22011-11-29 20:02:54 +00002982
Ville Syrjäläc1df5f32014-07-08 10:31:53 +05302983extern struct drm_property *drm_mode_create_rotation_property(struct drm_device *dev,
2984 unsigned int supported_rotations);
Ville Syrjälä3c9855f2014-07-08 10:31:56 +05302985extern unsigned int drm_rotation_simplify(unsigned int rotation,
2986 unsigned int supported_rotations);
Jyri Sarhaf8ed34a2016-06-07 15:09:14 +03002987extern void drm_crtc_enable_color_mgmt(struct drm_crtc *crtc,
2988 uint degamma_lut_size,
2989 bool has_ctm,
2990 uint gamma_lut_size);
Marek Szyprowski44d1240d2016-06-13 11:11:26 +02002991
2992int drm_plane_create_zpos_property(struct drm_plane *plane,
2993 unsigned int zpos,
2994 unsigned int min, unsigned int max);
2995
2996int drm_plane_create_zpos_immutable_property(struct drm_plane *plane,
2997 unsigned int zpos);
2998
Russell King96f60e32012-08-15 13:59:49 +01002999/* Helpers */
Daniel Vetter81065542016-06-21 10:54:13 +02003000struct drm_mode_object *drm_mode_object_find(struct drm_device *dev,
3001 uint32_t id, uint32_t type);
3002void drm_mode_object_reference(struct drm_mode_object *obj);
3003void drm_mode_object_unreference(struct drm_mode_object *obj);
Rob Clarka2b34e22013-10-05 16:36:52 -04003004
3005static inline struct drm_plane *drm_plane_find(struct drm_device *dev,
3006 uint32_t id)
3007{
3008 struct drm_mode_object *mo;
3009 mo = drm_mode_object_find(dev, id, DRM_MODE_OBJECT_PLANE);
3010 return mo ? obj_to_plane(mo) : NULL;
3011}
3012
Russell King96f60e32012-08-15 13:59:49 +01003013static inline struct drm_crtc *drm_crtc_find(struct drm_device *dev,
3014 uint32_t id)
3015{
3016 struct drm_mode_object *mo;
3017 mo = drm_mode_object_find(dev, id, DRM_MODE_OBJECT_CRTC);
3018 return mo ? obj_to_crtc(mo) : NULL;
3019}
3020
3021static inline struct drm_encoder *drm_encoder_find(struct drm_device *dev,
3022 uint32_t id)
3023{
3024 struct drm_mode_object *mo;
3025 mo = drm_mode_object_find(dev, id, DRM_MODE_OBJECT_ENCODER);
3026 return mo ? obj_to_encoder(mo) : NULL;
3027}
3028
Dave Airlieb164d312016-04-27 11:10:09 +10003029/**
3030 * drm_connector_lookup - lookup connector object
3031 * @dev: DRM device
3032 * @id: connector object id
3033 *
3034 * This function looks up the connector object specified by id
3035 * add takes a reference to it.
3036 */
3037static inline struct drm_connector *drm_connector_lookup(struct drm_device *dev,
Rob Clarka2b34e22013-10-05 16:36:52 -04003038 uint32_t id)
3039{
3040 struct drm_mode_object *mo;
3041 mo = drm_mode_object_find(dev, id, DRM_MODE_OBJECT_CONNECTOR);
3042 return mo ? obj_to_connector(mo) : NULL;
3043}
3044
3045static inline struct drm_property *drm_property_find(struct drm_device *dev,
3046 uint32_t id)
3047{
3048 struct drm_mode_object *mo;
3049 mo = drm_mode_object_find(dev, id, DRM_MODE_OBJECT_PROPERTY);
3050 return mo ? obj_to_property(mo) : NULL;
3051}
3052
Lionel Landwerlin5488dc12016-02-26 17:05:00 +00003053/*
3054 * Extract a degamma/gamma LUT value provided by user and round it to the
3055 * precision supported by the hardware.
3056 */
3057static inline uint32_t drm_color_lut_extract(uint32_t user_input,
3058 uint32_t bit_precision)
3059{
Lionel Landwerlin644a8052016-03-22 14:10:33 +00003060 uint32_t val = user_input;
Lionel Landwerlin5488dc12016-02-26 17:05:00 +00003061 uint32_t max = 0xffff >> (16 - bit_precision);
3062
Lionel Landwerlin644a8052016-03-22 14:10:33 +00003063 /* Round only if we're not using full precision. */
3064 if (bit_precision < 16) {
3065 val += 1UL << (16 - bit_precision - 1);
3066 val >>= 16 - bit_precision;
3067 }
Lionel Landwerlin5488dc12016-02-26 17:05:00 +00003068
3069 return clamp_val(val, 0, max);
3070}
3071
Dave Airliee76d3992016-05-03 10:17:52 +10003072/**
Dave Airlied0f37cf62016-04-15 15:10:36 +10003073 * drm_framebuffer_reference - incr the fb refcnt
3074 * @fb: framebuffer
3075 *
3076 * This functions increments the fb's refcount.
3077 */
3078static inline void drm_framebuffer_reference(struct drm_framebuffer *fb)
3079{
3080 drm_mode_object_reference(&fb->base);
3081}
3082
3083/**
3084 * drm_framebuffer_unreference - unref a framebuffer
3085 * @fb: framebuffer to unref
3086 *
3087 * This functions decrements the fb's refcount and frees it if it drops to zero.
3088 */
3089static inline void drm_framebuffer_unreference(struct drm_framebuffer *fb)
3090{
3091 drm_mode_object_unreference(&fb->base);
3092}
3093
Dave Airlie747a5982016-04-15 15:10:35 +10003094/**
3095 * drm_framebuffer_read_refcount - read the framebuffer reference count.
3096 * @fb: framebuffer
3097 *
3098 * This functions returns the framebuffer's reference count.
3099 */
3100static inline uint32_t drm_framebuffer_read_refcount(struct drm_framebuffer *fb)
3101{
Dave Airlied0f37cf62016-04-15 15:10:36 +10003102 return atomic_read(&fb->base.refcount.refcount);
Dave Airlie747a5982016-04-15 15:10:35 +10003103}
3104
Dave Airlieb164d312016-04-27 11:10:09 +10003105/**
3106 * drm_connector_reference - incr the connector refcnt
3107 * @connector: connector
3108 *
3109 * This function increments the connector's refcount.
3110 */
3111static inline void drm_connector_reference(struct drm_connector *connector)
3112{
3113 drm_mode_object_reference(&connector->base);
3114}
3115
3116/**
3117 * drm_connector_unreference - unref a connector
3118 * @connector: connector to unref
3119 *
3120 * This function decrements the connector's refcount and frees it if it drops to zero.
3121 */
3122static inline void drm_connector_unreference(struct drm_connector *connector)
3123{
3124 drm_mode_object_unreference(&connector->base);
3125}
3126
Matt Ropere27dde32014-04-01 15:22:30 -07003127/* Plane list iterator for legacy (overlay only) planes. */
Daniel Vetter4ea50e92015-07-09 23:44:24 +02003128#define drm_for_each_legacy_plane(plane, dev) \
3129 list_for_each_entry(plane, &(dev)->mode_config.plane_list, head) \
Jani Nikula373701b2015-11-24 21:21:55 +02003130 for_each_if (plane->type == DRM_PLANE_TYPE_OVERLAY)
Matt Ropere27dde32014-04-01 15:22:30 -07003131
Daniel Vetter6295d602015-07-09 23:44:25 +02003132#define drm_for_each_plane(plane, dev) \
3133 list_for_each_entry(plane, &(dev)->mode_config.plane_list, head)
3134
3135#define drm_for_each_crtc(crtc, dev) \
3136 list_for_each_entry(crtc, &(dev)->mode_config.crtc_list, head)
3137
Daniel Vetter7a3f3d62015-07-09 23:44:28 +02003138static inline void
3139assert_drm_connector_list_read_locked(struct drm_mode_config *mode_config)
3140{
Daniel Vettercff20ba2015-07-09 23:44:33 +02003141 /*
3142 * The connector hotadd/remove code currently grabs both locks when
3143 * updating lists. Hence readers need only hold either of them to be
3144 * safe and the check amounts to
3145 *
3146 * WARN_ON(not_holding(A) && not_holding(B)).
3147 */
3148 WARN_ON(!mutex_is_locked(&mode_config->mutex) &&
3149 !drm_modeset_is_locked(&mode_config->connection_mutex));
Daniel Vetter7a3f3d62015-07-09 23:44:28 +02003150}
3151
Daniel Vetter6295d602015-07-09 23:44:25 +02003152#define drm_for_each_connector(connector, dev) \
Daniel Vetter7a3f3d62015-07-09 23:44:28 +02003153 for (assert_drm_connector_list_read_locked(&(dev)->mode_config), \
3154 connector = list_first_entry(&(dev)->mode_config.connector_list, \
3155 struct drm_connector, head); \
3156 &connector->head != (&(dev)->mode_config.connector_list); \
3157 connector = list_next_entry(connector, head))
Daniel Vetter6295d602015-07-09 23:44:25 +02003158
3159#define drm_for_each_encoder(encoder, dev) \
3160 list_for_each_entry(encoder, &(dev)->mode_config.encoder_list, head)
3161
3162#define drm_for_each_fb(fb, dev) \
Daniel Vetter4676ba02015-07-09 23:44:30 +02003163 for (WARN_ON(!mutex_is_locked(&(dev)->mode_config.fb_lock)), \
3164 fb = list_first_entry(&(dev)->mode_config.fb_list, \
3165 struct drm_framebuffer, head); \
3166 &fb->head != (&(dev)->mode_config.fb_list); \
3167 fb = list_next_entry(fb, head))
Daniel Vetter6295d602015-07-09 23:44:25 +02003168
Daniel Vetter81065542016-06-21 10:54:13 +02003169/* drm_edid.c */
3170bool drm_probe_ddc(struct i2c_adapter *adapter);
3171struct edid *drm_get_edid(struct drm_connector *connector,
3172 struct i2c_adapter *adapter);
3173struct edid *drm_get_edid_switcheroo(struct drm_connector *connector,
3174 struct i2c_adapter *adapter);
3175struct edid *drm_edid_duplicate(const struct edid *edid);
3176int drm_add_edid_modes(struct drm_connector *connector, struct edid *edid);
3177
3178u8 drm_match_cea_mode(const struct drm_display_mode *to_match);
3179enum hdmi_picture_aspect drm_get_cea_aspect_ratio(const u8 video_code);
3180bool drm_detect_hdmi_monitor(struct edid *edid);
3181bool drm_detect_monitor_audio(struct edid *edid);
3182bool drm_rgb_quant_range_selectable(struct edid *edid);
3183int drm_add_modes_noedid(struct drm_connector *connector,
3184 int hdisplay, int vdisplay);
3185void drm_set_preferred_mode(struct drm_connector *connector,
3186 int hpref, int vpref);
3187
3188int drm_edid_header_is_valid(const u8 *raw_edid);
3189bool drm_edid_block_valid(u8 *raw_edid, int block, bool print_bad_edid,
3190 bool *edid_corrupt);
3191bool drm_edid_is_valid(struct edid *edid);
3192void drm_edid_get_monitor_name(struct edid *edid, char *name,
3193 int buflen);
3194struct drm_display_mode *drm_mode_find_dmt(struct drm_device *dev,
3195 int hsize, int vsize, int fresh,
3196 bool rb);
3197
3198/* drm_bridge.c */
3199extern int drm_bridge_add(struct drm_bridge *bridge);
3200extern void drm_bridge_remove(struct drm_bridge *bridge);
3201extern struct drm_bridge *of_drm_find_bridge(struct device_node *np);
3202extern int drm_bridge_attach(struct drm_device *dev, struct drm_bridge *bridge);
3203
3204bool drm_bridge_mode_fixup(struct drm_bridge *bridge,
3205 const struct drm_display_mode *mode,
3206 struct drm_display_mode *adjusted_mode);
3207void drm_bridge_disable(struct drm_bridge *bridge);
3208void drm_bridge_post_disable(struct drm_bridge *bridge);
3209void drm_bridge_mode_set(struct drm_bridge *bridge,
3210 struct drm_display_mode *mode,
3211 struct drm_display_mode *adjusted_mode);
3212void drm_bridge_pre_enable(struct drm_bridge *bridge);
3213void drm_bridge_enable(struct drm_bridge *bridge);
3214
Dave Airlief453ba02008-11-07 14:05:41 -08003215#endif /* __DRM_CRTC_H__ */