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