提交 8e7d688b 编写于 作者: M Matt Roper 提交者: Daniel Vetter

drm/i915: Move rotation from intel_plane to drm_plane_state

Runtime state that can be manipulated via properties should now go in
intel_plane_state/drm_plane_state so that it can be tracked as part of
an atomic transaction.

We add a new 'intel_create_plane_state' function so that the proper
initial value for this property (and future properties) doesn't have to
be repeated at each plane initialization site.

v2:
 - Stick rotation in common drm_plane_state rather than
   intel_plane_state. (Daniel)
 - Add intel_create_plane_state() to consolidate the places where we
   have to set initial state values.  (Ander)
Signed-off-by: NMatt Roper <matthew.d.roper@intel.com>
Reviewed-by: NAnder Conselvan de Oliveira <conselvan2@gmail.com>
Signed-off-by: NDaniel Vetter <daniel.vetter@ffwll.ch>
上级 7c59a9c1
...@@ -36,6 +36,30 @@ ...@@ -36,6 +36,30 @@
#include <drm/drm_plane_helper.h> #include <drm/drm_plane_helper.h>
#include "intel_drv.h" #include "intel_drv.h"
/**
* intel_create_plane_state - create plane state object
* @plane: drm plane
*
* Allocates a fresh plane state for the given plane and sets some of
* the state values to sensible initial values.
*
* Returns: A newly allocated plane state, or NULL on failure
*/
struct intel_plane_state *
intel_create_plane_state(struct drm_plane *plane)
{
struct intel_plane_state *state;
state = kzalloc(sizeof(*state), GFP_KERNEL);
if (!state)
return NULL;
state->base.plane = plane;
state->base.rotation = BIT(DRM_ROTATE_0);
return state;
}
/** /**
* intel_plane_duplicate_state - duplicate plane state * intel_plane_duplicate_state - duplicate plane state
* @plane: drm plane * @plane: drm plane
...@@ -43,25 +67,28 @@ ...@@ -43,25 +67,28 @@
* Allocates and returns a copy of the plane state (both common and * Allocates and returns a copy of the plane state (both common and
* Intel-specific) for the specified plane. * Intel-specific) for the specified plane.
* *
* Returns: The newly allocated plane state, or NULL or failure. * Returns: The newly allocated plane state, or NULL on failure.
*/ */
struct drm_plane_state * struct drm_plane_state *
intel_plane_duplicate_state(struct drm_plane *plane) intel_plane_duplicate_state(struct drm_plane *plane)
{ {
struct intel_plane_state *state; struct drm_plane_state *state;
struct intel_plane_state *intel_state;
if (plane->state) if (WARN_ON(!plane->state))
state = kmemdup(plane->state, sizeof(*state), GFP_KERNEL); intel_state = intel_create_plane_state(plane);
else else
state = kzalloc(sizeof(*state), GFP_KERNEL); intel_state = kmemdup(plane->state, sizeof(*intel_state),
GFP_KERNEL);
if (!state) if (!intel_state)
return NULL; return NULL;
if (state->base.fb) state = &intel_state->base;
drm_framebuffer_reference(state->base.fb); if (state->fb)
drm_framebuffer_reference(state->fb);
return &state->base; return state;
} }
/** /**
......
...@@ -2560,7 +2560,7 @@ static void i9xx_update_primary_plane(struct drm_crtc *crtc, ...@@ -2560,7 +2560,7 @@ static void i9xx_update_primary_plane(struct drm_crtc *crtc,
intel_crtc->dspaddr_offset = linear_offset; intel_crtc->dspaddr_offset = linear_offset;
} }
if (to_intel_plane(crtc->primary)->rotation == BIT(DRM_ROTATE_180)) { if (crtc->primary->state->rotation == BIT(DRM_ROTATE_180)) {
dspcntr |= DISPPLANE_ROTATE_180; dspcntr |= DISPPLANE_ROTATE_180;
x += (intel_crtc->config->pipe_src_w - 1); x += (intel_crtc->config->pipe_src_w - 1);
...@@ -2662,7 +2662,7 @@ static void ironlake_update_primary_plane(struct drm_crtc *crtc, ...@@ -2662,7 +2662,7 @@ static void ironlake_update_primary_plane(struct drm_crtc *crtc,
pixel_size, pixel_size,
fb->pitches[0]); fb->pitches[0]);
linear_offset -= intel_crtc->dspaddr_offset; linear_offset -= intel_crtc->dspaddr_offset;
if (to_intel_plane(crtc->primary)->rotation == BIT(DRM_ROTATE_180)) { if (crtc->primary->state->rotation == BIT(DRM_ROTATE_180)) {
dspcntr |= DISPPLANE_ROTATE_180; dspcntr |= DISPPLANE_ROTATE_180;
if (!IS_HASWELL(dev) && !IS_BROADWELL(dev)) { if (!IS_HASWELL(dev) && !IS_BROADWELL(dev)) {
...@@ -2759,7 +2759,7 @@ static void skylake_update_primary_plane(struct drm_crtc *crtc, ...@@ -2759,7 +2759,7 @@ static void skylake_update_primary_plane(struct drm_crtc *crtc,
} }
plane_ctl |= PLANE_CTL_PLANE_GAMMA_DISABLE; plane_ctl |= PLANE_CTL_PLANE_GAMMA_DISABLE;
if (to_intel_plane(crtc->primary)->rotation == BIT(DRM_ROTATE_180)) if (crtc->primary->state->rotation == BIT(DRM_ROTATE_180))
plane_ctl |= PLANE_CTL_ROTATE_180; plane_ctl |= PLANE_CTL_ROTATE_180;
I915_WRITE(PLANE_CTL(pipe, 0), plane_ctl); I915_WRITE(PLANE_CTL(pipe, 0), plane_ctl);
...@@ -8332,7 +8332,7 @@ static void i9xx_update_cursor(struct drm_crtc *crtc, u32 base) ...@@ -8332,7 +8332,7 @@ static void i9xx_update_cursor(struct drm_crtc *crtc, u32 base)
cntl |= CURSOR_PIPE_CSC_ENABLE; cntl |= CURSOR_PIPE_CSC_ENABLE;
} }
if (to_intel_plane(crtc->cursor)->rotation == BIT(DRM_ROTATE_180)) if (crtc->cursor->state->rotation == BIT(DRM_ROTATE_180))
cntl |= CURSOR_ROTATE_180; cntl |= CURSOR_ROTATE_180;
if (intel_crtc->cursor_cntl != cntl) { if (intel_crtc->cursor_cntl != cntl) {
...@@ -8394,7 +8394,7 @@ static void intel_crtc_update_cursor(struct drm_crtc *crtc, ...@@ -8394,7 +8394,7 @@ static void intel_crtc_update_cursor(struct drm_crtc *crtc,
/* ILK+ do this automagically */ /* ILK+ do this automagically */
if (HAS_GMCH_DISPLAY(dev) && if (HAS_GMCH_DISPLAY(dev) &&
to_intel_plane(crtc->cursor)->rotation == BIT(DRM_ROTATE_180)) { crtc->cursor->state->rotation == BIT(DRM_ROTATE_180)) {
base += (intel_crtc->cursor_height * base += (intel_crtc->cursor_height *
intel_crtc->cursor_width - 1) * 4; intel_crtc->cursor_width - 1) * 4;
} }
...@@ -11846,7 +11846,6 @@ intel_check_primary_plane(struct drm_plane *plane, ...@@ -11846,7 +11846,6 @@ intel_check_primary_plane(struct drm_plane *plane,
struct drm_i915_private *dev_priv = dev->dev_private; struct drm_i915_private *dev_priv = dev->dev_private;
struct drm_crtc *crtc = state->base.crtc; struct drm_crtc *crtc = state->base.crtc;
struct intel_crtc *intel_crtc; struct intel_crtc *intel_crtc;
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_rect *dest = &state->dst; struct drm_rect *dest = &state->dst;
struct drm_rect *src = &state->src; struct drm_rect *src = &state->src;
...@@ -11880,7 +11879,7 @@ intel_check_primary_plane(struct drm_plane *plane, ...@@ -11880,7 +11879,7 @@ intel_check_primary_plane(struct drm_plane *plane,
if (intel_crtc->primary_enabled && if (intel_crtc->primary_enabled &&
INTEL_INFO(dev)->gen <= 4 && !IS_G4X(dev) && INTEL_INFO(dev)->gen <= 4 && !IS_G4X(dev) &&
dev_priv->fbc.plane == intel_crtc->plane && dev_priv->fbc.plane == intel_crtc->plane &&
intel_plane->rotation != BIT(DRM_ROTATE_0)) { state->base.rotation != BIT(DRM_ROTATE_0)) {
intel_crtc->atomic.disable_fbc = true; intel_crtc->atomic.disable_fbc = true;
} }
...@@ -12064,6 +12063,7 @@ static struct drm_plane *intel_primary_plane_create(struct drm_device *dev, ...@@ -12064,6 +12063,7 @@ static struct drm_plane *intel_primary_plane_create(struct drm_device *dev,
int pipe) int pipe)
{ {
struct intel_plane *primary; struct intel_plane *primary;
struct intel_plane_state *state;
const uint32_t *intel_primary_formats; const uint32_t *intel_primary_formats;
int num_formats; int num_formats;
...@@ -12071,17 +12071,17 @@ static struct drm_plane *intel_primary_plane_create(struct drm_device *dev, ...@@ -12071,17 +12071,17 @@ static struct drm_plane *intel_primary_plane_create(struct drm_device *dev,
if (primary == NULL) if (primary == NULL)
return NULL; return NULL;
primary->base.state = intel_plane_duplicate_state(&primary->base); state = intel_create_plane_state(&primary->base);
if (primary->base.state == NULL) { if (!state) {
kfree(primary); kfree(primary);
return NULL; return NULL;
} }
primary->base.state = &state->base;
primary->can_scale = false; primary->can_scale = false;
primary->max_downscale = 1; primary->max_downscale = 1;
primary->pipe = pipe; primary->pipe = pipe;
primary->plane = pipe; primary->plane = pipe;
primary->rotation = BIT(DRM_ROTATE_0);
primary->check_plane = intel_check_primary_plane; primary->check_plane = intel_check_primary_plane;
primary->commit_plane = intel_commit_primary_plane; primary->commit_plane = intel_commit_primary_plane;
if (HAS_FBC(dev) && INTEL_INFO(dev)->gen < 4) if (HAS_FBC(dev) && INTEL_INFO(dev)->gen < 4)
...@@ -12109,7 +12109,7 @@ static struct drm_plane *intel_primary_plane_create(struct drm_device *dev, ...@@ -12109,7 +12109,7 @@ static struct drm_plane *intel_primary_plane_create(struct drm_device *dev,
if (dev->mode_config.rotation_property) if (dev->mode_config.rotation_property)
drm_object_attach_property(&primary->base.base, drm_object_attach_property(&primary->base.base,
dev->mode_config.rotation_property, dev->mode_config.rotation_property,
primary->rotation); state->base.rotation);
} }
drm_plane_helper_add(&primary->base, &intel_plane_helper_funcs); drm_plane_helper_add(&primary->base, &intel_plane_helper_funcs);
...@@ -12237,22 +12237,23 @@ static struct drm_plane *intel_cursor_plane_create(struct drm_device *dev, ...@@ -12237,22 +12237,23 @@ static struct drm_plane *intel_cursor_plane_create(struct drm_device *dev,
int pipe) int pipe)
{ {
struct intel_plane *cursor; struct intel_plane *cursor;
struct intel_plane_state *state;
cursor = kzalloc(sizeof(*cursor), GFP_KERNEL); cursor = kzalloc(sizeof(*cursor), GFP_KERNEL);
if (cursor == NULL) if (cursor == NULL)
return NULL; return NULL;
cursor->base.state = intel_plane_duplicate_state(&cursor->base); state = intel_create_plane_state(&cursor->base);
if (cursor->base.state == NULL) { if (!state) {
kfree(cursor); kfree(cursor);
return NULL; return NULL;
} }
cursor->base.state = &state->base;
cursor->can_scale = false; cursor->can_scale = false;
cursor->max_downscale = 1; cursor->max_downscale = 1;
cursor->pipe = pipe; cursor->pipe = pipe;
cursor->plane = pipe; cursor->plane = pipe;
cursor->rotation = BIT(DRM_ROTATE_0);
cursor->check_plane = intel_check_cursor_plane; cursor->check_plane = intel_check_cursor_plane;
cursor->commit_plane = intel_commit_cursor_plane; cursor->commit_plane = intel_commit_cursor_plane;
...@@ -12271,7 +12272,7 @@ static struct drm_plane *intel_cursor_plane_create(struct drm_device *dev, ...@@ -12271,7 +12272,7 @@ static struct drm_plane *intel_cursor_plane_create(struct drm_device *dev,
if (dev->mode_config.rotation_property) if (dev->mode_config.rotation_property)
drm_object_attach_property(&cursor->base.base, drm_object_attach_property(&cursor->base.base,
dev->mode_config.rotation_property, dev->mode_config.rotation_property,
cursor->rotation); state->base.rotation);
} }
drm_plane_helper_add(&cursor->base, &intel_plane_helper_funcs); drm_plane_helper_add(&cursor->base, &intel_plane_helper_funcs);
......
...@@ -509,7 +509,6 @@ struct intel_plane { ...@@ -509,7 +509,6 @@ struct intel_plane {
struct drm_i915_gem_object *obj; struct drm_i915_gem_object *obj;
bool can_scale; bool can_scale;
int max_downscale; int max_downscale;
unsigned int rotation;
/* Since we need to change the watermarks before/after /* Since we need to change the watermarks before/after
* enabling/disabling the planes, we need to store the parameters here * enabling/disabling the planes, we need to store the parameters here
...@@ -518,6 +517,12 @@ struct intel_plane { ...@@ -518,6 +517,12 @@ struct intel_plane {
*/ */
struct intel_plane_wm_parameters wm; struct intel_plane_wm_parameters wm;
/*
* NOTE: Do not place new plane state fields here (e.g., when adding
* new plane properties). New runtime state should now be placed in
* the intel_plane_state structure and accessed via drm_plane->state.
*/
void (*update_plane)(struct drm_plane *plane, void (*update_plane)(struct drm_plane *plane,
struct drm_crtc *crtc, struct drm_crtc *crtc,
struct drm_framebuffer *fb, struct drm_framebuffer *fb,
...@@ -1235,6 +1240,7 @@ void intel_pre_disable_primary(struct drm_crtc *crtc); ...@@ -1235,6 +1240,7 @@ void intel_pre_disable_primary(struct drm_crtc *crtc);
void intel_tv_init(struct drm_device *dev); void intel_tv_init(struct drm_device *dev);
/* intel_atomic.c */ /* intel_atomic.c */
struct intel_plane_state *intel_create_plane_state(struct drm_plane *plane);
struct drm_plane_state *intel_plane_duplicate_state(struct drm_plane *plane); struct drm_plane_state *intel_plane_duplicate_state(struct drm_plane *plane);
void intel_plane_destroy_state(struct drm_plane *plane, void intel_plane_destroy_state(struct drm_plane *plane,
struct drm_plane_state *state); struct drm_plane_state *state);
......
...@@ -595,7 +595,7 @@ void intel_fbc_update(struct drm_device *dev) ...@@ -595,7 +595,7 @@ void intel_fbc_update(struct drm_device *dev)
goto out_disable; goto out_disable;
} }
if (INTEL_INFO(dev)->gen <= 4 && !IS_G4X(dev) && if (INTEL_INFO(dev)->gen <= 4 && !IS_G4X(dev) &&
to_intel_plane(crtc->primary)->rotation != BIT(DRM_ROTATE_0)) { crtc->primary->state->rotation != BIT(DRM_ROTATE_0)) {
if (set_no_fbc_reason(dev_priv, FBC_UNSUPPORTED_MODE)) if (set_no_fbc_reason(dev_priv, FBC_UNSUPPORTED_MODE))
DRM_DEBUG_KMS("Rotation unsupported, disabling\n"); DRM_DEBUG_KMS("Rotation unsupported, disabling\n");
goto out_disable; goto out_disable;
......
...@@ -256,7 +256,7 @@ skl_update_plane(struct drm_plane *drm_plane, struct drm_crtc *crtc, ...@@ -256,7 +256,7 @@ skl_update_plane(struct drm_plane *drm_plane, struct drm_crtc *crtc,
default: default:
BUG(); BUG();
} }
if (intel_plane->rotation == BIT(DRM_ROTATE_180)) if (drm_plane->state->rotation == BIT(DRM_ROTATE_180))
plane_ctl |= PLANE_CTL_ROTATE_180; plane_ctl |= PLANE_CTL_ROTATE_180;
plane_ctl |= PLANE_CTL_ENABLE; plane_ctl |= PLANE_CTL_ENABLE;
...@@ -493,7 +493,7 @@ vlv_update_plane(struct drm_plane *dplane, struct drm_crtc *crtc, ...@@ -493,7 +493,7 @@ vlv_update_plane(struct drm_plane *dplane, struct drm_crtc *crtc,
fb->pitches[0]); fb->pitches[0]);
linear_offset -= sprsurf_offset; linear_offset -= sprsurf_offset;
if (intel_plane->rotation == BIT(DRM_ROTATE_180)) { if (dplane->state->rotation == BIT(DRM_ROTATE_180)) {
sprctl |= SP_ROTATE_180; sprctl |= SP_ROTATE_180;
x += src_w; x += src_w;
...@@ -684,7 +684,7 @@ ivb_update_plane(struct drm_plane *plane, struct drm_crtc *crtc, ...@@ -684,7 +684,7 @@ ivb_update_plane(struct drm_plane *plane, struct drm_crtc *crtc,
pixel_size, fb->pitches[0]); pixel_size, fb->pitches[0]);
linear_offset -= sprsurf_offset; linear_offset -= sprsurf_offset;
if (intel_plane->rotation == BIT(DRM_ROTATE_180)) { if (plane->state->rotation == BIT(DRM_ROTATE_180)) {
sprctl |= SPRITE_ROTATE_180; sprctl |= SPRITE_ROTATE_180;
/* HSW and BDW does this automagically in hardware */ /* HSW and BDW does this automagically in hardware */
...@@ -884,7 +884,7 @@ ilk_update_plane(struct drm_plane *plane, struct drm_crtc *crtc, ...@@ -884,7 +884,7 @@ ilk_update_plane(struct drm_plane *plane, struct drm_crtc *crtc,
pixel_size, fb->pitches[0]); pixel_size, fb->pitches[0]);
linear_offset -= dvssurf_offset; linear_offset -= dvssurf_offset;
if (intel_plane->rotation == BIT(DRM_ROTATE_180)) { if (plane->state->rotation == BIT(DRM_ROTATE_180)) {
dvscntr |= DVS_ROTATE_180; dvscntr |= DVS_ROTATE_180;
x += src_w; x += src_w;
...@@ -1125,7 +1125,7 @@ intel_check_sprite_plane(struct drm_plane *plane, ...@@ -1125,7 +1125,7 @@ intel_check_sprite_plane(struct drm_plane *plane,
min_scale = intel_plane->can_scale ? 1 : (1 << 16); min_scale = intel_plane->can_scale ? 1 : (1 << 16);
drm_rect_rotate(src, fb->width << 16, fb->height << 16, drm_rect_rotate(src, fb->width << 16, fb->height << 16,
intel_plane->rotation); state->base.rotation);
hscale = drm_rect_calc_hscale_relaxed(src, dst, min_scale, max_scale); hscale = drm_rect_calc_hscale_relaxed(src, dst, min_scale, max_scale);
BUG_ON(hscale < 0); BUG_ON(hscale < 0);
...@@ -1166,7 +1166,7 @@ intel_check_sprite_plane(struct drm_plane *plane, ...@@ -1166,7 +1166,7 @@ intel_check_sprite_plane(struct drm_plane *plane,
drm_rect_height(dst) * vscale - drm_rect_height(src)); drm_rect_height(dst) * vscale - drm_rect_height(src));
drm_rect_rotate_inv(src, fb->width << 16, fb->height << 16, drm_rect_rotate_inv(src, fb->width << 16, fb->height << 16,
intel_plane->rotation); state->base.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) state->base.src_x || WARN_ON(src->x1 < (int) state->base.src_x ||
...@@ -1367,7 +1367,6 @@ int intel_plane_set_property(struct drm_plane *plane, ...@@ -1367,7 +1367,6 @@ int intel_plane_set_property(struct drm_plane *plane,
uint64_t val) uint64_t val)
{ {
struct drm_device *dev = plane->dev; struct drm_device *dev = plane->dev;
struct intel_plane *intel_plane = to_intel_plane(plane);
uint64_t old_val; uint64_t old_val;
int ret = -ENOENT; int ret = -ENOENT;
...@@ -1376,14 +1375,14 @@ int intel_plane_set_property(struct drm_plane *plane, ...@@ -1376,14 +1375,14 @@ int intel_plane_set_property(struct drm_plane *plane,
if (hweight32(val & 0xf) != 1) if (hweight32(val & 0xf) != 1)
return -EINVAL; return -EINVAL;
if (intel_plane->rotation == val) if (plane->state->rotation == val)
return 0; return 0;
old_val = intel_plane->rotation; old_val = plane->state->rotation;
intel_plane->rotation = val; plane->state->rotation = val;
ret = intel_plane_restore(plane); ret = intel_plane_restore(plane);
if (ret) if (ret)
intel_plane->rotation = old_val; plane->state->rotation = old_val;
} }
return ret; return ret;
...@@ -1457,6 +1456,7 @@ int ...@@ -1457,6 +1456,7 @@ int
intel_plane_init(struct drm_device *dev, enum pipe pipe, int plane) intel_plane_init(struct drm_device *dev, enum pipe pipe, int plane)
{ {
struct intel_plane *intel_plane; struct intel_plane *intel_plane;
struct intel_plane_state *state;
unsigned long possible_crtcs; unsigned long possible_crtcs;
const uint32_t *plane_formats; const uint32_t *plane_formats;
int num_plane_formats; int num_plane_formats;
...@@ -1469,12 +1469,12 @@ intel_plane_init(struct drm_device *dev, enum pipe pipe, int plane) ...@@ -1469,12 +1469,12 @@ 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 = state = intel_create_plane_state(&intel_plane->base);
intel_plane_duplicate_state(&intel_plane->base); if (!state) {
if (intel_plane->base.state == NULL) {
kfree(intel_plane); kfree(intel_plane);
return -ENOMEM; return -ENOMEM;
} }
intel_plane->base.state = &state->base;
switch (INTEL_INFO(dev)->gen) { switch (INTEL_INFO(dev)->gen) {
case 5: case 5:
...@@ -1545,7 +1545,6 @@ intel_plane_init(struct drm_device *dev, enum pipe pipe, int plane) ...@@ -1545,7 +1545,6 @@ intel_plane_init(struct drm_device *dev, enum pipe pipe, int plane)
intel_plane->pipe = pipe; intel_plane->pipe = pipe;
intel_plane->plane = plane; intel_plane->plane = plane;
intel_plane->rotation = BIT(DRM_ROTATE_0);
intel_plane->check_plane = intel_check_sprite_plane; intel_plane->check_plane = intel_check_sprite_plane;
intel_plane->commit_plane = intel_commit_sprite_plane; intel_plane->commit_plane = intel_commit_sprite_plane;
possible_crtcs = (1 << pipe); possible_crtcs = (1 << pipe);
...@@ -1567,7 +1566,7 @@ intel_plane_init(struct drm_device *dev, enum pipe pipe, int plane) ...@@ -1567,7 +1566,7 @@ intel_plane_init(struct drm_device *dev, enum pipe pipe, int plane)
if (dev->mode_config.rotation_property) if (dev->mode_config.rotation_property)
drm_object_attach_property(&intel_plane->base.base, drm_object_attach_property(&intel_plane->base.base,
dev->mode_config.rotation_property, dev->mode_config.rotation_property,
intel_plane->rotation); state->base.rotation);
drm_plane_helper_add(&intel_plane->base, &intel_plane_helper_funcs); drm_plane_helper_add(&intel_plane->base, &intel_plane_helper_funcs);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册