Linux 4.13.16
[linux/fpc-iii.git] / include / drm / drm_plane.h
blob9ab3e70448127902aad5414f7fe1e109ed298e21
1 /*
2 * Copyright (c) 2016 Intel Corporation
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.
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.
23 #ifndef __DRM_PLANE_H__
24 #define __DRM_PLANE_H__
26 #include <linux/list.h>
27 #include <linux/ctype.h>
28 #include <drm/drm_mode_object.h>
30 struct drm_crtc;
31 struct drm_printer;
32 struct drm_modeset_acquire_ctx;
34 /**
35 * struct drm_plane_state - mutable plane state
36 * @plane: backpointer to the plane
37 * @crtc_w: width of visible portion of plane on crtc
38 * @crtc_h: height of visible portion of plane on crtc
39 * @src_x: left position of visible portion of plane within
40 * plane (in 16.16)
41 * @src_y: upper position of visible portion of plane within
42 * plane (in 16.16)
43 * @src_w: width of visible portion of plane (in 16.16)
44 * @src_h: height of visible portion of plane (in 16.16)
45 * @rotation: rotation of the plane
46 * @zpos: priority of the given plane on crtc (optional)
47 * Note that multiple active planes on the same crtc can have an identical
48 * zpos value. The rule to solving the conflict is to compare the plane
49 * object IDs; the plane with a higher ID must be stacked on top of a
50 * plane with a lower ID.
51 * @normalized_zpos: normalized value of zpos: unique, range from 0 to N-1
52 * where N is the number of active planes for given crtc. Note that
53 * the driver must call drm_atomic_normalize_zpos() to update this before
54 * it can be trusted.
55 * @src: clipped source coordinates of the plane (in 16.16)
56 * @dst: clipped destination coordinates of the plane
57 * @state: backpointer to global drm_atomic_state
59 struct drm_plane_state {
60 struct drm_plane *plane;
62 /**
63 * @crtc:
65 * Currently bound CRTC, NULL if disabled. Do not this write directly,
66 * use drm_atomic_set_crtc_for_plane()
68 struct drm_crtc *crtc;
70 /**
71 * @fb:
73 * Currently bound framebuffer. Do not write this directly, use
74 * drm_atomic_set_fb_for_plane()
76 struct drm_framebuffer *fb;
78 /**
79 * @fence:
81 * Optional fence to wait for before scanning out @fb. Do not write this
82 * directly, use drm_atomic_set_fence_for_plane()
84 struct dma_fence *fence;
86 /**
87 * @crtc_x:
89 * Left position of visible portion of plane on crtc, signed dest
90 * location allows it to be partially off screen.
93 int32_t crtc_x;
94 /**
95 * @crtc_y:
97 * Upper position of visible portion of plane on crtc, signed dest
98 * location allows it to be partially off screen.
100 int32_t crtc_y;
102 uint32_t crtc_w, crtc_h;
104 /* Source values are 16.16 fixed point */
105 uint32_t src_x, src_y;
106 uint32_t src_h, src_w;
108 /* Plane rotation */
109 unsigned int rotation;
111 /* Plane zpos */
112 unsigned int zpos;
113 unsigned int normalized_zpos;
115 /* Clipped coordinates */
116 struct drm_rect src, dst;
119 * @visible:
121 * Visibility of the plane. This can be false even if fb!=NULL and
122 * crtc!=NULL, due to clipping.
124 bool visible;
126 struct drm_atomic_state *state;
129 static inline struct drm_rect
130 drm_plane_state_src(const struct drm_plane_state *state)
132 struct drm_rect src = {
133 .x1 = state->src_x,
134 .y1 = state->src_y,
135 .x2 = state->src_x + state->src_w,
136 .y2 = state->src_y + state->src_h,
138 return src;
141 static inline struct drm_rect
142 drm_plane_state_dest(const struct drm_plane_state *state)
144 struct drm_rect dest = {
145 .x1 = state->crtc_x,
146 .y1 = state->crtc_y,
147 .x2 = state->crtc_x + state->crtc_w,
148 .y2 = state->crtc_y + state->crtc_h,
150 return dest;
154 * struct drm_plane_funcs - driver plane control functions
156 struct drm_plane_funcs {
158 * @update_plane:
160 * This is the legacy entry point to enable and configure the plane for
161 * the given CRTC and framebuffer. It is never called to disable the
162 * plane, i.e. the passed-in crtc and fb paramters are never NULL.
164 * The source rectangle in frame buffer memory coordinates is given by
165 * the src_x, src_y, src_w and src_h parameters (as 16.16 fixed point
166 * values). Devices that don't support subpixel plane coordinates can
167 * ignore the fractional part.
169 * The destination rectangle in CRTC coordinates is given by the
170 * crtc_x, crtc_y, crtc_w and crtc_h parameters (as integer values).
171 * Devices scale the source rectangle to the destination rectangle. If
172 * scaling is not supported, and the source rectangle size doesn't match
173 * the destination rectangle size, the driver must return a
174 * -<errorname>EINVAL</errorname> error.
176 * Drivers implementing atomic modeset should use
177 * drm_atomic_helper_update_plane() to implement this hook.
179 * RETURNS:
181 * 0 on success or a negative error code on failure.
183 int (*update_plane)(struct drm_plane *plane,
184 struct drm_crtc *crtc, struct drm_framebuffer *fb,
185 int crtc_x, int crtc_y,
186 unsigned int crtc_w, unsigned int crtc_h,
187 uint32_t src_x, uint32_t src_y,
188 uint32_t src_w, uint32_t src_h,
189 struct drm_modeset_acquire_ctx *ctx);
192 * @disable_plane:
194 * This is the legacy entry point to disable the plane. The DRM core
195 * calls this method in response to a DRM_IOCTL_MODE_SETPLANE IOCTL call
196 * with the frame buffer ID set to 0. Disabled planes must not be
197 * processed by the CRTC.
199 * Drivers implementing atomic modeset should use
200 * drm_atomic_helper_disable_plane() to implement this hook.
202 * RETURNS:
204 * 0 on success or a negative error code on failure.
206 int (*disable_plane)(struct drm_plane *plane,
207 struct drm_modeset_acquire_ctx *ctx);
210 * @destroy:
212 * Clean up plane resources. This is only called at driver unload time
213 * through drm_mode_config_cleanup() since a plane cannot be hotplugged
214 * in DRM.
216 void (*destroy)(struct drm_plane *plane);
219 * @reset:
221 * Reset plane hardware and software state to off. This function isn't
222 * called by the core directly, only through drm_mode_config_reset().
223 * It's not a helper hook only for historical reasons.
225 * Atomic drivers can use drm_atomic_helper_plane_reset() to reset
226 * atomic state using this hook.
228 void (*reset)(struct drm_plane *plane);
231 * @set_property:
233 * This is the legacy entry point to update a property attached to the
234 * plane.
236 * Drivers implementing atomic modeset should use
237 * drm_atomic_helper_plane_set_property() to implement this hook.
239 * This callback is optional if the driver does not support any legacy
240 * driver-private properties.
242 * RETURNS:
244 * 0 on success or a negative error code on failure.
246 int (*set_property)(struct drm_plane *plane,
247 struct drm_property *property, uint64_t val);
250 * @atomic_duplicate_state:
252 * Duplicate the current atomic state for this plane and return it.
253 * The core and helpers guarantee that any atomic state duplicated with
254 * this hook and still owned by the caller (i.e. not transferred to the
255 * driver by calling &drm_mode_config_funcs.atomic_commit) will be
256 * cleaned up by calling the @atomic_destroy_state hook in this
257 * structure.
259 * Atomic drivers which don't subclass &struct drm_plane_state should use
260 * drm_atomic_helper_plane_duplicate_state(). Drivers that subclass the
261 * state structure to extend it with driver-private state should use
262 * __drm_atomic_helper_plane_duplicate_state() to make sure shared state is
263 * duplicated in a consistent fashion across drivers.
265 * It is an error to call this hook before &drm_plane.state has been
266 * initialized correctly.
268 * NOTE:
270 * If the duplicate state references refcounted resources this hook must
271 * acquire a reference for each of them. The driver must release these
272 * references again in @atomic_destroy_state.
274 * RETURNS:
276 * Duplicated atomic state or NULL when the allocation failed.
278 struct drm_plane_state *(*atomic_duplicate_state)(struct drm_plane *plane);
281 * @atomic_destroy_state:
283 * Destroy a state duplicated with @atomic_duplicate_state and release
284 * or unreference all resources it references
286 void (*atomic_destroy_state)(struct drm_plane *plane,
287 struct drm_plane_state *state);
290 * @atomic_set_property:
292 * Decode a driver-private property value and store the decoded value
293 * into the passed-in state structure. Since the atomic core decodes all
294 * standardized properties (even for extensions beyond the core set of
295 * properties which might not be implemented by all drivers) this
296 * requires drivers to subclass the state structure.
298 * Such driver-private properties should really only be implemented for
299 * truly hardware/vendor specific state. Instead it is preferred to
300 * standardize atomic extension and decode the properties used to expose
301 * such an extension in the core.
303 * Do not call this function directly, use
304 * drm_atomic_plane_set_property() instead.
306 * This callback is optional if the driver does not support any
307 * driver-private atomic properties.
309 * NOTE:
311 * This function is called in the state assembly phase of atomic
312 * modesets, which can be aborted for any reason (including on
313 * userspace's request to just check whether a configuration would be
314 * possible). Drivers MUST NOT touch any persistent state (hardware or
315 * software) or data structures except the passed in @state parameter.
317 * Also since userspace controls in which order properties are set this
318 * function must not do any input validation (since the state update is
319 * incomplete and hence likely inconsistent). Instead any such input
320 * validation must be done in the various atomic_check callbacks.
322 * RETURNS:
324 * 0 if the property has been found, -EINVAL if the property isn't
325 * implemented by the driver (which shouldn't ever happen, the core only
326 * asks for properties attached to this plane). No other validation is
327 * allowed by the driver. The core already checks that the property
328 * value is within the range (integer, valid enum value, ...) the driver
329 * set when registering the property.
331 int (*atomic_set_property)(struct drm_plane *plane,
332 struct drm_plane_state *state,
333 struct drm_property *property,
334 uint64_t val);
337 * @atomic_get_property:
339 * Reads out the decoded driver-private property. This is used to
340 * implement the GETPLANE IOCTL.
342 * Do not call this function directly, use
343 * drm_atomic_plane_get_property() instead.
345 * This callback is optional if the driver does not support any
346 * driver-private atomic properties.
348 * RETURNS:
350 * 0 on success, -EINVAL if the property isn't implemented by the
351 * driver (which should never happen, the core only asks for
352 * properties attached to this plane).
354 int (*atomic_get_property)(struct drm_plane *plane,
355 const struct drm_plane_state *state,
356 struct drm_property *property,
357 uint64_t *val);
359 * @late_register:
361 * This optional hook can be used to register additional userspace
362 * interfaces attached to the plane like debugfs interfaces.
363 * It is called late in the driver load sequence from drm_dev_register().
364 * Everything added from this callback should be unregistered in
365 * the early_unregister callback.
367 * Returns:
369 * 0 on success, or a negative error code on failure.
371 int (*late_register)(struct drm_plane *plane);
374 * @early_unregister:
376 * This optional hook should be used to unregister the additional
377 * userspace interfaces attached to the plane from
378 * @late_register. It is called from drm_dev_unregister(),
379 * early in the driver unload sequence to disable userspace access
380 * before data structures are torndown.
382 void (*early_unregister)(struct drm_plane *plane);
385 * @atomic_print_state:
387 * If driver subclasses &struct drm_plane_state, it should implement
388 * this optional hook for printing additional driver specific state.
390 * Do not call this directly, use drm_atomic_plane_print_state()
391 * instead.
393 void (*atomic_print_state)(struct drm_printer *p,
394 const struct drm_plane_state *state);
398 * enum drm_plane_type - uapi plane type enumeration
400 * For historical reasons not all planes are made the same. This enumeration is
401 * used to tell the different types of planes apart to implement the different
402 * uapi semantics for them. For userspace which is universal plane aware and
403 * which is using that atomic IOCTL there's no difference between these planes
404 * (beyong what the driver and hardware can support of course).
406 * For compatibility with legacy userspace, only overlay planes are made
407 * available to userspace by default. Userspace clients may set the
408 * DRM_CLIENT_CAP_UNIVERSAL_PLANES client capability bit to indicate that they
409 * wish to receive a universal plane list containing all plane types. See also
410 * drm_for_each_legacy_plane().
412 * WARNING: The values of this enum is UABI since they're exposed in the "type"
413 * property.
415 enum drm_plane_type {
417 * @DRM_PLANE_TYPE_OVERLAY:
419 * Overlay planes represent all non-primary, non-cursor planes. Some
420 * drivers refer to these types of planes as "sprites" internally.
422 DRM_PLANE_TYPE_OVERLAY,
425 * @DRM_PLANE_TYPE_PRIMARY:
427 * Primary planes represent a "main" plane for a CRTC. Primary planes
428 * are the planes operated upon by CRTC modesetting and flipping
429 * operations described in the &drm_crtc_funcs.page_flip and
430 * &drm_crtc_funcs.set_config hooks.
432 DRM_PLANE_TYPE_PRIMARY,
435 * @DRM_PLANE_TYPE_CURSOR:
437 * Cursor planes represent a "cursor" plane for a CRTC. Cursor planes
438 * are the planes operated upon by the DRM_IOCTL_MODE_CURSOR and
439 * DRM_IOCTL_MODE_CURSOR2 IOCTLs.
441 DRM_PLANE_TYPE_CURSOR,
446 * struct drm_plane - central DRM plane control structure
447 * @dev: DRM device this plane belongs to
448 * @head: for list management
449 * @name: human readable name, can be overwritten by the driver
450 * @base: base mode object
451 * @possible_crtcs: pipes this plane can be bound to
452 * @format_types: array of formats supported by this plane
453 * @format_count: number of formats supported
454 * @format_default: driver hasn't supplied supported formats for the plane
455 * @crtc: currently bound CRTC
456 * @fb: currently bound fb
457 * @old_fb: Temporary tracking of the old fb while a modeset is ongoing. Used by
458 * drm_mode_set_config_internal() to implement correct refcounting.
459 * @funcs: helper functions
460 * @properties: property tracking for this plane
461 * @type: type of plane (overlay, primary, cursor)
462 * @zpos_property: zpos property for this plane
463 * @rotation_property: rotation property for this plane
464 * @helper_private: mid-layer private data
466 struct drm_plane {
467 struct drm_device *dev;
468 struct list_head head;
470 char *name;
473 * @mutex:
475 * Protects modeset plane state, together with the &drm_crtc.mutex of
476 * CRTC this plane is linked to (when active, getting activated or
477 * getting disabled).
479 * For atomic drivers specifically this protects @state.
481 struct drm_modeset_lock mutex;
483 struct drm_mode_object base;
485 uint32_t possible_crtcs;
486 uint32_t *format_types;
487 unsigned int format_count;
488 bool format_default;
490 struct drm_crtc *crtc;
491 struct drm_framebuffer *fb;
493 struct drm_framebuffer *old_fb;
495 const struct drm_plane_funcs *funcs;
497 struct drm_object_properties properties;
499 enum drm_plane_type type;
502 * @index: Position inside the mode_config.list, can be used as an array
503 * index. It is invariant over the lifetime of the plane.
505 unsigned index;
507 const struct drm_plane_helper_funcs *helper_private;
510 * @state:
512 * Current atomic state for this plane.
514 * This is protected by @mutex. Note that nonblocking atomic commits
515 * access the current plane state without taking locks. Either by going
516 * through the &struct drm_atomic_state pointers, see
517 * for_each_plane_in_state(), for_each_oldnew_plane_in_state(),
518 * for_each_old_plane_in_state() and for_each_new_plane_in_state(). Or
519 * through careful ordering of atomic commit operations as implemented
520 * in the atomic helpers, see &struct drm_crtc_commit.
522 struct drm_plane_state *state;
524 struct drm_property *zpos_property;
525 struct drm_property *rotation_property;
528 #define obj_to_plane(x) container_of(x, struct drm_plane, base)
530 __printf(8, 9)
531 int drm_universal_plane_init(struct drm_device *dev,
532 struct drm_plane *plane,
533 uint32_t possible_crtcs,
534 const struct drm_plane_funcs *funcs,
535 const uint32_t *formats,
536 unsigned int format_count,
537 enum drm_plane_type type,
538 const char *name, ...);
539 int drm_plane_init(struct drm_device *dev,
540 struct drm_plane *plane,
541 uint32_t possible_crtcs,
542 const struct drm_plane_funcs *funcs,
543 const uint32_t *formats, unsigned int format_count,
544 bool is_primary);
545 void drm_plane_cleanup(struct drm_plane *plane);
548 * drm_plane_index - find the index of a registered plane
549 * @plane: plane to find index for
551 * Given a registered plane, return the index of that plane within a DRM
552 * device's list of planes.
554 static inline unsigned int drm_plane_index(struct drm_plane *plane)
556 return plane->index;
558 struct drm_plane * drm_plane_from_index(struct drm_device *dev, int idx);
559 void drm_plane_force_disable(struct drm_plane *plane);
561 int drm_mode_plane_set_obj_prop(struct drm_plane *plane,
562 struct drm_property *property,
563 uint64_t value);
566 * drm_plane_find - find a &drm_plane
567 * @dev: DRM device
568 * @id: plane id
570 * Returns the plane with @id, NULL if it doesn't exist. Simple wrapper around
571 * drm_mode_object_find().
573 static inline struct drm_plane *drm_plane_find(struct drm_device *dev,
574 uint32_t id)
576 struct drm_mode_object *mo;
577 mo = drm_mode_object_find(dev, id, DRM_MODE_OBJECT_PLANE);
578 return mo ? obj_to_plane(mo) : NULL;
582 * drm_for_each_plane_mask - iterate over planes specified by bitmask
583 * @plane: the loop cursor
584 * @dev: the DRM device
585 * @plane_mask: bitmask of plane indices
587 * Iterate over all planes specified by bitmask.
589 #define drm_for_each_plane_mask(plane, dev, plane_mask) \
590 list_for_each_entry((plane), &(dev)->mode_config.plane_list, head) \
591 for_each_if ((plane_mask) & (1 << drm_plane_index(plane)))
594 * drm_for_each_legacy_plane - iterate over all planes for legacy userspace
595 * @plane: the loop cursor
596 * @dev: the DRM device
598 * Iterate over all legacy planes of @dev, excluding primary and cursor planes.
599 * This is useful for implementing userspace apis when userspace is not
600 * universal plane aware. See also &enum drm_plane_type.
602 #define drm_for_each_legacy_plane(plane, dev) \
603 list_for_each_entry(plane, &(dev)->mode_config.plane_list, head) \
604 for_each_if (plane->type == DRM_PLANE_TYPE_OVERLAY)
607 * drm_for_each_plane - iterate over all planes
608 * @plane: the loop cursor
609 * @dev: the DRM device
611 * Iterate over all planes of @dev, include primary and cursor planes.
613 #define drm_for_each_plane(plane, dev) \
614 list_for_each_entry(plane, &(dev)->mode_config.plane_list, head)
617 #endif