blob: 44a98082d40938f46259961e331bb1dd224479c4 [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 Barnesebec9a7b2011-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
Dave Airlief453ba02008-11-07 14:05:41 -0800165struct drm_framebuffer_funcs {
Rob Clarkf7eff602012-09-05 21:48:38 +0000166 /* note: use drm_framebuffer_remove() */
Dave Airlief453ba02008-11-07 14:05:41 -0800167 void (*destroy)(struct drm_framebuffer *framebuffer);
168 int (*create_handle)(struct drm_framebuffer *fb,
169 struct drm_file *file_priv,
170 unsigned int *handle);
Daniel Vetter3bf04012014-10-27 16:54:27 +0100171 /*
172 * Optional callback for the dirty fb ioctl.
Jakob Bornecrantz884840a2009-12-03 23:25:47 +0000173 *
174 * Userspace can notify the driver via this callback
175 * that a area of the framebuffer has changed and should
176 * be flushed to the display hardware.
177 *
178 * See documentation in drm_mode.h for the struct
179 * drm_mode_fb_dirty_cmd for more information as all
180 * the semantics and arguments have a one to one mapping
181 * on this function.
182 */
Thomas Hellstrom02b00162010-10-05 12:43:02 +0200183 int (*dirty)(struct drm_framebuffer *framebuffer,
184 struct drm_file *file_priv, unsigned flags,
Jakob Bornecrantz884840a2009-12-03 23:25:47 +0000185 unsigned color, struct drm_clip_rect *clips,
186 unsigned num_clips);
Dave Airlief453ba02008-11-07 14:05:41 -0800187};
188
189struct drm_framebuffer {
190 struct drm_device *dev;
Rob Clarkf7eff602012-09-05 21:48:38 +0000191 /*
192 * Note that the fb is refcounted for the benefit of driver internals,
193 * for example some hw, disabling a CRTC/plane is asynchronous, and
194 * scanout does not actually complete until the next vblank. So some
195 * cleanup (like releasing the reference(s) on the backing GEM bo(s))
196 * should be deferred. In cases like this, the driver would like to
197 * hold a ref to the fb even though it has already been removed from
198 * userspace perspective.
199 */
200 struct kref refcount;
Daniel Vetter4b096ac2012-12-10 21:19:18 +0100201 /*
202 * Place on the dev->mode_config.fb_list, access protected by
203 * dev->mode_config.fb_lock.
204 */
Dave Airlief453ba02008-11-07 14:05:41 -0800205 struct list_head head;
206 struct drm_mode_object base;
207 const struct drm_framebuffer_funcs *funcs;
Ville Syrjälä01f2c772011-12-20 00:06:49 +0200208 unsigned int pitches[4];
209 unsigned int offsets[4];
Rob Clarke3eb3252015-02-05 14:41:52 +0000210 uint64_t modifier[4];
Dave Airlief453ba02008-11-07 14:05:41 -0800211 unsigned int width;
212 unsigned int height;
213 /* depth can be 15 or 16 */
214 unsigned int depth;
215 int bits_per_pixel;
216 int flags;
Jesse Barnes308e5bc2011-11-14 14:51:28 -0800217 uint32_t pixel_format; /* fourcc format */
Dave Airlief453ba02008-11-07 14:05:41 -0800218 struct list_head filp_head;
219};
220
221struct drm_property_blob {
222 struct drm_mode_object base;
Daniel Stone6bcacf52015-04-20 19:22:55 +0100223 struct drm_device *dev;
224 struct kref refcount;
Daniel Stonee2f5d2e2015-05-22 13:34:51 +0100225 struct list_head head_global;
226 struct list_head head_file;
Thierry Redingecbbe592014-05-13 11:36:13 +0200227 size_t length;
Ville Syrjäläd63f5e62012-03-13 12:35:49 +0200228 unsigned char data[];
Dave Airlief453ba02008-11-07 14:05:41 -0800229};
230
231struct drm_property_enum {
232 uint64_t value;
233 struct list_head head;
234 char name[DRM_PROP_NAME_LEN];
235};
236
237struct drm_property {
238 struct list_head head;
239 struct drm_mode_object base;
240 uint32_t flags;
241 char name[DRM_PROP_NAME_LEN];
242 uint32_t num_values;
243 uint64_t *values;
Rob Clark98f75de2014-05-30 11:37:03 -0400244 struct drm_device *dev;
Dave Airlief453ba02008-11-07 14:05:41 -0800245
Daniel Vetter3758b342014-11-19 18:38:10 +0100246 struct list_head enum_list;
Dave Airlief453ba02008-11-07 14:05:41 -0800247};
248
249struct drm_crtc;
250struct drm_connector;
251struct drm_encoder;
Kristian Høgsbergd91d8a32009-11-17 12:43:55 -0500252struct drm_pending_vblank_event;
Jesse Barnes8cf5c912011-11-14 14:51:27 -0800253struct drm_plane;
Sean Paul3b336ec2013-08-14 16:47:37 -0400254struct drm_bridge;
Daniel Vetter144ecb92014-10-27 20:28:44 +0100255struct drm_atomic_state;
256
Daniel Vetter4490d4c2015-12-04 09:45:45 +0100257struct drm_crtc_helper_funcs;
258struct drm_encoder_helper_funcs;
259struct drm_connector_helper_funcs;
260struct drm_plane_helper_funcs;
261
Daniel Vetter144ecb92014-10-27 20:28:44 +0100262/**
Daniel Vettercc4ceb42014-07-25 21:30:38 +0200263 * struct drm_crtc_state - mutable CRTC state
Daniel Vetter07cc0ef2014-11-27 15:49:39 +0100264 * @crtc: backpointer to the CRTC
Daniel Vetter144ecb92014-10-27 20:28:44 +0100265 * @enable: whether the CRTC should be enabled, gates all other state
Daniel Vetterd9b13622014-11-26 16:57:41 +0100266 * @active: whether the CRTC is actively displaying (used for DPMS)
Maarten Lankhorstfc596662015-07-21 13:28:57 +0200267 * @planes_changed: planes on this crtc are updated
268 * @mode_changed: crtc_state->mode or crtc_state->enable has been changed
269 * @active_changed: crtc_state->active has been toggled.
270 * @connectors_changed: connectors to this crtc have been updated
Rob Clark6ddd3882014-11-21 15:28:31 -0500271 * @plane_mask: bitmask of (1 << drm_plane_index(plane)) of attached planes
Daniel Vetter623369e2014-09-16 17:50:47 +0200272 * @last_vblank_count: for helpers and drivers to capture the vblank of the
273 * update to ensure framebuffer cleanup isn't done too early
Daniel Vetter2f324b42014-10-29 11:13:47 +0100274 * @adjusted_mode: for use by helpers and drivers to compute adjusted mode timings
Daniel Vetter144ecb92014-10-27 20:28:44 +0100275 * @mode: current mode timings
276 * @event: optional pointer to a DRM event to signal upon completion of the
277 * state update
278 * @state: backpointer to global drm_atomic_state
Daniel Vetterd9b13622014-11-26 16:57:41 +0100279 *
280 * Note that the distinction between @enable and @active is rather subtile:
281 * Flipping @active while @enable is set without changing anything else may
282 * never return in a failure from the ->atomic_check callback. Userspace assumes
283 * that a DPMS On will always succeed. In other words: @enable controls resource
284 * assignment, @active controls the actual hardware state.
Daniel Vetter144ecb92014-10-27 20:28:44 +0100285 */
286struct drm_crtc_state {
Daniel Vetter07cc0ef2014-11-27 15:49:39 +0100287 struct drm_crtc *crtc;
288
Daniel Vettercc4ceb42014-07-25 21:30:38 +0200289 bool enable;
Daniel Vetterd9b13622014-11-26 16:57:41 +0100290 bool active;
Daniel Vetter144ecb92014-10-27 20:28:44 +0100291
Daniel Vetterc2fcd272014-11-05 00:14:14 +0100292 /* computed state bits used by helpers and drivers */
293 bool planes_changed : 1;
Daniel Vetter623369e2014-09-16 17:50:47 +0200294 bool mode_changed : 1;
Daniel Vettereab3bbe2015-01-22 16:36:21 +0100295 bool active_changed : 1;
Maarten Lankhorstfc596662015-07-21 13:28:57 +0200296 bool connectors_changed : 1;
Daniel Vetter623369e2014-09-16 17:50:47 +0200297
Rob Clark6ddd3882014-11-21 15:28:31 -0500298 /* attached planes bitmask:
299 * WARNING: transitional helpers do not maintain plane_mask so
300 * drivers not converted over to atomic helpers should not rely
301 * on plane_mask being accurate!
302 */
303 u32 plane_mask;
304
Daniel Vetter623369e2014-09-16 17:50:47 +0200305 /* last_vblank_count: for vblank waits before cleanup */
306 u32 last_vblank_count;
Daniel Vetterc2fcd272014-11-05 00:14:14 +0100307
Daniel Vetter2f324b42014-10-29 11:13:47 +0100308 /* adjusted_mode: for use by helpers and drivers */
309 struct drm_display_mode adjusted_mode;
310
Daniel Vetter144ecb92014-10-27 20:28:44 +0100311 struct drm_display_mode mode;
312
Daniel Stone99cf4a22015-05-25 19:11:51 +0100313 /* blob property to expose current mode to atomic userspace */
314 struct drm_property_blob *mode_blob;
315
Daniel Vetter144ecb92014-10-27 20:28:44 +0100316 struct drm_pending_vblank_event *event;
317
318 struct drm_atomic_state *state;
319};
Dave Airlief453ba02008-11-07 14:05:41 -0800320
321/**
Daniel Vetter3bf04012014-10-27 16:54:27 +0100322 * struct drm_crtc_funcs - control CRTCs for a given device
Dave Airlief453ba02008-11-07 14:05:41 -0800323 *
324 * The drm_crtc_funcs structure is the central CRTC management structure
325 * in the DRM. Each CRTC controls one or more connectors (note that the name
326 * CRTC is simply historical, a CRTC may control LVDS, VGA, DVI, TV out, etc.
327 * connectors, not just CRTs).
328 *
329 * Each driver is responsible for filling out this structure at startup time,
330 * in addition to providing other modesetting features, like i2c and DDC
331 * bus accessors.
332 */
333struct drm_crtc_funcs {
Daniel Vetter88548632015-12-04 09:45:48 +0100334 /**
335 * @reset:
336 *
337 * Reset CRTC hardware and software state to off. This function isn't
338 * called by the core directly, only through drm_mode_config_reset().
339 * It's not a helper hook only for historical reasons.
340 *
341 * Atomic drivers can use drm_atomic_helper_crtc_reset() to reset
342 * atomic state using this hook.
343 */
Chris Wilsoneb0335562011-01-24 15:11:08 +0000344 void (*reset)(struct drm_crtc *crtc);
Dave Airlief453ba02008-11-07 14:05:41 -0800345
Daniel Vetterf6da8c62015-12-04 09:46:00 +0100346 /**
347 * @cursor_set:
348 *
349 * Update the cursor image. The cursor position is relative to the CRTC
350 * and can be partially or fully outside of the visible area.
351 *
352 * Note that contrary to all other KMS functions the legacy cursor entry
353 * points don't take a framebuffer object, but instead take directly a
354 * raw buffer object id from the driver's buffer manager (which is
355 * either GEM or TTM for current drivers).
356 *
357 * This entry point is deprecated, drivers should instead implement
358 * universal plane support and register a proper cursor plane using
359 * drm_crtc_init_with_planes().
360 *
361 * This callback is optional
362 *
363 * RETURNS:
364 *
365 * 0 on success or a negative error code on failure.
366 */
Dave Airlief453ba02008-11-07 14:05:41 -0800367 int (*cursor_set)(struct drm_crtc *crtc, struct drm_file *file_priv,
368 uint32_t handle, uint32_t width, uint32_t height);
Daniel Vetterf6da8c62015-12-04 09:46:00 +0100369
370 /**
371 * @cursor_set2:
372 *
373 * Update the cursor image, including hotspot information. The hotspot
374 * must not affect the cursor position in CRTC coordinates, but is only
375 * meant as a hint for virtualized display hardware to coordinate the
376 * guests and hosts cursor position. The cursor hotspot is relative to
377 * the cursor image. Otherwise this works exactly like @cursor_set.
378 *
379 * This entry point is deprecated, drivers should instead implement
380 * universal plane support and register a proper cursor plane using
381 * drm_crtc_init_with_planes().
382 *
383 * This callback is optional.
384 *
385 * RETURNS:
386 *
387 * 0 on success or a negative error code on failure.
388 */
Dave Airlie4c813d42013-06-20 11:48:52 +1000389 int (*cursor_set2)(struct drm_crtc *crtc, struct drm_file *file_priv,
390 uint32_t handle, uint32_t width, uint32_t height,
391 int32_t hot_x, int32_t hot_y);
Daniel Vetterf6da8c62015-12-04 09:46:00 +0100392
393 /**
394 * @cursor_move:
395 *
396 * Update the cursor position. The cursor does not need to be visible
397 * when this hook is called.
398 *
399 * This entry point is deprecated, drivers should instead implement
400 * universal plane support and register a proper cursor plane using
401 * drm_crtc_init_with_planes().
402 *
403 * This callback is optional.
404 *
405 * RETURNS:
406 *
407 * 0 on success or a negative error code on failure.
408 */
Dave Airlief453ba02008-11-07 14:05:41 -0800409 int (*cursor_move)(struct drm_crtc *crtc, int x, int y);
410
Daniel Vetterf6da8c62015-12-04 09:46:00 +0100411 /**
412 * @gamma_set:
413 *
414 * Set gamma on the CRTC.
415 *
416 * This callback is optional.
417 *
418 * NOTE:
419 *
420 * Drivers that support gamma tables and also fbdev emulation through
421 * the provided helper library need to take care to fill out the gamma
422 * hooks for both. Currently there's a bit an unfortunate duplication
423 * going on, which should eventually be unified to just one set of
424 * hooks.
425 */
Dave Airlief453ba02008-11-07 14:05:41 -0800426 void (*gamma_set)(struct drm_crtc *crtc, u16 *r, u16 *g, u16 *b,
James Simmons72034252010-08-03 01:33:19 +0100427 uint32_t start, uint32_t size);
Daniel Vetter88548632015-12-04 09:45:48 +0100428
429 /**
430 * @destroy:
431 *
432 * Clean up plane resources. This is only called at driver unload time
433 * through drm_mode_config_cleanup() since a CRTC cannot be hotplugged
434 * in DRM.
435 */
Dave Airlief453ba02008-11-07 14:05:41 -0800436 void (*destroy)(struct drm_crtc *crtc);
437
Daniel Vetterf6da8c62015-12-04 09:46:00 +0100438 /**
439 * @set_config:
440 *
441 * This is the main legacy entry point to change the modeset state on a
442 * CRTC. All the details of the desired configuration are passed in a
443 * struct &drm_mode_set - see there for details.
444 *
445 * Drivers implementing atomic modeset should use
446 * drm_atomic_helper_set_config() to implement this hook.
447 *
448 * RETURNS:
449 *
450 * 0 on success or a negative error code on failure.
451 */
Dave Airlief453ba02008-11-07 14:05:41 -0800452 int (*set_config)(struct drm_mode_set *set);
Kristian Høgsbergd91d8a32009-11-17 12:43:55 -0500453
Daniel Vetterf6da8c62015-12-04 09:46:00 +0100454 /**
455 * @page_flip:
456 *
457 * Legacy entry point to schedule a flip to the given framebuffer.
458 *
459 * Page flipping is a synchronization mechanism that replaces the frame
460 * buffer being scanned out by the CRTC with a new frame buffer during
461 * vertical blanking, avoiding tearing (except when requested otherwise
462 * through the DRM_MODE_PAGE_FLIP_ASYNC flag). When an application
463 * requests a page flip the DRM core verifies that the new frame buffer
464 * is large enough to be scanned out by the CRTC in the currently
465 * configured mode and then calls the CRTC ->page_flip() operation with a
466 * pointer to the new frame buffer.
467 *
468 * The driver must wait for any pending rendering to the new framebuffer
469 * to complete before executing the flip. It should also wait for any
470 * pending rendering from other drivers if the underlying buffer is a
471 * shared dma-buf.
472 *
473 * An application can request to be notified when the page flip has
474 * completed. The drm core will supply a struct &drm_event in the event
475 * parameter in this case. This can be handled by the
476 * drm_crtc_send_vblank_event() function, which the driver should call on
477 * the provided event upon completion of the flip. Note that if
478 * the driver supports vblank signalling and timestamping the vblank
479 * counters and timestamps must agree with the ones returned from page
480 * flip events. With the current vblank helper infrastructure this can
481 * be achieved by holding a vblank reference while the page flip is
482 * pending, acquired through drm_crtc_vblank_get() and released with
483 * drm_crtc_vblank_put(). Drivers are free to implement their own vblank
484 * counter and timestamp tracking though, e.g. if they have accurate
485 * timestamp registers in hardware.
486 *
487 * FIXME:
488 *
489 * Up to that point drivers need to manage events themselves and can use
490 * even->base.list freely for that. Specifically they need to ensure
491 * that they don't send out page flip (or vblank) events for which the
492 * corresponding drm file has been closed already. The drm core
493 * unfortunately does not (yet) take care of that. Therefore drivers
494 * currently must clean up and release pending events in their
495 * ->preclose driver function.
496 *
497 * This callback is optional.
498 *
499 * NOTE:
500 *
501 * Very early versions of the KMS ABI mandated that the driver must
502 * block (but not reject) any rendering to the old framebuffer until the
503 * flip operation has completed and the old framebuffer is no longer
504 * visible. This requirement has been lifted, and userspace is instead
505 * expected to request delivery of an event and wait with recycling old
506 * buffers until such has been received.
507 *
508 * RETURNS:
509 *
510 * 0 on success or a negative error code on failure. Note that if a
511 * ->page_flip() operation is already pending the callback should return
512 * -EBUSY. Pageflips on a disabled CRTC (either by setting a NULL mode
513 * or just runtime disabled through DPMS respectively the new atomic
514 * "ACTIVE" state) should result in an -EINVAL error code.
Kristian Høgsbergd91d8a32009-11-17 12:43:55 -0500515 */
516 int (*page_flip)(struct drm_crtc *crtc,
517 struct drm_framebuffer *fb,
Keith Packarded8d1972013-07-22 18:49:58 -0700518 struct drm_pending_vblank_event *event,
519 uint32_t flags);
Paulo Zanonibffd9de02012-05-15 18:09:05 -0300520
Daniel Vetter88548632015-12-04 09:45:48 +0100521 /**
522 * @set_property:
523 *
524 * This is the legacy entry point to update a property attached to the
525 * CRTC.
526 *
527 * Drivers implementing atomic modeset should use
528 * drm_atomic_helper_crtc_set_property() to implement this hook.
529 *
530 * This callback is optional if the driver does not support any legacy
531 * driver-private properties.
532 *
533 * RETURNS:
534 *
535 * 0 on success or a negative error code on failure.
536 */
Paulo Zanonibffd9de02012-05-15 18:09:05 -0300537 int (*set_property)(struct drm_crtc *crtc,
538 struct drm_property *property, uint64_t val);
Daniel Vetter144ecb92014-10-27 20:28:44 +0100539
Daniel Vetter88548632015-12-04 09:45:48 +0100540 /**
541 * @atomic_duplicate_state:
542 *
543 * Duplicate the current atomic state for this CRTC and return it.
544 * The core and helpers gurantee that any atomic state duplicated with
545 * this hook and still owned by the caller (i.e. not transferred to the
546 * driver by calling ->atomic_commit() from struct
547 * &drm_mode_config_funcs) will be cleaned up by calling the
548 * @atomic_destroy_state hook in this structure.
549 *
550 * Atomic drivers which don't subclass struct &drm_crtc should use
551 * drm_atomic_helper_crtc_duplicate_state(). Drivers that subclass the
552 * state structure to extend it with driver-private state should use
553 * __drm_atomic_helper_crtc_duplicate_state() to make sure shared state is
554 * duplicated in a consistent fashion across drivers.
555 *
556 * It is an error to call this hook before crtc->state has been
557 * initialized correctly.
558 *
559 * NOTE:
560 *
561 * If the duplicate state references refcounted resources this hook must
562 * acquire a reference for each of them. The driver must release these
563 * references again in @atomic_destroy_state.
564 *
565 * RETURNS:
566 *
567 * Duplicated atomic state or NULL when the allocation failed.
568 */
Daniel Vetter144ecb92014-10-27 20:28:44 +0100569 struct drm_crtc_state *(*atomic_duplicate_state)(struct drm_crtc *crtc);
Daniel Vetter88548632015-12-04 09:45:48 +0100570
571 /**
572 * @atomic_destroy_state:
573 *
574 * Destroy a state duplicated with @atomic_duplicate_state and release
575 * or unreference all resources it references
576 */
Daniel Vetter144ecb92014-10-27 20:28:44 +0100577 void (*atomic_destroy_state)(struct drm_crtc *crtc,
Daniel Vettercc4ceb42014-07-25 21:30:38 +0200578 struct drm_crtc_state *state);
Daniel Vetter88548632015-12-04 09:45:48 +0100579
580 /**
581 * @atomic_set_property:
582 *
583 * Decode a driver-private property value and store the decoded value
584 * into the passed-in state structure. Since the atomic core decodes all
585 * standardized properties (even for extensions beyond the core set of
586 * properties which might not be implemented by all drivers) this
587 * requires drivers to subclass the state structure.
588 *
589 * Such driver-private properties should really only be implemented for
590 * truly hardware/vendor specific state. Instead it is preferred to
591 * standardize atomic extension and decode the properties used to expose
592 * such an extension in the core.
593 *
594 * Do not call this function directly, use
595 * drm_atomic_crtc_set_property() instead.
596 *
597 * This callback is optional if the driver does not support any
598 * driver-private atomic properties.
599 *
600 * NOTE:
601 *
602 * This function is called in the state assembly phase of atomic
603 * modesets, which can be aborted for any reason (including on
604 * userspace's request to just check whether a configuration would be
605 * possible). Drivers MUST NOT touch any persistent state (hardware or
606 * software) or data structures except the passed in @state parameter.
607 *
608 * Also since userspace controls in which order properties are set this
609 * function must not do any input validation (since the state update is
610 * incomplete and hence likely inconsistent). Instead any such input
611 * validation must be done in the various atomic_check callbacks.
612 *
613 * RETURNS:
614 *
615 * 0 if the property has been found, -EINVAL if the property isn't
616 * implemented by the driver (which should never happen, the core only
617 * asks for properties attached to this CRTC). No other validation is
618 * allowed by the driver. The core already checks that the property
619 * value is within the range (integer, valid enum value, ...) the driver
620 * set when registering the property.
621 */
Daniel Vetter144ecb92014-10-27 20:28:44 +0100622 int (*atomic_set_property)(struct drm_crtc *crtc,
623 struct drm_crtc_state *state,
624 struct drm_property *property,
625 uint64_t val);
Daniel Vetter88548632015-12-04 09:45:48 +0100626 /**
627 * @atomic_get_property:
628 *
629 * Reads out the decoded driver-private property. This is used to
630 * implement the GETCRTC ioctl.
631 *
632 * Do not call this function directly, use
633 * drm_atomic_crtc_get_property() instead.
634 *
635 * This callback is optional if the driver does not support any
636 * driver-private atomic properties.
637 *
638 * RETURNS:
639 *
640 * 0 on success, -EINVAL if the property isn't implemented by the
641 * driver (which should never happen, the core only asks for
642 * properties attached to this CRTC).
643 */
Rob Clarkac9c9252014-12-18 16:01:47 -0500644 int (*atomic_get_property)(struct drm_crtc *crtc,
645 const struct drm_crtc_state *state,
646 struct drm_property *property,
647 uint64_t *val);
Dave Airlief453ba02008-11-07 14:05:41 -0800648};
649
650/**
Daniel Vetter3bf04012014-10-27 16:54:27 +0100651 * struct drm_crtc - central CRTC control structure
Jesse Barnes77491632011-11-07 12:03:14 -0800652 * @dev: parent DRM device
Daniel Vetter2c0c33d2014-10-27 20:19:38 +0100653 * @port: OF node used by drm_of_find_possible_crtcs()
Jesse Barnes77491632011-11-07 12:03:14 -0800654 * @head: list management
Rob Clark51fd3712013-11-19 12:10:12 -0500655 * @mutex: per-CRTC locking
Jesse Barnes77491632011-11-07 12:03:14 -0800656 * @base: base KMS object for ID tracking etc.
Matt Ropere13161a2014-04-01 15:22:38 -0700657 * @primary: primary plane for this CRTC
658 * @cursor: cursor plane for this CRTC
Daniel Vetter2c0c33d2014-10-27 20:19:38 +0100659 * @cursor_x: current x position of the cursor, used for universal cursor planes
660 * @cursor_y: current y position of the cursor, used for universal cursor planes
Dave Airlief453ba02008-11-07 14:05:41 -0800661 * @enabled: is this CRTC enabled?
Jesse Barnes77491632011-11-07 12:03:14 -0800662 * @mode: current mode timings
663 * @hwmode: mode timings as programmed to hw regs
Dave Airlief453ba02008-11-07 14:05:41 -0800664 * @x: x position on screen
665 * @y: y position on screen
Dave Airlief453ba02008-11-07 14:05:41 -0800666 * @funcs: CRTC control functions
Jesse Barnes77491632011-11-07 12:03:14 -0800667 * @gamma_size: size of gamma ramp
668 * @gamma_store: gamma ramp values
Jesse Barnes77491632011-11-07 12:03:14 -0800669 * @helper_private: mid-layer private data
Paulo Zanonibffd9de02012-05-15 18:09:05 -0300670 * @properties: property tracking for this CRTC
Daniel Vetter144ecb92014-10-27 20:28:44 +0100671 * @state: current atomic state for this CRTC
Daniel Vetter2c0c33d2014-10-27 20:19:38 +0100672 * @acquire_ctx: per-CRTC implicit acquire context used by atomic drivers for
673 * legacy ioctls
Dave Airlief453ba02008-11-07 14:05:41 -0800674 *
675 * Each CRTC may have one or more connectors associated with it. This structure
676 * allows the CRTC to be controlled.
677 */
678struct drm_crtc {
679 struct drm_device *dev;
Russell King7e435aa2014-06-15 11:07:12 +0100680 struct device_node *port;
Dave Airlief453ba02008-11-07 14:05:41 -0800681 struct list_head head;
682
Daniel Vetter3bf04012014-10-27 16:54:27 +0100683 /*
Daniel Vetter29494c12012-12-02 02:18:25 +0100684 * crtc mutex
685 *
686 * This provides a read lock for the overall crtc state (mode, dpms
687 * state, ...) and a write lock for everything which can be update
688 * without a full modeset (fb, cursor data, ...)
689 */
Rob Clark51fd3712013-11-19 12:10:12 -0500690 struct drm_modeset_lock mutex;
Daniel Vetter29494c12012-12-02 02:18:25 +0100691
Dave Airlief453ba02008-11-07 14:05:41 -0800692 struct drm_mode_object base;
693
Matt Ropere13161a2014-04-01 15:22:38 -0700694 /* primary and cursor planes for CRTC */
695 struct drm_plane *primary;
696 struct drm_plane *cursor;
697
Matt Roper161d0dc2014-06-10 08:28:10 -0700698 /* position of cursor plane on crtc */
699 int cursor_x;
700 int cursor_y;
701
Dave Airlief453ba02008-11-07 14:05:41 -0800702 bool enabled;
703
Mario Kleiner27641c32010-10-23 04:20:23 +0200704 /* Requested mode from modesetting. */
Dave Airlief453ba02008-11-07 14:05:41 -0800705 struct drm_display_mode mode;
706
Mario Kleiner27641c32010-10-23 04:20:23 +0200707 /* Programmed mode in hw, after adjustments for encoders,
708 * crtc, panel scaling etc. Needed for timestamping etc.
709 */
710 struct drm_display_mode hwmode;
711
Dave Airlief453ba02008-11-07 14:05:41 -0800712 int x, y;
Dave Airlief453ba02008-11-07 14:05:41 -0800713 const struct drm_crtc_funcs *funcs;
714
715 /* CRTC gamma size for reporting to userspace */
716 uint32_t gamma_size;
717 uint16_t *gamma_store;
718
719 /* if you are using the helper */
Daniel Vetter4490d4c2015-12-04 09:45:45 +0100720 const struct drm_crtc_helper_funcs *helper_private;
Paulo Zanonibffd9de02012-05-15 18:09:05 -0300721
722 struct drm_object_properties properties;
Daniel Vetterd059f652014-07-25 18:07:40 +0200723
Daniel Vetter144ecb92014-10-27 20:28:44 +0100724 struct drm_crtc_state *state;
725
Daniel Vetterd059f652014-07-25 18:07:40 +0200726 /*
727 * For legacy crtc ioctls so that atomic drivers can get at the locking
728 * acquire context.
729 */
730 struct drm_modeset_acquire_ctx *acquire_ctx;
Dave Airlief453ba02008-11-07 14:05:41 -0800731};
732
Daniel Vetter144ecb92014-10-27 20:28:44 +0100733/**
734 * struct drm_connector_state - mutable connector state
Daniel Vetter07cc0ef2014-11-27 15:49:39 +0100735 * @connector: backpointer to the connector
Daniel Vettercc4ceb42014-07-25 21:30:38 +0200736 * @crtc: CRTC to connect connector to, NULL if disabled
Daniel Vetter623369e2014-09-16 17:50:47 +0200737 * @best_encoder: can be used by helpers and drivers to select the encoder
Daniel Vetter144ecb92014-10-27 20:28:44 +0100738 * @state: backpointer to global drm_atomic_state
739 */
740struct drm_connector_state {
Daniel Vetter07cc0ef2014-11-27 15:49:39 +0100741 struct drm_connector *connector;
742
Rob Clark6ddd3882014-11-21 15:28:31 -0500743 struct drm_crtc *crtc; /* do not write directly, use drm_atomic_set_crtc_for_connector() */
Daniel Vetter144ecb92014-10-27 20:28:44 +0100744
Daniel Vetter623369e2014-09-16 17:50:47 +0200745 struct drm_encoder *best_encoder;
746
Daniel Vetter144ecb92014-10-27 20:28:44 +0100747 struct drm_atomic_state *state;
748};
Dave Airlief453ba02008-11-07 14:05:41 -0800749
750/**
Daniel Vetter3bf04012014-10-27 16:54:27 +0100751 * struct drm_connector_funcs - control connectors on a given device
Daniel Vetter144ecb92014-10-27 20:28:44 +0100752 *
Dave Airlief453ba02008-11-07 14:05:41 -0800753 * Each CRTC may have one or more connectors attached to it. The functions
754 * below allow the core DRM code to control connectors, enumerate available modes,
755 * etc.
756 */
757struct drm_connector_funcs {
Daniel Vetter6fe14ac2015-12-04 09:45:58 +0100758 /**
759 * @dpms:
760 *
761 * Legacy entry point to set the per-connector DPMS state. Legacy DPMS
762 * is exposed as a standard property on the connector, but diverted to
763 * this callback in the drm core. Note that atomic drivers don't
764 * implement the 4 level DPMS support on the connector any more, but
765 * instead only have an on/off "ACTIVE" property on the CRTC object.
766 *
767 * Drivers implementing atomic modeset should use
768 * drm_atomic_helper_connector_dpms() to implement this hook.
769 *
770 * RETURNS:
771 *
772 * 0 on success or a negative error code on failure.
773 */
Maarten Lankhorst9a69a9a2015-07-21 11:34:55 +0200774 int (*dpms)(struct drm_connector *connector, int mode);
Daniel Vetter88548632015-12-04 09:45:48 +0100775
776 /**
777 * @reset:
778 *
779 * Reset connector hardware and software state to off. This function isn't
780 * called by the core directly, only through drm_mode_config_reset().
781 * It's not a helper hook only for historical reasons.
782 *
783 * Atomic drivers can use drm_atomic_helper_connector_reset() to reset
784 * atomic state using this hook.
785 */
Chris Wilsoneb0335562011-01-24 15:11:08 +0000786 void (*reset)(struct drm_connector *connector);
Chris Wilson930a9e22010-09-14 11:07:23 +0100787
Daniel Vetter6fe14ac2015-12-04 09:45:58 +0100788 /**
789 * @detect:
790 *
791 * Check to see if anything is attached to the connector. The parameter
792 * force is set to false whilst polling, true when checking the
793 * connector due to a user request. force can be used by the driver to
794 * avoid expensive, destructive operations during automated probing.
795 *
796 * FIXME:
797 *
798 * Note that this hook is only called by the probe helper. It's not in
799 * the helper library vtable purely for historical reasons. The only DRM
800 * core entry point to probe connector state is @fill_modes.
801 *
802 * RETURNS:
803 *
804 * drm_connector_status indicating the connector's status.
Chris Wilson930a9e22010-09-14 11:07:23 +0100805 */
Chris Wilson7b334fc2010-09-09 23:51:02 +0100806 enum drm_connector_status (*detect)(struct drm_connector *connector,
Chris Wilson930a9e22010-09-14 11:07:23 +0100807 bool force);
Daniel Vetter6fe14ac2015-12-04 09:45:58 +0100808
809 /**
810 * @force:
811 *
812 * This function is called to update internal encoder state when the
813 * connector is forced to a certain state by userspace, either through
814 * the sysfs interfaces or on the kernel cmdline. In that case the
815 * @detect callback isn't called.
816 *
817 * FIXME:
818 *
819 * Note that this hook is only called by the probe helper. It's not in
820 * the helper library vtable purely for historical reasons. The only DRM
821 * core entry point to probe connector state is @fill_modes.
822 */
823 void (*force)(struct drm_connector *connector);
824
825 /**
826 * @fill_modes:
827 *
828 * Entry point for output detection and basic mode validation. The
829 * driver should reprobe the output if needed (e.g. when hotplug
830 * handling is unreliable), add all detected modes to connector->modes
831 * and filter out any the device can't support in any configuration. It
832 * also needs to filter out any modes wider or higher than the
833 * parameters max_width and max_height indicate.
834 *
835 * The drivers must also prune any modes no longer valid from
836 * connector->modes. Furthermore it must update connector->status and
837 * connector->edid. If no EDID has been received for this output
838 * connector->edid must be NULL.
839 *
840 * Drivers using the probe helpers should use
841 * drm_helper_probe_single_connector_modes() or
842 * drm_helper_probe_single_connector_modes_nomerge() to implement this
843 * function.
844 *
845 * RETURNS:
846 *
847 * The number of modes detected and filled into connector->modes.
848 */
Jesse Barnes40a518d2009-01-12 12:05:32 -0800849 int (*fill_modes)(struct drm_connector *connector, uint32_t max_width, uint32_t max_height);
Daniel Vetter88548632015-12-04 09:45:48 +0100850
851 /**
852 * @set_property:
853 *
854 * This is the legacy entry point to update a property attached to the
855 * connector.
856 *
857 * Drivers implementing atomic modeset should use
858 * drm_atomic_helper_connector_set_property() to implement this hook.
859 *
860 * This callback is optional if the driver does not support any legacy
861 * driver-private properties.
862 *
863 * RETURNS:
864 *
865 * 0 on success or a negative error code on failure.
866 */
Dave Airlief453ba02008-11-07 14:05:41 -0800867 int (*set_property)(struct drm_connector *connector, struct drm_property *property,
868 uint64_t val);
Daniel Vetter88548632015-12-04 09:45:48 +0100869
870 /**
871 * @destroy:
872 *
873 * Clean up connector resources. This is called at driver unload time
874 * through drm_mode_config_cleanup(). It can also be called at runtime
875 * when a connector is being hot-unplugged for drivers that support
876 * connector hotplugging (e.g. DisplayPort MST).
877 */
Dave Airlief453ba02008-11-07 14:05:41 -0800878 void (*destroy)(struct drm_connector *connector);
Daniel Vetter144ecb92014-10-27 20:28:44 +0100879
Daniel Vetter88548632015-12-04 09:45:48 +0100880 /**
881 * @atomic_duplicate_state:
882 *
883 * Duplicate the current atomic state for this connector and return it.
884 * The core and helpers gurantee that any atomic state duplicated with
885 * this hook and still owned by the caller (i.e. not transferred to the
886 * driver by calling ->atomic_commit() from struct
887 * &drm_mode_config_funcs) will be cleaned up by calling the
888 * @atomic_destroy_state hook in this structure.
889 *
890 * Atomic drivers which don't subclass struct &drm_connector_state should use
891 * drm_atomic_helper_connector_duplicate_state(). Drivers that subclass the
892 * state structure to extend it with driver-private state should use
893 * __drm_atomic_helper_connector_duplicate_state() to make sure shared state is
894 * duplicated in a consistent fashion across drivers.
895 *
896 * It is an error to call this hook before connector->state has been
897 * initialized correctly.
898 *
899 * NOTE:
900 *
901 * If the duplicate state references refcounted resources this hook must
902 * acquire a reference for each of them. The driver must release these
903 * references again in @atomic_destroy_state.
904 *
905 * RETURNS:
906 *
907 * Duplicated atomic state or NULL when the allocation failed.
908 */
Daniel Vetter144ecb92014-10-27 20:28:44 +0100909 struct drm_connector_state *(*atomic_duplicate_state)(struct drm_connector *connector);
Daniel Vetter88548632015-12-04 09:45:48 +0100910
911 /**
912 * @atomic_destroy_state:
913 *
914 * Destroy a state duplicated with @atomic_duplicate_state and release
915 * or unreference all resources it references
916 */
Daniel Vetter144ecb92014-10-27 20:28:44 +0100917 void (*atomic_destroy_state)(struct drm_connector *connector,
Daniel Vettercc4ceb42014-07-25 21:30:38 +0200918 struct drm_connector_state *state);
Daniel Vetter88548632015-12-04 09:45:48 +0100919
920 /**
921 * @atomic_set_property:
922 *
923 * Decode a driver-private property value and store the decoded value
924 * into the passed-in state structure. Since the atomic core decodes all
925 * standardized properties (even for extensions beyond the core set of
926 * properties which might not be implemented by all drivers) this
927 * requires drivers to subclass the state structure.
928 *
929 * Such driver-private properties should really only be implemented for
930 * truly hardware/vendor specific state. Instead it is preferred to
931 * standardize atomic extension and decode the properties used to expose
932 * such an extension in the core.
933 *
934 * Do not call this function directly, use
935 * drm_atomic_connector_set_property() instead.
936 *
937 * This callback is optional if the driver does not support any
938 * driver-private atomic properties.
939 *
940 * NOTE:
941 *
942 * This function is called in the state assembly phase of atomic
943 * modesets, which can be aborted for any reason (including on
944 * userspace's request to just check whether a configuration would be
945 * possible). Drivers MUST NOT touch any persistent state (hardware or
946 * software) or data structures except the passed in @state parameter.
947 *
948 * Also since userspace controls in which order properties are set this
949 * function must not do any input validation (since the state update is
950 * incomplete and hence likely inconsistent). Instead any such input
951 * validation must be done in the various atomic_check callbacks.
952 *
953 * RETURNS:
954 *
955 * 0 if the property has been found, -EINVAL if the property isn't
956 * implemented by the driver (which shouldn't ever happen, the core only
957 * asks for properties attached to this connector). No other validation
958 * is allowed by the driver. The core already checks that the property
959 * value is within the range (integer, valid enum value, ...) the driver
960 * set when registering the property.
961 */
Daniel Vetter144ecb92014-10-27 20:28:44 +0100962 int (*atomic_set_property)(struct drm_connector *connector,
963 struct drm_connector_state *state,
964 struct drm_property *property,
965 uint64_t val);
Daniel Vetter88548632015-12-04 09:45:48 +0100966
967 /**
968 * @atomic_get_property:
969 *
970 * Reads out the decoded driver-private property. This is used to
971 * implement the GETCONNECTOR ioctl.
972 *
973 * Do not call this function directly, use
974 * drm_atomic_connector_get_property() instead.
975 *
976 * This callback is optional if the driver does not support any
977 * driver-private atomic properties.
978 *
979 * RETURNS:
980 *
981 * 0 on success, -EINVAL if the property isn't implemented by the
982 * driver (which shouldn't ever happen, the core only asks for
983 * properties attached to this connector).
984 */
Rob Clarkac9c9252014-12-18 16:01:47 -0500985 int (*atomic_get_property)(struct drm_connector *connector,
986 const struct drm_connector_state *state,
987 struct drm_property *property,
988 uint64_t *val);
Dave Airlief453ba02008-11-07 14:05:41 -0800989};
990
Jesse Barnes6c3db922011-11-07 12:03:16 -0800991/**
Daniel Vetter3bf04012014-10-27 16:54:27 +0100992 * struct drm_encoder_funcs - encoder controls
Jesse Barnes6c3db922011-11-07 12:03:16 -0800993 *
994 * Encoders sit between CRTCs and connectors.
995 */
Dave Airlief453ba02008-11-07 14:05:41 -0800996struct drm_encoder_funcs {
Daniel Vetter88548632015-12-04 09:45:48 +0100997 /**
998 * @reset:
999 *
1000 * Reset encoder hardware and software state to off. This function isn't
1001 * called by the core directly, only through drm_mode_config_reset().
1002 * It's not a helper hook only for historical reasons.
1003 */
Chris Wilsoneb0335562011-01-24 15:11:08 +00001004 void (*reset)(struct drm_encoder *encoder);
Daniel Vetter88548632015-12-04 09:45:48 +01001005
1006 /**
1007 * @destroy:
1008 *
1009 * Clean up encoder resources. This is only called at driver unload time
1010 * through drm_mode_config_cleanup() since an encoder cannot be
1011 * hotplugged in DRM.
1012 */
Dave Airlief453ba02008-11-07 14:05:41 -08001013 void (*destroy)(struct drm_encoder *encoder);
1014};
1015
Ben Skeggsafe887d2012-01-12 16:00:57 +10001016#define DRM_CONNECTOR_MAX_ENCODER 3
Dave Airlief453ba02008-11-07 14:05:41 -08001017
1018/**
Daniel Vetter3bf04012014-10-27 16:54:27 +01001019 * struct drm_encoder - central DRM encoder structure
Jesse Barnesdb3e4492011-11-07 12:03:17 -08001020 * @dev: parent DRM device
1021 * @head: list management
1022 * @base: base KMS object
Jani Nikulae5748942014-05-14 16:58:20 +03001023 * @name: encoder name
Jesse Barnesdb3e4492011-11-07 12:03:17 -08001024 * @encoder_type: one of the %DRM_MODE_ENCODER_<foo> types in drm_mode.h
1025 * @possible_crtcs: bitmask of potential CRTC bindings
1026 * @possible_clones: bitmask of potential sibling encoders for cloning
1027 * @crtc: currently bound CRTC
Sean Paul3b336ec2013-08-14 16:47:37 -04001028 * @bridge: bridge associated to the encoder
Jesse Barnesdb3e4492011-11-07 12:03:17 -08001029 * @funcs: control functions
1030 * @helper_private: mid-layer private data
1031 *
1032 * CRTCs drive pixels to encoders, which convert them into signals
1033 * appropriate for a given connector or set of connectors.
Dave Airlief453ba02008-11-07 14:05:41 -08001034 */
1035struct drm_encoder {
1036 struct drm_device *dev;
1037 struct list_head head;
1038
1039 struct drm_mode_object base;
Jani Nikulae5748942014-05-14 16:58:20 +03001040 char *name;
Dave Airlief453ba02008-11-07 14:05:41 -08001041 int encoder_type;
1042 uint32_t possible_crtcs;
1043 uint32_t possible_clones;
1044
1045 struct drm_crtc *crtc;
Sean Paul3b336ec2013-08-14 16:47:37 -04001046 struct drm_bridge *bridge;
Dave Airlief453ba02008-11-07 14:05:41 -08001047 const struct drm_encoder_funcs *funcs;
Daniel Vetter4490d4c2015-12-04 09:45:45 +01001048 const struct drm_encoder_helper_funcs *helper_private;
Dave Airlief453ba02008-11-07 14:05:41 -08001049};
1050
Dave Airlieeb1f8e4f32010-05-07 06:42:51 +00001051/* should we poll this connector for connects and disconnects */
1052/* hot plug detectable */
1053#define DRM_CONNECTOR_POLL_HPD (1 << 0)
1054/* poll for connections */
1055#define DRM_CONNECTOR_POLL_CONNECT (1 << 1)
1056/* can cleanly poll for disconnections without flickering the screen */
1057/* DACs should rarely do this without a lot of testing */
1058#define DRM_CONNECTOR_POLL_DISCONNECT (1 << 2)
1059
Wu Fengguang76adaa342011-09-05 14:23:20 +08001060#define MAX_ELD_BYTES 128
1061
Dave Airlief453ba02008-11-07 14:05:41 -08001062/**
Daniel Vetter3bf04012014-10-27 16:54:27 +01001063 * struct drm_connector - central DRM connector control structure
Jesse Barnes72252542011-11-07 12:03:18 -08001064 * @dev: parent DRM device
1065 * @kdev: kernel device for sysfs attributes
1066 * @attr: sysfs attributes
1067 * @head: list management
1068 * @base: base KMS object
Jani Nikula2abdd312014-05-14 16:58:19 +03001069 * @name: connector name
Jesse Barnes72252542011-11-07 12:03:18 -08001070 * @connector_type: one of the %DRM_MODE_CONNECTOR_<foo> types from drm_mode.h
1071 * @connector_type_id: index into connector type enum
Dave Airlief453ba02008-11-07 14:05:41 -08001072 * @interlace_allowed: can this connector handle interlaced modes?
1073 * @doublescan_allowed: can this connector handle doublescan?
Daniel Vetter2c0c33d2014-10-27 20:19:38 +01001074 * @stereo_allowed: can this connector handle stereo modes?
Jesse Barnes72252542011-11-07 12:03:18 -08001075 * @modes: modes available on this connector (from fill_modes() + user)
1076 * @status: one of the drm_connector_status enums (connected, not, or unknown)
1077 * @probed_modes: list of modes derived directly from the display
1078 * @display_info: information about attached display (e.g. from EDID)
Dave Airlief453ba02008-11-07 14:05:41 -08001079 * @funcs: connector control functions
Jesse Barnes72252542011-11-07 12:03:18 -08001080 * @edid_blob_ptr: DRM property containing EDID if present
Paulo Zanoni7e3bdf42012-05-15 18:09:01 -03001081 * @properties: property tracking for this connector
Daniel Vetter2c0c33d2014-10-27 20:19:38 +01001082 * @path_blob_ptr: DRM blob property data for the DP MST path property
Jesse Barnes72252542011-11-07 12:03:18 -08001083 * @polled: a %DRM_CONNECTOR_POLL_<foo> value for core driven polling
1084 * @dpms: current dpms state
1085 * @helper_private: mid-layer private data
Daniel Vetter2c0c33d2014-10-27 20:19:38 +01001086 * @cmdline_mode: mode line parsed from the kernel cmdline for this connector
Jesse Barnes72252542011-11-07 12:03:18 -08001087 * @force: a %DRM_FORCE_<foo> state for forced mode sets
Daniel Vetter2c0c33d2014-10-27 20:19:38 +01001088 * @override_edid: has the EDID been overwritten through debugfs for testing?
Jesse Barnes72252542011-11-07 12:03:18 -08001089 * @encoder_ids: valid encoders for this connector
1090 * @encoder: encoder driving this connector, if any
1091 * @eld: EDID-like data, if present
1092 * @dvi_dual: dual link DVI, if found
1093 * @max_tmds_clock: max clock rate, if found
1094 * @latency_present: AV delay info from ELD, if found
1095 * @video_latency: video latency info from ELD, if found
1096 * @audio_latency: audio latency info from ELD, if found
1097 * @null_edid_counter: track sinks that give us all zeros for the EDID
Daniel Vetter2c0c33d2014-10-27 20:19:38 +01001098 * @bad_edid_counter: track sinks that give us an EDID with invalid checksum
Daniel Vetterac6f2e22015-05-08 16:15:41 +02001099 * @edid_corrupt: indicates whether the last read EDID was corrupt
Daniel Vetter2c0c33d2014-10-27 20:19:38 +01001100 * @debugfs_entry: debugfs directory for this connector
Daniel Vetter144ecb92014-10-27 20:28:44 +01001101 * @state: current atomic state for this connector
Dave Airlie40d9b042014-10-20 16:29:33 +10001102 * @has_tile: is this connector connected to a tiled monitor
1103 * @tile_group: tile group for the connected monitor
1104 * @tile_is_single_monitor: whether the tile is one monitor housing
1105 * @num_h_tile: number of horizontal tiles in the tile group
1106 * @num_v_tile: number of vertical tiles in the tile group
1107 * @tile_h_loc: horizontal location of this tile
1108 * @tile_v_loc: vertical location of this tile
1109 * @tile_h_size: horizontal size of this tile.
1110 * @tile_v_size: vertical size of this tile.
Dave Airlief453ba02008-11-07 14:05:41 -08001111 *
1112 * Each connector may be connected to one or more CRTCs, or may be clonable by
1113 * another connector if they can share a CRTC. Each connector also has a specific
1114 * position in the broader display (referred to as a 'screen' though it could
1115 * span multiple monitors).
1116 */
1117struct drm_connector {
1118 struct drm_device *dev;
Dave Airlie5bdebb12013-10-11 14:07:25 +10001119 struct device *kdev;
Dave Airlief453ba02008-11-07 14:05:41 -08001120 struct device_attribute *attr;
1121 struct list_head head;
1122
1123 struct drm_mode_object base;
1124
Jani Nikula2abdd312014-05-14 16:58:19 +03001125 char *name;
Dave Airlief453ba02008-11-07 14:05:41 -08001126 int connector_type;
1127 int connector_type_id;
1128 bool interlace_allowed;
1129 bool doublescan_allowed;
Damien Lespiau560a0672013-09-25 16:45:29 +01001130 bool stereo_allowed;
Dave Airlief453ba02008-11-07 14:05:41 -08001131 struct list_head modes; /* list of modes on this connector */
1132
Dave Airlief453ba02008-11-07 14:05:41 -08001133 enum drm_connector_status status;
1134
1135 /* these are modes added by probing with DDC or the BIOS */
1136 struct list_head probed_modes;
1137
1138 struct drm_display_info display_info;
1139 const struct drm_connector_funcs *funcs;
1140
Dave Airlief453ba02008-11-07 14:05:41 -08001141 struct drm_property_blob *edid_blob_ptr;
Paulo Zanoni7e3bdf42012-05-15 18:09:01 -03001142 struct drm_object_properties properties;
Dave Airlief453ba02008-11-07 14:05:41 -08001143
Dave Airlie43aba7e2014-06-05 14:01:31 +10001144 struct drm_property_blob *path_blob_ptr;
1145
Dave Airlie6f134d72014-10-20 16:30:50 +10001146 struct drm_property_blob *tile_blob_ptr;
1147
Dave Airlieeb1f8e4f32010-05-07 06:42:51 +00001148 uint8_t polled; /* DRM_CONNECTOR_POLL_* */
1149
Keith Packardc9fb15f2009-05-30 20:42:28 -07001150 /* requested DPMS state */
1151 int dpms;
1152
Daniel Vetter4490d4c2015-12-04 09:45:45 +01001153 const struct drm_connector_helper_funcs *helper_private;
Dave Airlief453ba02008-11-07 14:05:41 -08001154
Dave Airlied50ba252009-09-23 14:44:08 +10001155 /* forced on connector */
Chris Wilsoneaf99c72014-08-06 10:08:32 +02001156 struct drm_cmdline_mode cmdline_mode;
Dave Airlied50ba252009-09-23 14:44:08 +10001157 enum drm_connector_force force;
Thomas Wood4cf2b282014-06-18 17:52:33 +01001158 bool override_edid;
Dave Airlief453ba02008-11-07 14:05:41 -08001159 uint32_t encoder_ids[DRM_CONNECTOR_MAX_ENCODER];
Dave Airlief453ba02008-11-07 14:05:41 -08001160 struct drm_encoder *encoder; /* currently active encoder */
Dave Airlie4a9a8b72011-06-14 06:13:55 +00001161
Wu Fengguang76adaa342011-09-05 14:23:20 +08001162 /* EDID bits */
1163 uint8_t eld[MAX_ELD_BYTES];
1164 bool dvi_dual;
1165 int max_tmds_clock; /* in MHz */
1166 bool latency_present[2];
1167 int video_latency[2]; /* [0]: progressive, [1]: interlaced */
1168 int audio_latency[2];
Dave Airlie4a9a8b72011-06-14 06:13:55 +00001169 int null_edid_counter; /* needed to workaround some HW bugs where we get all 0s */
Jerome Glisse0b2443e2012-08-09 11:25:51 -04001170 unsigned bad_edid_counter;
Thomas Wood30f65702014-06-18 17:52:32 +01001171
Todd Previte6ba2bd32015-04-21 11:09:41 -07001172 /* Flag for raw EDID header corruption - used in Displayport
1173 * compliance testing - * Displayport Link CTS Core 1.2 rev1.1 4.2.2.6
1174 */
1175 bool edid_corrupt;
1176
Thomas Wood30f65702014-06-18 17:52:32 +01001177 struct dentry *debugfs_entry;
Daniel Vetter144ecb92014-10-27 20:28:44 +01001178
1179 struct drm_connector_state *state;
Dave Airlie40d9b042014-10-20 16:29:33 +10001180
1181 /* DisplayID bits */
1182 bool has_tile;
1183 struct drm_tile_group *tile_group;
1184 bool tile_is_single_monitor;
1185
1186 uint8_t num_h_tile, num_v_tile;
1187 uint8_t tile_h_loc, tile_v_loc;
1188 uint16_t tile_h_size, tile_v_size;
Dave Airlief453ba02008-11-07 14:05:41 -08001189};
1190
1191/**
Daniel Vetter144ecb92014-10-27 20:28:44 +01001192 * struct drm_plane_state - mutable plane state
Daniel Vetter07cc0ef2014-11-27 15:49:39 +01001193 * @plane: backpointer to the plane
Daniel Vetter144ecb92014-10-27 20:28:44 +01001194 * @crtc: currently bound CRTC, NULL if disabled
Daniel Vettercc4ceb42014-07-25 21:30:38 +02001195 * @fb: currently bound framebuffer
Daniel Vettere2330f02014-10-29 11:34:56 +01001196 * @fence: optional fence to wait for before scanning out @fb
Daniel Vetter144ecb92014-10-27 20:28:44 +01001197 * @crtc_x: left position of visible portion of plane on crtc
1198 * @crtc_y: upper position of visible portion of plane on crtc
1199 * @crtc_w: width of visible portion of plane on crtc
1200 * @crtc_h: height of visible portion of plane on crtc
1201 * @src_x: left position of visible portion of plane within
1202 * plane (in 16.16)
1203 * @src_y: upper position of visible portion of plane within
1204 * plane (in 16.16)
1205 * @src_w: width of visible portion of plane (in 16.16)
1206 * @src_h: height of visible portion of plane (in 16.16)
1207 * @state: backpointer to global drm_atomic_state
1208 */
1209struct drm_plane_state {
Daniel Vetter07cc0ef2014-11-27 15:49:39 +01001210 struct drm_plane *plane;
1211
Rob Clark6ddd3882014-11-21 15:28:31 -05001212 struct drm_crtc *crtc; /* do not write directly, use drm_atomic_set_crtc_for_plane() */
1213 struct drm_framebuffer *fb; /* do not write directly, use drm_atomic_set_fb_for_plane() */
Daniel Vettere2330f02014-10-29 11:34:56 +01001214 struct fence *fence;
Daniel Vetter144ecb92014-10-27 20:28:44 +01001215
1216 /* Signed dest location allows it to be partially off screen */
1217 int32_t crtc_x, crtc_y;
1218 uint32_t crtc_w, crtc_h;
1219
1220 /* Source values are 16.16 fixed point */
1221 uint32_t src_x, src_y;
1222 uint32_t src_h, src_w;
1223
Matt Roper1da30622015-01-21 16:35:40 -08001224 /* Plane rotation */
1225 unsigned int rotation;
1226
Daniel Vetter144ecb92014-10-27 20:28:44 +01001227 struct drm_atomic_state *state;
1228};
1229
1230
1231/**
Daniel Vetter3bf04012014-10-27 16:54:27 +01001232 * struct drm_plane_funcs - driver plane control functions
Jesse Barnes8cf5c912011-11-14 14:51:27 -08001233 */
1234struct drm_plane_funcs {
Daniel Vetter88548632015-12-04 09:45:48 +01001235 /**
1236 * @update_plane:
1237 *
1238 * This is the legacy entry point to enable and configure the plane for
1239 * the given CRTC and framebuffer. It is never called to disable the
1240 * plane, i.e. the passed-in crtc and fb paramters are never NULL.
1241 *
1242 * The source rectangle in frame buffer memory coordinates is given by
1243 * the src_x, src_y, src_w and src_h parameters (as 16.16 fixed point
1244 * values). Devices that don't support subpixel plane coordinates can
1245 * ignore the fractional part.
1246 *
1247 * The destination rectangle in CRTC coordinates is given by the
1248 * crtc_x, crtc_y, crtc_w and crtc_h parameters (as integer values).
1249 * Devices scale the source rectangle to the destination rectangle. If
1250 * scaling is not supported, and the source rectangle size doesn't match
1251 * the destination rectangle size, the driver must return a
1252 * -<errorname>EINVAL</errorname> error.
1253 *
1254 * Drivers implementing atomic modeset should use
1255 * drm_atomic_helper_update_plane() to implement this hook.
1256 *
1257 * RETURNS:
1258 *
1259 * 0 on success or a negative error code on failure.
1260 */
Jesse Barnes8cf5c912011-11-14 14:51:27 -08001261 int (*update_plane)(struct drm_plane *plane,
1262 struct drm_crtc *crtc, struct drm_framebuffer *fb,
1263 int crtc_x, int crtc_y,
1264 unsigned int crtc_w, unsigned int crtc_h,
1265 uint32_t src_x, uint32_t src_y,
1266 uint32_t src_w, uint32_t src_h);
Daniel Vetter88548632015-12-04 09:45:48 +01001267
1268 /**
1269 * @disable_plane:
1270 *
1271 * This is the legacy entry point to disable the plane. The DRM core
1272 * calls this method in response to a DRM_IOCTL_MODE_SETPLANE ioctl call
1273 * with the frame buffer ID set to 0. Disabled planes must not be
1274 * processed by the CRTC.
1275 *
1276 * Drivers implementing atomic modeset should use
1277 * drm_atomic_helper_disable_plane() to implement this hook.
1278 *
1279 * RETURNS:
1280 *
1281 * 0 on success or a negative error code on failure.
1282 */
Jesse Barnes8cf5c912011-11-14 14:51:27 -08001283 int (*disable_plane)(struct drm_plane *plane);
Daniel Vetter88548632015-12-04 09:45:48 +01001284
1285 /**
1286 * @destroy:
1287 *
1288 * Clean up plane resources. This is only called at driver unload time
1289 * through drm_mode_config_cleanup() since a plane cannot be hotplugged
1290 * in DRM.
1291 */
Jesse Barnes8cf5c912011-11-14 14:51:27 -08001292 void (*destroy)(struct drm_plane *plane);
Daniel Vetter88548632015-12-04 09:45:48 +01001293
1294 /**
1295 * @reset:
1296 *
1297 * Reset plane hardware and software state to off. This function isn't
1298 * called by the core directly, only through drm_mode_config_reset().
1299 * It's not a helper hook only for historical reasons.
1300 *
1301 * Atomic drivers can use drm_atomic_helper_plane_reset() to reset
1302 * atomic state using this hook.
1303 */
Daniel Vetter2a0d7cf2014-07-29 15:32:37 +02001304 void (*reset)(struct drm_plane *plane);
Rob Clark4d939142012-05-17 02:23:27 -06001305
Daniel Vetter88548632015-12-04 09:45:48 +01001306 /**
1307 * @set_property:
1308 *
1309 * This is the legacy entry point to update a property attached to the
1310 * plane.
1311 *
1312 * Drivers implementing atomic modeset should use
1313 * drm_atomic_helper_plane_set_property() to implement this hook.
1314 *
1315 * This callback is optional if the driver does not support any legacy
1316 * driver-private properties.
1317 *
1318 * RETURNS:
1319 *
1320 * 0 on success or a negative error code on failure.
1321 */
Rob Clark4d939142012-05-17 02:23:27 -06001322 int (*set_property)(struct drm_plane *plane,
1323 struct drm_property *property, uint64_t val);
Daniel Vetter144ecb92014-10-27 20:28:44 +01001324
Daniel Vetter88548632015-12-04 09:45:48 +01001325 /**
1326 * @atomic_duplicate_state:
1327 *
1328 * Duplicate the current atomic state for this plane and return it.
1329 * The core and helpers gurantee that any atomic state duplicated with
1330 * this hook and still owned by the caller (i.e. not transferred to the
1331 * driver by calling ->atomic_commit() from struct
1332 * &drm_mode_config_funcs) will be cleaned up by calling the
1333 * @atomic_destroy_state hook in this structure.
1334 *
1335 * Atomic drivers which don't subclass struct &drm_plane_state should use
1336 * drm_atomic_helper_plane_duplicate_state(). Drivers that subclass the
1337 * state structure to extend it with driver-private state should use
1338 * __drm_atomic_helper_plane_duplicate_state() to make sure shared state is
1339 * duplicated in a consistent fashion across drivers.
1340 *
1341 * It is an error to call this hook before plane->state has been
1342 * initialized correctly.
1343 *
1344 * NOTE:
1345 *
1346 * If the duplicate state references refcounted resources this hook must
1347 * acquire a reference for each of them. The driver must release these
1348 * references again in @atomic_destroy_state.
1349 *
1350 * RETURNS:
1351 *
1352 * Duplicated atomic state or NULL when the allocation failed.
1353 */
Daniel Vetter144ecb92014-10-27 20:28:44 +01001354 struct drm_plane_state *(*atomic_duplicate_state)(struct drm_plane *plane);
Daniel Vetter88548632015-12-04 09:45:48 +01001355
1356 /**
1357 * @atomic_destroy_state:
1358 *
1359 * Destroy a state duplicated with @atomic_duplicate_state and release
1360 * or unreference all resources it references
1361 */
Daniel Vetter144ecb92014-10-27 20:28:44 +01001362 void (*atomic_destroy_state)(struct drm_plane *plane,
Daniel Vettercc4ceb42014-07-25 21:30:38 +02001363 struct drm_plane_state *state);
Daniel Vetter88548632015-12-04 09:45:48 +01001364
1365 /**
1366 * @atomic_set_property:
1367 *
1368 * Decode a driver-private property value and store the decoded value
1369 * into the passed-in state structure. Since the atomic core decodes all
1370 * standardized properties (even for extensions beyond the core set of
1371 * properties which might not be implemented by all drivers) this
1372 * requires drivers to subclass the state structure.
1373 *
1374 * Such driver-private properties should really only be implemented for
1375 * truly hardware/vendor specific state. Instead it is preferred to
1376 * standardize atomic extension and decode the properties used to expose
1377 * such an extension in the core.
1378 *
1379 * Do not call this function directly, use
1380 * drm_atomic_plane_set_property() instead.
1381 *
1382 * This callback is optional if the driver does not support any
1383 * driver-private atomic properties.
1384 *
1385 * NOTE:
1386 *
1387 * This function is called in the state assembly phase of atomic
1388 * modesets, which can be aborted for any reason (including on
1389 * userspace's request to just check whether a configuration would be
1390 * possible). Drivers MUST NOT touch any persistent state (hardware or
1391 * software) or data structures except the passed in @state parameter.
1392 *
1393 * Also since userspace controls in which order properties are set this
1394 * function must not do any input validation (since the state update is
1395 * incomplete and hence likely inconsistent). Instead any such input
1396 * validation must be done in the various atomic_check callbacks.
1397 *
1398 * RETURNS:
1399 *
1400 * 0 if the property has been found, -EINVAL if the property isn't
1401 * implemented by the driver (which shouldn't ever happen, the core only
1402 * asks for properties attached to this plane). No other validation is
1403 * allowed by the driver. The core already checks that the property
1404 * value is within the range (integer, valid enum value, ...) the driver
1405 * set when registering the property.
1406 */
Daniel Vetter144ecb92014-10-27 20:28:44 +01001407 int (*atomic_set_property)(struct drm_plane *plane,
1408 struct drm_plane_state *state,
1409 struct drm_property *property,
1410 uint64_t val);
Daniel Vetter88548632015-12-04 09:45:48 +01001411
1412 /**
1413 * @atomic_get_property:
1414 *
1415 * Reads out the decoded driver-private property. This is used to
1416 * implement the GETPLANE ioctl.
1417 *
1418 * Do not call this function directly, use
1419 * drm_atomic_plane_get_property() instead.
1420 *
1421 * This callback is optional if the driver does not support any
1422 * driver-private atomic properties.
1423 *
1424 * RETURNS:
1425 *
1426 * 0 on success, -EINVAL if the property isn't implemented by the
1427 * driver (which should never happen, the core only asks for
1428 * properties attached to this plane).
1429 */
Rob Clarkac9c9252014-12-18 16:01:47 -05001430 int (*atomic_get_property)(struct drm_plane *plane,
1431 const struct drm_plane_state *state,
1432 struct drm_property *property,
1433 uint64_t *val);
Jesse Barnes8cf5c912011-11-14 14:51:27 -08001434};
1435
Matt Ropere27dde32014-04-01 15:22:30 -07001436enum drm_plane_type {
1437 DRM_PLANE_TYPE_OVERLAY,
1438 DRM_PLANE_TYPE_PRIMARY,
1439 DRM_PLANE_TYPE_CURSOR,
1440};
1441
Daniel Vetter88548632015-12-04 09:45:48 +01001442
Jesse Barnes8cf5c912011-11-14 14:51:27 -08001443/**
Daniel Vetter3bf04012014-10-27 16:54:27 +01001444 * struct drm_plane - central DRM plane control structure
Jesse Barnes8cf5c912011-11-14 14:51:27 -08001445 * @dev: DRM device this plane belongs to
1446 * @head: for list management
1447 * @base: base mode object
1448 * @possible_crtcs: pipes this plane can be bound to
1449 * @format_types: array of formats supported by this plane
1450 * @format_count: number of formats supported
Laurent Pinchart7eb5f302015-03-09 10:41:07 +02001451 * @format_default: driver hasn't supplied supported formats for the plane
Jesse Barnes8cf5c912011-11-14 14:51:27 -08001452 * @crtc: currently bound CRTC
1453 * @fb: currently bound fb
Daniel Vetter2c0c33d2014-10-27 20:19:38 +01001454 * @old_fb: Temporary tracking of the old fb while a modeset is ongoing. Used by
1455 * drm_mode_set_config_internal() to implement correct refcounting.
Jesse Barnes8cf5c912011-11-14 14:51:27 -08001456 * @funcs: helper functions
Rob Clark4d939142012-05-17 02:23:27 -06001457 * @properties: property tracking for this plane
Matt Ropere27dde32014-04-01 15:22:30 -07001458 * @type: type of plane (overlay, primary, cursor)
Daniel Vetter144ecb92014-10-27 20:28:44 +01001459 * @state: current atomic state for this plane
Jesse Barnes8cf5c912011-11-14 14:51:27 -08001460 */
1461struct drm_plane {
1462 struct drm_device *dev;
1463 struct list_head head;
1464
Daniel Vetter4d02e2d2014-11-11 10:12:00 +01001465 struct drm_modeset_lock mutex;
1466
Jesse Barnes8cf5c912011-11-14 14:51:27 -08001467 struct drm_mode_object base;
1468
1469 uint32_t possible_crtcs;
1470 uint32_t *format_types;
Thierry Reding45e37432015-08-12 16:54:28 +02001471 unsigned int format_count;
Laurent Pinchart7eb5f302015-03-09 10:41:07 +02001472 bool format_default;
Jesse Barnes8cf5c912011-11-14 14:51:27 -08001473
1474 struct drm_crtc *crtc;
1475 struct drm_framebuffer *fb;
1476
Daniel Vetter3d30a592014-07-27 13:42:42 +02001477 struct drm_framebuffer *old_fb;
1478
Jesse Barnes8cf5c912011-11-14 14:51:27 -08001479 const struct drm_plane_funcs *funcs;
Rob Clark4d939142012-05-17 02:23:27 -06001480
1481 struct drm_object_properties properties;
Matt Ropere27dde32014-04-01 15:22:30 -07001482
1483 enum drm_plane_type type;
Daniel Vetter144ecb92014-10-27 20:28:44 +01001484
Daniel Vetter4490d4c2015-12-04 09:45:45 +01001485 const struct drm_plane_helper_funcs *helper_private;
Daniel Vetterc2fcd272014-11-05 00:14:14 +01001486
Daniel Vetter144ecb92014-10-27 20:28:44 +01001487 struct drm_plane_state *state;
Jesse Barnes8cf5c912011-11-14 14:51:27 -08001488};
1489
1490/**
Daniel Vetter3bf04012014-10-27 16:54:27 +01001491 * struct drm_bridge_funcs - drm_bridge control functions
Ajay Kumar3d3f8b12015-01-20 22:08:44 +05301492 * @attach: Called during drm_bridge_attach
Sean Paul3b336ec2013-08-14 16:47:37 -04001493 */
1494struct drm_bridge_funcs {
Ajay Kumar3d3f8b12015-01-20 22:08:44 +05301495 int (*attach)(struct drm_bridge *bridge);
Daniel Vetterda024fe2015-12-04 09:45:47 +01001496
1497 /**
1498 * @mode_fixup:
1499 *
1500 * This callback is used to validate and adjust a mode. The paramater
1501 * mode is the display mode that should be fed to the next element in
1502 * the display chain, either the final &drm_connector or the next
1503 * &drm_bridge. The parameter adjusted_mode is the input mode the bridge
1504 * requires. It can be modified by this callback and does not need to
1505 * match mode.
1506 *
1507 * This is the only hook that allows a bridge to reject a modeset. If
1508 * this function passes all other callbacks must succeed for this
1509 * configuration.
1510 *
1511 * NOTE:
1512 *
1513 * This function is called in the check phase of atomic modesets, which
1514 * can be aborted for any reason (including on userspace's request to
1515 * just check whether a configuration would be possible). Drivers MUST
1516 * NOT touch any persistent state (hardware or software) or data
Daniel Vetter88548632015-12-04 09:45:48 +01001517 * structures except the passed in @state parameter.
Daniel Vetterda024fe2015-12-04 09:45:47 +01001518 *
1519 * RETURNS:
1520 *
1521 * True if an acceptable configuration is possible, false if the modeset
1522 * operation should be rejected.
1523 */
Sean Paul3b336ec2013-08-14 16:47:37 -04001524 bool (*mode_fixup)(struct drm_bridge *bridge,
1525 const struct drm_display_mode *mode,
1526 struct drm_display_mode *adjusted_mode);
Daniel Vetterda024fe2015-12-04 09:45:47 +01001527 /**
1528 * @disable:
1529 *
1530 * This callback should disable the bridge. It is called right before
1531 * the preceding element in the display pipe is disabled. If the
1532 * preceding element is a bridge this means it's called before that
1533 * bridge's ->disable() function. If the preceding element is a
1534 * &drm_encoder it's called right before the encoder's ->disable(),
1535 * ->prepare() or ->dpms() hook from struct &drm_encoder_helper_funcs.
1536 *
1537 * The bridge can assume that the display pipe (i.e. clocks and timing
1538 * signals) feeding it is still running when this callback is called.
1539 */
Sean Paul3b336ec2013-08-14 16:47:37 -04001540 void (*disable)(struct drm_bridge *bridge);
Daniel Vetterda024fe2015-12-04 09:45:47 +01001541
1542 /**
1543 * @post_disable:
1544 *
1545 * This callback should disable the bridge. It is called right after
1546 * the preceding element in the display pipe is disabled. If the
1547 * preceding element is a bridge this means it's called after that
1548 * bridge's ->post_disable() function. If the preceding element is a
1549 * &drm_encoder it's called right after the encoder's ->disable(),
1550 * ->prepare() or ->dpms() hook from struct &drm_encoder_helper_funcs.
1551 *
1552 * The bridge must assume that the display pipe (i.e. clocks and timing
1553 * singals) feeding it is no longer running when this callback is
1554 * called.
1555 */
Sean Paul3b336ec2013-08-14 16:47:37 -04001556 void (*post_disable)(struct drm_bridge *bridge);
Daniel Vetterda024fe2015-12-04 09:45:47 +01001557
1558 /**
1559 * @mode_set:
1560 *
1561 * This callback should set the given mode on the bridge. It is called
1562 * after the ->mode_set() callback for the preceding element in the
1563 * display pipeline has been called already. The display pipe (i.e.
1564 * clocks and timing signals) is off when this function is called.
1565 */
Sean Paul3b336ec2013-08-14 16:47:37 -04001566 void (*mode_set)(struct drm_bridge *bridge,
1567 struct drm_display_mode *mode,
1568 struct drm_display_mode *adjusted_mode);
Daniel Vetterda024fe2015-12-04 09:45:47 +01001569 /**
1570 * @pre_enable:
1571 *
1572 * This callback should enable the bridge. It is called right before
1573 * the preceding element in the display pipe is enabled. If the
1574 * preceding element is a bridge this means it's called before that
1575 * bridge's ->pre_enable() function. If the preceding element is a
1576 * &drm_encoder it's called right before the encoder's ->enable(),
1577 * ->commit() or ->dpms() hook from struct &drm_encoder_helper_funcs.
1578 *
1579 * The display pipe (i.e. clocks and timing signals) feeding this bridge
1580 * will not yet be running when this callback is called. The bridge must
1581 * not enable the display link feeding the next bridge in the chain (if
1582 * there is one) when this callback is called.
1583 */
Sean Paul3b336ec2013-08-14 16:47:37 -04001584 void (*pre_enable)(struct drm_bridge *bridge);
Daniel Vetterda024fe2015-12-04 09:45:47 +01001585
1586 /**
1587 * @enable:
1588 *
1589 * This callback should enable the bridge. It is called right after
1590 * the preceding element in the display pipe is enabled. If the
1591 * preceding element is a bridge this means it's called after that
1592 * bridge's ->enable() function. If the preceding element is a
1593 * &drm_encoder it's called right after the encoder's ->enable(),
1594 * ->commit() or ->dpms() hook from struct &drm_encoder_helper_funcs.
1595 *
1596 * The bridge can assume that the display pipe (i.e. clocks and timing
1597 * signals) feeding it is running when this callback is called. This
1598 * callback must enable the display link feeding the next bridge in the
1599 * chain if there is one.
1600 */
Sean Paul3b336ec2013-08-14 16:47:37 -04001601 void (*enable)(struct drm_bridge *bridge);
Sean Paul3b336ec2013-08-14 16:47:37 -04001602};
1603
1604/**
Daniel Vetter3bf04012014-10-27 16:54:27 +01001605 * struct drm_bridge - central DRM bridge control structure
Sean Paul3b336ec2013-08-14 16:47:37 -04001606 * @dev: DRM device this bridge belongs to
Archit Taneja862e6862015-05-21 11:03:16 +05301607 * @encoder: encoder to which this bridge is connected
1608 * @next: the next bridge in the encoder chain
Ajay Kumar3d3f8b12015-01-20 22:08:44 +05301609 * @of_node: device node pointer to the bridge
1610 * @list: to keep track of all added bridges
Sean Paul3b336ec2013-08-14 16:47:37 -04001611 * @funcs: control functions
1612 * @driver_private: pointer to the bridge driver's internal context
1613 */
1614struct drm_bridge {
1615 struct drm_device *dev;
Ajay Kumar3d3f8b12015-01-20 22:08:44 +05301616 struct drm_encoder *encoder;
Archit Taneja862e6862015-05-21 11:03:16 +05301617 struct drm_bridge *next;
Ajay Kumar3d3f8b12015-01-20 22:08:44 +05301618#ifdef CONFIG_OF
1619 struct device_node *of_node;
1620#endif
1621 struct list_head list;
Sean Paul3b336ec2013-08-14 16:47:37 -04001622
1623 const struct drm_bridge_funcs *funcs;
1624 void *driver_private;
1625};
1626
1627/**
Rob Clark08855fa2015-03-11 10:23:09 -04001628 * struct drm_atomic_state - the global state object for atomic updates
Daniel Vettercc4ceb42014-07-25 21:30:38 +02001629 * @dev: parent DRM device
Rob Clarkd34f20d2014-12-18 16:01:56 -05001630 * @allow_modeset: allow full modeset
Daniel Vetterf02ad902015-01-22 16:36:23 +01001631 * @legacy_cursor_update: hint to enforce legacy cursor ioctl semantics
Daniel Vettercc4ceb42014-07-25 21:30:38 +02001632 * @planes: pointer to array of plane pointers
1633 * @plane_states: pointer to array of plane states pointers
1634 * @crtcs: pointer to array of CRTC pointers
1635 * @crtc_states: pointer to array of CRTC states pointers
Daniel Vetterf52b69f12014-11-19 18:38:08 +01001636 * @num_connector: size of the @connectors and @connector_states arrays
Daniel Vettercc4ceb42014-07-25 21:30:38 +02001637 * @connectors: pointer to array of connector pointers
1638 * @connector_states: pointer to array of connector states pointers
1639 * @acquire_ctx: acquire context for this atomic modeset state update
1640 */
1641struct drm_atomic_state {
1642 struct drm_device *dev;
Rob Clarkd34f20d2014-12-18 16:01:56 -05001643 bool allow_modeset : 1;
Daniel Vetterf02ad902015-01-22 16:36:23 +01001644 bool legacy_cursor_update : 1;
Daniel Vettercc4ceb42014-07-25 21:30:38 +02001645 struct drm_plane **planes;
1646 struct drm_plane_state **plane_states;
1647 struct drm_crtc **crtcs;
1648 struct drm_crtc_state **crtc_states;
Daniel Vetterf52b69f12014-11-19 18:38:08 +01001649 int num_connector;
Daniel Vettercc4ceb42014-07-25 21:30:38 +02001650 struct drm_connector **connectors;
1651 struct drm_connector_state **connector_states;
1652
1653 struct drm_modeset_acquire_ctx *acquire_ctx;
1654};
1655
1656
1657/**
Daniel Vetter3bf04012014-10-27 16:54:27 +01001658 * struct drm_mode_set - new values for a CRTC config change
Jesse Barnesef273512011-11-07 12:03:19 -08001659 * @fb: framebuffer to use for new config
1660 * @crtc: CRTC whose configuration we're about to change
1661 * @mode: mode timings to use
1662 * @x: position of this CRTC relative to @fb
1663 * @y: position of this CRTC relative to @fb
1664 * @connectors: array of connectors to drive with this CRTC if possible
1665 * @num_connectors: size of @connectors array
Dave Airlief453ba02008-11-07 14:05:41 -08001666 *
1667 * Represents a single crtc the connectors that it drives with what mode
1668 * and from which framebuffer it scans out from.
1669 *
1670 * This is used to set modes.
1671 */
1672struct drm_mode_set {
Dave Airlief453ba02008-11-07 14:05:41 -08001673 struct drm_framebuffer *fb;
1674 struct drm_crtc *crtc;
1675 struct drm_display_mode *mode;
1676
1677 uint32_t x;
1678 uint32_t y;
1679
1680 struct drm_connector **connectors;
1681 size_t num_connectors;
1682};
1683
1684/**
Jesse Barnes550cebc2011-11-07 12:03:20 -08001685 * struct drm_mode_config_funcs - basic driver provided mode setting functions
1686 * @fb_create: create a new framebuffer object
1687 * @output_poll_changed: function to handle output configuration changes
John Hunter2b1193d2015-04-14 17:07:22 +08001688 * @atomic_check: check whether a given atomic state update is possible
Daniel Vettercc4ceb42014-07-25 21:30:38 +02001689 * @atomic_commit: commit an atomic state update previously verified with
1690 * atomic_check()
Maarten Lankhorst036ef572015-05-18 10:06:40 +02001691 * @atomic_state_alloc: allocate a new atomic state
1692 * @atomic_state_clear: clear the atomic state
1693 * @atomic_state_free: free the atomic state
Jesse Barnes550cebc2011-11-07 12:03:20 -08001694 *
1695 * Some global (i.e. not per-CRTC, connector, etc) mode setting functions that
1696 * involve drivers.
Dave Airlief453ba02008-11-07 14:05:41 -08001697 */
1698struct drm_mode_config_funcs {
Jesse Barnes550cebc2011-11-07 12:03:20 -08001699 struct drm_framebuffer *(*fb_create)(struct drm_device *dev,
1700 struct drm_file *file_priv,
Ville Syrjälä1eb834512015-11-11 19:11:29 +02001701 const struct drm_mode_fb_cmd2 *mode_cmd);
Dave Airlieeb1f8e4f32010-05-07 06:42:51 +00001702 void (*output_poll_changed)(struct drm_device *dev);
Daniel Vettercc4ceb42014-07-25 21:30:38 +02001703
1704 int (*atomic_check)(struct drm_device *dev,
1705 struct drm_atomic_state *a);
1706 int (*atomic_commit)(struct drm_device *dev,
1707 struct drm_atomic_state *a,
1708 bool async);
Maarten Lankhorst036ef572015-05-18 10:06:40 +02001709 struct drm_atomic_state *(*atomic_state_alloc)(struct drm_device *dev);
1710 void (*atomic_state_clear)(struct drm_atomic_state *state);
1711 void (*atomic_state_free)(struct drm_atomic_state *state);
Dave Airlief453ba02008-11-07 14:05:41 -08001712};
1713
Jesse Barnesc1aaca22011-11-07 12:03:21 -08001714/**
Daniel Vetter2c0c33d2014-10-27 20:19:38 +01001715 * struct drm_mode_config - Mode configuration control structure
Jesse Barnesa62c93d2011-11-07 12:03:22 -08001716 * @mutex: mutex protecting KMS related lists and structures
Daniel Vetter2c0c33d2014-10-27 20:19:38 +01001717 * @connection_mutex: ww mutex protecting connector state and routing
1718 * @acquire_ctx: global implicit acquire context used by atomic drivers for
1719 * legacy ioctls
Jesse Barnesa62c93d2011-11-07 12:03:22 -08001720 * @idr_mutex: mutex for KMS ID allocation and management
1721 * @crtc_idr: main KMS ID tracking object
Daniel Vetter2c0c33d2014-10-27 20:19:38 +01001722 * @fb_lock: mutex to protect fb state and lists
Jesse Barnesa62c93d2011-11-07 12:03:22 -08001723 * @num_fb: number of fbs available
1724 * @fb_list: list of framebuffers available
1725 * @num_connector: number of connectors on this device
1726 * @connector_list: list of connector objects
1727 * @num_encoder: number of encoders on this device
1728 * @encoder_list: list of encoder objects
Daniel Vetter2c0c33d2014-10-27 20:19:38 +01001729 * @num_overlay_plane: number of overlay planes on this device
1730 * @num_total_plane: number of universal (i.e. with primary/curso) planes on this device
1731 * @plane_list: list of plane objects
Jesse Barnesa62c93d2011-11-07 12:03:22 -08001732 * @num_crtc: number of CRTCs on this device
1733 * @crtc_list: list of CRTC objects
Daniel Vetter2c0c33d2014-10-27 20:19:38 +01001734 * @property_list: list of property objects
Jesse Barnesa62c93d2011-11-07 12:03:22 -08001735 * @min_width: minimum pixel width on this device
1736 * @min_height: minimum pixel height on this device
1737 * @max_width: maximum pixel width on this device
1738 * @max_height: maximum pixel height on this device
1739 * @funcs: core driver provided mode setting functions
1740 * @fb_base: base address of the framebuffer
Daniel Vetter2c0c33d2014-10-27 20:19:38 +01001741 * @poll_enabled: track polling support for this device
1742 * @poll_running: track polling status for this device
Jesse Barnesa62c93d2011-11-07 12:03:22 -08001743 * @output_poll_work: delayed work for polling in process context
Daniel Vetter2c0c33d2014-10-27 20:19:38 +01001744 * @property_blob_list: list of all the blob property objects
Daniel Stone8fb6e7a2015-04-20 19:22:54 +01001745 * @blob_lock: mutex for blob property allocation and management
Jesse Barnesa62c93d2011-11-07 12:03:22 -08001746 * @*_property: core property tracking
Daniel Vetter2c0c33d2014-10-27 20:19:38 +01001747 * @preferred_depth: preferred RBG pixel depth, used by fb helpers
1748 * @prefer_shadow: hint to userspace to prefer shadow-fb rendering
1749 * @async_page_flip: does this device support async flips on the primary plane?
1750 * @cursor_width: hint to userspace for max cursor width
1751 * @cursor_height: hint to userspace for max cursor height
Dave Airlief453ba02008-11-07 14:05:41 -08001752 *
Jesse Barnesa62c93d2011-11-07 12:03:22 -08001753 * Core mode resource tracking structure. All CRTC, encoders, and connectors
1754 * enumerated by the driver are added here, as are global properties. Some
1755 * global restrictions are also here, e.g. dimension restrictions.
Dave Airlief453ba02008-11-07 14:05:41 -08001756 */
1757struct drm_mode_config {
Jesse Barnesad2563c2009-01-19 17:21:45 +10001758 struct mutex mutex; /* protects configuration (mode lists etc.) */
Rob Clark51fd3712013-11-19 12:10:12 -05001759 struct drm_modeset_lock connection_mutex; /* protects connector->encoder and encoder->crtc links */
1760 struct drm_modeset_acquire_ctx *acquire_ctx; /* for legacy _lock_all() / _unlock_all() */
Jesse Barnesad2563c2009-01-19 17:21:45 +10001761 struct mutex idr_mutex; /* for IDR management */
Dave Airlief453ba02008-11-07 14:05:41 -08001762 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 +10001763 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 -08001764 /* this is limited to one for now */
Daniel Vetter4b096ac2012-12-10 21:19:18 +01001765
Daniel Vetter2c0c33d2014-10-27 20:19:38 +01001766 struct mutex fb_lock; /* proctects global and per-file fb lists */
Dave Airlief453ba02008-11-07 14:05:41 -08001767 int num_fb;
1768 struct list_head fb_list;
Daniel Vetter4b096ac2012-12-10 21:19:18 +01001769
Dave Airlief453ba02008-11-07 14:05:41 -08001770 int num_connector;
1771 struct list_head connector_list;
1772 int num_encoder;
1773 struct list_head encoder_list;
Matt Ropere27dde32014-04-01 15:22:30 -07001774
1775 /*
1776 * Track # of overlay planes separately from # of total planes. By
1777 * default we only advertise overlay planes to userspace; if userspace
1778 * sets the "universal plane" capability bit, we'll go ahead and
1779 * expose all planes.
1780 */
1781 int num_overlay_plane;
1782 int num_total_plane;
Jesse Barnes8cf5c912011-11-14 14:51:27 -08001783 struct list_head plane_list;
Dave Airlief453ba02008-11-07 14:05:41 -08001784
1785 int num_crtc;
1786 struct list_head crtc_list;
1787
1788 struct list_head property_list;
1789
Dave Airlief453ba02008-11-07 14:05:41 -08001790 int min_width, min_height;
1791 int max_width, max_height;
Laurent Pincharte6ecefa2012-05-17 13:27:23 +02001792 const struct drm_mode_config_funcs *funcs;
Benjamin Herrenschmidtd883f7f2009-02-02 16:55:45 +11001793 resource_size_t fb_base;
Dave Airlief453ba02008-11-07 14:05:41 -08001794
Dave Airlieeb1f8e4f32010-05-07 06:42:51 +00001795 /* output poll support */
1796 bool poll_enabled;
Daniel Vetter905bc9f2012-10-23 18:23:36 +00001797 bool poll_running;
Daniel Vetter162b6a52015-01-21 08:45:21 +01001798 bool delayed_event;
Tejun Heo991ea752010-07-20 22:09:02 +02001799 struct delayed_work output_poll_work;
Dave Airlieeb1f8e4f32010-05-07 06:42:51 +00001800
Daniel Stone8fb6e7a2015-04-20 19:22:54 +01001801 struct mutex blob_lock;
1802
Dave Airlief453ba02008-11-07 14:05:41 -08001803 /* pointers to standard properties */
1804 struct list_head property_blob_list;
1805 struct drm_property *edid_property;
1806 struct drm_property *dpms_property;
Dave Airlie43aba7e2014-06-05 14:01:31 +10001807 struct drm_property *path_property;
Dave Airlie6f134d72014-10-20 16:30:50 +10001808 struct drm_property *tile_property;
Rob Clark9922ab52014-04-01 20:16:57 -04001809 struct drm_property *plane_type_property;
Sonika Jindal2a297cc2014-08-05 11:26:54 +05301810 struct drm_property *rotation_property;
Rob Clark6b4959f2014-12-18 16:01:53 -05001811 struct drm_property *prop_src_x;
1812 struct drm_property *prop_src_y;
1813 struct drm_property *prop_src_w;
1814 struct drm_property *prop_src_h;
1815 struct drm_property *prop_crtc_x;
1816 struct drm_property *prop_crtc_y;
1817 struct drm_property *prop_crtc_w;
1818 struct drm_property *prop_crtc_h;
1819 struct drm_property *prop_fb_id;
1820 struct drm_property *prop_crtc_id;
Daniel Vettereab3bbe2015-01-22 16:36:21 +01001821 struct drm_property *prop_active;
Daniel Stone955f3c32015-05-25 19:11:52 +01001822 struct drm_property *prop_mode_id;
Dave Airlief453ba02008-11-07 14:05:41 -08001823
1824 /* DVI-I properties */
1825 struct drm_property *dvi_i_subconnector_property;
1826 struct drm_property *dvi_i_select_subconnector_property;
1827
1828 /* TV properties */
1829 struct drm_property *tv_subconnector_property;
1830 struct drm_property *tv_select_subconnector_property;
1831 struct drm_property *tv_mode_property;
1832 struct drm_property *tv_left_margin_property;
1833 struct drm_property *tv_right_margin_property;
1834 struct drm_property *tv_top_margin_property;
1835 struct drm_property *tv_bottom_margin_property;
Francisco Jerezb6b79022009-08-02 04:19:20 +02001836 struct drm_property *tv_brightness_property;
1837 struct drm_property *tv_contrast_property;
1838 struct drm_property *tv_flicker_reduction_property;
Francisco Jereza75f0232009-08-12 02:30:10 +02001839 struct drm_property *tv_overscan_property;
1840 struct drm_property *tv_saturation_property;
1841 struct drm_property *tv_hue_property;
Dave Airlief453ba02008-11-07 14:05:41 -08001842
1843 /* Optional properties */
1844 struct drm_property *scaling_mode_property;
Vandana Kannanff587e42014-06-11 10:46:48 +05301845 struct drm_property *aspect_ratio_property;
Jakob Bornecrantz884840a2009-12-03 23:25:47 +00001846 struct drm_property *dirty_info_property;
Dave Airlie019d96c2011-09-29 16:20:42 +01001847
Dave Airlie5bb2bbf2014-11-10 10:18:15 +10001848 /* properties for virtual machine layout */
1849 struct drm_property *suggested_x_property;
1850 struct drm_property *suggested_y_property;
1851
Dave Airlie019d96c2011-09-29 16:20:42 +01001852 /* dumb ioctl parameters */
1853 uint32_t preferred_depth, prefer_shadow;
Keith Packard62f21042013-07-22 18:50:00 -07001854
1855 /* whether async page flip is supported or not */
1856 bool async_page_flip;
Alex Deucher8716ed42014-02-12 12:48:23 -05001857
Rob Clarke3eb3252015-02-05 14:41:52 +00001858 /* whether the driver supports fb modifiers */
1859 bool allow_fb_modifiers;
1860
Alex Deucher8716ed42014-02-12 12:48:23 -05001861 /* cursor size */
1862 uint32_t cursor_width, cursor_height;
Dave Airlief453ba02008-11-07 14:05:41 -08001863};
1864
Rob Clarkdd275952014-11-25 20:29:46 -05001865/**
1866 * drm_for_each_plane_mask - iterate over planes specified by bitmask
1867 * @plane: the loop cursor
1868 * @dev: the DRM device
1869 * @plane_mask: bitmask of plane indices
1870 *
1871 * Iterate over all planes specified by bitmask.
1872 */
1873#define drm_for_each_plane_mask(plane, dev, plane_mask) \
1874 list_for_each_entry((plane), &(dev)->mode_config.plane_list, head) \
Jani Nikula373701b2015-11-24 21:21:55 +02001875 for_each_if ((plane_mask) & (1 << drm_plane_index(plane)))
Rob Clarkdd275952014-11-25 20:29:46 -05001876
1877
Dave Airlief453ba02008-11-07 14:05:41 -08001878#define obj_to_crtc(x) container_of(x, struct drm_crtc, base)
1879#define obj_to_connector(x) container_of(x, struct drm_connector, base)
1880#define obj_to_encoder(x) container_of(x, struct drm_encoder, base)
1881#define obj_to_mode(x) container_of(x, struct drm_display_mode, base)
1882#define obj_to_fb(x) container_of(x, struct drm_framebuffer, base)
1883#define obj_to_property(x) container_of(x, struct drm_property, base)
1884#define obj_to_blob(x) container_of(x, struct drm_property_blob, base)
Jesse Barnes8cf5c912011-11-14 14:51:27 -08001885#define obj_to_plane(x) container_of(x, struct drm_plane, base)
Dave Airlief453ba02008-11-07 14:05:41 -08001886
Sascha Hauer4a67d392012-02-06 10:58:17 +01001887struct drm_prop_enum_list {
1888 int type;
1889 char *name;
1890};
Dave Airlief453ba02008-11-07 14:05:41 -08001891
Matt Ropere13161a2014-04-01 15:22:38 -07001892extern int drm_crtc_init_with_planes(struct drm_device *dev,
1893 struct drm_crtc *crtc,
1894 struct drm_plane *primary,
Matt Roperfc1d3e42014-06-10 08:28:11 -07001895 struct drm_plane *cursor,
Matt Ropere13161a2014-04-01 15:22:38 -07001896 const struct drm_crtc_funcs *funcs);
Dave Airlief453ba02008-11-07 14:05:41 -08001897extern void drm_crtc_cleanup(struct drm_crtc *crtc);
Russell Kingdb5f7a62014-01-02 21:27:33 +00001898extern unsigned int drm_crtc_index(struct drm_crtc *crtc);
1899
1900/**
1901 * drm_crtc_mask - find the mask of a registered CRTC
1902 * @crtc: CRTC to find mask for
1903 *
1904 * Given a registered CRTC, return the mask bit of that CRTC for an
1905 * encoder's possible_crtcs field.
1906 */
1907static inline uint32_t drm_crtc_mask(struct drm_crtc *crtc)
1908{
1909 return 1 << drm_crtc_index(crtc);
1910}
Dave Airlief453ba02008-11-07 14:05:41 -08001911
Ilia Mirkinb21e3af2013-08-07 22:34:48 -04001912extern void drm_connector_ida_init(void);
1913extern void drm_connector_ida_destroy(void);
Ville Syrjälä6bfc56a2012-03-13 12:35:48 +02001914extern int drm_connector_init(struct drm_device *dev,
1915 struct drm_connector *connector,
1916 const struct drm_connector_funcs *funcs,
1917 int connector_type);
Thomas Wood34ea3d32014-05-29 16:57:41 +01001918int drm_connector_register(struct drm_connector *connector);
1919void drm_connector_unregister(struct drm_connector *connector);
Dave Airlief453ba02008-11-07 14:05:41 -08001920
1921extern void drm_connector_cleanup(struct drm_connector *connector);
Daniel Vetter10f637b2014-07-29 13:47:11 +02001922extern unsigned int drm_connector_index(struct drm_connector *connector);
Dave Airliecbc7e222012-02-20 14:16:40 +00001923/* helper to unplug all connectors from sysfs for device */
1924extern void drm_connector_unplug_all(struct drm_device *dev);
Dave Airlief453ba02008-11-07 14:05:41 -08001925
Ajay Kumar3d3f8b12015-01-20 22:08:44 +05301926extern int drm_bridge_add(struct drm_bridge *bridge);
1927extern void drm_bridge_remove(struct drm_bridge *bridge);
1928extern struct drm_bridge *of_drm_find_bridge(struct device_node *np);
1929extern int drm_bridge_attach(struct drm_device *dev, struct drm_bridge *bridge);
Sean Paul3b336ec2013-08-14 16:47:37 -04001930
Archit Taneja862e6862015-05-21 11:03:16 +05301931bool drm_bridge_mode_fixup(struct drm_bridge *bridge,
1932 const struct drm_display_mode *mode,
1933 struct drm_display_mode *adjusted_mode);
1934void drm_bridge_disable(struct drm_bridge *bridge);
1935void drm_bridge_post_disable(struct drm_bridge *bridge);
1936void drm_bridge_mode_set(struct drm_bridge *bridge,
1937 struct drm_display_mode *mode,
1938 struct drm_display_mode *adjusted_mode);
1939void drm_bridge_pre_enable(struct drm_bridge *bridge);
1940void drm_bridge_enable(struct drm_bridge *bridge);
1941
Ville Syrjälä6bfc56a2012-03-13 12:35:48 +02001942extern int drm_encoder_init(struct drm_device *dev,
1943 struct drm_encoder *encoder,
1944 const struct drm_encoder_funcs *funcs,
1945 int encoder_type);
Dave Airlief453ba02008-11-07 14:05:41 -08001946
Thierry Reding3d887362014-01-13 14:33:20 +01001947/**
1948 * drm_encoder_crtc_ok - can a given crtc drive a given encoder?
1949 * @encoder: encoder to test
1950 * @crtc: crtc to test
1951 *
1952 * Return false if @encoder can't be driven by @crtc, true otherwise.
1953 */
1954static inline bool drm_encoder_crtc_ok(struct drm_encoder *encoder,
1955 struct drm_crtc *crtc)
1956{
1957 return !!(encoder->possible_crtcs & drm_crtc_mask(crtc));
1958}
1959
Matt Roperdc415ff2014-04-01 15:22:36 -07001960extern int drm_universal_plane_init(struct drm_device *dev,
1961 struct drm_plane *plane,
1962 unsigned long possible_crtcs,
1963 const struct drm_plane_funcs *funcs,
1964 const uint32_t *formats,
Thierry Reding45e37432015-08-12 16:54:28 +02001965 unsigned int format_count,
Matt Roperdc415ff2014-04-01 15:22:36 -07001966 enum drm_plane_type type);
Jesse Barnes8cf5c912011-11-14 14:51:27 -08001967extern int drm_plane_init(struct drm_device *dev,
1968 struct drm_plane *plane,
1969 unsigned long possible_crtcs,
1970 const struct drm_plane_funcs *funcs,
Thierry Reding45e37432015-08-12 16:54:28 +02001971 const uint32_t *formats, unsigned int format_count,
Matt Roperdc415ff2014-04-01 15:22:36 -07001972 bool is_primary);
Jesse Barnes8cf5c912011-11-14 14:51:27 -08001973extern void drm_plane_cleanup(struct drm_plane *plane);
Daniel Vetter10f637b2014-07-29 13:47:11 +02001974extern unsigned int drm_plane_index(struct drm_plane *plane);
Chandra Konduruf81338a2015-04-09 17:36:21 -07001975extern struct drm_plane * drm_plane_from_index(struct drm_device *dev, int idx);
Ville Syrjälä9125e612013-06-03 16:10:40 +03001976extern void drm_plane_force_disable(struct drm_plane *plane);
Laurent Pinchartead86102015-03-05 02:25:43 +02001977extern int drm_plane_check_pixel_format(const struct drm_plane *plane,
1978 u32 format);
Gustavo Padovanecb7e162014-12-01 15:40:09 -08001979extern void drm_crtc_get_hv_timing(const struct drm_display_mode *mode,
1980 int *hdisplay, int *vdisplay);
Matt Roperaf936292014-04-01 15:22:34 -07001981extern int drm_crtc_check_viewport(const struct drm_crtc *crtc,
1982 int x, int y,
1983 const struct drm_display_mode *mode,
1984 const struct drm_framebuffer *fb);
Jesse Barnes8cf5c912011-11-14 14:51:27 -08001985
Dave Airlief453ba02008-11-07 14:05:41 -08001986extern void drm_encoder_cleanup(struct drm_encoder *encoder);
1987
Ville Syrjäläd20d3172013-06-07 15:43:07 +00001988extern const char *drm_get_connector_status_name(enum drm_connector_status status);
Jesse Barnesac1bb362014-02-10 15:32:44 -08001989extern const char *drm_get_subpixel_order_name(enum subpixel_order order);
Ville Syrjäläd20d3172013-06-07 15:43:07 +00001990extern const char *drm_get_dpms_name(int val);
1991extern const char *drm_get_dvi_i_subconnector_name(int val);
1992extern const char *drm_get_dvi_i_select_name(int val);
1993extern const char *drm_get_tv_subconnector_name(int val);
1994extern const char *drm_get_tv_select_name(int val);
Kristian Høgsbergea39f832009-02-12 14:37:56 -05001995extern void drm_fb_release(struct drm_file *file_priv);
Daniel Stonee2f5d2e2015-05-22 13:34:51 +01001996extern void drm_property_destroy_user_blobs(struct drm_device *dev,
1997 struct drm_file *file_priv);
Adam Jacksonfbff4692012-09-18 10:58:47 -04001998extern bool drm_probe_ddc(struct i2c_adapter *adapter);
Dave Airlief453ba02008-11-07 14:05:41 -08001999extern struct edid *drm_get_edid(struct drm_connector *connector,
2000 struct i2c_adapter *adapter);
Jani Nikula51f8da52013-09-27 15:08:27 +03002001extern struct edid *drm_edid_duplicate(const struct edid *edid);
Dave Airlief453ba02008-11-07 14:05:41 -08002002extern int drm_add_edid_modes(struct drm_connector *connector, struct edid *edid);
Dave Airlief453ba02008-11-07 14:05:41 -08002003extern void drm_mode_config_init(struct drm_device *dev);
Chris Wilsoneb0335562011-01-24 15:11:08 +00002004extern void drm_mode_config_reset(struct drm_device *dev);
Dave Airlief453ba02008-11-07 14:05:41 -08002005extern void drm_mode_config_cleanup(struct drm_device *dev);
Dave Airlief453ba02008-11-07 14:05:41 -08002006
Dave Airlie43aba7e2014-06-05 14:01:31 +10002007extern int drm_mode_connector_set_path_property(struct drm_connector *connector,
Thierry Reding12e6cec2014-05-13 11:38:36 +02002008 const char *path);
Dave Airlie6f134d72014-10-20 16:30:50 +10002009int drm_mode_connector_set_tile_property(struct drm_connector *connector);
Dave Airlief453ba02008-11-07 14:05:41 -08002010extern int drm_mode_connector_update_edid_property(struct drm_connector *connector,
Thierry Reding12e6cec2014-05-13 11:38:36 +02002011 const struct edid *edid);
Rob Clark5ea22f22014-05-30 11:34:01 -04002012
Boris Brezillonb5571e92014-07-22 12:09:10 +02002013extern int drm_display_info_set_bus_formats(struct drm_display_info *info,
2014 const u32 *formats,
2015 unsigned int num_formats);
2016
Rob Clark5ea22f22014-05-30 11:34:01 -04002017static inline bool drm_property_type_is(struct drm_property *property,
2018 uint32_t type)
2019{
2020 /* instanceof for props.. handles extended type vs original types: */
2021 if (property->flags & DRM_MODE_PROP_EXTENDED_TYPE)
2022 return (property->flags & DRM_MODE_PROP_EXTENDED_TYPE) == type;
2023 return property->flags & type;
2024}
2025
2026static inline bool drm_property_type_valid(struct drm_property *property)
2027{
2028 if (property->flags & DRM_MODE_PROP_EXTENDED_TYPE)
2029 return !(property->flags & DRM_MODE_PROP_LEGACY_TYPE);
2030 return !!(property->flags & DRM_MODE_PROP_LEGACY_TYPE);
2031}
2032
Paulo Zanonic5431882012-05-15 18:09:02 -03002033extern int drm_object_property_set_value(struct drm_mode_object *obj,
2034 struct drm_property *property,
2035 uint64_t val);
2036extern int drm_object_property_get_value(struct drm_mode_object *obj,
2037 struct drm_property *property,
2038 uint64_t *value);
Dave Airlief453ba02008-11-07 14:05:41 -08002039extern int drm_framebuffer_init(struct drm_device *dev,
2040 struct drm_framebuffer *fb,
2041 const struct drm_framebuffer_funcs *funcs);
Daniel Vetter786b99e2012-12-02 21:53:40 +01002042extern struct drm_framebuffer *drm_framebuffer_lookup(struct drm_device *dev,
2043 uint32_t id);
Rob Clarkf7eff602012-09-05 21:48:38 +00002044extern void drm_framebuffer_unreference(struct drm_framebuffer *fb);
2045extern void drm_framebuffer_reference(struct drm_framebuffer *fb);
2046extern void drm_framebuffer_remove(struct drm_framebuffer *fb);
Dave Airlief453ba02008-11-07 14:05:41 -08002047extern void drm_framebuffer_cleanup(struct drm_framebuffer *fb);
Daniel Vetter36206362012-12-10 20:42:17 +01002048extern void drm_framebuffer_unregister_private(struct drm_framebuffer *fb);
Dave Airlief453ba02008-11-07 14:05:41 -08002049
Paulo Zanonic5431882012-05-15 18:09:02 -03002050extern void drm_object_attach_property(struct drm_mode_object *obj,
2051 struct drm_property *property,
2052 uint64_t init_val);
Dave Airlief453ba02008-11-07 14:05:41 -08002053extern struct drm_property *drm_property_create(struct drm_device *dev, int flags,
2054 const char *name, int num_values);
Sascha Hauer4a67d392012-02-06 10:58:17 +01002055extern struct drm_property *drm_property_create_enum(struct drm_device *dev, int flags,
2056 const char *name,
2057 const struct drm_prop_enum_list *props,
2058 int num_values);
Rob Clark49e27542012-05-17 02:23:26 -06002059struct drm_property *drm_property_create_bitmask(struct drm_device *dev,
2060 int flags, const char *name,
2061 const struct drm_prop_enum_list *props,
Ville Syrjälä7689ffb2014-07-08 10:31:52 +05302062 int num_props,
2063 uint64_t supported_bits);
Sascha Hauerd9bc3c02012-02-06 10:58:18 +01002064struct drm_property *drm_property_create_range(struct drm_device *dev, int flags,
2065 const char *name,
2066 uint64_t min, uint64_t max);
Rob Clarkebc44cf2012-09-12 22:22:31 -05002067struct drm_property *drm_property_create_signed_range(struct drm_device *dev,
2068 int flags, const char *name,
2069 int64_t min, int64_t max);
Rob Clark98f75de2014-05-30 11:37:03 -04002070struct drm_property *drm_property_create_object(struct drm_device *dev,
2071 int flags, const char *name, uint32_t type);
Daniel Vetter960cd9d2015-01-21 08:47:38 +01002072struct drm_property *drm_property_create_bool(struct drm_device *dev, int flags,
2073 const char *name);
Daniel Stone6bcacf52015-04-20 19:22:55 +01002074struct drm_property_blob *drm_property_create_blob(struct drm_device *dev,
2075 size_t length,
2076 const void *data);
2077struct drm_property_blob *drm_property_lookup_blob(struct drm_device *dev,
2078 uint32_t id);
2079struct drm_property_blob *drm_property_reference_blob(struct drm_property_blob *blob);
2080void drm_property_unreference_blob(struct drm_property_blob *blob);
Dave Airlief453ba02008-11-07 14:05:41 -08002081extern void drm_property_destroy(struct drm_device *dev, struct drm_property *property);
2082extern int drm_property_add_enum(struct drm_property *property, int index,
2083 uint64_t value, const char *name);
2084extern int drm_mode_create_dvi_i_properties(struct drm_device *dev);
Thierry Reding2f763312014-10-13 12:45:57 +02002085extern int drm_mode_create_tv_properties(struct drm_device *dev,
2086 unsigned int num_modes,
Ville Syrjäläb7c914b2015-08-31 15:09:26 +03002087 const char * const modes[]);
Dave Airlief453ba02008-11-07 14:05:41 -08002088extern int drm_mode_create_scaling_mode_property(struct drm_device *dev);
Vandana Kannanff587e42014-06-11 10:46:48 +05302089extern int drm_mode_create_aspect_ratio_property(struct drm_device *dev);
Jakob Bornecrantz884840a2009-12-03 23:25:47 +00002090extern int drm_mode_create_dirty_info_property(struct drm_device *dev);
Dave Airlie5bb2bbf2014-11-10 10:18:15 +10002091extern int drm_mode_create_suggested_offset_properties(struct drm_device *dev);
Rob Clarkd34f20d2014-12-18 16:01:56 -05002092extern bool drm_property_change_valid_get(struct drm_property *property,
2093 uint64_t value, struct drm_mode_object **ref);
2094extern void drm_property_change_valid_put(struct drm_property *property,
2095 struct drm_mode_object *ref);
Dave Airlief453ba02008-11-07 14:05:41 -08002096
2097extern int drm_mode_connector_attach_encoder(struct drm_connector *connector,
2098 struct drm_encoder *encoder);
Sascha Hauer4cae5b82012-02-01 11:38:23 +01002099extern int drm_mode_crtc_set_gamma_size(struct drm_crtc *crtc,
Dave Airlief453ba02008-11-07 14:05:41 -08002100 int gamma_size);
Daniel Vetter7a9c9062009-09-15 22:57:31 +02002101extern struct drm_mode_object *drm_mode_object_find(struct drm_device *dev,
2102 uint32_t id, uint32_t type);
Rob Clark98f75de2014-05-30 11:37:03 -04002103
Dave Airlief453ba02008-11-07 14:05:41 -08002104/* IOCTLs */
2105extern int drm_mode_getresources(struct drm_device *dev,
2106 void *data, struct drm_file *file_priv);
Jesse Barnes8cf5c912011-11-14 14:51:27 -08002107extern int drm_mode_getplane_res(struct drm_device *dev, void *data,
2108 struct drm_file *file_priv);
Dave Airlief453ba02008-11-07 14:05:41 -08002109extern int drm_mode_getcrtc(struct drm_device *dev,
2110 void *data, struct drm_file *file_priv);
2111extern int drm_mode_getconnector(struct drm_device *dev,
2112 void *data, struct drm_file *file_priv);
Daniel Vetter2d13b672012-12-11 13:47:23 +01002113extern int drm_mode_set_config_internal(struct drm_mode_set *set);
Dave Airlief453ba02008-11-07 14:05:41 -08002114extern int drm_mode_setcrtc(struct drm_device *dev,
2115 void *data, struct drm_file *file_priv);
Jesse Barnes8cf5c912011-11-14 14:51:27 -08002116extern int drm_mode_getplane(struct drm_device *dev,
2117 void *data, struct drm_file *file_priv);
2118extern int drm_mode_setplane(struct drm_device *dev,
2119 void *data, struct drm_file *file_priv);
Dave Airlief453ba02008-11-07 14:05:41 -08002120extern int drm_mode_cursor_ioctl(struct drm_device *dev,
2121 void *data, struct drm_file *file_priv);
Dave Airlie4c813d42013-06-20 11:48:52 +10002122extern int drm_mode_cursor2_ioctl(struct drm_device *dev,
2123 void *data, struct drm_file *file_priv);
Dave Airlief453ba02008-11-07 14:05:41 -08002124extern int drm_mode_addfb(struct drm_device *dev,
2125 void *data, struct drm_file *file_priv);
Jesse Barnes308e5bc2011-11-14 14:51:28 -08002126extern int drm_mode_addfb2(struct drm_device *dev,
2127 void *data, struct drm_file *file_priv);
2128extern uint32_t drm_mode_legacy_fb_format(uint32_t bpp, uint32_t depth);
Dave Airlief453ba02008-11-07 14:05:41 -08002129extern int drm_mode_rmfb(struct drm_device *dev,
2130 void *data, struct drm_file *file_priv);
2131extern int drm_mode_getfb(struct drm_device *dev,
2132 void *data, struct drm_file *file_priv);
Jakob Bornecrantz884840a2009-12-03 23:25:47 +00002133extern int drm_mode_dirtyfb_ioctl(struct drm_device *dev,
2134 void *data, struct drm_file *file_priv);
Dave Airlief453ba02008-11-07 14:05:41 -08002135
2136extern int drm_mode_getproperty_ioctl(struct drm_device *dev,
2137 void *data, struct drm_file *file_priv);
2138extern int drm_mode_getblob_ioctl(struct drm_device *dev,
2139 void *data, struct drm_file *file_priv);
Daniel Stonee2f5d2e2015-05-22 13:34:51 +01002140extern int drm_mode_createblob_ioctl(struct drm_device *dev,
2141 void *data, struct drm_file *file_priv);
2142extern int drm_mode_destroyblob_ioctl(struct drm_device *dev,
2143 void *data, struct drm_file *file_priv);
Dave Airlief453ba02008-11-07 14:05:41 -08002144extern int drm_mode_connector_property_set_ioctl(struct drm_device *dev,
2145 void *data, struct drm_file *file_priv);
Dave Airlief453ba02008-11-07 14:05:41 -08002146extern int drm_mode_getencoder(struct drm_device *dev,
2147 void *data, struct drm_file *file_priv);
2148extern int drm_mode_gamma_get_ioctl(struct drm_device *dev,
2149 void *data, struct drm_file *file_priv);
2150extern int drm_mode_gamma_set_ioctl(struct drm_device *dev,
2151 void *data, struct drm_file *file_priv);
Thierry Reding18316c82012-12-20 15:41:44 +01002152extern u8 drm_match_cea_mode(const struct drm_display_mode *to_match);
Vandana Kannan0967e6a2014-04-01 16:26:59 +05302153extern enum hdmi_picture_aspect drm_get_cea_aspect_ratio(const u8 video_code);
Ma Lingf23c20c2009-03-26 19:26:23 +08002154extern bool drm_detect_hdmi_monitor(struct edid *edid);
Zhenyu Wang8fe97902010-09-19 14:27:28 +08002155extern bool drm_detect_monitor_audio(struct edid *edid);
Ville Syrjäläb1edd6a2013-01-17 16:31:30 +02002156extern bool drm_rgb_quant_range_selectable(struct edid *edid);
Kristian Høgsbergd91d8a32009-11-17 12:43:55 -05002157extern int drm_mode_page_flip_ioctl(struct drm_device *dev,
2158 void *data, struct drm_file *file_priv);
Zhao Yakuif0fda0a2009-09-03 09:33:48 +08002159extern int drm_add_modes_noedid(struct drm_connector *connector,
2160 int hdisplay, int vdisplay);
Gerd Hoffmann3cf70da2013-10-11 10:01:08 +02002161extern void drm_set_preferred_mode(struct drm_connector *connector,
2162 int hpref, int vpref);
Alex Deucher3c537882010-02-05 04:21:19 -05002163
Thomas Reim051963d2011-07-29 14:28:57 +00002164extern int drm_edid_header_is_valid(const u8 *raw_edid);
Todd Previte6ba2bd32015-04-21 11:09:41 -07002165extern bool drm_edid_block_valid(u8 *raw_edid, int block, bool print_bad_edid,
2166 bool *edid_corrupt);
Alex Deucher3c537882010-02-05 04:21:19 -05002167extern bool drm_edid_is_valid(struct edid *edid);
Dave Airlie138f9eb2014-10-20 16:17:17 +10002168
2169extern struct drm_tile_group *drm_mode_create_tile_group(struct drm_device *dev,
2170 char topology[8]);
2171extern struct drm_tile_group *drm_mode_get_tile_group(struct drm_device *dev,
2172 char topology[8]);
2173extern void drm_mode_put_tile_group(struct drm_device *dev,
2174 struct drm_tile_group *tg);
Dave Airlie1d42bbc2010-05-07 05:02:30 +00002175struct drm_display_mode *drm_mode_find_dmt(struct drm_device *dev,
Adam Jacksonf6e252b2012-04-13 16:33:31 -04002176 int hsize, int vsize, int fresh,
2177 bool rb);
Dave Airlieff72145b2011-02-07 12:16:14 +10002178
2179extern int drm_mode_create_dumb_ioctl(struct drm_device *dev,
2180 void *data, struct drm_file *file_priv);
2181extern int drm_mode_mmap_dumb_ioctl(struct drm_device *dev,
2182 void *data, struct drm_file *file_priv);
2183extern int drm_mode_destroy_dumb_ioctl(struct drm_device *dev,
2184 void *data, struct drm_file *file_priv);
Paulo Zanonic5431882012-05-15 18:09:02 -03002185extern int drm_mode_obj_get_properties_ioctl(struct drm_device *dev, void *data,
2186 struct drm_file *file_priv);
2187extern int drm_mode_obj_set_property_ioctl(struct drm_device *dev, void *data,
2188 struct drm_file *file_priv);
Thomas Wood3a5f87c2014-08-20 14:45:00 +01002189extern int drm_mode_plane_set_obj_prop(struct drm_plane *plane,
2190 struct drm_property *property,
2191 uint64_t value);
Rob Clarkd34f20d2014-12-18 16:01:56 -05002192extern int drm_mode_atomic_ioctl(struct drm_device *dev,
2193 void *data, struct drm_file *file_priv);
Dave Airlie248dbc22011-11-29 20:02:54 +00002194
2195extern void drm_fb_get_bpp_depth(uint32_t format, unsigned int *depth,
2196 int *bpp);
Ville Syrjälä141670e2012-04-05 21:35:15 +03002197extern int drm_format_num_planes(uint32_t format);
Ville Syrjälä5a86bd52012-04-05 21:35:16 +03002198extern int drm_format_plane_cpp(uint32_t format, int plane);
Ville Syrjälä01b68b02012-04-05 21:35:17 +03002199extern int drm_format_horz_chroma_subsampling(uint32_t format);
2200extern int drm_format_vert_chroma_subsampling(uint32_t format);
Ville Syrjäläd20d3172013-06-07 15:43:07 +00002201extern const char *drm_get_format_name(uint32_t format);
Ville Syrjäläc1df5f32014-07-08 10:31:53 +05302202extern struct drm_property *drm_mode_create_rotation_property(struct drm_device *dev,
2203 unsigned int supported_rotations);
Ville Syrjälä3c9855f2014-07-08 10:31:56 +05302204extern unsigned int drm_rotation_simplify(unsigned int rotation,
2205 unsigned int supported_rotations);
Ville Syrjälä141670e2012-04-05 21:35:15 +03002206
Russell King96f60e32012-08-15 13:59:49 +01002207/* Helpers */
Rob Clarka2b34e22013-10-05 16:36:52 -04002208
2209static inline struct drm_plane *drm_plane_find(struct drm_device *dev,
2210 uint32_t id)
2211{
2212 struct drm_mode_object *mo;
2213 mo = drm_mode_object_find(dev, id, DRM_MODE_OBJECT_PLANE);
2214 return mo ? obj_to_plane(mo) : NULL;
2215}
2216
Russell King96f60e32012-08-15 13:59:49 +01002217static inline struct drm_crtc *drm_crtc_find(struct drm_device *dev,
2218 uint32_t id)
2219{
2220 struct drm_mode_object *mo;
2221 mo = drm_mode_object_find(dev, id, DRM_MODE_OBJECT_CRTC);
2222 return mo ? obj_to_crtc(mo) : NULL;
2223}
2224
2225static inline struct drm_encoder *drm_encoder_find(struct drm_device *dev,
2226 uint32_t id)
2227{
2228 struct drm_mode_object *mo;
2229 mo = drm_mode_object_find(dev, id, DRM_MODE_OBJECT_ENCODER);
2230 return mo ? obj_to_encoder(mo) : NULL;
2231}
2232
Rob Clarka2b34e22013-10-05 16:36:52 -04002233static inline struct drm_connector *drm_connector_find(struct drm_device *dev,
2234 uint32_t id)
2235{
2236 struct drm_mode_object *mo;
2237 mo = drm_mode_object_find(dev, id, DRM_MODE_OBJECT_CONNECTOR);
2238 return mo ? obj_to_connector(mo) : NULL;
2239}
2240
2241static inline struct drm_property *drm_property_find(struct drm_device *dev,
2242 uint32_t id)
2243{
2244 struct drm_mode_object *mo;
2245 mo = drm_mode_object_find(dev, id, DRM_MODE_OBJECT_PROPERTY);
2246 return mo ? obj_to_property(mo) : NULL;
2247}
2248
Matt Ropere27dde32014-04-01 15:22:30 -07002249/* Plane list iterator for legacy (overlay only) planes. */
Daniel Vetter4ea50e92015-07-09 23:44:24 +02002250#define drm_for_each_legacy_plane(plane, dev) \
2251 list_for_each_entry(plane, &(dev)->mode_config.plane_list, head) \
Jani Nikula373701b2015-11-24 21:21:55 +02002252 for_each_if (plane->type == DRM_PLANE_TYPE_OVERLAY)
Matt Ropere27dde32014-04-01 15:22:30 -07002253
Daniel Vetter6295d602015-07-09 23:44:25 +02002254#define drm_for_each_plane(plane, dev) \
2255 list_for_each_entry(plane, &(dev)->mode_config.plane_list, head)
2256
2257#define drm_for_each_crtc(crtc, dev) \
2258 list_for_each_entry(crtc, &(dev)->mode_config.crtc_list, head)
2259
Daniel Vetter7a3f3d62015-07-09 23:44:28 +02002260static inline void
2261assert_drm_connector_list_read_locked(struct drm_mode_config *mode_config)
2262{
Daniel Vettercff20ba2015-07-09 23:44:33 +02002263 /*
2264 * The connector hotadd/remove code currently grabs both locks when
2265 * updating lists. Hence readers need only hold either of them to be
2266 * safe and the check amounts to
2267 *
2268 * WARN_ON(not_holding(A) && not_holding(B)).
2269 */
2270 WARN_ON(!mutex_is_locked(&mode_config->mutex) &&
2271 !drm_modeset_is_locked(&mode_config->connection_mutex));
Daniel Vetter7a3f3d62015-07-09 23:44:28 +02002272}
2273
Daniel Vetter6295d602015-07-09 23:44:25 +02002274#define drm_for_each_connector(connector, dev) \
Daniel Vetter7a3f3d62015-07-09 23:44:28 +02002275 for (assert_drm_connector_list_read_locked(&(dev)->mode_config), \
2276 connector = list_first_entry(&(dev)->mode_config.connector_list, \
2277 struct drm_connector, head); \
2278 &connector->head != (&(dev)->mode_config.connector_list); \
2279 connector = list_next_entry(connector, head))
Daniel Vetter6295d602015-07-09 23:44:25 +02002280
2281#define drm_for_each_encoder(encoder, dev) \
2282 list_for_each_entry(encoder, &(dev)->mode_config.encoder_list, head)
2283
2284#define drm_for_each_fb(fb, dev) \
Daniel Vetter4676ba02015-07-09 23:44:30 +02002285 for (WARN_ON(!mutex_is_locked(&(dev)->mode_config.fb_lock)), \
2286 fb = list_first_entry(&(dev)->mode_config.fb_list, \
2287 struct drm_framebuffer, head); \
2288 &fb->head != (&(dev)->mode_config.fb_list); \
2289 fb = list_next_entry(fb, head))
Daniel Vetter6295d602015-07-09 23:44:25 +02002290
Dave Airlief453ba02008-11-07 14:05:41 -08002291#endif /* __DRM_CRTC_H__ */