Back to home page

OSCL-LXR

 
 

    


0001 /*
0002  * Copyright (c) 2016 Intel Corporation
0003  *
0004  * Permission to use, copy, modify, distribute, and sell this software and its
0005  * documentation for any purpose is hereby granted without fee, provided that
0006  * the above copyright notice appear in all copies and that both that copyright
0007  * notice and this permission notice appear in supporting documentation, and
0008  * that the name of the copyright holders not be used in advertising or
0009  * publicity pertaining to distribution of the software without specific,
0010  * written prior permission.  The copyright holders make no representations
0011  * about the suitability of this software for any purpose.  It is provided "as
0012  * is" without express or implied warranty.
0013  *
0014  * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
0015  * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
0016  * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
0017  * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
0018  * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
0019  * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
0020  * OF THIS SOFTWARE.
0021  */
0022 
0023 #ifndef __DRM_PLANE_H__
0024 #define __DRM_PLANE_H__
0025 
0026 #include <linux/list.h>
0027 #include <linux/ctype.h>
0028 #include <drm/drm_mode_object.h>
0029 #include <drm/drm_color_mgmt.h>
0030 #include <drm/drm_rect.h>
0031 #include <drm/drm_modeset_lock.h>
0032 #include <drm/drm_util.h>
0033 
0034 struct drm_crtc;
0035 struct drm_printer;
0036 struct drm_modeset_acquire_ctx;
0037 
0038 enum drm_scaling_filter {
0039     DRM_SCALING_FILTER_DEFAULT,
0040     DRM_SCALING_FILTER_NEAREST_NEIGHBOR,
0041 };
0042 
0043 /**
0044  * struct drm_plane_state - mutable plane state
0045  *
0046  * Please note that the destination coordinates @crtc_x, @crtc_y, @crtc_h and
0047  * @crtc_w and the source coordinates @src_x, @src_y, @src_h and @src_w are the
0048  * raw coordinates provided by userspace. Drivers should use
0049  * drm_atomic_helper_check_plane_state() and only use the derived rectangles in
0050  * @src and @dst to program the hardware.
0051  */
0052 struct drm_plane_state {
0053     /** @plane: backpointer to the plane */
0054     struct drm_plane *plane;
0055 
0056     /**
0057      * @crtc:
0058      *
0059      * Currently bound CRTC, NULL if disabled. Do not this write directly,
0060      * use drm_atomic_set_crtc_for_plane()
0061      */
0062     struct drm_crtc *crtc;
0063 
0064     /**
0065      * @fb:
0066      *
0067      * Currently bound framebuffer. Do not write this directly, use
0068      * drm_atomic_set_fb_for_plane()
0069      */
0070     struct drm_framebuffer *fb;
0071 
0072     /**
0073      * @fence:
0074      *
0075      * Optional fence to wait for before scanning out @fb. The core atomic
0076      * code will set this when userspace is using explicit fencing. Do not
0077      * write this field directly for a driver's implicit fence.
0078      *
0079      * Drivers should store any implicit fence in this from their
0080      * &drm_plane_helper_funcs.prepare_fb callback. See drm_gem_plane_helper_prepare_fb()
0081      * and drm_gem_simple_display_pipe_prepare_fb() for suitable helpers.
0082      */
0083     struct dma_fence *fence;
0084 
0085     /**
0086      * @crtc_x:
0087      *
0088      * Left position of visible portion of plane on crtc, signed dest
0089      * location allows it to be partially off screen.
0090      */
0091 
0092     int32_t crtc_x;
0093     /**
0094      * @crtc_y:
0095      *
0096      * Upper position of visible portion of plane on crtc, signed dest
0097      * location allows it to be partially off screen.
0098      */
0099     int32_t crtc_y;
0100 
0101     /** @crtc_w: width of visible portion of plane on crtc */
0102     /** @crtc_h: height of visible portion of plane on crtc */
0103     uint32_t crtc_w, crtc_h;
0104 
0105     /**
0106      * @src_x: left position of visible portion of plane within plane (in
0107      * 16.16 fixed point).
0108      */
0109     uint32_t src_x;
0110     /**
0111      * @src_y: upper position of visible portion of plane within plane (in
0112      * 16.16 fixed point).
0113      */
0114     uint32_t src_y;
0115     /** @src_w: width of visible portion of plane (in 16.16) */
0116     /** @src_h: height of visible portion of plane (in 16.16) */
0117     uint32_t src_h, src_w;
0118 
0119     /**
0120      * @alpha:
0121      * Opacity of the plane with 0 as completely transparent and 0xffff as
0122      * completely opaque. See drm_plane_create_alpha_property() for more
0123      * details.
0124      */
0125     u16 alpha;
0126 
0127     /**
0128      * @pixel_blend_mode:
0129      * The alpha blending equation selection, describing how the pixels from
0130      * the current plane are composited with the background. Value can be
0131      * one of DRM_MODE_BLEND_*
0132      */
0133     uint16_t pixel_blend_mode;
0134 
0135     /**
0136      * @rotation:
0137      * Rotation of the plane. See drm_plane_create_rotation_property() for
0138      * more details.
0139      */
0140     unsigned int rotation;
0141 
0142     /**
0143      * @zpos:
0144      * Priority of the given plane on crtc (optional).
0145      *
0146      * User-space may set mutable zpos properties so that multiple active
0147      * planes on the same CRTC have identical zpos values. This is a
0148      * user-space bug, but drivers can solve the conflict by comparing the
0149      * plane object IDs; the plane with a higher ID is stacked on top of a
0150      * plane with a lower ID.
0151      *
0152      * See drm_plane_create_zpos_property() and
0153      * drm_plane_create_zpos_immutable_property() for more details.
0154      */
0155     unsigned int zpos;
0156 
0157     /**
0158      * @normalized_zpos:
0159      * Normalized value of zpos: unique, range from 0 to N-1 where N is the
0160      * number of active planes for given crtc. Note that the driver must set
0161      * &drm_mode_config.normalize_zpos or call drm_atomic_normalize_zpos() to
0162      * update this before it can be trusted.
0163      */
0164     unsigned int normalized_zpos;
0165 
0166     /**
0167      * @color_encoding:
0168      *
0169      * Color encoding for non RGB formats
0170      */
0171     enum drm_color_encoding color_encoding;
0172 
0173     /**
0174      * @color_range:
0175      *
0176      * Color range for non RGB formats
0177      */
0178     enum drm_color_range color_range;
0179 
0180     /**
0181      * @fb_damage_clips:
0182      *
0183      * Blob representing damage (area in plane framebuffer that changed
0184      * since last plane update) as an array of &drm_mode_rect in framebuffer
0185      * coodinates of the attached framebuffer. Note that unlike plane src,
0186      * damage clips are not in 16.16 fixed point.
0187      *
0188      * See drm_plane_get_damage_clips() and
0189      * drm_plane_get_damage_clips_count() for accessing these.
0190      */
0191     struct drm_property_blob *fb_damage_clips;
0192 
0193     /**
0194      * @src:
0195      *
0196      * source coordinates of the plane (in 16.16).
0197      *
0198      * When using drm_atomic_helper_check_plane_state(),
0199      * the coordinates are clipped, but the driver may choose
0200      * to use unclipped coordinates instead when the hardware
0201      * performs the clipping automatically.
0202      */
0203     /**
0204      * @dst:
0205      *
0206      * clipped destination coordinates of the plane.
0207      *
0208      * When using drm_atomic_helper_check_plane_state(),
0209      * the coordinates are clipped, but the driver may choose
0210      * to use unclipped coordinates instead when the hardware
0211      * performs the clipping automatically.
0212      */
0213     struct drm_rect src, dst;
0214 
0215     /**
0216      * @visible:
0217      *
0218      * Visibility of the plane. This can be false even if fb!=NULL and
0219      * crtc!=NULL, due to clipping.
0220      */
0221     bool visible;
0222 
0223     /**
0224      * @scaling_filter:
0225      *
0226      * Scaling filter to be applied
0227      */
0228     enum drm_scaling_filter scaling_filter;
0229 
0230     /**
0231      * @commit: Tracks the pending commit to prevent use-after-free conditions,
0232      * and for async plane updates.
0233      *
0234      * May be NULL.
0235      */
0236     struct drm_crtc_commit *commit;
0237 
0238     /** @state: backpointer to global drm_atomic_state */
0239     struct drm_atomic_state *state;
0240 };
0241 
0242 static inline struct drm_rect
0243 drm_plane_state_src(const struct drm_plane_state *state)
0244 {
0245     struct drm_rect src = {
0246         .x1 = state->src_x,
0247         .y1 = state->src_y,
0248         .x2 = state->src_x + state->src_w,
0249         .y2 = state->src_y + state->src_h,
0250     };
0251     return src;
0252 }
0253 
0254 static inline struct drm_rect
0255 drm_plane_state_dest(const struct drm_plane_state *state)
0256 {
0257     struct drm_rect dest = {
0258         .x1 = state->crtc_x,
0259         .y1 = state->crtc_y,
0260         .x2 = state->crtc_x + state->crtc_w,
0261         .y2 = state->crtc_y + state->crtc_h,
0262     };
0263     return dest;
0264 }
0265 
0266 /**
0267  * struct drm_plane_funcs - driver plane control functions
0268  */
0269 struct drm_plane_funcs {
0270     /**
0271      * @update_plane:
0272      *
0273      * This is the legacy entry point to enable and configure the plane for
0274      * the given CRTC and framebuffer. It is never called to disable the
0275      * plane, i.e. the passed-in crtc and fb paramters are never NULL.
0276      *
0277      * The source rectangle in frame buffer memory coordinates is given by
0278      * the src_x, src_y, src_w and src_h parameters (as 16.16 fixed point
0279      * values). Devices that don't support subpixel plane coordinates can
0280      * ignore the fractional part.
0281      *
0282      * The destination rectangle in CRTC coordinates is given by the
0283      * crtc_x, crtc_y, crtc_w and crtc_h parameters (as integer values).
0284      * Devices scale the source rectangle to the destination rectangle. If
0285      * scaling is not supported, and the source rectangle size doesn't match
0286      * the destination rectangle size, the driver must return a
0287      * -<errorname>EINVAL</errorname> error.
0288      *
0289      * Drivers implementing atomic modeset should use
0290      * drm_atomic_helper_update_plane() to implement this hook.
0291      *
0292      * RETURNS:
0293      *
0294      * 0 on success or a negative error code on failure.
0295      */
0296     int (*update_plane)(struct drm_plane *plane,
0297                 struct drm_crtc *crtc, struct drm_framebuffer *fb,
0298                 int crtc_x, int crtc_y,
0299                 unsigned int crtc_w, unsigned int crtc_h,
0300                 uint32_t src_x, uint32_t src_y,
0301                 uint32_t src_w, uint32_t src_h,
0302                 struct drm_modeset_acquire_ctx *ctx);
0303 
0304     /**
0305      * @disable_plane:
0306      *
0307      * This is the legacy entry point to disable the plane. The DRM core
0308      * calls this method in response to a DRM_IOCTL_MODE_SETPLANE IOCTL call
0309      * with the frame buffer ID set to 0.  Disabled planes must not be
0310      * processed by the CRTC.
0311      *
0312      * Drivers implementing atomic modeset should use
0313      * drm_atomic_helper_disable_plane() to implement this hook.
0314      *
0315      * RETURNS:
0316      *
0317      * 0 on success or a negative error code on failure.
0318      */
0319     int (*disable_plane)(struct drm_plane *plane,
0320                  struct drm_modeset_acquire_ctx *ctx);
0321 
0322     /**
0323      * @destroy:
0324      *
0325      * Clean up plane resources. This is only called at driver unload time
0326      * through drm_mode_config_cleanup() since a plane cannot be hotplugged
0327      * in DRM.
0328      */
0329     void (*destroy)(struct drm_plane *plane);
0330 
0331     /**
0332      * @reset:
0333      *
0334      * Reset plane hardware and software state to off. This function isn't
0335      * called by the core directly, only through drm_mode_config_reset().
0336      * It's not a helper hook only for historical reasons.
0337      *
0338      * Atomic drivers can use drm_atomic_helper_plane_reset() to reset
0339      * atomic state using this hook.
0340      */
0341     void (*reset)(struct drm_plane *plane);
0342 
0343     /**
0344      * @set_property:
0345      *
0346      * This is the legacy entry point to update a property attached to the
0347      * plane.
0348      *
0349      * This callback is optional if the driver does not support any legacy
0350      * driver-private properties. For atomic drivers it is not used because
0351      * property handling is done entirely in the DRM core.
0352      *
0353      * RETURNS:
0354      *
0355      * 0 on success or a negative error code on failure.
0356      */
0357     int (*set_property)(struct drm_plane *plane,
0358                 struct drm_property *property, uint64_t val);
0359 
0360     /**
0361      * @atomic_duplicate_state:
0362      *
0363      * Duplicate the current atomic state for this plane and return it.
0364      * The core and helpers guarantee that any atomic state duplicated with
0365      * this hook and still owned by the caller (i.e. not transferred to the
0366      * driver by calling &drm_mode_config_funcs.atomic_commit) will be
0367      * cleaned up by calling the @atomic_destroy_state hook in this
0368      * structure.
0369      *
0370      * This callback is mandatory for atomic drivers.
0371      *
0372      * Atomic drivers which don't subclass &struct drm_plane_state should use
0373      * drm_atomic_helper_plane_duplicate_state(). Drivers that subclass the
0374      * state structure to extend it with driver-private state should use
0375      * __drm_atomic_helper_plane_duplicate_state() to make sure shared state is
0376      * duplicated in a consistent fashion across drivers.
0377      *
0378      * It is an error to call this hook before &drm_plane.state has been
0379      * initialized correctly.
0380      *
0381      * NOTE:
0382      *
0383      * If the duplicate state references refcounted resources this hook must
0384      * acquire a reference for each of them. The driver must release these
0385      * references again in @atomic_destroy_state.
0386      *
0387      * RETURNS:
0388      *
0389      * Duplicated atomic state or NULL when the allocation failed.
0390      */
0391     struct drm_plane_state *(*atomic_duplicate_state)(struct drm_plane *plane);
0392 
0393     /**
0394      * @atomic_destroy_state:
0395      *
0396      * Destroy a state duplicated with @atomic_duplicate_state and release
0397      * or unreference all resources it references
0398      *
0399      * This callback is mandatory for atomic drivers.
0400      */
0401     void (*atomic_destroy_state)(struct drm_plane *plane,
0402                      struct drm_plane_state *state);
0403 
0404     /**
0405      * @atomic_set_property:
0406      *
0407      * Decode a driver-private property value and store the decoded value
0408      * into the passed-in state structure. Since the atomic core decodes all
0409      * standardized properties (even for extensions beyond the core set of
0410      * properties which might not be implemented by all drivers) this
0411      * requires drivers to subclass the state structure.
0412      *
0413      * Such driver-private properties should really only be implemented for
0414      * truly hardware/vendor specific state. Instead it is preferred to
0415      * standardize atomic extension and decode the properties used to expose
0416      * such an extension in the core.
0417      *
0418      * Do not call this function directly, use
0419      * drm_atomic_plane_set_property() instead.
0420      *
0421      * This callback is optional if the driver does not support any
0422      * driver-private atomic properties.
0423      *
0424      * NOTE:
0425      *
0426      * This function is called in the state assembly phase of atomic
0427      * modesets, which can be aborted for any reason (including on
0428      * userspace's request to just check whether a configuration would be
0429      * possible). Drivers MUST NOT touch any persistent state (hardware or
0430      * software) or data structures except the passed in @state parameter.
0431      *
0432      * Also since userspace controls in which order properties are set this
0433      * function must not do any input validation (since the state update is
0434      * incomplete and hence likely inconsistent). Instead any such input
0435      * validation must be done in the various atomic_check callbacks.
0436      *
0437      * RETURNS:
0438      *
0439      * 0 if the property has been found, -EINVAL if the property isn't
0440      * implemented by the driver (which shouldn't ever happen, the core only
0441      * asks for properties attached to this plane). No other validation is
0442      * allowed by the driver. The core already checks that the property
0443      * value is within the range (integer, valid enum value, ...) the driver
0444      * set when registering the property.
0445      */
0446     int (*atomic_set_property)(struct drm_plane *plane,
0447                    struct drm_plane_state *state,
0448                    struct drm_property *property,
0449                    uint64_t val);
0450 
0451     /**
0452      * @atomic_get_property:
0453      *
0454      * Reads out the decoded driver-private property. This is used to
0455      * implement the GETPLANE IOCTL.
0456      *
0457      * Do not call this function directly, use
0458      * drm_atomic_plane_get_property() instead.
0459      *
0460      * This callback is optional if the driver does not support any
0461      * driver-private atomic properties.
0462      *
0463      * RETURNS:
0464      *
0465      * 0 on success, -EINVAL if the property isn't implemented by the
0466      * driver (which should never happen, the core only asks for
0467      * properties attached to this plane).
0468      */
0469     int (*atomic_get_property)(struct drm_plane *plane,
0470                    const struct drm_plane_state *state,
0471                    struct drm_property *property,
0472                    uint64_t *val);
0473     /**
0474      * @late_register:
0475      *
0476      * This optional hook can be used to register additional userspace
0477      * interfaces attached to the plane like debugfs interfaces.
0478      * It is called late in the driver load sequence from drm_dev_register().
0479      * Everything added from this callback should be unregistered in
0480      * the early_unregister callback.
0481      *
0482      * Returns:
0483      *
0484      * 0 on success, or a negative error code on failure.
0485      */
0486     int (*late_register)(struct drm_plane *plane);
0487 
0488     /**
0489      * @early_unregister:
0490      *
0491      * This optional hook should be used to unregister the additional
0492      * userspace interfaces attached to the plane from
0493      * @late_register. It is called from drm_dev_unregister(),
0494      * early in the driver unload sequence to disable userspace access
0495      * before data structures are torndown.
0496      */
0497     void (*early_unregister)(struct drm_plane *plane);
0498 
0499     /**
0500      * @atomic_print_state:
0501      *
0502      * If driver subclasses &struct drm_plane_state, it should implement
0503      * this optional hook for printing additional driver specific state.
0504      *
0505      * Do not call this directly, use drm_atomic_plane_print_state()
0506      * instead.
0507      */
0508     void (*atomic_print_state)(struct drm_printer *p,
0509                    const struct drm_plane_state *state);
0510 
0511     /**
0512      * @format_mod_supported:
0513      *
0514      * This optional hook is used for the DRM to determine if the given
0515      * format/modifier combination is valid for the plane. This allows the
0516      * DRM to generate the correct format bitmask (which formats apply to
0517      * which modifier), and to validate modifiers at atomic_check time.
0518      *
0519      * If not present, then any modifier in the plane's modifier
0520      * list is allowed with any of the plane's formats.
0521      *
0522      * Returns:
0523      *
0524      * True if the given modifier is valid for that format on the plane.
0525      * False otherwise.
0526      */
0527     bool (*format_mod_supported)(struct drm_plane *plane, uint32_t format,
0528                      uint64_t modifier);
0529 };
0530 
0531 /**
0532  * enum drm_plane_type - uapi plane type enumeration
0533  *
0534  * For historical reasons not all planes are made the same. This enumeration is
0535  * used to tell the different types of planes apart to implement the different
0536  * uapi semantics for them. For userspace which is universal plane aware and
0537  * which is using that atomic IOCTL there's no difference between these planes
0538  * (beyong what the driver and hardware can support of course).
0539  *
0540  * For compatibility with legacy userspace, only overlay planes are made
0541  * available to userspace by default. Userspace clients may set the
0542  * &DRM_CLIENT_CAP_UNIVERSAL_PLANES client capability bit to indicate that they
0543  * wish to receive a universal plane list containing all plane types. See also
0544  * drm_for_each_legacy_plane().
0545  *
0546  * In addition to setting each plane's type, drivers need to setup the
0547  * &drm_crtc.primary and optionally &drm_crtc.cursor pointers for legacy
0548  * IOCTLs. See drm_crtc_init_with_planes().
0549  *
0550  * WARNING: The values of this enum is UABI since they're exposed in the "type"
0551  * property.
0552  */
0553 enum drm_plane_type {
0554     /**
0555      * @DRM_PLANE_TYPE_OVERLAY:
0556      *
0557      * Overlay planes represent all non-primary, non-cursor planes. Some
0558      * drivers refer to these types of planes as "sprites" internally.
0559      */
0560     DRM_PLANE_TYPE_OVERLAY,
0561 
0562     /**
0563      * @DRM_PLANE_TYPE_PRIMARY:
0564      *
0565      * A primary plane attached to a CRTC is the most likely to be able to
0566      * light up the CRTC when no scaling/cropping is used and the plane
0567      * covers the whole CRTC.
0568      */
0569     DRM_PLANE_TYPE_PRIMARY,
0570 
0571     /**
0572      * @DRM_PLANE_TYPE_CURSOR:
0573      *
0574      * A cursor plane attached to a CRTC is more likely to be able to be
0575      * enabled when no scaling/cropping is used and the framebuffer has the
0576      * size indicated by &drm_mode_config.cursor_width and
0577      * &drm_mode_config.cursor_height. Additionally, if the driver doesn't
0578      * support modifiers, the framebuffer should have a linear layout.
0579      */
0580     DRM_PLANE_TYPE_CURSOR,
0581 };
0582 
0583 
0584 /**
0585  * struct drm_plane - central DRM plane control structure
0586  *
0587  * Planes represent the scanout hardware of a display block. They receive their
0588  * input data from a &drm_framebuffer and feed it to a &drm_crtc. Planes control
0589  * the color conversion, see `Plane Composition Properties`_ for more details,
0590  * and are also involved in the color conversion of input pixels, see `Color
0591  * Management Properties`_ for details on that.
0592  */
0593 struct drm_plane {
0594     /** @dev: DRM device this plane belongs to */
0595     struct drm_device *dev;
0596 
0597     /**
0598      * @head:
0599      *
0600      * List of all planes on @dev, linked from &drm_mode_config.plane_list.
0601      * Invariant over the lifetime of @dev and therefore does not need
0602      * locking.
0603      */
0604     struct list_head head;
0605 
0606     /** @name: human readable name, can be overwritten by the driver */
0607     char *name;
0608 
0609     /**
0610      * @mutex:
0611      *
0612      * Protects modeset plane state, together with the &drm_crtc.mutex of
0613      * CRTC this plane is linked to (when active, getting activated or
0614      * getting disabled).
0615      *
0616      * For atomic drivers specifically this protects @state.
0617      */
0618     struct drm_modeset_lock mutex;
0619 
0620     /** @base: base mode object */
0621     struct drm_mode_object base;
0622 
0623     /**
0624      * @possible_crtcs: pipes this plane can be bound to constructed from
0625      * drm_crtc_mask()
0626      */
0627     uint32_t possible_crtcs;
0628     /** @format_types: array of formats supported by this plane */
0629     uint32_t *format_types;
0630     /** @format_count: Size of the array pointed at by @format_types. */
0631     unsigned int format_count;
0632     /**
0633      * @format_default: driver hasn't supplied supported formats for the
0634      * plane. Used by the drm_plane_init compatibility wrapper only.
0635      */
0636     bool format_default;
0637 
0638     /** @modifiers: array of modifiers supported by this plane */
0639     uint64_t *modifiers;
0640     /** @modifier_count: Size of the array pointed at by @modifier_count. */
0641     unsigned int modifier_count;
0642 
0643     /**
0644      * @crtc:
0645      *
0646      * Currently bound CRTC, only meaningful for non-atomic drivers. For
0647      * atomic drivers this is forced to be NULL, atomic drivers should
0648      * instead check &drm_plane_state.crtc.
0649      */
0650     struct drm_crtc *crtc;
0651 
0652     /**
0653      * @fb:
0654      *
0655      * Currently bound framebuffer, only meaningful for non-atomic drivers.
0656      * For atomic drivers this is forced to be NULL, atomic drivers should
0657      * instead check &drm_plane_state.fb.
0658      */
0659     struct drm_framebuffer *fb;
0660 
0661     /**
0662      * @old_fb:
0663      *
0664      * Temporary tracking of the old fb while a modeset is ongoing. Only
0665      * used by non-atomic drivers, forced to be NULL for atomic drivers.
0666      */
0667     struct drm_framebuffer *old_fb;
0668 
0669     /** @funcs: plane control functions */
0670     const struct drm_plane_funcs *funcs;
0671 
0672     /** @properties: property tracking for this plane */
0673     struct drm_object_properties properties;
0674 
0675     /** @type: Type of plane, see &enum drm_plane_type for details. */
0676     enum drm_plane_type type;
0677 
0678     /**
0679      * @index: Position inside the mode_config.list, can be used as an array
0680      * index. It is invariant over the lifetime of the plane.
0681      */
0682     unsigned index;
0683 
0684     /** @helper_private: mid-layer private data */
0685     const struct drm_plane_helper_funcs *helper_private;
0686 
0687     /**
0688      * @state:
0689      *
0690      * Current atomic state for this plane.
0691      *
0692      * This is protected by @mutex. Note that nonblocking atomic commits
0693      * access the current plane state without taking locks. Either by going
0694      * through the &struct drm_atomic_state pointers, see
0695      * for_each_oldnew_plane_in_state(), for_each_old_plane_in_state() and
0696      * for_each_new_plane_in_state(). Or through careful ordering of atomic
0697      * commit operations as implemented in the atomic helpers, see
0698      * &struct drm_crtc_commit.
0699      */
0700     struct drm_plane_state *state;
0701 
0702     /**
0703      * @alpha_property:
0704      * Optional alpha property for this plane. See
0705      * drm_plane_create_alpha_property().
0706      */
0707     struct drm_property *alpha_property;
0708     /**
0709      * @zpos_property:
0710      * Optional zpos property for this plane. See
0711      * drm_plane_create_zpos_property().
0712      */
0713     struct drm_property *zpos_property;
0714     /**
0715      * @rotation_property:
0716      * Optional rotation property for this plane. See
0717      * drm_plane_create_rotation_property().
0718      */
0719     struct drm_property *rotation_property;
0720     /**
0721      * @blend_mode_property:
0722      * Optional "pixel blend mode" enum property for this plane.
0723      * Blend mode property represents the alpha blending equation selection,
0724      * describing how the pixels from the current plane are composited with
0725      * the background.
0726      */
0727     struct drm_property *blend_mode_property;
0728 
0729     /**
0730      * @color_encoding_property:
0731      *
0732      * Optional "COLOR_ENCODING" enum property for specifying
0733      * color encoding for non RGB formats.
0734      * See drm_plane_create_color_properties().
0735      */
0736     struct drm_property *color_encoding_property;
0737     /**
0738      * @color_range_property:
0739      *
0740      * Optional "COLOR_RANGE" enum property for specifying
0741      * color range for non RGB formats.
0742      * See drm_plane_create_color_properties().
0743      */
0744     struct drm_property *color_range_property;
0745 
0746     /**
0747      * @scaling_filter_property: property to apply a particular filter while
0748      * scaling.
0749      */
0750     struct drm_property *scaling_filter_property;
0751 };
0752 
0753 #define obj_to_plane(x) container_of(x, struct drm_plane, base)
0754 
0755 __printf(9, 10)
0756 int drm_universal_plane_init(struct drm_device *dev,
0757                  struct drm_plane *plane,
0758                  uint32_t possible_crtcs,
0759                  const struct drm_plane_funcs *funcs,
0760                  const uint32_t *formats,
0761                  unsigned int format_count,
0762                  const uint64_t *format_modifiers,
0763                  enum drm_plane_type type,
0764                  const char *name, ...);
0765 int drm_plane_init(struct drm_device *dev,
0766            struct drm_plane *plane,
0767            uint32_t possible_crtcs,
0768            const struct drm_plane_funcs *funcs,
0769            const uint32_t *formats, unsigned int format_count,
0770            bool is_primary);
0771 void drm_plane_cleanup(struct drm_plane *plane);
0772 
0773 __printf(10, 11)
0774 void *__drmm_universal_plane_alloc(struct drm_device *dev,
0775                    size_t size, size_t offset,
0776                    uint32_t possible_crtcs,
0777                    const struct drm_plane_funcs *funcs,
0778                    const uint32_t *formats,
0779                    unsigned int format_count,
0780                    const uint64_t *format_modifiers,
0781                    enum drm_plane_type plane_type,
0782                    const char *name, ...);
0783 
0784 /**
0785  * drmm_universal_plane_alloc - Allocate and initialize an universal plane object
0786  * @dev: DRM device
0787  * @type: the type of the struct which contains struct &drm_plane
0788  * @member: the name of the &drm_plane within @type
0789  * @possible_crtcs: bitmask of possible CRTCs
0790  * @funcs: callbacks for the new plane
0791  * @formats: array of supported formats (DRM_FORMAT\_\*)
0792  * @format_count: number of elements in @formats
0793  * @format_modifiers: array of struct drm_format modifiers terminated by
0794  *                    DRM_FORMAT_MOD_INVALID
0795  * @plane_type: type of plane (overlay, primary, cursor)
0796  * @name: printf style format string for the plane name, or NULL for default name
0797  *
0798  * Allocates and initializes a plane object of type @type. Cleanup is
0799  * automatically handled through registering drm_plane_cleanup() with
0800  * drmm_add_action().
0801  *
0802  * The @drm_plane_funcs.destroy hook must be NULL.
0803  *
0804  * Drivers that only support the DRM_FORMAT_MOD_LINEAR modifier support may set
0805  * @format_modifiers to NULL. The plane will advertise the linear modifier.
0806  *
0807  * Returns:
0808  * Pointer to new plane, or ERR_PTR on failure.
0809  */
0810 #define drmm_universal_plane_alloc(dev, type, member, possible_crtcs, funcs, formats, \
0811                    format_count, format_modifiers, plane_type, name, ...) \
0812     ((type *)__drmm_universal_plane_alloc(dev, sizeof(type), \
0813                           offsetof(type, member), \
0814                           possible_crtcs, funcs, formats, \
0815                           format_count, format_modifiers, \
0816                           plane_type, name, ##__VA_ARGS__))
0817 
0818 /**
0819  * drm_plane_index - find the index of a registered plane
0820  * @plane: plane to find index for
0821  *
0822  * Given a registered plane, return the index of that plane within a DRM
0823  * device's list of planes.
0824  */
0825 static inline unsigned int drm_plane_index(const struct drm_plane *plane)
0826 {
0827     return plane->index;
0828 }
0829 
0830 /**
0831  * drm_plane_mask - find the mask of a registered plane
0832  * @plane: plane to find mask for
0833  */
0834 static inline u32 drm_plane_mask(const struct drm_plane *plane)
0835 {
0836     return 1 << drm_plane_index(plane);
0837 }
0838 
0839 struct drm_plane * drm_plane_from_index(struct drm_device *dev, int idx);
0840 void drm_plane_force_disable(struct drm_plane *plane);
0841 
0842 int drm_mode_plane_set_obj_prop(struct drm_plane *plane,
0843                        struct drm_property *property,
0844                        uint64_t value);
0845 
0846 /**
0847  * drm_plane_find - find a &drm_plane
0848  * @dev: DRM device
0849  * @file_priv: drm file to check for lease against.
0850  * @id: plane id
0851  *
0852  * Returns the plane with @id, NULL if it doesn't exist. Simple wrapper around
0853  * drm_mode_object_find().
0854  */
0855 static inline struct drm_plane *drm_plane_find(struct drm_device *dev,
0856         struct drm_file *file_priv,
0857         uint32_t id)
0858 {
0859     struct drm_mode_object *mo;
0860     mo = drm_mode_object_find(dev, file_priv, id, DRM_MODE_OBJECT_PLANE);
0861     return mo ? obj_to_plane(mo) : NULL;
0862 }
0863 
0864 /**
0865  * drm_for_each_plane_mask - iterate over planes specified by bitmask
0866  * @plane: the loop cursor
0867  * @dev: the DRM device
0868  * @plane_mask: bitmask of plane indices
0869  *
0870  * Iterate over all planes specified by bitmask.
0871  */
0872 #define drm_for_each_plane_mask(plane, dev, plane_mask) \
0873     list_for_each_entry((plane), &(dev)->mode_config.plane_list, head) \
0874         for_each_if ((plane_mask) & drm_plane_mask(plane))
0875 
0876 /**
0877  * drm_for_each_legacy_plane - iterate over all planes for legacy userspace
0878  * @plane: the loop cursor
0879  * @dev: the DRM device
0880  *
0881  * Iterate over all legacy planes of @dev, excluding primary and cursor planes.
0882  * This is useful for implementing userspace apis when userspace is not
0883  * universal plane aware. See also &enum drm_plane_type.
0884  */
0885 #define drm_for_each_legacy_plane(plane, dev) \
0886     list_for_each_entry(plane, &(dev)->mode_config.plane_list, head) \
0887         for_each_if (plane->type == DRM_PLANE_TYPE_OVERLAY)
0888 
0889 /**
0890  * drm_for_each_plane - iterate over all planes
0891  * @plane: the loop cursor
0892  * @dev: the DRM device
0893  *
0894  * Iterate over all planes of @dev, include primary and cursor planes.
0895  */
0896 #define drm_for_each_plane(plane, dev) \
0897     list_for_each_entry(plane, &(dev)->mode_config.plane_list, head)
0898 
0899 bool drm_any_plane_has_format(struct drm_device *dev,
0900                   u32 format, u64 modifier);
0901 
0902 void drm_plane_enable_fb_damage_clips(struct drm_plane *plane);
0903 unsigned int
0904 drm_plane_get_damage_clips_count(const struct drm_plane_state *state);
0905 struct drm_mode_rect *
0906 drm_plane_get_damage_clips(const struct drm_plane_state *state);
0907 
0908 int drm_plane_create_scaling_filter_property(struct drm_plane *plane,
0909                          unsigned int supported_filters);
0910 
0911 #endif