blob: 0119161cad570d12e986d701bc4c632ccf07e55f [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>
Ville Syrjäläd7da8242016-07-26 19:06:57 +030038#include <drm/drm_rect.h>
Daniel Vetter7520a272016-08-15 16:07:02 +020039#include <drm/drm_modeset.h>
40#include <drm/drm_framebuffer.h>
41#include <drm/drm_modes.h>
Jesse Barnes308e5bc2011-11-14 14:51:28 -080042
Dave Airlief453ba02008-11-07 14:05:41 -080043struct drm_device;
44struct drm_mode_set;
Paulo Zanoni7e3bdf42012-05-15 18:09:01 -030045struct drm_object_properties;
Thierry Reding595887e2012-11-21 15:00:47 +010046struct drm_file;
47struct drm_clip_rect;
Russell King7e435aa2014-06-15 11:07:12 +010048struct device_node;
Daniel Vettere2330f02014-10-29 11:34:56 +010049struct fence;
Daniel Vetter81065542016-06-21 10:54:13 +020050struct edid;
Dave Airlief453ba02008-11-07 14:05:41 -080051
Paulo Zanonife456162012-06-12 11:27:01 -030052#define DRM_OBJECT_MAX_PROPERTY 24
Paulo Zanoni7e3bdf42012-05-15 18:09:01 -030053struct drm_object_properties {
Rob Clark88a48e22014-12-18 16:01:50 -050054 int count, atomic_count;
Rob Clarkb17cd752014-12-16 18:05:30 -050055 /* NOTE: if we ever start dynamically destroying properties (ie.
56 * not at drm_mode_config_cleanup() time), then we'd have to do
57 * a better job of detaching property from mode objects to avoid
58 * dangling property pointers:
59 */
60 struct drm_property *properties[DRM_OBJECT_MAX_PROPERTY];
Rob Clark22b8b132014-12-16 18:05:31 -050061 /* do not read/write values directly, but use drm_object_property_get_value()
62 * and drm_object_property_set_value():
63 */
Paulo Zanoni7e3bdf42012-05-15 18:09:01 -030064 uint64_t values[DRM_OBJECT_MAX_PROPERTY];
Dave Airlief453ba02008-11-07 14:05:41 -080065};
66
Rob Clarkebc44cf2012-09-12 22:22:31 -050067static inline int64_t U642I64(uint64_t val)
68{
69 return (int64_t)*((int64_t *)&val);
70}
71static inline uint64_t I642U64(int64_t val)
72{
73 return (uint64_t)*((uint64_t *)&val);
74}
75
Robert Feketed9c38242015-11-02 16:14:08 +010076/*
77 * Rotation property bits. DRM_ROTATE_<degrees> rotates the image by the
78 * specified amount in degrees in counter clockwise direction. DRM_REFLECT_X and
79 * DRM_REFLECT_Y reflects the image along the specified axis prior to rotation
80 */
Joonas Lahtinen31ad61e2016-07-29 08:50:05 +030081#define DRM_ROTATE_0 BIT(0)
82#define DRM_ROTATE_90 BIT(1)
83#define DRM_ROTATE_180 BIT(2)
84#define DRM_ROTATE_270 BIT(3)
85#define DRM_ROTATE_MASK (DRM_ROTATE_0 | DRM_ROTATE_90 | \
86 DRM_ROTATE_180 | DRM_ROTATE_270)
87#define DRM_REFLECT_X BIT(4)
88#define DRM_REFLECT_Y BIT(5)
89#define DRM_REFLECT_MASK (DRM_REFLECT_X | DRM_REFLECT_Y)
Ville Syrjälä06596962014-07-08 10:31:51 +053090
Dave Airlief453ba02008-11-07 14:05:41 -080091enum drm_connector_status {
92 connector_status_connected = 1,
93 connector_status_disconnected = 2,
94 connector_status_unknown = 3,
95};
96
97enum subpixel_order {
98 SubPixelUnknown = 0,
99 SubPixelHorizontalRGB,
100 SubPixelHorizontalBGR,
101 SubPixelVerticalRGB,
102 SubPixelVerticalBGR,
103 SubPixelNone,
104};
105
Jesse Barnesda05a5a72011-04-15 13:48:57 -0700106#define DRM_COLOR_FORMAT_RGB444 (1<<0)
107#define DRM_COLOR_FORMAT_YCRCB444 (1<<1)
108#define DRM_COLOR_FORMAT_YCRCB422 (1<<2)
Stefan Agnerf0aa0832016-02-08 11:38:14 -0800109
110#define DRM_BUS_FLAG_DE_LOW (1<<0)
111#define DRM_BUS_FLAG_DE_HIGH (1<<1)
112/* drive data on pos. edge */
113#define DRM_BUS_FLAG_PIXDATA_POSEDGE (1<<2)
114/* drive data on neg. edge */
115#define DRM_BUS_FLAG_PIXDATA_NEGEDGE (1<<3)
116
Dave Airlief453ba02008-11-07 14:05:41 -0800117/*
118 * Describes a given display (e.g. CRT or flat panel) and its limitations.
119 */
120struct drm_display_info {
121 char name[DRM_DISPLAY_INFO_LEN];
Adam Jacksonfb439642010-08-03 14:38:16 -0400122
Dave Airlief453ba02008-11-07 14:05:41 -0800123 /* Physical size */
124 unsigned int width_mm;
125 unsigned int height_mm;
126
Dave Airlief453ba02008-11-07 14:05:41 -0800127 /* Clock limits FIXME: storage format */
128 unsigned int min_vfreq, max_vfreq;
129 unsigned int min_hfreq, max_hfreq;
130 unsigned int pixel_clock;
Jesse Barnes3b112282011-04-15 12:49:23 -0700131 unsigned int bpc;
Dave Airlief453ba02008-11-07 14:05:41 -0800132
Dave Airlief453ba02008-11-07 14:05:41 -0800133 enum subpixel_order subpixel_order;
Jesse Barnesda05a5a72011-04-15 13:48:57 -0700134 u32 color_formats;
Dave Airlief453ba02008-11-07 14:05:41 -0800135
Boris Brezillonb5571e92014-07-22 12:09:10 +0200136 const u32 *bus_formats;
137 unsigned int num_bus_formats;
Stefan Agnerf0aa0832016-02-08 11:38:14 -0800138 u32 bus_flags;
Boris Brezillonb5571e92014-07-22 12:09:10 +0200139
Mario Kleiner5d02626d2014-06-05 09:52:10 -0400140 /* Mask of supported hdmi deep color modes */
141 u8 edid_hdmi_dc_modes;
142
Jesse Barnesebec9a72011-08-03 09:22:54 -0700143 u8 cea_rev;
Dave Airlief453ba02008-11-07 14:05:41 -0800144};
145
Dave Airlie138f9eb2014-10-20 16:17:17 +1000146/* data corresponds to displayid vend/prod/serial */
147struct drm_tile_group {
148 struct kref refcount;
149 struct drm_device *dev;
150 int id;
151 u8 group_data[8];
152};
153
Dave Airlief453ba02008-11-07 14:05:41 -0800154struct drm_property_blob {
155 struct drm_mode_object base;
Daniel Stone6bcacf52015-04-20 19:22:55 +0100156 struct drm_device *dev;
Daniel Stonee2f5d2e2015-05-22 13:34:51 +0100157 struct list_head head_global;
158 struct list_head head_file;
Thierry Redingecbbe592014-05-13 11:36:13 +0200159 size_t length;
Ville Syrjäläd63f5e62012-03-13 12:35:49 +0200160 unsigned char data[];
Dave Airlief453ba02008-11-07 14:05:41 -0800161};
162
163struct drm_property_enum {
164 uint64_t value;
165 struct list_head head;
166 char name[DRM_PROP_NAME_LEN];
167};
168
169struct drm_property {
170 struct list_head head;
171 struct drm_mode_object base;
172 uint32_t flags;
173 char name[DRM_PROP_NAME_LEN];
174 uint32_t num_values;
175 uint64_t *values;
Rob Clark98f75de2014-05-30 11:37:03 -0400176 struct drm_device *dev;
Dave Airlief453ba02008-11-07 14:05:41 -0800177
Daniel Vetter3758b342014-11-19 18:38:10 +0100178 struct list_head enum_list;
Dave Airlief453ba02008-11-07 14:05:41 -0800179};
180
181struct drm_crtc;
182struct drm_connector;
183struct drm_encoder;
Kristian Høgsbergd91d8a32009-11-17 12:43:55 -0500184struct drm_pending_vblank_event;
Jesse Barnes8cf5c912011-11-14 14:51:27 -0800185struct drm_plane;
Sean Paul3b336ec2013-08-14 16:47:37 -0400186struct drm_bridge;
Daniel Vetter144ecb92014-10-27 20:28:44 +0100187struct drm_atomic_state;
188
Daniel Vetter4490d4c2015-12-04 09:45:45 +0100189struct drm_crtc_helper_funcs;
190struct drm_encoder_helper_funcs;
191struct drm_connector_helper_funcs;
192struct drm_plane_helper_funcs;
193
Daniel Vetter144ecb92014-10-27 20:28:44 +0100194/**
Daniel Vettercc4ceb42014-07-25 21:30:38 +0200195 * struct drm_crtc_state - mutable CRTC state
Daniel Vetter07cc0ef2014-11-27 15:49:39 +0100196 * @crtc: backpointer to the CRTC
Daniel Vetter144ecb92014-10-27 20:28:44 +0100197 * @enable: whether the CRTC should be enabled, gates all other state
Daniel Vetterd9b13622014-11-26 16:57:41 +0100198 * @active: whether the CRTC is actively displaying (used for DPMS)
Maarten Lankhorstfc596662015-07-21 13:28:57 +0200199 * @planes_changed: planes on this crtc are updated
200 * @mode_changed: crtc_state->mode or crtc_state->enable has been changed
201 * @active_changed: crtc_state->active has been toggled.
202 * @connectors_changed: connectors to this crtc have been updated
Marek Szyprowski44d1240d2016-06-13 11:11:26 +0200203 * @zpos_changed: zpos values of planes on this crtc have been updated
Lionel Landwerlin5488dc12016-02-26 17:05:00 +0000204 * @color_mgmt_changed: color management properties have changed (degamma or
205 * gamma LUT or CSC matrix)
Rob Clark6ddd3882014-11-21 15:28:31 -0500206 * @plane_mask: bitmask of (1 << drm_plane_index(plane)) of attached planes
Maarten Lankhorst4cd9fa52016-01-04 12:53:18 +0100207 * @connector_mask: bitmask of (1 << drm_connector_index(connector)) of attached connectors
Maarten Lankhorste87a52b2016-01-28 15:04:58 +0100208 * @encoder_mask: bitmask of (1 << drm_encoder_index(encoder)) of attached encoders
Daniel Vetter623369e2014-09-16 17:50:47 +0200209 * @last_vblank_count: for helpers and drivers to capture the vblank of the
210 * update to ensure framebuffer cleanup isn't done too early
Daniel Vetter2f324b42014-10-29 11:13:47 +0100211 * @adjusted_mode: for use by helpers and drivers to compute adjusted mode timings
Daniel Vetter144ecb92014-10-27 20:28:44 +0100212 * @mode: current mode timings
Daniel Vetterac3ba4a2016-05-31 23:11:10 +0200213 * @mode_blob: &drm_property_blob for @mode
Lionel Landwerlin5488dc12016-02-26 17:05:00 +0000214 * @degamma_lut: Lookup table for converting framebuffer pixel data
215 * before apply the conversion matrix
216 * @ctm: Transformation matrix
217 * @gamma_lut: Lookup table for converting pixel data after the
218 * conversion matrix
Daniel Vetter144ecb92014-10-27 20:28:44 +0100219 * @event: optional pointer to a DRM event to signal upon completion of the
220 * state update
221 * @state: backpointer to global drm_atomic_state
Daniel Vetterd9b13622014-11-26 16:57:41 +0100222 *
223 * Note that the distinction between @enable and @active is rather subtile:
224 * Flipping @active while @enable is set without changing anything else may
225 * never return in a failure from the ->atomic_check callback. Userspace assumes
226 * that a DPMS On will always succeed. In other words: @enable controls resource
227 * assignment, @active controls the actual hardware state.
Daniel Vetter144ecb92014-10-27 20:28:44 +0100228 */
229struct drm_crtc_state {
Daniel Vetter07cc0ef2014-11-27 15:49:39 +0100230 struct drm_crtc *crtc;
231
Daniel Vettercc4ceb42014-07-25 21:30:38 +0200232 bool enable;
Daniel Vetterd9b13622014-11-26 16:57:41 +0100233 bool active;
Daniel Vetter144ecb92014-10-27 20:28:44 +0100234
Daniel Vetterc2fcd272014-11-05 00:14:14 +0100235 /* computed state bits used by helpers and drivers */
236 bool planes_changed : 1;
Daniel Vetter623369e2014-09-16 17:50:47 +0200237 bool mode_changed : 1;
Daniel Vettereab3bbe2015-01-22 16:36:21 +0100238 bool active_changed : 1;
Maarten Lankhorstfc596662015-07-21 13:28:57 +0200239 bool connectors_changed : 1;
Marek Szyprowski44d1240d2016-06-13 11:11:26 +0200240 bool zpos_changed : 1;
Lionel Landwerlin5488dc12016-02-26 17:05:00 +0000241 bool color_mgmt_changed : 1;
Daniel Vetter623369e2014-09-16 17:50:47 +0200242
Rob Clark6ddd3882014-11-21 15:28:31 -0500243 /* attached planes bitmask:
244 * WARNING: transitional helpers do not maintain plane_mask so
245 * drivers not converted over to atomic helpers should not rely
246 * on plane_mask being accurate!
247 */
248 u32 plane_mask;
249
Maarten Lankhorst4cd9fa52016-01-04 12:53:18 +0100250 u32 connector_mask;
Maarten Lankhorste87a52b2016-01-28 15:04:58 +0100251 u32 encoder_mask;
Maarten Lankhorst4cd9fa52016-01-04 12:53:18 +0100252
Daniel Vetter623369e2014-09-16 17:50:47 +0200253 /* last_vblank_count: for vblank waits before cleanup */
254 u32 last_vblank_count;
Daniel Vetterc2fcd272014-11-05 00:14:14 +0100255
Daniel Vetter2f324b42014-10-29 11:13:47 +0100256 /* adjusted_mode: for use by helpers and drivers */
257 struct drm_display_mode adjusted_mode;
258
Daniel Vetter144ecb92014-10-27 20:28:44 +0100259 struct drm_display_mode mode;
260
Daniel Stone99cf4a22015-05-25 19:11:51 +0100261 /* blob property to expose current mode to atomic userspace */
262 struct drm_property_blob *mode_blob;
263
Lionel Landwerlin5488dc12016-02-26 17:05:00 +0000264 /* blob property to expose color management to userspace */
265 struct drm_property_blob *degamma_lut;
266 struct drm_property_blob *ctm;
267 struct drm_property_blob *gamma_lut;
268
Daniel Vetter144ecb92014-10-27 20:28:44 +0100269 struct drm_pending_vblank_event *event;
270
271 struct drm_atomic_state *state;
272};
Dave Airlief453ba02008-11-07 14:05:41 -0800273
274/**
Daniel Vetter3bf04012014-10-27 16:54:27 +0100275 * struct drm_crtc_funcs - control CRTCs for a given device
Dave Airlief453ba02008-11-07 14:05:41 -0800276 *
277 * The drm_crtc_funcs structure is the central CRTC management structure
278 * in the DRM. Each CRTC controls one or more connectors (note that the name
279 * CRTC is simply historical, a CRTC may control LVDS, VGA, DVI, TV out, etc.
280 * connectors, not just CRTs).
281 *
282 * Each driver is responsible for filling out this structure at startup time,
283 * in addition to providing other modesetting features, like i2c and DDC
284 * bus accessors.
285 */
286struct drm_crtc_funcs {
Daniel Vetter88548632015-12-04 09:45:48 +0100287 /**
288 * @reset:
289 *
290 * Reset CRTC hardware and software state to off. This function isn't
291 * called by the core directly, only through drm_mode_config_reset().
292 * It's not a helper hook only for historical reasons.
293 *
294 * Atomic drivers can use drm_atomic_helper_crtc_reset() to reset
295 * atomic state using this hook.
296 */
Chris Wilsoneb033552011-01-24 15:11:08 +0000297 void (*reset)(struct drm_crtc *crtc);
Dave Airlief453ba02008-11-07 14:05:41 -0800298
Daniel Vetterf6da8c62015-12-04 09:46:00 +0100299 /**
300 * @cursor_set:
301 *
302 * Update the cursor image. The cursor position is relative to the CRTC
303 * and can be partially or fully outside of the visible area.
304 *
305 * Note that contrary to all other KMS functions the legacy cursor entry
306 * points don't take a framebuffer object, but instead take directly a
307 * raw buffer object id from the driver's buffer manager (which is
308 * either GEM or TTM for current drivers).
309 *
310 * This entry point is deprecated, drivers should instead implement
311 * universal plane support and register a proper cursor plane using
312 * drm_crtc_init_with_planes().
313 *
314 * This callback is optional
315 *
316 * RETURNS:
317 *
318 * 0 on success or a negative error code on failure.
319 */
Dave Airlief453ba02008-11-07 14:05:41 -0800320 int (*cursor_set)(struct drm_crtc *crtc, struct drm_file *file_priv,
321 uint32_t handle, uint32_t width, uint32_t height);
Daniel Vetterf6da8c62015-12-04 09:46:00 +0100322
323 /**
324 * @cursor_set2:
325 *
326 * Update the cursor image, including hotspot information. The hotspot
327 * must not affect the cursor position in CRTC coordinates, but is only
328 * meant as a hint for virtualized display hardware to coordinate the
329 * guests and hosts cursor position. The cursor hotspot is relative to
330 * the cursor image. Otherwise this works exactly like @cursor_set.
331 *
332 * This entry point is deprecated, drivers should instead implement
333 * universal plane support and register a proper cursor plane using
334 * drm_crtc_init_with_planes().
335 *
336 * This callback is optional.
337 *
338 * RETURNS:
339 *
340 * 0 on success or a negative error code on failure.
341 */
Dave Airlie4c813d42013-06-20 11:48:52 +1000342 int (*cursor_set2)(struct drm_crtc *crtc, struct drm_file *file_priv,
343 uint32_t handle, uint32_t width, uint32_t height,
344 int32_t hot_x, int32_t hot_y);
Daniel Vetterf6da8c62015-12-04 09:46:00 +0100345
346 /**
347 * @cursor_move:
348 *
349 * Update the cursor position. The cursor does not need to be visible
350 * when this hook is called.
351 *
352 * This entry point is deprecated, drivers should instead implement
353 * universal plane support and register a proper cursor plane using
354 * drm_crtc_init_with_planes().
355 *
356 * This callback is optional.
357 *
358 * RETURNS:
359 *
360 * 0 on success or a negative error code on failure.
361 */
Dave Airlief453ba02008-11-07 14:05:41 -0800362 int (*cursor_move)(struct drm_crtc *crtc, int x, int y);
363
Daniel Vetterf6da8c62015-12-04 09:46:00 +0100364 /**
365 * @gamma_set:
366 *
367 * Set gamma on the CRTC.
368 *
369 * This callback is optional.
370 *
371 * NOTE:
372 *
373 * Drivers that support gamma tables and also fbdev emulation through
374 * the provided helper library need to take care to fill out the gamma
375 * hooks for both. Currently there's a bit an unfortunate duplication
376 * going on, which should eventually be unified to just one set of
377 * hooks.
378 */
Maarten Lankhorst7ea77282016-06-07 12:49:30 +0200379 int (*gamma_set)(struct drm_crtc *crtc, u16 *r, u16 *g, u16 *b,
380 uint32_t size);
Daniel Vetter88548632015-12-04 09:45:48 +0100381
382 /**
383 * @destroy:
384 *
385 * Clean up plane resources. This is only called at driver unload time
386 * through drm_mode_config_cleanup() since a CRTC cannot be hotplugged
387 * in DRM.
388 */
Dave Airlief453ba02008-11-07 14:05:41 -0800389 void (*destroy)(struct drm_crtc *crtc);
390
Daniel Vetterf6da8c62015-12-04 09:46:00 +0100391 /**
392 * @set_config:
393 *
394 * This is the main legacy entry point to change the modeset state on a
395 * CRTC. All the details of the desired configuration are passed in a
396 * struct &drm_mode_set - see there for details.
397 *
398 * Drivers implementing atomic modeset should use
399 * drm_atomic_helper_set_config() to implement this hook.
400 *
401 * RETURNS:
402 *
403 * 0 on success or a negative error code on failure.
404 */
Dave Airlief453ba02008-11-07 14:05:41 -0800405 int (*set_config)(struct drm_mode_set *set);
Kristian Høgsbergd91d8a32009-11-17 12:43:55 -0500406
Daniel Vetterf6da8c62015-12-04 09:46:00 +0100407 /**
408 * @page_flip:
409 *
410 * Legacy entry point to schedule a flip to the given framebuffer.
411 *
412 * Page flipping is a synchronization mechanism that replaces the frame
413 * buffer being scanned out by the CRTC with a new frame buffer during
414 * vertical blanking, avoiding tearing (except when requested otherwise
415 * through the DRM_MODE_PAGE_FLIP_ASYNC flag). When an application
416 * requests a page flip the DRM core verifies that the new frame buffer
417 * is large enough to be scanned out by the CRTC in the currently
418 * configured mode and then calls the CRTC ->page_flip() operation with a
419 * pointer to the new frame buffer.
420 *
421 * The driver must wait for any pending rendering to the new framebuffer
422 * to complete before executing the flip. It should also wait for any
423 * pending rendering from other drivers if the underlying buffer is a
424 * shared dma-buf.
425 *
426 * An application can request to be notified when the page flip has
427 * completed. The drm core will supply a struct &drm_event in the event
428 * parameter in this case. This can be handled by the
429 * drm_crtc_send_vblank_event() function, which the driver should call on
430 * the provided event upon completion of the flip. Note that if
431 * the driver supports vblank signalling and timestamping the vblank
432 * counters and timestamps must agree with the ones returned from page
433 * flip events. With the current vblank helper infrastructure this can
434 * be achieved by holding a vblank reference while the page flip is
435 * pending, acquired through drm_crtc_vblank_get() and released with
436 * drm_crtc_vblank_put(). Drivers are free to implement their own vblank
437 * counter and timestamp tracking though, e.g. if they have accurate
438 * timestamp registers in hardware.
439 *
Daniel Vetterf6da8c62015-12-04 09:46:00 +0100440 * This callback is optional.
441 *
442 * NOTE:
443 *
444 * Very early versions of the KMS ABI mandated that the driver must
445 * block (but not reject) any rendering to the old framebuffer until the
446 * flip operation has completed and the old framebuffer is no longer
447 * visible. This requirement has been lifted, and userspace is instead
448 * expected to request delivery of an event and wait with recycling old
449 * buffers until such has been received.
450 *
451 * RETURNS:
452 *
453 * 0 on success or a negative error code on failure. Note that if a
454 * ->page_flip() operation is already pending the callback should return
455 * -EBUSY. Pageflips on a disabled CRTC (either by setting a NULL mode
456 * or just runtime disabled through DPMS respectively the new atomic
Daniel Vetter4cba6852015-12-08 09:49:20 +0100457 * "ACTIVE" state) should result in an -EINVAL error code. Note that
458 * drm_atomic_helper_page_flip() checks this already for atomic drivers.
Kristian Høgsbergd91d8a32009-11-17 12:43:55 -0500459 */
460 int (*page_flip)(struct drm_crtc *crtc,
461 struct drm_framebuffer *fb,
Keith Packarded8d1972013-07-22 18:49:58 -0700462 struct drm_pending_vblank_event *event,
463 uint32_t flags);
Paulo Zanonibffd9de02012-05-15 18:09:05 -0300464
Daniel Vetter88548632015-12-04 09:45:48 +0100465 /**
466 * @set_property:
467 *
468 * This is the legacy entry point to update a property attached to the
469 * CRTC.
470 *
471 * Drivers implementing atomic modeset should use
472 * drm_atomic_helper_crtc_set_property() to implement this hook.
473 *
474 * This callback is optional if the driver does not support any legacy
475 * driver-private properties.
476 *
477 * RETURNS:
478 *
479 * 0 on success or a negative error code on failure.
480 */
Paulo Zanonibffd9de02012-05-15 18:09:05 -0300481 int (*set_property)(struct drm_crtc *crtc,
482 struct drm_property *property, uint64_t val);
Daniel Vetter144ecb92014-10-27 20:28:44 +0100483
Daniel Vetter88548632015-12-04 09:45:48 +0100484 /**
485 * @atomic_duplicate_state:
486 *
487 * Duplicate the current atomic state for this CRTC and return it.
488 * The core and helpers gurantee that any atomic state duplicated with
489 * this hook and still owned by the caller (i.e. not transferred to the
490 * driver by calling ->atomic_commit() from struct
491 * &drm_mode_config_funcs) will be cleaned up by calling the
492 * @atomic_destroy_state hook in this structure.
493 *
494 * Atomic drivers which don't subclass struct &drm_crtc should use
495 * drm_atomic_helper_crtc_duplicate_state(). Drivers that subclass the
496 * state structure to extend it with driver-private state should use
497 * __drm_atomic_helper_crtc_duplicate_state() to make sure shared state is
498 * duplicated in a consistent fashion across drivers.
499 *
500 * It is an error to call this hook before crtc->state has been
501 * initialized correctly.
502 *
503 * NOTE:
504 *
505 * If the duplicate state references refcounted resources this hook must
506 * acquire a reference for each of them. The driver must release these
507 * references again in @atomic_destroy_state.
508 *
509 * RETURNS:
510 *
511 * Duplicated atomic state or NULL when the allocation failed.
512 */
Daniel Vetter144ecb92014-10-27 20:28:44 +0100513 struct drm_crtc_state *(*atomic_duplicate_state)(struct drm_crtc *crtc);
Daniel Vetter88548632015-12-04 09:45:48 +0100514
515 /**
516 * @atomic_destroy_state:
517 *
518 * Destroy a state duplicated with @atomic_duplicate_state and release
519 * or unreference all resources it references
520 */
Daniel Vetter144ecb92014-10-27 20:28:44 +0100521 void (*atomic_destroy_state)(struct drm_crtc *crtc,
Daniel Vettercc4ceb42014-07-25 21:30:38 +0200522 struct drm_crtc_state *state);
Daniel Vetter88548632015-12-04 09:45:48 +0100523
524 /**
525 * @atomic_set_property:
526 *
527 * Decode a driver-private property value and store the decoded value
528 * into the passed-in state structure. Since the atomic core decodes all
529 * standardized properties (even for extensions beyond the core set of
530 * properties which might not be implemented by all drivers) this
531 * requires drivers to subclass the state structure.
532 *
533 * Such driver-private properties should really only be implemented for
534 * truly hardware/vendor specific state. Instead it is preferred to
535 * standardize atomic extension and decode the properties used to expose
536 * such an extension in the core.
537 *
538 * Do not call this function directly, use
539 * drm_atomic_crtc_set_property() instead.
540 *
541 * This callback is optional if the driver does not support any
542 * driver-private atomic properties.
543 *
544 * NOTE:
545 *
546 * This function is called in the state assembly phase of atomic
547 * modesets, which can be aborted for any reason (including on
548 * userspace's request to just check whether a configuration would be
549 * possible). Drivers MUST NOT touch any persistent state (hardware or
550 * software) or data structures except the passed in @state parameter.
551 *
552 * Also since userspace controls in which order properties are set this
553 * function must not do any input validation (since the state update is
554 * incomplete and hence likely inconsistent). Instead any such input
555 * validation must be done in the various atomic_check callbacks.
556 *
557 * RETURNS:
558 *
559 * 0 if the property has been found, -EINVAL if the property isn't
560 * implemented by the driver (which should never happen, the core only
561 * asks for properties attached to this CRTC). No other validation is
562 * allowed by the driver. The core already checks that the property
563 * value is within the range (integer, valid enum value, ...) the driver
564 * set when registering the property.
565 */
Daniel Vetter144ecb92014-10-27 20:28:44 +0100566 int (*atomic_set_property)(struct drm_crtc *crtc,
567 struct drm_crtc_state *state,
568 struct drm_property *property,
569 uint64_t val);
Daniel Vetter88548632015-12-04 09:45:48 +0100570 /**
571 * @atomic_get_property:
572 *
573 * Reads out the decoded driver-private property. This is used to
Daniel Vetterc6b0ca32015-12-04 09:46:01 +0100574 * implement the GETCRTC IOCTL.
Daniel Vetter88548632015-12-04 09:45:48 +0100575 *
576 * Do not call this function directly, use
577 * drm_atomic_crtc_get_property() instead.
578 *
579 * This callback is optional if the driver does not support any
580 * driver-private atomic properties.
581 *
582 * RETURNS:
583 *
584 * 0 on success, -EINVAL if the property isn't implemented by the
585 * driver (which should never happen, the core only asks for
586 * properties attached to this CRTC).
587 */
Rob Clarkac9c9252014-12-18 16:01:47 -0500588 int (*atomic_get_property)(struct drm_crtc *crtc,
589 const struct drm_crtc_state *state,
590 struct drm_property *property,
591 uint64_t *val);
Benjamin Gaignard79190ea2016-06-21 16:37:09 +0200592
593 /**
594 * @late_register:
595 *
596 * This optional hook can be used to register additional userspace
597 * interfaces attached to the crtc like debugfs interfaces.
598 * It is called late in the driver load sequence from drm_dev_register().
599 * Everything added from this callback should be unregistered in
600 * the early_unregister callback.
601 *
602 * Returns:
603 *
604 * 0 on success, or a negative error code on failure.
605 */
606 int (*late_register)(struct drm_crtc *crtc);
607
608 /**
609 * @early_unregister:
610 *
611 * This optional hook should be used to unregister the additional
612 * userspace interfaces attached to the crtc from
613 * late_unregister(). It is called from drm_dev_unregister(),
614 * early in the driver unload sequence to disable userspace access
615 * before data structures are torndown.
616 */
617 void (*early_unregister)(struct drm_crtc *crtc);
Dave Airlief453ba02008-11-07 14:05:41 -0800618};
619
620/**
Daniel Vetter3bf04012014-10-27 16:54:27 +0100621 * struct drm_crtc - central CRTC control structure
Jesse Barnes77491632011-11-07 12:03:14 -0800622 * @dev: parent DRM device
Daniel Vetter2c0c33d2014-10-27 20:19:38 +0100623 * @port: OF node used by drm_of_find_possible_crtcs()
Jesse Barnes77491632011-11-07 12:03:14 -0800624 * @head: list management
Daniel Vetterac3ba4a2016-05-31 23:11:10 +0200625 * @name: human readable name, can be overwritten by the driver
Rob Clark51fd3712013-11-19 12:10:12 -0500626 * @mutex: per-CRTC locking
Jesse Barnes77491632011-11-07 12:03:14 -0800627 * @base: base KMS object for ID tracking etc.
Matt Ropere13161a2014-04-01 15:22:38 -0700628 * @primary: primary plane for this CRTC
629 * @cursor: cursor plane for this CRTC
Daniel Vetter2c0c33d2014-10-27 20:19:38 +0100630 * @cursor_x: current x position of the cursor, used for universal cursor planes
631 * @cursor_y: current y position of the cursor, used for universal cursor planes
Dave Airlief453ba02008-11-07 14:05:41 -0800632 * @enabled: is this CRTC enabled?
Jesse Barnes77491632011-11-07 12:03:14 -0800633 * @mode: current mode timings
634 * @hwmode: mode timings as programmed to hw regs
Dave Airlief453ba02008-11-07 14:05:41 -0800635 * @x: x position on screen
636 * @y: y position on screen
Dave Airlief453ba02008-11-07 14:05:41 -0800637 * @funcs: CRTC control functions
Jesse Barnes77491632011-11-07 12:03:14 -0800638 * @gamma_size: size of gamma ramp
639 * @gamma_store: gamma ramp values
Jesse Barnes77491632011-11-07 12:03:14 -0800640 * @helper_private: mid-layer private data
Paulo Zanonibffd9de02012-05-15 18:09:05 -0300641 * @properties: property tracking for this CRTC
Dave Airlief453ba02008-11-07 14:05:41 -0800642 *
643 * Each CRTC may have one or more connectors associated with it. This structure
644 * allows the CRTC to be controlled.
645 */
646struct drm_crtc {
647 struct drm_device *dev;
Russell King7e435aa2014-06-15 11:07:12 +0100648 struct device_node *port;
Dave Airlief453ba02008-11-07 14:05:41 -0800649 struct list_head head;
650
Ville Syrjäläfa3ab4c2015-12-08 18:41:53 +0200651 char *name;
652
Daniel Vetterac3ba4a2016-05-31 23:11:10 +0200653 /**
654 * @mutex:
Daniel Vetter29494c12012-12-02 02:18:25 +0100655 *
656 * This provides a read lock for the overall crtc state (mode, dpms
657 * state, ...) and a write lock for everything which can be update
Daniel Vetterac3ba4a2016-05-31 23:11:10 +0200658 * without a full modeset (fb, cursor data, crtc properties ...). Full
659 * modeset also need to grab dev->mode_config.connection_mutex.
Daniel Vetter29494c12012-12-02 02:18:25 +0100660 */
Rob Clark51fd3712013-11-19 12:10:12 -0500661 struct drm_modeset_lock mutex;
Daniel Vetter29494c12012-12-02 02:18:25 +0100662
Dave Airlief453ba02008-11-07 14:05:41 -0800663 struct drm_mode_object base;
664
Matt Ropere13161a2014-04-01 15:22:38 -0700665 /* primary and cursor planes for CRTC */
666 struct drm_plane *primary;
667 struct drm_plane *cursor;
668
Daniel Vetter96094082016-07-15 21:47:59 +0200669 /**
670 * @index: Position inside the mode_config.list, can be used as an array
671 * index. It is invariant over the lifetime of the CRTC.
672 */
Chris Wilson490d3d12016-05-27 20:05:00 +0100673 unsigned index;
674
Matt Roper161d0dc2014-06-10 08:28:10 -0700675 /* position of cursor plane on crtc */
676 int cursor_x;
677 int cursor_y;
678
Dave Airlief453ba02008-11-07 14:05:41 -0800679 bool enabled;
680
Mario Kleiner27641c32010-10-23 04:20:23 +0200681 /* Requested mode from modesetting. */
Dave Airlief453ba02008-11-07 14:05:41 -0800682 struct drm_display_mode mode;
683
Mario Kleiner27641c32010-10-23 04:20:23 +0200684 /* Programmed mode in hw, after adjustments for encoders,
685 * crtc, panel scaling etc. Needed for timestamping etc.
686 */
687 struct drm_display_mode hwmode;
688
Dave Airlief453ba02008-11-07 14:05:41 -0800689 int x, y;
Dave Airlief453ba02008-11-07 14:05:41 -0800690 const struct drm_crtc_funcs *funcs;
691
Lionel Landwerlin5488dc12016-02-26 17:05:00 +0000692 /* Legacy FB CRTC gamma size for reporting to userspace */
Dave Airlief453ba02008-11-07 14:05:41 -0800693 uint32_t gamma_size;
694 uint16_t *gamma_store;
695
696 /* if you are using the helper */
Daniel Vetter4490d4c2015-12-04 09:45:45 +0100697 const struct drm_crtc_helper_funcs *helper_private;
Paulo Zanonibffd9de02012-05-15 18:09:05 -0300698
699 struct drm_object_properties properties;
Daniel Vetterd059f652014-07-25 18:07:40 +0200700
Daniel Vetter3b24f7d2016-06-08 14:19:00 +0200701 /**
702 * @state:
703 *
704 * Current atomic state for this CRTC.
705 */
Daniel Vetter144ecb92014-10-27 20:28:44 +0100706 struct drm_crtc_state *state;
707
Daniel Vetter3b24f7d2016-06-08 14:19:00 +0200708 /**
709 * @commit_list:
710 *
711 * List of &drm_crtc_commit structures tracking pending commits.
712 * Protected by @commit_lock. This list doesn't hold its own full
713 * reference, but burrows it from the ongoing commit. Commit entries
714 * must be removed from this list once the commit is fully completed,
715 * but before it's correspoding &drm_atomic_state gets destroyed.
716 */
717 struct list_head commit_list;
718
719 /**
720 * @commit_lock:
721 *
722 * Spinlock to protect @commit_list.
723 */
724 spinlock_t commit_lock;
725
726 /**
727 * @acquire_ctx:
728 *
729 * Per-CRTC implicit acquire context used by atomic drivers for legacy
730 * IOCTLs, so that atomic drivers can get at the locking acquire
731 * context.
Daniel Vetterd059f652014-07-25 18:07:40 +0200732 */
733 struct drm_modeset_acquire_ctx *acquire_ctx;
Dave Airlief453ba02008-11-07 14:05:41 -0800734};
735
Daniel Vetter144ecb92014-10-27 20:28:44 +0100736/**
737 * struct drm_connector_state - mutable connector state
Daniel Vetter07cc0ef2014-11-27 15:49:39 +0100738 * @connector: backpointer to the connector
Daniel Vettercc4ceb42014-07-25 21:30:38 +0200739 * @crtc: CRTC to connect connector to, NULL if disabled
Daniel Vetter623369e2014-09-16 17:50:47 +0200740 * @best_encoder: can be used by helpers and drivers to select the encoder
Daniel Vetter144ecb92014-10-27 20:28:44 +0100741 * @state: backpointer to global drm_atomic_state
742 */
743struct drm_connector_state {
Daniel Vetter07cc0ef2014-11-27 15:49:39 +0100744 struct drm_connector *connector;
745
Rob Clark6ddd3882014-11-21 15:28:31 -0500746 struct drm_crtc *crtc; /* do not write directly, use drm_atomic_set_crtc_for_connector() */
Daniel Vetter144ecb92014-10-27 20:28:44 +0100747
Daniel Vetter623369e2014-09-16 17:50:47 +0200748 struct drm_encoder *best_encoder;
749
Daniel Vetter144ecb92014-10-27 20:28:44 +0100750 struct drm_atomic_state *state;
751};
Dave Airlief453ba02008-11-07 14:05:41 -0800752
753/**
Daniel Vetter3bf04012014-10-27 16:54:27 +0100754 * struct drm_connector_funcs - control connectors on a given device
Daniel Vetter144ecb92014-10-27 20:28:44 +0100755 *
Dave Airlief453ba02008-11-07 14:05:41 -0800756 * Each CRTC may have one or more connectors attached to it. The functions
757 * below allow the core DRM code to control connectors, enumerate available modes,
758 * etc.
759 */
760struct drm_connector_funcs {
Daniel Vetter6fe14ac2015-12-04 09:45:58 +0100761 /**
762 * @dpms:
763 *
764 * Legacy entry point to set the per-connector DPMS state. Legacy DPMS
765 * is exposed as a standard property on the connector, but diverted to
766 * this callback in the drm core. Note that atomic drivers don't
767 * implement the 4 level DPMS support on the connector any more, but
768 * instead only have an on/off "ACTIVE" property on the CRTC object.
769 *
770 * Drivers implementing atomic modeset should use
771 * drm_atomic_helper_connector_dpms() to implement this hook.
772 *
773 * RETURNS:
774 *
775 * 0 on success or a negative error code on failure.
776 */
Maarten Lankhorst9a69a9a2015-07-21 11:34:55 +0200777 int (*dpms)(struct drm_connector *connector, int mode);
Daniel Vetter88548632015-12-04 09:45:48 +0100778
779 /**
780 * @reset:
781 *
782 * Reset connector hardware and software state to off. This function isn't
783 * called by the core directly, only through drm_mode_config_reset().
784 * It's not a helper hook only for historical reasons.
785 *
786 * Atomic drivers can use drm_atomic_helper_connector_reset() to reset
787 * atomic state using this hook.
788 */
Chris Wilsoneb033552011-01-24 15:11:08 +0000789 void (*reset)(struct drm_connector *connector);
Chris Wilson930a9e22010-09-14 11:07:23 +0100790
Daniel Vetter6fe14ac2015-12-04 09:45:58 +0100791 /**
792 * @detect:
793 *
794 * Check to see if anything is attached to the connector. The parameter
795 * force is set to false whilst polling, true when checking the
796 * connector due to a user request. force can be used by the driver to
797 * avoid expensive, destructive operations during automated probing.
798 *
799 * FIXME:
800 *
801 * Note that this hook is only called by the probe helper. It's not in
802 * the helper library vtable purely for historical reasons. The only DRM
803 * core entry point to probe connector state is @fill_modes.
804 *
805 * RETURNS:
806 *
807 * drm_connector_status indicating the connector's status.
Chris Wilson930a9e22010-09-14 11:07:23 +0100808 */
Chris Wilson7b334fc2010-09-09 23:51:02 +0100809 enum drm_connector_status (*detect)(struct drm_connector *connector,
Chris Wilson930a9e22010-09-14 11:07:23 +0100810 bool force);
Daniel Vetter6fe14ac2015-12-04 09:45:58 +0100811
812 /**
813 * @force:
814 *
815 * This function is called to update internal encoder state when the
816 * connector is forced to a certain state by userspace, either through
817 * the sysfs interfaces or on the kernel cmdline. In that case the
818 * @detect callback isn't called.
819 *
820 * FIXME:
821 *
822 * Note that this hook is only called by the probe helper. It's not in
823 * the helper library vtable purely for historical reasons. The only DRM
824 * core entry point to probe connector state is @fill_modes.
825 */
826 void (*force)(struct drm_connector *connector);
827
828 /**
829 * @fill_modes:
830 *
831 * Entry point for output detection and basic mode validation. The
832 * driver should reprobe the output if needed (e.g. when hotplug
833 * handling is unreliable), add all detected modes to connector->modes
834 * and filter out any the device can't support in any configuration. It
835 * also needs to filter out any modes wider or higher than the
836 * parameters max_width and max_height indicate.
837 *
838 * The drivers must also prune any modes no longer valid from
839 * connector->modes. Furthermore it must update connector->status and
840 * connector->edid. If no EDID has been received for this output
841 * connector->edid must be NULL.
842 *
843 * Drivers using the probe helpers should use
844 * drm_helper_probe_single_connector_modes() or
845 * drm_helper_probe_single_connector_modes_nomerge() to implement this
846 * function.
847 *
848 * RETURNS:
849 *
850 * The number of modes detected and filled into connector->modes.
851 */
Jesse Barnes40a518d2009-01-12 12:05:32 -0800852 int (*fill_modes)(struct drm_connector *connector, uint32_t max_width, uint32_t max_height);
Daniel Vetter88548632015-12-04 09:45:48 +0100853
854 /**
855 * @set_property:
856 *
857 * This is the legacy entry point to update a property attached to the
858 * connector.
859 *
860 * Drivers implementing atomic modeset should use
861 * drm_atomic_helper_connector_set_property() to implement this hook.
862 *
863 * This callback is optional if the driver does not support any legacy
864 * driver-private properties.
865 *
866 * RETURNS:
867 *
868 * 0 on success or a negative error code on failure.
869 */
Dave Airlief453ba02008-11-07 14:05:41 -0800870 int (*set_property)(struct drm_connector *connector, struct drm_property *property,
871 uint64_t val);
Daniel Vetter88548632015-12-04 09:45:48 +0100872
873 /**
Chris Wilsonaaf285e2016-06-15 13:17:47 +0100874 * @late_register:
875 *
876 * This optional hook can be used to register additional userspace
877 * interfaces attached to the connector, light backlight control, i2c,
878 * DP aux or similar interfaces. It is called late in the driver load
879 * sequence from drm_connector_register() when registering all the
880 * core drm connector interfaces. Everything added from this callback
881 * should be unregistered in the early_unregister callback.
882 *
883 * Returns:
884 *
885 * 0 on success, or a negative error code on failure.
886 */
887 int (*late_register)(struct drm_connector *connector);
888
889 /**
890 * @early_unregister:
891 *
892 * This optional hook should be used to unregister the additional
893 * userspace interfaces attached to the connector from
894 * late_unregister(). It is called from drm_connector_unregister(),
895 * early in the driver unload sequence to disable userspace access
896 * before data structures are torndown.
897 */
898 void (*early_unregister)(struct drm_connector *connector);
899
900 /**
Daniel Vetter88548632015-12-04 09:45:48 +0100901 * @destroy:
902 *
903 * Clean up connector resources. This is called at driver unload time
904 * through drm_mode_config_cleanup(). It can also be called at runtime
905 * when a connector is being hot-unplugged for drivers that support
906 * connector hotplugging (e.g. DisplayPort MST).
907 */
Dave Airlief453ba02008-11-07 14:05:41 -0800908 void (*destroy)(struct drm_connector *connector);
Daniel Vetter144ecb92014-10-27 20:28:44 +0100909
Daniel Vetter88548632015-12-04 09:45:48 +0100910 /**
911 * @atomic_duplicate_state:
912 *
913 * Duplicate the current atomic state for this connector and return it.
914 * The core and helpers gurantee that any atomic state duplicated with
915 * this hook and still owned by the caller (i.e. not transferred to the
916 * driver by calling ->atomic_commit() from struct
917 * &drm_mode_config_funcs) will be cleaned up by calling the
918 * @atomic_destroy_state hook in this structure.
919 *
920 * Atomic drivers which don't subclass struct &drm_connector_state should use
921 * drm_atomic_helper_connector_duplicate_state(). Drivers that subclass the
922 * state structure to extend it with driver-private state should use
923 * __drm_atomic_helper_connector_duplicate_state() to make sure shared state is
924 * duplicated in a consistent fashion across drivers.
925 *
926 * It is an error to call this hook before connector->state has been
927 * initialized correctly.
928 *
929 * NOTE:
930 *
931 * If the duplicate state references refcounted resources this hook must
932 * acquire a reference for each of them. The driver must release these
933 * references again in @atomic_destroy_state.
934 *
935 * RETURNS:
936 *
937 * Duplicated atomic state or NULL when the allocation failed.
938 */
Daniel Vetter144ecb92014-10-27 20:28:44 +0100939 struct drm_connector_state *(*atomic_duplicate_state)(struct drm_connector *connector);
Daniel Vetter88548632015-12-04 09:45:48 +0100940
941 /**
942 * @atomic_destroy_state:
943 *
944 * Destroy a state duplicated with @atomic_duplicate_state and release
945 * or unreference all resources it references
946 */
Daniel Vetter144ecb92014-10-27 20:28:44 +0100947 void (*atomic_destroy_state)(struct drm_connector *connector,
Daniel Vettercc4ceb42014-07-25 21:30:38 +0200948 struct drm_connector_state *state);
Daniel Vetter88548632015-12-04 09:45:48 +0100949
950 /**
951 * @atomic_set_property:
952 *
953 * Decode a driver-private property value and store the decoded value
954 * into the passed-in state structure. Since the atomic core decodes all
955 * standardized properties (even for extensions beyond the core set of
956 * properties which might not be implemented by all drivers) this
957 * requires drivers to subclass the state structure.
958 *
959 * Such driver-private properties should really only be implemented for
960 * truly hardware/vendor specific state. Instead it is preferred to
961 * standardize atomic extension and decode the properties used to expose
962 * such an extension in the core.
963 *
964 * Do not call this function directly, use
965 * drm_atomic_connector_set_property() instead.
966 *
967 * This callback is optional if the driver does not support any
968 * driver-private atomic properties.
969 *
970 * NOTE:
971 *
972 * This function is called in the state assembly phase of atomic
973 * modesets, which can be aborted for any reason (including on
974 * userspace's request to just check whether a configuration would be
975 * possible). Drivers MUST NOT touch any persistent state (hardware or
976 * software) or data structures except the passed in @state parameter.
977 *
978 * Also since userspace controls in which order properties are set this
979 * function must not do any input validation (since the state update is
980 * incomplete and hence likely inconsistent). Instead any such input
981 * validation must be done in the various atomic_check callbacks.
982 *
983 * RETURNS:
984 *
985 * 0 if the property has been found, -EINVAL if the property isn't
986 * implemented by the driver (which shouldn't ever happen, the core only
987 * asks for properties attached to this connector). No other validation
988 * is allowed by the driver. The core already checks that the property
989 * value is within the range (integer, valid enum value, ...) the driver
990 * set when registering the property.
991 */
Daniel Vetter144ecb92014-10-27 20:28:44 +0100992 int (*atomic_set_property)(struct drm_connector *connector,
993 struct drm_connector_state *state,
994 struct drm_property *property,
995 uint64_t val);
Daniel Vetter88548632015-12-04 09:45:48 +0100996
997 /**
998 * @atomic_get_property:
999 *
1000 * Reads out the decoded driver-private property. This is used to
Daniel Vetterc6b0ca32015-12-04 09:46:01 +01001001 * implement the GETCONNECTOR IOCTL.
Daniel Vetter88548632015-12-04 09:45:48 +01001002 *
1003 * Do not call this function directly, use
1004 * drm_atomic_connector_get_property() instead.
1005 *
1006 * This callback is optional if the driver does not support any
1007 * driver-private atomic properties.
1008 *
1009 * RETURNS:
1010 *
1011 * 0 on success, -EINVAL if the property isn't implemented by the
1012 * driver (which shouldn't ever happen, the core only asks for
1013 * properties attached to this connector).
1014 */
Rob Clarkac9c9252014-12-18 16:01:47 -05001015 int (*atomic_get_property)(struct drm_connector *connector,
1016 const struct drm_connector_state *state,
1017 struct drm_property *property,
1018 uint64_t *val);
Dave Airlief453ba02008-11-07 14:05:41 -08001019};
1020
Jesse Barnes6c3db922011-11-07 12:03:16 -08001021/**
Daniel Vetter3bf04012014-10-27 16:54:27 +01001022 * struct drm_encoder_funcs - encoder controls
Jesse Barnes6c3db922011-11-07 12:03:16 -08001023 *
1024 * Encoders sit between CRTCs and connectors.
1025 */
Dave Airlief453ba02008-11-07 14:05:41 -08001026struct drm_encoder_funcs {
Daniel Vetter88548632015-12-04 09:45:48 +01001027 /**
1028 * @reset:
1029 *
1030 * Reset encoder hardware and software state to off. This function isn't
1031 * called by the core directly, only through drm_mode_config_reset().
1032 * It's not a helper hook only for historical reasons.
1033 */
Chris Wilsoneb033552011-01-24 15:11:08 +00001034 void (*reset)(struct drm_encoder *encoder);
Daniel Vetter88548632015-12-04 09:45:48 +01001035
1036 /**
1037 * @destroy:
1038 *
1039 * Clean up encoder resources. This is only called at driver unload time
1040 * through drm_mode_config_cleanup() since an encoder cannot be
1041 * hotplugged in DRM.
1042 */
Dave Airlief453ba02008-11-07 14:05:41 -08001043 void (*destroy)(struct drm_encoder *encoder);
Benjamin Gaignard79190ea2016-06-21 16:37:09 +02001044
1045 /**
1046 * @late_register:
1047 *
1048 * This optional hook can be used to register additional userspace
1049 * interfaces attached to the encoder like debugfs interfaces.
1050 * It is called late in the driver load sequence from drm_dev_register().
1051 * Everything added from this callback should be unregistered in
1052 * the early_unregister callback.
1053 *
1054 * Returns:
1055 *
1056 * 0 on success, or a negative error code on failure.
1057 */
1058 int (*late_register)(struct drm_encoder *encoder);
1059
1060 /**
1061 * @early_unregister:
1062 *
1063 * This optional hook should be used to unregister the additional
1064 * userspace interfaces attached to the encoder from
1065 * late_unregister(). It is called from drm_dev_unregister(),
1066 * early in the driver unload sequence to disable userspace access
1067 * before data structures are torndown.
1068 */
1069 void (*early_unregister)(struct drm_encoder *encoder);
Dave Airlief453ba02008-11-07 14:05:41 -08001070};
1071
Ben Skeggsafe887d2012-01-12 16:00:57 +10001072#define DRM_CONNECTOR_MAX_ENCODER 3
Dave Airlief453ba02008-11-07 14:05:41 -08001073
1074/**
Daniel Vetter3bf04012014-10-27 16:54:27 +01001075 * struct drm_encoder - central DRM encoder structure
Jesse Barnesdb3e4492011-11-07 12:03:17 -08001076 * @dev: parent DRM device
1077 * @head: list management
1078 * @base: base KMS object
Daniel Vetterac3ba4a2016-05-31 23:11:10 +02001079 * @name: human readable name, can be overwritten by the driver
Daniel Vetter62cacc72016-08-12 22:48:37 +02001080 * @encoder_type: one of the DRM_MODE_ENCODER_<foo> types in drm_mode.h
Jesse Barnesdb3e4492011-11-07 12:03:17 -08001081 * @possible_crtcs: bitmask of potential CRTC bindings
1082 * @possible_clones: bitmask of potential sibling encoders for cloning
1083 * @crtc: currently bound CRTC
Sean Paul3b336ec2013-08-14 16:47:37 -04001084 * @bridge: bridge associated to the encoder
Jesse Barnesdb3e4492011-11-07 12:03:17 -08001085 * @funcs: control functions
1086 * @helper_private: mid-layer private data
1087 *
1088 * CRTCs drive pixels to encoders, which convert them into signals
1089 * appropriate for a given connector or set of connectors.
Dave Airlief453ba02008-11-07 14:05:41 -08001090 */
1091struct drm_encoder {
1092 struct drm_device *dev;
1093 struct list_head head;
1094
1095 struct drm_mode_object base;
Jani Nikulae5748942014-05-14 16:58:20 +03001096 char *name;
Dave Airlief453ba02008-11-07 14:05:41 -08001097 int encoder_type;
Chris Wilson490d3d12016-05-27 20:05:00 +01001098
Daniel Vetter96094082016-07-15 21:47:59 +02001099 /**
1100 * @index: Position inside the mode_config.list, can be used as an array
1101 * index. It is invariant over the lifetime of the encoder.
1102 */
Chris Wilson490d3d12016-05-27 20:05:00 +01001103 unsigned index;
1104
Dave Airlief453ba02008-11-07 14:05:41 -08001105 uint32_t possible_crtcs;
1106 uint32_t possible_clones;
1107
1108 struct drm_crtc *crtc;
Sean Paul3b336ec2013-08-14 16:47:37 -04001109 struct drm_bridge *bridge;
Dave Airlief453ba02008-11-07 14:05:41 -08001110 const struct drm_encoder_funcs *funcs;
Daniel Vetter4490d4c2015-12-04 09:45:45 +01001111 const struct drm_encoder_helper_funcs *helper_private;
Dave Airlief453ba02008-11-07 14:05:41 -08001112};
1113
Dave Airlieeb1f8e42010-05-07 06:42:51 +00001114/* should we poll this connector for connects and disconnects */
1115/* hot plug detectable */
1116#define DRM_CONNECTOR_POLL_HPD (1 << 0)
1117/* poll for connections */
1118#define DRM_CONNECTOR_POLL_CONNECT (1 << 1)
1119/* can cleanly poll for disconnections without flickering the screen */
1120/* DACs should rarely do this without a lot of testing */
1121#define DRM_CONNECTOR_POLL_DISCONNECT (1 << 2)
1122
Wu Fengguang76adaa342011-09-05 14:23:20 +08001123#define MAX_ELD_BYTES 128
1124
Dave Airlief453ba02008-11-07 14:05:41 -08001125/**
Daniel Vetter3bf04012014-10-27 16:54:27 +01001126 * struct drm_connector - central DRM connector control structure
Jesse Barnes72252542011-11-07 12:03:18 -08001127 * @dev: parent DRM device
1128 * @kdev: kernel device for sysfs attributes
1129 * @attr: sysfs attributes
1130 * @head: list management
1131 * @base: base KMS object
Daniel Vetterac3ba4a2016-05-31 23:11:10 +02001132 * @name: human readable name, can be overwritten by the driver
Daniel Vetter62cacc72016-08-12 22:48:37 +02001133 * @connector_type: one of the DRM_MODE_CONNECTOR_<foo> types from drm_mode.h
Jesse Barnes72252542011-11-07 12:03:18 -08001134 * @connector_type_id: index into connector type enum
Dave Airlief453ba02008-11-07 14:05:41 -08001135 * @interlace_allowed: can this connector handle interlaced modes?
1136 * @doublescan_allowed: can this connector handle doublescan?
Daniel Vetter2c0c33d2014-10-27 20:19:38 +01001137 * @stereo_allowed: can this connector handle stereo modes?
Chris Wilson40daac62016-06-15 13:17:48 +01001138 * @registered: is this connector exposed (registered) with userspace?
Jesse Barnes72252542011-11-07 12:03:18 -08001139 * @modes: modes available on this connector (from fill_modes() + user)
1140 * @status: one of the drm_connector_status enums (connected, not, or unknown)
1141 * @probed_modes: list of modes derived directly from the display
1142 * @display_info: information about attached display (e.g. from EDID)
Dave Airlief453ba02008-11-07 14:05:41 -08001143 * @funcs: connector control functions
Jesse Barnes72252542011-11-07 12:03:18 -08001144 * @edid_blob_ptr: DRM property containing EDID if present
Paulo Zanoni7e3bdf42012-05-15 18:09:01 -03001145 * @properties: property tracking for this connector
Daniel Vetter62cacc72016-08-12 22:48:37 +02001146 * @polled: a DRM_CONNECTOR_POLL_<foo> value for core driven polling
Jesse Barnes72252542011-11-07 12:03:18 -08001147 * @dpms: current dpms state
1148 * @helper_private: mid-layer private data
Daniel Vetter2c0c33d2014-10-27 20:19:38 +01001149 * @cmdline_mode: mode line parsed from the kernel cmdline for this connector
Daniel Vetter62cacc72016-08-12 22:48:37 +02001150 * @force: a DRM_FORCE_<foo> state for forced mode sets
Daniel Vetter2c0c33d2014-10-27 20:19:38 +01001151 * @override_edid: has the EDID been overwritten through debugfs for testing?
Jesse Barnes72252542011-11-07 12:03:18 -08001152 * @encoder_ids: valid encoders for this connector
1153 * @encoder: encoder driving this connector, if any
1154 * @eld: EDID-like data, if present
1155 * @dvi_dual: dual link DVI, if found
1156 * @max_tmds_clock: max clock rate, if found
1157 * @latency_present: AV delay info from ELD, if found
1158 * @video_latency: video latency info from ELD, if found
1159 * @audio_latency: audio latency info from ELD, if found
1160 * @null_edid_counter: track sinks that give us all zeros for the EDID
Daniel Vetter2c0c33d2014-10-27 20:19:38 +01001161 * @bad_edid_counter: track sinks that give us an EDID with invalid checksum
Daniel Vetterac6f2e22015-05-08 16:15:41 +02001162 * @edid_corrupt: indicates whether the last read EDID was corrupt
Daniel Vetter2c0c33d2014-10-27 20:19:38 +01001163 * @debugfs_entry: debugfs directory for this connector
Daniel Vetter144ecb92014-10-27 20:28:44 +01001164 * @state: current atomic state for this connector
Dave Airlie40d9b042014-10-20 16:29:33 +10001165 * @has_tile: is this connector connected to a tiled monitor
1166 * @tile_group: tile group for the connected monitor
1167 * @tile_is_single_monitor: whether the tile is one monitor housing
1168 * @num_h_tile: number of horizontal tiles in the tile group
1169 * @num_v_tile: number of vertical tiles in the tile group
1170 * @tile_h_loc: horizontal location of this tile
1171 * @tile_v_loc: vertical location of this tile
1172 * @tile_h_size: horizontal size of this tile.
1173 * @tile_v_size: vertical size of this tile.
Dave Airlief453ba02008-11-07 14:05:41 -08001174 *
1175 * Each connector may be connected to one or more CRTCs, or may be clonable by
1176 * another connector if they can share a CRTC. Each connector also has a specific
1177 * position in the broader display (referred to as a 'screen' though it could
1178 * span multiple monitors).
1179 */
1180struct drm_connector {
1181 struct drm_device *dev;
Dave Airlie5bdebb12013-10-11 14:07:25 +10001182 struct device *kdev;
Dave Airlief453ba02008-11-07 14:05:41 -08001183 struct device_attribute *attr;
1184 struct list_head head;
1185
1186 struct drm_mode_object base;
1187
Jani Nikula2abdd312014-05-14 16:58:19 +03001188 char *name;
Daniel Vetter69425592016-07-19 18:25:01 +02001189
1190 /**
1191 * @index: Compacted connector index, which matches the position inside
1192 * the mode_config.list for drivers not supporting hot-add/removing. Can
1193 * be used as an array index. It is invariant over the lifetime of the
1194 * connector.
1195 */
1196 unsigned index;
1197
Dave Airlief453ba02008-11-07 14:05:41 -08001198 int connector_type;
1199 int connector_type_id;
1200 bool interlace_allowed;
1201 bool doublescan_allowed;
Damien Lespiau560a0672013-09-25 16:45:29 +01001202 bool stereo_allowed;
Chris Wilson40daac62016-06-15 13:17:48 +01001203 bool registered;
Dave Airlief453ba02008-11-07 14:05:41 -08001204 struct list_head modes; /* list of modes on this connector */
1205
Dave Airlief453ba02008-11-07 14:05:41 -08001206 enum drm_connector_status status;
1207
1208 /* these are modes added by probing with DDC or the BIOS */
1209 struct list_head probed_modes;
1210
1211 struct drm_display_info display_info;
1212 const struct drm_connector_funcs *funcs;
1213
Dave Airlief453ba02008-11-07 14:05:41 -08001214 struct drm_property_blob *edid_blob_ptr;
Paulo Zanoni7e3bdf42012-05-15 18:09:01 -03001215 struct drm_object_properties properties;
Dave Airlief453ba02008-11-07 14:05:41 -08001216
Daniel Vetterac3ba4a2016-05-31 23:11:10 +02001217 /**
1218 * @path_blob_ptr:
1219 *
1220 * DRM blob property data for the DP MST path property.
1221 */
Dave Airlie43aba7e2014-06-05 14:01:31 +10001222 struct drm_property_blob *path_blob_ptr;
1223
Daniel Vetterac3ba4a2016-05-31 23:11:10 +02001224 /**
1225 * @tile_blob_ptr:
1226 *
1227 * DRM blob property data for the tile property (used mostly by DP MST).
1228 * This is meant for screens which are driven through separate display
1229 * pipelines represented by &drm_crtc, which might not be running with
1230 * genlocked clocks. For tiled panels which are genlocked, like
1231 * dual-link LVDS or dual-link DSI, the driver should try to not expose
1232 * the tiling and virtualize both &drm_crtc and &drm_plane if needed.
1233 */
Dave Airlie6f134d72014-10-20 16:30:50 +10001234 struct drm_property_blob *tile_blob_ptr;
1235
Dave Airlieeb1f8e42010-05-07 06:42:51 +00001236 uint8_t polled; /* DRM_CONNECTOR_POLL_* */
1237
Keith Packardc9fb15f2009-05-30 20:42:28 -07001238 /* requested DPMS state */
1239 int dpms;
1240
Daniel Vetter4490d4c2015-12-04 09:45:45 +01001241 const struct drm_connector_helper_funcs *helper_private;
Dave Airlief453ba02008-11-07 14:05:41 -08001242
Dave Airlied50ba252009-09-23 14:44:08 +10001243 /* forced on connector */
Chris Wilsoneaf99c72014-08-06 10:08:32 +02001244 struct drm_cmdline_mode cmdline_mode;
Dave Airlied50ba252009-09-23 14:44:08 +10001245 enum drm_connector_force force;
Thomas Wood4cf2b282014-06-18 17:52:33 +01001246 bool override_edid;
Dave Airlief453ba02008-11-07 14:05:41 -08001247 uint32_t encoder_ids[DRM_CONNECTOR_MAX_ENCODER];
Dave Airlief453ba02008-11-07 14:05:41 -08001248 struct drm_encoder *encoder; /* currently active encoder */
Dave Airlie4a9a8b72011-06-14 06:13:55 +00001249
Wu Fengguang76adaa342011-09-05 14:23:20 +08001250 /* EDID bits */
1251 uint8_t eld[MAX_ELD_BYTES];
1252 bool dvi_dual;
1253 int max_tmds_clock; /* in MHz */
1254 bool latency_present[2];
1255 int video_latency[2]; /* [0]: progressive, [1]: interlaced */
1256 int audio_latency[2];
Dave Airlie4a9a8b72011-06-14 06:13:55 +00001257 int null_edid_counter; /* needed to workaround some HW bugs where we get all 0s */
Jerome Glisse0b2443e2012-08-09 11:25:51 -04001258 unsigned bad_edid_counter;
Thomas Wood30f65702014-06-18 17:52:32 +01001259
Todd Previte6ba2bd32015-04-21 11:09:41 -07001260 /* Flag for raw EDID header corruption - used in Displayport
1261 * compliance testing - * Displayport Link CTS Core 1.2 rev1.1 4.2.2.6
1262 */
1263 bool edid_corrupt;
1264
Thomas Wood30f65702014-06-18 17:52:32 +01001265 struct dentry *debugfs_entry;
Daniel Vetter144ecb92014-10-27 20:28:44 +01001266
1267 struct drm_connector_state *state;
Dave Airlie40d9b042014-10-20 16:29:33 +10001268
1269 /* DisplayID bits */
1270 bool has_tile;
1271 struct drm_tile_group *tile_group;
1272 bool tile_is_single_monitor;
1273
1274 uint8_t num_h_tile, num_v_tile;
1275 uint8_t tile_h_loc, tile_v_loc;
1276 uint16_t tile_h_size, tile_v_size;
Dave Airlief453ba02008-11-07 14:05:41 -08001277};
1278
1279/**
Daniel Vetter144ecb92014-10-27 20:28:44 +01001280 * struct drm_plane_state - mutable plane state
Daniel Vetter07cc0ef2014-11-27 15:49:39 +01001281 * @plane: backpointer to the plane
Daniel Vetter144ecb92014-10-27 20:28:44 +01001282 * @crtc: currently bound CRTC, NULL if disabled
Daniel Vettercc4ceb42014-07-25 21:30:38 +02001283 * @fb: currently bound framebuffer
Daniel Vettere2330f02014-10-29 11:34:56 +01001284 * @fence: optional fence to wait for before scanning out @fb
Daniel Vetter144ecb92014-10-27 20:28:44 +01001285 * @crtc_x: left position of visible portion of plane on crtc
1286 * @crtc_y: upper position of visible portion of plane on crtc
1287 * @crtc_w: width of visible portion of plane on crtc
1288 * @crtc_h: height of visible portion of plane on crtc
1289 * @src_x: left position of visible portion of plane within
1290 * plane (in 16.16)
1291 * @src_y: upper position of visible portion of plane within
1292 * plane (in 16.16)
1293 * @src_w: width of visible portion of plane (in 16.16)
1294 * @src_h: height of visible portion of plane (in 16.16)
Daniel Vetterac3ba4a2016-05-31 23:11:10 +02001295 * @rotation: rotation of the plane
Marek Szyprowski44d1240d2016-06-13 11:11:26 +02001296 * @zpos: priority of the given plane on crtc (optional)
1297 * @normalized_zpos: normalized value of zpos: unique, range from 0 to N-1
1298 * where N is the number of active planes for given crtc
Ville Syrjäläd7da8242016-07-26 19:06:57 +03001299 * @src: clipped source coordinates of the plane (in 16.16)
1300 * @dst: clipped destination coordinates of the plane
1301 * @visible: visibility of the plane
Daniel Vetter144ecb92014-10-27 20:28:44 +01001302 * @state: backpointer to global drm_atomic_state
1303 */
1304struct drm_plane_state {
Daniel Vetter07cc0ef2014-11-27 15:49:39 +01001305 struct drm_plane *plane;
1306
Rob Clark6ddd3882014-11-21 15:28:31 -05001307 struct drm_crtc *crtc; /* do not write directly, use drm_atomic_set_crtc_for_plane() */
1308 struct drm_framebuffer *fb; /* do not write directly, use drm_atomic_set_fb_for_plane() */
Daniel Vettere2330f02014-10-29 11:34:56 +01001309 struct fence *fence;
Daniel Vetter144ecb92014-10-27 20:28:44 +01001310
1311 /* Signed dest location allows it to be partially off screen */
1312 int32_t crtc_x, crtc_y;
1313 uint32_t crtc_w, crtc_h;
1314
1315 /* Source values are 16.16 fixed point */
1316 uint32_t src_x, src_y;
1317 uint32_t src_h, src_w;
1318
Matt Roper1da30622015-01-21 16:35:40 -08001319 /* Plane rotation */
1320 unsigned int rotation;
1321
Marek Szyprowski44d1240d2016-06-13 11:11:26 +02001322 /* Plane zpos */
1323 unsigned int zpos;
1324 unsigned int normalized_zpos;
1325
Ville Syrjäläd7da8242016-07-26 19:06:57 +03001326 /* Clipped coordinates */
1327 struct drm_rect src, dst;
1328
1329 /*
1330 * Is the plane actually visible? Can be false even
1331 * if fb!=NULL and crtc!=NULL, due to clipping.
1332 */
1333 bool visible;
1334
Daniel Vetter144ecb92014-10-27 20:28:44 +01001335 struct drm_atomic_state *state;
1336};
1337
1338
1339/**
Daniel Vetter3bf04012014-10-27 16:54:27 +01001340 * struct drm_plane_funcs - driver plane control functions
Jesse Barnes8cf5c912011-11-14 14:51:27 -08001341 */
1342struct drm_plane_funcs {
Daniel Vetter88548632015-12-04 09:45:48 +01001343 /**
1344 * @update_plane:
1345 *
1346 * This is the legacy entry point to enable and configure the plane for
1347 * the given CRTC and framebuffer. It is never called to disable the
1348 * plane, i.e. the passed-in crtc and fb paramters are never NULL.
1349 *
1350 * The source rectangle in frame buffer memory coordinates is given by
1351 * the src_x, src_y, src_w and src_h parameters (as 16.16 fixed point
1352 * values). Devices that don't support subpixel plane coordinates can
1353 * ignore the fractional part.
1354 *
1355 * The destination rectangle in CRTC coordinates is given by the
1356 * crtc_x, crtc_y, crtc_w and crtc_h parameters (as integer values).
1357 * Devices scale the source rectangle to the destination rectangle. If
1358 * scaling is not supported, and the source rectangle size doesn't match
1359 * the destination rectangle size, the driver must return a
1360 * -<errorname>EINVAL</errorname> error.
1361 *
1362 * Drivers implementing atomic modeset should use
1363 * drm_atomic_helper_update_plane() to implement this hook.
1364 *
1365 * RETURNS:
1366 *
1367 * 0 on success or a negative error code on failure.
1368 */
Jesse Barnes8cf5c912011-11-14 14:51:27 -08001369 int (*update_plane)(struct drm_plane *plane,
1370 struct drm_crtc *crtc, struct drm_framebuffer *fb,
1371 int crtc_x, int crtc_y,
1372 unsigned int crtc_w, unsigned int crtc_h,
1373 uint32_t src_x, uint32_t src_y,
1374 uint32_t src_w, uint32_t src_h);
Daniel Vetter88548632015-12-04 09:45:48 +01001375
1376 /**
1377 * @disable_plane:
1378 *
1379 * This is the legacy entry point to disable the plane. The DRM core
Daniel Vetterc6b0ca32015-12-04 09:46:01 +01001380 * calls this method in response to a DRM_IOCTL_MODE_SETPLANE IOCTL call
Daniel Vetter88548632015-12-04 09:45:48 +01001381 * with the frame buffer ID set to 0. Disabled planes must not be
1382 * processed by the CRTC.
1383 *
1384 * Drivers implementing atomic modeset should use
1385 * drm_atomic_helper_disable_plane() to implement this hook.
1386 *
1387 * RETURNS:
1388 *
1389 * 0 on success or a negative error code on failure.
1390 */
Jesse Barnes8cf5c912011-11-14 14:51:27 -08001391 int (*disable_plane)(struct drm_plane *plane);
Daniel Vetter88548632015-12-04 09:45:48 +01001392
1393 /**
1394 * @destroy:
1395 *
1396 * Clean up plane resources. This is only called at driver unload time
1397 * through drm_mode_config_cleanup() since a plane cannot be hotplugged
1398 * in DRM.
1399 */
Jesse Barnes8cf5c912011-11-14 14:51:27 -08001400 void (*destroy)(struct drm_plane *plane);
Daniel Vetter88548632015-12-04 09:45:48 +01001401
1402 /**
1403 * @reset:
1404 *
1405 * Reset plane hardware and software state to off. This function isn't
1406 * called by the core directly, only through drm_mode_config_reset().
1407 * It's not a helper hook only for historical reasons.
1408 *
1409 * Atomic drivers can use drm_atomic_helper_plane_reset() to reset
1410 * atomic state using this hook.
1411 */
Daniel Vetter2a0d7cf2014-07-29 15:32:37 +02001412 void (*reset)(struct drm_plane *plane);
Rob Clark4d939142012-05-17 02:23:27 -06001413
Daniel Vetter88548632015-12-04 09:45:48 +01001414 /**
1415 * @set_property:
1416 *
1417 * This is the legacy entry point to update a property attached to the
1418 * plane.
1419 *
1420 * Drivers implementing atomic modeset should use
1421 * drm_atomic_helper_plane_set_property() to implement this hook.
1422 *
1423 * This callback is optional if the driver does not support any legacy
1424 * driver-private properties.
1425 *
1426 * RETURNS:
1427 *
1428 * 0 on success or a negative error code on failure.
1429 */
Rob Clark4d939142012-05-17 02:23:27 -06001430 int (*set_property)(struct drm_plane *plane,
1431 struct drm_property *property, uint64_t val);
Daniel Vetter144ecb92014-10-27 20:28:44 +01001432
Daniel Vetter88548632015-12-04 09:45:48 +01001433 /**
1434 * @atomic_duplicate_state:
1435 *
1436 * Duplicate the current atomic state for this plane and return it.
1437 * The core and helpers gurantee that any atomic state duplicated with
1438 * this hook and still owned by the caller (i.e. not transferred to the
1439 * driver by calling ->atomic_commit() from struct
1440 * &drm_mode_config_funcs) will be cleaned up by calling the
1441 * @atomic_destroy_state hook in this structure.
1442 *
1443 * Atomic drivers which don't subclass struct &drm_plane_state should use
1444 * drm_atomic_helper_plane_duplicate_state(). Drivers that subclass the
1445 * state structure to extend it with driver-private state should use
1446 * __drm_atomic_helper_plane_duplicate_state() to make sure shared state is
1447 * duplicated in a consistent fashion across drivers.
1448 *
1449 * It is an error to call this hook before plane->state has been
1450 * initialized correctly.
1451 *
1452 * NOTE:
1453 *
1454 * If the duplicate state references refcounted resources this hook must
1455 * acquire a reference for each of them. The driver must release these
1456 * references again in @atomic_destroy_state.
1457 *
1458 * RETURNS:
1459 *
1460 * Duplicated atomic state or NULL when the allocation failed.
1461 */
Daniel Vetter144ecb92014-10-27 20:28:44 +01001462 struct drm_plane_state *(*atomic_duplicate_state)(struct drm_plane *plane);
Daniel Vetter88548632015-12-04 09:45:48 +01001463
1464 /**
1465 * @atomic_destroy_state:
1466 *
1467 * Destroy a state duplicated with @atomic_duplicate_state and release
1468 * or unreference all resources it references
1469 */
Daniel Vetter144ecb92014-10-27 20:28:44 +01001470 void (*atomic_destroy_state)(struct drm_plane *plane,
Daniel Vettercc4ceb42014-07-25 21:30:38 +02001471 struct drm_plane_state *state);
Daniel Vetter88548632015-12-04 09:45:48 +01001472
1473 /**
1474 * @atomic_set_property:
1475 *
1476 * Decode a driver-private property value and store the decoded value
1477 * into the passed-in state structure. Since the atomic core decodes all
1478 * standardized properties (even for extensions beyond the core set of
1479 * properties which might not be implemented by all drivers) this
1480 * requires drivers to subclass the state structure.
1481 *
1482 * Such driver-private properties should really only be implemented for
1483 * truly hardware/vendor specific state. Instead it is preferred to
1484 * standardize atomic extension and decode the properties used to expose
1485 * such an extension in the core.
1486 *
1487 * Do not call this function directly, use
1488 * drm_atomic_plane_set_property() instead.
1489 *
1490 * This callback is optional if the driver does not support any
1491 * driver-private atomic properties.
1492 *
1493 * NOTE:
1494 *
1495 * This function is called in the state assembly phase of atomic
1496 * modesets, which can be aborted for any reason (including on
1497 * userspace's request to just check whether a configuration would be
1498 * possible). Drivers MUST NOT touch any persistent state (hardware or
1499 * software) or data structures except the passed in @state parameter.
1500 *
1501 * Also since userspace controls in which order properties are set this
1502 * function must not do any input validation (since the state update is
1503 * incomplete and hence likely inconsistent). Instead any such input
1504 * validation must be done in the various atomic_check callbacks.
1505 *
1506 * RETURNS:
1507 *
1508 * 0 if the property has been found, -EINVAL if the property isn't
1509 * implemented by the driver (which shouldn't ever happen, the core only
1510 * asks for properties attached to this plane). No other validation is
1511 * allowed by the driver. The core already checks that the property
1512 * value is within the range (integer, valid enum value, ...) the driver
1513 * set when registering the property.
1514 */
Daniel Vetter144ecb92014-10-27 20:28:44 +01001515 int (*atomic_set_property)(struct drm_plane *plane,
1516 struct drm_plane_state *state,
1517 struct drm_property *property,
1518 uint64_t val);
Daniel Vetter88548632015-12-04 09:45:48 +01001519
1520 /**
1521 * @atomic_get_property:
1522 *
1523 * Reads out the decoded driver-private property. This is used to
Daniel Vetterc6b0ca32015-12-04 09:46:01 +01001524 * implement the GETPLANE IOCTL.
Daniel Vetter88548632015-12-04 09:45:48 +01001525 *
1526 * Do not call this function directly, use
1527 * drm_atomic_plane_get_property() instead.
1528 *
1529 * This callback is optional if the driver does not support any
1530 * driver-private atomic properties.
1531 *
1532 * RETURNS:
1533 *
1534 * 0 on success, -EINVAL if the property isn't implemented by the
1535 * driver (which should never happen, the core only asks for
1536 * properties attached to this plane).
1537 */
Rob Clarkac9c9252014-12-18 16:01:47 -05001538 int (*atomic_get_property)(struct drm_plane *plane,
1539 const struct drm_plane_state *state,
1540 struct drm_property *property,
1541 uint64_t *val);
Benjamin Gaignard79190ea2016-06-21 16:37:09 +02001542 /**
1543 * @late_register:
1544 *
1545 * This optional hook can be used to register additional userspace
1546 * interfaces attached to the plane like debugfs interfaces.
1547 * It is called late in the driver load sequence from drm_dev_register().
1548 * Everything added from this callback should be unregistered in
1549 * the early_unregister callback.
1550 *
1551 * Returns:
1552 *
1553 * 0 on success, or a negative error code on failure.
1554 */
1555 int (*late_register)(struct drm_plane *plane);
1556
1557 /**
1558 * @early_unregister:
1559 *
1560 * This optional hook should be used to unregister the additional
1561 * userspace interfaces attached to the plane from
1562 * late_unregister(). It is called from drm_dev_unregister(),
1563 * early in the driver unload sequence to disable userspace access
1564 * before data structures are torndown.
1565 */
1566 void (*early_unregister)(struct drm_plane *plane);
Jesse Barnes8cf5c912011-11-14 14:51:27 -08001567};
1568
Matt Ropere27dde32014-04-01 15:22:30 -07001569enum drm_plane_type {
1570 DRM_PLANE_TYPE_OVERLAY,
1571 DRM_PLANE_TYPE_PRIMARY,
1572 DRM_PLANE_TYPE_CURSOR,
1573};
1574
Daniel Vetter88548632015-12-04 09:45:48 +01001575
Jesse Barnes8cf5c912011-11-14 14:51:27 -08001576/**
Daniel Vetter3bf04012014-10-27 16:54:27 +01001577 * struct drm_plane - central DRM plane control structure
Jesse Barnes8cf5c912011-11-14 14:51:27 -08001578 * @dev: DRM device this plane belongs to
1579 * @head: for list management
Daniel Vetterac3ba4a2016-05-31 23:11:10 +02001580 * @name: human readable name, can be overwritten by the driver
Jesse Barnes8cf5c912011-11-14 14:51:27 -08001581 * @base: base mode object
1582 * @possible_crtcs: pipes this plane can be bound to
1583 * @format_types: array of formats supported by this plane
1584 * @format_count: number of formats supported
Laurent Pinchart7eb5f302015-03-09 10:41:07 +02001585 * @format_default: driver hasn't supplied supported formats for the plane
Jesse Barnes8cf5c912011-11-14 14:51:27 -08001586 * @crtc: currently bound CRTC
1587 * @fb: currently bound fb
Daniel Vetter2c0c33d2014-10-27 20:19:38 +01001588 * @old_fb: Temporary tracking of the old fb while a modeset is ongoing. Used by
1589 * drm_mode_set_config_internal() to implement correct refcounting.
Jesse Barnes8cf5c912011-11-14 14:51:27 -08001590 * @funcs: helper functions
Rob Clark4d939142012-05-17 02:23:27 -06001591 * @properties: property tracking for this plane
Matt Ropere27dde32014-04-01 15:22:30 -07001592 * @type: type of plane (overlay, primary, cursor)
Daniel Vetter144ecb92014-10-27 20:28:44 +01001593 * @state: current atomic state for this plane
Marek Szyprowski44d1240d2016-06-13 11:11:26 +02001594 * @zpos_property: zpos property for this plane
Daniel Vetterac3ba4a2016-05-31 23:11:10 +02001595 * @helper_private: mid-layer private data
Jesse Barnes8cf5c912011-11-14 14:51:27 -08001596 */
1597struct drm_plane {
1598 struct drm_device *dev;
1599 struct list_head head;
1600
Ville Syrjälä9f4c97a2015-12-08 18:41:54 +02001601 char *name;
1602
Daniel Vetterac3ba4a2016-05-31 23:11:10 +02001603 /**
1604 * @mutex:
1605 *
1606 * Protects modeset plane state, together with the mutex of &drm_crtc
1607 * this plane is linked to (when active, getting actived or getting
1608 * disabled).
1609 */
Daniel Vetter4d02e2d2014-11-11 10:12:00 +01001610 struct drm_modeset_lock mutex;
1611
Jesse Barnes8cf5c912011-11-14 14:51:27 -08001612 struct drm_mode_object base;
1613
1614 uint32_t possible_crtcs;
1615 uint32_t *format_types;
Thierry Reding45e37432015-08-12 16:54:28 +02001616 unsigned int format_count;
Laurent Pinchart7eb5f302015-03-09 10:41:07 +02001617 bool format_default;
Jesse Barnes8cf5c912011-11-14 14:51:27 -08001618
1619 struct drm_crtc *crtc;
1620 struct drm_framebuffer *fb;
1621
Daniel Vetter3d30a592014-07-27 13:42:42 +02001622 struct drm_framebuffer *old_fb;
1623
Jesse Barnes8cf5c912011-11-14 14:51:27 -08001624 const struct drm_plane_funcs *funcs;
Rob Clark4d939142012-05-17 02:23:27 -06001625
1626 struct drm_object_properties properties;
Matt Ropere27dde32014-04-01 15:22:30 -07001627
1628 enum drm_plane_type type;
Daniel Vetter144ecb92014-10-27 20:28:44 +01001629
Daniel Vetter96094082016-07-15 21:47:59 +02001630 /**
1631 * @index: Position inside the mode_config.list, can be used as an array
1632 * index. It is invariant over the lifetime of the plane.
1633 */
Chris Wilson490d3d12016-05-27 20:05:00 +01001634 unsigned index;
1635
Daniel Vetter4490d4c2015-12-04 09:45:45 +01001636 const struct drm_plane_helper_funcs *helper_private;
Daniel Vetterc2fcd272014-11-05 00:14:14 +01001637
Daniel Vetter144ecb92014-10-27 20:28:44 +01001638 struct drm_plane_state *state;
Marek Szyprowski44d1240d2016-06-13 11:11:26 +02001639
1640 struct drm_property *zpos_property;
Jesse Barnes8cf5c912011-11-14 14:51:27 -08001641};
1642
1643/**
Daniel Vetter3bf04012014-10-27 16:54:27 +01001644 * struct drm_bridge_funcs - drm_bridge control functions
Ajay Kumar3d3f8b12015-01-20 22:08:44 +05301645 * @attach: Called during drm_bridge_attach
Sean Paul3b336ec2013-08-14 16:47:37 -04001646 */
1647struct drm_bridge_funcs {
Ajay Kumar3d3f8b12015-01-20 22:08:44 +05301648 int (*attach)(struct drm_bridge *bridge);
Daniel Vetterda024fe2015-12-04 09:45:47 +01001649
1650 /**
1651 * @mode_fixup:
1652 *
1653 * This callback is used to validate and adjust a mode. The paramater
1654 * mode is the display mode that should be fed to the next element in
1655 * the display chain, either the final &drm_connector or the next
1656 * &drm_bridge. The parameter adjusted_mode is the input mode the bridge
1657 * requires. It can be modified by this callback and does not need to
1658 * match mode.
1659 *
1660 * This is the only hook that allows a bridge to reject a modeset. If
1661 * this function passes all other callbacks must succeed for this
1662 * configuration.
1663 *
1664 * NOTE:
1665 *
1666 * This function is called in the check phase of atomic modesets, which
1667 * can be aborted for any reason (including on userspace's request to
1668 * just check whether a configuration would be possible). Drivers MUST
1669 * NOT touch any persistent state (hardware or software) or data
Daniel Vetter88548632015-12-04 09:45:48 +01001670 * structures except the passed in @state parameter.
Daniel Vetterda024fe2015-12-04 09:45:47 +01001671 *
1672 * RETURNS:
1673 *
1674 * True if an acceptable configuration is possible, false if the modeset
1675 * operation should be rejected.
1676 */
Sean Paul3b336ec2013-08-14 16:47:37 -04001677 bool (*mode_fixup)(struct drm_bridge *bridge,
1678 const struct drm_display_mode *mode,
1679 struct drm_display_mode *adjusted_mode);
Daniel Vetterda024fe2015-12-04 09:45:47 +01001680 /**
1681 * @disable:
1682 *
1683 * This callback should disable the bridge. It is called right before
1684 * the preceding element in the display pipe is disabled. If the
1685 * preceding element is a bridge this means it's called before that
1686 * bridge's ->disable() function. If the preceding element is a
1687 * &drm_encoder it's called right before the encoder's ->disable(),
1688 * ->prepare() or ->dpms() hook from struct &drm_encoder_helper_funcs.
1689 *
1690 * The bridge can assume that the display pipe (i.e. clocks and timing
1691 * signals) feeding it is still running when this callback is called.
Laurent Pinchartc8a3b2a2016-02-26 11:51:06 +02001692 *
1693 * The disable callback is optional.
Daniel Vetterda024fe2015-12-04 09:45:47 +01001694 */
Sean Paul3b336ec2013-08-14 16:47:37 -04001695 void (*disable)(struct drm_bridge *bridge);
Daniel Vetterda024fe2015-12-04 09:45:47 +01001696
1697 /**
1698 * @post_disable:
1699 *
1700 * This callback should disable the bridge. It is called right after
1701 * the preceding element in the display pipe is disabled. If the
1702 * preceding element is a bridge this means it's called after that
1703 * bridge's ->post_disable() function. If the preceding element is a
1704 * &drm_encoder it's called right after the encoder's ->disable(),
1705 * ->prepare() or ->dpms() hook from struct &drm_encoder_helper_funcs.
1706 *
1707 * The bridge must assume that the display pipe (i.e. clocks and timing
1708 * singals) feeding it is no longer running when this callback is
1709 * called.
Laurent Pinchartc8a3b2a2016-02-26 11:51:06 +02001710 *
1711 * The post_disable callback is optional.
Daniel Vetterda024fe2015-12-04 09:45:47 +01001712 */
Sean Paul3b336ec2013-08-14 16:47:37 -04001713 void (*post_disable)(struct drm_bridge *bridge);
Daniel Vetterda024fe2015-12-04 09:45:47 +01001714
1715 /**
1716 * @mode_set:
1717 *
1718 * This callback should set the given mode on the bridge. It is called
1719 * after the ->mode_set() callback for the preceding element in the
1720 * display pipeline has been called already. The display pipe (i.e.
1721 * clocks and timing signals) is off when this function is called.
1722 */
Sean Paul3b336ec2013-08-14 16:47:37 -04001723 void (*mode_set)(struct drm_bridge *bridge,
1724 struct drm_display_mode *mode,
1725 struct drm_display_mode *adjusted_mode);
Daniel Vetterda024fe2015-12-04 09:45:47 +01001726 /**
1727 * @pre_enable:
1728 *
1729 * This callback should enable the bridge. It is called right before
1730 * the preceding element in the display pipe is enabled. If the
1731 * preceding element is a bridge this means it's called before that
1732 * bridge's ->pre_enable() function. If the preceding element is a
1733 * &drm_encoder it's called right before the encoder's ->enable(),
1734 * ->commit() or ->dpms() hook from struct &drm_encoder_helper_funcs.
1735 *
1736 * The display pipe (i.e. clocks and timing signals) feeding this bridge
1737 * will not yet be running when this callback is called. The bridge must
1738 * not enable the display link feeding the next bridge in the chain (if
1739 * there is one) when this callback is called.
Laurent Pinchartc8a3b2a2016-02-26 11:51:06 +02001740 *
1741 * The pre_enable callback is optional.
Daniel Vetterda024fe2015-12-04 09:45:47 +01001742 */
Sean Paul3b336ec2013-08-14 16:47:37 -04001743 void (*pre_enable)(struct drm_bridge *bridge);
Daniel Vetterda024fe2015-12-04 09:45:47 +01001744
1745 /**
1746 * @enable:
1747 *
1748 * This callback should enable the bridge. It is called right after
1749 * the preceding element in the display pipe is enabled. If the
1750 * preceding element is a bridge this means it's called after that
1751 * bridge's ->enable() function. If the preceding element is a
1752 * &drm_encoder it's called right after the encoder's ->enable(),
1753 * ->commit() or ->dpms() hook from struct &drm_encoder_helper_funcs.
1754 *
1755 * The bridge can assume that the display pipe (i.e. clocks and timing
1756 * signals) feeding it is running when this callback is called. This
1757 * callback must enable the display link feeding the next bridge in the
1758 * chain if there is one.
Laurent Pinchartc8a3b2a2016-02-26 11:51:06 +02001759 *
1760 * The enable callback is optional.
Daniel Vetterda024fe2015-12-04 09:45:47 +01001761 */
Sean Paul3b336ec2013-08-14 16:47:37 -04001762 void (*enable)(struct drm_bridge *bridge);
Sean Paul3b336ec2013-08-14 16:47:37 -04001763};
1764
1765/**
Daniel Vetter3bf04012014-10-27 16:54:27 +01001766 * struct drm_bridge - central DRM bridge control structure
Sean Paul3b336ec2013-08-14 16:47:37 -04001767 * @dev: DRM device this bridge belongs to
Archit Taneja862e6862015-05-21 11:03:16 +05301768 * @encoder: encoder to which this bridge is connected
1769 * @next: the next bridge in the encoder chain
Ajay Kumar3d3f8b12015-01-20 22:08:44 +05301770 * @of_node: device node pointer to the bridge
1771 * @list: to keep track of all added bridges
Sean Paul3b336ec2013-08-14 16:47:37 -04001772 * @funcs: control functions
1773 * @driver_private: pointer to the bridge driver's internal context
1774 */
1775struct drm_bridge {
1776 struct drm_device *dev;
Ajay Kumar3d3f8b12015-01-20 22:08:44 +05301777 struct drm_encoder *encoder;
Archit Taneja862e6862015-05-21 11:03:16 +05301778 struct drm_bridge *next;
Ajay Kumar3d3f8b12015-01-20 22:08:44 +05301779#ifdef CONFIG_OF
1780 struct device_node *of_node;
1781#endif
1782 struct list_head list;
Sean Paul3b336ec2013-08-14 16:47:37 -04001783
1784 const struct drm_bridge_funcs *funcs;
1785 void *driver_private;
1786};
1787
Daniel Vetter3b24f7d2016-06-08 14:19:00 +02001788/**
1789 * struct drm_crtc_commit - track modeset commits on a CRTC
1790 *
1791 * This structure is used to track pending modeset changes and atomic commit on
1792 * a per-CRTC basis. Since updating the list should never block this structure
1793 * is reference counted to allow waiters to safely wait on an event to complete,
1794 * without holding any locks.
1795 *
1796 * It has 3 different events in total to allow a fine-grained synchronization
1797 * between outstanding updates::
1798 *
1799 * atomic commit thread hardware
1800 *
1801 * write new state into hardware ----> ...
1802 * signal hw_done
1803 * switch to new state on next
1804 * ... v/hblank
1805 *
1806 * wait for buffers to show up ...
1807 *
1808 * ... send completion irq
1809 * irq handler signals flip_done
1810 * cleanup old buffers
1811 *
1812 * signal cleanup_done
1813 *
1814 * wait for flip_done <----
1815 * clean up atomic state
1816 *
1817 * The important bit to know is that cleanup_done is the terminal event, but the
1818 * ordering between flip_done and hw_done is entirely up to the specific driver
1819 * and modeset state change.
1820 *
1821 * For an implementation of how to use this look at
1822 * drm_atomic_helper_setup_commit() from the atomic helper library.
1823 */
1824struct drm_crtc_commit {
1825 /**
1826 * @crtc:
1827 *
1828 * DRM CRTC for this commit.
1829 */
1830 struct drm_crtc *crtc;
1831
1832 /**
1833 * @ref:
1834 *
1835 * Reference count for this structure. Needed to allow blocking on
1836 * completions without the risk of the completion disappearing
1837 * meanwhile.
1838 */
1839 struct kref ref;
1840
1841 /**
1842 * @flip_done:
1843 *
1844 * Will be signaled when the hardware has flipped to the new set of
1845 * buffers. Signals at the same time as when the drm event for this
1846 * commit is sent to userspace, or when an out-fence is singalled. Note
1847 * that for most hardware, in most cases this happens after @hw_done is
1848 * signalled.
1849 */
1850 struct completion flip_done;
1851
1852 /**
1853 * @hw_done:
1854 *
1855 * Will be signalled when all hw register changes for this commit have
1856 * been written out. Especially when disabling a pipe this can be much
1857 * later than than @flip_done, since that can signal already when the
1858 * screen goes black, whereas to fully shut down a pipe more register
1859 * I/O is required.
1860 *
1861 * Note that this does not need to include separately reference-counted
1862 * resources like backing storage buffer pinning, or runtime pm
1863 * management.
1864 */
1865 struct completion hw_done;
1866
1867 /**
1868 * @cleanup_done:
1869 *
1870 * Will be signalled after old buffers have been cleaned up by calling
1871 * drm_atomic_helper_cleanup_planes(). Since this can only happen after
1872 * a vblank wait completed it might be a bit later. This completion is
1873 * useful to throttle updates and avoid hardware updates getting ahead
1874 * of the buffer cleanup too much.
1875 */
1876 struct completion cleanup_done;
1877
1878 /**
1879 * @commit_entry:
1880 *
1881 * Entry on the per-CRTC commit_list. Protected by crtc->commit_lock.
1882 */
1883 struct list_head commit_entry;
1884
1885 /**
1886 * @event:
1887 *
1888 * &drm_pending_vblank_event pointer to clean up private events.
1889 */
1890 struct drm_pending_vblank_event *event;
1891};
1892
Daniel Vetterb8b53422016-06-02 00:06:33 +02001893struct __drm_planes_state {
1894 struct drm_plane *ptr;
1895 struct drm_plane_state *state;
1896};
1897
Daniel Vetter5d943aa62016-06-02 00:06:34 +02001898struct __drm_crtcs_state {
1899 struct drm_crtc *ptr;
1900 struct drm_crtc_state *state;
Daniel Vetter3b24f7d2016-06-08 14:19:00 +02001901 struct drm_crtc_commit *commit;
Daniel Vetter5d943aa62016-06-02 00:06:34 +02001902};
1903
Daniel Vetter63e83c12016-06-02 00:06:32 +02001904struct __drm_connnectors_state {
1905 struct drm_connector *ptr;
1906 struct drm_connector_state *state;
1907};
1908
Sean Paul3b336ec2013-08-14 16:47:37 -04001909/**
Rob Clark08855fa2015-03-11 10:23:09 -04001910 * struct drm_atomic_state - the global state object for atomic updates
Daniel Vettercc4ceb42014-07-25 21:30:38 +02001911 * @dev: parent DRM device
Rob Clarkd34f20d2014-12-18 16:01:56 -05001912 * @allow_modeset: allow full modeset
Daniel Vetterc6b0ca32015-12-04 09:46:01 +01001913 * @legacy_cursor_update: hint to enforce legacy cursor IOCTL semantics
Maarten Lankhorst40616a22016-03-03 10:17:39 +01001914 * @legacy_set_config: Disable conflicting encoders instead of failing with -EINVAL.
Daniel Vetterb8b53422016-06-02 00:06:33 +02001915 * @planes: pointer to array of structures with per-plane data
Daniel Vettercc4ceb42014-07-25 21:30:38 +02001916 * @crtcs: pointer to array of CRTC pointers
Daniel Vetterf52b69f12014-11-19 18:38:08 +01001917 * @num_connector: size of the @connectors and @connector_states arrays
Daniel Vetter63e83c12016-06-02 00:06:32 +02001918 * @connectors: pointer to array of structures with per-connector data
Daniel Vettercc4ceb42014-07-25 21:30:38 +02001919 * @acquire_ctx: acquire context for this atomic modeset state update
1920 */
1921struct drm_atomic_state {
1922 struct drm_device *dev;
Rob Clarkd34f20d2014-12-18 16:01:56 -05001923 bool allow_modeset : 1;
Daniel Vetterf02ad902015-01-22 16:36:23 +01001924 bool legacy_cursor_update : 1;
Maarten Lankhorst40616a22016-03-03 10:17:39 +01001925 bool legacy_set_config : 1;
Daniel Vetterb8b53422016-06-02 00:06:33 +02001926 struct __drm_planes_state *planes;
Daniel Vetter5d943aa62016-06-02 00:06:34 +02001927 struct __drm_crtcs_state *crtcs;
Daniel Vetterf52b69f12014-11-19 18:38:08 +01001928 int num_connector;
Daniel Vetter63e83c12016-06-02 00:06:32 +02001929 struct __drm_connnectors_state *connectors;
Daniel Vettercc4ceb42014-07-25 21:30:38 +02001930
1931 struct drm_modeset_acquire_ctx *acquire_ctx;
Daniel Vetter3b24f7d2016-06-08 14:19:00 +02001932
1933 /**
1934 * @commit_work:
1935 *
1936 * Work item which can be used by the driver or helpers to execute the
1937 * commit without blocking.
1938 */
1939 struct work_struct commit_work;
Daniel Vettercc4ceb42014-07-25 21:30:38 +02001940};
1941
1942
1943/**
Daniel Vetter3bf04012014-10-27 16:54:27 +01001944 * struct drm_mode_set - new values for a CRTC config change
Jesse Barnesef273512011-11-07 12:03:19 -08001945 * @fb: framebuffer to use for new config
1946 * @crtc: CRTC whose configuration we're about to change
1947 * @mode: mode timings to use
1948 * @x: position of this CRTC relative to @fb
1949 * @y: position of this CRTC relative to @fb
1950 * @connectors: array of connectors to drive with this CRTC if possible
1951 * @num_connectors: size of @connectors array
Dave Airlief453ba02008-11-07 14:05:41 -08001952 *
1953 * Represents a single crtc the connectors that it drives with what mode
1954 * and from which framebuffer it scans out from.
1955 *
1956 * This is used to set modes.
1957 */
1958struct drm_mode_set {
Dave Airlief453ba02008-11-07 14:05:41 -08001959 struct drm_framebuffer *fb;
1960 struct drm_crtc *crtc;
1961 struct drm_display_mode *mode;
1962
1963 uint32_t x;
1964 uint32_t y;
1965
1966 struct drm_connector **connectors;
1967 size_t num_connectors;
1968};
1969
1970/**
Jesse Barnes550cebc2011-11-07 12:03:20 -08001971 * struct drm_mode_config_funcs - basic driver provided mode setting functions
Jesse Barnes550cebc2011-11-07 12:03:20 -08001972 *
1973 * Some global (i.e. not per-CRTC, connector, etc) mode setting functions that
1974 * involve drivers.
Dave Airlief453ba02008-11-07 14:05:41 -08001975 */
1976struct drm_mode_config_funcs {
Daniel Vetter9953f412015-12-04 09:46:02 +01001977 /**
1978 * @fb_create:
1979 *
1980 * Create a new framebuffer object. The core does basic checks on the
1981 * requested metadata, but most of that is left to the driver. See
1982 * struct &drm_mode_fb_cmd2 for details.
1983 *
Daniel Vetterd55f5322015-12-08 09:49:19 +01001984 * If the parameters are deemed valid and the backing storage objects in
1985 * the underlying memory manager all exist, then the driver allocates
1986 * a new &drm_framebuffer structure, subclassed to contain
1987 * driver-specific information (like the internal native buffer object
1988 * references). It also needs to fill out all relevant metadata, which
1989 * should be done by calling drm_helper_mode_fill_fb_struct().
1990 *
1991 * The initialization is finalized by calling drm_framebuffer_init(),
1992 * which registers the framebuffer and makes it accessible to other
1993 * threads.
1994 *
Daniel Vetter9953f412015-12-04 09:46:02 +01001995 * RETURNS:
1996 *
1997 * A new framebuffer with an initial reference count of 1 or a negative
1998 * error code encoded with ERR_PTR().
1999 */
Jesse Barnes550cebc2011-11-07 12:03:20 -08002000 struct drm_framebuffer *(*fb_create)(struct drm_device *dev,
2001 struct drm_file *file_priv,
Ville Syrjälä1eb83452015-11-11 19:11:29 +02002002 const struct drm_mode_fb_cmd2 *mode_cmd);
Daniel Vetter9953f412015-12-04 09:46:02 +01002003
2004 /**
2005 * @output_poll_changed:
2006 *
2007 * Callback used by helpers to inform the driver of output configuration
2008 * changes.
2009 *
2010 * Drivers implementing fbdev emulation with the helpers can call
2011 * drm_fb_helper_hotplug_changed from this hook to inform the fbdev
2012 * helper of output changes.
2013 *
2014 * FIXME:
2015 *
2016 * Except that there's no vtable for device-level helper callbacks
2017 * there's no reason this is a core function.
2018 */
Dave Airlieeb1f8e42010-05-07 06:42:51 +00002019 void (*output_poll_changed)(struct drm_device *dev);
Daniel Vettercc4ceb42014-07-25 21:30:38 +02002020
Daniel Vetter9953f412015-12-04 09:46:02 +01002021 /**
2022 * @atomic_check:
2023 *
2024 * This is the only hook to validate an atomic modeset update. This
2025 * function must reject any modeset and state changes which the hardware
2026 * or driver doesn't support. This includes but is of course not limited
2027 * to:
2028 *
2029 * - Checking that the modes, framebuffers, scaling and placement
2030 * requirements and so on are within the limits of the hardware.
2031 *
2032 * - Checking that any hidden shared resources are not oversubscribed.
2033 * This can be shared PLLs, shared lanes, overall memory bandwidth,
2034 * display fifo space (where shared between planes or maybe even
2035 * CRTCs).
2036 *
2037 * - Checking that virtualized resources exported to userspace are not
2038 * oversubscribed. For various reasons it can make sense to expose
2039 * more planes, crtcs or encoders than which are physically there. One
2040 * example is dual-pipe operations (which generally should be hidden
2041 * from userspace if when lockstepped in hardware, exposed otherwise),
2042 * where a plane might need 1 hardware plane (if it's just on one
2043 * pipe), 2 hardware planes (when it spans both pipes) or maybe even
2044 * shared a hardware plane with a 2nd plane (if there's a compatible
2045 * plane requested on the area handled by the other pipe).
2046 *
2047 * - Check that any transitional state is possible and that if
2048 * requested, the update can indeed be done in the vblank period
2049 * without temporarily disabling some functions.
2050 *
2051 * - Check any other constraints the driver or hardware might have.
2052 *
2053 * - This callback also needs to correctly fill out the &drm_crtc_state
2054 * in this update to make sure that drm_atomic_crtc_needs_modeset()
2055 * reflects the nature of the possible update and returns true if and
2056 * only if the update cannot be applied without tearing within one
2057 * vblank on that CRTC. The core uses that information to reject
2058 * updates which require a full modeset (i.e. blanking the screen, or
2059 * at least pausing updates for a substantial amount of time) if
2060 * userspace has disallowed that in its request.
2061 *
2062 * - The driver also does not need to repeat basic input validation
2063 * like done for the corresponding legacy entry points. The core does
2064 * that before calling this hook.
2065 *
2066 * See the documentation of @atomic_commit for an exhaustive list of
2067 * error conditions which don't have to be checked at the
2068 * ->atomic_check() stage?
2069 *
2070 * See the documentation for struct &drm_atomic_state for how exactly
2071 * an atomic modeset update is described.
2072 *
2073 * Drivers using the atomic helpers can implement this hook using
2074 * drm_atomic_helper_check(), or one of the exported sub-functions of
2075 * it.
2076 *
2077 * RETURNS:
2078 *
2079 * 0 on success or one of the below negative error codes:
2080 *
2081 * - -EINVAL, if any of the above constraints are violated.
2082 *
2083 * - -EDEADLK, when returned from an attempt to acquire an additional
2084 * &drm_modeset_lock through drm_modeset_lock().
2085 *
2086 * - -ENOMEM, if allocating additional state sub-structures failed due
2087 * to lack of memory.
2088 *
2089 * - -EINTR, -EAGAIN or -ERESTARTSYS, if the IOCTL should be restarted.
2090 * This can either be due to a pending signal, or because the driver
2091 * needs to completely bail out to recover from an exceptional
2092 * situation like a GPU hang. From a userspace point all errors are
2093 * treated equally.
2094 */
Daniel Vettercc4ceb42014-07-25 21:30:38 +02002095 int (*atomic_check)(struct drm_device *dev,
Daniel Vetter9953f412015-12-04 09:46:02 +01002096 struct drm_atomic_state *state);
2097
2098 /**
2099 * @atomic_commit:
2100 *
2101 * This is the only hook to commit an atomic modeset update. The core
2102 * guarantees that @atomic_check has been called successfully before
2103 * calling this function, and that nothing has been changed in the
2104 * interim.
2105 *
2106 * See the documentation for struct &drm_atomic_state for how exactly
2107 * an atomic modeset update is described.
2108 *
2109 * Drivers using the atomic helpers can implement this hook using
2110 * drm_atomic_helper_commit(), or one of the exported sub-functions of
2111 * it.
2112 *
Maarten Lankhorst286dbb82016-04-26 16:11:34 +02002113 * Nonblocking commits (as indicated with the nonblock parameter) must
Daniel Vetter9953f412015-12-04 09:46:02 +01002114 * do any preparatory work which might result in an unsuccessful commit
2115 * in the context of this callback. The only exceptions are hardware
2116 * errors resulting in -EIO. But even in that case the driver must
2117 * ensure that the display pipe is at least running, to avoid
2118 * compositors crashing when pageflips don't work. Anything else,
2119 * specifically committing the update to the hardware, should be done
2120 * without blocking the caller. For updates which do not require a
2121 * modeset this must be guaranteed.
2122 *
2123 * The driver must wait for any pending rendering to the new
2124 * framebuffers to complete before executing the flip. It should also
2125 * wait for any pending rendering from other drivers if the underlying
Maarten Lankhorst286dbb82016-04-26 16:11:34 +02002126 * buffer is a shared dma-buf. Nonblocking commits must not wait for
Daniel Vetter9953f412015-12-04 09:46:02 +01002127 * rendering in the context of this callback.
2128 *
2129 * An application can request to be notified when the atomic commit has
2130 * completed. These events are per-CRTC and can be distinguished by the
2131 * CRTC index supplied in &drm_event to userspace.
2132 *
2133 * The drm core will supply a struct &drm_event in the event
2134 * member of each CRTC's &drm_crtc_state structure. This can be handled by the
2135 * drm_crtc_send_vblank_event() function, which the driver should call on
2136 * the provided event upon completion of the atomic commit. Note that if
2137 * the driver supports vblank signalling and timestamping the vblank
2138 * counters and timestamps must agree with the ones returned from page
2139 * flip events. With the current vblank helper infrastructure this can
2140 * be achieved by holding a vblank reference while the page flip is
2141 * pending, acquired through drm_crtc_vblank_get() and released with
2142 * drm_crtc_vblank_put(). Drivers are free to implement their own vblank
2143 * counter and timestamp tracking though, e.g. if they have accurate
2144 * timestamp registers in hardware.
2145 *
2146 * NOTE:
2147 *
2148 * Drivers are not allowed to shut down any display pipe successfully
2149 * enabled through an atomic commit on their own. Doing so can result in
2150 * compositors crashing if a page flip is suddenly rejected because the
2151 * pipe is off.
2152 *
2153 * RETURNS:
2154 *
2155 * 0 on success or one of the below negative error codes:
2156 *
Maarten Lankhorst286dbb82016-04-26 16:11:34 +02002157 * - -EBUSY, if a nonblocking updated is requested and there is
Daniel Vetter9953f412015-12-04 09:46:02 +01002158 * an earlier updated pending. Drivers are allowed to support a queue
2159 * of outstanding updates, but currently no driver supports that.
2160 * Note that drivers must wait for preceding updates to complete if a
2161 * synchronous update is requested, they are not allowed to fail the
2162 * commit in that case.
2163 *
2164 * - -ENOMEM, if the driver failed to allocate memory. Specifically
2165 * this can happen when trying to pin framebuffers, which must only
2166 * be done when committing the state.
2167 *
2168 * - -ENOSPC, as a refinement of the more generic -ENOMEM to indicate
2169 * that the driver has run out of vram, iommu space or similar GPU
2170 * address space needed for framebuffer.
2171 *
2172 * - -EIO, if the hardware completely died.
2173 *
2174 * - -EINTR, -EAGAIN or -ERESTARTSYS, if the IOCTL should be restarted.
2175 * This can either be due to a pending signal, or because the driver
2176 * needs to completely bail out to recover from an exceptional
2177 * situation like a GPU hang. From a userspace point of view all errors are
2178 * treated equally.
2179 *
2180 * This list is exhaustive. Specifically this hook is not allowed to
2181 * return -EINVAL (any invalid requests should be caught in
2182 * @atomic_check) or -EDEADLK (this function must not acquire
2183 * additional modeset locks).
2184 */
Daniel Vettercc4ceb42014-07-25 21:30:38 +02002185 int (*atomic_commit)(struct drm_device *dev,
Daniel Vetter9953f412015-12-04 09:46:02 +01002186 struct drm_atomic_state *state,
Maarten Lankhorst286dbb82016-04-26 16:11:34 +02002187 bool nonblock);
Daniel Vetter9953f412015-12-04 09:46:02 +01002188
2189 /**
2190 * @atomic_state_alloc:
2191 *
2192 * This optional hook can be used by drivers that want to subclass struct
2193 * &drm_atomic_state to be able to track their own driver-private global
2194 * state easily. If this hook is implemented, drivers must also
2195 * implement @atomic_state_clear and @atomic_state_free.
2196 *
2197 * RETURNS:
2198 *
2199 * A new &drm_atomic_state on success or NULL on failure.
2200 */
Maarten Lankhorst036ef572015-05-18 10:06:40 +02002201 struct drm_atomic_state *(*atomic_state_alloc)(struct drm_device *dev);
Daniel Vetter9953f412015-12-04 09:46:02 +01002202
2203 /**
2204 * @atomic_state_clear:
2205 *
2206 * This hook must clear any driver private state duplicated into the
2207 * passed-in &drm_atomic_state. This hook is called when the caller
2208 * encountered a &drm_modeset_lock deadlock and needs to drop all
2209 * already acquired locks as part of the deadlock avoidance dance
2210 * implemented in drm_modeset_lock_backoff().
2211 *
2212 * Any duplicated state must be invalidated since a concurrent atomic
2213 * update might change it, and the drm atomic interfaces always apply
2214 * updates as relative changes to the current state.
2215 *
2216 * Drivers that implement this must call drm_atomic_state_default_clear()
2217 * to clear common state.
2218 */
Maarten Lankhorst036ef572015-05-18 10:06:40 +02002219 void (*atomic_state_clear)(struct drm_atomic_state *state);
Daniel Vetter9953f412015-12-04 09:46:02 +01002220
2221 /**
2222 * @atomic_state_free:
2223 *
2224 * This hook needs driver private resources and the &drm_atomic_state
2225 * itself. Note that the core first calls drm_atomic_state_clear() to
2226 * avoid code duplicate between the clear and free hooks.
2227 *
2228 * Drivers that implement this must call drm_atomic_state_default_free()
2229 * to release common resources.
2230 */
Maarten Lankhorst036ef572015-05-18 10:06:40 +02002231 void (*atomic_state_free)(struct drm_atomic_state *state);
Dave Airlief453ba02008-11-07 14:05:41 -08002232};
2233
Jesse Barnesc1aaca22011-11-07 12:03:21 -08002234/**
Daniel Vetter2c0c33d2014-10-27 20:19:38 +01002235 * struct drm_mode_config - Mode configuration control structure
Jesse Barnesa62c93d2011-11-07 12:03:22 -08002236 * @mutex: mutex protecting KMS related lists and structures
Daniel Vetter2c0c33d2014-10-27 20:19:38 +01002237 * @connection_mutex: ww mutex protecting connector state and routing
2238 * @acquire_ctx: global implicit acquire context used by atomic drivers for
Daniel Vetterc6b0ca32015-12-04 09:46:01 +01002239 * legacy IOCTLs
Daniel Vetter2c0c33d2014-10-27 20:19:38 +01002240 * @fb_lock: mutex to protect fb state and lists
Jesse Barnesa62c93d2011-11-07 12:03:22 -08002241 * @num_fb: number of fbs available
2242 * @fb_list: list of framebuffers available
Jesse Barnesa62c93d2011-11-07 12:03:22 -08002243 * @num_encoder: number of encoders on this device
2244 * @encoder_list: list of encoder objects
Daniel Vetter2c0c33d2014-10-27 20:19:38 +01002245 * @num_overlay_plane: number of overlay planes on this device
2246 * @num_total_plane: number of universal (i.e. with primary/curso) planes on this device
2247 * @plane_list: list of plane objects
Jesse Barnesa62c93d2011-11-07 12:03:22 -08002248 * @num_crtc: number of CRTCs on this device
2249 * @crtc_list: list of CRTC objects
Daniel Vetter2c0c33d2014-10-27 20:19:38 +01002250 * @property_list: list of property objects
Jesse Barnesa62c93d2011-11-07 12:03:22 -08002251 * @min_width: minimum pixel width on this device
2252 * @min_height: minimum pixel height on this device
2253 * @max_width: maximum pixel width on this device
2254 * @max_height: maximum pixel height on this device
2255 * @funcs: core driver provided mode setting functions
2256 * @fb_base: base address of the framebuffer
Daniel Vetter2c0c33d2014-10-27 20:19:38 +01002257 * @poll_enabled: track polling support for this device
2258 * @poll_running: track polling status for this device
Daniel Vetterac3ba4a2016-05-31 23:11:10 +02002259 * @delayed_event: track delayed poll uevent deliver for this device
Jesse Barnesa62c93d2011-11-07 12:03:22 -08002260 * @output_poll_work: delayed work for polling in process context
Daniel Vetter2c0c33d2014-10-27 20:19:38 +01002261 * @property_blob_list: list of all the blob property objects
Daniel Stone8fb6e7a2015-04-20 19:22:54 +01002262 * @blob_lock: mutex for blob property allocation and management
Jesse Barnesa62c93d2011-11-07 12:03:22 -08002263 * @*_property: core property tracking
Daniel Vetter2c0c33d2014-10-27 20:19:38 +01002264 * @preferred_depth: preferred RBG pixel depth, used by fb helpers
2265 * @prefer_shadow: hint to userspace to prefer shadow-fb rendering
Daniel Vetter2c0c33d2014-10-27 20:19:38 +01002266 * @cursor_width: hint to userspace for max cursor width
2267 * @cursor_height: hint to userspace for max cursor height
Daniel Vetter9f2a7952016-06-08 14:19:02 +02002268 * @helper_private: mid-layer private data
Dave Airlief453ba02008-11-07 14:05:41 -08002269 *
Jesse Barnesa62c93d2011-11-07 12:03:22 -08002270 * Core mode resource tracking structure. All CRTC, encoders, and connectors
2271 * enumerated by the driver are added here, as are global properties. Some
2272 * global restrictions are also here, e.g. dimension restrictions.
Dave Airlief453ba02008-11-07 14:05:41 -08002273 */
2274struct drm_mode_config {
Jesse Barnesad2563c2009-01-19 17:21:45 +10002275 struct mutex mutex; /* protects configuration (mode lists etc.) */
Rob Clark51fd3712013-11-19 12:10:12 -05002276 struct drm_modeset_lock connection_mutex; /* protects connector->encoder and encoder->crtc links */
2277 struct drm_modeset_acquire_ctx *acquire_ctx; /* for legacy _lock_all() / _unlock_all() */
Daniel Vetterac3ba4a2016-05-31 23:11:10 +02002278
2279 /**
2280 * @idr_mutex:
2281 *
2282 * Mutex for KMS ID allocation and management. Protects both @crtc_idr
2283 * and @tile_idr.
2284 */
2285 struct mutex idr_mutex;
2286
2287 /**
2288 * @crtc_idr:
2289 *
2290 * Main KMS ID tracking object. Use this idr for all IDs, fb, crtc,
2291 * connector, modes - just makes life easier to have only one.
2292 */
2293 struct idr crtc_idr;
2294
2295 /**
2296 * @tile_idr:
2297 *
2298 * Use this idr for allocating new IDs for tiled sinks like use in some
2299 * high-res DP MST screens.
2300 */
2301 struct idr tile_idr;
Daniel Vetter4b096ac2012-12-10 21:19:18 +01002302
Daniel Vetter2c0c33d2014-10-27 20:19:38 +01002303 struct mutex fb_lock; /* proctects global and per-file fb lists */
Dave Airlief453ba02008-11-07 14:05:41 -08002304 int num_fb;
2305 struct list_head fb_list;
Daniel Vetter4b096ac2012-12-10 21:19:18 +01002306
Daniel Vetter96094082016-07-15 21:47:59 +02002307 /**
2308 * @num_connector: Number of connectors on this device.
2309 */
Dave Airlief453ba02008-11-07 14:05:41 -08002310 int num_connector;
Daniel Vetter96094082016-07-15 21:47:59 +02002311 /**
2312 * @connector_ida: ID allocator for connector indices.
2313 */
Maarten Lankhorst5fff80b2016-02-17 08:32:05 +01002314 struct ida connector_ida;
Daniel Vetter96094082016-07-15 21:47:59 +02002315 /**
2316 * @connector_list: List of connector objects.
2317 */
Dave Airlief453ba02008-11-07 14:05:41 -08002318 struct list_head connector_list;
2319 int num_encoder;
2320 struct list_head encoder_list;
Matt Ropere27dde32014-04-01 15:22:30 -07002321
2322 /*
2323 * Track # of overlay planes separately from # of total planes. By
2324 * default we only advertise overlay planes to userspace; if userspace
2325 * sets the "universal plane" capability bit, we'll go ahead and
2326 * expose all planes.
2327 */
2328 int num_overlay_plane;
2329 int num_total_plane;
Jesse Barnes8cf5c912011-11-14 14:51:27 -08002330 struct list_head plane_list;
Dave Airlief453ba02008-11-07 14:05:41 -08002331
2332 int num_crtc;
2333 struct list_head crtc_list;
2334
2335 struct list_head property_list;
2336
Dave Airlief453ba02008-11-07 14:05:41 -08002337 int min_width, min_height;
2338 int max_width, max_height;
Laurent Pincharte6ecefa2012-05-17 13:27:23 +02002339 const struct drm_mode_config_funcs *funcs;
Benjamin Herrenschmidtd883f7f2009-02-02 16:55:45 +11002340 resource_size_t fb_base;
Dave Airlief453ba02008-11-07 14:05:41 -08002341
Dave Airlieeb1f8e42010-05-07 06:42:51 +00002342 /* output poll support */
2343 bool poll_enabled;
Daniel Vetter905bc9f2012-10-23 18:23:36 +00002344 bool poll_running;
Daniel Vetter162b6a52015-01-21 08:45:21 +01002345 bool delayed_event;
Tejun Heo991ea752010-07-20 22:09:02 +02002346 struct delayed_work output_poll_work;
Dave Airlieeb1f8e42010-05-07 06:42:51 +00002347
Daniel Stone8fb6e7a2015-04-20 19:22:54 +01002348 struct mutex blob_lock;
2349
Dave Airlief453ba02008-11-07 14:05:41 -08002350 /* pointers to standard properties */
2351 struct list_head property_blob_list;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02002352 /**
2353 * @edid_property: Default connector property to hold the EDID of the
2354 * currently connected sink, if any.
2355 */
Dave Airlief453ba02008-11-07 14:05:41 -08002356 struct drm_property *edid_property;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02002357 /**
2358 * @dpms_property: Default connector property to control the
2359 * connector's DPMS state.
2360 */
Dave Airlief453ba02008-11-07 14:05:41 -08002361 struct drm_property *dpms_property;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02002362 /**
2363 * @path_property: Default connector property to hold the DP MST path
2364 * for the port.
2365 */
Dave Airlie43aba7e2014-06-05 14:01:31 +10002366 struct drm_property *path_property;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02002367 /**
2368 * @tile_property: Default connector property to store the tile
2369 * position of a tiled screen, for sinks which need to be driven with
2370 * multiple CRTCs.
2371 */
Dave Airlie6f134d72014-10-20 16:30:50 +10002372 struct drm_property *tile_property;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02002373 /**
2374 * @plane_type_property: Default plane property to differentiate
2375 * CURSOR, PRIMARY and OVERLAY legacy uses of planes.
2376 */
Rob Clark9922ab52014-04-01 20:16:57 -04002377 struct drm_property *plane_type_property;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02002378 /**
2379 * @rotation_property: Optional property for planes or CRTCs to specifiy
2380 * rotation.
2381 */
Sonika Jindal2a297cc2014-08-05 11:26:54 +05302382 struct drm_property *rotation_property;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02002383 /**
2384 * @prop_src_x: Default atomic plane property for the plane source
2385 * position in the connected &drm_framebuffer.
2386 */
Rob Clark6b4959f2014-12-18 16:01:53 -05002387 struct drm_property *prop_src_x;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02002388 /**
2389 * @prop_src_y: Default atomic plane property for the plane source
2390 * position in the connected &drm_framebuffer.
2391 */
Rob Clark6b4959f2014-12-18 16:01:53 -05002392 struct drm_property *prop_src_y;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02002393 /**
2394 * @prop_src_w: Default atomic plane property for the plane source
2395 * position in the connected &drm_framebuffer.
2396 */
Rob Clark6b4959f2014-12-18 16:01:53 -05002397 struct drm_property *prop_src_w;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02002398 /**
2399 * @prop_src_h: Default atomic plane property for the plane source
2400 * position in the connected &drm_framebuffer.
2401 */
Rob Clark6b4959f2014-12-18 16:01:53 -05002402 struct drm_property *prop_src_h;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02002403 /**
2404 * @prop_crtc_x: Default atomic plane property for the plane destination
2405 * position in the &drm_crtc is is being shown on.
2406 */
Rob Clark6b4959f2014-12-18 16:01:53 -05002407 struct drm_property *prop_crtc_x;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02002408 /**
2409 * @prop_crtc_y: Default atomic plane property for the plane destination
2410 * position in the &drm_crtc is is being shown on.
2411 */
Rob Clark6b4959f2014-12-18 16:01:53 -05002412 struct drm_property *prop_crtc_y;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02002413 /**
2414 * @prop_crtc_w: Default atomic plane property for the plane destination
2415 * position in the &drm_crtc is is being shown on.
2416 */
Rob Clark6b4959f2014-12-18 16:01:53 -05002417 struct drm_property *prop_crtc_w;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02002418 /**
2419 * @prop_crtc_h: Default atomic plane property for the plane destination
2420 * position in the &drm_crtc is is being shown on.
2421 */
Rob Clark6b4959f2014-12-18 16:01:53 -05002422 struct drm_property *prop_crtc_h;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02002423 /**
2424 * @prop_fb_id: Default atomic plane property to specify the
2425 * &drm_framebuffer.
2426 */
Rob Clark6b4959f2014-12-18 16:01:53 -05002427 struct drm_property *prop_fb_id;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02002428 /**
2429 * @prop_crtc_id: Default atomic plane property to specify the
2430 * &drm_crtc.
2431 */
Rob Clark6b4959f2014-12-18 16:01:53 -05002432 struct drm_property *prop_crtc_id;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02002433 /**
2434 * @prop_active: Default atomic CRTC property to control the active
2435 * state, which is the simplified implementation for DPMS in atomic
2436 * drivers.
2437 */
Daniel Vettereab3bbe2015-01-22 16:36:21 +01002438 struct drm_property *prop_active;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02002439 /**
2440 * @prop_mode_id: Default atomic CRTC property to set the mode for a
2441 * CRTC. A 0 mode implies that the CRTC is entirely disabled - all
2442 * connectors must be of and active must be set to disabled, too.
2443 */
Daniel Stone955f3c32015-05-25 19:11:52 +01002444 struct drm_property *prop_mode_id;
Dave Airlief453ba02008-11-07 14:05:41 -08002445
Daniel Vetter9a6bc032016-07-15 21:48:00 +02002446 /**
2447 * @dvi_i_subconnector_property: Optional DVI-I property to
2448 * differentiate between analog or digital mode.
2449 */
Dave Airlief453ba02008-11-07 14:05:41 -08002450 struct drm_property *dvi_i_subconnector_property;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02002451 /**
2452 * @dvi_i_select_subconnector_property: Optional DVI-I property to
2453 * select between analog or digital mode.
2454 */
Dave Airlief453ba02008-11-07 14:05:41 -08002455 struct drm_property *dvi_i_select_subconnector_property;
2456
Daniel Vetter9a6bc032016-07-15 21:48:00 +02002457 /**
2458 * @tv_subconnector_property: Optional TV property to differentiate
2459 * between different TV connector types.
2460 */
Dave Airlief453ba02008-11-07 14:05:41 -08002461 struct drm_property *tv_subconnector_property;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02002462 /**
2463 * @tv_select_subconnector_property: Optional TV property to select
2464 * between different TV connector types.
2465 */
Dave Airlief453ba02008-11-07 14:05:41 -08002466 struct drm_property *tv_select_subconnector_property;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02002467 /**
2468 * @tv_mode_property: Optional TV property to select
2469 * the output TV mode.
2470 */
Dave Airlief453ba02008-11-07 14:05:41 -08002471 struct drm_property *tv_mode_property;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02002472 /**
2473 * @tv_left_margin_property: Optional TV property to set the left
2474 * margin.
2475 */
Dave Airlief453ba02008-11-07 14:05:41 -08002476 struct drm_property *tv_left_margin_property;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02002477 /**
2478 * @tv_right_margin_property: Optional TV property to set the right
2479 * margin.
2480 */
Dave Airlief453ba02008-11-07 14:05:41 -08002481 struct drm_property *tv_right_margin_property;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02002482 /**
2483 * @tv_top_margin_property: Optional TV property to set the right
2484 * margin.
2485 */
Dave Airlief453ba02008-11-07 14:05:41 -08002486 struct drm_property *tv_top_margin_property;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02002487 /**
2488 * @tv_bottom_margin_property: Optional TV property to set the right
2489 * margin.
2490 */
Dave Airlief453ba02008-11-07 14:05:41 -08002491 struct drm_property *tv_bottom_margin_property;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02002492 /**
2493 * @tv_brightness_property: Optional TV property to set the
2494 * brightness.
2495 */
Francisco Jerezb6b79022009-08-02 04:19:20 +02002496 struct drm_property *tv_brightness_property;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02002497 /**
2498 * @tv_contrast_property: Optional TV property to set the
2499 * contrast.
2500 */
Francisco Jerezb6b79022009-08-02 04:19:20 +02002501 struct drm_property *tv_contrast_property;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02002502 /**
2503 * @tv_flicker_reduction_property: Optional TV property to control the
2504 * flicker reduction mode.
2505 */
Francisco Jerezb6b79022009-08-02 04:19:20 +02002506 struct drm_property *tv_flicker_reduction_property;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02002507 /**
2508 * @tv_overscan_property: Optional TV property to control the overscan
2509 * setting.
2510 */
Francisco Jereza75f0232009-08-12 02:30:10 +02002511 struct drm_property *tv_overscan_property;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02002512 /**
2513 * @tv_saturation_property: Optional TV property to set the
2514 * saturation.
2515 */
Francisco Jereza75f0232009-08-12 02:30:10 +02002516 struct drm_property *tv_saturation_property;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02002517 /**
2518 * @tv_hue_property: Optional TV property to set the hue.
2519 */
Francisco Jereza75f0232009-08-12 02:30:10 +02002520 struct drm_property *tv_hue_property;
Dave Airlief453ba02008-11-07 14:05:41 -08002521
Daniel Vetter9a6bc032016-07-15 21:48:00 +02002522 /**
2523 * @scaling_mode_property: Optional connector property to control the
2524 * upscaling, mostly used for built-in panels.
2525 */
Dave Airlief453ba02008-11-07 14:05:41 -08002526 struct drm_property *scaling_mode_property;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02002527 /**
2528 * @aspect_ratio_property: Optional connector property to control the
2529 * HDMI infoframe aspect ratio setting.
2530 */
Vandana Kannanff587e42014-06-11 10:46:48 +05302531 struct drm_property *aspect_ratio_property;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02002532 /**
Daniel Vetter9a6bc032016-07-15 21:48:00 +02002533 * @degamma_lut_property: Optional CRTC property to set the LUT used to
2534 * convert the framebuffer's colors to linear gamma.
2535 */
Lionel Landwerlin5488dc12016-02-26 17:05:00 +00002536 struct drm_property *degamma_lut_property;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02002537 /**
2538 * @degamma_lut_size_property: Optional CRTC property for the size of
2539 * the degamma LUT as supported by the driver (read-only).
2540 */
Lionel Landwerlin5488dc12016-02-26 17:05:00 +00002541 struct drm_property *degamma_lut_size_property;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02002542 /**
2543 * @ctm_property: Optional CRTC property to set the
2544 * matrix used to convert colors after the lookup in the
2545 * degamma LUT.
2546 */
Lionel Landwerlin5488dc12016-02-26 17:05:00 +00002547 struct drm_property *ctm_property;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02002548 /**
2549 * @gamma_lut_property: Optional CRTC property to set the LUT used to
2550 * convert the colors, after the CTM matrix, to the gamma space of the
2551 * connected screen.
2552 */
Lionel Landwerlin5488dc12016-02-26 17:05:00 +00002553 struct drm_property *gamma_lut_property;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02002554 /**
2555 * @gamma_lut_size_property: Optional CRTC property for the size of the
2556 * gamma LUT as supported by the driver (read-only).
2557 */
Lionel Landwerlin5488dc12016-02-26 17:05:00 +00002558 struct drm_property *gamma_lut_size_property;
2559
Daniel Vetter9a6bc032016-07-15 21:48:00 +02002560 /**
2561 * @suggested_x_property: Optional connector property with a hint for
2562 * the position of the output on the host's screen.
2563 */
Dave Airlie5bb2bbf2014-11-10 10:18:15 +10002564 struct drm_property *suggested_x_property;
Daniel Vetter9a6bc032016-07-15 21:48:00 +02002565 /**
2566 * @suggested_y_property: Optional connector property with a hint for
2567 * the position of the output on the host's screen.
2568 */
Dave Airlie5bb2bbf2014-11-10 10:18:15 +10002569 struct drm_property *suggested_y_property;
2570
Dave Airlie019d96c2011-09-29 16:20:42 +01002571 /* dumb ioctl parameters */
2572 uint32_t preferred_depth, prefer_shadow;
Keith Packard62f21042013-07-22 18:50:00 -07002573
Daniel Vetter9a6bc032016-07-15 21:48:00 +02002574 /**
2575 * @async_page_flip: Does this device support async flips on the primary
2576 * plane?
2577 */
Keith Packard62f21042013-07-22 18:50:00 -07002578 bool async_page_flip;
Alex Deucher8716ed42014-02-12 12:48:23 -05002579
Daniel Vetterac3ba4a2016-05-31 23:11:10 +02002580 /**
2581 * @allow_fb_modifiers:
2582 *
2583 * Whether the driver supports fb modifiers in the ADDFB2.1 ioctl call.
2584 */
Rob Clarke3eb3252015-02-05 14:41:52 +00002585 bool allow_fb_modifiers;
2586
Alex Deucher8716ed42014-02-12 12:48:23 -05002587 /* cursor size */
2588 uint32_t cursor_width, cursor_height;
Daniel Vetter9f2a7952016-06-08 14:19:02 +02002589
2590 struct drm_mode_config_helper_funcs *helper_private;
Dave Airlief453ba02008-11-07 14:05:41 -08002591};
2592
Rob Clarkdd275952014-11-25 20:29:46 -05002593/**
2594 * drm_for_each_plane_mask - iterate over planes specified by bitmask
2595 * @plane: the loop cursor
2596 * @dev: the DRM device
2597 * @plane_mask: bitmask of plane indices
2598 *
2599 * Iterate over all planes specified by bitmask.
2600 */
2601#define drm_for_each_plane_mask(plane, dev, plane_mask) \
2602 list_for_each_entry((plane), &(dev)->mode_config.plane_list, head) \
Jani Nikula373701b2015-11-24 21:21:55 +02002603 for_each_if ((plane_mask) & (1 << drm_plane_index(plane)))
Rob Clarkdd275952014-11-25 20:29:46 -05002604
Maarten Lankhorstead8b662016-01-07 10:59:19 +01002605/**
2606 * drm_for_each_encoder_mask - iterate over encoders specified by bitmask
2607 * @encoder: the loop cursor
2608 * @dev: the DRM device
2609 * @encoder_mask: bitmask of encoder indices
2610 *
2611 * Iterate over all encoders specified by bitmask.
2612 */
2613#define drm_for_each_encoder_mask(encoder, dev, encoder_mask) \
2614 list_for_each_entry((encoder), &(dev)->mode_config.encoder_list, head) \
2615 for_each_if ((encoder_mask) & (1 << drm_encoder_index(encoder)))
Rob Clarkdd275952014-11-25 20:29:46 -05002616
Dave Airlief453ba02008-11-07 14:05:41 -08002617#define obj_to_crtc(x) container_of(x, struct drm_crtc, base)
2618#define obj_to_connector(x) container_of(x, struct drm_connector, base)
2619#define obj_to_encoder(x) container_of(x, struct drm_encoder, base)
2620#define obj_to_mode(x) container_of(x, struct drm_display_mode, base)
2621#define obj_to_fb(x) container_of(x, struct drm_framebuffer, base)
2622#define obj_to_property(x) container_of(x, struct drm_property, base)
2623#define obj_to_blob(x) container_of(x, struct drm_property_blob, base)
Jesse Barnes8cf5c912011-11-14 14:51:27 -08002624#define obj_to_plane(x) container_of(x, struct drm_plane, base)
Dave Airlief453ba02008-11-07 14:05:41 -08002625
Sascha Hauer4a67d392012-02-06 10:58:17 +01002626struct drm_prop_enum_list {
2627 int type;
2628 char *name;
2629};
Dave Airlief453ba02008-11-07 14:05:41 -08002630
Ville Syrjäläf9882872015-12-09 16:19:31 +02002631extern __printf(6, 7)
2632int drm_crtc_init_with_planes(struct drm_device *dev,
2633 struct drm_crtc *crtc,
2634 struct drm_plane *primary,
2635 struct drm_plane *cursor,
2636 const struct drm_crtc_funcs *funcs,
2637 const char *name, ...);
Dave Airlief453ba02008-11-07 14:05:41 -08002638extern void drm_crtc_cleanup(struct drm_crtc *crtc);
Chris Wilson490d3d12016-05-27 20:05:00 +01002639
2640/**
2641 * drm_crtc_index - find the index of a registered CRTC
2642 * @crtc: CRTC to find index for
2643 *
2644 * Given a registered CRTC, return the index of that CRTC within a DRM
2645 * device's list of CRTCs.
2646 */
2647static inline unsigned int drm_crtc_index(struct drm_crtc *crtc)
2648{
2649 return crtc->index;
2650}
Russell Kingdb5f7a62014-01-02 21:27:33 +00002651
2652/**
2653 * drm_crtc_mask - find the mask of a registered CRTC
2654 * @crtc: CRTC to find mask for
2655 *
2656 * Given a registered CRTC, return the mask bit of that CRTC for an
2657 * encoder's possible_crtcs field.
2658 */
2659static inline uint32_t drm_crtc_mask(struct drm_crtc *crtc)
2660{
2661 return 1 << drm_crtc_index(crtc);
2662}
Dave Airlief453ba02008-11-07 14:05:41 -08002663
Daniel Vetter81065542016-06-21 10:54:13 +02002664int drm_connector_init(struct drm_device *dev,
2665 struct drm_connector *connector,
2666 const struct drm_connector_funcs *funcs,
2667 int connector_type);
Thomas Wood34ea3d32014-05-29 16:57:41 +01002668int drm_connector_register(struct drm_connector *connector);
2669void drm_connector_unregister(struct drm_connector *connector);
Dave Airlief453ba02008-11-07 14:05:41 -08002670
2671extern void drm_connector_cleanup(struct drm_connector *connector);
Maarten Lankhorst5fff80b2016-02-17 08:32:05 +01002672static inline unsigned drm_connector_index(struct drm_connector *connector)
2673{
Daniel Vetter69425592016-07-19 18:25:01 +02002674 return connector->index;
Maarten Lankhorst5fff80b2016-02-17 08:32:05 +01002675}
2676
Ville Syrjälä13a3d912015-12-09 16:20:18 +02002677extern __printf(5, 6)
2678int drm_encoder_init(struct drm_device *dev,
2679 struct drm_encoder *encoder,
2680 const struct drm_encoder_funcs *funcs,
2681 int encoder_type, const char *name, ...);
Chris Wilson490d3d12016-05-27 20:05:00 +01002682
2683/**
2684 * drm_encoder_index - find the index of a registered encoder
2685 * @encoder: encoder to find index for
2686 *
2687 * Given a registered encoder, return the index of that encoder within a DRM
2688 * device's list of encoders.
2689 */
2690static inline unsigned int drm_encoder_index(struct drm_encoder *encoder)
2691{
2692 return encoder->index;
2693}
Dave Airlief453ba02008-11-07 14:05:41 -08002694
Thierry Reding3d887362014-01-13 14:33:20 +01002695/**
2696 * drm_encoder_crtc_ok - can a given crtc drive a given encoder?
2697 * @encoder: encoder to test
2698 * @crtc: crtc to test
2699 *
2700 * Return false if @encoder can't be driven by @crtc, true otherwise.
2701 */
2702static inline bool drm_encoder_crtc_ok(struct drm_encoder *encoder,
2703 struct drm_crtc *crtc)
2704{
2705 return !!(encoder->possible_crtcs & drm_crtc_mask(crtc));
2706}
2707
Ville Syrjäläb0b3b792015-12-09 16:19:55 +02002708extern __printf(8, 9)
2709int drm_universal_plane_init(struct drm_device *dev,
2710 struct drm_plane *plane,
2711 unsigned long possible_crtcs,
2712 const struct drm_plane_funcs *funcs,
2713 const uint32_t *formats,
2714 unsigned int format_count,
2715 enum drm_plane_type type,
2716 const char *name, ...);
Jesse Barnes8cf5c912011-11-14 14:51:27 -08002717extern int drm_plane_init(struct drm_device *dev,
2718 struct drm_plane *plane,
2719 unsigned long possible_crtcs,
2720 const struct drm_plane_funcs *funcs,
Thierry Reding45e37432015-08-12 16:54:28 +02002721 const uint32_t *formats, unsigned int format_count,
Matt Roperdc415ff2014-04-01 15:22:36 -07002722 bool is_primary);
Jesse Barnes8cf5c912011-11-14 14:51:27 -08002723extern void drm_plane_cleanup(struct drm_plane *plane);
Chris Wilson490d3d12016-05-27 20:05:00 +01002724
2725/**
2726 * drm_plane_index - find the index of a registered plane
2727 * @plane: plane to find index for
2728 *
2729 * Given a registered plane, return the index of that plane within a DRM
2730 * device's list of planes.
2731 */
2732static inline unsigned int drm_plane_index(struct drm_plane *plane)
2733{
2734 return plane->index;
2735}
Chandra Konduruf81338a2015-04-09 17:36:21 -07002736extern struct drm_plane * drm_plane_from_index(struct drm_device *dev, int idx);
Ville Syrjälä9125e612013-06-03 16:10:40 +03002737extern void drm_plane_force_disable(struct drm_plane *plane);
Gustavo Padovanecb7e162014-12-01 15:40:09 -08002738extern void drm_crtc_get_hv_timing(const struct drm_display_mode *mode,
2739 int *hdisplay, int *vdisplay);
Lukas Wunner6a0d9522016-06-08 18:47:27 +02002740extern int drm_crtc_force_disable(struct drm_crtc *crtc);
2741extern int drm_crtc_force_disable_all(struct drm_device *dev);
Jesse Barnes8cf5c912011-11-14 14:51:27 -08002742
Dave Airlief453ba02008-11-07 14:05:41 -08002743extern void drm_encoder_cleanup(struct drm_encoder *encoder);
2744
Ville Syrjäläd20d3172013-06-07 15:43:07 +00002745extern const char *drm_get_connector_status_name(enum drm_connector_status status);
Jesse Barnesac1bb362014-02-10 15:32:44 -08002746extern const char *drm_get_subpixel_order_name(enum subpixel_order order);
Ville Syrjäläd20d3172013-06-07 15:43:07 +00002747extern const char *drm_get_dpms_name(int val);
2748extern const char *drm_get_dvi_i_subconnector_name(int val);
2749extern const char *drm_get_dvi_i_select_name(int val);
2750extern const char *drm_get_tv_subconnector_name(int val);
2751extern const char *drm_get_tv_select_name(int val);
Dave Airlief453ba02008-11-07 14:05:41 -08002752extern void drm_mode_config_init(struct drm_device *dev);
Chris Wilsoneb033552011-01-24 15:11:08 +00002753extern void drm_mode_config_reset(struct drm_device *dev);
Dave Airlief453ba02008-11-07 14:05:41 -08002754extern void drm_mode_config_cleanup(struct drm_device *dev);
Dave Airlief453ba02008-11-07 14:05:41 -08002755
Dave Airlie43aba7e2014-06-05 14:01:31 +10002756extern int drm_mode_connector_set_path_property(struct drm_connector *connector,
Thierry Reding12e6cec2014-05-13 11:38:36 +02002757 const char *path);
Dave Airlie6f134d72014-10-20 16:30:50 +10002758int drm_mode_connector_set_tile_property(struct drm_connector *connector);
Dave Airlief453ba02008-11-07 14:05:41 -08002759extern int drm_mode_connector_update_edid_property(struct drm_connector *connector,
Thierry Reding12e6cec2014-05-13 11:38:36 +02002760 const struct edid *edid);
Rob Clark5ea22f22014-05-30 11:34:01 -04002761
Boris Brezillonb5571e92014-07-22 12:09:10 +02002762extern int drm_display_info_set_bus_formats(struct drm_display_info *info,
2763 const u32 *formats,
2764 unsigned int num_formats);
2765
Rob Clark5ea22f22014-05-30 11:34:01 -04002766static inline bool drm_property_type_is(struct drm_property *property,
2767 uint32_t type)
2768{
2769 /* instanceof for props.. handles extended type vs original types: */
2770 if (property->flags & DRM_MODE_PROP_EXTENDED_TYPE)
2771 return (property->flags & DRM_MODE_PROP_EXTENDED_TYPE) == type;
2772 return property->flags & type;
2773}
2774
Paulo Zanonic5431882012-05-15 18:09:02 -03002775extern int drm_object_property_set_value(struct drm_mode_object *obj,
2776 struct drm_property *property,
2777 uint64_t val);
2778extern int drm_object_property_get_value(struct drm_mode_object *obj,
2779 struct drm_property *property,
2780 uint64_t *value);
Dave Airlief453ba02008-11-07 14:05:41 -08002781
Paulo Zanonic5431882012-05-15 18:09:02 -03002782extern void drm_object_attach_property(struct drm_mode_object *obj,
2783 struct drm_property *property,
2784 uint64_t init_val);
Dave Airlief453ba02008-11-07 14:05:41 -08002785extern struct drm_property *drm_property_create(struct drm_device *dev, int flags,
2786 const char *name, int num_values);
Sascha Hauer4a67d392012-02-06 10:58:17 +01002787extern struct drm_property *drm_property_create_enum(struct drm_device *dev, int flags,
2788 const char *name,
2789 const struct drm_prop_enum_list *props,
2790 int num_values);
Rob Clark49e27542012-05-17 02:23:26 -06002791struct drm_property *drm_property_create_bitmask(struct drm_device *dev,
2792 int flags, const char *name,
2793 const struct drm_prop_enum_list *props,
Ville Syrjälä7689ffb2014-07-08 10:31:52 +05302794 int num_props,
2795 uint64_t supported_bits);
Sascha Hauerd9bc3c02012-02-06 10:58:18 +01002796struct drm_property *drm_property_create_range(struct drm_device *dev, int flags,
2797 const char *name,
2798 uint64_t min, uint64_t max);
Rob Clarkebc44cf2012-09-12 22:22:31 -05002799struct drm_property *drm_property_create_signed_range(struct drm_device *dev,
2800 int flags, const char *name,
2801 int64_t min, int64_t max);
Rob Clark98f75de2014-05-30 11:37:03 -04002802struct drm_property *drm_property_create_object(struct drm_device *dev,
2803 int flags, const char *name, uint32_t type);
Daniel Vetter960cd9d2015-01-21 08:47:38 +01002804struct drm_property *drm_property_create_bool(struct drm_device *dev, int flags,
2805 const char *name);
Daniel Stone6bcacf52015-04-20 19:22:55 +01002806struct drm_property_blob *drm_property_create_blob(struct drm_device *dev,
2807 size_t length,
2808 const void *data);
2809struct drm_property_blob *drm_property_lookup_blob(struct drm_device *dev,
2810 uint32_t id);
2811struct drm_property_blob *drm_property_reference_blob(struct drm_property_blob *blob);
2812void drm_property_unreference_blob(struct drm_property_blob *blob);
Dave Airlief453ba02008-11-07 14:05:41 -08002813extern void drm_property_destroy(struct drm_device *dev, struct drm_property *property);
2814extern int drm_property_add_enum(struct drm_property *property, int index,
2815 uint64_t value, const char *name);
2816extern int drm_mode_create_dvi_i_properties(struct drm_device *dev);
Thierry Reding2f763312014-10-13 12:45:57 +02002817extern int drm_mode_create_tv_properties(struct drm_device *dev,
2818 unsigned int num_modes,
Ville Syrjäläb7c914b2015-08-31 15:09:26 +03002819 const char * const modes[]);
Dave Airlief453ba02008-11-07 14:05:41 -08002820extern int drm_mode_create_scaling_mode_property(struct drm_device *dev);
Vandana Kannanff587e42014-06-11 10:46:48 +05302821extern int drm_mode_create_aspect_ratio_property(struct drm_device *dev);
Dave Airlie5bb2bbf2014-11-10 10:18:15 +10002822extern int drm_mode_create_suggested_offset_properties(struct drm_device *dev);
Dave Airlief453ba02008-11-07 14:05:41 -08002823
2824extern int drm_mode_connector_attach_encoder(struct drm_connector *connector,
2825 struct drm_encoder *encoder);
Sascha Hauer4cae5b82012-02-01 11:38:23 +01002826extern int drm_mode_crtc_set_gamma_size(struct drm_crtc *crtc,
Dave Airlief453ba02008-11-07 14:05:41 -08002827 int gamma_size);
Rob Clark98f75de2014-05-30 11:37:03 -04002828
Daniel Vetter2d13b672012-12-11 13:47:23 +01002829extern int drm_mode_set_config_internal(struct drm_mode_set *set);
Daniel Vetter81065542016-06-21 10:54:13 +02002830
Jesse Barnes308e5bc2011-11-14 14:51:28 -08002831extern uint32_t drm_mode_legacy_fb_format(uint32_t bpp, uint32_t depth);
Dave Airlie138f9eb2014-10-20 16:17:17 +10002832
2833extern struct drm_tile_group *drm_mode_create_tile_group(struct drm_device *dev,
2834 char topology[8]);
2835extern struct drm_tile_group *drm_mode_get_tile_group(struct drm_device *dev,
2836 char topology[8]);
2837extern void drm_mode_put_tile_group(struct drm_device *dev,
2838 struct drm_tile_group *tg);
Dave Airlieff72145b2011-02-07 12:16:14 +10002839
Thomas Wood3a5f87c2014-08-20 14:45:00 +01002840extern int drm_mode_plane_set_obj_prop(struct drm_plane *plane,
2841 struct drm_property *property,
2842 uint64_t value);
Dave Airlie248dbc22011-11-29 20:02:54 +00002843
Ville Syrjäläc1df5f32014-07-08 10:31:53 +05302844extern struct drm_property *drm_mode_create_rotation_property(struct drm_device *dev,
2845 unsigned int supported_rotations);
Ville Syrjälä3c9855f2014-07-08 10:31:56 +05302846extern unsigned int drm_rotation_simplify(unsigned int rotation,
2847 unsigned int supported_rotations);
Jyri Sarhaf8ed34a2016-06-07 15:09:14 +03002848extern void drm_crtc_enable_color_mgmt(struct drm_crtc *crtc,
2849 uint degamma_lut_size,
2850 bool has_ctm,
2851 uint gamma_lut_size);
Marek Szyprowski44d1240d2016-06-13 11:11:26 +02002852
2853int drm_plane_create_zpos_property(struct drm_plane *plane,
2854 unsigned int zpos,
2855 unsigned int min, unsigned int max);
2856
2857int drm_plane_create_zpos_immutable_property(struct drm_plane *plane,
2858 unsigned int zpos);
2859
Russell King96f60e32012-08-15 13:59:49 +01002860/* Helpers */
Rob Clarka2b34e22013-10-05 16:36:52 -04002861static inline struct drm_plane *drm_plane_find(struct drm_device *dev,
2862 uint32_t id)
2863{
2864 struct drm_mode_object *mo;
2865 mo = drm_mode_object_find(dev, id, DRM_MODE_OBJECT_PLANE);
2866 return mo ? obj_to_plane(mo) : NULL;
2867}
2868
Russell King96f60e32012-08-15 13:59:49 +01002869static inline struct drm_crtc *drm_crtc_find(struct drm_device *dev,
2870 uint32_t id)
2871{
2872 struct drm_mode_object *mo;
2873 mo = drm_mode_object_find(dev, id, DRM_MODE_OBJECT_CRTC);
2874 return mo ? obj_to_crtc(mo) : NULL;
2875}
2876
2877static inline struct drm_encoder *drm_encoder_find(struct drm_device *dev,
2878 uint32_t id)
2879{
2880 struct drm_mode_object *mo;
2881 mo = drm_mode_object_find(dev, id, DRM_MODE_OBJECT_ENCODER);
2882 return mo ? obj_to_encoder(mo) : NULL;
2883}
2884
Dave Airlieb164d312016-04-27 11:10:09 +10002885/**
2886 * drm_connector_lookup - lookup connector object
2887 * @dev: DRM device
2888 * @id: connector object id
2889 *
2890 * This function looks up the connector object specified by id
2891 * add takes a reference to it.
2892 */
2893static inline struct drm_connector *drm_connector_lookup(struct drm_device *dev,
Rob Clarka2b34e22013-10-05 16:36:52 -04002894 uint32_t id)
2895{
2896 struct drm_mode_object *mo;
2897 mo = drm_mode_object_find(dev, id, DRM_MODE_OBJECT_CONNECTOR);
2898 return mo ? obj_to_connector(mo) : NULL;
2899}
2900
2901static inline struct drm_property *drm_property_find(struct drm_device *dev,
2902 uint32_t id)
2903{
2904 struct drm_mode_object *mo;
2905 mo = drm_mode_object_find(dev, id, DRM_MODE_OBJECT_PROPERTY);
2906 return mo ? obj_to_property(mo) : NULL;
2907}
2908
Lionel Landwerlin5488dc12016-02-26 17:05:00 +00002909/*
2910 * Extract a degamma/gamma LUT value provided by user and round it to the
2911 * precision supported by the hardware.
2912 */
2913static inline uint32_t drm_color_lut_extract(uint32_t user_input,
2914 uint32_t bit_precision)
2915{
Lionel Landwerlin644a8052016-03-22 14:10:33 +00002916 uint32_t val = user_input;
Lionel Landwerlin5488dc12016-02-26 17:05:00 +00002917 uint32_t max = 0xffff >> (16 - bit_precision);
2918
Lionel Landwerlin644a8052016-03-22 14:10:33 +00002919 /* Round only if we're not using full precision. */
2920 if (bit_precision < 16) {
2921 val += 1UL << (16 - bit_precision - 1);
2922 val >>= 16 - bit_precision;
2923 }
Lionel Landwerlin5488dc12016-02-26 17:05:00 +00002924
2925 return clamp_val(val, 0, max);
2926}
2927
Dave Airliee76d3992016-05-03 10:17:52 +10002928/**
Dave Airlieb164d312016-04-27 11:10:09 +10002929 * drm_connector_reference - incr the connector refcnt
2930 * @connector: connector
2931 *
2932 * This function increments the connector's refcount.
2933 */
2934static inline void drm_connector_reference(struct drm_connector *connector)
2935{
2936 drm_mode_object_reference(&connector->base);
2937}
2938
2939/**
2940 * drm_connector_unreference - unref a connector
2941 * @connector: connector to unref
2942 *
2943 * This function decrements the connector's refcount and frees it if it drops to zero.
2944 */
2945static inline void drm_connector_unreference(struct drm_connector *connector)
2946{
2947 drm_mode_object_unreference(&connector->base);
2948}
2949
Matt Ropere27dde32014-04-01 15:22:30 -07002950/* Plane list iterator for legacy (overlay only) planes. */
Daniel Vetter4ea50e92015-07-09 23:44:24 +02002951#define drm_for_each_legacy_plane(plane, dev) \
2952 list_for_each_entry(plane, &(dev)->mode_config.plane_list, head) \
Jani Nikula373701b2015-11-24 21:21:55 +02002953 for_each_if (plane->type == DRM_PLANE_TYPE_OVERLAY)
Matt Ropere27dde32014-04-01 15:22:30 -07002954
Daniel Vetter6295d602015-07-09 23:44:25 +02002955#define drm_for_each_plane(plane, dev) \
2956 list_for_each_entry(plane, &(dev)->mode_config.plane_list, head)
2957
2958#define drm_for_each_crtc(crtc, dev) \
2959 list_for_each_entry(crtc, &(dev)->mode_config.crtc_list, head)
2960
Daniel Vetter7a3f3d62015-07-09 23:44:28 +02002961static inline void
2962assert_drm_connector_list_read_locked(struct drm_mode_config *mode_config)
2963{
Daniel Vettercff20ba2015-07-09 23:44:33 +02002964 /*
2965 * The connector hotadd/remove code currently grabs both locks when
2966 * updating lists. Hence readers need only hold either of them to be
2967 * safe and the check amounts to
2968 *
2969 * WARN_ON(not_holding(A) && not_holding(B)).
2970 */
2971 WARN_ON(!mutex_is_locked(&mode_config->mutex) &&
2972 !drm_modeset_is_locked(&mode_config->connection_mutex));
Daniel Vetter7a3f3d62015-07-09 23:44:28 +02002973}
2974
Daniel Vetter6295d602015-07-09 23:44:25 +02002975#define drm_for_each_connector(connector, dev) \
Daniel Vetter7a3f3d62015-07-09 23:44:28 +02002976 for (assert_drm_connector_list_read_locked(&(dev)->mode_config), \
2977 connector = list_first_entry(&(dev)->mode_config.connector_list, \
2978 struct drm_connector, head); \
2979 &connector->head != (&(dev)->mode_config.connector_list); \
2980 connector = list_next_entry(connector, head))
Daniel Vetter6295d602015-07-09 23:44:25 +02002981
2982#define drm_for_each_encoder(encoder, dev) \
2983 list_for_each_entry(encoder, &(dev)->mode_config.encoder_list, head)
2984
2985#define drm_for_each_fb(fb, dev) \
Daniel Vetter4676ba02015-07-09 23:44:30 +02002986 for (WARN_ON(!mutex_is_locked(&(dev)->mode_config.fb_lock)), \
2987 fb = list_first_entry(&(dev)->mode_config.fb_list, \
2988 struct drm_framebuffer, head); \
2989 &fb->head != (&(dev)->mode_config.fb_list); \
2990 fb = list_next_entry(fb, head))
Daniel Vetter6295d602015-07-09 23:44:25 +02002991
Daniel Vetter81065542016-06-21 10:54:13 +02002992/* drm_edid.c */
2993bool drm_probe_ddc(struct i2c_adapter *adapter);
2994struct edid *drm_get_edid(struct drm_connector *connector,
2995 struct i2c_adapter *adapter);
2996struct edid *drm_get_edid_switcheroo(struct drm_connector *connector,
2997 struct i2c_adapter *adapter);
2998struct edid *drm_edid_duplicate(const struct edid *edid);
2999int drm_add_edid_modes(struct drm_connector *connector, struct edid *edid);
3000
3001u8 drm_match_cea_mode(const struct drm_display_mode *to_match);
3002enum hdmi_picture_aspect drm_get_cea_aspect_ratio(const u8 video_code);
3003bool drm_detect_hdmi_monitor(struct edid *edid);
3004bool drm_detect_monitor_audio(struct edid *edid);
3005bool drm_rgb_quant_range_selectable(struct edid *edid);
3006int drm_add_modes_noedid(struct drm_connector *connector,
3007 int hdisplay, int vdisplay);
3008void drm_set_preferred_mode(struct drm_connector *connector,
3009 int hpref, int vpref);
3010
3011int drm_edid_header_is_valid(const u8 *raw_edid);
3012bool drm_edid_block_valid(u8 *raw_edid, int block, bool print_bad_edid,
3013 bool *edid_corrupt);
3014bool drm_edid_is_valid(struct edid *edid);
3015void drm_edid_get_monitor_name(struct edid *edid, char *name,
3016 int buflen);
3017struct drm_display_mode *drm_mode_find_dmt(struct drm_device *dev,
3018 int hsize, int vsize, int fresh,
3019 bool rb);
3020
3021/* drm_bridge.c */
3022extern int drm_bridge_add(struct drm_bridge *bridge);
3023extern void drm_bridge_remove(struct drm_bridge *bridge);
3024extern struct drm_bridge *of_drm_find_bridge(struct device_node *np);
3025extern int drm_bridge_attach(struct drm_device *dev, struct drm_bridge *bridge);
3026
3027bool drm_bridge_mode_fixup(struct drm_bridge *bridge,
3028 const struct drm_display_mode *mode,
3029 struct drm_display_mode *adjusted_mode);
3030void drm_bridge_disable(struct drm_bridge *bridge);
3031void drm_bridge_post_disable(struct drm_bridge *bridge);
3032void drm_bridge_mode_set(struct drm_bridge *bridge,
3033 struct drm_display_mode *mode,
3034 struct drm_display_mode *adjusted_mode);
3035void drm_bridge_pre_enable(struct drm_bridge *bridge);
3036void drm_bridge_enable(struct drm_bridge *bridge);
3037
Dave Airlief453ba02008-11-07 14:05:41 -08003038#endif /* __DRM_CRTC_H__ */