blob: b4ab33f3fb63309151b1f815fea925d0c408f7e5 [file] [log] [blame]
Dave Airlief453ba02008-11-07 14:05:41 -08001/*
2 * Copyright © 2006 Keith Packard
3 * Copyright © 2007-2008 Dave Airlie
4 * Copyright © 2007-2008 Intel Corporation
5 * Jesse Barnes <jesse.barnes@intel.com>
6 *
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the "Software"),
9 * to deal in the Software without restriction, including without limitation
10 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
11 * and/or sell copies of the Software, and to permit persons to whom the
12 * Software is furnished to do so, subject to the following conditions:
13 *
14 * The above copyright notice and this permission notice shall be included in
15 * all copies or substantial portions of the Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
21 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
22 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
23 * OTHER DEALINGS IN THE SOFTWARE.
24 */
25#ifndef __DRM_CRTC_H__
26#define __DRM_CRTC_H__
27
28#include <linux/i2c.h>
29#include <linux/spinlock.h>
30#include <linux/types.h>
31#include <linux/idr.h>
Dave Airlief453ba02008-11-07 14:05:41 -080032#include <linux/fb.h>
Vandana Kannan985e5dc2013-12-19 15:34:07 +053033#include <linux/hdmi.h>
Boris Brezillonb5571e92014-07-22 12:09:10 +020034#include <linux/media-bus-format.h>
David Herrmannd7d2c482014-08-29 12:12:40 +020035#include <uapi/drm/drm_mode.h>
36#include <uapi/drm/drm_fourcc.h>
Rob Clark51fd3712013-11-19 12:10:12 -050037#include <drm/drm_modeset_lock.h>
Jesse Barnes308e5bc2011-11-14 14:51:28 -080038
Dave Airlief453ba02008-11-07 14:05:41 -080039struct drm_device;
40struct drm_mode_set;
41struct drm_framebuffer;
Paulo Zanoni7e3bdf42012-05-15 18:09:01 -030042struct drm_object_properties;
Thierry Reding595887e2012-11-21 15:00:47 +010043struct drm_file;
44struct drm_clip_rect;
Russell King7e435aa2014-06-15 11:07:12 +010045struct device_node;
Daniel Vettere2330f02014-10-29 11:34:56 +010046struct fence;
Dave Airlief453ba02008-11-07 14:05:41 -080047
Dave Airlief453ba02008-11-07 14:05:41 -080048struct drm_mode_object {
49 uint32_t id;
50 uint32_t type;
Paulo Zanoni7e3bdf42012-05-15 18:09:01 -030051 struct drm_object_properties *properties;
Dave Airlied0f37cf62016-04-15 15:10:36 +100052 struct kref refcount;
53 void (*free_cb)(struct kref *kref);
Paulo Zanoni7e3bdf42012-05-15 18:09:01 -030054};
55
Paulo Zanonife456162012-06-12 11:27:01 -030056#define DRM_OBJECT_MAX_PROPERTY 24
Paulo Zanoni7e3bdf42012-05-15 18:09:01 -030057struct drm_object_properties {
Rob Clark88a48e22014-12-18 16:01:50 -050058 int count, atomic_count;
Rob Clarkb17cd752014-12-16 18:05:30 -050059 /* NOTE: if we ever start dynamically destroying properties (ie.
60 * not at drm_mode_config_cleanup() time), then we'd have to do
61 * a better job of detaching property from mode objects to avoid
62 * dangling property pointers:
63 */
64 struct drm_property *properties[DRM_OBJECT_MAX_PROPERTY];
Rob Clark22b8b132014-12-16 18:05:31 -050065 /* do not read/write values directly, but use drm_object_property_get_value()
66 * and drm_object_property_set_value():
67 */
Paulo Zanoni7e3bdf42012-05-15 18:09:01 -030068 uint64_t values[DRM_OBJECT_MAX_PROPERTY];
Dave Airlief453ba02008-11-07 14:05:41 -080069};
70
Rob Clarkebc44cf2012-09-12 22:22:31 -050071static inline int64_t U642I64(uint64_t val)
72{
73 return (int64_t)*((int64_t *)&val);
74}
75static inline uint64_t I642U64(int64_t val)
76{
77 return (uint64_t)*((uint64_t *)&val);
78}
79
Robert Feketed9c38242015-11-02 16:14:08 +010080/*
81 * Rotation property bits. DRM_ROTATE_<degrees> rotates the image by the
82 * specified amount in degrees in counter clockwise direction. DRM_REFLECT_X and
83 * DRM_REFLECT_Y reflects the image along the specified axis prior to rotation
84 */
Joonas Lahtinen62209072015-10-01 10:00:57 +030085#define DRM_ROTATE_MASK 0x0f
Ville Syrjälä06596962014-07-08 10:31:51 +053086#define DRM_ROTATE_0 0
87#define DRM_ROTATE_90 1
88#define DRM_ROTATE_180 2
89#define DRM_ROTATE_270 3
Joonas Lahtinen62209072015-10-01 10:00:57 +030090#define DRM_REFLECT_MASK (~DRM_ROTATE_MASK)
Ville Syrjälä06596962014-07-08 10:31:51 +053091#define DRM_REFLECT_X 4
92#define DRM_REFLECT_Y 5
93
Daniel Vetter55310002014-01-23 15:52:20 +010094enum drm_connector_force {
95 DRM_FORCE_UNSPECIFIED,
96 DRM_FORCE_OFF,
97 DRM_FORCE_ON, /* force on analog part normally */
98 DRM_FORCE_ON_DIGITAL, /* for DVI-I use digital connector */
Dave Airlief453ba02008-11-07 14:05:41 -080099};
100
Daniel Vetter55310002014-01-23 15:52:20 +0100101#include <drm/drm_modes.h>
Damien Lespiau4aa17cf2013-09-25 16:45:21 +0100102
Dave Airlief453ba02008-11-07 14:05:41 -0800103enum drm_connector_status {
104 connector_status_connected = 1,
105 connector_status_disconnected = 2,
106 connector_status_unknown = 3,
107};
108
109enum subpixel_order {
110 SubPixelUnknown = 0,
111 SubPixelHorizontalRGB,
112 SubPixelHorizontalBGR,
113 SubPixelVerticalRGB,
114 SubPixelVerticalBGR,
115 SubPixelNone,
116};
117
Jesse Barnesda05a5a72011-04-15 13:48:57 -0700118#define DRM_COLOR_FORMAT_RGB444 (1<<0)
119#define DRM_COLOR_FORMAT_YCRCB444 (1<<1)
120#define DRM_COLOR_FORMAT_YCRCB422 (1<<2)
Stefan Agnerf0aa0832016-02-08 11:38:14 -0800121
122#define DRM_BUS_FLAG_DE_LOW (1<<0)
123#define DRM_BUS_FLAG_DE_HIGH (1<<1)
124/* drive data on pos. edge */
125#define DRM_BUS_FLAG_PIXDATA_POSEDGE (1<<2)
126/* drive data on neg. edge */
127#define DRM_BUS_FLAG_PIXDATA_NEGEDGE (1<<3)
128
Dave Airlief453ba02008-11-07 14:05:41 -0800129/*
130 * Describes a given display (e.g. CRT or flat panel) and its limitations.
131 */
132struct drm_display_info {
133 char name[DRM_DISPLAY_INFO_LEN];
Adam Jacksonfb439642010-08-03 14:38:16 -0400134
Dave Airlief453ba02008-11-07 14:05:41 -0800135 /* Physical size */
136 unsigned int width_mm;
137 unsigned int height_mm;
138
Dave Airlief453ba02008-11-07 14:05:41 -0800139 /* Clock limits FIXME: storage format */
140 unsigned int min_vfreq, max_vfreq;
141 unsigned int min_hfreq, max_hfreq;
142 unsigned int pixel_clock;
Jesse Barnes3b112282011-04-15 12:49:23 -0700143 unsigned int bpc;
Dave Airlief453ba02008-11-07 14:05:41 -0800144
Dave Airlief453ba02008-11-07 14:05:41 -0800145 enum subpixel_order subpixel_order;
Jesse Barnesda05a5a72011-04-15 13:48:57 -0700146 u32 color_formats;
Dave Airlief453ba02008-11-07 14:05:41 -0800147
Boris Brezillonb5571e92014-07-22 12:09:10 +0200148 const u32 *bus_formats;
149 unsigned int num_bus_formats;
Stefan Agnerf0aa0832016-02-08 11:38:14 -0800150 u32 bus_flags;
Boris Brezillonb5571e92014-07-22 12:09:10 +0200151
Mario Kleiner5d02626d2014-06-05 09:52:10 -0400152 /* Mask of supported hdmi deep color modes */
153 u8 edid_hdmi_dc_modes;
154
Jesse Barnesebec9a72011-08-03 09:22:54 -0700155 u8 cea_rev;
Dave Airlief453ba02008-11-07 14:05:41 -0800156};
157
Dave Airlie138f9eb2014-10-20 16:17:17 +1000158/* data corresponds to displayid vend/prod/serial */
159struct drm_tile_group {
160 struct kref refcount;
161 struct drm_device *dev;
162 int id;
163 u8 group_data[8];
164};
165
Daniel Vetterc6b0ca32015-12-04 09:46:01 +0100166/**
167 * struct drm_framebuffer_funcs - framebuffer hooks
168 */
Dave Airlief453ba02008-11-07 14:05:41 -0800169struct drm_framebuffer_funcs {
Daniel Vetterc6b0ca32015-12-04 09:46:01 +0100170 /**
171 * @destroy:
172 *
173 * Clean up framebuffer resources, specifically also unreference the
174 * backing storage. The core guarantees to call this function for every
175 * framebuffer successfully created by ->fb_create() in
Daniel Vetterd55f5322015-12-08 09:49:19 +0100176 * &drm_mode_config_funcs. Drivers must also call
177 * drm_framebuffer_cleanup() to release DRM core resources for this
178 * framebuffer.
Daniel Vetterc6b0ca32015-12-04 09:46:01 +0100179 */
Dave Airlief453ba02008-11-07 14:05:41 -0800180 void (*destroy)(struct drm_framebuffer *framebuffer);
Daniel Vetterc6b0ca32015-12-04 09:46:01 +0100181
182 /**
183 * @create_handle:
184 *
185 * Create a buffer handle in the driver-specific buffer manager (either
186 * GEM or TTM) valid for the passed-in struct &drm_file. This is used by
187 * the core to implement the GETFB IOCTL, which returns (for
188 * sufficiently priviledged user) also a native buffer handle. This can
189 * be used for seamless transitions between modesetting clients by
190 * copying the current screen contents to a private buffer and blending
191 * between that and the new contents.
192 *
Daniel Vetterd55f5322015-12-08 09:49:19 +0100193 * GEM based drivers should call drm_gem_handle_create() to create the
194 * handle.
195 *
Daniel Vetterc6b0ca32015-12-04 09:46:01 +0100196 * RETURNS:
197 *
198 * 0 on success or a negative error code on failure.
199 */
Dave Airlief453ba02008-11-07 14:05:41 -0800200 int (*create_handle)(struct drm_framebuffer *fb,
201 struct drm_file *file_priv,
202 unsigned int *handle);
Daniel Vetterc6b0ca32015-12-04 09:46:01 +0100203 /**
204 * @dirty:
Jakob Bornecrantz884840a2009-12-03 23:25:47 +0000205 *
Daniel Vetterc6b0ca32015-12-04 09:46:01 +0100206 * Optional callback for the dirty fb IOCTL.
Jakob Bornecrantz884840a2009-12-03 23:25:47 +0000207 *
Daniel Vetterc6b0ca32015-12-04 09:46:01 +0100208 * Userspace can notify the driver via this callback that an area of the
209 * framebuffer has changed and should be flushed to the display
210 * hardware. This can also be used internally, e.g. by the fbdev
211 * emulation, though that's not the case currently.
212 *
213 * See documentation in drm_mode.h for the struct drm_mode_fb_dirty_cmd
214 * for more information as all the semantics and arguments have a one to
215 * one mapping on this function.
216 *
217 * RETURNS:
218 *
219 * 0 on success or a negative error code on failure.
Jakob Bornecrantz884840a2009-12-03 23:25:47 +0000220 */
Thomas Hellstrom02b00162010-10-05 12:43:02 +0200221 int (*dirty)(struct drm_framebuffer *framebuffer,
222 struct drm_file *file_priv, unsigned flags,
Jakob Bornecrantz884840a2009-12-03 23:25:47 +0000223 unsigned color, struct drm_clip_rect *clips,
224 unsigned num_clips);
Dave Airlief453ba02008-11-07 14:05:41 -0800225};
226
227struct drm_framebuffer {
228 struct drm_device *dev;
Rob Clarkf7eff602012-09-05 21:48:38 +0000229 /*
230 * Note that the fb is refcounted for the benefit of driver internals,
231 * for example some hw, disabling a CRTC/plane is asynchronous, and
232 * scanout does not actually complete until the next vblank. So some
233 * cleanup (like releasing the reference(s) on the backing GEM bo(s))
234 * should be deferred. In cases like this, the driver would like to
235 * hold a ref to the fb even though it has already been removed from
236 * userspace perspective.
Dave Airlied0f37cf62016-04-15 15:10:36 +1000237 * The refcount is stored inside the mode object.
Rob Clarkf7eff602012-09-05 21:48:38 +0000238 */
Daniel Vetter4b096ac2012-12-10 21:19:18 +0100239 /*
240 * Place on the dev->mode_config.fb_list, access protected by
241 * dev->mode_config.fb_lock.
242 */
Dave Airlief453ba02008-11-07 14:05:41 -0800243 struct list_head head;
244 struct drm_mode_object base;
245 const struct drm_framebuffer_funcs *funcs;
Ville Syrjälä01f2c772011-12-20 00:06:49 +0200246 unsigned int pitches[4];
247 unsigned int offsets[4];
Rob Clarke3eb3252015-02-05 14:41:52 +0000248 uint64_t modifier[4];
Dave Airlief453ba02008-11-07 14:05:41 -0800249 unsigned int width;
250 unsigned int height;
251 /* depth can be 15 or 16 */
252 unsigned int depth;
253 int bits_per_pixel;
254 int flags;
Jesse Barnes308e5bc2011-11-14 14:51:28 -0800255 uint32_t pixel_format; /* fourcc format */
Gerd Hoffmanndd546592016-05-31 08:54:52 +0200256 int hot_x;
257 int hot_y;
Dave Airlief453ba02008-11-07 14:05:41 -0800258 struct list_head filp_head;
259};
260
261struct drm_property_blob {
262 struct drm_mode_object base;
Daniel Stone6bcacf52015-04-20 19:22:55 +0100263 struct drm_device *dev;
Daniel Stonee2f5d2e2015-05-22 13:34:51 +0100264 struct list_head head_global;
265 struct list_head head_file;
Thierry Redingecbbe592014-05-13 11:36:13 +0200266 size_t length;
Ville Syrjäläd63f5e62012-03-13 12:35:49 +0200267 unsigned char data[];
Dave Airlief453ba02008-11-07 14:05:41 -0800268};
269
270struct drm_property_enum {
271 uint64_t value;
272 struct list_head head;
273 char name[DRM_PROP_NAME_LEN];
274};
275
276struct drm_property {
277 struct list_head head;
278 struct drm_mode_object base;
279 uint32_t flags;
280 char name[DRM_PROP_NAME_LEN];
281 uint32_t num_values;
282 uint64_t *values;
Rob Clark98f75de2014-05-30 11:37:03 -0400283 struct drm_device *dev;
Dave Airlief453ba02008-11-07 14:05:41 -0800284
Daniel Vetter3758b342014-11-19 18:38:10 +0100285 struct list_head enum_list;
Dave Airlief453ba02008-11-07 14:05:41 -0800286};
287
288struct drm_crtc;
289struct drm_connector;
290struct drm_encoder;
Kristian Høgsbergd91d8a32009-11-17 12:43:55 -0500291struct drm_pending_vblank_event;
Jesse Barnes8cf5c912011-11-14 14:51:27 -0800292struct drm_plane;
Sean Paul3b336ec2013-08-14 16:47:37 -0400293struct drm_bridge;
Daniel Vetter144ecb92014-10-27 20:28:44 +0100294struct drm_atomic_state;
295
Daniel Vetter4490d4c2015-12-04 09:45:45 +0100296struct drm_crtc_helper_funcs;
297struct drm_encoder_helper_funcs;
298struct drm_connector_helper_funcs;
299struct drm_plane_helper_funcs;
300
Daniel Vetter144ecb92014-10-27 20:28:44 +0100301/**
Daniel Vettercc4ceb42014-07-25 21:30:38 +0200302 * struct drm_crtc_state - mutable CRTC state
Daniel Vetter07cc0ef2014-11-27 15:49:39 +0100303 * @crtc: backpointer to the CRTC
Daniel Vetter144ecb92014-10-27 20:28:44 +0100304 * @enable: whether the CRTC should be enabled, gates all other state
Daniel Vetterd9b13622014-11-26 16:57:41 +0100305 * @active: whether the CRTC is actively displaying (used for DPMS)
Maarten Lankhorstfc596662015-07-21 13:28:57 +0200306 * @planes_changed: planes on this crtc are updated
307 * @mode_changed: crtc_state->mode or crtc_state->enable has been changed
308 * @active_changed: crtc_state->active has been toggled.
309 * @connectors_changed: connectors to this crtc have been updated
Lionel Landwerlin5488dc12016-02-26 17:05:00 +0000310 * @color_mgmt_changed: color management properties have changed (degamma or
311 * gamma LUT or CSC matrix)
Rob Clark6ddd3882014-11-21 15:28:31 -0500312 * @plane_mask: bitmask of (1 << drm_plane_index(plane)) of attached planes
Maarten Lankhorst4cd9fa52016-01-04 12:53:18 +0100313 * @connector_mask: bitmask of (1 << drm_connector_index(connector)) of attached connectors
Maarten Lankhorste87a52b2016-01-28 15:04:58 +0100314 * @encoder_mask: bitmask of (1 << drm_encoder_index(encoder)) of attached encoders
Daniel Vetter623369e2014-09-16 17:50:47 +0200315 * @last_vblank_count: for helpers and drivers to capture the vblank of the
316 * update to ensure framebuffer cleanup isn't done too early
Daniel Vetter2f324b42014-10-29 11:13:47 +0100317 * @adjusted_mode: for use by helpers and drivers to compute adjusted mode timings
Daniel Vetter144ecb92014-10-27 20:28:44 +0100318 * @mode: current mode timings
Daniel Vetterac3ba4a2016-05-31 23:11:10 +0200319 * @mode_blob: &drm_property_blob for @mode
Lionel Landwerlin5488dc12016-02-26 17:05:00 +0000320 * @degamma_lut: Lookup table for converting framebuffer pixel data
321 * before apply the conversion matrix
322 * @ctm: Transformation matrix
323 * @gamma_lut: Lookup table for converting pixel data after the
324 * conversion matrix
Daniel Vetter144ecb92014-10-27 20:28:44 +0100325 * @event: optional pointer to a DRM event to signal upon completion of the
326 * state update
327 * @state: backpointer to global drm_atomic_state
Daniel Vetterd9b13622014-11-26 16:57:41 +0100328 *
329 * Note that the distinction between @enable and @active is rather subtile:
330 * Flipping @active while @enable is set without changing anything else may
331 * never return in a failure from the ->atomic_check callback. Userspace assumes
332 * that a DPMS On will always succeed. In other words: @enable controls resource
333 * assignment, @active controls the actual hardware state.
Daniel Vetter144ecb92014-10-27 20:28:44 +0100334 */
335struct drm_crtc_state {
Daniel Vetter07cc0ef2014-11-27 15:49:39 +0100336 struct drm_crtc *crtc;
337
Daniel Vettercc4ceb42014-07-25 21:30:38 +0200338 bool enable;
Daniel Vetterd9b13622014-11-26 16:57:41 +0100339 bool active;
Daniel Vetter144ecb92014-10-27 20:28:44 +0100340
Daniel Vetterc2fcd272014-11-05 00:14:14 +0100341 /* computed state bits used by helpers and drivers */
342 bool planes_changed : 1;
Daniel Vetter623369e2014-09-16 17:50:47 +0200343 bool mode_changed : 1;
Daniel Vettereab3bbe2015-01-22 16:36:21 +0100344 bool active_changed : 1;
Maarten Lankhorstfc596662015-07-21 13:28:57 +0200345 bool connectors_changed : 1;
Lionel Landwerlin5488dc12016-02-26 17:05:00 +0000346 bool color_mgmt_changed : 1;
Daniel Vetter623369e2014-09-16 17:50:47 +0200347
Rob Clark6ddd3882014-11-21 15:28:31 -0500348 /* attached planes bitmask:
349 * WARNING: transitional helpers do not maintain plane_mask so
350 * drivers not converted over to atomic helpers should not rely
351 * on plane_mask being accurate!
352 */
353 u32 plane_mask;
354
Maarten Lankhorst4cd9fa52016-01-04 12:53:18 +0100355 u32 connector_mask;
Maarten Lankhorste87a52b2016-01-28 15:04:58 +0100356 u32 encoder_mask;
Maarten Lankhorst4cd9fa52016-01-04 12:53:18 +0100357
Daniel Vetter623369e2014-09-16 17:50:47 +0200358 /* last_vblank_count: for vblank waits before cleanup */
359 u32 last_vblank_count;
Daniel Vetterc2fcd272014-11-05 00:14:14 +0100360
Daniel Vetter2f324b42014-10-29 11:13:47 +0100361 /* adjusted_mode: for use by helpers and drivers */
362 struct drm_display_mode adjusted_mode;
363
Daniel Vetter144ecb92014-10-27 20:28:44 +0100364 struct drm_display_mode mode;
365
Daniel Stone99cf4a22015-05-25 19:11:51 +0100366 /* blob property to expose current mode to atomic userspace */
367 struct drm_property_blob *mode_blob;
368
Lionel Landwerlin5488dc12016-02-26 17:05:00 +0000369 /* blob property to expose color management to userspace */
370 struct drm_property_blob *degamma_lut;
371 struct drm_property_blob *ctm;
372 struct drm_property_blob *gamma_lut;
373
Daniel Vetter144ecb92014-10-27 20:28:44 +0100374 struct drm_pending_vblank_event *event;
375
376 struct drm_atomic_state *state;
377};
Dave Airlief453ba02008-11-07 14:05:41 -0800378
379/**
Daniel Vetter3bf04012014-10-27 16:54:27 +0100380 * struct drm_crtc_funcs - control CRTCs for a given device
Dave Airlief453ba02008-11-07 14:05:41 -0800381 *
382 * The drm_crtc_funcs structure is the central CRTC management structure
383 * in the DRM. Each CRTC controls one or more connectors (note that the name
384 * CRTC is simply historical, a CRTC may control LVDS, VGA, DVI, TV out, etc.
385 * connectors, not just CRTs).
386 *
387 * Each driver is responsible for filling out this structure at startup time,
388 * in addition to providing other modesetting features, like i2c and DDC
389 * bus accessors.
390 */
391struct drm_crtc_funcs {
Daniel Vetter88548632015-12-04 09:45:48 +0100392 /**
393 * @reset:
394 *
395 * Reset CRTC hardware and software state to off. This function isn't
396 * called by the core directly, only through drm_mode_config_reset().
397 * It's not a helper hook only for historical reasons.
398 *
399 * Atomic drivers can use drm_atomic_helper_crtc_reset() to reset
400 * atomic state using this hook.
401 */
Chris Wilsoneb033552011-01-24 15:11:08 +0000402 void (*reset)(struct drm_crtc *crtc);
Dave Airlief453ba02008-11-07 14:05:41 -0800403
Daniel Vetterf6da8c62015-12-04 09:46:00 +0100404 /**
405 * @cursor_set:
406 *
407 * Update the cursor image. The cursor position is relative to the CRTC
408 * and can be partially or fully outside of the visible area.
409 *
410 * Note that contrary to all other KMS functions the legacy cursor entry
411 * points don't take a framebuffer object, but instead take directly a
412 * raw buffer object id from the driver's buffer manager (which is
413 * either GEM or TTM for current drivers).
414 *
415 * This entry point is deprecated, drivers should instead implement
416 * universal plane support and register a proper cursor plane using
417 * drm_crtc_init_with_planes().
418 *
419 * This callback is optional
420 *
421 * RETURNS:
422 *
423 * 0 on success or a negative error code on failure.
424 */
Dave Airlief453ba02008-11-07 14:05:41 -0800425 int (*cursor_set)(struct drm_crtc *crtc, struct drm_file *file_priv,
426 uint32_t handle, uint32_t width, uint32_t height);
Daniel Vetterf6da8c62015-12-04 09:46:00 +0100427
428 /**
429 * @cursor_set2:
430 *
431 * Update the cursor image, including hotspot information. The hotspot
432 * must not affect the cursor position in CRTC coordinates, but is only
433 * meant as a hint for virtualized display hardware to coordinate the
434 * guests and hosts cursor position. The cursor hotspot is relative to
435 * the cursor image. Otherwise this works exactly like @cursor_set.
436 *
437 * This entry point is deprecated, drivers should instead implement
438 * universal plane support and register a proper cursor plane using
439 * drm_crtc_init_with_planes().
440 *
441 * This callback is optional.
442 *
443 * RETURNS:
444 *
445 * 0 on success or a negative error code on failure.
446 */
Dave Airlie4c813d42013-06-20 11:48:52 +1000447 int (*cursor_set2)(struct drm_crtc *crtc, struct drm_file *file_priv,
448 uint32_t handle, uint32_t width, uint32_t height,
449 int32_t hot_x, int32_t hot_y);
Daniel Vetterf6da8c62015-12-04 09:46:00 +0100450
451 /**
452 * @cursor_move:
453 *
454 * Update the cursor position. The cursor does not need to be visible
455 * when this hook is called.
456 *
457 * This entry point is deprecated, drivers should instead implement
458 * universal plane support and register a proper cursor plane using
459 * drm_crtc_init_with_planes().
460 *
461 * This callback is optional.
462 *
463 * RETURNS:
464 *
465 * 0 on success or a negative error code on failure.
466 */
Dave Airlief453ba02008-11-07 14:05:41 -0800467 int (*cursor_move)(struct drm_crtc *crtc, int x, int y);
468
Daniel Vetterf6da8c62015-12-04 09:46:00 +0100469 /**
470 * @gamma_set:
471 *
472 * Set gamma on the CRTC.
473 *
474 * This callback is optional.
475 *
476 * NOTE:
477 *
478 * Drivers that support gamma tables and also fbdev emulation through
479 * the provided helper library need to take care to fill out the gamma
480 * hooks for both. Currently there's a bit an unfortunate duplication
481 * going on, which should eventually be unified to just one set of
482 * hooks.
483 */
Maarten Lankhorst7ea77282016-06-07 12:49:30 +0200484 int (*gamma_set)(struct drm_crtc *crtc, u16 *r, u16 *g, u16 *b,
485 uint32_t size);
Daniel Vetter88548632015-12-04 09:45:48 +0100486
487 /**
488 * @destroy:
489 *
490 * Clean up plane resources. This is only called at driver unload time
491 * through drm_mode_config_cleanup() since a CRTC cannot be hotplugged
492 * in DRM.
493 */
Dave Airlief453ba02008-11-07 14:05:41 -0800494 void (*destroy)(struct drm_crtc *crtc);
495
Daniel Vetterf6da8c62015-12-04 09:46:00 +0100496 /**
497 * @set_config:
498 *
499 * This is the main legacy entry point to change the modeset state on a
500 * CRTC. All the details of the desired configuration are passed in a
501 * struct &drm_mode_set - see there for details.
502 *
503 * Drivers implementing atomic modeset should use
504 * drm_atomic_helper_set_config() to implement this hook.
505 *
506 * RETURNS:
507 *
508 * 0 on success or a negative error code on failure.
509 */
Dave Airlief453ba02008-11-07 14:05:41 -0800510 int (*set_config)(struct drm_mode_set *set);
Kristian Høgsbergd91d8a32009-11-17 12:43:55 -0500511
Daniel Vetterf6da8c62015-12-04 09:46:00 +0100512 /**
513 * @page_flip:
514 *
515 * Legacy entry point to schedule a flip to the given framebuffer.
516 *
517 * Page flipping is a synchronization mechanism that replaces the frame
518 * buffer being scanned out by the CRTC with a new frame buffer during
519 * vertical blanking, avoiding tearing (except when requested otherwise
520 * through the DRM_MODE_PAGE_FLIP_ASYNC flag). When an application
521 * requests a page flip the DRM core verifies that the new frame buffer
522 * is large enough to be scanned out by the CRTC in the currently
523 * configured mode and then calls the CRTC ->page_flip() operation with a
524 * pointer to the new frame buffer.
525 *
526 * The driver must wait for any pending rendering to the new framebuffer
527 * to complete before executing the flip. It should also wait for any
528 * pending rendering from other drivers if the underlying buffer is a
529 * shared dma-buf.
530 *
531 * An application can request to be notified when the page flip has
532 * completed. The drm core will supply a struct &drm_event in the event
533 * parameter in this case. This can be handled by the
534 * drm_crtc_send_vblank_event() function, which the driver should call on
535 * the provided event upon completion of the flip. Note that if
536 * the driver supports vblank signalling and timestamping the vblank
537 * counters and timestamps must agree with the ones returned from page
538 * flip events. With the current vblank helper infrastructure this can
539 * be achieved by holding a vblank reference while the page flip is
540 * pending, acquired through drm_crtc_vblank_get() and released with
541 * drm_crtc_vblank_put(). Drivers are free to implement their own vblank
542 * counter and timestamp tracking though, e.g. if they have accurate
543 * timestamp registers in hardware.
544 *
545 * FIXME:
546 *
547 * Up to that point drivers need to manage events themselves and can use
548 * even->base.list freely for that. Specifically they need to ensure
549 * that they don't send out page flip (or vblank) events for which the
550 * corresponding drm file has been closed already. The drm core
551 * unfortunately does not (yet) take care of that. Therefore drivers
552 * currently must clean up and release pending events in their
553 * ->preclose driver function.
554 *
555 * This callback is optional.
556 *
557 * NOTE:
558 *
559 * Very early versions of the KMS ABI mandated that the driver must
560 * block (but not reject) any rendering to the old framebuffer until the
561 * flip operation has completed and the old framebuffer is no longer
562 * visible. This requirement has been lifted, and userspace is instead
563 * expected to request delivery of an event and wait with recycling old
564 * buffers until such has been received.
565 *
566 * RETURNS:
567 *
568 * 0 on success or a negative error code on failure. Note that if a
569 * ->page_flip() operation is already pending the callback should return
570 * -EBUSY. Pageflips on a disabled CRTC (either by setting a NULL mode
571 * or just runtime disabled through DPMS respectively the new atomic
Daniel Vetter4cba6852015-12-08 09:49:20 +0100572 * "ACTIVE" state) should result in an -EINVAL error code. Note that
573 * drm_atomic_helper_page_flip() checks this already for atomic drivers.
Kristian Høgsbergd91d8a32009-11-17 12:43:55 -0500574 */
575 int (*page_flip)(struct drm_crtc *crtc,
576 struct drm_framebuffer *fb,
Keith Packarded8d1972013-07-22 18:49:58 -0700577 struct drm_pending_vblank_event *event,
578 uint32_t flags);
Paulo Zanonibffd9de02012-05-15 18:09:05 -0300579
Daniel Vetter88548632015-12-04 09:45:48 +0100580 /**
581 * @set_property:
582 *
583 * This is the legacy entry point to update a property attached to the
584 * CRTC.
585 *
586 * Drivers implementing atomic modeset should use
587 * drm_atomic_helper_crtc_set_property() to implement this hook.
588 *
589 * This callback is optional if the driver does not support any legacy
590 * driver-private properties.
591 *
592 * RETURNS:
593 *
594 * 0 on success or a negative error code on failure.
595 */
Paulo Zanonibffd9de02012-05-15 18:09:05 -0300596 int (*set_property)(struct drm_crtc *crtc,
597 struct drm_property *property, uint64_t val);
Daniel Vetter144ecb92014-10-27 20:28:44 +0100598
Daniel Vetter88548632015-12-04 09:45:48 +0100599 /**
600 * @atomic_duplicate_state:
601 *
602 * Duplicate the current atomic state for this CRTC and return it.
603 * The core and helpers gurantee that any atomic state duplicated with
604 * this hook and still owned by the caller (i.e. not transferred to the
605 * driver by calling ->atomic_commit() from struct
606 * &drm_mode_config_funcs) will be cleaned up by calling the
607 * @atomic_destroy_state hook in this structure.
608 *
609 * Atomic drivers which don't subclass struct &drm_crtc should use
610 * drm_atomic_helper_crtc_duplicate_state(). Drivers that subclass the
611 * state structure to extend it with driver-private state should use
612 * __drm_atomic_helper_crtc_duplicate_state() to make sure shared state is
613 * duplicated in a consistent fashion across drivers.
614 *
615 * It is an error to call this hook before crtc->state has been
616 * initialized correctly.
617 *
618 * NOTE:
619 *
620 * If the duplicate state references refcounted resources this hook must
621 * acquire a reference for each of them. The driver must release these
622 * references again in @atomic_destroy_state.
623 *
624 * RETURNS:
625 *
626 * Duplicated atomic state or NULL when the allocation failed.
627 */
Daniel Vetter144ecb92014-10-27 20:28:44 +0100628 struct drm_crtc_state *(*atomic_duplicate_state)(struct drm_crtc *crtc);
Daniel Vetter88548632015-12-04 09:45:48 +0100629
630 /**
631 * @atomic_destroy_state:
632 *
633 * Destroy a state duplicated with @atomic_duplicate_state and release
634 * or unreference all resources it references
635 */
Daniel Vetter144ecb92014-10-27 20:28:44 +0100636 void (*atomic_destroy_state)(struct drm_crtc *crtc,
Daniel Vettercc4ceb42014-07-25 21:30:38 +0200637 struct drm_crtc_state *state);
Daniel Vetter88548632015-12-04 09:45:48 +0100638
639 /**
640 * @atomic_set_property:
641 *
642 * Decode a driver-private property value and store the decoded value
643 * into the passed-in state structure. Since the atomic core decodes all
644 * standardized properties (even for extensions beyond the core set of
645 * properties which might not be implemented by all drivers) this
646 * requires drivers to subclass the state structure.
647 *
648 * Such driver-private properties should really only be implemented for
649 * truly hardware/vendor specific state. Instead it is preferred to
650 * standardize atomic extension and decode the properties used to expose
651 * such an extension in the core.
652 *
653 * Do not call this function directly, use
654 * drm_atomic_crtc_set_property() instead.
655 *
656 * This callback is optional if the driver does not support any
657 * driver-private atomic properties.
658 *
659 * NOTE:
660 *
661 * This function is called in the state assembly phase of atomic
662 * modesets, which can be aborted for any reason (including on
663 * userspace's request to just check whether a configuration would be
664 * possible). Drivers MUST NOT touch any persistent state (hardware or
665 * software) or data structures except the passed in @state parameter.
666 *
667 * Also since userspace controls in which order properties are set this
668 * function must not do any input validation (since the state update is
669 * incomplete and hence likely inconsistent). Instead any such input
670 * validation must be done in the various atomic_check callbacks.
671 *
672 * RETURNS:
673 *
674 * 0 if the property has been found, -EINVAL if the property isn't
675 * implemented by the driver (which should never happen, the core only
676 * asks for properties attached to this CRTC). No other validation is
677 * allowed by the driver. The core already checks that the property
678 * value is within the range (integer, valid enum value, ...) the driver
679 * set when registering the property.
680 */
Daniel Vetter144ecb92014-10-27 20:28:44 +0100681 int (*atomic_set_property)(struct drm_crtc *crtc,
682 struct drm_crtc_state *state,
683 struct drm_property *property,
684 uint64_t val);
Daniel Vetter88548632015-12-04 09:45:48 +0100685 /**
686 * @atomic_get_property:
687 *
688 * Reads out the decoded driver-private property. This is used to
Daniel Vetterc6b0ca32015-12-04 09:46:01 +0100689 * implement the GETCRTC IOCTL.
Daniel Vetter88548632015-12-04 09:45:48 +0100690 *
691 * Do not call this function directly, use
692 * drm_atomic_crtc_get_property() instead.
693 *
694 * This callback is optional if the driver does not support any
695 * driver-private atomic properties.
696 *
697 * RETURNS:
698 *
699 * 0 on success, -EINVAL if the property isn't implemented by the
700 * driver (which should never happen, the core only asks for
701 * properties attached to this CRTC).
702 */
Rob Clarkac9c9252014-12-18 16:01:47 -0500703 int (*atomic_get_property)(struct drm_crtc *crtc,
704 const struct drm_crtc_state *state,
705 struct drm_property *property,
706 uint64_t *val);
Benjamin Gaignard79190ea2016-06-21 16:37:09 +0200707
708 /**
709 * @late_register:
710 *
711 * This optional hook can be used to register additional userspace
712 * interfaces attached to the crtc like debugfs interfaces.
713 * It is called late in the driver load sequence from drm_dev_register().
714 * Everything added from this callback should be unregistered in
715 * the early_unregister callback.
716 *
717 * Returns:
718 *
719 * 0 on success, or a negative error code on failure.
720 */
721 int (*late_register)(struct drm_crtc *crtc);
722
723 /**
724 * @early_unregister:
725 *
726 * This optional hook should be used to unregister the additional
727 * userspace interfaces attached to the crtc from
728 * late_unregister(). It is called from drm_dev_unregister(),
729 * early in the driver unload sequence to disable userspace access
730 * before data structures are torndown.
731 */
732 void (*early_unregister)(struct drm_crtc *crtc);
Dave Airlief453ba02008-11-07 14:05:41 -0800733};
734
735/**
Daniel Vetter3bf04012014-10-27 16:54:27 +0100736 * struct drm_crtc - central CRTC control structure
Jesse Barnes77491632011-11-07 12:03:14 -0800737 * @dev: parent DRM device
Daniel Vetter2c0c33d2014-10-27 20:19:38 +0100738 * @port: OF node used by drm_of_find_possible_crtcs()
Jesse Barnes77491632011-11-07 12:03:14 -0800739 * @head: list management
Daniel Vetterac3ba4a2016-05-31 23:11:10 +0200740 * @name: human readable name, can be overwritten by the driver
Rob Clark51fd3712013-11-19 12:10:12 -0500741 * @mutex: per-CRTC locking
Jesse Barnes77491632011-11-07 12:03:14 -0800742 * @base: base KMS object for ID tracking etc.
Matt Ropere13161a2014-04-01 15:22:38 -0700743 * @primary: primary plane for this CRTC
744 * @cursor: cursor plane for this CRTC
Daniel Vetter2c0c33d2014-10-27 20:19:38 +0100745 * @cursor_x: current x position of the cursor, used for universal cursor planes
746 * @cursor_y: current y position of the cursor, used for universal cursor planes
Dave Airlief453ba02008-11-07 14:05:41 -0800747 * @enabled: is this CRTC enabled?
Jesse Barnes77491632011-11-07 12:03:14 -0800748 * @mode: current mode timings
749 * @hwmode: mode timings as programmed to hw regs
Dave Airlief453ba02008-11-07 14:05:41 -0800750 * @x: x position on screen
751 * @y: y position on screen
Dave Airlief453ba02008-11-07 14:05:41 -0800752 * @funcs: CRTC control functions
Jesse Barnes77491632011-11-07 12:03:14 -0800753 * @gamma_size: size of gamma ramp
754 * @gamma_store: gamma ramp values
Jesse Barnes77491632011-11-07 12:03:14 -0800755 * @helper_private: mid-layer private data
Paulo Zanonibffd9de02012-05-15 18:09:05 -0300756 * @properties: property tracking for this CRTC
Dave Airlief453ba02008-11-07 14:05:41 -0800757 *
758 * Each CRTC may have one or more connectors associated with it. This structure
759 * allows the CRTC to be controlled.
760 */
761struct drm_crtc {
762 struct drm_device *dev;
Russell King7e435aa2014-06-15 11:07:12 +0100763 struct device_node *port;
Dave Airlief453ba02008-11-07 14:05:41 -0800764 struct list_head head;
765
Ville Syrjäläfa3ab4c2015-12-08 18:41:53 +0200766 char *name;
767
Daniel Vetterac3ba4a2016-05-31 23:11:10 +0200768 /**
769 * @mutex:
Daniel Vetter29494c12012-12-02 02:18:25 +0100770 *
771 * This provides a read lock for the overall crtc state (mode, dpms
772 * state, ...) and a write lock for everything which can be update
Daniel Vetterac3ba4a2016-05-31 23:11:10 +0200773 * without a full modeset (fb, cursor data, crtc properties ...). Full
774 * modeset also need to grab dev->mode_config.connection_mutex.
Daniel Vetter29494c12012-12-02 02:18:25 +0100775 */
Rob Clark51fd3712013-11-19 12:10:12 -0500776 struct drm_modeset_lock mutex;
Daniel Vetter29494c12012-12-02 02:18:25 +0100777
Dave Airlief453ba02008-11-07 14:05:41 -0800778 struct drm_mode_object base;
779
Matt Ropere13161a2014-04-01 15:22:38 -0700780 /* primary and cursor planes for CRTC */
781 struct drm_plane *primary;
782 struct drm_plane *cursor;
783
Chris Wilson490d3d12016-05-27 20:05:00 +0100784 /* position inside the mode_config.list, can be used as a [] idx */
785 unsigned index;
786
Matt Roper161d0dc2014-06-10 08:28:10 -0700787 /* position of cursor plane on crtc */
788 int cursor_x;
789 int cursor_y;
790
Dave Airlief453ba02008-11-07 14:05:41 -0800791 bool enabled;
792
Mario Kleiner27641c32010-10-23 04:20:23 +0200793 /* Requested mode from modesetting. */
Dave Airlief453ba02008-11-07 14:05:41 -0800794 struct drm_display_mode mode;
795
Mario Kleiner27641c32010-10-23 04:20:23 +0200796 /* Programmed mode in hw, after adjustments for encoders,
797 * crtc, panel scaling etc. Needed for timestamping etc.
798 */
799 struct drm_display_mode hwmode;
800
Dave Airlief453ba02008-11-07 14:05:41 -0800801 int x, y;
Dave Airlief453ba02008-11-07 14:05:41 -0800802 const struct drm_crtc_funcs *funcs;
803
Lionel Landwerlin5488dc12016-02-26 17:05:00 +0000804 /* Legacy FB CRTC gamma size for reporting to userspace */
Dave Airlief453ba02008-11-07 14:05:41 -0800805 uint32_t gamma_size;
806 uint16_t *gamma_store;
807
808 /* if you are using the helper */
Daniel Vetter4490d4c2015-12-04 09:45:45 +0100809 const struct drm_crtc_helper_funcs *helper_private;
Paulo Zanonibffd9de02012-05-15 18:09:05 -0300810
811 struct drm_object_properties properties;
Daniel Vetterd059f652014-07-25 18:07:40 +0200812
Daniel Vetter3b24f7d2016-06-08 14:19:00 +0200813 /**
814 * @state:
815 *
816 * Current atomic state for this CRTC.
817 */
Daniel Vetter144ecb92014-10-27 20:28:44 +0100818 struct drm_crtc_state *state;
819
Daniel Vetter3b24f7d2016-06-08 14:19:00 +0200820 /**
821 * @commit_list:
822 *
823 * List of &drm_crtc_commit structures tracking pending commits.
824 * Protected by @commit_lock. This list doesn't hold its own full
825 * reference, but burrows it from the ongoing commit. Commit entries
826 * must be removed from this list once the commit is fully completed,
827 * but before it's correspoding &drm_atomic_state gets destroyed.
828 */
829 struct list_head commit_list;
830
831 /**
832 * @commit_lock:
833 *
834 * Spinlock to protect @commit_list.
835 */
836 spinlock_t commit_lock;
837
838 /**
839 * @acquire_ctx:
840 *
841 * Per-CRTC implicit acquire context used by atomic drivers for legacy
842 * IOCTLs, so that atomic drivers can get at the locking acquire
843 * context.
Daniel Vetterd059f652014-07-25 18:07:40 +0200844 */
845 struct drm_modeset_acquire_ctx *acquire_ctx;
Dave Airlief453ba02008-11-07 14:05:41 -0800846};
847
Daniel Vetter144ecb92014-10-27 20:28:44 +0100848/**
849 * struct drm_connector_state - mutable connector state
Daniel Vetter07cc0ef2014-11-27 15:49:39 +0100850 * @connector: backpointer to the connector
Daniel Vettercc4ceb42014-07-25 21:30:38 +0200851 * @crtc: CRTC to connect connector to, NULL if disabled
Daniel Vetter623369e2014-09-16 17:50:47 +0200852 * @best_encoder: can be used by helpers and drivers to select the encoder
Daniel Vetter144ecb92014-10-27 20:28:44 +0100853 * @state: backpointer to global drm_atomic_state
854 */
855struct drm_connector_state {
Daniel Vetter07cc0ef2014-11-27 15:49:39 +0100856 struct drm_connector *connector;
857
Rob Clark6ddd3882014-11-21 15:28:31 -0500858 struct drm_crtc *crtc; /* do not write directly, use drm_atomic_set_crtc_for_connector() */
Daniel Vetter144ecb92014-10-27 20:28:44 +0100859
Daniel Vetter623369e2014-09-16 17:50:47 +0200860 struct drm_encoder *best_encoder;
861
Daniel Vetter144ecb92014-10-27 20:28:44 +0100862 struct drm_atomic_state *state;
863};
Dave Airlief453ba02008-11-07 14:05:41 -0800864
865/**
Daniel Vetter3bf04012014-10-27 16:54:27 +0100866 * struct drm_connector_funcs - control connectors on a given device
Daniel Vetter144ecb92014-10-27 20:28:44 +0100867 *
Dave Airlief453ba02008-11-07 14:05:41 -0800868 * Each CRTC may have one or more connectors attached to it. The functions
869 * below allow the core DRM code to control connectors, enumerate available modes,
870 * etc.
871 */
872struct drm_connector_funcs {
Daniel Vetter6fe14ac2015-12-04 09:45:58 +0100873 /**
874 * @dpms:
875 *
876 * Legacy entry point to set the per-connector DPMS state. Legacy DPMS
877 * is exposed as a standard property on the connector, but diverted to
878 * this callback in the drm core. Note that atomic drivers don't
879 * implement the 4 level DPMS support on the connector any more, but
880 * instead only have an on/off "ACTIVE" property on the CRTC object.
881 *
882 * Drivers implementing atomic modeset should use
883 * drm_atomic_helper_connector_dpms() to implement this hook.
884 *
885 * RETURNS:
886 *
887 * 0 on success or a negative error code on failure.
888 */
Maarten Lankhorst9a69a9a2015-07-21 11:34:55 +0200889 int (*dpms)(struct drm_connector *connector, int mode);
Daniel Vetter88548632015-12-04 09:45:48 +0100890
891 /**
892 * @reset:
893 *
894 * Reset connector hardware and software state to off. This function isn't
895 * called by the core directly, only through drm_mode_config_reset().
896 * It's not a helper hook only for historical reasons.
897 *
898 * Atomic drivers can use drm_atomic_helper_connector_reset() to reset
899 * atomic state using this hook.
900 */
Chris Wilsoneb033552011-01-24 15:11:08 +0000901 void (*reset)(struct drm_connector *connector);
Chris Wilson930a9e22010-09-14 11:07:23 +0100902
Daniel Vetter6fe14ac2015-12-04 09:45:58 +0100903 /**
904 * @detect:
905 *
906 * Check to see if anything is attached to the connector. The parameter
907 * force is set to false whilst polling, true when checking the
908 * connector due to a user request. force can be used by the driver to
909 * avoid expensive, destructive operations during automated probing.
910 *
911 * FIXME:
912 *
913 * Note that this hook is only called by the probe helper. It's not in
914 * the helper library vtable purely for historical reasons. The only DRM
915 * core entry point to probe connector state is @fill_modes.
916 *
917 * RETURNS:
918 *
919 * drm_connector_status indicating the connector's status.
Chris Wilson930a9e22010-09-14 11:07:23 +0100920 */
Chris Wilson7b334fc2010-09-09 23:51:02 +0100921 enum drm_connector_status (*detect)(struct drm_connector *connector,
Chris Wilson930a9e22010-09-14 11:07:23 +0100922 bool force);
Daniel Vetter6fe14ac2015-12-04 09:45:58 +0100923
924 /**
925 * @force:
926 *
927 * This function is called to update internal encoder state when the
928 * connector is forced to a certain state by userspace, either through
929 * the sysfs interfaces or on the kernel cmdline. In that case the
930 * @detect callback isn't called.
931 *
932 * FIXME:
933 *
934 * Note that this hook is only called by the probe helper. It's not in
935 * the helper library vtable purely for historical reasons. The only DRM
936 * core entry point to probe connector state is @fill_modes.
937 */
938 void (*force)(struct drm_connector *connector);
939
940 /**
941 * @fill_modes:
942 *
943 * Entry point for output detection and basic mode validation. The
944 * driver should reprobe the output if needed (e.g. when hotplug
945 * handling is unreliable), add all detected modes to connector->modes
946 * and filter out any the device can't support in any configuration. It
947 * also needs to filter out any modes wider or higher than the
948 * parameters max_width and max_height indicate.
949 *
950 * The drivers must also prune any modes no longer valid from
951 * connector->modes. Furthermore it must update connector->status and
952 * connector->edid. If no EDID has been received for this output
953 * connector->edid must be NULL.
954 *
955 * Drivers using the probe helpers should use
956 * drm_helper_probe_single_connector_modes() or
957 * drm_helper_probe_single_connector_modes_nomerge() to implement this
958 * function.
959 *
960 * RETURNS:
961 *
962 * The number of modes detected and filled into connector->modes.
963 */
Jesse Barnes40a518d2009-01-12 12:05:32 -0800964 int (*fill_modes)(struct drm_connector *connector, uint32_t max_width, uint32_t max_height);
Daniel Vetter88548632015-12-04 09:45:48 +0100965
966 /**
967 * @set_property:
968 *
969 * This is the legacy entry point to update a property attached to the
970 * connector.
971 *
972 * Drivers implementing atomic modeset should use
973 * drm_atomic_helper_connector_set_property() to implement this hook.
974 *
975 * This callback is optional if the driver does not support any legacy
976 * driver-private properties.
977 *
978 * RETURNS:
979 *
980 * 0 on success or a negative error code on failure.
981 */
Dave Airlief453ba02008-11-07 14:05:41 -0800982 int (*set_property)(struct drm_connector *connector, struct drm_property *property,
983 uint64_t val);
Daniel Vetter88548632015-12-04 09:45:48 +0100984
985 /**
Chris Wilsonaaf285e2016-06-15 13:17:47 +0100986 * @late_register:
987 *
988 * This optional hook can be used to register additional userspace
989 * interfaces attached to the connector, light backlight control, i2c,
990 * DP aux or similar interfaces. It is called late in the driver load
991 * sequence from drm_connector_register() when registering all the
992 * core drm connector interfaces. Everything added from this callback
993 * should be unregistered in the early_unregister callback.
994 *
995 * Returns:
996 *
997 * 0 on success, or a negative error code on failure.
998 */
999 int (*late_register)(struct drm_connector *connector);
1000
1001 /**
1002 * @early_unregister:
1003 *
1004 * This optional hook should be used to unregister the additional
1005 * userspace interfaces attached to the connector from
1006 * late_unregister(). It is called from drm_connector_unregister(),
1007 * early in the driver unload sequence to disable userspace access
1008 * before data structures are torndown.
1009 */
1010 void (*early_unregister)(struct drm_connector *connector);
1011
1012 /**
Daniel Vetter88548632015-12-04 09:45:48 +01001013 * @destroy:
1014 *
1015 * Clean up connector resources. This is called at driver unload time
1016 * through drm_mode_config_cleanup(). It can also be called at runtime
1017 * when a connector is being hot-unplugged for drivers that support
1018 * connector hotplugging (e.g. DisplayPort MST).
1019 */
Dave Airlief453ba02008-11-07 14:05:41 -08001020 void (*destroy)(struct drm_connector *connector);
Daniel Vetter144ecb92014-10-27 20:28:44 +01001021
Daniel Vetter88548632015-12-04 09:45:48 +01001022 /**
1023 * @atomic_duplicate_state:
1024 *
1025 * Duplicate the current atomic state for this connector and return it.
1026 * The core and helpers gurantee that any atomic state duplicated with
1027 * this hook and still owned by the caller (i.e. not transferred to the
1028 * driver by calling ->atomic_commit() from struct
1029 * &drm_mode_config_funcs) will be cleaned up by calling the
1030 * @atomic_destroy_state hook in this structure.
1031 *
1032 * Atomic drivers which don't subclass struct &drm_connector_state should use
1033 * drm_atomic_helper_connector_duplicate_state(). Drivers that subclass the
1034 * state structure to extend it with driver-private state should use
1035 * __drm_atomic_helper_connector_duplicate_state() to make sure shared state is
1036 * duplicated in a consistent fashion across drivers.
1037 *
1038 * It is an error to call this hook before connector->state has been
1039 * initialized correctly.
1040 *
1041 * NOTE:
1042 *
1043 * If the duplicate state references refcounted resources this hook must
1044 * acquire a reference for each of them. The driver must release these
1045 * references again in @atomic_destroy_state.
1046 *
1047 * RETURNS:
1048 *
1049 * Duplicated atomic state or NULL when the allocation failed.
1050 */
Daniel Vetter144ecb92014-10-27 20:28:44 +01001051 struct drm_connector_state *(*atomic_duplicate_state)(struct drm_connector *connector);
Daniel Vetter88548632015-12-04 09:45:48 +01001052
1053 /**
1054 * @atomic_destroy_state:
1055 *
1056 * Destroy a state duplicated with @atomic_duplicate_state and release
1057 * or unreference all resources it references
1058 */
Daniel Vetter144ecb92014-10-27 20:28:44 +01001059 void (*atomic_destroy_state)(struct drm_connector *connector,
Daniel Vettercc4ceb42014-07-25 21:30:38 +02001060 struct drm_connector_state *state);
Daniel Vetter88548632015-12-04 09:45:48 +01001061
1062 /**
1063 * @atomic_set_property:
1064 *
1065 * Decode a driver-private property value and store the decoded value
1066 * into the passed-in state structure. Since the atomic core decodes all
1067 * standardized properties (even for extensions beyond the core set of
1068 * properties which might not be implemented by all drivers) this
1069 * requires drivers to subclass the state structure.
1070 *
1071 * Such driver-private properties should really only be implemented for
1072 * truly hardware/vendor specific state. Instead it is preferred to
1073 * standardize atomic extension and decode the properties used to expose
1074 * such an extension in the core.
1075 *
1076 * Do not call this function directly, use
1077 * drm_atomic_connector_set_property() instead.
1078 *
1079 * This callback is optional if the driver does not support any
1080 * driver-private atomic properties.
1081 *
1082 * NOTE:
1083 *
1084 * This function is called in the state assembly phase of atomic
1085 * modesets, which can be aborted for any reason (including on
1086 * userspace's request to just check whether a configuration would be
1087 * possible). Drivers MUST NOT touch any persistent state (hardware or
1088 * software) or data structures except the passed in @state parameter.
1089 *
1090 * Also since userspace controls in which order properties are set this
1091 * function must not do any input validation (since the state update is
1092 * incomplete and hence likely inconsistent). Instead any such input
1093 * validation must be done in the various atomic_check callbacks.
1094 *
1095 * RETURNS:
1096 *
1097 * 0 if the property has been found, -EINVAL if the property isn't
1098 * implemented by the driver (which shouldn't ever happen, the core only
1099 * asks for properties attached to this connector). No other validation
1100 * is allowed by the driver. The core already checks that the property
1101 * value is within the range (integer, valid enum value, ...) the driver
1102 * set when registering the property.
1103 */
Daniel Vetter144ecb92014-10-27 20:28:44 +01001104 int (*atomic_set_property)(struct drm_connector *connector,
1105 struct drm_connector_state *state,
1106 struct drm_property *property,
1107 uint64_t val);
Daniel Vetter88548632015-12-04 09:45:48 +01001108
1109 /**
1110 * @atomic_get_property:
1111 *
1112 * Reads out the decoded driver-private property. This is used to
Daniel Vetterc6b0ca32015-12-04 09:46:01 +01001113 * implement the GETCONNECTOR IOCTL.
Daniel Vetter88548632015-12-04 09:45:48 +01001114 *
1115 * Do not call this function directly, use
1116 * drm_atomic_connector_get_property() instead.
1117 *
1118 * This callback is optional if the driver does not support any
1119 * driver-private atomic properties.
1120 *
1121 * RETURNS:
1122 *
1123 * 0 on success, -EINVAL if the property isn't implemented by the
1124 * driver (which shouldn't ever happen, the core only asks for
1125 * properties attached to this connector).
1126 */
Rob Clarkac9c9252014-12-18 16:01:47 -05001127 int (*atomic_get_property)(struct drm_connector *connector,
1128 const struct drm_connector_state *state,
1129 struct drm_property *property,
1130 uint64_t *val);
Dave Airlief453ba02008-11-07 14:05:41 -08001131};
1132
Jesse Barnes6c3db922011-11-07 12:03:16 -08001133/**
Daniel Vetter3bf04012014-10-27 16:54:27 +01001134 * struct drm_encoder_funcs - encoder controls
Jesse Barnes6c3db922011-11-07 12:03:16 -08001135 *
1136 * Encoders sit between CRTCs and connectors.
1137 */
Dave Airlief453ba02008-11-07 14:05:41 -08001138struct drm_encoder_funcs {
Daniel Vetter88548632015-12-04 09:45:48 +01001139 /**
1140 * @reset:
1141 *
1142 * Reset encoder hardware and software state to off. This function isn't
1143 * called by the core directly, only through drm_mode_config_reset().
1144 * It's not a helper hook only for historical reasons.
1145 */
Chris Wilsoneb033552011-01-24 15:11:08 +00001146 void (*reset)(struct drm_encoder *encoder);
Daniel Vetter88548632015-12-04 09:45:48 +01001147
1148 /**
1149 * @destroy:
1150 *
1151 * Clean up encoder resources. This is only called at driver unload time
1152 * through drm_mode_config_cleanup() since an encoder cannot be
1153 * hotplugged in DRM.
1154 */
Dave Airlief453ba02008-11-07 14:05:41 -08001155 void (*destroy)(struct drm_encoder *encoder);
Benjamin Gaignard79190ea2016-06-21 16:37:09 +02001156
1157 /**
1158 * @late_register:
1159 *
1160 * This optional hook can be used to register additional userspace
1161 * interfaces attached to the encoder like debugfs interfaces.
1162 * It is called late in the driver load sequence from drm_dev_register().
1163 * Everything added from this callback should be unregistered in
1164 * the early_unregister callback.
1165 *
1166 * Returns:
1167 *
1168 * 0 on success, or a negative error code on failure.
1169 */
1170 int (*late_register)(struct drm_encoder *encoder);
1171
1172 /**
1173 * @early_unregister:
1174 *
1175 * This optional hook should be used to unregister the additional
1176 * userspace interfaces attached to the encoder from
1177 * late_unregister(). It is called from drm_dev_unregister(),
1178 * early in the driver unload sequence to disable userspace access
1179 * before data structures are torndown.
1180 */
1181 void (*early_unregister)(struct drm_encoder *encoder);
Dave Airlief453ba02008-11-07 14:05:41 -08001182};
1183
Ben Skeggsafe887d2012-01-12 16:00:57 +10001184#define DRM_CONNECTOR_MAX_ENCODER 3
Dave Airlief453ba02008-11-07 14:05:41 -08001185
1186/**
Daniel Vetter3bf04012014-10-27 16:54:27 +01001187 * struct drm_encoder - central DRM encoder structure
Jesse Barnesdb3e4492011-11-07 12:03:17 -08001188 * @dev: parent DRM device
1189 * @head: list management
1190 * @base: base KMS object
Daniel Vetterac3ba4a2016-05-31 23:11:10 +02001191 * @name: human readable name, can be overwritten by the driver
Jesse Barnesdb3e4492011-11-07 12:03:17 -08001192 * @encoder_type: one of the %DRM_MODE_ENCODER_<foo> types in drm_mode.h
1193 * @possible_crtcs: bitmask of potential CRTC bindings
1194 * @possible_clones: bitmask of potential sibling encoders for cloning
1195 * @crtc: currently bound CRTC
Sean Paul3b336ec2013-08-14 16:47:37 -04001196 * @bridge: bridge associated to the encoder
Jesse Barnesdb3e4492011-11-07 12:03:17 -08001197 * @funcs: control functions
1198 * @helper_private: mid-layer private data
1199 *
1200 * CRTCs drive pixels to encoders, which convert them into signals
1201 * appropriate for a given connector or set of connectors.
Dave Airlief453ba02008-11-07 14:05:41 -08001202 */
1203struct drm_encoder {
1204 struct drm_device *dev;
1205 struct list_head head;
1206
1207 struct drm_mode_object base;
Jani Nikulae5748942014-05-14 16:58:20 +03001208 char *name;
Dave Airlief453ba02008-11-07 14:05:41 -08001209 int encoder_type;
Chris Wilson490d3d12016-05-27 20:05:00 +01001210
1211 /* position inside the mode_config.list, can be used as a [] idx */
1212 unsigned index;
1213
Dave Airlief453ba02008-11-07 14:05:41 -08001214 uint32_t possible_crtcs;
1215 uint32_t possible_clones;
1216
1217 struct drm_crtc *crtc;
Sean Paul3b336ec2013-08-14 16:47:37 -04001218 struct drm_bridge *bridge;
Dave Airlief453ba02008-11-07 14:05:41 -08001219 const struct drm_encoder_funcs *funcs;
Daniel Vetter4490d4c2015-12-04 09:45:45 +01001220 const struct drm_encoder_helper_funcs *helper_private;
Dave Airlief453ba02008-11-07 14:05:41 -08001221};
1222
Dave Airlieeb1f8e42010-05-07 06:42:51 +00001223/* should we poll this connector for connects and disconnects */
1224/* hot plug detectable */
1225#define DRM_CONNECTOR_POLL_HPD (1 << 0)
1226/* poll for connections */
1227#define DRM_CONNECTOR_POLL_CONNECT (1 << 1)
1228/* can cleanly poll for disconnections without flickering the screen */
1229/* DACs should rarely do this without a lot of testing */
1230#define DRM_CONNECTOR_POLL_DISCONNECT (1 << 2)
1231
Wu Fengguang76adaa342011-09-05 14:23:20 +08001232#define MAX_ELD_BYTES 128
1233
Dave Airlief453ba02008-11-07 14:05:41 -08001234/**
Daniel Vetter3bf04012014-10-27 16:54:27 +01001235 * struct drm_connector - central DRM connector control structure
Jesse Barnes72252542011-11-07 12:03:18 -08001236 * @dev: parent DRM device
1237 * @kdev: kernel device for sysfs attributes
1238 * @attr: sysfs attributes
1239 * @head: list management
1240 * @base: base KMS object
Daniel Vetterac3ba4a2016-05-31 23:11:10 +02001241 * @name: human readable name, can be overwritten by the driver
1242 * @connector_id: compacted connector id useful indexing arrays
Jesse Barnes72252542011-11-07 12:03:18 -08001243 * @connector_type: one of the %DRM_MODE_CONNECTOR_<foo> types from drm_mode.h
1244 * @connector_type_id: index into connector type enum
Dave Airlief453ba02008-11-07 14:05:41 -08001245 * @interlace_allowed: can this connector handle interlaced modes?
1246 * @doublescan_allowed: can this connector handle doublescan?
Daniel Vetter2c0c33d2014-10-27 20:19:38 +01001247 * @stereo_allowed: can this connector handle stereo modes?
Chris Wilson40daac62016-06-15 13:17:48 +01001248 * @registered: is this connector exposed (registered) with userspace?
Jesse Barnes72252542011-11-07 12:03:18 -08001249 * @modes: modes available on this connector (from fill_modes() + user)
1250 * @status: one of the drm_connector_status enums (connected, not, or unknown)
1251 * @probed_modes: list of modes derived directly from the display
1252 * @display_info: information about attached display (e.g. from EDID)
Dave Airlief453ba02008-11-07 14:05:41 -08001253 * @funcs: connector control functions
Jesse Barnes72252542011-11-07 12:03:18 -08001254 * @edid_blob_ptr: DRM property containing EDID if present
Paulo Zanoni7e3bdf42012-05-15 18:09:01 -03001255 * @properties: property tracking for this connector
Jesse Barnes72252542011-11-07 12:03:18 -08001256 * @polled: a %DRM_CONNECTOR_POLL_<foo> value for core driven polling
1257 * @dpms: current dpms state
1258 * @helper_private: mid-layer private data
Daniel Vetter2c0c33d2014-10-27 20:19:38 +01001259 * @cmdline_mode: mode line parsed from the kernel cmdline for this connector
Jesse Barnes72252542011-11-07 12:03:18 -08001260 * @force: a %DRM_FORCE_<foo> state for forced mode sets
Daniel Vetter2c0c33d2014-10-27 20:19:38 +01001261 * @override_edid: has the EDID been overwritten through debugfs for testing?
Jesse Barnes72252542011-11-07 12:03:18 -08001262 * @encoder_ids: valid encoders for this connector
1263 * @encoder: encoder driving this connector, if any
1264 * @eld: EDID-like data, if present
1265 * @dvi_dual: dual link DVI, if found
1266 * @max_tmds_clock: max clock rate, if found
1267 * @latency_present: AV delay info from ELD, if found
1268 * @video_latency: video latency info from ELD, if found
1269 * @audio_latency: audio latency info from ELD, if found
1270 * @null_edid_counter: track sinks that give us all zeros for the EDID
Daniel Vetter2c0c33d2014-10-27 20:19:38 +01001271 * @bad_edid_counter: track sinks that give us an EDID with invalid checksum
Daniel Vetterac6f2e22015-05-08 16:15:41 +02001272 * @edid_corrupt: indicates whether the last read EDID was corrupt
Daniel Vetter2c0c33d2014-10-27 20:19:38 +01001273 * @debugfs_entry: debugfs directory for this connector
Daniel Vetter144ecb92014-10-27 20:28:44 +01001274 * @state: current atomic state for this connector
Dave Airlie40d9b042014-10-20 16:29:33 +10001275 * @has_tile: is this connector connected to a tiled monitor
1276 * @tile_group: tile group for the connected monitor
1277 * @tile_is_single_monitor: whether the tile is one monitor housing
1278 * @num_h_tile: number of horizontal tiles in the tile group
1279 * @num_v_tile: number of vertical tiles in the tile group
1280 * @tile_h_loc: horizontal location of this tile
1281 * @tile_v_loc: vertical location of this tile
1282 * @tile_h_size: horizontal size of this tile.
1283 * @tile_v_size: vertical size of this tile.
Dave Airlief453ba02008-11-07 14:05:41 -08001284 *
1285 * Each connector may be connected to one or more CRTCs, or may be clonable by
1286 * another connector if they can share a CRTC. Each connector also has a specific
1287 * position in the broader display (referred to as a 'screen' though it could
1288 * span multiple monitors).
1289 */
1290struct drm_connector {
1291 struct drm_device *dev;
Dave Airlie5bdebb12013-10-11 14:07:25 +10001292 struct device *kdev;
Dave Airlief453ba02008-11-07 14:05:41 -08001293 struct device_attribute *attr;
1294 struct list_head head;
1295
1296 struct drm_mode_object base;
1297
Jani Nikula2abdd312014-05-14 16:58:19 +03001298 char *name;
Maarten Lankhorst5fff80b2016-02-17 08:32:05 +01001299 int connector_id;
Dave Airlief453ba02008-11-07 14:05:41 -08001300 int connector_type;
1301 int connector_type_id;
1302 bool interlace_allowed;
1303 bool doublescan_allowed;
Damien Lespiau560a0672013-09-25 16:45:29 +01001304 bool stereo_allowed;
Chris Wilson40daac62016-06-15 13:17:48 +01001305 bool registered;
Dave Airlief453ba02008-11-07 14:05:41 -08001306 struct list_head modes; /* list of modes on this connector */
1307
Dave Airlief453ba02008-11-07 14:05:41 -08001308 enum drm_connector_status status;
1309
1310 /* these are modes added by probing with DDC or the BIOS */
1311 struct list_head probed_modes;
1312
1313 struct drm_display_info display_info;
1314 const struct drm_connector_funcs *funcs;
1315
Dave Airlief453ba02008-11-07 14:05:41 -08001316 struct drm_property_blob *edid_blob_ptr;
Paulo Zanoni7e3bdf42012-05-15 18:09:01 -03001317 struct drm_object_properties properties;
Dave Airlief453ba02008-11-07 14:05:41 -08001318
Daniel Vetterac3ba4a2016-05-31 23:11:10 +02001319 /**
1320 * @path_blob_ptr:
1321 *
1322 * DRM blob property data for the DP MST path property.
1323 */
Dave Airlie43aba7e2014-06-05 14:01:31 +10001324 struct drm_property_blob *path_blob_ptr;
1325
Daniel Vetterac3ba4a2016-05-31 23:11:10 +02001326 /**
1327 * @tile_blob_ptr:
1328 *
1329 * DRM blob property data for the tile property (used mostly by DP MST).
1330 * This is meant for screens which are driven through separate display
1331 * pipelines represented by &drm_crtc, which might not be running with
1332 * genlocked clocks. For tiled panels which are genlocked, like
1333 * dual-link LVDS or dual-link DSI, the driver should try to not expose
1334 * the tiling and virtualize both &drm_crtc and &drm_plane if needed.
1335 */
Dave Airlie6f134d72014-10-20 16:30:50 +10001336 struct drm_property_blob *tile_blob_ptr;
1337
Dave Airlieeb1f8e42010-05-07 06:42:51 +00001338 uint8_t polled; /* DRM_CONNECTOR_POLL_* */
1339
Keith Packardc9fb15f2009-05-30 20:42:28 -07001340 /* requested DPMS state */
1341 int dpms;
1342
Daniel Vetter4490d4c2015-12-04 09:45:45 +01001343 const struct drm_connector_helper_funcs *helper_private;
Dave Airlief453ba02008-11-07 14:05:41 -08001344
Dave Airlied50ba252009-09-23 14:44:08 +10001345 /* forced on connector */
Chris Wilsoneaf99c72014-08-06 10:08:32 +02001346 struct drm_cmdline_mode cmdline_mode;
Dave Airlied50ba252009-09-23 14:44:08 +10001347 enum drm_connector_force force;
Thomas Wood4cf2b282014-06-18 17:52:33 +01001348 bool override_edid;
Dave Airlief453ba02008-11-07 14:05:41 -08001349 uint32_t encoder_ids[DRM_CONNECTOR_MAX_ENCODER];
Dave Airlief453ba02008-11-07 14:05:41 -08001350 struct drm_encoder *encoder; /* currently active encoder */
Dave Airlie4a9a8b72011-06-14 06:13:55 +00001351
Wu Fengguang76adaa342011-09-05 14:23:20 +08001352 /* EDID bits */
1353 uint8_t eld[MAX_ELD_BYTES];
1354 bool dvi_dual;
1355 int max_tmds_clock; /* in MHz */
1356 bool latency_present[2];
1357 int video_latency[2]; /* [0]: progressive, [1]: interlaced */
1358 int audio_latency[2];
Dave Airlie4a9a8b72011-06-14 06:13:55 +00001359 int null_edid_counter; /* needed to workaround some HW bugs where we get all 0s */
Jerome Glisse0b2443e2012-08-09 11:25:51 -04001360 unsigned bad_edid_counter;
Thomas Wood30f65702014-06-18 17:52:32 +01001361
Todd Previte6ba2bd32015-04-21 11:09:41 -07001362 /* Flag for raw EDID header corruption - used in Displayport
1363 * compliance testing - * Displayport Link CTS Core 1.2 rev1.1 4.2.2.6
1364 */
1365 bool edid_corrupt;
1366
Thomas Wood30f65702014-06-18 17:52:32 +01001367 struct dentry *debugfs_entry;
Daniel Vetter144ecb92014-10-27 20:28:44 +01001368
1369 struct drm_connector_state *state;
Dave Airlie40d9b042014-10-20 16:29:33 +10001370
1371 /* DisplayID bits */
1372 bool has_tile;
1373 struct drm_tile_group *tile_group;
1374 bool tile_is_single_monitor;
1375
1376 uint8_t num_h_tile, num_v_tile;
1377 uint8_t tile_h_loc, tile_v_loc;
1378 uint16_t tile_h_size, tile_v_size;
Dave Airlief453ba02008-11-07 14:05:41 -08001379};
1380
1381/**
Daniel Vetter144ecb92014-10-27 20:28:44 +01001382 * struct drm_plane_state - mutable plane state
Daniel Vetter07cc0ef2014-11-27 15:49:39 +01001383 * @plane: backpointer to the plane
Daniel Vetter144ecb92014-10-27 20:28:44 +01001384 * @crtc: currently bound CRTC, NULL if disabled
Daniel Vettercc4ceb42014-07-25 21:30:38 +02001385 * @fb: currently bound framebuffer
Daniel Vettere2330f02014-10-29 11:34:56 +01001386 * @fence: optional fence to wait for before scanning out @fb
Daniel Vetter144ecb92014-10-27 20:28:44 +01001387 * @crtc_x: left position of visible portion of plane on crtc
1388 * @crtc_y: upper position of visible portion of plane on crtc
1389 * @crtc_w: width of visible portion of plane on crtc
1390 * @crtc_h: height of visible portion of plane on crtc
1391 * @src_x: left position of visible portion of plane within
1392 * plane (in 16.16)
1393 * @src_y: upper position of visible portion of plane within
1394 * plane (in 16.16)
1395 * @src_w: width of visible portion of plane (in 16.16)
1396 * @src_h: height of visible portion of plane (in 16.16)
Daniel Vetterac3ba4a2016-05-31 23:11:10 +02001397 * @rotation: rotation of the plane
Daniel Vetter144ecb92014-10-27 20:28:44 +01001398 * @state: backpointer to global drm_atomic_state
1399 */
1400struct drm_plane_state {
Daniel Vetter07cc0ef2014-11-27 15:49:39 +01001401 struct drm_plane *plane;
1402
Rob Clark6ddd3882014-11-21 15:28:31 -05001403 struct drm_crtc *crtc; /* do not write directly, use drm_atomic_set_crtc_for_plane() */
1404 struct drm_framebuffer *fb; /* do not write directly, use drm_atomic_set_fb_for_plane() */
Daniel Vettere2330f02014-10-29 11:34:56 +01001405 struct fence *fence;
Daniel Vetter144ecb92014-10-27 20:28:44 +01001406
1407 /* Signed dest location allows it to be partially off screen */
1408 int32_t crtc_x, crtc_y;
1409 uint32_t crtc_w, crtc_h;
1410
1411 /* Source values are 16.16 fixed point */
1412 uint32_t src_x, src_y;
1413 uint32_t src_h, src_w;
1414
Matt Roper1da30622015-01-21 16:35:40 -08001415 /* Plane rotation */
1416 unsigned int rotation;
1417
Daniel Vetter144ecb92014-10-27 20:28:44 +01001418 struct drm_atomic_state *state;
1419};
1420
1421
1422/**
Daniel Vetter3bf04012014-10-27 16:54:27 +01001423 * struct drm_plane_funcs - driver plane control functions
Jesse Barnes8cf5c912011-11-14 14:51:27 -08001424 */
1425struct drm_plane_funcs {
Daniel Vetter88548632015-12-04 09:45:48 +01001426 /**
1427 * @update_plane:
1428 *
1429 * This is the legacy entry point to enable and configure the plane for
1430 * the given CRTC and framebuffer. It is never called to disable the
1431 * plane, i.e. the passed-in crtc and fb paramters are never NULL.
1432 *
1433 * The source rectangle in frame buffer memory coordinates is given by
1434 * the src_x, src_y, src_w and src_h parameters (as 16.16 fixed point
1435 * values). Devices that don't support subpixel plane coordinates can
1436 * ignore the fractional part.
1437 *
1438 * The destination rectangle in CRTC coordinates is given by the
1439 * crtc_x, crtc_y, crtc_w and crtc_h parameters (as integer values).
1440 * Devices scale the source rectangle to the destination rectangle. If
1441 * scaling is not supported, and the source rectangle size doesn't match
1442 * the destination rectangle size, the driver must return a
1443 * -<errorname>EINVAL</errorname> error.
1444 *
1445 * Drivers implementing atomic modeset should use
1446 * drm_atomic_helper_update_plane() to implement this hook.
1447 *
1448 * RETURNS:
1449 *
1450 * 0 on success or a negative error code on failure.
1451 */
Jesse Barnes8cf5c912011-11-14 14:51:27 -08001452 int (*update_plane)(struct drm_plane *plane,
1453 struct drm_crtc *crtc, struct drm_framebuffer *fb,
1454 int crtc_x, int crtc_y,
1455 unsigned int crtc_w, unsigned int crtc_h,
1456 uint32_t src_x, uint32_t src_y,
1457 uint32_t src_w, uint32_t src_h);
Daniel Vetter88548632015-12-04 09:45:48 +01001458
1459 /**
1460 * @disable_plane:
1461 *
1462 * This is the legacy entry point to disable the plane. The DRM core
Daniel Vetterc6b0ca32015-12-04 09:46:01 +01001463 * calls this method in response to a DRM_IOCTL_MODE_SETPLANE IOCTL call
Daniel Vetter88548632015-12-04 09:45:48 +01001464 * with the frame buffer ID set to 0. Disabled planes must not be
1465 * processed by the CRTC.
1466 *
1467 * Drivers implementing atomic modeset should use
1468 * drm_atomic_helper_disable_plane() to implement this hook.
1469 *
1470 * RETURNS:
1471 *
1472 * 0 on success or a negative error code on failure.
1473 */
Jesse Barnes8cf5c912011-11-14 14:51:27 -08001474 int (*disable_plane)(struct drm_plane *plane);
Daniel Vetter88548632015-12-04 09:45:48 +01001475
1476 /**
1477 * @destroy:
1478 *
1479 * Clean up plane resources. This is only called at driver unload time
1480 * through drm_mode_config_cleanup() since a plane cannot be hotplugged
1481 * in DRM.
1482 */
Jesse Barnes8cf5c912011-11-14 14:51:27 -08001483 void (*destroy)(struct drm_plane *plane);
Daniel Vetter88548632015-12-04 09:45:48 +01001484
1485 /**
1486 * @reset:
1487 *
1488 * Reset plane hardware and software state to off. This function isn't
1489 * called by the core directly, only through drm_mode_config_reset().
1490 * It's not a helper hook only for historical reasons.
1491 *
1492 * Atomic drivers can use drm_atomic_helper_plane_reset() to reset
1493 * atomic state using this hook.
1494 */
Daniel Vetter2a0d7cf2014-07-29 15:32:37 +02001495 void (*reset)(struct drm_plane *plane);
Rob Clark4d939142012-05-17 02:23:27 -06001496
Daniel Vetter88548632015-12-04 09:45:48 +01001497 /**
1498 * @set_property:
1499 *
1500 * This is the legacy entry point to update a property attached to the
1501 * plane.
1502 *
1503 * Drivers implementing atomic modeset should use
1504 * drm_atomic_helper_plane_set_property() to implement this hook.
1505 *
1506 * This callback is optional if the driver does not support any legacy
1507 * driver-private properties.
1508 *
1509 * RETURNS:
1510 *
1511 * 0 on success or a negative error code on failure.
1512 */
Rob Clark4d939142012-05-17 02:23:27 -06001513 int (*set_property)(struct drm_plane *plane,
1514 struct drm_property *property, uint64_t val);
Daniel Vetter144ecb92014-10-27 20:28:44 +01001515
Daniel Vetter88548632015-12-04 09:45:48 +01001516 /**
1517 * @atomic_duplicate_state:
1518 *
1519 * Duplicate the current atomic state for this plane and return it.
1520 * The core and helpers gurantee that any atomic state duplicated with
1521 * this hook and still owned by the caller (i.e. not transferred to the
1522 * driver by calling ->atomic_commit() from struct
1523 * &drm_mode_config_funcs) will be cleaned up by calling the
1524 * @atomic_destroy_state hook in this structure.
1525 *
1526 * Atomic drivers which don't subclass struct &drm_plane_state should use
1527 * drm_atomic_helper_plane_duplicate_state(). Drivers that subclass the
1528 * state structure to extend it with driver-private state should use
1529 * __drm_atomic_helper_plane_duplicate_state() to make sure shared state is
1530 * duplicated in a consistent fashion across drivers.
1531 *
1532 * It is an error to call this hook before plane->state has been
1533 * initialized correctly.
1534 *
1535 * NOTE:
1536 *
1537 * If the duplicate state references refcounted resources this hook must
1538 * acquire a reference for each of them. The driver must release these
1539 * references again in @atomic_destroy_state.
1540 *
1541 * RETURNS:
1542 *
1543 * Duplicated atomic state or NULL when the allocation failed.
1544 */
Daniel Vetter144ecb92014-10-27 20:28:44 +01001545 struct drm_plane_state *(*atomic_duplicate_state)(struct drm_plane *plane);
Daniel Vetter88548632015-12-04 09:45:48 +01001546
1547 /**
1548 * @atomic_destroy_state:
1549 *
1550 * Destroy a state duplicated with @atomic_duplicate_state and release
1551 * or unreference all resources it references
1552 */
Daniel Vetter144ecb92014-10-27 20:28:44 +01001553 void (*atomic_destroy_state)(struct drm_plane *plane,
Daniel Vettercc4ceb42014-07-25 21:30:38 +02001554 struct drm_plane_state *state);
Daniel Vetter88548632015-12-04 09:45:48 +01001555
1556 /**
1557 * @atomic_set_property:
1558 *
1559 * Decode a driver-private property value and store the decoded value
1560 * into the passed-in state structure. Since the atomic core decodes all
1561 * standardized properties (even for extensions beyond the core set of
1562 * properties which might not be implemented by all drivers) this
1563 * requires drivers to subclass the state structure.
1564 *
1565 * Such driver-private properties should really only be implemented for
1566 * truly hardware/vendor specific state. Instead it is preferred to
1567 * standardize atomic extension and decode the properties used to expose
1568 * such an extension in the core.
1569 *
1570 * Do not call this function directly, use
1571 * drm_atomic_plane_set_property() instead.
1572 *
1573 * This callback is optional if the driver does not support any
1574 * driver-private atomic properties.
1575 *
1576 * NOTE:
1577 *
1578 * This function is called in the state assembly phase of atomic
1579 * modesets, which can be aborted for any reason (including on
1580 * userspace's request to just check whether a configuration would be
1581 * possible). Drivers MUST NOT touch any persistent state (hardware or
1582 * software) or data structures except the passed in @state parameter.
1583 *
1584 * Also since userspace controls in which order properties are set this
1585 * function must not do any input validation (since the state update is
1586 * incomplete and hence likely inconsistent). Instead any such input
1587 * validation must be done in the various atomic_check callbacks.
1588 *
1589 * RETURNS:
1590 *
1591 * 0 if the property has been found, -EINVAL if the property isn't
1592 * implemented by the driver (which shouldn't ever happen, the core only
1593 * asks for properties attached to this plane). No other validation is
1594 * allowed by the driver. The core already checks that the property
1595 * value is within the range (integer, valid enum value, ...) the driver
1596 * set when registering the property.
1597 */
Daniel Vetter144ecb92014-10-27 20:28:44 +01001598 int (*atomic_set_property)(struct drm_plane *plane,
1599 struct drm_plane_state *state,
1600 struct drm_property *property,
1601 uint64_t val);
Daniel Vetter88548632015-12-04 09:45:48 +01001602
1603 /**
1604 * @atomic_get_property:
1605 *
1606 * Reads out the decoded driver-private property. This is used to
Daniel Vetterc6b0ca32015-12-04 09:46:01 +01001607 * implement the GETPLANE IOCTL.
Daniel Vetter88548632015-12-04 09:45:48 +01001608 *
1609 * Do not call this function directly, use
1610 * drm_atomic_plane_get_property() instead.
1611 *
1612 * This callback is optional if the driver does not support any
1613 * driver-private atomic properties.
1614 *
1615 * RETURNS:
1616 *
1617 * 0 on success, -EINVAL if the property isn't implemented by the
1618 * driver (which should never happen, the core only asks for
1619 * properties attached to this plane).
1620 */
Rob Clarkac9c9252014-12-18 16:01:47 -05001621 int (*atomic_get_property)(struct drm_plane *plane,
1622 const struct drm_plane_state *state,
1623 struct drm_property *property,
1624 uint64_t *val);
Benjamin Gaignard79190ea2016-06-21 16:37:09 +02001625 /**
1626 * @late_register:
1627 *
1628 * This optional hook can be used to register additional userspace
1629 * interfaces attached to the plane like debugfs interfaces.
1630 * It is called late in the driver load sequence from drm_dev_register().
1631 * Everything added from this callback should be unregistered in
1632 * the early_unregister callback.
1633 *
1634 * Returns:
1635 *
1636 * 0 on success, or a negative error code on failure.
1637 */
1638 int (*late_register)(struct drm_plane *plane);
1639
1640 /**
1641 * @early_unregister:
1642 *
1643 * This optional hook should be used to unregister the additional
1644 * userspace interfaces attached to the plane from
1645 * late_unregister(). It is called from drm_dev_unregister(),
1646 * early in the driver unload sequence to disable userspace access
1647 * before data structures are torndown.
1648 */
1649 void (*early_unregister)(struct drm_plane *plane);
Jesse Barnes8cf5c912011-11-14 14:51:27 -08001650};
1651
Matt Ropere27dde32014-04-01 15:22:30 -07001652enum drm_plane_type {
1653 DRM_PLANE_TYPE_OVERLAY,
1654 DRM_PLANE_TYPE_PRIMARY,
1655 DRM_PLANE_TYPE_CURSOR,
1656};
1657
Daniel Vetter88548632015-12-04 09:45:48 +01001658
Jesse Barnes8cf5c912011-11-14 14:51:27 -08001659/**
Daniel Vetter3bf04012014-10-27 16:54:27 +01001660 * struct drm_plane - central DRM plane control structure
Jesse Barnes8cf5c912011-11-14 14:51:27 -08001661 * @dev: DRM device this plane belongs to
1662 * @head: for list management
Daniel Vetterac3ba4a2016-05-31 23:11:10 +02001663 * @name: human readable name, can be overwritten by the driver
Jesse Barnes8cf5c912011-11-14 14:51:27 -08001664 * @base: base mode object
1665 * @possible_crtcs: pipes this plane can be bound to
1666 * @format_types: array of formats supported by this plane
1667 * @format_count: number of formats supported
Laurent Pinchart7eb5f302015-03-09 10:41:07 +02001668 * @format_default: driver hasn't supplied supported formats for the plane
Jesse Barnes8cf5c912011-11-14 14:51:27 -08001669 * @crtc: currently bound CRTC
1670 * @fb: currently bound fb
Daniel Vetter2c0c33d2014-10-27 20:19:38 +01001671 * @old_fb: Temporary tracking of the old fb while a modeset is ongoing. Used by
1672 * drm_mode_set_config_internal() to implement correct refcounting.
Jesse Barnes8cf5c912011-11-14 14:51:27 -08001673 * @funcs: helper functions
Rob Clark4d939142012-05-17 02:23:27 -06001674 * @properties: property tracking for this plane
Matt Ropere27dde32014-04-01 15:22:30 -07001675 * @type: type of plane (overlay, primary, cursor)
Daniel Vetter144ecb92014-10-27 20:28:44 +01001676 * @state: current atomic state for this plane
Daniel Vetterac3ba4a2016-05-31 23:11:10 +02001677 * @helper_private: mid-layer private data
Jesse Barnes8cf5c912011-11-14 14:51:27 -08001678 */
1679struct drm_plane {
1680 struct drm_device *dev;
1681 struct list_head head;
1682
Ville Syrjälä9f4c97a2015-12-08 18:41:54 +02001683 char *name;
1684
Daniel Vetterac3ba4a2016-05-31 23:11:10 +02001685 /**
1686 * @mutex:
1687 *
1688 * Protects modeset plane state, together with the mutex of &drm_crtc
1689 * this plane is linked to (when active, getting actived or getting
1690 * disabled).
1691 */
Daniel Vetter4d02e2d2014-11-11 10:12:00 +01001692 struct drm_modeset_lock mutex;
1693
Jesse Barnes8cf5c912011-11-14 14:51:27 -08001694 struct drm_mode_object base;
1695
1696 uint32_t possible_crtcs;
1697 uint32_t *format_types;
Thierry Reding45e37432015-08-12 16:54:28 +02001698 unsigned int format_count;
Laurent Pinchart7eb5f302015-03-09 10:41:07 +02001699 bool format_default;
Jesse Barnes8cf5c912011-11-14 14:51:27 -08001700
1701 struct drm_crtc *crtc;
1702 struct drm_framebuffer *fb;
1703
Daniel Vetter3d30a592014-07-27 13:42:42 +02001704 struct drm_framebuffer *old_fb;
1705
Jesse Barnes8cf5c912011-11-14 14:51:27 -08001706 const struct drm_plane_funcs *funcs;
Rob Clark4d939142012-05-17 02:23:27 -06001707
1708 struct drm_object_properties properties;
Matt Ropere27dde32014-04-01 15:22:30 -07001709
1710 enum drm_plane_type type;
Daniel Vetter144ecb92014-10-27 20:28:44 +01001711
Chris Wilson490d3d12016-05-27 20:05:00 +01001712 /* position inside the mode_config.list, can be used as a [] idx */
1713 unsigned index;
1714
Daniel Vetter4490d4c2015-12-04 09:45:45 +01001715 const struct drm_plane_helper_funcs *helper_private;
Daniel Vetterc2fcd272014-11-05 00:14:14 +01001716
Daniel Vetter144ecb92014-10-27 20:28:44 +01001717 struct drm_plane_state *state;
Jesse Barnes8cf5c912011-11-14 14:51:27 -08001718};
1719
1720/**
Daniel Vetter3bf04012014-10-27 16:54:27 +01001721 * struct drm_bridge_funcs - drm_bridge control functions
Ajay Kumar3d3f8b12015-01-20 22:08:44 +05301722 * @attach: Called during drm_bridge_attach
Sean Paul3b336ec2013-08-14 16:47:37 -04001723 */
1724struct drm_bridge_funcs {
Ajay Kumar3d3f8b12015-01-20 22:08:44 +05301725 int (*attach)(struct drm_bridge *bridge);
Daniel Vetterda024fe2015-12-04 09:45:47 +01001726
1727 /**
1728 * @mode_fixup:
1729 *
1730 * This callback is used to validate and adjust a mode. The paramater
1731 * mode is the display mode that should be fed to the next element in
1732 * the display chain, either the final &drm_connector or the next
1733 * &drm_bridge. The parameter adjusted_mode is the input mode the bridge
1734 * requires. It can be modified by this callback and does not need to
1735 * match mode.
1736 *
1737 * This is the only hook that allows a bridge to reject a modeset. If
1738 * this function passes all other callbacks must succeed for this
1739 * configuration.
1740 *
1741 * NOTE:
1742 *
1743 * This function is called in the check phase of atomic modesets, which
1744 * can be aborted for any reason (including on userspace's request to
1745 * just check whether a configuration would be possible). Drivers MUST
1746 * NOT touch any persistent state (hardware or software) or data
Daniel Vetter88548632015-12-04 09:45:48 +01001747 * structures except the passed in @state parameter.
Daniel Vetterda024fe2015-12-04 09:45:47 +01001748 *
1749 * RETURNS:
1750 *
1751 * True if an acceptable configuration is possible, false if the modeset
1752 * operation should be rejected.
1753 */
Sean Paul3b336ec2013-08-14 16:47:37 -04001754 bool (*mode_fixup)(struct drm_bridge *bridge,
1755 const struct drm_display_mode *mode,
1756 struct drm_display_mode *adjusted_mode);
Daniel Vetterda024fe2015-12-04 09:45:47 +01001757 /**
1758 * @disable:
1759 *
1760 * This callback should disable the bridge. It is called right before
1761 * the preceding element in the display pipe is disabled. If the
1762 * preceding element is a bridge this means it's called before that
1763 * bridge's ->disable() function. If the preceding element is a
1764 * &drm_encoder it's called right before the encoder's ->disable(),
1765 * ->prepare() or ->dpms() hook from struct &drm_encoder_helper_funcs.
1766 *
1767 * The bridge can assume that the display pipe (i.e. clocks and timing
1768 * signals) feeding it is still running when this callback is called.
Laurent Pinchartc8a3b2a2016-02-26 11:51:06 +02001769 *
1770 * The disable callback is optional.
Daniel Vetterda024fe2015-12-04 09:45:47 +01001771 */
Sean Paul3b336ec2013-08-14 16:47:37 -04001772 void (*disable)(struct drm_bridge *bridge);
Daniel Vetterda024fe2015-12-04 09:45:47 +01001773
1774 /**
1775 * @post_disable:
1776 *
1777 * This callback should disable the bridge. It is called right after
1778 * the preceding element in the display pipe is disabled. If the
1779 * preceding element is a bridge this means it's called after that
1780 * bridge's ->post_disable() function. If the preceding element is a
1781 * &drm_encoder it's called right after the encoder's ->disable(),
1782 * ->prepare() or ->dpms() hook from struct &drm_encoder_helper_funcs.
1783 *
1784 * The bridge must assume that the display pipe (i.e. clocks and timing
1785 * singals) feeding it is no longer running when this callback is
1786 * called.
Laurent Pinchartc8a3b2a2016-02-26 11:51:06 +02001787 *
1788 * The post_disable callback is optional.
Daniel Vetterda024fe2015-12-04 09:45:47 +01001789 */
Sean Paul3b336ec2013-08-14 16:47:37 -04001790 void (*post_disable)(struct drm_bridge *bridge);
Daniel Vetterda024fe2015-12-04 09:45:47 +01001791
1792 /**
1793 * @mode_set:
1794 *
1795 * This callback should set the given mode on the bridge. It is called
1796 * after the ->mode_set() callback for the preceding element in the
1797 * display pipeline has been called already. The display pipe (i.e.
1798 * clocks and timing signals) is off when this function is called.
1799 */
Sean Paul3b336ec2013-08-14 16:47:37 -04001800 void (*mode_set)(struct drm_bridge *bridge,
1801 struct drm_display_mode *mode,
1802 struct drm_display_mode *adjusted_mode);
Daniel Vetterda024fe2015-12-04 09:45:47 +01001803 /**
1804 * @pre_enable:
1805 *
1806 * This callback should enable the bridge. It is called right before
1807 * the preceding element in the display pipe is enabled. If the
1808 * preceding element is a bridge this means it's called before that
1809 * bridge's ->pre_enable() function. If the preceding element is a
1810 * &drm_encoder it's called right before the encoder's ->enable(),
1811 * ->commit() or ->dpms() hook from struct &drm_encoder_helper_funcs.
1812 *
1813 * The display pipe (i.e. clocks and timing signals) feeding this bridge
1814 * will not yet be running when this callback is called. The bridge must
1815 * not enable the display link feeding the next bridge in the chain (if
1816 * there is one) when this callback is called.
Laurent Pinchartc8a3b2a2016-02-26 11:51:06 +02001817 *
1818 * The pre_enable callback is optional.
Daniel Vetterda024fe2015-12-04 09:45:47 +01001819 */
Sean Paul3b336ec2013-08-14 16:47:37 -04001820 void (*pre_enable)(struct drm_bridge *bridge);
Daniel Vetterda024fe2015-12-04 09:45:47 +01001821
1822 /**
1823 * @enable:
1824 *
1825 * This callback should enable the bridge. It is called right after
1826 * the preceding element in the display pipe is enabled. If the
1827 * preceding element is a bridge this means it's called after that
1828 * bridge's ->enable() function. If the preceding element is a
1829 * &drm_encoder it's called right after the encoder's ->enable(),
1830 * ->commit() or ->dpms() hook from struct &drm_encoder_helper_funcs.
1831 *
1832 * The bridge can assume that the display pipe (i.e. clocks and timing
1833 * signals) feeding it is running when this callback is called. This
1834 * callback must enable the display link feeding the next bridge in the
1835 * chain if there is one.
Laurent Pinchartc8a3b2a2016-02-26 11:51:06 +02001836 *
1837 * The enable callback is optional.
Daniel Vetterda024fe2015-12-04 09:45:47 +01001838 */
Sean Paul3b336ec2013-08-14 16:47:37 -04001839 void (*enable)(struct drm_bridge *bridge);
Sean Paul3b336ec2013-08-14 16:47:37 -04001840};
1841
1842/**
Daniel Vetter3bf04012014-10-27 16:54:27 +01001843 * struct drm_bridge - central DRM bridge control structure
Sean Paul3b336ec2013-08-14 16:47:37 -04001844 * @dev: DRM device this bridge belongs to
Archit Taneja862e6862015-05-21 11:03:16 +05301845 * @encoder: encoder to which this bridge is connected
1846 * @next: the next bridge in the encoder chain
Ajay Kumar3d3f8b12015-01-20 22:08:44 +05301847 * @of_node: device node pointer to the bridge
1848 * @list: to keep track of all added bridges
Sean Paul3b336ec2013-08-14 16:47:37 -04001849 * @funcs: control functions
1850 * @driver_private: pointer to the bridge driver's internal context
1851 */
1852struct drm_bridge {
1853 struct drm_device *dev;
Ajay Kumar3d3f8b12015-01-20 22:08:44 +05301854 struct drm_encoder *encoder;
Archit Taneja862e6862015-05-21 11:03:16 +05301855 struct drm_bridge *next;
Ajay Kumar3d3f8b12015-01-20 22:08:44 +05301856#ifdef CONFIG_OF
1857 struct device_node *of_node;
1858#endif
1859 struct list_head list;
Sean Paul3b336ec2013-08-14 16:47:37 -04001860
1861 const struct drm_bridge_funcs *funcs;
1862 void *driver_private;
1863};
1864
Daniel Vetter3b24f7d2016-06-08 14:19:00 +02001865/**
1866 * struct drm_crtc_commit - track modeset commits on a CRTC
1867 *
1868 * This structure is used to track pending modeset changes and atomic commit on
1869 * a per-CRTC basis. Since updating the list should never block this structure
1870 * is reference counted to allow waiters to safely wait on an event to complete,
1871 * without holding any locks.
1872 *
1873 * It has 3 different events in total to allow a fine-grained synchronization
1874 * between outstanding updates::
1875 *
1876 * atomic commit thread hardware
1877 *
1878 * write new state into hardware ----> ...
1879 * signal hw_done
1880 * switch to new state on next
1881 * ... v/hblank
1882 *
1883 * wait for buffers to show up ...
1884 *
1885 * ... send completion irq
1886 * irq handler signals flip_done
1887 * cleanup old buffers
1888 *
1889 * signal cleanup_done
1890 *
1891 * wait for flip_done <----
1892 * clean up atomic state
1893 *
1894 * The important bit to know is that cleanup_done is the terminal event, but the
1895 * ordering between flip_done and hw_done is entirely up to the specific driver
1896 * and modeset state change.
1897 *
1898 * For an implementation of how to use this look at
1899 * drm_atomic_helper_setup_commit() from the atomic helper library.
1900 */
1901struct drm_crtc_commit {
1902 /**
1903 * @crtc:
1904 *
1905 * DRM CRTC for this commit.
1906 */
1907 struct drm_crtc *crtc;
1908
1909 /**
1910 * @ref:
1911 *
1912 * Reference count for this structure. Needed to allow blocking on
1913 * completions without the risk of the completion disappearing
1914 * meanwhile.
1915 */
1916 struct kref ref;
1917
1918 /**
1919 * @flip_done:
1920 *
1921 * Will be signaled when the hardware has flipped to the new set of
1922 * buffers. Signals at the same time as when the drm event for this
1923 * commit is sent to userspace, or when an out-fence is singalled. Note
1924 * that for most hardware, in most cases this happens after @hw_done is
1925 * signalled.
1926 */
1927 struct completion flip_done;
1928
1929 /**
1930 * @hw_done:
1931 *
1932 * Will be signalled when all hw register changes for this commit have
1933 * been written out. Especially when disabling a pipe this can be much
1934 * later than than @flip_done, since that can signal already when the
1935 * screen goes black, whereas to fully shut down a pipe more register
1936 * I/O is required.
1937 *
1938 * Note that this does not need to include separately reference-counted
1939 * resources like backing storage buffer pinning, or runtime pm
1940 * management.
1941 */
1942 struct completion hw_done;
1943
1944 /**
1945 * @cleanup_done:
1946 *
1947 * Will be signalled after old buffers have been cleaned up by calling
1948 * drm_atomic_helper_cleanup_planes(). Since this can only happen after
1949 * a vblank wait completed it might be a bit later. This completion is
1950 * useful to throttle updates and avoid hardware updates getting ahead
1951 * of the buffer cleanup too much.
1952 */
1953 struct completion cleanup_done;
1954
1955 /**
1956 * @commit_entry:
1957 *
1958 * Entry on the per-CRTC commit_list. Protected by crtc->commit_lock.
1959 */
1960 struct list_head commit_entry;
1961
1962 /**
1963 * @event:
1964 *
1965 * &drm_pending_vblank_event pointer to clean up private events.
1966 */
1967 struct drm_pending_vblank_event *event;
1968};
1969
Daniel Vetterb8b53422016-06-02 00:06:33 +02001970struct __drm_planes_state {
1971 struct drm_plane *ptr;
1972 struct drm_plane_state *state;
1973};
1974
Daniel Vetter5d943aa62016-06-02 00:06:34 +02001975struct __drm_crtcs_state {
1976 struct drm_crtc *ptr;
1977 struct drm_crtc_state *state;
Daniel Vetter3b24f7d2016-06-08 14:19:00 +02001978 struct drm_crtc_commit *commit;
Daniel Vetter5d943aa62016-06-02 00:06:34 +02001979};
1980
Daniel Vetter63e83c12016-06-02 00:06:32 +02001981struct __drm_connnectors_state {
1982 struct drm_connector *ptr;
1983 struct drm_connector_state *state;
1984};
1985
Sean Paul3b336ec2013-08-14 16:47:37 -04001986/**
Rob Clark08855fa2015-03-11 10:23:09 -04001987 * struct drm_atomic_state - the global state object for atomic updates
Daniel Vettercc4ceb42014-07-25 21:30:38 +02001988 * @dev: parent DRM device
Rob Clarkd34f20d2014-12-18 16:01:56 -05001989 * @allow_modeset: allow full modeset
Daniel Vetterc6b0ca32015-12-04 09:46:01 +01001990 * @legacy_cursor_update: hint to enforce legacy cursor IOCTL semantics
Maarten Lankhorst40616a22016-03-03 10:17:39 +01001991 * @legacy_set_config: Disable conflicting encoders instead of failing with -EINVAL.
Daniel Vetterb8b53422016-06-02 00:06:33 +02001992 * @planes: pointer to array of structures with per-plane data
Daniel Vettercc4ceb42014-07-25 21:30:38 +02001993 * @crtcs: pointer to array of CRTC pointers
Daniel Vetterf52b69f12014-11-19 18:38:08 +01001994 * @num_connector: size of the @connectors and @connector_states arrays
Daniel Vetter63e83c12016-06-02 00:06:32 +02001995 * @connectors: pointer to array of structures with per-connector data
Daniel Vettercc4ceb42014-07-25 21:30:38 +02001996 * @acquire_ctx: acquire context for this atomic modeset state update
1997 */
1998struct drm_atomic_state {
1999 struct drm_device *dev;
Rob Clarkd34f20d2014-12-18 16:01:56 -05002000 bool allow_modeset : 1;
Daniel Vetterf02ad902015-01-22 16:36:23 +01002001 bool legacy_cursor_update : 1;
Maarten Lankhorst40616a22016-03-03 10:17:39 +01002002 bool legacy_set_config : 1;
Daniel Vetterb8b53422016-06-02 00:06:33 +02002003 struct __drm_planes_state *planes;
Daniel Vetter5d943aa62016-06-02 00:06:34 +02002004 struct __drm_crtcs_state *crtcs;
Daniel Vetterf52b69f12014-11-19 18:38:08 +01002005 int num_connector;
Daniel Vetter63e83c12016-06-02 00:06:32 +02002006 struct __drm_connnectors_state *connectors;
Daniel Vettercc4ceb42014-07-25 21:30:38 +02002007
2008 struct drm_modeset_acquire_ctx *acquire_ctx;
Daniel Vetter3b24f7d2016-06-08 14:19:00 +02002009
2010 /**
2011 * @commit_work:
2012 *
2013 * Work item which can be used by the driver or helpers to execute the
2014 * commit without blocking.
2015 */
2016 struct work_struct commit_work;
Daniel Vettercc4ceb42014-07-25 21:30:38 +02002017};
2018
2019
2020/**
Daniel Vetter3bf04012014-10-27 16:54:27 +01002021 * struct drm_mode_set - new values for a CRTC config change
Jesse Barnesef273512011-11-07 12:03:19 -08002022 * @fb: framebuffer to use for new config
2023 * @crtc: CRTC whose configuration we're about to change
2024 * @mode: mode timings to use
2025 * @x: position of this CRTC relative to @fb
2026 * @y: position of this CRTC relative to @fb
2027 * @connectors: array of connectors to drive with this CRTC if possible
2028 * @num_connectors: size of @connectors array
Dave Airlief453ba02008-11-07 14:05:41 -08002029 *
2030 * Represents a single crtc the connectors that it drives with what mode
2031 * and from which framebuffer it scans out from.
2032 *
2033 * This is used to set modes.
2034 */
2035struct drm_mode_set {
Dave Airlief453ba02008-11-07 14:05:41 -08002036 struct drm_framebuffer *fb;
2037 struct drm_crtc *crtc;
2038 struct drm_display_mode *mode;
2039
2040 uint32_t x;
2041 uint32_t y;
2042
2043 struct drm_connector **connectors;
2044 size_t num_connectors;
2045};
2046
2047/**
Jesse Barnes550cebc2011-11-07 12:03:20 -08002048 * struct drm_mode_config_funcs - basic driver provided mode setting functions
Jesse Barnes550cebc2011-11-07 12:03:20 -08002049 *
2050 * Some global (i.e. not per-CRTC, connector, etc) mode setting functions that
2051 * involve drivers.
Dave Airlief453ba02008-11-07 14:05:41 -08002052 */
2053struct drm_mode_config_funcs {
Daniel Vetter9953f412015-12-04 09:46:02 +01002054 /**
2055 * @fb_create:
2056 *
2057 * Create a new framebuffer object. The core does basic checks on the
2058 * requested metadata, but most of that is left to the driver. See
2059 * struct &drm_mode_fb_cmd2 for details.
2060 *
Daniel Vetterd55f5322015-12-08 09:49:19 +01002061 * If the parameters are deemed valid and the backing storage objects in
2062 * the underlying memory manager all exist, then the driver allocates
2063 * a new &drm_framebuffer structure, subclassed to contain
2064 * driver-specific information (like the internal native buffer object
2065 * references). It also needs to fill out all relevant metadata, which
2066 * should be done by calling drm_helper_mode_fill_fb_struct().
2067 *
2068 * The initialization is finalized by calling drm_framebuffer_init(),
2069 * which registers the framebuffer and makes it accessible to other
2070 * threads.
2071 *
Daniel Vetter9953f412015-12-04 09:46:02 +01002072 * RETURNS:
2073 *
2074 * A new framebuffer with an initial reference count of 1 or a negative
2075 * error code encoded with ERR_PTR().
2076 */
Jesse Barnes550cebc2011-11-07 12:03:20 -08002077 struct drm_framebuffer *(*fb_create)(struct drm_device *dev,
2078 struct drm_file *file_priv,
Ville Syrjälä1eb83452015-11-11 19:11:29 +02002079 const struct drm_mode_fb_cmd2 *mode_cmd);
Daniel Vetter9953f412015-12-04 09:46:02 +01002080
2081 /**
2082 * @output_poll_changed:
2083 *
2084 * Callback used by helpers to inform the driver of output configuration
2085 * changes.
2086 *
2087 * Drivers implementing fbdev emulation with the helpers can call
2088 * drm_fb_helper_hotplug_changed from this hook to inform the fbdev
2089 * helper of output changes.
2090 *
2091 * FIXME:
2092 *
2093 * Except that there's no vtable for device-level helper callbacks
2094 * there's no reason this is a core function.
2095 */
Dave Airlieeb1f8e42010-05-07 06:42:51 +00002096 void (*output_poll_changed)(struct drm_device *dev);
Daniel Vettercc4ceb42014-07-25 21:30:38 +02002097
Daniel Vetter9953f412015-12-04 09:46:02 +01002098 /**
2099 * @atomic_check:
2100 *
2101 * This is the only hook to validate an atomic modeset update. This
2102 * function must reject any modeset and state changes which the hardware
2103 * or driver doesn't support. This includes but is of course not limited
2104 * to:
2105 *
2106 * - Checking that the modes, framebuffers, scaling and placement
2107 * requirements and so on are within the limits of the hardware.
2108 *
2109 * - Checking that any hidden shared resources are not oversubscribed.
2110 * This can be shared PLLs, shared lanes, overall memory bandwidth,
2111 * display fifo space (where shared between planes or maybe even
2112 * CRTCs).
2113 *
2114 * - Checking that virtualized resources exported to userspace are not
2115 * oversubscribed. For various reasons it can make sense to expose
2116 * more planes, crtcs or encoders than which are physically there. One
2117 * example is dual-pipe operations (which generally should be hidden
2118 * from userspace if when lockstepped in hardware, exposed otherwise),
2119 * where a plane might need 1 hardware plane (if it's just on one
2120 * pipe), 2 hardware planes (when it spans both pipes) or maybe even
2121 * shared a hardware plane with a 2nd plane (if there's a compatible
2122 * plane requested on the area handled by the other pipe).
2123 *
2124 * - Check that any transitional state is possible and that if
2125 * requested, the update can indeed be done in the vblank period
2126 * without temporarily disabling some functions.
2127 *
2128 * - Check any other constraints the driver or hardware might have.
2129 *
2130 * - This callback also needs to correctly fill out the &drm_crtc_state
2131 * in this update to make sure that drm_atomic_crtc_needs_modeset()
2132 * reflects the nature of the possible update and returns true if and
2133 * only if the update cannot be applied without tearing within one
2134 * vblank on that CRTC. The core uses that information to reject
2135 * updates which require a full modeset (i.e. blanking the screen, or
2136 * at least pausing updates for a substantial amount of time) if
2137 * userspace has disallowed that in its request.
2138 *
2139 * - The driver also does not need to repeat basic input validation
2140 * like done for the corresponding legacy entry points. The core does
2141 * that before calling this hook.
2142 *
2143 * See the documentation of @atomic_commit for an exhaustive list of
2144 * error conditions which don't have to be checked at the
2145 * ->atomic_check() stage?
2146 *
2147 * See the documentation for struct &drm_atomic_state for how exactly
2148 * an atomic modeset update is described.
2149 *
2150 * Drivers using the atomic helpers can implement this hook using
2151 * drm_atomic_helper_check(), or one of the exported sub-functions of
2152 * it.
2153 *
2154 * RETURNS:
2155 *
2156 * 0 on success or one of the below negative error codes:
2157 *
2158 * - -EINVAL, if any of the above constraints are violated.
2159 *
2160 * - -EDEADLK, when returned from an attempt to acquire an additional
2161 * &drm_modeset_lock through drm_modeset_lock().
2162 *
2163 * - -ENOMEM, if allocating additional state sub-structures failed due
2164 * to lack of memory.
2165 *
2166 * - -EINTR, -EAGAIN or -ERESTARTSYS, if the IOCTL should be restarted.
2167 * This can either be due to a pending signal, or because the driver
2168 * needs to completely bail out to recover from an exceptional
2169 * situation like a GPU hang. From a userspace point all errors are
2170 * treated equally.
2171 */
Daniel Vettercc4ceb42014-07-25 21:30:38 +02002172 int (*atomic_check)(struct drm_device *dev,
Daniel Vetter9953f412015-12-04 09:46:02 +01002173 struct drm_atomic_state *state);
2174
2175 /**
2176 * @atomic_commit:
2177 *
2178 * This is the only hook to commit an atomic modeset update. The core
2179 * guarantees that @atomic_check has been called successfully before
2180 * calling this function, and that nothing has been changed in the
2181 * interim.
2182 *
2183 * See the documentation for struct &drm_atomic_state for how exactly
2184 * an atomic modeset update is described.
2185 *
2186 * Drivers using the atomic helpers can implement this hook using
2187 * drm_atomic_helper_commit(), or one of the exported sub-functions of
2188 * it.
2189 *
Maarten Lankhorst286dbb82016-04-26 16:11:34 +02002190 * Nonblocking commits (as indicated with the nonblock parameter) must
Daniel Vetter9953f412015-12-04 09:46:02 +01002191 * do any preparatory work which might result in an unsuccessful commit
2192 * in the context of this callback. The only exceptions are hardware
2193 * errors resulting in -EIO. But even in that case the driver must
2194 * ensure that the display pipe is at least running, to avoid
2195 * compositors crashing when pageflips don't work. Anything else,
2196 * specifically committing the update to the hardware, should be done
2197 * without blocking the caller. For updates which do not require a
2198 * modeset this must be guaranteed.
2199 *
2200 * The driver must wait for any pending rendering to the new
2201 * framebuffers to complete before executing the flip. It should also
2202 * wait for any pending rendering from other drivers if the underlying
Maarten Lankhorst286dbb82016-04-26 16:11:34 +02002203 * buffer is a shared dma-buf. Nonblocking commits must not wait for
Daniel Vetter9953f412015-12-04 09:46:02 +01002204 * rendering in the context of this callback.
2205 *
2206 * An application can request to be notified when the atomic commit has
2207 * completed. These events are per-CRTC and can be distinguished by the
2208 * CRTC index supplied in &drm_event to userspace.
2209 *
2210 * The drm core will supply a struct &drm_event in the event
2211 * member of each CRTC's &drm_crtc_state structure. This can be handled by the
2212 * drm_crtc_send_vblank_event() function, which the driver should call on
2213 * the provided event upon completion of the atomic commit. Note that if
2214 * the driver supports vblank signalling and timestamping the vblank
2215 * counters and timestamps must agree with the ones returned from page
2216 * flip events. With the current vblank helper infrastructure this can
2217 * be achieved by holding a vblank reference while the page flip is
2218 * pending, acquired through drm_crtc_vblank_get() and released with
2219 * drm_crtc_vblank_put(). Drivers are free to implement their own vblank
2220 * counter and timestamp tracking though, e.g. if they have accurate
2221 * timestamp registers in hardware.
2222 *
2223 * NOTE:
2224 *
2225 * Drivers are not allowed to shut down any display pipe successfully
2226 * enabled through an atomic commit on their own. Doing so can result in
2227 * compositors crashing if a page flip is suddenly rejected because the
2228 * pipe is off.
2229 *
2230 * RETURNS:
2231 *
2232 * 0 on success or one of the below negative error codes:
2233 *
Maarten Lankhorst286dbb82016-04-26 16:11:34 +02002234 * - -EBUSY, if a nonblocking updated is requested and there is
Daniel Vetter9953f412015-12-04 09:46:02 +01002235 * an earlier updated pending. Drivers are allowed to support a queue
2236 * of outstanding updates, but currently no driver supports that.
2237 * Note that drivers must wait for preceding updates to complete if a
2238 * synchronous update is requested, they are not allowed to fail the
2239 * commit in that case.
2240 *
2241 * - -ENOMEM, if the driver failed to allocate memory. Specifically
2242 * this can happen when trying to pin framebuffers, which must only
2243 * be done when committing the state.
2244 *
2245 * - -ENOSPC, as a refinement of the more generic -ENOMEM to indicate
2246 * that the driver has run out of vram, iommu space or similar GPU
2247 * address space needed for framebuffer.
2248 *
2249 * - -EIO, if the hardware completely died.
2250 *
2251 * - -EINTR, -EAGAIN or -ERESTARTSYS, if the IOCTL should be restarted.
2252 * This can either be due to a pending signal, or because the driver
2253 * needs to completely bail out to recover from an exceptional
2254 * situation like a GPU hang. From a userspace point of view all errors are
2255 * treated equally.
2256 *
2257 * This list is exhaustive. Specifically this hook is not allowed to
2258 * return -EINVAL (any invalid requests should be caught in
2259 * @atomic_check) or -EDEADLK (this function must not acquire
2260 * additional modeset locks).
2261 */
Daniel Vettercc4ceb42014-07-25 21:30:38 +02002262 int (*atomic_commit)(struct drm_device *dev,
Daniel Vetter9953f412015-12-04 09:46:02 +01002263 struct drm_atomic_state *state,
Maarten Lankhorst286dbb82016-04-26 16:11:34 +02002264 bool nonblock);
Daniel Vetter9953f412015-12-04 09:46:02 +01002265
2266 /**
2267 * @atomic_state_alloc:
2268 *
2269 * This optional hook can be used by drivers that want to subclass struct
2270 * &drm_atomic_state to be able to track their own driver-private global
2271 * state easily. If this hook is implemented, drivers must also
2272 * implement @atomic_state_clear and @atomic_state_free.
2273 *
2274 * RETURNS:
2275 *
2276 * A new &drm_atomic_state on success or NULL on failure.
2277 */
Maarten Lankhorst036ef572015-05-18 10:06:40 +02002278 struct drm_atomic_state *(*atomic_state_alloc)(struct drm_device *dev);
Daniel Vetter9953f412015-12-04 09:46:02 +01002279
2280 /**
2281 * @atomic_state_clear:
2282 *
2283 * This hook must clear any driver private state duplicated into the
2284 * passed-in &drm_atomic_state. This hook is called when the caller
2285 * encountered a &drm_modeset_lock deadlock and needs to drop all
2286 * already acquired locks as part of the deadlock avoidance dance
2287 * implemented in drm_modeset_lock_backoff().
2288 *
2289 * Any duplicated state must be invalidated since a concurrent atomic
2290 * update might change it, and the drm atomic interfaces always apply
2291 * updates as relative changes to the current state.
2292 *
2293 * Drivers that implement this must call drm_atomic_state_default_clear()
2294 * to clear common state.
2295 */
Maarten Lankhorst036ef572015-05-18 10:06:40 +02002296 void (*atomic_state_clear)(struct drm_atomic_state *state);
Daniel Vetter9953f412015-12-04 09:46:02 +01002297
2298 /**
2299 * @atomic_state_free:
2300 *
2301 * This hook needs driver private resources and the &drm_atomic_state
2302 * itself. Note that the core first calls drm_atomic_state_clear() to
2303 * avoid code duplicate between the clear and free hooks.
2304 *
2305 * Drivers that implement this must call drm_atomic_state_default_free()
2306 * to release common resources.
2307 */
Maarten Lankhorst036ef572015-05-18 10:06:40 +02002308 void (*atomic_state_free)(struct drm_atomic_state *state);
Dave Airlief453ba02008-11-07 14:05:41 -08002309};
2310
Jesse Barnesc1aaca22011-11-07 12:03:21 -08002311/**
Daniel Vetter2c0c33d2014-10-27 20:19:38 +01002312 * struct drm_mode_config - Mode configuration control structure
Jesse Barnesa62c93d2011-11-07 12:03:22 -08002313 * @mutex: mutex protecting KMS related lists and structures
Daniel Vetter2c0c33d2014-10-27 20:19:38 +01002314 * @connection_mutex: ww mutex protecting connector state and routing
2315 * @acquire_ctx: global implicit acquire context used by atomic drivers for
Daniel Vetterc6b0ca32015-12-04 09:46:01 +01002316 * legacy IOCTLs
Daniel Vetter2c0c33d2014-10-27 20:19:38 +01002317 * @fb_lock: mutex to protect fb state and lists
Jesse Barnesa62c93d2011-11-07 12:03:22 -08002318 * @num_fb: number of fbs available
2319 * @fb_list: list of framebuffers available
2320 * @num_connector: number of connectors on this device
2321 * @connector_list: list of connector objects
2322 * @num_encoder: number of encoders on this device
2323 * @encoder_list: list of encoder objects
Daniel Vetter2c0c33d2014-10-27 20:19:38 +01002324 * @num_overlay_plane: number of overlay planes on this device
2325 * @num_total_plane: number of universal (i.e. with primary/curso) planes on this device
2326 * @plane_list: list of plane objects
Jesse Barnesa62c93d2011-11-07 12:03:22 -08002327 * @num_crtc: number of CRTCs on this device
2328 * @crtc_list: list of CRTC objects
Daniel Vetter2c0c33d2014-10-27 20:19:38 +01002329 * @property_list: list of property objects
Jesse Barnesa62c93d2011-11-07 12:03:22 -08002330 * @min_width: minimum pixel width on this device
2331 * @min_height: minimum pixel height on this device
2332 * @max_width: maximum pixel width on this device
2333 * @max_height: maximum pixel height on this device
2334 * @funcs: core driver provided mode setting functions
2335 * @fb_base: base address of the framebuffer
Daniel Vetter2c0c33d2014-10-27 20:19:38 +01002336 * @poll_enabled: track polling support for this device
2337 * @poll_running: track polling status for this device
Daniel Vetterac3ba4a2016-05-31 23:11:10 +02002338 * @delayed_event: track delayed poll uevent deliver for this device
Jesse Barnesa62c93d2011-11-07 12:03:22 -08002339 * @output_poll_work: delayed work for polling in process context
Daniel Vetter2c0c33d2014-10-27 20:19:38 +01002340 * @property_blob_list: list of all the blob property objects
Daniel Stone8fb6e7a2015-04-20 19:22:54 +01002341 * @blob_lock: mutex for blob property allocation and management
Jesse Barnesa62c93d2011-11-07 12:03:22 -08002342 * @*_property: core property tracking
Lionel Landwerlin5488dc12016-02-26 17:05:00 +00002343 * @degamma_lut_property: LUT used to convert the framebuffer's colors to linear
2344 * gamma
2345 * @degamma_lut_size_property: size of the degamma LUT as supported by the
2346 * driver (read-only)
2347 * @ctm_property: Matrix used to convert colors after the lookup in the
2348 * degamma LUT
2349 * @gamma_lut_property: LUT used to convert the colors, after the CSC matrix, to
2350 * the gamma space of the connected screen (read-only)
2351 * @gamma_lut_size_property: size of the gamma LUT as supported by the driver
Daniel Vetter2c0c33d2014-10-27 20:19:38 +01002352 * @preferred_depth: preferred RBG pixel depth, used by fb helpers
2353 * @prefer_shadow: hint to userspace to prefer shadow-fb rendering
2354 * @async_page_flip: does this device support async flips on the primary plane?
2355 * @cursor_width: hint to userspace for max cursor width
2356 * @cursor_height: hint to userspace for max cursor height
Daniel Vetter9f2a7952016-06-08 14:19:02 +02002357 * @helper_private: mid-layer private data
Dave Airlief453ba02008-11-07 14:05:41 -08002358 *
Jesse Barnesa62c93d2011-11-07 12:03:22 -08002359 * Core mode resource tracking structure. All CRTC, encoders, and connectors
2360 * enumerated by the driver are added here, as are global properties. Some
2361 * global restrictions are also here, e.g. dimension restrictions.
Dave Airlief453ba02008-11-07 14:05:41 -08002362 */
2363struct drm_mode_config {
Jesse Barnesad2563c2009-01-19 17:21:45 +10002364 struct mutex mutex; /* protects configuration (mode lists etc.) */
Rob Clark51fd3712013-11-19 12:10:12 -05002365 struct drm_modeset_lock connection_mutex; /* protects connector->encoder and encoder->crtc links */
2366 struct drm_modeset_acquire_ctx *acquire_ctx; /* for legacy _lock_all() / _unlock_all() */
Daniel Vetterac3ba4a2016-05-31 23:11:10 +02002367
2368 /**
2369 * @idr_mutex:
2370 *
2371 * Mutex for KMS ID allocation and management. Protects both @crtc_idr
2372 * and @tile_idr.
2373 */
2374 struct mutex idr_mutex;
2375
2376 /**
2377 * @crtc_idr:
2378 *
2379 * Main KMS ID tracking object. Use this idr for all IDs, fb, crtc,
2380 * connector, modes - just makes life easier to have only one.
2381 */
2382 struct idr crtc_idr;
2383
2384 /**
2385 * @tile_idr:
2386 *
2387 * Use this idr for allocating new IDs for tiled sinks like use in some
2388 * high-res DP MST screens.
2389 */
2390 struct idr tile_idr;
Daniel Vetter4b096ac2012-12-10 21:19:18 +01002391
Daniel Vetter2c0c33d2014-10-27 20:19:38 +01002392 struct mutex fb_lock; /* proctects global and per-file fb lists */
Dave Airlief453ba02008-11-07 14:05:41 -08002393 int num_fb;
2394 struct list_head fb_list;
Daniel Vetter4b096ac2012-12-10 21:19:18 +01002395
Dave Airlief453ba02008-11-07 14:05:41 -08002396 int num_connector;
Maarten Lankhorst5fff80b2016-02-17 08:32:05 +01002397 struct ida connector_ida;
Dave Airlief453ba02008-11-07 14:05:41 -08002398 struct list_head connector_list;
2399 int num_encoder;
2400 struct list_head encoder_list;
Matt Ropere27dde32014-04-01 15:22:30 -07002401
2402 /*
2403 * Track # of overlay planes separately from # of total planes. By
2404 * default we only advertise overlay planes to userspace; if userspace
2405 * sets the "universal plane" capability bit, we'll go ahead and
2406 * expose all planes.
2407 */
2408 int num_overlay_plane;
2409 int num_total_plane;
Jesse Barnes8cf5c912011-11-14 14:51:27 -08002410 struct list_head plane_list;
Dave Airlief453ba02008-11-07 14:05:41 -08002411
2412 int num_crtc;
2413 struct list_head crtc_list;
2414
2415 struct list_head property_list;
2416
Dave Airlief453ba02008-11-07 14:05:41 -08002417 int min_width, min_height;
2418 int max_width, max_height;
Laurent Pincharte6ecefa2012-05-17 13:27:23 +02002419 const struct drm_mode_config_funcs *funcs;
Benjamin Herrenschmidtd883f7f2009-02-02 16:55:45 +11002420 resource_size_t fb_base;
Dave Airlief453ba02008-11-07 14:05:41 -08002421
Dave Airlieeb1f8e42010-05-07 06:42:51 +00002422 /* output poll support */
2423 bool poll_enabled;
Daniel Vetter905bc9f2012-10-23 18:23:36 +00002424 bool poll_running;
Daniel Vetter162b6a52015-01-21 08:45:21 +01002425 bool delayed_event;
Tejun Heo991ea752010-07-20 22:09:02 +02002426 struct delayed_work output_poll_work;
Dave Airlieeb1f8e42010-05-07 06:42:51 +00002427
Daniel Stone8fb6e7a2015-04-20 19:22:54 +01002428 struct mutex blob_lock;
2429
Dave Airlief453ba02008-11-07 14:05:41 -08002430 /* pointers to standard properties */
2431 struct list_head property_blob_list;
2432 struct drm_property *edid_property;
2433 struct drm_property *dpms_property;
Dave Airlie43aba7e2014-06-05 14:01:31 +10002434 struct drm_property *path_property;
Dave Airlie6f134d72014-10-20 16:30:50 +10002435 struct drm_property *tile_property;
Rob Clark9922ab52014-04-01 20:16:57 -04002436 struct drm_property *plane_type_property;
Sonika Jindal2a297cc2014-08-05 11:26:54 +05302437 struct drm_property *rotation_property;
Rob Clark6b4959f2014-12-18 16:01:53 -05002438 struct drm_property *prop_src_x;
2439 struct drm_property *prop_src_y;
2440 struct drm_property *prop_src_w;
2441 struct drm_property *prop_src_h;
2442 struct drm_property *prop_crtc_x;
2443 struct drm_property *prop_crtc_y;
2444 struct drm_property *prop_crtc_w;
2445 struct drm_property *prop_crtc_h;
2446 struct drm_property *prop_fb_id;
2447 struct drm_property *prop_crtc_id;
Daniel Vettereab3bbe2015-01-22 16:36:21 +01002448 struct drm_property *prop_active;
Daniel Stone955f3c32015-05-25 19:11:52 +01002449 struct drm_property *prop_mode_id;
Dave Airlief453ba02008-11-07 14:05:41 -08002450
2451 /* DVI-I properties */
2452 struct drm_property *dvi_i_subconnector_property;
2453 struct drm_property *dvi_i_select_subconnector_property;
2454
2455 /* TV properties */
2456 struct drm_property *tv_subconnector_property;
2457 struct drm_property *tv_select_subconnector_property;
2458 struct drm_property *tv_mode_property;
2459 struct drm_property *tv_left_margin_property;
2460 struct drm_property *tv_right_margin_property;
2461 struct drm_property *tv_top_margin_property;
2462 struct drm_property *tv_bottom_margin_property;
Francisco Jerezb6b79022009-08-02 04:19:20 +02002463 struct drm_property *tv_brightness_property;
2464 struct drm_property *tv_contrast_property;
2465 struct drm_property *tv_flicker_reduction_property;
Francisco Jereza75f0232009-08-12 02:30:10 +02002466 struct drm_property *tv_overscan_property;
2467 struct drm_property *tv_saturation_property;
2468 struct drm_property *tv_hue_property;
Dave Airlief453ba02008-11-07 14:05:41 -08002469
2470 /* Optional properties */
2471 struct drm_property *scaling_mode_property;
Vandana Kannanff587e42014-06-11 10:46:48 +05302472 struct drm_property *aspect_ratio_property;
Jakob Bornecrantz884840a2009-12-03 23:25:47 +00002473 struct drm_property *dirty_info_property;
Dave Airlie019d96c2011-09-29 16:20:42 +01002474
Lionel Landwerlin5488dc12016-02-26 17:05:00 +00002475 /* Optional color correction properties */
2476 struct drm_property *degamma_lut_property;
2477 struct drm_property *degamma_lut_size_property;
2478 struct drm_property *ctm_property;
2479 struct drm_property *gamma_lut_property;
2480 struct drm_property *gamma_lut_size_property;
2481
Dave Airlie5bb2bbf2014-11-10 10:18:15 +10002482 /* properties for virtual machine layout */
2483 struct drm_property *suggested_x_property;
2484 struct drm_property *suggested_y_property;
2485
Dave Airlie019d96c2011-09-29 16:20:42 +01002486 /* dumb ioctl parameters */
2487 uint32_t preferred_depth, prefer_shadow;
Keith Packard62f21042013-07-22 18:50:00 -07002488
2489 /* whether async page flip is supported or not */
2490 bool async_page_flip;
Alex Deucher8716ed42014-02-12 12:48:23 -05002491
Daniel Vetterac3ba4a2016-05-31 23:11:10 +02002492 /**
2493 * @allow_fb_modifiers:
2494 *
2495 * Whether the driver supports fb modifiers in the ADDFB2.1 ioctl call.
2496 */
Rob Clarke3eb3252015-02-05 14:41:52 +00002497 bool allow_fb_modifiers;
2498
Alex Deucher8716ed42014-02-12 12:48:23 -05002499 /* cursor size */
2500 uint32_t cursor_width, cursor_height;
Daniel Vetter9f2a7952016-06-08 14:19:02 +02002501
2502 struct drm_mode_config_helper_funcs *helper_private;
Dave Airlief453ba02008-11-07 14:05:41 -08002503};
2504
Rob Clarkdd275952014-11-25 20:29:46 -05002505/**
2506 * drm_for_each_plane_mask - iterate over planes specified by bitmask
2507 * @plane: the loop cursor
2508 * @dev: the DRM device
2509 * @plane_mask: bitmask of plane indices
2510 *
2511 * Iterate over all planes specified by bitmask.
2512 */
2513#define drm_for_each_plane_mask(plane, dev, plane_mask) \
2514 list_for_each_entry((plane), &(dev)->mode_config.plane_list, head) \
Jani Nikula373701b2015-11-24 21:21:55 +02002515 for_each_if ((plane_mask) & (1 << drm_plane_index(plane)))
Rob Clarkdd275952014-11-25 20:29:46 -05002516
Maarten Lankhorstead8b662016-01-07 10:59:19 +01002517/**
2518 * drm_for_each_encoder_mask - iterate over encoders specified by bitmask
2519 * @encoder: the loop cursor
2520 * @dev: the DRM device
2521 * @encoder_mask: bitmask of encoder indices
2522 *
2523 * Iterate over all encoders specified by bitmask.
2524 */
2525#define drm_for_each_encoder_mask(encoder, dev, encoder_mask) \
2526 list_for_each_entry((encoder), &(dev)->mode_config.encoder_list, head) \
2527 for_each_if ((encoder_mask) & (1 << drm_encoder_index(encoder)))
Rob Clarkdd275952014-11-25 20:29:46 -05002528
Dave Airlief453ba02008-11-07 14:05:41 -08002529#define obj_to_crtc(x) container_of(x, struct drm_crtc, base)
2530#define obj_to_connector(x) container_of(x, struct drm_connector, base)
2531#define obj_to_encoder(x) container_of(x, struct drm_encoder, base)
2532#define obj_to_mode(x) container_of(x, struct drm_display_mode, base)
2533#define obj_to_fb(x) container_of(x, struct drm_framebuffer, base)
2534#define obj_to_property(x) container_of(x, struct drm_property, base)
2535#define obj_to_blob(x) container_of(x, struct drm_property_blob, base)
Jesse Barnes8cf5c912011-11-14 14:51:27 -08002536#define obj_to_plane(x) container_of(x, struct drm_plane, base)
Dave Airlief453ba02008-11-07 14:05:41 -08002537
Sascha Hauer4a67d392012-02-06 10:58:17 +01002538struct drm_prop_enum_list {
2539 int type;
2540 char *name;
2541};
Dave Airlief453ba02008-11-07 14:05:41 -08002542
Ville Syrjäläf9882872015-12-09 16:19:31 +02002543extern __printf(6, 7)
2544int drm_crtc_init_with_planes(struct drm_device *dev,
2545 struct drm_crtc *crtc,
2546 struct drm_plane *primary,
2547 struct drm_plane *cursor,
2548 const struct drm_crtc_funcs *funcs,
2549 const char *name, ...);
Dave Airlief453ba02008-11-07 14:05:41 -08002550extern void drm_crtc_cleanup(struct drm_crtc *crtc);
Chris Wilson490d3d12016-05-27 20:05:00 +01002551
2552/**
2553 * drm_crtc_index - find the index of a registered CRTC
2554 * @crtc: CRTC to find index for
2555 *
2556 * Given a registered CRTC, return the index of that CRTC within a DRM
2557 * device's list of CRTCs.
2558 */
2559static inline unsigned int drm_crtc_index(struct drm_crtc *crtc)
2560{
2561 return crtc->index;
2562}
Russell Kingdb5f7a62014-01-02 21:27:33 +00002563
2564/**
2565 * drm_crtc_mask - find the mask of a registered CRTC
2566 * @crtc: CRTC to find mask for
2567 *
2568 * Given a registered CRTC, return the mask bit of that CRTC for an
2569 * encoder's possible_crtcs field.
2570 */
2571static inline uint32_t drm_crtc_mask(struct drm_crtc *crtc)
2572{
2573 return 1 << drm_crtc_index(crtc);
2574}
Dave Airlief453ba02008-11-07 14:05:41 -08002575
Ilia Mirkinb21e3af2013-08-07 22:34:48 -04002576extern void drm_connector_ida_init(void);
2577extern void drm_connector_ida_destroy(void);
Ville Syrjälä6bfc56a2012-03-13 12:35:48 +02002578extern int drm_connector_init(struct drm_device *dev,
2579 struct drm_connector *connector,
2580 const struct drm_connector_funcs *funcs,
2581 int connector_type);
Thomas Wood34ea3d32014-05-29 16:57:41 +01002582int drm_connector_register(struct drm_connector *connector);
2583void drm_connector_unregister(struct drm_connector *connector);
Dave Airlief453ba02008-11-07 14:05:41 -08002584
2585extern void drm_connector_cleanup(struct drm_connector *connector);
Maarten Lankhorst5fff80b2016-02-17 08:32:05 +01002586static inline unsigned drm_connector_index(struct drm_connector *connector)
2587{
2588 return connector->connector_id;
2589}
2590
Alexey Brodkin54d2c2d2016-04-19 15:24:51 +03002591/* helpers to {un}register all connectors from sysfs for device */
2592extern int drm_connector_register_all(struct drm_device *dev);
Alexey Brodkin6c87e5c2016-03-23 11:42:54 +03002593extern void drm_connector_unregister_all(struct drm_device *dev);
Dave Airlief453ba02008-11-07 14:05:41 -08002594
Ajay Kumar3d3f8b12015-01-20 22:08:44 +05302595extern int drm_bridge_add(struct drm_bridge *bridge);
2596extern void drm_bridge_remove(struct drm_bridge *bridge);
2597extern struct drm_bridge *of_drm_find_bridge(struct device_node *np);
2598extern int drm_bridge_attach(struct drm_device *dev, struct drm_bridge *bridge);
Sean Paul3b336ec2013-08-14 16:47:37 -04002599
Archit Taneja862e6862015-05-21 11:03:16 +05302600bool drm_bridge_mode_fixup(struct drm_bridge *bridge,
2601 const struct drm_display_mode *mode,
2602 struct drm_display_mode *adjusted_mode);
2603void drm_bridge_disable(struct drm_bridge *bridge);
2604void drm_bridge_post_disable(struct drm_bridge *bridge);
2605void drm_bridge_mode_set(struct drm_bridge *bridge,
2606 struct drm_display_mode *mode,
2607 struct drm_display_mode *adjusted_mode);
2608void drm_bridge_pre_enable(struct drm_bridge *bridge);
2609void drm_bridge_enable(struct drm_bridge *bridge);
2610
Ville Syrjälä13a3d912015-12-09 16:20:18 +02002611extern __printf(5, 6)
2612int drm_encoder_init(struct drm_device *dev,
2613 struct drm_encoder *encoder,
2614 const struct drm_encoder_funcs *funcs,
2615 int encoder_type, const char *name, ...);
Chris Wilson490d3d12016-05-27 20:05:00 +01002616
2617/**
2618 * drm_encoder_index - find the index of a registered encoder
2619 * @encoder: encoder to find index for
2620 *
2621 * Given a registered encoder, return the index of that encoder within a DRM
2622 * device's list of encoders.
2623 */
2624static inline unsigned int drm_encoder_index(struct drm_encoder *encoder)
2625{
2626 return encoder->index;
2627}
Dave Airlief453ba02008-11-07 14:05:41 -08002628
Thierry Reding3d887362014-01-13 14:33:20 +01002629/**
2630 * drm_encoder_crtc_ok - can a given crtc drive a given encoder?
2631 * @encoder: encoder to test
2632 * @crtc: crtc to test
2633 *
2634 * Return false if @encoder can't be driven by @crtc, true otherwise.
2635 */
2636static inline bool drm_encoder_crtc_ok(struct drm_encoder *encoder,
2637 struct drm_crtc *crtc)
2638{
2639 return !!(encoder->possible_crtcs & drm_crtc_mask(crtc));
2640}
2641
Ville Syrjäläb0b3b792015-12-09 16:19:55 +02002642extern __printf(8, 9)
2643int drm_universal_plane_init(struct drm_device *dev,
2644 struct drm_plane *plane,
2645 unsigned long possible_crtcs,
2646 const struct drm_plane_funcs *funcs,
2647 const uint32_t *formats,
2648 unsigned int format_count,
2649 enum drm_plane_type type,
2650 const char *name, ...);
Jesse Barnes8cf5c912011-11-14 14:51:27 -08002651extern int drm_plane_init(struct drm_device *dev,
2652 struct drm_plane *plane,
2653 unsigned long possible_crtcs,
2654 const struct drm_plane_funcs *funcs,
Thierry Reding45e37432015-08-12 16:54:28 +02002655 const uint32_t *formats, unsigned int format_count,
Matt Roperdc415ff2014-04-01 15:22:36 -07002656 bool is_primary);
Jesse Barnes8cf5c912011-11-14 14:51:27 -08002657extern void drm_plane_cleanup(struct drm_plane *plane);
Chris Wilson490d3d12016-05-27 20:05:00 +01002658
2659/**
2660 * drm_plane_index - find the index of a registered plane
2661 * @plane: plane to find index for
2662 *
2663 * Given a registered plane, return the index of that plane within a DRM
2664 * device's list of planes.
2665 */
2666static inline unsigned int drm_plane_index(struct drm_plane *plane)
2667{
2668 return plane->index;
2669}
Chandra Konduruf81338a2015-04-09 17:36:21 -07002670extern struct drm_plane * drm_plane_from_index(struct drm_device *dev, int idx);
Ville Syrjälä9125e612013-06-03 16:10:40 +03002671extern void drm_plane_force_disable(struct drm_plane *plane);
Laurent Pinchartead86102015-03-05 02:25:43 +02002672extern int drm_plane_check_pixel_format(const struct drm_plane *plane,
2673 u32 format);
Gustavo Padovanecb7e162014-12-01 15:40:09 -08002674extern void drm_crtc_get_hv_timing(const struct drm_display_mode *mode,
2675 int *hdisplay, int *vdisplay);
Matt Roperaf936292014-04-01 15:22:34 -07002676extern int drm_crtc_check_viewport(const struct drm_crtc *crtc,
2677 int x, int y,
2678 const struct drm_display_mode *mode,
2679 const struct drm_framebuffer *fb);
Jesse Barnes8cf5c912011-11-14 14:51:27 -08002680
Dave Airlief453ba02008-11-07 14:05:41 -08002681extern void drm_encoder_cleanup(struct drm_encoder *encoder);
2682
Ville Syrjäläd20d3172013-06-07 15:43:07 +00002683extern const char *drm_get_connector_status_name(enum drm_connector_status status);
Jesse Barnesac1bb362014-02-10 15:32:44 -08002684extern const char *drm_get_subpixel_order_name(enum subpixel_order order);
Ville Syrjäläd20d3172013-06-07 15:43:07 +00002685extern const char *drm_get_dpms_name(int val);
2686extern const char *drm_get_dvi_i_subconnector_name(int val);
2687extern const char *drm_get_dvi_i_select_name(int val);
2688extern const char *drm_get_tv_subconnector_name(int val);
2689extern const char *drm_get_tv_select_name(int val);
Kristian Høgsbergea39f832009-02-12 14:37:56 -05002690extern void drm_fb_release(struct drm_file *file_priv);
Daniel Stonee2f5d2e2015-05-22 13:34:51 +01002691extern void drm_property_destroy_user_blobs(struct drm_device *dev,
2692 struct drm_file *file_priv);
Adam Jacksonfbff4692012-09-18 10:58:47 -04002693extern bool drm_probe_ddc(struct i2c_adapter *adapter);
Dave Airlief453ba02008-11-07 14:05:41 -08002694extern struct edid *drm_get_edid(struct drm_connector *connector,
2695 struct i2c_adapter *adapter);
Lukas Wunner5cb8eaa2016-01-11 20:09:20 +01002696extern struct edid *drm_get_edid_switcheroo(struct drm_connector *connector,
2697 struct i2c_adapter *adapter);
Jani Nikula51f8da52013-09-27 15:08:27 +03002698extern struct edid *drm_edid_duplicate(const struct edid *edid);
Dave Airlief453ba02008-11-07 14:05:41 -08002699extern int drm_add_edid_modes(struct drm_connector *connector, struct edid *edid);
Dave Airlief453ba02008-11-07 14:05:41 -08002700extern void drm_mode_config_init(struct drm_device *dev);
Chris Wilsoneb033552011-01-24 15:11:08 +00002701extern void drm_mode_config_reset(struct drm_device *dev);
Dave Airlief453ba02008-11-07 14:05:41 -08002702extern void drm_mode_config_cleanup(struct drm_device *dev);
Dave Airlief453ba02008-11-07 14:05:41 -08002703
Dave Airlie43aba7e2014-06-05 14:01:31 +10002704extern int drm_mode_connector_set_path_property(struct drm_connector *connector,
Thierry Reding12e6cec2014-05-13 11:38:36 +02002705 const char *path);
Dave Airlie6f134d72014-10-20 16:30:50 +10002706int drm_mode_connector_set_tile_property(struct drm_connector *connector);
Dave Airlief453ba02008-11-07 14:05:41 -08002707extern int drm_mode_connector_update_edid_property(struct drm_connector *connector,
Thierry Reding12e6cec2014-05-13 11:38:36 +02002708 const struct edid *edid);
Rob Clark5ea22f22014-05-30 11:34:01 -04002709
Boris Brezillonb5571e92014-07-22 12:09:10 +02002710extern int drm_display_info_set_bus_formats(struct drm_display_info *info,
2711 const u32 *formats,
2712 unsigned int num_formats);
2713
Rob Clark5ea22f22014-05-30 11:34:01 -04002714static inline bool drm_property_type_is(struct drm_property *property,
2715 uint32_t type)
2716{
2717 /* instanceof for props.. handles extended type vs original types: */
2718 if (property->flags & DRM_MODE_PROP_EXTENDED_TYPE)
2719 return (property->flags & DRM_MODE_PROP_EXTENDED_TYPE) == type;
2720 return property->flags & type;
2721}
2722
2723static inline bool drm_property_type_valid(struct drm_property *property)
2724{
2725 if (property->flags & DRM_MODE_PROP_EXTENDED_TYPE)
2726 return !(property->flags & DRM_MODE_PROP_LEGACY_TYPE);
2727 return !!(property->flags & DRM_MODE_PROP_LEGACY_TYPE);
2728}
2729
Paulo Zanonic5431882012-05-15 18:09:02 -03002730extern int drm_object_property_set_value(struct drm_mode_object *obj,
2731 struct drm_property *property,
2732 uint64_t val);
2733extern int drm_object_property_get_value(struct drm_mode_object *obj,
2734 struct drm_property *property,
2735 uint64_t *value);
Dave Airlief453ba02008-11-07 14:05:41 -08002736extern int drm_framebuffer_init(struct drm_device *dev,
2737 struct drm_framebuffer *fb,
2738 const struct drm_framebuffer_funcs *funcs);
Daniel Vetter786b99e2012-12-02 21:53:40 +01002739extern struct drm_framebuffer *drm_framebuffer_lookup(struct drm_device *dev,
2740 uint32_t id);
Rob Clarkf7eff602012-09-05 21:48:38 +00002741extern void drm_framebuffer_remove(struct drm_framebuffer *fb);
Dave Airlief453ba02008-11-07 14:05:41 -08002742extern void drm_framebuffer_cleanup(struct drm_framebuffer *fb);
Daniel Vetter36206362012-12-10 20:42:17 +01002743extern void drm_framebuffer_unregister_private(struct drm_framebuffer *fb);
Dave Airlief453ba02008-11-07 14:05:41 -08002744
Paulo Zanonic5431882012-05-15 18:09:02 -03002745extern void drm_object_attach_property(struct drm_mode_object *obj,
2746 struct drm_property *property,
2747 uint64_t init_val);
Dave Airlief453ba02008-11-07 14:05:41 -08002748extern struct drm_property *drm_property_create(struct drm_device *dev, int flags,
2749 const char *name, int num_values);
Sascha Hauer4a67d392012-02-06 10:58:17 +01002750extern struct drm_property *drm_property_create_enum(struct drm_device *dev, int flags,
2751 const char *name,
2752 const struct drm_prop_enum_list *props,
2753 int num_values);
Rob Clark49e27542012-05-17 02:23:26 -06002754struct drm_property *drm_property_create_bitmask(struct drm_device *dev,
2755 int flags, const char *name,
2756 const struct drm_prop_enum_list *props,
Ville Syrjälä7689ffb2014-07-08 10:31:52 +05302757 int num_props,
2758 uint64_t supported_bits);
Sascha Hauerd9bc3c02012-02-06 10:58:18 +01002759struct drm_property *drm_property_create_range(struct drm_device *dev, int flags,
2760 const char *name,
2761 uint64_t min, uint64_t max);
Rob Clarkebc44cf2012-09-12 22:22:31 -05002762struct drm_property *drm_property_create_signed_range(struct drm_device *dev,
2763 int flags, const char *name,
2764 int64_t min, int64_t max);
Rob Clark98f75de2014-05-30 11:37:03 -04002765struct drm_property *drm_property_create_object(struct drm_device *dev,
2766 int flags, const char *name, uint32_t type);
Daniel Vetter960cd9d2015-01-21 08:47:38 +01002767struct drm_property *drm_property_create_bool(struct drm_device *dev, int flags,
2768 const char *name);
Daniel Stone6bcacf52015-04-20 19:22:55 +01002769struct drm_property_blob *drm_property_create_blob(struct drm_device *dev,
2770 size_t length,
2771 const void *data);
2772struct drm_property_blob *drm_property_lookup_blob(struct drm_device *dev,
2773 uint32_t id);
2774struct drm_property_blob *drm_property_reference_blob(struct drm_property_blob *blob);
2775void drm_property_unreference_blob(struct drm_property_blob *blob);
Dave Airlief453ba02008-11-07 14:05:41 -08002776extern void drm_property_destroy(struct drm_device *dev, struct drm_property *property);
2777extern int drm_property_add_enum(struct drm_property *property, int index,
2778 uint64_t value, const char *name);
2779extern int drm_mode_create_dvi_i_properties(struct drm_device *dev);
Thierry Reding2f763312014-10-13 12:45:57 +02002780extern int drm_mode_create_tv_properties(struct drm_device *dev,
2781 unsigned int num_modes,
Ville Syrjäläb7c914b2015-08-31 15:09:26 +03002782 const char * const modes[]);
Dave Airlief453ba02008-11-07 14:05:41 -08002783extern int drm_mode_create_scaling_mode_property(struct drm_device *dev);
Vandana Kannanff587e42014-06-11 10:46:48 +05302784extern int drm_mode_create_aspect_ratio_property(struct drm_device *dev);
Jakob Bornecrantz884840a2009-12-03 23:25:47 +00002785extern int drm_mode_create_dirty_info_property(struct drm_device *dev);
Dave Airlie5bb2bbf2014-11-10 10:18:15 +10002786extern int drm_mode_create_suggested_offset_properties(struct drm_device *dev);
Rob Clarkd34f20d2014-12-18 16:01:56 -05002787extern bool drm_property_change_valid_get(struct drm_property *property,
2788 uint64_t value, struct drm_mode_object **ref);
2789extern void drm_property_change_valid_put(struct drm_property *property,
2790 struct drm_mode_object *ref);
Dave Airlief453ba02008-11-07 14:05:41 -08002791
2792extern int drm_mode_connector_attach_encoder(struct drm_connector *connector,
2793 struct drm_encoder *encoder);
Sascha Hauer4cae5b82012-02-01 11:38:23 +01002794extern int drm_mode_crtc_set_gamma_size(struct drm_crtc *crtc,
Dave Airlief453ba02008-11-07 14:05:41 -08002795 int gamma_size);
Daniel Vetter7a9c9062009-09-15 22:57:31 +02002796extern struct drm_mode_object *drm_mode_object_find(struct drm_device *dev,
2797 uint32_t id, uint32_t type);
Dave Airlied0f37cf62016-04-15 15:10:36 +10002798void drm_mode_object_reference(struct drm_mode_object *obj);
2799void drm_mode_object_unreference(struct drm_mode_object *obj);
Rob Clark98f75de2014-05-30 11:37:03 -04002800
Dave Airlief453ba02008-11-07 14:05:41 -08002801/* IOCTLs */
2802extern int drm_mode_getresources(struct drm_device *dev,
2803 void *data, struct drm_file *file_priv);
Jesse Barnes8cf5c912011-11-14 14:51:27 -08002804extern int drm_mode_getplane_res(struct drm_device *dev, void *data,
2805 struct drm_file *file_priv);
Dave Airlief453ba02008-11-07 14:05:41 -08002806extern int drm_mode_getcrtc(struct drm_device *dev,
2807 void *data, struct drm_file *file_priv);
2808extern int drm_mode_getconnector(struct drm_device *dev,
2809 void *data, struct drm_file *file_priv);
Daniel Vetter2d13b672012-12-11 13:47:23 +01002810extern int drm_mode_set_config_internal(struct drm_mode_set *set);
Dave Airlief453ba02008-11-07 14:05:41 -08002811extern int drm_mode_setcrtc(struct drm_device *dev,
2812 void *data, struct drm_file *file_priv);
Jesse Barnes8cf5c912011-11-14 14:51:27 -08002813extern int drm_mode_getplane(struct drm_device *dev,
2814 void *data, struct drm_file *file_priv);
2815extern int drm_mode_setplane(struct drm_device *dev,
2816 void *data, struct drm_file *file_priv);
Dave Airlief453ba02008-11-07 14:05:41 -08002817extern int drm_mode_cursor_ioctl(struct drm_device *dev,
2818 void *data, struct drm_file *file_priv);
Dave Airlie4c813d42013-06-20 11:48:52 +10002819extern int drm_mode_cursor2_ioctl(struct drm_device *dev,
2820 void *data, struct drm_file *file_priv);
Dave Airlief453ba02008-11-07 14:05:41 -08002821extern int drm_mode_addfb(struct drm_device *dev,
2822 void *data, struct drm_file *file_priv);
Jesse Barnes308e5bc2011-11-14 14:51:28 -08002823extern int drm_mode_addfb2(struct drm_device *dev,
2824 void *data, struct drm_file *file_priv);
2825extern uint32_t drm_mode_legacy_fb_format(uint32_t bpp, uint32_t depth);
Dave Airlief453ba02008-11-07 14:05:41 -08002826extern int drm_mode_rmfb(struct drm_device *dev,
2827 void *data, struct drm_file *file_priv);
2828extern int drm_mode_getfb(struct drm_device *dev,
2829 void *data, struct drm_file *file_priv);
Jakob Bornecrantz884840a2009-12-03 23:25:47 +00002830extern int drm_mode_dirtyfb_ioctl(struct drm_device *dev,
2831 void *data, struct drm_file *file_priv);
Dave Airlief453ba02008-11-07 14:05:41 -08002832
2833extern int drm_mode_getproperty_ioctl(struct drm_device *dev,
2834 void *data, struct drm_file *file_priv);
2835extern int drm_mode_getblob_ioctl(struct drm_device *dev,
2836 void *data, struct drm_file *file_priv);
Daniel Stonee2f5d2e2015-05-22 13:34:51 +01002837extern int drm_mode_createblob_ioctl(struct drm_device *dev,
2838 void *data, struct drm_file *file_priv);
2839extern int drm_mode_destroyblob_ioctl(struct drm_device *dev,
2840 void *data, struct drm_file *file_priv);
Dave Airlief453ba02008-11-07 14:05:41 -08002841extern int drm_mode_connector_property_set_ioctl(struct drm_device *dev,
2842 void *data, struct drm_file *file_priv);
Dave Airlief453ba02008-11-07 14:05:41 -08002843extern int drm_mode_getencoder(struct drm_device *dev,
2844 void *data, struct drm_file *file_priv);
2845extern int drm_mode_gamma_get_ioctl(struct drm_device *dev,
2846 void *data, struct drm_file *file_priv);
2847extern int drm_mode_gamma_set_ioctl(struct drm_device *dev,
2848 void *data, struct drm_file *file_priv);
Thierry Reding18316c82012-12-20 15:41:44 +01002849extern u8 drm_match_cea_mode(const struct drm_display_mode *to_match);
Vandana Kannan0967e6a2014-04-01 16:26:59 +05302850extern enum hdmi_picture_aspect drm_get_cea_aspect_ratio(const u8 video_code);
Ma Lingf23c20c2009-03-26 19:26:23 +08002851extern bool drm_detect_hdmi_monitor(struct edid *edid);
Zhenyu Wang8fe97902010-09-19 14:27:28 +08002852extern bool drm_detect_monitor_audio(struct edid *edid);
Ville Syrjäläb1edd6a2013-01-17 16:31:30 +02002853extern bool drm_rgb_quant_range_selectable(struct edid *edid);
Kristian Høgsbergd91d8a32009-11-17 12:43:55 -05002854extern int drm_mode_page_flip_ioctl(struct drm_device *dev,
2855 void *data, struct drm_file *file_priv);
Zhao Yakuif0fda0a2009-09-03 09:33:48 +08002856extern int drm_add_modes_noedid(struct drm_connector *connector,
2857 int hdisplay, int vdisplay);
Gerd Hoffmann3cf70da2013-10-11 10:01:08 +02002858extern void drm_set_preferred_mode(struct drm_connector *connector,
2859 int hpref, int vpref);
Alex Deucher3c537882010-02-05 04:21:19 -05002860
Thomas Reim051963d2011-07-29 14:28:57 +00002861extern int drm_edid_header_is_valid(const u8 *raw_edid);
Todd Previte6ba2bd32015-04-21 11:09:41 -07002862extern bool drm_edid_block_valid(u8 *raw_edid, int block, bool print_bad_edid,
2863 bool *edid_corrupt);
Alex Deucher3c537882010-02-05 04:21:19 -05002864extern bool drm_edid_is_valid(struct edid *edid);
Jim Bride59f7c0f2016-04-14 10:18:35 -07002865extern void drm_edid_get_monitor_name(struct edid *edid, char *name,
2866 int buflen);
Dave Airlie138f9eb2014-10-20 16:17:17 +10002867
2868extern struct drm_tile_group *drm_mode_create_tile_group(struct drm_device *dev,
2869 char topology[8]);
2870extern struct drm_tile_group *drm_mode_get_tile_group(struct drm_device *dev,
2871 char topology[8]);
2872extern void drm_mode_put_tile_group(struct drm_device *dev,
2873 struct drm_tile_group *tg);
Dave Airlie1d42bbc2010-05-07 05:02:30 +00002874struct drm_display_mode *drm_mode_find_dmt(struct drm_device *dev,
Adam Jacksonf6e252b2012-04-13 16:33:31 -04002875 int hsize, int vsize, int fresh,
2876 bool rb);
Dave Airlieff72145b2011-02-07 12:16:14 +10002877
2878extern int drm_mode_create_dumb_ioctl(struct drm_device *dev,
2879 void *data, struct drm_file *file_priv);
2880extern int drm_mode_mmap_dumb_ioctl(struct drm_device *dev,
2881 void *data, struct drm_file *file_priv);
2882extern int drm_mode_destroy_dumb_ioctl(struct drm_device *dev,
2883 void *data, struct drm_file *file_priv);
Paulo Zanonic5431882012-05-15 18:09:02 -03002884extern int drm_mode_obj_get_properties_ioctl(struct drm_device *dev, void *data,
2885 struct drm_file *file_priv);
2886extern int drm_mode_obj_set_property_ioctl(struct drm_device *dev, void *data,
2887 struct drm_file *file_priv);
Thomas Wood3a5f87c2014-08-20 14:45:00 +01002888extern int drm_mode_plane_set_obj_prop(struct drm_plane *plane,
2889 struct drm_property *property,
2890 uint64_t value);
Rob Clarkd34f20d2014-12-18 16:01:56 -05002891extern int drm_mode_atomic_ioctl(struct drm_device *dev,
2892 void *data, struct drm_file *file_priv);
Dave Airlie248dbc22011-11-29 20:02:54 +00002893
Ville Syrjäläc1df5f32014-07-08 10:31:53 +05302894extern struct drm_property *drm_mode_create_rotation_property(struct drm_device *dev,
2895 unsigned int supported_rotations);
Ville Syrjälä3c9855f2014-07-08 10:31:56 +05302896extern unsigned int drm_rotation_simplify(unsigned int rotation,
2897 unsigned int supported_rotations);
Jyri Sarhaf8ed34a2016-06-07 15:09:14 +03002898extern void drm_crtc_enable_color_mgmt(struct drm_crtc *crtc,
2899 uint degamma_lut_size,
2900 bool has_ctm,
2901 uint gamma_lut_size);
Russell King96f60e32012-08-15 13:59:49 +01002902/* Helpers */
Rob Clarka2b34e22013-10-05 16:36:52 -04002903
2904static inline struct drm_plane *drm_plane_find(struct drm_device *dev,
2905 uint32_t id)
2906{
2907 struct drm_mode_object *mo;
2908 mo = drm_mode_object_find(dev, id, DRM_MODE_OBJECT_PLANE);
2909 return mo ? obj_to_plane(mo) : NULL;
2910}
2911
Russell King96f60e32012-08-15 13:59:49 +01002912static inline struct drm_crtc *drm_crtc_find(struct drm_device *dev,
2913 uint32_t id)
2914{
2915 struct drm_mode_object *mo;
2916 mo = drm_mode_object_find(dev, id, DRM_MODE_OBJECT_CRTC);
2917 return mo ? obj_to_crtc(mo) : NULL;
2918}
2919
2920static inline struct drm_encoder *drm_encoder_find(struct drm_device *dev,
2921 uint32_t id)
2922{
2923 struct drm_mode_object *mo;
2924 mo = drm_mode_object_find(dev, id, DRM_MODE_OBJECT_ENCODER);
2925 return mo ? obj_to_encoder(mo) : NULL;
2926}
2927
Dave Airlieb164d312016-04-27 11:10:09 +10002928/**
2929 * drm_connector_lookup - lookup connector object
2930 * @dev: DRM device
2931 * @id: connector object id
2932 *
2933 * This function looks up the connector object specified by id
2934 * add takes a reference to it.
2935 */
2936static inline struct drm_connector *drm_connector_lookup(struct drm_device *dev,
Rob Clarka2b34e22013-10-05 16:36:52 -04002937 uint32_t id)
2938{
2939 struct drm_mode_object *mo;
2940 mo = drm_mode_object_find(dev, id, DRM_MODE_OBJECT_CONNECTOR);
2941 return mo ? obj_to_connector(mo) : NULL;
2942}
2943
2944static inline struct drm_property *drm_property_find(struct drm_device *dev,
2945 uint32_t id)
2946{
2947 struct drm_mode_object *mo;
2948 mo = drm_mode_object_find(dev, id, DRM_MODE_OBJECT_PROPERTY);
2949 return mo ? obj_to_property(mo) : NULL;
2950}
2951
Lionel Landwerlin5488dc12016-02-26 17:05:00 +00002952/*
2953 * Extract a degamma/gamma LUT value provided by user and round it to the
2954 * precision supported by the hardware.
2955 */
2956static inline uint32_t drm_color_lut_extract(uint32_t user_input,
2957 uint32_t bit_precision)
2958{
Lionel Landwerlin644a8052016-03-22 14:10:33 +00002959 uint32_t val = user_input;
Lionel Landwerlin5488dc12016-02-26 17:05:00 +00002960 uint32_t max = 0xffff >> (16 - bit_precision);
2961
Lionel Landwerlin644a8052016-03-22 14:10:33 +00002962 /* Round only if we're not using full precision. */
2963 if (bit_precision < 16) {
2964 val += 1UL << (16 - bit_precision - 1);
2965 val >>= 16 - bit_precision;
2966 }
Lionel Landwerlin5488dc12016-02-26 17:05:00 +00002967
2968 return clamp_val(val, 0, max);
2969}
2970
Dave Airliee76d3992016-05-03 10:17:52 +10002971/**
Dave Airlied0f37cf62016-04-15 15:10:36 +10002972 * drm_framebuffer_reference - incr the fb refcnt
2973 * @fb: framebuffer
2974 *
2975 * This functions increments the fb's refcount.
2976 */
2977static inline void drm_framebuffer_reference(struct drm_framebuffer *fb)
2978{
2979 drm_mode_object_reference(&fb->base);
2980}
2981
2982/**
2983 * drm_framebuffer_unreference - unref a framebuffer
2984 * @fb: framebuffer to unref
2985 *
2986 * This functions decrements the fb's refcount and frees it if it drops to zero.
2987 */
2988static inline void drm_framebuffer_unreference(struct drm_framebuffer *fb)
2989{
2990 drm_mode_object_unreference(&fb->base);
2991}
2992
Dave Airlie747a5982016-04-15 15:10:35 +10002993/**
2994 * drm_framebuffer_read_refcount - read the framebuffer reference count.
2995 * @fb: framebuffer
2996 *
2997 * This functions returns the framebuffer's reference count.
2998 */
2999static inline uint32_t drm_framebuffer_read_refcount(struct drm_framebuffer *fb)
3000{
Dave Airlied0f37cf62016-04-15 15:10:36 +10003001 return atomic_read(&fb->base.refcount.refcount);
Dave Airlie747a5982016-04-15 15:10:35 +10003002}
3003
Dave Airlieb164d312016-04-27 11:10:09 +10003004/**
3005 * drm_connector_reference - incr the connector refcnt
3006 * @connector: connector
3007 *
3008 * This function increments the connector's refcount.
3009 */
3010static inline void drm_connector_reference(struct drm_connector *connector)
3011{
3012 drm_mode_object_reference(&connector->base);
3013}
3014
3015/**
3016 * drm_connector_unreference - unref a connector
3017 * @connector: connector to unref
3018 *
3019 * This function decrements the connector's refcount and frees it if it drops to zero.
3020 */
3021static inline void drm_connector_unreference(struct drm_connector *connector)
3022{
3023 drm_mode_object_unreference(&connector->base);
3024}
3025
Matt Ropere27dde32014-04-01 15:22:30 -07003026/* Plane list iterator for legacy (overlay only) planes. */
Daniel Vetter4ea50e92015-07-09 23:44:24 +02003027#define drm_for_each_legacy_plane(plane, dev) \
3028 list_for_each_entry(plane, &(dev)->mode_config.plane_list, head) \
Jani Nikula373701b2015-11-24 21:21:55 +02003029 for_each_if (plane->type == DRM_PLANE_TYPE_OVERLAY)
Matt Ropere27dde32014-04-01 15:22:30 -07003030
Daniel Vetter6295d602015-07-09 23:44:25 +02003031#define drm_for_each_plane(plane, dev) \
3032 list_for_each_entry(plane, &(dev)->mode_config.plane_list, head)
3033
3034#define drm_for_each_crtc(crtc, dev) \
3035 list_for_each_entry(crtc, &(dev)->mode_config.crtc_list, head)
3036
Daniel Vetter7a3f3d62015-07-09 23:44:28 +02003037static inline void
3038assert_drm_connector_list_read_locked(struct drm_mode_config *mode_config)
3039{
Daniel Vettercff20ba2015-07-09 23:44:33 +02003040 /*
3041 * The connector hotadd/remove code currently grabs both locks when
3042 * updating lists. Hence readers need only hold either of them to be
3043 * safe and the check amounts to
3044 *
3045 * WARN_ON(not_holding(A) && not_holding(B)).
3046 */
3047 WARN_ON(!mutex_is_locked(&mode_config->mutex) &&
3048 !drm_modeset_is_locked(&mode_config->connection_mutex));
Daniel Vetter7a3f3d62015-07-09 23:44:28 +02003049}
3050
Daniel Vetter6295d602015-07-09 23:44:25 +02003051#define drm_for_each_connector(connector, dev) \
Daniel Vetter7a3f3d62015-07-09 23:44:28 +02003052 for (assert_drm_connector_list_read_locked(&(dev)->mode_config), \
3053 connector = list_first_entry(&(dev)->mode_config.connector_list, \
3054 struct drm_connector, head); \
3055 &connector->head != (&(dev)->mode_config.connector_list); \
3056 connector = list_next_entry(connector, head))
Daniel Vetter6295d602015-07-09 23:44:25 +02003057
3058#define drm_for_each_encoder(encoder, dev) \
3059 list_for_each_entry(encoder, &(dev)->mode_config.encoder_list, head)
3060
3061#define drm_for_each_fb(fb, dev) \
Daniel Vetter4676ba02015-07-09 23:44:30 +02003062 for (WARN_ON(!mutex_is_locked(&(dev)->mode_config.fb_lock)), \
3063 fb = list_first_entry(&(dev)->mode_config.fb_list, \
3064 struct drm_framebuffer, head); \
3065 &fb->head != (&(dev)->mode_config.fb_list); \
3066 fb = list_next_entry(fb, head))
Daniel Vetter6295d602015-07-09 23:44:25 +02003067
Dave Airlief453ba02008-11-07 14:05:41 -08003068#endif /* __DRM_CRTC_H__ */