Skip to content

Commit 597a89b

Browse files
chadmedjannau
authored andcommitted
drm: apple: constrain swaps to maximum blendable surfaces
Despite having 4 surfaces, DCP can only blend two of them at once. Constrain swaps to two surfaces, and warn if userspace somehow tries to give us more to swap. Signed-off-by: James Calligeros <[email protected]>
1 parent 9b1cbf8 commit 597a89b

2 files changed

Lines changed: 7 additions & 3 deletions

File tree

drivers/gpu/drm/apple/iomfb.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,8 @@ enum iomfb_property_id {
7777
/* Structures used in v12.0 firmware */
7878

7979
#define SWAP_SURFACES 4
80+
/* We have 4 surfaces, but we can only ever blend two */
81+
#define MAX_BLEND_SURFACES 2
8082
#define MAX_PLANES 3
8183

8284
enum dcp_colorspace {

drivers/gpu/drm/apple/iomfb_template.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -904,6 +904,7 @@ void DCP_FW_NAME(iomfb_poweroff)(struct apple_dcp *dcp)
904904
swap->swap.bl_power = 0;
905905
}
906906

907+
/* Null all surfaces */
907908
for (int l = 0; l < SWAP_SURFACES; l++)
908909
swap->surf_null[l] = true;
909910
#if DCP_FW_VER >= DCP_FW_VERSION(13, 2, 0)
@@ -1274,7 +1275,7 @@ void DCP_FW_NAME(iomfb_flush)(struct apple_dcp *dcp, struct drm_crtc *crtc, stru
12741275

12751276
crtc_state = drm_atomic_get_new_crtc_state(state, crtc);
12761277

1277-
/* Reset to defaults */
1278+
/* Reset all surfaces to defaults */
12781279
memset(req, 0, sizeof(*req));
12791280
for (l = 0; l < SWAP_SURFACES; l++)
12801281
req->surf_null[l] = true;
@@ -1314,9 +1315,10 @@ void DCP_FW_NAME(iomfb_flush)(struct apple_dcp *dcp, struct drm_crtc *crtc, stru
13141315
* Despite having 4 surfaces, we can only blend two. Surface 0 is
13151316
* also unusable on some machines, so ignore it.
13161317
*/
1317-
l = 2 - new_state->zpos;
13181318

1319-
WARN_ON(l >= SWAP_SURFACES);
1319+
l = MAX_BLEND_SURFACES - new_state->zpos;
1320+
1321+
WARN_ON(l > MAX_BLEND_SURFACES);
13201322

13211323
req->swap.swap_enabled |= BIT(l);
13221324

0 commit comments

Comments
 (0)