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> |
d7da824d | 38 | #include <drm/drm_rect.h> |
949619f3 | 39 | #include <drm/drm_mode_object.h> |
7520a277 DV |
40 | #include <drm/drm_framebuffer.h> |
41 | #include <drm/drm_modes.h> | |
52217195 | 42 | #include <drm/drm_connector.h> |
321a95ae | 43 | #include <drm/drm_encoder.h> |
59e71ee7 | 44 | #include <drm/drm_property.h> |
308e5bcb | 45 | |
f453ba04 DA |
46 | struct drm_device; |
47 | struct drm_mode_set; | |
595887eb TR |
48 | struct drm_file; |
49 | struct drm_clip_rect; | |
7e435aad | 50 | struct device_node; |
e2330f07 | 51 | struct fence; |
81065548 | 52 | struct edid; |
f453ba04 | 53 | |
ebc44cf3 RC |
54 | static inline int64_t U642I64(uint64_t val) |
55 | { | |
56 | return (int64_t)*((int64_t *)&val); | |
57 | } | |
58 | static inline uint64_t I642U64(int64_t val) | |
59 | { | |
60 | return (uint64_t)*((uint64_t *)&val); | |
61 | } | |
62 | ||
d9c38242 RF |
63 | /* |
64 | * Rotation property bits. DRM_ROTATE_<degrees> rotates the image by the | |
65 | * specified amount in degrees in counter clockwise direction. DRM_REFLECT_X and | |
66 | * DRM_REFLECT_Y reflects the image along the specified axis prior to rotation | |
67 | */ | |
31ad61e4 JL |
68 | #define DRM_ROTATE_0 BIT(0) |
69 | #define DRM_ROTATE_90 BIT(1) | |
70 | #define DRM_ROTATE_180 BIT(2) | |
71 | #define DRM_ROTATE_270 BIT(3) | |
72 | #define DRM_ROTATE_MASK (DRM_ROTATE_0 | DRM_ROTATE_90 | \ | |
73 | DRM_ROTATE_180 | DRM_ROTATE_270) | |
74 | #define DRM_REFLECT_X BIT(4) | |
75 | #define DRM_REFLECT_Y BIT(5) | |
76 | #define DRM_REFLECT_MASK (DRM_REFLECT_X | DRM_REFLECT_Y) | |
06596961 | 77 | |
138f9ebb DA |
78 | /* data corresponds to displayid vend/prod/serial */ |
79 | struct drm_tile_group { | |
80 | struct kref refcount; | |
81 | struct drm_device *dev; | |
82 | int id; | |
83 | u8 group_data[8]; | |
84 | }; | |
85 | ||
f453ba04 | 86 | struct drm_crtc; |
f453ba04 | 87 | struct drm_encoder; |
d91d8a3f | 88 | struct drm_pending_vblank_event; |
8cf5c917 | 89 | struct drm_plane; |
3b336ec4 | 90 | struct drm_bridge; |
144ecb97 DV |
91 | struct drm_atomic_state; |
92 | ||
4490d4c7 DV |
93 | struct drm_crtc_helper_funcs; |
94 | struct drm_encoder_helper_funcs; | |
4490d4c7 DV |
95 | struct drm_plane_helper_funcs; |
96 | ||
144ecb97 | 97 | /** |
cc4ceb48 | 98 | * struct drm_crtc_state - mutable CRTC state |
07cc0ef6 | 99 | * @crtc: backpointer to the CRTC |
144ecb97 | 100 | * @enable: whether the CRTC should be enabled, gates all other state |
d9b13620 | 101 | * @active: whether the CRTC is actively displaying (used for DPMS) |
fc596660 ML |
102 | * @planes_changed: planes on this crtc are updated |
103 | * @mode_changed: crtc_state->mode or crtc_state->enable has been changed | |
104 | * @active_changed: crtc_state->active has been toggled. | |
105 | * @connectors_changed: connectors to this crtc have been updated | |
44d1240d | 106 | * @zpos_changed: zpos values of planes on this crtc have been updated |
5488dc16 LL |
107 | * @color_mgmt_changed: color management properties have changed (degamma or |
108 | * gamma LUT or CSC matrix) | |
6ddd388a | 109 | * @plane_mask: bitmask of (1 << drm_plane_index(plane)) of attached planes |
4cd9fa52 | 110 | * @connector_mask: bitmask of (1 << drm_connector_index(connector)) of attached connectors |
e87a52b3 | 111 | * @encoder_mask: bitmask of (1 << drm_encoder_index(encoder)) of attached encoders |
623369e5 DV |
112 | * @last_vblank_count: for helpers and drivers to capture the vblank of the |
113 | * update to ensure framebuffer cleanup isn't done too early | |
2f324b42 | 114 | * @adjusted_mode: for use by helpers and drivers to compute adjusted mode timings |
144ecb97 | 115 | * @mode: current mode timings |
ac3ba4a5 | 116 | * @mode_blob: &drm_property_blob for @mode |
5488dc16 LL |
117 | * @degamma_lut: Lookup table for converting framebuffer pixel data |
118 | * before apply the conversion matrix | |
119 | * @ctm: Transformation matrix | |
120 | * @gamma_lut: Lookup table for converting pixel data after the | |
121 | * conversion matrix | |
144ecb97 DV |
122 | * @event: optional pointer to a DRM event to signal upon completion of the |
123 | * state update | |
124 | * @state: backpointer to global drm_atomic_state | |
d9b13620 DV |
125 | * |
126 | * Note that the distinction between @enable and @active is rather subtile: | |
127 | * Flipping @active while @enable is set without changing anything else may | |
128 | * never return in a failure from the ->atomic_check callback. Userspace assumes | |
129 | * that a DPMS On will always succeed. In other words: @enable controls resource | |
130 | * assignment, @active controls the actual hardware state. | |
144ecb97 DV |
131 | */ |
132 | struct drm_crtc_state { | |
07cc0ef6 DV |
133 | struct drm_crtc *crtc; |
134 | ||
cc4ceb48 | 135 | bool enable; |
d9b13620 | 136 | bool active; |
144ecb97 | 137 | |
c2fcd274 DV |
138 | /* computed state bits used by helpers and drivers */ |
139 | bool planes_changed : 1; | |
623369e5 | 140 | bool mode_changed : 1; |
eab3bbef | 141 | bool active_changed : 1; |
fc596660 | 142 | bool connectors_changed : 1; |
44d1240d | 143 | bool zpos_changed : 1; |
5488dc16 | 144 | bool color_mgmt_changed : 1; |
623369e5 | 145 | |
6ddd388a RC |
146 | /* attached planes bitmask: |
147 | * WARNING: transitional helpers do not maintain plane_mask so | |
148 | * drivers not converted over to atomic helpers should not rely | |
149 | * on plane_mask being accurate! | |
150 | */ | |
151 | u32 plane_mask; | |
152 | ||
4cd9fa52 | 153 | u32 connector_mask; |
e87a52b3 | 154 | u32 encoder_mask; |
4cd9fa52 | 155 | |
623369e5 DV |
156 | /* last_vblank_count: for vblank waits before cleanup */ |
157 | u32 last_vblank_count; | |
c2fcd274 | 158 | |
2f324b42 DV |
159 | /* adjusted_mode: for use by helpers and drivers */ |
160 | struct drm_display_mode adjusted_mode; | |
161 | ||
144ecb97 DV |
162 | struct drm_display_mode mode; |
163 | ||
99cf4a29 DS |
164 | /* blob property to expose current mode to atomic userspace */ |
165 | struct drm_property_blob *mode_blob; | |
166 | ||
5488dc16 LL |
167 | /* blob property to expose color management to userspace */ |
168 | struct drm_property_blob *degamma_lut; | |
169 | struct drm_property_blob *ctm; | |
170 | struct drm_property_blob *gamma_lut; | |
171 | ||
144ecb97 DV |
172 | struct drm_pending_vblank_event *event; |
173 | ||
174 | struct drm_atomic_state *state; | |
175 | }; | |
f453ba04 DA |
176 | |
177 | /** | |
3bf0401c | 178 | * struct drm_crtc_funcs - control CRTCs for a given device |
f453ba04 DA |
179 | * |
180 | * The drm_crtc_funcs structure is the central CRTC management structure | |
181 | * in the DRM. Each CRTC controls one or more connectors (note that the name | |
182 | * CRTC is simply historical, a CRTC may control LVDS, VGA, DVI, TV out, etc. | |
183 | * connectors, not just CRTs). | |
184 | * | |
185 | * Each driver is responsible for filling out this structure at startup time, | |
186 | * in addition to providing other modesetting features, like i2c and DDC | |
187 | * bus accessors. | |
188 | */ | |
189 | struct drm_crtc_funcs { | |
88548636 DV |
190 | /** |
191 | * @reset: | |
192 | * | |
193 | * Reset CRTC hardware and software state to off. This function isn't | |
194 | * called by the core directly, only through drm_mode_config_reset(). | |
195 | * It's not a helper hook only for historical reasons. | |
196 | * | |
197 | * Atomic drivers can use drm_atomic_helper_crtc_reset() to reset | |
198 | * atomic state using this hook. | |
199 | */ | |
eb033556 | 200 | void (*reset)(struct drm_crtc *crtc); |
f453ba04 | 201 | |
f6da8c6e DV |
202 | /** |
203 | * @cursor_set: | |
204 | * | |
205 | * Update the cursor image. The cursor position is relative to the CRTC | |
206 | * and can be partially or fully outside of the visible area. | |
207 | * | |
208 | * Note that contrary to all other KMS functions the legacy cursor entry | |
209 | * points don't take a framebuffer object, but instead take directly a | |
210 | * raw buffer object id from the driver's buffer manager (which is | |
211 | * either GEM or TTM for current drivers). | |
212 | * | |
213 | * This entry point is deprecated, drivers should instead implement | |
214 | * universal plane support and register a proper cursor plane using | |
215 | * drm_crtc_init_with_planes(). | |
216 | * | |
217 | * This callback is optional | |
218 | * | |
219 | * RETURNS: | |
220 | * | |
221 | * 0 on success or a negative error code on failure. | |
222 | */ | |
f453ba04 DA |
223 | int (*cursor_set)(struct drm_crtc *crtc, struct drm_file *file_priv, |
224 | uint32_t handle, uint32_t width, uint32_t height); | |
f6da8c6e DV |
225 | |
226 | /** | |
227 | * @cursor_set2: | |
228 | * | |
229 | * Update the cursor image, including hotspot information. The hotspot | |
230 | * must not affect the cursor position in CRTC coordinates, but is only | |
231 | * meant as a hint for virtualized display hardware to coordinate the | |
232 | * guests and hosts cursor position. The cursor hotspot is relative to | |
233 | * the cursor image. Otherwise this works exactly like @cursor_set. | |
234 | * | |
235 | * This entry point is deprecated, drivers should instead implement | |
236 | * universal plane support and register a proper cursor plane using | |
237 | * drm_crtc_init_with_planes(). | |
238 | * | |
239 | * This callback is optional. | |
240 | * | |
241 | * RETURNS: | |
242 | * | |
243 | * 0 on success or a negative error code on failure. | |
244 | */ | |
4c813d4d DA |
245 | int (*cursor_set2)(struct drm_crtc *crtc, struct drm_file *file_priv, |
246 | uint32_t handle, uint32_t width, uint32_t height, | |
247 | int32_t hot_x, int32_t hot_y); | |
f6da8c6e DV |
248 | |
249 | /** | |
250 | * @cursor_move: | |
251 | * | |
252 | * Update the cursor position. The cursor does not need to be visible | |
253 | * when this hook is called. | |
254 | * | |
255 | * This entry point is deprecated, drivers should instead implement | |
256 | * universal plane support and register a proper cursor plane using | |
257 | * drm_crtc_init_with_planes(). | |
258 | * | |
259 | * This callback is optional. | |
260 | * | |
261 | * RETURNS: | |
262 | * | |
263 | * 0 on success or a negative error code on failure. | |
264 | */ | |
f453ba04 DA |
265 | int (*cursor_move)(struct drm_crtc *crtc, int x, int y); |
266 | ||
f6da8c6e DV |
267 | /** |
268 | * @gamma_set: | |
269 | * | |
270 | * Set gamma on the CRTC. | |
271 | * | |
272 | * This callback is optional. | |
273 | * | |
274 | * NOTE: | |
275 | * | |
276 | * Drivers that support gamma tables and also fbdev emulation through | |
277 | * the provided helper library need to take care to fill out the gamma | |
278 | * hooks for both. Currently there's a bit an unfortunate duplication | |
279 | * going on, which should eventually be unified to just one set of | |
280 | * hooks. | |
281 | */ | |
7ea77283 ML |
282 | int (*gamma_set)(struct drm_crtc *crtc, u16 *r, u16 *g, u16 *b, |
283 | uint32_t size); | |
88548636 DV |
284 | |
285 | /** | |
286 | * @destroy: | |
287 | * | |
288 | * Clean up plane resources. This is only called at driver unload time | |
289 | * through drm_mode_config_cleanup() since a CRTC cannot be hotplugged | |
290 | * in DRM. | |
291 | */ | |
f453ba04 DA |
292 | void (*destroy)(struct drm_crtc *crtc); |
293 | ||
f6da8c6e DV |
294 | /** |
295 | * @set_config: | |
296 | * | |
297 | * This is the main legacy entry point to change the modeset state on a | |
298 | * CRTC. All the details of the desired configuration are passed in a | |
299 | * struct &drm_mode_set - see there for details. | |
300 | * | |
301 | * Drivers implementing atomic modeset should use | |
302 | * drm_atomic_helper_set_config() to implement this hook. | |
303 | * | |
304 | * RETURNS: | |
305 | * | |
306 | * 0 on success or a negative error code on failure. | |
307 | */ | |
f453ba04 | 308 | int (*set_config)(struct drm_mode_set *set); |
d91d8a3f | 309 | |
f6da8c6e DV |
310 | /** |
311 | * @page_flip: | |
312 | * | |
313 | * Legacy entry point to schedule a flip to the given framebuffer. | |
314 | * | |
315 | * Page flipping is a synchronization mechanism that replaces the frame | |
316 | * buffer being scanned out by the CRTC with a new frame buffer during | |
317 | * vertical blanking, avoiding tearing (except when requested otherwise | |
318 | * through the DRM_MODE_PAGE_FLIP_ASYNC flag). When an application | |
319 | * requests a page flip the DRM core verifies that the new frame buffer | |
320 | * is large enough to be scanned out by the CRTC in the currently | |
321 | * configured mode and then calls the CRTC ->page_flip() operation with a | |
322 | * pointer to the new frame buffer. | |
323 | * | |
324 | * The driver must wait for any pending rendering to the new framebuffer | |
325 | * to complete before executing the flip. It should also wait for any | |
326 | * pending rendering from other drivers if the underlying buffer is a | |
327 | * shared dma-buf. | |
328 | * | |
329 | * An application can request to be notified when the page flip has | |
330 | * completed. The drm core will supply a struct &drm_event in the event | |
331 | * parameter in this case. This can be handled by the | |
332 | * drm_crtc_send_vblank_event() function, which the driver should call on | |
333 | * the provided event upon completion of the flip. Note that if | |
334 | * the driver supports vblank signalling and timestamping the vblank | |
335 | * counters and timestamps must agree with the ones returned from page | |
336 | * flip events. With the current vblank helper infrastructure this can | |
337 | * be achieved by holding a vblank reference while the page flip is | |
338 | * pending, acquired through drm_crtc_vblank_get() and released with | |
339 | * drm_crtc_vblank_put(). Drivers are free to implement their own vblank | |
340 | * counter and timestamp tracking though, e.g. if they have accurate | |
341 | * timestamp registers in hardware. | |
342 | * | |
f6da8c6e DV |
343 | * This callback is optional. |
344 | * | |
345 | * NOTE: | |
346 | * | |
347 | * Very early versions of the KMS ABI mandated that the driver must | |
348 | * block (but not reject) any rendering to the old framebuffer until the | |
349 | * flip operation has completed and the old framebuffer is no longer | |
350 | * visible. This requirement has been lifted, and userspace is instead | |
351 | * expected to request delivery of an event and wait with recycling old | |
352 | * buffers until such has been received. | |
353 | * | |
354 | * RETURNS: | |
355 | * | |
356 | * 0 on success or a negative error code on failure. Note that if a | |
357 | * ->page_flip() operation is already pending the callback should return | |
358 | * -EBUSY. Pageflips on a disabled CRTC (either by setting a NULL mode | |
359 | * or just runtime disabled through DPMS respectively the new atomic | |
4cba6850 DV |
360 | * "ACTIVE" state) should result in an -EINVAL error code. Note that |
361 | * drm_atomic_helper_page_flip() checks this already for atomic drivers. | |
d91d8a3f KH |
362 | */ |
363 | int (*page_flip)(struct drm_crtc *crtc, | |
364 | struct drm_framebuffer *fb, | |
ed8d1975 KP |
365 | struct drm_pending_vblank_event *event, |
366 | uint32_t flags); | |
bffd9de0 | 367 | |
c229bfbb MD |
368 | /** |
369 | * @page_flip_target: | |
370 | * | |
371 | * Same as @page_flip but with an additional parameter specifying the | |
372 | * absolute target vertical blank period (as reported by | |
373 | * drm_crtc_vblank_count()) when the flip should take effect. | |
374 | * | |
375 | * Note that the core code calls drm_crtc_vblank_get before this entry | |
376 | * point, and will call drm_crtc_vblank_put if this entry point returns | |
377 | * any non-0 error code. It's the driver's responsibility to call | |
378 | * drm_crtc_vblank_put after this entry point returns 0, typically when | |
379 | * the flip completes. | |
380 | */ | |
381 | int (*page_flip_target)(struct drm_crtc *crtc, | |
382 | struct drm_framebuffer *fb, | |
383 | struct drm_pending_vblank_event *event, | |
384 | uint32_t flags, uint32_t target); | |
385 | ||
88548636 DV |
386 | /** |
387 | * @set_property: | |
388 | * | |
389 | * This is the legacy entry point to update a property attached to the | |
390 | * CRTC. | |
391 | * | |
392 | * Drivers implementing atomic modeset should use | |
393 | * drm_atomic_helper_crtc_set_property() to implement this hook. | |
394 | * | |
395 | * This callback is optional if the driver does not support any legacy | |
396 | * driver-private properties. | |
397 | * | |
398 | * RETURNS: | |
399 | * | |
400 | * 0 on success or a negative error code on failure. | |
401 | */ | |
bffd9de0 PZ |
402 | int (*set_property)(struct drm_crtc *crtc, |
403 | struct drm_property *property, uint64_t val); | |
144ecb97 | 404 | |
88548636 DV |
405 | /** |
406 | * @atomic_duplicate_state: | |
407 | * | |
408 | * Duplicate the current atomic state for this CRTC and return it. | |
409 | * The core and helpers gurantee that any atomic state duplicated with | |
410 | * this hook and still owned by the caller (i.e. not transferred to the | |
411 | * driver by calling ->atomic_commit() from struct | |
412 | * &drm_mode_config_funcs) will be cleaned up by calling the | |
413 | * @atomic_destroy_state hook in this structure. | |
414 | * | |
415 | * Atomic drivers which don't subclass struct &drm_crtc should use | |
416 | * drm_atomic_helper_crtc_duplicate_state(). Drivers that subclass the | |
417 | * state structure to extend it with driver-private state should use | |
418 | * __drm_atomic_helper_crtc_duplicate_state() to make sure shared state is | |
419 | * duplicated in a consistent fashion across drivers. | |
420 | * | |
421 | * It is an error to call this hook before crtc->state has been | |
422 | * initialized correctly. | |
423 | * | |
424 | * NOTE: | |
425 | * | |
426 | * If the duplicate state references refcounted resources this hook must | |
427 | * acquire a reference for each of them. The driver must release these | |
428 | * references again in @atomic_destroy_state. | |
429 | * | |
430 | * RETURNS: | |
431 | * | |
432 | * Duplicated atomic state or NULL when the allocation failed. | |
433 | */ | |
144ecb97 | 434 | struct drm_crtc_state *(*atomic_duplicate_state)(struct drm_crtc *crtc); |
88548636 DV |
435 | |
436 | /** | |
437 | * @atomic_destroy_state: | |
438 | * | |
439 | * Destroy a state duplicated with @atomic_duplicate_state and release | |
440 | * or unreference all resources it references | |
441 | */ | |
144ecb97 | 442 | void (*atomic_destroy_state)(struct drm_crtc *crtc, |
cc4ceb48 | 443 | struct drm_crtc_state *state); |
88548636 DV |
444 | |
445 | /** | |
446 | * @atomic_set_property: | |
447 | * | |
448 | * Decode a driver-private property value and store the decoded value | |
449 | * into the passed-in state structure. Since the atomic core decodes all | |
450 | * standardized properties (even for extensions beyond the core set of | |
451 | * properties which might not be implemented by all drivers) this | |
452 | * requires drivers to subclass the state structure. | |
453 | * | |
454 | * Such driver-private properties should really only be implemented for | |
455 | * truly hardware/vendor specific state. Instead it is preferred to | |
456 | * standardize atomic extension and decode the properties used to expose | |
457 | * such an extension in the core. | |
458 | * | |
459 | * Do not call this function directly, use | |
460 | * drm_atomic_crtc_set_property() instead. | |
461 | * | |
462 | * This callback is optional if the driver does not support any | |
463 | * driver-private atomic properties. | |
464 | * | |
465 | * NOTE: | |
466 | * | |
467 | * This function is called in the state assembly phase of atomic | |
468 | * modesets, which can be aborted for any reason (including on | |
469 | * userspace's request to just check whether a configuration would be | |
470 | * possible). Drivers MUST NOT touch any persistent state (hardware or | |
471 | * software) or data structures except the passed in @state parameter. | |
472 | * | |
473 | * Also since userspace controls in which order properties are set this | |
474 | * function must not do any input validation (since the state update is | |
475 | * incomplete and hence likely inconsistent). Instead any such input | |
476 | * validation must be done in the various atomic_check callbacks. | |
477 | * | |
478 | * RETURNS: | |
479 | * | |
480 | * 0 if the property has been found, -EINVAL if the property isn't | |
481 | * implemented by the driver (which should never happen, the core only | |
482 | * asks for properties attached to this CRTC). No other validation is | |
483 | * allowed by the driver. The core already checks that the property | |
484 | * value is within the range (integer, valid enum value, ...) the driver | |
485 | * set when registering the property. | |
486 | */ | |
144ecb97 DV |
487 | int (*atomic_set_property)(struct drm_crtc *crtc, |
488 | struct drm_crtc_state *state, | |
489 | struct drm_property *property, | |
490 | uint64_t val); | |
88548636 DV |
491 | /** |
492 | * @atomic_get_property: | |
493 | * | |
494 | * Reads out the decoded driver-private property. This is used to | |
c6b0ca3e | 495 | * implement the GETCRTC IOCTL. |
88548636 DV |
496 | * |
497 | * Do not call this function directly, use | |
498 | * drm_atomic_crtc_get_property() instead. | |
499 | * | |
500 | * This callback is optional if the driver does not support any | |
501 | * driver-private atomic properties. | |
502 | * | |
503 | * RETURNS: | |
504 | * | |
505 | * 0 on success, -EINVAL if the property isn't implemented by the | |
506 | * driver (which should never happen, the core only asks for | |
507 | * properties attached to this CRTC). | |
508 | */ | |
ac9c9256 RC |
509 | int (*atomic_get_property)(struct drm_crtc *crtc, |
510 | const struct drm_crtc_state *state, | |
511 | struct drm_property *property, | |
512 | uint64_t *val); | |
79190ea2 BG |
513 | |
514 | /** | |
515 | * @late_register: | |
516 | * | |
517 | * This optional hook can be used to register additional userspace | |
518 | * interfaces attached to the crtc like debugfs interfaces. | |
519 | * It is called late in the driver load sequence from drm_dev_register(). | |
520 | * Everything added from this callback should be unregistered in | |
521 | * the early_unregister callback. | |
522 | * | |
523 | * Returns: | |
524 | * | |
525 | * 0 on success, or a negative error code on failure. | |
526 | */ | |
527 | int (*late_register)(struct drm_crtc *crtc); | |
528 | ||
529 | /** | |
530 | * @early_unregister: | |
531 | * | |
532 | * This optional hook should be used to unregister the additional | |
533 | * userspace interfaces attached to the crtc from | |
534 | * late_unregister(). It is called from drm_dev_unregister(), | |
535 | * early in the driver unload sequence to disable userspace access | |
536 | * before data structures are torndown. | |
537 | */ | |
538 | void (*early_unregister)(struct drm_crtc *crtc); | |
f453ba04 DA |
539 | }; |
540 | ||
541 | /** | |
3bf0401c | 542 | * struct drm_crtc - central CRTC control structure |
7749163e | 543 | * @dev: parent DRM device |
2c0c33d4 | 544 | * @port: OF node used by drm_of_find_possible_crtcs() |
7749163e | 545 | * @head: list management |
ac3ba4a5 | 546 | * @name: human readable name, can be overwritten by the driver |
51fd371b | 547 | * @mutex: per-CRTC locking |
7749163e | 548 | * @base: base KMS object for ID tracking etc. |
e13161af MR |
549 | * @primary: primary plane for this CRTC |
550 | * @cursor: cursor plane for this CRTC | |
2c0c33d4 DV |
551 | * @cursor_x: current x position of the cursor, used for universal cursor planes |
552 | * @cursor_y: current y position of the cursor, used for universal cursor planes | |
f453ba04 | 553 | * @enabled: is this CRTC enabled? |
7749163e JB |
554 | * @mode: current mode timings |
555 | * @hwmode: mode timings as programmed to hw regs | |
f453ba04 DA |
556 | * @x: x position on screen |
557 | * @y: y position on screen | |
f453ba04 | 558 | * @funcs: CRTC control functions |
7749163e JB |
559 | * @gamma_size: size of gamma ramp |
560 | * @gamma_store: gamma ramp values | |
7749163e | 561 | * @helper_private: mid-layer private data |
bffd9de0 | 562 | * @properties: property tracking for this CRTC |
f453ba04 DA |
563 | * |
564 | * Each CRTC may have one or more connectors associated with it. This structure | |
565 | * allows the CRTC to be controlled. | |
566 | */ | |
567 | struct drm_crtc { | |
568 | struct drm_device *dev; | |
7e435aad | 569 | struct device_node *port; |
f453ba04 DA |
570 | struct list_head head; |
571 | ||
fa3ab4c2 VS |
572 | char *name; |
573 | ||
ac3ba4a5 DV |
574 | /** |
575 | * @mutex: | |
29494c17 DV |
576 | * |
577 | * This provides a read lock for the overall crtc state (mode, dpms | |
578 | * state, ...) and a write lock for everything which can be update | |
ac3ba4a5 DV |
579 | * without a full modeset (fb, cursor data, crtc properties ...). Full |
580 | * modeset also need to grab dev->mode_config.connection_mutex. | |
29494c17 | 581 | */ |
51fd371b | 582 | struct drm_modeset_lock mutex; |
29494c17 | 583 | |
f453ba04 DA |
584 | struct drm_mode_object base; |
585 | ||
e13161af MR |
586 | /* primary and cursor planes for CRTC */ |
587 | struct drm_plane *primary; | |
588 | struct drm_plane *cursor; | |
589 | ||
96094081 DV |
590 | /** |
591 | * @index: Position inside the mode_config.list, can be used as an array | |
592 | * index. It is invariant over the lifetime of the CRTC. | |
593 | */ | |
490d3d1b CW |
594 | unsigned index; |
595 | ||
161d0dc1 MR |
596 | /* position of cursor plane on crtc */ |
597 | int cursor_x; | |
598 | int cursor_y; | |
599 | ||
f453ba04 DA |
600 | bool enabled; |
601 | ||
27641c3f | 602 | /* Requested mode from modesetting. */ |
f453ba04 DA |
603 | struct drm_display_mode mode; |
604 | ||
27641c3f MK |
605 | /* Programmed mode in hw, after adjustments for encoders, |
606 | * crtc, panel scaling etc. Needed for timestamping etc. | |
607 | */ | |
608 | struct drm_display_mode hwmode; | |
609 | ||
f453ba04 | 610 | int x, y; |
f453ba04 DA |
611 | const struct drm_crtc_funcs *funcs; |
612 | ||
5488dc16 | 613 | /* Legacy FB CRTC gamma size for reporting to userspace */ |
f453ba04 DA |
614 | uint32_t gamma_size; |
615 | uint16_t *gamma_store; | |
616 | ||
617 | /* if you are using the helper */ | |
4490d4c7 | 618 | const struct drm_crtc_helper_funcs *helper_private; |
bffd9de0 PZ |
619 | |
620 | struct drm_object_properties properties; | |
d059f652 | 621 | |
3b24f7d6 DV |
622 | /** |
623 | * @state: | |
624 | * | |
625 | * Current atomic state for this CRTC. | |
626 | */ | |
144ecb97 DV |
627 | struct drm_crtc_state *state; |
628 | ||
3b24f7d6 DV |
629 | /** |
630 | * @commit_list: | |
631 | * | |
632 | * List of &drm_crtc_commit structures tracking pending commits. | |
633 | * Protected by @commit_lock. This list doesn't hold its own full | |
634 | * reference, but burrows it from the ongoing commit. Commit entries | |
635 | * must be removed from this list once the commit is fully completed, | |
636 | * but before it's correspoding &drm_atomic_state gets destroyed. | |
637 | */ | |
638 | struct list_head commit_list; | |
639 | ||
640 | /** | |
641 | * @commit_lock: | |
642 | * | |
643 | * Spinlock to protect @commit_list. | |
644 | */ | |
645 | spinlock_t commit_lock; | |
646 | ||
647 | /** | |
648 | * @acquire_ctx: | |
649 | * | |
650 | * Per-CRTC implicit acquire context used by atomic drivers for legacy | |
651 | * IOCTLs, so that atomic drivers can get at the locking acquire | |
652 | * context. | |
d059f652 DV |
653 | */ |
654 | struct drm_modeset_acquire_ctx *acquire_ctx; | |
f453ba04 DA |
655 | }; |
656 | ||
144ecb97 DV |
657 | /** |
658 | * struct drm_plane_state - mutable plane state | |
07cc0ef6 | 659 | * @plane: backpointer to the plane |
144ecb97 | 660 | * @crtc: currently bound CRTC, NULL if disabled |
cc4ceb48 | 661 | * @fb: currently bound framebuffer |
e2330f07 | 662 | * @fence: optional fence to wait for before scanning out @fb |
144ecb97 DV |
663 | * @crtc_x: left position of visible portion of plane on crtc |
664 | * @crtc_y: upper position of visible portion of plane on crtc | |
665 | * @crtc_w: width of visible portion of plane on crtc | |
666 | * @crtc_h: height of visible portion of plane on crtc | |
667 | * @src_x: left position of visible portion of plane within | |
668 | * plane (in 16.16) | |
669 | * @src_y: upper position of visible portion of plane within | |
670 | * plane (in 16.16) | |
671 | * @src_w: width of visible portion of plane (in 16.16) | |
672 | * @src_h: height of visible portion of plane (in 16.16) | |
ac3ba4a5 | 673 | * @rotation: rotation of the plane |
44d1240d MS |
674 | * @zpos: priority of the given plane on crtc (optional) |
675 | * @normalized_zpos: normalized value of zpos: unique, range from 0 to N-1 | |
676 | * where N is the number of active planes for given crtc | |
d7da824d VS |
677 | * @src: clipped source coordinates of the plane (in 16.16) |
678 | * @dst: clipped destination coordinates of the plane | |
679 | * @visible: visibility of the plane | |
144ecb97 DV |
680 | * @state: backpointer to global drm_atomic_state |
681 | */ | |
682 | struct drm_plane_state { | |
07cc0ef6 DV |
683 | struct drm_plane *plane; |
684 | ||
6ddd388a RC |
685 | struct drm_crtc *crtc; /* do not write directly, use drm_atomic_set_crtc_for_plane() */ |
686 | struct drm_framebuffer *fb; /* do not write directly, use drm_atomic_set_fb_for_plane() */ | |
e2330f07 | 687 | struct fence *fence; |
144ecb97 DV |
688 | |
689 | /* Signed dest location allows it to be partially off screen */ | |
690 | int32_t crtc_x, crtc_y; | |
691 | uint32_t crtc_w, crtc_h; | |
692 | ||
693 | /* Source values are 16.16 fixed point */ | |
694 | uint32_t src_x, src_y; | |
695 | uint32_t src_h, src_w; | |
696 | ||
1da30627 MR |
697 | /* Plane rotation */ |
698 | unsigned int rotation; | |
699 | ||
44d1240d MS |
700 | /* Plane zpos */ |
701 | unsigned int zpos; | |
702 | unsigned int normalized_zpos; | |
703 | ||
d7da824d VS |
704 | /* Clipped coordinates */ |
705 | struct drm_rect src, dst; | |
706 | ||
707 | /* | |
708 | * Is the plane actually visible? Can be false even | |
709 | * if fb!=NULL and crtc!=NULL, due to clipping. | |
710 | */ | |
711 | bool visible; | |
712 | ||
144ecb97 | 713 | struct drm_atomic_state *state; |
f453ba04 DA |
714 | }; |
715 | ||
144ecb97 | 716 | |
8cf5c917 | 717 | /** |
3bf0401c | 718 | * struct drm_plane_funcs - driver plane control functions |
8cf5c917 JB |
719 | */ |
720 | struct drm_plane_funcs { | |
88548636 DV |
721 | /** |
722 | * @update_plane: | |
723 | * | |
724 | * This is the legacy entry point to enable and configure the plane for | |
725 | * the given CRTC and framebuffer. It is never called to disable the | |
726 | * plane, i.e. the passed-in crtc and fb paramters are never NULL. | |
727 | * | |
728 | * The source rectangle in frame buffer memory coordinates is given by | |
729 | * the src_x, src_y, src_w and src_h parameters (as 16.16 fixed point | |
730 | * values). Devices that don't support subpixel plane coordinates can | |
731 | * ignore the fractional part. | |
732 | * | |
733 | * The destination rectangle in CRTC coordinates is given by the | |
734 | * crtc_x, crtc_y, crtc_w and crtc_h parameters (as integer values). | |
735 | * Devices scale the source rectangle to the destination rectangle. If | |
736 | * scaling is not supported, and the source rectangle size doesn't match | |
737 | * the destination rectangle size, the driver must return a | |
738 | * -<errorname>EINVAL</errorname> error. | |
739 | * | |
740 | * Drivers implementing atomic modeset should use | |
741 | * drm_atomic_helper_update_plane() to implement this hook. | |
742 | * | |
743 | * RETURNS: | |
744 | * | |
745 | * 0 on success or a negative error code on failure. | |
746 | */ | |
8cf5c917 JB |
747 | int (*update_plane)(struct drm_plane *plane, |
748 | struct drm_crtc *crtc, struct drm_framebuffer *fb, | |
749 | int crtc_x, int crtc_y, | |
750 | unsigned int crtc_w, unsigned int crtc_h, | |
751 | uint32_t src_x, uint32_t src_y, | |
752 | uint32_t src_w, uint32_t src_h); | |
88548636 DV |
753 | |
754 | /** | |
755 | * @disable_plane: | |
756 | * | |
757 | * This is the legacy entry point to disable the plane. The DRM core | |
c6b0ca3e | 758 | * calls this method in response to a DRM_IOCTL_MODE_SETPLANE IOCTL call |
88548636 DV |
759 | * with the frame buffer ID set to 0. Disabled planes must not be |
760 | * processed by the CRTC. | |
761 | * | |
762 | * Drivers implementing atomic modeset should use | |
763 | * drm_atomic_helper_disable_plane() to implement this hook. | |
764 | * | |
765 | * RETURNS: | |
766 | * | |
767 | * 0 on success or a negative error code on failure. | |
768 | */ | |
8cf5c917 | 769 | int (*disable_plane)(struct drm_plane *plane); |
88548636 DV |
770 | |
771 | /** | |
772 | * @destroy: | |
773 | * | |
774 | * Clean up plane resources. This is only called at driver unload time | |
775 | * through drm_mode_config_cleanup() since a plane cannot be hotplugged | |
776 | * in DRM. | |
777 | */ | |
8cf5c917 | 778 | void (*destroy)(struct drm_plane *plane); |
88548636 DV |
779 | |
780 | /** | |
781 | * @reset: | |
782 | * | |
783 | * Reset plane hardware and software state to off. This function isn't | |
784 | * called by the core directly, only through drm_mode_config_reset(). | |
785 | * It's not a helper hook only for historical reasons. | |
786 | * | |
787 | * Atomic drivers can use drm_atomic_helper_plane_reset() to reset | |
788 | * atomic state using this hook. | |
789 | */ | |
2a0d7cfd | 790 | void (*reset)(struct drm_plane *plane); |
4d93914a | 791 | |
88548636 DV |
792 | /** |
793 | * @set_property: | |
794 | * | |
795 | * This is the legacy entry point to update a property attached to the | |
796 | * plane. | |
797 | * | |
798 | * Drivers implementing atomic modeset should use | |
799 | * drm_atomic_helper_plane_set_property() to implement this hook. | |
800 | * | |
801 | * This callback is optional if the driver does not support any legacy | |
802 | * driver-private properties. | |
803 | * | |
804 | * RETURNS: | |
805 | * | |
806 | * 0 on success or a negative error code on failure. | |
807 | */ | |
4d93914a RC |
808 | int (*set_property)(struct drm_plane *plane, |
809 | struct drm_property *property, uint64_t val); | |
144ecb97 | 810 | |
88548636 DV |
811 | /** |
812 | * @atomic_duplicate_state: | |
813 | * | |
814 | * Duplicate the current atomic state for this plane and return it. | |
815 | * The core and helpers gurantee that any atomic state duplicated with | |
816 | * this hook and still owned by the caller (i.e. not transferred to the | |
817 | * driver by calling ->atomic_commit() from struct | |
818 | * &drm_mode_config_funcs) will be cleaned up by calling the | |
819 | * @atomic_destroy_state hook in this structure. | |
820 | * | |
821 | * Atomic drivers which don't subclass struct &drm_plane_state should use | |
822 | * drm_atomic_helper_plane_duplicate_state(). Drivers that subclass the | |
823 | * state structure to extend it with driver-private state should use | |
824 | * __drm_atomic_helper_plane_duplicate_state() to make sure shared state is | |
825 | * duplicated in a consistent fashion across drivers. | |
826 | * | |
827 | * It is an error to call this hook before plane->state has been | |
828 | * initialized correctly. | |
829 | * | |
830 | * NOTE: | |
831 | * | |
832 | * If the duplicate state references refcounted resources this hook must | |
833 | * acquire a reference for each of them. The driver must release these | |
834 | * references again in @atomic_destroy_state. | |
835 | * | |
836 | * RETURNS: | |
837 | * | |
838 | * Duplicated atomic state or NULL when the allocation failed. | |
839 | */ | |
144ecb97 | 840 | struct drm_plane_state *(*atomic_duplicate_state)(struct drm_plane *plane); |
88548636 DV |
841 | |
842 | /** | |
843 | * @atomic_destroy_state: | |
844 | * | |
845 | * Destroy a state duplicated with @atomic_duplicate_state and release | |
846 | * or unreference all resources it references | |
847 | */ | |
144ecb97 | 848 | void (*atomic_destroy_state)(struct drm_plane *plane, |
cc4ceb48 | 849 | struct drm_plane_state *state); |
88548636 DV |
850 | |
851 | /** | |
852 | * @atomic_set_property: | |
853 | * | |
854 | * Decode a driver-private property value and store the decoded value | |
855 | * into the passed-in state structure. Since the atomic core decodes all | |
856 | * standardized properties (even for extensions beyond the core set of | |
857 | * properties which might not be implemented by all drivers) this | |
858 | * requires drivers to subclass the state structure. | |
859 | * | |
860 | * Such driver-private properties should really only be implemented for | |
861 | * truly hardware/vendor specific state. Instead it is preferred to | |
862 | * standardize atomic extension and decode the properties used to expose | |
863 | * such an extension in the core. | |
864 | * | |
865 | * Do not call this function directly, use | |
866 | * drm_atomic_plane_set_property() instead. | |
867 | * | |
868 | * This callback is optional if the driver does not support any | |
869 | * driver-private atomic properties. | |
870 | * | |
871 | * NOTE: | |
872 | * | |
873 | * This function is called in the state assembly phase of atomic | |
874 | * modesets, which can be aborted for any reason (including on | |
875 | * userspace's request to just check whether a configuration would be | |
876 | * possible). Drivers MUST NOT touch any persistent state (hardware or | |
877 | * software) or data structures except the passed in @state parameter. | |
878 | * | |
879 | * Also since userspace controls in which order properties are set this | |
880 | * function must not do any input validation (since the state update is | |
881 | * incomplete and hence likely inconsistent). Instead any such input | |
882 | * validation must be done in the various atomic_check callbacks. | |
883 | * | |
884 | * RETURNS: | |
885 | * | |
886 | * 0 if the property has been found, -EINVAL if the property isn't | |
887 | * implemented by the driver (which shouldn't ever happen, the core only | |
888 | * asks for properties attached to this plane). No other validation is | |
889 | * allowed by the driver. The core already checks that the property | |
890 | * value is within the range (integer, valid enum value, ...) the driver | |
891 | * set when registering the property. | |
892 | */ | |
144ecb97 DV |
893 | int (*atomic_set_property)(struct drm_plane *plane, |
894 | struct drm_plane_state *state, | |
895 | struct drm_property *property, | |
896 | uint64_t val); | |
88548636 DV |
897 | |
898 | /** | |
899 | * @atomic_get_property: | |
900 | * | |
901 | * Reads out the decoded driver-private property. This is used to | |
c6b0ca3e | 902 | * implement the GETPLANE IOCTL. |
88548636 DV |
903 | * |
904 | * Do not call this function directly, use | |
905 | * drm_atomic_plane_get_property() instead. | |
906 | * | |
907 | * This callback is optional if the driver does not support any | |
908 | * driver-private atomic properties. | |
909 | * | |
910 | * RETURNS: | |
911 | * | |
912 | * 0 on success, -EINVAL if the property isn't implemented by the | |
913 | * driver (which should never happen, the core only asks for | |
914 | * properties attached to this plane). | |
915 | */ | |
ac9c9256 RC |
916 | int (*atomic_get_property)(struct drm_plane *plane, |
917 | const struct drm_plane_state *state, | |
918 | struct drm_property *property, | |
919 | uint64_t *val); | |
79190ea2 BG |
920 | /** |
921 | * @late_register: | |
922 | * | |
923 | * This optional hook can be used to register additional userspace | |
924 | * interfaces attached to the plane like debugfs interfaces. | |
925 | * It is called late in the driver load sequence from drm_dev_register(). | |
926 | * Everything added from this callback should be unregistered in | |
927 | * the early_unregister callback. | |
928 | * | |
929 | * Returns: | |
930 | * | |
931 | * 0 on success, or a negative error code on failure. | |
932 | */ | |
933 | int (*late_register)(struct drm_plane *plane); | |
934 | ||
935 | /** | |
936 | * @early_unregister: | |
937 | * | |
938 | * This optional hook should be used to unregister the additional | |
939 | * userspace interfaces attached to the plane from | |
940 | * late_unregister(). It is called from drm_dev_unregister(), | |
941 | * early in the driver unload sequence to disable userspace access | |
942 | * before data structures are torndown. | |
943 | */ | |
944 | void (*early_unregister)(struct drm_plane *plane); | |
8cf5c917 JB |
945 | }; |
946 | ||
e27dde3e MR |
947 | enum drm_plane_type { |
948 | DRM_PLANE_TYPE_OVERLAY, | |
949 | DRM_PLANE_TYPE_PRIMARY, | |
950 | DRM_PLANE_TYPE_CURSOR, | |
951 | }; | |
952 | ||
88548636 | 953 | |
8cf5c917 | 954 | /** |
3bf0401c | 955 | * struct drm_plane - central DRM plane control structure |
8cf5c917 JB |
956 | * @dev: DRM device this plane belongs to |
957 | * @head: for list management | |
ac3ba4a5 | 958 | * @name: human readable name, can be overwritten by the driver |
8cf5c917 JB |
959 | * @base: base mode object |
960 | * @possible_crtcs: pipes this plane can be bound to | |
961 | * @format_types: array of formats supported by this plane | |
962 | * @format_count: number of formats supported | |
7eb5f302 | 963 | * @format_default: driver hasn't supplied supported formats for the plane |
8cf5c917 JB |
964 | * @crtc: currently bound CRTC |
965 | * @fb: currently bound fb | |
2c0c33d4 DV |
966 | * @old_fb: Temporary tracking of the old fb while a modeset is ongoing. Used by |
967 | * drm_mode_set_config_internal() to implement correct refcounting. | |
8cf5c917 | 968 | * @funcs: helper functions |
4d93914a | 969 | * @properties: property tracking for this plane |
e27dde3e | 970 | * @type: type of plane (overlay, primary, cursor) |
144ecb97 | 971 | * @state: current atomic state for this plane |
44d1240d | 972 | * @zpos_property: zpos property for this plane |
ac3ba4a5 | 973 | * @helper_private: mid-layer private data |
8cf5c917 JB |
974 | */ |
975 | struct drm_plane { | |
976 | struct drm_device *dev; | |
977 | struct list_head head; | |
978 | ||
9f4c97a2 VS |
979 | char *name; |
980 | ||
ac3ba4a5 DV |
981 | /** |
982 | * @mutex: | |
983 | * | |
984 | * Protects modeset plane state, together with the mutex of &drm_crtc | |
985 | * this plane is linked to (when active, getting actived or getting | |
986 | * disabled). | |
987 | */ | |
4d02e2de DV |
988 | struct drm_modeset_lock mutex; |
989 | ||
8cf5c917 JB |
990 | struct drm_mode_object base; |
991 | ||
992 | uint32_t possible_crtcs; | |
993 | uint32_t *format_types; | |
45e3743a | 994 | unsigned int format_count; |
7eb5f302 | 995 | bool format_default; |
8cf5c917 JB |
996 | |
997 | struct drm_crtc *crtc; | |
998 | struct drm_framebuffer *fb; | |
999 | ||
3d30a59b DV |
1000 | struct drm_framebuffer *old_fb; |
1001 | ||
8cf5c917 | 1002 | const struct drm_plane_funcs *funcs; |
4d93914a RC |
1003 | |
1004 | struct drm_object_properties properties; | |
e27dde3e MR |
1005 | |
1006 | enum drm_plane_type type; | |
144ecb97 | 1007 | |
96094081 DV |
1008 | /** |
1009 | * @index: Position inside the mode_config.list, can be used as an array | |
1010 | * index. It is invariant over the lifetime of the plane. | |
1011 | */ | |
490d3d1b CW |
1012 | unsigned index; |
1013 | ||
4490d4c7 | 1014 | const struct drm_plane_helper_funcs *helper_private; |
c2fcd274 | 1015 | |
144ecb97 | 1016 | struct drm_plane_state *state; |
44d1240d MS |
1017 | |
1018 | struct drm_property *zpos_property; | |
8cf5c917 JB |
1019 | }; |
1020 | ||
3b336ec4 | 1021 | /** |
3bf0401c | 1022 | * struct drm_bridge_funcs - drm_bridge control functions |
3b336ec4 SP |
1023 | */ |
1024 | struct drm_bridge_funcs { | |
cf3bef95 AM |
1025 | /** |
1026 | * @attach: | |
1027 | * | |
1028 | * This callback is invoked whenever our bridge is being attached to a | |
1029 | * &drm_encoder. | |
1030 | * | |
1031 | * The attach callback is optional. | |
1032 | * | |
1033 | * RETURNS: | |
1034 | * | |
1035 | * Zero on success, error code on failure. | |
1036 | */ | |
3d3f8b1f | 1037 | int (*attach)(struct drm_bridge *bridge); |
da024fe5 | 1038 | |
cf3bef95 AM |
1039 | /** |
1040 | * @detach: | |
1041 | * | |
1042 | * This callback is invoked whenever our bridge is being detached from a | |
1043 | * &drm_encoder. | |
1044 | * | |
1045 | * The detach callback is optional. | |
1046 | */ | |
1047 | void (*detach)(struct drm_bridge *bridge); | |
1048 | ||
da024fe5 DV |
1049 | /** |
1050 | * @mode_fixup: | |
1051 | * | |
1052 | * This callback is used to validate and adjust a mode. The paramater | |
1053 | * mode is the display mode that should be fed to the next element in | |
1054 | * the display chain, either the final &drm_connector or the next | |
1055 | * &drm_bridge. The parameter adjusted_mode is the input mode the bridge | |
1056 | * requires. It can be modified by this callback and does not need to | |
1057 | * match mode. | |
1058 | * | |
1059 | * This is the only hook that allows a bridge to reject a modeset. If | |
1060 | * this function passes all other callbacks must succeed for this | |
1061 | * configuration. | |
1062 | * | |
cf3bef95 AM |
1063 | * The mode_fixup callback is optional. |
1064 | * | |
da024fe5 DV |
1065 | * NOTE: |
1066 | * | |
1067 | * This function is called in the check phase of atomic modesets, which | |
1068 | * can be aborted for any reason (including on userspace's request to | |
1069 | * just check whether a configuration would be possible). Drivers MUST | |
1070 | * NOT touch any persistent state (hardware or software) or data | |
88548636 | 1071 | * structures except the passed in @state parameter. |
da024fe5 DV |
1072 | * |
1073 | * RETURNS: | |
1074 | * | |
1075 | * True if an acceptable configuration is possible, false if the modeset | |
1076 | * operation should be rejected. | |
1077 | */ | |
3b336ec4 SP |
1078 | bool (*mode_fixup)(struct drm_bridge *bridge, |
1079 | const struct drm_display_mode *mode, | |
1080 | struct drm_display_mode *adjusted_mode); | |
da024fe5 DV |
1081 | /** |
1082 | * @disable: | |
1083 | * | |
1084 | * This callback should disable the bridge. It is called right before | |
1085 | * the preceding element in the display pipe is disabled. If the | |
1086 | * preceding element is a bridge this means it's called before that | |
1087 | * bridge's ->disable() function. If the preceding element is a | |
1088 | * &drm_encoder it's called right before the encoder's ->disable(), | |
1089 | * ->prepare() or ->dpms() hook from struct &drm_encoder_helper_funcs. | |
1090 | * | |
1091 | * The bridge can assume that the display pipe (i.e. clocks and timing | |
1092 | * signals) feeding it is still running when this callback is called. | |
c8a3b2ae LP |
1093 | * |
1094 | * The disable callback is optional. | |
da024fe5 | 1095 | */ |
3b336ec4 | 1096 | void (*disable)(struct drm_bridge *bridge); |
da024fe5 DV |
1097 | |
1098 | /** | |
1099 | * @post_disable: | |
1100 | * | |
1101 | * This callback should disable the bridge. It is called right after | |
1102 | * the preceding element in the display pipe is disabled. If the | |
1103 | * preceding element is a bridge this means it's called after that | |
1104 | * bridge's ->post_disable() function. If the preceding element is a | |
1105 | * &drm_encoder it's called right after the encoder's ->disable(), | |
1106 | * ->prepare() or ->dpms() hook from struct &drm_encoder_helper_funcs. | |
1107 | * | |
1108 | * The bridge must assume that the display pipe (i.e. clocks and timing | |
1109 | * singals) feeding it is no longer running when this callback is | |
1110 | * called. | |
c8a3b2ae LP |
1111 | * |
1112 | * The post_disable callback is optional. | |
da024fe5 | 1113 | */ |
3b336ec4 | 1114 | void (*post_disable)(struct drm_bridge *bridge); |
da024fe5 DV |
1115 | |
1116 | /** | |
1117 | * @mode_set: | |
1118 | * | |
1119 | * This callback should set the given mode on the bridge. It is called | |
1120 | * after the ->mode_set() callback for the preceding element in the | |
1121 | * display pipeline has been called already. The display pipe (i.e. | |
1122 | * clocks and timing signals) is off when this function is called. | |
1123 | */ | |
3b336ec4 SP |
1124 | void (*mode_set)(struct drm_bridge *bridge, |
1125 | struct drm_display_mode *mode, | |
1126 | struct drm_display_mode *adjusted_mode); | |
da024fe5 DV |
1127 | /** |
1128 | * @pre_enable: | |
1129 | * | |
1130 | * This callback should enable the bridge. It is called right before | |
1131 | * the preceding element in the display pipe is enabled. If the | |
1132 | * preceding element is a bridge this means it's called before that | |
1133 | * bridge's ->pre_enable() function. If the preceding element is a | |
1134 | * &drm_encoder it's called right before the encoder's ->enable(), | |
1135 | * ->commit() or ->dpms() hook from struct &drm_encoder_helper_funcs. | |
1136 | * | |
1137 | * The display pipe (i.e. clocks and timing signals) feeding this bridge | |
1138 | * will not yet be running when this callback is called. The bridge must | |
1139 | * not enable the display link feeding the next bridge in the chain (if | |
1140 | * there is one) when this callback is called. | |
c8a3b2ae LP |
1141 | * |
1142 | * The pre_enable callback is optional. | |
da024fe5 | 1143 | */ |
3b336ec4 | 1144 | void (*pre_enable)(struct drm_bridge *bridge); |
da024fe5 DV |
1145 | |
1146 | /** | |
1147 | * @enable: | |
1148 | * | |
1149 | * This callback should enable the bridge. It is called right after | |
1150 | * the preceding element in the display pipe is enabled. If the | |
1151 | * preceding element is a bridge this means it's called after that | |
1152 | * bridge's ->enable() function. If the preceding element is a | |
1153 | * &drm_encoder it's called right after the encoder's ->enable(), | |
1154 | * ->commit() or ->dpms() hook from struct &drm_encoder_helper_funcs. | |
1155 | * | |
1156 | * The bridge can assume that the display pipe (i.e. clocks and timing | |
1157 | * signals) feeding it is running when this callback is called. This | |
1158 | * callback must enable the display link feeding the next bridge in the | |
1159 | * chain if there is one. | |
c8a3b2ae LP |
1160 | * |
1161 | * The enable callback is optional. | |
da024fe5 | 1162 | */ |
3b336ec4 | 1163 | void (*enable)(struct drm_bridge *bridge); |
3b336ec4 SP |
1164 | }; |
1165 | ||
1166 | /** | |
3bf0401c | 1167 | * struct drm_bridge - central DRM bridge control structure |
3b336ec4 | 1168 | * @dev: DRM device this bridge belongs to |
862e686c AT |
1169 | * @encoder: encoder to which this bridge is connected |
1170 | * @next: the next bridge in the encoder chain | |
3d3f8b1f AK |
1171 | * @of_node: device node pointer to the bridge |
1172 | * @list: to keep track of all added bridges | |
3b336ec4 SP |
1173 | * @funcs: control functions |
1174 | * @driver_private: pointer to the bridge driver's internal context | |
1175 | */ | |
1176 | struct drm_bridge { | |
1177 | struct drm_device *dev; | |
3d3f8b1f | 1178 | struct drm_encoder *encoder; |
862e686c | 1179 | struct drm_bridge *next; |
3d3f8b1f AK |
1180 | #ifdef CONFIG_OF |
1181 | struct device_node *of_node; | |
1182 | #endif | |
1183 | struct list_head list; | |
3b336ec4 SP |
1184 | |
1185 | const struct drm_bridge_funcs *funcs; | |
1186 | void *driver_private; | |
1187 | }; | |
1188 | ||
3b24f7d6 DV |
1189 | /** |
1190 | * struct drm_crtc_commit - track modeset commits on a CRTC | |
1191 | * | |
1192 | * This structure is used to track pending modeset changes and atomic commit on | |
1193 | * a per-CRTC basis. Since updating the list should never block this structure | |
1194 | * is reference counted to allow waiters to safely wait on an event to complete, | |
1195 | * without holding any locks. | |
1196 | * | |
1197 | * It has 3 different events in total to allow a fine-grained synchronization | |
1198 | * between outstanding updates:: | |
1199 | * | |
1200 | * atomic commit thread hardware | |
1201 | * | |
1202 | * write new state into hardware ----> ... | |
1203 | * signal hw_done | |
1204 | * switch to new state on next | |
1205 | * ... v/hblank | |
1206 | * | |
1207 | * wait for buffers to show up ... | |
1208 | * | |
1209 | * ... send completion irq | |
1210 | * irq handler signals flip_done | |
1211 | * cleanup old buffers | |
1212 | * | |
1213 | * signal cleanup_done | |
1214 | * | |
1215 | * wait for flip_done <---- | |
1216 | * clean up atomic state | |
1217 | * | |
1218 | * The important bit to know is that cleanup_done is the terminal event, but the | |
1219 | * ordering between flip_done and hw_done is entirely up to the specific driver | |
1220 | * and modeset state change. | |
1221 | * | |
1222 | * For an implementation of how to use this look at | |
1223 | * drm_atomic_helper_setup_commit() from the atomic helper library. | |
1224 | */ | |
1225 | struct drm_crtc_commit { | |
1226 | /** | |
1227 | * @crtc: | |
1228 | * | |
1229 | * DRM CRTC for this commit. | |
1230 | */ | |
1231 | struct drm_crtc *crtc; | |
1232 | ||
1233 | /** | |
1234 | * @ref: | |
1235 | * | |
1236 | * Reference count for this structure. Needed to allow blocking on | |
1237 | * completions without the risk of the completion disappearing | |
1238 | * meanwhile. | |
1239 | */ | |
1240 | struct kref ref; | |
1241 | ||
1242 | /** | |
1243 | * @flip_done: | |
1244 | * | |
1245 | * Will be signaled when the hardware has flipped to the new set of | |
1246 | * buffers. Signals at the same time as when the drm event for this | |
1247 | * commit is sent to userspace, or when an out-fence is singalled. Note | |
1248 | * that for most hardware, in most cases this happens after @hw_done is | |
1249 | * signalled. | |
1250 | */ | |
1251 | struct completion flip_done; | |
1252 | ||
1253 | /** | |
1254 | * @hw_done: | |
1255 | * | |
1256 | * Will be signalled when all hw register changes for this commit have | |
1257 | * been written out. Especially when disabling a pipe this can be much | |
1258 | * later than than @flip_done, since that can signal already when the | |
1259 | * screen goes black, whereas to fully shut down a pipe more register | |
1260 | * I/O is required. | |
1261 | * | |
1262 | * Note that this does not need to include separately reference-counted | |
1263 | * resources like backing storage buffer pinning, or runtime pm | |
1264 | * management. | |
1265 | */ | |
1266 | struct completion hw_done; | |
1267 | ||
1268 | /** | |
1269 | * @cleanup_done: | |
1270 | * | |
1271 | * Will be signalled after old buffers have been cleaned up by calling | |
1272 | * drm_atomic_helper_cleanup_planes(). Since this can only happen after | |
1273 | * a vblank wait completed it might be a bit later. This completion is | |
1274 | * useful to throttle updates and avoid hardware updates getting ahead | |
1275 | * of the buffer cleanup too much. | |
1276 | */ | |
1277 | struct completion cleanup_done; | |
1278 | ||
1279 | /** | |
1280 | * @commit_entry: | |
1281 | * | |
1282 | * Entry on the per-CRTC commit_list. Protected by crtc->commit_lock. | |
1283 | */ | |
1284 | struct list_head commit_entry; | |
1285 | ||
1286 | /** | |
1287 | * @event: | |
1288 | * | |
1289 | * &drm_pending_vblank_event pointer to clean up private events. | |
1290 | */ | |
1291 | struct drm_pending_vblank_event *event; | |
1292 | }; | |
1293 | ||
b8b5342b DV |
1294 | struct __drm_planes_state { |
1295 | struct drm_plane *ptr; | |
1296 | struct drm_plane_state *state; | |
1297 | }; | |
1298 | ||
5d943aa6 DV |
1299 | struct __drm_crtcs_state { |
1300 | struct drm_crtc *ptr; | |
1301 | struct drm_crtc_state *state; | |
3b24f7d6 | 1302 | struct drm_crtc_commit *commit; |
5d943aa6 DV |
1303 | }; |
1304 | ||
63e83c1d DV |
1305 | struct __drm_connnectors_state { |
1306 | struct drm_connector *ptr; | |
1307 | struct drm_connector_state *state; | |
1308 | }; | |
1309 | ||
cc4ceb48 | 1310 | /** |
08855fae | 1311 | * struct drm_atomic_state - the global state object for atomic updates |
cc4ceb48 | 1312 | * @dev: parent DRM device |
d34f20d6 | 1313 | * @allow_modeset: allow full modeset |
c6b0ca3e | 1314 | * @legacy_cursor_update: hint to enforce legacy cursor IOCTL semantics |
40616a26 | 1315 | * @legacy_set_config: Disable conflicting encoders instead of failing with -EINVAL. |
b8b5342b | 1316 | * @planes: pointer to array of structures with per-plane data |
cc4ceb48 | 1317 | * @crtcs: pointer to array of CRTC pointers |
f52b69f1 | 1318 | * @num_connector: size of the @connectors and @connector_states arrays |
63e83c1d | 1319 | * @connectors: pointer to array of structures with per-connector data |
cc4ceb48 DV |
1320 | * @acquire_ctx: acquire context for this atomic modeset state update |
1321 | */ | |
1322 | struct drm_atomic_state { | |
1323 | struct drm_device *dev; | |
d34f20d6 | 1324 | bool allow_modeset : 1; |
f02ad907 | 1325 | bool legacy_cursor_update : 1; |
40616a26 | 1326 | bool legacy_set_config : 1; |
b8b5342b | 1327 | struct __drm_planes_state *planes; |
5d943aa6 | 1328 | struct __drm_crtcs_state *crtcs; |
f52b69f1 | 1329 | int num_connector; |
63e83c1d | 1330 | struct __drm_connnectors_state *connectors; |
cc4ceb48 DV |
1331 | |
1332 | struct drm_modeset_acquire_ctx *acquire_ctx; | |
3b24f7d6 DV |
1333 | |
1334 | /** | |
1335 | * @commit_work: | |
1336 | * | |
1337 | * Work item which can be used by the driver or helpers to execute the | |
1338 | * commit without blocking. | |
1339 | */ | |
1340 | struct work_struct commit_work; | |
cc4ceb48 DV |
1341 | }; |
1342 | ||
1343 | ||
f453ba04 | 1344 | /** |
3bf0401c | 1345 | * struct drm_mode_set - new values for a CRTC config change |
ef27351a JB |
1346 | * @fb: framebuffer to use for new config |
1347 | * @crtc: CRTC whose configuration we're about to change | |
1348 | * @mode: mode timings to use | |
1349 | * @x: position of this CRTC relative to @fb | |
1350 | * @y: position of this CRTC relative to @fb | |
1351 | * @connectors: array of connectors to drive with this CRTC if possible | |
1352 | * @num_connectors: size of @connectors array | |
f453ba04 DA |
1353 | * |
1354 | * Represents a single crtc the connectors that it drives with what mode | |
1355 | * and from which framebuffer it scans out from. | |
1356 | * | |
1357 | * This is used to set modes. | |
1358 | */ | |
1359 | struct drm_mode_set { | |
f453ba04 DA |
1360 | struct drm_framebuffer *fb; |
1361 | struct drm_crtc *crtc; | |
1362 | struct drm_display_mode *mode; | |
1363 | ||
1364 | uint32_t x; | |
1365 | uint32_t y; | |
1366 | ||
1367 | struct drm_connector **connectors; | |
1368 | size_t num_connectors; | |
1369 | }; | |
1370 | ||
1371 | /** | |
550cebcd | 1372 | * struct drm_mode_config_funcs - basic driver provided mode setting functions |
550cebcd JB |
1373 | * |
1374 | * Some global (i.e. not per-CRTC, connector, etc) mode setting functions that | |
1375 | * involve drivers. | |
f453ba04 DA |
1376 | */ |
1377 | struct drm_mode_config_funcs { | |
9953f417 DV |
1378 | /** |
1379 | * @fb_create: | |
1380 | * | |
1381 | * Create a new framebuffer object. The core does basic checks on the | |
1382 | * requested metadata, but most of that is left to the driver. See | |
1383 | * struct &drm_mode_fb_cmd2 for details. | |
1384 | * | |
d55f5320 DV |
1385 | * If the parameters are deemed valid and the backing storage objects in |
1386 | * the underlying memory manager all exist, then the driver allocates | |
1387 | * a new &drm_framebuffer structure, subclassed to contain | |
1388 | * driver-specific information (like the internal native buffer object | |
1389 | * references). It also needs to fill out all relevant metadata, which | |
1390 | * should be done by calling drm_helper_mode_fill_fb_struct(). | |
1391 | * | |
1392 | * The initialization is finalized by calling drm_framebuffer_init(), | |
1393 | * which registers the framebuffer and makes it accessible to other | |
1394 | * threads. | |
1395 | * | |
9953f417 DV |
1396 | * RETURNS: |
1397 | * | |
1398 | * A new framebuffer with an initial reference count of 1 or a negative | |
1399 | * error code encoded with ERR_PTR(). | |
1400 | */ | |
550cebcd JB |
1401 | struct drm_framebuffer *(*fb_create)(struct drm_device *dev, |
1402 | struct drm_file *file_priv, | |
1eb83451 | 1403 | const struct drm_mode_fb_cmd2 *mode_cmd); |
9953f417 DV |
1404 | |
1405 | /** | |
1406 | * @output_poll_changed: | |
1407 | * | |
1408 | * Callback used by helpers to inform the driver of output configuration | |
1409 | * changes. | |
1410 | * | |
1411 | * Drivers implementing fbdev emulation with the helpers can call | |
1412 | * drm_fb_helper_hotplug_changed from this hook to inform the fbdev | |
1413 | * helper of output changes. | |
1414 | * | |
1415 | * FIXME: | |
1416 | * | |
1417 | * Except that there's no vtable for device-level helper callbacks | |
1418 | * there's no reason this is a core function. | |
1419 | */ | |
eb1f8e4f | 1420 | void (*output_poll_changed)(struct drm_device *dev); |
cc4ceb48 | 1421 | |
9953f417 DV |
1422 | /** |
1423 | * @atomic_check: | |
1424 | * | |
1425 | * This is the only hook to validate an atomic modeset update. This | |
1426 | * function must reject any modeset and state changes which the hardware | |
1427 | * or driver doesn't support. This includes but is of course not limited | |
1428 | * to: | |
1429 | * | |
1430 | * - Checking that the modes, framebuffers, scaling and placement | |
1431 | * requirements and so on are within the limits of the hardware. | |
1432 | * | |
1433 | * - Checking that any hidden shared resources are not oversubscribed. | |
1434 | * This can be shared PLLs, shared lanes, overall memory bandwidth, | |
1435 | * display fifo space (where shared between planes or maybe even | |
1436 | * CRTCs). | |
1437 | * | |
1438 | * - Checking that virtualized resources exported to userspace are not | |
1439 | * oversubscribed. For various reasons it can make sense to expose | |
1440 | * more planes, crtcs or encoders than which are physically there. One | |
1441 | * example is dual-pipe operations (which generally should be hidden | |
1442 | * from userspace if when lockstepped in hardware, exposed otherwise), | |
1443 | * where a plane might need 1 hardware plane (if it's just on one | |
1444 | * pipe), 2 hardware planes (when it spans both pipes) or maybe even | |
1445 | * shared a hardware plane with a 2nd plane (if there's a compatible | |
1446 | * plane requested on the area handled by the other pipe). | |
1447 | * | |
1448 | * - Check that any transitional state is possible and that if | |
1449 | * requested, the update can indeed be done in the vblank period | |
1450 | * without temporarily disabling some functions. | |
1451 | * | |
1452 | * - Check any other constraints the driver or hardware might have. | |
1453 | * | |
1454 | * - This callback also needs to correctly fill out the &drm_crtc_state | |
1455 | * in this update to make sure that drm_atomic_crtc_needs_modeset() | |
1456 | * reflects the nature of the possible update and returns true if and | |
1457 | * only if the update cannot be applied without tearing within one | |
1458 | * vblank on that CRTC. The core uses that information to reject | |
1459 | * updates which require a full modeset (i.e. blanking the screen, or | |
1460 | * at least pausing updates for a substantial amount of time) if | |
1461 | * userspace has disallowed that in its request. | |
1462 | * | |
1463 | * - The driver also does not need to repeat basic input validation | |
1464 | * like done for the corresponding legacy entry points. The core does | |
1465 | * that before calling this hook. | |
1466 | * | |
1467 | * See the documentation of @atomic_commit for an exhaustive list of | |
1468 | * error conditions which don't have to be checked at the | |
1469 | * ->atomic_check() stage? | |
1470 | * | |
1471 | * See the documentation for struct &drm_atomic_state for how exactly | |
1472 | * an atomic modeset update is described. | |
1473 | * | |
1474 | * Drivers using the atomic helpers can implement this hook using | |
1475 | * drm_atomic_helper_check(), or one of the exported sub-functions of | |
1476 | * it. | |
1477 | * | |
1478 | * RETURNS: | |
1479 | * | |
1480 | * 0 on success or one of the below negative error codes: | |
1481 | * | |
1482 | * - -EINVAL, if any of the above constraints are violated. | |
1483 | * | |
1484 | * - -EDEADLK, when returned from an attempt to acquire an additional | |
1485 | * &drm_modeset_lock through drm_modeset_lock(). | |
1486 | * | |
1487 | * - -ENOMEM, if allocating additional state sub-structures failed due | |
1488 | * to lack of memory. | |
1489 | * | |
1490 | * - -EINTR, -EAGAIN or -ERESTARTSYS, if the IOCTL should be restarted. | |
1491 | * This can either be due to a pending signal, or because the driver | |
1492 | * needs to completely bail out to recover from an exceptional | |
1493 | * situation like a GPU hang. From a userspace point all errors are | |
1494 | * treated equally. | |
1495 | */ | |
cc4ceb48 | 1496 | int (*atomic_check)(struct drm_device *dev, |
9953f417 DV |
1497 | struct drm_atomic_state *state); |
1498 | ||
1499 | /** | |
1500 | * @atomic_commit: | |
1501 | * | |
1502 | * This is the only hook to commit an atomic modeset update. The core | |
1503 | * guarantees that @atomic_check has been called successfully before | |
1504 | * calling this function, and that nothing has been changed in the | |
1505 | * interim. | |
1506 | * | |
1507 | * See the documentation for struct &drm_atomic_state for how exactly | |
1508 | * an atomic modeset update is described. | |
1509 | * | |
1510 | * Drivers using the atomic helpers can implement this hook using | |
1511 | * drm_atomic_helper_commit(), or one of the exported sub-functions of | |
1512 | * it. | |
1513 | * | |
286dbb8d | 1514 | * Nonblocking commits (as indicated with the nonblock parameter) must |
9953f417 DV |
1515 | * do any preparatory work which might result in an unsuccessful commit |
1516 | * in the context of this callback. The only exceptions are hardware | |
1517 | * errors resulting in -EIO. But even in that case the driver must | |
1518 | * ensure that the display pipe is at least running, to avoid | |
1519 | * compositors crashing when pageflips don't work. Anything else, | |
1520 | * specifically committing the update to the hardware, should be done | |
1521 | * without blocking the caller. For updates which do not require a | |
1522 | * modeset this must be guaranteed. | |
1523 | * | |
1524 | * The driver must wait for any pending rendering to the new | |
1525 | * framebuffers to complete before executing the flip. It should also | |
1526 | * wait for any pending rendering from other drivers if the underlying | |
286dbb8d | 1527 | * buffer is a shared dma-buf. Nonblocking commits must not wait for |
9953f417 DV |
1528 | * rendering in the context of this callback. |
1529 | * | |
1530 | * An application can request to be notified when the atomic commit has | |
1531 | * completed. These events are per-CRTC and can be distinguished by the | |
1532 | * CRTC index supplied in &drm_event to userspace. | |
1533 | * | |
1534 | * The drm core will supply a struct &drm_event in the event | |
1535 | * member of each CRTC's &drm_crtc_state structure. This can be handled by the | |
1536 | * drm_crtc_send_vblank_event() function, which the driver should call on | |
1537 | * the provided event upon completion of the atomic commit. Note that if | |
1538 | * the driver supports vblank signalling and timestamping the vblank | |
1539 | * counters and timestamps must agree with the ones returned from page | |
1540 | * flip events. With the current vblank helper infrastructure this can | |
1541 | * be achieved by holding a vblank reference while the page flip is | |
1542 | * pending, acquired through drm_crtc_vblank_get() and released with | |
1543 | * drm_crtc_vblank_put(). Drivers are free to implement their own vblank | |
1544 | * counter and timestamp tracking though, e.g. if they have accurate | |
1545 | * timestamp registers in hardware. | |
1546 | * | |
1547 | * NOTE: | |
1548 | * | |
1549 | * Drivers are not allowed to shut down any display pipe successfully | |
1550 | * enabled through an atomic commit on their own. Doing so can result in | |
1551 | * compositors crashing if a page flip is suddenly rejected because the | |
1552 | * pipe is off. | |
1553 | * | |
1554 | * RETURNS: | |
1555 | * | |
1556 | * 0 on success or one of the below negative error codes: | |
1557 | * | |
286dbb8d | 1558 | * - -EBUSY, if a nonblocking updated is requested and there is |
9953f417 DV |
1559 | * an earlier updated pending. Drivers are allowed to support a queue |
1560 | * of outstanding updates, but currently no driver supports that. | |
1561 | * Note that drivers must wait for preceding updates to complete if a | |
1562 | * synchronous update is requested, they are not allowed to fail the | |
1563 | * commit in that case. | |
1564 | * | |
1565 | * - -ENOMEM, if the driver failed to allocate memory. Specifically | |
1566 | * this can happen when trying to pin framebuffers, which must only | |
1567 | * be done when committing the state. | |
1568 | * | |
1569 | * - -ENOSPC, as a refinement of the more generic -ENOMEM to indicate | |
1570 | * that the driver has run out of vram, iommu space or similar GPU | |
1571 | * address space needed for framebuffer. | |
1572 | * | |
1573 | * - -EIO, if the hardware completely died. | |
1574 | * | |
1575 | * - -EINTR, -EAGAIN or -ERESTARTSYS, if the IOCTL should be restarted. | |
1576 | * This can either be due to a pending signal, or because the driver | |
1577 | * needs to completely bail out to recover from an exceptional | |
1578 | * situation like a GPU hang. From a userspace point of view all errors are | |
1579 | * treated equally. | |
1580 | * | |
1581 | * This list is exhaustive. Specifically this hook is not allowed to | |
1582 | * return -EINVAL (any invalid requests should be caught in | |
1583 | * @atomic_check) or -EDEADLK (this function must not acquire | |
1584 | * additional modeset locks). | |
1585 | */ | |
cc4ceb48 | 1586 | int (*atomic_commit)(struct drm_device *dev, |
9953f417 | 1587 | struct drm_atomic_state *state, |
286dbb8d | 1588 | bool nonblock); |
9953f417 DV |
1589 | |
1590 | /** | |
1591 | * @atomic_state_alloc: | |
1592 | * | |
1593 | * This optional hook can be used by drivers that want to subclass struct | |
1594 | * &drm_atomic_state to be able to track their own driver-private global | |
1595 | * state easily. If this hook is implemented, drivers must also | |
1596 | * implement @atomic_state_clear and @atomic_state_free. | |
1597 | * | |
1598 | * RETURNS: | |
1599 | * | |
1600 | * A new &drm_atomic_state on success or NULL on failure. | |
1601 | */ | |
036ef573 | 1602 | struct drm_atomic_state *(*atomic_state_alloc)(struct drm_device *dev); |
9953f417 DV |
1603 | |
1604 | /** | |
1605 | * @atomic_state_clear: | |
1606 | * | |
1607 | * This hook must clear any driver private state duplicated into the | |
1608 | * passed-in &drm_atomic_state. This hook is called when the caller | |
1609 | * encountered a &drm_modeset_lock deadlock and needs to drop all | |
1610 | * already acquired locks as part of the deadlock avoidance dance | |
1611 | * implemented in drm_modeset_lock_backoff(). | |
1612 | * | |
1613 | * Any duplicated state must be invalidated since a concurrent atomic | |
1614 | * update might change it, and the drm atomic interfaces always apply | |
1615 | * updates as relative changes to the current state. | |
1616 | * | |
1617 | * Drivers that implement this must call drm_atomic_state_default_clear() | |
1618 | * to clear common state. | |
1619 | */ | |
036ef573 | 1620 | void (*atomic_state_clear)(struct drm_atomic_state *state); |
9953f417 DV |
1621 | |
1622 | /** | |
1623 | * @atomic_state_free: | |
1624 | * | |
1625 | * This hook needs driver private resources and the &drm_atomic_state | |
1626 | * itself. Note that the core first calls drm_atomic_state_clear() to | |
1627 | * avoid code duplicate between the clear and free hooks. | |
1628 | * | |
1629 | * Drivers that implement this must call drm_atomic_state_default_free() | |
1630 | * to release common resources. | |
1631 | */ | |
036ef573 | 1632 | void (*atomic_state_free)(struct drm_atomic_state *state); |
f453ba04 DA |
1633 | }; |
1634 | ||
f453ba04 | 1635 | /** |
2c0c33d4 | 1636 | * struct drm_mode_config - Mode configuration control structure |
a62c93d5 | 1637 | * @mutex: mutex protecting KMS related lists and structures |
2c0c33d4 DV |
1638 | * @connection_mutex: ww mutex protecting connector state and routing |
1639 | * @acquire_ctx: global implicit acquire context used by atomic drivers for | |
c6b0ca3e | 1640 | * legacy IOCTLs |
2c0c33d4 | 1641 | * @fb_lock: mutex to protect fb state and lists |
a62c93d5 JB |
1642 | * @num_fb: number of fbs available |
1643 | * @fb_list: list of framebuffers available | |
a62c93d5 JB |
1644 | * @num_encoder: number of encoders on this device |
1645 | * @encoder_list: list of encoder objects | |
2c0c33d4 DV |
1646 | * @num_overlay_plane: number of overlay planes on this device |
1647 | * @num_total_plane: number of universal (i.e. with primary/curso) planes on this device | |
1648 | * @plane_list: list of plane objects | |
a62c93d5 JB |
1649 | * @num_crtc: number of CRTCs on this device |
1650 | * @crtc_list: list of CRTC objects | |
2c0c33d4 | 1651 | * @property_list: list of property objects |
a62c93d5 JB |
1652 | * @min_width: minimum pixel width on this device |
1653 | * @min_height: minimum pixel height on this device | |
1654 | * @max_width: maximum pixel width on this device | |
1655 | * @max_height: maximum pixel height on this device | |
1656 | * @funcs: core driver provided mode setting functions | |
1657 | * @fb_base: base address of the framebuffer | |
2c0c33d4 DV |
1658 | * @poll_enabled: track polling support for this device |
1659 | * @poll_running: track polling status for this device | |
ac3ba4a5 | 1660 | * @delayed_event: track delayed poll uevent deliver for this device |
a62c93d5 | 1661 | * @output_poll_work: delayed work for polling in process context |
2c0c33d4 | 1662 | * @property_blob_list: list of all the blob property objects |
8fb6e7a5 | 1663 | * @blob_lock: mutex for blob property allocation and management |
a62c93d5 | 1664 | * @*_property: core property tracking |
2c0c33d4 DV |
1665 | * @preferred_depth: preferred RBG pixel depth, used by fb helpers |
1666 | * @prefer_shadow: hint to userspace to prefer shadow-fb rendering | |
2c0c33d4 DV |
1667 | * @cursor_width: hint to userspace for max cursor width |
1668 | * @cursor_height: hint to userspace for max cursor height | |
9f2a7950 | 1669 | * @helper_private: mid-layer private data |
f453ba04 | 1670 | * |
a62c93d5 JB |
1671 | * Core mode resource tracking structure. All CRTC, encoders, and connectors |
1672 | * enumerated by the driver are added here, as are global properties. Some | |
1673 | * global restrictions are also here, e.g. dimension restrictions. | |
f453ba04 DA |
1674 | */ |
1675 | struct drm_mode_config { | |
ad2563c2 | 1676 | struct mutex mutex; /* protects configuration (mode lists etc.) */ |
51fd371b RC |
1677 | struct drm_modeset_lock connection_mutex; /* protects connector->encoder and encoder->crtc links */ |
1678 | struct drm_modeset_acquire_ctx *acquire_ctx; /* for legacy _lock_all() / _unlock_all() */ | |
ac3ba4a5 DV |
1679 | |
1680 | /** | |
1681 | * @idr_mutex: | |
1682 | * | |
1683 | * Mutex for KMS ID allocation and management. Protects both @crtc_idr | |
1684 | * and @tile_idr. | |
1685 | */ | |
1686 | struct mutex idr_mutex; | |
1687 | ||
1688 | /** | |
1689 | * @crtc_idr: | |
1690 | * | |
1691 | * Main KMS ID tracking object. Use this idr for all IDs, fb, crtc, | |
1692 | * connector, modes - just makes life easier to have only one. | |
1693 | */ | |
1694 | struct idr crtc_idr; | |
1695 | ||
1696 | /** | |
1697 | * @tile_idr: | |
1698 | * | |
1699 | * Use this idr for allocating new IDs for tiled sinks like use in some | |
1700 | * high-res DP MST screens. | |
1701 | */ | |
1702 | struct idr tile_idr; | |
4b096ac1 | 1703 | |
2c0c33d4 | 1704 | struct mutex fb_lock; /* proctects global and per-file fb lists */ |
f453ba04 DA |
1705 | int num_fb; |
1706 | struct list_head fb_list; | |
4b096ac1 | 1707 | |
96094081 DV |
1708 | /** |
1709 | * @num_connector: Number of connectors on this device. | |
1710 | */ | |
f453ba04 | 1711 | int num_connector; |
96094081 DV |
1712 | /** |
1713 | * @connector_ida: ID allocator for connector indices. | |
1714 | */ | |
5fff80bb | 1715 | struct ida connector_ida; |
96094081 DV |
1716 | /** |
1717 | * @connector_list: List of connector objects. | |
1718 | */ | |
f453ba04 DA |
1719 | struct list_head connector_list; |
1720 | int num_encoder; | |
1721 | struct list_head encoder_list; | |
e27dde3e MR |
1722 | |
1723 | /* | |
1724 | * Track # of overlay planes separately from # of total planes. By | |
1725 | * default we only advertise overlay planes to userspace; if userspace | |
1726 | * sets the "universal plane" capability bit, we'll go ahead and | |
1727 | * expose all planes. | |
1728 | */ | |
1729 | int num_overlay_plane; | |
1730 | int num_total_plane; | |
8cf5c917 | 1731 | struct list_head plane_list; |
f453ba04 DA |
1732 | |
1733 | int num_crtc; | |
1734 | struct list_head crtc_list; | |
1735 | ||
1736 | struct list_head property_list; | |
1737 | ||
f453ba04 DA |
1738 | int min_width, min_height; |
1739 | int max_width, max_height; | |
e6ecefaa | 1740 | const struct drm_mode_config_funcs *funcs; |
d883f7f1 | 1741 | resource_size_t fb_base; |
f453ba04 | 1742 | |
eb1f8e4f DA |
1743 | /* output poll support */ |
1744 | bool poll_enabled; | |
905bc9ff | 1745 | bool poll_running; |
162b6a57 | 1746 | bool delayed_event; |
991ea75c | 1747 | struct delayed_work output_poll_work; |
eb1f8e4f | 1748 | |
8fb6e7a5 DS |
1749 | struct mutex blob_lock; |
1750 | ||
f453ba04 DA |
1751 | /* pointers to standard properties */ |
1752 | struct list_head property_blob_list; | |
9a6bc03c DV |
1753 | /** |
1754 | * @edid_property: Default connector property to hold the EDID of the | |
1755 | * currently connected sink, if any. | |
1756 | */ | |
f453ba04 | 1757 | struct drm_property *edid_property; |
9a6bc03c DV |
1758 | /** |
1759 | * @dpms_property: Default connector property to control the | |
1760 | * connector's DPMS state. | |
1761 | */ | |
f453ba04 | 1762 | struct drm_property *dpms_property; |
9a6bc03c DV |
1763 | /** |
1764 | * @path_property: Default connector property to hold the DP MST path | |
1765 | * for the port. | |
1766 | */ | |
43aba7eb | 1767 | struct drm_property *path_property; |
9a6bc03c DV |
1768 | /** |
1769 | * @tile_property: Default connector property to store the tile | |
1770 | * position of a tiled screen, for sinks which need to be driven with | |
1771 | * multiple CRTCs. | |
1772 | */ | |
6f134d7b | 1773 | struct drm_property *tile_property; |
9a6bc03c DV |
1774 | /** |
1775 | * @plane_type_property: Default plane property to differentiate | |
1776 | * CURSOR, PRIMARY and OVERLAY legacy uses of planes. | |
1777 | */ | |
9922ab5a | 1778 | struct drm_property *plane_type_property; |
9a6bc03c DV |
1779 | /** |
1780 | * @rotation_property: Optional property for planes or CRTCs to specifiy | |
1781 | * rotation. | |
1782 | */ | |
2a297cce | 1783 | struct drm_property *rotation_property; |
9a6bc03c DV |
1784 | /** |
1785 | * @prop_src_x: Default atomic plane property for the plane source | |
1786 | * position in the connected &drm_framebuffer. | |
1787 | */ | |
6b4959f4 | 1788 | struct drm_property *prop_src_x; |
9a6bc03c DV |
1789 | /** |
1790 | * @prop_src_y: Default atomic plane property for the plane source | |
1791 | * position in the connected &drm_framebuffer. | |
1792 | */ | |
6b4959f4 | 1793 | struct drm_property *prop_src_y; |
9a6bc03c DV |
1794 | /** |
1795 | * @prop_src_w: Default atomic plane property for the plane source | |
1796 | * position in the connected &drm_framebuffer. | |
1797 | */ | |
6b4959f4 | 1798 | struct drm_property *prop_src_w; |
9a6bc03c DV |
1799 | /** |
1800 | * @prop_src_h: Default atomic plane property for the plane source | |
1801 | * position in the connected &drm_framebuffer. | |
1802 | */ | |
6b4959f4 | 1803 | struct drm_property *prop_src_h; |
9a6bc03c DV |
1804 | /** |
1805 | * @prop_crtc_x: Default atomic plane property for the plane destination | |
1806 | * position in the &drm_crtc is is being shown on. | |
1807 | */ | |
6b4959f4 | 1808 | struct drm_property *prop_crtc_x; |
9a6bc03c DV |
1809 | /** |
1810 | * @prop_crtc_y: Default atomic plane property for the plane destination | |
1811 | * position in the &drm_crtc is is being shown on. | |
1812 | */ | |
6b4959f4 | 1813 | struct drm_property *prop_crtc_y; |
9a6bc03c DV |
1814 | /** |
1815 | * @prop_crtc_w: Default atomic plane property for the plane destination | |
1816 | * position in the &drm_crtc is is being shown on. | |
1817 | */ | |
6b4959f4 | 1818 | struct drm_property *prop_crtc_w; |
9a6bc03c DV |
1819 | /** |
1820 | * @prop_crtc_h: Default atomic plane property for the plane destination | |
1821 | * position in the &drm_crtc is is being shown on. | |
1822 | */ | |
6b4959f4 | 1823 | struct drm_property *prop_crtc_h; |
9a6bc03c DV |
1824 | /** |
1825 | * @prop_fb_id: Default atomic plane property to specify the | |
1826 | * &drm_framebuffer. | |
1827 | */ | |
6b4959f4 | 1828 | struct drm_property *prop_fb_id; |
9a6bc03c DV |
1829 | /** |
1830 | * @prop_crtc_id: Default atomic plane property to specify the | |
1831 | * &drm_crtc. | |
1832 | */ | |
6b4959f4 | 1833 | struct drm_property *prop_crtc_id; |
9a6bc03c DV |
1834 | /** |
1835 | * @prop_active: Default atomic CRTC property to control the active | |
1836 | * state, which is the simplified implementation for DPMS in atomic | |
1837 | * drivers. | |
1838 | */ | |
eab3bbef | 1839 | struct drm_property *prop_active; |
9a6bc03c DV |
1840 | /** |
1841 | * @prop_mode_id: Default atomic CRTC property to set the mode for a | |
1842 | * CRTC. A 0 mode implies that the CRTC is entirely disabled - all | |
1843 | * connectors must be of and active must be set to disabled, too. | |
1844 | */ | |
955f3c33 | 1845 | struct drm_property *prop_mode_id; |
f453ba04 | 1846 | |
9a6bc03c DV |
1847 | /** |
1848 | * @dvi_i_subconnector_property: Optional DVI-I property to | |
1849 | * differentiate between analog or digital mode. | |
1850 | */ | |
f453ba04 | 1851 | struct drm_property *dvi_i_subconnector_property; |
9a6bc03c DV |
1852 | /** |
1853 | * @dvi_i_select_subconnector_property: Optional DVI-I property to | |
1854 | * select between analog or digital mode. | |
1855 | */ | |
f453ba04 DA |
1856 | struct drm_property *dvi_i_select_subconnector_property; |
1857 | ||
9a6bc03c DV |
1858 | /** |
1859 | * @tv_subconnector_property: Optional TV property to differentiate | |
1860 | * between different TV connector types. | |
1861 | */ | |
f453ba04 | 1862 | struct drm_property *tv_subconnector_property; |
9a6bc03c DV |
1863 | /** |
1864 | * @tv_select_subconnector_property: Optional TV property to select | |
1865 | * between different TV connector types. | |
1866 | */ | |
f453ba04 | 1867 | struct drm_property *tv_select_subconnector_property; |
9a6bc03c DV |
1868 | /** |
1869 | * @tv_mode_property: Optional TV property to select | |
1870 | * the output TV mode. | |
1871 | */ | |
f453ba04 | 1872 | struct drm_property *tv_mode_property; |
9a6bc03c DV |
1873 | /** |
1874 | * @tv_left_margin_property: Optional TV property to set the left | |
1875 | * margin. | |
1876 | */ | |
f453ba04 | 1877 | struct drm_property *tv_left_margin_property; |
9a6bc03c DV |
1878 | /** |
1879 | * @tv_right_margin_property: Optional TV property to set the right | |
1880 | * margin. | |
1881 | */ | |
f453ba04 | 1882 | struct drm_property *tv_right_margin_property; |
9a6bc03c DV |
1883 | /** |
1884 | * @tv_top_margin_property: Optional TV property to set the right | |
1885 | * margin. | |
1886 | */ | |
f453ba04 | 1887 | struct drm_property *tv_top_margin_property; |
9a6bc03c DV |
1888 | /** |
1889 | * @tv_bottom_margin_property: Optional TV property to set the right | |
1890 | * margin. | |
1891 | */ | |
f453ba04 | 1892 | struct drm_property *tv_bottom_margin_property; |
9a6bc03c DV |
1893 | /** |
1894 | * @tv_brightness_property: Optional TV property to set the | |
1895 | * brightness. | |
1896 | */ | |
b6b7902e | 1897 | struct drm_property *tv_brightness_property; |
9a6bc03c DV |
1898 | /** |
1899 | * @tv_contrast_property: Optional TV property to set the | |
1900 | * contrast. | |
1901 | */ | |
b6b7902e | 1902 | struct drm_property *tv_contrast_property; |
9a6bc03c DV |
1903 | /** |
1904 | * @tv_flicker_reduction_property: Optional TV property to control the | |
1905 | * flicker reduction mode. | |
1906 | */ | |
b6b7902e | 1907 | struct drm_property *tv_flicker_reduction_property; |
9a6bc03c DV |
1908 | /** |
1909 | * @tv_overscan_property: Optional TV property to control the overscan | |
1910 | * setting. | |
1911 | */ | |
a75f0236 | 1912 | struct drm_property *tv_overscan_property; |
9a6bc03c DV |
1913 | /** |
1914 | * @tv_saturation_property: Optional TV property to set the | |
1915 | * saturation. | |
1916 | */ | |
a75f0236 | 1917 | struct drm_property *tv_saturation_property; |
9a6bc03c DV |
1918 | /** |
1919 | * @tv_hue_property: Optional TV property to set the hue. | |
1920 | */ | |
a75f0236 | 1921 | struct drm_property *tv_hue_property; |
f453ba04 | 1922 | |
9a6bc03c DV |
1923 | /** |
1924 | * @scaling_mode_property: Optional connector property to control the | |
1925 | * upscaling, mostly used for built-in panels. | |
1926 | */ | |
f453ba04 | 1927 | struct drm_property *scaling_mode_property; |
9a6bc03c DV |
1928 | /** |
1929 | * @aspect_ratio_property: Optional connector property to control the | |
1930 | * HDMI infoframe aspect ratio setting. | |
1931 | */ | |
ff587e45 | 1932 | struct drm_property *aspect_ratio_property; |
9a6bc03c DV |
1933 | /** |
1934 | * @degamma_lut_property: Optional CRTC property to set the LUT used to | |
1935 | * convert the framebuffer's colors to linear gamma. | |
1936 | */ | |
5488dc16 | 1937 | struct drm_property *degamma_lut_property; |
9a6bc03c DV |
1938 | /** |
1939 | * @degamma_lut_size_property: Optional CRTC property for the size of | |
1940 | * the degamma LUT as supported by the driver (read-only). | |
1941 | */ | |
5488dc16 | 1942 | struct drm_property *degamma_lut_size_property; |
9a6bc03c DV |
1943 | /** |
1944 | * @ctm_property: Optional CRTC property to set the | |
1945 | * matrix used to convert colors after the lookup in the | |
1946 | * degamma LUT. | |
1947 | */ | |
5488dc16 | 1948 | struct drm_property *ctm_property; |
9a6bc03c DV |
1949 | /** |
1950 | * @gamma_lut_property: Optional CRTC property to set the LUT used to | |
1951 | * convert the colors, after the CTM matrix, to the gamma space of the | |
1952 | * connected screen. | |
1953 | */ | |
5488dc16 | 1954 | struct drm_property *gamma_lut_property; |
9a6bc03c DV |
1955 | /** |
1956 | * @gamma_lut_size_property: Optional CRTC property for the size of the | |
1957 | * gamma LUT as supported by the driver (read-only). | |
1958 | */ | |
5488dc16 LL |
1959 | struct drm_property *gamma_lut_size_property; |
1960 | ||
9a6bc03c DV |
1961 | /** |
1962 | * @suggested_x_property: Optional connector property with a hint for | |
1963 | * the position of the output on the host's screen. | |
1964 | */ | |
5bb2bbf5 | 1965 | struct drm_property *suggested_x_property; |
9a6bc03c DV |
1966 | /** |
1967 | * @suggested_y_property: Optional connector property with a hint for | |
1968 | * the position of the output on the host's screen. | |
1969 | */ | |
5bb2bbf5 DA |
1970 | struct drm_property *suggested_y_property; |
1971 | ||
019d96cb DA |
1972 | /* dumb ioctl parameters */ |
1973 | uint32_t preferred_depth, prefer_shadow; | |
62f2104f | 1974 | |
9a6bc03c DV |
1975 | /** |
1976 | * @async_page_flip: Does this device support async flips on the primary | |
1977 | * plane? | |
1978 | */ | |
62f2104f | 1979 | bool async_page_flip; |
8716ed4e | 1980 | |
ac3ba4a5 DV |
1981 | /** |
1982 | * @allow_fb_modifiers: | |
1983 | * | |
1984 | * Whether the driver supports fb modifiers in the ADDFB2.1 ioctl call. | |
1985 | */ | |
e3eb3250 RC |
1986 | bool allow_fb_modifiers; |
1987 | ||
8716ed4e AD |
1988 | /* cursor size */ |
1989 | uint32_t cursor_width, cursor_height; | |
9f2a7950 DV |
1990 | |
1991 | struct drm_mode_config_helper_funcs *helper_private; | |
f453ba04 DA |
1992 | }; |
1993 | ||
dd275956 RC |
1994 | /** |
1995 | * drm_for_each_plane_mask - iterate over planes specified by bitmask | |
1996 | * @plane: the loop cursor | |
1997 | * @dev: the DRM device | |
1998 | * @plane_mask: bitmask of plane indices | |
1999 | * | |
2000 | * Iterate over all planes specified by bitmask. | |
2001 | */ | |
2002 | #define drm_for_each_plane_mask(plane, dev, plane_mask) \ | |
2003 | list_for_each_entry((plane), &(dev)->mode_config.plane_list, head) \ | |
373701b1 | 2004 | for_each_if ((plane_mask) & (1 << drm_plane_index(plane))) |
dd275956 | 2005 | |
ead8b665 ML |
2006 | /** |
2007 | * drm_for_each_encoder_mask - iterate over encoders specified by bitmask | |
2008 | * @encoder: the loop cursor | |
2009 | * @dev: the DRM device | |
2010 | * @encoder_mask: bitmask of encoder indices | |
2011 | * | |
2012 | * Iterate over all encoders specified by bitmask. | |
2013 | */ | |
2014 | #define drm_for_each_encoder_mask(encoder, dev, encoder_mask) \ | |
2015 | list_for_each_entry((encoder), &(dev)->mode_config.encoder_list, head) \ | |
2016 | for_each_if ((encoder_mask) & (1 << drm_encoder_index(encoder))) | |
dd275956 | 2017 | |
f453ba04 | 2018 | #define obj_to_crtc(x) container_of(x, struct drm_crtc, base) |
f453ba04 DA |
2019 | #define obj_to_mode(x) container_of(x, struct drm_display_mode, base) |
2020 | #define obj_to_fb(x) container_of(x, struct drm_framebuffer, base) | |
f453ba04 | 2021 | #define obj_to_blob(x) container_of(x, struct drm_property_blob, base) |
8cf5c917 | 2022 | #define obj_to_plane(x) container_of(x, struct drm_plane, base) |
f453ba04 | 2023 | |
f9882876 VS |
2024 | extern __printf(6, 7) |
2025 | int drm_crtc_init_with_planes(struct drm_device *dev, | |
2026 | struct drm_crtc *crtc, | |
2027 | struct drm_plane *primary, | |
2028 | struct drm_plane *cursor, | |
2029 | const struct drm_crtc_funcs *funcs, | |
2030 | const char *name, ...); | |
f453ba04 | 2031 | extern void drm_crtc_cleanup(struct drm_crtc *crtc); |
490d3d1b CW |
2032 | |
2033 | /** | |
2034 | * drm_crtc_index - find the index of a registered CRTC | |
2035 | * @crtc: CRTC to find index for | |
2036 | * | |
2037 | * Given a registered CRTC, return the index of that CRTC within a DRM | |
2038 | * device's list of CRTCs. | |
2039 | */ | |
2040 | static inline unsigned int drm_crtc_index(struct drm_crtc *crtc) | |
2041 | { | |
2042 | return crtc->index; | |
2043 | } | |
db5f7a6e RK |
2044 | |
2045 | /** | |
2046 | * drm_crtc_mask - find the mask of a registered CRTC | |
2047 | * @crtc: CRTC to find mask for | |
2048 | * | |
2049 | * Given a registered CRTC, return the mask bit of that CRTC for an | |
2050 | * encoder's possible_crtcs field. | |
2051 | */ | |
2052 | static inline uint32_t drm_crtc_mask(struct drm_crtc *crtc) | |
2053 | { | |
2054 | return 1 << drm_crtc_index(crtc); | |
2055 | } | |
f453ba04 | 2056 | |
b0b3b795 VS |
2057 | extern __printf(8, 9) |
2058 | int drm_universal_plane_init(struct drm_device *dev, | |
2059 | struct drm_plane *plane, | |
2060 | unsigned long possible_crtcs, | |
2061 | const struct drm_plane_funcs *funcs, | |
2062 | const uint32_t *formats, | |
2063 | unsigned int format_count, | |
2064 | enum drm_plane_type type, | |
2065 | const char *name, ...); | |
8cf5c917 JB |
2066 | extern int drm_plane_init(struct drm_device *dev, |
2067 | struct drm_plane *plane, | |
2068 | unsigned long possible_crtcs, | |
2069 | const struct drm_plane_funcs *funcs, | |
45e3743a | 2070 | const uint32_t *formats, unsigned int format_count, |
dc415ff9 | 2071 | bool is_primary); |
8cf5c917 | 2072 | extern void drm_plane_cleanup(struct drm_plane *plane); |
490d3d1b CW |
2073 | |
2074 | /** | |
2075 | * drm_plane_index - find the index of a registered plane | |
2076 | * @plane: plane to find index for | |
2077 | * | |
2078 | * Given a registered plane, return the index of that plane within a DRM | |
2079 | * device's list of planes. | |
2080 | */ | |
2081 | static inline unsigned int drm_plane_index(struct drm_plane *plane) | |
2082 | { | |
2083 | return plane->index; | |
2084 | } | |
f81338a5 | 2085 | extern struct drm_plane * drm_plane_from_index(struct drm_device *dev, int idx); |
9125e618 | 2086 | extern void drm_plane_force_disable(struct drm_plane *plane); |
ecb7e16b GP |
2087 | extern void drm_crtc_get_hv_timing(const struct drm_display_mode *mode, |
2088 | int *hdisplay, int *vdisplay); | |
6a0d9528 LW |
2089 | extern int drm_crtc_force_disable(struct drm_crtc *crtc); |
2090 | extern int drm_crtc_force_disable_all(struct drm_device *dev); | |
8cf5c917 | 2091 | |
f453ba04 | 2092 | extern void drm_mode_config_init(struct drm_device *dev); |
eb033556 | 2093 | extern void drm_mode_config_reset(struct drm_device *dev); |
f453ba04 | 2094 | extern void drm_mode_config_cleanup(struct drm_device *dev); |
55310008 | 2095 | |
4cae5b84 | 2096 | extern int drm_mode_crtc_set_gamma_size(struct drm_crtc *crtc, |
f453ba04 | 2097 | int gamma_size); |
98f75de4 | 2098 | |
2d13b679 | 2099 | extern int drm_mode_set_config_internal(struct drm_mode_set *set); |
81065548 | 2100 | |
138f9ebb DA |
2101 | extern struct drm_tile_group *drm_mode_create_tile_group(struct drm_device *dev, |
2102 | char topology[8]); | |
2103 | extern struct drm_tile_group *drm_mode_get_tile_group(struct drm_device *dev, | |
2104 | char topology[8]); | |
2105 | extern void drm_mode_put_tile_group(struct drm_device *dev, | |
2106 | struct drm_tile_group *tg); | |
ff72145b | 2107 | |
3a5f87c2 TW |
2108 | extern int drm_mode_plane_set_obj_prop(struct drm_plane *plane, |
2109 | struct drm_property *property, | |
2110 | uint64_t value); | |
248dbc23 | 2111 | |
c1df5f3c VS |
2112 | extern struct drm_property *drm_mode_create_rotation_property(struct drm_device *dev, |
2113 | unsigned int supported_rotations); | |
3c9855f6 VS |
2114 | extern unsigned int drm_rotation_simplify(unsigned int rotation, |
2115 | unsigned int supported_rotations); | |
f8ed34ac JS |
2116 | extern void drm_crtc_enable_color_mgmt(struct drm_crtc *crtc, |
2117 | uint degamma_lut_size, | |
2118 | bool has_ctm, | |
2119 | uint gamma_lut_size); | |
44d1240d MS |
2120 | |
2121 | int drm_plane_create_zpos_property(struct drm_plane *plane, | |
2122 | unsigned int zpos, | |
2123 | unsigned int min, unsigned int max); | |
2124 | ||
2125 | int drm_plane_create_zpos_immutable_property(struct drm_plane *plane, | |
2126 | unsigned int zpos); | |
2127 | ||
96f60e37 | 2128 | /* Helpers */ |
a2b34e22 RC |
2129 | static inline struct drm_plane *drm_plane_find(struct drm_device *dev, |
2130 | uint32_t id) | |
2131 | { | |
2132 | struct drm_mode_object *mo; | |
2133 | mo = drm_mode_object_find(dev, id, DRM_MODE_OBJECT_PLANE); | |
2134 | return mo ? obj_to_plane(mo) : NULL; | |
2135 | } | |
2136 | ||
96f60e37 RK |
2137 | static inline struct drm_crtc *drm_crtc_find(struct drm_device *dev, |
2138 | uint32_t id) | |
2139 | { | |
2140 | struct drm_mode_object *mo; | |
2141 | mo = drm_mode_object_find(dev, id, DRM_MODE_OBJECT_CRTC); | |
2142 | return mo ? obj_to_crtc(mo) : NULL; | |
2143 | } | |
2144 | ||
5488dc16 LL |
2145 | /* |
2146 | * Extract a degamma/gamma LUT value provided by user and round it to the | |
2147 | * precision supported by the hardware. | |
2148 | */ | |
2149 | static inline uint32_t drm_color_lut_extract(uint32_t user_input, | |
2150 | uint32_t bit_precision) | |
2151 | { | |
644a8050 | 2152 | uint32_t val = user_input; |
5488dc16 LL |
2153 | uint32_t max = 0xffff >> (16 - bit_precision); |
2154 | ||
644a8050 LL |
2155 | /* Round only if we're not using full precision. */ |
2156 | if (bit_precision < 16) { | |
2157 | val += 1UL << (16 - bit_precision - 1); | |
2158 | val >>= 16 - bit_precision; | |
2159 | } | |
5488dc16 LL |
2160 | |
2161 | return clamp_val(val, 0, max); | |
2162 | } | |
2163 | ||
e27dde3e | 2164 | /* Plane list iterator for legacy (overlay only) planes. */ |
4ea50e99 DV |
2165 | #define drm_for_each_legacy_plane(plane, dev) \ |
2166 | list_for_each_entry(plane, &(dev)->mode_config.plane_list, head) \ | |
373701b1 | 2167 | for_each_if (plane->type == DRM_PLANE_TYPE_OVERLAY) |
e27dde3e | 2168 | |
6295d607 DV |
2169 | #define drm_for_each_plane(plane, dev) \ |
2170 | list_for_each_entry(plane, &(dev)->mode_config.plane_list, head) | |
2171 | ||
2172 | #define drm_for_each_crtc(crtc, dev) \ | |
2173 | list_for_each_entry(crtc, &(dev)->mode_config.crtc_list, head) | |
2174 | ||
7a3f3d66 DV |
2175 | static inline void |
2176 | assert_drm_connector_list_read_locked(struct drm_mode_config *mode_config) | |
2177 | { | |
cff20ba2 DV |
2178 | /* |
2179 | * The connector hotadd/remove code currently grabs both locks when | |
2180 | * updating lists. Hence readers need only hold either of them to be | |
2181 | * safe and the check amounts to | |
2182 | * | |
2183 | * WARN_ON(not_holding(A) && not_holding(B)). | |
2184 | */ | |
2185 | WARN_ON(!mutex_is_locked(&mode_config->mutex) && | |
2186 | !drm_modeset_is_locked(&mode_config->connection_mutex)); | |
7a3f3d66 DV |
2187 | } |
2188 | ||
6295d607 | 2189 | #define drm_for_each_connector(connector, dev) \ |
7a3f3d66 DV |
2190 | for (assert_drm_connector_list_read_locked(&(dev)->mode_config), \ |
2191 | connector = list_first_entry(&(dev)->mode_config.connector_list, \ | |
2192 | struct drm_connector, head); \ | |
2193 | &connector->head != (&(dev)->mode_config.connector_list); \ | |
2194 | connector = list_next_entry(connector, head)) | |
6295d607 DV |
2195 | |
2196 | #define drm_for_each_encoder(encoder, dev) \ | |
2197 | list_for_each_entry(encoder, &(dev)->mode_config.encoder_list, head) | |
2198 | ||
2199 | #define drm_for_each_fb(fb, dev) \ | |
4676ba0b DV |
2200 | for (WARN_ON(!mutex_is_locked(&(dev)->mode_config.fb_lock)), \ |
2201 | fb = list_first_entry(&(dev)->mode_config.fb_list, \ | |
2202 | struct drm_framebuffer, head); \ | |
2203 | &fb->head != (&(dev)->mode_config.fb_list); \ | |
2204 | fb = list_next_entry(fb, head)) | |
6295d607 | 2205 | |
81065548 DV |
2206 | /* drm_edid.c */ |
2207 | bool drm_probe_ddc(struct i2c_adapter *adapter); | |
2208 | struct edid *drm_get_edid(struct drm_connector *connector, | |
2209 | struct i2c_adapter *adapter); | |
2210 | struct edid *drm_get_edid_switcheroo(struct drm_connector *connector, | |
2211 | struct i2c_adapter *adapter); | |
2212 | struct edid *drm_edid_duplicate(const struct edid *edid); | |
2213 | int drm_add_edid_modes(struct drm_connector *connector, struct edid *edid); | |
2214 | ||
2215 | u8 drm_match_cea_mode(const struct drm_display_mode *to_match); | |
2216 | enum hdmi_picture_aspect drm_get_cea_aspect_ratio(const u8 video_code); | |
2217 | bool drm_detect_hdmi_monitor(struct edid *edid); | |
2218 | bool drm_detect_monitor_audio(struct edid *edid); | |
2219 | bool drm_rgb_quant_range_selectable(struct edid *edid); | |
2220 | int drm_add_modes_noedid(struct drm_connector *connector, | |
2221 | int hdisplay, int vdisplay); | |
2222 | void drm_set_preferred_mode(struct drm_connector *connector, | |
2223 | int hpref, int vpref); | |
2224 | ||
2225 | int drm_edid_header_is_valid(const u8 *raw_edid); | |
2226 | bool drm_edid_block_valid(u8 *raw_edid, int block, bool print_bad_edid, | |
2227 | bool *edid_corrupt); | |
2228 | bool drm_edid_is_valid(struct edid *edid); | |
2229 | void drm_edid_get_monitor_name(struct edid *edid, char *name, | |
2230 | int buflen); | |
2231 | struct drm_display_mode *drm_mode_find_dmt(struct drm_device *dev, | |
2232 | int hsize, int vsize, int fresh, | |
2233 | bool rb); | |
2234 | ||
2235 | /* drm_bridge.c */ | |
2236 | extern int drm_bridge_add(struct drm_bridge *bridge); | |
2237 | extern void drm_bridge_remove(struct drm_bridge *bridge); | |
2238 | extern struct drm_bridge *of_drm_find_bridge(struct device_node *np); | |
2239 | extern int drm_bridge_attach(struct drm_device *dev, struct drm_bridge *bridge); | |
cf3bef95 | 2240 | extern void drm_bridge_detach(struct drm_bridge *bridge); |
81065548 DV |
2241 | |
2242 | bool drm_bridge_mode_fixup(struct drm_bridge *bridge, | |
2243 | const struct drm_display_mode *mode, | |
2244 | struct drm_display_mode *adjusted_mode); | |
2245 | void drm_bridge_disable(struct drm_bridge *bridge); | |
2246 | void drm_bridge_post_disable(struct drm_bridge *bridge); | |
2247 | void drm_bridge_mode_set(struct drm_bridge *bridge, | |
2248 | struct drm_display_mode *mode, | |
2249 | struct drm_display_mode *adjusted_mode); | |
2250 | void drm_bridge_pre_enable(struct drm_bridge *bridge); | |
2251 | void drm_bridge_enable(struct drm_bridge *bridge); | |
2252 | ||
f453ba04 | 2253 | #endif /* __DRM_CRTC_H__ */ |