Lines Matching refs:plane

40  * A plane represents an image source that can be blended with or overlayed on
42 * &drm_framebuffer object. The plane itself specifies the cropping and scaling
44 * pipeline, represented by &drm_crtc. A plane can also have additional
48 * To create a plane, a KMS drivers allocates and zeroes an instances of
53 * primary plane per CRTC to avoid surprising userspace too much. See enum
55 * plane types. Special planes are associated with their CRTC by calling
58 * The type of a plane is exposed in the immutable "type" enumeration property,
86 static int create_in_format_blob(struct drm_device *dev, struct drm_plane *plane)
95 formats_size = sizeof(__u32) * plane->format_count;
102 sizeof(struct drm_format_modifier) * plane->modifier_count;
118 blob_data->count_formats = plane->format_count;
120 blob_data->count_modifiers = plane->modifier_count;
125 memcpy(formats_ptr(blob_data), plane->format_types, formats_size);
128 if (!plane->funcs->format_mod_supported)
132 for (i = 0; i < plane->modifier_count; i++) {
133 for (j = 0; j < plane->format_count; j++) {
134 if (plane->funcs->format_mod_supported(plane,
135 plane->format_types[j],
136 plane->modifiers[i])) {
142 mod->modifier = plane->modifiers[i];
149 drm_object_attach_property(&plane->base, config->modifiers_property,
156 * drm_universal_plane_init - Initialize a new universal plane object
158 * @plane: plane object to init
160 * @funcs: callbacks for the new plane
165 * @type: type of plane (overlay, primary, cursor)
166 * @name: printf style format string for the plane name, or NULL for default name
168 * Initializes a plane object of type @type.
173 int drm_universal_plane_init(struct drm_device *dev, struct drm_plane *plane,
185 /* plane index is used with 32bit bitmasks */
200 ret = drm_mode_object_add(dev, &plane->base, DRM_MODE_OBJECT_PLANE);
204 drm_modeset_lock_init(&plane->mutex);
206 plane->base.properties = &plane->properties;
207 plane->dev = dev;
208 plane->funcs = funcs;
209 plane->format_types = kmalloc_array(format_count, sizeof(uint32_t),
211 if (!plane->format_types) {
212 DRM_DEBUG_KMS("out of memory when allocating plane\n");
213 drm_mode_object_unregister(dev, &plane->base);
227 plane->modifier_count = format_modifier_count;
228 plane->modifiers = kmalloc_array(format_modifier_count,
232 if (format_modifier_count && !plane->modifiers) {
233 DRM_DEBUG_KMS("out of memory when allocating plane\n");
234 kfree(plane->format_types);
235 drm_mode_object_unregister(dev, &plane->base);
243 plane->name = kvasprintf(GFP_KERNEL, name, ap);
246 plane->name = kasprintf(GFP_KERNEL, "plane-%d",
249 if (!plane->name) {
250 kfree(plane->format_types);
251 kfree(plane->modifiers);
252 drm_mode_object_unregister(dev, &plane->base);
256 memcpy(plane->format_types, formats, format_count * sizeof(uint32_t));
257 plane->format_count = format_count;
258 memcpy(plane->modifiers, format_modifiers,
260 plane->possible_crtcs = possible_crtcs;
261 plane->type = type;
263 list_add_tail(&plane->head, &config->plane_list);
264 plane->index = config->num_total_plane++;
266 drm_object_attach_property(&plane->base,
268 plane->type);
271 drm_object_attach_property(&plane->base, config->prop_fb_id, 0);
272 drm_object_attach_property(&plane->base, config->prop_in_fence_fd, -1);
273 drm_object_attach_property(&plane->base, config->prop_crtc_id, 0);
274 drm_object_attach_property(&plane->base, config->prop_crtc_x, 0);
275 drm_object_attach_property(&plane->base, config->prop_crtc_y, 0);
276 drm_object_attach_property(&plane->base, config->prop_crtc_w, 0);
277 drm_object_attach_property(&plane->base, config->prop_crtc_h, 0);
278 drm_object_attach_property(&plane->base, config->prop_src_x, 0);
279 drm_object_attach_property(&plane->base, config->prop_src_y, 0);
280 drm_object_attach_property(&plane->base, config->prop_src_w, 0);
281 drm_object_attach_property(&plane->base, config->prop_src_h, 0);
285 create_in_format_blob(dev, plane);
295 struct drm_plane *plane;
298 drm_for_each_plane(plane, dev) {
299 if (plane->funcs->late_register)
300 ret = plane->funcs->late_register(plane);
304 if (plane->zpos_property)
317 struct drm_plane *plane;
319 drm_for_each_plane(plane, dev) {
320 if (plane->funcs->early_unregister)
321 plane->funcs->early_unregister(plane);
326 * drm_plane_init - Initialize a legacy plane
328 * @plane: plane object to init
330 * @funcs: callbacks for the new plane
333 * @is_primary: plane type (primary vs overlay)
335 * Legacy API to initialize a DRM plane.
342 int drm_plane_init(struct drm_device *dev, struct drm_plane *plane,
351 return drm_universal_plane_init(dev, plane, possible_crtcs, funcs,
358 * drm_plane_cleanup - Clean up the core plane usage
359 * @plane: plane to cleanup
361 * This function cleans up @plane and removes it from the DRM mode setting
362 * core. Note that the function does *not* free the plane structure itself,
365 void drm_plane_cleanup(struct drm_plane *plane)
367 struct drm_device *dev = plane->dev;
369 drm_modeset_lock_fini(&plane->mutex);
371 kfree(plane->format_types);
372 kfree(plane->modifiers);
373 drm_mode_object_unregister(dev, &plane->base);
375 BUG_ON(list_empty(&plane->head));
382 list_del(&plane->head);
385 WARN_ON(plane->state && !plane->funcs->atomic_destroy_state);
386 if (plane->state && plane->funcs->atomic_destroy_state)
387 plane->funcs->atomic_destroy_state(plane, plane->state);
389 kfree(plane->name);
391 memset(plane, 0, sizeof(*plane));
396 * drm_plane_from_index - find the registered plane at an index
398 * @idx: index of registered plane to find for
400 * Given a plane index, return the registered plane from DRM device's
406 struct drm_plane *plane;
408 drm_for_each_plane(plane, dev)
409 if (idx == plane->index)
410 return plane;
417 * drm_plane_force_disable - Forcibly disable a plane
418 * @plane: plane to disable
420 * Forces the plane to be disabled.
422 * Used when the plane's current framebuffer is destroyed,
431 void drm_plane_force_disable(struct drm_plane *plane)
435 if (!plane->fb)
438 WARN_ON(drm_drv_uses_atomic_modeset(plane->dev));
440 plane->old_fb = plane->fb;
441 ret = plane->funcs->disable_plane(plane, NULL);
443 DRM_ERROR("failed to disable plane with busy fb\n");
444 plane->old_fb = NULL;
447 /* disconnect the plane from the fb and crtc: */
448 drm_framebuffer_put(plane->old_fb);
449 plane->old_fb = NULL;
450 plane->fb = NULL;
451 plane->crtc = NULL;
457 * @plane: drm plane object to set property value for
461 * This functions sets a given property on a given plane object. This function
468 int drm_mode_plane_set_obj_prop(struct drm_plane *plane,
473 struct drm_mode_object *obj = &plane->base;
475 if (plane->funcs->set_property)
476 ret = plane->funcs->set_property(plane, property, value);
488 struct drm_plane *plane;
501 drm_for_each_plane(plane, dev) {
506 if (plane->type != DRM_PLANE_TYPE_OVERLAY &&
510 if (drm_lease_held(file_priv, plane->base.id)) {
512 put_user(plane->base.id, plane_ptr + count))
526 struct drm_plane *plane;
532 plane = drm_plane_find(dev, file_priv, plane_resp->plane_id);
533 if (!plane)
536 drm_modeset_lock(&plane->mutex, NULL);
537 if (plane->state && plane->state->crtc && drm_lease_held(file_priv, plane->state->crtc->base.id))
538 plane_resp->crtc_id = plane->state->crtc->base.id;
539 else if (!plane->state && plane->crtc && drm_lease_held(file_priv, plane->crtc->base.id))
540 plane_resp->crtc_id = plane->crtc->base.id;
544 if (plane->state && plane->state->fb)
545 plane_resp->fb_id = plane->state->fb->base.id;
546 else if (!plane->state && plane->fb)
547 plane_resp->fb_id = plane->fb->base.id;
550 drm_modeset_unlock(&plane->mutex);
552 plane_resp->plane_id = plane->base.id;
554 plane->possible_crtcs);
562 if (plane->format_count &&
563 (plane_resp->count_format_types >= plane->format_count)) {
566 plane->format_types,
567 sizeof(uint32_t) * plane->format_count)) {
571 plane_resp->count_format_types = plane->format_count;
576 int drm_plane_check_pixel_format(struct drm_plane *plane,
581 for (i = 0; i < plane->format_count; i++) {
582 if (format == plane->format_types[i])
585 if (i == plane->format_count)
588 if (plane->funcs->format_mod_supported) {
589 if (!plane->funcs->format_mod_supported(plane, format, modifier))
592 if (!plane->modifier_count)
595 for (i = 0; i < plane->modifier_count; i++) {
596 if (modifier == plane->modifiers[i])
599 if (i == plane->modifier_count)
606 static int __setplane_check(struct drm_plane *plane,
616 /* Check whether this plane is usable on this CRTC */
617 if (!(plane->possible_crtcs & drm_crtc_mask(crtc))) {
618 DRM_DEBUG_KMS("Invalid crtc for plane\n");
622 /* Check whether this plane supports the fb pixel format. */
623 ret = drm_plane_check_pixel_format(plane, fb->format->format,
653 * drm_any_plane_has_format - Check whether any plane supports this format and modifier combination
659 * Whether at least one plane supports the specified format and modifier combination.
664 struct drm_plane *plane;
666 drm_for_each_plane(plane, dev) {
667 if (drm_plane_check_pixel_format(plane, format, modifier) == 0)
678 * This function will take a reference on the new fb for the plane
683 static int __setplane_internal(struct drm_plane *plane,
695 WARN_ON(drm_drv_uses_atomic_modeset(plane->dev));
699 plane->old_fb = plane->fb;
700 ret = plane->funcs->disable_plane(plane, ctx);
702 plane->crtc = NULL;
703 plane->fb = NULL;
705 plane->old_fb = NULL;
710 ret = __setplane_check(plane, crtc, fb,
716 plane->old_fb = plane->fb;
717 ret = plane->funcs->update_plane(plane, crtc, fb,
721 plane->crtc = crtc;
722 plane->fb = fb;
723 drm_framebuffer_get(plane->fb);
725 plane->old_fb = NULL;
729 if (plane->old_fb)
730 drm_framebuffer_put(plane->old_fb);
731 plane->old_fb = NULL;
736 static int __setplane_atomic(struct drm_plane *plane,
747 WARN_ON(!drm_drv_uses_atomic_modeset(plane->dev));
751 return plane->funcs->disable_plane(plane, ctx);
760 ret = __setplane_check(plane, crtc, fb,
766 return plane->funcs->update_plane(plane, crtc, fb,
771 static int setplane_internal(struct drm_plane *plane,
783 DRM_MODESET_LOCK_ALL_BEGIN(plane->dev, ctx,
786 if (drm_drv_uses_atomic_modeset(plane->dev))
787 ret = __setplane_atomic(plane, crtc, fb,
791 ret = __setplane_internal(plane, crtc, fb,
795 DRM_MODESET_LOCK_ALL_END(plane->dev, ctx, ret);
804 struct drm_plane *plane;
813 * First, find the plane, crtc, and fb objects. If not available,
816 plane = drm_plane_find(dev, file_priv, plane_req->plane_id);
817 if (!plane) {
818 DRM_DEBUG_KMS("Unknown plane ID %d\n",
840 ret = setplane_internal(plane, crtc, fb,
858 struct drm_plane *plane = crtc->cursor;
872 BUG_ON(!plane);
873 WARN_ON(plane->crtc != crtc && plane->crtc != NULL);
878 * the reference if the plane update fails.
894 if (plane->state)
895 fb = plane->state->fb;
897 fb = plane->fb;
919 ret = __setplane_atomic(plane, crtc, fb,
923 ret = __setplane_internal(plane, crtc, fb,
965 * If this crtc has a universal cursor plane, call that plane's update
1049 struct drm_plane *plane;
1078 plane = crtc->primary;
1080 if (!drm_lease_held(file_priv, plane->base.id))
1127 ret = drm_modeset_lock(&plane->mutex, &ctx);
1131 if (plane->state)
1132 old_fb = plane->state->fb;
1134 old_fb = plane->fb;
1151 if (plane->state) {
1152 const struct drm_plane_state *state = plane->state;
1192 plane->old_fb = plane->fb;
1205 plane->old_fb = NULL;
1207 if (!plane->state) {
1208 plane->fb = fb;
1217 if (plane->old_fb)
1218 drm_framebuffer_put(plane->old_fb);
1219 plane->old_fb = NULL;