Daniel Vetter | 43968d7 | 2016-09-21 10:59:24 +0200 | [diff] [blame] | 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> |
Jyri Sarha | 80f690e | 2018-02-19 22:28:23 +0200 | [diff] [blame] | 29 | #include <drm/drm_color_mgmt.h> |
Daniel Vetter | 43968d7 | 2016-09-21 10:59:24 +0200 | [diff] [blame] | 30 | |
| 31 | struct drm_crtc; |
Rob Clark | fceffb32 | 2016-11-05 11:08:09 -0400 | [diff] [blame] | 32 | struct drm_printer; |
Daniel Vetter | 34a2ab5 | 2017-03-22 22:50:41 +0100 | [diff] [blame] | 33 | struct drm_modeset_acquire_ctx; |
Daniel Vetter | 43968d7 | 2016-09-21 10:59:24 +0200 | [diff] [blame] | 34 | |
| 35 | /** |
| 36 | * struct drm_plane_state - mutable plane state |
| 37 | * @plane: backpointer to the plane |
Daniel Vetter | 43968d7 | 2016-09-21 10:59:24 +0200 | [diff] [blame] | 38 | * @crtc_w: width of visible portion of plane on crtc |
| 39 | * @crtc_h: height of visible portion of plane on crtc |
| 40 | * @src_x: left position of visible portion of plane within |
| 41 | * plane (in 16.16) |
| 42 | * @src_y: upper position of visible portion of plane within |
| 43 | * plane (in 16.16) |
| 44 | * @src_w: width of visible portion of plane (in 16.16) |
| 45 | * @src_h: height of visible portion of plane (in 16.16) |
Maxime Ripard | ae0e282 | 2018-04-11 09:39:25 +0200 | [diff] [blame] | 46 | * @alpha: opacity of the plane |
Daniel Vetter | 43968d7 | 2016-09-21 10:59:24 +0200 | [diff] [blame] | 47 | * @rotation: rotation of the plane |
| 48 | * @zpos: priority of the given plane on crtc (optional) |
Ville Syrjälä | 38d868e | 2016-10-10 17:50:56 +0300 | [diff] [blame] | 49 | * Note that multiple active planes on the same crtc can have an identical |
| 50 | * zpos value. The rule to solving the conflict is to compare the plane |
| 51 | * object IDs; the plane with a higher ID must be stacked on top of a |
| 52 | * plane with a lower ID. |
Daniel Vetter | 43968d7 | 2016-09-21 10:59:24 +0200 | [diff] [blame] | 53 | * @normalized_zpos: normalized value of zpos: unique, range from 0 to N-1 |
Ville Syrjälä | 38d868e | 2016-10-10 17:50:56 +0300 | [diff] [blame] | 54 | * where N is the number of active planes for given crtc. Note that |
Peter Ujfalusi | 49efffc | 2018-03-21 12:20:24 +0200 | [diff] [blame] | 55 | * the driver must set drm_mode_config.normalize_zpos or call |
| 56 | * drm_atomic_normalize_zpos() to update this before it can be trusted. |
Daniel Vetter | 43968d7 | 2016-09-21 10:59:24 +0200 | [diff] [blame] | 57 | * @src: clipped source coordinates of the plane (in 16.16) |
| 58 | * @dst: clipped destination coordinates of the plane |
Daniel Vetter | 43968d7 | 2016-09-21 10:59:24 +0200 | [diff] [blame] | 59 | * @state: backpointer to global drm_atomic_state |
| 60 | */ |
| 61 | struct drm_plane_state { |
| 62 | struct drm_plane *plane; |
| 63 | |
Gustavo Padovan | 3835b46 | 2016-11-07 19:03:33 +0900 | [diff] [blame] | 64 | /** |
| 65 | * @crtc: |
| 66 | * |
| 67 | * Currently bound CRTC, NULL if disabled. Do not this write directly, |
| 68 | * use drm_atomic_set_crtc_for_plane() |
| 69 | */ |
| 70 | struct drm_crtc *crtc; |
Daniel Vetter | 43968d7 | 2016-09-21 10:59:24 +0200 | [diff] [blame] | 71 | |
Gustavo Padovan | 3835b46 | 2016-11-07 19:03:33 +0900 | [diff] [blame] | 72 | /** |
| 73 | * @fb: |
| 74 | * |
| 75 | * Currently bound framebuffer. Do not write this directly, use |
| 76 | * drm_atomic_set_fb_for_plane() |
| 77 | */ |
| 78 | struct drm_framebuffer *fb; |
| 79 | |
| 80 | /** |
| 81 | * @fence: |
| 82 | * |
Daniel Vetter | 30d23f2 | 2018-04-05 17:44:46 +0200 | [diff] [blame] | 83 | * Optional fence to wait for before scanning out @fb. The core atomic |
| 84 | * code will set this when userspace is using explicit fencing. Do not |
| 85 | * write this directly for a driver's implicit fence, use |
| 86 | * drm_atomic_set_fence_for_plane() to ensure that an explicit fence is |
| 87 | * preserved. |
| 88 | * |
| 89 | * Drivers should store any implicit fence in this from their |
| 90 | * &drm_plane_helper.prepare_fb callback. See drm_gem_fb_prepare_fb() |
| 91 | * and drm_gem_fb_simple_display_pipe_prepare_fb() for suitable helpers. |
Gustavo Padovan | 3835b46 | 2016-11-07 19:03:33 +0900 | [diff] [blame] | 92 | */ |
Daniel Vetter | 43968d7 | 2016-09-21 10:59:24 +0200 | [diff] [blame] | 93 | struct dma_fence *fence; |
| 94 | |
Gustavo Padovan | 3835b46 | 2016-11-07 19:03:33 +0900 | [diff] [blame] | 95 | /** |
| 96 | * @crtc_x: |
| 97 | * |
| 98 | * Left position of visible portion of plane on crtc, signed dest |
| 99 | * location allows it to be partially off screen. |
| 100 | */ |
| 101 | |
| 102 | int32_t crtc_x; |
| 103 | /** |
| 104 | * @crtc_y: |
| 105 | * |
| 106 | * Upper position of visible portion of plane on crtc, signed dest |
| 107 | * location allows it to be partially off screen. |
| 108 | */ |
| 109 | int32_t crtc_y; |
| 110 | |
Daniel Vetter | 43968d7 | 2016-09-21 10:59:24 +0200 | [diff] [blame] | 111 | uint32_t crtc_w, crtc_h; |
| 112 | |
| 113 | /* Source values are 16.16 fixed point */ |
| 114 | uint32_t src_x, src_y; |
| 115 | uint32_t src_h, src_w; |
| 116 | |
Maxime Ripard | ae0e282 | 2018-04-11 09:39:25 +0200 | [diff] [blame] | 117 | /* Plane opacity */ |
| 118 | u16 alpha; |
| 119 | |
Daniel Vetter | 43968d7 | 2016-09-21 10:59:24 +0200 | [diff] [blame] | 120 | /* Plane rotation */ |
| 121 | unsigned int rotation; |
| 122 | |
| 123 | /* Plane zpos */ |
| 124 | unsigned int zpos; |
| 125 | unsigned int normalized_zpos; |
| 126 | |
Jyri Sarha | 80f690e | 2018-02-19 22:28:23 +0200 | [diff] [blame] | 127 | /** |
| 128 | * @color_encoding: |
| 129 | * |
| 130 | * Color encoding for non RGB formats |
| 131 | */ |
| 132 | enum drm_color_encoding color_encoding; |
| 133 | |
| 134 | /** |
| 135 | * @color_range: |
| 136 | * |
| 137 | * Color range for non RGB formats |
| 138 | */ |
| 139 | enum drm_color_range color_range; |
| 140 | |
Daniel Vetter | 43968d7 | 2016-09-21 10:59:24 +0200 | [diff] [blame] | 141 | /* Clipped coordinates */ |
| 142 | struct drm_rect src, dst; |
| 143 | |
Gustavo Padovan | 3835b46 | 2016-11-07 19:03:33 +0900 | [diff] [blame] | 144 | /** |
| 145 | * @visible: |
| 146 | * |
| 147 | * Visibility of the plane. This can be false even if fb!=NULL and |
| 148 | * crtc!=NULL, due to clipping. |
Daniel Vetter | 43968d7 | 2016-09-21 10:59:24 +0200 | [diff] [blame] | 149 | */ |
| 150 | bool visible; |
| 151 | |
Maarten Lankhorst | 21a01ab | 2017-09-04 12:48:37 +0200 | [diff] [blame] | 152 | /** |
Maarten Lankhorst | 669c921 | 2017-09-04 12:48:38 +0200 | [diff] [blame] | 153 | * @commit: Tracks the pending commit to prevent use-after-free conditions, |
| 154 | * and for async plane updates. |
Maarten Lankhorst | 21a01ab | 2017-09-04 12:48:37 +0200 | [diff] [blame] | 155 | * |
Maarten Lankhorst | 669c921 | 2017-09-04 12:48:38 +0200 | [diff] [blame] | 156 | * May be NULL. |
Maarten Lankhorst | 21a01ab | 2017-09-04 12:48:37 +0200 | [diff] [blame] | 157 | */ |
| 158 | struct drm_crtc_commit *commit; |
| 159 | |
Daniel Vetter | 43968d7 | 2016-09-21 10:59:24 +0200 | [diff] [blame] | 160 | struct drm_atomic_state *state; |
| 161 | }; |
| 162 | |
Rob Clark | 1638d30 | 2016-11-05 11:08:08 -0400 | [diff] [blame] | 163 | static inline struct drm_rect |
| 164 | drm_plane_state_src(const struct drm_plane_state *state) |
| 165 | { |
| 166 | struct drm_rect src = { |
| 167 | .x1 = state->src_x, |
| 168 | .y1 = state->src_y, |
| 169 | .x2 = state->src_x + state->src_w, |
| 170 | .y2 = state->src_y + state->src_h, |
| 171 | }; |
| 172 | return src; |
| 173 | } |
| 174 | |
| 175 | static inline struct drm_rect |
| 176 | drm_plane_state_dest(const struct drm_plane_state *state) |
| 177 | { |
| 178 | struct drm_rect dest = { |
| 179 | .x1 = state->crtc_x, |
| 180 | .y1 = state->crtc_y, |
| 181 | .x2 = state->crtc_x + state->crtc_w, |
| 182 | .y2 = state->crtc_y + state->crtc_h, |
| 183 | }; |
| 184 | return dest; |
| 185 | } |
| 186 | |
Daniel Vetter | 43968d7 | 2016-09-21 10:59:24 +0200 | [diff] [blame] | 187 | /** |
| 188 | * struct drm_plane_funcs - driver plane control functions |
| 189 | */ |
| 190 | struct drm_plane_funcs { |
| 191 | /** |
| 192 | * @update_plane: |
| 193 | * |
| 194 | * This is the legacy entry point to enable and configure the plane for |
| 195 | * the given CRTC and framebuffer. It is never called to disable the |
| 196 | * plane, i.e. the passed-in crtc and fb paramters are never NULL. |
| 197 | * |
| 198 | * The source rectangle in frame buffer memory coordinates is given by |
| 199 | * the src_x, src_y, src_w and src_h parameters (as 16.16 fixed point |
| 200 | * values). Devices that don't support subpixel plane coordinates can |
| 201 | * ignore the fractional part. |
| 202 | * |
| 203 | * The destination rectangle in CRTC coordinates is given by the |
| 204 | * crtc_x, crtc_y, crtc_w and crtc_h parameters (as integer values). |
| 205 | * Devices scale the source rectangle to the destination rectangle. If |
| 206 | * scaling is not supported, and the source rectangle size doesn't match |
| 207 | * the destination rectangle size, the driver must return a |
| 208 | * -<errorname>EINVAL</errorname> error. |
| 209 | * |
| 210 | * Drivers implementing atomic modeset should use |
| 211 | * drm_atomic_helper_update_plane() to implement this hook. |
| 212 | * |
| 213 | * RETURNS: |
| 214 | * |
| 215 | * 0 on success or a negative error code on failure. |
| 216 | */ |
| 217 | int (*update_plane)(struct drm_plane *plane, |
| 218 | struct drm_crtc *crtc, struct drm_framebuffer *fb, |
| 219 | int crtc_x, int crtc_y, |
| 220 | unsigned int crtc_w, unsigned int crtc_h, |
| 221 | uint32_t src_x, uint32_t src_y, |
Daniel Vetter | 34a2ab5 | 2017-03-22 22:50:41 +0100 | [diff] [blame] | 222 | uint32_t src_w, uint32_t src_h, |
| 223 | struct drm_modeset_acquire_ctx *ctx); |
Daniel Vetter | 43968d7 | 2016-09-21 10:59:24 +0200 | [diff] [blame] | 224 | |
| 225 | /** |
| 226 | * @disable_plane: |
| 227 | * |
| 228 | * This is the legacy entry point to disable the plane. The DRM core |
| 229 | * calls this method in response to a DRM_IOCTL_MODE_SETPLANE IOCTL call |
| 230 | * with the frame buffer ID set to 0. Disabled planes must not be |
| 231 | * processed by the CRTC. |
| 232 | * |
| 233 | * Drivers implementing atomic modeset should use |
| 234 | * drm_atomic_helper_disable_plane() to implement this hook. |
| 235 | * |
| 236 | * RETURNS: |
| 237 | * |
| 238 | * 0 on success or a negative error code on failure. |
| 239 | */ |
Daniel Vetter | 1931529 | 2017-03-22 22:50:43 +0100 | [diff] [blame] | 240 | int (*disable_plane)(struct drm_plane *plane, |
| 241 | struct drm_modeset_acquire_ctx *ctx); |
Daniel Vetter | 43968d7 | 2016-09-21 10:59:24 +0200 | [diff] [blame] | 242 | |
| 243 | /** |
| 244 | * @destroy: |
| 245 | * |
| 246 | * Clean up plane resources. This is only called at driver unload time |
| 247 | * through drm_mode_config_cleanup() since a plane cannot be hotplugged |
| 248 | * in DRM. |
| 249 | */ |
| 250 | void (*destroy)(struct drm_plane *plane); |
| 251 | |
| 252 | /** |
| 253 | * @reset: |
| 254 | * |
| 255 | * Reset plane hardware and software state to off. This function isn't |
| 256 | * called by the core directly, only through drm_mode_config_reset(). |
| 257 | * It's not a helper hook only for historical reasons. |
| 258 | * |
| 259 | * Atomic drivers can use drm_atomic_helper_plane_reset() to reset |
| 260 | * atomic state using this hook. |
| 261 | */ |
| 262 | void (*reset)(struct drm_plane *plane); |
| 263 | |
| 264 | /** |
| 265 | * @set_property: |
| 266 | * |
| 267 | * This is the legacy entry point to update a property attached to the |
| 268 | * plane. |
| 269 | * |
Daniel Vetter | 43968d7 | 2016-09-21 10:59:24 +0200 | [diff] [blame] | 270 | * This callback is optional if the driver does not support any legacy |
Daniel Vetter | 144a799 | 2017-07-25 14:02:04 +0200 | [diff] [blame] | 271 | * driver-private properties. For atomic drivers it is not used because |
| 272 | * property handling is done entirely in the DRM core. |
Daniel Vetter | 43968d7 | 2016-09-21 10:59:24 +0200 | [diff] [blame] | 273 | * |
| 274 | * RETURNS: |
| 275 | * |
| 276 | * 0 on success or a negative error code on failure. |
| 277 | */ |
| 278 | int (*set_property)(struct drm_plane *plane, |
| 279 | struct drm_property *property, uint64_t val); |
| 280 | |
| 281 | /** |
| 282 | * @atomic_duplicate_state: |
| 283 | * |
| 284 | * Duplicate the current atomic state for this plane and return it. |
Daniel Vetter | d574528 | 2017-01-25 07:26:45 +0100 | [diff] [blame] | 285 | * The core and helpers guarantee that any atomic state duplicated with |
Daniel Vetter | 43968d7 | 2016-09-21 10:59:24 +0200 | [diff] [blame] | 286 | * this hook and still owned by the caller (i.e. not transferred to the |
Daniel Vetter | d574528 | 2017-01-25 07:26:45 +0100 | [diff] [blame] | 287 | * driver by calling &drm_mode_config_funcs.atomic_commit) will be |
| 288 | * cleaned up by calling the @atomic_destroy_state hook in this |
| 289 | * structure. |
Daniel Vetter | 43968d7 | 2016-09-21 10:59:24 +0200 | [diff] [blame] | 290 | * |
Haneen Mohammed | ba1f665 | 2018-05-25 04:25:55 +0300 | [diff] [blame^] | 291 | * This callback is mandatory for atomic drivers. |
| 292 | * |
Daniel Vetter | ea0dd85 | 2016-12-29 21:48:26 +0100 | [diff] [blame] | 293 | * Atomic drivers which don't subclass &struct drm_plane_state should use |
Daniel Vetter | 43968d7 | 2016-09-21 10:59:24 +0200 | [diff] [blame] | 294 | * drm_atomic_helper_plane_duplicate_state(). Drivers that subclass the |
| 295 | * state structure to extend it with driver-private state should use |
| 296 | * __drm_atomic_helper_plane_duplicate_state() to make sure shared state is |
| 297 | * duplicated in a consistent fashion across drivers. |
| 298 | * |
Daniel Vetter | d574528 | 2017-01-25 07:26:45 +0100 | [diff] [blame] | 299 | * It is an error to call this hook before &drm_plane.state has been |
Daniel Vetter | 43968d7 | 2016-09-21 10:59:24 +0200 | [diff] [blame] | 300 | * initialized correctly. |
| 301 | * |
| 302 | * NOTE: |
| 303 | * |
| 304 | * If the duplicate state references refcounted resources this hook must |
| 305 | * acquire a reference for each of them. The driver must release these |
| 306 | * references again in @atomic_destroy_state. |
| 307 | * |
| 308 | * RETURNS: |
| 309 | * |
| 310 | * Duplicated atomic state or NULL when the allocation failed. |
| 311 | */ |
| 312 | struct drm_plane_state *(*atomic_duplicate_state)(struct drm_plane *plane); |
| 313 | |
| 314 | /** |
| 315 | * @atomic_destroy_state: |
| 316 | * |
| 317 | * Destroy a state duplicated with @atomic_duplicate_state and release |
| 318 | * or unreference all resources it references |
Haneen Mohammed | ba1f665 | 2018-05-25 04:25:55 +0300 | [diff] [blame^] | 319 | * |
| 320 | * This callback is mandatory for atomic drivers. |
Daniel Vetter | 43968d7 | 2016-09-21 10:59:24 +0200 | [diff] [blame] | 321 | */ |
| 322 | void (*atomic_destroy_state)(struct drm_plane *plane, |
| 323 | struct drm_plane_state *state); |
| 324 | |
| 325 | /** |
| 326 | * @atomic_set_property: |
| 327 | * |
| 328 | * Decode a driver-private property value and store the decoded value |
| 329 | * into the passed-in state structure. Since the atomic core decodes all |
| 330 | * standardized properties (even for extensions beyond the core set of |
| 331 | * properties which might not be implemented by all drivers) this |
| 332 | * requires drivers to subclass the state structure. |
| 333 | * |
| 334 | * Such driver-private properties should really only be implemented for |
| 335 | * truly hardware/vendor specific state. Instead it is preferred to |
| 336 | * standardize atomic extension and decode the properties used to expose |
| 337 | * such an extension in the core. |
| 338 | * |
| 339 | * Do not call this function directly, use |
| 340 | * drm_atomic_plane_set_property() instead. |
| 341 | * |
| 342 | * This callback is optional if the driver does not support any |
| 343 | * driver-private atomic properties. |
| 344 | * |
| 345 | * NOTE: |
| 346 | * |
| 347 | * This function is called in the state assembly phase of atomic |
| 348 | * modesets, which can be aborted for any reason (including on |
| 349 | * userspace's request to just check whether a configuration would be |
| 350 | * possible). Drivers MUST NOT touch any persistent state (hardware or |
| 351 | * software) or data structures except the passed in @state parameter. |
| 352 | * |
| 353 | * Also since userspace controls in which order properties are set this |
| 354 | * function must not do any input validation (since the state update is |
| 355 | * incomplete and hence likely inconsistent). Instead any such input |
| 356 | * validation must be done in the various atomic_check callbacks. |
| 357 | * |
| 358 | * RETURNS: |
| 359 | * |
| 360 | * 0 if the property has been found, -EINVAL if the property isn't |
| 361 | * implemented by the driver (which shouldn't ever happen, the core only |
| 362 | * asks for properties attached to this plane). No other validation is |
| 363 | * allowed by the driver. The core already checks that the property |
| 364 | * value is within the range (integer, valid enum value, ...) the driver |
| 365 | * set when registering the property. |
| 366 | */ |
| 367 | int (*atomic_set_property)(struct drm_plane *plane, |
| 368 | struct drm_plane_state *state, |
| 369 | struct drm_property *property, |
| 370 | uint64_t val); |
| 371 | |
| 372 | /** |
| 373 | * @atomic_get_property: |
| 374 | * |
| 375 | * Reads out the decoded driver-private property. This is used to |
| 376 | * implement the GETPLANE IOCTL. |
| 377 | * |
| 378 | * Do not call this function directly, use |
| 379 | * drm_atomic_plane_get_property() instead. |
| 380 | * |
| 381 | * This callback is optional if the driver does not support any |
| 382 | * driver-private atomic properties. |
| 383 | * |
| 384 | * RETURNS: |
| 385 | * |
| 386 | * 0 on success, -EINVAL if the property isn't implemented by the |
| 387 | * driver (which should never happen, the core only asks for |
| 388 | * properties attached to this plane). |
| 389 | */ |
| 390 | int (*atomic_get_property)(struct drm_plane *plane, |
| 391 | const struct drm_plane_state *state, |
| 392 | struct drm_property *property, |
| 393 | uint64_t *val); |
| 394 | /** |
| 395 | * @late_register: |
| 396 | * |
| 397 | * This optional hook can be used to register additional userspace |
| 398 | * interfaces attached to the plane like debugfs interfaces. |
| 399 | * It is called late in the driver load sequence from drm_dev_register(). |
| 400 | * Everything added from this callback should be unregistered in |
| 401 | * the early_unregister callback. |
| 402 | * |
| 403 | * Returns: |
| 404 | * |
| 405 | * 0 on success, or a negative error code on failure. |
| 406 | */ |
| 407 | int (*late_register)(struct drm_plane *plane); |
| 408 | |
| 409 | /** |
| 410 | * @early_unregister: |
| 411 | * |
| 412 | * This optional hook should be used to unregister the additional |
| 413 | * userspace interfaces attached to the plane from |
Daniel Vetter | 559bdaf | 2017-01-25 07:26:55 +0100 | [diff] [blame] | 414 | * @late_register. It is called from drm_dev_unregister(), |
Daniel Vetter | 43968d7 | 2016-09-21 10:59:24 +0200 | [diff] [blame] | 415 | * early in the driver unload sequence to disable userspace access |
| 416 | * before data structures are torndown. |
| 417 | */ |
| 418 | void (*early_unregister)(struct drm_plane *plane); |
Rob Clark | fceffb32 | 2016-11-05 11:08:09 -0400 | [diff] [blame] | 419 | |
| 420 | /** |
| 421 | * @atomic_print_state: |
| 422 | * |
Daniel Vetter | ea0dd85 | 2016-12-29 21:48:26 +0100 | [diff] [blame] | 423 | * If driver subclasses &struct drm_plane_state, it should implement |
Rob Clark | fceffb32 | 2016-11-05 11:08:09 -0400 | [diff] [blame] | 424 | * this optional hook for printing additional driver specific state. |
| 425 | * |
| 426 | * Do not call this directly, use drm_atomic_plane_print_state() |
| 427 | * instead. |
| 428 | */ |
| 429 | void (*atomic_print_state)(struct drm_printer *p, |
| 430 | const struct drm_plane_state *state); |
Ben Widawsky | e6fc3b6 | 2017-07-23 20:46:38 -0700 | [diff] [blame] | 431 | |
| 432 | /** |
| 433 | * @format_mod_supported: |
| 434 | * |
| 435 | * This optional hook is used for the DRM to determine if the given |
| 436 | * format/modifier combination is valid for the plane. This allows the |
| 437 | * DRM to generate the correct format bitmask (which formats apply to |
Eric Anholt | 8fb756d | 2018-03-16 15:04:33 -0700 | [diff] [blame] | 438 | * which modifier), and to valdiate modifiers at atomic_check time. |
| 439 | * |
| 440 | * If not present, then any modifier in the plane's modifier |
| 441 | * list is allowed with any of the plane's formats. |
Ben Widawsky | e6fc3b6 | 2017-07-23 20:46:38 -0700 | [diff] [blame] | 442 | * |
| 443 | * Returns: |
| 444 | * |
| 445 | * True if the given modifier is valid for that format on the plane. |
| 446 | * False otherwise. |
| 447 | */ |
| 448 | bool (*format_mod_supported)(struct drm_plane *plane, uint32_t format, |
| 449 | uint64_t modifier); |
Daniel Vetter | 43968d7 | 2016-09-21 10:59:24 +0200 | [diff] [blame] | 450 | }; |
| 451 | |
Daniel Vetter | 532b367 | 2016-09-21 10:59:25 +0200 | [diff] [blame] | 452 | /** |
| 453 | * enum drm_plane_type - uapi plane type enumeration |
| 454 | * |
| 455 | * For historical reasons not all planes are made the same. This enumeration is |
| 456 | * used to tell the different types of planes apart to implement the different |
| 457 | * uapi semantics for them. For userspace which is universal plane aware and |
| 458 | * which is using that atomic IOCTL there's no difference between these planes |
| 459 | * (beyong what the driver and hardware can support of course). |
| 460 | * |
| 461 | * For compatibility with legacy userspace, only overlay planes are made |
| 462 | * available to userspace by default. Userspace clients may set the |
| 463 | * DRM_CLIENT_CAP_UNIVERSAL_PLANES client capability bit to indicate that they |
| 464 | * wish to receive a universal plane list containing all plane types. See also |
| 465 | * drm_for_each_legacy_plane(). |
Daniel Vetter | 226714d | 2016-09-23 08:35:25 +0200 | [diff] [blame] | 466 | * |
| 467 | * WARNING: The values of this enum is UABI since they're exposed in the "type" |
| 468 | * property. |
Daniel Vetter | 532b367 | 2016-09-21 10:59:25 +0200 | [diff] [blame] | 469 | */ |
Daniel Vetter | 43968d7 | 2016-09-21 10:59:24 +0200 | [diff] [blame] | 470 | enum drm_plane_type { |
Daniel Vetter | 532b367 | 2016-09-21 10:59:25 +0200 | [diff] [blame] | 471 | /** |
Daniel Vetter | 226714d | 2016-09-23 08:35:25 +0200 | [diff] [blame] | 472 | * @DRM_PLANE_TYPE_OVERLAY: |
| 473 | * |
| 474 | * Overlay planes represent all non-primary, non-cursor planes. Some |
| 475 | * drivers refer to these types of planes as "sprites" internally. |
| 476 | */ |
| 477 | DRM_PLANE_TYPE_OVERLAY, |
| 478 | |
| 479 | /** |
Daniel Vetter | 532b367 | 2016-09-21 10:59:25 +0200 | [diff] [blame] | 480 | * @DRM_PLANE_TYPE_PRIMARY: |
| 481 | * |
| 482 | * Primary planes represent a "main" plane for a CRTC. Primary planes |
| 483 | * are the planes operated upon by CRTC modesetting and flipping |
Daniel Vetter | d574528 | 2017-01-25 07:26:45 +0100 | [diff] [blame] | 484 | * operations described in the &drm_crtc_funcs.page_flip and |
| 485 | * &drm_crtc_funcs.set_config hooks. |
Daniel Vetter | 532b367 | 2016-09-21 10:59:25 +0200 | [diff] [blame] | 486 | */ |
Daniel Vetter | 43968d7 | 2016-09-21 10:59:24 +0200 | [diff] [blame] | 487 | DRM_PLANE_TYPE_PRIMARY, |
Daniel Vetter | 532b367 | 2016-09-21 10:59:25 +0200 | [diff] [blame] | 488 | |
| 489 | /** |
| 490 | * @DRM_PLANE_TYPE_CURSOR: |
| 491 | * |
| 492 | * Cursor planes represent a "cursor" plane for a CRTC. Cursor planes |
| 493 | * are the planes operated upon by the DRM_IOCTL_MODE_CURSOR and |
| 494 | * DRM_IOCTL_MODE_CURSOR2 IOCTLs. |
| 495 | */ |
Daniel Vetter | 43968d7 | 2016-09-21 10:59:24 +0200 | [diff] [blame] | 496 | DRM_PLANE_TYPE_CURSOR, |
| 497 | }; |
| 498 | |
| 499 | |
| 500 | /** |
| 501 | * struct drm_plane - central DRM plane control structure |
| 502 | * @dev: DRM device this plane belongs to |
| 503 | * @head: for list management |
| 504 | * @name: human readable name, can be overwritten by the driver |
| 505 | * @base: base mode object |
| 506 | * @possible_crtcs: pipes this plane can be bound to |
| 507 | * @format_types: array of formats supported by this plane |
| 508 | * @format_count: number of formats supported |
| 509 | * @format_default: driver hasn't supplied supported formats for the plane |
Ville Syrjälä | 3df6745 | 2017-11-14 21:10:21 +0200 | [diff] [blame] | 510 | * @modifiers: array of modifiers supported by this plane |
| 511 | * @modifier_count: number of modifiers supported |
Daniel Vetter | 43968d7 | 2016-09-21 10:59:24 +0200 | [diff] [blame] | 512 | * @old_fb: Temporary tracking of the old fb while a modeset is ongoing. Used by |
| 513 | * drm_mode_set_config_internal() to implement correct refcounting. |
| 514 | * @funcs: helper functions |
| 515 | * @properties: property tracking for this plane |
| 516 | * @type: type of plane (overlay, primary, cursor) |
Maxime Ripard | ae0e282 | 2018-04-11 09:39:25 +0200 | [diff] [blame] | 517 | * @alpha_property: alpha property for this plane |
Daniel Vetter | 43968d7 | 2016-09-21 10:59:24 +0200 | [diff] [blame] | 518 | * @zpos_property: zpos property for this plane |
Ville Syrjälä | d138dd3 | 2016-09-26 19:30:48 +0300 | [diff] [blame] | 519 | * @rotation_property: rotation property for this plane |
Daniel Vetter | 43968d7 | 2016-09-21 10:59:24 +0200 | [diff] [blame] | 520 | * @helper_private: mid-layer private data |
| 521 | */ |
| 522 | struct drm_plane { |
| 523 | struct drm_device *dev; |
| 524 | struct list_head head; |
| 525 | |
| 526 | char *name; |
| 527 | |
| 528 | /** |
| 529 | * @mutex: |
| 530 | * |
Daniel Vetter | d574528 | 2017-01-25 07:26:45 +0100 | [diff] [blame] | 531 | * Protects modeset plane state, together with the &drm_crtc.mutex of |
| 532 | * CRTC this plane is linked to (when active, getting activated or |
| 533 | * getting disabled). |
Daniel Vetter | c9e42b7 | 2017-03-28 17:53:48 +0200 | [diff] [blame] | 534 | * |
| 535 | * For atomic drivers specifically this protects @state. |
Daniel Vetter | 43968d7 | 2016-09-21 10:59:24 +0200 | [diff] [blame] | 536 | */ |
| 537 | struct drm_modeset_lock mutex; |
| 538 | |
| 539 | struct drm_mode_object base; |
| 540 | |
| 541 | uint32_t possible_crtcs; |
| 542 | uint32_t *format_types; |
| 543 | unsigned int format_count; |
| 544 | bool format_default; |
| 545 | |
Ben Widawsky | e6fc3b6 | 2017-07-23 20:46:38 -0700 | [diff] [blame] | 546 | uint64_t *modifiers; |
| 547 | unsigned int modifier_count; |
| 548 | |
Daniel Vetter | 2e2b96e | 2017-11-08 21:30:07 +0100 | [diff] [blame] | 549 | /** |
| 550 | * @crtc: Currently bound CRTC, only really meaningful for non-atomic |
| 551 | * drivers. Atomic drivers should instead check &drm_plane_state.crtc. |
| 552 | */ |
Daniel Vetter | 43968d7 | 2016-09-21 10:59:24 +0200 | [diff] [blame] | 553 | struct drm_crtc *crtc; |
Daniel Vetter | 2e2b96e | 2017-11-08 21:30:07 +0100 | [diff] [blame] | 554 | |
| 555 | /** |
| 556 | * @fb: Currently bound framebuffer, only really meaningful for |
| 557 | * non-atomic drivers. Atomic drivers should instead check |
| 558 | * &drm_plane_state.fb. |
| 559 | */ |
Daniel Vetter | 43968d7 | 2016-09-21 10:59:24 +0200 | [diff] [blame] | 560 | struct drm_framebuffer *fb; |
| 561 | |
| 562 | struct drm_framebuffer *old_fb; |
| 563 | |
| 564 | const struct drm_plane_funcs *funcs; |
| 565 | |
| 566 | struct drm_object_properties properties; |
| 567 | |
| 568 | enum drm_plane_type type; |
| 569 | |
| 570 | /** |
| 571 | * @index: Position inside the mode_config.list, can be used as an array |
| 572 | * index. It is invariant over the lifetime of the plane. |
| 573 | */ |
| 574 | unsigned index; |
| 575 | |
| 576 | const struct drm_plane_helper_funcs *helper_private; |
| 577 | |
Daniel Vetter | c9e42b7 | 2017-03-28 17:53:48 +0200 | [diff] [blame] | 578 | /** |
| 579 | * @state: |
| 580 | * |
| 581 | * Current atomic state for this plane. |
| 582 | * |
| 583 | * This is protected by @mutex. Note that nonblocking atomic commits |
| 584 | * access the current plane state without taking locks. Either by going |
| 585 | * through the &struct drm_atomic_state pointers, see |
Maarten Lankhorst | 77ac3b0 | 2017-07-19 16:39:20 +0200 | [diff] [blame] | 586 | * for_each_oldnew_plane_in_state(), for_each_old_plane_in_state() and |
| 587 | * for_each_new_plane_in_state(). Or through careful ordering of atomic |
| 588 | * commit operations as implemented in the atomic helpers, see |
| 589 | * &struct drm_crtc_commit. |
Daniel Vetter | c9e42b7 | 2017-03-28 17:53:48 +0200 | [diff] [blame] | 590 | */ |
Daniel Vetter | 43968d7 | 2016-09-21 10:59:24 +0200 | [diff] [blame] | 591 | struct drm_plane_state *state; |
| 592 | |
Maxime Ripard | ae0e282 | 2018-04-11 09:39:25 +0200 | [diff] [blame] | 593 | struct drm_property *alpha_property; |
Daniel Vetter | 43968d7 | 2016-09-21 10:59:24 +0200 | [diff] [blame] | 594 | struct drm_property *zpos_property; |
Ville Syrjälä | d138dd3 | 2016-09-26 19:30:48 +0300 | [diff] [blame] | 595 | struct drm_property *rotation_property; |
Jyri Sarha | 80f690e | 2018-02-19 22:28:23 +0200 | [diff] [blame] | 596 | |
| 597 | /** |
| 598 | * @color_encoding_property: |
| 599 | * |
| 600 | * Optional "COLOR_ENCODING" enum property for specifying |
| 601 | * color encoding for non RGB formats. |
| 602 | * See drm_plane_create_color_properties(). |
| 603 | */ |
| 604 | struct drm_property *color_encoding_property; |
| 605 | /** |
| 606 | * @color_range_property: |
| 607 | * |
| 608 | * Optional "COLOR_RANGE" enum property for specifying |
| 609 | * color range for non RGB formats. |
| 610 | * See drm_plane_create_color_properties(). |
| 611 | */ |
| 612 | struct drm_property *color_range_property; |
Daniel Vetter | 43968d7 | 2016-09-21 10:59:24 +0200 | [diff] [blame] | 613 | }; |
| 614 | |
| 615 | #define obj_to_plane(x) container_of(x, struct drm_plane, base) |
| 616 | |
Ben Widawsky | e6fc3b6 | 2017-07-23 20:46:38 -0700 | [diff] [blame] | 617 | __printf(9, 10) |
Daniel Vetter | 43968d7 | 2016-09-21 10:59:24 +0200 | [diff] [blame] | 618 | int drm_universal_plane_init(struct drm_device *dev, |
| 619 | struct drm_plane *plane, |
Tomi Valkeinen | 5cd57a4 | 2016-12-02 15:45:35 +0200 | [diff] [blame] | 620 | uint32_t possible_crtcs, |
Daniel Vetter | 43968d7 | 2016-09-21 10:59:24 +0200 | [diff] [blame] | 621 | const struct drm_plane_funcs *funcs, |
| 622 | const uint32_t *formats, |
| 623 | unsigned int format_count, |
Ben Widawsky | e6fc3b6 | 2017-07-23 20:46:38 -0700 | [diff] [blame] | 624 | const uint64_t *format_modifiers, |
Daniel Vetter | 43968d7 | 2016-09-21 10:59:24 +0200 | [diff] [blame] | 625 | enum drm_plane_type type, |
| 626 | const char *name, ...); |
Daniel Vetter | 91faa04 | 2017-03-22 09:36:02 +0100 | [diff] [blame] | 627 | int drm_plane_init(struct drm_device *dev, |
| 628 | struct drm_plane *plane, |
| 629 | uint32_t possible_crtcs, |
| 630 | const struct drm_plane_funcs *funcs, |
| 631 | const uint32_t *formats, unsigned int format_count, |
| 632 | bool is_primary); |
| 633 | void drm_plane_cleanup(struct drm_plane *plane); |
Daniel Vetter | 43968d7 | 2016-09-21 10:59:24 +0200 | [diff] [blame] | 634 | |
| 635 | /** |
| 636 | * drm_plane_index - find the index of a registered plane |
| 637 | * @plane: plane to find index for |
| 638 | * |
| 639 | * Given a registered plane, return the index of that plane within a DRM |
| 640 | * device's list of planes. |
| 641 | */ |
| 642 | static inline unsigned int drm_plane_index(struct drm_plane *plane) |
| 643 | { |
| 644 | return plane->index; |
| 645 | } |
Daniel Vetter | 91faa04 | 2017-03-22 09:36:02 +0100 | [diff] [blame] | 646 | struct drm_plane * drm_plane_from_index(struct drm_device *dev, int idx); |
| 647 | void drm_plane_force_disable(struct drm_plane *plane); |
Daniel Vetter | 43968d7 | 2016-09-21 10:59:24 +0200 | [diff] [blame] | 648 | |
| 649 | int drm_mode_plane_set_obj_prop(struct drm_plane *plane, |
| 650 | struct drm_property *property, |
| 651 | uint64_t value); |
| 652 | |
| 653 | /** |
| 654 | * drm_plane_find - find a &drm_plane |
| 655 | * @dev: DRM device |
Dave Airlie | e7e62c7 | 2017-11-09 09:35:04 +1000 | [diff] [blame] | 656 | * @file_priv: drm file to check for lease against. |
Daniel Vetter | 43968d7 | 2016-09-21 10:59:24 +0200 | [diff] [blame] | 657 | * @id: plane id |
| 658 | * |
| 659 | * Returns the plane with @id, NULL if it doesn't exist. Simple wrapper around |
| 660 | * drm_mode_object_find(). |
| 661 | */ |
| 662 | static inline struct drm_plane *drm_plane_find(struct drm_device *dev, |
Keith Packard | 418da17 | 2017-03-14 23:25:07 -0700 | [diff] [blame] | 663 | struct drm_file *file_priv, |
Daniel Vetter | 43968d7 | 2016-09-21 10:59:24 +0200 | [diff] [blame] | 664 | uint32_t id) |
| 665 | { |
| 666 | struct drm_mode_object *mo; |
Keith Packard | 418da17 | 2017-03-14 23:25:07 -0700 | [diff] [blame] | 667 | mo = drm_mode_object_find(dev, file_priv, id, DRM_MODE_OBJECT_PLANE); |
Daniel Vetter | 43968d7 | 2016-09-21 10:59:24 +0200 | [diff] [blame] | 668 | return mo ? obj_to_plane(mo) : NULL; |
| 669 | } |
| 670 | |
| 671 | /** |
| 672 | * drm_for_each_plane_mask - iterate over planes specified by bitmask |
| 673 | * @plane: the loop cursor |
| 674 | * @dev: the DRM device |
| 675 | * @plane_mask: bitmask of plane indices |
| 676 | * |
| 677 | * Iterate over all planes specified by bitmask. |
| 678 | */ |
| 679 | #define drm_for_each_plane_mask(plane, dev, plane_mask) \ |
| 680 | list_for_each_entry((plane), &(dev)->mode_config.plane_list, head) \ |
| 681 | for_each_if ((plane_mask) & (1 << drm_plane_index(plane))) |
| 682 | |
Daniel Vetter | 532b367 | 2016-09-21 10:59:25 +0200 | [diff] [blame] | 683 | /** |
| 684 | * drm_for_each_legacy_plane - iterate over all planes for legacy userspace |
| 685 | * @plane: the loop cursor |
| 686 | * @dev: the DRM device |
| 687 | * |
| 688 | * Iterate over all legacy planes of @dev, excluding primary and cursor planes. |
| 689 | * This is useful for implementing userspace apis when userspace is not |
Daniel Vetter | d574528 | 2017-01-25 07:26:45 +0100 | [diff] [blame] | 690 | * universal plane aware. See also &enum drm_plane_type. |
Daniel Vetter | 532b367 | 2016-09-21 10:59:25 +0200 | [diff] [blame] | 691 | */ |
Daniel Vetter | 43968d7 | 2016-09-21 10:59:24 +0200 | [diff] [blame] | 692 | #define drm_for_each_legacy_plane(plane, dev) \ |
| 693 | list_for_each_entry(plane, &(dev)->mode_config.plane_list, head) \ |
| 694 | for_each_if (plane->type == DRM_PLANE_TYPE_OVERLAY) |
| 695 | |
Daniel Vetter | 532b367 | 2016-09-21 10:59:25 +0200 | [diff] [blame] | 696 | /** |
| 697 | * drm_for_each_plane - iterate over all planes |
| 698 | * @plane: the loop cursor |
| 699 | * @dev: the DRM device |
| 700 | * |
| 701 | * Iterate over all planes of @dev, include primary and cursor planes. |
| 702 | */ |
Daniel Vetter | 43968d7 | 2016-09-21 10:59:24 +0200 | [diff] [blame] | 703 | #define drm_for_each_plane(plane, dev) \ |
| 704 | list_for_each_entry(plane, &(dev)->mode_config.plane_list, head) |
| 705 | |
| 706 | |
| 707 | #endif |