Skip to content

Commit 6beb8c2

Browse files
mattropedanvet
authored andcommitted
drm/i915: Consolidate plane 'prepare' functions (v2)
The 'prepare' step for all types of planes are pretty similar; consolidate the three 'prepare' functions into a single function. This paves the way for future integration with the atomic plane handlers. Note that we pull the 'wait for pending flips' functionality out of the primary plane's prepare step and place it directly in the 'setplane' code. When we move to the atomic plane handlers, this code will be in the 'atomic begin' step. v2: Update GEM fb tracking for physical cursors also (Ander) Signed-off-by: Matt Roper <matthew.d.roper@intel.com> Reviewed-by: Ander Conselvan de Oliveira <ander.conselvan.de.oliveira@intel.com> Signed-off-by: Daniel Vetter <daniel.vetter@ffwll.ch>
1 parent 2b875c2 commit 6beb8c2

File tree

3 files changed

+98
-116
lines changed

3 files changed

+98
-116
lines changed

drivers/gpu/drm/i915/intel_display.c

Lines changed: 90 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -11689,6 +11689,65 @@ intel_primary_plane_disable(struct drm_plane *plane)
1168911689
return 0;
1169011690
}
1169111691

11692+
/**
11693+
* intel_prepare_plane_fb - Prepare fb for usage on plane
11694+
* @plane: drm plane to prepare for
11695+
* @fb: framebuffer to prepare for presentation
11696+
*
11697+
* Prepares a framebuffer for usage on a display plane. Generally this
11698+
* involves pinning the underlying object and updating the frontbuffer tracking
11699+
* bits. Some older platforms need special physical address handling for
11700+
* cursor planes.
11701+
*
11702+
* Returns 0 on success, negative error code on failure.
11703+
*/
11704+
int
11705+
intel_prepare_plane_fb(struct drm_plane *plane,
11706+
struct drm_framebuffer *fb)
11707+
{
11708+
struct drm_device *dev = plane->dev;
11709+
struct intel_plane *intel_plane = to_intel_plane(plane);
11710+
enum pipe pipe = intel_plane->pipe;
11711+
struct drm_i915_gem_object *obj = intel_fb_obj(fb);
11712+
struct drm_i915_gem_object *old_obj = intel_fb_obj(plane->fb);
11713+
unsigned frontbuffer_bits = 0;
11714+
int ret = 0;
11715+
11716+
if (WARN_ON(fb == plane->fb || !obj))
11717+
return 0;
11718+
11719+
switch (plane->type) {
11720+
case DRM_PLANE_TYPE_PRIMARY:
11721+
frontbuffer_bits = INTEL_FRONTBUFFER_PRIMARY(pipe);
11722+
break;
11723+
case DRM_PLANE_TYPE_CURSOR:
11724+
frontbuffer_bits = INTEL_FRONTBUFFER_CURSOR(pipe);
11725+
break;
11726+
case DRM_PLANE_TYPE_OVERLAY:
11727+
frontbuffer_bits = INTEL_FRONTBUFFER_SPRITE(pipe);
11728+
break;
11729+
}
11730+
11731+
mutex_lock(&dev->struct_mutex);
11732+
11733+
if (plane->type == DRM_PLANE_TYPE_CURSOR &&
11734+
INTEL_INFO(dev)->cursor_needs_physical) {
11735+
int align = IS_I830(dev) ? 16 * 1024 : 256;
11736+
ret = i915_gem_object_attach_phys(obj, align);
11737+
if (ret)
11738+
DRM_DEBUG_KMS("failed to attach phys object\n");
11739+
} else {
11740+
ret = intel_pin_and_fence_fb_obj(plane, fb, NULL);
11741+
}
11742+
11743+
if (ret == 0)
11744+
i915_gem_track_fb(old_obj, obj, frontbuffer_bits);
11745+
11746+
mutex_unlock(&dev->struct_mutex);
11747+
11748+
return ret;
11749+
}
11750+
1169211751
static int
1169311752
intel_check_primary_plane(struct drm_plane *plane,
1169411753
struct intel_plane_state *state)
@@ -11706,42 +11765,6 @@ intel_check_primary_plane(struct drm_plane *plane,
1170611765
false, true, &state->visible);
1170711766
}
1170811767

