blob: e3c4d486e1af853a44422620be736823102c2a8a [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
48#define DRM_MODE_OBJECT_CRTC 0xcccccccc
49#define DRM_MODE_OBJECT_CONNECTOR 0xc0c0c0c0
50#define DRM_MODE_OBJECT_ENCODER 0xe0e0e0e0
51#define DRM_MODE_OBJECT_MODE 0xdededede
52#define DRM_MODE_OBJECT_PROPERTY 0xb0b0b0b0
53#define DRM_MODE_OBJECT_FB 0xfbfbfbfb
54#define DRM_MODE_OBJECT_BLOB 0xbbbbbbbb
Jesse Barnes8cf5c912011-11-14 14:51:27 -080055#define DRM_MODE_OBJECT_PLANE 0xeeeeeeee
Rob Clark98f75de2014-05-30 11:37:03 -040056#define DRM_MODE_OBJECT_ANY 0
Dave Airlief453ba02008-11-07 14:05:41 -080057
58struct drm_mode_object {
59 uint32_t id;
60 uint32_t type;
Paulo Zanoni7e3bdf42012-05-15 18:09:01 -030061 struct drm_object_properties *properties;
62};
63
Paulo Zanonife456162012-06-12 11:27:01 -030064#define DRM_OBJECT_MAX_PROPERTY 24
Paulo Zanoni7e3bdf42012-05-15 18:09:01 -030065struct drm_object_properties {
Rob Clark88a48e22014-12-18 16:01:50 -050066 int count, atomic_count;
Rob Clarkb17cd752014-12-16 18:05:30 -050067 /* NOTE: if we ever start dynamically destroying properties (ie.
68 * not at drm_mode_config_cleanup() time), then we'd have to do
69 * a better job of detaching property from mode objects to avoid
70 * dangling property pointers:
71 */
72 struct drm_property *properties[DRM_OBJECT_MAX_PROPERTY];
Rob Clark22b8b132014-12-16 18:05:31 -050073 /* do not read/write values directly, but use drm_object_property_get_value()
74 * and drm_object_property_set_value():
75 */
Paulo Zanoni7e3bdf42012-05-15 18:09:01 -030076 uint64_t values[DRM_OBJECT_MAX_PROPERTY];
Dave Airlief453ba02008-11-07 14:05:41 -080077};
78
Rob Clarkebc44cf2012-09-12 22:22:31 -050079static inline int64_t U642I64(uint64_t val)
80{
81 return (int64_t)*((int64_t *)&val);
82}
83static inline uint64_t I642U64(int64_t val)
84{
85 return (uint64_t)*((uint64_t *)&val);
86}
87
Robert Feketed9c38242015-11-02 16:14:08 +010088/*
89 * Rotation property bits. DRM_ROTATE_<degrees> rotates the image by the
90 * specified amount in degrees in counter clockwise direction. DRM_REFLECT_X and
91 * DRM_REFLECT_Y reflects the image along the specified axis prior to rotation
92 */
Joonas Lahtinen62209072015-10-01 10:00:57 +030093#define DRM_ROTATE_MASK 0x0f
Ville Syrjälä06596962014-07-08 10:31:51 +053094#define DRM_ROTATE_0 0
95#define DRM_ROTATE_90 1
96#define DRM_ROTATE_180 2
97#define DRM_ROTATE_270 3
Joonas Lahtinen62209072015-10-01 10:00:57 +030098#define DRM_REFLECT_MASK (~DRM_ROTATE_MASK)
Ville Syrjälä06596962014-07-08 10:31:51 +053099#define DRM_REFLECT_X 4
100#define DRM_REFLECT_Y 5
101
Daniel Vetter55310002014-01-23 15:52:20 +0100102enum drm_connector_force {
103 DRM_FORCE_UNSPECIFIED,
104 DRM_FORCE_OFF,
105 DRM_FORCE_ON, /* force on analog part normally */
106 DRM_FORCE_ON_DIGITAL, /* for DVI-I use digital connector */
Dave Airlief453ba02008-11-07 14:05:41 -0800107};
108
Daniel Vetter55310002014-01-23 15:52:20 +0100109#include <drm/drm_modes.h>
Damien Lespiau4aa17cf2013-09-25 16:45:21 +0100110
Dave Airlief453ba02008-11-07 14:05:41 -0800111enum drm_connector_status {
112 connector_status_connected = 1,
113 connector_status_disconnected = 2,
114 connector_status_unknown = 3,
115};
116
117enum subpixel_order {
118 SubPixelUnknown = 0,
119 SubPixelHorizontalRGB,
120 SubPixelHorizontalBGR,
121 SubPixelVerticalRGB,
122 SubPixelVerticalBGR,
123 SubPixelNone,
124};
125
Jesse Barnesda05a5a72011-04-15 13:48:57 -0700126#define DRM_COLOR_FORMAT_RGB444 (1<<0)
127#define DRM_COLOR_FORMAT_YCRCB444 (1<<1)
128#define DRM_COLOR_FORMAT_YCRCB422 (1<<2)
Dave Airlief453ba02008-11-07 14:05:41 -0800129/*
130 * Describes a given display (e.g. CRT or flat panel) and its limitations.
131 */
132struct drm_display_info {
133 char name[DRM_DISPLAY_INFO_LEN];
Adam Jacksonfb439642010-08-03 14:38:16 -0400134
Dave Airlief453ba02008-11-07 14:05:41 -0800135 /* Physical size */
136 unsigned int width_mm;
137 unsigned int height_mm;
138
Dave Airlief453ba02008-11-07 14:05:41 -0800139 /* Clock limits FIXME: storage format */
140 unsigned int min_vfreq, max_vfreq;
141 unsigned int min_hfreq, max_hfreq;
142 unsigned int pixel_clock;
Jesse Barnes3b112282011-04-15 12:49:23 -0700143 unsigned int bpc;
Dave Airlief453ba02008-11-07 14:05:41 -0800144
Dave Airlief453ba02008-11-07 14:05:41 -0800145 enum subpixel_order subpixel_order;
Jesse Barnesda05a5a72011-04-15 13:48:57 -0700146 u32 color_formats;
Dave Airlief453ba02008-11-07 14:05:41 -0800147
Boris Brezillonb5571e92014-07-22 12:09:10 +0200148 const u32 *bus_formats;
149 unsigned int num_bus_formats;
150
Mario Kleiner5d02626d2014-06-05 09:52:10 -0400151 /* Mask of supported hdmi deep color modes */
152 u8 edid_hdmi_dc_modes;
153
Jesse Barnesebec9a72011-08-03 09:22:54 -0700154 u8 cea_rev;
Dave Airlief453ba02008-11-07 14:05:41 -0800155};
156
Dave Airlie138f9eb2014-10-20 16:17:17 +1000157/* data corresponds to displayid vend/prod/serial */
158struct drm_tile_group {
159 struct kref refcount;
160 struct drm_device *dev;
161 int id;
162 u8 group_data[8];
163};
164
Daniel Vetterc6b0ca32015-12-04 09:46:01 +0100165/**
166 * struct drm_framebuffer_funcs - framebuffer hooks
167 */
Dave Airlief453ba02008-11-07 14:05:41 -0800168struct drm_framebuffer_funcs {
Daniel Vetterc6b0ca32015-12-04 09:46:01 +0100169 /**
170 * @destroy:
171 *
172 * Clean up framebuffer resources, specifically also unreference the
173 * backing storage. The core guarantees to call this function for every
174 * framebuffer successfully created by ->fb_create() in
Daniel Vetterd55f5322015-12-08 09:49:19 +0100175 * &drm_mode_config_funcs. Drivers must also call
176 * drm_framebuffer_cleanup() to release DRM core resources for this
177 * framebuffer.
Daniel Vetterc6b0ca32015-12-04 09:46:01 +0100178 */
Dave Airlief453ba02008-11-07 14:05:41 -0800179 void (*destroy)(struct drm_framebuffer *framebuffer);
Daniel Vetterc6b0ca32015-12-04 09:46:01 +0100180
181 /**
182 * @create_handle:
183 *
184 * Create a buffer handle in the driver-specific buffer manager (either
185 * GEM or TTM) valid for the passed-in struct &drm_file. This is used by
186 * the core to implement the GETFB IOCTL, which returns (for
187 * sufficiently priviledged user) also a native buffer handle. This can
188 * be used for seamless transitions between modesetting clients by
189 * copying the current screen contents to a private buffer and blending
190 * between that and the new contents.
191 *
Daniel Vetterd55f5322015-12-08 09:49:19 +0100192 * GEM based drivers should call drm_gem_handle_create() to create the
193 * handle.
194 *
Daniel Vetterc6b0ca32015-12-04 09:46:01 +0100195 * RETURNS:
196 *
197 * 0 on success or a negative error code on failure.
198 */
Dave Airlief453ba02008-11-07 14:05:41 -0800199 int (*create_handle)(struct drm_framebuffer *fb,
200 struct drm_file *file_priv,
201 unsigned int *handle);
Daniel Vetterc6b0ca32015-12-04 09:46:01 +0100202 /**
203 * @dirty:
Jakob Bornecrantz884840a2009-12-03 23:25:47 +0000204 *
Daniel Vetterc6b0ca32015-12-04 09:46:01 +0100205 * Optional callback for the dirty fb IOCTL.
Jakob Bornecrantz884840a2009-12-03 23:25:47 +0000206 *
Daniel Vetterc6b0ca32015-12-04 09:46:01 +0100207 * Userspace can notify the driver via this callback that an area of the
208 * framebuffer has changed and should be flushed to the display
209 * hardware. This can also be used internally, e.g. by the fbdev
210 * emulation, though that's not the case currently.
211 *
212 * See documentation in drm_mode.h for the struct drm_mode_fb_dirty_cmd
213 * for more information as all the semantics and arguments have a one to
214 * one mapping on this function.
215 *
216 * RETURNS:
217 *
218 * 0 on success or a negative error code on failure.
Jakob Bornecrantz884840a2009-12-03 23:25:47 +0000219 */
Thomas Hellstrom02b00162010-10-05 12:43:02 +0200220 int (*dirty)(struct drm_framebuffer *framebuffer,
221 struct drm_file *file_priv, unsigned flags,
Jakob Bornecrantz884840a2009-12-03 23:25:47 +0000222 unsigned color, struct drm_clip_rect *clips,
223 unsigned num_clips);
Dave Airlief453ba02008-11-07 14:05:41 -0800224};
225
226struct drm_framebuffer {
227 struct drm_device *dev;
Rob Clarkf7eff602012-09-05 21:48:38 +0000228 /*
229 * Note that the fb is refcounted for the benefit of driver internals,
230 * for example some hw, disabling a CRTC/plane is asynchronous, and
231 * scanout does not actually complete until the next vblank. So some
232 * cleanup (like releasing the reference(s) on the backing GEM bo(s))
233 * should be deferred. In cases like this, the driver would like to
234 * hold a ref to the fb even though it has already been removed from
235 * userspace perspective.
236 */
237 struct kref refcount;
Daniel Vetter4b096ac2012-12-10 21:19:18 +0100238 /*
239 * Place on the dev->mode_config.fb_list, access protected by
240 * dev->mode_config.fb_lock.
241 */
Dave Airlief453ba02008-11-07 14:05:41 -0800242 struct list_head head;
243 struct drm_mode_object base;
244 const struct drm_framebuffer_funcs *funcs;
Ville Syrjälä01f2c772011-12-20 00:06:49 +0200245 unsigned int pitches[4];
246 unsigned int offsets[4];
Rob Clarke3eb3252015-02-05 14:41:52 +0000247 uint64_t modifier[4];
Dave Airlief453ba02008-11-07 14:05:41 -0800248 unsigned int width;
249 unsigned int height;
250 /* depth can be 15 or 16 */
251 unsigned int depth;
252 int bits_per_pixel;
253 int flags;
Jesse Barnes308e5bc2011-11-14 14:51:28 -0800254 uint32_t pixel_format; /* fourcc format */
Dave Airlief453ba02008-11-07 14:05:41 -0800255 struct list_head filp_head;
256};
257
258struct drm_property_blob {
259 struct drm_mode_object base;
Daniel Stone6bcacf52015-04-20 19:22:55 +0100260 struct drm_device *dev;
261 struct kref refcount;
Daniel Stonee2f5d2e2015-05-22 13:34:51 +0100262 struct list_head head_global;
263 struct list_head head_file;
Thierry Redingecbbe592014-05-13 11:36:13 +0200264 size_t length;
Ville Syrjäläd63f5e62012-03-13 12:35:49 +0200265 unsigned char data[];
Dave Airlief453ba02008-11-07 14:05:41 -0800266};
267
268struct drm_property_enum {
269 uint64_t value;
270 struct list_head head;
271 char name[DRM_PROP_NAME_LEN];
272};
273
274struct drm_property {
275 struct list_head head;
276 struct drm_mode_object base;
277 uint32_t flags;
278 char name[DRM_PROP_NAME_LEN];
279 uint32_t num_values;
280 uint64_t *values;
Rob Clark98f75de2014-05-30 11:37:03 -0400281 struct drm_device *dev;
Dave Airlief453ba02008-11-07 14:05:41 -0800282
Daniel Vetter3758b342014-11-19 18:38:10 +0100283 struct list_head enum_list;
Dave Airlief453ba02008-11-07 14:05:41 -0800284};
285
286struct drm_crtc;
287struct drm_connector;
288struct drm_encoder;
Kristian Høgsbergd91d8a32009-11-17 12:43:55 -0500289struct drm_pending_vblank_event;
Jesse Barnes8cf5c912011-11-14 14:51:27 -0800290struct drm_plane;
Sean Paul3b336ec2013-08-14 16:47:37 -0400291struct drm_bridge;
Daniel Vetter144ecb92014-10-27 20:28:44 +0100292struct drm_atomic_state;
293
Daniel Vetter4490d4c2015-12-04 09:45:45 +0100294struct drm_crtc_helper_funcs;
295struct drm_encoder_helper_funcs;
296struct drm_connector_helper_funcs;
297struct drm_plane_helper_funcs;
298
Daniel Vetter144ecb92014-10-27 20:28:44 +0100299/**
Daniel Vettercc4ceb42014-07-25 21:30:38 +0200300 * struct drm_crtc_state - mutable CRTC state
Daniel Vetter07cc0ef2014-11-27 15:49:39 +0100301 * @crtc: backpointer to the CRTC
Daniel Vetter144ecb92014-10-27 20:28:44 +0100302 * @enable: whether the CRTC should be enabled, gates all other state
Daniel Vetterd9b13622014-11-26 16:57:41 +0100303 * @active: whether the CRTC is actively displaying (used for DPMS)
Maarten Lankhorstfc596662015-07-21 13:28:57 +0200304 * @planes_changed: planes on this crtc are updated
305 * @mode_changed: crtc_state->mode or crtc_state->enable has been changed
306 * @active_changed: crtc_state->active has been toggled.
307 * @connectors_changed: connectors to this crtc have been updated
Rob Clark6ddd3882014-11-21 15:28:31 -0500308 * @plane_mask: bitmask of (1 << drm_plane_index(plane)) of attached planes
Maarten Lankhorst4cd9fa52016-01-04 12:53:18 +0100309 * @connector_mask: bitmask of (1 << drm_connector_index(connector)) of attached connectors
Daniel Vetter623369e2014-09-16 17:50:47 +0200310 * @last_vblank_count: for helpers and drivers to capture the vblank of the
311 * update to ensure framebuffer cleanup isn't done too early
Daniel Vetter2f324b42014-10-29 11:13:47 +0100312 * @adjusted_mode: for use by helpers and drivers to compute adjusted mode timings
Daniel Vetter144ecb92014-10-27 20:28:44 +0100313 * @mode: current mode timings
314 * @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;
Daniel Vetter623369e2014-09-16 17:50:47 +0200335
Rob Clark6ddd3882014-11-21 15:28:31 -0500336 /* attached planes bitmask:
337 * WARNING: transitional helpers do not maintain plane_mask so
338 * drivers not converted over to atomic helpers should not rely
339 * on plane_mask being accurate!
340 */
341 u32 plane_mask;
342
Maarten Lankhorst4cd9fa52016-01-04 12:53:18 +0100343 u32 connector_mask;
344
Daniel Vetter623369e2014-09-16 17:50:47 +0200345 /* last_vblank_count: for vblank waits before cleanup */
346 u32 last_vblank_count;
Daniel Vetterc2fcd272014-11-05 00:14:14 +0100347
Daniel Vetter2f324b42014-10-29 11:13:47 +0100348 /* adjusted_mode: for use by helpers and drivers */
349 struct drm_display_mode adjusted_mode;
350
Daniel Vetter144ecb92014-10-27 20:28:44 +0100351 struct drm_display_mode mode;
352
Daniel Stone99cf4a22015-05-25 19:11:51 +0100353 /* blob property to expose current mode to atomic userspace */
354 struct drm_property_blob *mode_blob;
355
Daniel Vetter144ecb92014-10-27 20:28:44 +0100356 struct drm_pending_vblank_event *event;
357
358 struct drm_atomic_state *state;
359};
Dave Airlief453ba02008-11-07 14:05:41 -0800360
361/**
Daniel Vetter3bf04012014-10-27 16:54:27 +0100362 * struct drm_crtc_funcs - control CRTCs for a given device
Dave Airlief453ba02008-11-07 14:05:41 -0800363 *
364 * The drm_crtc_funcs structure is the central CRTC management structure
365 * in the DRM. Each CRTC controls one or more connectors (note that the name
366 * CRTC is simply historical, a CRTC may control LVDS, VGA, DVI, TV out, etc.
367 * connectors, not just CRTs).
368 *
369 * Each driver is responsible for filling out this structure at startup time,
370 * in addition to providing other modesetting features, like i2c and DDC
371 * bus accessors.
372 */
373struct drm_crtc_funcs {
Daniel Vetter88548632015-12-04 09:45:48 +0100374 /**
375 * @reset:
376 *
377 * Reset CRTC hardware and software state to off. This function isn't
378 * called by the core directly, only through drm_mode_config_reset().
379 * It's not a helper hook only for historical reasons.
380 *
381 * Atomic drivers can use drm_atomic_helper_crtc_reset() to reset
382 * atomic state using this hook.
383 */
Chris Wilsoneb033552011-01-24 15:11:08 +0000384 void (*reset)(struct drm_crtc *crtc);
Dave Airlief453ba02008-11-07 14:05:41 -0800385
Daniel Vetterf6da8c62015-12-04 09:46:00 +0100386 /**
387 * @cursor_set:
388 *
389 * Update the cursor image. The cursor position is relative to the CRTC
390 * and can be partially or fully outside of the visible area.
391 *
392 * Note that contrary to all other KMS functions the legacy cursor entry
393 * points don't take a framebuffer object, but instead take directly a
394 * raw buffer object id from the driver's buffer manager (which is
395 * either GEM or TTM for current drivers).
396 *
397 * This entry point is deprecated, drivers should instead implement
398 * universal plane support and register a proper cursor plane using
399 * drm_crtc_init_with_planes().
400 *
401 * This callback is optional
402 *
403 * RETURNS:
404 *
405 * 0 on success or a negative error code on failure.
406 */
Dave Airlief453ba02008-11-07 14:05:41 -0800407 int (*cursor_set)(struct drm_crtc *crtc, struct drm_file *file_priv,
408 uint32_t handle, uint32_t width, uint32_t height);
Daniel Vetterf6da8c62015-12-04 09:46:00 +0100409
410 /**
411 * @cursor_set2:
412 *
413 * Update the cursor image, including hotspot information. The hotspot
414 * must not affect the cursor position in CRTC coordinates, but is only
415 * meant as a hint for virtualized display hardware to coordinate the
416 * guests and hosts cursor position. The cursor hotspot is relative to
417 * the cursor image. Otherwise this works exactly like @cursor_set.
418 *
419 * This entry point is deprecated, drivers should instead implement
420 * universal plane support and register a proper cursor plane using
421 * drm_crtc_init_with_planes().
422 *
423 * This callback is optional.
424 *
425 * RETURNS:
426 *
427 * 0 on success or a negative error code on failure.
428 */
Dave Airlie4c813d42013-06-20 11:48:52 +1000429 int (*cursor_set2)(struct drm_crtc *crtc, struct drm_file *file_priv,
430 uint32_t handle, uint32_t width, uint32_t height,
431 int32_t hot_x, int32_t hot_y);
Daniel Vetterf6da8c62015-12-04 09:46:00 +0100432
433 /**
434 * @cursor_move:
435 *
436 * Update the cursor position. The cursor does not need to be visible
437 * when this hook is called.
438 *
439 * This entry point is deprecated, drivers should instead implement
440 * universal plane support and register a proper cursor plane using
441 * drm_crtc_init_with_planes().
442 *
443 * This callback is optional.
444 *
445 * RETURNS:
446 *
447 * 0 on success or a negative error code on failure.
448 */
Dave Airlief453ba02008-11-07 14:05:41 -0800449 int (*cursor_move)(struct drm_crtc *crtc, int x, int y);
450
Daniel Vetterf6da8c62015-12-04 09:46:00 +0100451 /**
452 * @gamma_set:
453 *
454 * Set gamma on the CRTC.
455 *
456 * This callback is optional.
457 *
458 * NOTE:
459 *
460 * Drivers that support gamma tables and also fbdev emulation through
461 * the provided helper library need to take care to fill out the gamma
462 * hooks for both. Currently there's a bit an unfortunate duplication
463 * going on, which should eventually be unified to just one set of
464 * hooks.
465 */
Dave Airlief453ba02008-11-07 14:05:41 -0800466 void (*gamma_set)(struct drm_crtc *crtc, u16 *r, u16 *g, u16 *b,
James Simmons72034252010-08-03 01:33:19 +0100467 uint32_t start, uint32_t size);
Daniel Vetter88548632015-12-04 09:45:48 +0100468
469 /**
470 * @destroy:
471 *
472 * Clean up plane resources. This is only called at driver unload time
473 * through drm_mode_config_cleanup() since a CRTC cannot be hotplugged
474 * in DRM.
475 */
Dave Airlief453ba02008-11-07 14:05:41 -0800476 void (*destroy)(struct drm_crtc *crtc);
477
Daniel Vetterf6da8c62015-12-04 09:46:00 +0100478 /**
479 * @set_config:
480 *
481 * This is the main legacy entry point to change the modeset state on a
482 * CRTC. All the details of the desired configuration are passed in a
483 * struct &drm_mode_set - see there for details.
484 *
485 * Drivers implementing atomic modeset should use
486 * drm_atomic_helper_set_config() to implement this hook.
487 *
488 * RETURNS:
489 *
490 * 0 on success or a negative error code on failure.
491 */
Dave Airlief453ba02008-11-07 14:05:41 -0800492 int (*set_config)(struct drm_mode_set *set);
Kristian Høgsbergd91d8a32009-11-17 12:43:55 -0500493
Daniel Vetterf6da8c62015-12-04 09:46:00 +0100494 /**
495 * @page_flip:
496 *
497 * Legacy entry point to schedule a flip to the given framebuffer.
498 *
499 * Page flipping is a synchronization mechanism that replaces the frame
500 * buffer being scanned out by the CRTC with a new frame buffer during
501 * vertical blanking, avoiding tearing (except when requested otherwise
502 * through the DRM_MODE_PAGE_FLIP_ASYNC flag). When an application
503 * requests a page flip the DRM core verifies that the new frame buffer
504 * is large enough to be scanned out by the CRTC in the currently
505 * configured mode and then calls the CRTC ->page_flip() operation with a
506 * pointer to the new frame buffer.
507 *
508 * The driver must wait for any pending rendering to the new framebuffer
509 * to complete before executing the flip. It should also wait for any
510 * pending rendering from other drivers if the underlying buffer is a
511 * shared dma-buf.
512 *
513 * An application can request to be notified when the page flip has
514 * completed. The drm core will supply a struct &drm_event in the event
515 * parameter in this case. This can be handled by the
516 * drm_crtc_send_vblank_event() function, which the driver should call on
517 * the provided event upon completion of the flip. Note that if
518 * the driver supports vblank signalling and timestamping the vblank
519 * counters and timestamps must agree with the ones returned from page
520 * flip events. With the current vblank helper infrastructure this can
521 * be achieved by holding a vblank reference while the page flip is
522 * pending, acquired through drm_crtc_vblank_get() and released with
523 * drm_crtc_vblank_put(). Drivers are free to implement their own vblank
524 * counter and timestamp tracking though, e.g. if they have accurate
525 * timestamp registers in hardware.
526 *
527 * FIXME:
528 *
529 * Up to that point drivers need to manage events themselves and can use
530 * even->base.list freely for that. Specifically they need to ensure
531 * that they don't send out page flip (or vblank) events for which the
532 * corresponding drm file has been closed already. The drm core
533 * unfortunately does not (yet) take care of that. Therefore drivers
534 * currently must clean up and release pending events in their
535 * ->preclose driver function.
536 *
537 * This callback is optional.
538 *
539 * NOTE:
540 *
541 * Very early versions of the KMS ABI mandated that the driver must
542 * block (but not reject) any rendering to the old framebuffer until the
543 * flip operation has completed and the old framebuffer is no longer
544 * visible. This requirement has been lifted, and userspace is instead
545 * expected to request delivery of an event and wait with recycling old
546 * buffers until such has been received.
547 *
548 * RETURNS:
549 *
550 * 0 on success or a negative error code on failure. Note that if a
551 * ->page_flip() operation is already pending the callback should return
552 * -EBUSY. Pageflips on a disabled CRTC (either by setting a NULL mode
553 * or just runtime disabled through DPMS respectively the new atomic
554 * "ACTIVE" state) should result in an -EINVAL error code.
Kristian Høgsbergd91d8a32009-11-17 12:43:55 -0500555 */
556 int (*page_flip)(struct drm_crtc *crtc,
557 struct drm_framebuffer *fb,
Keith Packarded8d1972013-07-22 18:49:58 -0700558 struct drm_pending_vblank_event *event,
559 uint32_t flags);
Paulo Zanonibffd9de02012-05-15 18:09:05 -0300560
Daniel Vetter88548632015-12-04 09:45:48 +0100561 /**
562 * @set_property:
563 *
564 * This is the legacy entry point to update a property attached to the
565 * CRTC.
566 *
567 * Drivers implementing atomic modeset should use
568 * drm_atomic_helper_crtc_set_property() to implement this hook.
569 *
570 * This callback is optional if the driver does not support any legacy
571 * driver-private properties.
572 *
573 * RETURNS:
574 *
575 * 0 on success or a negative error code on failure.
576 */
Paulo Zanonibffd9de02012-05-15 18:09:05 -0300577 int (*set_property)(struct drm_crtc *crtc,
578 struct drm_property *property, uint64_t val);
Daniel Vetter144ecb92014-10-27 20:28:44 +0100579
Daniel Vetter88548632015-12-04 09:45:48 +0100580 /**
581 * @atomic_duplicate_state:
582 *
583 * Duplicate the current atomic state for this CRTC and return it.
584 * The core and helpers gurantee that any atomic state duplicated with
585 * this hook and still owned by the caller (i.e. not transferred to the
586 * driver by calling ->atomic_commit() from struct
587 * &drm_mode_config_funcs) will be cleaned up by calling the
588 * @atomic_destroy_state hook in this structure.
589 *
590 * Atomic drivers which don't subclass struct &drm_crtc should use
591 * drm_atomic_helper_crtc_duplicate_state(). Drivers that subclass the
592 * state structure to extend it with driver-private state should use
593 * __drm_atomic_helper_crtc_duplicate_state() to make sure shared state is
594 * duplicated in a consistent fashion across drivers.
595 *
596 * It is an error to call this hook before crtc->state has been
597 * initialized correctly.
598 *
599 * NOTE:
600 *
601 * If the duplicate state references refcounted resources this hook must
602 * acquire a reference for each of them. The driver must release these
603 * references again in @atomic_destroy_state.
604 *
605 * RETURNS:
606 *
607 * Duplicated atomic state or NULL when the allocation failed.
608 */
Daniel Vetter144ecb92014-10-27 20:28:44 +0100609 struct drm_crtc_state *(*atomic_duplicate_state)(struct drm_crtc *crtc);
Daniel Vetter88548632015-12-04 09:45:48 +0100610
611 /**
612 * @atomic_destroy_state:
613 *
614 * Destroy a state duplicated with @atomic_duplicate_state and release
615 * or unreference all resources it references
616 */
Daniel Vetter144ecb92014-10-27 20:28:44 +0100617 void (*atomic_destroy_state)(struct drm_crtc *crtc,
Daniel Vettercc4ceb42014-07-25 21:30:38 +0200618 struct drm_crtc_state *state);
Daniel Vetter88548632015-12-04 09:45:48 +0100619
620 /**
621 * @atomic_set_property:
622 *
623 * Decode a driver-private property value and store the decoded value
624 * into the passed-in state structure. Since the atomic core decodes all
625 * standardized properties (even for extensions beyond the core set of
626 * properties which might not be implemented by all drivers) this
627 * requires drivers to subclass the state structure.
628 *
629 * Such driver-private properties should really only be implemented for
630 * truly hardware/vendor specific state. Instead it is preferred to
631 * standardize atomic extension and decode the properties used to expose
632 * such an extension in the core.
633 *
634 * Do not call this function directly, use
635 * drm_atomic_crtc_set_property() instead.
636 *
637 * This callback is optional if the driver does not support any
638 * driver-private atomic properties.
639 *
640 * NOTE:
641 *
642 * This function is called in the state assembly phase of atomic
643 * modesets, which can be aborted for any reason (including on
644 * userspace's request to just check whether a configuration would be
645 * possible). Drivers MUST NOT touch any persistent state (hardware or
646 * software) or data structures except the passed in @state parameter.
647 *
648 * Also since userspace controls in which order properties are set this
649 * function must not do any input validation (since the state update is
650 * incomplete and hence likely inconsistent). Instead any such input
651 * validation must be done in the various atomic_check callbacks.
652 *
653 * RETURNS:
654 *
655 * 0 if the property has been found, -EINVAL if the property isn't
656 * implemented by the driver (which should never happen, the core only
657 * asks for properties attached to this CRTC). No other validation is
658 * allowed by the driver. The core already checks that the property
659 * value is within the range (integer, valid enum value, ...) the driver
660 * set when registering the property.
661 */
Daniel Vetter144ecb92014-10-27 20:28:44 +0100662 int (*atomic_set_property)(struct drm_crtc *crtc,
663 struct drm_crtc_state *state,
664 struct drm_property *property,
665 uint64_t val);
Daniel Vetter88548632015-12-04 09:45:48 +0100666 /**
667 * @atomic_get_property:
668 *
669 * Reads out the decoded driver-private property. This is used to
Daniel Vetterc6b0ca32015-12-04 09:46:01 +0100670 * implement the GETCRTC IOCTL.
Daniel Vetter88548632015-12-04 09:45:48 +0100671 *
672 * Do not call this function directly, use
673 * drm_atomic_crtc_get_property() instead.
674 *
675 * This callback is optional if the driver does not support any
676 * driver-private atomic properties.
677 *
678 * RETURNS:
679 *
680 * 0 on success, -EINVAL if the property isn't implemented by the
681 * driver (which should never happen, the core only asks for
682 * properties attached to this CRTC).
683 */
Rob Clarkac9c9252014-12-18 16:01:47 -0500684 int (*atomic_get_property)(struct drm_crtc *crtc,
685 const struct drm_crtc_state *state,
686 struct drm_property *property,
687 uint64_t *val);
Dave Airlief453ba02008-11-07 14:05:41 -0800688};
689
690/**
Daniel Vetter3bf04012014-10-27 16:54:27 +0100691 * struct drm_crtc - central CRTC control structure
Jesse Barnes77491632011-11-07 12:03:14 -0800692 * @dev: parent DRM device
Daniel Vetter2c0c33d2014-10-27 20:19:38 +0100693 * @port: OF node used by drm_of_find_possible_crtcs()
Jesse Barnes77491632011-11-07 12:03:14 -0800694 * @head: list management
Rob Clark51fd3712013-11-19 12:10:12 -0500695 * @mutex: per-CRTC locking
Jesse Barnes77491632011-11-07 12:03:14 -0800696 * @base: base KMS object for ID tracking etc.
Matt Ropere13161a2014-04-01 15:22:38 -0700697 * @primary: primary plane for this CRTC
698 * @cursor: cursor plane for this CRTC
Daniel Vetter2c0c33d2014-10-27 20:19:38 +0100699 * @cursor_x: current x position of the cursor, used for universal cursor planes
700 * @cursor_y: current y position of the cursor, used for universal cursor planes
Dave Airlief453ba02008-11-07 14:05:41 -0800701 * @enabled: is this CRTC enabled?
Jesse Barnes77491632011-11-07 12:03:14 -0800702 * @mode: current mode timings
703 * @hwmode: mode timings as programmed to hw regs
Dave Airlief453ba02008-11-07 14:05:41 -0800704 * @x: x position on screen
705 * @y: y position on screen
Dave Airlief453ba02008-11-07 14:05:41 -0800706 * @funcs: CRTC control functions
Jesse Barnes77491632011-11-07 12:03:14 -0800707 * @gamma_size: size of gamma ramp
708 * @gamma_store: gamma ramp values
Jesse Barnes77491632011-11-07 12:03:14 -0800709 * @helper_private: mid-layer private data
Paulo Zanonibffd9de02012-05-15 18:09:05 -0300710 * @properties: property tracking for this CRTC
Daniel Vetter144ecb92014-10-27 20:28:44 +0100711 * @state: current atomic state for this CRTC
Daniel Vetter2c0c33d2014-10-27 20:19:38 +0100712 * @acquire_ctx: per-CRTC implicit acquire context used by atomic drivers for
Daniel Vetterc6b0ca32015-12-04 09:46:01 +0100713 * legacy IOCTLs
Dave Airlief453ba02008-11-07 14:05:41 -0800714 *
715 * Each CRTC may have one or more connectors associated with it. This structure
716 * allows the CRTC to be controlled.
717 */
718struct drm_crtc {
719 struct drm_device *dev;
Russell King7e435aa2014-06-15 11:07:12 +0100720 struct device_node *port;
Dave Airlief453ba02008-11-07 14:05:41 -0800721 struct list_head head;
722
Ville Syrjäläfa3ab4c2015-12-08 18:41:53 +0200723 char *name;
724
Daniel Vetter3bf04012014-10-27 16:54:27 +0100725 /*
Daniel Vetter29494c12012-12-02 02:18:25 +0100726 * crtc mutex
727 *
728 * This provides a read lock for the overall crtc state (mode, dpms
729 * state, ...) and a write lock for everything which can be update
730 * without a full modeset (fb, cursor data, ...)
731 */
Rob Clark51fd3712013-11-19 12:10:12 -0500732 struct drm_modeset_lock mutex;
Daniel Vetter29494c12012-12-02 02:18:25 +0100733
Dave Airlief453ba02008-11-07 14:05:41 -0800734 struct drm_mode_object base;
735
Matt Ropere13161a2014-04-01 15:22:38 -0700736 /* primary and cursor planes for CRTC */
737 struct drm_plane *primary;
738 struct drm_plane *cursor;
739
Matt Roper161d0dc2014-06-10 08:28:10 -0700740 /* position of cursor plane on crtc */
741 int cursor_x;
742 int cursor_y;
743
Dave Airlief453ba02008-11-07 14:05:41 -0800744 bool enabled;
745
Mario Kleiner27641c32010-10-23 04:20:23 +0200746 /* Requested mode from modesetting. */
Dave Airlief453ba02008-11-07 14:05:41 -0800747 struct drm_display_mode mode;
748
Mario Kleiner27641c32010-10-23 04:20:23 +0200749 /* Programmed mode in hw, after adjustments for encoders,
750 * crtc, panel scaling etc. Needed for timestamping etc.
751 */
752 struct drm_display_mode hwmode;
753
Dave Airlief453ba02008-11-07 14:05:41 -0800754 int x, y;
Dave Airlief453ba02008-11-07 14:05:41 -0800755 const struct drm_crtc_funcs *funcs;
756
757 /* CRTC gamma size for reporting to userspace */
758 uint32_t gamma_size;
759 uint16_t *gamma_store;
760
761 /* if you are using the helper */
Daniel Vetter4490d4c2015-12-04 09:45:45 +0100762 const struct drm_crtc_helper_funcs *helper_private;
Paulo Zanonibffd9de02012-05-15 18:09:05 -0300763
764 struct drm_object_properties properties;
Daniel Vetterd059f652014-07-25 18:07:40 +0200765
Daniel Vetter144ecb92014-10-27 20:28:44 +0100766 struct drm_crtc_state *state;
767
Daniel Vetterd059f652014-07-25 18:07:40 +0200768 /*
Daniel Vetterc6b0ca32015-12-04 09:46:01 +0100769 * For legacy crtc IOCTLs so that atomic drivers can get at the locking
Daniel Vetterd059f652014-07-25 18:07:40 +0200770 * acquire context.
771 */
772 struct drm_modeset_acquire_ctx *acquire_ctx;
Dave Airlief453ba02008-11-07 14:05:41 -0800773};
774
Daniel Vetter144ecb92014-10-27 20:28:44 +0100775/**
776 * struct drm_connector_state - mutable connector state
Daniel Vetter07cc0ef2014-11-27 15:49:39 +0100777 * @connector: backpointer to the connector
Daniel Vettercc4ceb42014-07-25 21:30:38 +0200778 * @crtc: CRTC to connect connector to, NULL if disabled
Daniel Vetter623369e2014-09-16 17:50:47 +0200779 * @best_encoder: can be used by helpers and drivers to select the encoder
Daniel Vetter144ecb92014-10-27 20:28:44 +0100780 * @state: backpointer to global drm_atomic_state
781 */
782struct drm_connector_state {
Daniel Vetter07cc0ef2014-11-27 15:49:39 +0100783 struct drm_connector *connector;
784
Rob Clark6ddd3882014-11-21 15:28:31 -0500785 struct drm_crtc *crtc; /* do not write directly, use drm_atomic_set_crtc_for_connector() */
Daniel Vetter144ecb92014-10-27 20:28:44 +0100786
Daniel Vetter623369e2014-09-16 17:50:47 +0200787 struct drm_encoder *best_encoder;
788
Daniel Vetter144ecb92014-10-27 20:28:44 +0100789 struct drm_atomic_state *state;
790};
Dave Airlief453ba02008-11-07 14:05:41 -0800791
792/**
Daniel Vetter3bf04012014-10-27 16:54:27 +0100793 * struct drm_connector_funcs - control connectors on a given device
Daniel Vetter144ecb92014-10-27 20:28:44 +0100794 *
Dave Airlief453ba02008-11-07 14:05:41 -0800795 * Each CRTC may have one or more connectors attached to it. The functions
796 * below allow the core DRM code to control connectors, enumerate available modes,
797 * etc.
798 */
799struct drm_connector_funcs {
Daniel Vetter6fe14ac2015-12-04 09:45:58 +0100800 /**
801 * @dpms:
802 *
803 * Legacy entry point to set the per-connector DPMS state. Legacy DPMS
804 * is exposed as a standard property on the connector, but diverted to
805 * this callback in the drm core. Note that atomic drivers don't
806 * implement the 4 level DPMS support on the connector any more, but
807 * instead only have an on/off "ACTIVE" property on the CRTC object.
808 *
809 * Drivers implementing atomic modeset should use
810 * drm_atomic_helper_connector_dpms() to implement this hook.
811 *
812 * RETURNS:
813 *
814 * 0 on success or a negative error code on failure.
815 */
Maarten Lankhorst9a69a9a2015-07-21 11:34:55 +0200816 int (*dpms)(struct drm_connector *connector, int mode);
Daniel Vetter88548632015-12-04 09:45:48 +0100817
818 /**
819 * @reset:
820 *
821 * Reset connector hardware and software state to off. This function isn't
822 * called by the core directly, only through drm_mode_config_reset().
823 * It's not a helper hook only for historical reasons.
824 *
825 * Atomic drivers can use drm_atomic_helper_connector_reset() to reset
826 * atomic state using this hook.
827 */
Chris Wilsoneb033552011-01-24 15:11:08 +0000828 void (*reset)(struct drm_connector *connector);
Chris Wilson930a9e22010-09-14 11:07:23 +0100829
Daniel Vetter6fe14ac2015-12-04 09:45:58 +0100830 /**
831 * @detect:
832 *
833 * Check to see if anything is attached to the connector. The parameter
834 * force is set to false whilst polling, true when checking the
835 * connector due to a user request. force can be used by the driver to
836 * avoid expensive, destructive operations during automated probing.
837 *
838 * FIXME:
839 *
840 * Note that this hook is only called by the probe helper. It's not in
841 * the helper library vtable purely for historical reasons. The only DRM
842 * core entry point to probe connector state is @fill_modes.
843 *
844 * RETURNS:
845 *
846 * drm_connector_status indicating the connector's status.
Chris Wilson930a9e22010-09-14 11:07:23 +0100847 */
Chris Wilson7b334fc2010-09-09 23:51:02 +0100848 enum drm_connector_status (*detect)(struct drm_connector *connector,
Chris Wilson930a9e22010-09-14 11:07:23 +0100849 bool force);
Daniel Vetter6fe14ac2015-12-04 09:45:58 +0100850
851 /**
852 * @force:
853 *
854 * This function is called to update internal encoder state when the
855 * connector is forced to a certain state by userspace, either through
856 * the sysfs interfaces or on the kernel cmdline. In that case the
857 * @detect callback isn't called.
858 *
859 * FIXME:
860 *
861 * Note that this hook is only called by the probe helper. It's not in
862 * the helper library vtable purely for historical reasons. The only DRM
863 * core entry point to probe connector state is @fill_modes.
864 */
865 void (*force)(struct drm_connector *connector);
866
867 /**
868 * @fill_modes:
869 *
870 * Entry point for output detection and basic mode validation. The
871 * driver should reprobe the output if needed (e.g. when hotplug
872 * handling is unreliable), add all detected modes to connector->modes
873 * and filter out any the device can't support in any configuration. It
874 * also needs to filter out any modes wider or higher than the
875 * parameters max_width and max_height indicate.
876 *
877 * The drivers must also prune any modes no longer valid from
878 * connector->modes. Furthermore it must update connector->status and
879 * connector->edid. If no EDID has been received for this output
880 * connector->edid must be NULL.
881 *
882 * Drivers using the probe helpers should use
883 * drm_helper_probe_single_connector_modes() or
884 * drm_helper_probe_single_connector_modes_nomerge() to implement this
885 * function.
886 *
887 * RETURNS:
888 *
889 * The number of modes detected and filled into connector->modes.
890 */
Jesse Barnes40a518d2009-01-12 12:05:32 -0800891 int (*fill_modes)(struct drm_connector *connector, uint32_t max_width, uint32_t max_height);
Daniel Vetter88548632015-12-04 09:45:48 +0100892
893 /**
894 * @set_property:
895 *
896 * This is the legacy entry point to update a property attached to the
897 * connector.
898 *
899 * Drivers implementing atomic modeset should use
900 * drm_atomic_helper_connector_set_property() to implement this hook.
901 *
902 * This callback is optional if the driver does not support any legacy
903 * driver-private properties.
904 *
905 * RETURNS:
906 *
907 * 0 on success or a negative error code on failure.
908 */
Dave Airlief453ba02008-11-07 14:05:41 -0800909 int (*set_property)(struct drm_connector *connector, struct drm_property *property,
910 uint64_t val);
Daniel Vetter88548632015-12-04 09:45:48 +0100911
912 /**
913 * @destroy:
914 *
915 * Clean up connector resources. This is called at driver unload time
916 * through drm_mode_config_cleanup(). It can also be called at runtime
917 * when a connector is being hot-unplugged for drivers that support
918 * connector hotplugging (e.g. DisplayPort MST).
919 */
Dave Airlief453ba02008-11-07 14:05:41 -0800920 void (*destroy)(struct drm_connector *connector);
Daniel Vetter144ecb92014-10-27 20:28:44 +0100921
Daniel Vetter88548632015-12-04 09:45:48 +0100922 /**
923 * @atomic_duplicate_state:
924 *
925 * Duplicate the current atomic state for this connector and return it.
926 * The core and helpers gurantee that any atomic state duplicated with
927 * this hook and still owned by the caller (i.e. not transferred to the
928 * driver by calling ->atomic_commit() from struct
929 * &drm_mode_config_funcs) will be cleaned up by calling the
930 * @atomic_destroy_state hook in this structure.
931 *
932 * Atomic drivers which don't subclass struct &drm_connector_state should use
933 * drm_atomic_helper_connector_duplicate_state(). Drivers that subclass the
934 * state structure to extend it with driver-private state should use
935 * __drm_atomic_helper_connector_duplicate_state() to make sure shared state is
936 * duplicated in a consistent fashion across drivers.
937 *
938 * It is an error to call this hook before connector->state has been
939 * initialized correctly.
940 *
941 * NOTE:
942 *
943 * If the duplicate state references refcounted resources this hook must
944 * acquire a reference for each of them. The driver must release these
945 * references again in @atomic_destroy_state.
946 *
947 * RETURNS:
948 *
949 * Duplicated atomic state or NULL when the allocation failed.
950 */
Daniel Vetter144ecb92014-10-27 20:28:44 +0100951 struct drm_connector_state *(*atomic_duplicate_state)(struct drm_connector *connector);
Daniel Vetter88548632015-12-04 09:45:48 +0100952
953 /**
954 * @atomic_destroy_state:
955 *
956 * Destroy a state duplicated with @atomic_duplicate_state and release
957 * or unreference all resources it references
958 */
Daniel Vetter144ecb92014-10-27 20:28:44 +0100959 void (*atomic_destroy_state)(struct drm_connector *connector,
Daniel Vettercc4ceb42014-07-25 21:30:38 +0200960 struct drm_connector_state *state);
Daniel Vetter88548632015-12-04 09:45:48 +0100961
962 /**
963 * @atomic_set_property:
964 *
965 * Decode a driver-private property value and store the decoded value
966 * into the passed-in state structure. Since the atomic core decodes all
967 * standardized properties (even for extensions beyond the core set of
968 * properties which might not be implemented by all drivers) this
969 * requires drivers to subclass the state structure.
970 *
971 * Such driver-private properties should really only be implemented for
972 * truly hardware/vendor specific state. Instead it is preferred to
973 * standardize atomic extension and decode the properties used to expose
974 * such an extension in the core.
975 *
976 * Do not call this function directly, use
977 * drm_atomic_connector_set_property() instead.
978 *
979 * This callback is optional if the driver does not support any
980 * driver-private atomic properties.
981 *
982 * NOTE:
983 *
984 * This function is called in the state assembly phase of atomic
985 * modesets, which can be aborted for any reason (including on
986 * userspace's request to just check whether a configuration would be
987 * possible). Drivers MUST NOT touch any persistent state (hardware or
988 * software) or data structures except the passed in @state parameter.
989 *
990 * Also since userspace controls in which order properties are set this
991 * function must not do any input validation (since the state update is
992 * incomplete and hence likely inconsistent). Instead any such input
993 * validation must be done in the various atomic_check callbacks.
994 *
995 * RETURNS:
996 *
997 * 0 if the property has been found, -EINVAL if the property isn't
998 * implemented by the driver (which shouldn't ever happen, the core only
999 * asks for properties attached to this connector). No other validation
1000 * is allowed by the driver. The core already checks that the property
1001 * value is within the range (integer, valid enum value, ...) the driver
1002 * set when registering the property.
1003 */
Daniel Vetter144ecb92014-10-27 20:28:44 +01001004 int (*atomic_set_property)(struct drm_connector *connector,
1005 struct drm_connector_state *state,
1006 struct drm_property *property,
1007 uint64_t val);
Daniel Vetter88548632015-12-04 09:45:48 +01001008
1009 /**
1010 * @atomic_get_property:
1011 *
1012 * Reads out the decoded driver-private property. This is used to
Daniel Vetterc6b0ca32015-12-04 09:46:01 +01001013 * implement the GETCONNECTOR IOCTL.
Daniel Vetter88548632015-12-04 09:45:48 +01001014 *
1015 * Do not call this function directly, use
1016 * drm_atomic_connector_get_property() instead.
1017 *
1018 * This callback is optional if the driver does not support any
1019 * driver-private atomic properties.
1020 *
1021 * RETURNS:
1022 *
1023 * 0 on success, -EINVAL if the property isn't implemented by the
1024 * driver (which shouldn't ever happen, the core only asks for
1025 * properties attached to this connector).
1026 */
Rob Clarkac9c9252014-12-18 16:01:47 -05001027 int (*atomic_get_property)(struct drm_connector *connector,
1028 const struct drm_connector_state *state,
1029 struct drm_property *property,
1030 uint64_t *val);
Dave Airlief453ba02008-11-07 14:05:41 -08001031};
1032
Jesse Barnes6c3db922011-11-07 12:03:16 -08001033/**
Daniel Vetter3bf04012014-10-27 16:54:27 +01001034 * struct drm_encoder_funcs - encoder controls
Jesse Barnes6c3db922011-11-07 12:03:16 -08001035 *
1036 * Encoders sit between CRTCs and connectors.
1037 */
Dave Airlief453ba02008-11-07 14:05:41 -08001038struct drm_encoder_funcs {
Daniel Vetter88548632015-12-04 09:45:48 +01001039 /**
1040 * @reset:
1041 *
1042 * Reset encoder hardware and software state to off. This function isn't
1043 * called by the core directly, only through drm_mode_config_reset().
1044 * It's not a helper hook only for historical reasons.
1045 */
Chris Wilsoneb033552011-01-24 15:11:08 +00001046 void (*reset)(struct drm_encoder *encoder);
Daniel Vetter88548632015-12-04 09:45:48 +01001047
1048 /**
1049 * @destroy:
1050 *
1051 * Clean up encoder resources. This is only called at driver unload time
1052 * through drm_mode_config_cleanup() since an encoder cannot be
1053 * hotplugged in DRM.
1054 */
Dave Airlief453ba02008-11-07 14:05:41 -08001055 void (*destroy)(struct drm_encoder *encoder);
1056};
1057
Ben Skeggsafe887d2012-01-12 16:00:57 +10001058#define DRM_CONNECTOR_MAX_ENCODER 3
Dave Airlief453ba02008-11-07 14:05:41 -08001059
1060/**
Daniel Vetter3bf04012014-10-27 16:54:27 +01001061 * struct drm_encoder - central DRM encoder structure
Jesse Barnesdb3e4492011-11-07 12:03:17 -08001062 * @dev: parent DRM device
1063 * @head: list management
1064 * @base: base KMS object
Jani Nikulae5748942014-05-14 16:58:20 +03001065 * @name: encoder name
Jesse Barnesdb3e4492011-11-07 12:03:17 -08001066 * @encoder_type: one of the %DRM_MODE_ENCODER_<foo> types in drm_mode.h
1067 * @possible_crtcs: bitmask of potential CRTC bindings
1068 * @possible_clones: bitmask of potential sibling encoders for cloning
1069 * @crtc: currently bound CRTC
Sean Paul3b336ec2013-08-14 16:47:37 -04001070 * @bridge: bridge associated to the encoder
Jesse Barnesdb3e4492011-11-07 12:03:17 -08001071 * @funcs: control functions
1072 * @helper_private: mid-layer private data
1073 *
1074 * CRTCs drive pixels to encoders, which convert them into signals
1075 * appropriate for a given connector or set of connectors.
Dave Airlief453ba02008-11-07 14:05:41 -08001076 */
1077struct drm_encoder {
1078 struct drm_device *dev;
1079 struct list_head head;
1080
1081 struct drm_mode_object base;
Jani Nikulae5748942014-05-14 16:58:20 +03001082 char *name;
Dave Airlief453ba02008-11-07 14:05:41 -08001083 int encoder_type;
1084 uint32_t possible_crtcs;
1085 uint32_t possible_clones;
1086
1087 struct drm_crtc *crtc;
Sean Paul3b336ec2013-08-14 16:47:37 -04001088 struct drm_bridge *bridge;
Dave Airlief453ba02008-11-07 14:05:41 -08001089 const struct drm_encoder_funcs *funcs;
Daniel Vetter4490d4c2015-12-04 09:45:45 +01001090 const struct drm_encoder_helper_funcs *helper_private;
Dave Airlief453ba02008-11-07 14:05:41 -08001091};
1092
Dave Airlieeb1f8e42010-05-07 06:42:51 +00001093/* should we poll this connector for connects and disconnects */
1094/* hot plug detectable */
1095#define DRM_CONNECTOR_POLL_HPD (1 << 0)
1096/* poll for connections */
1097#define DRM_CONNECTOR_POLL_CONNECT (1 << 1)
1098/* can cleanly poll for disconnections without flickering the screen */
1099/* DACs should rarely do this without a lot of testing */
1100#define DRM_CONNECTOR_POLL_DISCONNECT (1 << 2)
1101
Wu Fengguang76adaa342011-09-05 14:23:20 +08001102#define MAX_ELD_BYTES 128
1103
Dave Airlief453ba02008-11-07 14:05:41 -08001104/**
Daniel Vetter3bf04012014-10-27 16:54:27 +01001105 * struct drm_connector - central DRM connector control structure
Jesse Barnes72252542011-11-07 12:03:18 -08001106 * @dev: parent DRM device
1107 * @kdev: kernel device for sysfs attributes
1108 * @attr: sysfs attributes
1109 * @head: list management
1110 * @base: base KMS object
Jani Nikula2abdd312014-05-14 16:58:19 +03001111 * @name: connector name
Jesse Barnes72252542011-11-07 12:03:18 -08001112 * @connector_type: one of the %DRM_MODE_CONNECTOR_<foo> types from drm_mode.h
1113 * @connector_type_id: index into connector type enum
Dave Airlief453ba02008-11-07 14:05:41 -08001114 * @interlace_allowed: can this connector handle interlaced modes?
1115 * @doublescan_allowed: can this connector handle doublescan?
Daniel Vetter2c0c33d2014-10-27 20:19:38 +01001116 * @stereo_allowed: can this connector handle stereo modes?
Jesse Barnes72252542011-11-07 12:03:18 -08001117 * @modes: modes available on this connector (from fill_modes() + user)
1118 * @status: one of the drm_connector_status enums (connected, not, or unknown)
1119 * @probed_modes: list of modes derived directly from the display
1120 * @display_info: information about attached display (e.g. from EDID)
Dave Airlief453ba02008-11-07 14:05:41 -08001121 * @funcs: connector control functions
Jesse Barnes72252542011-11-07 12:03:18 -08001122 * @edid_blob_ptr: DRM property containing EDID if present
Paulo Zanoni7e3bdf42012-05-15 18:09:01 -03001123 * @properties: property tracking for this connector
Daniel Vetter2c0c33d2014-10-27 20:19:38 +01001124 * @path_blob_ptr: DRM blob property data for the DP MST path property
Jesse Barnes72252542011-11-07 12:03:18 -08001125 * @polled: a %DRM_CONNECTOR_POLL_<foo> value for core driven polling
1126 * @dpms: current dpms state
1127 * @helper_private: mid-layer private data
Daniel Vetter2c0c33d2014-10-27 20:19:38 +01001128 * @cmdline_mode: mode line parsed from the kernel cmdline for this connector
Jesse Barnes72252542011-11-07 12:03:18 -08001129 * @force: a %DRM_FORCE_<foo> state for forced mode sets
Daniel Vetter2c0c33d2014-10-27 20:19:38 +01001130 * @override_edid: has the EDID been overwritten through debugfs for testing?
Jesse Barnes72252542011-11-07 12:03:18 -08001131 * @encoder_ids: valid encoders for this connector
1132 * @encoder: encoder driving this connector, if any
1133 * @eld: EDID-like data, if present
1134 * @dvi_dual: dual link DVI, if found
1135 * @max_tmds_clock: max clock rate, if found
1136 * @latency_present: AV delay info from ELD, if found
1137 * @video_latency: video latency info from ELD, if found
1138 * @audio_latency: audio latency info from ELD, if found
1139 * @null_edid_counter: track sinks that give us all zeros for the EDID
Daniel Vetter2c0c33d2014-10-27 20:19:38 +01001140 * @bad_edid_counter: track sinks that give us an EDID with invalid checksum
Daniel Vetterac6f2e22015-05-08 16:15:41 +02001141 * @edid_corrupt: indicates whether the last read EDID was corrupt
Daniel Vetter2c0c33d2014-10-27 20:19:38 +01001142 * @debugfs_entry: debugfs directory for this connector
Daniel Vetter144ecb92014-10-27 20:28:44 +01001143 * @state: current atomic state for this connector
Dave Airlie40d9b042014-10-20 16:29:33 +10001144 * @has_tile: is this connector connected to a tiled monitor
1145 * @tile_group: tile group for the connected monitor
1146 * @tile_is_single_monitor: whether the tile is one monitor housing
1147 * @num_h_tile: number of horizontal tiles in the tile group
1148 * @num_v_tile: number of vertical tiles in the tile group
1149 * @tile_h_loc: horizontal location of this tile
1150 * @tile_v_loc: vertical location of this tile
1151 * @tile_h_size: horizontal size of this tile.
1152 * @tile_v_size: vertical size of this tile.
Dave Airlief453ba02008-11-07 14:05:41 -08001153 *
1154 * Each connector may be connected to one or more CRTCs, or may be clonable by
1155 * another connector if they can share a CRTC. Each connector also has a specific
1156 * position in the broader display (referred to as a 'screen' though it could
1157 * span multiple monitors).
1158 */
1159struct drm_connector {
1160 struct drm_device *dev;
Dave Airlie5bdebb12013-10-11 14:07:25 +10001161 struct device *kdev;
Dave Airlief453ba02008-11-07 14:05:41 -08001162 struct device_attribute *attr;
1163 struct list_head head;
1164
1165 struct drm_mode_object base;
1166
Jani Nikula2abdd312014-05-14 16:58:19 +03001167 char *name;
Dave Airlief453ba02008-11-07 14:05:41 -08001168 int connector_type;
1169 int connector_type_id;
1170 bool interlace_allowed;
1171 bool doublescan_allowed;
Damien Lespiau560a0672013-09-25 16:45:29 +01001172 bool stereo_allowed;
Dave Airlief453ba02008-11-07 14:05:41 -08001173 struct list_head modes; /* list of modes on this connector */
1174
Dave Airlief453ba02008-11-07 14:05:41 -08001175 enum drm_connector_status status;
1176
1177 /* these are modes added by probing with DDC or the BIOS */
1178 struct list_head probed_modes;
1179
1180 struct drm_display_info display_info;
1181 const struct drm_connector_funcs *funcs;
1182
Dave Airlief453ba02008-11-07 14:05:41 -08001183 struct drm_property_blob *edid_blob_ptr;
Paulo Zanoni7e3bdf42012-05-15 18:09:01 -03001184 struct drm_object_properties properties;
Dave Airlief453ba02008-11-07 14:05:41 -08001185
Dave Airlie43aba7e2014-06-05 14:01:31 +10001186 struct drm_property_blob *path_blob_ptr;
1187
Dave Airlie6f134d72014-10-20 16:30:50 +10001188 struct drm_property_blob *tile_blob_ptr;
1189
Dave Airlieeb1f8e42010-05-07 06:42:51 +00001190 uint8_t polled; /* DRM_CONNECTOR_POLL_* */
1191
Keith Packardc9fb15f2009-05-30 20:42:28 -07001192 /* requested DPMS state */
1193 int dpms;
1194
Daniel Vetter4490d4c2015-12-04 09:45:45 +01001195 const struct drm_connector_helper_funcs *helper_private;
Dave Airlief453ba02008-11-07 14:05:41 -08001196
Dave Airlied50ba252009-09-23 14:44:08 +10001197 /* forced on connector */
Chris Wilsoneaf99c72014-08-06 10:08:32 +02001198 struct drm_cmdline_mode cmdline_mode;
Dave Airlied50ba252009-09-23 14:44:08 +10001199 enum drm_connector_force force;
Thomas Wood4cf2b282014-06-18 17:52:33 +01001200 bool override_edid;
Dave Airlief453ba02008-11-07 14:05:41 -08001201 uint32_t encoder_ids[DRM_CONNECTOR_MAX_ENCODER];
Dave Airlief453ba02008-11-07 14:05:41 -08001202 struct drm_encoder *encoder; /* currently active encoder */
Dave Airlie4a9a8b72011-06-14 06:13:55 +00001203
Wu Fengguang76adaa342011-09-05 14:23:20 +08001204 /* EDID bits */
1205 uint8_t eld[MAX_ELD_BYTES];
1206 bool dvi_dual;
1207 int max_tmds_clock; /* in MHz */
1208 bool latency_present[2];
1209 int video_latency[2]; /* [0]: progressive, [1]: interlaced */
1210 int audio_latency[2];
Dave Airlie4a9a8b72011-06-14 06:13:55 +00001211 int null_edid_counter; /* needed to workaround some HW bugs where we get all 0s */
Jerome Glisse0b2443e2012-08-09 11:25:51 -04001212 unsigned bad_edid_counter;
Thomas Wood30f65702014-06-18 17:52:32 +01001213
Todd Previte6ba2bd32015-04-21 11:09:41 -07001214 /* Flag for raw EDID header corruption - used in Displayport
1215 * compliance testing - * Displayport Link CTS Core 1.2 rev1.1 4.2.2.6
1216 */
1217 bool edid_corrupt;
1218
Thomas Wood30f65702014-06-18 17:52:32 +01001219 struct dentry *debugfs_entry;
Daniel Vetter144ecb92014-10-27 20:28:44 +01001220
1221 struct drm_connector_state *state;
Dave Airlie40d9b042014-10-20 16:29:33 +10001222
1223 /* DisplayID bits */
1224 bool has_tile;
1225 struct drm_tile_group *tile_group;
1226 bool tile_is_single_monitor;
1227
1228 uint8_t num_h_tile, num_v_tile;
1229 uint8_t tile_h_loc, tile_v_loc;
1230 uint16_t tile_h_size, tile_v_size;
Dave Airlief453ba02008-11-07 14:05:41 -08001231};
1232
1233/**
Daniel Vetter144ecb92014-10-27 20:28:44 +01001234 * struct drm_plane_state - mutable plane state
Daniel Vetter07cc0ef2014-11-27 15:49:39 +01001235 * @plane: backpointer to the plane
Daniel Vetter144ecb92014-10-27 20:28:44 +01001236 * @crtc: currently bound CRTC, NULL if disabled
Daniel Vettercc4ceb42014-07-25 21:30:38 +02001237 * @fb: currently bound framebuffer
Daniel Vettere2330f02014-10-29 11:34:56 +01001238 * @fence: optional fence to wait for before scanning out @fb
Daniel Vetter144ecb92014-10-27 20:28:44 +01001239 * @crtc_x: left position of visible portion of plane on crtc
1240 * @crtc_y: upper position of visible portion of plane on crtc
1241 * @crtc_w: width of visible portion of plane on crtc
1242 * @crtc_h: height of visible portion of plane on crtc
1243 * @src_x: left position of visible portion of plane within
1244 * plane (in 16.16)
1245 * @src_y: upper position of visible portion of plane within
1246 * plane (in 16.16)
1247 * @src_w: width of visible portion of plane (in 16.16)
1248 * @src_h: height of visible portion of plane (in 16.16)
1249 * @state: backpointer to global drm_atomic_state
1250 */
1251struct drm_plane_state {
Daniel Vetter07cc0ef2014-11-27 15:49:39 +01001252 struct drm_plane *plane;
1253
Rob Clark6ddd3882014-11-21 15:28:31 -05001254 struct drm_crtc *crtc; /* do not write directly, use drm_atomic_set_crtc_for_plane() */
1255 struct drm_framebuffer *fb; /* do not write directly, use drm_atomic_set_fb_for_plane() */
Daniel Vettere2330f02014-10-29 11:34:56 +01001256 struct fence *fence;
Daniel Vetter144ecb92014-10-27 20:28:44 +01001257
1258 /* Signed dest location allows it to be partially off screen */
1259 int32_t crtc_x, crtc_y;
1260 uint32_t crtc_w, crtc_h;
1261
1262 /* Source values are 16.16 fixed point */
1263 uint32_t src_x, src_y;
1264 uint32_t src_h, src_w;
1265
Matt Roper1da30622015-01-21 16:35:40 -08001266 /* Plane rotation */
1267 unsigned int rotation;
1268
Daniel Vetter144ecb92014-10-27 20:28:44 +01001269 struct drm_atomic_state *state;
1270};
1271
1272
1273/**
Daniel Vetter3bf04012014-10-27 16:54:27 +01001274 * struct drm_plane_funcs - driver plane control functions
Jesse Barnes8cf5c912011-11-14 14:51:27 -08001275 */
1276struct drm_plane_funcs {
Daniel Vetter88548632015-12-04 09:45:48 +01001277 /**
1278 * @update_plane:
1279 *
1280 * This is the legacy entry point to enable and configure the plane for
1281 * the given CRTC and framebuffer. It is never called to disable the
1282 * plane, i.e. the passed-in crtc and fb paramters are never NULL.
1283 *
1284 * The source rectangle in frame buffer memory coordinates is given by
1285 * the src_x, src_y, src_w and src_h parameters (as 16.16 fixed point
1286 * values). Devices that don't support subpixel plane coordinates can
1287 * ignore the fractional part.
1288 *
1289 * The destination rectangle in CRTC coordinates is given by the
1290 * crtc_x, crtc_y, crtc_w and crtc_h parameters (as integer values).
1291 * Devices scale the source rectangle to the destination rectangle. If
1292 * scaling is not supported, and the source rectangle size doesn't match
1293 * the destination rectangle size, the driver must return a
1294 * -<errorname>EINVAL</errorname> error.
1295 *
1296 * Drivers implementing atomic modeset should use
1297 * drm_atomic_helper_update_plane() to implement this hook.
1298 *
1299 * RETURNS:
1300 *
1301 * 0 on success or a negative error code on failure.
1302 */
Jesse Barnes8cf5c912011-11-14 14:51:27 -08001303 int (*update_plane)(struct drm_plane *plane,
1304 struct drm_crtc *crtc, struct drm_framebuffer *fb,
1305 int crtc_x, int crtc_y,
1306 unsigned int crtc_w, unsigned int crtc_h,
1307 uint32_t src_x, uint32_t src_y,
1308 uint32_t src_w, uint32_t src_h);
Daniel Vetter88548632015-12-04 09:45:48 +01001309
1310 /**
1311 * @disable_plane:
1312 *
1313 * This is the legacy entry point to disable the plane. The DRM core
Daniel Vetterc6b0ca32015-12-04 09:46:01 +01001314 * calls this method in response to a DRM_IOCTL_MODE_SETPLANE IOCTL call
Daniel Vetter88548632015-12-04 09:45:48 +01001315 * with the frame buffer ID set to 0. Disabled planes must not be
1316 * processed by the CRTC.
1317 *
1318 * Drivers implementing atomic modeset should use
1319 * drm_atomic_helper_disable_plane() to implement this hook.
1320 *
1321 * RETURNS:
1322 *
1323 * 0 on success or a negative error code on failure.
1324 */
Jesse Barnes8cf5c912011-11-14 14:51:27 -08001325 int (*disable_plane)(struct drm_plane *plane);
Daniel Vetter88548632015-12-04 09:45:48 +01001326
1327 /**
1328 * @destroy:
1329 *
1330 * Clean up plane resources. This is only called at driver unload time
1331 * through drm_mode_config_cleanup() since a plane cannot be hotplugged
1332 * in DRM.
1333 */
Jesse Barnes8cf5c912011-11-14 14:51:27 -08001334 void (*destroy)(struct drm_plane *plane);
Daniel Vetter88548632015-12-04 09:45:48 +01001335
1336 /**
1337 * @reset:
1338 *
1339 * Reset plane hardware and software state to off. This function isn't
1340 * called by the core directly, only through drm_mode_config_reset().
1341 * It's not a helper hook only for historical reasons.
1342 *
1343 * Atomic drivers can use drm_atomic_helper_plane_reset() to reset
1344 * atomic state using this hook.
1345 */
Daniel Vetter2a0d7cf2014-07-29 15:32:37 +02001346 void (*reset)(struct drm_plane *plane);
Rob Clark4d939142012-05-17 02:23:27 -06001347
Daniel Vetter88548632015-12-04 09:45:48 +01001348 /**
1349 * @set_property:
1350 *
1351 * This is the legacy entry point to update a property attached to the
1352 * plane.
1353 *
1354 * Drivers implementing atomic modeset should use
1355 * drm_atomic_helper_plane_set_property() to implement this hook.
1356 *
1357 * This callback is optional if the driver does not support any legacy
1358 * driver-private properties.
1359 *
1360 * RETURNS:
1361 *
1362 * 0 on success or a negative error code on failure.
1363 */
Rob Clark4d939142012-05-17 02:23:27 -06001364 int (*set_property)(struct drm_plane *plane,
1365 struct drm_property *property, uint64_t val);
Daniel Vetter144ecb92014-10-27 20:28:44 +01001366
Daniel Vetter88548632015-12-04 09:45:48 +01001367 /**
1368 * @atomic_duplicate_state:
1369 *
1370 * Duplicate the current atomic state for this plane and return it.
1371 * The core and helpers gurantee that any atomic state duplicated with
1372 * this hook and still owned by the caller (i.e. not transferred to the
1373 * driver by calling ->atomic_commit() from struct
1374 * &drm_mode_config_funcs) will be cleaned up by calling the
1375 * @atomic_destroy_state hook in this structure.
1376 *
1377 * Atomic drivers which don't subclass struct &drm_plane_state should use
1378 * drm_atomic_helper_plane_duplicate_state(). Drivers that subclass the
1379 * state structure to extend it with driver-private state should use
1380 * __drm_atomic_helper_plane_duplicate_state() to make sure shared state is
1381 * duplicated in a consistent fashion across drivers.
1382 *
1383 * It is an error to call this hook before plane->state has been
1384 * initialized correctly.
1385 *
1386 * NOTE:
1387 *
1388 * If the duplicate state references refcounted resources this hook must
1389 * acquire a reference for each of them. The driver must release these
1390 * references again in @atomic_destroy_state.
1391 *
1392 * RETURNS:
1393 *
1394 * Duplicated atomic state or NULL when the allocation failed.
1395 */
Daniel Vetter144ecb92014-10-27 20:28:44 +01001396 struct drm_plane_state *(*atomic_duplicate_state)(struct drm_plane *plane);
Daniel Vetter88548632015-12-04 09:45:48 +01001397
1398 /**
1399 * @atomic_destroy_state:
1400 *
1401 * Destroy a state duplicated with @atomic_duplicate_state and release
1402 * or unreference all resources it references
1403 */
Daniel Vetter144ecb92014-10-27 20:28:44 +01001404 void (*atomic_destroy_state)(struct drm_plane *plane,
Daniel Vettercc4ceb42014-07-25 21:30:38 +02001405 struct drm_plane_state *state);
Daniel Vetter88548632015-12-04 09:45:48 +01001406
1407 /**
1408 * @atomic_set_property:
1409 *
1410 * Decode a driver-private property value and store the decoded value
1411 * into the passed-in state structure. Since the atomic core decodes all
1412 * standardized properties (even for extensions beyond the core set of
1413 * properties which might not be implemented by all drivers) this
1414 * requires drivers to subclass the state structure.
1415 *
1416 * Such driver-private properties should really only be implemented for
1417 * truly hardware/vendor specific state. Instead it is preferred to
1418 * standardize atomic extension and decode the properties used to expose
1419 * such an extension in the core.
1420 *
1421 * Do not call this function directly, use
1422 * drm_atomic_plane_set_property() instead.
1423 *
1424 * This callback is optional if the driver does not support any
1425 * driver-private atomic properties.
1426 *
1427 * NOTE:
1428 *
1429 * This function is called in the state assembly phase of atomic
1430 * modesets, which can be aborted for any reason (including on
1431 * userspace's request to just check whether a configuration would be
1432 * possible). Drivers MUST NOT touch any persistent state (hardware or
1433 * software) or data structures except the passed in @state parameter.
1434 *
1435 * Also since userspace controls in which order properties are set this
1436 * function must not do any input validation (since the state update is
1437 * incomplete and hence likely inconsistent). Instead any such input
1438 * validation must be done in the various atomic_check callbacks.
1439 *
1440 * RETURNS:
1441 *
1442 * 0 if the property has been found, -EINVAL if the property isn't
1443 * implemented by the driver (which shouldn't ever happen, the core only
1444 * asks for properties attached to this plane). No other validation is
1445 * allowed by the driver. The core already checks that the property
1446 * value is within the range (integer, valid enum value, ...) the driver
1447 * set when registering the property.
1448 */
Daniel Vetter144ecb92014-10-27 20:28:44 +01001449 int (*atomic_set_property)(struct drm_plane *plane,
1450 struct drm_plane_state *state,
1451 struct drm_property *property,
1452 uint64_t val);
Daniel Vetter88548632015-12-04 09:45:48 +01001453
1454 /**
1455 * @atomic_get_property:
1456 *
1457 * Reads out the decoded driver-private property. This is used to
Daniel Vetterc6b0ca32015-12-04 09:46:01 +01001458 * implement the GETPLANE IOCTL.
Daniel Vetter88548632015-12-04 09:45:48 +01001459 *
1460 * Do not call this function directly, use
1461 * drm_atomic_plane_get_property() instead.
1462 *
1463 * This callback is optional if the driver does not support any
1464 * driver-private atomic properties.
1465 *
1466 * RETURNS:
1467 *
1468 * 0 on success, -EINVAL if the property isn't implemented by the
1469 * driver (which should never happen, the core only asks for
1470 * properties attached to this plane).
1471 */
Rob Clarkac9c9252014-12-18 16:01:47 -05001472 int (*atomic_get_property)(struct drm_plane *plane,
1473 const struct drm_plane_state *state,
1474 struct drm_property *property,
1475 uint64_t *val);
Jesse Barnes8cf5c912011-11-14 14:51:27 -08001476};
1477
Matt Ropere27dde32014-04-01 15:22:30 -07001478enum drm_plane_type {
1479 DRM_PLANE_TYPE_OVERLAY,
1480 DRM_PLANE_TYPE_PRIMARY,
1481 DRM_PLANE_TYPE_CURSOR,
1482};
1483
Daniel Vetter88548632015-12-04 09:45:48 +01001484
Jesse Barnes8cf5c912011-11-14 14:51:27 -08001485/**
Daniel Vetter3bf04012014-10-27 16:54:27 +01001486 * struct drm_plane - central DRM plane control structure
Jesse Barnes8cf5c912011-11-14 14:51:27 -08001487 * @dev: DRM device this plane belongs to
1488 * @head: for list management
1489 * @base: base mode object
1490 * @possible_crtcs: pipes this plane can be bound to
1491 * @format_types: array of formats supported by this plane
1492 * @format_count: number of formats supported
Laurent Pinchart7eb5f302015-03-09 10:41:07 +02001493 * @format_default: driver hasn't supplied supported formats for the plane
Jesse Barnes8cf5c912011-11-14 14:51:27 -08001494 * @crtc: currently bound CRTC
1495 * @fb: currently bound fb
Daniel Vetter2c0c33d2014-10-27 20:19:38 +01001496 * @old_fb: Temporary tracking of the old fb while a modeset is ongoing. Used by
1497 * drm_mode_set_config_internal() to implement correct refcounting.
Jesse Barnes8cf5c912011-11-14 14:51:27 -08001498 * @funcs: helper functions
Rob Clark4d939142012-05-17 02:23:27 -06001499 * @properties: property tracking for this plane
Matt Ropere27dde32014-04-01 15:22:30 -07001500 * @type: type of plane (overlay, primary, cursor)
Daniel Vetter144ecb92014-10-27 20:28:44 +01001501 * @state: current atomic state for this plane
Jesse Barnes8cf5c912011-11-14 14:51:27 -08001502 */
1503struct drm_plane {
1504 struct drm_device *dev;
1505 struct list_head head;
1506
Ville Syrjälä9f4c97a2015-12-08 18:41:54 +02001507 char *name;
1508
Daniel Vetter4d02e2d2014-11-11 10:12:00 +01001509 struct drm_modeset_lock mutex;
1510
Jesse Barnes8cf5c912011-11-14 14:51:27 -08001511 struct drm_mode_object base;
1512
1513 uint32_t possible_crtcs;
1514 uint32_t *format_types;
Thierry Reding45e37432015-08-12 16:54:28 +02001515 unsigned int format_count;
Laurent Pinchart7eb5f302015-03-09 10:41:07 +02001516 bool format_default;
Jesse Barnes8cf5c912011-11-14 14:51:27 -08001517
1518 struct drm_crtc *crtc;
1519 struct drm_framebuffer *fb;
1520
Daniel Vetter3d30a592014-07-27 13:42:42 +02001521 struct drm_framebuffer *old_fb;
1522
Jesse Barnes8cf5c912011-11-14 14:51:27 -08001523 const struct drm_plane_funcs *funcs;
Rob Clark4d939142012-05-17 02:23:27 -06001524
1525 struct drm_object_properties properties;
Matt Ropere27dde32014-04-01 15:22:30 -07001526
1527 enum drm_plane_type type;
Daniel Vetter144ecb92014-10-27 20:28:44 +01001528
Daniel Vetter4490d4c2015-12-04 09:45:45 +01001529 const struct drm_plane_helper_funcs *helper_private;
Daniel Vetterc2fcd272014-11-05 00:14:14 +01001530
Daniel Vetter144ecb92014-10-27 20:28:44 +01001531 struct drm_plane_state *state;
Jesse Barnes8cf5c912011-11-14 14:51:27 -08001532};
1533
1534/**
Daniel Vetter3bf04012014-10-27 16:54:27 +01001535 * struct drm_bridge_funcs - drm_bridge control functions
Ajay Kumar3d3f8b12015-01-20 22:08:44 +05301536 * @attach: Called during drm_bridge_attach
Sean Paul3b336ec2013-08-14 16:47:37 -04001537 */
1538struct drm_bridge_funcs {
Ajay Kumar3d3f8b12015-01-20 22:08:44 +05301539 int (*attach)(struct drm_bridge *bridge);
Daniel Vetterda024fe2015-12-04 09:45:47 +01001540
1541 /**
1542 * @mode_fixup:
1543 *
1544 * This callback is used to validate and adjust a mode. The paramater
1545 * mode is the display mode that should be fed to the next element in
1546 * the display chain, either the final &drm_connector or the next
1547 * &drm_bridge. The parameter adjusted_mode is the input mode the bridge
1548 * requires. It can be modified by this callback and does not need to
1549 * match mode.
1550 *
1551 * This is the only hook that allows a bridge to reject a modeset. If
1552 * this function passes all other callbacks must succeed for this
1553 * configuration.
1554 *
1555 * NOTE:
1556 *
1557 * This function is called in the check phase of atomic modesets, which
1558 * can be aborted for any reason (including on userspace's request to
1559 * just check whether a configuration would be possible). Drivers MUST
1560 * NOT touch any persistent state (hardware or software) or data
Daniel Vetter88548632015-12-04 09:45:48 +01001561 * structures except the passed in @state parameter.
Daniel Vetterda024fe2015-12-04 09:45:47 +01001562 *
1563 * RETURNS:
1564 *
1565 * True if an acceptable configuration is possible, false if the modeset
1566 * operation should be rejected.
1567 */
Sean Paul3b336ec2013-08-14 16:47:37 -04001568 bool (*mode_fixup)(struct drm_bridge *bridge,
1569 const struct drm_display_mode *mode,
1570 struct drm_display_mode *adjusted_mode);
Daniel Vetterda024fe2015-12-04 09:45:47 +01001571 /**
1572 * @disable:
1573 *
1574 * This callback should disable the bridge. It is called right before
1575 * the preceding element in the display pipe is disabled. If the
1576 * preceding element is a bridge this means it's called before that
1577 * bridge's ->disable() function. If the preceding element is a
1578 * &drm_encoder it's called right before the encoder's ->disable(),
1579 * ->prepare() or ->dpms() hook from struct &drm_encoder_helper_funcs.
1580 *
1581 * The bridge can assume that the display pipe (i.e. clocks and timing
1582 * signals) feeding it is still running when this callback is called.
1583 */
Sean Paul3b336ec2013-08-14 16:47:37 -04001584 void (*disable)(struct drm_bridge *bridge);
Daniel Vetterda024fe2015-12-04 09:45:47 +01001585
1586 /**
1587 * @post_disable:
1588 *
1589 * This callback should disable the bridge. It is called right after
1590 * the preceding element in the display pipe is disabled. If the
1591 * preceding element is a bridge this means it's called after that
1592 * bridge's ->post_disable() function. If the preceding element is a
1593 * &drm_encoder it's called right after the encoder's ->disable(),
1594 * ->prepare() or ->dpms() hook from struct &drm_encoder_helper_funcs.
1595 *
1596 * The bridge must assume that the display pipe (i.e. clocks and timing
1597 * singals) feeding it is no longer running when this callback is
1598 * called.
1599 */
Sean Paul3b336ec2013-08-14 16:47:37 -04001600 void (*post_disable)(struct drm_bridge *bridge);
Daniel Vetterda024fe2015-12-04 09:45:47 +01001601
1602 /**
1603 * @mode_set:
1604 *
1605 * This callback should set the given mode on the bridge. It is called
1606 * after the ->mode_set() callback for the preceding element in the
1607 * display pipeline has been called already. The display pipe (i.e.
1608 * clocks and timing signals) is off when this function is called.
1609 */
Sean Paul3b336ec2013-08-14 16:47:37 -04001610 void (*mode_set)(struct drm_bridge *bridge,
1611 struct drm_display_mode *mode,
1612 struct drm_display_mode *adjusted_mode);
Daniel Vetterda024fe2015-12-04 09:45:47 +01001613 /**
1614 * @pre_enable:
1615 *
1616 * This callback should enable the bridge. It is called right before
1617 * the preceding element in the display pipe is enabled. If the
1618 * preceding element is a bridge this means it's called before that
1619 * bridge's ->pre_enable() function. If the preceding element is a
1620 * &drm_encoder it's called right before the encoder's ->enable(),
1621 * ->commit() or ->dpms() hook from struct &drm_encoder_helper_funcs.
1622 *
1623 * The display pipe (i.e. clocks and timing signals) feeding this bridge
1624 * will not yet be running when this callback is called. The bridge must
1625 * not enable the display link feeding the next bridge in the chain (if
1626 * there is one) when this callback is called.
1627 */
Sean Paul3b336ec2013-08-14 16:47:37 -04001628 void (*pre_enable)(struct drm_bridge *bridge);
Daniel Vetterda024fe2015-12-04 09:45:47 +01001629
1630 /**
1631 * @enable:
1632 *
1633 * This callback should enable the bridge. It is called right after
1634 * the preceding element in the display pipe is enabled. If the
1635 * preceding element is a bridge this means it's called after that
1636 * bridge's ->enable() function. If the preceding element is a
1637 * &drm_encoder it's called right after the encoder's ->enable(),
1638 * ->commit() or ->dpms() hook from struct &drm_encoder_helper_funcs.
1639 *
1640 * The bridge can assume that the display pipe (i.e. clocks and timing
1641 * signals) feeding it is running when this callback is called. This
1642 * callback must enable the display link feeding the next bridge in the
1643 * chain if there is one.
1644 */
Sean Paul3b336ec2013-08-14 16:47:37 -04001645 void (*enable)(struct drm_bridge *bridge);
Sean Paul3b336ec2013-08-14 16:47:37 -04001646};
1647
1648/**
Daniel Vetter3bf04012014-10-27 16:54:27 +01001649 * struct drm_bridge - central DRM bridge control structure
Sean Paul3b336ec2013-08-14 16:47:37 -04001650 * @dev: DRM device this bridge belongs to
Archit Taneja862e6862015-05-21 11:03:16 +05301651 * @encoder: encoder to which this bridge is connected
1652 * @next: the next bridge in the encoder chain
Ajay Kumar3d3f8b12015-01-20 22:08:44 +05301653 * @of_node: device node pointer to the bridge
1654 * @list: to keep track of all added bridges
Sean Paul3b336ec2013-08-14 16:47:37 -04001655 * @funcs: control functions
1656 * @driver_private: pointer to the bridge driver's internal context
1657 */
1658struct drm_bridge {
1659 struct drm_device *dev;
Ajay Kumar3d3f8b12015-01-20 22:08:44 +05301660 struct drm_encoder *encoder;
Archit Taneja862e6862015-05-21 11:03:16 +05301661 struct drm_bridge *next;
Ajay Kumar3d3f8b12015-01-20 22:08:44 +05301662#ifdef CONFIG_OF
1663 struct device_node *of_node;
1664#endif
1665 struct list_head list;
Sean Paul3b336ec2013-08-14 16:47:37 -04001666
1667 const struct drm_bridge_funcs *funcs;
1668 void *driver_private;
1669};
1670
1671/**
Rob Clark08855fa2015-03-11 10:23:09 -04001672 * struct drm_atomic_state - the global state object for atomic updates
Daniel Vettercc4ceb42014-07-25 21:30:38 +02001673 * @dev: parent DRM device
Rob Clarkd34f20d2014-12-18 16:01:56 -05001674 * @allow_modeset: allow full modeset
Daniel Vetterc6b0ca32015-12-04 09:46:01 +01001675 * @legacy_cursor_update: hint to enforce legacy cursor IOCTL semantics
Daniel Vettercc4ceb42014-07-25 21:30:38 +02001676 * @planes: pointer to array of plane pointers
1677 * @plane_states: pointer to array of plane states pointers
1678 * @crtcs: pointer to array of CRTC pointers
1679 * @crtc_states: pointer to array of CRTC states pointers
Daniel Vetterf52b69f12014-11-19 18:38:08 +01001680 * @num_connector: size of the @connectors and @connector_states arrays
Daniel Vettercc4ceb42014-07-25 21:30:38 +02001681 * @connectors: pointer to array of connector pointers
1682 * @connector_states: pointer to array of connector states pointers
1683 * @acquire_ctx: acquire context for this atomic modeset state update
1684 */
1685struct drm_atomic_state {
1686 struct drm_device *dev;
Rob Clarkd34f20d2014-12-18 16:01:56 -05001687 bool allow_modeset : 1;
Daniel Vetterf02ad902015-01-22 16:36:23 +01001688 bool legacy_cursor_update : 1;
Daniel Vettercc4ceb42014-07-25 21:30:38 +02001689 struct drm_plane **planes;
1690 struct drm_plane_state **plane_states;
1691 struct drm_crtc **crtcs;
1692 struct drm_crtc_state **crtc_states;
Daniel Vetterf52b69f12014-11-19 18:38:08 +01001693 int num_connector;
Daniel Vettercc4ceb42014-07-25 21:30:38 +02001694 struct drm_connector **connectors;
1695 struct drm_connector_state **connector_states;
1696
1697 struct drm_modeset_acquire_ctx *acquire_ctx;
1698};
1699
1700
1701/**
Daniel Vetter3bf04012014-10-27 16:54:27 +01001702 * struct drm_mode_set - new values for a CRTC config change
Jesse Barnesef273512011-11-07 12:03:19 -08001703 * @fb: framebuffer to use for new config
1704 * @crtc: CRTC whose configuration we're about to change
1705 * @mode: mode timings to use
1706 * @x: position of this CRTC relative to @fb
1707 * @y: position of this CRTC relative to @fb
1708 * @connectors: array of connectors to drive with this CRTC if possible
1709 * @num_connectors: size of @connectors array
Dave Airlief453ba02008-11-07 14:05:41 -08001710 *
1711 * Represents a single crtc the connectors that it drives with what mode
1712 * and from which framebuffer it scans out from.
1713 *
1714 * This is used to set modes.
1715 */
1716struct drm_mode_set {
Dave Airlief453ba02008-11-07 14:05:41 -08001717 struct drm_framebuffer *fb;
1718 struct drm_crtc *crtc;
1719 struct drm_display_mode *mode;
1720
1721 uint32_t x;
1722 uint32_t y;
1723
1724 struct drm_connector **connectors;
1725 size_t num_connectors;
1726};
1727
1728/**
Jesse Barnes550cebc2011-11-07 12:03:20 -08001729 * struct drm_mode_config_funcs - basic driver provided mode setting functions
Jesse Barnes550cebc2011-11-07 12:03:20 -08001730 *
1731 * Some global (i.e. not per-CRTC, connector, etc) mode setting functions that
1732 * involve drivers.
Dave Airlief453ba02008-11-07 14:05:41 -08001733 */
1734struct drm_mode_config_funcs {
Daniel Vetter9953f412015-12-04 09:46:02 +01001735 /**
1736 * @fb_create:
1737 *
1738 * Create a new framebuffer object. The core does basic checks on the
1739 * requested metadata, but most of that is left to the driver. See
1740 * struct &drm_mode_fb_cmd2 for details.
1741 *
Daniel Vetterd55f5322015-12-08 09:49:19 +01001742 * If the parameters are deemed valid and the backing storage objects in
1743 * the underlying memory manager all exist, then the driver allocates
1744 * a new &drm_framebuffer structure, subclassed to contain
1745 * driver-specific information (like the internal native buffer object
1746 * references). It also needs to fill out all relevant metadata, which
1747 * should be done by calling drm_helper_mode_fill_fb_struct().
1748 *
1749 * The initialization is finalized by calling drm_framebuffer_init(),
1750 * which registers the framebuffer and makes it accessible to other
1751 * threads.
1752 *
Daniel Vetter9953f412015-12-04 09:46:02 +01001753 * RETURNS:
1754 *
1755 * A new framebuffer with an initial reference count of 1 or a negative
1756 * error code encoded with ERR_PTR().
1757 */
Jesse Barnes550cebc2011-11-07 12:03:20 -08001758 struct drm_framebuffer *(*fb_create)(struct drm_device *dev,
1759 struct drm_file *file_priv,
Ville Syrjälä1eb83452015-11-11 19:11:29 +02001760 const struct drm_mode_fb_cmd2 *mode_cmd);
Daniel Vetter9953f412015-12-04 09:46:02 +01001761
1762 /**
1763 * @output_poll_changed:
1764 *
1765 * Callback used by helpers to inform the driver of output configuration
1766 * changes.
1767 *
1768 * Drivers implementing fbdev emulation with the helpers can call
1769 * drm_fb_helper_hotplug_changed from this hook to inform the fbdev
1770 * helper of output changes.
1771 *
1772 * FIXME:
1773 *
1774 * Except that there's no vtable for device-level helper callbacks
1775 * there's no reason this is a core function.
1776 */
Dave Airlieeb1f8e42010-05-07 06:42:51 +00001777 void (*output_poll_changed)(struct drm_device *dev);
Daniel Vettercc4ceb42014-07-25 21:30:38 +02001778
Daniel Vetter9953f412015-12-04 09:46:02 +01001779 /**
1780 * @atomic_check:
1781 *
1782 * This is the only hook to validate an atomic modeset update. This
1783 * function must reject any modeset and state changes which the hardware
1784 * or driver doesn't support. This includes but is of course not limited
1785 * to:
1786 *
1787 * - Checking that the modes, framebuffers, scaling and placement
1788 * requirements and so on are within the limits of the hardware.
1789 *
1790 * - Checking that any hidden shared resources are not oversubscribed.
1791 * This can be shared PLLs, shared lanes, overall memory bandwidth,
1792 * display fifo space (where shared between planes or maybe even
1793 * CRTCs).
1794 *
1795 * - Checking that virtualized resources exported to userspace are not
1796 * oversubscribed. For various reasons it can make sense to expose
1797 * more planes, crtcs or encoders than which are physically there. One
1798 * example is dual-pipe operations (which generally should be hidden
1799 * from userspace if when lockstepped in hardware, exposed otherwise),
1800 * where a plane might need 1 hardware plane (if it's just on one
1801 * pipe), 2 hardware planes (when it spans both pipes) or maybe even
1802 * shared a hardware plane with a 2nd plane (if there's a compatible
1803 * plane requested on the area handled by the other pipe).
1804 *
1805 * - Check that any transitional state is possible and that if
1806 * requested, the update can indeed be done in the vblank period
1807 * without temporarily disabling some functions.
1808 *
1809 * - Check any other constraints the driver or hardware might have.
1810 *
1811 * - This callback also needs to correctly fill out the &drm_crtc_state
1812 * in this update to make sure that drm_atomic_crtc_needs_modeset()
1813 * reflects the nature of the possible update and returns true if and
1814 * only if the update cannot be applied without tearing within one
1815 * vblank on that CRTC. The core uses that information to reject
1816 * updates which require a full modeset (i.e. blanking the screen, or
1817 * at least pausing updates for a substantial amount of time) if
1818 * userspace has disallowed that in its request.
1819 *
1820 * - The driver also does not need to repeat basic input validation
1821 * like done for the corresponding legacy entry points. The core does
1822 * that before calling this hook.
1823 *
1824 * See the documentation of @atomic_commit for an exhaustive list of
1825 * error conditions which don't have to be checked at the
1826 * ->atomic_check() stage?
1827 *
1828 * See the documentation for struct &drm_atomic_state for how exactly
1829 * an atomic modeset update is described.
1830 *
1831 * Drivers using the atomic helpers can implement this hook using
1832 * drm_atomic_helper_check(), or one of the exported sub-functions of
1833 * it.
1834 *
1835 * RETURNS:
1836 *
1837 * 0 on success or one of the below negative error codes:
1838 *
1839 * - -EINVAL, if any of the above constraints are violated.
1840 *
1841 * - -EDEADLK, when returned from an attempt to acquire an additional
1842 * &drm_modeset_lock through drm_modeset_lock().
1843 *
1844 * - -ENOMEM, if allocating additional state sub-structures failed due
1845 * to lack of memory.
1846 *
1847 * - -EINTR, -EAGAIN or -ERESTARTSYS, if the IOCTL should be restarted.
1848 * This can either be due to a pending signal, or because the driver
1849 * needs to completely bail out to recover from an exceptional
1850 * situation like a GPU hang. From a userspace point all errors are
1851 * treated equally.
1852 */
Daniel Vettercc4ceb42014-07-25 21:30:38 +02001853 int (*atomic_check)(struct drm_device *dev,
Daniel Vetter9953f412015-12-04 09:46:02 +01001854 struct drm_atomic_state *state);
1855
1856 /**
1857 * @atomic_commit:
1858 *
1859 * This is the only hook to commit an atomic modeset update. The core
1860 * guarantees that @atomic_check has been called successfully before
1861 * calling this function, and that nothing has been changed in the
1862 * interim.
1863 *
1864 * See the documentation for struct &drm_atomic_state for how exactly
1865 * an atomic modeset update is described.
1866 *
1867 * Drivers using the atomic helpers can implement this hook using
1868 * drm_atomic_helper_commit(), or one of the exported sub-functions of
1869 * it.
1870 *
1871 * Asynchronous commits (as indicated with the async parameter) must
1872 * do any preparatory work which might result in an unsuccessful commit
1873 * in the context of this callback. The only exceptions are hardware
1874 * errors resulting in -EIO. But even in that case the driver must
1875 * ensure that the display pipe is at least running, to avoid
1876 * compositors crashing when pageflips don't work. Anything else,
1877 * specifically committing the update to the hardware, should be done
1878 * without blocking the caller. For updates which do not require a
1879 * modeset this must be guaranteed.
1880 *
1881 * The driver must wait for any pending rendering to the new
1882 * framebuffers to complete before executing the flip. It should also
1883 * wait for any pending rendering from other drivers if the underlying
1884 * buffer is a shared dma-buf. Asynchronous commits must not wait for
1885 * rendering in the context of this callback.
1886 *
1887 * An application can request to be notified when the atomic commit has
1888 * completed. These events are per-CRTC and can be distinguished by the
1889 * CRTC index supplied in &drm_event to userspace.
1890 *
1891 * The drm core will supply a struct &drm_event in the event
1892 * member of each CRTC's &drm_crtc_state structure. This can be handled by the
1893 * drm_crtc_send_vblank_event() function, which the driver should call on
1894 * the provided event upon completion of the atomic commit. Note that if
1895 * the driver supports vblank signalling and timestamping the vblank
1896 * counters and timestamps must agree with the ones returned from page
1897 * flip events. With the current vblank helper infrastructure this can
1898 * be achieved by holding a vblank reference while the page flip is
1899 * pending, acquired through drm_crtc_vblank_get() and released with
1900 * drm_crtc_vblank_put(). Drivers are free to implement their own vblank
1901 * counter and timestamp tracking though, e.g. if they have accurate
1902 * timestamp registers in hardware.
1903 *
1904 * NOTE:
1905 *
1906 * Drivers are not allowed to shut down any display pipe successfully
1907 * enabled through an atomic commit on their own. Doing so can result in
1908 * compositors crashing if a page flip is suddenly rejected because the
1909 * pipe is off.
1910 *
1911 * RETURNS:
1912 *
1913 * 0 on success or one of the below negative error codes:
1914 *
1915 * - -EBUSY, if an asynchronous updated is requested and there is
1916 * an earlier updated pending. Drivers are allowed to support a queue
1917 * of outstanding updates, but currently no driver supports that.
1918 * Note that drivers must wait for preceding updates to complete if a
1919 * synchronous update is requested, they are not allowed to fail the
1920 * commit in that case.
1921 *
1922 * - -ENOMEM, if the driver failed to allocate memory. Specifically
1923 * this can happen when trying to pin framebuffers, which must only
1924 * be done when committing the state.
1925 *
1926 * - -ENOSPC, as a refinement of the more generic -ENOMEM to indicate
1927 * that the driver has run out of vram, iommu space or similar GPU
1928 * address space needed for framebuffer.
1929 *
1930 * - -EIO, if the hardware completely died.
1931 *
1932 * - -EINTR, -EAGAIN or -ERESTARTSYS, if the IOCTL should be restarted.
1933 * This can either be due to a pending signal, or because the driver
1934 * needs to completely bail out to recover from an exceptional
1935 * situation like a GPU hang. From a userspace point of view all errors are
1936 * treated equally.
1937 *
1938 * This list is exhaustive. Specifically this hook is not allowed to
1939 * return -EINVAL (any invalid requests should be caught in
1940 * @atomic_check) or -EDEADLK (this function must not acquire
1941 * additional modeset locks).
1942 */
Daniel Vettercc4ceb42014-07-25 21:30:38 +02001943 int (*atomic_commit)(struct drm_device *dev,
Daniel Vetter9953f412015-12-04 09:46:02 +01001944 struct drm_atomic_state *state,
Daniel Vettercc4ceb42014-07-25 21:30:38 +02001945 bool async);
Daniel Vetter9953f412015-12-04 09:46:02 +01001946
1947 /**
1948 * @atomic_state_alloc:
1949 *
1950 * This optional hook can be used by drivers that want to subclass struct
1951 * &drm_atomic_state to be able to track their own driver-private global
1952 * state easily. If this hook is implemented, drivers must also
1953 * implement @atomic_state_clear and @atomic_state_free.
1954 *
1955 * RETURNS:
1956 *
1957 * A new &drm_atomic_state on success or NULL on failure.
1958 */
Maarten Lankhorst036ef572015-05-18 10:06:40 +02001959 struct drm_atomic_state *(*atomic_state_alloc)(struct drm_device *dev);
Daniel Vetter9953f412015-12-04 09:46:02 +01001960
1961 /**
1962 * @atomic_state_clear:
1963 *
1964 * This hook must clear any driver private state duplicated into the
1965 * passed-in &drm_atomic_state. This hook is called when the caller
1966 * encountered a &drm_modeset_lock deadlock and needs to drop all
1967 * already acquired locks as part of the deadlock avoidance dance
1968 * implemented in drm_modeset_lock_backoff().
1969 *
1970 * Any duplicated state must be invalidated since a concurrent atomic
1971 * update might change it, and the drm atomic interfaces always apply
1972 * updates as relative changes to the current state.
1973 *
1974 * Drivers that implement this must call drm_atomic_state_default_clear()
1975 * to clear common state.
1976 */
Maarten Lankhorst036ef572015-05-18 10:06:40 +02001977 void (*atomic_state_clear)(struct drm_atomic_state *state);
Daniel Vetter9953f412015-12-04 09:46:02 +01001978
1979 /**
1980 * @atomic_state_free:
1981 *
1982 * This hook needs driver private resources and the &drm_atomic_state
1983 * itself. Note that the core first calls drm_atomic_state_clear() to
1984 * avoid code duplicate between the clear and free hooks.
1985 *
1986 * Drivers that implement this must call drm_atomic_state_default_free()
1987 * to release common resources.
1988 */
Maarten Lankhorst036ef572015-05-18 10:06:40 +02001989 void (*atomic_state_free)(struct drm_atomic_state *state);
Dave Airlief453ba02008-11-07 14:05:41 -08001990};
1991
Jesse Barnesc1aaca22011-11-07 12:03:21 -08001992/**
Daniel Vetter2c0c33d2014-10-27 20:19:38 +01001993 * struct drm_mode_config - Mode configuration control structure
Jesse Barnesa62c93d2011-11-07 12:03:22 -08001994 * @mutex: mutex protecting KMS related lists and structures
Daniel Vetter2c0c33d2014-10-27 20:19:38 +01001995 * @connection_mutex: ww mutex protecting connector state and routing
1996 * @acquire_ctx: global implicit acquire context used by atomic drivers for
Daniel Vetterc6b0ca32015-12-04 09:46:01 +01001997 * legacy IOCTLs
Jesse Barnesa62c93d2011-11-07 12:03:22 -08001998 * @idr_mutex: mutex for KMS ID allocation and management
1999 * @crtc_idr: main KMS ID tracking object
Daniel Vetter2c0c33d2014-10-27 20:19:38 +01002000 * @fb_lock: mutex to protect fb state and lists
Jesse Barnesa62c93d2011-11-07 12:03:22 -08002001 * @num_fb: number of fbs available
2002 * @fb_list: list of framebuffers available
2003 * @num_connector: number of connectors on this device
2004 * @connector_list: list of connector objects
2005 * @num_encoder: number of encoders on this device
2006 * @encoder_list: list of encoder objects
Daniel Vetter2c0c33d2014-10-27 20:19:38 +01002007 * @num_overlay_plane: number of overlay planes on this device
2008 * @num_total_plane: number of universal (i.e. with primary/curso) planes on this device
2009 * @plane_list: list of plane objects
Jesse Barnesa62c93d2011-11-07 12:03:22 -08002010 * @num_crtc: number of CRTCs on this device
2011 * @crtc_list: list of CRTC objects
Daniel Vetter2c0c33d2014-10-27 20:19:38 +01002012 * @property_list: list of property objects
Jesse Barnesa62c93d2011-11-07 12:03:22 -08002013 * @min_width: minimum pixel width on this device
2014 * @min_height: minimum pixel height on this device
2015 * @max_width: maximum pixel width on this device
2016 * @max_height: maximum pixel height on this device
2017 * @funcs: core driver provided mode setting functions
2018 * @fb_base: base address of the framebuffer
Daniel Vetter2c0c33d2014-10-27 20:19:38 +01002019 * @poll_enabled: track polling support for this device
2020 * @poll_running: track polling status for this device
Jesse Barnesa62c93d2011-11-07 12:03:22 -08002021 * @output_poll_work: delayed work for polling in process context
Daniel Vetter2c0c33d2014-10-27 20:19:38 +01002022 * @property_blob_list: list of all the blob property objects
Daniel Stone8fb6e7a2015-04-20 19:22:54 +01002023 * @blob_lock: mutex for blob property allocation and management
Jesse Barnesa62c93d2011-11-07 12:03:22 -08002024 * @*_property: core property tracking
Daniel Vetter2c0c33d2014-10-27 20:19:38 +01002025 * @preferred_depth: preferred RBG pixel depth, used by fb helpers
2026 * @prefer_shadow: hint to userspace to prefer shadow-fb rendering
2027 * @async_page_flip: does this device support async flips on the primary plane?
2028 * @cursor_width: hint to userspace for max cursor width
2029 * @cursor_height: hint to userspace for max cursor height
Dave Airlief453ba02008-11-07 14:05:41 -08002030 *
Jesse Barnesa62c93d2011-11-07 12:03:22 -08002031 * Core mode resource tracking structure. All CRTC, encoders, and connectors
2032 * enumerated by the driver are added here, as are global properties. Some
2033 * global restrictions are also here, e.g. dimension restrictions.
Dave Airlief453ba02008-11-07 14:05:41 -08002034 */
2035struct drm_mode_config {
Jesse Barnesad2563c2009-01-19 17:21:45 +10002036 struct mutex mutex; /* protects configuration (mode lists etc.) */
Rob Clark51fd3712013-11-19 12:10:12 -05002037 struct drm_modeset_lock connection_mutex; /* protects connector->encoder and encoder->crtc links */
2038 struct drm_modeset_acquire_ctx *acquire_ctx; /* for legacy _lock_all() / _unlock_all() */
Jesse Barnesad2563c2009-01-19 17:21:45 +10002039 struct mutex idr_mutex; /* for IDR management */
Dave Airlief453ba02008-11-07 14:05:41 -08002040 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 +10002041 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 -08002042 /* this is limited to one for now */
Daniel Vetter4b096ac2012-12-10 21:19:18 +01002043
Daniel Vetter2c0c33d2014-10-27 20:19:38 +01002044 struct mutex fb_lock; /* proctects global and per-file fb lists */
Dave Airlief453ba02008-11-07 14:05:41 -08002045 int num_fb;
2046 struct list_head fb_list;
Daniel Vetter4b096ac2012-12-10 21:19:18 +01002047
Dave Airlief453ba02008-11-07 14:05:41 -08002048 int num_connector;
2049 struct list_head connector_list;
2050 int num_encoder;
2051 struct list_head encoder_list;
Matt Ropere27dde32014-04-01 15:22:30 -07002052
2053 /*
2054 * Track # of overlay planes separately from # of total planes. By
2055 * default we only advertise overlay planes to userspace; if userspace
2056 * sets the "universal plane" capability bit, we'll go ahead and
2057 * expose all planes.
2058 */
2059 int num_overlay_plane;
2060 int num_total_plane;
Jesse Barnes8cf5c912011-11-14 14:51:27 -08002061 struct list_head plane_list;
Dave Airlief453ba02008-11-07 14:05:41 -08002062
2063 int num_crtc;
2064 struct list_head crtc_list;
2065
2066 struct list_head property_list;
2067
Dave Airlief453ba02008-11-07 14:05:41 -08002068 int min_width, min_height;
2069 int max_width, max_height;
Laurent Pincharte6ecefa2012-05-17 13:27:23 +02002070 const struct drm_mode_config_funcs *funcs;
Benjamin Herrenschmidtd883f7f2009-02-02 16:55:45 +11002071 resource_size_t fb_base;
Dave Airlief453ba02008-11-07 14:05:41 -08002072
Dave Airlieeb1f8e42010-05-07 06:42:51 +00002073 /* output poll support */
2074 bool poll_enabled;
Daniel Vetter905bc9f2012-10-23 18:23:36 +00002075 bool poll_running;
Daniel Vetter162b6a52015-01-21 08:45:21 +01002076 bool delayed_event;
Tejun Heo991ea752010-07-20 22:09:02 +02002077 struct delayed_work output_poll_work;
Dave Airlieeb1f8e42010-05-07 06:42:51 +00002078
Daniel Stone8fb6e7a2015-04-20 19:22:54 +01002079 struct mutex blob_lock;
2080
Dave Airlief453ba02008-11-07 14:05:41 -08002081 /* pointers to standard properties */
2082 struct list_head property_blob_list;
2083 struct drm_property *edid_property;
2084 struct drm_property *dpms_property;
Dave Airlie43aba7e2014-06-05 14:01:31 +10002085 struct drm_property *path_property;
Dave Airlie6f134d72014-10-20 16:30:50 +10002086 struct drm_property *tile_property;
Rob Clark9922ab52014-04-01 20:16:57 -04002087 struct drm_property *plane_type_property;
Sonika Jindal2a297cc2014-08-05 11:26:54 +05302088 struct drm_property *rotation_property;
Rob Clark6b4959f2014-12-18 16:01:53 -05002089 struct drm_property *prop_src_x;
2090 struct drm_property *prop_src_y;
2091 struct drm_property *prop_src_w;
2092 struct drm_property *prop_src_h;
2093 struct drm_property *prop_crtc_x;
2094 struct drm_property *prop_crtc_y;
2095 struct drm_property *prop_crtc_w;
2096 struct drm_property *prop_crtc_h;
2097 struct drm_property *prop_fb_id;
2098 struct drm_property *prop_crtc_id;
Daniel Vettereab3bbe2015-01-22 16:36:21 +01002099 struct drm_property *prop_active;
Daniel Stone955f3c32015-05-25 19:11:52 +01002100 struct drm_property *prop_mode_id;
Dave Airlief453ba02008-11-07 14:05:41 -08002101
2102 /* DVI-I properties */
2103 struct drm_property *dvi_i_subconnector_property;
2104 struct drm_property *dvi_i_select_subconnector_property;
2105
2106 /* TV properties */
2107 struct drm_property *tv_subconnector_property;
2108 struct drm_property *tv_select_subconnector_property;
2109 struct drm_property *tv_mode_property;
2110 struct drm_property *tv_left_margin_property;
2111 struct drm_property *tv_right_margin_property;
2112 struct drm_property *tv_top_margin_property;
2113 struct drm_property *tv_bottom_margin_property;
Francisco Jerezb6b79022009-08-02 04:19:20 +02002114 struct drm_property *tv_brightness_property;
2115 struct drm_property *tv_contrast_property;
2116 struct drm_property *tv_flicker_reduction_property;
Francisco Jereza75f0232009-08-12 02:30:10 +02002117 struct drm_property *tv_overscan_property;
2118 struct drm_property *tv_saturation_property;
2119 struct drm_property *tv_hue_property;
Dave Airlief453ba02008-11-07 14:05:41 -08002120
2121 /* Optional properties */
2122 struct drm_property *scaling_mode_property;
Vandana Kannanff587e42014-06-11 10:46:48 +05302123 struct drm_property *aspect_ratio_property;
Jakob Bornecrantz884840a2009-12-03 23:25:47 +00002124 struct drm_property *dirty_info_property;
Dave Airlie019d96c2011-09-29 16:20:42 +01002125
Dave Airlie5bb2bbf2014-11-10 10:18:15 +10002126 /* properties for virtual machine layout */
2127 struct drm_property *suggested_x_property;
2128 struct drm_property *suggested_y_property;
2129
Dave Airlie019d96c2011-09-29 16:20:42 +01002130 /* dumb ioctl parameters */
2131 uint32_t preferred_depth, prefer_shadow;
Keith Packard62f21042013-07-22 18:50:00 -07002132
2133 /* whether async page flip is supported or not */
2134 bool async_page_flip;
Alex Deucher8716ed42014-02-12 12:48:23 -05002135
Rob Clarke3eb3252015-02-05 14:41:52 +00002136 /* whether the driver supports fb modifiers */
2137 bool allow_fb_modifiers;
2138
Alex Deucher8716ed42014-02-12 12:48:23 -05002139 /* cursor size */
2140 uint32_t cursor_width, cursor_height;
Dave Airlief453ba02008-11-07 14:05:41 -08002141};
2142
Rob Clarkdd275952014-11-25 20:29:46 -05002143/**
2144 * drm_for_each_plane_mask - iterate over planes specified by bitmask
2145 * @plane: the loop cursor
2146 * @dev: the DRM device
2147 * @plane_mask: bitmask of plane indices
2148 *
2149 * Iterate over all planes specified by bitmask.
2150 */
2151#define drm_for_each_plane_mask(plane, dev, plane_mask) \
2152 list_for_each_entry((plane), &(dev)->mode_config.plane_list, head) \
Jani Nikula373701b2015-11-24 21:21:55 +02002153 for_each_if ((plane_mask) & (1 << drm_plane_index(plane)))
Rob Clarkdd275952014-11-25 20:29:46 -05002154
2155
Dave Airlief453ba02008-11-07 14:05:41 -08002156#define obj_to_crtc(x) container_of(x, struct drm_crtc, base)
2157#define obj_to_connector(x) container_of(x, struct drm_connector, base)
2158#define obj_to_encoder(x) container_of(x, struct drm_encoder, base)
2159#define obj_to_mode(x) container_of(x, struct drm_display_mode, base)
2160#define obj_to_fb(x) container_of(x, struct drm_framebuffer, base)
2161#define obj_to_property(x) container_of(x, struct drm_property, base)
2162#define obj_to_blob(x) container_of(x, struct drm_property_blob, base)
Jesse Barnes8cf5c912011-11-14 14:51:27 -08002163#define obj_to_plane(x) container_of(x, struct drm_plane, base)
Dave Airlief453ba02008-11-07 14:05:41 -08002164
Sascha Hauer4a67d392012-02-06 10:58:17 +01002165struct drm_prop_enum_list {
2166 int type;
2167 char *name;
2168};
Dave Airlief453ba02008-11-07 14:05:41 -08002169
Ville Syrjäläf9882872015-12-09 16:19:31 +02002170extern __printf(6, 7)
2171int drm_crtc_init_with_planes(struct drm_device *dev,
2172 struct drm_crtc *crtc,
2173 struct drm_plane *primary,
2174 struct drm_plane *cursor,
2175 const struct drm_crtc_funcs *funcs,
2176 const char *name, ...);
Dave Airlief453ba02008-11-07 14:05:41 -08002177extern void drm_crtc_cleanup(struct drm_crtc *crtc);
Russell Kingdb5f7a62014-01-02 21:27:33 +00002178extern unsigned int drm_crtc_index(struct drm_crtc *crtc);
2179
2180/**
2181 * drm_crtc_mask - find the mask of a registered CRTC
2182 * @crtc: CRTC to find mask for
2183 *
2184 * Given a registered CRTC, return the mask bit of that CRTC for an
2185 * encoder's possible_crtcs field.
2186 */
2187static inline uint32_t drm_crtc_mask(struct drm_crtc *crtc)
2188{
2189 return 1 << drm_crtc_index(crtc);
2190}
Dave Airlief453ba02008-11-07 14:05:41 -08002191
Ilia Mirkinb21e3af2013-08-07 22:34:48 -04002192extern void drm_connector_ida_init(void);
2193extern void drm_connector_ida_destroy(void);
Ville Syrjälä6bfc56a2012-03-13 12:35:48 +02002194extern int drm_connector_init(struct drm_device *dev,
2195 struct drm_connector *connector,
2196 const struct drm_connector_funcs *funcs,
2197 int connector_type);
Thomas Wood34ea3d32014-05-29 16:57:41 +01002198int drm_connector_register(struct drm_connector *connector);
2199void drm_connector_unregister(struct drm_connector *connector);
Dave Airlief453ba02008-11-07 14:05:41 -08002200
2201extern void drm_connector_cleanup(struct drm_connector *connector);
Daniel Vetter10f637b2014-07-29 13:47:11 +02002202extern unsigned int drm_connector_index(struct drm_connector *connector);
Dave Airliecbc7e222012-02-20 14:16:40 +00002203/* helper to unplug all connectors from sysfs for device */
2204extern void drm_connector_unplug_all(struct drm_device *dev);
Dave Airlief453ba02008-11-07 14:05:41 -08002205
Ajay Kumar3d3f8b12015-01-20 22:08:44 +05302206extern int drm_bridge_add(struct drm_bridge *bridge);
2207extern void drm_bridge_remove(struct drm_bridge *bridge);
2208extern struct drm_bridge *of_drm_find_bridge(struct device_node *np);
2209extern int drm_bridge_attach(struct drm_device *dev, struct drm_bridge *bridge);
Sean Paul3b336ec2013-08-14 16:47:37 -04002210
Archit Taneja862e6862015-05-21 11:03:16 +05302211bool drm_bridge_mode_fixup(struct drm_bridge *bridge,
2212 const struct drm_display_mode *mode,
2213 struct drm_display_mode *adjusted_mode);
2214void drm_bridge_disable(struct drm_bridge *bridge);
2215void drm_bridge_post_disable(struct drm_bridge *bridge);
2216void drm_bridge_mode_set(struct drm_bridge *bridge,
2217 struct drm_display_mode *mode,
2218 struct drm_display_mode *adjusted_mode);
2219void drm_bridge_pre_enable(struct drm_bridge *bridge);
2220void drm_bridge_enable(struct drm_bridge *bridge);
2221
Ville Syrjälä13a3d912015-12-09 16:20:18 +02002222extern __printf(5, 6)
2223int drm_encoder_init(struct drm_device *dev,
2224 struct drm_encoder *encoder,
2225 const struct drm_encoder_funcs *funcs,
2226 int encoder_type, const char *name, ...);
Dave Airlief453ba02008-11-07 14:05:41 -08002227
Thierry Reding3d887362014-01-13 14:33:20 +01002228/**
2229 * drm_encoder_crtc_ok - can a given crtc drive a given encoder?
2230 * @encoder: encoder to test
2231 * @crtc: crtc to test
2232 *
2233 * Return false if @encoder can't be driven by @crtc, true otherwise.
2234 */
2235static inline bool drm_encoder_crtc_ok(struct drm_encoder *encoder,
2236 struct drm_crtc *crtc)
2237{
2238 return !!(encoder->possible_crtcs & drm_crtc_mask(crtc));
2239}
2240
Ville Syrjäläb0b3b792015-12-09 16:19:55 +02002241extern __printf(8, 9)
2242int drm_universal_plane_init(struct drm_device *dev,
2243 struct drm_plane *plane,
2244 unsigned long possible_crtcs,
2245 const struct drm_plane_funcs *funcs,
2246 const uint32_t *formats,
2247 unsigned int format_count,
2248 enum drm_plane_type type,
2249 const char *name, ...);
Jesse Barnes8cf5c912011-11-14 14:51:27 -08002250extern int drm_plane_init(struct drm_device *dev,
2251 struct drm_plane *plane,
2252 unsigned long possible_crtcs,
2253 const struct drm_plane_funcs *funcs,
Thierry Reding45e37432015-08-12 16:54:28 +02002254 const uint32_t *formats, unsigned int format_count,
Matt Roperdc415ff2014-04-01 15:22:36 -07002255 bool is_primary);
Jesse Barnes8cf5c912011-11-14 14:51:27 -08002256extern void drm_plane_cleanup(struct drm_plane *plane);
Daniel Vetter10f637b2014-07-29 13:47:11 +02002257extern unsigned int drm_plane_index(struct drm_plane *plane);
Chandra Konduruf81338a2015-04-09 17:36:21 -07002258extern struct drm_plane * drm_plane_from_index(struct drm_device *dev, int idx);
Ville Syrjälä9125e612013-06-03 16:10:40 +03002259extern void drm_plane_force_disable(struct drm_plane *plane);
Laurent Pinchartead86102015-03-05 02:25:43 +02002260extern int drm_plane_check_pixel_format(const struct drm_plane *plane,
2261 u32 format);
Gustavo Padovanecb7e162014-12-01 15:40:09 -08002262extern void drm_crtc_get_hv_timing(const struct drm_display_mode *mode,
2263 int *hdisplay, int *vdisplay);
Matt Roperaf936292014-04-01 15:22:34 -07002264extern int drm_crtc_check_viewport(const struct drm_crtc *crtc,
2265 int x, int y,
2266 const struct drm_display_mode *mode,
2267 const struct drm_framebuffer *fb);
Jesse Barnes8cf5c912011-11-14 14:51:27 -08002268
Dave Airlief453ba02008-11-07 14:05:41 -08002269extern void drm_encoder_cleanup(struct drm_encoder *encoder);
2270
Ville Syrjäläd20d3172013-06-07 15:43:07 +00002271extern const char *drm_get_connector_status_name(enum drm_connector_status status);
Jesse Barnesac1bb362014-02-10 15:32:44 -08002272extern const char *drm_get_subpixel_order_name(enum subpixel_order order);
Ville Syrjäläd20d3172013-06-07 15:43:07 +00002273extern const char *drm_get_dpms_name(int val);
2274extern const char *drm_get_dvi_i_subconnector_name(int val);
2275extern const char *drm_get_dvi_i_select_name(int val);
2276extern const char *drm_get_tv_subconnector_name(int val);
2277extern const char *drm_get_tv_select_name(int val);
Kristian Høgsbergea39f832009-02-12 14:37:56 -05002278extern void drm_fb_release(struct drm_file *file_priv);
Daniel Stonee2f5d2e2015-05-22 13:34:51 +01002279extern void drm_property_destroy_user_blobs(struct drm_device *dev,
2280 struct drm_file *file_priv);
Adam Jacksonfbff4692012-09-18 10:58:47 -04002281extern bool drm_probe_ddc(struct i2c_adapter *adapter);
Dave Airlief453ba02008-11-07 14:05:41 -08002282extern struct edid *drm_get_edid(struct drm_connector *connector,
2283 struct i2c_adapter *adapter);
Jani Nikula51f8da52013-09-27 15:08:27 +03002284extern struct edid *drm_edid_duplicate(const struct edid *edid);
Dave Airlief453ba02008-11-07 14:05:41 -08002285extern int drm_add_edid_modes(struct drm_connector *connector, struct edid *edid);
Dave Airlief453ba02008-11-07 14:05:41 -08002286extern void drm_mode_config_init(struct drm_device *dev);
Chris Wilsoneb033552011-01-24 15:11:08 +00002287extern void drm_mode_config_reset(struct drm_device *dev);
Dave Airlief453ba02008-11-07 14:05:41 -08002288extern void drm_mode_config_cleanup(struct drm_device *dev);
Dave Airlief453ba02008-11-07 14:05:41 -08002289
Dave Airlie43aba7e2014-06-05 14:01:31 +10002290extern int drm_mode_connector_set_path_property(struct drm_connector *connector,
Thierry Reding12e6cec2014-05-13 11:38:36 +02002291 const char *path);
Dave Airlie6f134d72014-10-20 16:30:50 +10002292int drm_mode_connector_set_tile_property(struct drm_connector *connector);
Dave Airlief453ba02008-11-07 14:05:41 -08002293extern int drm_mode_connector_update_edid_property(struct drm_connector *connector,
Thierry Reding12e6cec2014-05-13 11:38:36 +02002294 const struct edid *edid);
Rob Clark5ea22f22014-05-30 11:34:01 -04002295
Boris Brezillonb5571e92014-07-22 12:09:10 +02002296extern int drm_display_info_set_bus_formats(struct drm_display_info *info,
2297 const u32 *formats,
2298 unsigned int num_formats);
2299
Rob Clark5ea22f22014-05-30 11:34:01 -04002300static inline bool drm_property_type_is(struct drm_property *property,
2301 uint32_t type)
2302{
2303 /* instanceof for props.. handles extended type vs original types: */
2304 if (property->flags & DRM_MODE_PROP_EXTENDED_TYPE)
2305 return (property->flags & DRM_MODE_PROP_EXTENDED_TYPE) == type;
2306 return property->flags & type;
2307}
2308
2309static inline bool drm_property_type_valid(struct drm_property *property)
2310{
2311 if (property->flags & DRM_MODE_PROP_EXTENDED_TYPE)
2312 return !(property->flags & DRM_MODE_PROP_LEGACY_TYPE);
2313 return !!(property->flags & DRM_MODE_PROP_LEGACY_TYPE);
2314}
2315
Paulo Zanonic5431882012-05-15 18:09:02 -03002316extern int drm_object_property_set_value(struct drm_mode_object *obj,
2317 struct drm_property *property,
2318 uint64_t val);
2319extern int drm_object_property_get_value(struct drm_mode_object *obj,
2320 struct drm_property *property,
2321 uint64_t *value);
Dave Airlief453ba02008-11-07 14:05:41 -08002322extern int drm_framebuffer_init(struct drm_device *dev,
2323 struct drm_framebuffer *fb,
2324 const struct drm_framebuffer_funcs *funcs);
Daniel Vetter786b99e2012-12-02 21:53:40 +01002325extern struct drm_framebuffer *drm_framebuffer_lookup(struct drm_device *dev,
2326 uint32_t id);
Rob Clarkf7eff602012-09-05 21:48:38 +00002327extern void drm_framebuffer_unreference(struct drm_framebuffer *fb);
2328extern void drm_framebuffer_reference(struct drm_framebuffer *fb);
2329extern void drm_framebuffer_remove(struct drm_framebuffer *fb);
Dave Airlief453ba02008-11-07 14:05:41 -08002330extern void drm_framebuffer_cleanup(struct drm_framebuffer *fb);
Daniel Vetter36206362012-12-10 20:42:17 +01002331extern void drm_framebuffer_unregister_private(struct drm_framebuffer *fb);
Dave Airlief453ba02008-11-07 14:05:41 -08002332
Paulo Zanonic5431882012-05-15 18:09:02 -03002333extern void drm_object_attach_property(struct drm_mode_object *obj,
2334 struct drm_property *property,
2335 uint64_t init_val);
Dave Airlief453ba02008-11-07 14:05:41 -08002336extern struct drm_property *drm_property_create(struct drm_device *dev, int flags,
2337 const char *name, int num_values);
Sascha Hauer4a67d392012-02-06 10:58:17 +01002338extern struct drm_property *drm_property_create_enum(struct drm_device *dev, int flags,
2339 const char *name,
2340 const struct drm_prop_enum_list *props,
2341 int num_values);
Rob Clark49e27542012-05-17 02:23:26 -06002342struct drm_property *drm_property_create_bitmask(struct drm_device *dev,
2343 int flags, const char *name,
2344 const struct drm_prop_enum_list *props,
Ville Syrjälä7689ffb2014-07-08 10:31:52 +05302345 int num_props,
2346 uint64_t supported_bits);
Sascha Hauerd9bc3c02012-02-06 10:58:18 +01002347struct drm_property *drm_property_create_range(struct drm_device *dev, int flags,
2348 const char *name,
2349 uint64_t min, uint64_t max);
Rob Clarkebc44cf2012-09-12 22:22:31 -05002350struct drm_property *drm_property_create_signed_range(struct drm_device *dev,
2351 int flags, const char *name,
2352 int64_t min, int64_t max);
Rob Clark98f75de2014-05-30 11:37:03 -04002353struct drm_property *drm_property_create_object(struct drm_device *dev,
2354 int flags, const char *name, uint32_t type);
Daniel Vetter960cd9d2015-01-21 08:47:38 +01002355struct drm_property *drm_property_create_bool(struct drm_device *dev, int flags,
2356 const char *name);
Daniel Stone6bcacf52015-04-20 19:22:55 +01002357struct drm_property_blob *drm_property_create_blob(struct drm_device *dev,
2358 size_t length,
2359 const void *data);
2360struct drm_property_blob *drm_property_lookup_blob(struct drm_device *dev,
2361 uint32_t id);
2362struct drm_property_blob *drm_property_reference_blob(struct drm_property_blob *blob);
2363void drm_property_unreference_blob(struct drm_property_blob *blob);
Dave Airlief453ba02008-11-07 14:05:41 -08002364extern void drm_property_destroy(struct drm_device *dev, struct drm_property *property);
2365extern int drm_property_add_enum(struct drm_property *property, int index,
2366 uint64_t value, const char *name);
2367extern int drm_mode_create_dvi_i_properties(struct drm_device *dev);
Thierry Reding2f763312014-10-13 12:45:57 +02002368extern int drm_mode_create_tv_properties(struct drm_device *dev,
2369 unsigned int num_modes,
Ville Syrjäläb7c914b2015-08-31 15:09:26 +03002370 const char * const modes[]);
Dave Airlief453ba02008-11-07 14:05:41 -08002371extern int drm_mode_create_scaling_mode_property(struct drm_device *dev);
Vandana Kannanff587e42014-06-11 10:46:48 +05302372extern int drm_mode_create_aspect_ratio_property(struct drm_device *dev);
Jakob Bornecrantz884840a2009-12-03 23:25:47 +00002373extern int drm_mode_create_dirty_info_property(struct drm_device *dev);
Dave Airlie5bb2bbf2014-11-10 10:18:15 +10002374extern int drm_mode_create_suggested_offset_properties(struct drm_device *dev);
Rob Clarkd34f20d2014-12-18 16:01:56 -05002375extern bool drm_property_change_valid_get(struct drm_property *property,
2376 uint64_t value, struct drm_mode_object **ref);
2377extern void drm_property_change_valid_put(struct drm_property *property,
2378 struct drm_mode_object *ref);
Dave Airlief453ba02008-11-07 14:05:41 -08002379
2380extern int drm_mode_connector_attach_encoder(struct drm_connector *connector,
2381 struct drm_encoder *encoder);
Sascha Hauer4cae5b82012-02-01 11:38:23 +01002382extern int drm_mode_crtc_set_gamma_size(struct drm_crtc *crtc,
Dave Airlief453ba02008-11-07 14:05:41 -08002383 int gamma_size);
Daniel Vetter7a9c9062009-09-15 22:57:31 +02002384extern struct drm_mode_object *drm_mode_object_find(struct drm_device *dev,
2385 uint32_t id, uint32_t type);
Rob Clark98f75de2014-05-30 11:37:03 -04002386
Dave Airlief453ba02008-11-07 14:05:41 -08002387/* IOCTLs */
2388extern int drm_mode_getresources(struct drm_device *dev,
2389 void *data, struct drm_file *file_priv);
Jesse Barnes8cf5c912011-11-14 14:51:27 -08002390extern int drm_mode_getplane_res(struct drm_device *dev, void *data,
2391 struct drm_file *file_priv);
Dave Airlief453ba02008-11-07 14:05:41 -08002392extern int drm_mode_getcrtc(struct drm_device *dev,
2393 void *data, struct drm_file *file_priv);
2394extern int drm_mode_getconnector(struct drm_device *dev,
2395 void *data, struct drm_file *file_priv);
Daniel Vetter2d13b672012-12-11 13:47:23 +01002396extern int drm_mode_set_config_internal(struct drm_mode_set *set);
Dave Airlief453ba02008-11-07 14:05:41 -08002397extern int drm_mode_setcrtc(struct drm_device *dev,
2398 void *data, struct drm_file *file_priv);
Jesse Barnes8cf5c912011-11-14 14:51:27 -08002399extern int drm_mode_getplane(struct drm_device *dev,
2400 void *data, struct drm_file *file_priv);
2401extern int drm_mode_setplane(struct drm_device *dev,
2402 void *data, struct drm_file *file_priv);
Dave Airlief453ba02008-11-07 14:05:41 -08002403extern int drm_mode_cursor_ioctl(struct drm_device *dev,
2404 void *data, struct drm_file *file_priv);
Dave Airlie4c813d42013-06-20 11:48:52 +10002405extern int drm_mode_cursor2_ioctl(struct drm_device *dev,
2406 void *data, struct drm_file *file_priv);
Dave Airlief453ba02008-11-07 14:05:41 -08002407extern int drm_mode_addfb(struct drm_device *dev,
2408 void *data, struct drm_file *file_priv);
Jesse Barnes308e5bc2011-11-14 14:51:28 -08002409extern int drm_mode_addfb2(struct drm_device *dev,
2410 void *data, struct drm_file *file_priv);
2411extern uint32_t drm_mode_legacy_fb_format(uint32_t bpp, uint32_t depth);
Dave Airlief453ba02008-11-07 14:05:41 -08002412extern int drm_mode_rmfb(struct drm_device *dev,
2413 void *data, struct drm_file *file_priv);
2414extern int drm_mode_getfb(struct drm_device *dev,
2415 void *data, struct drm_file *file_priv);
Jakob Bornecrantz884840a2009-12-03 23:25:47 +00002416extern int drm_mode_dirtyfb_ioctl(struct drm_device *dev,
2417 void *data, struct drm_file *file_priv);
Dave Airlief453ba02008-11-07 14:05:41 -08002418
2419extern int drm_mode_getproperty_ioctl(struct drm_device *dev,
2420 void *data, struct drm_file *file_priv);
2421extern int drm_mode_getblob_ioctl(struct drm_device *dev,
2422 void *data, struct drm_file *file_priv);
Daniel Stonee2f5d2e2015-05-22 13:34:51 +01002423extern int drm_mode_createblob_ioctl(struct drm_device *dev,
2424 void *data, struct drm_file *file_priv);
2425extern int drm_mode_destroyblob_ioctl(struct drm_device *dev,
2426 void *data, struct drm_file *file_priv);
Dave Airlief453ba02008-11-07 14:05:41 -08002427extern int drm_mode_connector_property_set_ioctl(struct drm_device *dev,
2428 void *data, struct drm_file *file_priv);
Dave Airlief453ba02008-11-07 14:05:41 -08002429extern int drm_mode_getencoder(struct drm_device *dev,
2430 void *data, struct drm_file *file_priv);
2431extern int drm_mode_gamma_get_ioctl(struct drm_device *dev,
2432 void *data, struct drm_file *file_priv);
2433extern int drm_mode_gamma_set_ioctl(struct drm_device *dev,
2434 void *data, struct drm_file *file_priv);
Thierry Reding18316c82012-12-20 15:41:44 +01002435extern u8 drm_match_cea_mode(const struct drm_display_mode *to_match);
Vandana Kannan0967e6a2014-04-01 16:26:59 +05302436extern enum hdmi_picture_aspect drm_get_cea_aspect_ratio(const u8 video_code);
Ma Lingf23c20c2009-03-26 19:26:23 +08002437extern bool drm_detect_hdmi_monitor(struct edid *edid);
Zhenyu Wang8fe97902010-09-19 14:27:28 +08002438extern bool drm_detect_monitor_audio(struct edid *edid);
Ville Syrjäläb1edd6a2013-01-17 16:31:30 +02002439extern bool drm_rgb_quant_range_selectable(struct edid *edid);
Kristian Høgsbergd91d8a32009-11-17 12:43:55 -05002440extern int drm_mode_page_flip_ioctl(struct drm_device *dev,
2441 void *data, struct drm_file *file_priv);
Zhao Yakuif0fda0a2009-09-03 09:33:48 +08002442extern int drm_add_modes_noedid(struct drm_connector *connector,
2443 int hdisplay, int vdisplay);
Gerd Hoffmann3cf70da2013-10-11 10:01:08 +02002444extern void drm_set_preferred_mode(struct drm_connector *connector,
2445 int hpref, int vpref);
Alex Deucher3c537882010-02-05 04:21:19 -05002446
Thomas Reim051963d2011-07-29 14:28:57 +00002447extern int drm_edid_header_is_valid(const u8 *raw_edid);
Todd Previte6ba2bd32015-04-21 11:09:41 -07002448extern bool drm_edid_block_valid(u8 *raw_edid, int block, bool print_bad_edid,
2449 bool *edid_corrupt);
Alex Deucher3c537882010-02-05 04:21:19 -05002450extern bool drm_edid_is_valid(struct edid *edid);
Dave Airlie138f9eb2014-10-20 16:17:17 +10002451
2452extern struct drm_tile_group *drm_mode_create_tile_group(struct drm_device *dev,
2453 char topology[8]);
2454extern struct drm_tile_group *drm_mode_get_tile_group(struct drm_device *dev,
2455 char topology[8]);
2456extern void drm_mode_put_tile_group(struct drm_device *dev,
2457 struct drm_tile_group *tg);
Dave Airlie1d42bbc2010-05-07 05:02:30 +00002458struct drm_display_mode *drm_mode_find_dmt(struct drm_device *dev,
Adam Jacksonf6e252b2012-04-13 16:33:31 -04002459 int hsize, int vsize, int fresh,
2460 bool rb);
Dave Airlieff72145b2011-02-07 12:16:14 +10002461
2462extern int drm_mode_create_dumb_ioctl(struct drm_device *dev,
2463 void *data, struct drm_file *file_priv);
2464extern int drm_mode_mmap_dumb_ioctl(struct drm_device *dev,
2465 void *data, struct drm_file *file_priv);
2466extern int drm_mode_destroy_dumb_ioctl(struct drm_device *dev,
2467 void *data, struct drm_file *file_priv);
Paulo Zanonic5431882012-05-15 18:09:02 -03002468extern int drm_mode_obj_get_properties_ioctl(struct drm_device *dev, void *data,
2469 struct drm_file *file_priv);
2470extern int drm_mode_obj_set_property_ioctl(struct drm_device *dev, void *data,
2471 struct drm_file *file_priv);
Thomas Wood3a5f87c2014-08-20 14:45:00 +01002472extern int drm_mode_plane_set_obj_prop(struct drm_plane *plane,
2473 struct drm_property *property,
2474 uint64_t value);
Rob Clarkd34f20d2014-12-18 16:01:56 -05002475extern int drm_mode_atomic_ioctl(struct drm_device *dev,
2476 void *data, struct drm_file *file_priv);
Dave Airlie248dbc22011-11-29 20:02:54 +00002477
2478extern void drm_fb_get_bpp_depth(uint32_t format, unsigned int *depth,
2479 int *bpp);
Ville Syrjälä141670e2012-04-05 21:35:15 +03002480extern int drm_format_num_planes(uint32_t format);
Ville Syrjälä5a86bd52012-04-05 21:35:16 +03002481extern int drm_format_plane_cpp(uint32_t format, int plane);
Ville Syrjälä01b68b02012-04-05 21:35:17 +03002482extern int drm_format_horz_chroma_subsampling(uint32_t format);
2483extern int drm_format_vert_chroma_subsampling(uint32_t format);
Ville Syrjäläd20d3172013-06-07 15:43:07 +00002484extern const char *drm_get_format_name(uint32_t format);
Ville Syrjäläc1df5f32014-07-08 10:31:53 +05302485extern struct drm_property *drm_mode_create_rotation_property(struct drm_device *dev,
2486 unsigned int supported_rotations);
Ville Syrjälä3c9855f2014-07-08 10:31:56 +05302487extern unsigned int drm_rotation_simplify(unsigned int rotation,
2488 unsigned int supported_rotations);
Ville Syrjälä141670e2012-04-05 21:35:15 +03002489
Russell King96f60e32012-08-15 13:59:49 +01002490/* Helpers */
Rob Clarka2b34e22013-10-05 16:36:52 -04002491
2492static inline struct drm_plane *drm_plane_find(struct drm_device *dev,
2493 uint32_t id)
2494{
2495 struct drm_mode_object *mo;
2496 mo = drm_mode_object_find(dev, id, DRM_MODE_OBJECT_PLANE);
2497 return mo ? obj_to_plane(mo) : NULL;
2498}
2499
Russell King96f60e32012-08-15 13:59:49 +01002500static inline struct drm_crtc *drm_crtc_find(struct drm_device *dev,
2501 uint32_t id)
2502{
2503 struct drm_mode_object *mo;
2504 mo = drm_mode_object_find(dev, id, DRM_MODE_OBJECT_CRTC);
2505 return mo ? obj_to_crtc(mo) : NULL;
2506}
2507
2508static inline struct drm_encoder *drm_encoder_find(struct drm_device *dev,
2509 uint32_t id)
2510{
2511 struct drm_mode_object *mo;
2512 mo = drm_mode_object_find(dev, id, DRM_MODE_OBJECT_ENCODER);
2513 return mo ? obj_to_encoder(mo) : NULL;
2514}
2515
Rob Clarka2b34e22013-10-05 16:36:52 -04002516static inline struct drm_connector *drm_connector_find(struct drm_device *dev,
2517 uint32_t id)
2518{
2519 struct drm_mode_object *mo;
2520 mo = drm_mode_object_find(dev, id, DRM_MODE_OBJECT_CONNECTOR);
2521 return mo ? obj_to_connector(mo) : NULL;
2522}
2523
2524static inline struct drm_property *drm_property_find(struct drm_device *dev,
2525 uint32_t id)
2526{
2527 struct drm_mode_object *mo;
2528 mo = drm_mode_object_find(dev, id, DRM_MODE_OBJECT_PROPERTY);
2529 return mo ? obj_to_property(mo) : NULL;
2530}
2531
Matt Ropere27dde32014-04-01 15:22:30 -07002532/* Plane list iterator for legacy (overlay only) planes. */
Daniel Vetter4ea50e92015-07-09 23:44:24 +02002533#define drm_for_each_legacy_plane(plane, dev) \
2534 list_for_each_entry(plane, &(dev)->mode_config.plane_list, head) \
Jani Nikula373701b2015-11-24 21:21:55 +02002535 for_each_if (plane->type == DRM_PLANE_TYPE_OVERLAY)
Matt Ropere27dde32014-04-01 15:22:30 -07002536
Daniel Vetter6295d602015-07-09 23:44:25 +02002537#define drm_for_each_plane(plane, dev) \
2538 list_for_each_entry(plane, &(dev)->mode_config.plane_list, head)
2539
2540#define drm_for_each_crtc(crtc, dev) \
2541 list_for_each_entry(crtc, &(dev)->mode_config.crtc_list, head)
2542
Daniel Vetter7a3f3d62015-07-09 23:44:28 +02002543static inline void
2544assert_drm_connector_list_read_locked(struct drm_mode_config *mode_config)
2545{
Daniel Vettercff20ba2015-07-09 23:44:33 +02002546 /*
2547 * The connector hotadd/remove code currently grabs both locks when
2548 * updating lists. Hence readers need only hold either of them to be
2549 * safe and the check amounts to
2550 *
2551 * WARN_ON(not_holding(A) && not_holding(B)).
2552 */
2553 WARN_ON(!mutex_is_locked(&mode_config->mutex) &&
2554 !drm_modeset_is_locked(&mode_config->connection_mutex));
Daniel Vetter7a3f3d62015-07-09 23:44:28 +02002555}
2556
Daniel Vetter6295d602015-07-09 23:44:25 +02002557#define drm_for_each_connector(connector, dev) \
Daniel Vetter7a3f3d62015-07-09 23:44:28 +02002558 for (assert_drm_connector_list_read_locked(&(dev)->mode_config), \
2559 connector = list_first_entry(&(dev)->mode_config.connector_list, \
2560 struct drm_connector, head); \
2561 &connector->head != (&(dev)->mode_config.connector_list); \
2562 connector = list_next_entry(connector, head))
Daniel Vetter6295d602015-07-09 23:44:25 +02002563
2564#define drm_for_each_encoder(encoder, dev) \
2565 list_for_each_entry(encoder, &(dev)->mode_config.encoder_list, head)
2566
2567#define drm_for_each_fb(fb, dev) \
Daniel Vetter4676ba02015-07-09 23:44:30 +02002568 for (WARN_ON(!mutex_is_locked(&(dev)->mode_config.fb_lock)), \
2569 fb = list_first_entry(&(dev)->mode_config.fb_list, \
2570 struct drm_framebuffer, head); \
2571 &fb->head != (&(dev)->mode_config.fb_list); \
2572 fb = list_next_entry(fb, head))
Daniel Vetter6295d602015-07-09 23:44:25 +02002573
Dave Airlief453ba02008-11-07 14:05:41 -08002574#endif /* __DRM_CRTC_H__ */