blob: 3b040b3554726e25132b8c11b42588743816e576 [file] [log] [blame]
Dave Airlief453ba02008-11-07 14:05:41 -08001/*
2 * Copyright © 2006 Keith Packard
3 * Copyright © 2007-2008 Dave Airlie
4 * Copyright © 2007-2008 Intel Corporation
5 * Jesse Barnes <jesse.barnes@intel.com>
6 *
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the "Software"),
9 * to deal in the Software without restriction, including without limitation
10 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
11 * and/or sell copies of the Software, and to permit persons to whom the
12 * Software is furnished to do so, subject to the following conditions:
13 *
14 * The above copyright notice and this permission notice shall be included in
15 * all copies or substantial portions of the Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
21 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
22 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
23 * OTHER DEALINGS IN THE SOFTWARE.
24 */
25#ifndef __DRM_CRTC_H__
26#define __DRM_CRTC_H__
27
28#include <linux/i2c.h>
29#include <linux/spinlock.h>
30#include <linux/types.h>
31#include <linux/idr.h>
Dave Airlief453ba02008-11-07 14:05:41 -080032#include <linux/fb.h>
Vandana Kannan985e5dc2013-12-19 15:34:07 +053033#include <linux/hdmi.h>
Boris Brezillonb5571e92014-07-22 12:09:10 +020034#include <linux/media-bus-format.h>
David Herrmannd7d2c482014-08-29 12:12:40 +020035#include <uapi/drm/drm_mode.h>
36#include <uapi/drm/drm_fourcc.h>
Rob Clark51fd3712013-11-19 12:10:12 -050037#include <drm/drm_modeset_lock.h>
Jesse Barnes308e5bc2011-11-14 14:51:28 -080038
Dave Airlief453ba02008-11-07 14:05:41 -080039struct drm_device;
40struct drm_mode_set;
41struct drm_framebuffer;
Paulo Zanoni7e3bdf42012-05-15 18:09:01 -030042struct drm_object_properties;
Thierry Reding595887e2012-11-21 15:00:47 +010043struct drm_file;
44struct drm_clip_rect;
Russell King7e435aa2014-06-15 11:07:12 +010045struct device_node;
Daniel Vettere2330f02014-10-29 11:34:56 +010046struct fence;
Dave Airlief453ba02008-11-07 14:05:41 -080047
48#define DRM_MODE_OBJECT_CRTC 0xcccccccc
49#define DRM_MODE_OBJECT_CONNECTOR 0xc0c0c0c0
50#define DRM_MODE_OBJECT_ENCODER 0xe0e0e0e0
51#define DRM_MODE_OBJECT_MODE 0xdededede
52#define DRM_MODE_OBJECT_PROPERTY 0xb0b0b0b0
53#define DRM_MODE_OBJECT_FB 0xfbfbfbfb
54#define DRM_MODE_OBJECT_BLOB 0xbbbbbbbb
Jesse Barnes8cf5c912011-11-14 14:51:27 -080055#define DRM_MODE_OBJECT_PLANE 0xeeeeeeee
Rob Clark98f75de2014-05-30 11:37:03 -040056#define DRM_MODE_OBJECT_ANY 0
Dave Airlief453ba02008-11-07 14:05:41 -080057
58struct drm_mode_object {
59 uint32_t id;
60 uint32_t type;
Paulo Zanoni7e3bdf42012-05-15 18:09:01 -030061 struct drm_object_properties *properties;
62};
63
Paulo Zanonife456162012-06-12 11:27:01 -030064#define DRM_OBJECT_MAX_PROPERTY 24
Paulo Zanoni7e3bdf42012-05-15 18:09:01 -030065struct drm_object_properties {
Rob Clark88a48e22014-12-18 16:01:50 -050066 int count, atomic_count;
Rob Clarkb17cd752014-12-16 18:05:30 -050067 /* NOTE: if we ever start dynamically destroying properties (ie.
68 * not at drm_mode_config_cleanup() time), then we'd have to do
69 * a better job of detaching property from mode objects to avoid
70 * dangling property pointers:
71 */
72 struct drm_property *properties[DRM_OBJECT_MAX_PROPERTY];
Rob Clark22b8b132014-12-16 18:05:31 -050073 /* do not read/write values directly, but use drm_object_property_get_value()
74 * and drm_object_property_set_value():
75 */
Paulo Zanoni7e3bdf42012-05-15 18:09:01 -030076 uint64_t values[DRM_OBJECT_MAX_PROPERTY];
Dave Airlief453ba02008-11-07 14:05:41 -080077};
78
Rob Clarkebc44cf2012-09-12 22:22:31 -050079static inline int64_t U642I64(uint64_t val)
80{
81 return (int64_t)*((int64_t *)&val);
82}
83static inline uint64_t I642U64(int64_t val)
84{
85 return (uint64_t)*((uint64_t *)&val);
86}
87
Robert Feketed9c38242015-11-02 16:14:08 +010088/*
89 * Rotation property bits. DRM_ROTATE_<degrees> rotates the image by the
90 * specified amount in degrees in counter clockwise direction. DRM_REFLECT_X and
91 * DRM_REFLECT_Y reflects the image along the specified axis prior to rotation
92 */
Joonas Lahtinen62209072015-10-01 10:00:57 +030093#define DRM_ROTATE_MASK 0x0f
Ville Syrjälä06596962014-07-08 10:31:51 +053094#define DRM_ROTATE_0 0
95#define DRM_ROTATE_90 1
96#define DRM_ROTATE_180 2
97#define DRM_ROTATE_270 3
Joonas Lahtinen62209072015-10-01 10:00:57 +030098#define DRM_REFLECT_MASK (~DRM_ROTATE_MASK)
Ville Syrjälä06596962014-07-08 10:31:51 +053099#define DRM_REFLECT_X 4
100#define DRM_REFLECT_Y 5
101
Daniel Vetter55310002014-01-23 15:52:20 +0100102enum drm_connector_force {
103 DRM_FORCE_UNSPECIFIED,
104 DRM_FORCE_OFF,
105 DRM_FORCE_ON, /* force on analog part normally */
106 DRM_FORCE_ON_DIGITAL, /* for DVI-I use digital connector */
Dave Airlief453ba02008-11-07 14:05:41 -0800107};
108
Daniel Vetter55310002014-01-23 15:52:20 +0100109#include <drm/drm_modes.h>
Damien Lespiau4aa17cf2013-09-25 16:45:21 +0100110
Dave Airlief453ba02008-11-07 14:05:41 -0800111enum drm_connector_status {
112 connector_status_connected = 1,
113 connector_status_disconnected = 2,
114 connector_status_unknown = 3,
115};
116
117enum subpixel_order {
118 SubPixelUnknown = 0,
119 SubPixelHorizontalRGB,
120 SubPixelHorizontalBGR,
121 SubPixelVerticalRGB,
122 SubPixelVerticalBGR,
123 SubPixelNone,
124};
125
Jesse Barnesda05a5a72011-04-15 13:48:57 -0700126#define DRM_COLOR_FORMAT_RGB444 (1<<0)
127#define DRM_COLOR_FORMAT_YCRCB444 (1<<1)
128#define DRM_COLOR_FORMAT_YCRCB422 (1<<2)
Dave Airlief453ba02008-11-07 14:05:41 -0800129/*
130 * Describes a given display (e.g. CRT or flat panel) and its limitations.
131 */
132struct drm_display_info {
133 char name[DRM_DISPLAY_INFO_LEN];
Adam Jacksonfb439642010-08-03 14:38:16 -0400134
Dave Airlief453ba02008-11-07 14:05:41 -0800135 /* Physical size */
136 unsigned int width_mm;
137 unsigned int height_mm;
138
Dave Airlief453ba02008-11-07 14:05:41 -0800139 /* Clock limits FIXME: storage format */
140 unsigned int min_vfreq, max_vfreq;
141 unsigned int min_hfreq, max_hfreq;
142 unsigned int pixel_clock;
Jesse Barnes3b112282011-04-15 12:49:23 -0700143 unsigned int bpc;
Dave Airlief453ba02008-11-07 14:05:41 -0800144
Dave Airlief453ba02008-11-07 14:05:41 -0800145 enum subpixel_order subpixel_order;
Jesse Barnesda05a5a72011-04-15 13:48:57 -0700146 u32 color_formats;
Dave Airlief453ba02008-11-07 14:05:41 -0800147
Boris Brezillonb5571e92014-07-22 12:09:10 +0200148 const u32 *bus_formats;
149 unsigned int num_bus_formats;
150
Mario Kleiner5d02626d2014-06-05 09:52:10 -0400151 /* Mask of supported hdmi deep color modes */
152 u8 edid_hdmi_dc_modes;
153
Jesse Barnesebec9a72011-08-03 09:22:54 -0700154 u8 cea_rev;
Dave Airlief453ba02008-11-07 14:05:41 -0800155};
156
Dave Airlie138f9eb2014-10-20 16:17:17 +1000157/* data corresponds to displayid vend/prod/serial */
158struct drm_tile_group {
159 struct kref refcount;
160 struct drm_device *dev;
161 int id;
162 u8 group_data[8];
163};
164
Daniel Vetterc6b0ca32015-12-04 09:46:01 +0100165/**
166 * struct drm_framebuffer_funcs - framebuffer hooks
167 */
Dave Airlief453ba02008-11-07 14:05:41 -0800168struct drm_framebuffer_funcs {
Daniel Vetterc6b0ca32015-12-04 09:46:01 +0100169 /**
170 * @destroy:
171 *
172 * Clean up framebuffer resources, specifically also unreference the
173 * backing storage. The core guarantees to call this function for every
174 * framebuffer successfully created by ->fb_create() in
Daniel Vetterd55f5322015-12-08 09:49:19 +0100175 * &drm_mode_config_funcs. Drivers must also call
176 * drm_framebuffer_cleanup() to release DRM core resources for this
177 * framebuffer.
Daniel Vetterc6b0ca32015-12-04 09:46:01 +0100178 */
Dave Airlief453ba02008-11-07 14:05:41 -0800179 void (*destroy)(struct drm_framebuffer *framebuffer);
Daniel Vetterc6b0ca32015-12-04 09:46:01 +0100180
181 /**
182 * @create_handle:
183 *
184 * Create a buffer handle in the driver-specific buffer manager (either
185 * GEM or TTM) valid for the passed-in struct &drm_file. This is used by
186 * the core to implement the GETFB IOCTL, which returns (for
187 * sufficiently priviledged user) also a native buffer handle. This can
188 * be used for seamless transitions between modesetting clients by
189 * copying the current screen contents to a private buffer and blending
190 * between that and the new contents.
191 *
Daniel Vetterd55f5322015-12-08 09:49:19 +0100192 * GEM based drivers should call drm_gem_handle_create() to create the
193 * handle.
194 *
Daniel Vetterc6b0ca32015-12-04 09:46:01 +0100195 * RETURNS:
196 *
197 * 0 on success or a negative error code on failure.
198 */
Dave Airlief453ba02008-11-07 14:05:41 -0800199 int (*create_handle)(struct drm_framebuffer *fb,
200 struct drm_file *file_priv,
201 unsigned int *handle);
Daniel Vetterc6b0ca32015-12-04 09:46:01 +0100202 /**
203 * @dirty:
Jakob Bornecrantz884840a2009-12-03 23:25:47 +0000204 *
Daniel Vetterc6b0ca32015-12-04 09:46:01 +0100205 * Optional callback for the dirty fb IOCTL.
Jakob Bornecrantz884840a2009-12-03 23:25:47 +0000206 *
Daniel Vetterc6b0ca32015-12-04 09:46:01 +0100207 * Userspace can notify the driver via this callback that an area of the
208 * framebuffer has changed and should be flushed to the display
209 * hardware. This can also be used internally, e.g. by the fbdev
210 * emulation, though that's not the case currently.
211 *
212 * See documentation in drm_mode.h for the struct drm_mode_fb_dirty_cmd
213 * for more information as all the semantics and arguments have a one to
214 * one mapping on this function.
215 *
216 * RETURNS:
217 *
218 * 0 on success or a negative error code on failure.
Jakob Bornecrantz884840a2009-12-03 23:25:47 +0000219 */
Thomas Hellstrom02b00162010-10-05 12:43:02 +0200220 int (*dirty)(struct drm_framebuffer *framebuffer,
221 struct drm_file *file_priv, unsigned flags,
Jakob Bornecrantz884840a2009-12-03 23:25:47 +0000222 unsigned color, struct drm_clip_rect *clips,
223 unsigned num_clips);
Dave Airlief453ba02008-11-07 14:05:41 -0800224};
225
226struct drm_framebuffer {
227 struct drm_device *dev;
Rob Clarkf7eff602012-09-05 21:48:38 +0000228 /*
229 * Note that the fb is refcounted for the benefit of driver internals,
230 * for example some hw, disabling a CRTC/plane is asynchronous, and
231 * scanout does not actually complete until the next vblank. So some
232 * cleanup (like releasing the reference(s) on the backing GEM bo(s))
233 * should be deferred. In cases like this, the driver would like to
234 * hold a ref to the fb even though it has already been removed from
235 * userspace perspective.
236 */
237 struct kref refcount;
Daniel Vetter4b096ac2012-12-10 21:19:18 +0100238 /*
239 * Place on the dev->mode_config.fb_list, access protected by
240 * dev->mode_config.fb_lock.
241 */
Dave Airlief453ba02008-11-07 14:05:41 -0800242 struct list_head head;
243 struct drm_mode_object base;
244 const struct drm_framebuffer_funcs *funcs;
Ville Syrjälä01f2c772011-12-20 00:06:49 +0200245 unsigned int pitches[4];
246 unsigned int offsets[4];
Rob Clarke3eb3252015-02-05 14:41:52 +0000247 uint64_t modifier[4];
Dave Airlief453ba02008-11-07 14:05:41 -0800248 unsigned int width;
249 unsigned int height;
250 /* depth can be 15 or 16 */
251 unsigned int depth;
252 int bits_per_pixel;
253 int flags;
Jesse Barnes308e5bc2011-11-14 14:51:28 -0800254 uint32_t pixel_format; /* fourcc format */
Dave Airlief453ba02008-11-07 14:05:41 -0800255 struct list_head filp_head;
256};
257
258struct drm_property_blob {
259 struct drm_mode_object base;
Daniel Stone6bcacf52015-04-20 19:22:55 +0100260 struct drm_device *dev;
261 struct kref refcount;
Daniel Stonee2f5d2e2015-05-22 13:34:51 +0100262 struct list_head head_global;
263 struct list_head head_file;
Thierry Redingecbbe592014-05-13 11:36:13 +0200264 size_t length;
Ville Syrjäläd63f5e62012-03-13 12:35:49 +0200265 unsigned char data[];
Dave Airlief453ba02008-11-07 14:05:41 -0800266};
267
268struct drm_property_enum {
269 uint64_t value;
270 struct list_head head;
271 char name[DRM_PROP_NAME_LEN];
272};
273
274struct drm_property {
275 struct list_head head;
276 struct drm_mode_object base;
277 uint32_t flags;
278 char name[DRM_PROP_NAME_LEN];
279 uint32_t num_values;
280 uint64_t *values;
Rob Clark98f75de2014-05-30 11:37:03 -0400281 struct drm_device *dev;
Dave Airlief453ba02008-11-07 14:05:41 -0800282
Daniel Vetter3758b342014-11-19 18:38:10 +0100283 struct list_head enum_list;
Dave Airlief453ba02008-11-07 14:05:41 -0800284};
285
286struct drm_crtc;
287struct drm_connector;
288struct drm_encoder;
Kristian Høgsbergd91d8a32009-11-17 12:43:55 -0500289struct drm_pending_vblank_event;
Jesse Barnes8cf5c912011-11-14 14:51:27 -0800290struct drm_plane;
Sean Paul3b336ec2013-08-14 16:47:37 -0400291struct drm_bridge;
Daniel Vetter144ecb92014-10-27 20:28:44 +0100292struct drm_atomic_state;
293
Daniel Vetter4490d4c2015-12-04 09:45:45 +0100294struct drm_crtc_helper_funcs;
295struct drm_encoder_helper_funcs;
296struct drm_connector_helper_funcs;
297struct drm_plane_helper_funcs;
298
Daniel Vetter144ecb92014-10-27 20:28:44 +0100299/**
Daniel Vettercc4ceb42014-07-25 21:30:38 +0200300 * struct drm_crtc_state - mutable CRTC state
Daniel Vetter07cc0ef2014-11-27 15:49:39 +0100301 * @crtc: backpointer to the CRTC
Daniel Vetter144ecb92014-10-27 20:28:44 +0100302 * @enable: whether the CRTC should be enabled, gates all other state
Daniel Vetterd9b13622014-11-26 16:57:41 +0100303 * @active: whether the CRTC is actively displaying (used for DPMS)
Maarten Lankhorstfc596662015-07-21 13:28:57 +0200304 * @planes_changed: planes on this crtc are updated
305 * @mode_changed: crtc_state->mode or crtc_state->enable has been changed
306 * @active_changed: crtc_state->active has been toggled.
307 * @connectors_changed: connectors to this crtc have been updated
Rob Clark6ddd3882014-11-21 15:28:31 -0500308 * @plane_mask: bitmask of (1 << drm_plane_index(plane)) of attached planes
Daniel Vetter623369e2014-09-16 17:50:47 +0200309 * @last_vblank_count: for helpers and drivers to capture the vblank of the
310 * update to ensure framebuffer cleanup isn't done too early
Daniel Vetter2f324b42014-10-29 11:13:47 +0100311 * @adjusted_mode: for use by helpers and drivers to compute adjusted mode timings
Daniel Vetter144ecb92014-10-27 20:28:44 +0100312 * @mode: current mode timings
313 * @event: optional pointer to a DRM event to signal upon completion of the
314 * state update
315 * @state: backpointer to global drm_atomic_state
Daniel Vetterd9b13622014-11-26 16:57:41 +0100316 *
317 * Note that the distinction between @enable and @active is rather subtile:
318 * Flipping @active while @enable is set without changing anything else may
319 * never return in a failure from the ->atomic_check callback. Userspace assumes
320 * that a DPMS On will always succeed. In other words: @enable controls resource
321 * assignment, @active controls the actual hardware state.
Daniel Vetter144ecb92014-10-27 20:28:44 +0100322 */
323struct drm_crtc_state {
Daniel Vetter07cc0ef2014-11-27 15:49:39 +0100324 struct drm_crtc *crtc;
325
Daniel Vettercc4ceb42014-07-25 21:30:38 +0200326 bool enable;
Daniel Vetterd9b13622014-11-26 16:57:41 +0100327 bool active;
Daniel Vetter144ecb92014-10-27 20:28:44 +0100328
Daniel Vetterc2fcd272014-11-05 00:14:14 +0100329 /* computed state bits used by helpers and drivers */
330 bool planes_changed : 1;
Daniel Vetter623369e2014-09-16 17:50:47 +0200331 bool mode_changed : 1;
Daniel Vettereab3bbe2015-01-22 16:36:21 +0100332 bool active_changed : 1;
Maarten Lankhorstfc596662015-07-21 13:28:57 +0200333 bool connectors_changed : 1;
Daniel Vetter623369e2014-09-16 17:50:47 +0200334
Rob Clark6ddd3882014-11-21 15:28:31 -0500335 /* attached planes bitmask:
336 * WARNING: transitional helpers do not maintain plane_mask so
337 * drivers not converted over to atomic helpers should not rely
338 * on plane_mask being accurate!
339 */
340 u32 plane_mask;
341
Daniel Vetter623369e2014-09-16 17:50:47 +0200342 /* last_vblank_count: for vblank waits before cleanup */
343 u32 last_vblank_count;
Daniel Vetterc2fcd272014-11-05 00:14:14 +0100344
Daniel Vetter2f324b42014-10-29 11:13:47 +0100345 /* adjusted_mode: for use by helpers and drivers */
346 struct drm_display_mode adjusted_mode;
347
Daniel Vetter144ecb92014-10-27 20:28:44 +0100348 struct drm_display_mode mode;
349
Daniel Stone99cf4a22015-05-25 19:11:51 +0100350 /* blob property to expose current mode to atomic userspace */
351 struct drm_property_blob *mode_blob;
352
Daniel Vetter144ecb92014-10-27 20:28:44 +0100353 struct drm_pending_vblank_event *event;
354
355 struct drm_atomic_state *state;
356};
Dave Airlief453ba02008-11-07 14:05:41 -0800357
358/**
Daniel Vetter3bf04012014-10-27 16:54:27 +0100359 * struct drm_crtc_funcs - control CRTCs for a given device
Dave Airlief453ba02008-11-07 14:05:41 -0800360 *
361 * The drm_crtc_funcs structure is the central CRTC management structure
362 * in the DRM. Each CRTC controls one or more connectors (note that the name
363 * CRTC is simply historical, a CRTC may control LVDS, VGA, DVI, TV out, etc.
364 * connectors, not just CRTs).
365 *
366 * Each driver is responsible for filling out this structure at startup time,
367 * in addition to providing other modesetting features, like i2c and DDC
368 * bus accessors.
369 */
370struct drm_crtc_funcs {
Daniel Vetter88548632015-12-04 09:45:48 +0100371 /**
372 * @reset:
373 *
374 * Reset CRTC hardware and software state to off. This function isn't
375 * called by the core directly, only through drm_mode_config_reset().
376 * It's not a helper hook only for historical reasons.
377 *
378 * Atomic drivers can use drm_atomic_helper_crtc_reset() to reset
379 * atomic state using this hook.
380 */
Chris Wilsoneb033552011-01-24 15:11:08 +0000381 void (*reset)(struct drm_crtc *crtc);
Dave Airlief453ba02008-11-07 14:05:41 -0800382
Daniel Vetterf6da8c62015-12-04 09:46:00 +0100383 /**
384 * @cursor_set:
385 *
386 * Update the cursor image. The cursor position is relative to the CRTC
387 * and can be partially or fully outside of the visible area.
388 *
389 * Note that contrary to all other KMS functions the legacy cursor entry
390 * points don't take a framebuffer object, but instead take directly a
391 * raw buffer object id from the driver's buffer manager (which is
392 * either GEM or TTM for current drivers).
393 *
394 * This entry point is deprecated, drivers should instead implement
395 * universal plane support and register a proper cursor plane using
396 * drm_crtc_init_with_planes().
397 *
398 * This callback is optional
399 *
400 * RETURNS:
401 *
402 * 0 on success or a negative error code on failure.
403 */
Dave Airlief453ba02008-11-07 14:05:41 -0800404 int (*cursor_set)(struct drm_crtc *crtc, struct drm_file *file_priv,
405 uint32_t handle, uint32_t width, uint32_t height);
Daniel Vetterf6da8c62015-12-04 09:46:00 +0100406
407 /**
408 * @cursor_set2:
409 *
410 * Update the cursor image, including hotspot information. The hotspot
411 * must not affect the cursor position in CRTC coordinates, but is only
412 * meant as a hint for virtualized display hardware to coordinate the
413 * guests and hosts cursor position. The cursor hotspot is relative to
414 * the cursor image. Otherwise this works exactly like @cursor_set.
415 *
416 * This entry point is deprecated, drivers should instead implement
417 * universal plane support and register a proper cursor plane using
418 * drm_crtc_init_with_planes().
419 *
420 * This callback is optional.
421 *
422 * RETURNS:
423 *
424 * 0 on success or a negative error code on failure.
425 */
Dave Airlie4c813d42013-06-20 11:48:52 +1000426 int (*cursor_set2)(struct drm_crtc *crtc, struct drm_file *file_priv,
427 uint32_t handle, uint32_t width, uint32_t height,
428 int32_t hot_x, int32_t hot_y);
Daniel Vetterf6da8c62015-12-04 09:46:00 +0100429
430 /**
431 * @cursor_move:
432 *
433 * Update the cursor position. The cursor does not need to be visible
434 * when this hook is called.
435 *
436 * This entry point is deprecated, drivers should instead implement
437 * universal plane support and register a proper cursor plane using
438 * drm_crtc_init_with_planes().
439 *
440 * This callback is optional.
441 *
442 * RETURNS:
443 *
444 * 0 on success or a negative error code on failure.
445 */
Dave Airlief453ba02008-11-07 14:05:41 -0800446 int (*cursor_move)(struct drm_crtc *crtc, int x, int y);
447
Daniel Vetterf6da8c62015-12-04 09:46:00 +0100448 /**
449 * @gamma_set:
450 *
451 * Set gamma on the CRTC.
452 *
453 * This callback is optional.
454 *
455 * NOTE:
456 *
457 * Drivers that support gamma tables and also fbdev emulation through
458 * the provided helper library need to take care to fill out the gamma
459 * hooks for both. Currently there's a bit an unfortunate duplication
460 * going on, which should eventually be unified to just one set of
461 * hooks.
462 */
Dave Airlief453ba02008-11-07 14:05:41 -0800463 void (*gamma_set)(struct drm_crtc *crtc, u16 *r, u16 *g, u16 *b,
James Simmons72034252010-08-03 01:33:19 +0100464 uint32_t start, uint32_t size);
Daniel Vetter88548632015-12-04 09:45:48 +0100465
466 /**
467 * @destroy:
468 *
469 * Clean up plane resources. This is only called at driver unload time
470 * through drm_mode_config_cleanup() since a CRTC cannot be hotplugged
471 * in DRM.
472 */
Dave Airlief453ba02008-11-07 14:05:41 -0800473 void (*destroy)(struct drm_crtc *crtc);
474
Daniel Vetterf6da8c62015-12-04 09:46:00 +0100475 /**
476 * @set_config:
477 *
478 * This is the main legacy entry point to change the modeset state on a
479 * CRTC. All the details of the desired configuration are passed in a
480 * struct &drm_mode_set - see there for details.
481 *
482 * Drivers implementing atomic modeset should use
483 * drm_atomic_helper_set_config() to implement this hook.
484 *
485 * RETURNS:
486 *
487 * 0 on success or a negative error code on failure.
488 */
Dave Airlief453ba02008-11-07 14:05:41 -0800489 int (*set_config)(struct drm_mode_set *set);
Kristian Høgsbergd91d8a32009-11-17 12:43:55 -0500490
Daniel Vetterf6da8c62015-12-04 09:46:00 +0100491 /**
492 * @page_flip:
493 *
494 * Legacy entry point to schedule a flip to the given framebuffer.
495 *
496 * Page flipping is a synchronization mechanism that replaces the frame
497 * buffer being scanned out by the CRTC with a new frame buffer during
498 * vertical blanking, avoiding tearing (except when requested otherwise
499 * through the DRM_MODE_PAGE_FLIP_ASYNC flag). When an application
500 * requests a page flip the DRM core verifies that the new frame buffer
501 * is large enough to be scanned out by the CRTC in the currently
502 * configured mode and then calls the CRTC ->page_flip() operation with a
503 * pointer to the new frame buffer.
504 *
505 * The driver must wait for any pending rendering to the new framebuffer
506 * to complete before executing the flip. It should also wait for any
507 * pending rendering from other drivers if the underlying buffer is a
508 * shared dma-buf.
509 *
510 * An application can request to be notified when the page flip has
511 * completed. The drm core will supply a struct &drm_event in the event
512 * parameter in this case. This can be handled by the
513 * drm_crtc_send_vblank_event() function, which the driver should call on
514 * the provided event upon completion of the flip. Note that if
515 * the driver supports vblank signalling and timestamping the vblank
516 * counters and timestamps must agree with the ones returned from page
517 * flip events. With the current vblank helper infrastructure this can
518 * be achieved by holding a vblank reference while the page flip is
519 * pending, acquired through drm_crtc_vblank_get() and released with
520 * drm_crtc_vblank_put(). Drivers are free to implement their own vblank
521 * counter and timestamp tracking though, e.g. if they have accurate
522 * timestamp registers in hardware.
523 *
524 * FIXME:
525 *
526 * Up to that point drivers need to manage events themselves and can use
527 * even->base.list freely for that. Specifically they need to ensure
528 * that they don't send out page flip (or vblank) events for which the
529 * corresponding drm file has been closed already. The drm core
530 * unfortunately does not (yet) take care of that. Therefore drivers
531 * currently must clean up and release pending events in their
532 * ->preclose driver function.
533 *
534 * This callback is optional.
535 *
536 * NOTE:
537 *
538 * Very early versions of the KMS ABI mandated that the driver must
539 * block (but not reject) any rendering to the old framebuffer until the
540 * flip operation has completed and the old framebuffer is no longer
541 * visible. This requirement has been lifted, and userspace is instead
542 * expected to request delivery of an event and wait with recycling old
543 * buffers until such has been received.
544 *
545 * RETURNS:
546 *
547 * 0 on success or a negative error code on failure. Note that if a
548 * ->page_flip() operation is already pending the callback should return
549 * -EBUSY. Pageflips on a disabled CRTC (either by setting a NULL mode
550 * or just runtime disabled through DPMS respectively the new atomic
551 * "ACTIVE" state) should result in an -EINVAL error code.
Kristian Høgsbergd91d8a32009-11-17 12:43:55 -0500552 */
553 int (*page_flip)(struct drm_crtc *crtc,
554 struct drm_framebuffer *fb,
Keith Packarded8d1972013-07-22 18:49:58 -0700555 struct drm_pending_vblank_event *event,
556 uint32_t flags);
Paulo Zanonibffd9de02012-05-15 18:09:05 -0300557
Daniel Vetter88548632015-12-04 09:45:48 +0100558 /**
559 * @set_property:
560 *
561 * This is the legacy entry point to update a property attached to the
562 * CRTC.
563 *
564 * Drivers implementing atomic modeset should use
565 * drm_atomic_helper_crtc_set_property() to implement this hook.
566 *
567 * This callback is optional if the driver does not support any legacy
568 * driver-private properties.
569 *
570 * RETURNS:
571 *
572 * 0 on success or a negative error code on failure.
573 */
Paulo Zanonibffd9de02012-05-15 18:09:05 -0300574 int (*set_property)(struct drm_crtc *crtc,
575 struct drm_property *property, uint64_t val);
Daniel Vetter144ecb92014-10-27 20:28:44 +0100576
Daniel Vetter88548632015-12-04 09:45:48 +0100577 /**
578 * @atomic_duplicate_state:
579 *
580 * Duplicate the current atomic state for this CRTC and return it.
581 * The core and helpers gurantee that any atomic state duplicated with
582 * this hook and still owned by the caller (i.e. not transferred to the
583 * driver by calling ->atomic_commit() from struct
584 * &drm_mode_config_funcs) will be cleaned up by calling the
585 * @atomic_destroy_state hook in this structure.
586 *
587 * Atomic drivers which don't subclass struct &drm_crtc should use
588 * drm_atomic_helper_crtc_duplicate_state(). Drivers that subclass the
589 * state structure to extend it with driver-private state should use
590 * __drm_atomic_helper_crtc_duplicate_state() to make sure shared state is
591 * duplicated in a consistent fashion across drivers.
592 *
593 * It is an error to call this hook before crtc->state has been
594 * initialized correctly.
595 *
596 * NOTE:
597 *
598 * If the duplicate state references refcounted resources this hook must
599 * acquire a reference for each of them. The driver must release these
600 * references again in @atomic_destroy_state.
601 *
602 * RETURNS:
603 *
604 * Duplicated atomic state or NULL when the allocation failed.
605 */
Daniel Vetter144ecb92014-10-27 20:28:44 +0100606 struct drm_crtc_state *(*atomic_duplicate_state)(struct drm_crtc *crtc);
Daniel Vetter88548632015-12-04 09:45:48 +0100607
608 /**
609 * @atomic_destroy_state:
610 *
611 * Destroy a state duplicated with @atomic_duplicate_state and release
612 * or unreference all resources it references
613 */
Daniel Vetter144ecb92014-10-27 20:28:44 +0100614 void (*atomic_destroy_state)(struct drm_crtc *crtc,
Daniel Vettercc4ceb42014-07-25 21:30:38 +0200615 struct drm_crtc_state *state);
Daniel Vetter88548632015-12-04 09:45:48 +0100616
617 /**
618 * @atomic_set_property:
619 *
620 * Decode a driver-private property value and store the decoded value
621 * into the passed-in state structure. Since the atomic core decodes all
622 * standardized properties (even for extensions beyond the core set of
623 * properties which might not be implemented by all drivers) this
624 * requires drivers to subclass the state structure.
625 *
626 * Such driver-private properties should really only be implemented for
627 * truly hardware/vendor specific state. Instead it is preferred to
628 * standardize atomic extension and decode the properties used to expose
629 * such an extension in the core.
630 *
631 * Do not call this function directly, use
632 * drm_atomic_crtc_set_property() instead.
633 *
634 * This callback is optional if the driver does not support any
635 * driver-private atomic properties.
636 *
637 * NOTE:
638 *
639 * This function is called in the state assembly phase of atomic
640 * modesets, which can be aborted for any reason (including on
641 * userspace's request to just check whether a configuration would be
642 * possible). Drivers MUST NOT touch any persistent state (hardware or
643 * software) or data structures except the passed in @state parameter.
644 *
645 * Also since userspace controls in which order properties are set this
646 * function must not do any input validation (since the state update is
647 * incomplete and hence likely inconsistent). Instead any such input
648 * validation must be done in the various atomic_check callbacks.
649 *
650 * RETURNS:
651 *
652 * 0 if the property has been found, -EINVAL if the property isn't
653 * implemented by the driver (which should never happen, the core only
654 * asks for properties attached to this CRTC). No other validation is
655 * allowed by the driver. The core already checks that the property
656 * value is within the range (integer, valid enum value, ...) the driver
657 * set when registering the property.
658 */
Daniel Vetter144ecb92014-10-27 20:28:44 +0100659 int (*atomic_set_property)(struct drm_crtc *crtc,
660 struct drm_crtc_state *state,
661 struct drm_property *property,
662 uint64_t val);
Daniel Vetter88548632015-12-04 09:45:48 +0100663 /**
664 * @atomic_get_property:
665 *
666 * Reads out the decoded driver-private property. This is used to
Daniel Vetterc6b0ca32015-12-04 09:46:01 +0100667 * implement the GETCRTC IOCTL.
Daniel Vetter88548632015-12-04 09:45:48 +0100668 *
669 * Do not call this function directly, use
670 * drm_atomic_crtc_get_property() instead.
671 *
672 * This callback is optional if the driver does not support any
673 * driver-private atomic properties.
674 *
675 * RETURNS:
676 *
677 * 0 on success, -EINVAL if the property isn't implemented by the
678 * driver (which should never happen, the core only asks for
679 * properties attached to this CRTC).
680 */
Rob Clarkac9c9252014-12-18 16:01:47 -0500681 int (*atomic_get_property)(struct drm_crtc *crtc,
682 const struct drm_crtc_state *state,
683 struct drm_property *property,
684 uint64_t *val);
Dave Airlief453ba02008-11-07 14:05:41 -0800685};
686
687/**
Daniel Vetter3bf04012014-10-27 16:54:27 +0100688 * struct drm_crtc - central CRTC control structure
Jesse Barnes77491632011-11-07 12:03:14 -0800689 * @dev: parent DRM device
Daniel Vetter2c0c33d2014-10-27 20:19:38 +0100690 * @port: OF node used by drm_of_find_possible_crtcs()
Jesse Barnes77491632011-11-07 12:03:14 -0800691 * @head: list management
Rob Clark51fd3712013-11-19 12:10:12 -0500692 * @mutex: per-CRTC locking
Jesse Barnes77491632011-11-07 12:03:14 -0800693 * @base: base KMS object for ID tracking etc.
Matt Ropere13161a2014-04-01 15:22:38 -0700694 * @primary: primary plane for this CRTC
695 * @cursor: cursor plane for this CRTC
Daniel Vetter2c0c33d2014-10-27 20:19:38 +0100696 * @cursor_x: current x position of the cursor, used for universal cursor planes
697 * @cursor_y: current y position of the cursor, used for universal cursor planes
Dave Airlief453ba02008-11-07 14:05:41 -0800698 * @enabled: is this CRTC enabled?
Jesse Barnes77491632011-11-07 12:03:14 -0800699 * @mode: current mode timings
700 * @hwmode: mode timings as programmed to hw regs
Dave Airlief453ba02008-11-07 14:05:41 -0800701 * @x: x position on screen
702 * @y: y position on screen
Dave Airlief453ba02008-11-07 14:05:41 -0800703 * @funcs: CRTC control functions
Jesse Barnes77491632011-11-07 12:03:14 -0800704 * @gamma_size: size of gamma ramp
705 * @gamma_store: gamma ramp values
Jesse Barnes77491632011-11-07 12:03:14 -0800706 * @helper_private: mid-layer private data
Paulo Zanonibffd9de02012-05-15 18:09:05 -0300707 * @properties: property tracking for this CRTC
Daniel Vetter144ecb92014-10-27 20:28:44 +0100708 * @state: current atomic state for this CRTC
Daniel Vetter2c0c33d2014-10-27 20:19:38 +0100709 * @acquire_ctx: per-CRTC implicit acquire context used by atomic drivers for
Daniel Vetterc6b0ca32015-12-04 09:46:01 +0100710 * legacy IOCTLs
Dave Airlief453ba02008-11-07 14:05:41 -0800711 *
712 * Each CRTC may have one or more connectors associated with it. This structure
713 * allows the CRTC to be controlled.
714 */
715struct drm_crtc {
716 struct drm_device *dev;
Russell King7e435aa2014-06-15 11:07:12 +0100717 struct device_node *port;
Dave Airlief453ba02008-11-07 14:05:41 -0800718 struct list_head head;
719
Ville Syrjäläfa3ab4c2015-12-08 18:41:53 +0200720 char *name;
721
Daniel Vetter3bf04012014-10-27 16:54:27 +0100722 /*
Daniel Vetter29494c12012-12-02 02:18:25 +0100723 * crtc mutex
724 *
725 * This provides a read lock for the overall crtc state (mode, dpms
726 * state, ...) and a write lock for everything which can be update
727 * without a full modeset (fb, cursor data, ...)
728 */
Rob Clark51fd3712013-11-19 12:10:12 -0500729 struct drm_modeset_lock mutex;
Daniel Vetter29494c12012-12-02 02:18:25 +0100730
Dave Airlief453ba02008-11-07 14:05:41 -0800731 struct drm_mode_object base;
732
Matt Ropere13161a2014-04-01 15:22:38 -0700733 /* primary and cursor planes for CRTC */
734 struct drm_plane *primary;
735 struct drm_plane *cursor;
736
Matt Roper161d0dc2014-06-10 08:28:10 -0700737 /* position of cursor plane on crtc */
738 int cursor_x;
739 int cursor_y;
740
Dave Airlief453ba02008-11-07 14:05:41 -0800741 bool enabled;
742
Mario Kleiner27641c32010-10-23 04:20:23 +0200743 /* Requested mode from modesetting. */
Dave Airlief453ba02008-11-07 14:05:41 -0800744 struct drm_display_mode mode;
745
Mario Kleiner27641c32010-10-23 04:20:23 +0200746 /* Programmed mode in hw, after adjustments for encoders,
747 * crtc, panel scaling etc. Needed for timestamping etc.
748 */
749 struct drm_display_mode hwmode;
750
Dave Airlief453ba02008-11-07 14:05:41 -0800751 int x, y;
Dave Airlief453ba02008-11-07 14:05:41 -0800752 const struct drm_crtc_funcs *funcs;
753
754 /* CRTC gamma size for reporting to userspace */
755 uint32_t gamma_size;
756 uint16_t *gamma_store;
757
758 /* if you are using the helper */
Daniel Vetter4490d4c2015-12-04 09:45:45 +0100759 const struct drm_crtc_helper_funcs *helper_private;
Paulo Zanonibffd9de02012-05-15 18:09:05 -0300760
761 struct drm_object_properties properties;
Daniel Vetterd059f652014-07-25 18:07:40 +0200762
Daniel Vetter144ecb92014-10-27 20:28:44 +0100763 struct drm_crtc_state *state;
764
Daniel Vetterd059f652014-07-25 18:07:40 +0200765 /*
Daniel Vetterc6b0ca32015-12-04 09:46:01 +0100766 * For legacy crtc IOCTLs so that atomic drivers can get at the locking
Daniel Vetterd059f652014-07-25 18:07:40 +0200767 * acquire context.
768 */
769 struct drm_modeset_acquire_ctx *acquire_ctx;
Dave Airlief453ba02008-11-07 14:05:41 -0800770};
771
Daniel Vetter144ecb92014-10-27 20:28:44 +0100772/**
773 * struct drm_connector_state - mutable connector state
Daniel Vetter07cc0ef2014-11-27 15:49:39 +0100774 * @connector: backpointer to the connector
Daniel Vettercc4ceb42014-07-25 21:30:38 +0200775 * @crtc: CRTC to connect connector to, NULL if disabled
Daniel Vetter623369e2014-09-16 17:50:47 +0200776 * @best_encoder: can be used by helpers and drivers to select the encoder
Daniel Vetter144ecb92014-10-27 20:28:44 +0100777 * @state: backpointer to global drm_atomic_state
778 */
779struct drm_connector_state {
Daniel Vetter07cc0ef2014-11-27 15:49:39 +0100780 struct drm_connector *connector;
781
Rob Clark6ddd3882014-11-21 15:28:31 -0500782 struct drm_crtc *crtc; /* do not write directly, use drm_atomic_set_crtc_for_connector() */
Daniel Vetter144ecb92014-10-27 20:28:44 +0100783
Daniel Vetter623369e2014-09-16 17:50:47 +0200784 struct drm_encoder *best_encoder;
785
Daniel Vetter144ecb92014-10-27 20:28:44 +0100786 struct drm_atomic_state *state;
787};
Dave Airlief453ba02008-11-07 14:05:41 -0800788
789/**
Daniel Vetter3bf04012014-10-27 16:54:27 +0100790 * struct drm_connector_funcs - control connectors on a given device
Daniel Vetter144ecb92014-10-27 20:28:44 +0100791 *
Dave Airlief453ba02008-11-07 14:05:41 -0800792 * Each CRTC may have one or more connectors attached to it. The functions
793 * below allow the core DRM code to control connectors, enumerate available modes,
794 * etc.
795 */
796struct drm_connector_funcs {
Daniel Vetter6fe14ac2015-12-04 09:45:58 +0100797 /**
798 * @dpms:
799 *
800 * Legacy entry point to set the per-connector DPMS state. Legacy DPMS
801 * is exposed as a standard property on the connector, but diverted to
802 * this callback in the drm core. Note that atomic drivers don't
803 * implement the 4 level DPMS support on the connector any more, but
804 * instead only have an on/off "ACTIVE" property on the CRTC object.
805 *
806 * Drivers implementing atomic modeset should use
807 * drm_atomic_helper_connector_dpms() to implement this hook.
808 *
809 * RETURNS:
810 *
811 * 0 on success or a negative error code on failure.
812 */
Maarten Lankhorst9a69a9a2015-07-21 11:34:55 +0200813 int (*dpms)(struct drm_connector *connector, int mode);
Daniel Vetter88548632015-12-04 09:45:48 +0100814
815 /**
816 * @reset:
817 *
818 * Reset connector hardware and software state to off. This function isn't
819 * called by the core directly, only through drm_mode_config_reset().
820 * It's not a helper hook only for historical reasons.
821 *
822 * Atomic drivers can use drm_atomic_helper_connector_reset() to reset
823 * atomic state using this hook.
824 */
Chris Wilsoneb033552011-01-24 15:11:08 +0000825 void (*reset)(struct drm_connector *connector);
Chris Wilson930a9e22010-09-14 11:07:23 +0100826
Daniel Vetter6fe14ac2015-12-04 09:45:58 +0100827 /**
828 * @detect:
829 *
830 * Check to see if anything is attached to the connector. The parameter
831 * force is set to false whilst polling, true when checking the
832 * connector due to a user request. force can be used by the driver to
833 * avoid expensive, destructive operations during automated probing.
834 *
835 * FIXME:
836 *
837 * Note that this hook is only called by the probe helper. It's not in
838 * the helper library vtable purely for historical reasons. The only DRM
839 * core entry point to probe connector state is @fill_modes.
840 *
841 * RETURNS:
842 *
843 * drm_connector_status indicating the connector's status.
Chris Wilson930a9e22010-09-14 11:07:23 +0100844 */
Chris Wilson7b334fc2010-09-09 23:51:02 +0100845 enum drm_connector_status (*detect)(struct drm_connector *connector,
Chris Wilson930a9e22010-09-14 11:07:23 +0100846 bool force);
Daniel Vetter6fe14ac2015-12-04 09:45:58 +0100847
848 /**
849 * @force:
850 *
851 * This function is called to update internal encoder state when the
852 * connector is forced to a certain state by userspace, either through
853 * the sysfs interfaces or on the kernel cmdline. In that case the
854 * @detect callback isn't called.
855 *
856 * FIXME:
857 *
858 * Note that this hook is only called by the probe helper. It's not in
859 * the helper library vtable purely for historical reasons. The only DRM
860 * core entry point to probe connector state is @fill_modes.
861 */
862 void (*force)(struct drm_connector *connector);
863
864 /**
865 * @fill_modes:
866 *
867 * Entry point for output detection and basic mode validation. The
868 * driver should reprobe the output if needed (e.g. when hotplug
869 * handling is unreliable), add all detected modes to connector->modes
870 * and filter out any the device can't support in any configuration. It
871 * also needs to filter out any modes wider or higher than the
872 * parameters max_width and max_height indicate.
873 *
874 * The drivers must also prune any modes no longer valid from
875 * connector->modes. Furthermore it must update connector->status and
876 * connector->edid. If no EDID has been received for this output
877 * connector->edid must be NULL.
878 *
879 * Drivers using the probe helpers should use
880 * drm_helper_probe_single_connector_modes() or
881 * drm_helper_probe_single_connector_modes_nomerge() to implement this
882 * function.
883 *
884 * RETURNS:
885 *
886 * The number of modes detected and filled into connector->modes.
887 */
Jesse Barnes40a518d2009-01-12 12:05:32 -0800888 int (*fill_modes)(struct drm_connector *connector, uint32_t max_width, uint32_t max_height);
Daniel Vetter88548632015-12-04 09:45:48 +0100889
890 /**
891 * @set_property:
892 *
893 * This is the legacy entry point to update a property attached to the
894 * connector.
895 *
896 * Drivers implementing atomic modeset should use
897 * drm_atomic_helper_connector_set_property() to implement this hook.
898 *
899 * This callback is optional if the driver does not support any legacy
900 * driver-private properties.
901 *
902 * RETURNS:
903 *
904 * 0 on success or a negative error code on failure.
905 */
Dave Airlief453ba02008-11-07 14:05:41 -0800906 int (*set_property)(struct drm_connector *connector, struct drm_property *property,
907 uint64_t val);
Daniel Vetter88548632015-12-04 09:45:48 +0100908
909 /**
910 * @destroy:
911 *
912 * Clean up connector resources. This is called at driver unload time
913 * through drm_mode_config_cleanup(). It can also be called at runtime
914 * when a connector is being hot-unplugged for drivers that support
915 * connector hotplugging (e.g. DisplayPort MST).
916 */
Dave Airlief453ba02008-11-07 14:05:41 -0800917 void (*destroy)(struct drm_connector *connector);
Daniel Vetter144ecb92014-10-27 20:28:44 +0100918
Daniel Vetter88548632015-12-04 09:45:48 +0100919 /**
920 * @atomic_duplicate_state:
921 *
922 * Duplicate the current atomic state for this connector and return it.
923 * The core and helpers gurantee that any atomic state duplicated with
924 * this hook and still owned by the caller (i.e. not transferred to the
925 * driver by calling ->atomic_commit() from struct
926 * &drm_mode_config_funcs) will be cleaned up by calling the
927 * @atomic_destroy_state hook in this structure.
928 *
929 * Atomic drivers which don't subclass struct &drm_connector_state should use
930 * drm_atomic_helper_connector_duplicate_state(). Drivers that subclass the
931 * state structure to extend it with driver-private state should use
932 * __drm_atomic_helper_connector_duplicate_state() to make sure shared state is
933 * duplicated in a consistent fashion across drivers.
934 *
935 * It is an error to call this hook before connector->state has been
936 * initialized correctly.
937 *
938 * NOTE:
939 *
940 * If the duplicate state references refcounted resources this hook must
941 * acquire a reference for each of them. The driver must release these
942 * references again in @atomic_destroy_state.
943 *
944 * RETURNS:
945 *
946 * Duplicated atomic state or NULL when the allocation failed.
947 */
Daniel Vetter144ecb92014-10-27 20:28:44 +0100948 struct drm_connector_state *(*atomic_duplicate_state)(struct drm_connector *connector);
Daniel Vetter88548632015-12-04 09:45:48 +0100949
950 /**
951 * @atomic_destroy_state:
952 *
953 * Destroy a state duplicated with @atomic_duplicate_state and release
954 * or unreference all resources it references
955 */
Daniel Vetter144ecb92014-10-27 20:28:44 +0100956 void (*atomic_destroy_state)(struct drm_connector *connector,
Daniel Vettercc4ceb42014-07-25 21:30:38 +0200957 struct drm_connector_state *state);
Daniel Vetter88548632015-12-04 09:45:48 +0100958
959 /**
960 * @atomic_set_property:
961 *
962 * Decode a driver-private property value and store the decoded value
963 * into the passed-in state structure. Since the atomic core decodes all
964 * standardized properties (even for extensions beyond the core set of
965 * properties which might not be implemented by all drivers) this
966 * requires drivers to subclass the state structure.
967 *
968 * Such driver-private properties should really only be implemented for
969 * truly hardware/vendor specific state. Instead it is preferred to
970 * standardize atomic extension and decode the properties used to expose
971 * such an extension in the core.
972 *
973 * Do not call this function directly, use
974 * drm_atomic_connector_set_property() instead.
975 *
976 * This callback is optional if the driver does not support any
977 * driver-private atomic properties.
978 *
979 * NOTE:
980 *
981 * This function is called in the state assembly phase of atomic
982 * modesets, which can be aborted for any reason (including on
983 * userspace's request to just check whether a configuration would be
984 * possible). Drivers MUST NOT touch any persistent state (hardware or
985 * software) or data structures except the passed in @state parameter.
986 *
987 * Also since userspace controls in which order properties are set this
988 * function must not do any input validation (since the state update is
989 * incomplete and hence likely inconsistent). Instead any such input
990 * validation must be done in the various atomic_check callbacks.
991 *
992 * RETURNS:
993 *
994 * 0 if the property has been found, -EINVAL if the property isn't
995 * implemented by the driver (which shouldn't ever happen, the core only
996 * asks for properties attached to this connector). No other validation
997 * is allowed by the driver. The core already checks that the property
998 * value is within the range (integer, valid enum value, ...) the driver
999 * set when registering the property.
1000 */
Daniel Vetter144ecb92014-10-27 20:28:44 +01001001 int (*atomic_set_property)(struct drm_connector *connector,
1002 struct drm_connector_state *state,
1003 struct drm_property *property,
1004 uint64_t val);
Daniel Vetter88548632015-12-04 09:45:48 +01001005
1006 /**
1007 * @atomic_get_property:
1008 *
1009 * Reads out the decoded driver-private property. This is used to
Daniel Vetterc6b0ca32015-12-04 09:46:01 +01001010 * implement the GETCONNECTOR IOCTL.
Daniel Vetter88548632015-12-04 09:45:48 +01001011 *
1012 * Do not call this function directly, use
1013 * drm_atomic_connector_get_property() instead.
1014 *
1015 * This callback is optional if the driver does not support any
1016 * driver-private atomic properties.
1017 *
1018 * RETURNS:
1019 *
1020 * 0 on success, -EINVAL if the property isn't implemented by the
1021 * driver (which shouldn't ever happen, the core only asks for
1022 * properties attached to this connector).
1023 */
Rob Clarkac9c9252014-12-18 16:01:47 -05001024 int (*atomic_get_property)(struct drm_connector *connector,
1025 const struct drm_connector_state *state,
1026 struct drm_property *property,
1027 uint64_t *val);
Dave Airlief453ba02008-11-07 14:05:41 -08001028};
1029
Jesse Barnes6c3db922011-11-07 12:03:16 -08001030/**
Daniel Vetter3bf04012014-10-27 16:54:27 +01001031 * struct drm_encoder_funcs - encoder controls
Jesse Barnes6c3db922011-11-07 12:03:16 -08001032 *
1033 * Encoders sit between CRTCs and connectors.
1034 */
Dave Airlief453ba02008-11-07 14:05:41 -08001035struct drm_encoder_funcs {
Daniel Vetter88548632015-12-04 09:45:48 +01001036 /**
1037 * @reset:
1038 *
1039 * Reset encoder hardware and software state to off. This function isn't
1040 * called by the core directly, only through drm_mode_config_reset().
1041 * It's not a helper hook only for historical reasons.
1042 */
Chris Wilsoneb033552011-01-24 15:11:08 +00001043 void (*reset)(struct drm_encoder *encoder);
Daniel Vetter88548632015-12-04 09:45:48 +01001044
1045 /**
1046 * @destroy:
1047 *
1048 * Clean up encoder resources. This is only called at driver unload time
1049 * through drm_mode_config_cleanup() since an encoder cannot be
1050 * hotplugged in DRM.
1051 */
Dave Airlief453ba02008-11-07 14:05:41 -08001052 void (*destroy)(struct drm_encoder *encoder);
1053};
1054
Ben Skeggsafe887d2012-01-12 16:00:57 +10001055#define DRM_CONNECTOR_MAX_ENCODER 3
Dave Airlief453ba02008-11-07 14:05:41 -08001056
1057/**
Daniel Vetter3bf04012014-10-27 16:54:27 +01001058 * struct drm_encoder - central DRM encoder structure
Jesse Barnesdb3e4492011-11-07 12:03:17 -08001059 * @dev: parent DRM device
1060 * @head: list management
1061 * @base: base KMS object
Jani Nikulae5748942014-05-14 16:58:20 +03001062 * @name: encoder name
Jesse Barnesdb3e4492011-11-07 12:03:17 -08001063 * @encoder_type: one of the %DRM_MODE_ENCODER_<foo> types in drm_mode.h
1064 * @possible_crtcs: bitmask of potential CRTC bindings
1065 * @possible_clones: bitmask of potential sibling encoders for cloning
1066 * @crtc: currently bound CRTC
Sean Paul3b336ec2013-08-14 16:47:37 -04001067 * @bridge: bridge associated to the encoder
Jesse Barnesdb3e4492011-11-07 12:03:17 -08001068 * @funcs: control functions
1069 * @helper_private: mid-layer private data
1070 *
1071 * CRTCs drive pixels to encoders, which convert them into signals
1072 * appropriate for a given connector or set of connectors.
Dave Airlief453ba02008-11-07 14:05:41 -08001073 */
1074struct drm_encoder {
1075 struct drm_device *dev;
1076 struct list_head head;
1077
1078 struct drm_mode_object base;
Jani Nikulae5748942014-05-14 16:58:20 +03001079 char *name;
Dave Airlief453ba02008-11-07 14:05:41 -08001080 int encoder_type;
1081 uint32_t possible_crtcs;
1082 uint32_t possible_clones;
1083
1084 struct drm_crtc *crtc;
Sean Paul3b336ec2013-08-14 16:47:37 -04001085 struct drm_bridge *bridge;
Dave Airlief453ba02008-11-07 14:05:41 -08001086 const struct drm_encoder_funcs *funcs;
Daniel Vetter4490d4c2015-12-04 09:45:45 +01001087 const struct drm_encoder_helper_funcs *helper_private;
Dave Airlief453ba02008-11-07 14:05:41 -08001088};
1089
Dave Airlieeb1f8e42010-05-07 06:42:51 +00001090/* should we poll this connector for connects and disconnects */
1091/* hot plug detectable */
1092#define DRM_CONNECTOR_POLL_HPD (1 << 0)
1093/* poll for connections */
1094#define DRM_CONNECTOR_POLL_CONNECT (1 << 1)
1095/* can cleanly poll for disconnections without flickering the screen */
1096/* DACs should rarely do this without a lot of testing */
1097#define DRM_CONNECTOR_POLL_DISCONNECT (1 << 2)
1098
Wu Fengguang76adaa342011-09-05 14:23:20 +08001099#define MAX_ELD_BYTES 128
1100
Dave Airlief453ba02008-11-07 14:05:41 -08001101/**
Daniel Vetter3bf04012014-10-27 16:54:27 +01001102 * struct drm_connector - central DRM connector control structure
Jesse Barnes72252542011-11-07 12:03:18 -08001103 * @dev: parent DRM device
1104 * @kdev: kernel device for sysfs attributes
1105 * @attr: sysfs attributes
1106 * @head: list management
1107 * @base: base KMS object
Jani Nikula2abdd312014-05-14 16:58:19 +03001108 * @name: connector name
Jesse Barnes72252542011-11-07 12:03:18 -08001109 * @connector_type: one of the %DRM_MODE_CONNECTOR_<foo> types from drm_mode.h
1110 * @connector_type_id: index into connector type enum
Dave Airlief453ba02008-11-07 14:05:41 -08001111 * @interlace_allowed: can this connector handle interlaced modes?
1112 * @doublescan_allowed: can this connector handle doublescan?
Daniel Vetter2c0c33d2014-10-27 20:19:38 +01001113 * @stereo_allowed: can this connector handle stereo modes?
Jesse Barnes72252542011-11-07 12:03:18 -08001114 * @modes: modes available on this connector (from fill_modes() + user)
1115 * @status: one of the drm_connector_status enums (connected, not, or unknown)
1116 * @probed_modes: list of modes derived directly from the display
1117 * @display_info: information about attached display (e.g. from EDID)
Dave Airlief453ba02008-11-07 14:05:41 -08001118 * @funcs: connector control functions
Jesse Barnes72252542011-11-07 12:03:18 -08001119 * @edid_blob_ptr: DRM property containing EDID if present
Paulo Zanoni7e3bdf42012-05-15 18:09:01 -03001120 * @properties: property tracking for this connector
Daniel Vetter2c0c33d2014-10-27 20:19:38 +01001121 * @path_blob_ptr: DRM blob property data for the DP MST path property
Jesse Barnes72252542011-11-07 12:03:18 -08001122 * @polled: a %DRM_CONNECTOR_POLL_<foo> value for core driven polling
1123 * @dpms: current dpms state
1124 * @helper_private: mid-layer private data
Daniel Vetter2c0c33d2014-10-27 20:19:38 +01001125 * @cmdline_mode: mode line parsed from the kernel cmdline for this connector
Jesse Barnes72252542011-11-07 12:03:18 -08001126 * @force: a %DRM_FORCE_<foo> state for forced mode sets
Daniel Vetter2c0c33d2014-10-27 20:19:38 +01001127 * @override_edid: has the EDID been overwritten through debugfs for testing?
Jesse Barnes72252542011-11-07 12:03:18 -08001128 * @encoder_ids: valid encoders for this connector
1129 * @encoder: encoder driving this connector, if any
1130 * @eld: EDID-like data, if present
1131 * @dvi_dual: dual link DVI, if found
1132 * @max_tmds_clock: max clock rate, if found
1133 * @latency_present: AV delay info from ELD, if found
1134 * @video_latency: video latency info from ELD, if found
1135 * @audio_latency: audio latency info from ELD, if found
1136 * @null_edid_counter: track sinks that give us all zeros for the EDID
Daniel Vetter2c0c33d2014-10-27 20:19:38 +01001137 * @bad_edid_counter: track sinks that give us an EDID with invalid checksum
Daniel Vetterac6f2e22015-05-08 16:15:41 +02001138 * @edid_corrupt: indicates whether the last read EDID was corrupt
Daniel Vetter2c0c33d2014-10-27 20:19:38 +01001139 * @debugfs_entry: debugfs directory for this connector
Daniel Vetter144ecb92014-10-27 20:28:44 +01001140 * @state: current atomic state for this connector
Dave Airlie40d9b042014-10-20 16:29:33 +10001141 * @has_tile: is this connector connected to a tiled monitor
1142 * @tile_group: tile group for the connected monitor
1143 * @tile_is_single_monitor: whether the tile is one monitor housing
1144 * @num_h_tile: number of horizontal tiles in the tile group
1145 * @num_v_tile: number of vertical tiles in the tile group
1146 * @tile_h_loc: horizontal location of this tile
1147 * @tile_v_loc: vertical location of this tile
1148 * @tile_h_size: horizontal size of this tile.
1149 * @tile_v_size: vertical size of this tile.
Dave Airlief453ba02008-11-07 14:05:41 -08001150 *
1151 * Each connector may be connected to one or more CRTCs, or may be clonable by
1152 * another connector if they can share a CRTC. Each connector also has a specific
1153 * position in the broader display (referred to as a 'screen' though it could
1154 * span multiple monitors).
1155 */
1156struct drm_connector {
1157 struct drm_device *dev;
Dave Airlie5bdebb12013-10-11 14:07:25 +10001158 struct device *kdev;
Dave Airlief453ba02008-11-07 14:05:41 -08001159 struct device_attribute *attr;
1160 struct list_head head;
1161
1162 struct drm_mode_object base;
1163
Jani Nikula2abdd312014-05-14 16:58:19 +03001164 char *name;
Dave Airlief453ba02008-11-07 14:05:41 -08001165 int connector_type;
1166 int connector_type_id;
1167 bool interlace_allowed;
1168 bool doublescan_allowed;
Damien Lespiau560a0672013-09-25 16:45:29 +01001169 bool stereo_allowed;
Dave Airlief453ba02008-11-07 14:05:41 -08001170 struct list_head modes; /* list of modes on this connector */
1171
Dave Airlief453ba02008-11-07 14:05:41 -08001172 enum drm_connector_status status;
1173
1174 /* these are modes added by probing with DDC or the BIOS */
1175 struct list_head probed_modes;
1176
1177 struct drm_display_info display_info;
1178 const struct drm_connector_funcs *funcs;
1179
Dave Airlief453ba02008-11-07 14:05:41 -08001180 struct drm_property_blob *edid_blob_ptr;
Paulo Zanoni7e3bdf42012-05-15 18:09:01 -03001181 struct drm_object_properties properties;
Dave Airlief453ba02008-11-07 14:05:41 -08001182
Dave Airlie43aba7e2014-06-05 14:01:31 +10001183 struct drm_property_blob *path_blob_ptr;
1184
Dave Airlie6f134d72014-10-20 16:30:50 +10001185 struct drm_property_blob *tile_blob_ptr;
1186
Dave Airlieeb1f8e42010-05-07 06:42:51 +00001187 uint8_t polled; /* DRM_CONNECTOR_POLL_* */
1188
Keith Packardc9fb15f2009-05-30 20:42:28 -07001189 /* requested DPMS state */
1190 int dpms;
1191
Daniel Vetter4490d4c2015-12-04 09:45:45 +01001192 const struct drm_connector_helper_funcs *helper_private;
Dave Airlief453ba02008-11-07 14:05:41 -08001193
Dave Airlied50ba252009-09-23 14:44:08 +10001194 /* forced on connector */
Chris Wilsoneaf99c72014-08-06 10:08:32 +02001195 struct drm_cmdline_mode cmdline_mode;
Dave Airlied50ba252009-09-23 14:44:08 +10001196 enum drm_connector_force force;
Thomas Wood4cf2b282014-06-18 17:52:33 +01001197 bool override_edid;
Dave Airlief453ba02008-11-07 14:05:41 -08001198 uint32_t encoder_ids[DRM_CONNECTOR_MAX_ENCODER];
Dave Airlief453ba02008-11-07 14:05:41 -08001199 struct drm_encoder *encoder; /* currently active encoder */
Dave Airlie4a9a8b72011-06-14 06:13:55 +00001200
Wu Fengguang76adaa342011-09-05 14:23:20 +08001201 /* EDID bits */
1202 uint8_t eld[MAX_ELD_BYTES];
1203 bool dvi_dual;
1204 int max_tmds_clock; /* in MHz */
1205 bool latency_present[2];
1206 int video_latency[2]; /* [0]: progressive, [1]: interlaced */
1207 int audio_latency[2];
Dave Airlie4a9a8b72011-06-14 06:13:55 +00001208 int null_edid_counter; /* needed to workaround some HW bugs where we get all 0s */
Jerome Glisse0b2443e2012-08-09 11:25:51 -04001209 unsigned bad_edid_counter;
Thomas Wood30f65702014-06-18 17:52:32 +01001210
Todd Previte6ba2bd32015-04-21 11:09:41 -07001211 /* Flag for raw EDID header corruption - used in Displayport
1212 * compliance testing - * Displayport Link CTS Core 1.2 rev1.1 4.2.2.6
1213 */
1214 bool edid_corrupt;
1215
Thomas Wood30f65702014-06-18 17:52:32 +01001216 struct dentry *debugfs_entry;
Daniel Vetter144ecb92014-10-27 20:28:44 +01001217
1218 struct drm_connector_state *state;
Dave Airlie40d9b042014-10-20 16:29:33 +10001219
1220 /* DisplayID bits */
1221 bool has_tile;
1222 struct drm_tile_group *tile_group;
1223 bool tile_is_single_monitor;
1224
1225 uint8_t num_h_tile, num_v_tile;
1226 uint8_t tile_h_loc, tile_v_loc;
1227 uint16_t tile_h_size, tile_v_size;
Dave Airlief453ba02008-11-07 14:05:41 -08001228};
1229
1230/**
Daniel Vetter144ecb92014-10-27 20:28:44 +01001231 * struct drm_plane_state - mutable plane state
Daniel Vetter07cc0ef2014-11-27 15:49:39 +01001232 * @plane: backpointer to the plane
Daniel Vetter144ecb92014-10-27 20:28:44 +01001233 * @crtc: currently bound CRTC, NULL if disabled
Daniel Vettercc4ceb42014-07-25 21:30:38 +02001234 * @fb: currently bound framebuffer
Daniel Vettere2330f02014-10-29 11:34:56 +01001235 * @fence: optional fence to wait for before scanning out @fb
Daniel Vetter144ecb92014-10-27 20:28:44 +01001236 * @crtc_x: left position of visible portion of plane on crtc
1237 * @crtc_y: upper position of visible portion of plane on crtc
1238 * @crtc_w: width of visible portion of plane on crtc
1239 * @crtc_h: height of visible portion of plane on crtc
1240 * @src_x: left position of visible portion of plane within
1241 * plane (in 16.16)
1242 * @src_y: upper position of visible portion of plane within
1243 * plane (in 16.16)
1244 * @src_w: width of visible portion of plane (in 16.16)
1245 * @src_h: height of visible portion of plane (in 16.16)
1246 * @state: backpointer to global drm_atomic_state
1247 */
1248struct drm_plane_state {
Daniel Vetter07cc0ef2014-11-27 15:49:39 +01001249 struct drm_plane *plane;
1250
Rob Clark6ddd3882014-11-21 15:28:31 -05001251 struct drm_crtc *crtc; /* do not write directly, use drm_atomic_set_crtc_for_plane() */
1252 struct drm_framebuffer *fb; /* do not write directly, use drm_atomic_set_fb_for_plane() */
Daniel Vettere2330f02014-10-29 11:34:56 +01001253 struct fence *fence;
Daniel Vetter144ecb92014-10-27 20:28:44 +01001254
1255 /* Signed dest location allows it to be partially off screen */
1256 int32_t crtc_x, crtc_y;
1257 uint32_t crtc_w, crtc_h;
1258
1259 /* Source values are 16.16 fixed point */
1260 uint32_t src_x, src_y;
1261 uint32_t src_h, src_w;
1262
Matt Roper1da30622015-01-21 16:35:40 -08001263 /* Plane rotation */
1264 unsigned int rotation;
1265
Daniel Vetter144ecb92014-10-27 20:28:44 +01001266 struct drm_atomic_state *state;
1267};
1268
1269
1270/**
Daniel Vetter3bf04012014-10-27 16:54:27 +01001271 * struct drm_plane_funcs - driver plane control functions
Jesse Barnes8cf5c912011-11-14 14:51:27 -08001272 */
1273struct drm_plane_funcs {
Daniel Vetter88548632015-12-04 09:45:48 +01001274 /**
1275 * @update_plane:
1276 *
1277 * This is the legacy entry point to enable and configure the plane for
1278 * the given CRTC and framebuffer. It is never called to disable the
1279 * plane, i.e. the passed-in crtc and fb paramters are never NULL.
1280 *
1281 * The source rectangle in frame buffer memory coordinates is given by
1282 * the src_x, src_y, src_w and src_h parameters (as 16.16 fixed point
1283 * values). Devices that don't support subpixel plane coordinates can
1284 * ignore the fractional part.
1285 *
1286 * The destination rectangle in CRTC coordinates is given by the
1287 * crtc_x, crtc_y, crtc_w and crtc_h parameters (as integer values).
1288 * Devices scale the source rectangle to the destination rectangle. If
1289 * scaling is not supported, and the source rectangle size doesn't match
1290 * the destination rectangle size, the driver must return a
1291 * -<errorname>EINVAL</errorname> error.
1292 *
1293 * Drivers implementing atomic modeset should use
1294 * drm_atomic_helper_update_plane() to implement this hook.
1295 *
1296 * RETURNS:
1297 *
1298 * 0 on success or a negative error code on failure.
1299 */
Jesse Barnes8cf5c912011-11-14 14:51:27 -08001300 int (*update_plane)(struct drm_plane *plane,
1301 struct drm_crtc *crtc, struct drm_framebuffer *fb,
1302 int crtc_x, int crtc_y,
1303 unsigned int crtc_w, unsigned int crtc_h,
1304 uint32_t src_x, uint32_t src_y,
1305 uint32_t src_w, uint32_t src_h);
Daniel Vetter88548632015-12-04 09:45:48 +01001306
1307 /**
1308 * @disable_plane:
1309 *
1310 * This is the legacy entry point to disable the plane. The DRM core
Daniel Vetterc6b0ca32015-12-04 09:46:01 +01001311 * calls this method in response to a DRM_IOCTL_MODE_SETPLANE IOCTL call
Daniel Vetter88548632015-12-04 09:45:48 +01001312 * with the frame buffer ID set to 0. Disabled planes must not be
1313 * processed by the CRTC.
1314 *
1315 * Drivers implementing atomic modeset should use
1316 * drm_atomic_helper_disable_plane() to implement this hook.
1317 *
1318 * RETURNS:
1319 *
1320 * 0 on success or a negative error code on failure.
1321 */
Jesse Barnes8cf5c912011-11-14 14:51:27 -08001322 int (*disable_plane)(struct drm_plane *plane);
Daniel Vetter88548632015-12-04 09:45:48 +01001323
1324 /**
1325 * @destroy:
1326 *
1327 * Clean up plane resources. This is only called at driver unload time
1328 * through drm_mode_config_cleanup() since a plane cannot be hotplugged
1329 * in DRM.
1330 */
Jesse Barnes8cf5c912011-11-14 14:51:27 -08001331 void (*destroy)(struct drm_plane *plane);
Daniel Vetter88548632015-12-04 09:45:48 +01001332
1333 /**
1334 * @reset:
1335 *
1336 * Reset plane hardware and software state to off. This function isn't
1337 * called by the core directly, only through drm_mode_config_reset().
1338 * It's not a helper hook only for historical reasons.
1339 *
1340 * Atomic drivers can use drm_atomic_helper_plane_reset() to reset
1341 * atomic state using this hook.
1342 */
Daniel Vetter2a0d7cf2014-07-29 15:32:37 +02001343 void (*reset)(struct drm_plane *plane);
Rob Clark4d939142012-05-17 02:23:27 -06001344
Daniel Vetter88548632015-12-04 09:45:48 +01001345 /**
1346 * @set_property:
1347 *
1348 * This is the legacy entry point to update a property attached to the
1349 * plane.
1350 *
1351 * Drivers implementing atomic modeset should use
1352 * drm_atomic_helper_plane_set_property() to implement this hook.
1353 *
1354 * This callback is optional if the driver does not support any legacy
1355 * driver-private properties.
1356 *
1357 * RETURNS:
1358 *
1359 * 0 on success or a negative error code on failure.
1360 */
Rob Clark4d939142012-05-17 02:23:27 -06001361 int (*set_property)(struct drm_plane *plane,
1362 struct drm_property *property, uint64_t val);
Daniel Vetter144ecb92014-10-27 20:28:44 +01001363
Daniel Vetter88548632015-12-04 09:45:48 +01001364 /**
1365 * @atomic_duplicate_state:
1366 *
1367 * Duplicate the current atomic state for this plane and return it.
1368 * The core and helpers gurantee that any atomic state duplicated with
1369 * this hook and still owned by the caller (i.e. not transferred to the
1370 * driver by calling ->atomic_commit() from struct
1371 * &drm_mode_config_funcs) will be cleaned up by calling the
1372 * @atomic_destroy_state hook in this structure.
1373 *
1374 * Atomic drivers which don't subclass struct &drm_plane_state should use
1375 * drm_atomic_helper_plane_duplicate_state(). Drivers that subclass the
1376 * state structure to extend it with driver-private state should use
1377 * __drm_atomic_helper_plane_duplicate_state() to make sure shared state is
1378 * duplicated in a consistent fashion across drivers.
1379 *
1380 * It is an error to call this hook before plane->state has been
1381 * initialized correctly.
1382 *
1383 * NOTE:
1384 *
1385 * If the duplicate state references refcounted resources this hook must
1386 * acquire a reference for each of them. The driver must release these
1387 * references again in @atomic_destroy_state.
1388 *
1389 * RETURNS:
1390 *
1391 * Duplicated atomic state or NULL when the allocation failed.
1392 */
Daniel Vetter144ecb92014-10-27 20:28:44 +01001393 struct drm_plane_state *(*atomic_duplicate_state)(struct drm_plane *plane);
Daniel Vetter88548632015-12-04 09:45:48 +01001394
1395 /**
1396 * @atomic_destroy_state:
1397 *
1398 * Destroy a state duplicated with @atomic_duplicate_state and release
1399 * or unreference all resources it references
1400 */
Daniel Vetter144ecb92014-10-27 20:28:44 +01001401 void (*atomic_destroy_state)(struct drm_plane *plane,
Daniel Vettercc4ceb42014-07-25 21:30:38 +02001402 struct drm_plane_state *state);
Daniel Vetter88548632015-12-04 09:45:48 +01001403
1404 /**
1405 * @atomic_set_property:
1406 *
1407 * Decode a driver-private property value and store the decoded value
1408 * into the passed-in state structure. Since the atomic core decodes all
1409 * standardized properties (even for extensions beyond the core set of
1410 * properties which might not be implemented by all drivers) this
1411 * requires drivers to subclass the state structure.
1412 *
1413 * Such driver-private properties should really only be implemented for
1414 * truly hardware/vendor specific state. Instead it is preferred to
1415 * standardize atomic extension and decode the properties used to expose
1416 * such an extension in the core.
1417 *
1418 * Do not call this function directly, use
1419 * drm_atomic_plane_set_property() instead.
1420 *
1421 * This callback is optional if the driver does not support any
1422 * driver-private atomic properties.
1423 *
1424 * NOTE:
1425 *
1426 * This function is called in the state assembly phase of atomic
1427 * modesets, which can be aborted for any reason (including on
1428 * userspace's request to just check whether a configuration would be
1429 * possible). Drivers MUST NOT touch any persistent state (hardware or
1430 * software) or data structures except the passed in @state parameter.
1431 *
1432 * Also since userspace controls in which order properties are set this
1433 * function must not do any input validation (since the state update is
1434 * incomplete and hence likely inconsistent). Instead any such input
1435 * validation must be done in the various atomic_check callbacks.
1436 *
1437 * RETURNS:
1438 *
1439 * 0 if the property has been found, -EINVAL if the property isn't
1440 * implemented by the driver (which shouldn't ever happen, the core only
1441 * asks for properties attached to this plane). No other validation is
1442 * allowed by the driver. The core already checks that the property
1443 * value is within the range (integer, valid enum value, ...) the driver
1444 * set when registering the property.
1445 */
Daniel Vetter144ecb92014-10-27 20:28:44 +01001446 int (*atomic_set_property)(struct drm_plane *plane,
1447 struct drm_plane_state *state,
1448 struct drm_property *property,
1449 uint64_t val);
Daniel Vetter88548632015-12-04 09:45:48 +01001450
1451 /**
1452 * @atomic_get_property:
1453 *
1454 * Reads out the decoded driver-private property. This is used to
Daniel Vetterc6b0ca32015-12-04 09:46:01 +01001455 * implement the GETPLANE IOCTL.
Daniel Vetter88548632015-12-04 09:45:48 +01001456 *
1457 * Do not call this function directly, use
1458 * drm_atomic_plane_get_property() instead.
1459 *
1460 * This callback is optional if the driver does not support any
1461 * driver-private atomic properties.
1462 *
1463 * RETURNS:
1464 *
1465 * 0 on success, -EINVAL if the property isn't implemented by the
1466 * driver (which should never happen, the core only asks for
1467 * properties attached to this plane).
1468 */
Rob Clarkac9c9252014-12-18 16:01:47 -05001469 int (*atomic_get_property)(struct drm_plane *plane,
1470 const struct drm_plane_state *state,
1471 struct drm_property *property,
1472 uint64_t *val);
Jesse Barnes8cf5c912011-11-14 14:51:27 -08001473};
1474
Matt Ropere27dde32014-04-01 15:22:30 -07001475enum drm_plane_type {
1476 DRM_PLANE_TYPE_OVERLAY,
1477 DRM_PLANE_TYPE_PRIMARY,
1478 DRM_PLANE_TYPE_CURSOR,
1479};
1480
Daniel Vetter88548632015-12-04 09:45:48 +01001481
Jesse Barnes8cf5c912011-11-14 14:51:27 -08001482/**
Daniel Vetter3bf04012014-10-27 16:54:27 +01001483 * struct drm_plane - central DRM plane control structure
Jesse Barnes8cf5c912011-11-14 14:51:27 -08001484 * @dev: DRM device this plane belongs to
1485 * @head: for list management
1486 * @base: base mode object
1487 * @possible_crtcs: pipes this plane can be bound to
1488 * @format_types: array of formats supported by this plane
1489 * @format_count: number of formats supported
Laurent Pinchart7eb5f302015-03-09 10:41:07 +02001490 * @format_default: driver hasn't supplied supported formats for the plane
Jesse Barnes8cf5c912011-11-14 14:51:27 -08001491 * @crtc: currently bound CRTC
1492 * @fb: currently bound fb
Daniel Vetter2c0c33d2014-10-27 20:19:38 +01001493 * @old_fb: Temporary tracking of the old fb while a modeset is ongoing. Used by
1494 * drm_mode_set_config_internal() to implement correct refcounting.
Jesse Barnes8cf5c912011-11-14 14:51:27 -08001495 * @funcs: helper functions
Rob Clark4d939142012-05-17 02:23:27 -06001496 * @properties: property tracking for this plane
Matt Ropere27dde32014-04-01 15:22:30 -07001497 * @type: type of plane (overlay, primary, cursor)
Daniel Vetter144ecb92014-10-27 20:28:44 +01001498 * @state: current atomic state for this plane
Jesse Barnes8cf5c912011-11-14 14:51:27 -08001499 */
1500struct drm_plane {
1501 struct drm_device *dev;
1502 struct list_head head;
1503
Ville Syrjälä9f4c97a2015-12-08 18:41:54 +02001504 char *name;
1505
Daniel Vetter4d02e2d2014-11-11 10:12:00 +01001506 struct drm_modeset_lock mutex;
1507
Jesse Barnes8cf5c912011-11-14 14:51:27 -08001508 struct drm_mode_object base;
1509
1510 uint32_t possible_crtcs;
1511 uint32_t *format_types;
Thierry Reding45e37432015-08-12 16:54:28 +02001512 unsigned int format_count;
Laurent Pinchart7eb5f302015-03-09 10:41:07 +02001513 bool format_default;
Jesse Barnes8cf5c912011-11-14 14:51:27 -08001514
1515 struct drm_crtc *crtc;
1516 struct drm_framebuffer *fb;
1517
Daniel Vetter3d30a592014-07-27 13:42:42 +02001518 struct drm_framebuffer *old_fb;
1519
Jesse Barnes8cf5c912011-11-14 14:51:27 -08001520 const struct drm_plane_funcs *funcs;
Rob Clark4d939142012-05-17 02:23:27 -06001521
1522 struct drm_object_properties properties;
Matt Ropere27dde32014-04-01 15:22:30 -07001523
1524 enum drm_plane_type type;
Daniel Vetter144ecb92014-10-27 20:28:44 +01001525
Daniel Vetter4490d4c2015-12-04 09:45:45 +01001526 const struct drm_plane_helper_funcs *helper_private;
Daniel Vetterc2fcd272014-11-05 00:14:14 +01001527
Daniel Vetter144ecb92014-10-27 20:28:44 +01001528 struct drm_plane_state *state;
Jesse Barnes8cf5c912011-11-14 14:51:27 -08001529};
1530
1531/**
Daniel Vetter3bf04012014-10-27 16:54:27 +01001532 * struct drm_bridge_funcs - drm_bridge control functions
Ajay Kumar3d3f8b12015-01-20 22:08:44 +05301533 * @attach: Called during drm_bridge_attach
Sean Paul3b336ec2013-08-14 16:47:37 -04001534 */
1535struct drm_bridge_funcs {
Ajay Kumar3d3f8b12015-01-20 22:08:44 +05301536 int (*attach)(struct drm_bridge *bridge);
Daniel Vetterda024fe2015-12-04 09:45:47 +01001537
1538 /**
1539 * @mode_fixup:
1540 *
1541 * This callback is used to validate and adjust a mode. The paramater
1542 * mode is the display mode that should be fed to the next element in
1543 * the display chain, either the final &drm_connector or the next
1544 * &drm_bridge. The parameter adjusted_mode is the input mode the bridge
1545 * requires. It can be modified by this callback and does not need to
1546 * match mode.
1547 *
1548 * This is the only hook that allows a bridge to reject a modeset. If
1549 * this function passes all other callbacks must succeed for this
1550 * configuration.
1551 *
1552 * NOTE:
1553 *
1554 * This function is called in the check phase of atomic modesets, which
1555 * can be aborted for any reason (including on userspace's request to
1556 * just check whether a configuration would be possible). Drivers MUST
1557 * NOT touch any persistent state (hardware or software) or data
Daniel Vetter88548632015-12-04 09:45:48 +01001558 * structures except the passed in @state parameter.
Daniel Vetterda024fe2015-12-04 09:45:47 +01001559 *
1560 * RETURNS:
1561 *
1562 * True if an acceptable configuration is possible, false if the modeset
1563 * operation should be rejected.
1564 */
Sean Paul3b336ec2013-08-14 16:47:37 -04001565 bool (*mode_fixup)(struct drm_bridge *bridge,
1566 const struct drm_display_mode *mode,
1567 struct drm_display_mode *adjusted_mode);
Daniel Vetterda024fe2015-12-04 09:45:47 +01001568 /**
1569 * @disable:
1570 *
1571 * This callback should disable the bridge. It is called right before
1572 * the preceding element in the display pipe is disabled. If the
1573 * preceding element is a bridge this means it's called before that
1574 * bridge's ->disable() function. If the preceding element is a
1575 * &drm_encoder it's called right before the encoder's ->disable(),
1576 * ->prepare() or ->dpms() hook from struct &drm_encoder_helper_funcs.
1577 *
1578 * The bridge can assume that the display pipe (i.e. clocks and timing
1579 * signals) feeding it is still running when this callback is called.
1580 */
Sean Paul3b336ec2013-08-14 16:47:37 -04001581 void (*disable)(struct drm_bridge *bridge);
Daniel Vetterda024fe2015-12-04 09:45:47 +01001582
1583 /**
1584 * @post_disable:
1585 *
1586 * This callback should disable the bridge. It is called right after
1587 * the preceding element in the display pipe is disabled. If the
1588 * preceding element is a bridge this means it's called after that
1589 * bridge's ->post_disable() function. If the preceding element is a
1590 * &drm_encoder it's called right after the encoder's ->disable(),
1591 * ->prepare() or ->dpms() hook from struct &drm_encoder_helper_funcs.
1592 *
1593 * The bridge must assume that the display pipe (i.e. clocks and timing
1594 * singals) feeding it is no longer running when this callback is
1595 * called.
1596 */
Sean Paul3b336ec2013-08-14 16:47:37 -04001597 void (*post_disable)(struct drm_bridge *bridge);
Daniel Vetterda024fe2015-12-04 09:45:47 +01001598
1599 /**
1600 * @mode_set:
1601 *
1602 * This callback should set the given mode on the bridge. It is called
1603 * after the ->mode_set() callback for the preceding element in the
1604 * display pipeline has been called already. The display pipe (i.e.
1605 * clocks and timing signals) is off when this function is called.
1606 */
Sean Paul3b336ec2013-08-14 16:47:37 -04001607 void (*mode_set)(struct drm_bridge *bridge,
1608 struct drm_display_mode *mode,
1609 struct drm_display_mode *adjusted_mode);
Daniel Vetterda024fe2015-12-04 09:45:47 +01001610 /**
1611 * @pre_enable:
1612 *
1613 * This callback should enable the bridge. It is called right before
1614 * the preceding element in the display pipe is enabled. If the
1615 * preceding element is a bridge this means it's called before that
1616 * bridge's ->pre_enable() function. If the preceding element is a
1617 * &drm_encoder it's called right before the encoder's ->enable(),
1618 * ->commit() or ->dpms() hook from struct &drm_encoder_helper_funcs.
1619 *
1620 * The display pipe (i.e. clocks and timing signals) feeding this bridge
1621 * will not yet be running when this callback is called. The bridge must
1622 * not enable the display link feeding the next bridge in the chain (if
1623 * there is one) when this callback is called.
1624 */
Sean Paul3b336ec2013-08-14 16:47:37 -04001625 void (*pre_enable)(struct drm_bridge *bridge);
Daniel Vetterda024fe2015-12-04 09:45:47 +01001626
1627 /**
1628 * @enable:
1629 *
1630 * This callback should enable the bridge. It is called right after
1631 * the preceding element in the display pipe is enabled. If the
1632 * preceding element is a bridge this means it's called after that
1633 * bridge's ->enable() function. If the preceding element is a
1634 * &drm_encoder it's called right after the encoder's ->enable(),
1635 * ->commit() or ->dpms() hook from struct &drm_encoder_helper_funcs.
1636 *
1637 * The bridge can assume that the display pipe (i.e. clocks and timing
1638 * signals) feeding it is running when this callback is called. This
1639 * callback must enable the display link feeding the next bridge in the
1640 * chain if there is one.
1641 */
Sean Paul3b336ec2013-08-14 16:47:37 -04001642 void (*enable)(struct drm_bridge *bridge);
Sean Paul3b336ec2013-08-14 16:47:37 -04001643};
1644
1645/**
Daniel Vetter3bf04012014-10-27 16:54:27 +01001646 * struct drm_bridge - central DRM bridge control structure
Sean Paul3b336ec2013-08-14 16:47:37 -04001647 * @dev: DRM device this bridge belongs to
Archit Taneja862e6862015-05-21 11:03:16 +05301648 * @encoder: encoder to which this bridge is connected
1649 * @next: the next bridge in the encoder chain
Ajay Kumar3d3f8b12015-01-20 22:08:44 +05301650 * @of_node: device node pointer to the bridge
1651 * @list: to keep track of all added bridges
Sean Paul3b336ec2013-08-14 16:47:37 -04001652 * @funcs: control functions
1653 * @driver_private: pointer to the bridge driver's internal context
1654 */
1655struct drm_bridge {
1656 struct drm_device *dev;
Ajay Kumar3d3f8b12015-01-20 22:08:44 +05301657 struct drm_encoder *encoder;
Archit Taneja862e6862015-05-21 11:03:16 +05301658 struct drm_bridge *next;
Ajay Kumar3d3f8b12015-01-20 22:08:44 +05301659#ifdef CONFIG_OF
1660 struct device_node *of_node;
1661#endif
1662 struct list_head list;
Sean Paul3b336ec2013-08-14 16:47:37 -04001663
1664 const struct drm_bridge_funcs *funcs;
1665 void *driver_private;
1666};
1667
1668/**
Rob Clark08855fa2015-03-11 10:23:09 -04001669 * struct drm_atomic_state - the global state object for atomic updates
Daniel Vettercc4ceb42014-07-25 21:30:38 +02001670 * @dev: parent DRM device
Rob Clarkd34f20d2014-12-18 16:01:56 -05001671 * @allow_modeset: allow full modeset
Daniel Vetterc6b0ca32015-12-04 09:46:01 +01001672 * @legacy_cursor_update: hint to enforce legacy cursor IOCTL semantics
Daniel Vettercc4ceb42014-07-25 21:30:38 +02001673 * @planes: pointer to array of plane pointers
1674 * @plane_states: pointer to array of plane states pointers
1675 * @crtcs: pointer to array of CRTC pointers
1676 * @crtc_states: pointer to array of CRTC states pointers
Daniel Vetterf52b69f12014-11-19 18:38:08 +01001677 * @num_connector: size of the @connectors and @connector_states arrays
Daniel Vettercc4ceb42014-07-25 21:30:38 +02001678 * @connectors: pointer to array of connector pointers
1679 * @connector_states: pointer to array of connector states pointers
1680 * @acquire_ctx: acquire context for this atomic modeset state update
1681 */
1682struct drm_atomic_state {
1683 struct drm_device *dev;
Rob Clarkd34f20d2014-12-18 16:01:56 -05001684 bool allow_modeset : 1;
Daniel Vetterf02ad902015-01-22 16:36:23 +01001685 bool legacy_cursor_update : 1;
Daniel Vettercc4ceb42014-07-25 21:30:38 +02001686 struct drm_plane **planes;
1687 struct drm_plane_state **plane_states;
1688 struct drm_crtc **crtcs;
1689 struct drm_crtc_state **crtc_states;
Daniel Vetterf52b69f12014-11-19 18:38:08 +01001690 int num_connector;
Daniel Vettercc4ceb42014-07-25 21:30:38 +02001691 struct drm_connector **connectors;
1692 struct drm_connector_state **connector_states;
1693
1694 struct drm_modeset_acquire_ctx *acquire_ctx;
1695};
1696
1697
1698/**
Daniel Vetter3bf04012014-10-27 16:54:27 +01001699 * struct drm_mode_set - new values for a CRTC config change
Jesse Barnesef273512011-11-07 12:03:19 -08001700 * @fb: framebuffer to use for new config
1701 * @crtc: CRTC whose configuration we're about to change
1702 * @mode: mode timings to use
1703 * @x: position of this CRTC relative to @fb
1704 * @y: position of this CRTC relative to @fb
1705 * @connectors: array of connectors to drive with this CRTC if possible
1706 * @num_connectors: size of @connectors array
Dave Airlief453ba02008-11-07 14:05:41 -08001707 *
1708 * Represents a single crtc the connectors that it drives with what mode
1709 * and from which framebuffer it scans out from.
1710 *
1711 * This is used to set modes.
1712 */
1713struct drm_mode_set {
Dave Airlief453ba02008-11-07 14:05:41 -08001714 struct drm_framebuffer *fb;
1715 struct drm_crtc *crtc;
1716 struct drm_display_mode *mode;
1717
1718 uint32_t x;
1719 uint32_t y;
1720
1721 struct drm_connector **connectors;
1722 size_t num_connectors;
1723};
1724
1725/**
Jesse Barnes550cebc2011-11-07 12:03:20 -08001726 * struct drm_mode_config_funcs - basic driver provided mode setting functions
Jesse Barnes550cebc2011-11-07 12:03:20 -08001727 *
1728 * Some global (i.e. not per-CRTC, connector, etc) mode setting functions that
1729 * involve drivers.
Dave Airlief453ba02008-11-07 14:05:41 -08001730 */
1731struct drm_mode_config_funcs {
Daniel Vetter9953f412015-12-04 09:46:02 +01001732 /**
1733 * @fb_create:
1734 *
1735 * Create a new framebuffer object. The core does basic checks on the
1736 * requested metadata, but most of that is left to the driver. See
1737 * struct &drm_mode_fb_cmd2 for details.
1738 *
Daniel Vetterd55f5322015-12-08 09:49:19 +01001739 * If the parameters are deemed valid and the backing storage objects in
1740 * the underlying memory manager all exist, then the driver allocates
1741 * a new &drm_framebuffer structure, subclassed to contain
1742 * driver-specific information (like the internal native buffer object
1743 * references). It also needs to fill out all relevant metadata, which
1744 * should be done by calling drm_helper_mode_fill_fb_struct().
1745 *
1746 * The initialization is finalized by calling drm_framebuffer_init(),
1747 * which registers the framebuffer and makes it accessible to other
1748 * threads.
1749 *
Daniel Vetter9953f412015-12-04 09:46:02 +01001750 * RETURNS:
1751 *
1752 * A new framebuffer with an initial reference count of 1 or a negative
1753 * error code encoded with ERR_PTR().
1754 */
Jesse Barnes550cebc2011-11-07 12:03:20 -08001755 struct drm_framebuffer *(*fb_create)(struct drm_device *dev,
1756 struct drm_file *file_priv,
Ville Syrjälä1eb83452015-11-11 19:11:29 +02001757 const struct drm_mode_fb_cmd2 *mode_cmd);
Daniel Vetter9953f412015-12-04 09:46:02 +01001758
1759 /**
1760 * @output_poll_changed:
1761 *
1762 * Callback used by helpers to inform the driver of output configuration
1763 * changes.
1764 *
1765 * Drivers implementing fbdev emulation with the helpers can call
1766 * drm_fb_helper_hotplug_changed from this hook to inform the fbdev
1767 * helper of output changes.
1768 *
1769 * FIXME:
1770 *
1771 * Except that there's no vtable for device-level helper callbacks
1772 * there's no reason this is a core function.
1773 */
Dave Airlieeb1f8e42010-05-07 06:42:51 +00001774 void (*output_poll_changed)(struct drm_device *dev);
Daniel Vettercc4ceb42014-07-25 21:30:38 +02001775
Daniel Vetter9953f412015-12-04 09:46:02 +01001776 /**
1777 * @atomic_check:
1778 *
1779 * This is the only hook to validate an atomic modeset update. This
1780 * function must reject any modeset and state changes which the hardware
1781 * or driver doesn't support. This includes but is of course not limited
1782 * to:
1783 *
1784 * - Checking that the modes, framebuffers, scaling and placement
1785 * requirements and so on are within the limits of the hardware.
1786 *
1787 * - Checking that any hidden shared resources are not oversubscribed.
1788 * This can be shared PLLs, shared lanes, overall memory bandwidth,
1789 * display fifo space (where shared between planes or maybe even
1790 * CRTCs).
1791 *
1792 * - Checking that virtualized resources exported to userspace are not
1793 * oversubscribed. For various reasons it can make sense to expose
1794 * more planes, crtcs or encoders than which are physically there. One
1795 * example is dual-pipe operations (which generally should be hidden
1796 * from userspace if when lockstepped in hardware, exposed otherwise),
1797 * where a plane might need 1 hardware plane (if it's just on one
1798 * pipe), 2 hardware planes (when it spans both pipes) or maybe even
1799 * shared a hardware plane with a 2nd plane (if there's a compatible
1800 * plane requested on the area handled by the other pipe).
1801 *
1802 * - Check that any transitional state is possible and that if
1803 * requested, the update can indeed be done in the vblank period
1804 * without temporarily disabling some functions.
1805 *
1806 * - Check any other constraints the driver or hardware might have.
1807 *
1808 * - This callback also needs to correctly fill out the &drm_crtc_state
1809 * in this update to make sure that drm_atomic_crtc_needs_modeset()
1810 * reflects the nature of the possible update and returns true if and
1811 * only if the update cannot be applied without tearing within one
1812 * vblank on that CRTC. The core uses that information to reject
1813 * updates which require a full modeset (i.e. blanking the screen, or
1814 * at least pausing updates for a substantial amount of time) if
1815 * userspace has disallowed that in its request.
1816 *
1817 * - The driver also does not need to repeat basic input validation
1818 * like done for the corresponding legacy entry points. The core does
1819 * that before calling this hook.
1820 *
1821 * See the documentation of @atomic_commit for an exhaustive list of
1822 * error conditions which don't have to be checked at the
1823 * ->atomic_check() stage?
1824 *
1825 * See the documentation for struct &drm_atomic_state for how exactly
1826 * an atomic modeset update is described.
1827 *
1828 * Drivers using the atomic helpers can implement this hook using
1829 * drm_atomic_helper_check(), or one of the exported sub-functions of
1830 * it.
1831 *
1832 * RETURNS:
1833 *
1834 * 0 on success or one of the below negative error codes:
1835 *
1836 * - -EINVAL, if any of the above constraints are violated.
1837 *
1838 * - -EDEADLK, when returned from an attempt to acquire an additional
1839 * &drm_modeset_lock through drm_modeset_lock().
1840 *
1841 * - -ENOMEM, if allocating additional state sub-structures failed due
1842 * to lack of memory.
1843 *
1844 * - -EINTR, -EAGAIN or -ERESTARTSYS, if the IOCTL should be restarted.
1845 * This can either be due to a pending signal, or because the driver
1846 * needs to completely bail out to recover from an exceptional
1847 * situation like a GPU hang. From a userspace point all errors are
1848 * treated equally.
1849 */
Daniel Vettercc4ceb42014-07-25 21:30:38 +02001850 int (*atomic_check)(struct drm_device *dev,
Daniel Vetter9953f412015-12-04 09:46:02 +01001851 struct drm_atomic_state *state);
1852
1853 /**
1854 * @atomic_commit:
1855 *
1856 * This is the only hook to commit an atomic modeset update. The core
1857 * guarantees that @atomic_check has been called successfully before
1858 * calling this function, and that nothing has been changed in the
1859 * interim.
1860 *
1861 * See the documentation for struct &drm_atomic_state for how exactly
1862 * an atomic modeset update is described.
1863 *
1864 * Drivers using the atomic helpers can implement this hook using
1865 * drm_atomic_helper_commit(), or one of the exported sub-functions of
1866 * it.
1867 *
1868 * Asynchronous commits (as indicated with the async parameter) must
1869 * do any preparatory work which might result in an unsuccessful commit
1870 * in the context of this callback. The only exceptions are hardware
1871 * errors resulting in -EIO. But even in that case the driver must
1872 * ensure that the display pipe is at least running, to avoid
1873 * compositors crashing when pageflips don't work. Anything else,
1874 * specifically committing the update to the hardware, should be done
1875 * without blocking the caller. For updates which do not require a
1876 * modeset this must be guaranteed.
1877 *
1878 * The driver must wait for any pending rendering to the new
1879 * framebuffers to complete before executing the flip. It should also
1880 * wait for any pending rendering from other drivers if the underlying
1881 * buffer is a shared dma-buf. Asynchronous commits must not wait for
1882 * rendering in the context of this callback.
1883 *
1884 * An application can request to be notified when the atomic commit has
1885 * completed. These events are per-CRTC and can be distinguished by the
1886 * CRTC index supplied in &drm_event to userspace.
1887 *
1888 * The drm core will supply a struct &drm_event in the event
1889 * member of each CRTC's &drm_crtc_state structure. This can be handled by the
1890 * drm_crtc_send_vblank_event() function, which the driver should call on
1891 * the provided event upon completion of the atomic commit. Note that if
1892 * the driver supports vblank signalling and timestamping the vblank
1893 * counters and timestamps must agree with the ones returned from page
1894 * flip events. With the current vblank helper infrastructure this can
1895 * be achieved by holding a vblank reference while the page flip is
1896 * pending, acquired through drm_crtc_vblank_get() and released with
1897 * drm_crtc_vblank_put(). Drivers are free to implement their own vblank
1898 * counter and timestamp tracking though, e.g. if they have accurate
1899 * timestamp registers in hardware.
1900 *
1901 * NOTE:
1902 *
1903 * Drivers are not allowed to shut down any display pipe successfully
1904 * enabled through an atomic commit on their own. Doing so can result in
1905 * compositors crashing if a page flip is suddenly rejected because the
1906 * pipe is off.
1907 *
1908 * RETURNS:
1909 *
1910 * 0 on success or one of the below negative error codes:
1911 *
1912 * - -EBUSY, if an asynchronous updated is requested and there is
1913 * an earlier updated pending. Drivers are allowed to support a queue
1914 * of outstanding updates, but currently no driver supports that.
1915 * Note that drivers must wait for preceding updates to complete if a
1916 * synchronous update is requested, they are not allowed to fail the
1917 * commit in that case.
1918 *
1919 * - -ENOMEM, if the driver failed to allocate memory. Specifically
1920 * this can happen when trying to pin framebuffers, which must only
1921 * be done when committing the state.
1922 *
1923 * - -ENOSPC, as a refinement of the more generic -ENOMEM to indicate
1924 * that the driver has run out of vram, iommu space or similar GPU
1925 * address space needed for framebuffer.
1926 *
1927 * - -EIO, if the hardware completely died.
1928 *
1929 * - -EINTR, -EAGAIN or -ERESTARTSYS, if the IOCTL should be restarted.
1930 * This can either be due to a pending signal, or because the driver
1931 * needs to completely bail out to recover from an exceptional
1932 * situation like a GPU hang. From a userspace point of view all errors are
1933 * treated equally.
1934 *
1935 * This list is exhaustive. Specifically this hook is not allowed to
1936 * return -EINVAL (any invalid requests should be caught in
1937 * @atomic_check) or -EDEADLK (this function must not acquire
1938 * additional modeset locks).
1939 */
Daniel Vettercc4ceb42014-07-25 21:30:38 +02001940 int (*atomic_commit)(struct drm_device *dev,
Daniel Vetter9953f412015-12-04 09:46:02 +01001941 struct drm_atomic_state *state,
Daniel Vettercc4ceb42014-07-25 21:30:38 +02001942 bool async);
Daniel Vetter9953f412015-12-04 09:46:02 +01001943
1944 /**
1945 * @atomic_state_alloc:
1946 *
1947 * This optional hook can be used by drivers that want to subclass struct
1948 * &drm_atomic_state to be able to track their own driver-private global
1949 * state easily. If this hook is implemented, drivers must also
1950 * implement @atomic_state_clear and @atomic_state_free.
1951 *
1952 * RETURNS:
1953 *
1954 * A new &drm_atomic_state on success or NULL on failure.
1955 */
Maarten Lankhorst036ef572015-05-18 10:06:40 +02001956 struct drm_atomic_state *(*atomic_state_alloc)(struct drm_device *dev);
Daniel Vetter9953f412015-12-04 09:46:02 +01001957
1958 /**
1959 * @atomic_state_clear:
1960 *
1961 * This hook must clear any driver private state duplicated into the
1962 * passed-in &drm_atomic_state. This hook is called when the caller
1963 * encountered a &drm_modeset_lock deadlock and needs to drop all
1964 * already acquired locks as part of the deadlock avoidance dance
1965 * implemented in drm_modeset_lock_backoff().
1966 *
1967 * Any duplicated state must be invalidated since a concurrent atomic
1968 * update might change it, and the drm atomic interfaces always apply
1969 * updates as relative changes to the current state.
1970 *
1971 * Drivers that implement this must call drm_atomic_state_default_clear()
1972 * to clear common state.
1973 */
Maarten Lankhorst036ef572015-05-18 10:06:40 +02001974 void (*atomic_state_clear)(struct drm_atomic_state *state);
Daniel Vetter9953f412015-12-04 09:46:02 +01001975
1976 /**
1977 * @atomic_state_free:
1978 *
1979 * This hook needs driver private resources and the &drm_atomic_state
1980 * itself. Note that the core first calls drm_atomic_state_clear() to
1981 * avoid code duplicate between the clear and free hooks.
1982 *
1983 * Drivers that implement this must call drm_atomic_state_default_free()
1984 * to release common resources.
1985 */
Maarten Lankhorst036ef572015-05-18 10:06:40 +02001986 void (*atomic_state_free)(struct drm_atomic_state *state);
Dave Airlief453ba02008-11-07 14:05:41 -08001987};
1988
Jesse Barnesc1aaca22011-11-07 12:03:21 -08001989/**
Daniel Vetter2c0c33d2014-10-27 20:19:38 +01001990 * struct drm_mode_config - Mode configuration control structure
Jesse Barnesa62c93d2011-11-07 12:03:22 -08001991 * @mutex: mutex protecting KMS related lists and structures
Daniel Vetter2c0c33d2014-10-27 20:19:38 +01001992 * @connection_mutex: ww mutex protecting connector state and routing
1993 * @acquire_ctx: global implicit acquire context used by atomic drivers for
Daniel Vetterc6b0ca32015-12-04 09:46:01 +01001994 * legacy IOCTLs
Jesse Barnesa62c93d2011-11-07 12:03:22 -08001995 * @idr_mutex: mutex for KMS ID allocation and management
1996 * @crtc_idr: main KMS ID tracking object
Daniel Vetter2c0c33d2014-10-27 20:19:38 +01001997 * @fb_lock: mutex to protect fb state and lists
Jesse Barnesa62c93d2011-11-07 12:03:22 -08001998 * @num_fb: number of fbs available
1999 * @fb_list: list of framebuffers available
2000 * @num_connector: number of connectors on this device
2001 * @connector_list: list of connector objects
2002 * @num_encoder: number of encoders on this device
2003 * @encoder_list: list of encoder objects
Daniel Vetter2c0c33d2014-10-27 20:19:38 +01002004 * @num_overlay_plane: number of overlay planes on this device
2005 * @num_total_plane: number of universal (i.e. with primary/curso) planes on this device
2006 * @plane_list: list of plane objects
Jesse Barnesa62c93d2011-11-07 12:03:22 -08002007 * @num_crtc: number of CRTCs on this device
2008 * @crtc_list: list of CRTC objects
Daniel Vetter2c0c33d2014-10-27 20:19:38 +01002009 * @property_list: list of property objects
Jesse Barnesa62c93d2011-11-07 12:03:22 -08002010 * @min_width: minimum pixel width on this device
2011 * @min_height: minimum pixel height on this device
2012 * @max_width: maximum pixel width on this device
2013 * @max_height: maximum pixel height on this device
2014 * @funcs: core driver provided mode setting functions
2015 * @fb_base: base address of the framebuffer
Daniel Vetter2c0c33d2014-10-27 20:19:38 +01002016 * @poll_enabled: track polling support for this device
2017 * @poll_running: track polling status for this device
Jesse Barnesa62c93d2011-11-07 12:03:22 -08002018 * @output_poll_work: delayed work for polling in process context
Daniel Vetter2c0c33d2014-10-27 20:19:38 +01002019 * @property_blob_list: list of all the blob property objects
Daniel Stone8fb6e7a2015-04-20 19:22:54 +01002020 * @blob_lock: mutex for blob property allocation and management
Jesse Barnesa62c93d2011-11-07 12:03:22 -08002021 * @*_property: core property tracking
Daniel Vetter2c0c33d2014-10-27 20:19:38 +01002022 * @preferred_depth: preferred RBG pixel depth, used by fb helpers
2023 * @prefer_shadow: hint to userspace to prefer shadow-fb rendering
2024 * @async_page_flip: does this device support async flips on the primary plane?
2025 * @cursor_width: hint to userspace for max cursor width
2026 * @cursor_height: hint to userspace for max cursor height
Dave Airlief453ba02008-11-07 14:05:41 -08002027 *
Jesse Barnesa62c93d2011-11-07 12:03:22 -08002028 * Core mode resource tracking structure. All CRTC, encoders, and connectors
2029 * enumerated by the driver are added here, as are global properties. Some
2030 * global restrictions are also here, e.g. dimension restrictions.
Dave Airlief453ba02008-11-07 14:05:41 -08002031 */
2032struct drm_mode_config {
Jesse Barnesad2563c2009-01-19 17:21:45 +10002033 struct mutex mutex; /* protects configuration (mode lists etc.) */
Rob Clark51fd3712013-11-19 12:10:12 -05002034 struct drm_modeset_lock connection_mutex; /* protects connector->encoder and encoder->crtc links */
2035 struct drm_modeset_acquire_ctx *acquire_ctx; /* for legacy _lock_all() / _unlock_all() */
Jesse Barnesad2563c2009-01-19 17:21:45 +10002036 struct mutex idr_mutex; /* for IDR management */
Dave Airlief453ba02008-11-07 14:05:41 -08002037 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 +10002038 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 -08002039 /* this is limited to one for now */
Daniel Vetter4b096ac2012-12-10 21:19:18 +01002040
Daniel Vetter2c0c33d2014-10-27 20:19:38 +01002041 struct mutex fb_lock; /* proctects global and per-file fb lists */
Dave Airlief453ba02008-11-07 14:05:41 -08002042 int num_fb;
2043 struct list_head fb_list;
Daniel Vetter4b096ac2012-12-10 21:19:18 +01002044
Dave Airlief453ba02008-11-07 14:05:41 -08002045 int num_connector;
2046 struct list_head connector_list;
2047 int num_encoder;
2048 struct list_head encoder_list;
Matt Ropere27dde32014-04-01 15:22:30 -07002049
2050 /*
2051 * Track # of overlay planes separately from # of total planes. By
2052 * default we only advertise overlay planes to userspace; if userspace
2053 * sets the "universal plane" capability bit, we'll go ahead and
2054 * expose all planes.
2055 */
2056 int num_overlay_plane;
2057 int num_total_plane;
Jesse Barnes8cf5c912011-11-14 14:51:27 -08002058 struct list_head plane_list;
Dave Airlief453ba02008-11-07 14:05:41 -08002059
2060 int num_crtc;
2061 struct list_head crtc_list;
2062
2063 struct list_head property_list;
2064
Dave Airlief453ba02008-11-07 14:05:41 -08002065 int min_width, min_height;
2066 int max_width, max_height;
Laurent Pincharte6ecefa2012-05-17 13:27:23 +02002067 const struct drm_mode_config_funcs *funcs;
Benjamin Herrenschmidtd883f7f2009-02-02 16:55:45 +11002068 resource_size_t fb_base;
Dave Airlief453ba02008-11-07 14:05:41 -08002069
Dave Airlieeb1f8e42010-05-07 06:42:51 +00002070 /* output poll support */
2071 bool poll_enabled;
Daniel Vetter905bc9f2012-10-23 18:23:36 +00002072 bool poll_running;
Daniel Vetter162b6a52015-01-21 08:45:21 +01002073 bool delayed_event;
Tejun Heo991ea752010-07-20 22:09:02 +02002074 struct delayed_work output_poll_work;
Dave Airlieeb1f8e42010-05-07 06:42:51 +00002075
Daniel Stone8fb6e7a2015-04-20 19:22:54 +01002076 struct mutex blob_lock;
2077
Dave Airlief453ba02008-11-07 14:05:41 -08002078 /* pointers to standard properties */
2079 struct list_head property_blob_list;
2080 struct drm_property *edid_property;
2081 struct drm_property *dpms_property;
Dave Airlie43aba7e2014-06-05 14:01:31 +10002082 struct drm_property *path_property;
Dave Airlie6f134d72014-10-20 16:30:50 +10002083 struct drm_property *tile_property;
Rob Clark9922ab52014-04-01 20:16:57 -04002084 struct drm_property *plane_type_property;
Sonika Jindal2a297cc2014-08-05 11:26:54 +05302085 struct drm_property *rotation_property;
Rob Clark6b4959f2014-12-18 16:01:53 -05002086 struct drm_property *prop_src_x;
2087 struct drm_property *prop_src_y;
2088 struct drm_property *prop_src_w;
2089 struct drm_property *prop_src_h;
2090 struct drm_property *prop_crtc_x;
2091 struct drm_property *prop_crtc_y;
2092 struct drm_property *prop_crtc_w;
2093 struct drm_property *prop_crtc_h;
2094 struct drm_property *prop_fb_id;
2095 struct drm_property *prop_crtc_id;
Daniel Vettereab3bbe2015-01-22 16:36:21 +01002096 struct drm_property *prop_active;
Daniel Stone955f3c32015-05-25 19:11:52 +01002097 struct drm_property *prop_mode_id;
Dave Airlief453ba02008-11-07 14:05:41 -08002098
2099 /* DVI-I properties */
2100 struct drm_property *dvi_i_subconnector_property;
2101 struct drm_property *dvi_i_select_subconnector_property;
2102
2103 /* TV properties */
2104 struct drm_property *tv_subconnector_property;
2105 struct drm_property *tv_select_subconnector_property;
2106 struct drm_property *tv_mode_property;
2107 struct drm_property *tv_left_margin_property;
2108 struct drm_property *tv_right_margin_property;
2109 struct drm_property *tv_top_margin_property;
2110 struct drm_property *tv_bottom_margin_property;
Francisco Jerezb6b79022009-08-02 04:19:20 +02002111 struct drm_property *tv_brightness_property;
2112 struct drm_property *tv_contrast_property;
2113 struct drm_property *tv_flicker_reduction_property;
Francisco Jereza75f0232009-08-12 02:30:10 +02002114 struct drm_property *tv_overscan_property;
2115 struct drm_property *tv_saturation_property;
2116 struct drm_property *tv_hue_property;
Dave Airlief453ba02008-11-07 14:05:41 -08002117
2118 /* Optional properties */
2119 struct drm_property *scaling_mode_property;
Vandana Kannanff587e42014-06-11 10:46:48 +05302120 struct drm_property *aspect_ratio_property;
Jakob Bornecrantz884840a2009-12-03 23:25:47 +00002121 struct drm_property *dirty_info_property;
Dave Airlie019d96c2011-09-29 16:20:42 +01002122
Dave Airlie5bb2bbf2014-11-10 10:18:15 +10002123 /* properties for virtual machine layout */
2124 struct drm_property *suggested_x_property;
2125 struct drm_property *suggested_y_property;
2126
Dave Airlie019d96c2011-09-29 16:20:42 +01002127 /* dumb ioctl parameters */
2128 uint32_t preferred_depth, prefer_shadow;
Keith Packard62f21042013-07-22 18:50:00 -07002129
2130 /* whether async page flip is supported or not */
2131 bool async_page_flip;
Alex Deucher8716ed42014-02-12 12:48:23 -05002132
Rob Clarke3eb3252015-02-05 14:41:52 +00002133 /* whether the driver supports fb modifiers */
2134 bool allow_fb_modifiers;
2135
Alex Deucher8716ed42014-02-12 12:48:23 -05002136 /* cursor size */
2137 uint32_t cursor_width, cursor_height;
Dave Airlief453ba02008-11-07 14:05:41 -08002138};
2139
Rob Clarkdd275952014-11-25 20:29:46 -05002140/**
2141 * drm_for_each_plane_mask - iterate over planes specified by bitmask
2142 * @plane: the loop cursor
2143 * @dev: the DRM device
2144 * @plane_mask: bitmask of plane indices
2145 *
2146 * Iterate over all planes specified by bitmask.
2147 */
2148#define drm_for_each_plane_mask(plane, dev, plane_mask) \
2149 list_for_each_entry((plane), &(dev)->mode_config.plane_list, head) \
Jani Nikula373701b2015-11-24 21:21:55 +02002150 for_each_if ((plane_mask) & (1 << drm_plane_index(plane)))
Rob Clarkdd275952014-11-25 20:29:46 -05002151
2152
Dave Airlief453ba02008-11-07 14:05:41 -08002153#define obj_to_crtc(x) container_of(x, struct drm_crtc, base)
2154#define obj_to_connector(x) container_of(x, struct drm_connector, base)
2155#define obj_to_encoder(x) container_of(x, struct drm_encoder, base)
2156#define obj_to_mode(x) container_of(x, struct drm_display_mode, base)
2157#define obj_to_fb(x) container_of(x, struct drm_framebuffer, base)
2158#define obj_to_property(x) container_of(x, struct drm_property, base)
2159#define obj_to_blob(x) container_of(x, struct drm_property_blob, base)
Jesse Barnes8cf5c912011-11-14 14:51:27 -08002160#define obj_to_plane(x) container_of(x, struct drm_plane, base)
Dave Airlief453ba02008-11-07 14:05:41 -08002161
Sascha Hauer4a67d392012-02-06 10:58:17 +01002162struct drm_prop_enum_list {
2163 int type;
2164 char *name;
2165};
Dave Airlief453ba02008-11-07 14:05:41 -08002166
Ville Syrjäläf9882872015-12-09 16:19:31 +02002167extern __printf(6, 7)
2168int drm_crtc_init_with_planes(struct drm_device *dev,
2169 struct drm_crtc *crtc,
2170 struct drm_plane *primary,
2171 struct drm_plane *cursor,
2172 const struct drm_crtc_funcs *funcs,
2173 const char *name, ...);
Dave Airlief453ba02008-11-07 14:05:41 -08002174extern void drm_crtc_cleanup(struct drm_crtc *crtc);
Russell Kingdb5f7a62014-01-02 21:27:33 +00002175extern unsigned int drm_crtc_index(struct drm_crtc *crtc);
2176
2177/**
2178 * drm_crtc_mask - find the mask of a registered CRTC
2179 * @crtc: CRTC to find mask for
2180 *
2181 * Given a registered CRTC, return the mask bit of that CRTC for an
2182 * encoder's possible_crtcs field.
2183 */
2184static inline uint32_t drm_crtc_mask(struct drm_crtc *crtc)
2185{
2186 return 1 << drm_crtc_index(crtc);
2187}
Dave Airlief453ba02008-11-07 14:05:41 -08002188
Ilia Mirkinb21e3af2013-08-07 22:34:48 -04002189extern void drm_connector_ida_init(void);
2190extern void drm_connector_ida_destroy(void);
Ville Syrjälä6bfc56a2012-03-13 12:35:48 +02002191extern int drm_connector_init(struct drm_device *dev,
2192 struct drm_connector *connector,
2193 const struct drm_connector_funcs *funcs,
2194 int connector_type);
Thomas Wood34ea3d32014-05-29 16:57:41 +01002195int drm_connector_register(struct drm_connector *connector);
2196void drm_connector_unregister(struct drm_connector *connector);
Dave Airlief453ba02008-11-07 14:05:41 -08002197
2198extern void drm_connector_cleanup(struct drm_connector *connector);
Daniel Vetter10f637b2014-07-29 13:47:11 +02002199extern unsigned int drm_connector_index(struct drm_connector *connector);
Dave Airliecbc7e222012-02-20 14:16:40 +00002200/* helper to unplug all connectors from sysfs for device */
2201extern void drm_connector_unplug_all(struct drm_device *dev);
Dave Airlief453ba02008-11-07 14:05:41 -08002202
Ajay Kumar3d3f8b12015-01-20 22:08:44 +05302203extern int drm_bridge_add(struct drm_bridge *bridge);
2204extern void drm_bridge_remove(struct drm_bridge *bridge);
2205extern struct drm_bridge *of_drm_find_bridge(struct device_node *np);
2206extern int drm_bridge_attach(struct drm_device *dev, struct drm_bridge *bridge);
Sean Paul3b336ec2013-08-14 16:47:37 -04002207
Archit Taneja862e6862015-05-21 11:03:16 +05302208bool drm_bridge_mode_fixup(struct drm_bridge *bridge,
2209 const struct drm_display_mode *mode,
2210 struct drm_display_mode *adjusted_mode);
2211void drm_bridge_disable(struct drm_bridge *bridge);
2212void drm_bridge_post_disable(struct drm_bridge *bridge);
2213void drm_bridge_mode_set(struct drm_bridge *bridge,
2214 struct drm_display_mode *mode,
2215 struct drm_display_mode *adjusted_mode);
2216void drm_bridge_pre_enable(struct drm_bridge *bridge);
2217void drm_bridge_enable(struct drm_bridge *bridge);
2218
Ville Syrjälä13a3d912015-12-09 16:20:18 +02002219extern __printf(5, 6)
2220int drm_encoder_init(struct drm_device *dev,
2221 struct drm_encoder *encoder,
2222 const struct drm_encoder_funcs *funcs,
2223 int encoder_type, const char *name, ...);
Dave Airlief453ba02008-11-07 14:05:41 -08002224
Thierry Reding3d887362014-01-13 14:33:20 +01002225/**
2226 * drm_encoder_crtc_ok - can a given crtc drive a given encoder?
2227 * @encoder: encoder to test
2228 * @crtc: crtc to test
2229 *
2230 * Return false if @encoder can't be driven by @crtc, true otherwise.
2231 */
2232static inline bool drm_encoder_crtc_ok(struct drm_encoder *encoder,
2233 struct drm_crtc *crtc)
2234{
2235 return !!(encoder->possible_crtcs & drm_crtc_mask(crtc));
2236}
2237
Ville Syrjäläb0b3b792015-12-09 16:19:55 +02002238extern __printf(8, 9)
2239int drm_universal_plane_init(struct drm_device *dev,
2240 struct drm_plane *plane,
2241 unsigned long possible_crtcs,
2242 const struct drm_plane_funcs *funcs,
2243 const uint32_t *formats,
2244 unsigned int format_count,
2245 enum drm_plane_type type,
2246 const char *name, ...);
Jesse Barnes8cf5c912011-11-14 14:51:27 -08002247extern int drm_plane_init(struct drm_device *dev,
2248 struct drm_plane *plane,
2249 unsigned long possible_crtcs,
2250 const struct drm_plane_funcs *funcs,
Thierry Reding45e37432015-08-12 16:54:28 +02002251 const uint32_t *formats, unsigned int format_count,
Matt Roperdc415ff2014-04-01 15:22:36 -07002252 bool is_primary);
Jesse Barnes8cf5c912011-11-14 14:51:27 -08002253extern void drm_plane_cleanup(struct drm_plane *plane);
Daniel Vetter10f637b2014-07-29 13:47:11 +02002254extern unsigned int drm_plane_index(struct drm_plane *plane);
Chandra Konduruf81338a2015-04-09 17:36:21 -07002255extern struct drm_plane * drm_plane_from_index(struct drm_device *dev, int idx);
Ville Syrjälä9125e612013-06-03 16:10:40 +03002256extern void drm_plane_force_disable(struct drm_plane *plane);
Laurent Pinchartead86102015-03-05 02:25:43 +02002257extern int drm_plane_check_pixel_format(const struct drm_plane *plane,
2258 u32 format);
Gustavo Padovanecb7e162014-12-01 15:40:09 -08002259extern void drm_crtc_get_hv_timing(const struct drm_display_mode *mode,
2260 int *hdisplay, int *vdisplay);
Matt Roperaf936292014-04-01 15:22:34 -07002261extern int drm_crtc_check_viewport(const struct drm_crtc *crtc,
2262 int x, int y,
2263 const struct drm_display_mode *mode,
2264 const struct drm_framebuffer *fb);
Jesse Barnes8cf5c912011-11-14 14:51:27 -08002265
Dave Airlief453ba02008-11-07 14:05:41 -08002266extern void drm_encoder_cleanup(struct drm_encoder *encoder);
2267
Ville Syrjäläd20d3172013-06-07 15:43:07 +00002268extern const char *drm_get_connector_status_name(enum drm_connector_status status);
Jesse Barnesac1bb362014-02-10 15:32:44 -08002269extern const char *drm_get_subpixel_order_name(enum subpixel_order order);
Ville Syrjäläd20d3172013-06-07 15:43:07 +00002270extern const char *drm_get_dpms_name(int val);
2271extern const char *drm_get_dvi_i_subconnector_name(int val);
2272extern const char *drm_get_dvi_i_select_name(int val);
2273extern const char *drm_get_tv_subconnector_name(int val);
2274extern const char *drm_get_tv_select_name(int val);
Kristian Høgsbergea39f832009-02-12 14:37:56 -05002275extern void drm_fb_release(struct drm_file *file_priv);
Daniel Stonee2f5d2e2015-05-22 13:34:51 +01002276extern void drm_property_destroy_user_blobs(struct drm_device *dev,
2277 struct drm_file *file_priv);
Adam Jacksonfbff4692012-09-18 10:58:47 -04002278extern bool drm_probe_ddc(struct i2c_adapter *adapter);
Dave Airlief453ba02008-11-07 14:05:41 -08002279extern struct edid *drm_get_edid(struct drm_connector *connector,
2280 struct i2c_adapter *adapter);
Jani Nikula51f8da52013-09-27 15:08:27 +03002281extern struct edid *drm_edid_duplicate(const struct edid *edid);
Dave Airlief453ba02008-11-07 14:05:41 -08002282extern int drm_add_edid_modes(struct drm_connector *connector, struct edid *edid);
Dave Airlief453ba02008-11-07 14:05:41 -08002283extern void drm_mode_config_init(struct drm_device *dev);
Chris Wilsoneb033552011-01-24 15:11:08 +00002284extern void drm_mode_config_reset(struct drm_device *dev);
Dave Airlief453ba02008-11-07 14:05:41 -08002285extern void drm_mode_config_cleanup(struct drm_device *dev);
Dave Airlief453ba02008-11-07 14:05:41 -08002286
Dave Airlie43aba7e2014-06-05 14:01:31 +10002287extern int drm_mode_connector_set_path_property(struct drm_connector *connector,
Thierry Reding12e6cec2014-05-13 11:38:36 +02002288 const char *path);
Dave Airlie6f134d72014-10-20 16:30:50 +10002289int drm_mode_connector_set_tile_property(struct drm_connector *connector);
Dave Airlief453ba02008-11-07 14:05:41 -08002290extern int drm_mode_connector_update_edid_property(struct drm_connector *connector,
Thierry Reding12e6cec2014-05-13 11:38:36 +02002291 const struct edid *edid);
Rob Clark5ea22f22014-05-30 11:34:01 -04002292
Boris Brezillonb5571e92014-07-22 12:09:10 +02002293extern int drm_display_info_set_bus_formats(struct drm_display_info *info,
2294 const u32 *formats,
2295 unsigned int num_formats);
2296
Rob Clark5ea22f22014-05-30 11:34:01 -04002297static inline bool drm_property_type_is(struct drm_property *property,
2298 uint32_t type)
2299{
2300 /* instanceof for props.. handles extended type vs original types: */
2301 if (property->flags & DRM_MODE_PROP_EXTENDED_TYPE)
2302 return (property->flags & DRM_MODE_PROP_EXTENDED_TYPE) == type;
2303 return property->flags & type;
2304}
2305
2306static inline bool drm_property_type_valid(struct drm_property *property)
2307{
2308 if (property->flags & DRM_MODE_PROP_EXTENDED_TYPE)
2309 return !(property->flags & DRM_MODE_PROP_LEGACY_TYPE);
2310 return !!(property->flags & DRM_MODE_PROP_LEGACY_TYPE);
2311}
2312
Paulo Zanonic5431882012-05-15 18:09:02 -03002313extern int drm_object_property_set_value(struct drm_mode_object *obj,
2314 struct drm_property *property,
2315 uint64_t val);
2316extern int drm_object_property_get_value(struct drm_mode_object *obj,
2317 struct drm_property *property,
2318 uint64_t *value);
Dave Airlief453ba02008-11-07 14:05:41 -08002319extern int drm_framebuffer_init(struct drm_device *dev,
2320 struct drm_framebuffer *fb,
2321 const struct drm_framebuffer_funcs *funcs);
Daniel Vetter786b99e2012-12-02 21:53:40 +01002322extern struct drm_framebuffer *drm_framebuffer_lookup(struct drm_device *dev,
2323 uint32_t id);
Rob Clarkf7eff602012-09-05 21:48:38 +00002324extern void drm_framebuffer_unreference(struct drm_framebuffer *fb);
2325extern void drm_framebuffer_reference(struct drm_framebuffer *fb);
2326extern void drm_framebuffer_remove(struct drm_framebuffer *fb);
Dave Airlief453ba02008-11-07 14:05:41 -08002327extern void drm_framebuffer_cleanup(struct drm_framebuffer *fb);
Daniel Vetter36206362012-12-10 20:42:17 +01002328extern void drm_framebuffer_unregister_private(struct drm_framebuffer *fb);
Dave Airlief453ba02008-11-07 14:05:41 -08002329
Paulo Zanonic5431882012-05-15 18:09:02 -03002330extern void drm_object_attach_property(struct drm_mode_object *obj,
2331 struct drm_property *property,
2332 uint64_t init_val);
Dave Airlief453ba02008-11-07 14:05:41 -08002333extern struct drm_property *drm_property_create(struct drm_device *dev, int flags,
2334 const char *name, int num_values);
Sascha Hauer4a67d392012-02-06 10:58:17 +01002335extern struct drm_property *drm_property_create_enum(struct drm_device *dev, int flags,
2336 const char *name,
2337 const struct drm_prop_enum_list *props,
2338 int num_values);
Rob Clark49e27542012-05-17 02:23:26 -06002339struct drm_property *drm_property_create_bitmask(struct drm_device *dev,
2340 int flags, const char *name,
2341 const struct drm_prop_enum_list *props,
Ville Syrjälä7689ffb2014-07-08 10:31:52 +05302342 int num_props,
2343 uint64_t supported_bits);
Sascha Hauerd9bc3c02012-02-06 10:58:18 +01002344struct drm_property *drm_property_create_range(struct drm_device *dev, int flags,
2345 const char *name,
2346 uint64_t min, uint64_t max);
Rob Clarkebc44cf2012-09-12 22:22:31 -05002347struct drm_property *drm_property_create_signed_range(struct drm_device *dev,
2348 int flags, const char *name,
2349 int64_t min, int64_t max);
Rob Clark98f75de2014-05-30 11:37:03 -04002350struct drm_property *drm_property_create_object(struct drm_device *dev,
2351 int flags, const char *name, uint32_t type);
Daniel Vetter960cd9d2015-01-21 08:47:38 +01002352struct drm_property *drm_property_create_bool(struct drm_device *dev, int flags,
2353 const char *name);
Daniel Stone6bcacf52015-04-20 19:22:55 +01002354struct drm_property_blob *drm_property_create_blob(struct drm_device *dev,
2355 size_t length,
2356 const void *data);
2357struct drm_property_blob *drm_property_lookup_blob(struct drm_device *dev,
2358 uint32_t id);
2359struct drm_property_blob *drm_property_reference_blob(struct drm_property_blob *blob);
2360void drm_property_unreference_blob(struct drm_property_blob *blob);
Dave Airlief453ba02008-11-07 14:05:41 -08002361extern void drm_property_destroy(struct drm_device *dev, struct drm_property *property);
2362extern int drm_property_add_enum(struct drm_property *property, int index,
2363 uint64_t value, const char *name);
2364extern int drm_mode_create_dvi_i_properties(struct drm_device *dev);
Thierry Reding2f763312014-10-13 12:45:57 +02002365extern int drm_mode_create_tv_properties(struct drm_device *dev,
2366 unsigned int num_modes,
Ville Syrjäläb7c914b2015-08-31 15:09:26 +03002367 const char * const modes[]);
Dave Airlief453ba02008-11-07 14:05:41 -08002368extern int drm_mode_create_scaling_mode_property(struct drm_device *dev);
Vandana Kannanff587e42014-06-11 10:46:48 +05302369extern int drm_mode_create_aspect_ratio_property(struct drm_device *dev);
Jakob Bornecrantz884840a2009-12-03 23:25:47 +00002370extern int drm_mode_create_dirty_info_property(struct drm_device *dev);
Dave Airlie5bb2bbf2014-11-10 10:18:15 +10002371extern int drm_mode_create_suggested_offset_properties(struct drm_device *dev);
Rob Clarkd34f20d2014-12-18 16:01:56 -05002372extern bool drm_property_change_valid_get(struct drm_property *property,
2373 uint64_t value, struct drm_mode_object **ref);
2374extern void drm_property_change_valid_put(struct drm_property *property,
2375 struct drm_mode_object *ref);
Dave Airlief453ba02008-11-07 14:05:41 -08002376
2377extern int drm_mode_connector_attach_encoder(struct drm_connector *connector,
2378 struct drm_encoder *encoder);
Sascha Hauer4cae5b82012-02-01 11:38:23 +01002379extern int drm_mode_crtc_set_gamma_size(struct drm_crtc *crtc,
Dave Airlief453ba02008-11-07 14:05:41 -08002380 int gamma_size);
Daniel Vetter7a9c9062009-09-15 22:57:31 +02002381extern struct drm_mode_object *drm_mode_object_find(struct drm_device *dev,
2382 uint32_t id, uint32_t type);
Rob Clark98f75de2014-05-30 11:37:03 -04002383
Dave Airlief453ba02008-11-07 14:05:41 -08002384/* IOCTLs */
2385extern int drm_mode_getresources(struct drm_device *dev,
2386 void *data, struct drm_file *file_priv);
Jesse Barnes8cf5c912011-11-14 14:51:27 -08002387extern int drm_mode_getplane_res(struct drm_device *dev, void *data,
2388 struct drm_file *file_priv);
Dave Airlief453ba02008-11-07 14:05:41 -08002389extern int drm_mode_getcrtc(struct drm_device *dev,
2390 void *data, struct drm_file *file_priv);
2391extern int drm_mode_getconnector(struct drm_device *dev,
2392 void *data, struct drm_file *file_priv);
Daniel Vetter2d13b672012-12-11 13:47:23 +01002393extern int drm_mode_set_config_internal(struct drm_mode_set *set);
Dave Airlief453ba02008-11-07 14:05:41 -08002394extern int drm_mode_setcrtc(struct drm_device *dev,
2395 void *data, struct drm_file *file_priv);
Jesse Barnes8cf5c912011-11-14 14:51:27 -08002396extern int drm_mode_getplane(struct drm_device *dev,
2397 void *data, struct drm_file *file_priv);
2398extern int drm_mode_setplane(struct drm_device *dev,
2399 void *data, struct drm_file *file_priv);
Dave Airlief453ba02008-11-07 14:05:41 -08002400extern int drm_mode_cursor_ioctl(struct drm_device *dev,
2401 void *data, struct drm_file *file_priv);
Dave Airlie4c813d42013-06-20 11:48:52 +10002402extern int drm_mode_cursor2_ioctl(struct drm_device *dev,
2403 void *data, struct drm_file *file_priv);
Dave Airlief453ba02008-11-07 14:05:41 -08002404extern int drm_mode_addfb(struct drm_device *dev,
2405 void *data, struct drm_file *file_priv);
Jesse Barnes308e5bc2011-11-14 14:51:28 -08002406extern int drm_mode_addfb2(struct drm_device *dev,
2407 void *data, struct drm_file *file_priv);
2408extern uint32_t drm_mode_legacy_fb_format(uint32_t bpp, uint32_t depth);
Dave Airlief453ba02008-11-07 14:05:41 -08002409extern int drm_mode_rmfb(struct drm_device *dev,
2410 void *data, struct drm_file *file_priv);
2411extern int drm_mode_getfb(struct drm_device *dev,
2412 void *data, struct drm_file *file_priv);
Jakob Bornecrantz884840a2009-12-03 23:25:47 +00002413extern int drm_mode_dirtyfb_ioctl(struct drm_device *dev,
2414 void *data, struct drm_file *file_priv);
Dave Airlief453ba02008-11-07 14:05:41 -08002415
2416extern int drm_mode_getproperty_ioctl(struct drm_device *dev,
2417 void *data, struct drm_file *file_priv);
2418extern int drm_mode_getblob_ioctl(struct drm_device *dev,
2419 void *data, struct drm_file *file_priv);
Daniel Stonee2f5d2e2015-05-22 13:34:51 +01002420extern int drm_mode_createblob_ioctl(struct drm_device *dev,
2421 void *data, struct drm_file *file_priv);
2422extern int drm_mode_destroyblob_ioctl(struct drm_device *dev,
2423 void *data, struct drm_file *file_priv);
Dave Airlief453ba02008-11-07 14:05:41 -08002424extern int drm_mode_connector_property_set_ioctl(struct drm_device *dev,
2425 void *data, struct drm_file *file_priv);
Dave Airlief453ba02008-11-07 14:05:41 -08002426extern int drm_mode_getencoder(struct drm_device *dev,
2427 void *data, struct drm_file *file_priv);
2428extern int drm_mode_gamma_get_ioctl(struct drm_device *dev,
2429 void *data, struct drm_file *file_priv);
2430extern int drm_mode_gamma_set_ioctl(struct drm_device *dev,
2431 void *data, struct drm_file *file_priv);
Thierry Reding18316c82012-12-20 15:41:44 +01002432extern u8 drm_match_cea_mode(const struct drm_display_mode *to_match);
Vandana Kannan0967e6a2014-04-01 16:26:59 +05302433extern enum hdmi_picture_aspect drm_get_cea_aspect_ratio(const u8 video_code);
Ma Lingf23c20c2009-03-26 19:26:23 +08002434extern bool drm_detect_hdmi_monitor(struct edid *edid);
Zhenyu Wang8fe97902010-09-19 14:27:28 +08002435extern bool drm_detect_monitor_audio(struct edid *edid);
Ville Syrjäläb1edd6a2013-01-17 16:31:30 +02002436extern bool drm_rgb_quant_range_selectable(struct edid *edid);
Kristian Høgsbergd91d8a32009-11-17 12:43:55 -05002437extern int drm_mode_page_flip_ioctl(struct drm_device *dev,
2438 void *data, struct drm_file *file_priv);
Zhao Yakuif0fda0a2009-09-03 09:33:48 +08002439extern int drm_add_modes_noedid(struct drm_connector *connector,
2440 int hdisplay, int vdisplay);
Gerd Hoffmann3cf70da2013-10-11 10:01:08 +02002441extern void drm_set_preferred_mode(struct drm_connector *connector,
2442 int hpref, int vpref);
Alex Deucher3c537882010-02-05 04:21:19 -05002443
Thomas Reim051963d2011-07-29 14:28:57 +00002444extern int drm_edid_header_is_valid(const u8 *raw_edid);
Todd Previte6ba2bd32015-04-21 11:09:41 -07002445extern bool drm_edid_block_valid(u8 *raw_edid, int block, bool print_bad_edid,
2446 bool *edid_corrupt);
Alex Deucher3c537882010-02-05 04:21:19 -05002447extern bool drm_edid_is_valid(struct edid *edid);
Dave Airlie138f9eb2014-10-20 16:17:17 +10002448
2449extern struct drm_tile_group *drm_mode_create_tile_group(struct drm_device *dev,
2450 char topology[8]);
2451extern struct drm_tile_group *drm_mode_get_tile_group(struct drm_device *dev,
2452 char topology[8]);
2453extern void drm_mode_put_tile_group(struct drm_device *dev,
2454 struct drm_tile_group *tg);
Dave Airlie1d42bbc2010-05-07 05:02:30 +00002455struct drm_display_mode *drm_mode_find_dmt(struct drm_device *dev,
Adam Jacksonf6e252b2012-04-13 16:33:31 -04002456 int hsize, int vsize, int fresh,
2457 bool rb);
Dave Airlieff72145b2011-02-07 12:16:14 +10002458
2459extern int drm_mode_create_dumb_ioctl(struct drm_device *dev,
2460 void *data, struct drm_file *file_priv);
2461extern int drm_mode_mmap_dumb_ioctl(struct drm_device *dev,
2462 void *data, struct drm_file *file_priv);
2463extern int drm_mode_destroy_dumb_ioctl(struct drm_device *dev,
2464 void *data, struct drm_file *file_priv);
Paulo Zanonic5431882012-05-15 18:09:02 -03002465extern int drm_mode_obj_get_properties_ioctl(struct drm_device *dev, void *data,
2466 struct drm_file *file_priv);
2467extern int drm_mode_obj_set_property_ioctl(struct drm_device *dev, void *data,
2468 struct drm_file *file_priv);
Thomas Wood3a5f87c2014-08-20 14:45:00 +01002469extern int drm_mode_plane_set_obj_prop(struct drm_plane *plane,
2470 struct drm_property *property,
2471 uint64_t value);
Rob Clarkd34f20d2014-12-18 16:01:56 -05002472extern int drm_mode_atomic_ioctl(struct drm_device *dev,
2473 void *data, struct drm_file *file_priv);
Dave Airlie248dbc22011-11-29 20:02:54 +00002474
2475extern void drm_fb_get_bpp_depth(uint32_t format, unsigned int *depth,
2476 int *bpp);
Ville Syrjälä141670e2012-04-05 21:35:15 +03002477extern int drm_format_num_planes(uint32_t format);
Ville Syrjälä5a86bd52012-04-05 21:35:16 +03002478extern int drm_format_plane_cpp(uint32_t format, int plane);
Ville Syrjälä01b68b02012-04-05 21:35:17 +03002479extern int drm_format_horz_chroma_subsampling(uint32_t format);
2480extern int drm_format_vert_chroma_subsampling(uint32_t format);
Ville Syrjäläd20d3172013-06-07 15:43:07 +00002481extern const char *drm_get_format_name(uint32_t format);
Ville Syrjäläc1df5f32014-07-08 10:31:53 +05302482extern struct drm_property *drm_mode_create_rotation_property(struct drm_device *dev,
2483 unsigned int supported_rotations);
Ville Syrjälä3c9855f2014-07-08 10:31:56 +05302484extern unsigned int drm_rotation_simplify(unsigned int rotation,
2485 unsigned int supported_rotations);
Ville Syrjälä141670e2012-04-05 21:35:15 +03002486
Russell King96f60e32012-08-15 13:59:49 +01002487/* Helpers */
Rob Clarka2b34e22013-10-05 16:36:52 -04002488
2489static inline struct drm_plane *drm_plane_find(struct drm_device *dev,
2490 uint32_t id)
2491{
2492 struct drm_mode_object *mo;
2493 mo = drm_mode_object_find(dev, id, DRM_MODE_OBJECT_PLANE);
2494 return mo ? obj_to_plane(mo) : NULL;
2495}
2496
Russell King96f60e32012-08-15 13:59:49 +01002497static inline struct drm_crtc *drm_crtc_find(struct drm_device *dev,
2498 uint32_t id)
2499{
2500 struct drm_mode_object *mo;
2501 mo = drm_mode_object_find(dev, id, DRM_MODE_OBJECT_CRTC);
2502 return mo ? obj_to_crtc(mo) : NULL;
2503}
2504
2505static inline struct drm_encoder *drm_encoder_find(struct drm_device *dev,
2506 uint32_t id)
2507{
2508 struct drm_mode_object *mo;
2509 mo = drm_mode_object_find(dev, id, DRM_MODE_OBJECT_ENCODER);
2510 return mo ? obj_to_encoder(mo) : NULL;
2511}
2512
Rob Clarka2b34e22013-10-05 16:36:52 -04002513static inline struct drm_connector *drm_connector_find(struct drm_device *dev,
2514 uint32_t id)
2515{
2516 struct drm_mode_object *mo;
2517 mo = drm_mode_object_find(dev, id, DRM_MODE_OBJECT_CONNECTOR);
2518 return mo ? obj_to_connector(mo) : NULL;
2519}
2520
2521static inline struct drm_property *drm_property_find(struct drm_device *dev,
2522 uint32_t id)
2523{
2524 struct drm_mode_object *mo;
2525 mo = drm_mode_object_find(dev, id, DRM_MODE_OBJECT_PROPERTY);
2526 return mo ? obj_to_property(mo) : NULL;
2527}
2528
Matt Ropere27dde32014-04-01 15:22:30 -07002529/* Plane list iterator for legacy (overlay only) planes. */
Daniel Vetter4ea50e92015-07-09 23:44:24 +02002530#define drm_for_each_legacy_plane(plane, dev) \
2531 list_for_each_entry(plane, &(dev)->mode_config.plane_list, head) \
Jani Nikula373701b2015-11-24 21:21:55 +02002532 for_each_if (plane->type == DRM_PLANE_TYPE_OVERLAY)
Matt Ropere27dde32014-04-01 15:22:30 -07002533
Daniel Vetter6295d602015-07-09 23:44:25 +02002534#define drm_for_each_plane(plane, dev) \
2535 list_for_each_entry(plane, &(dev)->mode_config.plane_list, head)
2536
2537#define drm_for_each_crtc(crtc, dev) \
2538 list_for_each_entry(crtc, &(dev)->mode_config.crtc_list, head)
2539
Daniel Vetter7a3f3d62015-07-09 23:44:28 +02002540static inline void
2541assert_drm_connector_list_read_locked(struct drm_mode_config *mode_config)
2542{
Daniel Vettercff20ba2015-07-09 23:44:33 +02002543 /*
2544 * The connector hotadd/remove code currently grabs both locks when
2545 * updating lists. Hence readers need only hold either of them to be
2546 * safe and the check amounts to
2547 *
2548 * WARN_ON(not_holding(A) && not_holding(B)).
2549 */
2550 WARN_ON(!mutex_is_locked(&mode_config->mutex) &&
2551 !drm_modeset_is_locked(&mode_config->connection_mutex));
Daniel Vetter7a3f3d62015-07-09 23:44:28 +02002552}
2553
Daniel Vetter6295d602015-07-09 23:44:25 +02002554#define drm_for_each_connector(connector, dev) \
Daniel Vetter7a3f3d62015-07-09 23:44:28 +02002555 for (assert_drm_connector_list_read_locked(&(dev)->mode_config), \
2556 connector = list_first_entry(&(dev)->mode_config.connector_list, \
2557 struct drm_connector, head); \
2558 &connector->head != (&(dev)->mode_config.connector_list); \
2559 connector = list_next_entry(connector, head))
Daniel Vetter6295d602015-07-09 23:44:25 +02002560
2561#define drm_for_each_encoder(encoder, dev) \
2562 list_for_each_entry(encoder, &(dev)->mode_config.encoder_list, head)
2563
2564#define drm_for_each_fb(fb, dev) \
Daniel Vetter4676ba02015-07-09 23:44:30 +02002565 for (WARN_ON(!mutex_is_locked(&(dev)->mode_config.fb_lock)), \
2566 fb = list_first_entry(&(dev)->mode_config.fb_list, \
2567 struct drm_framebuffer, head); \
2568 &fb->head != (&(dev)->mode_config.fb_list); \
2569 fb = list_next_entry(fb, head))
Daniel Vetter6295d602015-07-09 23:44:25 +02002570
Dave Airlief453ba02008-11-07 14:05:41 -08002571#endif /* __DRM_CRTC_H__ */