]>
Commit | Line | Data |
---|---|---|
f453ba04 DA |
1 | /* |
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> | |
f453ba04 | 32 | #include <linux/fb.h> |
985e5dc2 | 33 | #include <linux/hdmi.h> |
b5571e9d | 34 | #include <linux/media-bus-format.h> |
d7d2c48e DH |
35 | #include <uapi/drm/drm_mode.h> |
36 | #include <uapi/drm/drm_fourcc.h> | |
51fd371b | 37 | #include <drm/drm_modeset_lock.h> |
308e5bcb | 38 | |
f453ba04 DA |
39 | struct drm_device; |
40 | struct drm_mode_set; | |
41 | struct drm_framebuffer; | |
7e3bdf4a | 42 | struct drm_object_properties; |
595887eb TR |
43 | struct drm_file; |
44 | struct drm_clip_rect; | |
7e435aad | 45 | struct device_node; |
e2330f07 | 46 | struct fence; |
f453ba04 | 47 | |
f453ba04 DA |
48 | struct drm_mode_object { |
49 | uint32_t id; | |
50 | uint32_t type; | |
7e3bdf4a | 51 | struct drm_object_properties *properties; |
d0f37cf6 DA |
52 | struct kref refcount; |
53 | void (*free_cb)(struct kref *kref); | |
7e3bdf4a PZ |
54 | }; |
55 | ||
fe456168 | 56 | #define DRM_OBJECT_MAX_PROPERTY 24 |
7e3bdf4a | 57 | struct drm_object_properties { |
88a48e29 | 58 | int count, atomic_count; |
b17cd757 RC |
59 | /* NOTE: if we ever start dynamically destroying properties (ie. |
60 | * not at drm_mode_config_cleanup() time), then we'd have to do | |
61 | * a better job of detaching property from mode objects to avoid | |
62 | * dangling property pointers: | |
63 | */ | |
64 | struct drm_property *properties[DRM_OBJECT_MAX_PROPERTY]; | |
22b8b13b RC |
65 | /* do not read/write values directly, but use drm_object_property_get_value() |
66 | * and drm_object_property_set_value(): | |
67 | */ | |
7e3bdf4a | 68 | uint64_t values[DRM_OBJECT_MAX_PROPERTY]; |
f453ba04 DA |
69 | }; |
70 | ||
ebc44cf3 RC |
71 | static inline int64_t U642I64(uint64_t val) |
72 | { | |
73 | return (int64_t)*((int64_t *)&val); | |
74 | } | |
75 | static inline uint64_t I642U64(int64_t val) | |
76 | { | |
77 | return (uint64_t)*((uint64_t *)&val); | |
78 | } | |
79 | ||
d9c38242 RF |
80 | /* |
81 | * Rotation property bits. DRM_ROTATE_<degrees> rotates the image by the | |
82 | * specified amount in degrees in counter clockwise direction. DRM_REFLECT_X and | |
83 | * DRM_REFLECT_Y reflects the image along the specified axis prior to rotation | |
84 | */ | |
62209070 | 85 | #define DRM_ROTATE_MASK 0x0f |
06596961 VS |
86 | #define DRM_ROTATE_0 0 |
87 | #define DRM_ROTATE_90 1 | |
88 | #define DRM_ROTATE_180 2 | |
89 | #define DRM_ROTATE_270 3 | |
62209070 | 90 | #define DRM_REFLECT_MASK (~DRM_ROTATE_MASK) |
06596961 VS |
91 | #define DRM_REFLECT_X 4 |
92 | #define DRM_REFLECT_Y 5 | |
93 | ||
55310008 DV |
94 | enum drm_connector_force { |
95 | DRM_FORCE_UNSPECIFIED, | |
96 | DRM_FORCE_OFF, | |
97 | DRM_FORCE_ON, /* force on analog part normally */ | |
98 | DRM_FORCE_ON_DIGITAL, /* for DVI-I use digital connector */ | |
f453ba04 DA |
99 | }; |
100 | ||
55310008 | 101 | #include <drm/drm_modes.h> |
4aa17cf0 | 102 | |
f453ba04 DA |
103 | enum drm_connector_status { |
104 | connector_status_connected = 1, | |
105 | connector_status_disconnected = 2, | |
106 | connector_status_unknown = 3, | |
107 | }; | |
108 | ||
109 | enum subpixel_order { | |
110 | SubPixelUnknown = 0, | |
111 | SubPixelHorizontalRGB, | |
112 | SubPixelHorizontalBGR, | |
113 | SubPixelVerticalRGB, | |
114 | SubPixelVerticalBGR, | |
115 | SubPixelNone, | |
116 | }; | |
117 | ||
da05a5a7 JB |
118 | #define DRM_COLOR_FORMAT_RGB444 (1<<0) |
119 | #define DRM_COLOR_FORMAT_YCRCB444 (1<<1) | |
120 | #define DRM_COLOR_FORMAT_YCRCB422 (1<<2) | |
f0aa0838 SA |
121 | |
122 | #define DRM_BUS_FLAG_DE_LOW (1<<0) | |
123 | #define DRM_BUS_FLAG_DE_HIGH (1<<1) | |
124 | /* drive data on pos. edge */ | |
125 | #define DRM_BUS_FLAG_PIXDATA_POSEDGE (1<<2) | |
126 | /* drive data on neg. edge */ | |
127 | #define DRM_BUS_FLAG_PIXDATA_NEGEDGE (1<<3) | |
128 | ||
f453ba04 DA |
129 | /* |
130 | * Describes a given display (e.g. CRT or flat panel) and its limitations. | |
131 | */ | |
132 | struct drm_display_info { | |
133 | char name[DRM_DISPLAY_INFO_LEN]; | |
fb439640 | 134 | |
f453ba04 DA |
135 | /* Physical size */ |
136 | unsigned int width_mm; | |
137 | unsigned int height_mm; | |
138 | ||
f453ba04 DA |
139 | /* Clock limits FIXME: storage format */ |
140 | unsigned int min_vfreq, max_vfreq; | |
141 | unsigned int min_hfreq, max_hfreq; | |
142 | unsigned int pixel_clock; | |
3b11228b | 143 | unsigned int bpc; |
f453ba04 | 144 | |
f453ba04 | 145 | enum subpixel_order subpixel_order; |
da05a5a7 | 146 | u32 color_formats; |
f453ba04 | 147 | |
b5571e9d BB |
148 | const u32 *bus_formats; |
149 | unsigned int num_bus_formats; | |
f0aa0838 | 150 | u32 bus_flags; |
b5571e9d | 151 | |
5d02626d MK |
152 | /* Mask of supported hdmi deep color modes */ |
153 | u8 edid_hdmi_dc_modes; | |
154 | ||
ebec9a7b | 155 | u8 cea_rev; |
f453ba04 DA |
156 | }; |
157 | ||
138f9ebb DA |
158 | /* data corresponds to displayid vend/prod/serial */ |
159 | struct drm_tile_group { | |
160 | struct kref refcount; | |
161 | struct drm_device *dev; | |
162 | int id; | |
163 | u8 group_data[8]; | |
164 | }; | |
165 | ||
c6b0ca3e DV |
166 | /** |
167 | * struct drm_framebuffer_funcs - framebuffer hooks | |
168 | */ | |
f453ba04 | 169 | struct drm_framebuffer_funcs { |
c6b0ca3e DV |
170 | /** |
171 | * @destroy: | |
172 | * | |
173 | * Clean up framebuffer resources, specifically also unreference the | |
174 | * backing storage. The core guarantees to call this function for every | |
175 | * framebuffer successfully created by ->fb_create() in | |
d55f5320 DV |
176 | * &drm_mode_config_funcs. Drivers must also call |
177 | * drm_framebuffer_cleanup() to release DRM core resources for this | |
178 | * framebuffer. | |
c6b0ca3e | 179 | */ |
f453ba04 | 180 | void (*destroy)(struct drm_framebuffer *framebuffer); |
c6b0ca3e DV |
181 | |
182 | /** | |
183 | * @create_handle: | |
184 | * | |
185 | * Create a buffer handle in the driver-specific buffer manager (either | |
186 | * GEM or TTM) valid for the passed-in struct &drm_file. This is used by | |
187 | * the core to implement the GETFB IOCTL, which returns (for | |
188 | * sufficiently priviledged user) also a native buffer handle. This can | |
189 | * be used for seamless transitions between modesetting clients by | |
190 | * copying the current screen contents to a private buffer and blending | |
191 | * between that and the new contents. | |
192 | * | |
d55f5320 DV |
193 | * GEM based drivers should call drm_gem_handle_create() to create the |
194 | * handle. | |
195 | * | |
c6b0ca3e DV |
196 | * RETURNS: |
197 | * | |
198 | * 0 on success or a negative error code on failure. | |
199 | */ | |
f453ba04 DA |
200 | int (*create_handle)(struct drm_framebuffer *fb, |
201 | struct drm_file *file_priv, | |
202 | unsigned int *handle); | |
c6b0ca3e DV |
203 | /** |
204 | * @dirty: | |
884840aa | 205 | * |
c6b0ca3e | 206 | * Optional callback for the dirty fb IOCTL. |
884840aa | 207 | * |
c6b0ca3e DV |
208 | * Userspace can notify the driver via this callback that an area of the |
209 | * framebuffer has changed and should be flushed to the display | |
210 | * hardware. This can also be used internally, e.g. by the fbdev | |
211 | * emulation, though that's not the case currently. | |
212 | * | |
213 | * See documentation in drm_mode.h for the struct drm_mode_fb_dirty_cmd | |
214 | * for more information as all the semantics and arguments have a one to | |
215 | * one mapping on this function. | |
216 | * | |
217 | * RETURNS: | |
218 | * | |
219 | * 0 on success or a negative error code on failure. | |
884840aa | 220 | */ |
02b00162 TH |
221 | int (*dirty)(struct drm_framebuffer *framebuffer, |
222 | struct drm_file *file_priv, unsigned flags, | |
884840aa JB |
223 | unsigned color, struct drm_clip_rect *clips, |
224 | unsigned num_clips); | |
f453ba04 DA |
225 | }; |
226 | ||
227 | struct drm_framebuffer { | |
228 | struct drm_device *dev; | |
f7eff60e RC |
229 | /* |
230 | * Note that the fb is refcounted for the benefit of driver internals, | |
231 | * for example some hw, disabling a CRTC/plane is asynchronous, and | |
232 | * scanout does not actually complete until the next vblank. So some | |
233 | * cleanup (like releasing the reference(s) on the backing GEM bo(s)) | |
234 | * should be deferred. In cases like this, the driver would like to | |
235 | * hold a ref to the fb even though it has already been removed from | |
236 | * userspace perspective. | |
d0f37cf6 | 237 | * The refcount is stored inside the mode object. |
f7eff60e | 238 | */ |
4b096ac1 DV |
239 | /* |
240 | * Place on the dev->mode_config.fb_list, access protected by | |
241 | * dev->mode_config.fb_lock. | |
242 | */ | |
f453ba04 DA |
243 | struct list_head head; |
244 | struct drm_mode_object base; | |
245 | const struct drm_framebuffer_funcs *funcs; | |
01f2c773 VS |
246 | unsigned int pitches[4]; |
247 | unsigned int offsets[4]; | |
e3eb3250 | 248 | uint64_t modifier[4]; |
f453ba04 DA |
249 | unsigned int width; |
250 | unsigned int height; | |
251 | /* depth can be 15 or 16 */ | |
252 | unsigned int depth; | |
253 | int bits_per_pixel; | |
254 | int flags; | |
308e5bcb | 255 | uint32_t pixel_format; /* fourcc format */ |
dd546591 GH |
256 | int hot_x; |
257 | int hot_y; | |
f453ba04 DA |
258 | struct list_head filp_head; |
259 | }; | |
260 | ||
261 | struct drm_property_blob { | |
262 | struct drm_mode_object base; | |
6bcacf51 | 263 | struct drm_device *dev; |
e2f5d2ea DS |
264 | struct list_head head_global; |
265 | struct list_head head_file; | |
ecbbe59b | 266 | size_t length; |
d63f5e6b | 267 | unsigned char data[]; |
f453ba04 DA |
268 | }; |
269 | ||
270 | struct drm_property_enum { | |
271 | uint64_t value; | |
272 | struct list_head head; | |
273 | char name[DRM_PROP_NAME_LEN]; | |
274 | }; | |
275 | ||
276 | struct drm_property { | |
277 | struct list_head head; | |
278 | struct drm_mode_object base; | |
279 | uint32_t flags; | |
280 | char name[DRM_PROP_NAME_LEN]; | |
281 | uint32_t num_values; | |
282 | uint64_t *values; | |
98f75de4 | 283 | struct drm_device *dev; |
f453ba04 | 284 | |
3758b341 | 285 | struct list_head enum_list; |
f453ba04 DA |
286 | }; |
287 | ||
288 | struct drm_crtc; | |
289 | struct drm_connector; | |
290 | struct drm_encoder; | |
d91d8a3f | 291 | struct drm_pending_vblank_event; |
8cf5c917 | 292 | struct drm_plane; |
3b336ec4 | 293 | struct drm_bridge; |
144ecb97 DV |
294 | struct drm_atomic_state; |
295 | ||
4490d4c7 DV |
296 | struct drm_crtc_helper_funcs; |
297 | struct drm_encoder_helper_funcs; | |
298 | struct drm_connector_helper_funcs; | |
299 | struct drm_plane_helper_funcs; | |
300 | ||
144ecb97 | 301 | /** |
cc4ceb48 | 302 | * struct drm_crtc_state - mutable CRTC state |
07cc0ef6 | 303 | * @crtc: backpointer to the CRTC |
144ecb97 | 304 | * @enable: whether the CRTC should be enabled, gates all other state |
d9b13620 | 305 | * @active: whether the CRTC is actively displaying (used for DPMS) |
fc596660 ML |
306 | * @planes_changed: planes on this crtc are updated |
307 | * @mode_changed: crtc_state->mode or crtc_state->enable has been changed | |
308 | * @active_changed: crtc_state->active has been toggled. | |
309 | * @connectors_changed: connectors to this crtc have been updated | |
5488dc16 LL |
310 | * @color_mgmt_changed: color management properties have changed (degamma or |
311 | * gamma LUT or CSC matrix) | |
6ddd388a | 312 | * @plane_mask: bitmask of (1 << drm_plane_index(plane)) of attached planes |
4cd9fa52 | 313 | * @connector_mask: bitmask of (1 << drm_connector_index(connector)) of attached connectors |
e87a52b3 | 314 | * @encoder_mask: bitmask of (1 << drm_encoder_index(encoder)) of attached encoders |
623369e5 DV |
315 | * @last_vblank_count: for helpers and drivers to capture the vblank of the |
316 | * update to ensure framebuffer cleanup isn't done too early | |
2f324b42 | 317 | * @adjusted_mode: for use by helpers and drivers to compute adjusted mode timings |
144ecb97 | 318 | * @mode: current mode timings |
5488dc16 LL |
319 | * @degamma_lut: Lookup table for converting framebuffer pixel data |
320 | * before apply the conversion matrix | |
321 | * @ctm: Transformation matrix | |
322 | * @gamma_lut: Lookup table for converting pixel data after the | |
323 | * conversion matrix | |
144ecb97 DV |
324 | * @event: optional pointer to a DRM event to signal upon completion of the |
325 | * state update | |
326 | * @state: backpointer to global drm_atomic_state | |
d9b13620 DV |
327 | * |
328 | * Note that the distinction between @enable and @active is rather subtile: | |
329 | * Flipping @active while @enable is set without changing anything else may | |
330 | * never return in a failure from the ->atomic_check callback. Userspace assumes | |
331 | * that a DPMS On will always succeed. In other words: @enable controls resource | |
332 | * assignment, @active controls the actual hardware state. | |
144ecb97 DV |
333 | */ |
334 | struct drm_crtc_state { | |
07cc0ef6 DV |
335 | struct drm_crtc *crtc; |
336 | ||
cc4ceb48 | 337 | bool enable; |
d9b13620 | 338 | bool active; |
144ecb97 | 339 | |
c2fcd274 DV |
340 | /* computed state bits used by helpers and drivers */ |
341 | bool planes_changed : 1; | |
623369e5 | 342 | bool mode_changed : 1; |
eab3bbef | 343 | bool active_changed : 1; |
fc596660 | 344 | bool connectors_changed : 1; |
5488dc16 | 345 | bool color_mgmt_changed : 1; |
623369e5 | 346 | |
6ddd388a RC |
347 | /* attached planes bitmask: |
348 | * WARNING: transitional helpers do not maintain plane_mask so | |
349 | * drivers not converted over to atomic helpers should not rely | |
350 | * on plane_mask being accurate! | |
351 | */ | |
352 | u32 plane_mask; | |
353 | ||
4cd9fa52 | 354 | u32 connector_mask; |
e87a52b3 | 355 | u32 encoder_mask; |
4cd9fa52 | 356 | |
623369e5 DV |
357 | /* last_vblank_count: for vblank waits before cleanup */ |
358 | u32 last_vblank_count; | |
c2fcd274 | 359 | |
2f324b42 DV |
360 | /* adjusted_mode: for use by helpers and drivers */ |
361 | struct drm_display_mode adjusted_mode; | |
362 | ||
144ecb97 DV |
363 | struct drm_display_mode mode; |
364 | ||
99cf4a29 DS |
365 | /* blob property to expose current mode to atomic userspace */ |
366 | struct drm_property_blob *mode_blob; | |
367 | ||
5488dc16 LL |
368 | /* blob property to expose color management to userspace */ |
369 | struct drm_property_blob *degamma_lut; | |
370 | struct drm_property_blob *ctm; | |
371 | struct drm_property_blob *gamma_lut; | |
372 | ||
144ecb97 DV |
373 | struct drm_pending_vblank_event *event; |
374 | ||
375 | struct drm_atomic_state *state; | |
376 | }; | |
f453ba04 DA |
377 | |
378 | /** | |
3bf0401c | 379 | * struct drm_crtc_funcs - control CRTCs for a given device |
f453ba04 DA |
380 | * |
381 | * The drm_crtc_funcs structure is the central CRTC management structure | |
382 | * in the DRM. Each CRTC controls one or more connectors (note that the name | |
383 | * CRTC is simply historical, a CRTC may control LVDS, VGA, DVI, TV out, etc. | |
384 | * connectors, not just CRTs). | |
385 | * | |
386 | * Each driver is responsible for filling out this structure at startup time, | |
387 | * in addition to providing other modesetting features, like i2c and DDC | |
388 | * bus accessors. | |
389 | */ | |
390 | struct drm_crtc_funcs { | |
88548636 DV |
391 | /** |
392 | * @reset: | |
393 | * | |
394 | * Reset CRTC hardware and software state to off. This function isn't | |
395 | * called by the core directly, only through drm_mode_config_reset(). | |
396 | * It's not a helper hook only for historical reasons. | |
397 | * | |
398 | * Atomic drivers can use drm_atomic_helper_crtc_reset() to reset | |
399 | * atomic state using this hook. | |
400 | */ | |
eb033556 | 401 | void (*reset)(struct drm_crtc *crtc); |
f453ba04 | 402 | |
f6da8c6e DV |
403 | /** |
404 | * @cursor_set: | |
405 | * | |
406 | * Update the cursor image. The cursor position is relative to the CRTC | |
407 | * and can be partially or fully outside of the visible area. | |
408 | * | |
409 | * Note that contrary to all other KMS functions the legacy cursor entry | |
410 | * points don't take a framebuffer object, but instead take directly a | |
411 | * raw buffer object id from the driver's buffer manager (which is | |
412 | * either GEM or TTM for current drivers). | |
413 | * | |
414 | * This entry point is deprecated, drivers should instead implement | |
415 | * universal plane support and register a proper cursor plane using | |
416 | * drm_crtc_init_with_planes(). | |
417 | * | |
418 | * This callback is optional | |
419 | * | |
420 | * RETURNS: | |
421 | * | |
422 | * 0 on success or a negative error code on failure. | |
423 | */ | |
f453ba04 DA |
424 | int (*cursor_set)(struct drm_crtc *crtc, struct drm_file *file_priv, |
425 | uint32_t handle, uint32_t width, uint32_t height); | |
f6da8c6e DV |
426 | |
427 | /** | |
428 | * @cursor_set2: | |
429 | * | |
430 | * Update the cursor image, including hotspot information. The hotspot | |
431 | * must not affect the cursor position in CRTC coordinates, but is only | |
432 | * meant as a hint for virtualized display hardware to coordinate the | |
433 | * guests and hosts cursor position. The cursor hotspot is relative to | |
434 | * the cursor image. Otherwise this works exactly like @cursor_set. | |
435 | * | |
436 | * This entry point is deprecated, drivers should instead implement | |
437 | * universal plane support and register a proper cursor plane using | |
438 | * drm_crtc_init_with_planes(). | |
439 | * | |
440 | * This callback is optional. | |
441 | * | |
442 | * RETURNS: | |
443 | * | |
444 | * 0 on success or a negative error code on failure. | |
445 | */ | |
4c813d4d DA |
446 | int (*cursor_set2)(struct drm_crtc *crtc, struct drm_file *file_priv, |
447 | uint32_t handle, uint32_t width, uint32_t height, | |
448 | int32_t hot_x, int32_t hot_y); | |
f6da8c6e DV |
449 | |
450 | /** | |
451 | * @cursor_move: | |
452 | * | |
453 | * Update the cursor position. The cursor does not need to be visible | |
454 | * when this hook is called. | |
455 | * | |
456 | * This entry point is deprecated, drivers should instead implement | |
457 | * universal plane support and register a proper cursor plane using | |
458 | * drm_crtc_init_with_planes(). | |
459 | * | |
460 | * This callback is optional. | |
461 | * | |
462 | * RETURNS: | |
463 | * | |
464 | * 0 on success or a negative error code on failure. | |
465 | */ | |
f453ba04 DA |
466 | int (*cursor_move)(struct drm_crtc *crtc, int x, int y); |
467 | ||
f6da8c6e DV |
468 | /** |
469 | * @gamma_set: | |
470 | * | |
471 | * Set gamma on the CRTC. | |
472 | * | |
473 | * This callback is optional. | |
474 | * | |
475 | * NOTE: | |
476 | * | |
477 | * Drivers that support gamma tables and also fbdev emulation through | |
478 | * the provided helper library need to take care to fill out the gamma | |
479 | * hooks for both. Currently there's a bit an unfortunate duplication | |
480 | * going on, which should eventually be unified to just one set of | |
481 | * hooks. | |
482 | */ | |
f453ba04 | 483 | void (*gamma_set)(struct drm_crtc *crtc, u16 *r, u16 *g, u16 *b, |
7203425a | 484 | uint32_t start, uint32_t size); |
88548636 DV |
485 | |
486 | /** | |
487 | * @destroy: | |
488 | * | |
489 | * Clean up plane resources. This is only called at driver unload time | |
490 | * through drm_mode_config_cleanup() since a CRTC cannot be hotplugged | |
491 | * in DRM. | |
492 | */ | |
f453ba04 DA |
493 | void (*destroy)(struct drm_crtc *crtc); |
494 | ||
f6da8c6e DV |
495 | /** |
496 | * @set_config: | |
497 | * | |
498 | * This is the main legacy entry point to change the modeset state on a | |
499 | * CRTC. All the details of the desired configuration are passed in a | |
500 | * struct &drm_mode_set - see there for details. | |
501 | * | |
502 | * Drivers implementing atomic modeset should use | |
503 | * drm_atomic_helper_set_config() to implement this hook. | |
504 | * | |
505 | * RETURNS: | |
506 | * | |
507 | * 0 on success or a negative error code on failure. | |
508 | */ | |
f453ba04 | 509 | int (*set_config)(struct drm_mode_set *set); |
d91d8a3f | 510 | |
f6da8c6e DV |
511 | /** |
512 | * @page_flip: | |
513 | * | |
514 | * Legacy entry point to schedule a flip to the given framebuffer. | |
515 | * | |
516 | * Page flipping is a synchronization mechanism that replaces the frame | |
517 | * buffer being scanned out by the CRTC with a new frame buffer during | |
518 | * vertical blanking, avoiding tearing (except when requested otherwise | |
519 | * through the DRM_MODE_PAGE_FLIP_ASYNC flag). When an application | |
520 | * requests a page flip the DRM core verifies that the new frame buffer | |
521 | * is large enough to be scanned out by the CRTC in the currently | |
522 | * configured mode and then calls the CRTC ->page_flip() operation with a | |
523 | * pointer to the new frame buffer. | |
524 | * | |
525 | * The driver must wait for any pending rendering to the new framebuffer | |
526 | * to complete before executing the flip. It should also wait for any | |
527 | * pending rendering from other drivers if the underlying buffer is a | |
528 | * shared dma-buf. | |
529 | * | |
530 | * An application can request to be notified when the page flip has | |
531 | * completed. The drm core will supply a struct &drm_event in the event | |
532 | * parameter in this case. This can be handled by the | |
533 | * drm_crtc_send_vblank_event() function, which the driver should call on | |
534 | * the provided event upon completion of the flip. Note that if | |
535 | * the driver supports vblank signalling and timestamping the vblank | |
536 | * counters and timestamps must agree with the ones returned from page | |
537 | * flip events. With the current vblank helper infrastructure this can | |
538 | * be achieved by holding a vblank reference while the page flip is | |
539 | * pending, acquired through drm_crtc_vblank_get() and released with | |
540 | * drm_crtc_vblank_put(). Drivers are free to implement their own vblank | |
541 | * counter and timestamp tracking though, e.g. if they have accurate | |
542 | * timestamp registers in hardware. | |
543 | * | |
544 | * FIXME: | |
545 | * | |
546 | * Up to that point drivers need to manage events themselves and can use | |
547 | * even->base.list freely for that. Specifically they need to ensure | |
548 | * that they don't send out page flip (or vblank) events for which the | |
549 | * corresponding drm file has been closed already. The drm core | |
550 | * unfortunately does not (yet) take care of that. Therefore drivers | |
551 | * currently must clean up and release pending events in their | |
552 | * ->preclose driver function. | |
553 | * | |
554 | * This callback is optional. | |
555 | * | |
556 | * NOTE: | |
557 | * | |
558 | * Very early versions of the KMS ABI mandated that the driver must | |
559 | * block (but not reject) any rendering to the old framebuffer until the | |
560 | * flip operation has completed and the old framebuffer is no longer | |
561 | * visible. This requirement has been lifted, and userspace is instead | |
562 | * expected to request delivery of an event and wait with recycling old | |
563 | * buffers until such has been received. | |
564 | * | |
565 | * RETURNS: | |
566 | * | |
567 | * 0 on success or a negative error code on failure. Note that if a | |
568 | * ->page_flip() operation is already pending the callback should return | |
569 | * -EBUSY. Pageflips on a disabled CRTC (either by setting a NULL mode | |
570 | * or just runtime disabled through DPMS respectively the new atomic | |
4cba6850 DV |
571 | * "ACTIVE" state) should result in an -EINVAL error code. Note that |
572 | * drm_atomic_helper_page_flip() checks this already for atomic drivers. | |
d91d8a3f KH |
573 | */ |
574 | int (*page_flip)(struct drm_crtc *crtc, | |
575 | struct drm_framebuffer *fb, | |
ed8d1975 KP |
576 | struct drm_pending_vblank_event *event, |
577 | uint32_t flags); | |
bffd9de0 | 578 | |
88548636 DV |
579 | /** |
580 | * @set_property: | |
581 | * | |
582 | * This is the legacy entry point to update a property attached to the | |
583 | * CRTC. | |
584 | * | |
585 | * Drivers implementing atomic modeset should use | |
586 | * drm_atomic_helper_crtc_set_property() to implement this hook. | |
587 | * | |
588 | * This callback is optional if the driver does not support any legacy | |
589 | * driver-private properties. | |
590 | * | |
591 | * RETURNS: | |
592 | * | |
593 | * 0 on success or a negative error code on failure. | |
594 | */ | |
bffd9de0 PZ |
595 | int (*set_property)(struct drm_crtc *crtc, |
596 | struct drm_property *property, uint64_t val); | |
144ecb97 | 597 | |
88548636 DV |
598 | /** |
599 | * @atomic_duplicate_state: | |
600 | * | |
601 | * Duplicate the current atomic state for this CRTC and return it. | |
602 | * The core and helpers gurantee that any atomic state duplicated with | |
603 | * this hook and still owned by the caller (i.e. not transferred to the | |
604 | * driver by calling ->atomic_commit() from struct | |
605 | * &drm_mode_config_funcs) will be cleaned up by calling the | |
606 | * @atomic_destroy_state hook in this structure. | |
607 | * | |
608 | * Atomic drivers which don't subclass struct &drm_crtc should use | |
609 | * drm_atomic_helper_crtc_duplicate_state(). Drivers that subclass the | |
610 | * state structure to extend it with driver-private state should use | |
611 | * __drm_atomic_helper_crtc_duplicate_state() to make sure shared state is | |
612 | * duplicated in a consistent fashion across drivers. | |
613 | * | |
614 | * It is an error to call this hook before crtc->state has been | |
615 | * initialized correctly. | |
616 | * | |
617 | * NOTE: | |
618 | * | |
619 | * If the duplicate state references refcounted resources this hook must | |
620 | * acquire a reference for each of them. The driver must release these | |
621 | * references again in @atomic_destroy_state. | |
622 | * | |
623 | * RETURNS: | |
624 | * | |
625 | * Duplicated atomic state or NULL when the allocation failed. | |
626 | */ | |
144ecb97 | 627 | struct drm_crtc_state *(*atomic_duplicate_state)(struct drm_crtc *crtc); |
88548636 DV |
628 | |
629 | /** | |
630 | * @atomic_destroy_state: | |
631 | * | |
632 | * Destroy a state duplicated with @atomic_duplicate_state and release | |
633 | * or unreference all resources it references | |
634 | */ | |
144ecb97 | 635 | void (*atomic_destroy_state)(struct drm_crtc *crtc, |
cc4ceb48 | 636 | struct drm_crtc_state *state); |
88548636 DV |
637 | |
638 | /** | |
639 | * @atomic_set_property: | |
640 | * | |
641 | * Decode a driver-private property value and store the decoded value | |
642 | * into the passed-in state structure. Since the atomic core decodes all | |
643 | * standardized properties (even for extensions beyond the core set of | |
644 | * properties which might not be implemented by all drivers) this | |
645 | * requires drivers to subclass the state structure. | |
646 | * | |
647 | * Such driver-private properties should really only be implemented for | |
648 | * truly hardware/vendor specific state. Instead it is preferred to | |
649 | * standardize atomic extension and decode the properties used to expose | |
650 | * such an extension in the core. | |
651 | * | |
652 | * Do not call this function directly, use | |
653 | * drm_atomic_crtc_set_property() instead. | |
654 | * | |
655 | * This callback is optional if the driver does not support any | |
656 | * driver-private atomic properties. | |
657 | * | |
658 | * NOTE: | |
659 | * | |
660 | * This function is called in the state assembly phase of atomic | |
661 | * modesets, which can be aborted for any reason (including on | |
662 | * userspace's request to just check whether a configuration would be | |
663 | * possible). Drivers MUST NOT touch any persistent state (hardware or | |
664 | * software) or data structures except the passed in @state parameter. | |
665 | * | |
666 | * Also since userspace controls in which order properties are set this | |
667 | * function must not do any input validation (since the state update is | |
668 | * incomplete and hence likely inconsistent). Instead any such input | |
669 | * validation must be done in the various atomic_check callbacks. | |
670 | * | |
671 | * RETURNS: | |
672 | * | |
673 | * 0 if the property has been found, -EINVAL if the property isn't | |
674 | * implemented by the driver (which should never happen, the core only | |
675 | * asks for properties attached to this CRTC). No other validation is | |
676 | * allowed by the driver. The core already checks that the property | |
677 | * value is within the range (integer, valid enum value, ...) the driver | |
678 | * set when registering the property. | |
679 | */ | |
144ecb97 DV |
680 | int (*atomic_set_property)(struct drm_crtc *crtc, |
681 | struct drm_crtc_state *state, | |
682 | struct drm_property *property, | |
683 | uint64_t val); | |
88548636 DV |
684 | /** |
685 | * @atomic_get_property: | |
686 | * | |
687 | * Reads out the decoded driver-private property. This is used to | |
c6b0ca3e | 688 | * implement the GETCRTC IOCTL. |
88548636 DV |
689 | * |
690 | * Do not call this function directly, use | |
691 | * drm_atomic_crtc_get_property() instead. | |
692 | * | |
693 | * This callback is optional if the driver does not support any | |
694 | * driver-private atomic properties. | |
695 | * | |
696 | * RETURNS: | |
697 | * | |
698 | * 0 on success, -EINVAL if the property isn't implemented by the | |
699 | * driver (which should never happen, the core only asks for | |
700 | * properties attached to this CRTC). | |
701 | */ | |
ac9c9256 RC |
702 | int (*atomic_get_property)(struct drm_crtc *crtc, |
703 | const struct drm_crtc_state *state, | |
704 | struct drm_property *property, | |
705 | uint64_t *val); | |
f453ba04 DA |
706 | }; |
707 | ||
708 | /** | |
3bf0401c | 709 | * struct drm_crtc - central CRTC control structure |
7749163e | 710 | * @dev: parent DRM device |
2c0c33d4 | 711 | * @port: OF node used by drm_of_find_possible_crtcs() |
7749163e | 712 | * @head: list management |
51fd371b | 713 | * @mutex: per-CRTC locking |
7749163e | 714 | * @base: base KMS object for ID tracking etc. |
e13161af MR |
715 | * @primary: primary plane for this CRTC |
716 | * @cursor: cursor plane for this CRTC | |
2c0c33d4 DV |
717 | * @cursor_x: current x position of the cursor, used for universal cursor planes |
718 | * @cursor_y: current y position of the cursor, used for universal cursor planes | |
f453ba04 | 719 | * @enabled: is this CRTC enabled? |
7749163e JB |
720 | * @mode: current mode timings |
721 | * @hwmode: mode timings as programmed to hw regs | |
f453ba04 DA |
722 | * @x: x position on screen |
723 | * @y: y position on screen | |
f453ba04 | 724 | * @funcs: CRTC control functions |
7749163e JB |
725 | * @gamma_size: size of gamma ramp |
726 | * @gamma_store: gamma ramp values | |
7749163e | 727 | * @helper_private: mid-layer private data |
bffd9de0 | 728 | * @properties: property tracking for this CRTC |
144ecb97 | 729 | * @state: current atomic state for this CRTC |
2c0c33d4 | 730 | * @acquire_ctx: per-CRTC implicit acquire context used by atomic drivers for |
c6b0ca3e | 731 | * legacy IOCTLs |
f453ba04 DA |
732 | * |
733 | * Each CRTC may have one or more connectors associated with it. This structure | |
734 | * allows the CRTC to be controlled. | |
735 | */ | |
736 | struct drm_crtc { | |
737 | struct drm_device *dev; | |
7e435aad | 738 | struct device_node *port; |
f453ba04 DA |
739 | struct list_head head; |
740 | ||
fa3ab4c2 VS |
741 | char *name; |
742 | ||
3bf0401c | 743 | /* |
29494c17 DV |
744 | * crtc mutex |
745 | * | |
746 | * This provides a read lock for the overall crtc state (mode, dpms | |
747 | * state, ...) and a write lock for everything which can be update | |
748 | * without a full modeset (fb, cursor data, ...) | |
749 | */ | |
51fd371b | 750 | struct drm_modeset_lock mutex; |
29494c17 | 751 | |
f453ba04 DA |
752 | struct drm_mode_object base; |
753 | ||
e13161af MR |
754 | /* primary and cursor planes for CRTC */ |
755 | struct drm_plane *primary; | |
756 | struct drm_plane *cursor; | |
757 | ||
161d0dc1 MR |
758 | /* position of cursor plane on crtc */ |
759 | int cursor_x; | |
760 | int cursor_y; | |
761 | ||
f453ba04 DA |
762 | bool enabled; |
763 | ||
27641c3f | 764 | /* Requested mode from modesetting. */ |
f453ba04 DA |
765 | struct drm_display_mode mode; |
766 | ||
27641c3f MK |
767 | /* Programmed mode in hw, after adjustments for encoders, |
768 | * crtc, panel scaling etc. Needed for timestamping etc. | |
769 | */ | |
770 | struct drm_display_mode hwmode; | |
771 | ||
f453ba04 | 772 | int x, y; |
f453ba04 DA |
773 | const struct drm_crtc_funcs *funcs; |
774 | ||
5488dc16 | 775 | /* Legacy FB CRTC gamma size for reporting to userspace */ |
f453ba04 DA |
776 | uint32_t gamma_size; |
777 | uint16_t *gamma_store; | |
778 | ||
779 | /* if you are using the helper */ | |
4490d4c7 | 780 | const struct drm_crtc_helper_funcs *helper_private; |
bffd9de0 PZ |
781 | |
782 | struct drm_object_properties properties; | |
d059f652 | 783 | |
144ecb97 DV |
784 | struct drm_crtc_state *state; |
785 | ||
d059f652 | 786 | /* |
c6b0ca3e | 787 | * For legacy crtc IOCTLs so that atomic drivers can get at the locking |
d059f652 DV |
788 | * acquire context. |
789 | */ | |
790 | struct drm_modeset_acquire_ctx *acquire_ctx; | |
f453ba04 DA |
791 | }; |
792 | ||
144ecb97 DV |
793 | /** |
794 | * struct drm_connector_state - mutable connector state | |
07cc0ef6 | 795 | * @connector: backpointer to the connector |
cc4ceb48 | 796 | * @crtc: CRTC to connect connector to, NULL if disabled |
623369e5 | 797 | * @best_encoder: can be used by helpers and drivers to select the encoder |
144ecb97 DV |
798 | * @state: backpointer to global drm_atomic_state |
799 | */ | |
800 | struct drm_connector_state { | |
07cc0ef6 DV |
801 | struct drm_connector *connector; |
802 | ||
6ddd388a | 803 | struct drm_crtc *crtc; /* do not write directly, use drm_atomic_set_crtc_for_connector() */ |
144ecb97 | 804 | |
623369e5 DV |
805 | struct drm_encoder *best_encoder; |
806 | ||
144ecb97 DV |
807 | struct drm_atomic_state *state; |
808 | }; | |
f453ba04 DA |
809 | |
810 | /** | |
3bf0401c | 811 | * struct drm_connector_funcs - control connectors on a given device |
144ecb97 | 812 | * |
f453ba04 DA |
813 | * Each CRTC may have one or more connectors attached to it. The functions |
814 | * below allow the core DRM code to control connectors, enumerate available modes, | |
815 | * etc. | |
816 | */ | |
817 | struct drm_connector_funcs { | |
6fe14acd DV |
818 | /** |
819 | * @dpms: | |
820 | * | |
821 | * Legacy entry point to set the per-connector DPMS state. Legacy DPMS | |
822 | * is exposed as a standard property on the connector, but diverted to | |
823 | * this callback in the drm core. Note that atomic drivers don't | |
824 | * implement the 4 level DPMS support on the connector any more, but | |
825 | * instead only have an on/off "ACTIVE" property on the CRTC object. | |
826 | * | |
827 | * Drivers implementing atomic modeset should use | |
828 | * drm_atomic_helper_connector_dpms() to implement this hook. | |
829 | * | |
830 | * RETURNS: | |
831 | * | |
832 | * 0 on success or a negative error code on failure. | |
833 | */ | |
9a69a9ac | 834 | int (*dpms)(struct drm_connector *connector, int mode); |
88548636 DV |
835 | |
836 | /** | |
837 | * @reset: | |
838 | * | |
839 | * Reset connector hardware and software state to off. This function isn't | |
840 | * called by the core directly, only through drm_mode_config_reset(). | |
841 | * It's not a helper hook only for historical reasons. | |
842 | * | |
843 | * Atomic drivers can use drm_atomic_helper_connector_reset() to reset | |
844 | * atomic state using this hook. | |
845 | */ | |
eb033556 | 846 | void (*reset)(struct drm_connector *connector); |
930a9e28 | 847 | |
6fe14acd DV |
848 | /** |
849 | * @detect: | |
850 | * | |
851 | * Check to see if anything is attached to the connector. The parameter | |
852 | * force is set to false whilst polling, true when checking the | |
853 | * connector due to a user request. force can be used by the driver to | |
854 | * avoid expensive, destructive operations during automated probing. | |
855 | * | |
856 | * FIXME: | |
857 | * | |
858 | * Note that this hook is only called by the probe helper. It's not in | |
859 | * the helper library vtable purely for historical reasons. The only DRM | |
860 | * core entry point to probe connector state is @fill_modes. | |
861 | * | |
862 | * RETURNS: | |
863 | * | |
864 | * drm_connector_status indicating the connector's status. | |
930a9e28 | 865 | */ |
7b334fcb | 866 | enum drm_connector_status (*detect)(struct drm_connector *connector, |
930a9e28 | 867 | bool force); |
6fe14acd DV |
868 | |
869 | /** | |
870 | * @force: | |
871 | * | |
872 | * This function is called to update internal encoder state when the | |
873 | * connector is forced to a certain state by userspace, either through | |
874 | * the sysfs interfaces or on the kernel cmdline. In that case the | |
875 | * @detect callback isn't called. | |
876 | * | |
877 | * FIXME: | |
878 | * | |
879 | * Note that this hook is only called by the probe helper. It's not in | |
880 | * the helper library vtable purely for historical reasons. The only DRM | |
881 | * core entry point to probe connector state is @fill_modes. | |
882 | */ | |
883 | void (*force)(struct drm_connector *connector); | |
884 | ||
885 | /** | |
886 | * @fill_modes: | |
887 | * | |
888 | * Entry point for output detection and basic mode validation. The | |
889 | * driver should reprobe the output if needed (e.g. when hotplug | |
890 | * handling is unreliable), add all detected modes to connector->modes | |
891 | * and filter out any the device can't support in any configuration. It | |
892 | * also needs to filter out any modes wider or higher than the | |
893 | * parameters max_width and max_height indicate. | |
894 | * | |
895 | * The drivers must also prune any modes no longer valid from | |
896 | * connector->modes. Furthermore it must update connector->status and | |
897 | * connector->edid. If no EDID has been received for this output | |
898 | * connector->edid must be NULL. | |
899 | * | |
900 | * Drivers using the probe helpers should use | |
901 | * drm_helper_probe_single_connector_modes() or | |
902 | * drm_helper_probe_single_connector_modes_nomerge() to implement this | |
903 | * function. | |
904 | * | |
905 | * RETURNS: | |
906 | * | |
907 | * The number of modes detected and filled into connector->modes. | |
908 | */ | |
40a518d9 | 909 | int (*fill_modes)(struct drm_connector *connector, uint32_t max_width, uint32_t max_height); |
88548636 DV |
910 | |
911 | /** | |
912 | * @set_property: | |
913 | * | |
914 | * This is the legacy entry point to update a property attached to the | |
915 | * connector. | |
916 | * | |
917 | * Drivers implementing atomic modeset should use | |
918 | * drm_atomic_helper_connector_set_property() to implement this hook. | |
919 | * | |
920 | * This callback is optional if the driver does not support any legacy | |
921 | * driver-private properties. | |
922 | * | |
923 | * RETURNS: | |
924 | * | |
925 | * 0 on success or a negative error code on failure. | |
926 | */ | |
f453ba04 DA |
927 | int (*set_property)(struct drm_connector *connector, struct drm_property *property, |
928 | uint64_t val); | |
88548636 DV |
929 | |
930 | /** | |
931 | * @destroy: | |
932 | * | |
933 | * Clean up connector resources. This is called at driver unload time | |
934 | * through drm_mode_config_cleanup(). It can also be called at runtime | |
935 | * when a connector is being hot-unplugged for drivers that support | |
936 | * connector hotplugging (e.g. DisplayPort MST). | |
937 | */ | |
f453ba04 | 938 | void (*destroy)(struct drm_connector *connector); |
144ecb97 | 939 | |
88548636 DV |
940 | /** |
941 | * @atomic_duplicate_state: | |
942 | * | |
943 | * Duplicate the current atomic state for this connector and return it. | |
944 | * The core and helpers gurantee that any atomic state duplicated with | |
945 | * this hook and still owned by the caller (i.e. not transferred to the | |
946 | * driver by calling ->atomic_commit() from struct | |
947 | * &drm_mode_config_funcs) will be cleaned up by calling the | |
948 | * @atomic_destroy_state hook in this structure. | |
949 | * | |
950 | * Atomic drivers which don't subclass struct &drm_connector_state should use | |
951 | * drm_atomic_helper_connector_duplicate_state(). Drivers that subclass the | |
952 | * state structure to extend it with driver-private state should use | |
953 | * __drm_atomic_helper_connector_duplicate_state() to make sure shared state is | |
954 | * duplicated in a consistent fashion across drivers. | |
955 | * | |
956 | * It is an error to call this hook before connector->state has been | |
957 | * initialized correctly. | |
958 | * | |
959 | * NOTE: | |
960 | * | |
961 | * If the duplicate state references refcounted resources this hook must | |
962 | * acquire a reference for each of them. The driver must release these | |
963 | * references again in @atomic_destroy_state. | |
964 | * | |
965 | * RETURNS: | |
966 | * | |
967 | * Duplicated atomic state or NULL when the allocation failed. | |
968 | */ | |
144ecb97 | 969 | struct drm_connector_state *(*atomic_duplicate_state)(struct drm_connector *connector); |
88548636 DV |
970 | |
971 | /** | |
972 | * @atomic_destroy_state: | |
973 | * | |
974 | * Destroy a state duplicated with @atomic_duplicate_state and release | |
975 | * or unreference all resources it references | |
976 | */ | |
144ecb97 | 977 | void (*atomic_destroy_state)(struct drm_connector *connector, |
cc4ceb48 | 978 | struct drm_connector_state *state); |
88548636 DV |
979 | |
980 | /** | |
981 | * @atomic_set_property: | |
982 | * | |
983 | * Decode a driver-private property value and store the decoded value | |
984 | * into the passed-in state structure. Since the atomic core decodes all | |
985 | * standardized properties (even for extensions beyond the core set of | |
986 | * properties which might not be implemented by all drivers) this | |
987 | * requires drivers to subclass the state structure. | |
988 | * | |
989 | * Such driver-private properties should really only be implemented for | |
990 | * truly hardware/vendor specific state. Instead it is preferred to | |
991 | * standardize atomic extension and decode the properties used to expose | |
992 | * such an extension in the core. | |
993 | * | |
994 | * Do not call this function directly, use | |
995 | * drm_atomic_connector_set_property() instead. | |
996 | * | |
997 | * This callback is optional if the driver does not support any | |
998 | * driver-private atomic properties. | |
999 | * | |
1000 | * NOTE: | |
1001 | * | |
1002 | * This function is called in the state assembly phase of atomic | |
1003 | * modesets, which can be aborted for any reason (including on | |
1004 | * userspace's request to just check whether a configuration would be | |
1005 | * possible). Drivers MUST NOT touch any persistent state (hardware or | |
1006 | * software) or data structures except the passed in @state parameter. | |
1007 | * | |
1008 | * Also since userspace controls in which order properties are set this | |
1009 | * function must not do any input validation (since the state update is | |
1010 | * incomplete and hence likely inconsistent). Instead any such input | |
1011 | * validation must be done in the various atomic_check callbacks. | |
1012 | * | |
1013 | * RETURNS: | |
1014 | * | |
1015 | * 0 if the property has been found, -EINVAL if the property isn't | |
1016 | * implemented by the driver (which shouldn't ever happen, the core only | |
1017 | * asks for properties attached to this connector). No other validation | |
1018 | * is allowed by the driver. The core already checks that the property | |
1019 | * value is within the range (integer, valid enum value, ...) the driver | |
1020 | * set when registering the property. | |
1021 | */ | |
144ecb97 DV |
1022 | int (*atomic_set_property)(struct drm_connector *connector, |
1023 | struct drm_connector_state *state, | |
1024 | struct drm_property *property, | |
1025 | uint64_t val); | |
88548636 DV |
1026 | |
1027 | /** | |
1028 | * @atomic_get_property: | |
1029 | * | |
1030 | * Reads out the decoded driver-private property. This is used to | |
c6b0ca3e | 1031 | * implement the GETCONNECTOR IOCTL. |
88548636 DV |
1032 | * |
1033 | * Do not call this function directly, use | |
1034 | * drm_atomic_connector_get_property() instead. | |
1035 | * | |
1036 | * This callback is optional if the driver does not support any | |
1037 | * driver-private atomic properties. | |
1038 | * | |
1039 | * RETURNS: | |
1040 | * | |
1041 | * 0 on success, -EINVAL if the property isn't implemented by the | |
1042 | * driver (which shouldn't ever happen, the core only asks for | |
1043 | * properties attached to this connector). | |
1044 | */ | |
ac9c9256 RC |
1045 | int (*atomic_get_property)(struct drm_connector *connector, |
1046 | const struct drm_connector_state *state, | |
1047 | struct drm_property *property, | |
1048 | uint64_t *val); | |
f453ba04 DA |
1049 | }; |
1050 | ||
6c3db920 | 1051 | /** |
3bf0401c | 1052 | * struct drm_encoder_funcs - encoder controls |
6c3db920 JB |
1053 | * |
1054 | * Encoders sit between CRTCs and connectors. | |
1055 | */ | |
f453ba04 | 1056 | struct drm_encoder_funcs { |
88548636 DV |
1057 | /** |
1058 | * @reset: | |
1059 | * | |
1060 | * Reset encoder hardware and software state to off. This function isn't | |
1061 | * called by the core directly, only through drm_mode_config_reset(). | |
1062 | * It's not a helper hook only for historical reasons. | |
1063 | */ | |
eb033556 | 1064 | void (*reset)(struct drm_encoder *encoder); |
88548636 DV |
1065 | |
1066 | /** | |
1067 | * @destroy: | |
1068 | * | |
1069 | * Clean up encoder resources. This is only called at driver unload time | |
1070 | * through drm_mode_config_cleanup() since an encoder cannot be | |
1071 | * hotplugged in DRM. | |
1072 | */ | |
f453ba04 DA |
1073 | void (*destroy)(struct drm_encoder *encoder); |
1074 | }; | |
1075 | ||
afe887df | 1076 | #define DRM_CONNECTOR_MAX_ENCODER 3 |
f453ba04 DA |
1077 | |
1078 | /** | |
3bf0401c | 1079 | * struct drm_encoder - central DRM encoder structure |
db3e4499 JB |
1080 | * @dev: parent DRM device |
1081 | * @head: list management | |
1082 | * @base: base KMS object | |
e5748946 | 1083 | * @name: encoder name |
db3e4499 JB |
1084 | * @encoder_type: one of the %DRM_MODE_ENCODER_<foo> types in drm_mode.h |
1085 | * @possible_crtcs: bitmask of potential CRTC bindings | |
1086 | * @possible_clones: bitmask of potential sibling encoders for cloning | |
1087 | * @crtc: currently bound CRTC | |
3b336ec4 | 1088 | * @bridge: bridge associated to the encoder |
db3e4499 JB |
1089 | * @funcs: control functions |
1090 | * @helper_private: mid-layer private data | |
1091 | * | |
1092 | * CRTCs drive pixels to encoders, which convert them into signals | |
1093 | * appropriate for a given connector or set of connectors. | |
f453ba04 DA |
1094 | */ |
1095 | struct drm_encoder { | |
1096 | struct drm_device *dev; | |
1097 | struct list_head head; | |
1098 | ||
1099 | struct drm_mode_object base; | |
e5748946 | 1100 | char *name; |
f453ba04 DA |
1101 | int encoder_type; |
1102 | uint32_t possible_crtcs; | |
1103 | uint32_t possible_clones; | |
1104 | ||
1105 | struct drm_crtc *crtc; | |
3b336ec4 | 1106 | struct drm_bridge *bridge; |
f453ba04 | 1107 | const struct drm_encoder_funcs *funcs; |
4490d4c7 | 1108 | const struct drm_encoder_helper_funcs *helper_private; |
f453ba04 DA |
1109 | }; |
1110 | ||
eb1f8e4f DA |
1111 | /* should we poll this connector for connects and disconnects */ |
1112 | /* hot plug detectable */ | |
1113 | #define DRM_CONNECTOR_POLL_HPD (1 << 0) | |
1114 | /* poll for connections */ | |
1115 | #define DRM_CONNECTOR_POLL_CONNECT (1 << 1) | |
1116 | /* can cleanly poll for disconnections without flickering the screen */ | |
1117 | /* DACs should rarely do this without a lot of testing */ | |
1118 | #define DRM_CONNECTOR_POLL_DISCONNECT (1 << 2) | |
1119 | ||
76adaa34 WF |
1120 | #define MAX_ELD_BYTES 128 |
1121 | ||
f453ba04 | 1122 | /** |
3bf0401c | 1123 | * struct drm_connector - central DRM connector control structure |
72252548 JB |
1124 | * @dev: parent DRM device |
1125 | * @kdev: kernel device for sysfs attributes | |
1126 | * @attr: sysfs attributes | |
1127 | * @head: list management | |
1128 | * @base: base KMS object | |
2abdd313 | 1129 | * @name: connector name |
72252548 JB |
1130 | * @connector_type: one of the %DRM_MODE_CONNECTOR_<foo> types from drm_mode.h |
1131 | * @connector_type_id: index into connector type enum | |
f453ba04 DA |
1132 | * @interlace_allowed: can this connector handle interlaced modes? |
1133 | * @doublescan_allowed: can this connector handle doublescan? | |
2c0c33d4 | 1134 | * @stereo_allowed: can this connector handle stereo modes? |
72252548 JB |
1135 | * @modes: modes available on this connector (from fill_modes() + user) |
1136 | * @status: one of the drm_connector_status enums (connected, not, or unknown) | |
1137 | * @probed_modes: list of modes derived directly from the display | |
1138 | * @display_info: information about attached display (e.g. from EDID) | |
f453ba04 | 1139 | * @funcs: connector control functions |
72252548 | 1140 | * @edid_blob_ptr: DRM property containing EDID if present |
7e3bdf4a | 1141 | * @properties: property tracking for this connector |
2c0c33d4 | 1142 | * @path_blob_ptr: DRM blob property data for the DP MST path property |
72252548 JB |
1143 | * @polled: a %DRM_CONNECTOR_POLL_<foo> value for core driven polling |
1144 | * @dpms: current dpms state | |
1145 | * @helper_private: mid-layer private data | |
2c0c33d4 | 1146 | * @cmdline_mode: mode line parsed from the kernel cmdline for this connector |
72252548 | 1147 | * @force: a %DRM_FORCE_<foo> state for forced mode sets |
2c0c33d4 | 1148 | * @override_edid: has the EDID been overwritten through debugfs for testing? |
72252548 JB |
1149 | * @encoder_ids: valid encoders for this connector |
1150 | * @encoder: encoder driving this connector, if any | |
1151 | * @eld: EDID-like data, if present | |
1152 | * @dvi_dual: dual link DVI, if found | |
1153 | * @max_tmds_clock: max clock rate, if found | |
1154 | * @latency_present: AV delay info from ELD, if found | |
1155 | * @video_latency: video latency info from ELD, if found | |
1156 | * @audio_latency: audio latency info from ELD, if found | |
1157 | * @null_edid_counter: track sinks that give us all zeros for the EDID | |
2c0c33d4 | 1158 | * @bad_edid_counter: track sinks that give us an EDID with invalid checksum |
ac6f2e29 | 1159 | * @edid_corrupt: indicates whether the last read EDID was corrupt |
2c0c33d4 | 1160 | * @debugfs_entry: debugfs directory for this connector |
144ecb97 | 1161 | * @state: current atomic state for this connector |
40d9b043 DA |
1162 | * @has_tile: is this connector connected to a tiled monitor |
1163 | * @tile_group: tile group for the connected monitor | |
1164 | * @tile_is_single_monitor: whether the tile is one monitor housing | |
1165 | * @num_h_tile: number of horizontal tiles in the tile group | |
1166 | * @num_v_tile: number of vertical tiles in the tile group | |
1167 | * @tile_h_loc: horizontal location of this tile | |
1168 | * @tile_v_loc: vertical location of this tile | |
1169 | * @tile_h_size: horizontal size of this tile. | |
1170 | * @tile_v_size: vertical size of this tile. | |
f453ba04 DA |
1171 | * |
1172 | * Each connector may be connected to one or more CRTCs, or may be clonable by | |
1173 | * another connector if they can share a CRTC. Each connector also has a specific | |
1174 | * position in the broader display (referred to as a 'screen' though it could | |
1175 | * span multiple monitors). | |
1176 | */ | |
1177 | struct drm_connector { | |
1178 | struct drm_device *dev; | |
5bdebb18 | 1179 | struct device *kdev; |
f453ba04 DA |
1180 | struct device_attribute *attr; |
1181 | struct list_head head; | |
1182 | ||
1183 | struct drm_mode_object base; | |
1184 | ||
2abdd313 | 1185 | char *name; |
5fff80bb | 1186 | int connector_id; |
f453ba04 DA |
1187 | int connector_type; |
1188 | int connector_type_id; | |
1189 | bool interlace_allowed; | |
1190 | bool doublescan_allowed; | |
560a067a | 1191 | bool stereo_allowed; |
f453ba04 DA |
1192 | struct list_head modes; /* list of modes on this connector */ |
1193 | ||
f453ba04 DA |
1194 | enum drm_connector_status status; |
1195 | ||
1196 | /* these are modes added by probing with DDC or the BIOS */ | |
1197 | struct list_head probed_modes; | |
1198 | ||
1199 | struct drm_display_info display_info; | |
1200 | const struct drm_connector_funcs *funcs; | |
1201 | ||
f453ba04 | 1202 | struct drm_property_blob *edid_blob_ptr; |
7e3bdf4a | 1203 | struct drm_object_properties properties; |
f453ba04 | 1204 | |
43aba7eb DA |
1205 | struct drm_property_blob *path_blob_ptr; |
1206 | ||
6f134d7b DA |
1207 | struct drm_property_blob *tile_blob_ptr; |
1208 | ||
eb1f8e4f DA |
1209 | uint8_t polled; /* DRM_CONNECTOR_POLL_* */ |
1210 | ||
c9fb15f6 KP |
1211 | /* requested DPMS state */ |
1212 | int dpms; | |
1213 | ||
4490d4c7 | 1214 | const struct drm_connector_helper_funcs *helper_private; |
f453ba04 | 1215 | |
d50ba256 | 1216 | /* forced on connector */ |
eaf99c74 | 1217 | struct drm_cmdline_mode cmdline_mode; |
d50ba256 | 1218 | enum drm_connector_force force; |
4cf2b281 | 1219 | bool override_edid; |
f453ba04 | 1220 | uint32_t encoder_ids[DRM_CONNECTOR_MAX_ENCODER]; |
f453ba04 | 1221 | struct drm_encoder *encoder; /* currently active encoder */ |
4a9a8b71 | 1222 | |
76adaa34 WF |
1223 | /* EDID bits */ |
1224 | uint8_t eld[MAX_ELD_BYTES]; | |
1225 | bool dvi_dual; | |
1226 | int max_tmds_clock; /* in MHz */ | |
1227 | bool latency_present[2]; | |
1228 | int video_latency[2]; /* [0]: progressive, [1]: interlaced */ | |
1229 | int audio_latency[2]; | |
4a9a8b71 | 1230 | int null_edid_counter; /* needed to workaround some HW bugs where we get all 0s */ |
0b2443ed | 1231 | unsigned bad_edid_counter; |
30f65707 | 1232 | |
6ba2bd3d TP |
1233 | /* Flag for raw EDID header corruption - used in Displayport |
1234 | * compliance testing - * Displayport Link CTS Core 1.2 rev1.1 4.2.2.6 | |
1235 | */ | |
1236 | bool edid_corrupt; | |
1237 | ||
30f65707 | 1238 | struct dentry *debugfs_entry; |
144ecb97 DV |
1239 | |
1240 | struct drm_connector_state *state; | |
40d9b043 DA |
1241 | |
1242 | /* DisplayID bits */ | |
1243 | bool has_tile; | |
1244 | struct drm_tile_group *tile_group; | |
1245 | bool tile_is_single_monitor; | |
1246 | ||
1247 | uint8_t num_h_tile, num_v_tile; | |
1248 | uint8_t tile_h_loc, tile_v_loc; | |
1249 | uint16_t tile_h_size, tile_v_size; | |
144ecb97 DV |
1250 | }; |
1251 | ||
1252 | /** | |
1253 | * struct drm_plane_state - mutable plane state | |
07cc0ef6 | 1254 | * @plane: backpointer to the plane |
144ecb97 | 1255 | * @crtc: currently bound CRTC, NULL if disabled |
cc4ceb48 | 1256 | * @fb: currently bound framebuffer |
e2330f07 | 1257 | * @fence: optional fence to wait for before scanning out @fb |
144ecb97 DV |
1258 | * @crtc_x: left position of visible portion of plane on crtc |
1259 | * @crtc_y: upper position of visible portion of plane on crtc | |
1260 | * @crtc_w: width of visible portion of plane on crtc | |
1261 | * @crtc_h: height of visible portion of plane on crtc | |
1262 | * @src_x: left position of visible portion of plane within | |
1263 | * plane (in 16.16) | |
1264 | * @src_y: upper position of visible portion of plane within | |
1265 | * plane (in 16.16) | |
1266 | * @src_w: width of visible portion of plane (in 16.16) | |
1267 | * @src_h: height of visible portion of plane (in 16.16) | |
1268 | * @state: backpointer to global drm_atomic_state | |
1269 | */ | |
1270 | struct drm_plane_state { | |
07cc0ef6 DV |
1271 | struct drm_plane *plane; |
1272 | ||
6ddd388a RC |
1273 | struct drm_crtc *crtc; /* do not write directly, use drm_atomic_set_crtc_for_plane() */ |
1274 | struct drm_framebuffer *fb; /* do not write directly, use drm_atomic_set_fb_for_plane() */ | |
e2330f07 | 1275 | struct fence *fence; |
144ecb97 DV |
1276 | |
1277 | /* Signed dest location allows it to be partially off screen */ | |
1278 | int32_t crtc_x, crtc_y; | |
1279 | uint32_t crtc_w, crtc_h; | |
1280 | ||
1281 | /* Source values are 16.16 fixed point */ | |
1282 | uint32_t src_x, src_y; | |
1283 | uint32_t src_h, src_w; | |
1284 | ||
1da30627 MR |
1285 | /* Plane rotation */ |
1286 | unsigned int rotation; | |
1287 | ||
144ecb97 | 1288 | struct drm_atomic_state *state; |
f453ba04 DA |
1289 | }; |
1290 | ||
144ecb97 | 1291 | |
8cf5c917 | 1292 | /** |
3bf0401c | 1293 | * struct drm_plane_funcs - driver plane control functions |
8cf5c917 JB |
1294 | */ |
1295 | struct drm_plane_funcs { | |
88548636 DV |
1296 | /** |
1297 | * @update_plane: | |
1298 | * | |
1299 | * This is the legacy entry point to enable and configure the plane for | |
1300 | * the given CRTC and framebuffer. It is never called to disable the | |
1301 | * plane, i.e. the passed-in crtc and fb paramters are never NULL. | |
1302 | * | |
1303 | * The source rectangle in frame buffer memory coordinates is given by | |
1304 | * the src_x, src_y, src_w and src_h parameters (as 16.16 fixed point | |
1305 | * values). Devices that don't support subpixel plane coordinates can | |
1306 | * ignore the fractional part. | |
1307 | * | |
1308 | * The destination rectangle in CRTC coordinates is given by the | |
1309 | * crtc_x, crtc_y, crtc_w and crtc_h parameters (as integer values). | |
1310 | * Devices scale the source rectangle to the destination rectangle. If | |
1311 | * scaling is not supported, and the source rectangle size doesn't match | |
1312 | * the destination rectangle size, the driver must return a | |
1313 | * -<errorname>EINVAL</errorname> error. | |
1314 | * | |
1315 | * Drivers implementing atomic modeset should use | |
1316 | * drm_atomic_helper_update_plane() to implement this hook. | |
1317 | * | |
1318 | * RETURNS: | |
1319 | * | |
1320 | * 0 on success or a negative error code on failure. | |
1321 | */ | |
8cf5c917 JB |
1322 | int (*update_plane)(struct drm_plane *plane, |
1323 | struct drm_crtc *crtc, struct drm_framebuffer *fb, | |
1324 | int crtc_x, int crtc_y, | |
1325 | unsigned int crtc_w, unsigned int crtc_h, | |
1326 | uint32_t src_x, uint32_t src_y, | |
1327 | uint32_t src_w, uint32_t src_h); | |
88548636 DV |
1328 | |
1329 | /** | |
1330 | * @disable_plane: | |
1331 | * | |
1332 | * This is the legacy entry point to disable the plane. The DRM core | |
c6b0ca3e | 1333 | * calls this method in response to a DRM_IOCTL_MODE_SETPLANE IOCTL call |
88548636 DV |
1334 | * with the frame buffer ID set to 0. Disabled planes must not be |
1335 | * processed by the CRTC. | |
1336 | * | |
1337 | * Drivers implementing atomic modeset should use | |
1338 | * drm_atomic_helper_disable_plane() to implement this hook. | |
1339 | * | |
1340 | * RETURNS: | |
1341 | * | |
1342 | * 0 on success or a negative error code on failure. | |
1343 | */ | |
8cf5c917 | 1344 | int (*disable_plane)(struct drm_plane *plane); |
88548636 DV |
1345 | |
1346 | /** | |
1347 | * @destroy: | |
1348 | * | |
1349 | * Clean up plane resources. This is only called at driver unload time | |
1350 | * through drm_mode_config_cleanup() since a plane cannot be hotplugged | |
1351 | * in DRM. | |
1352 | */ | |
8cf5c917 | 1353 | void (*destroy)(struct drm_plane *plane); |
88548636 DV |
1354 | |
1355 | /** | |
1356 | * @reset: | |
1357 | * | |
1358 | * Reset plane hardware and software state to off. This function isn't | |
1359 | * called by the core directly, only through drm_mode_config_reset(). | |
1360 | * It's not a helper hook only for historical reasons. | |
1361 | * | |
1362 | * Atomic drivers can use drm_atomic_helper_plane_reset() to reset | |
1363 | * atomic state using this hook. | |
1364 | */ | |
2a0d7cfd | 1365 | void (*reset)(struct drm_plane *plane); |
4d93914a | 1366 | |
88548636 DV |
1367 | /** |
1368 | * @set_property: | |
1369 | * | |
1370 | * This is the legacy entry point to update a property attached to the | |
1371 | * plane. | |
1372 | * | |
1373 | * Drivers implementing atomic modeset should use | |
1374 | * drm_atomic_helper_plane_set_property() to implement this hook. | |
1375 | * | |
1376 | * This callback is optional if the driver does not support any legacy | |
1377 | * driver-private properties. | |
1378 | * | |
1379 | * RETURNS: | |
1380 | * | |
1381 | * 0 on success or a negative error code on failure. | |
1382 | */ | |
4d93914a RC |
1383 | int (*set_property)(struct drm_plane *plane, |
1384 | struct drm_property *property, uint64_t val); | |
144ecb97 | 1385 | |
88548636 DV |
1386 | /** |
1387 | * @atomic_duplicate_state: | |
1388 | * | |
1389 | * Duplicate the current atomic state for this plane and return it. | |
1390 | * The core and helpers gurantee that any atomic state duplicated with | |
1391 | * this hook and still owned by the caller (i.e. not transferred to the | |
1392 | * driver by calling ->atomic_commit() from struct | |
1393 | * &drm_mode_config_funcs) will be cleaned up by calling the | |
1394 | * @atomic_destroy_state hook in this structure. | |
1395 | * | |
1396 | * Atomic drivers which don't subclass struct &drm_plane_state should use | |
1397 | * drm_atomic_helper_plane_duplicate_state(). Drivers that subclass the | |
1398 | * state structure to extend it with driver-private state should use | |
1399 | * __drm_atomic_helper_plane_duplicate_state() to make sure shared state is | |
1400 | * duplicated in a consistent fashion across drivers. | |
1401 | * | |
1402 | * It is an error to call this hook before plane->state has been | |
1403 | * initialized correctly. | |
1404 | * | |
1405 | * NOTE: | |
1406 | * | |
1407 | * If the duplicate state references refcounted resources this hook must | |
1408 | * acquire a reference for each of them. The driver must release these | |
1409 | * references again in @atomic_destroy_state. | |
1410 | * | |
1411 | * RETURNS: | |
1412 | * | |
1413 | * Duplicated atomic state or NULL when the allocation failed. | |
1414 | */ | |
144ecb97 | 1415 | struct drm_plane_state *(*atomic_duplicate_state)(struct drm_plane *plane); |
88548636 DV |
1416 | |
1417 | /** | |
1418 | * @atomic_destroy_state: | |
1419 | * | |
1420 | * Destroy a state duplicated with @atomic_duplicate_state and release | |
1421 | * or unreference all resources it references | |
1422 | */ | |
144ecb97 | 1423 | void (*atomic_destroy_state)(struct drm_plane *plane, |
cc4ceb48 | 1424 | struct drm_plane_state *state); |
88548636 DV |
1425 | |
1426 | /** | |
1427 | * @atomic_set_property: | |
1428 | * | |
1429 | * Decode a driver-private property value and store the decoded value | |
1430 | * into the passed-in state structure. Since the atomic core decodes all | |
1431 | * standardized properties (even for extensions beyond the core set of | |
1432 | * properties which might not be implemented by all drivers) this | |
1433 | * requires drivers to subclass the state structure. | |
1434 | * | |
1435 | * Such driver-private properties should really only be implemented for | |
1436 | * truly hardware/vendor specific state. Instead it is preferred to | |
1437 | * standardize atomic extension and decode the properties used to expose | |
1438 | * such an extension in the core. | |
1439 | * | |
1440 | * Do not call this function directly, use | |
1441 | * drm_atomic_plane_set_property() instead. | |
1442 | * | |
1443 | * This callback is optional if the driver does not support any | |
1444 | * driver-private atomic properties. | |
1445 | * | |
1446 | * NOTE: | |
1447 | * | |
1448 | * This function is called in the state assembly phase of atomic | |
1449 | * modesets, which can be aborted for any reason (including on | |
1450 | * userspace's request to just check whether a configuration would be | |
1451 | * possible). Drivers MUST NOT touch any persistent state (hardware or | |
1452 | * software) or data structures except the passed in @state parameter. | |
1453 | * | |
1454 | * Also since userspace controls in which order properties are set this | |
1455 | * function must not do any input validation (since the state update is | |
1456 | * incomplete and hence likely inconsistent). Instead any such input | |
1457 | * validation must be done in the various atomic_check callbacks. | |
1458 | * | |
1459 | * RETURNS: | |
1460 | * | |
1461 | * 0 if the property has been found, -EINVAL if the property isn't | |
1462 | * implemented by the driver (which shouldn't ever happen, the core only | |
1463 | * asks for properties attached to this plane). No other validation is | |
1464 | * allowed by the driver. The core already checks that the property | |
1465 | * value is within the range (integer, valid enum value, ...) the driver | |
1466 | * set when registering the property. | |
1467 | */ | |
144ecb97 DV |
1468 | int (*atomic_set_property)(struct drm_plane *plane, |
1469 | struct drm_plane_state *state, | |
1470 | struct drm_property *property, | |
1471 | uint64_t val); | |
88548636 DV |
1472 | |
1473 | /** | |
1474 | * @atomic_get_property: | |
1475 | * | |
1476 | * Reads out the decoded driver-private property. This is used to | |
c6b0ca3e | 1477 | * implement the GETPLANE IOCTL. |
88548636 DV |
1478 | * |
1479 | * Do not call this function directly, use | |
1480 | * drm_atomic_plane_get_property() instead. | |
1481 | * | |
1482 | * This callback is optional if the driver does not support any | |
1483 | * driver-private atomic properties. | |
1484 | * | |
1485 | * RETURNS: | |
1486 | * | |
1487 | * 0 on success, -EINVAL if the property isn't implemented by the | |
1488 | * driver (which should never happen, the core only asks for | |
1489 | * properties attached to this plane). | |
1490 | */ | |
ac9c9256 RC |
1491 | int (*atomic_get_property)(struct drm_plane *plane, |
1492 | const struct drm_plane_state *state, | |
1493 | struct drm_property *property, | |
1494 | uint64_t *val); | |
8cf5c917 JB |
1495 | }; |
1496 | ||
e27dde3e MR |
1497 | enum drm_plane_type { |
1498 | DRM_PLANE_TYPE_OVERLAY, | |
1499 | DRM_PLANE_TYPE_PRIMARY, | |
1500 | DRM_PLANE_TYPE_CURSOR, | |
1501 | }; | |
1502 | ||
88548636 | 1503 | |
8cf5c917 | 1504 | /** |
3bf0401c | 1505 | * struct drm_plane - central DRM plane control structure |
8cf5c917 JB |
1506 | * @dev: DRM device this plane belongs to |
1507 | * @head: for list management | |
1508 | * @base: base mode object | |
1509 | * @possible_crtcs: pipes this plane can be bound to | |
1510 | * @format_types: array of formats supported by this plane | |
1511 | * @format_count: number of formats supported | |
7eb5f302 | 1512 | * @format_default: driver hasn't supplied supported formats for the plane |
8cf5c917 JB |
1513 | * @crtc: currently bound CRTC |
1514 | * @fb: currently bound fb | |
2c0c33d4 DV |
1515 | * @old_fb: Temporary tracking of the old fb while a modeset is ongoing. Used by |
1516 | * drm_mode_set_config_internal() to implement correct refcounting. | |
8cf5c917 | 1517 | * @funcs: helper functions |
4d93914a | 1518 | * @properties: property tracking for this plane |
e27dde3e | 1519 | * @type: type of plane (overlay, primary, cursor) |
144ecb97 | 1520 | * @state: current atomic state for this plane |
8cf5c917 JB |
1521 | */ |
1522 | struct drm_plane { | |
1523 | struct drm_device *dev; | |
1524 | struct list_head head; | |
1525 | ||
9f4c97a2 VS |
1526 | char *name; |
1527 | ||
4d02e2de DV |
1528 | struct drm_modeset_lock mutex; |
1529 | ||
8cf5c917 JB |
1530 | struct drm_mode_object base; |
1531 | ||
1532 | uint32_t possible_crtcs; | |
1533 | uint32_t *format_types; | |
45e3743a | 1534 | unsigned int format_count; |
7eb5f302 | 1535 | bool format_default; |
8cf5c917 JB |
1536 | |
1537 | struct drm_crtc *crtc; | |
1538 | struct drm_framebuffer *fb; | |
1539 | ||
3d30a59b DV |
1540 | struct drm_framebuffer *old_fb; |
1541 | ||
8cf5c917 | 1542 | const struct drm_plane_funcs *funcs; |
4d93914a RC |
1543 | |
1544 | struct drm_object_properties properties; | |
e27dde3e MR |
1545 | |
1546 | enum drm_plane_type type; | |
144ecb97 | 1547 | |
4490d4c7 | 1548 | const struct drm_plane_helper_funcs *helper_private; |
c2fcd274 | 1549 | |
144ecb97 | 1550 | struct drm_plane_state *state; |
8cf5c917 JB |
1551 | }; |
1552 | ||
3b336ec4 | 1553 | /** |
3bf0401c | 1554 | * struct drm_bridge_funcs - drm_bridge control functions |
3d3f8b1f | 1555 | * @attach: Called during drm_bridge_attach |
3b336ec4 SP |
1556 | */ |
1557 | struct drm_bridge_funcs { | |
3d3f8b1f | 1558 | int (*attach)(struct drm_bridge *bridge); |
da024fe5 DV |
1559 | |
1560 | /** | |
1561 | * @mode_fixup: | |
1562 | * | |
1563 | * This callback is used to validate and adjust a mode. The paramater | |
1564 | * mode is the display mode that should be fed to the next element in | |
1565 | * the display chain, either the final &drm_connector or the next | |
1566 | * &drm_bridge. The parameter adjusted_mode is the input mode the bridge | |
1567 | * requires. It can be modified by this callback and does not need to | |
1568 | * match mode. | |
1569 | * | |
1570 | * This is the only hook that allows a bridge to reject a modeset. If | |
1571 | * this function passes all other callbacks must succeed for this | |
1572 | * configuration. | |
1573 | * | |
1574 | * NOTE: | |
1575 | * | |
1576 | * This function is called in the check phase of atomic modesets, which | |
1577 | * can be aborted for any reason (including on userspace's request to | |
1578 | * just check whether a configuration would be possible). Drivers MUST | |
1579 | * NOT touch any persistent state (hardware or software) or data | |
88548636 | 1580 | * structures except the passed in @state parameter. |
da024fe5 DV |
1581 | * |
1582 | * RETURNS: | |
1583 | * | |
1584 | * True if an acceptable configuration is possible, false if the modeset | |
1585 | * operation should be rejected. | |
1586 | */ | |
3b336ec4 SP |
1587 | bool (*mode_fixup)(struct drm_bridge *bridge, |
1588 | const struct drm_display_mode *mode, | |
1589 | struct drm_display_mode *adjusted_mode); | |
da024fe5 DV |
1590 | /** |
1591 | * @disable: | |
1592 | * | |
1593 | * This callback should disable the bridge. It is called right before | |
1594 | * the preceding element in the display pipe is disabled. If the | |
1595 | * preceding element is a bridge this means it's called before that | |
1596 | * bridge's ->disable() function. If the preceding element is a | |
1597 | * &drm_encoder it's called right before the encoder's ->disable(), | |
1598 | * ->prepare() or ->dpms() hook from struct &drm_encoder_helper_funcs. | |
1599 | * | |
1600 | * The bridge can assume that the display pipe (i.e. clocks and timing | |
1601 | * signals) feeding it is still running when this callback is called. | |
c8a3b2ae LP |
1602 | * |
1603 | * The disable callback is optional. | |
da024fe5 | 1604 | */ |
3b336ec4 | 1605 | void (*disable)(struct drm_bridge *bridge); |
da024fe5 DV |
1606 | |
1607 | /** | |
1608 | * @post_disable: | |
1609 | * | |
1610 | * This callback should disable the bridge. It is called right after | |
1611 | * the preceding element in the display pipe is disabled. If the | |
1612 | * preceding element is a bridge this means it's called after that | |
1613 | * bridge's ->post_disable() function. If the preceding element is a | |
1614 | * &drm_encoder it's called right after the encoder's ->disable(), | |
1615 | * ->prepare() or ->dpms() hook from struct &drm_encoder_helper_funcs. | |
1616 | * | |
1617 | * The bridge must assume that the display pipe (i.e. clocks and timing | |
1618 | * singals) feeding it is no longer running when this callback is | |
1619 | * called. | |
c8a3b2ae LP |
1620 | * |
1621 | * The post_disable callback is optional. | |
da024fe5 | 1622 | */ |
3b336ec4 | 1623 | void (*post_disable)(struct drm_bridge *bridge); |
da024fe5 DV |
1624 | |
1625 | /** | |
1626 | * @mode_set: | |
1627 | * | |
1628 | * This callback should set the given mode on the bridge. It is called | |
1629 | * after the ->mode_set() callback for the preceding element in the | |
1630 | * display pipeline has been called already. The display pipe (i.e. | |
1631 | * clocks and timing signals) is off when this function is called. | |
1632 | */ | |
3b336ec4 SP |
1633 | void (*mode_set)(struct drm_bridge *bridge, |
1634 | struct drm_display_mode *mode, | |
1635 | struct drm_display_mode *adjusted_mode); | |
da024fe5 DV |
1636 | /** |
1637 | * @pre_enable: | |
1638 | * | |
1639 | * This callback should enable the bridge. It is called right before | |
1640 | * the preceding element in the display pipe is enabled. If the | |
1641 | * preceding element is a bridge this means it's called before that | |
1642 | * bridge's ->pre_enable() function. If the preceding element is a | |
1643 | * &drm_encoder it's called right before the encoder's ->enable(), | |
1644 | * ->commit() or ->dpms() hook from struct &drm_encoder_helper_funcs. | |
1645 | * | |
1646 | * The display pipe (i.e. clocks and timing signals) feeding this bridge | |
1647 | * will not yet be running when this callback is called. The bridge must | |
1648 | * not enable the display link feeding the next bridge in the chain (if | |
1649 | * there is one) when this callback is called. | |
c8a3b2ae LP |
1650 | * |
1651 | * The pre_enable callback is optional. | |
da024fe5 | 1652 | */ |
3b336ec4 | 1653 | void (*pre_enable)(struct drm_bridge *bridge); |
da024fe5 DV |
1654 | |
1655 | /** | |
1656 | * @enable: | |
1657 | * | |
1658 | * This callback should enable the bridge. It is called right after | |
1659 | * the preceding element in the display pipe is enabled. If the | |
1660 | * preceding element is a bridge this means it's called after that | |
1661 | * bridge's ->enable() function. If the preceding element is a | |
1662 | * &drm_encoder it's called right after the encoder's ->enable(), | |
1663 | * ->commit() or ->dpms() hook from struct &drm_encoder_helper_funcs. | |
1664 | * | |
1665 | * The bridge can assume that the display pipe (i.e. clocks and timing | |
1666 | * signals) feeding it is running when this callback is called. This | |
1667 | * callback must enable the display link feeding the next bridge in the | |
1668 | * chain if there is one. | |
c8a3b2ae LP |
1669 | * |
1670 | * The enable callback is optional. | |
da024fe5 | 1671 | */ |
3b336ec4 | 1672 | void (*enable)(struct drm_bridge *bridge); |
3b336ec4 SP |
1673 | }; |
1674 | ||
1675 | /** | |
3bf0401c | 1676 | * struct drm_bridge - central DRM bridge control structure |
3b336ec4 | 1677 | * @dev: DRM device this bridge belongs to |
862e686c AT |
1678 | * @encoder: encoder to which this bridge is connected |
1679 | * @next: the next bridge in the encoder chain | |
3d3f8b1f AK |
1680 | * @of_node: device node pointer to the bridge |
1681 | * @list: to keep track of all added bridges | |
3b336ec4 SP |
1682 | * @funcs: control functions |
1683 | * @driver_private: pointer to the bridge driver's internal context | |
1684 | */ | |
1685 | struct drm_bridge { | |
1686 | struct drm_device *dev; | |
3d3f8b1f | 1687 | struct drm_encoder *encoder; |
862e686c | 1688 | struct drm_bridge *next; |
3d3f8b1f AK |
1689 | #ifdef CONFIG_OF |
1690 | struct device_node *of_node; | |
1691 | #endif | |
1692 | struct list_head list; | |
3b336ec4 SP |
1693 | |
1694 | const struct drm_bridge_funcs *funcs; | |
1695 | void *driver_private; | |
1696 | }; | |
1697 | ||
cc4ceb48 | 1698 | /** |
08855fae | 1699 | * struct drm_atomic_state - the global state object for atomic updates |
cc4ceb48 | 1700 | * @dev: parent DRM device |
d34f20d6 | 1701 | * @allow_modeset: allow full modeset |
c6b0ca3e | 1702 | * @legacy_cursor_update: hint to enforce legacy cursor IOCTL semantics |
40616a26 | 1703 | * @legacy_set_config: Disable conflicting encoders instead of failing with -EINVAL. |
cc4ceb48 DV |
1704 | * @planes: pointer to array of plane pointers |
1705 | * @plane_states: pointer to array of plane states pointers | |
1706 | * @crtcs: pointer to array of CRTC pointers | |
1707 | * @crtc_states: pointer to array of CRTC states pointers | |
f52b69f1 | 1708 | * @num_connector: size of the @connectors and @connector_states arrays |
cc4ceb48 DV |
1709 | * @connectors: pointer to array of connector pointers |
1710 | * @connector_states: pointer to array of connector states pointers | |
1711 | * @acquire_ctx: acquire context for this atomic modeset state update | |
1712 | */ | |
1713 | struct drm_atomic_state { | |
1714 | struct drm_device *dev; | |
d34f20d6 | 1715 | bool allow_modeset : 1; |
f02ad907 | 1716 | bool legacy_cursor_update : 1; |
40616a26 | 1717 | bool legacy_set_config : 1; |
cc4ceb48 DV |
1718 | struct drm_plane **planes; |
1719 | struct drm_plane_state **plane_states; | |
1720 | struct drm_crtc **crtcs; | |
1721 | struct drm_crtc_state **crtc_states; | |
f52b69f1 | 1722 | int num_connector; |
cc4ceb48 DV |
1723 | struct drm_connector **connectors; |
1724 | struct drm_connector_state **connector_states; | |
1725 | ||
1726 | struct drm_modeset_acquire_ctx *acquire_ctx; | |
1727 | }; | |
1728 | ||
1729 | ||
f453ba04 | 1730 | /** |
3bf0401c | 1731 | * struct drm_mode_set - new values for a CRTC config change |
ef27351a JB |
1732 | * @fb: framebuffer to use for new config |
1733 | * @crtc: CRTC whose configuration we're about to change | |
1734 | * @mode: mode timings to use | |
1735 | * @x: position of this CRTC relative to @fb | |
1736 | * @y: position of this CRTC relative to @fb | |
1737 | * @connectors: array of connectors to drive with this CRTC if possible | |
1738 | * @num_connectors: size of @connectors array | |
f453ba04 DA |
1739 | * |
1740 | * Represents a single crtc the connectors that it drives with what mode | |
1741 | * and from which framebuffer it scans out from. | |
1742 | * | |
1743 | * This is used to set modes. | |
1744 | */ | |
1745 | struct drm_mode_set { | |
f453ba04 DA |
1746 | struct drm_framebuffer *fb; |
1747 | struct drm_crtc *crtc; | |
1748 | struct drm_display_mode *mode; | |
1749 | ||
1750 | uint32_t x; | |
1751 | uint32_t y; | |
1752 | ||
1753 | struct drm_connector **connectors; | |
1754 | size_t num_connectors; | |
1755 | }; | |
1756 | ||
1757 | /** | |
550cebcd | 1758 | * struct drm_mode_config_funcs - basic driver provided mode setting functions |
550cebcd JB |
1759 | * |
1760 | * Some global (i.e. not per-CRTC, connector, etc) mode setting functions that | |
1761 | * involve drivers. | |
f453ba04 DA |
1762 | */ |
1763 | struct drm_mode_config_funcs { | |
9953f417 DV |
1764 | /** |
1765 | * @fb_create: | |
1766 | * | |
1767 | * Create a new framebuffer object. The core does basic checks on the | |
1768 | * requested metadata, but most of that is left to the driver. See | |
1769 | * struct &drm_mode_fb_cmd2 for details. | |
1770 | * | |
d55f5320 DV |
1771 | * If the parameters are deemed valid and the backing storage objects in |
1772 | * the underlying memory manager all exist, then the driver allocates | |
1773 | * a new &drm_framebuffer structure, subclassed to contain | |
1774 | * driver-specific information (like the internal native buffer object | |
1775 | * references). It also needs to fill out all relevant metadata, which | |
1776 | * should be done by calling drm_helper_mode_fill_fb_struct(). | |
1777 | * | |
1778 | * The initialization is finalized by calling drm_framebuffer_init(), | |
1779 | * which registers the framebuffer and makes it accessible to other | |
1780 | * threads. | |
1781 | * | |
9953f417 DV |
1782 | * RETURNS: |
1783 | * | |
1784 | * A new framebuffer with an initial reference count of 1 or a negative | |
1785 | * error code encoded with ERR_PTR(). | |
1786 | */ | |
550cebcd JB |
1787 | struct drm_framebuffer *(*fb_create)(struct drm_device *dev, |
1788 | struct drm_file *file_priv, | |
1eb83451 | 1789 | const struct drm_mode_fb_cmd2 *mode_cmd); |
9953f417 DV |
1790 | |
1791 | /** | |
1792 | * @output_poll_changed: | |
1793 | * | |
1794 | * Callback used by helpers to inform the driver of output configuration | |
1795 | * changes. | |
1796 | * | |
1797 | * Drivers implementing fbdev emulation with the helpers can call | |
1798 | * drm_fb_helper_hotplug_changed from this hook to inform the fbdev | |
1799 | * helper of output changes. | |
1800 | * | |
1801 | * FIXME: | |
1802 | * | |
1803 | * Except that there's no vtable for device-level helper callbacks | |
1804 | * there's no reason this is a core function. | |
1805 | */ | |
eb1f8e4f | 1806 | void (*output_poll_changed)(struct drm_device *dev); |
cc4ceb48 | 1807 | |
9953f417 DV |
1808 | /** |
1809 | * @atomic_check: | |
1810 | * | |
1811 | * This is the only hook to validate an atomic modeset update. This | |
1812 | * function must reject any modeset and state changes which the hardware | |
1813 | * or driver doesn't support. This includes but is of course not limited | |
1814 | * to: | |
1815 | * | |
1816 | * - Checking that the modes, framebuffers, scaling and placement | |
1817 | * requirements and so on are within the limits of the hardware. | |
1818 | * | |
1819 | * - Checking that any hidden shared resources are not oversubscribed. | |
1820 | * This can be shared PLLs, shared lanes, overall memory bandwidth, | |
1821 | * display fifo space (where shared between planes or maybe even | |
1822 | * CRTCs). | |
1823 | * | |
1824 | * - Checking that virtualized resources exported to userspace are not | |
1825 | * oversubscribed. For various reasons it can make sense to expose | |
1826 | * more planes, crtcs or encoders than which are physically there. One | |
1827 | * example is dual-pipe operations (which generally should be hidden | |
1828 | * from userspace if when lockstepped in hardware, exposed otherwise), | |
1829 | * where a plane might need 1 hardware plane (if it's just on one | |
1830 | * pipe), 2 hardware planes (when it spans both pipes) or maybe even | |
1831 | * shared a hardware plane with a 2nd plane (if there's a compatible | |
1832 | * plane requested on the area handled by the other pipe). | |
1833 | * | |
1834 | * - Check that any transitional state is possible and that if | |
1835 | * requested, the update can indeed be done in the vblank period | |
1836 | * without temporarily disabling some functions. | |
1837 | * | |
1838 | * - Check any other constraints the driver or hardware might have. | |
1839 | * | |
1840 | * - This callback also needs to correctly fill out the &drm_crtc_state | |
1841 | * in this update to make sure that drm_atomic_crtc_needs_modeset() | |
1842 | * reflects the nature of the possible update and returns true if and | |
1843 | * only if the update cannot be applied without tearing within one | |
1844 | * vblank on that CRTC. The core uses that information to reject | |
1845 | * updates which require a full modeset (i.e. blanking the screen, or | |
1846 | * at least pausing updates for a substantial amount of time) if | |
1847 | * userspace has disallowed that in its request. | |
1848 | * | |
1849 | * - The driver also does not need to repeat basic input validation | |
1850 | * like done for the corresponding legacy entry points. The core does | |
1851 | * that before calling this hook. | |
1852 | * | |
1853 | * See the documentation of @atomic_commit for an exhaustive list of | |
1854 | * error conditions which don't have to be checked at the | |
1855 | * ->atomic_check() stage? | |
1856 | * | |
1857 | * See the documentation for struct &drm_atomic_state for how exactly | |
1858 | * an atomic modeset update is described. | |
1859 | * | |
1860 | * Drivers using the atomic helpers can implement this hook using | |
1861 | * drm_atomic_helper_check(), or one of the exported sub-functions of | |
1862 | * it. | |
1863 | * | |
1864 | * RETURNS: | |
1865 | * | |
1866 | * 0 on success or one of the below negative error codes: | |
1867 | * | |
1868 | * - -EINVAL, if any of the above constraints are violated. | |
1869 | * | |
1870 | * - -EDEADLK, when returned from an attempt to acquire an additional | |
1871 | * &drm_modeset_lock through drm_modeset_lock(). | |
1872 | * | |
1873 | * - -ENOMEM, if allocating additional state sub-structures failed due | |
1874 | * to lack of memory. | |
1875 | * | |
1876 | * - -EINTR, -EAGAIN or -ERESTARTSYS, if the IOCTL should be restarted. | |
1877 | * This can either be due to a pending signal, or because the driver | |
1878 | * needs to completely bail out to recover from an exceptional | |
1879 | * situation like a GPU hang. From a userspace point all errors are | |
1880 | * treated equally. | |
1881 | */ | |
cc4ceb48 | 1882 | int (*atomic_check)(struct drm_device *dev, |
9953f417 DV |
1883 | struct drm_atomic_state *state); |
1884 | ||
1885 | /** | |
1886 | * @atomic_commit: | |
1887 | * | |
1888 | * This is the only hook to commit an atomic modeset update. The core | |
1889 | * guarantees that @atomic_check has been called successfully before | |
1890 | * calling this function, and that nothing has been changed in the | |
1891 | * interim. | |
1892 | * | |
1893 | * See the documentation for struct &drm_atomic_state for how exactly | |
1894 | * an atomic modeset update is described. | |
1895 | * | |
1896 | * Drivers using the atomic helpers can implement this hook using | |
1897 | * drm_atomic_helper_commit(), or one of the exported sub-functions of | |
1898 | * it. | |
1899 | * | |
286dbb8d | 1900 | * Nonblocking commits (as indicated with the nonblock parameter) must |
9953f417 DV |
1901 | * do any preparatory work which might result in an unsuccessful commit |
1902 | * in the context of this callback. The only exceptions are hardware | |
1903 | * errors resulting in -EIO. But even in that case the driver must | |
1904 | * ensure that the display pipe is at least running, to avoid | |
1905 | * compositors crashing when pageflips don't work. Anything else, | |
1906 | * specifically committing the update to the hardware, should be done | |
1907 | * without blocking the caller. For updates which do not require a | |
1908 | * modeset this must be guaranteed. | |
1909 | * | |
1910 | * The driver must wait for any pending rendering to the new | |
1911 | * framebuffers to complete before executing the flip. It should also | |
1912 | * wait for any pending rendering from other drivers if the underlying | |
286dbb8d | 1913 | * buffer is a shared dma-buf. Nonblocking commits must not wait for |
9953f417 DV |
1914 | * rendering in the context of this callback. |
1915 | * | |
1916 | * An application can request to be notified when the atomic commit has | |
1917 | * completed. These events are per-CRTC and can be distinguished by the | |
1918 | * CRTC index supplied in &drm_event to userspace. | |
1919 | * | |
1920 | * The drm core will supply a struct &drm_event in the event | |
1921 | * member of each CRTC's &drm_crtc_state structure. This can be handled by the | |
1922 | * drm_crtc_send_vblank_event() function, which the driver should call on | |
1923 | * the provided event upon completion of the atomic commit. Note that if | |
1924 | * the driver supports vblank signalling and timestamping the vblank | |
1925 | * counters and timestamps must agree with the ones returned from page | |
1926 | * flip events. With the current vblank helper infrastructure this can | |
1927 | * be achieved by holding a vblank reference while the page flip is | |
1928 | * pending, acquired through drm_crtc_vblank_get() and released with | |
1929 | * drm_crtc_vblank_put(). Drivers are free to implement their own vblank | |
1930 | * counter and timestamp tracking though, e.g. if they have accurate | |
1931 | * timestamp registers in hardware. | |
1932 | * | |
1933 | * NOTE: | |
1934 | * | |
1935 | * Drivers are not allowed to shut down any display pipe successfully | |
1936 | * enabled through an atomic commit on their own. Doing so can result in | |
1937 | * compositors crashing if a page flip is suddenly rejected because the | |
1938 | * pipe is off. | |
1939 | * | |
1940 | * RETURNS: | |
1941 | * | |
1942 | * 0 on success or one of the below negative error codes: | |
1943 | * | |
286dbb8d | 1944 | * - -EBUSY, if a nonblocking updated is requested and there is |
9953f417 DV |
1945 | * an earlier updated pending. Drivers are allowed to support a queue |
1946 | * of outstanding updates, but currently no driver supports that. | |
1947 | * Note that drivers must wait for preceding updates to complete if a | |
1948 | * synchronous update is requested, they are not allowed to fail the | |
1949 | * commit in that case. | |
1950 | * | |
1951 | * - -ENOMEM, if the driver failed to allocate memory. Specifically | |
1952 | * this can happen when trying to pin framebuffers, which must only | |
1953 | * be done when committing the state. | |
1954 | * | |
1955 | * - -ENOSPC, as a refinement of the more generic -ENOMEM to indicate | |
1956 | * that the driver has run out of vram, iommu space or similar GPU | |
1957 | * address space needed for framebuffer. | |
1958 | * | |
1959 | * - -EIO, if the hardware completely died. | |
1960 | * | |
1961 | * - -EINTR, -EAGAIN or -ERESTARTSYS, if the IOCTL should be restarted. | |
1962 | * This can either be due to a pending signal, or because the driver | |
1963 | * needs to completely bail out to recover from an exceptional | |
1964 | * situation like a GPU hang. From a userspace point of view all errors are | |
1965 | * treated equally. | |
1966 | * | |
1967 | * This list is exhaustive. Specifically this hook is not allowed to | |
1968 | * return -EINVAL (any invalid requests should be caught in | |
1969 | * @atomic_check) or -EDEADLK (this function must not acquire | |
1970 | * additional modeset locks). | |
1971 | */ | |
cc4ceb48 | 1972 | int (*atomic_commit)(struct drm_device *dev, |
9953f417 | 1973 | struct drm_atomic_state *state, |
286dbb8d | 1974 | bool nonblock); |
9953f417 DV |
1975 | |
1976 | /** | |
1977 | * @atomic_state_alloc: | |
1978 | * | |
1979 | * This optional hook can be used by drivers that want to subclass struct | |
1980 | * &drm_atomic_state to be able to track their own driver-private global | |
1981 | * state easily. If this hook is implemented, drivers must also | |
1982 | * implement @atomic_state_clear and @atomic_state_free. | |
1983 | * | |
1984 | * RETURNS: | |
1985 | * | |
1986 | * A new &drm_atomic_state on success or NULL on failure. | |
1987 | */ | |
036ef573 | 1988 | struct drm_atomic_state *(*atomic_state_alloc)(struct drm_device *dev); |
9953f417 DV |
1989 | |
1990 | /** | |
1991 | * @atomic_state_clear: | |
1992 | * | |
1993 | * This hook must clear any driver private state duplicated into the | |
1994 | * passed-in &drm_atomic_state. This hook is called when the caller | |
1995 | * encountered a &drm_modeset_lock deadlock and needs to drop all | |
1996 | * already acquired locks as part of the deadlock avoidance dance | |
1997 | * implemented in drm_modeset_lock_backoff(). | |
1998 | * | |
1999 | * Any duplicated state must be invalidated since a concurrent atomic | |
2000 | * update might change it, and the drm atomic interfaces always apply | |
2001 | * updates as relative changes to the current state. | |
2002 | * | |
2003 | * Drivers that implement this must call drm_atomic_state_default_clear() | |
2004 | * to clear common state. | |
2005 | */ | |
036ef573 | 2006 | void (*atomic_state_clear)(struct drm_atomic_state *state); |
9953f417 DV |
2007 | |
2008 | /** | |
2009 | * @atomic_state_free: | |
2010 | * | |
2011 | * This hook needs driver private resources and the &drm_atomic_state | |
2012 | * itself. Note that the core first calls drm_atomic_state_clear() to | |
2013 | * avoid code duplicate between the clear and free hooks. | |
2014 | * | |
2015 | * Drivers that implement this must call drm_atomic_state_default_free() | |
2016 | * to release common resources. | |
2017 | */ | |
036ef573 | 2018 | void (*atomic_state_free)(struct drm_atomic_state *state); |
f453ba04 DA |
2019 | }; |
2020 | ||
f453ba04 | 2021 | /** |
2c0c33d4 | 2022 | * struct drm_mode_config - Mode configuration control structure |
a62c93d5 | 2023 | * @mutex: mutex protecting KMS related lists and structures |
2c0c33d4 DV |
2024 | * @connection_mutex: ww mutex protecting connector state and routing |
2025 | * @acquire_ctx: global implicit acquire context used by atomic drivers for | |
c6b0ca3e | 2026 | * legacy IOCTLs |
a62c93d5 JB |
2027 | * @idr_mutex: mutex for KMS ID allocation and management |
2028 | * @crtc_idr: main KMS ID tracking object | |
2c0c33d4 | 2029 | * @fb_lock: mutex to protect fb state and lists |
a62c93d5 JB |
2030 | * @num_fb: number of fbs available |
2031 | * @fb_list: list of framebuffers available | |
2032 | * @num_connector: number of connectors on this device | |
2033 | * @connector_list: list of connector objects | |
2034 | * @num_encoder: number of encoders on this device | |
2035 | * @encoder_list: list of encoder objects | |
2c0c33d4 DV |
2036 | * @num_overlay_plane: number of overlay planes on this device |
2037 | * @num_total_plane: number of universal (i.e. with primary/curso) planes on this device | |
2038 | * @plane_list: list of plane objects | |
a62c93d5 JB |
2039 | * @num_crtc: number of CRTCs on this device |
2040 | * @crtc_list: list of CRTC objects | |
2c0c33d4 | 2041 | * @property_list: list of property objects |
a62c93d5 JB |
2042 | * @min_width: minimum pixel width on this device |
2043 | * @min_height: minimum pixel height on this device | |
2044 | * @max_width: maximum pixel width on this device | |
2045 | * @max_height: maximum pixel height on this device | |
2046 | * @funcs: core driver provided mode setting functions | |
2047 | * @fb_base: base address of the framebuffer | |
2c0c33d4 DV |
2048 | * @poll_enabled: track polling support for this device |
2049 | * @poll_running: track polling status for this device | |
a62c93d5 | 2050 | * @output_poll_work: delayed work for polling in process context |
2c0c33d4 | 2051 | * @property_blob_list: list of all the blob property objects |
8fb6e7a5 | 2052 | * @blob_lock: mutex for blob property allocation and management |
a62c93d5 | 2053 | * @*_property: core property tracking |
5488dc16 LL |
2054 | * @degamma_lut_property: LUT used to convert the framebuffer's colors to linear |
2055 | * gamma | |
2056 | * @degamma_lut_size_property: size of the degamma LUT as supported by the | |
2057 | * driver (read-only) | |
2058 | * @ctm_property: Matrix used to convert colors after the lookup in the | |
2059 | * degamma LUT | |
2060 | * @gamma_lut_property: LUT used to convert the colors, after the CSC matrix, to | |
2061 | * the gamma space of the connected screen (read-only) | |
2062 | * @gamma_lut_size_property: size of the gamma LUT as supported by the driver | |
2c0c33d4 DV |
2063 | * @preferred_depth: preferred RBG pixel depth, used by fb helpers |
2064 | * @prefer_shadow: hint to userspace to prefer shadow-fb rendering | |
2065 | * @async_page_flip: does this device support async flips on the primary plane? | |
2066 | * @cursor_width: hint to userspace for max cursor width | |
2067 | * @cursor_height: hint to userspace for max cursor height | |
f453ba04 | 2068 | * |
a62c93d5 JB |
2069 | * Core mode resource tracking structure. All CRTC, encoders, and connectors |
2070 | * enumerated by the driver are added here, as are global properties. Some | |
2071 | * global restrictions are also here, e.g. dimension restrictions. | |
f453ba04 DA |
2072 | */ |
2073 | struct drm_mode_config { | |
ad2563c2 | 2074 | struct mutex mutex; /* protects configuration (mode lists etc.) */ |
51fd371b RC |
2075 | struct drm_modeset_lock connection_mutex; /* protects connector->encoder and encoder->crtc links */ |
2076 | struct drm_modeset_acquire_ctx *acquire_ctx; /* for legacy _lock_all() / _unlock_all() */ | |
ad2563c2 | 2077 | struct mutex idr_mutex; /* for IDR management */ |
f453ba04 | 2078 | struct idr crtc_idr; /* use this idr for all IDs, fb, crtc, connector, modes - just makes life easier */ |
138f9ebb | 2079 | struct idr tile_idr; /* use this idr for all IDs, fb, crtc, connector, modes - just makes life easier */ |
f453ba04 | 2080 | /* this is limited to one for now */ |
4b096ac1 | 2081 | |
2c0c33d4 | 2082 | struct mutex fb_lock; /* proctects global and per-file fb lists */ |
f453ba04 DA |
2083 | int num_fb; |
2084 | struct list_head fb_list; | |
4b096ac1 | 2085 | |
f453ba04 | 2086 | int num_connector; |
5fff80bb | 2087 | struct ida connector_ida; |
f453ba04 DA |
2088 | struct list_head connector_list; |
2089 | int num_encoder; | |
2090 | struct list_head encoder_list; | |
e27dde3e MR |
2091 | |
2092 | /* | |
2093 | * Track # of overlay planes separately from # of total planes. By | |
2094 | * default we only advertise overlay planes to userspace; if userspace | |
2095 | * sets the "universal plane" capability bit, we'll go ahead and | |
2096 | * expose all planes. | |
2097 | */ | |
2098 | int num_overlay_plane; | |
2099 | int num_total_plane; | |
8cf5c917 | 2100 | struct list_head plane_list; |
f453ba04 DA |
2101 | |
2102 | int num_crtc; | |
2103 | struct list_head crtc_list; | |
2104 | ||
2105 | struct list_head property_list; | |
2106 | ||
f453ba04 DA |
2107 | int min_width, min_height; |
2108 | int max_width, max_height; | |
e6ecefaa | 2109 | const struct drm_mode_config_funcs *funcs; |
d883f7f1 | 2110 | resource_size_t fb_base; |
f453ba04 | 2111 | |
eb1f8e4f DA |
2112 | /* output poll support */ |
2113 | bool poll_enabled; | |
905bc9ff | 2114 | bool poll_running; |
162b6a57 | 2115 | bool delayed_event; |
991ea75c | 2116 | struct delayed_work output_poll_work; |
eb1f8e4f | 2117 | |
8fb6e7a5 DS |
2118 | struct mutex blob_lock; |
2119 | ||
f453ba04 DA |
2120 | /* pointers to standard properties */ |
2121 | struct list_head property_blob_list; | |
2122 | struct drm_property *edid_property; | |
2123 | struct drm_property *dpms_property; | |
43aba7eb | 2124 | struct drm_property *path_property; |
6f134d7b | 2125 | struct drm_property *tile_property; |
9922ab5a | 2126 | struct drm_property *plane_type_property; |
2a297cce | 2127 | struct drm_property *rotation_property; |
6b4959f4 RC |
2128 | struct drm_property *prop_src_x; |
2129 | struct drm_property *prop_src_y; | |
2130 | struct drm_property *prop_src_w; | |
2131 | struct drm_property *prop_src_h; | |
2132 | struct drm_property *prop_crtc_x; | |
2133 | struct drm_property *prop_crtc_y; | |
2134 | struct drm_property *prop_crtc_w; | |
2135 | struct drm_property *prop_crtc_h; | |
2136 | struct drm_property *prop_fb_id; | |
2137 | struct drm_property *prop_crtc_id; | |
eab3bbef | 2138 | struct drm_property *prop_active; |
955f3c33 | 2139 | struct drm_property *prop_mode_id; |
f453ba04 DA |
2140 | |
2141 | /* DVI-I properties */ | |
2142 | struct drm_property *dvi_i_subconnector_property; | |
2143 | struct drm_property *dvi_i_select_subconnector_property; | |
2144 | ||
2145 | /* TV properties */ | |
2146 | struct drm_property *tv_subconnector_property; | |
2147 | struct drm_property *tv_select_subconnector_property; | |
2148 | struct drm_property *tv_mode_property; | |
2149 | struct drm_property *tv_left_margin_property; | |
2150 | struct drm_property *tv_right_margin_property; | |
2151 | struct drm_property *tv_top_margin_property; | |
2152 | struct drm_property *tv_bottom_margin_property; | |
b6b7902e FJ |
2153 | struct drm_property *tv_brightness_property; |
2154 | struct drm_property *tv_contrast_property; | |
2155 | struct drm_property *tv_flicker_reduction_property; | |
a75f0236 FJ |
2156 | struct drm_property *tv_overscan_property; |
2157 | struct drm_property *tv_saturation_property; | |
2158 | struct drm_property *tv_hue_property; | |
f453ba04 DA |
2159 | |
2160 | /* Optional properties */ | |
2161 | struct drm_property *scaling_mode_property; | |
ff587e45 | 2162 | struct drm_property *aspect_ratio_property; |
884840aa | 2163 | struct drm_property *dirty_info_property; |
019d96cb | 2164 | |
5488dc16 LL |
2165 | /* Optional color correction properties */ |
2166 | struct drm_property *degamma_lut_property; | |
2167 | struct drm_property *degamma_lut_size_property; | |
2168 | struct drm_property *ctm_property; | |
2169 | struct drm_property *gamma_lut_property; | |
2170 | struct drm_property *gamma_lut_size_property; | |
2171 | ||
5bb2bbf5 DA |
2172 | /* properties for virtual machine layout */ |
2173 | struct drm_property *suggested_x_property; | |
2174 | struct drm_property *suggested_y_property; | |
2175 | ||
019d96cb DA |
2176 | /* dumb ioctl parameters */ |
2177 | uint32_t preferred_depth, prefer_shadow; | |
62f2104f KP |
2178 | |
2179 | /* whether async page flip is supported or not */ | |
2180 | bool async_page_flip; | |
8716ed4e | 2181 | |
e3eb3250 RC |
2182 | /* whether the driver supports fb modifiers */ |
2183 | bool allow_fb_modifiers; | |
2184 | ||
8716ed4e AD |
2185 | /* cursor size */ |
2186 | uint32_t cursor_width, cursor_height; | |
f453ba04 DA |
2187 | }; |
2188 | ||
dd275956 RC |
2189 | /** |
2190 | * drm_for_each_plane_mask - iterate over planes specified by bitmask | |
2191 | * @plane: the loop cursor | |
2192 | * @dev: the DRM device | |
2193 | * @plane_mask: bitmask of plane indices | |
2194 | * | |
2195 | * Iterate over all planes specified by bitmask. | |
2196 | */ | |
2197 | #define drm_for_each_plane_mask(plane, dev, plane_mask) \ | |
2198 | list_for_each_entry((plane), &(dev)->mode_config.plane_list, head) \ | |
373701b1 | 2199 | for_each_if ((plane_mask) & (1 << drm_plane_index(plane))) |
dd275956 | 2200 | |
ead8b665 ML |
2201 | /** |
2202 | * drm_for_each_encoder_mask - iterate over encoders specified by bitmask | |
2203 | * @encoder: the loop cursor | |
2204 | * @dev: the DRM device | |
2205 | * @encoder_mask: bitmask of encoder indices | |
2206 | * | |
2207 | * Iterate over all encoders specified by bitmask. | |
2208 | */ | |
2209 | #define drm_for_each_encoder_mask(encoder, dev, encoder_mask) \ | |
2210 | list_for_each_entry((encoder), &(dev)->mode_config.encoder_list, head) \ | |
2211 | for_each_if ((encoder_mask) & (1 << drm_encoder_index(encoder))) | |
dd275956 | 2212 | |
f453ba04 DA |
2213 | #define obj_to_crtc(x) container_of(x, struct drm_crtc, base) |
2214 | #define obj_to_connector(x) container_of(x, struct drm_connector, base) | |
2215 | #define obj_to_encoder(x) container_of(x, struct drm_encoder, base) | |
2216 | #define obj_to_mode(x) container_of(x, struct drm_display_mode, base) | |
2217 | #define obj_to_fb(x) container_of(x, struct drm_framebuffer, base) | |
2218 | #define obj_to_property(x) container_of(x, struct drm_property, base) | |
2219 | #define obj_to_blob(x) container_of(x, struct drm_property_blob, base) | |
8cf5c917 | 2220 | #define obj_to_plane(x) container_of(x, struct drm_plane, base) |
f453ba04 | 2221 | |
4a67d391 SH |
2222 | struct drm_prop_enum_list { |
2223 | int type; | |
2224 | char *name; | |
2225 | }; | |
f453ba04 | 2226 | |
f9882876 VS |
2227 | extern __printf(6, 7) |
2228 | int drm_crtc_init_with_planes(struct drm_device *dev, | |
2229 | struct drm_crtc *crtc, | |
2230 | struct drm_plane *primary, | |
2231 | struct drm_plane *cursor, | |
2232 | const struct drm_crtc_funcs *funcs, | |
2233 | const char *name, ...); | |
f453ba04 | 2234 | extern void drm_crtc_cleanup(struct drm_crtc *crtc); |
db5f7a6e RK |
2235 | extern unsigned int drm_crtc_index(struct drm_crtc *crtc); |
2236 | ||
2237 | /** | |
2238 | * drm_crtc_mask - find the mask of a registered CRTC | |
2239 | * @crtc: CRTC to find mask for | |
2240 | * | |
2241 | * Given a registered CRTC, return the mask bit of that CRTC for an | |
2242 | * encoder's possible_crtcs field. | |
2243 | */ | |
2244 | static inline uint32_t drm_crtc_mask(struct drm_crtc *crtc) | |
2245 | { | |
2246 | return 1 << drm_crtc_index(crtc); | |
2247 | } | |
f453ba04 | 2248 | |
b21e3afe IM |
2249 | extern void drm_connector_ida_init(void); |
2250 | extern void drm_connector_ida_destroy(void); | |
6bfc56aa VS |
2251 | extern int drm_connector_init(struct drm_device *dev, |
2252 | struct drm_connector *connector, | |
2253 | const struct drm_connector_funcs *funcs, | |
2254 | int connector_type); | |
34ea3d38 TW |
2255 | int drm_connector_register(struct drm_connector *connector); |
2256 | void drm_connector_unregister(struct drm_connector *connector); | |
f453ba04 DA |
2257 | |
2258 | extern void drm_connector_cleanup(struct drm_connector *connector); | |
5fff80bb ML |
2259 | static inline unsigned drm_connector_index(struct drm_connector *connector) |
2260 | { | |
2261 | return connector->connector_id; | |
2262 | } | |
2263 | ||
54d2c2da AB |
2264 | /* helpers to {un}register all connectors from sysfs for device */ |
2265 | extern int drm_connector_register_all(struct drm_device *dev); | |
6c87e5c3 | 2266 | extern void drm_connector_unregister_all(struct drm_device *dev); |
f453ba04 | 2267 | |
3d3f8b1f AK |
2268 | extern int drm_bridge_add(struct drm_bridge *bridge); |
2269 | extern void drm_bridge_remove(struct drm_bridge *bridge); | |
2270 | extern struct drm_bridge *of_drm_find_bridge(struct device_node *np); | |
2271 | extern int drm_bridge_attach(struct drm_device *dev, struct drm_bridge *bridge); | |
3b336ec4 | 2272 | |
862e686c AT |
2273 | bool drm_bridge_mode_fixup(struct drm_bridge *bridge, |
2274 | const struct drm_display_mode *mode, | |
2275 | struct drm_display_mode *adjusted_mode); | |
2276 | void drm_bridge_disable(struct drm_bridge *bridge); | |
2277 | void drm_bridge_post_disable(struct drm_bridge *bridge); | |
2278 | void drm_bridge_mode_set(struct drm_bridge *bridge, | |
2279 | struct drm_display_mode *mode, | |
2280 | struct drm_display_mode *adjusted_mode); | |
2281 | void drm_bridge_pre_enable(struct drm_bridge *bridge); | |
2282 | void drm_bridge_enable(struct drm_bridge *bridge); | |
2283 | ||
13a3d91f VS |
2284 | extern __printf(5, 6) |
2285 | int drm_encoder_init(struct drm_device *dev, | |
2286 | struct drm_encoder *encoder, | |
2287 | const struct drm_encoder_funcs *funcs, | |
2288 | int encoder_type, const char *name, ...); | |
47d7777f | 2289 | extern unsigned int drm_encoder_index(struct drm_encoder *encoder); |
f453ba04 | 2290 | |
3d887368 TR |
2291 | /** |
2292 | * drm_encoder_crtc_ok - can a given crtc drive a given encoder? | |
2293 | * @encoder: encoder to test | |
2294 | * @crtc: crtc to test | |
2295 | * | |
2296 | * Return false if @encoder can't be driven by @crtc, true otherwise. | |
2297 | */ | |
2298 | static inline bool drm_encoder_crtc_ok(struct drm_encoder *encoder, | |
2299 | struct drm_crtc *crtc) | |
2300 | { | |
2301 | return !!(encoder->possible_crtcs & drm_crtc_mask(crtc)); | |
2302 | } | |
2303 | ||
b0b3b795 VS |
2304 | extern __printf(8, 9) |
2305 | int drm_universal_plane_init(struct drm_device *dev, | |
2306 | struct drm_plane *plane, | |
2307 | unsigned long possible_crtcs, | |
2308 | const struct drm_plane_funcs *funcs, | |
2309 | const uint32_t *formats, | |
2310 | unsigned int format_count, | |
2311 | enum drm_plane_type type, | |
2312 | const char *name, ...); | |
8cf5c917 JB |
2313 | extern int drm_plane_init(struct drm_device *dev, |
2314 | struct drm_plane *plane, | |
2315 | unsigned long possible_crtcs, | |
2316 | const struct drm_plane_funcs *funcs, | |
45e3743a | 2317 | const uint32_t *formats, unsigned int format_count, |
dc415ff9 | 2318 | bool is_primary); |
8cf5c917 | 2319 | extern void drm_plane_cleanup(struct drm_plane *plane); |
10f637bf | 2320 | extern unsigned int drm_plane_index(struct drm_plane *plane); |
f81338a5 | 2321 | extern struct drm_plane * drm_plane_from_index(struct drm_device *dev, int idx); |
9125e618 | 2322 | extern void drm_plane_force_disable(struct drm_plane *plane); |
ead8610d LP |
2323 | extern int drm_plane_check_pixel_format(const struct drm_plane *plane, |
2324 | u32 format); | |
ecb7e16b GP |
2325 | extern void drm_crtc_get_hv_timing(const struct drm_display_mode *mode, |
2326 | int *hdisplay, int *vdisplay); | |
af93629d MR |
2327 | extern int drm_crtc_check_viewport(const struct drm_crtc *crtc, |
2328 | int x, int y, | |
2329 | const struct drm_display_mode *mode, | |
2330 | const struct drm_framebuffer *fb); | |
8cf5c917 | 2331 | |
f453ba04 DA |
2332 | extern void drm_encoder_cleanup(struct drm_encoder *encoder); |
2333 | ||
d20d3174 | 2334 | extern const char *drm_get_connector_status_name(enum drm_connector_status status); |
ac1bb36c | 2335 | extern const char *drm_get_subpixel_order_name(enum subpixel_order order); |
d20d3174 VS |
2336 | extern const char *drm_get_dpms_name(int val); |
2337 | extern const char *drm_get_dvi_i_subconnector_name(int val); | |
2338 | extern const char *drm_get_dvi_i_select_name(int val); | |
2339 | extern const char *drm_get_tv_subconnector_name(int val); | |
2340 | extern const char *drm_get_tv_select_name(int val); | |
ea39f835 | 2341 | extern void drm_fb_release(struct drm_file *file_priv); |
e2f5d2ea DS |
2342 | extern void drm_property_destroy_user_blobs(struct drm_device *dev, |
2343 | struct drm_file *file_priv); | |
fbff4690 | 2344 | extern bool drm_probe_ddc(struct i2c_adapter *adapter); |
f453ba04 DA |
2345 | extern struct edid *drm_get_edid(struct drm_connector *connector, |
2346 | struct i2c_adapter *adapter); | |
5cb8eaa2 LW |
2347 | extern struct edid *drm_get_edid_switcheroo(struct drm_connector *connector, |
2348 | struct i2c_adapter *adapter); | |
51f8da59 | 2349 | extern struct edid *drm_edid_duplicate(const struct edid *edid); |
f453ba04 | 2350 | extern int drm_add_edid_modes(struct drm_connector *connector, struct edid *edid); |
f453ba04 | 2351 | extern void drm_mode_config_init(struct drm_device *dev); |
eb033556 | 2352 | extern void drm_mode_config_reset(struct drm_device *dev); |
f453ba04 | 2353 | extern void drm_mode_config_cleanup(struct drm_device *dev); |
55310008 | 2354 | |
43aba7eb | 2355 | extern int drm_mode_connector_set_path_property(struct drm_connector *connector, |
12e6cecd | 2356 | const char *path); |
6f134d7b | 2357 | int drm_mode_connector_set_tile_property(struct drm_connector *connector); |
f453ba04 | 2358 | extern int drm_mode_connector_update_edid_property(struct drm_connector *connector, |
12e6cecd | 2359 | const struct edid *edid); |
5ea22f24 | 2360 | |
b5571e9d BB |
2361 | extern int drm_display_info_set_bus_formats(struct drm_display_info *info, |
2362 | const u32 *formats, | |
2363 | unsigned int num_formats); | |
2364 | ||
5ea22f24 RC |
2365 | static inline bool drm_property_type_is(struct drm_property *property, |
2366 | uint32_t type) | |
2367 | { | |
2368 | /* instanceof for props.. handles extended type vs original types: */ | |
2369 | if (property->flags & DRM_MODE_PROP_EXTENDED_TYPE) | |
2370 | return (property->flags & DRM_MODE_PROP_EXTENDED_TYPE) == type; | |
2371 | return property->flags & type; | |
2372 | } | |
2373 | ||
2374 | static inline bool drm_property_type_valid(struct drm_property *property) | |
2375 | { | |
2376 | if (property->flags & DRM_MODE_PROP_EXTENDED_TYPE) | |
2377 | return !(property->flags & DRM_MODE_PROP_LEGACY_TYPE); | |
2378 | return !!(property->flags & DRM_MODE_PROP_LEGACY_TYPE); | |
2379 | } | |
2380 | ||
c543188a PZ |
2381 | extern int drm_object_property_set_value(struct drm_mode_object *obj, |
2382 | struct drm_property *property, | |
2383 | uint64_t val); | |
2384 | extern int drm_object_property_get_value(struct drm_mode_object *obj, | |
2385 | struct drm_property *property, | |
2386 | uint64_t *value); | |
f453ba04 DA |
2387 | extern int drm_framebuffer_init(struct drm_device *dev, |
2388 | struct drm_framebuffer *fb, | |
2389 | const struct drm_framebuffer_funcs *funcs); | |
786b99ed DV |
2390 | extern struct drm_framebuffer *drm_framebuffer_lookup(struct drm_device *dev, |
2391 | uint32_t id); | |
f7eff60e | 2392 | extern void drm_framebuffer_remove(struct drm_framebuffer *fb); |
f453ba04 | 2393 | extern void drm_framebuffer_cleanup(struct drm_framebuffer *fb); |
36206361 | 2394 | extern void drm_framebuffer_unregister_private(struct drm_framebuffer *fb); |
f453ba04 | 2395 | |
c543188a PZ |
2396 | extern void drm_object_attach_property(struct drm_mode_object *obj, |
2397 | struct drm_property *property, | |
2398 | uint64_t init_val); | |
f453ba04 DA |
2399 | extern struct drm_property *drm_property_create(struct drm_device *dev, int flags, |
2400 | const char *name, int num_values); | |
4a67d391 SH |
2401 | extern struct drm_property *drm_property_create_enum(struct drm_device *dev, int flags, |
2402 | const char *name, | |
49e27545 RC |
2403 | const struct drm_prop_enum_list *props, |
2404 | int num_values); | |
2405 | struct drm_property *drm_property_create_bitmask(struct drm_device *dev, | |
2406 | int flags, const char *name, | |
4a67d391 | 2407 | const struct drm_prop_enum_list *props, |
7689ffb3 VS |
2408 | int num_props, |
2409 | uint64_t supported_bits); | |
d9bc3c02 SH |
2410 | struct drm_property *drm_property_create_range(struct drm_device *dev, int flags, |
2411 | const char *name, | |
2412 | uint64_t min, uint64_t max); | |
ebc44cf3 RC |
2413 | struct drm_property *drm_property_create_signed_range(struct drm_device *dev, |
2414 | int flags, const char *name, | |
2415 | int64_t min, int64_t max); | |
98f75de4 RC |
2416 | struct drm_property *drm_property_create_object(struct drm_device *dev, |
2417 | int flags, const char *name, uint32_t type); | |
960cd9d4 DV |
2418 | struct drm_property *drm_property_create_bool(struct drm_device *dev, int flags, |
2419 | const char *name); | |
6bcacf51 DS |
2420 | struct drm_property_blob *drm_property_create_blob(struct drm_device *dev, |
2421 | size_t length, | |
2422 | const void *data); | |
2423 | struct drm_property_blob *drm_property_lookup_blob(struct drm_device *dev, | |
2424 | uint32_t id); | |
2425 | struct drm_property_blob *drm_property_reference_blob(struct drm_property_blob *blob); | |
2426 | void drm_property_unreference_blob(struct drm_property_blob *blob); | |
f453ba04 DA |
2427 | extern void drm_property_destroy(struct drm_device *dev, struct drm_property *property); |
2428 | extern int drm_property_add_enum(struct drm_property *property, int index, | |
2429 | uint64_t value, const char *name); | |
2430 | extern int drm_mode_create_dvi_i_properties(struct drm_device *dev); | |
2f763312 TR |
2431 | extern int drm_mode_create_tv_properties(struct drm_device *dev, |
2432 | unsigned int num_modes, | |
b7c914b3 | 2433 | const char * const modes[]); |
f453ba04 | 2434 | extern int drm_mode_create_scaling_mode_property(struct drm_device *dev); |
ff587e45 | 2435 | extern int drm_mode_create_aspect_ratio_property(struct drm_device *dev); |
884840aa | 2436 | extern int drm_mode_create_dirty_info_property(struct drm_device *dev); |
5bb2bbf5 | 2437 | extern int drm_mode_create_suggested_offset_properties(struct drm_device *dev); |
d34f20d6 RC |
2438 | extern bool drm_property_change_valid_get(struct drm_property *property, |
2439 | uint64_t value, struct drm_mode_object **ref); | |
2440 | extern void drm_property_change_valid_put(struct drm_property *property, | |
2441 | struct drm_mode_object *ref); | |
f453ba04 DA |
2442 | |
2443 | extern int drm_mode_connector_attach_encoder(struct drm_connector *connector, | |
2444 | struct drm_encoder *encoder); | |
4cae5b84 | 2445 | extern int drm_mode_crtc_set_gamma_size(struct drm_crtc *crtc, |
f453ba04 | 2446 | int gamma_size); |
7a9c9060 DV |
2447 | extern struct drm_mode_object *drm_mode_object_find(struct drm_device *dev, |
2448 | uint32_t id, uint32_t type); | |
d0f37cf6 DA |
2449 | void drm_mode_object_reference(struct drm_mode_object *obj); |
2450 | void drm_mode_object_unreference(struct drm_mode_object *obj); | |
98f75de4 | 2451 | |
f453ba04 DA |
2452 | /* IOCTLs */ |
2453 | extern int drm_mode_getresources(struct drm_device *dev, | |
2454 | void *data, struct drm_file *file_priv); | |
8cf5c917 JB |
2455 | extern int drm_mode_getplane_res(struct drm_device *dev, void *data, |
2456 | struct drm_file *file_priv); | |
f453ba04 DA |
2457 | extern int drm_mode_getcrtc(struct drm_device *dev, |
2458 | void *data, struct drm_file *file_priv); | |
2459 | extern int drm_mode_getconnector(struct drm_device *dev, | |
2460 | void *data, struct drm_file *file_priv); | |
2d13b679 | 2461 | extern int drm_mode_set_config_internal(struct drm_mode_set *set); |
f453ba04 DA |
2462 | extern int drm_mode_setcrtc(struct drm_device *dev, |
2463 | void *data, struct drm_file *file_priv); | |
8cf5c917 JB |
2464 | extern int drm_mode_getplane(struct drm_device *dev, |
2465 | void *data, struct drm_file *file_priv); | |
2466 | extern int drm_mode_setplane(struct drm_device *dev, | |
2467 | void *data, struct drm_file *file_priv); | |
f453ba04 DA |
2468 | extern int drm_mode_cursor_ioctl(struct drm_device *dev, |
2469 | void *data, struct drm_file *file_priv); | |
4c813d4d DA |
2470 | extern int drm_mode_cursor2_ioctl(struct drm_device *dev, |
2471 | void *data, struct drm_file *file_priv); | |
f453ba04 DA |
2472 | extern int drm_mode_addfb(struct drm_device *dev, |
2473 | void *data, struct drm_file *file_priv); | |
308e5bcb JB |
2474 | extern int drm_mode_addfb2(struct drm_device *dev, |
2475 | void *data, struct drm_file *file_priv); | |
2476 | extern uint32_t drm_mode_legacy_fb_format(uint32_t bpp, uint32_t depth); | |
f453ba04 DA |
2477 | extern int drm_mode_rmfb(struct drm_device *dev, |
2478 | void *data, struct drm_file *file_priv); | |
2479 | extern int drm_mode_getfb(struct drm_device *dev, | |
2480 | void *data, struct drm_file *file_priv); | |
884840aa JB |
2481 | extern int drm_mode_dirtyfb_ioctl(struct drm_device *dev, |
2482 | void *data, struct drm_file *file_priv); | |
f453ba04 DA |
2483 | |
2484 | extern int drm_mode_getproperty_ioctl(struct drm_device *dev, | |
2485 | void *data, struct drm_file *file_priv); | |
2486 | extern int drm_mode_getblob_ioctl(struct drm_device *dev, | |
2487 | void *data, struct drm_file *file_priv); | |
e2f5d2ea DS |
2488 | extern int drm_mode_createblob_ioctl(struct drm_device *dev, |
2489 | void *data, struct drm_file *file_priv); | |
2490 | extern int drm_mode_destroyblob_ioctl(struct drm_device *dev, | |
2491 | void *data, struct drm_file *file_priv); | |
f453ba04 DA |
2492 | extern int drm_mode_connector_property_set_ioctl(struct drm_device *dev, |
2493 | void *data, struct drm_file *file_priv); | |
f453ba04 DA |
2494 | extern int drm_mode_getencoder(struct drm_device *dev, |
2495 | void *data, struct drm_file *file_priv); | |
2496 | extern int drm_mode_gamma_get_ioctl(struct drm_device *dev, | |
2497 | void *data, struct drm_file *file_priv); | |
2498 | extern int drm_mode_gamma_set_ioctl(struct drm_device *dev, | |
2499 | void *data, struct drm_file *file_priv); | |
18316c8c | 2500 | extern u8 drm_match_cea_mode(const struct drm_display_mode *to_match); |
0967e6a5 | 2501 | extern enum hdmi_picture_aspect drm_get_cea_aspect_ratio(const u8 video_code); |
f23c20c8 | 2502 | extern bool drm_detect_hdmi_monitor(struct edid *edid); |
8fe9790d | 2503 | extern bool drm_detect_monitor_audio(struct edid *edid); |
b1edd6a6 | 2504 | extern bool drm_rgb_quant_range_selectable(struct edid *edid); |
d91d8a3f KH |
2505 | extern int drm_mode_page_flip_ioctl(struct drm_device *dev, |
2506 | void *data, struct drm_file *file_priv); | |
f0fda0a4 ZY |
2507 | extern int drm_add_modes_noedid(struct drm_connector *connector, |
2508 | int hdisplay, int vdisplay); | |
3cf70daf GH |
2509 | extern void drm_set_preferred_mode(struct drm_connector *connector, |
2510 | int hpref, int vpref); | |
3c537889 | 2511 | |
051963d4 | 2512 | extern int drm_edid_header_is_valid(const u8 *raw_edid); |
6ba2bd3d TP |
2513 | extern bool drm_edid_block_valid(u8 *raw_edid, int block, bool print_bad_edid, |
2514 | bool *edid_corrupt); | |
3c537889 | 2515 | extern bool drm_edid_is_valid(struct edid *edid); |
59f7c0fa JB |
2516 | extern void drm_edid_get_monitor_name(struct edid *edid, char *name, |
2517 | int buflen); | |
138f9ebb DA |
2518 | |
2519 | extern struct drm_tile_group *drm_mode_create_tile_group(struct drm_device *dev, | |
2520 | char topology[8]); | |
2521 | extern struct drm_tile_group *drm_mode_get_tile_group(struct drm_device *dev, | |
2522 | char topology[8]); | |
2523 | extern void drm_mode_put_tile_group(struct drm_device *dev, | |
2524 | struct drm_tile_group *tg); | |
1d42bbc8 | 2525 | struct drm_display_mode *drm_mode_find_dmt(struct drm_device *dev, |
f6e252ba AJ |
2526 | int hsize, int vsize, int fresh, |
2527 | bool rb); | |
ff72145b DA |
2528 | |
2529 | extern int drm_mode_create_dumb_ioctl(struct drm_device *dev, | |
2530 | void *data, struct drm_file *file_priv); | |
2531 | extern int drm_mode_mmap_dumb_ioctl(struct drm_device *dev, | |
2532 | void *data, struct drm_file *file_priv); | |
2533 | extern int drm_mode_destroy_dumb_ioctl(struct drm_device *dev, | |
2534 | void *data, struct drm_file *file_priv); | |
c543188a PZ |
2535 | extern int drm_mode_obj_get_properties_ioctl(struct drm_device *dev, void *data, |
2536 | struct drm_file *file_priv); | |
2537 | extern int drm_mode_obj_set_property_ioctl(struct drm_device *dev, void *data, | |
2538 | struct drm_file *file_priv); | |
3a5f87c2 TW |
2539 | extern int drm_mode_plane_set_obj_prop(struct drm_plane *plane, |
2540 | struct drm_property *property, | |
2541 | uint64_t value); | |
d34f20d6 RC |
2542 | extern int drm_mode_atomic_ioctl(struct drm_device *dev, |
2543 | void *data, struct drm_file *file_priv); | |
248dbc23 DA |
2544 | |
2545 | extern void drm_fb_get_bpp_depth(uint32_t format, unsigned int *depth, | |
2546 | int *bpp); | |
141670e9 | 2547 | extern int drm_format_num_planes(uint32_t format); |
5a86bd55 | 2548 | extern int drm_format_plane_cpp(uint32_t format, int plane); |
01b68b04 VS |
2549 | extern int drm_format_horz_chroma_subsampling(uint32_t format); |
2550 | extern int drm_format_vert_chroma_subsampling(uint32_t format); | |
4c61716c VS |
2551 | extern int drm_format_plane_width(int width, uint32_t format, int plane); |
2552 | extern int drm_format_plane_height(int height, uint32_t format, int plane); | |
d20d3174 | 2553 | extern const char *drm_get_format_name(uint32_t format); |
c1df5f3c VS |
2554 | extern struct drm_property *drm_mode_create_rotation_property(struct drm_device *dev, |
2555 | unsigned int supported_rotations); | |
3c9855f6 VS |
2556 | extern unsigned int drm_rotation_simplify(unsigned int rotation, |
2557 | unsigned int supported_rotations); | |
141670e9 | 2558 | |
96f60e37 | 2559 | /* Helpers */ |
a2b34e22 RC |
2560 | |
2561 | static inline struct drm_plane *drm_plane_find(struct drm_device *dev, | |
2562 | uint32_t id) | |
2563 | { | |
2564 | struct drm_mode_object *mo; | |
2565 | mo = drm_mode_object_find(dev, id, DRM_MODE_OBJECT_PLANE); | |
2566 | return mo ? obj_to_plane(mo) : NULL; | |
2567 | } | |
2568 | ||
96f60e37 RK |
2569 | static inline struct drm_crtc *drm_crtc_find(struct drm_device *dev, |
2570 | uint32_t id) | |
2571 | { | |
2572 | struct drm_mode_object *mo; | |
2573 | mo = drm_mode_object_find(dev, id, DRM_MODE_OBJECT_CRTC); | |
2574 | return mo ? obj_to_crtc(mo) : NULL; | |
2575 | } | |
2576 | ||
2577 | static inline struct drm_encoder *drm_encoder_find(struct drm_device *dev, | |
2578 | uint32_t id) | |
2579 | { | |
2580 | struct drm_mode_object *mo; | |
2581 | mo = drm_mode_object_find(dev, id, DRM_MODE_OBJECT_ENCODER); | |
2582 | return mo ? obj_to_encoder(mo) : NULL; | |
2583 | } | |
2584 | ||
b164d31f DA |
2585 | /** |
2586 | * drm_connector_lookup - lookup connector object | |
2587 | * @dev: DRM device | |
2588 | * @id: connector object id | |
2589 | * | |
2590 | * This function looks up the connector object specified by id | |
2591 | * add takes a reference to it. | |
2592 | */ | |
2593 | static inline struct drm_connector *drm_connector_lookup(struct drm_device *dev, | |
a2b34e22 RC |
2594 | uint32_t id) |
2595 | { | |
2596 | struct drm_mode_object *mo; | |
2597 | mo = drm_mode_object_find(dev, id, DRM_MODE_OBJECT_CONNECTOR); | |
2598 | return mo ? obj_to_connector(mo) : NULL; | |
2599 | } | |
2600 | ||
2601 | static inline struct drm_property *drm_property_find(struct drm_device *dev, | |
2602 | uint32_t id) | |
2603 | { | |
2604 | struct drm_mode_object *mo; | |
2605 | mo = drm_mode_object_find(dev, id, DRM_MODE_OBJECT_PROPERTY); | |
2606 | return mo ? obj_to_property(mo) : NULL; | |
2607 | } | |
2608 | ||
5488dc16 LL |
2609 | /* |
2610 | * Extract a degamma/gamma LUT value provided by user and round it to the | |
2611 | * precision supported by the hardware. | |
2612 | */ | |
2613 | static inline uint32_t drm_color_lut_extract(uint32_t user_input, | |
2614 | uint32_t bit_precision) | |
2615 | { | |
644a8050 | 2616 | uint32_t val = user_input; |
5488dc16 LL |
2617 | uint32_t max = 0xffff >> (16 - bit_precision); |
2618 | ||
644a8050 LL |
2619 | /* Round only if we're not using full precision. */ |
2620 | if (bit_precision < 16) { | |
2621 | val += 1UL << (16 - bit_precision - 1); | |
2622 | val >>= 16 - bit_precision; | |
2623 | } | |
5488dc16 LL |
2624 | |
2625 | return clamp_val(val, 0, max); | |
2626 | } | |
2627 | ||
e76d399f | 2628 | /** |
d0f37cf6 DA |
2629 | * drm_framebuffer_reference - incr the fb refcnt |
2630 | * @fb: framebuffer | |
2631 | * | |
2632 | * This functions increments the fb's refcount. | |
2633 | */ | |
2634 | static inline void drm_framebuffer_reference(struct drm_framebuffer *fb) | |
2635 | { | |
2636 | drm_mode_object_reference(&fb->base); | |
2637 | } | |
2638 | ||
2639 | /** | |
2640 | * drm_framebuffer_unreference - unref a framebuffer | |
2641 | * @fb: framebuffer to unref | |
2642 | * | |
2643 | * This functions decrements the fb's refcount and frees it if it drops to zero. | |
2644 | */ | |
2645 | static inline void drm_framebuffer_unreference(struct drm_framebuffer *fb) | |
2646 | { | |
2647 | drm_mode_object_unreference(&fb->base); | |
2648 | } | |
2649 | ||
747a598f DA |
2650 | /** |
2651 | * drm_framebuffer_read_refcount - read the framebuffer reference count. | |
2652 | * @fb: framebuffer | |
2653 | * | |
2654 | * This functions returns the framebuffer's reference count. | |
2655 | */ | |
2656 | static inline uint32_t drm_framebuffer_read_refcount(struct drm_framebuffer *fb) | |
2657 | { | |
d0f37cf6 | 2658 | return atomic_read(&fb->base.refcount.refcount); |
747a598f DA |
2659 | } |
2660 | ||
b164d31f DA |
2661 | /** |
2662 | * drm_connector_reference - incr the connector refcnt | |
2663 | * @connector: connector | |
2664 | * | |
2665 | * This function increments the connector's refcount. | |
2666 | */ | |
2667 | static inline void drm_connector_reference(struct drm_connector *connector) | |
2668 | { | |
2669 | drm_mode_object_reference(&connector->base); | |
2670 | } | |
2671 | ||
2672 | /** | |
2673 | * drm_connector_unreference - unref a connector | |
2674 | * @connector: connector to unref | |
2675 | * | |
2676 | * This function decrements the connector's refcount and frees it if it drops to zero. | |
2677 | */ | |
2678 | static inline void drm_connector_unreference(struct drm_connector *connector) | |
2679 | { | |
2680 | drm_mode_object_unreference(&connector->base); | |
2681 | } | |
2682 | ||
e27dde3e | 2683 | /* Plane list iterator for legacy (overlay only) planes. */ |
4ea50e99 DV |
2684 | #define drm_for_each_legacy_plane(plane, dev) \ |
2685 | list_for_each_entry(plane, &(dev)->mode_config.plane_list, head) \ | |
373701b1 | 2686 | for_each_if (plane->type == DRM_PLANE_TYPE_OVERLAY) |
e27dde3e | 2687 | |
6295d607 DV |
2688 | #define drm_for_each_plane(plane, dev) \ |
2689 | list_for_each_entry(plane, &(dev)->mode_config.plane_list, head) | |
2690 | ||
2691 | #define drm_for_each_crtc(crtc, dev) \ | |
2692 | list_for_each_entry(crtc, &(dev)->mode_config.crtc_list, head) | |
2693 | ||
7a3f3d66 DV |
2694 | static inline void |
2695 | assert_drm_connector_list_read_locked(struct drm_mode_config *mode_config) | |
2696 | { | |
cff20ba2 DV |
2697 | /* |
2698 | * The connector hotadd/remove code currently grabs both locks when | |
2699 | * updating lists. Hence readers need only hold either of them to be | |
2700 | * safe and the check amounts to | |
2701 | * | |
2702 | * WARN_ON(not_holding(A) && not_holding(B)). | |
2703 | */ | |
2704 | WARN_ON(!mutex_is_locked(&mode_config->mutex) && | |
2705 | !drm_modeset_is_locked(&mode_config->connection_mutex)); | |
7a3f3d66 DV |
2706 | } |
2707 | ||
6295d607 | 2708 | #define drm_for_each_connector(connector, dev) \ |
7a3f3d66 DV |
2709 | for (assert_drm_connector_list_read_locked(&(dev)->mode_config), \ |
2710 | connector = list_first_entry(&(dev)->mode_config.connector_list, \ | |
2711 | struct drm_connector, head); \ | |
2712 | &connector->head != (&(dev)->mode_config.connector_list); \ | |
2713 | connector = list_next_entry(connector, head)) | |
6295d607 DV |
2714 | |
2715 | #define drm_for_each_encoder(encoder, dev) \ | |
2716 | list_for_each_entry(encoder, &(dev)->mode_config.encoder_list, head) | |
2717 | ||
2718 | #define drm_for_each_fb(fb, dev) \ | |
4676ba0b DV |
2719 | for (WARN_ON(!mutex_is_locked(&(dev)->mode_config.fb_lock)), \ |
2720 | fb = list_first_entry(&(dev)->mode_config.fb_list, \ | |
2721 | struct drm_framebuffer, head); \ | |
2722 | &fb->head != (&(dev)->mode_config.fb_list); \ | |
2723 | fb = list_next_entry(fb, head)) | |
6295d607 | 2724 | |
f453ba04 | 2725 | #endif /* __DRM_CRTC_H__ */ |