Skip to content

Commit 1ce34fb

Browse files
Rodrigo Siqueiragregkh
authored andcommitted
drm/amd/display: Fix two cursor duplication when using overlay
[ Upstream commit 16e9b3e ] Our driver supports overlay planes, and as expected, some userspace compositor takes advantage of these features. If the userspace is not enabling the cursor, they can use multiple planes as they please. Nevertheless, we start to have constraints when userspace tries to enable hardware cursor with various planes. Basically, we cannot draw the cursor at the same size and position on two separated pipes since it uses extra bandwidth and DML only run with one cursor. For those reasons, when we enable hardware cursor and multiple planes, our driver should accept variations like the ones described below: +-------------+ +--------------+ | +---------+ | | | | |Primary | | | Primary | | | | | | Overlay | | +---------+ | | | |Overlay | | | +-------------+ +--------------+ In this scenario, we can have the desktop UI in the overlay and some other framebuffer attached to the primary plane (e.g., video). However, userspace needs to obey some rules and avoid scenarios like the ones described below (when enabling hw cursor): +--------+ |Overlay | +-------------+ +-----+-------+ +-| |--+ | +--------+ | +--------+ | | +--------+ | | |Overlay | | |Overlay | | | | | | | | | | | | | | +--------+ | +--------+ | | | | Primary | | Primary | | Primary | +-------------+ +-------------+ +-------------+ +-------------+ +-------------+ | +--------+ | Primary | | |Overlay | | | | | | | | | +--------+ | +--------+ | | Primary | | |Overlay | | +-------------+ +-| |--+ +--------+ If the userspace violates some of the above scenarios, our driver needs to reject the commit; otherwise, we can have unexpected behavior. Since we don't have a proper driver validation for the above case, we can see some problems like a duplicate cursor in applications that use multiple planes. This commit fixes the cursor issue and others by adding adequate verification for multiple planes. Change since V1 (Harry and Sean): - Remove cursor verification from the equation. Cc: Louis Li <Ching-shih.Li@amd.com> Cc: Nicholas Kazlauskas <Nicholas.Kazlauskas@amd.com> Cc: Harry Wentland <Harry.Wentland@amd.com> Cc: Hersen Wu <hersenxs.wu@amd.com> Cc: Sean Paul <seanpaul@chromium.org> Signed-off-by: Rodrigo Siqueira <Rodrigo.Siqueira@amd.com> Reviewed-by: Harry Wentland <harry.wentland@amd.com> Signed-off-by: Alex Deucher <alexander.deucher@amd.com> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent 3851a86 commit 1ce34fb

1 file changed

Lines changed: 51 additions & 0 deletions

File tree

drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8611,6 +8611,53 @@ static int add_affected_mst_dsc_crtcs(struct drm_atomic_state *state, struct drm
86118611
}
86128612
#endif
86138613

8614+
static int validate_overlay(struct drm_atomic_state *state)
8615+
{
8616+
int i;
8617+
struct drm_plane *plane;
8618+
struct drm_plane_state *old_plane_state, *new_plane_state;
8619+
struct drm_plane_state *primary_state, *overlay_state = NULL;
8620+
8621+
/* Check if primary plane is contained inside overlay */
8622+
for_each_oldnew_plane_in_state_reverse(state, plane, old_plane_state, new_plane_state, i) {
8623+
if (plane->type == DRM_PLANE_TYPE_OVERLAY) {
8624+
if (drm_atomic_plane_disabling(plane->state, new_plane_state))
8625+
return 0;
8626+
8627+
overlay_state = new_plane_state;
8628+
continue;
8629+
}
8630+
}
8631+
8632+
/* check if we're making changes to the overlay plane */
8633+
if (!overlay_state)
8634+
return 0;
8635+
8636+
/* check if overlay plane is enabled */
8637+
if (!overlay_state->crtc)
8638+
return 0;
8639+
8640+
/* find the primary plane for the CRTC that the overlay is enabled on */
8641+
primary_state = drm_atomic_get_plane_state(state, overlay_state->crtc->primary);
8642+
if (IS_ERR(primary_state))
8643+
return PTR_ERR(primary_state);
8644+
8645+
/* check if primary plane is enabled */
8646+
if (!primary_state->crtc)
8647+
return 0;
8648+
8649+
/* Perform the bounds check to ensure the overlay plane covers the primary */
8650+
if (primary_state->crtc_x < overlay_state->crtc_x ||
8651+
primary_state->crtc_y < overlay_state->crtc_y ||
8652+
primary_state->crtc_x + primary_state->crtc_w > overlay_state->crtc_x + overlay_state->crtc_w ||
8653+
primary_state->crtc_y + primary_state->crtc_h > overlay_state->crtc_y + overlay_state->crtc_h) {
8654+
DRM_DEBUG_ATOMIC("Overlay plane is enabled with hardware cursor but does not fully cover primary plane\n");
8655+
return -EINVAL;
8656+
}
8657+
8658+
return 0;
8659+
}
8660+
86148661
/**
86158662
* amdgpu_dm_atomic_check() - Atomic check implementation for AMDgpu DM.
86168663
* @dev: The DRM device
@@ -8789,6 +8836,10 @@ static int amdgpu_dm_atomic_check(struct drm_device *dev,
87898836
goto fail;
87908837
}
87918838

8839+
ret = validate_overlay(state);
8840+
if (ret)
8841+
goto fail;
8842+
87928843
/* Add new/modified planes */
87938844
for_each_oldnew_plane_in_state_reverse(state, plane, old_plane_state, new_plane_state, i) {
87948845
ret = dm_update_plane_state(dc, state, plane,

0 commit comments

Comments
 (0)