Add support for the zpos plane property. Depending on the plane type: - Primary and cursor planes: Create an immutable zpos property. The primary plane is always at the bottom and the cursor plane is always on the top. - Overlay planes: Create a mutable zpos property allowing to change their order but always keep them between the primary and cursor planes. As documented, "vkms_crtc_state.active_planes" must be sorted by zpos. This is achieved by inserting them in the array at their normalized_zpos index. The following igt-gpu-tools tests were executed: | master branch | this patch | | SUCCESS | SKIP | FAIL | SUCCESS | SKIP | FAIL | kms_atomic | 10 | 02 | 00 | 09 | 02 | 01 | kms_plane | 06 | 00 | 14 | 06 | 00 | 14 | kms_plane_cursor | 09 | 45 | 00 | 09 | 45 | 00 | kms_plane_multiple | 01 | 23 | 00 | 01 | 23 | 00 | kms_writeback | 04 | 00 | 00 | 04 | 00 | 00 | Notice that there is one test failing in the kms_atomic row (plane-immutable-zpos) but it is due to timeout capturing CRC. This happens when the primary plane is disabled and the composer is not able to find the "primary_composer" variable. While the timeout bug needs to be fixed in a different series, the zpos property works as expected. Signed-off-by: José Expósito <jose.exposito89@xxxxxxxxx> --- v2: - Use number of planes constant introduced in "drm/vkms: add support for multiple overlay planes" v2 - Add a test results in the commit message --- drivers/gpu/drm/vkms/vkms_crtc.c | 3 +-- drivers/gpu/drm/vkms/vkms_drv.c | 1 + drivers/gpu/drm/vkms/vkms_plane.c | 23 +++++++++++++++++++++++ 3 files changed, 25 insertions(+), 2 deletions(-) diff --git a/drivers/gpu/drm/vkms/vkms_crtc.c b/drivers/gpu/drm/vkms/vkms_crtc.c index 57bbd32e9beb..4f23488b15f3 100644 --- a/drivers/gpu/drm/vkms/vkms_crtc.c +++ b/drivers/gpu/drm/vkms/vkms_crtc.c @@ -207,7 +207,6 @@ static int vkms_crtc_atomic_check(struct drm_crtc *crtc, return -ENOMEM; vkms_state->num_active_planes = i; - i = 0; drm_for_each_plane_mask(plane, crtc->dev, crtc_state->plane_mask) { plane_state = drm_atomic_get_existing_plane_state(crtc_state->state, plane); @@ -215,7 +214,7 @@ static int vkms_crtc_atomic_check(struct drm_crtc *crtc, if (!plane_state->visible) continue; - vkms_state->active_planes[i++] = + vkms_state->active_planes[plane_state->normalized_zpos] = to_vkms_plane_state(plane_state); } diff --git a/drivers/gpu/drm/vkms/vkms_drv.c b/drivers/gpu/drm/vkms/vkms_drv.c index 0ffe5f0e33f7..d7ee64f5e339 100644 --- a/drivers/gpu/drm/vkms/vkms_drv.c +++ b/drivers/gpu/drm/vkms/vkms_drv.c @@ -153,6 +153,7 @@ static int vkms_modeset_init(struct vkms_device *vkmsdev) * fbdev helpers. We have to go with 0, meaning "pick the default", * which ix XRGB8888 in all cases. */ dev->mode_config.preferred_depth = 0; + dev->mode_config.normalize_zpos = true; dev->mode_config.helper_private = &vkms_mode_config_helpers; return vkms_output_init(vkmsdev, 0); diff --git a/drivers/gpu/drm/vkms/vkms_plane.c b/drivers/gpu/drm/vkms/vkms_plane.c index 32409e15244b..55d22a6a401a 100644 --- a/drivers/gpu/drm/vkms/vkms_plane.c +++ b/drivers/gpu/drm/vkms/vkms_plane.c @@ -81,6 +81,8 @@ static void vkms_plane_reset(struct drm_plane *plane) } __drm_gem_reset_shadow_plane(plane, &vkms_state->base); + vkms_state->base.base.zpos = drm_plane_index(plane); + vkms_state->base.base.normalized_zpos = drm_plane_index(plane); } static const struct drm_plane_funcs vkms_plane_funcs = { @@ -158,6 +160,22 @@ static const struct drm_plane_helper_funcs vkms_primary_helper_funcs = { DRM_GEM_SHADOW_PLANE_HELPER_FUNCS, }; +static int vkms_plane_create_zpos_property(struct vkms_plane *plane) +{ + int ret; + unsigned int zpos = drm_plane_index(&plane->base); + + if (plane->base.type == DRM_PLANE_TYPE_OVERLAY) { + ret = drm_plane_create_zpos_property(&plane->base, zpos, + 1, NUM_OVERLAY_PLANES); + } else { + ret = drm_plane_create_zpos_immutable_property(&plane->base, + zpos); + } + + return ret; +} + struct vkms_plane *vkms_plane_init(struct vkms_device *vkmsdev, enum drm_plane_type type, int index) { @@ -166,6 +184,7 @@ struct vkms_plane *vkms_plane_init(struct vkms_device *vkmsdev, struct vkms_plane *plane; const u32 *formats; int nformats; + int ret; switch (type) { case DRM_PLANE_TYPE_PRIMARY: @@ -195,5 +214,9 @@ struct vkms_plane *vkms_plane_init(struct vkms_device *vkmsdev, drm_plane_helper_add(&plane->base, funcs); + ret = vkms_plane_create_zpos_property(plane); + if (ret) + return ERR_PTR(ret); + return plane; } -- 2.25.1