Commit ea2c67bb authored by Matt Roper's avatar Matt Roper Committed by Daniel Vetter

drm/i915: Move to atomic plane helpers (v9)

Switch plane handling to use the atomic plane helpers.  This means that
rather than provide our own implementations of .update_plane() and
.disable_plane(), we expose the lower-level check/prepare/commit/cleanup
entrypoints and let the DRM core implement update/disable for us using
those entrypoints.

The other main change that falls out of this patch is that our
drm_plane's will now always have a valid plane->state that contains the
relevant plane state (initial state is allocated at plane creation).
The base drm_plane_state pointed to holds the requested source/dest
coordinates, and the subclassed intel_plane_state holds the adjusted
values that our driver actually uses.

v2:
 - Renamed file from intel_atomic.c to intel_atomic_plane.c (Daniel)
 - Fix a copy/paste comment mistake (Bob)

v3:
 - Use prepare/cleanup functions that we've already factored out
 - Use newly refactored pre_commit/commit/post_commit to avoid sleeping
   during vblank evasion

v4:
 - Rebase to latest di-nightly requires adding an 'old_state' parameter
   to atomic_update;

v5:
 - Must have botched a rebase somewhere and lost some work.  Restore
   state 'dirty' flag to let begin/end code know which planes to
   run the pre_commit/post_commit hooks for.  This would have actually
   shown up as broken in the next commit rather than this one.

v6:
 - Squash kerneldoc patch into this one.
 - Previous patches have now already taken care of most of the
   infrastructure that used to be in this patch.  All we're adding here
   now is some thin wrappers.

v7:
 - Check return of intel_plane_duplicate_state() for allocation
   failures.

v8:
 - Drop unused drm_plane_state -> intel_plane_state cast.  (Ander)
 - Squash in actual transition to plane helpers.  Significant
   refactoring earlier in the patchset has made the combined
   prep+transition much easier to swallow than it was in earlier
   iterations. (Ander)

v9:
 - s/track_fbs/disabled_planes/ in the atomic crtc flags.  The only fb's
   we need to update frontbuffer tracking for are those on a plane about
   to be disabled (since the atomic helpers never call prepare_fb() when
   disabling a plane), so the new name more accurately describes what
   we're actually tracking.

