]>
Commit | Line | Data |
---|---|---|
43968d7b DV |
1 | /* |
2 | * Copyright (c) 2016 Intel Corporation | |
3 | * | |
4 | * Permission to use, copy, modify, distribute, and sell this software and its | |
5 | * documentation for any purpose is hereby granted without fee, provided that | |
6 | * the above copyright notice appear in all copies and that both that copyright | |
7 | * notice and this permission notice appear in supporting documentation, and | |
8 | * that the name of the copyright holders not be used in advertising or | |
9 | * publicity pertaining to distribution of the software without specific, | |
10 | * written prior permission. The copyright holders make no representations | |
11 | * about the suitability of this software for any purpose. It is provided "as | |
12 | * is" without express or implied warranty. | |
13 | * | |
14 | * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, | |
15 | * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO | |
16 | * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR | |
17 | * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, | |
18 | * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER | |
19 | * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE | |
20 | * OF THIS SOFTWARE. | |
21 | */ | |
22 | ||
23 | #ifndef __DRM_PLANE_H__ | |
24 | #define __DRM_PLANE_H__ | |
25 | ||
26 | #include <linux/list.h> | |
27 | #include <linux/ctype.h> | |
28 | #include <drm/drm_mode_object.h> | |
29 | ||
30 | struct drm_crtc; | |
31 | ||
32 | /** | |
33 | * struct drm_plane_state - mutable plane state | |
34 | * @plane: backpointer to the plane | |
35 | * @crtc: currently bound CRTC, NULL if disabled | |
36 | * @fb: currently bound framebuffer | |
37 | * @fence: optional fence to wait for before scanning out @fb | |
38 | * @crtc_x: left position of visible portion of plane on crtc | |
39 | * @crtc_y: upper position of visible portion of plane on crtc | |
40 | * @crtc_w: width of visible portion of plane on crtc | |
41 | * @crtc_h: height of visible portion of plane on crtc | |
42 | * @src_x: left position of visible portion of plane within | |
43 | * plane (in 16.16) | |
44 | * @src_y: upper position of visible portion of plane within | |
45 | * plane (in 16.16) | |
46 | * @src_w: width of visible portion of plane (in 16.16) | |
47 | * @src_h: height of visible portion of plane (in 16.16) | |
48 | * @rotation: rotation of the plane | |
49 | * @zpos: priority of the given plane on crtc (optional) | |
50 | * @normalized_zpos: normalized value of zpos: unique, range from 0 to N-1 | |
51 | * where N is the number of active planes for given crtc | |
52 | * @src: clipped source coordinates of the plane (in 16.16) | |
53 | * @dst: clipped destination coordinates of the plane | |
54 | * @visible: visibility of the plane | |
55 | * @state: backpointer to global drm_atomic_state | |
56 | */ | |
57 | struct drm_plane_state { | |
58 | struct drm_plane *plane; | |
59 | ||
60 | struct drm_crtc *crtc; /* do not write directly, use drm_atomic_set_crtc_for_plane() */ | |
61 | struct drm_framebuffer *fb; /* do not write directly, use drm_atomic_set_fb_for_plane() */ | |
62 | struct fence *fence; | |
63 | ||
64 | /* Signed dest location allows it to be partially off screen */ | |
65 | int32_t crtc_x, crtc_y; | |
66 | uint32_t crtc_w, crtc_h; | |
67 | ||
68 | /* Source values are 16.16 fixed point */ | |
69 | uint32_t src_x, src_y; | |
70 | uint32_t src_h, src_w; | |
71 | ||
72 | /* Plane rotation */ | |
73 | unsigned int rotation; | |
74 | ||
75 | /* Plane zpos */ | |
76 | unsigned int zpos; | |
77 | unsigned int normalized_zpos; | |
78 | ||
79 | /* Clipped coordinates */ | |
80 | struct drm_rect src, dst; | |
81 | ||
82 | /* | |
83 | * Is the plane actually visible? Can be false even | |
84 | * if fb!=NULL and crtc!=NULL, due to clipping. | |
85 | */ | |
86 | bool visible; | |
87 | ||
88 | struct drm_atomic_state *state; | |
89 | }; | |
90 | ||
91 | ||
92 | /** | |
93 | * struct drm_plane_funcs - driver plane control functions | |
94 | */ | |
95 | struct drm_plane_funcs { | |
96 | /** | |
97 | * @update_plane: | |
98 | * | |
99 | * This is the legacy entry point to enable and configure the plane for | |
100 | * the given CRTC and framebuffer. It is never called to disable the | |
101 | * plane, i.e. the passed-in crtc and fb paramters are never NULL. | |
102 | * | |
103 | * The source rectangle in frame buffer memory coordinates is given by | |
104 | * the src_x, src_y, src_w and src_h parameters (as 16.16 fixed point | |
105 | * values). Devices that don't support subpixel plane coordinates can | |
106 | * ignore the fractional part. | |
107 | * | |
108 | * The destination rectangle in CRTC coordinates is given by the | |
109 | * crtc_x, crtc_y, crtc_w and crtc_h parameters (as integer values). | |
110 | * Devices scale the source rectangle to the destination rectangle. If | |
111 | * scaling is not supported, and the source rectangle size doesn't match | |
112 | * the destination rectangle size, the driver must return a | |
113 | * -<errorname>EINVAL</errorname> error. | |
114 | * | |
115 | * Drivers implementing atomic modeset should use | |
116 | * drm_atomic_helper_update_plane() to implement this hook. | |
117 | * | |
118 | * RETURNS: | |
119 | * | |
120 | * 0 on success or a negative error code on failure. | |
121 | */ | |
122 | int (*update_plane)(struct drm_plane *plane, | |
123 | struct drm_crtc *crtc, struct drm_framebuffer *fb, | |
124 | int crtc_x, int crtc_y, | |
125 | unsigned int crtc_w, unsigned int crtc_h, | |
126 | uint32_t src_x, uint32_t src_y, | |
127 | uint32_t src_w, uint32_t src_h); | |
128 | ||
129 | /** | |
130 | * @disable_plane: | |
131 | * | |
132 | * This is the legacy entry point to disable the plane. The DRM core | |
133 | * calls this method in response to a DRM_IOCTL_MODE_SETPLANE IOCTL call | |
134 | * with the frame buffer ID set to 0. Disabled planes must not be | |
135 | * processed by the CRTC. | |
136 | * | |
137 | * Drivers implementing atomic modeset should use | |
138 | * drm_atomic_helper_disable_plane() to implement this hook. | |
139 | * | |
140 | * RETURNS: | |
141 | * | |
142 | * 0 on success or a negative error code on failure. | |
143 | */ | |
144 | int (*disable_plane)(struct drm_plane *plane); | |
145 | ||
146 | /** | |
147 | * @destroy: | |
148 | * | |
149 | * Clean up plane resources. This is only called at driver unload time | |
150 | * through drm_mode_config_cleanup() since a plane cannot be hotplugged | |
151 | * in DRM. | |
152 | */ | |
153 | void (*destroy)(struct drm_plane *plane); | |
154 | ||
155 | /** | |
156 | * @reset: | |
157 | * | |
158 | * Reset plane hardware and software state to off. This function isn't | |
159 | * called by the core directly, only through drm_mode_config_reset(). | |
160 | * It's not a helper hook only for historical reasons. | |
161 | * | |
162 | * Atomic drivers can use drm_atomic_helper_plane_reset() to reset | |
163 | * atomic state using this hook. | |
164 | */ | |
165 | void (*reset)(struct drm_plane *plane); | |
166 | ||
167 | /** | |
168 | * @set_property: | |
169 | * | |
170 | * This is the legacy entry point to update a property attached to the | |
171 | * plane. | |
172 | * | |
173 | * Drivers implementing atomic modeset should use | |
174 | * drm_atomic_helper_plane_set_property() to implement this hook. | |
175 | * | |
176 | * This callback is optional if the driver does not support any legacy | |
177 | * driver-private properties. | |
178 | * | |
179 | * RETURNS: | |
180 | * | |
181 | * 0 on success or a negative error code on failure. | |
182 | */ | |
183 | int (*set_property)(struct drm_plane *plane, | |
184 | struct drm_property *property, uint64_t val); | |
185 | ||
186 | /** | |
187 | * @atomic_duplicate_state: | |
188 | * | |
189 | * Duplicate the current atomic state for this plane and return it. | |
190 | * The core and helpers gurantee that any atomic state duplicated with | |
191 | * this hook and still owned by the caller (i.e. not transferred to the | |
192 | * driver by calling ->atomic_commit() from struct | |
193 | * &drm_mode_config_funcs) will be cleaned up by calling the | |
194 | * @atomic_destroy_state hook in this structure. | |
195 | * | |
196 | * Atomic drivers which don't subclass struct &drm_plane_state should use | |
197 | * drm_atomic_helper_plane_duplicate_state(). Drivers that subclass the | |
198 | * state structure to extend it with driver-private state should use | |
199 | * __drm_atomic_helper_plane_duplicate_state() to make sure shared state is | |
200 | * duplicated in a consistent fashion across drivers. | |
201 | * | |
202 | * It is an error to call this hook before plane->state has been | |
203 | * initialized correctly. | |
204 | * | |
205 | * NOTE: | |
206 | * | |
207 | * If the duplicate state references refcounted resources this hook must | |
208 | * acquire a reference for each of them. The driver must release these | |
209 | * references again in @atomic_destroy_state. | |
210 | * | |
211 | * RETURNS: | |
212 | * | |
213 | * Duplicated atomic state or NULL when the allocation failed. | |
214 | */ | |
215 | struct drm_plane_state *(*atomic_duplicate_state)(struct drm_plane *plane); | |
216 | ||
217 | /** | |
218 | * @atomic_destroy_state: | |
219 | * | |
220 | * Destroy a state duplicated with @atomic_duplicate_state and release | |
221 | * or unreference all resources it references | |
222 | */ | |
223 | void (*atomic_destroy_state)(struct drm_plane *plane, | |
224 | struct drm_plane_state *state); | |
225 | ||
226 | /** | |
227 | * @atomic_set_property: | |
228 | * | |
229 | * Decode a driver-private property value and store the decoded value | |
230 | * into the passed-in state structure. Since the atomic core decodes all | |
231 | * standardized properties (even for extensions beyond the core set of | |
232 | * properties which might not be implemented by all drivers) this | |
233 | * requires drivers to subclass the state structure. | |
234 | * | |
235 | * Such driver-private properties should really only be implemented for | |
236 | * truly hardware/vendor specific state. Instead it is preferred to | |
237 | * standardize atomic extension and decode the properties used to expose | |
238 | * such an extension in the core. | |
239 | * | |
240 | * Do not call this function directly, use | |
241 | * drm_atomic_plane_set_property() instead. | |
242 | * | |
243 | * This callback is optional if the driver does not support any | |
244 | * driver-private atomic properties. | |
245 | * | |
246 | * NOTE: | |
247 | * | |
248 | * This function is called in the state assembly phase of atomic | |
249 | * modesets, which can be aborted for any reason (including on | |
250 | * userspace's request to just check whether a configuration would be | |
251 | * possible). Drivers MUST NOT touch any persistent state (hardware or | |
252 | * software) or data structures except the passed in @state parameter. | |
253 | * | |
254 | * Also since userspace controls in which order properties are set this | |
255 | * function must not do any input validation (since the state update is | |
256 | * incomplete and hence likely inconsistent). Instead any such input | |
257 | * validation must be done in the various atomic_check callbacks. | |
258 | * | |
259 | * RETURNS: | |
260 | * | |
261 | * 0 if the property has been found, -EINVAL if the property isn't | |
262 | * implemented by the driver (which shouldn't ever happen, the core only | |
263 | * asks for properties attached to this plane). No other validation is | |
264 | * allowed by the driver. The core already checks that the property | |
265 | * value is within the range (integer, valid enum value, ...) the driver | |
266 | * set when registering the property. | |
267 | */ | |
268 | int (*atomic_set_property)(struct drm_plane *plane, | |
269 | struct drm_plane_state *state, | |
270 | struct drm_property *property, | |
271 | uint64_t val); | |
272 | ||
273 | /** | |
274 | * @atomic_get_property: | |
275 | * | |
276 | * Reads out the decoded driver-private property. This is used to | |
277 | * implement the GETPLANE IOCTL. | |
278 | * | |
279 | * Do not call this function directly, use | |
280 | * drm_atomic_plane_get_property() instead. | |
281 | * | |
282 | * This callback is optional if the driver does not support any | |
283 | * driver-private atomic properties. | |
284 | * | |
285 | * RETURNS: | |
286 | * | |
287 | * 0 on success, -EINVAL if the property isn't implemented by the | |
288 | * driver (which should never happen, the core only asks for | |
289 | * properties attached to this plane). | |
290 | */ | |
291 | int (*atomic_get_property)(struct drm_plane *plane, | |
292 | const struct drm_plane_state *state, | |
293 | struct drm_property *property, | |
294 | uint64_t *val); | |
295 | /** | |
296 | * @late_register: | |
297 | * | |
298 | * This optional hook can be used to register additional userspace | |
299 | * interfaces attached to the plane like debugfs interfaces. | |
300 | * It is called late in the driver load sequence from drm_dev_register(). | |
301 | * Everything added from this callback should be unregistered in | |
302 | * the early_unregister callback. | |
303 | * | |
304 | * Returns: | |
305 | * | |
306 | * 0 on success, or a negative error code on failure. | |
307 | */ | |
308 | int (*late_register)(struct drm_plane *plane); | |
309 | ||
310 | /** | |
311 | * @early_unregister: | |
312 | * | |
313 | * This optional hook should be used to unregister the additional | |
314 | * userspace interfaces attached to the plane from | |
315 | * late_unregister(). It is called from drm_dev_unregister(), | |
316 | * early in the driver unload sequence to disable userspace access | |
317 | * before data structures are torndown. | |
318 | */ | |
319 | void (*early_unregister)(struct drm_plane *plane); | |
320 | }; | |
321 | ||
532b3671 DV |
322 | /** |
323 | * enum drm_plane_type - uapi plane type enumeration | |
324 | * | |
325 | * For historical reasons not all planes are made the same. This enumeration is | |
326 | * used to tell the different types of planes apart to implement the different | |
327 | * uapi semantics for them. For userspace which is universal plane aware and | |
328 | * which is using that atomic IOCTL there's no difference between these planes | |
329 | * (beyong what the driver and hardware can support of course). | |
330 | * | |
331 | * For compatibility with legacy userspace, only overlay planes are made | |
332 | * available to userspace by default. Userspace clients may set the | |
333 | * DRM_CLIENT_CAP_UNIVERSAL_PLANES client capability bit to indicate that they | |
334 | * wish to receive a universal plane list containing all plane types. See also | |
335 | * drm_for_each_legacy_plane(). | |
336 | */ | |
43968d7b | 337 | enum drm_plane_type { |
532b3671 DV |
338 | /** |
339 | * @DRM_PLANE_TYPE_PRIMARY: | |
340 | * | |
341 | * Primary planes represent a "main" plane for a CRTC. Primary planes | |
342 | * are the planes operated upon by CRTC modesetting and flipping | |
343 | * operations described in the page_flip and set_config hooks in struct | |
344 | * &drm_crtc_funcs. | |
345 | */ | |
43968d7b | 346 | DRM_PLANE_TYPE_PRIMARY, |
532b3671 DV |
347 | |
348 | /** | |
349 | * @DRM_PLANE_TYPE_CURSOR: | |
350 | * | |
351 | * Cursor planes represent a "cursor" plane for a CRTC. Cursor planes | |
352 | * are the planes operated upon by the DRM_IOCTL_MODE_CURSOR and | |
353 | * DRM_IOCTL_MODE_CURSOR2 IOCTLs. | |
354 | */ | |
43968d7b | 355 | DRM_PLANE_TYPE_CURSOR, |
532b3671 DV |
356 | |
357 | /** | |
358 | * @DRM_PLANE_TYPE_OVERLAY: | |
359 | * | |
360 | * Overlay planes represent all non-primary, non-cursor planes. Some | |
361 | * drivers refer to these types of planes as "sprites" internally. | |
362 | */ | |
363 | DRM_PLANE_TYPE_OVERLAY, | |
43968d7b DV |
364 | }; |
365 | ||
366 | ||
367 | /** | |
368 | * struct drm_plane - central DRM plane control structure | |
369 | * @dev: DRM device this plane belongs to | |
370 | * @head: for list management | |
371 | * @name: human readable name, can be overwritten by the driver | |
372 | * @base: base mode object | |
373 | * @possible_crtcs: pipes this plane can be bound to | |
374 | * @format_types: array of formats supported by this plane | |
375 | * @format_count: number of formats supported | |
376 | * @format_default: driver hasn't supplied supported formats for the plane | |
377 | * @crtc: currently bound CRTC | |
378 | * @fb: currently bound fb | |
379 | * @old_fb: Temporary tracking of the old fb while a modeset is ongoing. Used by | |
380 | * drm_mode_set_config_internal() to implement correct refcounting. | |
381 | * @funcs: helper functions | |
382 | * @properties: property tracking for this plane | |
383 | * @type: type of plane (overlay, primary, cursor) | |
384 | * @state: current atomic state for this plane | |
385 | * @zpos_property: zpos property for this plane | |
386 | * @helper_private: mid-layer private data | |
387 | */ | |
388 | struct drm_plane { | |
389 | struct drm_device *dev; | |
390 | struct list_head head; | |
391 | ||
392 | char *name; | |
393 | ||
394 | /** | |
395 | * @mutex: | |
396 | * | |
397 | * Protects modeset plane state, together with the mutex of &drm_crtc | |
398 | * this plane is linked to (when active, getting actived or getting | |
399 | * disabled). | |
400 | */ | |
401 | struct drm_modeset_lock mutex; | |
402 | ||
403 | struct drm_mode_object base; | |
404 | ||
405 | uint32_t possible_crtcs; | |
406 | uint32_t *format_types; | |
407 | unsigned int format_count; | |
408 | bool format_default; | |
409 | ||
410 | struct drm_crtc *crtc; | |
411 | struct drm_framebuffer *fb; | |
412 | ||
413 | struct drm_framebuffer *old_fb; | |
414 | ||
415 | const struct drm_plane_funcs *funcs; | |
416 | ||
417 | struct drm_object_properties properties; | |
418 | ||
419 | enum drm_plane_type type; | |
420 | ||
421 | /** | |
422 | * @index: Position inside the mode_config.list, can be used as an array | |
423 | * index. It is invariant over the lifetime of the plane. | |
424 | */ | |
425 | unsigned index; | |
426 | ||
427 | const struct drm_plane_helper_funcs *helper_private; | |
428 | ||
429 | struct drm_plane_state *state; | |
430 | ||
431 | struct drm_property *zpos_property; | |
432 | }; | |
433 | ||
434 | #define obj_to_plane(x) container_of(x, struct drm_plane, base) | |
435 | ||
436 | extern __printf(8, 9) | |
437 | int drm_universal_plane_init(struct drm_device *dev, | |
438 | struct drm_plane *plane, | |
439 | unsigned long possible_crtcs, | |
440 | const struct drm_plane_funcs *funcs, | |
441 | const uint32_t *formats, | |
442 | unsigned int format_count, | |
443 | enum drm_plane_type type, | |
444 | const char *name, ...); | |
445 | extern int drm_plane_init(struct drm_device *dev, | |
446 | struct drm_plane *plane, | |
447 | unsigned long possible_crtcs, | |
448 | const struct drm_plane_funcs *funcs, | |
449 | const uint32_t *formats, unsigned int format_count, | |
450 | bool is_primary); | |
451 | extern void drm_plane_cleanup(struct drm_plane *plane); | |
452 | ||
453 | /** | |
454 | * drm_plane_index - find the index of a registered plane | |
455 | * @plane: plane to find index for | |
456 | * | |
457 | * Given a registered plane, return the index of that plane within a DRM | |
458 | * device's list of planes. | |
459 | */ | |
460 | static inline unsigned int drm_plane_index(struct drm_plane *plane) | |
461 | { | |
462 | return plane->index; | |
463 | } | |
464 | extern struct drm_plane * drm_plane_from_index(struct drm_device *dev, int idx); | |
465 | extern void drm_plane_force_disable(struct drm_plane *plane); | |
466 | ||
467 | int drm_mode_plane_set_obj_prop(struct drm_plane *plane, | |
468 | struct drm_property *property, | |
469 | uint64_t value); | |
470 | ||
471 | /** | |
472 | * drm_plane_find - find a &drm_plane | |
473 | * @dev: DRM device | |
474 | * @id: plane id | |
475 | * | |
476 | * Returns the plane with @id, NULL if it doesn't exist. Simple wrapper around | |
477 | * drm_mode_object_find(). | |
478 | */ | |
479 | static inline struct drm_plane *drm_plane_find(struct drm_device *dev, | |
480 | uint32_t id) | |
481 | { | |
482 | struct drm_mode_object *mo; | |
483 | mo = drm_mode_object_find(dev, id, DRM_MODE_OBJECT_PLANE); | |
484 | return mo ? obj_to_plane(mo) : NULL; | |
485 | } | |
486 | ||
487 | /** | |
488 | * drm_for_each_plane_mask - iterate over planes specified by bitmask | |
489 | * @plane: the loop cursor | |
490 | * @dev: the DRM device | |
491 | * @plane_mask: bitmask of plane indices | |
492 | * | |
493 | * Iterate over all planes specified by bitmask. | |
494 | */ | |
495 | #define drm_for_each_plane_mask(plane, dev, plane_mask) \ | |
496 | list_for_each_entry((plane), &(dev)->mode_config.plane_list, head) \ | |
497 | for_each_if ((plane_mask) & (1 << drm_plane_index(plane))) | |
498 | ||
532b3671 DV |
499 | /** |
500 | * drm_for_each_legacy_plane - iterate over all planes for legacy userspace | |
501 | * @plane: the loop cursor | |
502 | * @dev: the DRM device | |
503 | * | |
504 | * Iterate over all legacy planes of @dev, excluding primary and cursor planes. | |
505 | * This is useful for implementing userspace apis when userspace is not | |
506 | * universal plane aware. See also enum &drm_plane_type. | |
507 | */ | |
43968d7b DV |
508 | #define drm_for_each_legacy_plane(plane, dev) \ |
509 | list_for_each_entry(plane, &(dev)->mode_config.plane_list, head) \ | |
510 | for_each_if (plane->type == DRM_PLANE_TYPE_OVERLAY) | |
511 | ||
532b3671 DV |
512 | /** |
513 | * drm_for_each_plane - iterate over all planes | |
514 | * @plane: the loop cursor | |
515 | * @dev: the DRM device | |
516 | * | |
517 | * Iterate over all planes of @dev, include primary and cursor planes. | |
518 | */ | |
43968d7b DV |
519 | #define drm_for_each_plane(plane, dev) \ |
520 | list_for_each_entry(plane, &(dev)->mode_config.plane_list, head) | |
521 | ||
522 | ||
523 | #endif |