blob: 4bea0a1151bc01009fe2a8682f27adf7f4696d09 [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
175 * &drm_mode_config_funcs.
176 */
Dave Airlief453ba02008-11-07 14:05:41 -0800177 void (*destroy)(struct drm_framebuffer *framebuffer);
Daniel Vetterc6b0ca32015-12-04 09:46:01 +0100178
179 /**
180 * @create_handle:
181 *
182 * Create a buffer handle in the driver-specific buffer manager (either
183 * GEM or TTM) valid for the passed-in struct &drm_file. This is used by
184 * the core to implement the GETFB IOCTL, which returns (for
185 * sufficiently priviledged user) also a native buffer handle. This can
186 * be used for seamless transitions between modesetting clients by
187 * copying the current screen contents to a private buffer and blending
188 * between that and the new contents.
189 *
190 * RETURNS:
191 *
192 * 0 on success or a negative error code on failure.
193 */
Dave Airlief453ba02008-11-07 14:05:41 -0800194 int (*create_handle)(struct drm_framebuffer *fb,
195 struct drm_file *file_priv,
196 unsigned int *handle);
Daniel Vetterc6b0ca32015-12-04 09:46:01 +0100197 /**
198 * @dirty:
Jakob Bornecrantz884840a2009-12-03 23:25:47 +0000199 *
Daniel Vetterc6b0ca32015-12-04 09:46:01 +0100200 * Optional callback for the dirty fb IOCTL.
Jakob Bornecrantz884840a2009-12-03 23:25:47 +0000201 *
Daniel Vetterc6b0ca32015-12-04 09:46:01 +0100202 * Userspace can notify the driver via this callback that an area of the
203 * framebuffer has changed and should be flushed to the display
204 * hardware. This can also be used internally, e.g. by the fbdev
205 * emulation, though that's not the case currently.
206 *
207 * See documentation in drm_mode.h for the struct drm_mode_fb_dirty_cmd
208 * for more information as all the semantics and arguments have a one to
209 * one mapping on this function.
210 *
211 * RETURNS:
212 *
213 * 0 on success or a negative error code on failure.
Jakob Bornecrantz884840a2009-12-03 23:25:47 +0000214 */
Thomas Hellstrom02b00162010-10-05 12:43:02 +0200215 int (*dirty)(struct drm_framebuffer *framebuffer,
216 struct drm_file *file_priv, unsigned flags,
Jakob Bornecrantz884840a2009-12-03 23:25:47 +0000217 unsigned color, struct drm_clip_rect *clips,
218 unsigned num_clips);
Dave Airlief453ba02008-11-07 14:05:41 -0800219};
220
221struct drm_framebuffer {
222 struct drm_device *dev;
Rob Clarkf7eff602012-09-05 21:48:38 +0000223 /*
224 * Note that the fb is refcounted for the benefit of driver internals,
225 * for example some hw, disabling a CRTC/plane is asynchronous, and
226 * scanout does not actually complete until the next vblank. So some
227 * cleanup (like releasing the reference(s) on the backing GEM bo(s))
228 * should be deferred. In cases like this, the driver would like to
229 * hold a ref to the fb even though it has already been removed from
230 * userspace perspective.
231 */
232 struct kref refcount;
Daniel Vetter4b096ac2012-12-10 21:19:18 +0100233 /*
234 * Place on the dev->mode_config.fb_list, access protected by
235 * dev->mode_config.fb_lock.
236 */
Dave Airlief453ba02008-11-07 14:05:41 -0800237 struct list_head head;
238 struct drm_mode_object base;
239 const struct drm_framebuffer_funcs *funcs;
Ville Syrjälä01f2c772011-12-20 00:06:49 +0200240 unsigned int pitches[4];
241 unsigned int offsets[4];
Rob Clarke3eb3252015-02-05 14:41:52 +0000242 uint64_t modifier[4];
Dave Airlief453ba02008-11-07 14:05:41 -0800243 unsigned int width;
244 unsigned int height;
245 /* depth can be 15 or 16 */
246 unsigned int depth;
247 int bits_per_pixel;
248 int flags;
Jesse Barnes308e5bc2011-11-14 14:51:28 -0800249 uint32_t pixel_format; /* fourcc format */
Dave Airlief453ba02008-11-07 14:05:41 -0800250 struct list_head filp_head;
251};
252
253struct drm_property_blob {
254 struct drm_mode_object base;
Daniel Stone6bcacf52015-04-20 19:22:55 +0100255 struct drm_device *dev;
256 struct kref refcount;
Daniel Stonee2f5d2e2015-05-22 13:34:51 +0100257 struct list_head head_global;
258 struct list_head head_file;
Thierry Redingecbbe592014-05-13 11:36:13 +0200259 size_t length;
Ville Syrjäläd63f5e62012-03-13 12:35:49 +0200260 unsigned char data[];
Dave Airlief453ba02008-11-07 14:05:41 -0800261};
262
263struct drm_property_enum {
264 uint64_t value;
265 struct list_head head;
266 char name[DRM_PROP_NAME_LEN];
267};
268
269struct drm_property {
270 struct list_head head;
271 struct drm_mode_object base;
272 uint32_t flags;
273 char name[DRM_PROP_NAME_LEN];
274 uint32_t num_values;
275 uint64_t *values;
Rob Clark98f75de2014-05-30 11:37:03 -0400276 struct drm_device *dev;
Dave Airlief453ba02008-11-07 14:05:41 -0800277
Daniel Vetter3758b342014-11-19 18:38:10 +0100278 struct list_head enum_list;
Dave Airlief453ba02008-11-07 14:05:41 -0800279};
280
281struct drm_crtc;
282struct drm_connector;
283struct drm_encoder;
Kristian Høgsbergd91d8a32009-11-17 12:43:55 -0500284struct drm_pending_vblank_event;
Jesse Barnes8cf5c912011-11-14 14:51:27 -0800285struct drm_plane;
Sean Paul3b336ec2013-08-14 16:47:37 -0400286struct drm_bridge;
Daniel Vetter144ecb92014-10-27 20:28:44 +0100287struct drm_atomic_state;
288
Daniel Vetter4490d4c2015-12-04 09:45:45 +0100289struct drm_crtc_helper_funcs;
290struct drm_encoder_helper_funcs;
291struct drm_connector_helper_funcs;
292struct drm_plane_helper_funcs;
293
Daniel Vetter144ecb92014-10-27 20:28:44 +0100294/**
Daniel Vettercc4ceb42014-07-25 21:30:38 +0200295 * struct drm_crtc_state - mutable CRTC state
Daniel Vetter07cc0ef2014-11-27 15:49:39 +0100296 * @crtc: backpointer to the CRTC
Daniel Vetter144ecb92014-10-27 20:28:44 +0100297 * @enable: whether the CRTC should be enabled, gates all other state
Daniel Vetterd9b13622014-11-26 16:57:41 +0100298 * @active: whether the CRTC is actively displaying (used for DPMS)
Maarten Lankhorstfc596662015-07-21 13:28:57 +0200299 * @planes_changed: planes on this crtc are updated
300 * @mode_changed: crtc_state->mode or crtc_state->enable has been changed
301 * @active_changed: crtc_state->active has been toggled.
302 * @connectors_changed: connectors to this crtc have been updated
Rob Clark6ddd3882014-11-21 15:28:31 -0500303 * @plane_mask: bitmask of (1 << drm_plane_index(plane)) of attached planes
Daniel Vetter623369e2014-09-16 17:50:47 +0200304 * @last_vblank_count: for helpers and drivers to capture the vblank of the
305 * update to ensure framebuffer cleanup isn't done too early
Daniel Vetter2f324b42014-10-29 11:13:47 +0100306 * @adjusted_mode: for use by helpers and drivers to compute adjusted mode timings
Daniel Vetter144ecb92014-10-27 20:28:44 +0100307 * @mode: current mode timings
308 * @event: optional pointer to a DRM event to signal upon completion of the
309 * state update
310 * @state: backpointer to global drm_atomic_state
Daniel Vetterd9b13622014-11-26 16:57:41 +0100311 *
312 * Note that the distinction between @enable and @active is rather subtile:
313 * Flipping @active while @enable is set without changing anything else may
314 * never return in a failure from the ->atomic_check callback. Userspace assumes
315 * that a DPMS On will always succeed. In other words: @enable controls resource
316 * assignment, @active controls the actual hardware state.
Daniel Vetter144ecb92014-10-27 20:28:44 +0100317 */
318struct drm_crtc_state {
Daniel Vetter07cc0ef2014-11-27 15:49:39 +0100319 struct drm_crtc *crtc;
320
Daniel Vettercc4ceb42014-07-25 21:30:38 +0200321 bool enable;
Daniel Vetterd9b13622014-11-26 16:57:41 +0100322 bool active;
Daniel Vetter144ecb92014-10-27 20:28:44 +0100323
Daniel Vetterc2fcd272014-11-05 00:14:14 +0100324 /* computed state bits used by helpers and drivers */
325 bool planes_changed : 1;
Daniel Vetter623369e2014-09-16 17:50:47 +0200326 bool mode_changed : 1;
Daniel Vettereab3bbe2015-01-22 16:36:21 +0100327 bool active_changed : 1;
Maarten Lankhorstfc596662015-07-21 13:28:57 +0200328 bool connectors_changed : 1;
Daniel Vetter623369e2014-09-16 17:50:47 +0200329
Rob Clark6ddd3882014-11-21 15:28:31 -0500330 /* attached planes bitmask:
331 * WARNING: transitional helpers do not maintain plane_mask so
332 * drivers not converted over to atomic helpers should not rely
333 * on plane_mask being accurate!
334 */
335 u32 plane_mask;
336
Daniel Vetter623369e2014-09-16 17:50:47 +0200337 /* last_vblank_count: for vblank waits before cleanup */
338 u32 last_vblank_count;
Daniel Vetterc2fcd272014-11-05 00:14:14 +0100339
Daniel Vetter2f324b42014-10-29 11:13:47 +0100340 /* adjusted_mode: for use by helpers and drivers */
341 struct drm_display_mode adjusted_mode;
342
Daniel Vetter144ecb92014-10-27 20:28:44 +0100343 struct drm_display_mode mode;
344
Daniel Stone99cf4a22015-05-25 19:11:51 +0100345 /* blob property to expose current mode to atomic userspace */
346 struct drm_property_blob *mode_blob;
347
Daniel Vetter144ecb92014-10-27 20:28:44 +0100348 struct drm_pending_vblank_event *event;
349
350 struct drm_atomic_state *state;
351};
Dave Airlief453ba02008-11-07 14:05:41 -0800352
353/**
Daniel Vetter3bf04012014-10-27 16:54:27 +0100354 * struct drm_crtc_funcs - control CRTCs for a given device
Dave Airlief453ba02008-11-07 14:05:41 -0800355 *
356 * The drm_crtc_funcs structure is the central CRTC management structure
357 * in the DRM. Each CRTC controls one or more connectors (note that the name
358 * CRTC is simply historical, a CRTC may control LVDS, VGA, DVI, TV out, etc.
359 * connectors, not just CRTs).
360 *
361 * Each driver is responsible for filling out this structure at startup time,
362 * in addition to providing other modesetting features, like i2c and DDC
363 * bus accessors.
364 */
365struct drm_crtc_funcs {
Daniel Vetter88548632015-12-04 09:45:48 +0100366 /**
367 * @reset:
368 *
369 * Reset CRTC hardware and software state to off. This function isn't
370 * called by the core directly, only through drm_mode_config_reset().
371 * It's not a helper hook only for historical reasons.
372 *
373 * Atomic drivers can use drm_atomic_helper_crtc_reset() to reset
374 * atomic state using this hook.
375 */
Chris Wilsoneb033552011-01-24 15:11:08 +0000376 void (*reset)(struct drm_crtc *crtc);
Dave Airlief453ba02008-11-07 14:05:41 -0800377
Daniel Vetterf6da8c62015-12-04 09:46:00 +0100378 /**
379 * @cursor_set:
380 *
381 * Update the cursor image. The cursor position is relative to the CRTC
382 * and can be partially or fully outside of the visible area.
383 *
384 * Note that contrary to all other KMS functions the legacy cursor entry
385 * points don't take a framebuffer object, but instead take directly a
386 * raw buffer object id from the driver's buffer manager (which is
387 * either GEM or TTM for current drivers).
388 *
389 * This entry point is deprecated, drivers should instead implement
390 * universal plane support and register a proper cursor plane using
391 * drm_crtc_init_with_planes().
392 *
393 * This callback is optional
394 *
395 * RETURNS:
396 *
397 * 0 on success or a negative error code on failure.
398 */
Dave Airlief453ba02008-11-07 14:05:41 -0800399 int (*cursor_set)(struct drm_crtc *crtc, struct drm_file *file_priv,
400 uint32_t handle, uint32_t width, uint32_t height);
Daniel Vetterf6da8c62015-12-04 09:46:00 +0100401
402 /**
403 * @cursor_set2:
404 *
405 * Update the cursor image, including hotspot information. The hotspot
406 * must not affect the cursor position in CRTC coordinates, but is only
407 * meant as a hint for virtualized display hardware to coordinate the
408 * guests and hosts cursor position. The cursor hotspot is relative to
409 * the cursor image. Otherwise this works exactly like @cursor_set.
410 *
411 * This entry point is deprecated, drivers should instead implement
412 * universal plane support and register a proper cursor plane using
413 * drm_crtc_init_with_planes().
414 *
415 * This callback is optional.
416 *
417 * RETURNS:
418 *
419 * 0 on success or a negative error code on failure.
420 */
Dave Airlie4c813d42013-06-20 11:48:52 +1000421 int (*cursor_set2)(struct drm_crtc *crtc, struct drm_file *file_priv,
422 uint32_t handle, uint32_t width, uint32_t height,
423 int32_t hot_x, int32_t hot_y);
Daniel Vetterf6da8c62015-12-04 09:46:00 +0100424
425 /**
426 * @cursor_move:
427 *
428 * Update the cursor position. The cursor does not need to be visible
429 * when this hook is called.
430 *
431 * This entry point is deprecated, drivers should instead implement
432 * universal plane support and register a proper cursor plane using
433 * drm_crtc_init_with_planes().
434 *
435 * This callback is optional.
436 *
437 * RETURNS:
438 *
439 * 0 on success or a negative error code on failure.
440 */
Dave Airlief453ba02008-11-07 14:05:41 -0800441 int (*cursor_move)(struct drm_crtc *crtc, int x, int y);
442
Daniel Vetterf6da8c62015-12-04 09:46:00 +0100443 /**
444 * @gamma_set:
445 *
446 * Set gamma on the CRTC.
447 *
448 * This callback is optional.
449 *
450 * NOTE:
451 *
452 * Drivers that support gamma tables and also fbdev emulation through
453 * the provided helper library need to take care to fill out the gamma
454 * hooks for both. Currently there's a bit an unfortunate duplication
455 * going on, which should eventually be unified to just one set of
456 * hooks.
457 */
Dave Airlief453ba02008-11-07 14:05:41 -0800458 void (*gamma_set)(struct drm_crtc *crtc, u16 *r, u16 *g, u16 *b,
James Simmons72034252010-08-03 01:33:19 +0100459 uint32_t start, uint32_t size);
Daniel Vetter88548632015-12-04 09:45:48 +0100460
461 /**
462 * @destroy:
463 *
464 * Clean up plane resources. This is only called at driver unload time
465 * through drm_mode_config_cleanup() since a CRTC cannot be hotplugged
466 * in DRM.
467 */
Dave Airlief453ba02008-11-07 14:05:41 -0800468 void (*destroy)(struct drm_crtc *crtc);
469
Daniel Vetterf6da8c62015-12-04 09:46:00 +0100470 /**
471 * @set_config:
472 *
473 * This is the main legacy entry point to change the modeset state on a
474 * CRTC. All the details of the desired configuration are passed in a
475 * struct &drm_mode_set - see there for details.
476 *
477 * Drivers implementing atomic modeset should use
478 * drm_atomic_helper_set_config() to implement this hook.
479 *
480 * RETURNS:
481 *
482 * 0 on success or a negative error code on failure.
483 */
Dave Airlief453ba02008-11-07 14:05:41 -0800484 int (*set_config)(struct drm_mode_set *set);
Kristian Høgsbergd91d8a32009-11-17 12:43:55 -0500485
Daniel Vetterf6da8c62015-12-04 09:46:00 +0100486 /**
487 * @page_flip:
488 *
489 * Legacy entry point to schedule a flip to the given framebuffer.
490 *
491 * Page flipping is a synchronization mechanism that replaces the frame
492 * buffer being scanned out by the CRTC with a new frame buffer during
493 * vertical blanking, avoiding tearing (except when requested otherwise
494 * through the DRM_MODE_PAGE_FLIP_ASYNC flag). When an application
495 * requests a page flip the DRM core verifies that the new frame buffer
496 * is large enough to be scanned out by the CRTC in the currently
497 * configured mode and then calls the CRTC ->page_flip() operation with a
498 * pointer to the new frame buffer.
499 *
500 * The driver must wait for any pending rendering to the new framebuffer
501 * to complete before executing the flip. It should also wait for any
502 * pending rendering from other drivers if the underlying buffer is a
503 * shared dma-buf.
504 *
505 * An application can request to be notified when the page flip has
506 * completed. The drm core will supply a struct &drm_event in the event
507 * parameter in this case. This can be handled by the
508 * drm_crtc_send_vblank_event() function, which the driver should call on
509 * the provided event upon completion of the flip. Note that if
510 * the driver supports vblank signalling and timestamping the vblank
511 * counters and timestamps must agree with the ones returned from page
512 * flip events. With the current vblank helper infrastructure this can
513 * be achieved by holding a vblank reference while the page flip is
514 * pending, acquired through drm_crtc_vblank_get() and released with
515 * drm_crtc_vblank_put(). Drivers are free to implement their own vblank
516 * counter and timestamp tracking though, e.g. if they have accurate
517 * timestamp registers in hardware.
518 *
519 * FIXME:
520 *
521 * Up to that point drivers need to manage events themselves and can use
522 * even->base.list freely for that. Specifically they need to ensure
523 * that they don't send out page flip (or vblank) events for which the
524 * corresponding drm file has been closed already. The drm core
525 * unfortunately does not (yet) take care of that. Therefore drivers
526 * currently must clean up and release pending events in their
527 * ->preclose driver function.
528 *
529 * This callback is optional.
530 *
531 * NOTE:
532 *
533 * Very early versions of the KMS ABI mandated that the driver must
534 * block (but not reject) any rendering to the old framebuffer until the
535 * flip operation has completed and the old framebuffer is no longer
536 * visible. This requirement has been lifted, and userspace is instead
537 * expected to request delivery of an event and wait with recycling old
538 * buffers until such has been received.
539 *
540 * RETURNS:
541 *
542 * 0 on success or a negative error code on failure. Note that if a
543 * ->page_flip() operation is already pending the callback should return
544 * -EBUSY. Pageflips on a disabled CRTC (either by setting a NULL mode
545 * or just runtime disabled through DPMS respectively the new atomic
546 * "ACTIVE" state) should result in an -EINVAL error code.
Kristian Høgsbergd91d8a32009-11-17 12:43:55 -0500547 */
548 int (*page_flip)(struct drm_crtc *crtc,
549 struct drm_framebuffer *fb,
Keith Packarded8d1972013-07-22 18:49:58 -0700550 struct drm_pending_vblank_event *event,
551 uint32_t flags);
Paulo Zanonibffd9de02012-05-15 18:09:05 -0300552
Daniel Vetter88548632015-12-04 09:45:48 +0100553 /**
554 * @set_property:
555 *
556 * This is the legacy entry point to update a property attached to the
557 * CRTC.
558 *
559 * Drivers implementing atomic modeset should use
560 * drm_atomic_helper_crtc_set_property() to implement this hook.
561 *
562 * This callback is optional if the driver does not support any legacy
563 * driver-private properties.
564 *
565 * RETURNS:
566 *
567 * 0 on success or a negative error code on failure.
568 */
Paulo Zanonibffd9de02012-05-15 18:09:05 -0300569 int (*set_property)(struct drm_crtc *crtc,
570 struct drm_property *property, uint64_t val);
Daniel Vetter144ecb92014-10-27 20:28:44 +0100571
Daniel Vetter88548632015-12-04 09:45:48 +0100572 /**
573 * @atomic_duplicate_state:
574 *
575 * Duplicate the current atomic state for this CRTC and return it.
576 * The core and helpers gurantee that any atomic state duplicated with
577 * this hook and still owned by the caller (i.e. not transferred to the
578 * driver by calling ->atomic_commit() from struct
579 * &drm_mode_config_funcs) will be cleaned up by calling the
580 * @atomic_destroy_state hook in this structure.
581 *
582 * Atomic drivers which don't subclass struct &drm_crtc should use
583 * drm_atomic_helper_crtc_duplicate_state(). Drivers that subclass the
584 * state structure to extend it with driver-private state should use
585 * __drm_atomic_helper_crtc_duplicate_state() to make sure shared state is
586 * duplicated in a consistent fashion across drivers.
587 *
588 * It is an error to call this hook before crtc->state has been
589 * initialized correctly.
590 *
591 * NOTE:
592 *
593 * If the duplicate state references refcounted resources this hook must
594 * acquire a reference for each of them. The driver must release these
595 * references again in @atomic_destroy_state.
596 *
597 * RETURNS:
598 *
599 * Duplicated atomic state or NULL when the allocation failed.
600 */
Daniel Vetter144ecb92014-10-27 20:28:44 +0100601 struct drm_crtc_state *(*atomic_duplicate_state)(struct drm_crtc *crtc);
Daniel Vetter88548632015-12-04 09:45:48 +0100602
603 /**
604 * @atomic_destroy_state:
605 *
606 * Destroy a state duplicated with @atomic_duplicate_state and release
607 * or unreference all resources it references
608 */
Daniel Vetter144ecb92014-10-27 20:28:44 +0100609 void (*atomic_destroy_state)(struct drm_crtc *crtc,
Daniel Vettercc4ceb42014-07-25 21:30:38 +0200610 struct drm_crtc_state *state);
Daniel Vetter88548632015-12-04 09:45:48 +0100611
612 /**
613 * @atomic_set_property:
614 *
615 * Decode a driver-private property value and store the decoded value
616 * into the passed-in state structure. Since the atomic core decodes all
617 * standardized properties (even for extensions beyond the core set of
618 * properties which might not be implemented by all drivers) this
619 * requires drivers to subclass the state structure.
620 *
621 * Such driver-private properties should really only be implemented for
622 * truly hardware/vendor specific state. Instead it is preferred to
623 * standardize atomic extension and decode the properties used to expose
624 * such an extension in the core.
625 *
626 * Do not call this function directly, use
627 * drm_atomic_crtc_set_property() instead.
628 *
629 * This callback is optional if the driver does not support any
630 * driver-private atomic properties.
631 *
632 * NOTE:
633 *
634 * This function is called in the state assembly phase of atomic
635 * modesets, which can be aborted for any reason (including on
636 * userspace's request to just check whether a configuration would be
637 * possible). Drivers MUST NOT touch any persistent state (hardware or
638 * software) or data structures except the passed in @state parameter.
639 *
640 * Also since userspace controls in which order properties are set this
641 * function must not do any input validation (since the state update is
642 * incomplete and hence likely inconsistent). Instead any such input
643 * validation must be done in the various atomic_check callbacks.
644 *
645 * RETURNS:
646 *
647 * 0 if the property has been found, -EINVAL if the property isn't
648 * implemented by the driver (which should never happen, the core only
649 * asks for properties attached to this CRTC). No other validation is
650 * allowed by the driver. The core already checks that the property
651 * value is within the range (integer, valid enum value, ...) the driver
652 * set when registering the property.
653 */
Daniel Vetter144ecb92014-10-27 20:28:44 +0100654 int (*atomic_set_property)(struct drm_crtc *crtc,
655 struct drm_crtc_state *state,
656 struct drm_property *property,
657 uint64_t val);
Daniel Vetter88548632015-12-04 09:45:48 +0100658 /**
659 * @atomic_get_property:
660 *
661 * Reads out the decoded driver-private property. This is used to
Daniel Vetterc6b0ca32015-12-04 09:46:01 +0100662 * implement the GETCRTC IOCTL.
Daniel Vetter88548632015-12-04 09:45:48 +0100663 *
664 * Do not call this function directly, use
665 * drm_atomic_crtc_get_property() instead.
666 *
667 * This callback is optional if the driver does not support any
668 * driver-private atomic properties.
669 *
670 * RETURNS:
671 *
672 * 0 on success, -EINVAL if the property isn't implemented by the
673 * driver (which should never happen, the core only asks for
674 * properties attached to this CRTC).
675 */
Rob Clarkac9c9252014-12-18 16:01:47 -0500676 int (*atomic_get_property)(struct drm_crtc *crtc,
677 const struct drm_crtc_state *state,
678 struct drm_property *property,
679 uint64_t *val);
Dave Airlief453ba02008-11-07 14:05:41 -0800680};
681
682/**
Daniel Vetter3bf04012014-10-27 16:54:27 +0100683 * struct drm_crtc - central CRTC control structure
Jesse Barnes77491632011-11-07 12:03:14 -0800684 * @dev: parent DRM device
Daniel Vetter2c0c33d2014-10-27 20:19:38 +0100685 * @port: OF node used by drm_of_find_possible_crtcs()
Jesse Barnes77491632011-11-07 12:03:14 -0800686 * @head: list management
Rob Clark51fd3712013-11-19 12:10:12 -0500687 * @mutex: per-CRTC locking
Jesse Barnes77491632011-11-07 12:03:14 -0800688 * @base: base KMS object for ID tracking etc.
Matt Ropere13161a2014-04-01 15:22:38 -0700689 * @primary: primary plane for this CRTC
690 * @cursor: cursor plane for this CRTC
Daniel Vetter2c0c33d2014-10-27 20:19:38 +0100691 * @cursor_x: current x position of the cursor, used for universal cursor planes
692 * @cursor_y: current y position of the cursor, used for universal cursor planes
Dave Airlief453ba02008-11-07 14:05:41 -0800693 * @enabled: is this CRTC enabled?
Jesse Barnes77491632011-11-07 12:03:14 -0800694 * @mode: current mode timings
695 * @hwmode: mode timings as programmed to hw regs
Dave Airlief453ba02008-11-07 14:05:41 -0800696 * @x: x position on screen
697 * @y: y position on screen
Dave Airlief453ba02008-11-07 14:05:41 -0800698 * @funcs: CRTC control functions
Jesse Barnes77491632011-11-07 12:03:14 -0800699 * @gamma_size: size of gamma ramp
700 * @gamma_store: gamma ramp values
Jesse Barnes77491632011-11-07 12:03:14 -0800701 * @helper_private: mid-layer private data
Paulo Zanonibffd9de02012-05-15 18:09:05 -0300702 * @properties: property tracking for this CRTC
Daniel Vetter144ecb92014-10-27 20:28:44 +0100703 * @state: current atomic state for this CRTC
Daniel Vetter2c0c33d2014-10-27 20:19:38 +0100704 * @acquire_ctx: per-CRTC implicit acquire context used by atomic drivers for
Daniel Vetterc6b0ca32015-12-04 09:46:01 +0100705 * legacy IOCTLs
Dave Airlief453ba02008-11-07 14:05:41 -0800706 *
707 * Each CRTC may have one or more connectors associated with it. This structure
708 * allows the CRTC to be controlled.
709 */
710struct drm_crtc {
711 struct drm_device *dev;
Russell King7e435aa2014-06-15 11:07:12 +0100712 struct device_node *port;
Dave Airlief453ba02008-11-07 14:05:41 -0800713 struct list_head head;
714
Ville Syrjäläfa3ab4c2015-12-08 18:41:53 +0200715 char *name;
716
Daniel Vetter3bf04012014-10-27 16:54:27 +0100717 /*
Daniel Vetter29494c12012-12-02 02:18:25 +0100718 * crtc mutex
719 *
720 * This provides a read lock for the overall crtc state (mode, dpms
721 * state, ...) and a write lock for everything which can be update
722 * without a full modeset (fb, cursor data, ...)
723 */
Rob Clark51fd3712013-11-19 12:10:12 -0500724 struct drm_modeset_lock mutex;
Daniel Vetter29494c12012-12-02 02:18:25 +0100725
Dave Airlief453ba02008-11-07 14:05:41 -0800726 struct drm_mode_object base;
727
Matt Ropere13161a2014-04-01 15:22:38 -0700728 /* primary and cursor planes for CRTC */
729 struct drm_plane *primary;
730 struct drm_plane *cursor;
731
Matt Roper161d0dc2014-06-10 08:28:10 -0700732 /* position of cursor plane on crtc */
733 int cursor_x;
734 int cursor_y;
735
Dave Airlief453ba02008-11-07 14:05:41 -0800736 bool enabled;
737
Mario Kleiner27641c32010-10-23 04:20:23 +0200738 /* Requested mode from modesetting. */
Dave Airlief453ba02008-11-07 14:05:41 -0800739 struct drm_display_mode mode;
740
Mario Kleiner27641c32010-10-23 04:20:23 +0200741 /* Programmed mode in hw, after adjustments for encoders,
742 * crtc, panel scaling etc. Needed for timestamping etc.
743 */
744 struct drm_display_mode hwmode;
745
Dave Airlief453ba02008-11-07 14:05:41 -0800746 int x, y;
Dave Airlief453ba02008-11-07 14:05:41 -0800747 const struct drm_crtc_funcs *funcs;
748
749 /* CRTC gamma size for reporting to userspace */
750 uint32_t gamma_size;
751 uint16_t *gamma_store;
752
753 /* if you are using the helper */
Daniel Vetter4490d4c2015-12-04 09:45:45 +0100754 const struct drm_crtc_helper_funcs *helper_private;
Paulo Zanonibffd9de02012-05-15 18:09:05 -0300755
756 struct drm_object_properties properties;
Daniel Vetterd059f652014-07-25 18:07:40 +0200757
Daniel Vetter144ecb92014-10-27 20:28:44 +0100758 struct drm_crtc_state *state;
759
Daniel Vetterd059f652014-07-25 18:07:40 +0200760 /*
Daniel Vetterc6b0ca32015-12-04 09:46:01 +0100761 * For legacy crtc IOCTLs so that atomic drivers can get at the locking
Daniel Vetterd059f652014-07-25 18:07:40 +0200762 * acquire context.
763 */
764 struct drm_modeset_acquire_ctx *acquire_ctx;
Dave Airlief453ba02008-11-07 14:05:41 -0800765};
766
Daniel Vetter144ecb92014-10-27 20:28:44 +0100767/**
768 * struct drm_connector_state - mutable connector state
Daniel Vetter07cc0ef2014-11-27 15:49:39 +0100769 * @connector: backpointer to the connector
Daniel Vettercc4ceb42014-07-25 21:30:38 +0200770 * @crtc: CRTC to connect connector to, NULL if disabled
Daniel Vetter623369e2014-09-16 17:50:47 +0200771 * @best_encoder: can be used by helpers and drivers to select the encoder
Daniel Vetter144ecb92014-10-27 20:28:44 +0100772 * @state: backpointer to global drm_atomic_state
773 */
774struct drm_connector_state {
Daniel Vetter07cc0ef2014-11-27 15:49:39 +0100775 struct drm_connector *connector;
776
Rob Clark6ddd3882014-11-21 15:28:31 -0500777 struct drm_crtc *crtc; /* do not write directly, use drm_atomic_set_crtc_for_connector() */
Daniel Vetter144ecb92014-10-27 20:28:44 +0100778
Daniel Vetter623369e2014-09-16 17:50:47 +0200779 struct drm_encoder *best_encoder;
780
Daniel Vetter144ecb92014-10-27 20:28:44 +0100781 struct drm_atomic_state *state;
782};
Dave Airlief453ba02008-11-07 14:05:41 -0800783
784/**
Daniel Vetter3bf04012014-10-27 16:54:27 +0100785 * struct drm_connector_funcs - control connectors on a given device
Daniel Vetter144ecb92014-10-27 20:28:44 +0100786 *
Dave Airlief453ba02008-11-07 14:05:41 -0800787 * Each CRTC may have one or more connectors attached to it. The functions
788 * below allow the core DRM code to control connectors, enumerate available modes,
789 * etc.
790 */
791struct drm_connector_funcs {
Daniel Vetter6fe14ac2015-12-04 09:45:58 +0100792 /**
793 * @dpms:
794 *
795 * Legacy entry point to set the per-connector DPMS state. Legacy DPMS
796 * is exposed as a standard property on the connector, but diverted to
797 * this callback in the drm core. Note that atomic drivers don't
798 * implement the 4 level DPMS support on the connector any more, but
799 * instead only have an on/off "ACTIVE" property on the CRTC object.
800 *
801 * Drivers implementing atomic modeset should use
802 * drm_atomic_helper_connector_dpms() to implement this hook.
803 *
804 * RETURNS:
805 *
806 * 0 on success or a negative error code on failure.
807 */
Maarten Lankhorst9a69a9a2015-07-21 11:34:55 +0200808 int (*dpms)(struct drm_connector *connector, int mode);
Daniel Vetter88548632015-12-04 09:45:48 +0100809
810 /**
811 * @reset:
812 *
813 * Reset connector hardware and software state to off. This function isn't
814 * called by the core directly, only through drm_mode_config_reset().
815 * It's not a helper hook only for historical reasons.
816 *
817 * Atomic drivers can use drm_atomic_helper_connector_reset() to reset
818 * atomic state using this hook.
819 */
Chris Wilsoneb033552011-01-24 15:11:08 +0000820 void (*reset)(struct drm_connector *connector);
Chris Wilson930a9e22010-09-14 11:07:23 +0100821
Daniel Vetter6fe14ac2015-12-04 09:45:58 +0100822 /**
823 * @detect:
824 *
825 * Check to see if anything is attached to the connector. The parameter
826 * force is set to false whilst polling, true when checking the
827 * connector due to a user request. force can be used by the driver to
828 * avoid expensive, destructive operations during automated probing.
829 *
830 * FIXME:
831 *
832 * Note that this hook is only called by the probe helper. It's not in
833 * the helper library vtable purely for historical reasons. The only DRM
834 * core entry point to probe connector state is @fill_modes.
835 *
836 * RETURNS:
837 *
838 * drm_connector_status indicating the connector's status.
Chris Wilson930a9e22010-09-14 11:07:23 +0100839 */
Chris Wilson7b334fc2010-09-09 23:51:02 +0100840 enum drm_connector_status (*detect)(struct drm_connector *connector,
Chris Wilson930a9e22010-09-14 11:07:23 +0100841 bool force);
Daniel Vetter6fe14ac2015-12-04 09:45:58 +0100842
843 /**
844 * @force:
845 *
846 * This function is called to update internal encoder state when the
847 * connector is forced to a certain state by userspace, either through
848 * the sysfs interfaces or on the kernel cmdline. In that case the
849 * @detect callback isn't called.
850 *
851 * FIXME:
852 *
853 * Note that this hook is only called by the probe helper. It's not in
854 * the helper library vtable purely for historical reasons. The only DRM
855 * core entry point to probe connector state is @fill_modes.
856 */
857 void (*force)(struct drm_connector *connector);
858
859 /**
860 * @fill_modes:
861 *
862 * Entry point for output detection and basic mode validation. The
863 * driver should reprobe the output if needed (e.g. when hotplug
864 * handling is unreliable), add all detected modes to connector->modes
865 * and filter out any the device can't support in any configuration. It
866 * also needs to filter out any modes wider or higher than the
867 * parameters max_width and max_height indicate.
868 *
869 * The drivers must also prune any modes no longer valid from
870 * connector->modes. Furthermore it must update connector->status and
871 * connector->edid. If no EDID has been received for this output
872 * connector->edid must be NULL.
873 *
874 * Drivers using the probe helpers should use
875 * drm_helper_probe_single_connector_modes() or
876 * drm_helper_probe_single_connector_modes_nomerge() to implement this
877 * function.
878 *
879 * RETURNS:
880 *
881 * The number of modes detected and filled into connector->modes.
882 */
Jesse Barnes40a518d2009-01-12 12:05:32 -0800883 int (*fill_modes)(struct drm_connector *connector, uint32_t max_width, uint32_t max_height);
Daniel Vetter88548632015-12-04 09:45:48 +0100884
885 /**
886 * @set_property:
887 *
888 * This is the legacy entry point to update a property attached to the
889 * connector.
890 *
891 * Drivers implementing atomic modeset should use
892 * drm_atomic_helper_connector_set_property() to implement this hook.
893 *
894 * This callback is optional if the driver does not support any legacy
895 * driver-private properties.
896 *
897 * RETURNS:
898 *
899 * 0 on success or a negative error code on failure.
900 */
Dave Airlief453ba02008-11-07 14:05:41 -0800901 int (*set_property)(struct drm_connector *connector, struct drm_property *property,
902 uint64_t val);
Daniel Vetter88548632015-12-04 09:45:48 +0100903
904 /**
905 * @destroy:
906 *
907 * Clean up connector resources. This is called at driver unload time
908 * through drm_mode_config_cleanup(). It can also be called at runtime
909 * when a connector is being hot-unplugged for drivers that support
910 * connector hotplugging (e.g. DisplayPort MST).
911 */
Dave Airlief453ba02008-11-07 14:05:41 -0800912 void (*destroy)(struct drm_connector *connector);
Daniel Vetter144ecb92014-10-27 20:28:44 +0100913
Daniel Vetter88548632015-12-04 09:45:48 +0100914 /**
915 * @atomic_duplicate_state:
916 *
917 * Duplicate the current atomic state for this connector and return it.
918 * The core and helpers gurantee that any atomic state duplicated with
919 * this hook and still owned by the caller (i.e. not transferred to the
920 * driver by calling ->atomic_commit() from struct
921 * &drm_mode_config_funcs) will be cleaned up by calling the
922 * @atomic_destroy_state hook in this structure.
923 *
924 * Atomic drivers which don't subclass struct &drm_connector_state should use
925 * drm_atomic_helper_connector_duplicate_state(). Drivers that subclass the
926 * state structure to extend it with driver-private state should use
927 * __drm_atomic_helper_connector_duplicate_state() to make sure shared state is
928 * duplicated in a consistent fashion across drivers.
929 *
930 * It is an error to call this hook before connector->state has been
931 * initialized correctly.
932 *
933 * NOTE:
934 *
935 * If the duplicate state references refcounted resources this hook must
936 * acquire a reference for each of them. The driver must release these
937 * references again in @atomic_destroy_state.
938 *
939 * RETURNS:
940 *
941 * Duplicated atomic state or NULL when the allocation failed.
942 */
Daniel Vetter144ecb92014-10-27 20:28:44 +0100943 struct drm_connector_state *(*atomic_duplicate_state)(struct drm_connector *connector);
Daniel Vetter88548632015-12-04 09:45:48 +0100944
945 /**
946 * @atomic_destroy_state:
947 *
948 * Destroy a state duplicated with @atomic_duplicate_state and release
949 * or unreference all resources it references
950 */
Daniel Vetter144ecb92014-10-27 20:28:44 +0100951 void (*atomic_destroy_state)(struct drm_connector *connector,
Daniel Vettercc4ceb42014-07-25 21:30:38 +0200952 struct drm_connector_state *state);
Daniel Vetter88548632015-12-04 09:45:48 +0100953
954 /**
955 * @atomic_set_property:
956 *
957 * Decode a driver-private property value and store the decoded value
958 * into the passed-in state structure. Since the atomic core decodes all
959 * standardized properties (even for extensions beyond the core set of
960 * properties which might not be implemented by all drivers) this
961 * requires drivers to subclass the state structure.
962 *
963 * Such driver-private properties should really only be implemented for
964 * truly hardware/vendor specific state. Instead it is preferred to
965 * standardize atomic extension and decode the properties used to expose
966 * such an extension in the core.
967 *
968 * Do not call this function directly, use
969 * drm_atomic_connector_set_property() instead.
970 *
971 * This callback is optional if the driver does not support any
972 * driver-private atomic properties.
973 *
974 * NOTE:
975 *
976 * This function is called in the state assembly phase of atomic
977 * modesets, which can be aborted for any reason (including on
978 * userspace's request to just check whether a configuration would be
979 * possible). Drivers MUST NOT touch any persistent state (hardware or
980 * software) or data structures except the passed in @state parameter.
981 *
982 * Also since userspace controls in which order properties are set this
983 * function must not do any input validation (since the state update is
984 * incomplete and hence likely inconsistent). Instead any such input
985 * validation must be done in the various atomic_check callbacks.
986 *
987 * RETURNS:
988 *
989 * 0 if the property has been found, -EINVAL if the property isn't
990 * implemented by the driver (which shouldn't ever happen, the core only
991 * asks for properties attached to this connector). No other validation
992 * is allowed by the driver. The core already checks that the property
993 * value is within the range (integer, valid enum value, ...) the driver
994 * set when registering the property.
995 */
Daniel Vetter144ecb92014-10-27 20:28:44 +0100996 int (*atomic_set_property)(struct drm_connector *connector,
997 struct drm_connector_state *state,
998 struct drm_property *property,
999 uint64_t val);
Daniel Vetter88548632015-12-04 09:45:48 +01001000
1001 /**
1002 * @atomic_get_property:
1003 *
1004 * Reads out the decoded driver-private property. This is used to
Daniel Vetterc6b0ca32015-12-04 09:46:01 +01001005 * implement the GETCONNECTOR IOCTL.
Daniel Vetter88548632015-12-04 09:45:48 +01001006 *
1007 * Do not call this function directly, use
1008 * drm_atomic_connector_get_property() instead.
1009 *
1010 * This callback is optional if the driver does not support any
1011 * driver-private atomic properties.
1012 *
1013 * RETURNS:
1014 *
1015 * 0 on success, -EINVAL if the property isn't implemented by the
1016 * driver (which shouldn't ever happen, the core only asks for
1017 * properties attached to this connector).
1018 */
Rob Clarkac9c9252014-12-18 16:01:47 -05001019 int (*atomic_get_property)(struct drm_connector *connector,
1020 const struct drm_connector_state *state,
1021 struct drm_property *property,
1022 uint64_t *val);
Dave Airlief453ba02008-11-07 14:05:41 -08001023};
1024
Jesse Barnes6c3db922011-11-07 12:03:16 -08001025/**
Daniel Vetter3bf04012014-10-27 16:54:27 +01001026 * struct drm_encoder_funcs - encoder controls
Jesse Barnes6c3db922011-11-07 12:03:16 -08001027 *
1028 * Encoders sit between CRTCs and connectors.
1029 */
Dave Airlief453ba02008-11-07 14:05:41 -08001030struct drm_encoder_funcs {
Daniel Vetter88548632015-12-04 09:45:48 +01001031 /**
1032 * @reset:
1033 *
1034 * Reset encoder hardware and software state to off. This function isn't
1035 * called by the core directly, only through drm_mode_config_reset().
1036 * It's not a helper hook only for historical reasons.
1037 */
Chris Wilsoneb033552011-01-24 15:11:08 +00001038 void (*reset)(struct drm_encoder *encoder);
Daniel Vetter88548632015-12-04 09:45:48 +01001039
1040 /**
1041 * @destroy:
1042 *
1043 * Clean up encoder resources. This is only called at driver unload time
1044 * through drm_mode_config_cleanup() since an encoder cannot be
1045 * hotplugged in DRM.
1046 */
Dave Airlief453ba02008-11-07 14:05:41 -08001047 void (*destroy)(struct drm_encoder *encoder);
1048};
1049
Ben Skeggsafe887d2012-01-12 16:00:57 +10001050#define DRM_CONNECTOR_MAX_ENCODER 3
Dave Airlief453ba02008-11-07 14:05:41 -08001051
1052/**
Daniel Vetter3bf04012014-10-27 16:54:27 +01001053 * struct drm_encoder - central DRM encoder structure
Jesse Barnesdb3e4492011-11-07 12:03:17 -08001054 * @dev: parent DRM device
1055 * @head: list management
1056 * @base: base KMS object
Jani Nikulae5748942014-05-14 16:58:20 +03001057 * @name: encoder name
Jesse Barnesdb3e4492011-11-07 12:03:17 -08001058 * @encoder_type: one of the %DRM_MODE_ENCODER_<foo> types in drm_mode.h
1059 * @possible_crtcs: bitmask of potential CRTC bindings
1060 * @possible_clones: bitmask of potential sibling encoders for cloning
1061 * @crtc: currently bound CRTC
Sean Paul3b336ec2013-08-14 16:47:37 -04001062 * @bridge: bridge associated to the encoder
Jesse Barnesdb3e4492011-11-07 12:03:17 -08001063 * @funcs: control functions
1064 * @helper_private: mid-layer private data
1065 *
1066 * CRTCs drive pixels to encoders, which convert them into signals
1067 * appropriate for a given connector or set of connectors.
Dave Airlief453ba02008-11-07 14:05:41 -08001068 */
1069struct drm_encoder {
1070 struct drm_device *dev;
1071 struct list_head head;
1072
1073 struct drm_mode_object base;
Jani Nikulae5748942014-05-14 16:58:20 +03001074 char *name;
Dave Airlief453ba02008-11-07 14:05:41 -08001075 int encoder_type;
1076 uint32_t possible_crtcs;
1077 uint32_t possible_clones;
1078
1079 struct drm_crtc *crtc;
Sean Paul3b336ec2013-08-14 16:47:37 -04001080 struct drm_bridge *bridge;
Dave Airlief453ba02008-11-07 14:05:41 -08001081 const struct drm_encoder_funcs *funcs;
Daniel Vetter4490d4c2015-12-04 09:45:45 +01001082 const struct drm_encoder_helper_funcs *helper_private;
Dave Airlief453ba02008-11-07 14:05:41 -08001083};
1084
Dave Airlieeb1f8e42010-05-07 06:42:51 +00001085/* should we poll this connector for connects and disconnects */
1086/* hot plug detectable */
1087#define DRM_CONNECTOR_POLL_HPD (1 << 0)
1088/* poll for connections */
1089#define DRM_CONNECTOR_POLL_CONNECT (1 << 1)
1090/* can cleanly poll for disconnections without flickering the screen */
1091/* DACs should rarely do this without a lot of testing */
1092#define DRM_CONNECTOR_POLL_DISCONNECT (1 << 2)
1093
Wu Fengguang76adaa342011-09-05 14:23:20 +08001094#define MAX_ELD_BYTES 128
1095
Dave Airlief453ba02008-11-07 14:05:41 -08001096/**
Daniel Vetter3bf04012014-10-27 16:54:27 +01001097 * struct drm_connector - central DRM connector control structure
Jesse Barnes72252542011-11-07 12:03:18 -08001098 * @dev: parent DRM device
1099 * @kdev: kernel device for sysfs attributes
1100 * @attr: sysfs attributes
1101 * @head: list management
1102 * @base: base KMS object
Jani Nikula2abdd312014-05-14 16:58:19 +03001103 * @name: connector name
Jesse Barnes72252542011-11-07 12:03:18 -08001104 * @connector_type: one of the %DRM_MODE_CONNECTOR_<foo> types from drm_mode.h
1105 * @connector_type_id: index into connector type enum
Dave Airlief453ba02008-11-07 14:05:41 -08001106 * @interlace_allowed: can this connector handle interlaced modes?
1107 * @doublescan_allowed: can this connector handle doublescan?
Daniel Vetter2c0c33d2014-10-27 20:19:38 +01001108 * @stereo_allowed: can this connector handle stereo modes?
Jesse Barnes72252542011-11-07 12:03:18 -08001109 * @modes: modes available on this connector (from fill_modes() + user)
1110 * @status: one of the drm_connector_status enums (connected, not, or unknown)
1111 * @probed_modes: list of modes derived directly from the display
1112 * @display_info: information about attached display (e.g. from EDID)
Dave Airlief453ba02008-11-07 14:05:41 -08001113 * @funcs: connector control functions
Jesse Barnes72252542011-11-07 12:03:18 -08001114 * @edid_blob_ptr: DRM property containing EDID if present
Paulo Zanoni7e3bdf42012-05-15 18:09:01 -03001115 * @properties: property tracking for this connector
Daniel Vetter2c0c33d2014-10-27 20:19:38 +01001116 * @path_blob_ptr: DRM blob property data for the DP MST path property
Jesse Barnes72252542011-11-07 12:03:18 -08001117 * @polled: a %DRM_CONNECTOR_POLL_<foo> value for core driven polling
1118 * @dpms: current dpms state
1119 * @helper_private: mid-layer private data
Daniel Vetter2c0c33d2014-10-27 20:19:38 +01001120 * @cmdline_mode: mode line parsed from the kernel cmdline for this connector
Jesse Barnes72252542011-11-07 12:03:18 -08001121 * @force: a %DRM_FORCE_<foo> state for forced mode sets
Daniel Vetter2c0c33d2014-10-27 20:19:38 +01001122 * @override_edid: has the EDID been overwritten through debugfs for testing?
Jesse Barnes72252542011-11-07 12:03:18 -08001123 * @encoder_ids: valid encoders for this connector
1124 * @encoder: encoder driving this connector, if any
1125 * @eld: EDID-like data, if present
1126 * @dvi_dual: dual link DVI, if found
1127 * @max_tmds_clock: max clock rate, if found
1128 * @latency_present: AV delay info from ELD, if found
1129 * @video_latency: video latency info from ELD, if found
1130 * @audio_latency: audio latency info from ELD, if found
1131 * @null_edid_counter: track sinks that give us all zeros for the EDID
Daniel Vetter2c0c33d2014-10-27 20:19:38 +01001132 * @bad_edid_counter: track sinks that give us an EDID with invalid checksum
Daniel Vetterac6f2e22015-05-08 16:15:41 +02001133 * @edid_corrupt: indicates whether the last read EDID was corrupt
Daniel Vetter2c0c33d2014-10-27 20:19:38 +01001134 * @debugfs_entry: debugfs directory for this connector
Daniel Vetter144ecb92014-10-27 20:28:44 +01001135 * @state: current atomic state for this connector
Dave Airlie40d9b042014-10-20 16:29:33 +10001136 * @has_tile: is this connector connected to a tiled monitor
1137 * @tile_group: tile group for the connected monitor
1138 * @tile_is_single_monitor: whether the tile is one monitor housing
1139 * @num_h_tile: number of horizontal tiles in the tile group
1140 * @num_v_tile: number of vertical tiles in the tile group
1141 * @tile_h_loc: horizontal location of this tile
1142 * @tile_v_loc: vertical location of this tile
1143 * @tile_h_size: horizontal size of this tile.
1144 * @tile_v_size: vertical size of this tile.
Dave Airlief453ba02008-11-07 14:05:41 -08001145 *
1146 * Each connector may be connected to one or more CRTCs, or may be clonable by
1147 * another connector if they can share a CRTC. Each connector also has a specific
1148 * position in the broader display (referred to as a 'screen' though it could
1149 * span multiple monitors).
1150 */
1151struct drm_connector {
1152 struct drm_device *dev;
Dave Airlie5bdebb12013-10-11 14:07:25 +10001153 struct device *kdev;
Dave Airlief453ba02008-11-07 14:05:41 -08001154 struct device_attribute *attr;
1155 struct list_head head;
1156
1157 struct drm_mode_object base;
1158
Jani Nikula2abdd312014-05-14 16:58:19 +03001159 char *name;
Dave Airlief453ba02008-11-07 14:05:41 -08001160 int connector_type;
1161 int connector_type_id;
1162 bool interlace_allowed;
1163 bool doublescan_allowed;
Damien Lespiau560a0672013-09-25 16:45:29 +01001164 bool stereo_allowed;
Dave Airlief453ba02008-11-07 14:05:41 -08001165 struct list_head modes; /* list of modes on this connector */
1166
Dave Airlief453ba02008-11-07 14:05:41 -08001167 enum drm_connector_status status;
1168
1169 /* these are modes added by probing with DDC or the BIOS */
1170 struct list_head probed_modes;
1171
1172 struct drm_display_info display_info;
1173 const struct drm_connector_funcs *funcs;
1174
Dave Airlief453ba02008-11-07 14:05:41 -08001175 struct drm_property_blob *edid_blob_ptr;
Paulo Zanoni7e3bdf42012-05-15 18:09:01 -03001176 struct drm_object_properties properties;
Dave Airlief453ba02008-11-07 14:05:41 -08001177
Dave Airlie43aba7e2014-06-05 14:01:31 +10001178 struct drm_property_blob *path_blob_ptr;
1179
Dave Airlie6f134d72014-10-20 16:30:50 +10001180 struct drm_property_blob *tile_blob_ptr;
1181
Dave Airlieeb1f8e42010-05-07 06:42:51 +00001182 uint8_t polled; /* DRM_CONNECTOR_POLL_* */
1183
Keith Packardc9fb15f2009-05-30 20:42:28 -07001184 /* requested DPMS state */
1185 int dpms;
1186
Daniel Vetter4490d4c2015-12-04 09:45:45 +01001187 const struct drm_connector_helper_funcs *helper_private;
Dave Airlief453ba02008-11-07 14:05:41 -08001188
Dave Airlied50ba252009-09-23 14:44:08 +10001189 /* forced on connector */
Chris Wilsoneaf99c72014-08-06 10:08:32 +02001190 struct drm_cmdline_mode cmdline_mode;
Dave Airlied50ba252009-09-23 14:44:08 +10001191 enum drm_connector_force force;
Thomas Wood4cf2b282014-06-18 17:52:33 +01001192 bool override_edid;
Dave Airlief453ba02008-11-07 14:05:41 -08001193 uint32_t encoder_ids[DRM_CONNECTOR_MAX_ENCODER];
Dave Airlief453ba02008-11-07 14:05:41 -08001194 struct drm_encoder *encoder; /* currently active encoder */
Dave Airlie4a9a8b72011-06-14 06:13:55 +00001195
Wu Fengguang76adaa342011-09-05 14:23:20 +08001196 /* EDID bits */
1197 uint8_t eld[MAX_ELD_BYTES];
1198 bool dvi_dual;
1199 int max_tmds_clock; /* in MHz */
1200 bool latency_present[2];
1201 int video_latency[2]; /* [0]: progressive, [1]: interlaced */
1202 int audio_latency[2];
Dave Airlie4a9a8b72011-06-14 06:13:55 +00001203 int null_edid_counter; /* needed to workaround some HW bugs where we get all 0s */
Jerome Glisse0b2443e2012-08-09 11:25:51 -04001204 unsigned bad_edid_counter;
Thomas Wood30f65702014-06-18 17:52:32 +01001205
Todd Previte6ba2bd32015-04-21 11:09:41 -07001206 /* Flag for raw EDID header corruption - used in Displayport
1207 * compliance testing - * Displayport Link CTS Core 1.2 rev1.1 4.2.2.6
1208 */
1209 bool edid_corrupt;
1210
Thomas Wood30f65702014-06-18 17:52:32 +01001211 struct dentry *debugfs_entry;
Daniel Vetter144ecb92014-10-27 20:28:44 +01001212
1213 struct drm_connector_state *state;
Dave Airlie40d9b042014-10-20 16:29:33 +10001214
1215 /* DisplayID bits */
1216 bool has_tile;
1217 struct drm_tile_group *tile_group;
1218 bool tile_is_single_monitor;
1219
1220 uint8_t num_h_tile, num_v_tile;
1221 uint8_t tile_h_loc, tile_v_loc;
1222 uint16_t tile_h_size, tile_v_size;
Dave Airlief453ba02008-11-07 14:05:41 -08001223};
1224
1225/**
Daniel Vetter144ecb92014-10-27 20:28:44 +01001226 * struct drm_plane_state - mutable plane state
Daniel Vetter07cc0ef2014-11-27 15:49:39 +01001227 * @plane: backpointer to the plane
Daniel Vetter144ecb92014-10-27 20:28:44 +01001228 * @crtc: currently bound CRTC, NULL if disabled
Daniel Vettercc4ceb42014-07-25 21:30:38 +02001229 * @fb: currently bound framebuffer
Daniel Vettere2330f02014-10-29 11:34:56 +01001230 * @fence: optional fence to wait for before scanning out @fb
Daniel Vetter144ecb92014-10-27 20:28:44 +01001231 * @crtc_x: left position of visible portion of plane on crtc
1232 * @crtc_y: upper position of visible portion of plane on crtc
1233 * @crtc_w: width of visible portion of plane on crtc
1234 * @crtc_h: height of visible portion of plane on crtc
1235 * @src_x: left position of visible portion of plane within
1236 * plane (in 16.16)
1237 * @src_y: upper position of visible portion of plane within
1238 * plane (in 16.16)
1239 * @src_w: width of visible portion of plane (in 16.16)
1240 * @src_h: height of visible portion of plane (in 16.16)
1241 * @state: backpointer to global drm_atomic_state
1242 */
1243struct drm_plane_state {
Daniel Vetter07cc0ef2014-11-27 15:49:39 +01001244 struct drm_plane *plane;
1245
Rob Clark6ddd3882014-11-21 15:28:31 -05001246 struct drm_crtc *crtc; /* do not write directly, use drm_atomic_set_crtc_for_plane() */
1247 struct drm_framebuffer *fb; /* do not write directly, use drm_atomic_set_fb_for_plane() */
Daniel Vettere2330f02014-10-29 11:34:56 +01001248 struct fence *fence;
Daniel Vetter144ecb92014-10-27 20:28:44 +01001249
1250 /* Signed dest location allows it to be partially off screen */
1251 int32_t crtc_x, crtc_y;
1252 uint32_t crtc_w, crtc_h;
1253
1254 /* Source values are 16.16 fixed point */
1255 uint32_t src_x, src_y;
1256 uint32_t src_h, src_w;
1257
Matt Roper1da30622015-01-21 16:35:40 -08001258 /* Plane rotation */
1259 unsigned int rotation;
1260
Daniel Vetter144ecb92014-10-27 20:28:44 +01001261 struct drm_atomic_state *state;
1262};
1263
1264
1265/**
Daniel Vetter3bf04012014-10-27 16:54:27 +01001266 * struct drm_plane_funcs - driver plane control functions
Jesse Barnes8cf5c912011-11-14 14:51:27 -08001267 */
1268struct drm_plane_funcs {
Daniel Vetter88548632015-12-04 09:45:48 +01001269 /**
1270 * @update_plane:
1271 *
1272 * This is the legacy entry point to enable and configure the plane for
1273 * the given CRTC and framebuffer. It is never called to disable the
1274 * plane, i.e. the passed-in crtc and fb paramters are never NULL.
1275 *
1276 * The source rectangle in frame buffer memory coordinates is given by
1277 * the src_x, src_y, src_w and src_h parameters (as 16.16 fixed point
1278 * values). Devices that don't support subpixel plane coordinates can
1279 * ignore the fractional part.
1280 *
1281 * The destination rectangle in CRTC coordinates is given by the
1282 * crtc_x, crtc_y, crtc_w and crtc_h parameters (as integer values).
1283 * Devices scale the source rectangle to the destination rectangle. If
1284 * scaling is not supported, and the source rectangle size doesn't match
1285 * the destination rectangle size, the driver must return a
1286 * -<errorname>EINVAL</errorname> error.
1287 *
1288 * Drivers implementing atomic modeset should use
1289 * drm_atomic_helper_update_plane() to implement this hook.
1290 *
1291 * RETURNS:
1292 *
1293 * 0 on success or a negative error code on failure.
1294 */
Jesse Barnes8cf5c912011-11-14 14:51:27 -08001295 int (*update_plane)(struct drm_plane *plane,
1296 struct drm_crtc *crtc, struct drm_framebuffer *fb,
1297 int crtc_x, int crtc_y,
1298 unsigned int crtc_w, unsigned int crtc_h,
1299 uint32_t src_x, uint32_t src_y,
1300 uint32_t src_w, uint32_t src_h);
Daniel Vetter88548632015-12-04 09:45:48 +01001301
1302 /**
1303 * @disable_plane:
1304 *
1305 * This is the legacy entry point to disable the plane. The DRM core
Daniel Vetterc6b0ca32015-12-04 09:46:01 +01001306 * calls this method in response to a DRM_IOCTL_MODE_SETPLANE IOCTL call
Daniel Vetter88548632015-12-04 09:45:48 +01001307 * with the frame buffer ID set to 0. Disabled planes must not be
1308 * processed by the CRTC.
1309 *
1310 * Drivers implementing atomic modeset should use
1311 * drm_atomic_helper_disable_plane() to implement this hook.
1312 *
1313 * RETURNS:
1314 *
1315 * 0 on success or a negative error code on failure.
1316 */
Jesse Barnes8cf5c912011-11-14 14:51:27 -08001317 int (*disable_plane)(struct drm_plane *plane);
Daniel Vetter88548632015-12-04 09:45:48 +01001318
1319 /**
1320 * @destroy:
1321 *
1322 * Clean up plane resources. This is only called at driver unload time
1323 * through drm_mode_config_cleanup() since a plane cannot be hotplugged
1324 * in DRM.
1325 */
Jesse Barnes8cf5c912011-11-14 14:51:27 -08001326 void (*destroy)(struct drm_plane *plane);
Daniel Vetter88548632015-12-04 09:45:48 +01001327
1328 /**
1329 * @reset:
1330 *
1331 * Reset plane hardware and software state to off. This function isn't
1332 * called by the core directly, only through drm_mode_config_reset().
1333 * It's not a helper hook only for historical reasons.
1334 *
1335 * Atomic drivers can use drm_atomic_helper_plane_reset() to reset
1336 * atomic state using this hook.
1337 */
Daniel Vetter2a0d7cf2014-07-29 15:32:37 +02001338 void (*reset)(struct drm_plane *plane);
Rob Clark4d939142012-05-17 02:23:27 -06001339
Daniel Vetter88548632015-12-04 09:45:48 +01001340 /**
1341 * @set_property:
1342 *
1343 * This is the legacy entry point to update a property attached to the
1344 * plane.
1345 *
1346 * Drivers implementing atomic modeset should use
1347 * drm_atomic_helper_plane_set_property() to implement this hook.
1348 *
1349 * This callback is optional if the driver does not support any legacy
1350 * driver-private properties.
1351 *
1352 * RETURNS:
1353 *
1354 * 0 on success or a negative error code on failure.
1355 */
Rob Clark4d939142012-05-17 02:23:27 -06001356 int (*set_property)(struct drm_plane *plane,
1357 struct drm_property *property, uint64_t val);
Daniel Vetter144ecb92014-10-27 20:28:44 +01001358
Daniel Vetter88548632015-12-04 09:45:48 +01001359 /**
1360 * @atomic_duplicate_state:
1361 *
1362 * Duplicate the current atomic state for this plane and return it.
1363 * The core and helpers gurantee that any atomic state duplicated with
1364 * this hook and still owned by the caller (i.e. not transferred to the
1365 * driver by calling ->atomic_commit() from struct
1366 * &drm_mode_config_funcs) will be cleaned up by calling the
1367 * @atomic_destroy_state hook in this structure.
1368 *
1369 * Atomic drivers which don't subclass struct &drm_plane_state should use
1370 * drm_atomic_helper_plane_duplicate_state(). Drivers that subclass the
1371 * state structure to extend it with driver-private state should use
1372 * __drm_atomic_helper_plane_duplicate_state() to make sure shared state is
1373 * duplicated in a consistent fashion across drivers.
1374 *
1375 * It is an error to call this hook before plane->state has been
1376 * initialized correctly.
1377 *
1378 * NOTE:
1379 *
1380 * If the duplicate state references refcounted resources this hook must
1381 * acquire a reference for each of them. The driver must release these
1382 * references again in @atomic_destroy_state.
1383 *
1384 * RETURNS:
1385 *
1386 * Duplicated atomic state or NULL when the allocation failed.
1387 */
Daniel Vetter144ecb92014-10-27 20:28:44 +01001388 struct drm_plane_state *(*atomic_duplicate_state)(struct drm_plane *plane);
Daniel Vetter88548632015-12-04 09:45:48 +01001389
1390 /**
1391 * @atomic_destroy_state:
1392 *
1393 * Destroy a state duplicated with @atomic_duplicate_state and release
1394 * or unreference all resources it references
1395 */
Daniel Vetter144ecb92014-10-27 20:28:44 +01001396 void (*atomic_destroy_state)(struct drm_plane *plane,
Daniel Vettercc4ceb42014-07-25 21:30:38 +02001397 struct drm_plane_state *state);
Daniel Vetter88548632015-12-04 09:45:48 +01001398
1399 /**
1400 * @atomic_set_property:
1401 *
1402 * Decode a driver-private property value and store the decoded value
1403 * into the passed-in state structure. Since the atomic core decodes all
1404 * standardized properties (even for extensions beyond the core set of
1405 * properties which might not be implemented by all drivers) this
1406 * requires drivers to subclass the state structure.
1407 *
1408 * Such driver-private properties should really only be implemented for
1409 * truly hardware/vendor specific state. Instead it is preferred to
1410 * standardize atomic extension and decode the properties used to expose
1411 * such an extension in the core.
1412 *
1413 * Do not call this function directly, use
1414 * drm_atomic_plane_set_property() instead.
1415 *
1416 * This callback is optional if the driver does not support any
1417 * driver-private atomic properties.
1418 *
1419 * NOTE:
1420 *
1421 * This function is called in the state assembly phase of atomic
1422 * modesets, which can be aborted for any reason (including on
1423 * userspace's request to just check whether a configuration would be
1424 * possible). Drivers MUST NOT touch any persistent state (hardware or
1425 * software) or data structures except the passed in @state parameter.
1426 *
1427 * Also since userspace controls in which order properties are set this
1428 * function must not do any input validation (since the state update is
1429 * incomplete and hence likely inconsistent). Instead any such input
1430 * validation must be done in the various atomic_check callbacks.
1431 *
1432 * RETURNS:
1433 *
1434 * 0 if the property has been found, -EINVAL if the property isn't
1435 * implemented by the driver (which shouldn't ever happen, the core only
1436 * asks for properties attached to this plane). No other validation is
1437 * allowed by the driver. The core already checks that the property
1438 * value is within the range (integer, valid enum value, ...) the driver
1439 * set when registering the property.
1440 */
Daniel Vetter144ecb92014-10-27 20:28:44 +01001441 int (*atomic_set_property)(struct drm_plane *plane,
1442 struct drm_plane_state *state,
1443 struct drm_property *property,
1444 uint64_t val);
Daniel Vetter88548632015-12-04 09:45:48 +01001445
1446 /**
1447 * @atomic_get_property:
1448 *
1449 * Reads out the decoded driver-private property. This is used to
Daniel Vetterc6b0ca32015-12-04 09:46:01 +01001450 * implement the GETPLANE IOCTL.
Daniel Vetter88548632015-12-04 09:45:48 +01001451 *
1452 * Do not call this function directly, use
1453 * drm_atomic_plane_get_property() instead.
1454 *
1455 * This callback is optional if the driver does not support any
1456 * driver-private atomic properties.
1457 *
1458 * RETURNS:
1459 *
1460 * 0 on success, -EINVAL if the property isn't implemented by the
1461 * driver (which should never happen, the core only asks for
1462 * properties attached to this plane).
1463 */
Rob Clarkac9c9252014-12-18 16:01:47 -05001464 int (*atomic_get_property)(struct drm_plane *plane,
1465 const struct drm_plane_state *state,
1466 struct drm_property *property,
1467 uint64_t *val);
Jesse Barnes8cf5c912011-11-14 14:51:27 -08001468};
1469
Matt Ropere27dde32014-04-01 15:22:30 -07001470enum drm_plane_type {
1471 DRM_PLANE_TYPE_OVERLAY,
1472 DRM_PLANE_TYPE_PRIMARY,
1473 DRM_PLANE_TYPE_CURSOR,
1474};
1475
Daniel Vetter88548632015-12-04 09:45:48 +01001476
Jesse Barnes8cf5c912011-11-14 14:51:27 -08001477/**
Daniel Vetter3bf04012014-10-27 16:54:27 +01001478 * struct drm_plane - central DRM plane control structure
Jesse Barnes8cf5c912011-11-14 14:51:27 -08001479 * @dev: DRM device this plane belongs to
1480 * @head: for list management
1481 * @base: base mode object
1482 * @possible_crtcs: pipes this plane can be bound to
1483 * @format_types: array of formats supported by this plane
1484 * @format_count: number of formats supported
Laurent Pinchart7eb5f302015-03-09 10:41:07 +02001485 * @format_default: driver hasn't supplied supported formats for the plane
Jesse Barnes8cf5c912011-11-14 14:51:27 -08001486 * @crtc: currently bound CRTC
1487 * @fb: currently bound fb
Daniel Vetter2c0c33d2014-10-27 20:19:38 +01001488 * @old_fb: Temporary tracking of the old fb while a modeset is ongoing. Used by
1489 * drm_mode_set_config_internal() to implement correct refcounting.
Jesse Barnes8cf5c912011-11-14 14:51:27 -08001490 * @funcs: helper functions
Rob Clark4d939142012-05-17 02:23:27 -06001491 * @properties: property tracking for this plane
Matt Ropere27dde32014-04-01 15:22:30 -07001492 * @type: type of plane (overlay, primary, cursor)
Daniel Vetter144ecb92014-10-27 20:28:44 +01001493 * @state: current atomic state for this plane
Jesse Barnes8cf5c912011-11-14 14:51:27 -08001494 */
1495struct drm_plane {
1496 struct drm_device *dev;
1497 struct list_head head;
1498
Daniel Vetter4d02e2d2014-11-11 10:12:00 +01001499 struct drm_modeset_lock mutex;
1500
Jesse Barnes8cf5c912011-11-14 14:51:27 -08001501 struct drm_mode_object base;
1502
1503 uint32_t possible_crtcs;
1504 uint32_t *format_types;
Thierry Reding45e37432015-08-12 16:54:28 +02001505 unsigned int format_count;
Laurent Pinchart7eb5f302015-03-09 10:41:07 +02001506 bool format_default;
Jesse Barnes8cf5c912011-11-14 14:51:27 -08001507
1508 struct drm_crtc *crtc;
1509 struct drm_framebuffer *fb;
1510
Daniel Vetter3d30a592014-07-27 13:42:42 +02001511 struct drm_framebuffer *old_fb;
1512
Jesse Barnes8cf5c912011-11-14 14:51:27 -08001513 const struct drm_plane_funcs *funcs;
Rob Clark4d939142012-05-17 02:23:27 -06001514
1515 struct drm_object_properties properties;
Matt Ropere27dde32014-04-01 15:22:30 -07001516
1517 enum drm_plane_type type;
Daniel Vetter144ecb92014-10-27 20:28:44 +01001518
Daniel Vetter4490d4c2015-12-04 09:45:45 +01001519 const struct drm_plane_helper_funcs *helper_private;
Daniel Vetterc2fcd272014-11-05 00:14:14 +01001520
Daniel Vetter144ecb92014-10-27 20:28:44 +01001521 struct drm_plane_state *state;
Jesse Barnes8cf5c912011-11-14 14:51:27 -08001522};
1523
1524/**
Daniel Vetter3bf04012014-10-27 16:54:27 +01001525 * struct drm_bridge_funcs - drm_bridge control functions
Ajay Kumar3d3f8b12015-01-20 22:08:44 +05301526 * @attach: Called during drm_bridge_attach
Sean Paul3b336ec2013-08-14 16:47:37 -04001527 */
1528struct drm_bridge_funcs {
Ajay Kumar3d3f8b12015-01-20 22:08:44 +05301529 int (*attach)(struct drm_bridge *bridge);
Daniel Vetterda024fe2015-12-04 09:45:47 +01001530
1531 /**
1532 * @mode_fixup:
1533 *
1534 * This callback is used to validate and adjust a mode. The paramater
1535 * mode is the display mode that should be fed to the next element in
1536 * the display chain, either the final &drm_connector or the next
1537 * &drm_bridge. The parameter adjusted_mode is the input mode the bridge
1538 * requires. It can be modified by this callback and does not need to
1539 * match mode.
1540 *
1541 * This is the only hook that allows a bridge to reject a modeset. If
1542 * this function passes all other callbacks must succeed for this
1543 * configuration.
1544 *
1545 * NOTE:
1546 *
1547 * This function is called in the check phase of atomic modesets, which
1548 * can be aborted for any reason (including on userspace's request to
1549 * just check whether a configuration would be possible). Drivers MUST
1550 * NOT touch any persistent state (hardware or software) or data
Daniel Vetter88548632015-12-04 09:45:48 +01001551 * structures except the passed in @state parameter.
Daniel Vetterda024fe2015-12-04 09:45:47 +01001552 *
1553 * RETURNS:
1554 *
1555 * True if an acceptable configuration is possible, false if the modeset
1556 * operation should be rejected.
1557 */
Sean Paul3b336ec2013-08-14 16:47:37 -04001558 bool (*mode_fixup)(struct drm_bridge *bridge,
1559 const struct drm_display_mode *mode,
1560 struct drm_display_mode *adjusted_mode);
Daniel Vetterda024fe2015-12-04 09:45:47 +01001561 /**
1562 * @disable:
1563 *
1564 * This callback should disable the bridge. It is called right before
1565 * the preceding element in the display pipe is disabled. If the
1566 * preceding element is a bridge this means it's called before that
1567 * bridge's ->disable() function. If the preceding element is a
1568 * &drm_encoder it's called right before the encoder's ->disable(),
1569 * ->prepare() or ->dpms() hook from struct &drm_encoder_helper_funcs.
1570 *
1571 * The bridge can assume that the display pipe (i.e. clocks and timing
1572 * signals) feeding it is still running when this callback is called.
1573 */
Sean Paul3b336ec2013-08-14 16:47:37 -04001574 void (*disable)(struct drm_bridge *bridge);
Daniel Vetterda024fe2015-12-04 09:45:47 +01001575
1576 /**
1577 * @post_disable:
1578 *
1579 * This callback should disable the bridge. It is called right after
1580 * the preceding element in the display pipe is disabled. If the
1581 * preceding element is a bridge this means it's called after that
1582 * bridge's ->post_disable() function. If the preceding element is a
1583 * &drm_encoder it's called right after the encoder's ->disable(),
1584 * ->prepare() or ->dpms() hook from struct &drm_encoder_helper_funcs.
1585 *
1586 * The bridge must assume that the display pipe (i.e. clocks and timing
1587 * singals) feeding it is no longer running when this callback is
1588 * called.
1589 */
Sean Paul3b336ec2013-08-14 16:47:37 -04001590 void (*post_disable)(struct drm_bridge *bridge);
Daniel Vetterda024fe2015-12-04 09:45:47 +01001591
1592 /**
1593 * @mode_set:
1594 *
1595 * This callback should set the given mode on the bridge. It is called
1596 * after the ->mode_set() callback for the preceding element in the
1597 * display pipeline has been called already. The display pipe (i.e.
1598 * clocks and timing signals) is off when this function is called.
1599 */
Sean Paul3b336ec2013-08-14 16:47:37 -04001600 void (*mode_set)(struct drm_bridge *bridge,
1601 struct drm_display_mode *mode,
1602 struct drm_display_mode *adjusted_mode);
Daniel Vetterda024fe2015-12-04 09:45:47 +01001603 /**
1604 * @pre_enable:
1605 *
1606 * This callback should enable the bridge. It is called right before
1607 * the preceding element in the display pipe is enabled. If the
1608 * preceding element is a bridge this means it's called before that
1609 * bridge's ->pre_enable() function. If the preceding element is a
1610 * &drm_encoder it's called right before the encoder's ->enable(),
1611 * ->commit() or ->dpms() hook from struct &drm_encoder_helper_funcs.
1612 *
1613 * The display pipe (i.e. clocks and timing signals) feeding this bridge
1614 * will not yet be running when this callback is called. The bridge must
1615 * not enable the display link feeding the next bridge in the chain (if
1616 * there is one) when this callback is called.
1617 */
Sean Paul3b336ec2013-08-14 16:47:37 -04001618 void (*pre_enable)(struct drm_bridge *bridge);
Daniel Vetterda024fe2015-12-04 09:45:47 +01001619
1620 /**
1621 * @enable:
1622 *
1623 * This callback should enable the bridge. It is called right after
1624 * the preceding element in the display pipe is enabled. If the
1625 * preceding element is a bridge this means it's called after that
1626 * bridge's ->enable() function. If the preceding element is a
1627 * &drm_encoder it's called right after the encoder's ->enable(),
1628 * ->commit() or ->dpms() hook from struct &drm_encoder_helper_funcs.
1629 *
1630 * The bridge can assume that the display pipe (i.e. clocks and timing
1631 * signals) feeding it is running when this callback is called. This
1632 * callback must enable the display link feeding the next bridge in the
1633 * chain if there is one.
1634 */
Sean Paul3b336ec2013-08-14 16:47:37 -04001635 void (*enable)(struct drm_bridge *bridge);
Sean Paul3b336ec2013-08-14 16:47:37 -04001636};
1637
1638/**
Daniel Vetter3bf04012014-10-27 16:54:27 +01001639 * struct drm_bridge - central DRM bridge control structure
Sean Paul3b336ec2013-08-14 16:47:37 -04001640 * @dev: DRM device this bridge belongs to
Archit Taneja862e6862015-05-21 11:03:16 +05301641 * @encoder: encoder to which this bridge is connected
1642 * @next: the next bridge in the encoder chain
Ajay Kumar3d3f8b12015-01-20 22:08:44 +05301643 * @of_node: device node pointer to the bridge
1644 * @list: to keep track of all added bridges
Sean Paul3b336ec2013-08-14 16:47:37 -04001645 * @funcs: control functions
1646 * @driver_private: pointer to the bridge driver's internal context
1647 */
1648struct drm_bridge {
1649 struct drm_device *dev;
Ajay Kumar3d3f8b12015-01-20 22:08:44 +05301650 struct drm_encoder *encoder;
Archit Taneja862e6862015-05-21 11:03:16 +05301651 struct drm_bridge *next;
Ajay Kumar3d3f8b12015-01-20 22:08:44 +05301652#ifdef CONFIG_OF
1653 struct device_node *of_node;
1654#endif
1655 struct list_head list;
Sean Paul3b336ec2013-08-14 16:47:37 -04001656
1657 const struct drm_bridge_funcs *funcs;
1658 void *driver_private;
1659};
1660
1661/**
Rob Clark08855fa2015-03-11 10:23:09 -04001662 * struct drm_atomic_state - the global state object for atomic updates
Daniel Vettercc4ceb42014-07-25 21:30:38 +02001663 * @dev: parent DRM device
Rob Clarkd34f20d2014-12-18 16:01:56 -05001664 * @allow_modeset: allow full modeset
Daniel Vetterc6b0ca32015-12-04 09:46:01 +01001665 * @legacy_cursor_update: hint to enforce legacy cursor IOCTL semantics
Daniel Vettercc4ceb42014-07-25 21:30:38 +02001666 * @planes: pointer to array of plane pointers
1667 * @plane_states: pointer to array of plane states pointers
1668 * @crtcs: pointer to array of CRTC pointers
1669 * @crtc_states: pointer to array of CRTC states pointers
Daniel Vetterf52b69f12014-11-19 18:38:08 +01001670 * @num_connector: size of the @connectors and @connector_states arrays
Daniel Vettercc4ceb42014-07-25 21:30:38 +02001671 * @connectors: pointer to array of connector pointers
1672 * @connector_states: pointer to array of connector states pointers
1673 * @acquire_ctx: acquire context for this atomic modeset state update
1674 */
1675struct drm_atomic_state {
1676 struct drm_device *dev;
Rob Clarkd34f20d2014-12-18 16:01:56 -05001677 bool allow_modeset : 1;
Daniel Vetterf02ad902015-01-22 16:36:23 +01001678 bool legacy_cursor_update : 1;
Daniel Vettercc4ceb42014-07-25 21:30:38 +02001679 struct drm_plane **planes;
1680 struct drm_plane_state **plane_states;
1681 struct drm_crtc **crtcs;
1682 struct drm_crtc_state **crtc_states;
Daniel Vetterf52b69f12014-11-19 18:38:08 +01001683 int num_connector;
Daniel Vettercc4ceb42014-07-25 21:30:38 +02001684 struct drm_connector **connectors;
1685 struct drm_connector_state **connector_states;
1686
1687 struct drm_modeset_acquire_ctx *acquire_ctx;
1688};
1689
1690
1691/**
Daniel Vetter3bf04012014-10-27 16:54:27 +01001692 * struct drm_mode_set - new values for a CRTC config change
Jesse Barnesef273512011-11-07 12:03:19 -08001693 * @fb: framebuffer to use for new config
1694 * @crtc: CRTC whose configuration we're about to change
1695 * @mode: mode timings to use
1696 * @x: position of this CRTC relative to @fb
1697 * @y: position of this CRTC relative to @fb
1698 * @connectors: array of connectors to drive with this CRTC if possible
1699 * @num_connectors: size of @connectors array
Dave Airlief453ba02008-11-07 14:05:41 -08001700 *
1701 * Represents a single crtc the connectors that it drives with what mode
1702 * and from which framebuffer it scans out from.
1703 *
1704 * This is used to set modes.
1705 */
1706struct drm_mode_set {
Dave Airlief453ba02008-11-07 14:05:41 -08001707 struct drm_framebuffer *fb;
1708 struct drm_crtc *crtc;
1709 struct drm_display_mode *mode;
1710
1711 uint32_t x;
1712 uint32_t y;
1713
1714 struct drm_connector **connectors;
1715 size_t num_connectors;
1716};
1717
1718/**
Jesse Barnes550cebc2011-11-07 12:03:20 -08001719 * struct drm_mode_config_funcs - basic driver provided mode setting functions
Jesse Barnes550cebc2011-11-07 12:03:20 -08001720 *
1721 * Some global (i.e. not per-CRTC, connector, etc) mode setting functions that
1722 * involve drivers.
Dave Airlief453ba02008-11-07 14:05:41 -08001723 */
1724struct drm_mode_config_funcs {
Daniel Vetter9953f412015-12-04 09:46:02 +01001725 /**
1726 * @fb_create:
1727 *
1728 * Create a new framebuffer object. The core does basic checks on the
1729 * requested metadata, but most of that is left to the driver. See
1730 * struct &drm_mode_fb_cmd2 for details.
1731 *
1732 * RETURNS:
1733 *
1734 * A new framebuffer with an initial reference count of 1 or a negative
1735 * error code encoded with ERR_PTR().
1736 */
Jesse Barnes550cebc2011-11-07 12:03:20 -08001737 struct drm_framebuffer *(*fb_create)(struct drm_device *dev,
1738 struct drm_file *file_priv,
Ville Syrjälä1eb83452015-11-11 19:11:29 +02001739 const struct drm_mode_fb_cmd2 *mode_cmd);
Daniel Vetter9953f412015-12-04 09:46:02 +01001740
1741 /**
1742 * @output_poll_changed:
1743 *
1744 * Callback used by helpers to inform the driver of output configuration
1745 * changes.
1746 *
1747 * Drivers implementing fbdev emulation with the helpers can call
1748 * drm_fb_helper_hotplug_changed from this hook to inform the fbdev
1749 * helper of output changes.
1750 *
1751 * FIXME:
1752 *
1753 * Except that there's no vtable for device-level helper callbacks
1754 * there's no reason this is a core function.
1755 */
Dave Airlieeb1f8e42010-05-07 06:42:51 +00001756 void (*output_poll_changed)(struct drm_device *dev);
Daniel Vettercc4ceb42014-07-25 21:30:38 +02001757
Daniel Vetter9953f412015-12-04 09:46:02 +01001758 /**
1759 * @atomic_check:
1760 *
1761 * This is the only hook to validate an atomic modeset update. This
1762 * function must reject any modeset and state changes which the hardware
1763 * or driver doesn't support. This includes but is of course not limited
1764 * to:
1765 *
1766 * - Checking that the modes, framebuffers, scaling and placement
1767 * requirements and so on are within the limits of the hardware.
1768 *
1769 * - Checking that any hidden shared resources are not oversubscribed.
1770 * This can be shared PLLs, shared lanes, overall memory bandwidth,
1771 * display fifo space (where shared between planes or maybe even
1772 * CRTCs).
1773 *
1774 * - Checking that virtualized resources exported to userspace are not
1775 * oversubscribed. For various reasons it can make sense to expose
1776 * more planes, crtcs or encoders than which are physically there. One
1777 * example is dual-pipe operations (which generally should be hidden
1778 * from userspace if when lockstepped in hardware, exposed otherwise),
1779 * where a plane might need 1 hardware plane (if it's just on one
1780 * pipe), 2 hardware planes (when it spans both pipes) or maybe even
1781 * shared a hardware plane with a 2nd plane (if there's a compatible
1782 * plane requested on the area handled by the other pipe).
1783 *
1784 * - Check that any transitional state is possible and that if
1785 * requested, the update can indeed be done in the vblank period
1786 * without temporarily disabling some functions.
1787 *
1788 * - Check any other constraints the driver or hardware might have.
1789 *
1790 * - This callback also needs to correctly fill out the &drm_crtc_state
1791 * in this update to make sure that drm_atomic_crtc_needs_modeset()
1792 * reflects the nature of the possible update and returns true if and
1793 * only if the update cannot be applied without tearing within one
1794 * vblank on that CRTC. The core uses that information to reject
1795 * updates which require a full modeset (i.e. blanking the screen, or
1796 * at least pausing updates for a substantial amount of time) if
1797 * userspace has disallowed that in its request.
1798 *
1799 * - The driver also does not need to repeat basic input validation
1800 * like done for the corresponding legacy entry points. The core does
1801 * that before calling this hook.
1802 *
1803 * See the documentation of @atomic_commit for an exhaustive list of
1804 * error conditions which don't have to be checked at the
1805 * ->atomic_check() stage?
1806 *
1807 * See the documentation for struct &drm_atomic_state for how exactly
1808 * an atomic modeset update is described.
1809 *
1810 * Drivers using the atomic helpers can implement this hook using
1811 * drm_atomic_helper_check(), or one of the exported sub-functions of
1812 * it.
1813 *
1814 * RETURNS:
1815 *
1816 * 0 on success or one of the below negative error codes:
1817 *
1818 * - -EINVAL, if any of the above constraints are violated.
1819 *
1820 * - -EDEADLK, when returned from an attempt to acquire an additional
1821 * &drm_modeset_lock through drm_modeset_lock().
1822 *
1823 * - -ENOMEM, if allocating additional state sub-structures failed due
1824 * to lack of memory.
1825 *
1826 * - -EINTR, -EAGAIN or -ERESTARTSYS, if the IOCTL should be restarted.
1827 * This can either be due to a pending signal, or because the driver
1828 * needs to completely bail out to recover from an exceptional
1829 * situation like a GPU hang. From a userspace point all errors are
1830 * treated equally.
1831 */
Daniel Vettercc4ceb42014-07-25 21:30:38 +02001832 int (*atomic_check)(struct drm_device *dev,
Daniel Vetter9953f412015-12-04 09:46:02 +01001833 struct drm_atomic_state *state);
1834
1835 /**
1836 * @atomic_commit:
1837 *
1838 * This is the only hook to commit an atomic modeset update. The core
1839 * guarantees that @atomic_check has been called successfully before
1840 * calling this function, and that nothing has been changed in the
1841 * interim.
1842 *
1843 * See the documentation for struct &drm_atomic_state for how exactly
1844 * an atomic modeset update is described.
1845 *
1846 * Drivers using the atomic helpers can implement this hook using
1847 * drm_atomic_helper_commit(), or one of the exported sub-functions of
1848 * it.
1849 *
1850 * Asynchronous commits (as indicated with the async parameter) must
1851 * do any preparatory work which might result in an unsuccessful commit
1852 * in the context of this callback. The only exceptions are hardware
1853 * errors resulting in -EIO. But even in that case the driver must
1854 * ensure that the display pipe is at least running, to avoid
1855 * compositors crashing when pageflips don't work. Anything else,
1856 * specifically committing the update to the hardware, should be done
1857 * without blocking the caller. For updates which do not require a
1858 * modeset this must be guaranteed.
1859 *
1860 * The driver must wait for any pending rendering to the new
1861 * framebuffers to complete before executing the flip. It should also
1862 * wait for any pending rendering from other drivers if the underlying
1863 * buffer is a shared dma-buf. Asynchronous commits must not wait for
1864 * rendering in the context of this callback.
1865 *
1866 * An application can request to be notified when the atomic commit has
1867 * completed. These events are per-CRTC and can be distinguished by the
1868 * CRTC index supplied in &drm_event to userspace.
1869 *
1870 * The drm core will supply a struct &drm_event in the event
1871 * member of each CRTC's &drm_crtc_state structure. This can be handled by the
1872 * drm_crtc_send_vblank_event() function, which the driver should call on
1873 * the provided event upon completion of the atomic commit. Note that if
1874 * the driver supports vblank signalling and timestamping the vblank
1875 * counters and timestamps must agree with the ones returned from page
1876 * flip events. With the current vblank helper infrastructure this can
1877 * be achieved by holding a vblank reference while the page flip is
1878 * pending, acquired through drm_crtc_vblank_get() and released with
1879 * drm_crtc_vblank_put(). Drivers are free to implement their own vblank
1880 * counter and timestamp tracking though, e.g. if they have accurate
1881 * timestamp registers in hardware.
1882 *
1883 * NOTE:
1884 *
1885 * Drivers are not allowed to shut down any display pipe successfully
1886 * enabled through an atomic commit on their own. Doing so can result in
1887 * compositors crashing if a page flip is suddenly rejected because the
1888 * pipe is off.
1889 *
1890 * RETURNS:
1891 *
1892 * 0 on success or one of the below negative error codes:
1893 *
1894 * - -EBUSY, if an asynchronous updated is requested and there is
1895 * an earlier updated pending. Drivers are allowed to support a queue
1896 * of outstanding updates, but currently no driver supports that.
1897 * Note that drivers must wait for preceding updates to complete if a
1898 * synchronous update is requested, they are not allowed to fail the
1899 * commit in that case.
1900 *
1901 * - -ENOMEM, if the driver failed to allocate memory. Specifically
1902 * this can happen when trying to pin framebuffers, which must only
1903 * be done when committing the state.
1904 *
1905 * - -ENOSPC, as a refinement of the more generic -ENOMEM to indicate
1906 * that the driver has run out of vram, iommu space or similar GPU
1907 * address space needed for framebuffer.
1908 *
1909 * - -EIO, if the hardware completely died.
1910 *
1911 * - -EINTR, -EAGAIN or -ERESTARTSYS, if the IOCTL should be restarted.
1912 * This can either be due to a pending signal, or because the driver
1913 * needs to completely bail out to recover from an exceptional
1914 * situation like a GPU hang. From a userspace point of view all errors are
1915 * treated equally.
1916 *
1917 * This list is exhaustive. Specifically this hook is not allowed to
1918 * return -EINVAL (any invalid requests should be caught in
1919 * @atomic_check) or -EDEADLK (this function must not acquire
1920 * additional modeset locks).
1921 */
Daniel Vettercc4ceb42014-07-25 21:30:38 +02001922 int (*atomic_commit)(struct drm_device *dev,
Daniel Vetter9953f412015-12-04 09:46:02 +01001923 struct drm_atomic_state *state,
Daniel Vettercc4ceb42014-07-25 21:30:38 +02001924 bool async);
Daniel Vetter9953f412015-12-04 09:46:02 +01001925
1926 /**
1927 * @atomic_state_alloc:
1928 *
1929 * This optional hook can be used by drivers that want to subclass struct
1930 * &drm_atomic_state to be able to track their own driver-private global
1931 * state easily. If this hook is implemented, drivers must also
1932 * implement @atomic_state_clear and @atomic_state_free.
1933 *
1934 * RETURNS:
1935 *
1936 * A new &drm_atomic_state on success or NULL on failure.
1937 */
Maarten Lankhorst036ef572015-05-18 10:06:40 +02001938 struct drm_atomic_state *(*atomic_state_alloc)(struct drm_device *dev);
Daniel Vetter9953f412015-12-04 09:46:02 +01001939
1940 /**
1941 * @atomic_state_clear:
1942 *
1943 * This hook must clear any driver private state duplicated into the
1944 * passed-in &drm_atomic_state. This hook is called when the caller
1945 * encountered a &drm_modeset_lock deadlock and needs to drop all
1946 * already acquired locks as part of the deadlock avoidance dance
1947 * implemented in drm_modeset_lock_backoff().
1948 *
1949 * Any duplicated state must be invalidated since a concurrent atomic
1950 * update might change it, and the drm atomic interfaces always apply
1951 * updates as relative changes to the current state.
1952 *
1953 * Drivers that implement this must call drm_atomic_state_default_clear()
1954 * to clear common state.
1955 */
Maarten Lankhorst036ef572015-05-18 10:06:40 +02001956 void (*atomic_state_clear)(struct drm_atomic_state *state);
Daniel Vetter9953f412015-12-04 09:46:02 +01001957
1958 /**
1959 * @atomic_state_free:
1960 *
1961 * This hook needs driver private resources and the &drm_atomic_state
1962 * itself. Note that the core first calls drm_atomic_state_clear() to
1963 * avoid code duplicate between the clear and free hooks.
1964 *
1965 * Drivers that implement this must call drm_atomic_state_default_free()
1966 * to release common resources.
1967 */
Maarten Lankhorst036ef572015-05-18 10:06:40 +02001968 void (*atomic_state_free)(struct drm_atomic_state *state);
Dave Airlief453ba02008-11-07 14:05:41 -08001969};
1970
Jesse Barnesc1aaca22011-11-07 12:03:21 -08001971/**
Daniel Vetter2c0c33d2014-10-27 20:19:38 +01001972 * struct drm_mode_config - Mode configuration control structure
Jesse Barnesa62c93d2011-11-07 12:03:22 -08001973 * @mutex: mutex protecting KMS related lists and structures
Daniel Vetter2c0c33d2014-10-27 20:19:38 +01001974 * @connection_mutex: ww mutex protecting connector state and routing
1975 * @acquire_ctx: global implicit acquire context used by atomic drivers for
Daniel Vetterc6b0ca32015-12-04 09:46:01 +01001976 * legacy IOCTLs
Jesse Barnesa62c93d2011-11-07 12:03:22 -08001977 * @idr_mutex: mutex for KMS ID allocation and management
1978 * @crtc_idr: main KMS ID tracking object
Daniel Vetter2c0c33d2014-10-27 20:19:38 +01001979 * @fb_lock: mutex to protect fb state and lists
Jesse Barnesa62c93d2011-11-07 12:03:22 -08001980 * @num_fb: number of fbs available
1981 * @fb_list: list of framebuffers available
1982 * @num_connector: number of connectors on this device
1983 * @connector_list: list of connector objects
1984 * @num_encoder: number of encoders on this device
1985 * @encoder_list: list of encoder objects
Daniel Vetter2c0c33d2014-10-27 20:19:38 +01001986 * @num_overlay_plane: number of overlay planes on this device
1987 * @num_total_plane: number of universal (i.e. with primary/curso) planes on this device
1988 * @plane_list: list of plane objects
Jesse Barnesa62c93d2011-11-07 12:03:22 -08001989 * @num_crtc: number of CRTCs on this device
1990 * @crtc_list: list of CRTC objects
Daniel Vetter2c0c33d2014-10-27 20:19:38 +01001991 * @property_list: list of property objects
Jesse Barnesa62c93d2011-11-07 12:03:22 -08001992 * @min_width: minimum pixel width on this device
1993 * @min_height: minimum pixel height on this device
1994 * @max_width: maximum pixel width on this device
1995 * @max_height: maximum pixel height on this device
1996 * @funcs: core driver provided mode setting functions
1997 * @fb_base: base address of the framebuffer
Daniel Vetter2c0c33d2014-10-27 20:19:38 +01001998 * @poll_enabled: track polling support for this device
1999 * @poll_running: track polling status for this device
Jesse Barnesa62c93d2011-11-07 12:03:22 -08002000 * @output_poll_work: delayed work for polling in process context
Daniel Vetter2c0c33d2014-10-27 20:19:38 +01002001 * @property_blob_list: list of all the blob property objects
Daniel Stone8fb6e7a2015-04-20 19:22:54 +01002002 * @blob_lock: mutex for blob property allocation and management
Jesse Barnesa62c93d2011-11-07 12:03:22 -08002003 * @*_property: core property tracking
Daniel Vetter2c0c33d2014-10-27 20:19:38 +01002004 * @preferred_depth: preferred RBG pixel depth, used by fb helpers
2005 * @prefer_shadow: hint to userspace to prefer shadow-fb rendering
2006 * @async_page_flip: does this device support async flips on the primary plane?
2007 * @cursor_width: hint to userspace for max cursor width
2008 * @cursor_height: hint to userspace for max cursor height
Dave Airlief453ba02008-11-07 14:05:41 -08002009 *
Jesse Barnesa62c93d2011-11-07 12:03:22 -08002010 * Core mode resource tracking structure. All CRTC, encoders, and connectors
2011 * enumerated by the driver are added here, as are global properties. Some
2012 * global restrictions are also here, e.g. dimension restrictions.
Dave Airlief453ba02008-11-07 14:05:41 -08002013 */
2014struct drm_mode_config {
Jesse Barnesad2563c2009-01-19 17:21:45 +10002015 struct mutex mutex; /* protects configuration (mode lists etc.) */
Rob Clark51fd3712013-11-19 12:10:12 -05002016 struct drm_modeset_lock connection_mutex; /* protects connector->encoder and encoder->crtc links */
2017 struct drm_modeset_acquire_ctx *acquire_ctx; /* for legacy _lock_all() / _unlock_all() */
Jesse Barnesad2563c2009-01-19 17:21:45 +10002018 struct mutex idr_mutex; /* for IDR management */
Dave Airlief453ba02008-11-07 14:05:41 -08002019 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 +10002020 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 -08002021 /* this is limited to one for now */
Daniel Vetter4b096ac2012-12-10 21:19:18 +01002022
Daniel Vetter2c0c33d2014-10-27 20:19:38 +01002023 struct mutex fb_lock; /* proctects global and per-file fb lists */
Dave Airlief453ba02008-11-07 14:05:41 -08002024 int num_fb;
2025 struct list_head fb_list;
Daniel Vetter4b096ac2012-12-10 21:19:18 +01002026
Dave Airlief453ba02008-11-07 14:05:41 -08002027 int num_connector;
2028 struct list_head connector_list;
2029 int num_encoder;
2030 struct list_head encoder_list;
Matt Ropere27dde32014-04-01 15:22:30 -07002031
2032 /*
2033 * Track # of overlay planes separately from # of total planes. By
2034 * default we only advertise overlay planes to userspace; if userspace
2035 * sets the "universal plane" capability bit, we'll go ahead and
2036 * expose all planes.
2037 */
2038 int num_overlay_plane;
2039 int num_total_plane;
Jesse Barnes8cf5c912011-11-14 14:51:27 -08002040 struct list_head plane_list;
Dave Airlief453ba02008-11-07 14:05:41 -08002041
2042 int num_crtc;
2043 struct list_head crtc_list;
2044
2045 struct list_head property_list;
2046
Dave Airlief453ba02008-11-07 14:05:41 -08002047 int min_width, min_height;
2048 int max_width, max_height;
Laurent Pincharte6ecefa2012-05-17 13:27:23 +02002049 const struct drm_mode_config_funcs *funcs;
Benjamin Herrenschmidtd883f7f2009-02-02 16:55:45 +11002050 resource_size_t fb_base;
Dave Airlief453ba02008-11-07 14:05:41 -08002051
Dave Airlieeb1f8e42010-05-07 06:42:51 +00002052 /* output poll support */
2053 bool poll_enabled;
Daniel Vetter905bc9f2012-10-23 18:23:36 +00002054 bool poll_running;
Daniel Vetter162b6a52015-01-21 08:45:21 +01002055 bool delayed_event;
Tejun Heo991ea752010-07-20 22:09:02 +02002056 struct delayed_work output_poll_work;
Dave Airlieeb1f8e42010-05-07 06:42:51 +00002057
Daniel Stone8fb6e7a2015-04-20 19:22:54 +01002058 struct mutex blob_lock;
2059
Dave Airlief453ba02008-11-07 14:05:41 -08002060 /* pointers to standard properties */
2061 struct list_head property_blob_list;
2062 struct drm_property *edid_property;
2063 struct drm_property *dpms_property;
Dave Airlie43aba7e2014-06-05 14:01:31 +10002064 struct drm_property *path_property;
Dave Airlie6f134d72014-10-20 16:30:50 +10002065 struct drm_property *tile_property;
Rob Clark9922ab52014-04-01 20:16:57 -04002066 struct drm_property *plane_type_property;
Sonika Jindal2a297cc2014-08-05 11:26:54 +05302067 struct drm_property *rotation_property;
Rob Clark6b4959f2014-12-18 16:01:53 -05002068 struct drm_property *prop_src_x;
2069 struct drm_property *prop_src_y;
2070 struct drm_property *prop_src_w;
2071 struct drm_property *prop_src_h;
2072 struct drm_property *prop_crtc_x;
2073 struct drm_property *prop_crtc_y;
2074 struct drm_property *prop_crtc_w;
2075 struct drm_property *prop_crtc_h;
2076 struct drm_property *prop_fb_id;
2077 struct drm_property *prop_crtc_id;
Daniel Vettereab3bbe2015-01-22 16:36:21 +01002078 struct drm_property *prop_active;
Daniel Stone955f3c32015-05-25 19:11:52 +01002079 struct drm_property *prop_mode_id;
Dave Airlief453ba02008-11-07 14:05:41 -08002080
2081 /* DVI-I properties */
2082 struct drm_property *dvi_i_subconnector_property;
2083 struct drm_property *dvi_i_select_subconnector_property;
2084
2085 /* TV properties */
2086 struct drm_property *tv_subconnector_property;
2087 struct drm_property *tv_select_subconnector_property;
2088 struct drm_property *tv_mode_property;
2089 struct drm_property *tv_left_margin_property;
2090 struct drm_property *tv_right_margin_property;
2091 struct drm_property *tv_top_margin_property;
2092 struct drm_property *tv_bottom_margin_property;
Francisco Jerezb6b79022009-08-02 04:19:20 +02002093 struct drm_property *tv_brightness_property;
2094 struct drm_property *tv_contrast_property;
2095 struct drm_property *tv_flicker_reduction_property;
Francisco Jereza75f0232009-08-12 02:30:10 +02002096 struct drm_property *tv_overscan_property;
2097 struct drm_property *tv_saturation_property;
2098 struct drm_property *tv_hue_property;
Dave Airlief453ba02008-11-07 14:05:41 -08002099
2100 /* Optional properties */
2101 struct drm_property *scaling_mode_property;
Vandana Kannanff587e42014-06-11 10:46:48 +05302102 struct drm_property *aspect_ratio_property;
Jakob Bornecrantz884840a2009-12-03 23:25:47 +00002103 struct drm_property *dirty_info_property;
Dave Airlie019d96c2011-09-29 16:20:42 +01002104
Dave Airlie5bb2bbf2014-11-10 10:18:15 +10002105 /* properties for virtual machine layout */
2106 struct drm_property *suggested_x_property;
2107 struct drm_property *suggested_y_property;
2108
Dave Airlie019d96c2011-09-29 16:20:42 +01002109 /* dumb ioctl parameters */
2110 uint32_t preferred_depth, prefer_shadow;
Keith Packard62f21042013-07-22 18:50:00 -07002111
2112 /* whether async page flip is supported or not */
2113 bool async_page_flip;
Alex Deucher8716ed42014-02-12 12:48:23 -05002114
Rob Clarke3eb3252015-02-05 14:41:52 +00002115 /* whether the driver supports fb modifiers */
2116 bool allow_fb_modifiers;
2117
Alex Deucher8716ed42014-02-12 12:48:23 -05002118 /* cursor size */
2119 uint32_t cursor_width, cursor_height;
Dave Airlief453ba02008-11-07 14:05:41 -08002120};
2121
Rob Clarkdd275952014-11-25 20:29:46 -05002122/**
2123 * drm_for_each_plane_mask - iterate over planes specified by bitmask
2124 * @plane: the loop cursor
2125 * @dev: the DRM device
2126 * @plane_mask: bitmask of plane indices
2127 *
2128 * Iterate over all planes specified by bitmask.
2129 */
2130#define drm_for_each_plane_mask(plane, dev, plane_mask) \
2131 list_for_each_entry((plane), &(dev)->mode_config.plane_list, head) \
Jani Nikula373701b2015-11-24 21:21:55 +02002132 for_each_if ((plane_mask) & (1 << drm_plane_index(plane)))
Rob Clarkdd275952014-11-25 20:29:46 -05002133
2134
Dave Airlief453ba02008-11-07 14:05:41 -08002135#define obj_to_crtc(x) container_of(x, struct drm_crtc, base)
2136#define obj_to_connector(x) container_of(x, struct drm_connector, base)
2137#define obj_to_encoder(x) container_of(x, struct drm_encoder, base)
2138#define obj_to_mode(x) container_of(x, struct drm_display_mode, base)
2139#define obj_to_fb(x) container_of(x, struct drm_framebuffer, base)
2140#define obj_to_property(x) container_of(x, struct drm_property, base)
2141#define obj_to_blob(x) container_of(x, struct drm_property_blob, base)
Jesse Barnes8cf5c912011-11-14 14:51:27 -08002142#define obj_to_plane(x) container_of(x, struct drm_plane, base)
Dave Airlief453ba02008-11-07 14:05:41 -08002143
Sascha Hauer4a67d392012-02-06 10:58:17 +01002144struct drm_prop_enum_list {
2145 int type;
2146 char *name;
2147};
Dave Airlief453ba02008-11-07 14:05:41 -08002148
Ville Syrjäläf9882872015-12-09 16:19:31 +02002149extern __printf(6, 7)
2150int drm_crtc_init_with_planes(struct drm_device *dev,
2151 struct drm_crtc *crtc,
2152 struct drm_plane *primary,
2153 struct drm_plane *cursor,
2154 const struct drm_crtc_funcs *funcs,
2155 const char *name, ...);
Dave Airlief453ba02008-11-07 14:05:41 -08002156extern void drm_crtc_cleanup(struct drm_crtc *crtc);
Russell Kingdb5f7a62014-01-02 21:27:33 +00002157extern unsigned int drm_crtc_index(struct drm_crtc *crtc);
2158
2159/**
2160 * drm_crtc_mask - find the mask of a registered CRTC
2161 * @crtc: CRTC to find mask for
2162 *
2163 * Given a registered CRTC, return the mask bit of that CRTC for an
2164 * encoder's possible_crtcs field.
2165 */
2166static inline uint32_t drm_crtc_mask(struct drm_crtc *crtc)
2167{
2168 return 1 << drm_crtc_index(crtc);
2169}
Dave Airlief453ba02008-11-07 14:05:41 -08002170
Ilia Mirkinb21e3af2013-08-07 22:34:48 -04002171extern void drm_connector_ida_init(void);
2172extern void drm_connector_ida_destroy(void);
Ville Syrjälä6bfc56a2012-03-13 12:35:48 +02002173extern int drm_connector_init(struct drm_device *dev,
2174 struct drm_connector *connector,
2175 const struct drm_connector_funcs *funcs,
2176 int connector_type);
Thomas Wood34ea3d32014-05-29 16:57:41 +01002177int drm_connector_register(struct drm_connector *connector);
2178void drm_connector_unregister(struct drm_connector *connector);
Dave Airlief453ba02008-11-07 14:05:41 -08002179
2180extern void drm_connector_cleanup(struct drm_connector *connector);
Daniel Vetter10f637b2014-07-29 13:47:11 +02002181extern unsigned int drm_connector_index(struct drm_connector *connector);
Dave Airliecbc7e222012-02-20 14:16:40 +00002182/* helper to unplug all connectors from sysfs for device */
2183extern void drm_connector_unplug_all(struct drm_device *dev);
Dave Airlief453ba02008-11-07 14:05:41 -08002184
Ajay Kumar3d3f8b12015-01-20 22:08:44 +05302185extern int drm_bridge_add(struct drm_bridge *bridge);
2186extern void drm_bridge_remove(struct drm_bridge *bridge);
2187extern struct drm_bridge *of_drm_find_bridge(struct device_node *np);
2188extern int drm_bridge_attach(struct drm_device *dev, struct drm_bridge *bridge);
Sean Paul3b336ec2013-08-14 16:47:37 -04002189
Archit Taneja862e6862015-05-21 11:03:16 +05302190bool drm_bridge_mode_fixup(struct drm_bridge *bridge,
2191 const struct drm_display_mode *mode,
2192 struct drm_display_mode *adjusted_mode);
2193void drm_bridge_disable(struct drm_bridge *bridge);
2194void drm_bridge_post_disable(struct drm_bridge *bridge);
2195void drm_bridge_mode_set(struct drm_bridge *bridge,
2196 struct drm_display_mode *mode,
2197 struct drm_display_mode *adjusted_mode);
2198void drm_bridge_pre_enable(struct drm_bridge *bridge);
2199void drm_bridge_enable(struct drm_bridge *bridge);
2200
Ville Syrjälä13a3d912015-12-09 16:20:18 +02002201extern __printf(5, 6)
2202int drm_encoder_init(struct drm_device *dev,
2203 struct drm_encoder *encoder,
2204 const struct drm_encoder_funcs *funcs,
2205 int encoder_type, const char *name, ...);
Dave Airlief453ba02008-11-07 14:05:41 -08002206
Thierry Reding3d887362014-01-13 14:33:20 +01002207/**
2208 * drm_encoder_crtc_ok - can a given crtc drive a given encoder?
2209 * @encoder: encoder to test
2210 * @crtc: crtc to test
2211 *
2212 * Return false if @encoder can't be driven by @crtc, true otherwise.
2213 */
2214static inline bool drm_encoder_crtc_ok(struct drm_encoder *encoder,
2215 struct drm_crtc *crtc)
2216{
2217 return !!(encoder->possible_crtcs & drm_crtc_mask(crtc));
2218}
2219
Ville Syrjäläb0b3b792015-12-09 16:19:55 +02002220extern __printf(8, 9)
2221int drm_universal_plane_init(struct drm_device *dev,
2222 struct drm_plane *plane,
2223 unsigned long possible_crtcs,
2224 const struct drm_plane_funcs *funcs,
2225 const uint32_t *formats,
2226 unsigned int format_count,
2227 enum drm_plane_type type,
2228 const char *name, ...);
Jesse Barnes8cf5c912011-11-14 14:51:27 -08002229extern int drm_plane_init(struct drm_device *dev,
2230 struct drm_plane *plane,
2231 unsigned long possible_crtcs,
2232 const struct drm_plane_funcs *funcs,
Thierry Reding45e37432015-08-12 16:54:28 +02002233 const uint32_t *formats, unsigned int format_count,
Matt Roperdc415ff2014-04-01 15:22:36 -07002234 bool is_primary);
Jesse Barnes8cf5c912011-11-14 14:51:27 -08002235extern void drm_plane_cleanup(struct drm_plane *plane);
Daniel Vetter10f637b2014-07-29 13:47:11 +02002236extern unsigned int drm_plane_index(struct drm_plane *plane);
Chandra Konduruf81338a2015-04-09 17:36:21 -07002237extern struct drm_plane * drm_plane_from_index(struct drm_device *dev, int idx);
Ville Syrjälä9125e612013-06-03 16:10:40 +03002238extern void drm_plane_force_disable(struct drm_plane *plane);
Laurent Pinchartead86102015-03-05 02:25:43 +02002239extern int drm_plane_check_pixel_format(const struct drm_plane *plane,
2240 u32 format);
Gustavo Padovanecb7e162014-12-01 15:40:09 -08002241extern void drm_crtc_get_hv_timing(const struct drm_display_mode *mode,
2242 int *hdisplay, int *vdisplay);
Matt Roperaf936292014-04-01 15:22:34 -07002243extern int drm_crtc_check_viewport(const struct drm_crtc *crtc,
2244 int x, int y,
2245 const struct drm_display_mode *mode,
2246 const struct drm_framebuffer *fb);
Jesse Barnes8cf5c912011-11-14 14:51:27 -08002247
Dave Airlief453ba02008-11-07 14:05:41 -08002248extern void drm_encoder_cleanup(struct drm_encoder *encoder);
2249
Ville Syrjäläd20d3172013-06-07 15:43:07 +00002250extern const char *drm_get_connector_status_name(enum drm_connector_status status);
Jesse Barnesac1bb362014-02-10 15:32:44 -08002251extern const char *drm_get_subpixel_order_name(enum subpixel_order order);
Ville Syrjäläd20d3172013-06-07 15:43:07 +00002252extern const char *drm_get_dpms_name(int val);
2253extern const char *drm_get_dvi_i_subconnector_name(int val);
2254extern const char *drm_get_dvi_i_select_name(int val);
2255extern const char *drm_get_tv_subconnector_name(int val);
2256extern const char *drm_get_tv_select_name(int val);
Kristian Høgsbergea39f832009-02-12 14:37:56 -05002257extern void drm_fb_release(struct drm_file *file_priv);
Daniel Stonee2f5d2e2015-05-22 13:34:51 +01002258extern void drm_property_destroy_user_blobs(struct drm_device *dev,
2259 struct drm_file *file_priv);
Adam Jacksonfbff4692012-09-18 10:58:47 -04002260extern bool drm_probe_ddc(struct i2c_adapter *adapter);
Dave Airlief453ba02008-11-07 14:05:41 -08002261extern struct edid *drm_get_edid(struct drm_connector *connector,
2262 struct i2c_adapter *adapter);
Jani Nikula51f8da52013-09-27 15:08:27 +03002263extern struct edid *drm_edid_duplicate(const struct edid *edid);
Dave Airlief453ba02008-11-07 14:05:41 -08002264extern int drm_add_edid_modes(struct drm_connector *connector, struct edid *edid);
Dave Airlief453ba02008-11-07 14:05:41 -08002265extern void drm_mode_config_init(struct drm_device *dev);
Chris Wilsoneb033552011-01-24 15:11:08 +00002266extern void drm_mode_config_reset(struct drm_device *dev);
Dave Airlief453ba02008-11-07 14:05:41 -08002267extern void drm_mode_config_cleanup(struct drm_device *dev);
Dave Airlief453ba02008-11-07 14:05:41 -08002268
Dave Airlie43aba7e2014-06-05 14:01:31 +10002269extern int drm_mode_connector_set_path_property(struct drm_connector *connector,
Thierry Reding12e6cec2014-05-13 11:38:36 +02002270 const char *path);
Dave Airlie6f134d72014-10-20 16:30:50 +10002271int drm_mode_connector_set_tile_property(struct drm_connector *connector);
Dave Airlief453ba02008-11-07 14:05:41 -08002272extern int drm_mode_connector_update_edid_property(struct drm_connector *connector,
Thierry Reding12e6cec2014-05-13 11:38:36 +02002273 const struct edid *edid);
Rob Clark5ea22f22014-05-30 11:34:01 -04002274
Boris Brezillonb5571e92014-07-22 12:09:10 +02002275extern int drm_display_info_set_bus_formats(struct drm_display_info *info,
2276 const u32 *formats,
2277 unsigned int num_formats);
2278
Rob Clark5ea22f22014-05-30 11:34:01 -04002279static inline bool drm_property_type_is(struct drm_property *property,
2280 uint32_t type)
2281{
2282 /* instanceof for props.. handles extended type vs original types: */
2283 if (property->flags & DRM_MODE_PROP_EXTENDED_TYPE)
2284 return (property->flags & DRM_MODE_PROP_EXTENDED_TYPE) == type;
2285 return property->flags & type;
2286}
2287
2288static inline bool drm_property_type_valid(struct drm_property *property)
2289{
2290 if (property->flags & DRM_MODE_PROP_EXTENDED_TYPE)
2291 return !(property->flags & DRM_MODE_PROP_LEGACY_TYPE);
2292 return !!(property->flags & DRM_MODE_PROP_LEGACY_TYPE);
2293}
2294
Paulo Zanonic5431882012-05-15 18:09:02 -03002295extern int drm_object_property_set_value(struct drm_mode_object *obj,
2296 struct drm_property *property,
2297 uint64_t val);
2298extern int drm_object_property_get_value(struct drm_mode_object *obj,
2299 struct drm_property *property,
2300 uint64_t *value);
Dave Airlief453ba02008-11-07 14:05:41 -08002301extern int drm_framebuffer_init(struct drm_device *dev,
2302 struct drm_framebuffer *fb,
2303 const struct drm_framebuffer_funcs *funcs);
Daniel Vetter786b99e2012-12-02 21:53:40 +01002304extern struct drm_framebuffer *drm_framebuffer_lookup(struct drm_device *dev,
2305 uint32_t id);
Rob Clarkf7eff602012-09-05 21:48:38 +00002306extern void drm_framebuffer_unreference(struct drm_framebuffer *fb);
2307extern void drm_framebuffer_reference(struct drm_framebuffer *fb);
2308extern void drm_framebuffer_remove(struct drm_framebuffer *fb);
Dave Airlief453ba02008-11-07 14:05:41 -08002309extern void drm_framebuffer_cleanup(struct drm_framebuffer *fb);
Daniel Vetter36206362012-12-10 20:42:17 +01002310extern void drm_framebuffer_unregister_private(struct drm_framebuffer *fb);
Dave Airlief453ba02008-11-07 14:05:41 -08002311
Paulo Zanonic5431882012-05-15 18:09:02 -03002312extern void drm_object_attach_property(struct drm_mode_object *obj,
2313 struct drm_property *property,
2314 uint64_t init_val);
Dave Airlief453ba02008-11-07 14:05:41 -08002315extern struct drm_property *drm_property_create(struct drm_device *dev, int flags,
2316 const char *name, int num_values);
Sascha Hauer4a67d392012-02-06 10:58:17 +01002317extern struct drm_property *drm_property_create_enum(struct drm_device *dev, int flags,
2318 const char *name,
2319 const struct drm_prop_enum_list *props,
2320 int num_values);
Rob Clark49e27542012-05-17 02:23:26 -06002321struct drm_property *drm_property_create_bitmask(struct drm_device *dev,
2322 int flags, const char *name,
2323 const struct drm_prop_enum_list *props,
Ville Syrjälä7689ffb2014-07-08 10:31:52 +05302324 int num_props,
2325 uint64_t supported_bits);
Sascha Hauerd9bc3c02012-02-06 10:58:18 +01002326struct drm_property *drm_property_create_range(struct drm_device *dev, int flags,
2327 const char *name,
2328 uint64_t min, uint64_t max);
Rob Clarkebc44cf2012-09-12 22:22:31 -05002329struct drm_property *drm_property_create_signed_range(struct drm_device *dev,
2330 int flags, const char *name,
2331 int64_t min, int64_t max);
Rob Clark98f75de2014-05-30 11:37:03 -04002332struct drm_property *drm_property_create_object(struct drm_device *dev,
2333 int flags, const char *name, uint32_t type);
Daniel Vetter960cd9d2015-01-21 08:47:38 +01002334struct drm_property *drm_property_create_bool(struct drm_device *dev, int flags,
2335 const char *name);
Daniel Stone6bcacf52015-04-20 19:22:55 +01002336struct drm_property_blob *drm_property_create_blob(struct drm_device *dev,
2337 size_t length,
2338 const void *data);
2339struct drm_property_blob *drm_property_lookup_blob(struct drm_device *dev,
2340 uint32_t id);
2341struct drm_property_blob *drm_property_reference_blob(struct drm_property_blob *blob);
2342void drm_property_unreference_blob(struct drm_property_blob *blob);
Dave Airlief453ba02008-11-07 14:05:41 -08002343extern void drm_property_destroy(struct drm_device *dev, struct drm_property *property);
2344extern int drm_property_add_enum(struct drm_property *property, int index,
2345 uint64_t value, const char *name);
2346extern int drm_mode_create_dvi_i_properties(struct drm_device *dev);
Thierry Reding2f763312014-10-13 12:45:57 +02002347extern int drm_mode_create_tv_properties(struct drm_device *dev,
2348 unsigned int num_modes,
Ville Syrjäläb7c914b2015-08-31 15:09:26 +03002349 const char * const modes[]);
Dave Airlief453ba02008-11-07 14:05:41 -08002350extern int drm_mode_create_scaling_mode_property(struct drm_device *dev);
Vandana Kannanff587e42014-06-11 10:46:48 +05302351extern int drm_mode_create_aspect_ratio_property(struct drm_device *dev);
Jakob Bornecrantz884840a2009-12-03 23:25:47 +00002352extern int drm_mode_create_dirty_info_property(struct drm_device *dev);
Dave Airlie5bb2bbf2014-11-10 10:18:15 +10002353extern int drm_mode_create_suggested_offset_properties(struct drm_device *dev);
Rob Clarkd34f20d2014-12-18 16:01:56 -05002354extern bool drm_property_change_valid_get(struct drm_property *property,
2355 uint64_t value, struct drm_mode_object **ref);
2356extern void drm_property_change_valid_put(struct drm_property *property,
2357 struct drm_mode_object *ref);
Dave Airlief453ba02008-11-07 14:05:41 -08002358
2359extern int drm_mode_connector_attach_encoder(struct drm_connector *connector,
2360 struct drm_encoder *encoder);
Sascha Hauer4cae5b82012-02-01 11:38:23 +01002361extern int drm_mode_crtc_set_gamma_size(struct drm_crtc *crtc,
Dave Airlief453ba02008-11-07 14:05:41 -08002362 int gamma_size);
Daniel Vetter7a9c9062009-09-15 22:57:31 +02002363extern struct drm_mode_object *drm_mode_object_find(struct drm_device *dev,
2364 uint32_t id, uint32_t type);
Rob Clark98f75de2014-05-30 11:37:03 -04002365
Dave Airlief453ba02008-11-07 14:05:41 -08002366/* IOCTLs */
2367extern int drm_mode_getresources(struct drm_device *dev,
2368 void *data, struct drm_file *file_priv);
Jesse Barnes8cf5c912011-11-14 14:51:27 -08002369extern int drm_mode_getplane_res(struct drm_device *dev, void *data,
2370 struct drm_file *file_priv);
Dave Airlief453ba02008-11-07 14:05:41 -08002371extern int drm_mode_getcrtc(struct drm_device *dev,
2372 void *data, struct drm_file *file_priv);
2373extern int drm_mode_getconnector(struct drm_device *dev,
2374 void *data, struct drm_file *file_priv);
Daniel Vetter2d13b672012-12-11 13:47:23 +01002375extern int drm_mode_set_config_internal(struct drm_mode_set *set);
Dave Airlief453ba02008-11-07 14:05:41 -08002376extern int drm_mode_setcrtc(struct drm_device *dev,
2377 void *data, struct drm_file *file_priv);
Jesse Barnes8cf5c912011-11-14 14:51:27 -08002378extern int drm_mode_getplane(struct drm_device *dev,
2379 void *data, struct drm_file *file_priv);
2380extern int drm_mode_setplane(struct drm_device *dev,
2381 void *data, struct drm_file *file_priv);
Dave Airlief453ba02008-11-07 14:05:41 -08002382extern int drm_mode_cursor_ioctl(struct drm_device *dev,
2383 void *data, struct drm_file *file_priv);
Dave Airlie4c813d42013-06-20 11:48:52 +10002384extern int drm_mode_cursor2_ioctl(struct drm_device *dev,
2385 void *data, struct drm_file *file_priv);
Dave Airlief453ba02008-11-07 14:05:41 -08002386extern int drm_mode_addfb(struct drm_device *dev,
2387 void *data, struct drm_file *file_priv);
Jesse Barnes308e5bc2011-11-14 14:51:28 -08002388extern int drm_mode_addfb2(struct drm_device *dev,
2389 void *data, struct drm_file *file_priv);
2390extern uint32_t drm_mode_legacy_fb_format(uint32_t bpp, uint32_t depth);
Dave Airlief453ba02008-11-07 14:05:41 -08002391extern int drm_mode_rmfb(struct drm_device *dev,
2392 void *data, struct drm_file *file_priv);
2393extern int drm_mode_getfb(struct drm_device *dev,
2394 void *data, struct drm_file *file_priv);
Jakob Bornecrantz884840a2009-12-03 23:25:47 +00002395extern int drm_mode_dirtyfb_ioctl(struct drm_device *dev,
2396 void *data, struct drm_file *file_priv);
Dave Airlief453ba02008-11-07 14:05:41 -08002397
2398extern int drm_mode_getproperty_ioctl(struct drm_device *dev,
2399 void *data, struct drm_file *file_priv);
2400extern int drm_mode_getblob_ioctl(struct drm_device *dev,
2401 void *data, struct drm_file *file_priv);
Daniel Stonee2f5d2e2015-05-22 13:34:51 +01002402extern int drm_mode_createblob_ioctl(struct drm_device *dev,
2403 void *data, struct drm_file *file_priv);
2404extern int drm_mode_destroyblob_ioctl(struct drm_device *dev,
2405 void *data, struct drm_file *file_priv);
Dave Airlief453ba02008-11-07 14:05:41 -08002406extern int drm_mode_connector_property_set_ioctl(struct drm_device *dev,
2407 void *data, struct drm_file *file_priv);
Dave Airlief453ba02008-11-07 14:05:41 -08002408extern int drm_mode_getencoder(struct drm_device *dev,
2409 void *data, struct drm_file *file_priv);
2410extern int drm_mode_gamma_get_ioctl(struct drm_device *dev,
2411 void *data, struct drm_file *file_priv);
2412extern int drm_mode_gamma_set_ioctl(struct drm_device *dev,
2413 void *data, struct drm_file *file_priv);
Thierry Reding18316c82012-12-20 15:41:44 +01002414extern u8 drm_match_cea_mode(const struct drm_display_mode *to_match);
Vandana Kannan0967e6a2014-04-01 16:26:59 +05302415extern enum hdmi_picture_aspect drm_get_cea_aspect_ratio(const u8 video_code);
Ma Lingf23c20c2009-03-26 19:26:23 +08002416extern bool drm_detect_hdmi_monitor(struct edid *edid);
Zhenyu Wang8fe97902010-09-19 14:27:28 +08002417extern bool drm_detect_monitor_audio(struct edid *edid);
Ville Syrjäläb1edd6a2013-01-17 16:31:30 +02002418extern bool drm_rgb_quant_range_selectable(struct edid *edid);
Kristian Høgsbergd91d8a32009-11-17 12:43:55 -05002419extern int drm_mode_page_flip_ioctl(struct drm_device *dev,
2420 void *data, struct drm_file *file_priv);
Zhao Yakuif0fda0a2009-09-03 09:33:48 +08002421extern int drm_add_modes_noedid(struct drm_connector *connector,
2422 int hdisplay, int vdisplay);
Gerd Hoffmann3cf70da2013-10-11 10:01:08 +02002423extern void drm_set_preferred_mode(struct drm_connector *connector,
2424 int hpref, int vpref);
Alex Deucher3c537882010-02-05 04:21:19 -05002425
Thomas Reim051963d2011-07-29 14:28:57 +00002426extern int drm_edid_header_is_valid(const u8 *raw_edid);
Todd Previte6ba2bd32015-04-21 11:09:41 -07002427extern bool drm_edid_block_valid(u8 *raw_edid, int block, bool print_bad_edid,
2428 bool *edid_corrupt);
Alex Deucher3c537882010-02-05 04:21:19 -05002429extern bool drm_edid_is_valid(struct edid *edid);
Dave Airlie138f9eb2014-10-20 16:17:17 +10002430
2431extern struct drm_tile_group *drm_mode_create_tile_group(struct drm_device *dev,
2432 char topology[8]);
2433extern struct drm_tile_group *drm_mode_get_tile_group(struct drm_device *dev,
2434 char topology[8]);
2435extern void drm_mode_put_tile_group(struct drm_device *dev,
2436 struct drm_tile_group *tg);
Dave Airlie1d42bbc2010-05-07 05:02:30 +00002437struct drm_display_mode *drm_mode_find_dmt(struct drm_device *dev,
Adam Jacksonf6e252b2012-04-13 16:33:31 -04002438 int hsize, int vsize, int fresh,
2439 bool rb);
Dave Airlieff72145b2011-02-07 12:16:14 +10002440
2441extern int drm_mode_create_dumb_ioctl(struct drm_device *dev,
2442 void *data, struct drm_file *file_priv);
2443extern int drm_mode_mmap_dumb_ioctl(struct drm_device *dev,
2444 void *data, struct drm_file *file_priv);
2445extern int drm_mode_destroy_dumb_ioctl(struct drm_device *dev,
2446 void *data, struct drm_file *file_priv);
Paulo Zanonic5431882012-05-15 18:09:02 -03002447extern int drm_mode_obj_get_properties_ioctl(struct drm_device *dev, void *data,
2448 struct drm_file *file_priv);
2449extern int drm_mode_obj_set_property_ioctl(struct drm_device *dev, void *data,
2450 struct drm_file *file_priv);
Thomas Wood3a5f87c2014-08-20 14:45:00 +01002451extern int drm_mode_plane_set_obj_prop(struct drm_plane *plane,
2452 struct drm_property *property,
2453 uint64_t value);
Rob Clarkd34f20d2014-12-18 16:01:56 -05002454extern int drm_mode_atomic_ioctl(struct drm_device *dev,
2455 void *data, struct drm_file *file_priv);
Dave Airlie248dbc22011-11-29 20:02:54 +00002456
2457extern void drm_fb_get_bpp_depth(uint32_t format, unsigned int *depth,
2458 int *bpp);
Ville Syrjälä141670e2012-04-05 21:35:15 +03002459extern int drm_format_num_planes(uint32_t format);
Ville Syrjälä5a86bd52012-04-05 21:35:16 +03002460extern int drm_format_plane_cpp(uint32_t format, int plane);
Ville Syrjälä01b68b02012-04-05 21:35:17 +03002461extern int drm_format_horz_chroma_subsampling(uint32_t format);
2462extern int drm_format_vert_chroma_subsampling(uint32_t format);
Ville Syrjäläd20d3172013-06-07 15:43:07 +00002463extern const char *drm_get_format_name(uint32_t format);
Ville Syrjäläc1df5f32014-07-08 10:31:53 +05302464extern struct drm_property *drm_mode_create_rotation_property(struct drm_device *dev,
2465 unsigned int supported_rotations);
Ville Syrjälä3c9855f2014-07-08 10:31:56 +05302466extern unsigned int drm_rotation_simplify(unsigned int rotation,
2467 unsigned int supported_rotations);
Ville Syrjälä141670e2012-04-05 21:35:15 +03002468
Russell King96f60e32012-08-15 13:59:49 +01002469/* Helpers */
Rob Clarka2b34e22013-10-05 16:36:52 -04002470
2471static inline struct drm_plane *drm_plane_find(struct drm_device *dev,
2472 uint32_t id)
2473{
2474 struct drm_mode_object *mo;
2475 mo = drm_mode_object_find(dev, id, DRM_MODE_OBJECT_PLANE);
2476 return mo ? obj_to_plane(mo) : NULL;
2477}
2478
Russell King96f60e32012-08-15 13:59:49 +01002479static inline struct drm_crtc *drm_crtc_find(struct drm_device *dev,
2480 uint32_t id)
2481{
2482 struct drm_mode_object *mo;
2483 mo = drm_mode_object_find(dev, id, DRM_MODE_OBJECT_CRTC);
2484 return mo ? obj_to_crtc(mo) : NULL;
2485}
2486
2487static inline struct drm_encoder *drm_encoder_find(struct drm_device *dev,
2488 uint32_t id)
2489{
2490 struct drm_mode_object *mo;
2491 mo = drm_mode_object_find(dev, id, DRM_MODE_OBJECT_ENCODER);
2492 return mo ? obj_to_encoder(mo) : NULL;
2493}
2494
Rob Clarka2b34e22013-10-05 16:36:52 -04002495static inline struct drm_connector *drm_connector_find(struct drm_device *dev,
2496 uint32_t id)
2497{
2498 struct drm_mode_object *mo;
2499 mo = drm_mode_object_find(dev, id, DRM_MODE_OBJECT_CONNECTOR);
2500 return mo ? obj_to_connector(mo) : NULL;
2501}
2502
2503static inline struct drm_property *drm_property_find(struct drm_device *dev,
2504 uint32_t id)
2505{
2506 struct drm_mode_object *mo;
2507 mo = drm_mode_object_find(dev, id, DRM_MODE_OBJECT_PROPERTY);
2508 return mo ? obj_to_property(mo) : NULL;
2509}
2510
Matt Ropere27dde32014-04-01 15:22:30 -07002511/* Plane list iterator for legacy (overlay only) planes. */
Daniel Vetter4ea50e92015-07-09 23:44:24 +02002512#define drm_for_each_legacy_plane(plane, dev) \
2513 list_for_each_entry(plane, &(dev)->mode_config.plane_list, head) \
Jani Nikula373701b2015-11-24 21:21:55 +02002514 for_each_if (plane->type == DRM_PLANE_TYPE_OVERLAY)
Matt Ropere27dde32014-04-01 15:22:30 -07002515
Daniel Vetter6295d602015-07-09 23:44:25 +02002516#define drm_for_each_plane(plane, dev) \
2517 list_for_each_entry(plane, &(dev)->mode_config.plane_list, head)
2518
2519#define drm_for_each_crtc(crtc, dev) \
2520 list_for_each_entry(crtc, &(dev)->mode_config.crtc_list, head)
2521
Daniel Vetter7a3f3d62015-07-09 23:44:28 +02002522static inline void
2523assert_drm_connector_list_read_locked(struct drm_mode_config *mode_config)
2524{
Daniel Vettercff20ba2015-07-09 23:44:33 +02002525 /*
2526 * The connector hotadd/remove code currently grabs both locks when
2527 * updating lists. Hence readers need only hold either of them to be
2528 * safe and the check amounts to
2529 *
2530 * WARN_ON(not_holding(A) && not_holding(B)).
2531 */
2532 WARN_ON(!mutex_is_locked(&mode_config->mutex) &&
2533 !drm_modeset_is_locked(&mode_config->connection_mutex));
Daniel Vetter7a3f3d62015-07-09 23:44:28 +02002534}
2535
Daniel Vetter6295d602015-07-09 23:44:25 +02002536#define drm_for_each_connector(connector, dev) \
Daniel Vetter7a3f3d62015-07-09 23:44:28 +02002537 for (assert_drm_connector_list_read_locked(&(dev)->mode_config), \
2538 connector = list_first_entry(&(dev)->mode_config.connector_list, \
2539 struct drm_connector, head); \
2540 &connector->head != (&(dev)->mode_config.connector_list); \
2541 connector = list_next_entry(connector, head))
Daniel Vetter6295d602015-07-09 23:44:25 +02002542
2543#define drm_for_each_encoder(encoder, dev) \
2544 list_for_each_entry(encoder, &(dev)->mode_config.encoder_list, head)
2545
2546#define drm_for_each_fb(fb, dev) \
Daniel Vetter4676ba02015-07-09 23:44:30 +02002547 for (WARN_ON(!mutex_is_locked(&(dev)->mode_config.fb_lock)), \
2548 fb = list_first_entry(&(dev)->mode_config.fb_list, \
2549 struct drm_framebuffer, head); \
2550 &fb->head != (&(dev)->mode_config.fb_list); \
2551 fb = list_next_entry(fb, head))
Daniel Vetter6295d602015-07-09 23:44:25 +02002552
Dave Airlief453ba02008-11-07 14:05:41 -08002553#endif /* __DRM_CRTC_H__ */