Testcase: igt/kms_plane
Testcase: igt/kms_universal_plane
Testcase: igt/kms_cursor_crc
Signed-off-by: default avatarMatt Roper <matthew.d.roper@intel.com>
Reviewed-by: default avatarAnder Conselvan de Oliveira <conselvan2@gmail.com>
Signed-off-by: default avatarDaniel Vetter <daniel.vetter@ffwll.ch>
parent 4a3b8769
...@@ -3931,6 +3931,11 @@ int num_ioctls;</synopsis> ...@@ -3931,6 +3931,11 @@ int num_ioctls;</synopsis>
framebuffer compression and panel self refresh. framebuffer compression and panel self refresh.
</para> </para>
</sect2> </sect2>
<sect2>
<title>Atomic Plane Helpers</title>
!Pdrivers/gpu/drm/i915/intel_atomic_plane.c atomic plane helpers
!Idrivers/gpu/drm/i915/intel_atomic_plane.c
</sect2>
<sect2> <sect2>
<title>Output Probing</title> <title>Output Probing</title>
<para> <para>
......
...@@ -66,6 +66,7 @@ i915-y += dvo_ch7017.o \ ...@@ -66,6 +66,7 @@ i915-y += dvo_ch7017.o \
dvo_ns2501.o \ dvo_ns2501.o \
dvo_sil164.o \ dvo_sil164.o \
dvo_tfp410.o \ dvo_tfp410.o \
intel_atomic_plane.o \
intel_crt.o \ intel_crt.o \
intel_ddi.o \ intel_ddi.o \
intel_dp.o \ intel_dp.o \
......
/*
* Copyright © 2014 Intel Corporation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice (including the next
* paragraph) shall be included in all copies or substantial portions of the
* Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/
/**
* DOC: atomic plane helper support
*
* The functions here are used by the atomic plane helper functions to
* implement legacy plane updates (i.e., drm_plane->update_plane() and
* drm_plane->disable_plane()). This allows plane updates to use the
* atomic state infrastructure and perform plane updates as separate
* prepare/check/commit/cleanup steps.
*/
#include <drm/drmP.h>
#include <drm/drm_atomic_helper.h>
#include <drm/drm_plane_helper.h>
#include "intel_drv.h"
/**
* intel_plane_duplicate_state - duplicate plane state
* @plane: drm plane
*
* Allocates and returns a copy of the plane state (both common and
* Intel-specific) for the specified plane.
*
* Returns: The newly allocated plane state, or NULL or failure.
*/
struct drm_plane_state *
intel_plane_duplicate_state(struct drm_plane *plane)
{
struct intel_plane_state *state;
if (plane->state)
state = kmemdup(plane->state, sizeof(*state), GFP_KERNEL);
else
state = kzalloc(sizeof(*state), GFP_KERNEL);
if (!state)
return NULL;
if (state->base.fb)
drm_framebuffer_reference(state->base.fb);
return &state->base;
}
/**
* intel_plane_destroy_state - destroy plane state
* @plane: drm plane
*
* Destroys the plane state (both common and Intel-specific) for the
* specified plane.
*/
void
intel_plane_destroy_state(struct drm_plane *plane,
struct drm_plane_state *state)
{
drm_atomic_helper_plane_destroy_state(plane, state);
}
static int intel_plane_atomic_check(struct drm_plane *plane,
struct drm_plane_state *state)
{
struct drm_crtc *crtc = state->crtc;
struct intel_crtc *intel_crtc;
struct intel_plane *intel_plane = to_intel_plane(plane);
struct intel_plane_state *intel_state = to_intel_plane_state(state);
crtc = crtc ? crtc : plane->crtc;
intel_crtc = to_intel_crtc(crtc);
/*
* The original src/dest coordinates are stored in state->base, but
* we want to keep another copy internal to our driver that we can
* clip/modify ourselves.
*/
intel_state->src.x1 = state->src_x;
intel_state->src.y1 = state->src_y;
intel_state->src.x2 = state->src_x + state->src_w;
intel_state->src.y2 = state->src_y + state->src_h;
intel_state->dst.x1 = state->crtc_x;
intel_state->dst.y1 = state->crtc_y;
intel_state->dst.x2 = state->crtc_x + state->crtc_w;
intel_state->dst.y2 = state->crtc_y + state->crtc_h;
/* Clip all planes to CRTC size, or 0x0 if CRTC is disabled */
intel_state->clip.x1 = 0;
intel_state->clip.y1 = 0;
intel_state->clip.x2 =
intel_crtc->active ? intel_crtc->config.pipe_src_w : 0;
intel_state->clip.y2 =
intel_crtc->active ? intel_crtc->config.pipe_src_h : 0;
/*
* Disabling a plane is always okay; we just need to update
* fb tracking in a special way since cleanup_fb() won't
* get called by the plane helpers.
*/
if (state->fb == NULL && plane->state->fb != NULL) {
/*
* 'prepare' is never called when plane is being disabled, so
* we need to handle frontbuffer tracking as a special case
*/
intel_crtc->atomic.disabled_planes |=
(1 << drm_plane_index(plane));
}
return intel_plane->check_plane(plane, intel_state);
}
static void intel_plane_atomic_update(struct drm_plane *plane,
struct drm_plane_state *old_state)
{
struct intel_plane *intel_plane = to_intel_plane(plane);
struct intel_plane_state *intel_state =
to_intel_plane_state(plane->state);
/* Don't disable an already disabled plane */
if (!plane->state->fb && !old_state->fb)
return;
intel_plane->commit_plane(plane, intel_state);
}
const struct drm_plane_helper_funcs intel_plane_helper_funcs = {
.prepare_fb = intel_prepare_plane_fb,
.cleanup_fb = intel_cleanup_plane_fb,
.atomic_check = intel_plane_atomic_check,
.atomic_update = intel_plane_atomic_update,
};
This diff is collapsed.
...@@ -248,8 +248,6 @@ struct intel_plane_state { ...@@ -248,8 +248,6 @@ struct intel_plane_state {
struct drm_rect src; struct drm_rect src;
struct drm_rect dst; struct drm_rect dst;
struct drm_rect clip; struct drm_rect clip;
struct drm_rect orig_src;
struct drm_rect orig_dst;
bool visible; bool visible;
/* /*
...@@ -437,6 +435,7 @@ struct intel_crtc_atomic_commit { ...@@ -437,6 +435,7 @@ struct intel_crtc_atomic_commit {
bool disable_fbc; bool disable_fbc;
bool pre_disable_primary; bool pre_disable_primary;
bool update_wm; bool update_wm;
unsigned disabled_planes;
/* Sleepable operations to perform after commit */ /* Sleepable operations to perform after commit */
unsigned fb_bits; unsigned fb_bits;
...@@ -575,6 +574,7 @@ struct cxsr_latency { ...@@ -575,6 +574,7 @@ struct cxsr_latency {
#define to_intel_encoder(x) container_of(x, struct intel_encoder, base) #define to_intel_encoder(x) container_of(x, struct intel_encoder, base)
#define to_intel_framebuffer(x) container_of(x, struct intel_framebuffer, base) #define to_intel_framebuffer(x) container_of(x, struct intel_framebuffer, base)
#define to_intel_plane(x) container_of(x, struct intel_plane, base) #define to_intel_plane(x) container_of(x, struct intel_plane, base)
#define to_intel_plane_state(x) container_of(x, struct intel_plane_state, base)
#define intel_fb_obj(x) (x ? to_intel_framebuffer(x)->obj : NULL) #define intel_fb_obj(x) (x ? to_intel_framebuffer(x)->obj : NULL)
struct intel_hdmi { struct intel_hdmi {
...@@ -1255,4 +1255,10 @@ void intel_pre_disable_primary(struct drm_crtc *crtc); ...@@ -1255,4 +1255,10 @@ void intel_pre_disable_primary(struct drm_crtc *crtc);
/* intel_tv.c */ /* intel_tv.c */
void intel_tv_init(struct drm_device *dev); void intel_tv_init(struct drm_device *dev);
/* intel_atomic.c */
struct drm_plane_state *intel_plane_duplicate_state(struct drm_plane *plane);
void intel_plane_destroy_state(struct drm_plane *plane,
struct drm_plane_state *state);
extern const struct drm_plane_helper_funcs intel_plane_helper_funcs;
#endif /* __INTEL_DRV_H__ */ #endif /* __INTEL_DRV_H__ */
...@@ -33,6 +33,7 @@ ...@@ -33,6 +33,7 @@
#include <drm/drm_crtc.h> #include <drm/drm_crtc.h>
#include <drm/drm_fourcc.h> #include <drm/drm_fourcc.h>
#include <drm/drm_rect.h> #include <drm/drm_rect.h>
#include <drm/drm_plane_helper.h>
#include "intel_drv.h" #include "intel_drv.h"
#include <drm/i915_drm.h> #include <drm/i915_drm.h>
#include "i915_drv.h" #include "i915_drv.h"
...@@ -1081,12 +1082,13 @@ intel_check_sprite_plane(struct drm_plane *plane, ...@@ -1081,12 +1082,13 @@ intel_check_sprite_plane(struct drm_plane *plane,
uint32_t src_x, src_y, src_w, src_h; uint32_t src_x, src_y, src_w, src_h;
struct drm_rect *src = &state->src; struct drm_rect *src = &state->src;
struct drm_rect *dst = &state->dst; struct drm_rect *dst = &state->dst;
struct drm_rect *orig_src = &state->orig_src;
const struct drm_rect *clip = &state->clip; const struct drm_rect *clip = &state->clip;
int hscale, vscale; int hscale, vscale;
int max_scale, min_scale; int max_scale, min_scale;
int pixel_size; int pixel_size;
intel_crtc = intel_crtc ? intel_crtc : to_intel_crtc(plane->crtc);
if (!fb) { if (!fb) {
state->visible = false; state->visible = false;
goto finish; goto finish;
...@@ -1167,10 +1169,10 @@ intel_check_sprite_plane(struct drm_plane *plane, ...@@ -1167,10 +1169,10 @@ intel_check_sprite_plane(struct drm_plane *plane,
intel_plane->rotation); intel_plane->rotation);
/* sanity check to make sure the src viewport wasn't enlarged */ /* sanity check to make sure the src viewport wasn't enlarged */
WARN_ON(src->x1 < (int) orig_src->x1 || WARN_ON(src->x1 < (int) state->base.src_x ||
src->y1 < (int) orig_src->y1 || src->y1 < (int) state->base.src_y ||
src->x2 > (int) orig_src->x2 || src->x2 > (int) state->base.src_x + state->base.src_w ||
src->y2 > (int) orig_src->y2); src->y2 > (int) state->base.src_y + state->base.src_h);
/* /*
* Hardware doesn't handle subpixel coordinates. * Hardware doesn't handle subpixel coordinates.
...@@ -1267,7 +1269,7 @@ intel_commit_sprite_plane(struct drm_plane *plane, ...@@ -1267,7 +1269,7 @@ intel_commit_sprite_plane(struct drm_plane *plane,
struct intel_plane_state *state) struct intel_plane_state *state)
{ {
struct drm_crtc *crtc = state->base.crtc; struct drm_crtc *crtc = state->base.crtc;
struct intel_crtc *intel_crtc = to_intel_crtc(crtc); struct intel_crtc *intel_crtc;
struct intel_plane *intel_plane = to_intel_plane(plane); struct intel_plane *intel_plane = to_intel_plane(plane);
struct drm_framebuffer *fb = state->base.fb; struct drm_framebuffer *fb = state->base.fb;
struct drm_i915_gem_object *obj = intel_fb_obj(fb); struct drm_i915_gem_object *obj = intel_fb_obj(fb);
...@@ -1275,14 +1277,19 @@ intel_commit_sprite_plane(struct drm_plane *plane, ...@@ -1275,14 +1277,19 @@ intel_commit_sprite_plane(struct drm_plane *plane,
unsigned int crtc_w, crtc_h; unsigned int crtc_w, crtc_h;
uint32_t src_x, src_y, src_w, src_h; uint32_t src_x, src_y, src_w, src_h;
intel_plane->crtc_x = state->orig_dst.x1; intel_plane->crtc_x = state->base.crtc_x;
intel_plane->crtc_y = state->orig_dst.y1; intel_plane->crtc_y = state->base.crtc_y;
intel_plane->crtc_w = drm_rect_width(&state->orig_dst); intel_plane->crtc_w = state->base.crtc_w;
intel_plane->crtc_h = drm_rect_height(&state->orig_dst); intel_plane->crtc_h = state->base.crtc_h;
intel_plane->src_x = state->orig_src.x1; intel_plane->src_x = state->base.src_x;
intel_plane->src_y = state->orig_src.y1; intel_plane->src_y = state->base.src_y;
intel_plane->src_w = drm_rect_width(&state->orig_src); intel_plane->src_w = state->base.src_w;
intel_plane->src_h = drm_rect_height(&state->orig_src); intel_plane->src_h = state->base.src_h;
crtc = crtc ? crtc : plane->crtc;
intel_crtc = to_intel_crtc(crtc);
plane->fb = state->base.fb;
intel_plane->obj = obj; intel_plane->obj = obj;
if (intel_crtc->active) { if (intel_crtc->active) {
...@@ -1406,10 +1413,12 @@ int intel_plane_restore(struct drm_plane *plane) ...@@ -1406,10 +1413,12 @@ int intel_plane_restore(struct drm_plane *plane)
} }
static const struct drm_plane_funcs intel_sprite_plane_funcs = { static const struct drm_plane_funcs intel_sprite_plane_funcs = {
.update_plane = intel_update_plane, .update_plane = drm_plane_helper_update,
.disable_plane = intel_disable_plane, .disable_plane = drm_plane_helper_disable,
.destroy = intel_plane_destroy, .destroy = intel_plane_destroy,
.set_property = intel_plane_set_property, .set_property = intel_plane_set_property,
.atomic_duplicate_state = intel_plane_duplicate_state,
.atomic_destroy_state = intel_plane_destroy_state,
}; };
static uint32_t ilk_plane_formats[] = { static uint32_t ilk_plane_formats[] = {
...@@ -1471,6 +1480,13 @@ intel_plane_init(struct drm_device *dev, enum pipe pipe, int plane) ...@@ -1471,6 +1480,13 @@ intel_plane_init(struct drm_device *dev, enum pipe pipe, int plane)
if (!intel_plane) if (!intel_plane)
return -ENOMEM; return -ENOMEM;
intel_plane->base.state =
intel_plane_duplicate_state(&intel_plane->base);
if (intel_plane->base.state == NULL) {
kfree(intel_plane);
return -ENOMEM;
}
switch (INTEL_INFO(dev)->gen) { switch (INTEL_INFO(dev)->gen) {
case 5: case 5:
case 6: case 6:
...@@ -1564,6 +1580,8 @@ intel_plane_init(struct drm_device *dev, enum pipe pipe, int plane) ...@@ -1564,6 +1580,8 @@ intel_plane_init(struct drm_device *dev, enum pipe pipe, int plane)
dev->mode_config.rotation_property, dev->mode_config.rotation_property,
intel_plane->rotation); intel_plane->rotation);
drm_plane_helper_add(&intel_plane->base, &intel_plane_helper_funcs);
out: out:
return ret; return ret;
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment