Lines Matching defs:plane
45 * A plane represents an image source that can be blended with or overlayed on
47 * &drm_framebuffer object. The plane itself specifies the cropping and scaling
49 * pipeline, represented by &drm_crtc. A plane can also have additional
53 * To create a plane, a KMS drivers allocates and zeroes an instances of
58 * primary plane per CRTC to avoid surprising userspace too much. See enum
60 * plane types. Special planes are associated with their CRTC by calling
63 * The type of a plane is exposed in the immutable "type" enumeration property,
91 static int create_in_format_blob(struct drm_device *dev, struct drm_plane *plane)
100 formats_size = sizeof(__u32) * plane->format_count;
107 sizeof(struct drm_format_modifier) * plane->modifier_count;
123 blob_data->count_formats = plane->format_count;
125 blob_data->count_modifiers = plane->modifier_count;
130 memcpy(formats_ptr(blob_data), plane->format_types, formats_size);
133 if (!plane->funcs->format_mod_supported)
137 for (i = 0; i < plane->modifier_count; i++) {
138 for (j = 0; j < plane->format_count; j++) {
139 if (plane->funcs->format_mod_supported(plane,
140 plane->format_types[j],
141 plane->modifiers[i])) {
147 mod->modifier = plane->modifiers[i];
154 drm_object_attach_property(&plane->base, config->modifiers_property,
161 * drm_universal_plane_init - Initialize a new universal plane object
163 * @plane: plane object to init
165 * @funcs: callbacks for the new plane
170 * @type: type of plane (overlay, primary, cursor)
171 * @name: printf style format string for the plane name, or NULL for default name
173 * Initializes a plane object of type @type.
178 int drm_universal_plane_init(struct drm_device *dev, struct drm_plane *plane,
190 /* plane index is used with 32bit bitmasks */
198 ret = drm_mode_object_add(dev, &plane->base, DRM_MODE_OBJECT_PLANE);
202 drm_modeset_lock_init(&plane->mutex);
204 plane->base.properties = &plane->properties;
205 plane->dev = dev;
206 plane->funcs = funcs;
207 plane->format_types = kmalloc_array(format_count, sizeof(uint32_t),
209 if (!plane->format_types) {
210 DRM_DEBUG_KMS("out of memory when allocating plane\n");
211 drm_mode_object_unregister(dev, &plane->base);
231 plane->modifier_count = format_modifier_count;
232 plane->modifiers = kmalloc_array(format_modifier_count,
236 if (format_modifier_count && !plane->modifiers) {
237 DRM_DEBUG_KMS("out of memory when allocating plane\n");
238 kfree(plane->format_types);
239 drm_mode_object_unregister(dev, &plane->base);
247 plane->name = kvasprintf(GFP_KERNEL, name, ap);
250 plane->name = kasprintf(GFP_KERNEL, "plane-%d",
253 if (!plane->name) {
254 kfree(plane->format_types);
255 kfree(plane->modifiers);
256 drm_mode_object_unregister(dev, &plane->base);
260 memcpy(plane->format_types, formats, format_count * sizeof(uint32_t));
261 plane->format_count = format_count;
262 memcpy(plane->modifiers, format_modifiers,
264 plane->possible_crtcs = possible_crtcs;
265 plane->type = type;
267 list_add_tail(&plane->head, &config->plane_list);
268 plane->index = config->num_total_plane++;
270 drm_object_attach_property(&plane->base,
272 plane->type);
275 drm_object_attach_property(&plane->base, config->prop_fb_id, 0);
276 drm_object_attach_property(&plane->base, config->prop_in_fence_fd, -1);
277 drm_object_attach_property(&plane->base, config->prop_crtc_id, 0);
278 drm_object_attach_property(&plane->base, config->prop_crtc_x, 0);
279 drm_object_attach_property(&plane->base, config->prop_crtc_y, 0);
280 drm_object_attach_property(&plane->base, config->prop_crtc_w, 0);
281 drm_object_attach_property(&plane->base, config->prop_crtc_h, 0);
282 drm_object_attach_property(&plane->base, config->prop_src_x, 0);
283 drm_object_attach_property(&plane->base, config->prop_src_y, 0);
284 drm_object_attach_property(&plane->base, config->prop_src_w, 0);
285 drm_object_attach_property(&plane->base, config->prop_src_h, 0);
289 create_in_format_blob(dev, plane);
297 struct drm_plane *plane;
300 drm_for_each_plane(plane, dev) {
301 if (plane->funcs->late_register)
302 ret = plane->funcs->late_register(plane);
312 struct drm_plane *plane;
314 drm_for_each_plane(plane, dev) {
315 if (plane->funcs->early_unregister)
316 plane->funcs->early_unregister(plane);
321 * drm_plane_init - Initialize a legacy plane
323 * @plane: plane object to init
325 * @funcs: callbacks for the new plane
328 * @is_primary: plane type (primary vs overlay)
330 * Legacy API to initialize a DRM plane.
337 int drm_plane_init(struct drm_device *dev, struct drm_plane *plane,
346 return drm_universal_plane_init(dev, plane, possible_crtcs, funcs,
353 * drm_plane_cleanup - Clean up the core plane usage
354 * @plane: plane to cleanup
356 * This function cleans up @plane and removes it from the DRM mode setting
357 * core. Note that the function does *not* free the plane structure itself,
360 void drm_plane_cleanup(struct drm_plane *plane)
362 struct drm_device *dev = plane->dev;
364 drm_modeset_lock_fini(&plane->mutex);
366 kfree(plane->format_types);
367 kfree(plane->modifiers);
368 drm_mode_object_unregister(dev, &plane->base);
370 BUG_ON(list_empty(&plane->head));
377 list_del(&plane->head);
380 WARN_ON(plane->state && !plane->funcs->atomic_destroy_state);
381 if (plane->state && plane->funcs->atomic_destroy_state)
382 plane->funcs->atomic_destroy_state(plane, plane->state);
384 kfree(plane->name);
386 memset(plane, 0, sizeof(*plane));
391 * drm_plane_from_index - find the registered plane at an index
393 * @idx: index of registered plane to find for
395 * Given a plane index, return the registered plane from DRM device's
401 struct drm_plane *plane;
403 drm_for_each_plane(plane, dev)
404 if (idx == plane->index)
405 return plane;
412 * drm_plane_force_disable - Forcibly disable a plane
413 * @plane: plane to disable
415 * Forces the plane to be disabled.
417 * Used when the plane's current framebuffer is destroyed,
426 void drm_plane_force_disable(struct drm_plane *plane)
430 if (!plane->fb)
433 WARN_ON(drm_drv_uses_atomic_modeset(plane->dev));
435 plane->old_fb = plane->fb;
436 ret = plane->funcs->disable_plane(plane, NULL);
438 DRM_ERROR("failed to disable plane with busy fb\n");
439 plane->old_fb = NULL;
442 /* disconnect the plane from the fb and crtc: */
443 drm_framebuffer_put(plane->old_fb);
444 plane->old_fb = NULL;
445 plane->fb = NULL;
446 plane->crtc = NULL;
452 * @plane: drm plane object to set property value for
456 * This functions sets a given property on a given plane object. This function
463 int drm_mode_plane_set_obj_prop(struct drm_plane *plane,
468 struct drm_mode_object *obj = &plane->base;
470 if (plane->funcs->set_property)
471 ret = plane->funcs->set_property(plane, property, value);
483 struct drm_plane *plane;
496 drm_for_each_plane(plane, dev) {
501 if (plane->type != DRM_PLANE_TYPE_OVERLAY &&
505 if (drm_lease_held(file_priv, plane->base.id)) {
507 put_user(plane->base.id, plane_ptr + count))
521 struct drm_plane *plane;
527 plane = drm_plane_find(dev, file_priv, plane_resp->plane_id);
528 if (!plane)
531 drm_modeset_lock(&plane->mutex, NULL);
532 if (plane->state && plane->state->crtc && drm_lease_held(file_priv, plane->state->crtc->base.id))
533 plane_resp->crtc_id = plane->state->crtc->base.id;
534 else if (!plane->state && plane->crtc && drm_lease_held(file_priv, plane->crtc->base.id))
535 plane_resp->crtc_id = plane->crtc->base.id;
539 if (plane->state && plane->state->fb)
540 plane_resp->fb_id = plane->state->fb->base.id;
541 else if (!plane->state && plane->fb)
542 plane_resp->fb_id = plane->fb->base.id;
545 drm_modeset_unlock(&plane->mutex);
547 plane_resp->plane_id = plane->base.id;
549 plane->possible_crtcs);
557 if (plane->format_count &&
558 (plane_resp->count_format_types >= plane->format_count)) {
561 plane->format_types,
562 sizeof(uint32_t) * plane->format_count)) {
566 plane_resp->count_format_types = plane->format_count;
571 int drm_plane_check_pixel_format(struct drm_plane *plane,
576 for (i = 0; i < plane->format_count; i++) {
577 if (format == plane->format_types[i])
580 if (i == plane->format_count)
583 if (plane->funcs->format_mod_supported) {
584 if (!plane->funcs->format_mod_supported(plane, format, modifier))
587 if (!plane->modifier_count)
590 for (i = 0; i < plane->modifier_count; i++) {
591 if (modifier == plane->modifiers[i])
594 if (i == plane->modifier_count)
601 static int __setplane_check(struct drm_plane *plane,
611 /* Check whether this plane is usable on this CRTC */
612 if (!(plane->possible_crtcs & drm_crtc_mask(crtc))) {
613 DRM_DEBUG_KMS("Invalid crtc for plane\n");
617 /* Check whether this plane supports the fb pixel format. */
618 ret = drm_plane_check_pixel_format(plane, fb->format->format,
648 * drm_any_plane_has_format - Check whether any plane supports this format and modifier combination
654 * Whether at least one plane supports the specified format and modifier combination.
659 struct drm_plane *plane;
661 drm_for_each_plane(plane, dev) {
662 if (drm_plane_check_pixel_format(plane, format, modifier) == 0)
673 * This function will take a reference on the new fb for the plane
678 static int __setplane_internal(struct drm_plane *plane,
690 WARN_ON(drm_drv_uses_atomic_modeset(plane->dev));
694 plane->old_fb = plane->fb;
695 ret = plane->funcs->disable_plane(plane, ctx);
697 plane->crtc = NULL;
698 plane->fb = NULL;
700 plane->old_fb = NULL;
705 ret = __setplane_check(plane, crtc, fb,
711 plane->old_fb = plane->fb;
712 ret = plane->funcs->update_plane(plane, crtc, fb,
716 plane->crtc = crtc;
717 plane->fb = fb;
718 drm_framebuffer_get(plane->fb);
720 plane->old_fb = NULL;
724 if (plane->old_fb)
725 drm_framebuffer_put(plane->old_fb);
726 plane->old_fb = NULL;
731 static int __setplane_atomic(struct drm_plane *plane,
742 WARN_ON(!drm_drv_uses_atomic_modeset(plane->dev));
746 return plane->funcs->disable_plane(plane, ctx);
755 ret = __setplane_check(plane, crtc, fb,
761 return plane->funcs->update_plane(plane, crtc, fb,
766 static int setplane_internal(struct drm_plane *plane,
778 DRM_MODESET_LOCK_ALL_BEGIN(plane->dev, ctx,
781 if (drm_drv_uses_atomic_modeset(plane->dev))
782 ret = __setplane_atomic(plane, crtc, fb,
786 ret = __setplane_internal(plane, crtc, fb,
799 struct drm_plane *plane;
808 * First, find the plane, crtc, and fb objects. If not available,
811 plane = drm_plane_find(dev, file_priv, plane_req->plane_id);
812 if (!plane) {
813 DRM_DEBUG_KMS("Unknown plane ID %d\n",
835 ret = setplane_internal(plane, crtc, fb,
853 struct drm_plane *plane = crtc->cursor;
867 BUG_ON(!plane);
868 WARN_ON(plane->crtc != crtc && plane->crtc != NULL);
873 * the reference if the plane update fails.
889 if (plane->state)
890 fb = plane->state->fb;
892 fb = plane->fb;
914 ret = __setplane_atomic(plane, crtc, fb,
918 ret = __setplane_internal(plane, crtc, fb,
960 * If this crtc has a universal cursor plane, call that plane's update
1044 struct drm_plane *plane;
1073 plane = crtc->primary;
1075 if (!drm_lease_held(file_priv, plane->base.id))
1122 ret = drm_modeset_lock(&plane->mutex, &ctx);
1126 if (plane->state)
1127 old_fb = plane->state->fb;
1129 old_fb = plane->fb;
1146 if (plane->state) {
1147 const struct drm_plane_state *state = plane->state;
1187 plane->old_fb = plane->fb;
1200 plane->old_fb = NULL;
1202 if (!plane->state) {
1203 plane->fb = fb;
1211 if (plane->old_fb)
1212 drm_framebuffer_put(plane->old_fb);
1213 plane->old_fb = NULL;