blob: 29a175754aee0c113d972069106f2934c72d1075 [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
Daniel Vetter43968d72016-09-21 10:59:24 +0200121/**
122 * struct drm_plane_funcs - driver plane control functions
123 */
124struct drm_plane_funcs {
125 /**
126 * @update_plane:
127 *
128 * This is the legacy entry point to enable and configure the plane for
129 * the given CRTC and framebuffer. It is never called to disable the
130 * plane, i.e. the passed-in crtc and fb paramters are never NULL.
131 *
132 * The source rectangle in frame buffer memory coordinates is given by
133 * the src_x, src_y, src_w and src_h parameters (as 16.16 fixed point
134 * values). Devices that don't support subpixel plane coordinates can
135 * ignore the fractional part.
136 *
137 * The destination rectangle in CRTC coordinates is given by the
138 * crtc_x, crtc_y, crtc_w and crtc_h parameters (as integer values).
139 * Devices scale the source rectangle to the destination rectangle. If
140 * scaling is not supported, and the source rectangle size doesn't match
141 * the destination rectangle size, the driver must return a
142 * -<errorname>EINVAL</errorname> error.
143 *
144 * Drivers implementing atomic modeset should use
145 * drm_atomic_helper_update_plane() to implement this hook.
146 *
147 * RETURNS:
148 *
149 * 0 on success or a negative error code on failure.
150 */
151 int (*update_plane)(struct drm_plane *plane,
152 struct drm_crtc *crtc, struct drm_framebuffer *fb,
153 int crtc_x, int crtc_y,
154 unsigned int crtc_w, unsigned int crtc_h,
155 uint32_t src_x, uint32_t src_y,
156 uint32_t src_w, uint32_t src_h);
157
158 /**
159 * @disable_plane:
160 *
161 * This is the legacy entry point to disable the plane. The DRM core
162 * calls this method in response to a DRM_IOCTL_MODE_SETPLANE IOCTL call
163 * with the frame buffer ID set to 0. Disabled planes must not be
164 * processed by the CRTC.
165 *
166 * Drivers implementing atomic modeset should use
167 * drm_atomic_helper_disable_plane() to implement this hook.
168 *
169 * RETURNS:
170 *
171 * 0 on success or a negative error code on failure.
172 */
173 int (*disable_plane)(struct drm_plane *plane);
174
175 /**
176 * @destroy:
177 *
178 * Clean up plane resources. This is only called at driver unload time
179 * through drm_mode_config_cleanup() since a plane cannot be hotplugged
180 * in DRM.
181 */
182 void (*destroy)(struct drm_plane *plane);
183
184 /**
185 * @reset:
186 *
187 * Reset plane hardware and software state to off. This function isn't
188 * called by the core directly, only through drm_mode_config_reset().
189 * It's not a helper hook only for historical reasons.
190 *
191 * Atomic drivers can use drm_atomic_helper_plane_reset() to reset
192 * atomic state using this hook.
193 */
194 void (*reset)(struct drm_plane *plane);
195
196 /**
197 * @set_property:
198 *
199 * This is the legacy entry point to update a property attached to the
200 * plane.
201 *
202 * Drivers implementing atomic modeset should use
203 * drm_atomic_helper_plane_set_property() to implement this hook.
204 *
205 * This callback is optional if the driver does not support any legacy
206 * driver-private properties.
207 *
208 * RETURNS:
209 *
210 * 0 on success or a negative error code on failure.
211 */
212 int (*set_property)(struct drm_plane *plane,
213 struct drm_property *property, uint64_t val);
214
215 /**
216 * @atomic_duplicate_state:
217 *
218 * Duplicate the current atomic state for this plane and return it.
219 * The core and helpers gurantee that any atomic state duplicated with
220 * this hook and still owned by the caller (i.e. not transferred to the
221 * driver by calling ->atomic_commit() from struct
222 * &drm_mode_config_funcs) will be cleaned up by calling the
223 * @atomic_destroy_state hook in this structure.
224 *
225 * Atomic drivers which don't subclass struct &drm_plane_state should use
226 * drm_atomic_helper_plane_duplicate_state(). Drivers that subclass the
227 * state structure to extend it with driver-private state should use
228 * __drm_atomic_helper_plane_duplicate_state() to make sure shared state is
229 * duplicated in a consistent fashion across drivers.
230 *
231 * It is an error to call this hook before plane->state has been
232 * initialized correctly.
233 *
234 * NOTE:
235 *
236 * If the duplicate state references refcounted resources this hook must
237 * acquire a reference for each of them. The driver must release these
238 * references again in @atomic_destroy_state.
239 *
240 * RETURNS:
241 *
242 * Duplicated atomic state or NULL when the allocation failed.
243 */
244 struct drm_plane_state *(*atomic_duplicate_state)(struct drm_plane *plane);
245
246 /**
247 * @atomic_destroy_state:
248 *
249 * Destroy a state duplicated with @atomic_duplicate_state and release
250 * or unreference all resources it references
251 */
252 void (*atomic_destroy_state)(struct drm_plane *plane,
253 struct drm_plane_state *state);
254
255 /**
256 * @atomic_set_property:
257 *
258 * Decode a driver-private property value and store the decoded value
259 * into the passed-in state structure. Since the atomic core decodes all
260 * standardized properties (even for extensions beyond the core set of
261 * properties which might not be implemented by all drivers) this
262 * requires drivers to subclass the state structure.
263 *
264 * Such driver-private properties should really only be implemented for
265 * truly hardware/vendor specific state. Instead it is preferred to
266 * standardize atomic extension and decode the properties used to expose
267 * such an extension in the core.
268 *
269 * Do not call this function directly, use
270 * drm_atomic_plane_set_property() instead.
271 *
272 * This callback is optional if the driver does not support any
273 * driver-private atomic properties.
274 *
275 * NOTE:
276 *
277 * This function is called in the state assembly phase of atomic
278 * modesets, which can be aborted for any reason (including on
279 * userspace's request to just check whether a configuration would be
280 * possible). Drivers MUST NOT touch any persistent state (hardware or
281 * software) or data structures except the passed in @state parameter.
282 *
283 * Also since userspace controls in which order properties are set this
284 * function must not do any input validation (since the state update is
285 * incomplete and hence likely inconsistent). Instead any such input
286 * validation must be done in the various atomic_check callbacks.
287 *
288 * RETURNS:
289 *
290 * 0 if the property has been found, -EINVAL if the property isn't
291 * implemented by the driver (which shouldn't ever happen, the core only
292 * asks for properties attached to this plane). No other validation is
293 * allowed by the driver. The core already checks that the property
294 * value is within the range (integer, valid enum value, ...) the driver
295 * set when registering the property.
296 */
297 int (*atomic_set_property)(struct drm_plane *plane,
298 struct drm_plane_state *state,
299 struct drm_property *property,
300 uint64_t val);
301
302 /**
303 * @atomic_get_property:
304 *
305 * Reads out the decoded driver-private property. This is used to
306 * implement the GETPLANE IOCTL.
307 *
308 * Do not call this function directly, use
309 * drm_atomic_plane_get_property() instead.
310 *
311 * This callback is optional if the driver does not support any
312 * driver-private atomic properties.
313 *
314 * RETURNS:
315 *
316 * 0 on success, -EINVAL if the property isn't implemented by the
317 * driver (which should never happen, the core only asks for
318 * properties attached to this plane).
319 */
320 int (*atomic_get_property)(struct drm_plane *plane,
321 const struct drm_plane_state *state,
322 struct drm_property *property,
323 uint64_t *val);
324 /**
325 * @late_register:
326 *
327 * This optional hook can be used to register additional userspace
328 * interfaces attached to the plane like debugfs interfaces.
329 * It is called late in the driver load sequence from drm_dev_register().
330 * Everything added from this callback should be unregistered in
331 * the early_unregister callback.
332 *
333 * Returns:
334 *
335 * 0 on success, or a negative error code on failure.
336 */
337 int (*late_register)(struct drm_plane *plane);
338
339 /**
340 * @early_unregister:
341 *
342 * This optional hook should be used to unregister the additional
343 * userspace interfaces attached to the plane from
344 * late_unregister(). It is called from drm_dev_unregister(),
345 * early in the driver unload sequence to disable userspace access
346 * before data structures are torndown.
347 */
348 void (*early_unregister)(struct drm_plane *plane);
349};
350
Daniel Vetter532b3672016-09-21 10:59:25 +0200351/**
352 * enum drm_plane_type - uapi plane type enumeration
353 *
354 * For historical reasons not all planes are made the same. This enumeration is
355 * used to tell the different types of planes apart to implement the different
356 * uapi semantics for them. For userspace which is universal plane aware and
357 * which is using that atomic IOCTL there's no difference between these planes
358 * (beyong what the driver and hardware can support of course).
359 *
360 * For compatibility with legacy userspace, only overlay planes are made
361 * available to userspace by default. Userspace clients may set the
362 * DRM_CLIENT_CAP_UNIVERSAL_PLANES client capability bit to indicate that they
363 * wish to receive a universal plane list containing all plane types. See also
364 * drm_for_each_legacy_plane().
Daniel Vetter226714d2016-09-23 08:35:25 +0200365 *
366 * WARNING: The values of this enum is UABI since they're exposed in the "type"
367 * property.
Daniel Vetter532b3672016-09-21 10:59:25 +0200368 */
Daniel Vetter43968d72016-09-21 10:59:24 +0200369enum drm_plane_type {
Daniel Vetter532b3672016-09-21 10:59:25 +0200370 /**
Daniel Vetter226714d2016-09-23 08:35:25 +0200371 * @DRM_PLANE_TYPE_OVERLAY:
372 *
373 * Overlay planes represent all non-primary, non-cursor planes. Some
374 * drivers refer to these types of planes as "sprites" internally.
375 */
376 DRM_PLANE_TYPE_OVERLAY,
377
378 /**
Daniel Vetter532b3672016-09-21 10:59:25 +0200379 * @DRM_PLANE_TYPE_PRIMARY:
380 *
381 * Primary planes represent a "main" plane for a CRTC. Primary planes
382 * are the planes operated upon by CRTC modesetting and flipping
383 * operations described in the page_flip and set_config hooks in struct
384 * &drm_crtc_funcs.
385 */
Daniel Vetter43968d72016-09-21 10:59:24 +0200386 DRM_PLANE_TYPE_PRIMARY,
Daniel Vetter532b3672016-09-21 10:59:25 +0200387
388 /**
389 * @DRM_PLANE_TYPE_CURSOR:
390 *
391 * Cursor planes represent a "cursor" plane for a CRTC. Cursor planes
392 * are the planes operated upon by the DRM_IOCTL_MODE_CURSOR and
393 * DRM_IOCTL_MODE_CURSOR2 IOCTLs.
394 */
Daniel Vetter43968d72016-09-21 10:59:24 +0200395 DRM_PLANE_TYPE_CURSOR,
396};
397
398
399/**
400 * struct drm_plane - central DRM plane control structure
401 * @dev: DRM device this plane belongs to
402 * @head: for list management
403 * @name: human readable name, can be overwritten by the driver
404 * @base: base mode object
405 * @possible_crtcs: pipes this plane can be bound to
406 * @format_types: array of formats supported by this plane
407 * @format_count: number of formats supported
408 * @format_default: driver hasn't supplied supported formats for the plane
409 * @crtc: currently bound CRTC
410 * @fb: currently bound fb
411 * @old_fb: Temporary tracking of the old fb while a modeset is ongoing. Used by
412 * drm_mode_set_config_internal() to implement correct refcounting.
413 * @funcs: helper functions
414 * @properties: property tracking for this plane
415 * @type: type of plane (overlay, primary, cursor)
416 * @state: current atomic state for this plane
417 * @zpos_property: zpos property for this plane
Ville Syrjäläd138dd32016-09-26 19:30:48 +0300418 * @rotation_property: rotation property for this plane
Daniel Vetter43968d72016-09-21 10:59:24 +0200419 * @helper_private: mid-layer private data
420 */
421struct drm_plane {
422 struct drm_device *dev;
423 struct list_head head;
424
425 char *name;
426
427 /**
428 * @mutex:
429 *
430 * Protects modeset plane state, together with the mutex of &drm_crtc
431 * this plane is linked to (when active, getting actived or getting
432 * disabled).
433 */
434 struct drm_modeset_lock mutex;
435
436 struct drm_mode_object base;
437
438 uint32_t possible_crtcs;
439 uint32_t *format_types;
440 unsigned int format_count;
441 bool format_default;
442
443 struct drm_crtc *crtc;
444 struct drm_framebuffer *fb;
445
446 struct drm_framebuffer *old_fb;
447
448 const struct drm_plane_funcs *funcs;
449
450 struct drm_object_properties properties;
451
452 enum drm_plane_type type;
453
454 /**
455 * @index: Position inside the mode_config.list, can be used as an array
456 * index. It is invariant over the lifetime of the plane.
457 */
458 unsigned index;
459
460 const struct drm_plane_helper_funcs *helper_private;
461
462 struct drm_plane_state *state;
463
464 struct drm_property *zpos_property;
Ville Syrjäläd138dd32016-09-26 19:30:48 +0300465 struct drm_property *rotation_property;
Daniel Vetter43968d72016-09-21 10:59:24 +0200466};
467
468#define obj_to_plane(x) container_of(x, struct drm_plane, base)
469
470extern __printf(8, 9)
471int drm_universal_plane_init(struct drm_device *dev,
472 struct drm_plane *plane,
473 unsigned long possible_crtcs,
474 const struct drm_plane_funcs *funcs,
475 const uint32_t *formats,
476 unsigned int format_count,
477 enum drm_plane_type type,
478 const char *name, ...);
479extern int drm_plane_init(struct drm_device *dev,
480 struct drm_plane *plane,
481 unsigned long possible_crtcs,
482 const struct drm_plane_funcs *funcs,
483 const uint32_t *formats, unsigned int format_count,
484 bool is_primary);
485extern void drm_plane_cleanup(struct drm_plane *plane);
486
487/**
488 * drm_plane_index - find the index of a registered plane
489 * @plane: plane to find index for
490 *
491 * Given a registered plane, return the index of that plane within a DRM
492 * device's list of planes.
493 */
494static inline unsigned int drm_plane_index(struct drm_plane *plane)
495{
496 return plane->index;
497}
498extern struct drm_plane * drm_plane_from_index(struct drm_device *dev, int idx);
499extern void drm_plane_force_disable(struct drm_plane *plane);
500
501int drm_mode_plane_set_obj_prop(struct drm_plane *plane,
502 struct drm_property *property,
503 uint64_t value);
504
505/**
506 * drm_plane_find - find a &drm_plane
507 * @dev: DRM device
508 * @id: plane id
509 *
510 * Returns the plane with @id, NULL if it doesn't exist. Simple wrapper around
511 * drm_mode_object_find().
512 */
513static inline struct drm_plane *drm_plane_find(struct drm_device *dev,
514 uint32_t id)
515{
516 struct drm_mode_object *mo;
517 mo = drm_mode_object_find(dev, id, DRM_MODE_OBJECT_PLANE);
518 return mo ? obj_to_plane(mo) : NULL;
519}
520
521/**
522 * drm_for_each_plane_mask - iterate over planes specified by bitmask
523 * @plane: the loop cursor
524 * @dev: the DRM device
525 * @plane_mask: bitmask of plane indices
526 *
527 * Iterate over all planes specified by bitmask.
528 */
529#define drm_for_each_plane_mask(plane, dev, plane_mask) \
530 list_for_each_entry((plane), &(dev)->mode_config.plane_list, head) \
531 for_each_if ((plane_mask) & (1 << drm_plane_index(plane)))
532
Daniel Vetter532b3672016-09-21 10:59:25 +0200533/**
534 * drm_for_each_legacy_plane - iterate over all planes for legacy userspace
535 * @plane: the loop cursor
536 * @dev: the DRM device
537 *
538 * Iterate over all legacy planes of @dev, excluding primary and cursor planes.
539 * This is useful for implementing userspace apis when userspace is not
540 * universal plane aware. See also enum &drm_plane_type.
541 */
Daniel Vetter43968d72016-09-21 10:59:24 +0200542#define drm_for_each_legacy_plane(plane, dev) \
543 list_for_each_entry(plane, &(dev)->mode_config.plane_list, head) \
544 for_each_if (plane->type == DRM_PLANE_TYPE_OVERLAY)
545
Daniel Vetter532b3672016-09-21 10:59:25 +0200546/**
547 * drm_for_each_plane - iterate over all planes
548 * @plane: the loop cursor
549 * @dev: the DRM device
550 *
551 * Iterate over all planes of @dev, include primary and cursor planes.
552 */
Daniel Vetter43968d72016-09-21 10:59:24 +0200553#define drm_for_each_plane(plane, dev) \
554 list_for_each_entry(plane, &(dev)->mode_config.plane_list, head)
555
556
557#endif