blob: 800c48e80811f7293265761572dcf0802971a1f7 [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)
Dave Airlief453ba02008-11-07 14:05:41 -0800121/*
122 * Describes a given display (e.g. CRT or flat panel) and its limitations.
123 */
124struct drm_display_info {
125 char name[DRM_DISPLAY_INFO_LEN];
Adam Jacksonfb439642010-08-03 14:38:16 -0400126
Dave Airlief453ba02008-11-07 14:05:41 -0800127 /* Physical size */
128 unsigned int width_mm;
129 unsigned int height_mm;
130
Dave Airlief453ba02008-11-07 14:05:41 -0800131 /* Clock limits FIXME: storage format */
132 unsigned int min_vfreq, max_vfreq;
133 unsigned int min_hfreq, max_hfreq;
134 unsigned int pixel_clock;
Jesse Barnes3b112282011-04-15 12:49:23 -0700135 unsigned int bpc;
Dave Airlief453ba02008-11-07 14:05:41 -0800136
Dave Airlief453ba02008-11-07 14:05:41 -0800137 enum subpixel_order subpixel_order;
Jesse Barnesda05a5a72011-04-15 13:48:57 -0700138 u32 color_formats;
Dave Airlief453ba02008-11-07 14:05:41 -0800139
Boris Brezillonb5571e92014-07-22 12:09:10 +0200140 const u32 *bus_formats;
141 unsigned int num_bus_formats;
142
Mario Kleiner5d02626d2014-06-05 09:52:10 -0400143 /* Mask of supported hdmi deep color modes */
144 u8 edid_hdmi_dc_modes;
145
Jesse Barnesebec9a7b2011-08-03 09:22:54 -0700146 u8 cea_rev;
Dave Airlief453ba02008-11-07 14:05:41 -0800147};
148
Dave Airlie138f9eb2014-10-20 16:17:17 +1000149/* data corresponds to displayid vend/prod/serial */
150struct drm_tile_group {
151 struct kref refcount;
152 struct drm_device *dev;
153 int id;
154 u8 group_data[8];
155};
156
Daniel Vetterc6b0ca32015-12-04 09:46:01 +0100157/**
158 * struct drm_framebuffer_funcs - framebuffer hooks
159 */
Dave Airlief453ba02008-11-07 14:05:41 -0800160struct drm_framebuffer_funcs {
Daniel Vetterc6b0ca32015-12-04 09:46:01 +0100161 /**
162 * @destroy:
163 *
164 * Clean up framebuffer resources, specifically also unreference the
165 * backing storage. The core guarantees to call this function for every
166 * framebuffer successfully created by ->fb_create() in
Daniel Vetterd55f5322015-12-08 09:49:19 +0100167 * &drm_mode_config_funcs. Drivers must also call
168 * drm_framebuffer_cleanup() to release DRM core resources for this
169 * framebuffer.
Daniel Vetterc6b0ca32015-12-04 09:46:01 +0100170 */
Dave Airlief453ba02008-11-07 14:05:41 -0800171 void (*destroy)(struct drm_framebuffer *framebuffer);
Daniel Vetterc6b0ca32015-12-04 09:46:01 +0100172
173 /**
174 * @create_handle:
175 *
176 * Create a buffer handle in the driver-specific buffer manager (either
177 * GEM or TTM) valid for the passed-in struct &drm_file. This is used by
178 * the core to implement the GETFB IOCTL, which returns (for
179 * sufficiently priviledged user) also a native buffer handle. This can
180 * be used for seamless transitions between modesetting clients by
181 * copying the current screen contents to a private buffer and blending
182 * between that and the new contents.
183 *
Daniel Vetterd55f5322015-12-08 09:49:19 +0100184 * GEM based drivers should call drm_gem_handle_create() to create the
185 * handle.
186 *
Daniel Vetterc6b0ca32015-12-04 09:46:01 +0100187 * RETURNS:
188 *
189 * 0 on success or a negative error code on failure.
190 */
Dave Airlief453ba02008-11-07 14:05:41 -0800191 int (*create_handle)(struct drm_framebuffer *fb,
192 struct drm_file *file_priv,
193 unsigned int *handle);
Daniel Vetterc6b0ca32015-12-04 09:46:01 +0100194 /**
195 * @dirty:
Jakob Bornecrantz884840a2009-12-03 23:25:47 +0000196 *
Daniel Vetterc6b0ca32015-12-04 09:46:01 +0100197 * Optional callback for the dirty fb IOCTL.
Jakob Bornecrantz884840a2009-12-03 23:25:47 +0000198 *
Daniel Vetterc6b0ca32015-12-04 09:46:01 +0100199 * Userspace can notify the driver via this callback that an area of the
200 * framebuffer has changed and should be flushed to the display
201 * hardware. This can also be used internally, e.g. by the fbdev
202 * emulation, though that's not the case currently.
203 *
204 * See documentation in drm_mode.h for the struct drm_mode_fb_dirty_cmd
205 * for more information as all the semantics and arguments have a one to
206 * one mapping on this function.
207 *
208 * RETURNS:
209 *
210 * 0 on success or a negative error code on failure.
Jakob Bornecrantz884840a2009-12-03 23:25:47 +0000211 */
Thomas Hellstrom02b00162010-10-05 12:43:02 +0200212 int (*dirty)(struct drm_framebuffer *framebuffer,
213 struct drm_file *file_priv, unsigned flags,
Jakob Bornecrantz884840a2009-12-03 23:25:47 +0000214 unsigned color, struct drm_clip_rect *clips,
215 unsigned num_clips);
Dave Airlief453ba02008-11-07 14:05:41 -0800216};
217
218struct drm_framebuffer {
219 struct drm_device *dev;
Rob Clarkf7eff602012-09-05 21:48:38 +0000220 /*
221 * Note that the fb is refcounted for the benefit of driver internals,
222 * for example some hw, disabling a CRTC/plane is asynchronous, and
223 * scanout does not actually complete until the next vblank. So some
224 * cleanup (like releasing the reference(s) on the backing GEM bo(s))
225 * should be deferred. In cases like this, the driver would like to
226 * hold a ref to the fb even though it has already been removed from
227 * userspace perspective.
Dave Airlied0f37cf62016-04-15 15:10:36 +1000228 * The refcount is stored inside the mode object.
Rob Clarkf7eff602012-09-05 21:48:38 +0000229 */
Daniel Vetter4b096ac2012-12-10 21:19:18 +0100230 /*
231 * Place on the dev->mode_config.fb_list, access protected by
232 * dev->mode_config.fb_lock.
233 */
Dave Airlief453ba02008-11-07 14:05:41 -0800234 struct list_head head;
235 struct drm_mode_object base;
236 const struct drm_framebuffer_funcs *funcs;
Ville Syrjälä01f2c772011-12-20 00:06:49 +0200237 unsigned int pitches[4];
238 unsigned int offsets[4];
Rob Clarke3eb3252015-02-05 14:41:52 +0000239 uint64_t modifier[4];
Dave Airlief453ba02008-11-07 14:05:41 -0800240 unsigned int width;
241 unsigned int height;
242 /* depth can be 15 or 16 */
243 unsigned int depth;
244 int bits_per_pixel;
245 int flags;
Jesse Barnes308e5bc2011-11-14 14:51:28 -0800246 uint32_t pixel_format; /* fourcc format */
Dave Airlief453ba02008-11-07 14:05:41 -0800247 struct list_head filp_head;
248};
249
250struct drm_property_blob {
251 struct drm_mode_object base;
Daniel Stone6bcacf52015-04-20 19:22:55 +0100252 struct drm_device *dev;
253 struct kref refcount;
Daniel Stonee2f5d2e2015-05-22 13:34:51 +0100254 struct list_head head_global;
255 struct list_head head_file;
Thierry Redingecbbe592014-05-13 11:36:13 +0200256 size_t length;
Ville Syrjäläd63f5e62012-03-13 12:35:49 +0200257 unsigned char data[];
Dave Airlief453ba02008-11-07 14:05:41 -0800258};
259
260struct drm_property_enum {
261 uint64_t value;
262 struct list_head head;
263 char name[DRM_PROP_NAME_LEN];
264};
265
266struct drm_property {
267 struct list_head head;
268 struct drm_mode_object base;
269 uint32_t flags;
270 char name[DRM_PROP_NAME_LEN];
271 uint32_t num_values;
272 uint64_t *values;
Rob Clark98f75de2014-05-30 11:37:03 -0400273 struct drm_device *dev;
Dave Airlief453ba02008-11-07 14:05:41 -0800274
Daniel Vetter3758b342014-11-19 18:38:10 +0100275 struct list_head enum_list;
Dave Airlief453ba02008-11-07 14:05:41 -0800276};
277
278struct drm_crtc;
279struct drm_connector;
280struct drm_encoder;
Kristian Høgsbergd91d8a32009-11-17 12:43:55 -0500281struct drm_pending_vblank_event;
Jesse Barnes8cf5c912011-11-14 14:51:27 -0800282struct drm_plane;
Sean Paul3b336ec2013-08-14 16:47:37 -0400283struct drm_bridge;
Daniel Vetter144ecb92014-10-27 20:28:44 +0100284struct drm_atomic_state;
285
Daniel Vetter4490d4c2015-12-04 09:45:45 +0100286struct drm_crtc_helper_funcs;
287struct drm_encoder_helper_funcs;
288struct drm_connector_helper_funcs;
289struct drm_plane_helper_funcs;
290
Daniel Vetter144ecb92014-10-27 20:28:44 +0100291/**
Daniel Vettercc4ceb42014-07-25 21:30:38 +0200292 * struct drm_crtc_state - mutable CRTC state
Daniel Vetter07cc0ef2014-11-27 15:49:39 +0100293 * @crtc: backpointer to the CRTC
Daniel Vetter144ecb92014-10-27 20:28:44 +0100294 * @enable: whether the CRTC should be enabled, gates all other state
Daniel Vetterd9b13622014-11-26 16:57:41 +0100295 * @active: whether the CRTC is actively displaying (used for DPMS)
Maarten Lankhorstfc596662015-07-21 13:28:57 +0200296 * @planes_changed: planes on this crtc are updated
297 * @mode_changed: crtc_state->mode or crtc_state->enable has been changed
298 * @active_changed: crtc_state->active has been toggled.
299 * @connectors_changed: connectors to this crtc have been updated
Lionel Landwerlin5488dc12016-02-26 17:05:00 +0000300 * @color_mgmt_changed: color management properties have changed (degamma or
301 * gamma LUT or CSC matrix)
Rob Clark6ddd3882014-11-21 15:28:31 -0500302 * @plane_mask: bitmask of (1 << drm_plane_index(plane)) of attached planes
Maarten Lankhorst4cd9fa52016-01-04 12:53:18 +0100303 * @connector_mask: bitmask of (1 << drm_connector_index(connector)) of attached connectors
Maarten Lankhorste87a52b2016-01-28 15:04:58 +0100304 * @encoder_mask: bitmask of (1 << drm_encoder_index(encoder)) of attached encoders
Daniel Vetter623369e2014-09-16 17:50:47 +0200305 * @last_vblank_count: for helpers and drivers to capture the vblank of the
306 * update to ensure framebuffer cleanup isn't done too early
Daniel Vetter2f324b42014-10-29 11:13:47 +0100307 * @adjusted_mode: for use by helpers and drivers to compute adjusted mode timings
Daniel Vetter144ecb92014-10-27 20:28:44 +0100308 * @mode: current mode timings
Lionel Landwerlin5488dc12016-02-26 17:05:00 +0000309 * @degamma_lut: Lookup table for converting framebuffer pixel data
310 * before apply the conversion matrix
311 * @ctm: Transformation matrix
312 * @gamma_lut: Lookup table for converting pixel data after the
313 * conversion matrix
Daniel Vetter144ecb92014-10-27 20:28:44 +0100314 * @event: optional pointer to a DRM event to signal upon completion of the
315 * state update
316 * @state: backpointer to global drm_atomic_state
Daniel Vetterd9b13622014-11-26 16:57:41 +0100317 *
318 * Note that the distinction between @enable and @active is rather subtile:
319 * Flipping @active while @enable is set without changing anything else may
320 * never return in a failure from the ->atomic_check callback. Userspace assumes
321 * that a DPMS On will always succeed. In other words: @enable controls resource
322 * assignment, @active controls the actual hardware state.
Daniel Vetter144ecb92014-10-27 20:28:44 +0100323 */
324struct drm_crtc_state {
Daniel Vetter07cc0ef2014-11-27 15:49:39 +0100325 struct drm_crtc *crtc;
326
Daniel Vettercc4ceb42014-07-25 21:30:38 +0200327 bool enable;
Daniel Vetterd9b13622014-11-26 16:57:41 +0100328 bool active;
Daniel Vetter144ecb92014-10-27 20:28:44 +0100329
Daniel Vetterc2fcd272014-11-05 00:14:14 +0100330 /* computed state bits used by helpers and drivers */
331 bool planes_changed : 1;
Daniel Vetter623369e2014-09-16 17:50:47 +0200332 bool mode_changed : 1;
Daniel Vettereab3bbe2015-01-22 16:36:21 +0100333 bool active_changed : 1;
Maarten Lankhorstfc596662015-07-21 13:28:57 +0200334 bool connectors_changed : 1;
Lionel Landwerlin5488dc12016-02-26 17:05:00 +0000335 bool color_mgmt_changed : 1;
Daniel Vetter623369e2014-09-16 17:50:47 +0200336
Rob Clark6ddd3882014-11-21 15:28:31 -0500337 /* attached planes bitmask:
338 * WARNING: transitional helpers do not maintain plane_mask so
339 * drivers not converted over to atomic helpers should not rely
340 * on plane_mask being accurate!
341 */
342 u32 plane_mask;
343
Maarten Lankhorst4cd9fa52016-01-04 12:53:18 +0100344 u32 connector_mask;
Maarten Lankhorste87a52b2016-01-28 15:04:58 +0100345 u32 encoder_mask;
Maarten Lankhorst4cd9fa52016-01-04 12:53:18 +0100346
Daniel Vetter623369e2014-09-16 17:50:47 +0200347 /* last_vblank_count: for vblank waits before cleanup */
348 u32 last_vblank_count;
Daniel Vetterc2fcd272014-11-05 00:14:14 +0100349
Daniel Vetter2f324b42014-10-29 11:13:47 +0100350 /* adjusted_mode: for use by helpers and drivers */
351 struct drm_display_mode adjusted_mode;
352
Daniel Vetter144ecb92014-10-27 20:28:44 +0100353 struct drm_display_mode mode;
354
Daniel Stone99cf4a22015-05-25 19:11:51 +0100355 /* blob property to expose current mode to atomic userspace */
356 struct drm_property_blob *mode_blob;
357
Lionel Landwerlin5488dc12016-02-26 17:05:00 +0000358 /* blob property to expose color management to userspace */
359 struct drm_property_blob *degamma_lut;
360 struct drm_property_blob *ctm;
361 struct drm_property_blob *gamma_lut;
362
Daniel Vetter144ecb92014-10-27 20:28:44 +0100363 struct drm_pending_vblank_event *event;
364
365 struct drm_atomic_state *state;
366};
Dave Airlief453ba02008-11-07 14:05:41 -0800367
368/**
Daniel Vetter3bf04012014-10-27 16:54:27 +0100369 * struct drm_crtc_funcs - control CRTCs for a given device
Dave Airlief453ba02008-11-07 14:05:41 -0800370 *
371 * The drm_crtc_funcs structure is the central CRTC management structure
372 * in the DRM. Each CRTC controls one or more connectors (note that the name
373 * CRTC is simply historical, a CRTC may control LVDS, VGA, DVI, TV out, etc.
374 * connectors, not just CRTs).
375 *
376 * Each driver is responsible for filling out this structure at startup time,
377 * in addition to providing other modesetting features, like i2c and DDC
378 * bus accessors.
379 */
380struct drm_crtc_funcs {
Daniel Vetter88548632015-12-04 09:45:48 +0100381 /**
382 * @reset:
383 *
384 * Reset CRTC hardware and software state to off. This function isn't
385 * called by the core directly, only through drm_mode_config_reset().
386 * It's not a helper hook only for historical reasons.
387 *
388 * Atomic drivers can use drm_atomic_helper_crtc_reset() to reset
389 * atomic state using this hook.
390 */
Chris Wilsoneb0335562011-01-24 15:11:08 +0000391 void (*reset)(struct drm_crtc *crtc);
Dave Airlief453ba02008-11-07 14:05:41 -0800392
Daniel Vetterf6da8c62015-12-04 09:46:00 +0100393 /**
394 * @cursor_set:
395 *
396 * Update the cursor image. The cursor position is relative to the CRTC
397 * and can be partially or fully outside of the visible area.
398 *
399 * Note that contrary to all other KMS functions the legacy cursor entry
400 * points don't take a framebuffer object, but instead take directly a
401 * raw buffer object id from the driver's buffer manager (which is
402 * either GEM or TTM for current drivers).
403 *
404 * This entry point is deprecated, drivers should instead implement
405 * universal plane support and register a proper cursor plane using
406 * drm_crtc_init_with_planes().
407 *
408 * This callback is optional
409 *
410 * RETURNS:
411 *
412 * 0 on success or a negative error code on failure.
413 */
Dave Airlief453ba02008-11-07 14:05:41 -0800414 int (*cursor_set)(struct drm_crtc *crtc, struct drm_file *file_priv,
415 uint32_t handle, uint32_t width, uint32_t height);
Daniel Vetterf6da8c62015-12-04 09:46:00 +0100416
417 /**
418 * @cursor_set2:
419 *
420 * Update the cursor image, including hotspot information. The hotspot
421 * must not affect the cursor position in CRTC coordinates, but is only
422 * meant as a hint for virtualized display hardware to coordinate the
423 * guests and hosts cursor position. The cursor hotspot is relative to
424 * the cursor image. Otherwise this works exactly like @cursor_set.
425 *
426 * This entry point is deprecated, drivers should instead implement
427 * universal plane support and register a proper cursor plane using
428 * drm_crtc_init_with_planes().
429 *
430 * This callback is optional.
431 *
432 * RETURNS:
433 *
434 * 0 on success or a negative error code on failure.
435 */
Dave Airlie4c813d42013-06-20 11:48:52 +1000436 int (*cursor_set2)(struct drm_crtc *crtc, struct drm_file *file_priv,
437 uint32_t handle, uint32_t width, uint32_t height,
438 int32_t hot_x, int32_t hot_y);
Daniel Vetterf6da8c62015-12-04 09:46:00 +0100439
440 /**
441 * @cursor_move:
442 *
443 * Update the cursor position. The cursor does not need to be visible
444 * when this hook is called.
445 *
446 * This entry point is deprecated, drivers should instead implement
447 * universal plane support and register a proper cursor plane using
448 * drm_crtc_init_with_planes().
449 *
450 * This callback is optional.
451 *
452 * RETURNS:
453 *
454 * 0 on success or a negative error code on failure.
455 */
Dave Airlief453ba02008-11-07 14:05:41 -0800456 int (*cursor_move)(struct drm_crtc *crtc, int x, int y);
457
Daniel Vetterf6da8c62015-12-04 09:46:00 +0100458 /**
459 * @gamma_set:
460 *
461 * Set gamma on the CRTC.
462 *
463 * This callback is optional.
464 *
465 * NOTE:
466 *
467 * Drivers that support gamma tables and also fbdev emulation through
468 * the provided helper library need to take care to fill out the gamma
469 * hooks for both. Currently there's a bit an unfortunate duplication
470 * going on, which should eventually be unified to just one set of
471 * hooks.
472 */
Dave Airlief453ba02008-11-07 14:05:41 -0800473 void (*gamma_set)(struct drm_crtc *crtc, u16 *r, u16 *g, u16 *b,
James Simmons72034252010-08-03 01:33:19 +0100474 uint32_t start, uint32_t size);
Daniel Vetter88548632015-12-04 09:45:48 +0100475
476 /**
477 * @destroy:
478 *
479 * Clean up plane resources. This is only called at driver unload time
480 * through drm_mode_config_cleanup() since a CRTC cannot be hotplugged
481 * in DRM.
482 */
Dave Airlief453ba02008-11-07 14:05:41 -0800483 void (*destroy)(struct drm_crtc *crtc);
484
Daniel Vetterf6da8c62015-12-04 09:46:00 +0100485 /**
486 * @set_config:
487 *
488 * This is the main legacy entry point to change the modeset state on a
489 * CRTC. All the details of the desired configuration are passed in a
490 * struct &drm_mode_set - see there for details.
491 *
492 * Drivers implementing atomic modeset should use
493 * drm_atomic_helper_set_config() to implement this hook.
494 *
495 * RETURNS:
496 *
497 * 0 on success or a negative error code on failure.
498 */
Dave Airlief453ba02008-11-07 14:05:41 -0800499 int (*set_config)(struct drm_mode_set *set);
Kristian Høgsbergd91d8a32009-11-17 12:43:55 -0500500
Daniel Vetterf6da8c62015-12-04 09:46:00 +0100501 /**
502 * @page_flip:
503 *
504 * Legacy entry point to schedule a flip to the given framebuffer.
505 *
506 * Page flipping is a synchronization mechanism that replaces the frame
507 * buffer being scanned out by the CRTC with a new frame buffer during
508 * vertical blanking, avoiding tearing (except when requested otherwise
509 * through the DRM_MODE_PAGE_FLIP_ASYNC flag). When an application
510 * requests a page flip the DRM core verifies that the new frame buffer
511 * is large enough to be scanned out by the CRTC in the currently
512 * configured mode and then calls the CRTC ->page_flip() operation with a
513 * pointer to the new frame buffer.
514 *
515 * The driver must wait for any pending rendering to the new framebuffer
516 * to complete before executing the flip. It should also wait for any
517 * pending rendering from other drivers if the underlying buffer is a
518 * shared dma-buf.
519 *
520 * An application can request to be notified when the page flip has
521 * completed. The drm core will supply a struct &drm_event in the event
522 * parameter in this case. This can be handled by the
523 * drm_crtc_send_vblank_event() function, which the driver should call on
524 * the provided event upon completion of the flip. Note that if
525 * the driver supports vblank signalling and timestamping the vblank
526 * counters and timestamps must agree with the ones returned from page
527 * flip events. With the current vblank helper infrastructure this can
528 * be achieved by holding a vblank reference while the page flip is
529 * pending, acquired through drm_crtc_vblank_get() and released with
530 * drm_crtc_vblank_put(). Drivers are free to implement their own vblank
531 * counter and timestamp tracking though, e.g. if they have accurate
532 * timestamp registers in hardware.
533 *
534 * FIXME:
535 *
536 * Up to that point drivers need to manage events themselves and can use
537 * even->base.list freely for that. Specifically they need to ensure
538 * that they don't send out page flip (or vblank) events for which the
539 * corresponding drm file has been closed already. The drm core
540 * unfortunately does not (yet) take care of that. Therefore drivers
541 * currently must clean up and release pending events in their
542 * ->preclose driver function.
543 *
544 * This callback is optional.
545 *
546 * NOTE:
547 *
548 * Very early versions of the KMS ABI mandated that the driver must
549 * block (but not reject) any rendering to the old framebuffer until the
550 * flip operation has completed and the old framebuffer is no longer
551 * visible. This requirement has been lifted, and userspace is instead
552 * expected to request delivery of an event and wait with recycling old
553 * buffers until such has been received.
554 *
555 * RETURNS:
556 *
557 * 0 on success or a negative error code on failure. Note that if a
558 * ->page_flip() operation is already pending the callback should return
559 * -EBUSY. Pageflips on a disabled CRTC (either by setting a NULL mode
560 * or just runtime disabled through DPMS respectively the new atomic
Daniel Vetter4cba6852015-12-08 09:49:20 +0100561 * "ACTIVE" state) should result in an -EINVAL error code. Note that
562 * drm_atomic_helper_page_flip() checks this already for atomic drivers.
Kristian Høgsbergd91d8a32009-11-17 12:43:55 -0500563 */
564 int (*page_flip)(struct drm_crtc *crtc,
565 struct drm_framebuffer *fb,
Keith Packarded8d1972013-07-22 18:49:58 -0700566 struct drm_pending_vblank_event *event,
567 uint32_t flags);
Paulo Zanonibffd9de02012-05-15 18:09:05 -0300568
Daniel Vetter88548632015-12-04 09:45:48 +0100569 /**
570 * @set_property:
571 *
572 * This is the legacy entry point to update a property attached to the
573 * CRTC.
574 *
575 * Drivers implementing atomic modeset should use
576 * drm_atomic_helper_crtc_set_property() to implement this hook.
577 *
578 * This callback is optional if the driver does not support any legacy
579 * driver-private properties.
580 *
581 * RETURNS:
582 *
583 * 0 on success or a negative error code on failure.
584 */
Paulo Zanonibffd9de02012-05-15 18:09:05 -0300585 int (*set_property)(struct drm_crtc *crtc,
586 struct drm_property *property, uint64_t val);
Daniel Vetter144ecb92014-10-27 20:28:44 +0100587
Daniel Vetter88548632015-12-04 09:45:48 +0100588 /**
589 * @atomic_duplicate_state:
590 *
591 * Duplicate the current atomic state for this CRTC and return it.
592 * The core and helpers gurantee that any atomic state duplicated with
593 * this hook and still owned by the caller (i.e. not transferred to the
594 * driver by calling ->atomic_commit() from struct
595 * &drm_mode_config_funcs) will be cleaned up by calling the
596 * @atomic_destroy_state hook in this structure.
597 *
598 * Atomic drivers which don't subclass struct &drm_crtc should use
599 * drm_atomic_helper_crtc_duplicate_state(). Drivers that subclass the
600 * state structure to extend it with driver-private state should use
601 * __drm_atomic_helper_crtc_duplicate_state() to make sure shared state is
602 * duplicated in a consistent fashion across drivers.
603 *
604 * It is an error to call this hook before crtc->state has been
605 * initialized correctly.
606 *
607 * NOTE:
608 *
609 * If the duplicate state references refcounted resources this hook must
610 * acquire a reference for each of them. The driver must release these
611 * references again in @atomic_destroy_state.
612 *
613 * RETURNS:
614 *
615 * Duplicated atomic state or NULL when the allocation failed.
616 */
Daniel Vetter144ecb92014-10-27 20:28:44 +0100617 struct drm_crtc_state *(*atomic_duplicate_state)(struct drm_crtc *crtc);
Daniel Vetter88548632015-12-04 09:45:48 +0100618
619 /**
620 * @atomic_destroy_state:
621 *
622 * Destroy a state duplicated with @atomic_duplicate_state and release
623 * or unreference all resources it references
624 */
Daniel Vetter144ecb92014-10-27 20:28:44 +0100625 void (*atomic_destroy_state)(struct drm_crtc *crtc,
Daniel Vettercc4ceb42014-07-25 21:30:38 +0200626 struct drm_crtc_state *state);
Daniel Vetter88548632015-12-04 09:45:48 +0100627
628 /**
629 * @atomic_set_property:
630 *
631 * Decode a driver-private property value and store the decoded value
632 * into the passed-in state structure. Since the atomic core decodes all
633 * standardized properties (even for extensions beyond the core set of
634 * properties which might not be implemented by all drivers) this
635 * requires drivers to subclass the state structure.
636 *
637 * Such driver-private properties should really only be implemented for
638 * truly hardware/vendor specific state. Instead it is preferred to
639 * standardize atomic extension and decode the properties used to expose
640 * such an extension in the core.
641 *
642 * Do not call this function directly, use
643 * drm_atomic_crtc_set_property() instead.
644 *
645 * This callback is optional if the driver does not support any
646 * driver-private atomic properties.
647 *
648 * NOTE:
649 *
650 * This function is called in the state assembly phase of atomic
651 * modesets, which can be aborted for any reason (including on
652 * userspace's request to just check whether a configuration would be
653 * possible). Drivers MUST NOT touch any persistent state (hardware or
654 * software) or data structures except the passed in @state parameter.
655 *
656 * Also since userspace controls in which order properties are set this
657 * function must not do any input validation (since the state update is
658 * incomplete and hence likely inconsistent). Instead any such input
659 * validation must be done in the various atomic_check callbacks.
660 *
661 * RETURNS:
662 *
663 * 0 if the property has been found, -EINVAL if the property isn't
664 * implemented by the driver (which should never happen, the core only
665 * asks for properties attached to this CRTC). No other validation is
666 * allowed by the driver. The core already checks that the property
667 * value is within the range (integer, valid enum value, ...) the driver
668 * set when registering the property.
669 */
Daniel Vetter144ecb92014-10-27 20:28:44 +0100670 int (*atomic_set_property)(struct drm_crtc *crtc,
671 struct drm_crtc_state *state,
672 struct drm_property *property,
673 uint64_t val);
Daniel Vetter88548632015-12-04 09:45:48 +0100674 /**
675 * @atomic_get_property:
676 *
677 * Reads out the decoded driver-private property. This is used to
Daniel Vetterc6b0ca32015-12-04 09:46:01 +0100678 * implement the GETCRTC IOCTL.
Daniel Vetter88548632015-12-04 09:45:48 +0100679 *
680 * Do not call this function directly, use
681 * drm_atomic_crtc_get_property() instead.
682 *
683 * This callback is optional if the driver does not support any
684 * driver-private atomic properties.
685 *
686 * RETURNS:
687 *
688 * 0 on success, -EINVAL if the property isn't implemented by the
689 * driver (which should never happen, the core only asks for
690 * properties attached to this CRTC).
691 */
Rob Clarkac9c9252014-12-18 16:01:47 -0500692 int (*atomic_get_property)(struct drm_crtc *crtc,
693 const struct drm_crtc_state *state,
694 struct drm_property *property,
695 uint64_t *val);
Dave Airlief453ba02008-11-07 14:05:41 -0800696};
697
698/**
Daniel Vetter3bf04012014-10-27 16:54:27 +0100699 * struct drm_crtc - central CRTC control structure
Jesse Barnes77491632011-11-07 12:03:14 -0800700 * @dev: parent DRM device
Daniel Vetter2c0c33d2014-10-27 20:19:38 +0100701 * @port: OF node used by drm_of_find_possible_crtcs()
Jesse Barnes77491632011-11-07 12:03:14 -0800702 * @head: list management
Rob Clark51fd3712013-11-19 12:10:12 -0500703 * @mutex: per-CRTC locking
Jesse Barnes77491632011-11-07 12:03:14 -0800704 * @base: base KMS object for ID tracking etc.
Matt Ropere13161a2014-04-01 15:22:38 -0700705 * @primary: primary plane for this CRTC
706 * @cursor: cursor plane for this CRTC
Daniel Vetter2c0c33d2014-10-27 20:19:38 +0100707 * @cursor_x: current x position of the cursor, used for universal cursor planes
708 * @cursor_y: current y position of the cursor, used for universal cursor planes
Dave Airlief453ba02008-11-07 14:05:41 -0800709 * @enabled: is this CRTC enabled?
Jesse Barnes77491632011-11-07 12:03:14 -0800710 * @mode: current mode timings
711 * @hwmode: mode timings as programmed to hw regs
Dave Airlief453ba02008-11-07 14:05:41 -0800712 * @x: x position on screen
713 * @y: y position on screen
Dave Airlief453ba02008-11-07 14:05:41 -0800714 * @funcs: CRTC control functions
Jesse Barnes77491632011-11-07 12:03:14 -0800715 * @gamma_size: size of gamma ramp
716 * @gamma_store: gamma ramp values
Jesse Barnes77491632011-11-07 12:03:14 -0800717 * @helper_private: mid-layer private data
Paulo Zanonibffd9de02012-05-15 18:09:05 -0300718 * @properties: property tracking for this CRTC
Daniel Vetter144ecb92014-10-27 20:28:44 +0100719 * @state: current atomic state for this CRTC
Daniel Vetter2c0c33d2014-10-27 20:19:38 +0100720 * @acquire_ctx: per-CRTC implicit acquire context used by atomic drivers for
Daniel Vetterc6b0ca32015-12-04 09:46:01 +0100721 * legacy IOCTLs
Dave Airlief453ba02008-11-07 14:05:41 -0800722 *
723 * Each CRTC may have one or more connectors associated with it. This structure
724 * allows the CRTC to be controlled.
725 */
726struct drm_crtc {
727 struct drm_device *dev;
Russell King7e435aa2014-06-15 11:07:12 +0100728 struct device_node *port;
Dave Airlief453ba02008-11-07 14:05:41 -0800729 struct list_head head;
730
Ville Syrjäläfa3ab4c2015-12-08 18:41:53 +0200731 char *name;
732
Daniel Vetter3bf04012014-10-27 16:54:27 +0100733 /*
Daniel Vetter29494c12012-12-02 02:18:25 +0100734 * crtc mutex
735 *
736 * This provides a read lock for the overall crtc state (mode, dpms
737 * state, ...) and a write lock for everything which can be update
738 * without a full modeset (fb, cursor data, ...)
739 */
Rob Clark51fd3712013-11-19 12:10:12 -0500740 struct drm_modeset_lock mutex;
Daniel Vetter29494c12012-12-02 02:18:25 +0100741
Dave Airlief453ba02008-11-07 14:05:41 -0800742 struct drm_mode_object base;
743
Matt Ropere13161a2014-04-01 15:22:38 -0700744 /* primary and cursor planes for CRTC */
745 struct drm_plane *primary;
746 struct drm_plane *cursor;
747
Matt Roper161d0dc2014-06-10 08:28:10 -0700748 /* position of cursor plane on crtc */
749 int cursor_x;
750 int cursor_y;
751
Dave Airlief453ba02008-11-07 14:05:41 -0800752 bool enabled;
753
Mario Kleiner27641c32010-10-23 04:20:23 +0200754 /* Requested mode from modesetting. */
Dave Airlief453ba02008-11-07 14:05:41 -0800755 struct drm_display_mode mode;
756
Mario Kleiner27641c32010-10-23 04:20:23 +0200757 /* Programmed mode in hw, after adjustments for encoders,
758 * crtc, panel scaling etc. Needed for timestamping etc.
759 */
760 struct drm_display_mode hwmode;
761
Dave Airlief453ba02008-11-07 14:05:41 -0800762 int x, y;
Dave Airlief453ba02008-11-07 14:05:41 -0800763 const struct drm_crtc_funcs *funcs;
764
Lionel Landwerlin5488dc12016-02-26 17:05:00 +0000765 /* Legacy FB CRTC gamma size for reporting to userspace */
Dave Airlief453ba02008-11-07 14:05:41 -0800766 uint32_t gamma_size;
767 uint16_t *gamma_store;
768
769 /* if you are using the helper */
Daniel Vetter4490d4c2015-12-04 09:45:45 +0100770 const struct drm_crtc_helper_funcs *helper_private;
Paulo Zanonibffd9de02012-05-15 18:09:05 -0300771
772 struct drm_object_properties properties;
Daniel Vetterd059f652014-07-25 18:07:40 +0200773
Daniel Vetter144ecb92014-10-27 20:28:44 +0100774 struct drm_crtc_state *state;
775
Daniel Vetterd059f652014-07-25 18:07:40 +0200776 /*
Daniel Vetterc6b0ca32015-12-04 09:46:01 +0100777 * For legacy crtc IOCTLs so that atomic drivers can get at the locking
Daniel Vetterd059f652014-07-25 18:07:40 +0200778 * acquire context.
779 */
780 struct drm_modeset_acquire_ctx *acquire_ctx;
Dave Airlief453ba02008-11-07 14:05:41 -0800781};
782
Daniel Vetter144ecb92014-10-27 20:28:44 +0100783/**
784 * struct drm_connector_state - mutable connector state
Daniel Vetter07cc0ef2014-11-27 15:49:39 +0100785 * @connector: backpointer to the connector
Daniel Vettercc4ceb42014-07-25 21:30:38 +0200786 * @crtc: CRTC to connect connector to, NULL if disabled
Daniel Vetter623369e2014-09-16 17:50:47 +0200787 * @best_encoder: can be used by helpers and drivers to select the encoder
Daniel Vetter144ecb92014-10-27 20:28:44 +0100788 * @state: backpointer to global drm_atomic_state
789 */
790struct drm_connector_state {
Daniel Vetter07cc0ef2014-11-27 15:49:39 +0100791 struct drm_connector *connector;
792
Rob Clark6ddd3882014-11-21 15:28:31 -0500793 struct drm_crtc *crtc; /* do not write directly, use drm_atomic_set_crtc_for_connector() */
Daniel Vetter144ecb92014-10-27 20:28:44 +0100794
Daniel Vetter623369e2014-09-16 17:50:47 +0200795 struct drm_encoder *best_encoder;
796
Daniel Vetter144ecb92014-10-27 20:28:44 +0100797 struct drm_atomic_state *state;
798};
Dave Airlief453ba02008-11-07 14:05:41 -0800799
800/**
Daniel Vetter3bf04012014-10-27 16:54:27 +0100801 * struct drm_connector_funcs - control connectors on a given device
Daniel Vetter144ecb92014-10-27 20:28:44 +0100802 *
Dave Airlief453ba02008-11-07 14:05:41 -0800803 * Each CRTC may have one or more connectors attached to it. The functions
804 * below allow the core DRM code to control connectors, enumerate available modes,
805 * etc.
806 */
807struct drm_connector_funcs {
Daniel Vetter6fe14ac2015-12-04 09:45:58 +0100808 /**
809 * @dpms:
810 *
811 * Legacy entry point to set the per-connector DPMS state. Legacy DPMS
812 * is exposed as a standard property on the connector, but diverted to
813 * this callback in the drm core. Note that atomic drivers don't
814 * implement the 4 level DPMS support on the connector any more, but
815 * instead only have an on/off "ACTIVE" property on the CRTC object.
816 *
817 * Drivers implementing atomic modeset should use
818 * drm_atomic_helper_connector_dpms() to implement this hook.
819 *
820 * RETURNS:
821 *
822 * 0 on success or a negative error code on failure.
823 */
Maarten Lankhorst9a69a9a2015-07-21 11:34:55 +0200824 int (*dpms)(struct drm_connector *connector, int mode);
Daniel Vetter88548632015-12-04 09:45:48 +0100825
826 /**
827 * @reset:
828 *
829 * Reset connector hardware and software state to off. This function isn't
830 * called by the core directly, only through drm_mode_config_reset().
831 * It's not a helper hook only for historical reasons.
832 *
833 * Atomic drivers can use drm_atomic_helper_connector_reset() to reset
834 * atomic state using this hook.
835 */
Chris Wilsoneb0335562011-01-24 15:11:08 +0000836 void (*reset)(struct drm_connector *connector);
Chris Wilson930a9e22010-09-14 11:07:23 +0100837
Daniel Vetter6fe14ac2015-12-04 09:45:58 +0100838 /**
839 * @detect:
840 *
841 * Check to see if anything is attached to the connector. The parameter
842 * force is set to false whilst polling, true when checking the
843 * connector due to a user request. force can be used by the driver to
844 * avoid expensive, destructive operations during automated probing.
845 *
846 * FIXME:
847 *
848 * Note that this hook is only called by the probe helper. It's not in
849 * the helper library vtable purely for historical reasons. The only DRM
850 * core entry point to probe connector state is @fill_modes.
851 *
852 * RETURNS:
853 *
854 * drm_connector_status indicating the connector's status.
Chris Wilson930a9e22010-09-14 11:07:23 +0100855 */
Chris Wilson7b334fc2010-09-09 23:51:02 +0100856 enum drm_connector_status (*detect)(struct drm_connector *connector,
Chris Wilson930a9e22010-09-14 11:07:23 +0100857 bool force);
Daniel Vetter6fe14ac2015-12-04 09:45:58 +0100858
859 /**
860 * @force:
861 *
862 * This function is called to update internal encoder state when the
863 * connector is forced to a certain state by userspace, either through
864 * the sysfs interfaces or on the kernel cmdline. In that case the
865 * @detect callback isn't called.
866 *
867 * FIXME:
868 *
869 * Note that this hook is only called by the probe helper. It's not in
870 * the helper library vtable purely for historical reasons. The only DRM
871 * core entry point to probe connector state is @fill_modes.
872 */
873 void (*force)(struct drm_connector *connector);
874
875 /**
876 * @fill_modes:
877 *
878 * Entry point for output detection and basic mode validation. The
879 * driver should reprobe the output if needed (e.g. when hotplug
880 * handling is unreliable), add all detected modes to connector->modes
881 * and filter out any the device can't support in any configuration. It
882 * also needs to filter out any modes wider or higher than the
883 * parameters max_width and max_height indicate.
884 *
885 * The drivers must also prune any modes no longer valid from
886 * connector->modes. Furthermore it must update connector->status and
887 * connector->edid. If no EDID has been received for this output
888 * connector->edid must be NULL.
889 *
890 * Drivers using the probe helpers should use
891 * drm_helper_probe_single_connector_modes() or
892 * drm_helper_probe_single_connector_modes_nomerge() to implement this
893 * function.
894 *
895 * RETURNS:
896 *
897 * The number of modes detected and filled into connector->modes.
898 */
Jesse Barnes40a518d2009-01-12 12:05:32 -0800899 int (*fill_modes)(struct drm_connector *connector, uint32_t max_width, uint32_t max_height);
Daniel Vetter88548632015-12-04 09:45:48 +0100900
901 /**
902 * @set_property:
903 *
904 * This is the legacy entry point to update a property attached to the
905 * connector.
906 *
907 * Drivers implementing atomic modeset should use
908 * drm_atomic_helper_connector_set_property() to implement this hook.
909 *
910 * This callback is optional if the driver does not support any legacy
911 * driver-private properties.
912 *
913 * RETURNS:
914 *
915 * 0 on success or a negative error code on failure.
916 */
Dave Airlief453ba02008-11-07 14:05:41 -0800917 int (*set_property)(struct drm_connector *connector, struct drm_property *property,
918 uint64_t val);
Daniel Vetter88548632015-12-04 09:45:48 +0100919
920 /**
921 * @destroy:
922 *
923 * Clean up connector resources. This is called at driver unload time
924 * through drm_mode_config_cleanup(). It can also be called at runtime
925 * when a connector is being hot-unplugged for drivers that support
926 * connector hotplugging (e.g. DisplayPort MST).
927 */
Dave Airlief453ba02008-11-07 14:05:41 -0800928 void (*destroy)(struct drm_connector *connector);
Daniel Vetter144ecb92014-10-27 20:28:44 +0100929
Daniel Vetter88548632015-12-04 09:45:48 +0100930 /**
931 * @atomic_duplicate_state:
932 *
933 * Duplicate the current atomic state for this connector and return it.
934 * The core and helpers gurantee that any atomic state duplicated with
935 * this hook and still owned by the caller (i.e. not transferred to the
936 * driver by calling ->atomic_commit() from struct
937 * &drm_mode_config_funcs) will be cleaned up by calling the
938 * @atomic_destroy_state hook in this structure.
939 *
940 * Atomic drivers which don't subclass struct &drm_connector_state should use
941 * drm_atomic_helper_connector_duplicate_state(). Drivers that subclass the
942 * state structure to extend it with driver-private state should use
943 * __drm_atomic_helper_connector_duplicate_state() to make sure shared state is
944 * duplicated in a consistent fashion across drivers.
945 *
946 * It is an error to call this hook before connector->state has been
947 * initialized correctly.
948 *
949 * NOTE:
950 *
951 * If the duplicate state references refcounted resources this hook must
952 * acquire a reference for each of them. The driver must release these
953 * references again in @atomic_destroy_state.
954 *
955 * RETURNS:
956 *
957 * Duplicated atomic state or NULL when the allocation failed.
958 */
Daniel Vetter144ecb92014-10-27 20:28:44 +0100959 struct drm_connector_state *(*atomic_duplicate_state)(struct drm_connector *connector);
Daniel Vetter88548632015-12-04 09:45:48 +0100960
961 /**
962 * @atomic_destroy_state:
963 *
964 * Destroy a state duplicated with @atomic_duplicate_state and release
965 * or unreference all resources it references
966 */
Daniel Vetter144ecb92014-10-27 20:28:44 +0100967 void (*atomic_destroy_state)(struct drm_connector *connector,
Daniel Vettercc4ceb42014-07-25 21:30:38 +0200968 struct drm_connector_state *state);
Daniel Vetter88548632015-12-04 09:45:48 +0100969
970 /**
971 * @atomic_set_property:
972 *
973 * Decode a driver-private property value and store the decoded value
974 * into the passed-in state structure. Since the atomic core decodes all
975 * standardized properties (even for extensions beyond the core set of
976 * properties which might not be implemented by all drivers) this
977 * requires drivers to subclass the state structure.
978 *
979 * Such driver-private properties should really only be implemented for
980 * truly hardware/vendor specific state. Instead it is preferred to
981 * standardize atomic extension and decode the properties used to expose
982 * such an extension in the core.
983 *
984 * Do not call this function directly, use
985 * drm_atomic_connector_set_property() instead.
986 *
987 * This callback is optional if the driver does not support any
988 * driver-private atomic properties.
989 *
990 * NOTE:
991 *
992 * This function is called in the state assembly phase of atomic
993 * modesets, which can be aborted for any reason (including on
994 * userspace's request to just check whether a configuration would be
995 * possible). Drivers MUST NOT touch any persistent state (hardware or
996 * software) or data structures except the passed in @state parameter.
997 *
998 * Also since userspace controls in which order properties are set this
999 * function must not do any input validation (since the state update is
1000 * incomplete and hence likely inconsistent). Instead any such input
1001 * validation must be done in the various atomic_check callbacks.
1002 *
1003 * RETURNS:
1004 *
1005 * 0 if the property has been found, -EINVAL if the property isn't
1006 * implemented by the driver (which shouldn't ever happen, the core only
1007 * asks for properties attached to this connector). No other validation
1008 * is allowed by the driver. The core already checks that the property
1009 * value is within the range (integer, valid enum value, ...) the driver
1010 * set when registering the property.
1011 */
Daniel Vetter144ecb92014-10-27 20:28:44 +01001012 int (*atomic_set_property)(struct drm_connector *connector,
1013 struct drm_connector_state *state,
1014 struct drm_property *property,
1015 uint64_t val);
Daniel Vetter88548632015-12-04 09:45:48 +01001016
1017 /**
1018 * @atomic_get_property:
1019 *
1020 * Reads out the decoded driver-private property. This is used to
Daniel Vetterc6b0ca32015-12-04 09:46:01 +01001021 * implement the GETCONNECTOR IOCTL.
Daniel Vetter88548632015-12-04 09:45:48 +01001022 *
1023 * Do not call this function directly, use
1024 * drm_atomic_connector_get_property() instead.
1025 *
1026 * This callback is optional if the driver does not support any
1027 * driver-private atomic properties.
1028 *
1029 * RETURNS:
1030 *
1031 * 0 on success, -EINVAL if the property isn't implemented by the
1032 * driver (which shouldn't ever happen, the core only asks for
1033 * properties attached to this connector).
1034 */
Rob Clarkac9c9252014-12-18 16:01:47 -05001035 int (*atomic_get_property)(struct drm_connector *connector,
1036 const struct drm_connector_state *state,
1037 struct drm_property *property,
1038 uint64_t *val);
Dave Airlief453ba02008-11-07 14:05:41 -08001039};
1040
Jesse Barnes6c3db922011-11-07 12:03:16 -08001041/**
Daniel Vetter3bf04012014-10-27 16:54:27 +01001042 * struct drm_encoder_funcs - encoder controls
Jesse Barnes6c3db922011-11-07 12:03:16 -08001043 *
1044 * Encoders sit between CRTCs and connectors.
1045 */
Dave Airlief453ba02008-11-07 14:05:41 -08001046struct drm_encoder_funcs {
Daniel Vetter88548632015-12-04 09:45:48 +01001047 /**
1048 * @reset:
1049 *
1050 * Reset encoder hardware and software state to off. This function isn't
1051 * called by the core directly, only through drm_mode_config_reset().
1052 * It's not a helper hook only for historical reasons.
1053 */
Chris Wilsoneb0335562011-01-24 15:11:08 +00001054 void (*reset)(struct drm_encoder *encoder);
Daniel Vetter88548632015-12-04 09:45:48 +01001055
1056 /**
1057 * @destroy:
1058 *
1059 * Clean up encoder resources. This is only called at driver unload time
1060 * through drm_mode_config_cleanup() since an encoder cannot be
1061 * hotplugged in DRM.
1062 */
Dave Airlief453ba02008-11-07 14:05:41 -08001063 void (*destroy)(struct drm_encoder *encoder);
1064};
1065
Ben Skeggsafe887d2012-01-12 16:00:57 +10001066#define DRM_CONNECTOR_MAX_ENCODER 3
Dave Airlief453ba02008-11-07 14:05:41 -08001067
1068/**
Daniel Vetter3bf04012014-10-27 16:54:27 +01001069 * struct drm_encoder - central DRM encoder structure
Jesse Barnesdb3e4492011-11-07 12:03:17 -08001070 * @dev: parent DRM device
1071 * @head: list management
1072 * @base: base KMS object
Jani Nikulae5748942014-05-14 16:58:20 +03001073 * @name: encoder name
Jesse Barnesdb3e4492011-11-07 12:03:17 -08001074 * @encoder_type: one of the %DRM_MODE_ENCODER_<foo> types in drm_mode.h
1075 * @possible_crtcs: bitmask of potential CRTC bindings
1076 * @possible_clones: bitmask of potential sibling encoders for cloning
1077 * @crtc: currently bound CRTC
Sean Paul3b336ec2013-08-14 16:47:37 -04001078 * @bridge: bridge associated to the encoder
Jesse Barnesdb3e4492011-11-07 12:03:17 -08001079 * @funcs: control functions
1080 * @helper_private: mid-layer private data
1081 *
1082 * CRTCs drive pixels to encoders, which convert them into signals
1083 * appropriate for a given connector or set of connectors.
Dave Airlief453ba02008-11-07 14:05:41 -08001084 */
1085struct drm_encoder {
1086 struct drm_device *dev;
1087 struct list_head head;
1088
1089 struct drm_mode_object base;
Jani Nikulae5748942014-05-14 16:58:20 +03001090 char *name;
Dave Airlief453ba02008-11-07 14:05:41 -08001091 int encoder_type;
1092 uint32_t possible_crtcs;
1093 uint32_t possible_clones;
1094
1095 struct drm_crtc *crtc;
Sean Paul3b336ec2013-08-14 16:47:37 -04001096 struct drm_bridge *bridge;
Dave Airlief453ba02008-11-07 14:05:41 -08001097 const struct drm_encoder_funcs *funcs;
Daniel Vetter4490d4c2015-12-04 09:45:45 +01001098 const struct drm_encoder_helper_funcs *helper_private;
Dave Airlief453ba02008-11-07 14:05:41 -08001099};
1100
Dave Airlieeb1f8e4f32010-05-07 06:42:51 +00001101/* should we poll this connector for connects and disconnects */
1102/* hot plug detectable */
1103#define DRM_CONNECTOR_POLL_HPD (1 << 0)
1104/* poll for connections */
1105#define DRM_CONNECTOR_POLL_CONNECT (1 << 1)
1106/* can cleanly poll for disconnections without flickering the screen */
1107/* DACs should rarely do this without a lot of testing */
1108#define DRM_CONNECTOR_POLL_DISCONNECT (1 << 2)
1109
Wu Fengguang76adaa342011-09-05 14:23:20 +08001110#define MAX_ELD_BYTES 128
1111
Dave Airlief453ba02008-11-07 14:05:41 -08001112/**
Daniel Vetter3bf04012014-10-27 16:54:27 +01001113 * struct drm_connector - central DRM connector control structure
Jesse Barnes72252542011-11-07 12:03:18 -08001114 * @dev: parent DRM device
1115 * @kdev: kernel device for sysfs attributes
1116 * @attr: sysfs attributes
1117 * @head: list management
1118 * @base: base KMS object
Jani Nikula2abdd312014-05-14 16:58:19 +03001119 * @name: connector name
Jesse Barnes72252542011-11-07 12:03:18 -08001120 * @connector_type: one of the %DRM_MODE_CONNECTOR_<foo> types from drm_mode.h
1121 * @connector_type_id: index into connector type enum
Dave Airlief453ba02008-11-07 14:05:41 -08001122 * @interlace_allowed: can this connector handle interlaced modes?
1123 * @doublescan_allowed: can this connector handle doublescan?
Daniel Vetter2c0c33d2014-10-27 20:19:38 +01001124 * @stereo_allowed: can this connector handle stereo modes?
Jesse Barnes72252542011-11-07 12:03:18 -08001125 * @modes: modes available on this connector (from fill_modes() + user)
1126 * @status: one of the drm_connector_status enums (connected, not, or unknown)
1127 * @probed_modes: list of modes derived directly from the display
1128 * @display_info: information about attached display (e.g. from EDID)
Dave Airlief453ba02008-11-07 14:05:41 -08001129 * @funcs: connector control functions
Jesse Barnes72252542011-11-07 12:03:18 -08001130 * @edid_blob_ptr: DRM property containing EDID if present
Paulo Zanoni7e3bdf42012-05-15 18:09:01 -03001131 * @properties: property tracking for this connector
Daniel Vetter2c0c33d2014-10-27 20:19:38 +01001132 * @path_blob_ptr: DRM blob property data for the DP MST path property
Jesse Barnes72252542011-11-07 12:03:18 -08001133 * @polled: a %DRM_CONNECTOR_POLL_<foo> value for core driven polling
1134 * @dpms: current dpms state
1135 * @helper_private: mid-layer private data
Daniel Vetter2c0c33d2014-10-27 20:19:38 +01001136 * @cmdline_mode: mode line parsed from the kernel cmdline for this connector
Jesse Barnes72252542011-11-07 12:03:18 -08001137 * @force: a %DRM_FORCE_<foo> state for forced mode sets
Daniel Vetter2c0c33d2014-10-27 20:19:38 +01001138 * @override_edid: has the EDID been overwritten through debugfs for testing?
Jesse Barnes72252542011-11-07 12:03:18 -08001139 * @encoder_ids: valid encoders for this connector
1140 * @encoder: encoder driving this connector, if any
1141 * @eld: EDID-like data, if present
1142 * @dvi_dual: dual link DVI, if found
1143 * @max_tmds_clock: max clock rate, if found
1144 * @latency_present: AV delay info from ELD, if found
1145 * @video_latency: video latency info from ELD, if found
1146 * @audio_latency: audio latency info from ELD, if found
1147 * @null_edid_counter: track sinks that give us all zeros for the EDID
Daniel Vetter2c0c33d2014-10-27 20:19:38 +01001148 * @bad_edid_counter: track sinks that give us an EDID with invalid checksum
Daniel Vetterac6f2e22015-05-08 16:15:41 +02001149 * @edid_corrupt: indicates whether the last read EDID was corrupt
Daniel Vetter2c0c33d2014-10-27 20:19:38 +01001150 * @debugfs_entry: debugfs directory for this connector
Daniel Vetter144ecb92014-10-27 20:28:44 +01001151 * @state: current atomic state for this connector
Dave Airlie40d9b042014-10-20 16:29:33 +10001152 * @has_tile: is this connector connected to a tiled monitor
1153 * @tile_group: tile group for the connected monitor
1154 * @tile_is_single_monitor: whether the tile is one monitor housing
1155 * @num_h_tile: number of horizontal tiles in the tile group
1156 * @num_v_tile: number of vertical tiles in the tile group
1157 * @tile_h_loc: horizontal location of this tile
1158 * @tile_v_loc: vertical location of this tile
1159 * @tile_h_size: horizontal size of this tile.
1160 * @tile_v_size: vertical size of this tile.
Dave Airlief453ba02008-11-07 14:05:41 -08001161 *
1162 * Each connector may be connected to one or more CRTCs, or may be clonable by
1163 * another connector if they can share a CRTC. Each connector also has a specific
1164 * position in the broader display (referred to as a 'screen' though it could
1165 * span multiple monitors).
1166 */
1167struct drm_connector {
1168 struct drm_device *dev;
Dave Airlie5bdebb12013-10-11 14:07:25 +10001169 struct device *kdev;
Dave Airlief453ba02008-11-07 14:05:41 -08001170 struct device_attribute *attr;
1171 struct list_head head;
1172
1173 struct drm_mode_object base;
1174
Jani Nikula2abdd312014-05-14 16:58:19 +03001175 char *name;
Maarten Lankhorst5fff80b2016-02-17 08:32:05 +01001176 int connector_id;
Dave Airlief453ba02008-11-07 14:05:41 -08001177 int connector_type;
1178 int connector_type_id;
1179 bool interlace_allowed;
1180 bool doublescan_allowed;
Damien Lespiau560a0672013-09-25 16:45:29 +01001181 bool stereo_allowed;
Dave Airlief453ba02008-11-07 14:05:41 -08001182 struct list_head modes; /* list of modes on this connector */
1183
Dave Airlief453ba02008-11-07 14:05:41 -08001184 enum drm_connector_status status;
1185
1186 /* these are modes added by probing with DDC or the BIOS */
1187 struct list_head probed_modes;
1188
1189 struct drm_display_info display_info;
1190 const struct drm_connector_funcs *funcs;
1191
Dave Airlief453ba02008-11-07 14:05:41 -08001192 struct drm_property_blob *edid_blob_ptr;
Paulo Zanoni7e3bdf42012-05-15 18:09:01 -03001193 struct drm_object_properties properties;
Dave Airlief453ba02008-11-07 14:05:41 -08001194
Dave Airlie43aba7e2014-06-05 14:01:31 +10001195 struct drm_property_blob *path_blob_ptr;
1196
Dave Airlie6f134d72014-10-20 16:30:50 +10001197 struct drm_property_blob *tile_blob_ptr;
1198
Dave Airlieeb1f8e4f32010-05-07 06:42:51 +00001199 uint8_t polled; /* DRM_CONNECTOR_POLL_* */
1200
Keith Packardc9fb15f2009-05-30 20:42:28 -07001201 /* requested DPMS state */
1202 int dpms;
1203
Daniel Vetter4490d4c2015-12-04 09:45:45 +01001204 const struct drm_connector_helper_funcs *helper_private;
Dave Airlief453ba02008-11-07 14:05:41 -08001205
Dave Airlied50ba252009-09-23 14:44:08 +10001206 /* forced on connector */
Chris Wilsoneaf99c72014-08-06 10:08:32 +02001207 struct drm_cmdline_mode cmdline_mode;
Dave Airlied50ba252009-09-23 14:44:08 +10001208 enum drm_connector_force force;
Thomas Wood4cf2b282014-06-18 17:52:33 +01001209 bool override_edid;
Dave Airlief453ba02008-11-07 14:05:41 -08001210 uint32_t encoder_ids[DRM_CONNECTOR_MAX_ENCODER];
Dave Airlief453ba02008-11-07 14:05:41 -08001211 struct drm_encoder *encoder; /* currently active encoder */
Dave Airlie4a9a8b72011-06-14 06:13:55 +00001212
Wu Fengguang76adaa342011-09-05 14:23:20 +08001213 /* EDID bits */
1214 uint8_t eld[MAX_ELD_BYTES];
1215 bool dvi_dual;
1216 int max_tmds_clock; /* in MHz */
1217 bool latency_present[2];
1218 int video_latency[2]; /* [0]: progressive, [1]: interlaced */
1219 int audio_latency[2];
Dave Airlie4a9a8b72011-06-14 06:13:55 +00001220 int null_edid_counter; /* needed to workaround some HW bugs where we get all 0s */
Jerome Glisse0b2443e2012-08-09 11:25:51 -04001221 unsigned bad_edid_counter;
Thomas Wood30f65702014-06-18 17:52:32 +01001222
Todd Previte6ba2bd32015-04-21 11:09:41 -07001223 /* Flag for raw EDID header corruption - used in Displayport
1224 * compliance testing - * Displayport Link CTS Core 1.2 rev1.1 4.2.2.6
1225 */
1226 bool edid_corrupt;
1227
Thomas Wood30f65702014-06-18 17:52:32 +01001228 struct dentry *debugfs_entry;
Daniel Vetter144ecb92014-10-27 20:28:44 +01001229
1230 struct drm_connector_state *state;
Dave Airlie40d9b042014-10-20 16:29:33 +10001231
1232 /* DisplayID bits */
1233 bool has_tile;
1234 struct drm_tile_group *tile_group;
1235 bool tile_is_single_monitor;
1236
1237 uint8_t num_h_tile, num_v_tile;
1238 uint8_t tile_h_loc, tile_v_loc;
1239 uint16_t tile_h_size, tile_v_size;
Dave Airlief453ba02008-11-07 14:05:41 -08001240};
1241
1242/**
Daniel Vetter144ecb92014-10-27 20:28:44 +01001243 * struct drm_plane_state - mutable plane state
Daniel Vetter07cc0ef2014-11-27 15:49:39 +01001244 * @plane: backpointer to the plane
Daniel Vetter144ecb92014-10-27 20:28:44 +01001245 * @crtc: currently bound CRTC, NULL if disabled
Daniel Vettercc4ceb42014-07-25 21:30:38 +02001246 * @fb: currently bound framebuffer
Daniel Vettere2330f02014-10-29 11:34:56 +01001247 * @fence: optional fence to wait for before scanning out @fb
Daniel Vetter144ecb92014-10-27 20:28:44 +01001248 * @crtc_x: left position of visible portion of plane on crtc
1249 * @crtc_y: upper position of visible portion of plane on crtc
1250 * @crtc_w: width of visible portion of plane on crtc
1251 * @crtc_h: height of visible portion of plane on crtc
1252 * @src_x: left position of visible portion of plane within
1253 * plane (in 16.16)
1254 * @src_y: upper position of visible portion of plane within
1255 * plane (in 16.16)
1256 * @src_w: width of visible portion of plane (in 16.16)
1257 * @src_h: height of visible portion of plane (in 16.16)
1258 * @state: backpointer to global drm_atomic_state
1259 */
1260struct drm_plane_state {
Daniel Vetter07cc0ef2014-11-27 15:49:39 +01001261 struct drm_plane *plane;
1262
Rob Clark6ddd3882014-11-21 15:28:31 -05001263 struct drm_crtc *crtc; /* do not write directly, use drm_atomic_set_crtc_for_plane() */
1264 struct drm_framebuffer *fb; /* do not write directly, use drm_atomic_set_fb_for_plane() */
Daniel Vettere2330f02014-10-29 11:34:56 +01001265 struct fence *fence;
Daniel Vetter144ecb92014-10-27 20:28:44 +01001266
1267 /* Signed dest location allows it to be partially off screen */
1268 int32_t crtc_x, crtc_y;
1269 uint32_t crtc_w, crtc_h;
1270
1271 /* Source values are 16.16 fixed point */
1272 uint32_t src_x, src_y;
1273 uint32_t src_h, src_w;
1274
Matt Roper1da30622015-01-21 16:35:40 -08001275 /* Plane rotation */
1276 unsigned int rotation;
1277
Daniel Vetter144ecb92014-10-27 20:28:44 +01001278 struct drm_atomic_state *state;
1279};
1280
1281
1282/**
Daniel Vetter3bf04012014-10-27 16:54:27 +01001283 * struct drm_plane_funcs - driver plane control functions
Jesse Barnes8cf5c912011-11-14 14:51:27 -08001284 */
1285struct drm_plane_funcs {
Daniel Vetter88548632015-12-04 09:45:48 +01001286 /**
1287 * @update_plane:
1288 *
1289 * This is the legacy entry point to enable and configure the plane for
1290 * the given CRTC and framebuffer. It is never called to disable the
1291 * plane, i.e. the passed-in crtc and fb paramters are never NULL.
1292 *
1293 * The source rectangle in frame buffer memory coordinates is given by
1294 * the src_x, src_y, src_w and src_h parameters (as 16.16 fixed point
1295 * values). Devices that don't support subpixel plane coordinates can
1296 * ignore the fractional part.
1297 *
1298 * The destination rectangle in CRTC coordinates is given by the
1299 * crtc_x, crtc_y, crtc_w and crtc_h parameters (as integer values).
1300 * Devices scale the source rectangle to the destination rectangle. If
1301 * scaling is not supported, and the source rectangle size doesn't match
1302 * the destination rectangle size, the driver must return a
1303 * -<errorname>EINVAL</errorname> error.
1304 *
1305 * Drivers implementing atomic modeset should use
1306 * drm_atomic_helper_update_plane() to implement this hook.
1307 *
1308 * RETURNS:
1309 *
1310 * 0 on success or a negative error code on failure.
1311 */
Jesse Barnes8cf5c912011-11-14 14:51:27 -08001312 int (*update_plane)(struct drm_plane *plane,
1313 struct drm_crtc *crtc, struct drm_framebuffer *fb,
1314 int crtc_x, int crtc_y,
1315 unsigned int crtc_w, unsigned int crtc_h,
1316 uint32_t src_x, uint32_t src_y,
1317 uint32_t src_w, uint32_t src_h);
Daniel Vetter88548632015-12-04 09:45:48 +01001318
1319 /**
1320 * @disable_plane:
1321 *
1322 * This is the legacy entry point to disable the plane. The DRM core
Daniel Vetterc6b0ca32015-12-04 09:46:01 +01001323 * calls this method in response to a DRM_IOCTL_MODE_SETPLANE IOCTL call
Daniel Vetter88548632015-12-04 09:45:48 +01001324 * with the frame buffer ID set to 0. Disabled planes must not be
1325 * processed by the CRTC.
1326 *
1327 * Drivers implementing atomic modeset should use
1328 * drm_atomic_helper_disable_plane() to implement this hook.
1329 *
1330 * RETURNS:
1331 *
1332 * 0 on success or a negative error code on failure.
1333 */
Jesse Barnes8cf5c912011-11-14 14:51:27 -08001334 int (*disable_plane)(struct drm_plane *plane);
Daniel Vetter88548632015-12-04 09:45:48 +01001335
1336 /**
1337 * @destroy:
1338 *
1339 * Clean up plane resources. This is only called at driver unload time
1340 * through drm_mode_config_cleanup() since a plane cannot be hotplugged
1341 * in DRM.
1342 */
Jesse Barnes8cf5c912011-11-14 14:51:27 -08001343 void (*destroy)(struct drm_plane *plane);
Daniel Vetter88548632015-12-04 09:45:48 +01001344
1345 /**
1346 * @reset:
1347 *
1348 * Reset plane hardware and software state to off. This function isn't
1349 * called by the core directly, only through drm_mode_config_reset().
1350 * It's not a helper hook only for historical reasons.
1351 *
1352 * Atomic drivers can use drm_atomic_helper_plane_reset() to reset
1353 * atomic state using this hook.
1354 */
Daniel Vetter2a0d7cf2014-07-29 15:32:37 +02001355 void (*reset)(struct drm_plane *plane);
Rob Clark4d939142012-05-17 02:23:27 -06001356
Daniel Vetter88548632015-12-04 09:45:48 +01001357 /**
1358 * @set_property:
1359 *
1360 * This is the legacy entry point to update a property attached to the
1361 * plane.
1362 *
1363 * Drivers implementing atomic modeset should use
1364 * drm_atomic_helper_plane_set_property() to implement this hook.
1365 *
1366 * This callback is optional if the driver does not support any legacy
1367 * driver-private properties.
1368 *
1369 * RETURNS:
1370 *
1371 * 0 on success or a negative error code on failure.
1372 */
Rob Clark4d939142012-05-17 02:23:27 -06001373 int (*set_property)(struct drm_plane *plane,
1374 struct drm_property *property, uint64_t val);
Daniel Vetter144ecb92014-10-27 20:28:44 +01001375
Daniel Vetter88548632015-12-04 09:45:48 +01001376 /**
1377 * @atomic_duplicate_state:
1378 *
1379 * Duplicate the current atomic state for this plane and return it.
1380 * The core and helpers gurantee that any atomic state duplicated with
1381 * this hook and still owned by the caller (i.e. not transferred to the
1382 * driver by calling ->atomic_commit() from struct
1383 * &drm_mode_config_funcs) will be cleaned up by calling the
1384 * @atomic_destroy_state hook in this structure.
1385 *
1386 * Atomic drivers which don't subclass struct &drm_plane_state should use
1387 * drm_atomic_helper_plane_duplicate_state(). Drivers that subclass the
1388 * state structure to extend it with driver-private state should use
1389 * __drm_atomic_helper_plane_duplicate_state() to make sure shared state is
1390 * duplicated in a consistent fashion across drivers.
1391 *
1392 * It is an error to call this hook before plane->state has been
1393 * initialized correctly.
1394 *
1395 * NOTE:
1396 *
1397 * If the duplicate state references refcounted resources this hook must
1398 * acquire a reference for each of them. The driver must release these
1399 * references again in @atomic_destroy_state.
1400 *
1401 * RETURNS:
1402 *
1403 * Duplicated atomic state or NULL when the allocation failed.
1404 */
Daniel Vetter144ecb92014-10-27 20:28:44 +01001405 struct drm_plane_state *(*atomic_duplicate_state)(struct drm_plane *plane);
Daniel Vetter88548632015-12-04 09:45:48 +01001406
1407 /**
1408 * @atomic_destroy_state:
1409 *
1410 * Destroy a state duplicated with @atomic_duplicate_state and release
1411 * or unreference all resources it references
1412 */
Daniel Vetter144ecb92014-10-27 20:28:44 +01001413 void (*atomic_destroy_state)(struct drm_plane *plane,
Daniel Vettercc4ceb42014-07-25 21:30:38 +02001414 struct drm_plane_state *state);
Daniel Vetter88548632015-12-04 09:45:48 +01001415
1416 /**
1417 * @atomic_set_property:
1418 *
1419 * Decode a driver-private property value and store the decoded value
1420 * into the passed-in state structure. Since the atomic core decodes all
1421 * standardized properties (even for extensions beyond the core set of
1422 * properties which might not be implemented by all drivers) this
1423 * requires drivers to subclass the state structure.
1424 *
1425 * Such driver-private properties should really only be implemented for
1426 * truly hardware/vendor specific state. Instead it is preferred to
1427 * standardize atomic extension and decode the properties used to expose
1428 * such an extension in the core.
1429 *
1430 * Do not call this function directly, use
1431 * drm_atomic_plane_set_property() instead.
1432 *
1433 * This callback is optional if the driver does not support any
1434 * driver-private atomic properties.
1435 *
1436 * NOTE:
1437 *
1438 * This function is called in the state assembly phase of atomic
1439 * modesets, which can be aborted for any reason (including on
1440 * userspace's request to just check whether a configuration would be
1441 * possible). Drivers MUST NOT touch any persistent state (hardware or
1442 * software) or data structures except the passed in @state parameter.
1443 *
1444 * Also since userspace controls in which order properties are set this
1445 * function must not do any input validation (since the state update is
1446 * incomplete and hence likely inconsistent). Instead any such input
1447 * validation must be done in the various atomic_check callbacks.
1448 *
1449 * RETURNS:
1450 *
1451 * 0 if the property has been found, -EINVAL if the property isn't
1452 * implemented by the driver (which shouldn't ever happen, the core only
1453 * asks for properties attached to this plane). No other validation is
1454 * allowed by the driver. The core already checks that the property
1455 * value is within the range (integer, valid enum value, ...) the driver
1456 * set when registering the property.
1457 */
Daniel Vetter144ecb92014-10-27 20:28:44 +01001458 int (*atomic_set_property)(struct drm_plane *plane,
1459 struct drm_plane_state *state,
1460 struct drm_property *property,
1461 uint64_t val);
Daniel Vetter88548632015-12-04 09:45:48 +01001462
1463 /**
1464 * @atomic_get_property:
1465 *
1466 * Reads out the decoded driver-private property. This is used to
Daniel Vetterc6b0ca32015-12-04 09:46:01 +01001467 * implement the GETPLANE IOCTL.
Daniel Vetter88548632015-12-04 09:45:48 +01001468 *
1469 * Do not call this function directly, use
1470 * drm_atomic_plane_get_property() instead.
1471 *
1472 * This callback is optional if the driver does not support any
1473 * driver-private atomic properties.
1474 *
1475 * RETURNS:
1476 *
1477 * 0 on success, -EINVAL if the property isn't implemented by the
1478 * driver (which should never happen, the core only asks for
1479 * properties attached to this plane).
1480 */
Rob Clarkac9c9252014-12-18 16:01:47 -05001481 int (*atomic_get_property)(struct drm_plane *plane,
1482 const struct drm_plane_state *state,
1483 struct drm_property *property,
1484 uint64_t *val);
Jesse Barnes8cf5c912011-11-14 14:51:27 -08001485};
1486
Matt Ropere27dde32014-04-01 15:22:30 -07001487enum drm_plane_type {
1488 DRM_PLANE_TYPE_OVERLAY,
1489 DRM_PLANE_TYPE_PRIMARY,
1490 DRM_PLANE_TYPE_CURSOR,
1491};
1492
Daniel Vetter88548632015-12-04 09:45:48 +01001493
Jesse Barnes8cf5c912011-11-14 14:51:27 -08001494/**
Daniel Vetter3bf04012014-10-27 16:54:27 +01001495 * struct drm_plane - central DRM plane control structure
Jesse Barnes8cf5c912011-11-14 14:51:27 -08001496 * @dev: DRM device this plane belongs to
1497 * @head: for list management
1498 * @base: base mode object
1499 * @possible_crtcs: pipes this plane can be bound to
1500 * @format_types: array of formats supported by this plane
1501 * @format_count: number of formats supported
Laurent Pinchart7eb5f302015-03-09 10:41:07 +02001502 * @format_default: driver hasn't supplied supported formats for the plane
Jesse Barnes8cf5c912011-11-14 14:51:27 -08001503 * @crtc: currently bound CRTC
1504 * @fb: currently bound fb
Daniel Vetter2c0c33d2014-10-27 20:19:38 +01001505 * @old_fb: Temporary tracking of the old fb while a modeset is ongoing. Used by
1506 * drm_mode_set_config_internal() to implement correct refcounting.
Jesse Barnes8cf5c912011-11-14 14:51:27 -08001507 * @funcs: helper functions
Rob Clark4d939142012-05-17 02:23:27 -06001508 * @properties: property tracking for this plane
Matt Ropere27dde32014-04-01 15:22:30 -07001509 * @type: type of plane (overlay, primary, cursor)
Daniel Vetter144ecb92014-10-27 20:28:44 +01001510 * @state: current atomic state for this plane
Jesse Barnes8cf5c912011-11-14 14:51:27 -08001511 */
1512struct drm_plane {
1513 struct drm_device *dev;
1514 struct list_head head;
1515
Ville Syrjälä9f4c97a2015-12-08 18:41:54 +02001516 char *name;
1517
Daniel Vetter4d02e2d2014-11-11 10:12:00 +01001518 struct drm_modeset_lock mutex;
1519
Jesse Barnes8cf5c912011-11-14 14:51:27 -08001520 struct drm_mode_object base;
1521
1522 uint32_t possible_crtcs;
1523 uint32_t *format_types;
Thierry Reding45e37432015-08-12 16:54:28 +02001524 unsigned int format_count;
Laurent Pinchart7eb5f302015-03-09 10:41:07 +02001525 bool format_default;
Jesse Barnes8cf5c912011-11-14 14:51:27 -08001526
1527 struct drm_crtc *crtc;
1528 struct drm_framebuffer *fb;
1529
Daniel Vetter3d30a592014-07-27 13:42:42 +02001530 struct drm_framebuffer *old_fb;
1531
Jesse Barnes8cf5c912011-11-14 14:51:27 -08001532 const struct drm_plane_funcs *funcs;
Rob Clark4d939142012-05-17 02:23:27 -06001533
1534 struct drm_object_properties properties;
Matt Ropere27dde32014-04-01 15:22:30 -07001535
1536 enum drm_plane_type type;
Daniel Vetter144ecb92014-10-27 20:28:44 +01001537
Daniel Vetter4490d4c2015-12-04 09:45:45 +01001538 const struct drm_plane_helper_funcs *helper_private;
Daniel Vetterc2fcd272014-11-05 00:14:14 +01001539
Daniel Vetter144ecb92014-10-27 20:28:44 +01001540 struct drm_plane_state *state;
Jesse Barnes8cf5c912011-11-14 14:51:27 -08001541};
1542
1543/**
Daniel Vetter3bf04012014-10-27 16:54:27 +01001544 * struct drm_bridge_funcs - drm_bridge control functions
Ajay Kumar3d3f8b12015-01-20 22:08:44 +05301545 * @attach: Called during drm_bridge_attach
Sean Paul3b336ec2013-08-14 16:47:37 -04001546 */
1547struct drm_bridge_funcs {
Ajay Kumar3d3f8b12015-01-20 22:08:44 +05301548 int (*attach)(struct drm_bridge *bridge);
Daniel Vetterda024fe2015-12-04 09:45:47 +01001549
1550 /**
1551 * @mode_fixup:
1552 *
1553 * This callback is used to validate and adjust a mode. The paramater
1554 * mode is the display mode that should be fed to the next element in
1555 * the display chain, either the final &drm_connector or the next
1556 * &drm_bridge. The parameter adjusted_mode is the input mode the bridge
1557 * requires. It can be modified by this callback and does not need to
1558 * match mode.
1559 *
1560 * This is the only hook that allows a bridge to reject a modeset. If
1561 * this function passes all other callbacks must succeed for this
1562 * configuration.
1563 *
1564 * NOTE:
1565 *
1566 * This function is called in the check phase of atomic modesets, which
1567 * can be aborted for any reason (including on userspace's request to
1568 * just check whether a configuration would be possible). Drivers MUST
1569 * NOT touch any persistent state (hardware or software) or data
Daniel Vetter88548632015-12-04 09:45:48 +01001570 * structures except the passed in @state parameter.
Daniel Vetterda024fe2015-12-04 09:45:47 +01001571 *
1572 * RETURNS:
1573 *
1574 * True if an acceptable configuration is possible, false if the modeset
1575 * operation should be rejected.
1576 */
Sean Paul3b336ec2013-08-14 16:47:37 -04001577 bool (*mode_fixup)(struct drm_bridge *bridge,
1578 const struct drm_display_mode *mode,
1579 struct drm_display_mode *adjusted_mode);
Daniel Vetterda024fe2015-12-04 09:45:47 +01001580 /**
1581 * @disable:
1582 *
1583 * This callback should disable the bridge. It is called right before
1584 * the preceding element in the display pipe is disabled. If the
1585 * preceding element is a bridge this means it's called before that
1586 * bridge's ->disable() function. If the preceding element is a
1587 * &drm_encoder it's called right before the encoder's ->disable(),
1588 * ->prepare() or ->dpms() hook from struct &drm_encoder_helper_funcs.
1589 *
1590 * The bridge can assume that the display pipe (i.e. clocks and timing
1591 * signals) feeding it is still running when this callback is called.
Laurent Pinchartc8a3b2a2016-02-26 11:51:06 +02001592 *
1593 * The disable callback is optional.
Daniel Vetterda024fe2015-12-04 09:45:47 +01001594 */
Sean Paul3b336ec2013-08-14 16:47:37 -04001595 void (*disable)(struct drm_bridge *bridge);
Daniel Vetterda024fe2015-12-04 09:45:47 +01001596
1597 /**
1598 * @post_disable:
1599 *
1600 * This callback should disable the bridge. It is called right after
1601 * the preceding element in the display pipe is disabled. If the
1602 * preceding element is a bridge this means it's called after that
1603 * bridge's ->post_disable() function. If the preceding element is a
1604 * &drm_encoder it's called right after the encoder's ->disable(),
1605 * ->prepare() or ->dpms() hook from struct &drm_encoder_helper_funcs.
1606 *
1607 * The bridge must assume that the display pipe (i.e. clocks and timing
1608 * singals) feeding it is no longer running when this callback is
1609 * called.
Laurent Pinchartc8a3b2a2016-02-26 11:51:06 +02001610 *
1611 * The post_disable callback is optional.
Daniel Vetterda024fe2015-12-04 09:45:47 +01001612 */
Sean Paul3b336ec2013-08-14 16:47:37 -04001613 void (*post_disable)(struct drm_bridge *bridge);
Daniel Vetterda024fe2015-12-04 09:45:47 +01001614
1615 /**
1616 * @mode_set:
1617 *
1618 * This callback should set the given mode on the bridge. It is called
1619 * after the ->mode_set() callback for the preceding element in the
1620 * display pipeline has been called already. The display pipe (i.e.
1621 * clocks and timing signals) is off when this function is called.
1622 */
Sean Paul3b336ec2013-08-14 16:47:37 -04001623 void (*mode_set)(struct drm_bridge *bridge,
1624 struct drm_display_mode *mode,
1625 struct drm_display_mode *adjusted_mode);
Daniel Vetterda024fe2015-12-04 09:45:47 +01001626 /**
1627 * @pre_enable:
1628 *
1629 * This callback should enable the bridge. It is called right before
1630 * the preceding element in the display pipe is enabled. If the
1631 * preceding element is a bridge this means it's called before that
1632 * bridge's ->pre_enable() function. If the preceding element is a
1633 * &drm_encoder it's called right before the encoder's ->enable(),
1634 * ->commit() or ->dpms() hook from struct &drm_encoder_helper_funcs.
1635 *
1636 * The display pipe (i.e. clocks and timing signals) feeding this bridge
1637 * will not yet be running when this callback is called. The bridge must
1638 * not enable the display link feeding the next bridge in the chain (if
1639 * there is one) when this callback is called.
Laurent Pinchartc8a3b2a2016-02-26 11:51:06 +02001640 *
1641 * The pre_enable callback is optional.
Daniel Vetterda024fe2015-12-04 09:45:47 +01001642 */
Sean Paul3b336ec2013-08-14 16:47:37 -04001643 void (*pre_enable)(struct drm_bridge *bridge);
Daniel Vetterda024fe2015-12-04 09:45:47 +01001644
1645 /**
1646 * @enable:
1647 *
1648 * This callback should enable the bridge. It is called right after
1649 * the preceding element in the display pipe is enabled. If the
1650 * preceding element is a bridge this means it's called after that
1651 * bridge's ->enable() function. If the preceding element is a
1652 * &drm_encoder it's called right after the encoder's ->enable(),
1653 * ->commit() or ->dpms() hook from struct &drm_encoder_helper_funcs.
1654 *
1655 * The bridge can assume that the display pipe (i.e. clocks and timing
1656 * signals) feeding it is running when this callback is called. This
1657 * callback must enable the display link feeding the next bridge in the
1658 * chain if there is one.
Laurent Pinchartc8a3b2a2016-02-26 11:51:06 +02001659 *
1660 * The enable callback is optional.
Daniel Vetterda024fe2015-12-04 09:45:47 +01001661 */
Sean Paul3b336ec2013-08-14 16:47:37 -04001662 void (*enable)(struct drm_bridge *bridge);
Sean Paul3b336ec2013-08-14 16:47:37 -04001663};
1664
1665/**
Daniel Vetter3bf04012014-10-27 16:54:27 +01001666 * struct drm_bridge - central DRM bridge control structure
Sean Paul3b336ec2013-08-14 16:47:37 -04001667 * @dev: DRM device this bridge belongs to
Archit Taneja862e6862015-05-21 11:03:16 +05301668 * @encoder: encoder to which this bridge is connected
1669 * @next: the next bridge in the encoder chain
Ajay Kumar3d3f8b12015-01-20 22:08:44 +05301670 * @of_node: device node pointer to the bridge
1671 * @list: to keep track of all added bridges
Sean Paul3b336ec2013-08-14 16:47:37 -04001672 * @funcs: control functions
1673 * @driver_private: pointer to the bridge driver's internal context
1674 */
1675struct drm_bridge {
1676 struct drm_device *dev;
Ajay Kumar3d3f8b12015-01-20 22:08:44 +05301677 struct drm_encoder *encoder;
Archit Taneja862e6862015-05-21 11:03:16 +05301678 struct drm_bridge *next;
Ajay Kumar3d3f8b12015-01-20 22:08:44 +05301679#ifdef CONFIG_OF
1680 struct device_node *of_node;
1681#endif
1682 struct list_head list;
Sean Paul3b336ec2013-08-14 16:47:37 -04001683
1684 const struct drm_bridge_funcs *funcs;
1685 void *driver_private;
1686};
1687
1688/**
Rob Clark08855fa2015-03-11 10:23:09 -04001689 * struct drm_atomic_state - the global state object for atomic updates
Daniel Vettercc4ceb42014-07-25 21:30:38 +02001690 * @dev: parent DRM device
Rob Clarkd34f20d2014-12-18 16:01:56 -05001691 * @allow_modeset: allow full modeset
Daniel Vetterc6b0ca32015-12-04 09:46:01 +01001692 * @legacy_cursor_update: hint to enforce legacy cursor IOCTL semantics
Maarten Lankhorst40616a22016-03-03 10:17:39 +01001693 * @legacy_set_config: Disable conflicting encoders instead of failing with -EINVAL.
Daniel Vettercc4ceb42014-07-25 21:30:38 +02001694 * @planes: pointer to array of plane pointers
1695 * @plane_states: pointer to array of plane states pointers
1696 * @crtcs: pointer to array of CRTC pointers
1697 * @crtc_states: pointer to array of CRTC states pointers
Daniel Vetterf52b69f12014-11-19 18:38:08 +01001698 * @num_connector: size of the @connectors and @connector_states arrays
Daniel Vettercc4ceb42014-07-25 21:30:38 +02001699 * @connectors: pointer to array of connector pointers
1700 * @connector_states: pointer to array of connector states pointers
1701 * @acquire_ctx: acquire context for this atomic modeset state update
1702 */
1703struct drm_atomic_state {
1704 struct drm_device *dev;
Rob Clarkd34f20d2014-12-18 16:01:56 -05001705 bool allow_modeset : 1;
Daniel Vetterf02ad902015-01-22 16:36:23 +01001706 bool legacy_cursor_update : 1;
Maarten Lankhorst40616a22016-03-03 10:17:39 +01001707 bool legacy_set_config : 1;
Daniel Vettercc4ceb42014-07-25 21:30:38 +02001708 struct drm_plane **planes;
1709 struct drm_plane_state **plane_states;
1710 struct drm_crtc **crtcs;
1711 struct drm_crtc_state **crtc_states;
Daniel Vetterf52b69f12014-11-19 18:38:08 +01001712 int num_connector;
Daniel Vettercc4ceb42014-07-25 21:30:38 +02001713 struct drm_connector **connectors;
1714 struct drm_connector_state **connector_states;
1715
1716 struct drm_modeset_acquire_ctx *acquire_ctx;
1717};
1718
1719
1720/**
Daniel Vetter3bf04012014-10-27 16:54:27 +01001721 * struct drm_mode_set - new values for a CRTC config change
Jesse Barnesef273512011-11-07 12:03:19 -08001722 * @fb: framebuffer to use for new config
1723 * @crtc: CRTC whose configuration we're about to change
1724 * @mode: mode timings to use
1725 * @x: position of this CRTC relative to @fb
1726 * @y: position of this CRTC relative to @fb
1727 * @connectors: array of connectors to drive with this CRTC if possible
1728 * @num_connectors: size of @connectors array
Dave Airlief453ba02008-11-07 14:05:41 -08001729 *
1730 * Represents a single crtc the connectors that it drives with what mode
1731 * and from which framebuffer it scans out from.
1732 *
1733 * This is used to set modes.
1734 */
1735struct drm_mode_set {
Dave Airlief453ba02008-11-07 14:05:41 -08001736 struct drm_framebuffer *fb;
1737 struct drm_crtc *crtc;
1738 struct drm_display_mode *mode;
1739
1740 uint32_t x;
1741 uint32_t y;
1742
1743 struct drm_connector **connectors;
1744 size_t num_connectors;
1745};
1746
1747/**
Jesse Barnes550cebc2011-11-07 12:03:20 -08001748 * struct drm_mode_config_funcs - basic driver provided mode setting functions
Jesse Barnes550cebc2011-11-07 12:03:20 -08001749 *
1750 * Some global (i.e. not per-CRTC, connector, etc) mode setting functions that
1751 * involve drivers.
Dave Airlief453ba02008-11-07 14:05:41 -08001752 */
1753struct drm_mode_config_funcs {
Daniel Vetter9953f412015-12-04 09:46:02 +01001754 /**
1755 * @fb_create:
1756 *
1757 * Create a new framebuffer object. The core does basic checks on the
1758 * requested metadata, but most of that is left to the driver. See
1759 * struct &drm_mode_fb_cmd2 for details.
1760 *
Daniel Vetterd55f5322015-12-08 09:49:19 +01001761 * If the parameters are deemed valid and the backing storage objects in
1762 * the underlying memory manager all exist, then the driver allocates
1763 * a new &drm_framebuffer structure, subclassed to contain
1764 * driver-specific information (like the internal native buffer object
1765 * references). It also needs to fill out all relevant metadata, which
1766 * should be done by calling drm_helper_mode_fill_fb_struct().
1767 *
1768 * The initialization is finalized by calling drm_framebuffer_init(),
1769 * which registers the framebuffer and makes it accessible to other
1770 * threads.
1771 *
Daniel Vetter9953f412015-12-04 09:46:02 +01001772 * RETURNS:
1773 *
1774 * A new framebuffer with an initial reference count of 1 or a negative
1775 * error code encoded with ERR_PTR().
1776 */
Jesse Barnes550cebc2011-11-07 12:03:20 -08001777 struct drm_framebuffer *(*fb_create)(struct drm_device *dev,
1778 struct drm_file *file_priv,
Ville Syrjälä1eb834512015-11-11 19:11:29 +02001779 const struct drm_mode_fb_cmd2 *mode_cmd);
Daniel Vetter9953f412015-12-04 09:46:02 +01001780
1781 /**
1782 * @output_poll_changed:
1783 *
1784 * Callback used by helpers to inform the driver of output configuration
1785 * changes.
1786 *
1787 * Drivers implementing fbdev emulation with the helpers can call
1788 * drm_fb_helper_hotplug_changed from this hook to inform the fbdev
1789 * helper of output changes.
1790 *
1791 * FIXME:
1792 *
1793 * Except that there's no vtable for device-level helper callbacks
1794 * there's no reason this is a core function.
1795 */
Dave Airlieeb1f8e4f32010-05-07 06:42:51 +00001796 void (*output_poll_changed)(struct drm_device *dev);
Daniel Vettercc4ceb42014-07-25 21:30:38 +02001797
Daniel Vetter9953f412015-12-04 09:46:02 +01001798 /**
1799 * @atomic_check:
1800 *
1801 * This is the only hook to validate an atomic modeset update. This
1802 * function must reject any modeset and state changes which the hardware
1803 * or driver doesn't support. This includes but is of course not limited
1804 * to:
1805 *
1806 * - Checking that the modes, framebuffers, scaling and placement
1807 * requirements and so on are within the limits of the hardware.
1808 *
1809 * - Checking that any hidden shared resources are not oversubscribed.
1810 * This can be shared PLLs, shared lanes, overall memory bandwidth,
1811 * display fifo space (where shared between planes or maybe even
1812 * CRTCs).
1813 *
1814 * - Checking that virtualized resources exported to userspace are not
1815 * oversubscribed. For various reasons it can make sense to expose
1816 * more planes, crtcs or encoders than which are physically there. One
1817 * example is dual-pipe operations (which generally should be hidden
1818 * from userspace if when lockstepped in hardware, exposed otherwise),
1819 * where a plane might need 1 hardware plane (if it's just on one
1820 * pipe), 2 hardware planes (when it spans both pipes) or maybe even
1821 * shared a hardware plane with a 2nd plane (if there's a compatible
1822 * plane requested on the area handled by the other pipe).
1823 *
1824 * - Check that any transitional state is possible and that if
1825 * requested, the update can indeed be done in the vblank period
1826 * without temporarily disabling some functions.
1827 *
1828 * - Check any other constraints the driver or hardware might have.
1829 *
1830 * - This callback also needs to correctly fill out the &drm_crtc_state
1831 * in this update to make sure that drm_atomic_crtc_needs_modeset()
1832 * reflects the nature of the possible update and returns true if and
1833 * only if the update cannot be applied without tearing within one
1834 * vblank on that CRTC. The core uses that information to reject
1835 * updates which require a full modeset (i.e. blanking the screen, or
1836 * at least pausing updates for a substantial amount of time) if
1837 * userspace has disallowed that in its request.
1838 *
1839 * - The driver also does not need to repeat basic input validation
1840 * like done for the corresponding legacy entry points. The core does
1841 * that before calling this hook.
1842 *
1843 * See the documentation of @atomic_commit for an exhaustive list of
1844 * error conditions which don't have to be checked at the
1845 * ->atomic_check() stage?
1846 *
1847 * See the documentation for struct &drm_atomic_state for how exactly
1848 * an atomic modeset update is described.
1849 *
1850 * Drivers using the atomic helpers can implement this hook using
1851 * drm_atomic_helper_check(), or one of the exported sub-functions of
1852 * it.
1853 *
1854 * RETURNS:
1855 *
1856 * 0 on success or one of the below negative error codes:
1857 *
1858 * - -EINVAL, if any of the above constraints are violated.
1859 *
1860 * - -EDEADLK, when returned from an attempt to acquire an additional
1861 * &drm_modeset_lock through drm_modeset_lock().
1862 *
1863 * - -ENOMEM, if allocating additional state sub-structures failed due
1864 * to lack of memory.
1865 *
1866 * - -EINTR, -EAGAIN or -ERESTARTSYS, if the IOCTL should be restarted.
1867 * This can either be due to a pending signal, or because the driver
1868 * needs to completely bail out to recover from an exceptional
1869 * situation like a GPU hang. From a userspace point all errors are
1870 * treated equally.
1871 */
Daniel Vettercc4ceb42014-07-25 21:30:38 +02001872 int (*atomic_check)(struct drm_device *dev,
Daniel Vetter9953f412015-12-04 09:46:02 +01001873 struct drm_atomic_state *state);
1874
1875 /**
1876 * @atomic_commit:
1877 *
1878 * This is the only hook to commit an atomic modeset update. The core
1879 * guarantees that @atomic_check has been called successfully before
1880 * calling this function, and that nothing has been changed in the
1881 * interim.
1882 *
1883 * See the documentation for struct &drm_atomic_state for how exactly
1884 * an atomic modeset update is described.
1885 *
1886 * Drivers using the atomic helpers can implement this hook using
1887 * drm_atomic_helper_commit(), or one of the exported sub-functions of
1888 * it.
1889 *
Maarten Lankhorst286dbb82016-04-26 16:11:34 +02001890 * Nonblocking commits (as indicated with the nonblock parameter) must
Daniel Vetter9953f412015-12-04 09:46:02 +01001891 * do any preparatory work which might result in an unsuccessful commit
1892 * in the context of this callback. The only exceptions are hardware
1893 * errors resulting in -EIO. But even in that case the driver must
1894 * ensure that the display pipe is at least running, to avoid
1895 * compositors crashing when pageflips don't work. Anything else,
1896 * specifically committing the update to the hardware, should be done
1897 * without blocking the caller. For updates which do not require a
1898 * modeset this must be guaranteed.
1899 *
1900 * The driver must wait for any pending rendering to the new
1901 * framebuffers to complete before executing the flip. It should also
1902 * wait for any pending rendering from other drivers if the underlying
Maarten Lankhorst286dbb82016-04-26 16:11:34 +02001903 * buffer is a shared dma-buf. Nonblocking commits must not wait for
Daniel Vetter9953f412015-12-04 09:46:02 +01001904 * rendering in the context of this callback.
1905 *
1906 * An application can request to be notified when the atomic commit has
1907 * completed. These events are per-CRTC and can be distinguished by the
1908 * CRTC index supplied in &drm_event to userspace.
1909 *
1910 * The drm core will supply a struct &drm_event in the event
1911 * member of each CRTC's &drm_crtc_state structure. This can be handled by the
1912 * drm_crtc_send_vblank_event() function, which the driver should call on
1913 * the provided event upon completion of the atomic commit. Note that if
1914 * the driver supports vblank signalling and timestamping the vblank
1915 * counters and timestamps must agree with the ones returned from page
1916 * flip events. With the current vblank helper infrastructure this can
1917 * be achieved by holding a vblank reference while the page flip is
1918 * pending, acquired through drm_crtc_vblank_get() and released with
1919 * drm_crtc_vblank_put(). Drivers are free to implement their own vblank
1920 * counter and timestamp tracking though, e.g. if they have accurate
1921 * timestamp registers in hardware.
1922 *
1923 * NOTE:
1924 *
1925 * Drivers are not allowed to shut down any display pipe successfully
1926 * enabled through an atomic commit on their own. Doing so can result in
1927 * compositors crashing if a page flip is suddenly rejected because the
1928 * pipe is off.
1929 *
1930 * RETURNS:
1931 *
1932 * 0 on success or one of the below negative error codes:
1933 *
Maarten Lankhorst286dbb82016-04-26 16:11:34 +02001934 * - -EBUSY, if a nonblocking updated is requested and there is
Daniel Vetter9953f412015-12-04 09:46:02 +01001935 * an earlier updated pending. Drivers are allowed to support a queue
1936 * of outstanding updates, but currently no driver supports that.
1937 * Note that drivers must wait for preceding updates to complete if a
1938 * synchronous update is requested, they are not allowed to fail the
1939 * commit in that case.
1940 *
1941 * - -ENOMEM, if the driver failed to allocate memory. Specifically
1942 * this can happen when trying to pin framebuffers, which must only
1943 * be done when committing the state.
1944 *
1945 * - -ENOSPC, as a refinement of the more generic -ENOMEM to indicate
1946 * that the driver has run out of vram, iommu space or similar GPU
1947 * address space needed for framebuffer.
1948 *
1949 * - -EIO, if the hardware completely died.
1950 *
1951 * - -EINTR, -EAGAIN or -ERESTARTSYS, if the IOCTL should be restarted.
1952 * This can either be due to a pending signal, or because the driver
1953 * needs to completely bail out to recover from an exceptional
1954 * situation like a GPU hang. From a userspace point of view all errors are
1955 * treated equally.
1956 *
1957 * This list is exhaustive. Specifically this hook is not allowed to
1958 * return -EINVAL (any invalid requests should be caught in
1959 * @atomic_check) or -EDEADLK (this function must not acquire
1960 * additional modeset locks).
1961 */
Daniel Vettercc4ceb42014-07-25 21:30:38 +02001962 int (*atomic_commit)(struct drm_device *dev,
Daniel Vetter9953f412015-12-04 09:46:02 +01001963 struct drm_atomic_state *state,
Maarten Lankhorst286dbb82016-04-26 16:11:34 +02001964 bool nonblock);
Daniel Vetter9953f412015-12-04 09:46:02 +01001965
1966 /**
1967 * @atomic_state_alloc:
1968 *
1969 * This optional hook can be used by drivers that want to subclass struct
1970 * &drm_atomic_state to be able to track their own driver-private global
1971 * state easily. If this hook is implemented, drivers must also
1972 * implement @atomic_state_clear and @atomic_state_free.
1973 *
1974 * RETURNS:
1975 *
1976 * A new &drm_atomic_state on success or NULL on failure.
1977 */
Maarten Lankhorst036ef572015-05-18 10:06:40 +02001978 struct drm_atomic_state *(*atomic_state_alloc)(struct drm_device *dev);
Daniel Vetter9953f412015-12-04 09:46:02 +01001979
1980 /**
1981 * @atomic_state_clear:
1982 *
1983 * This hook must clear any driver private state duplicated into the
1984 * passed-in &drm_atomic_state. This hook is called when the caller
1985 * encountered a &drm_modeset_lock deadlock and needs to drop all
1986 * already acquired locks as part of the deadlock avoidance dance
1987 * implemented in drm_modeset_lock_backoff().
1988 *
1989 * Any duplicated state must be invalidated since a concurrent atomic
1990 * update might change it, and the drm atomic interfaces always apply
1991 * updates as relative changes to the current state.
1992 *
1993 * Drivers that implement this must call drm_atomic_state_default_clear()
1994 * to clear common state.
1995 */
Maarten Lankhorst036ef572015-05-18 10:06:40 +02001996 void (*atomic_state_clear)(struct drm_atomic_state *state);
Daniel Vetter9953f412015-12-04 09:46:02 +01001997
1998 /**
1999 * @atomic_state_free:
2000 *
2001 * This hook needs driver private resources and the &drm_atomic_state
2002 * itself. Note that the core first calls drm_atomic_state_clear() to
2003 * avoid code duplicate between the clear and free hooks.
2004 *
2005 * Drivers that implement this must call drm_atomic_state_default_free()
2006 * to release common resources.
2007 */
Maarten Lankhorst036ef572015-05-18 10:06:40 +02002008 void (*atomic_state_free)(struct drm_atomic_state *state);
Dave Airlief453ba02008-11-07 14:05:41 -08002009};
2010
Jesse Barnesc1aaca22011-11-07 12:03:21 -08002011/**
Daniel Vetter2c0c33d2014-10-27 20:19:38 +01002012 * struct drm_mode_config - Mode configuration control structure
Jesse Barnesa62c93d2011-11-07 12:03:22 -08002013 * @mutex: mutex protecting KMS related lists and structures
Daniel Vetter2c0c33d2014-10-27 20:19:38 +01002014 * @connection_mutex: ww mutex protecting connector state and routing
2015 * @acquire_ctx: global implicit acquire context used by atomic drivers for
Daniel Vetterc6b0ca32015-12-04 09:46:01 +01002016 * legacy IOCTLs
Jesse Barnesa62c93d2011-11-07 12:03:22 -08002017 * @idr_mutex: mutex for KMS ID allocation and management
2018 * @crtc_idr: main KMS ID tracking object
Daniel Vetter2c0c33d2014-10-27 20:19:38 +01002019 * @fb_lock: mutex to protect fb state and lists
Jesse Barnesa62c93d2011-11-07 12:03:22 -08002020 * @num_fb: number of fbs available
2021 * @fb_list: list of framebuffers available
2022 * @num_connector: number of connectors on this device
2023 * @connector_list: list of connector objects
2024 * @num_encoder: number of encoders on this device
2025 * @encoder_list: list of encoder objects
Daniel Vetter2c0c33d2014-10-27 20:19:38 +01002026 * @num_overlay_plane: number of overlay planes on this device
2027 * @num_total_plane: number of universal (i.e. with primary/curso) planes on this device
2028 * @plane_list: list of plane objects
Jesse Barnesa62c93d2011-11-07 12:03:22 -08002029 * @num_crtc: number of CRTCs on this device
2030 * @crtc_list: list of CRTC objects
Daniel Vetter2c0c33d2014-10-27 20:19:38 +01002031 * @property_list: list of property objects
Jesse Barnesa62c93d2011-11-07 12:03:22 -08002032 * @min_width: minimum pixel width on this device
2033 * @min_height: minimum pixel height on this device
2034 * @max_width: maximum pixel width on this device
2035 * @max_height: maximum pixel height on this device
2036 * @funcs: core driver provided mode setting functions
2037 * @fb_base: base address of the framebuffer
Daniel Vetter2c0c33d2014-10-27 20:19:38 +01002038 * @poll_enabled: track polling support for this device
2039 * @poll_running: track polling status for this device
Jesse Barnesa62c93d2011-11-07 12:03:22 -08002040 * @output_poll_work: delayed work for polling in process context
Daniel Vetter2c0c33d2014-10-27 20:19:38 +01002041 * @property_blob_list: list of all the blob property objects
Daniel Stone8fb6e7a2015-04-20 19:22:54 +01002042 * @blob_lock: mutex for blob property allocation and management
Jesse Barnesa62c93d2011-11-07 12:03:22 -08002043 * @*_property: core property tracking
Lionel Landwerlin5488dc12016-02-26 17:05:00 +00002044 * @degamma_lut_property: LUT used to convert the framebuffer's colors to linear
2045 * gamma
2046 * @degamma_lut_size_property: size of the degamma LUT as supported by the
2047 * driver (read-only)
2048 * @ctm_property: Matrix used to convert colors after the lookup in the
2049 * degamma LUT
2050 * @gamma_lut_property: LUT used to convert the colors, after the CSC matrix, to
2051 * the gamma space of the connected screen (read-only)
2052 * @gamma_lut_size_property: size of the gamma LUT as supported by the driver
Daniel Vetter2c0c33d2014-10-27 20:19:38 +01002053 * @preferred_depth: preferred RBG pixel depth, used by fb helpers
2054 * @prefer_shadow: hint to userspace to prefer shadow-fb rendering
2055 * @async_page_flip: does this device support async flips on the primary plane?
2056 * @cursor_width: hint to userspace for max cursor width
2057 * @cursor_height: hint to userspace for max cursor height
Dave Airlief453ba02008-11-07 14:05:41 -08002058 *
Jesse Barnesa62c93d2011-11-07 12:03:22 -08002059 * Core mode resource tracking structure. All CRTC, encoders, and connectors
2060 * enumerated by the driver are added here, as are global properties. Some
2061 * global restrictions are also here, e.g. dimension restrictions.
Dave Airlief453ba02008-11-07 14:05:41 -08002062 */
2063struct drm_mode_config {
Jesse Barnesad2563c2009-01-19 17:21:45 +10002064 struct mutex mutex; /* protects configuration (mode lists etc.) */
Rob Clark51fd3712013-11-19 12:10:12 -05002065 struct drm_modeset_lock connection_mutex; /* protects connector->encoder and encoder->crtc links */
2066 struct drm_modeset_acquire_ctx *acquire_ctx; /* for legacy _lock_all() / _unlock_all() */
Jesse Barnesad2563c2009-01-19 17:21:45 +10002067 struct mutex idr_mutex; /* for IDR management */
Dave Airlief453ba02008-11-07 14:05:41 -08002068 struct idr crtc_idr; /* use this idr for all IDs, fb, crtc, connector, modes - just makes life easier */
Dave Airlie138f9eb2014-10-20 16:17:17 +10002069 struct idr tile_idr; /* use this idr for all IDs, fb, crtc, connector, modes - just makes life easier */
Dave Airlief453ba02008-11-07 14:05:41 -08002070 /* this is limited to one for now */
Daniel Vetter4b096ac2012-12-10 21:19:18 +01002071
Daniel Vetter2c0c33d2014-10-27 20:19:38 +01002072 struct mutex fb_lock; /* proctects global and per-file fb lists */
Dave Airlief453ba02008-11-07 14:05:41 -08002073 int num_fb;
2074 struct list_head fb_list;
Daniel Vetter4b096ac2012-12-10 21:19:18 +01002075
Dave Airlief453ba02008-11-07 14:05:41 -08002076 int num_connector;
Maarten Lankhorst5fff80b2016-02-17 08:32:05 +01002077 struct ida connector_ida;
Dave Airlief453ba02008-11-07 14:05:41 -08002078 struct list_head connector_list;
2079 int num_encoder;
2080 struct list_head encoder_list;
Matt Ropere27dde32014-04-01 15:22:30 -07002081
2082 /*
2083 * Track # of overlay planes separately from # of total planes. By
2084 * default we only advertise overlay planes to userspace; if userspace
2085 * sets the "universal plane" capability bit, we'll go ahead and
2086 * expose all planes.
2087 */
2088 int num_overlay_plane;
2089 int num_total_plane;
Jesse Barnes8cf5c912011-11-14 14:51:27 -08002090 struct list_head plane_list;
Dave Airlief453ba02008-11-07 14:05:41 -08002091
2092 int num_crtc;
2093 struct list_head crtc_list;
2094
2095 struct list_head property_list;
2096
Dave Airlief453ba02008-11-07 14:05:41 -08002097 int min_width, min_height;
2098 int max_width, max_height;
Laurent Pincharte6ecefa2012-05-17 13:27:23 +02002099 const struct drm_mode_config_funcs *funcs;
Benjamin Herrenschmidtd883f7f2009-02-02 16:55:45 +11002100 resource_size_t fb_base;
Dave Airlief453ba02008-11-07 14:05:41 -08002101
Dave Airlieeb1f8e4f32010-05-07 06:42:51 +00002102 /* output poll support */
2103 bool poll_enabled;
Daniel Vetter905bc9f2012-10-23 18:23:36 +00002104 bool poll_running;
Daniel Vetter162b6a52015-01-21 08:45:21 +01002105 bool delayed_event;
Tejun Heo991ea752010-07-20 22:09:02 +02002106 struct delayed_work output_poll_work;
Dave Airlieeb1f8e4f32010-05-07 06:42:51 +00002107
Daniel Stone8fb6e7a2015-04-20 19:22:54 +01002108 struct mutex blob_lock;
2109
Dave Airlief453ba02008-11-07 14:05:41 -08002110 /* pointers to standard properties */
2111 struct list_head property_blob_list;
2112 struct drm_property *edid_property;
2113 struct drm_property *dpms_property;
Dave Airlie43aba7e2014-06-05 14:01:31 +10002114 struct drm_property *path_property;
Dave Airlie6f134d72014-10-20 16:30:50 +10002115 struct drm_property *tile_property;
Rob Clark9922ab52014-04-01 20:16:57 -04002116 struct drm_property *plane_type_property;
Sonika Jindal2a297cc2014-08-05 11:26:54 +05302117 struct drm_property *rotation_property;
Rob Clark6b4959f2014-12-18 16:01:53 -05002118 struct drm_property *prop_src_x;
2119 struct drm_property *prop_src_y;
2120 struct drm_property *prop_src_w;
2121 struct drm_property *prop_src_h;
2122 struct drm_property *prop_crtc_x;
2123 struct drm_property *prop_crtc_y;
2124 struct drm_property *prop_crtc_w;
2125 struct drm_property *prop_crtc_h;
2126 struct drm_property *prop_fb_id;
2127 struct drm_property *prop_crtc_id;
Daniel Vettereab3bbe2015-01-22 16:36:21 +01002128 struct drm_property *prop_active;
Daniel Stone955f3c32015-05-25 19:11:52 +01002129 struct drm_property *prop_mode_id;
Dave Airlief453ba02008-11-07 14:05:41 -08002130
2131 /* DVI-I properties */
2132 struct drm_property *dvi_i_subconnector_property;
2133 struct drm_property *dvi_i_select_subconnector_property;
2134
2135 /* TV properties */
2136 struct drm_property *tv_subconnector_property;
2137 struct drm_property *tv_select_subconnector_property;
2138 struct drm_property *tv_mode_property;
2139 struct drm_property *tv_left_margin_property;
2140 struct drm_property *tv_right_margin_property;
2141 struct drm_property *tv_top_margin_property;
2142 struct drm_property *tv_bottom_margin_property;
Francisco Jerezb6b79022009-08-02 04:19:20 +02002143 struct drm_property *tv_brightness_property;
2144 struct drm_property *tv_contrast_property;
2145 struct drm_property *tv_flicker_reduction_property;
Francisco Jereza75f0232009-08-12 02:30:10 +02002146 struct drm_property *tv_overscan_property;
2147 struct drm_property *tv_saturation_property;
2148 struct drm_property *tv_hue_property;
Dave Airlief453ba02008-11-07 14:05:41 -08002149
2150 /* Optional properties */
2151 struct drm_property *scaling_mode_property;
Vandana Kannanff587e42014-06-11 10:46:48 +05302152 struct drm_property *aspect_ratio_property;
Jakob Bornecrantz884840a2009-12-03 23:25:47 +00002153 struct drm_property *dirty_info_property;
Dave Airlie019d96c2011-09-29 16:20:42 +01002154
Lionel Landwerlin5488dc12016-02-26 17:05:00 +00002155 /* Optional color correction properties */
2156 struct drm_property *degamma_lut_property;
2157 struct drm_property *degamma_lut_size_property;
2158 struct drm_property *ctm_property;
2159 struct drm_property *gamma_lut_property;
2160 struct drm_property *gamma_lut_size_property;
2161
Dave Airlie5bb2bbf2014-11-10 10:18:15 +10002162 /* properties for virtual machine layout */
2163 struct drm_property *suggested_x_property;
2164 struct drm_property *suggested_y_property;
2165
Dave Airlie019d96c2011-09-29 16:20:42 +01002166 /* dumb ioctl parameters */
2167 uint32_t preferred_depth, prefer_shadow;
Keith Packard62f21042013-07-22 18:50:00 -07002168
2169 /* whether async page flip is supported or not */
2170 bool async_page_flip;
Alex Deucher8716ed42014-02-12 12:48:23 -05002171
Rob Clarke3eb3252015-02-05 14:41:52 +00002172 /* whether the driver supports fb modifiers */
2173 bool allow_fb_modifiers;
2174
Alex Deucher8716ed42014-02-12 12:48:23 -05002175 /* cursor size */
2176 uint32_t cursor_width, cursor_height;
Dave Airlief453ba02008-11-07 14:05:41 -08002177};
2178
Rob Clarkdd275952014-11-25 20:29:46 -05002179/**
2180 * drm_for_each_plane_mask - iterate over planes specified by bitmask
2181 * @plane: the loop cursor
2182 * @dev: the DRM device
2183 * @plane_mask: bitmask of plane indices
2184 *
2185 * Iterate over all planes specified by bitmask.
2186 */
2187#define drm_for_each_plane_mask(plane, dev, plane_mask) \
2188 list_for_each_entry((plane), &(dev)->mode_config.plane_list, head) \
Jani Nikula373701b2015-11-24 21:21:55 +02002189 for_each_if ((plane_mask) & (1 << drm_plane_index(plane)))
Rob Clarkdd275952014-11-25 20:29:46 -05002190
Maarten Lankhorstead8b662016-01-07 10:59:19 +01002191/**
2192 * drm_for_each_encoder_mask - iterate over encoders specified by bitmask
2193 * @encoder: the loop cursor
2194 * @dev: the DRM device
2195 * @encoder_mask: bitmask of encoder indices
2196 *
2197 * Iterate over all encoders specified by bitmask.
2198 */
2199#define drm_for_each_encoder_mask(encoder, dev, encoder_mask) \
2200 list_for_each_entry((encoder), &(dev)->mode_config.encoder_list, head) \
2201 for_each_if ((encoder_mask) & (1 << drm_encoder_index(encoder)))
Rob Clarkdd275952014-11-25 20:29:46 -05002202
Dave Airlief453ba02008-11-07 14:05:41 -08002203#define obj_to_crtc(x) container_of(x, struct drm_crtc, base)
2204#define obj_to_connector(x) container_of(x, struct drm_connector, base)
2205#define obj_to_encoder(x) container_of(x, struct drm_encoder, base)
2206#define obj_to_mode(x) container_of(x, struct drm_display_mode, base)
2207#define obj_to_fb(x) container_of(x, struct drm_framebuffer, base)
2208#define obj_to_property(x) container_of(x, struct drm_property, base)
2209#define obj_to_blob(x) container_of(x, struct drm_property_blob, base)
Jesse Barnes8cf5c912011-11-14 14:51:27 -08002210#define obj_to_plane(x) container_of(x, struct drm_plane, base)
Dave Airlief453ba02008-11-07 14:05:41 -08002211
Sascha Hauer4a67d392012-02-06 10:58:17 +01002212struct drm_prop_enum_list {
2213 int type;
2214 char *name;
2215};
Dave Airlief453ba02008-11-07 14:05:41 -08002216
Ville Syrjäläf9882872015-12-09 16:19:31 +02002217extern __printf(6, 7)
2218int drm_crtc_init_with_planes(struct drm_device *dev,
2219 struct drm_crtc *crtc,
2220 struct drm_plane *primary,
2221 struct drm_plane *cursor,
2222 const struct drm_crtc_funcs *funcs,
2223 const char *name, ...);
Dave Airlief453ba02008-11-07 14:05:41 -08002224extern void drm_crtc_cleanup(struct drm_crtc *crtc);
Russell Kingdb5f7a62014-01-02 21:27:33 +00002225extern unsigned int drm_crtc_index(struct drm_crtc *crtc);
2226
2227/**
2228 * drm_crtc_mask - find the mask of a registered CRTC
2229 * @crtc: CRTC to find mask for
2230 *
2231 * Given a registered CRTC, return the mask bit of that CRTC for an
2232 * encoder's possible_crtcs field.
2233 */
2234static inline uint32_t drm_crtc_mask(struct drm_crtc *crtc)
2235{
2236 return 1 << drm_crtc_index(crtc);
2237}
Dave Airlief453ba02008-11-07 14:05:41 -08002238
Ilia Mirkinb21e3af2013-08-07 22:34:48 -04002239extern void drm_connector_ida_init(void);
2240extern void drm_connector_ida_destroy(void);
Ville Syrjälä6bfc56a2012-03-13 12:35:48 +02002241extern int drm_connector_init(struct drm_device *dev,
2242 struct drm_connector *connector,
2243 const struct drm_connector_funcs *funcs,
2244 int connector_type);
Thomas Wood34ea3d32014-05-29 16:57:41 +01002245int drm_connector_register(struct drm_connector *connector);
2246void drm_connector_unregister(struct drm_connector *connector);
Dave Airlief453ba02008-11-07 14:05:41 -08002247
2248extern void drm_connector_cleanup(struct drm_connector *connector);
Maarten Lankhorst5fff80b2016-02-17 08:32:05 +01002249static inline unsigned drm_connector_index(struct drm_connector *connector)
2250{
2251 return connector->connector_id;
2252}
2253
Alexey Brodkin54d2c2d2016-04-19 15:24:51 +03002254/* helpers to {un}register all connectors from sysfs for device */
2255extern int drm_connector_register_all(struct drm_device *dev);
Alexey Brodkin6c87e5c2016-03-23 11:42:54 +03002256extern void drm_connector_unregister_all(struct drm_device *dev);
Dave Airlief453ba02008-11-07 14:05:41 -08002257
Ajay Kumar3d3f8b12015-01-20 22:08:44 +05302258extern int drm_bridge_add(struct drm_bridge *bridge);
2259extern void drm_bridge_remove(struct drm_bridge *bridge);
2260extern struct drm_bridge *of_drm_find_bridge(struct device_node *np);
2261extern int drm_bridge_attach(struct drm_device *dev, struct drm_bridge *bridge);
Sean Paul3b336ec2013-08-14 16:47:37 -04002262
Archit Taneja862e6862015-05-21 11:03:16 +05302263bool drm_bridge_mode_fixup(struct drm_bridge *bridge,
2264 const struct drm_display_mode *mode,
2265 struct drm_display_mode *adjusted_mode);
2266void drm_bridge_disable(struct drm_bridge *bridge);
2267void drm_bridge_post_disable(struct drm_bridge *bridge);
2268void drm_bridge_mode_set(struct drm_bridge *bridge,
2269 struct drm_display_mode *mode,
2270 struct drm_display_mode *adjusted_mode);
2271void drm_bridge_pre_enable(struct drm_bridge *bridge);
2272void drm_bridge_enable(struct drm_bridge *bridge);
2273
Ville Syrjälä13a3d912015-12-09 16:20:18 +02002274extern __printf(5, 6)
2275int drm_encoder_init(struct drm_device *dev,
2276 struct drm_encoder *encoder,
2277 const struct drm_encoder_funcs *funcs,
2278 int encoder_type, const char *name, ...);
Maarten Lankhorst47d77772016-01-07 10:59:18 +01002279extern unsigned int drm_encoder_index(struct drm_encoder *encoder);
Dave Airlief453ba02008-11-07 14:05:41 -08002280
Thierry Reding3d887362014-01-13 14:33:20 +01002281/**
2282 * drm_encoder_crtc_ok - can a given crtc drive a given encoder?
2283 * @encoder: encoder to test
2284 * @crtc: crtc to test
2285 *
2286 * Return false if @encoder can't be driven by @crtc, true otherwise.
2287 */
2288static inline bool drm_encoder_crtc_ok(struct drm_encoder *encoder,
2289 struct drm_crtc *crtc)
2290{
2291 return !!(encoder->possible_crtcs & drm_crtc_mask(crtc));
2292}
2293
Ville Syrjäläb0b3b792015-12-09 16:19:55 +02002294extern __printf(8, 9)
2295int drm_universal_plane_init(struct drm_device *dev,
2296 struct drm_plane *plane,
2297 unsigned long possible_crtcs,
2298 const struct drm_plane_funcs *funcs,
2299 const uint32_t *formats,
2300 unsigned int format_count,
2301 enum drm_plane_type type,
2302 const char *name, ...);
Jesse Barnes8cf5c912011-11-14 14:51:27 -08002303extern int drm_plane_init(struct drm_device *dev,
2304 struct drm_plane *plane,
2305 unsigned long possible_crtcs,
2306 const struct drm_plane_funcs *funcs,
Thierry Reding45e37432015-08-12 16:54:28 +02002307 const uint32_t *formats, unsigned int format_count,
Matt Roperdc415ff2014-04-01 15:22:36 -07002308 bool is_primary);
Jesse Barnes8cf5c912011-11-14 14:51:27 -08002309extern void drm_plane_cleanup(struct drm_plane *plane);
Daniel Vetter10f637b2014-07-29 13:47:11 +02002310extern unsigned int drm_plane_index(struct drm_plane *plane);
Chandra Konduruf81338a2015-04-09 17:36:21 -07002311extern struct drm_plane * drm_plane_from_index(struct drm_device *dev, int idx);
Ville Syrjälä9125e612013-06-03 16:10:40 +03002312extern void drm_plane_force_disable(struct drm_plane *plane);
Laurent Pinchartead86102015-03-05 02:25:43 +02002313extern int drm_plane_check_pixel_format(const struct drm_plane *plane,
2314 u32 format);
Gustavo Padovanecb7e162014-12-01 15:40:09 -08002315extern void drm_crtc_get_hv_timing(const struct drm_display_mode *mode,
2316 int *hdisplay, int *vdisplay);
Matt Roperaf936292014-04-01 15:22:34 -07002317extern int drm_crtc_check_viewport(const struct drm_crtc *crtc,
2318 int x, int y,
2319 const struct drm_display_mode *mode,
2320 const struct drm_framebuffer *fb);
Jesse Barnes8cf5c912011-11-14 14:51:27 -08002321
Dave Airlief453ba02008-11-07 14:05:41 -08002322extern void drm_encoder_cleanup(struct drm_encoder *encoder);
2323
Ville Syrjäläd20d3172013-06-07 15:43:07 +00002324extern const char *drm_get_connector_status_name(enum drm_connector_status status);
Jesse Barnesac1bb362014-02-10 15:32:44 -08002325extern const char *drm_get_subpixel_order_name(enum subpixel_order order);
Ville Syrjäläd20d3172013-06-07 15:43:07 +00002326extern const char *drm_get_dpms_name(int val);
2327extern const char *drm_get_dvi_i_subconnector_name(int val);
2328extern const char *drm_get_dvi_i_select_name(int val);
2329extern const char *drm_get_tv_subconnector_name(int val);
2330extern const char *drm_get_tv_select_name(int val);
Kristian Høgsbergea39f832009-02-12 14:37:56 -05002331extern void drm_fb_release(struct drm_file *file_priv);
Daniel Stonee2f5d2e2015-05-22 13:34:51 +01002332extern void drm_property_destroy_user_blobs(struct drm_device *dev,
2333 struct drm_file *file_priv);
Adam Jacksonfbff4692012-09-18 10:58:47 -04002334extern bool drm_probe_ddc(struct i2c_adapter *adapter);
Dave Airlief453ba02008-11-07 14:05:41 -08002335extern struct edid *drm_get_edid(struct drm_connector *connector,
2336 struct i2c_adapter *adapter);
Lukas Wunner5cb8eaa22016-01-11 20:09:20 +01002337extern struct edid *drm_get_edid_switcheroo(struct drm_connector *connector,
2338 struct i2c_adapter *adapter);
Jani Nikula51f8da52013-09-27 15:08:27 +03002339extern struct edid *drm_edid_duplicate(const struct edid *edid);
Dave Airlief453ba02008-11-07 14:05:41 -08002340extern int drm_add_edid_modes(struct drm_connector *connector, struct edid *edid);
Dave Airlief453ba02008-11-07 14:05:41 -08002341extern void drm_mode_config_init(struct drm_device *dev);
Chris Wilsoneb0335562011-01-24 15:11:08 +00002342extern void drm_mode_config_reset(struct drm_device *dev);
Dave Airlief453ba02008-11-07 14:05:41 -08002343extern void drm_mode_config_cleanup(struct drm_device *dev);
Dave Airlief453ba02008-11-07 14:05:41 -08002344
Dave Airlie43aba7e2014-06-05 14:01:31 +10002345extern int drm_mode_connector_set_path_property(struct drm_connector *connector,
Thierry Reding12e6cec2014-05-13 11:38:36 +02002346 const char *path);
Dave Airlie6f134d72014-10-20 16:30:50 +10002347int drm_mode_connector_set_tile_property(struct drm_connector *connector);
Dave Airlief453ba02008-11-07 14:05:41 -08002348extern int drm_mode_connector_update_edid_property(struct drm_connector *connector,
Thierry Reding12e6cec2014-05-13 11:38:36 +02002349 const struct edid *edid);
Rob Clark5ea22f22014-05-30 11:34:01 -04002350
Boris Brezillonb5571e92014-07-22 12:09:10 +02002351extern int drm_display_info_set_bus_formats(struct drm_display_info *info,
2352 const u32 *formats,
2353 unsigned int num_formats);
2354
Rob Clark5ea22f22014-05-30 11:34:01 -04002355static inline bool drm_property_type_is(struct drm_property *property,
2356 uint32_t type)
2357{
2358 /* instanceof for props.. handles extended type vs original types: */
2359 if (property->flags & DRM_MODE_PROP_EXTENDED_TYPE)
2360 return (property->flags & DRM_MODE_PROP_EXTENDED_TYPE) == type;
2361 return property->flags & type;
2362}
2363
2364static inline bool drm_property_type_valid(struct drm_property *property)
2365{
2366 if (property->flags & DRM_MODE_PROP_EXTENDED_TYPE)
2367 return !(property->flags & DRM_MODE_PROP_LEGACY_TYPE);
2368 return !!(property->flags & DRM_MODE_PROP_LEGACY_TYPE);
2369}
2370
Paulo Zanonic5431882012-05-15 18:09:02 -03002371extern int drm_object_property_set_value(struct drm_mode_object *obj,
2372 struct drm_property *property,
2373 uint64_t val);
2374extern int drm_object_property_get_value(struct drm_mode_object *obj,
2375 struct drm_property *property,
2376 uint64_t *value);
Dave Airlief453ba02008-11-07 14:05:41 -08002377extern int drm_framebuffer_init(struct drm_device *dev,
2378 struct drm_framebuffer *fb,
2379 const struct drm_framebuffer_funcs *funcs);
Daniel Vetter786b99e2012-12-02 21:53:40 +01002380extern struct drm_framebuffer *drm_framebuffer_lookup(struct drm_device *dev,
2381 uint32_t id);
Rob Clarkf7eff602012-09-05 21:48:38 +00002382extern void drm_framebuffer_remove(struct drm_framebuffer *fb);
Dave Airlief453ba02008-11-07 14:05:41 -08002383extern void drm_framebuffer_cleanup(struct drm_framebuffer *fb);
Daniel Vetter36206362012-12-10 20:42:17 +01002384extern void drm_framebuffer_unregister_private(struct drm_framebuffer *fb);
Dave Airlief453ba02008-11-07 14:05:41 -08002385
Paulo Zanonic5431882012-05-15 18:09:02 -03002386extern void drm_object_attach_property(struct drm_mode_object *obj,
2387 struct drm_property *property,
2388 uint64_t init_val);
Dave Airlief453ba02008-11-07 14:05:41 -08002389extern struct drm_property *drm_property_create(struct drm_device *dev, int flags,
2390 const char *name, int num_values);
Sascha Hauer4a67d392012-02-06 10:58:17 +01002391extern struct drm_property *drm_property_create_enum(struct drm_device *dev, int flags,
2392 const char *name,
2393 const struct drm_prop_enum_list *props,
2394 int num_values);
Rob Clark49e27542012-05-17 02:23:26 -06002395struct drm_property *drm_property_create_bitmask(struct drm_device *dev,
2396 int flags, const char *name,
2397 const struct drm_prop_enum_list *props,
Ville Syrjälä7689ffb2014-07-08 10:31:52 +05302398 int num_props,
2399 uint64_t supported_bits);
Sascha Hauerd9bc3c02012-02-06 10:58:18 +01002400struct drm_property *drm_property_create_range(struct drm_device *dev, int flags,
2401 const char *name,
2402 uint64_t min, uint64_t max);
Rob Clarkebc44cf2012-09-12 22:22:31 -05002403struct drm_property *drm_property_create_signed_range(struct drm_device *dev,
2404 int flags, const char *name,
2405 int64_t min, int64_t max);
Rob Clark98f75de2014-05-30 11:37:03 -04002406struct drm_property *drm_property_create_object(struct drm_device *dev,
2407 int flags, const char *name, uint32_t type);
Daniel Vetter960cd9d2015-01-21 08:47:38 +01002408struct drm_property *drm_property_create_bool(struct drm_device *dev, int flags,
2409 const char *name);
Daniel Stone6bcacf52015-04-20 19:22:55 +01002410struct drm_property_blob *drm_property_create_blob(struct drm_device *dev,
2411 size_t length,
2412 const void *data);
2413struct drm_property_blob *drm_property_lookup_blob(struct drm_device *dev,
2414 uint32_t id);
2415struct drm_property_blob *drm_property_reference_blob(struct drm_property_blob *blob);
2416void drm_property_unreference_blob(struct drm_property_blob *blob);
Dave Airlief453ba02008-11-07 14:05:41 -08002417extern void drm_property_destroy(struct drm_device *dev, struct drm_property *property);
2418extern int drm_property_add_enum(struct drm_property *property, int index,
2419 uint64_t value, const char *name);
2420extern int drm_mode_create_dvi_i_properties(struct drm_device *dev);
Thierry Reding2f763312014-10-13 12:45:57 +02002421extern int drm_mode_create_tv_properties(struct drm_device *dev,
2422 unsigned int num_modes,
Ville Syrjäläb7c914b2015-08-31 15:09:26 +03002423 const char * const modes[]);
Dave Airlief453ba02008-11-07 14:05:41 -08002424extern int drm_mode_create_scaling_mode_property(struct drm_device *dev);
Vandana Kannanff587e42014-06-11 10:46:48 +05302425extern int drm_mode_create_aspect_ratio_property(struct drm_device *dev);
Jakob Bornecrantz884840a2009-12-03 23:25:47 +00002426extern int drm_mode_create_dirty_info_property(struct drm_device *dev);
Dave Airlie5bb2bbf2014-11-10 10:18:15 +10002427extern int drm_mode_create_suggested_offset_properties(struct drm_device *dev);
Rob Clarkd34f20d2014-12-18 16:01:56 -05002428extern bool drm_property_change_valid_get(struct drm_property *property,
2429 uint64_t value, struct drm_mode_object **ref);
2430extern void drm_property_change_valid_put(struct drm_property *property,
2431 struct drm_mode_object *ref);
Dave Airlief453ba02008-11-07 14:05:41 -08002432
2433extern int drm_mode_connector_attach_encoder(struct drm_connector *connector,
2434 struct drm_encoder *encoder);
Sascha Hauer4cae5b82012-02-01 11:38:23 +01002435extern int drm_mode_crtc_set_gamma_size(struct drm_crtc *crtc,
Dave Airlief453ba02008-11-07 14:05:41 -08002436 int gamma_size);
Daniel Vetter7a9c9062009-09-15 22:57:31 +02002437extern struct drm_mode_object *drm_mode_object_find(struct drm_device *dev,
2438 uint32_t id, uint32_t type);
Dave Airlied0f37cf62016-04-15 15:10:36 +10002439void drm_mode_object_reference(struct drm_mode_object *obj);
2440void drm_mode_object_unreference(struct drm_mode_object *obj);
Rob Clark98f75de2014-05-30 11:37:03 -04002441
Dave Airlief453ba02008-11-07 14:05:41 -08002442/* IOCTLs */
2443extern int drm_mode_getresources(struct drm_device *dev,
2444 void *data, struct drm_file *file_priv);
Jesse Barnes8cf5c912011-11-14 14:51:27 -08002445extern int drm_mode_getplane_res(struct drm_device *dev, void *data,
2446 struct drm_file *file_priv);
Dave Airlief453ba02008-11-07 14:05:41 -08002447extern int drm_mode_getcrtc(struct drm_device *dev,
2448 void *data, struct drm_file *file_priv);
2449extern int drm_mode_getconnector(struct drm_device *dev,
2450 void *data, struct drm_file *file_priv);
Daniel Vetter2d13b672012-12-11 13:47:23 +01002451extern int drm_mode_set_config_internal(struct drm_mode_set *set);
Dave Airlief453ba02008-11-07 14:05:41 -08002452extern int drm_mode_setcrtc(struct drm_device *dev,
2453 void *data, struct drm_file *file_priv);
Jesse Barnes8cf5c912011-11-14 14:51:27 -08002454extern int drm_mode_getplane(struct drm_device *dev,
2455 void *data, struct drm_file *file_priv);
2456extern int drm_mode_setplane(struct drm_device *dev,
2457 void *data, struct drm_file *file_priv);
Dave Airlief453ba02008-11-07 14:05:41 -08002458extern int drm_mode_cursor_ioctl(struct drm_device *dev,
2459 void *data, struct drm_file *file_priv);
Dave Airlie4c813d42013-06-20 11:48:52 +10002460extern int drm_mode_cursor2_ioctl(struct drm_device *dev,
2461 void *data, struct drm_file *file_priv);
Dave Airlief453ba02008-11-07 14:05:41 -08002462extern int drm_mode_addfb(struct drm_device *dev,
2463 void *data, struct drm_file *file_priv);
Jesse Barnes308e5bc2011-11-14 14:51:28 -08002464extern int drm_mode_addfb2(struct drm_device *dev,
2465 void *data, struct drm_file *file_priv);
2466extern uint32_t drm_mode_legacy_fb_format(uint32_t bpp, uint32_t depth);
Dave Airlief453ba02008-11-07 14:05:41 -08002467extern int drm_mode_rmfb(struct drm_device *dev,
2468 void *data, struct drm_file *file_priv);
2469extern int drm_mode_getfb(struct drm_device *dev,
2470 void *data, struct drm_file *file_priv);
Jakob Bornecrantz884840a2009-12-03 23:25:47 +00002471extern int drm_mode_dirtyfb_ioctl(struct drm_device *dev,
2472 void *data, struct drm_file *file_priv);
Dave Airlief453ba02008-11-07 14:05:41 -08002473
2474extern int drm_mode_getproperty_ioctl(struct drm_device *dev,
2475 void *data, struct drm_file *file_priv);
2476extern int drm_mode_getblob_ioctl(struct drm_device *dev,
2477 void *data, struct drm_file *file_priv);
Daniel Stonee2f5d2e2015-05-22 13:34:51 +01002478extern int drm_mode_createblob_ioctl(struct drm_device *dev,
2479 void *data, struct drm_file *file_priv);
2480extern int drm_mode_destroyblob_ioctl(struct drm_device *dev,
2481 void *data, struct drm_file *file_priv);
Dave Airlief453ba02008-11-07 14:05:41 -08002482extern int drm_mode_connector_property_set_ioctl(struct drm_device *dev,
2483 void *data, struct drm_file *file_priv);
Dave Airlief453ba02008-11-07 14:05:41 -08002484extern int drm_mode_getencoder(struct drm_device *dev,
2485 void *data, struct drm_file *file_priv);
2486extern int drm_mode_gamma_get_ioctl(struct drm_device *dev,
2487 void *data, struct drm_file *file_priv);
2488extern int drm_mode_gamma_set_ioctl(struct drm_device *dev,
2489 void *data, struct drm_file *file_priv);
Thierry Reding18316c82012-12-20 15:41:44 +01002490extern u8 drm_match_cea_mode(const struct drm_display_mode *to_match);
Vandana Kannan0967e6a2014-04-01 16:26:59 +05302491extern enum hdmi_picture_aspect drm_get_cea_aspect_ratio(const u8 video_code);
Ma Lingf23c20c2009-03-26 19:26:23 +08002492extern bool drm_detect_hdmi_monitor(struct edid *edid);
Zhenyu Wang8fe97902010-09-19 14:27:28 +08002493extern bool drm_detect_monitor_audio(struct edid *edid);
Ville Syrjäläb1edd6a2013-01-17 16:31:30 +02002494extern bool drm_rgb_quant_range_selectable(struct edid *edid);
Kristian Høgsbergd91d8a32009-11-17 12:43:55 -05002495extern int drm_mode_page_flip_ioctl(struct drm_device *dev,
2496 void *data, struct drm_file *file_priv);
Zhao Yakuif0fda0a2009-09-03 09:33:48 +08002497extern int drm_add_modes_noedid(struct drm_connector *connector,
2498 int hdisplay, int vdisplay);
Gerd Hoffmann3cf70da2013-10-11 10:01:08 +02002499extern void drm_set_preferred_mode(struct drm_connector *connector,
2500 int hpref, int vpref);
Alex Deucher3c537882010-02-05 04:21:19 -05002501
Thomas Reim051963d2011-07-29 14:28:57 +00002502extern int drm_edid_header_is_valid(const u8 *raw_edid);
Todd Previte6ba2bd32015-04-21 11:09:41 -07002503extern bool drm_edid_block_valid(u8 *raw_edid, int block, bool print_bad_edid,
2504 bool *edid_corrupt);
Alex Deucher3c537882010-02-05 04:21:19 -05002505extern bool drm_edid_is_valid(struct edid *edid);
Jim Bride59f7c0f2016-04-14 10:18:35 -07002506extern void drm_edid_get_monitor_name(struct edid *edid, char *name,
2507 int buflen);
Dave Airlie138f9eb2014-10-20 16:17:17 +10002508
2509extern struct drm_tile_group *drm_mode_create_tile_group(struct drm_device *dev,
2510 char topology[8]);
2511extern struct drm_tile_group *drm_mode_get_tile_group(struct drm_device *dev,
2512 char topology[8]);
2513extern void drm_mode_put_tile_group(struct drm_device *dev,
2514 struct drm_tile_group *tg);
Dave Airlie1d42bbc2010-05-07 05:02:30 +00002515struct drm_display_mode *drm_mode_find_dmt(struct drm_device *dev,
Adam Jacksonf6e252b2012-04-13 16:33:31 -04002516 int hsize, int vsize, int fresh,
2517 bool rb);
Dave Airlieff72145b2011-02-07 12:16:14 +10002518
2519extern int drm_mode_create_dumb_ioctl(struct drm_device *dev,
2520 void *data, struct drm_file *file_priv);
2521extern int drm_mode_mmap_dumb_ioctl(struct drm_device *dev,
2522 void *data, struct drm_file *file_priv);
2523extern int drm_mode_destroy_dumb_ioctl(struct drm_device *dev,
2524 void *data, struct drm_file *file_priv);
Paulo Zanonic5431882012-05-15 18:09:02 -03002525extern int drm_mode_obj_get_properties_ioctl(struct drm_device *dev, void *data,
2526 struct drm_file *file_priv);
2527extern int drm_mode_obj_set_property_ioctl(struct drm_device *dev, void *data,
2528 struct drm_file *file_priv);
Thomas Wood3a5f87c2014-08-20 14:45:00 +01002529extern int drm_mode_plane_set_obj_prop(struct drm_plane *plane,
2530 struct drm_property *property,
2531 uint64_t value);
Rob Clarkd34f20d2014-12-18 16:01:56 -05002532extern int drm_mode_atomic_ioctl(struct drm_device *dev,
2533 void *data, struct drm_file *file_priv);
Dave Airlie248dbc22011-11-29 20:02:54 +00002534
2535extern void drm_fb_get_bpp_depth(uint32_t format, unsigned int *depth,
2536 int *bpp);
Ville Syrjälä141670e2012-04-05 21:35:15 +03002537extern int drm_format_num_planes(uint32_t format);
Ville Syrjälä5a86bd52012-04-05 21:35:16 +03002538extern int drm_format_plane_cpp(uint32_t format, int plane);
Ville Syrjälä01b68b02012-04-05 21:35:17 +03002539extern int drm_format_horz_chroma_subsampling(uint32_t format);
2540extern int drm_format_vert_chroma_subsampling(uint32_t format);
Ville Syrjälä4c617162016-02-09 17:29:44 +02002541extern int drm_format_plane_width(int width, uint32_t format, int plane);
2542extern int drm_format_plane_height(int height, uint32_t format, int plane);
Ville Syrjäläd20d3172013-06-07 15:43:07 +00002543extern const char *drm_get_format_name(uint32_t format);
Ville Syrjäläc1df5f32014-07-08 10:31:53 +05302544extern struct drm_property *drm_mode_create_rotation_property(struct drm_device *dev,
2545 unsigned int supported_rotations);
Ville Syrjälä3c9855f2014-07-08 10:31:56 +05302546extern unsigned int drm_rotation_simplify(unsigned int rotation,
2547 unsigned int supported_rotations);
Ville Syrjälä141670e2012-04-05 21:35:15 +03002548
Russell King96f60e32012-08-15 13:59:49 +01002549/* Helpers */
Rob Clarka2b34e22013-10-05 16:36:52 -04002550
2551static inline struct drm_plane *drm_plane_find(struct drm_device *dev,
2552 uint32_t id)
2553{
2554 struct drm_mode_object *mo;
2555 mo = drm_mode_object_find(dev, id, DRM_MODE_OBJECT_PLANE);
2556 return mo ? obj_to_plane(mo) : NULL;
2557}
2558
Russell King96f60e32012-08-15 13:59:49 +01002559static inline struct drm_crtc *drm_crtc_find(struct drm_device *dev,
2560 uint32_t id)
2561{
2562 struct drm_mode_object *mo;
2563 mo = drm_mode_object_find(dev, id, DRM_MODE_OBJECT_CRTC);
2564 return mo ? obj_to_crtc(mo) : NULL;
2565}
2566
2567static inline struct drm_encoder *drm_encoder_find(struct drm_device *dev,
2568 uint32_t id)
2569{
2570 struct drm_mode_object *mo;
2571 mo = drm_mode_object_find(dev, id, DRM_MODE_OBJECT_ENCODER);
2572 return mo ? obj_to_encoder(mo) : NULL;
2573}
2574
Rob Clarka2b34e22013-10-05 16:36:52 -04002575static inline struct drm_connector *drm_connector_find(struct drm_device *dev,
2576 uint32_t id)
2577{
2578 struct drm_mode_object *mo;
2579 mo = drm_mode_object_find(dev, id, DRM_MODE_OBJECT_CONNECTOR);
2580 return mo ? obj_to_connector(mo) : NULL;
2581}
2582
2583static inline struct drm_property *drm_property_find(struct drm_device *dev,
2584 uint32_t id)
2585{
2586 struct drm_mode_object *mo;
2587 mo = drm_mode_object_find(dev, id, DRM_MODE_OBJECT_PROPERTY);
2588 return mo ? obj_to_property(mo) : NULL;
2589}
2590
Lionel Landwerlin5488dc12016-02-26 17:05:00 +00002591/*
2592 * Extract a degamma/gamma LUT value provided by user and round it to the
2593 * precision supported by the hardware.
2594 */
2595static inline uint32_t drm_color_lut_extract(uint32_t user_input,
2596 uint32_t bit_precision)
2597{
Lionel Landwerlin644a8052016-03-22 14:10:33 +00002598 uint32_t val = user_input;
Lionel Landwerlin5488dc12016-02-26 17:05:00 +00002599 uint32_t max = 0xffff >> (16 - bit_precision);
2600
Lionel Landwerlin644a8052016-03-22 14:10:33 +00002601 /* Round only if we're not using full precision. */
2602 if (bit_precision < 16) {
2603 val += 1UL << (16 - bit_precision - 1);
2604 val >>= 16 - bit_precision;
2605 }
Lionel Landwerlin5488dc12016-02-26 17:05:00 +00002606
2607 return clamp_val(val, 0, max);
2608}
2609
Dave Airlied0f37cf62016-04-15 15:10:36 +10002610/*
2611 * drm_framebuffer_reference - incr the fb refcnt
2612 * @fb: framebuffer
2613 *
2614 * This functions increments the fb's refcount.
2615 */
2616static inline void drm_framebuffer_reference(struct drm_framebuffer *fb)
2617{
2618 drm_mode_object_reference(&fb->base);
2619}
2620
2621/**
2622 * drm_framebuffer_unreference - unref a framebuffer
2623 * @fb: framebuffer to unref
2624 *
2625 * This functions decrements the fb's refcount and frees it if it drops to zero.
2626 */
2627static inline void drm_framebuffer_unreference(struct drm_framebuffer *fb)
2628{
2629 drm_mode_object_unreference(&fb->base);
2630}
2631
Dave Airlie747a5982016-04-15 15:10:35 +10002632/**
2633 * drm_framebuffer_read_refcount - read the framebuffer reference count.
2634 * @fb: framebuffer
2635 *
2636 * This functions returns the framebuffer's reference count.
2637 */
2638static inline uint32_t drm_framebuffer_read_refcount(struct drm_framebuffer *fb)
2639{
Dave Airlied0f37cf62016-04-15 15:10:36 +10002640 return atomic_read(&fb->base.refcount.refcount);
Dave Airlie747a5982016-04-15 15:10:35 +10002641}
2642
Matt Ropere27dde32014-04-01 15:22:30 -07002643/* Plane list iterator for legacy (overlay only) planes. */
Daniel Vetter4ea50e92015-07-09 23:44:24 +02002644#define drm_for_each_legacy_plane(plane, dev) \
2645 list_for_each_entry(plane, &(dev)->mode_config.plane_list, head) \
Jani Nikula373701b2015-11-24 21:21:55 +02002646 for_each_if (plane->type == DRM_PLANE_TYPE_OVERLAY)
Matt Ropere27dde32014-04-01 15:22:30 -07002647
Daniel Vetter6295d602015-07-09 23:44:25 +02002648#define drm_for_each_plane(plane, dev) \
2649 list_for_each_entry(plane, &(dev)->mode_config.plane_list, head)
2650
2651#define drm_for_each_crtc(crtc, dev) \
2652 list_for_each_entry(crtc, &(dev)->mode_config.crtc_list, head)
2653
Daniel Vetter7a3f3d62015-07-09 23:44:28 +02002654static inline void
2655assert_drm_connector_list_read_locked(struct drm_mode_config *mode_config)
2656{
Daniel Vettercff20ba2015-07-09 23:44:33 +02002657 /*
2658 * The connector hotadd/remove code currently grabs both locks when
2659 * updating lists. Hence readers need only hold either of them to be
2660 * safe and the check amounts to
2661 *
2662 * WARN_ON(not_holding(A) && not_holding(B)).
2663 */
2664 WARN_ON(!mutex_is_locked(&mode_config->mutex) &&
2665 !drm_modeset_is_locked(&mode_config->connection_mutex));
Daniel Vetter7a3f3d62015-07-09 23:44:28 +02002666}
2667
Daniel Vetter6295d602015-07-09 23:44:25 +02002668#define drm_for_each_connector(connector, dev) \
Daniel Vetter7a3f3d62015-07-09 23:44:28 +02002669 for (assert_drm_connector_list_read_locked(&(dev)->mode_config), \
2670 connector = list_first_entry(&(dev)->mode_config.connector_list, \
2671 struct drm_connector, head); \
2672 &connector->head != (&(dev)->mode_config.connector_list); \
2673 connector = list_next_entry(connector, head))
Daniel Vetter6295d602015-07-09 23:44:25 +02002674
2675#define drm_for_each_encoder(encoder, dev) \
2676 list_for_each_entry(encoder, &(dev)->mode_config.encoder_list, head)
2677
2678#define drm_for_each_fb(fb, dev) \
Daniel Vetter4676ba02015-07-09 23:44:30 +02002679 for (WARN_ON(!mutex_is_locked(&(dev)->mode_config.fb_lock)), \
2680 fb = list_first_entry(&(dev)->mode_config.fb_list, \
2681 struct drm_framebuffer, head); \
2682 &fb->head != (&(dev)->mode_config.fb_list); \
2683 fb = list_next_entry(fb, head))
Daniel Vetter6295d602015-07-09 23:44:25 +02002684
Dave Airlief453ba02008-11-07 14:05:41 -08002685#endif /* __DRM_CRTC_H__ */