11709-
static int
11710-
intel_prepare_primary_plane(struct drm_plane *plane,
11711-
struct intel_plane_state *state)
11712-
{
11713-
struct drm_crtc *crtc = state->base.crtc;
11714-
struct drm_framebuffer *fb = state->base.fb;
11715-
struct drm_device *dev = crtc->dev;
11716-
struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
11717-
enum pipe pipe = intel_crtc->pipe;
11718-
struct drm_i915_gem_object *obj = intel_fb_obj(fb);
11719-
struct drm_i915_gem_object *old_obj = intel_fb_obj(plane->fb);
11720-
int ret;
11721-
11722-
intel_crtc_wait_for_pending_flips(crtc);
11723-
11724-
if (intel_crtc_has_pending_flip(crtc)) {
11725-
DRM_ERROR("pipe is still busy with an old pageflip\n");
11726-
return -EBUSY;
11727-
}
11728-
11729-
if (old_obj != obj) {
11730-
mutex_lock(&dev->struct_mutex);
11731-
ret = intel_pin_and_fence_fb_obj(plane, fb, NULL);
11732-
if (ret == 0)
11733-
i915_gem_track_fb(old_obj, obj,
11734-
INTEL_FRONTBUFFER_PRIMARY(pipe));
11735-
mutex_unlock(&dev->struct_mutex);
11736-
if (ret != 0) {
11737-
DRM_DEBUG_KMS("pin & fence failed\n");
11738-
return ret;
11739-
}
11740-
}
11741-
11742-
return 0;
11743-
}
11744-
1174511768
static void
1174611769
intel_commit_primary_plane(struct drm_plane *plane,
1174711770
struct intel_plane_state *state)
@@ -11843,6 +11866,7 @@ intel_primary_plane_setplane(struct drm_plane *plane, struct drm_crtc *crtc,
1184311866
uint32_t src_x, uint32_t src_y,
1184411867
uint32_t src_w, uint32_t src_h)
1184511868
{
11869+
struct drm_framebuffer *old_fb = plane->fb;
1184611870
struct intel_plane_state state;
1184711871
struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
1184811872
int ret;
@@ -11874,9 +11898,18 @@ intel_primary_plane_setplane(struct drm_plane *plane, struct drm_crtc *crtc,
1187411898
if (ret)
1187511899
return ret;
1187611900

11877-
ret = intel_prepare_primary_plane(plane, &state);
11878-
if (ret)
11879-
return ret;
11901+
intel_crtc_wait_for_pending_flips(crtc);
11902+
11903+
if (intel_crtc_has_pending_flip(crtc)) {
11904+
DRM_ERROR("pipe is still busy with an old pageflip\n");
11905+
return -EBUSY;
11906+
}
11907+
11908+
if (fb != old_fb && fb) {
11909+
ret = intel_prepare_plane_fb(plane, fb);
11910+
if (ret)
11911+
return ret;
11912+
}
1188011913

1188111914
intel_commit_primary_plane(plane, &state);
1188211915

@@ -12013,42 +12046,6 @@ intel_check_cursor_plane(struct drm_plane *plane,
1201312046
return ret;
1201412047
}
1201512048

12016-
static int
12017-
intel_prepare_cursor_plane(struct drm_plane *plane,
12018-
struct intel_plane_state *state)
12019-
{
12020-
struct drm_device *dev = plane->dev;
12021-
struct drm_framebuffer *fb = state->base.fb;
12022-
struct intel_crtc *intel_crtc = to_intel_crtc(state->base.crtc);
12023-
struct drm_i915_gem_object *obj = intel_fb_obj(fb);
12024-
struct drm_i915_gem_object *old_obj = intel_fb_obj(plane->fb);
12025-
enum pipe pipe = intel_crtc->pipe;
12026-
int ret = 0;
12027-
12028-
if (old_obj != obj) {
12029-
/* we only need to pin inside GTT if cursor is non-phy */
12030-
mutex_lock(&dev->struct_mutex);
12031-
if (!INTEL_INFO(dev)->cursor_needs_physical) {
12032-
if (obj)
12033-
ret = intel_pin_and_fence_fb_obj(plane, fb, NULL);
12034-
} else {
12035-
int align = IS_I830(dev) ? 16 * 1024 : 256;
12036-
if (obj)
12037-
ret = i915_gem_object_attach_phys(obj, align);
12038-
if (ret)
12039-
DRM_DEBUG_KMS("failed to attach phys object\n");
12040-
}
12041-
12042-
if (ret == 0)
12043-
i915_gem_track_fb(intel_crtc->cursor_bo, obj,
12044-
INTEL_FRONTBUFFER_CURSOR(pipe));
12045-
12046-
mutex_unlock(&dev->struct_mutex);
12047-
}
12048-
12049-
return ret;
12050-
}
12051-
1205212049
static void
1205312050
intel_commit_cursor_plane(struct drm_plane *plane,
1205412051
struct intel_plane_state *state)
@@ -12058,6 +12055,7 @@ intel_commit_cursor_plane(struct drm_plane *plane,
1205812055
struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
1205912056
struct intel_plane *intel_plane = to_intel_plane(plane);
1206012057
struct drm_i915_gem_object *obj = intel_fb_obj(state->base.fb);
12058+
struct drm_i915_gem_object *old_obj = intel_fb_obj(plane->fb);
1206112059
enum pipe pipe = intel_crtc->pipe;
1206212060
unsigned old_width;
1206312061
uint32_t addr;
@@ -12079,6 +12077,17 @@ intel_commit_cursor_plane(struct drm_plane *plane,
1207912077
if (intel_crtc->cursor_bo == obj)
1208012078
goto update;
1208112079

12080+
/*
12081+
* 'prepare' is only called when fb != NULL; we still need to update
12082+
* frontbuffer tracking for the 'disable' case here.
12083+
*/
12084+
if (!obj) {
12085+
mutex_lock(&dev->struct_mutex);
12086+
i915_gem_track_fb(old_obj, NULL,
12087+
INTEL_FRONTBUFFER_CURSOR(pipe));
12088+
mutex_unlock(&dev->struct_mutex);
12089+
}
12090+
1208212091
if (!obj)
1208312092
addr = 0;
1208412093
else if (!INTEL_INFO(dev)->cursor_needs_physical)
@@ -12118,6 +12127,7 @@ intel_cursor_plane_update(struct drm_plane *plane, struct drm_crtc *crtc,
1211812127
uint32_t src_x, uint32_t src_y,
1211912128
uint32_t src_w, uint32_t src_h)
1212012129
{
12130+
struct drm_framebuffer *old_fb = plane->fb;
1212112131
struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
1212212132
struct intel_plane_state state;
1212312133
int ret;
@@ -12149,9 +12159,11 @@ intel_cursor_plane_update(struct drm_plane *plane, struct drm_crtc *crtc,
1214912159
if (ret)
1215012160
return ret;
1215112161

12152-
ret = intel_prepare_cursor_plane(plane, &state);
12153-
if (ret)
12154-
return ret;
12162+
if (fb != old_fb && fb) {
12163+
ret = intel_prepare_plane_fb(plane, fb);
12164+
if (ret)
12165+
return ret;
12166+
}
1215512167

1215612168
intel_commit_cursor_plane(plane, &state);
1215712169

drivers/gpu/drm/i915/intel_drv.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -922,6 +922,8 @@ void intel_prepare_page_flip(struct drm_device *dev, int plane);
922922
void intel_finish_page_flip(struct drm_device *dev, int pipe);
923923
void intel_finish_page_flip_plane(struct drm_device *dev, int plane);
924924
void intel_check_page_flip(struct drm_device *dev, int pipe);
925+
int intel_prepare_plane_fb(struct drm_plane *plane,
926+
struct drm_framebuffer *fb);
925927

926928
/* shared dpll functions */
927929
struct intel_shared_dpll *intel_crtc_to_shared_dpll(struct intel_crtc *crtc);

drivers/gpu/drm/i915/intel_sprite.c

Lines changed: 6 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1257,41 +1257,6 @@ intel_check_sprite_plane(struct drm_plane *plane,
12571257
return 0;
12581258
}
12591259

1260-
static int
1261-
intel_prepare_sprite_plane(struct drm_plane *plane,
1262-
struct intel_plane_state *state)
1263-
{
1264-
struct drm_device *dev = plane->dev;
1265-
struct drm_crtc *crtc = state->base.crtc;
1266-
struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
1267-
struct intel_plane *intel_plane = to_intel_plane(plane);
1268-
enum pipe pipe = intel_crtc->pipe;
1269-
struct drm_framebuffer *fb = state->base.fb;
1270-
struct drm_i915_gem_object *obj = intel_fb_obj(fb);
1271-
struct drm_i915_gem_object *old_obj = intel_plane->obj;
1272-
int ret;
1273-
1274-
if (old_obj != obj) {
1275-
mutex_lock(&dev->struct_mutex);
1276-
1277-
/* Note that this will apply the VT-d workaround for scanouts,
1278-
* which is more restrictive than required for sprites. (The
1279-
* primary plane requires 256KiB alignment with 64 PTE padding,
1280-
* the sprite planes only require 128KiB alignment and 32 PTE
1281-
* padding.
1282-
*/
1283-
ret = intel_pin_and_fence_fb_obj(plane, fb, NULL);
1284-
if (ret == 0)
1285-
i915_gem_track_fb(old_obj, obj,
1286-
INTEL_FRONTBUFFER_SPRITE(pipe));
1287-
mutex_unlock(&dev->struct_mutex);
1288-
if (ret)
1289-
return ret;
1290-
}
1291-
1292-
return 0;
1293-
}
1294-
12951260
static void
12961261
intel_commit_sprite_plane(struct drm_plane *plane,
12971262
struct intel_plane_state *state)
@@ -1387,6 +1352,7 @@ intel_update_plane(struct drm_plane *plane, struct drm_crtc *crtc,
13871352
uint32_t src_x, uint32_t src_y,
13881353
uint32_t src_w, uint32_t src_h)
13891354
{
1355+
struct drm_framebuffer *old_fb = plane->fb;
13901356
struct intel_plane_state state;
13911357
struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
13921358
int ret;
@@ -1417,9 +1383,11 @@ intel_update_plane(struct drm_plane *plane, struct drm_crtc *crtc,
14171383
if (ret)
14181384
return ret;
14191385

1420-
ret = intel_prepare_sprite_plane(plane, &state);
1421-
if (ret)
1422-
return ret;
1386+
if (fb != old_fb && fb) {
1387+
ret = intel_prepare_plane_fb(plane, fb);
1388+
if (ret)
1389+
return ret;
1390+
}
14231391

14241392
intel_commit_sprite_plane(plane, &state);
14251393
return 0;

0 commit comments

Comments
 (0)