On ke, 2016-07-20 at 16:18 +0300, ville.syrjala at linux.intel.com wrote:
> From: Ville Syrjälä <ville.syrjala at linux.intel.com>
>
> We have intel_rotation_90_or_270() in i915 to check if the rotation is
> 90 or 270 degrees. Similar checks are elsewhere in drm, so let's move
> the helper into a central place and use it everwhere.
>
> Signed-off-by: Ville Syrjälä <ville.syrjala at linux.intel.com>
Reviewed-by: Joonas Lahtinen <joonas.lahtinen at linux.intel.com>
> ---
> Â drivers/gpu/drm/atmel-hlcdc/atmel_hlcdc_plane.c |Â Â 4 ++--
>  drivers/gpu/drm/drm_atomic_helper.c             |  2 +-
>  drivers/gpu/drm/drm_crtc.c                      | Â
> 3 +--
>  drivers/gpu/drm/i915/intel_atomic_plane.c       |  2 +-
>  drivers/gpu/drm/i915/intel_display.c            | 10 +++++-----
>  drivers/gpu/drm/i915/intel_drv.h                |  6
> ------
>  drivers/gpu/drm/i915/intel_fbc.c                |  2 +-
>  drivers/gpu/drm/i915/intel_pm.c                 | 12
> ++++++------
>  drivers/gpu/drm/i915/intel_sprite.c             |  2 +-
>  drivers/gpu/drm/omapdrm/omap_plane.c            |  8 ++------
>  include/drm/drm_crtc.h                         Â
> |Â Â 5 +++++
> Â 11 files changed, 25 insertions(+), 31 deletions(-)
>
> diff --git a/drivers/gpu/drm/atmel-hlcdc/atmel_hlcdc_plane.c
> b/drivers/gpu/drm/atmel-hlcdc/atmel_hlcdc_plane.c
> index 016c191221f3..f3350c80704d 100644
> --- a/drivers/gpu/drm/atmel-hlcdc/atmel_hlcdc_plane.c
> +++ b/drivers/gpu/drm/atmel-hlcdc/atmel_hlcdc_plane.c
> @@ -393,7 +393,7 @@ static void atmel_hlcdc_plane_update_format(struct
> atmel_hlcdc_plane *plane,
> Â
> Â if ((state->base.fb->pixel_format == DRM_FORMAT_YUV422 ||
> Â Â Â Â Â Â state->base.fb->pixel_format == DRM_FORMAT_NV61) &&
> - Â Â Â Â (state->base.rotation & (BIT(DRM_ROTATE_90) |
> BIT(DRM_ROTATE_270))))
> + Â Â Â Â drm_rotation_90_or_270(state->base.rotation))
> Â cfg |= ATMEL_HLCDC_YUV422ROT;
> Â
> Â atmel_hlcdc_layer_update_cfg(&plane->layer,
> @@ -628,7 +628,7 @@ static int atmel_hlcdc_plane_atomic_check(struct
> drm_plane *p,
> Â /*
> Â Â * Swap width and size in case of 90 or 270 degrees rotation
> Â Â */
> - if (state->base.rotation & (BIT(DRM_ROTATE_90) | BIT(DRM_ROTATE_270))) {
> + if (drm_rotation_90_or_270(state->base.rotation)) {
> Â tmp = state->crtc_w;
> Â state->crtc_w = state->crtc_h;
> Â state->crtc_h = tmp;
> diff --git a/drivers/gpu/drm/drm_atomic_helper.c
> b/drivers/gpu/drm/drm_atomic_helper.c
> index de7fddce3cef..3e12e6e646ad 100644
> --- a/drivers/gpu/drm/drm_atomic_helper.c
> +++ b/drivers/gpu/drm/drm_atomic_helper.c
> @@ -2348,7 +2348,7 @@ int __drm_atomic_helper_set_config(struct drm_mode_set
> *set,
> Â primary_state->crtc_h = vdisplay;
> Â primary_state->src_x = set->x << 16;
> Â primary_state->src_y = set->y << 16;
> - if (primary_state->rotation & (BIT(DRM_ROTATE_90) |
> BIT(DRM_ROTATE_270))) {
> + if (drm_rotation_90_or_270(primary_state->rotation)) {
> Â primary_state->src_w = vdisplay << 16;
> Â primary_state->src_h = hdisplay << 16;
> Â } else {
> diff --git a/drivers/gpu/drm/drm_crtc.c b/drivers/gpu/drm/drm_crtc.c
> index f1d9f0569d7f..986de180e6c2 100644
> --- a/drivers/gpu/drm/drm_crtc.c
> +++ b/drivers/gpu/drm/drm_crtc.c
> @@ -2804,8 +2804,7 @@ int drm_crtc_check_viewport(const struct drm_crtc *crtc,
> Â drm_crtc_get_hv_timing(mode, &hdisplay, &vdisplay);
> Â
> Â if (crtc->state &&
> - Â Â Â Â crtc->primary->state->rotation & (BIT(DRM_ROTATE_90) |
> - Â Â Â Â Â Â BIT(DRM_ROTATE_270)))
> + Â Â Â Â drm_rotation_90_or_270(crtc->primary->state->rotation))
> Â swap(hdisplay, vdisplay);
> Â
> Â return check_src_coords(x << 16, y << 16,
> diff --git a/drivers/gpu/drm/i915/intel_atomic_plane.c
> b/drivers/gpu/drm/i915/intel_atomic_plane.c
> index 7de7721f65bc..c19eb9a0cd4a 100644
> --- a/drivers/gpu/drm/i915/intel_atomic_plane.c
> +++ b/drivers/gpu/drm/i915/intel_atomic_plane.c
> @@ -156,7 +156,7 @@ static int intel_plane_atomic_check(struct drm_plane
> *plane,
> Â intel_state->clip.y2 =
> Â crtc_state->base.enable ? crtc_state->pipe_src_h : 0;
> Â
> - if (state->fb && intel_rotation_90_or_270(state->rotation)) {
> + if (state->fb && drm_rotation_90_or_270(state->rotation)) {
> Â if (!(state->fb->modifier[0] == I915_FORMAT_MOD_Y_TILED ||
> Â state->fb->modifier[0] == I915_FORMAT_MOD_Yf_TILED)) {
> Â DRM_DEBUG_KMS("Y/Yf tiling required for 90/270!\n");
> diff --git a/drivers/gpu/drm/i915/intel_display.c
> b/drivers/gpu/drm/i915/intel_display.c
> index 51fbca756cdb..08b9f9a19df0 100644
> --- a/drivers/gpu/drm/i915/intel_display.c
> +++ b/drivers/gpu/drm/i915/intel_display.c
> @@ -2138,7 +2138,7 @@ intel_fill_fb_ggtt_view(struct i915_ggtt_view *view,
> Â const struct drm_framebuffer *fb,
> Â unsigned int rotation)
> Â {
> - if (intel_rotation_90_or_270(rotation)) {
> + if (drm_rotation_90_or_270(rotation)) {
> Â *view = i915_ggtt_view_rotated;
> Â view->params.rotated = to_intel_framebuffer(fb)->rot_info;
> Â } else {
> @@ -2352,7 +2352,7 @@ u32 intel_compute_tile_offset(int *x, int *y,
> Â intel_tile_dims(dev_priv, &tile_width, &tile_height,
> Â fb_modifier, cpp);
> Â
> - if (intel_rotation_90_or_270(rotation)) {
> + if (drm_rotation_90_or_270(rotation)) {
> Â pitch_tiles = pitch / tile_height;
> Â swap(tile_width, tile_height);
> Â } else {
> @@ -3011,7 +3011,7 @@ static void skylake_update_primary_plane(struct
> drm_plane *plane,
> Â
> Â WARN_ON(drm_rect_width(&plane_state->src) == 0);
> Â
> - if (intel_rotation_90_or_270(rotation)) {
> + if (drm_rotation_90_or_270(rotation)) {
> Â int cpp = drm_format_plane_cpp(fb->pixel_format, 0);
> Â
> Â /* stride = Surface height in tiles */
> @@ -4179,7 +4179,7 @@ skl_update_scaler(struct intel_crtc_state *crtc_state,
> bool force_detach,
> Â to_intel_crtc(crtc_state->base.crtc);
> Â int need_scaling;
> Â
> - need_scaling = intel_rotation_90_or_270(rotation) ?
> + need_scaling = drm_rotation_90_or_270(rotation) ?
> Â (src_h != dst_w || src_w != dst_h):
> Â (src_w != dst_w || src_h != dst_h);
> Â
> @@ -11414,7 +11414,7 @@ static void skl_do_mmio_flip(struct intel_crtc
> *intel_crtc,
> Â Â * The stride is either expressed as a multiple of 64 bytes chunks for
> Â Â * linear buffers or in number of tiles for tiled buffers.
> Â Â */
> - if (intel_rotation_90_or_270(rotation)) {
> + if (drm_rotation_90_or_270(rotation)) {
> Â /* stride = Surface height in tiles */
> Â tile_height = intel_tile_height(dev_priv, fb->modifier[0], 0);
> Â stride = DIV_ROUND_UP(fb->height, tile_height);
> diff --git a/drivers/gpu/drm/i915/intel_drv.h
> b/drivers/gpu/drm/i915/intel_drv.h
> index e74d851868c5..907a72cfdad3 100644
> --- a/drivers/gpu/drm/i915/intel_drv.h
> +++ b/drivers/gpu/drm/i915/intel_drv.h
> @@ -1255,12 +1255,6 @@ int intel_plane_atomic_calc_changes(struct
> drm_crtc_state *crtc_state,
> Â unsigned int intel_tile_height(const struct drm_i915_private *dev_priv,
> Â Â Â Â Â Â Â Â uint64_t fb_modifier, unsigned int cpp);
> Â
> -static inline bool
> -intel_rotation_90_or_270(unsigned int rotation)
> -{
> - return rotation & (BIT(DRM_ROTATE_90) | BIT(DRM_ROTATE_270));
> -}
> -
> Â void intel_create_rotation_property(struct drm_device *dev,
> Â struct intel_plane *plane);
> Â
> diff --git a/drivers/gpu/drm/i915/intel_fbc.c
> b/drivers/gpu/drm/i915/intel_fbc.c
> index 781e2f5f7cd8..f3f3322139e0 100644
> --- a/drivers/gpu/drm/i915/intel_fbc.c
> +++ b/drivers/gpu/drm/i915/intel_fbc.c
> @@ -84,7 +84,7 @@ static void intel_fbc_get_plane_source_size(struct
> intel_fbc_state_cache *cache,
> Â {
> Â int w, h;
> Â
> - if (intel_rotation_90_or_270(cache->plane.rotation)) {
> + if (drm_rotation_90_or_270(cache->plane.rotation)) {
> Â w = cache->plane.src_h;
> Â h = cache->plane.src_w;
> Â } else {
> diff --git a/drivers/gpu/drm/i915/intel_pm.c b/drivers/gpu/drm/i915/intel_pm.c
> index a1bf5f8fbb1c..53116cdc43a6 100644
> --- a/drivers/gpu/drm/i915/intel_pm.c
> +++ b/drivers/gpu/drm/i915/intel_pm.c
> @@ -3004,7 +3004,7 @@ skl_plane_downscale_amount(const struct
> intel_plane_state *pstate)
> Â src_h = drm_rect_height(&pstate->src);
> Â dst_w = drm_rect_width(&pstate->dst);
> Â dst_h = drm_rect_height(&pstate->dst);
> - if (intel_rotation_90_or_270(pstate->base.rotation))
> + if (drm_rotation_90_or_270(pstate->base.rotation))
> Â swap(dst_w, dst_h);
> Â
> Â downscale_h = max(src_h / dst_h, (uint32_t)DRM_PLANE_HELPER_NO_SCALING);
> @@ -3035,7 +3035,7 @@ skl_plane_relative_data_rate(const struct
> intel_crtc_state *cstate,
> Â width = drm_rect_width(&intel_pstate->src) >> 16;
> Â height = drm_rect_height(&intel_pstate->src) >> 16;
> Â
> - if (intel_rotation_90_or_270(pstate->rotation))
> + if (drm_rotation_90_or_270(pstate->rotation))
> Â swap(width, height);
> Â
> Â /* for planar format */
> @@ -3137,7 +3137,7 @@ skl_ddb_min_alloc(const struct drm_plane_state *pstate,
> Â src_w = drm_rect_width(&intel_pstate->src) >> 16;
> Â src_h = drm_rect_height(&intel_pstate->src) >> 16;
> Â
> - if (intel_rotation_90_or_270(pstate->rotation))
> + if (drm_rotation_90_or_270(pstate->rotation))
> Â swap(src_w, src_h);
> Â
> Â /* Halve UV plane width and height for NV12 */
> @@ -3151,7 +3151,7 @@ skl_ddb_min_alloc(const struct drm_plane_state *pstate,
> Â else
> Â plane_bpp = drm_format_plane_cpp(fb->pixel_format, 0);
> Â
> - if (intel_rotation_90_or_270(pstate->rotation)) {
> + if (drm_rotation_90_or_270(pstate->rotation)) {
> Â switch (plane_bpp) {
> Â case 1:
> Â min_scanlines = 32;
> @@ -3407,7 +3407,7 @@ static int skl_compute_plane_wm(const struct
> drm_i915_private *dev_priv,
> Â width = drm_rect_width(&intel_pstate->src) >> 16;
> Â height = drm_rect_height(&intel_pstate->src) >> 16;
> Â
> - if (intel_rotation_90_or_270(pstate->rotation))
> + if (drm_rotation_90_or_270(pstate->rotation))
> Â swap(width, height);
> Â
> Â cpp = drm_format_plane_cpp(fb->pixel_format, 0);
> @@ -3428,7 +3428,7 @@ static int skl_compute_plane_wm(const struct
> drm_i915_private *dev_priv,
> Â Â Â Â Â fb->modifier[0] == I915_FORMAT_MOD_Yf_TILED) {
> Â uint32_t min_scanlines = 4;
> Â uint32_t y_tile_minimum;
> - if (intel_rotation_90_or_270(pstate->rotation)) {
> + if (drm_rotation_90_or_270(pstate->rotation)) {
> Â int cpp = (fb->pixel_format == DRM_FORMAT_NV12) ?
> Â drm_format_plane_cpp(fb->pixel_format, 1) :
> Â drm_format_plane_cpp(fb->pixel_format, 0);
> diff --git a/drivers/gpu/drm/i915/intel_sprite.c
> b/drivers/gpu/drm/i915/intel_sprite.c
> index 0de935ad01c2..cc6af1410d67 100644
> --- a/drivers/gpu/drm/i915/intel_sprite.c
> +++ b/drivers/gpu/drm/i915/intel_sprite.c
> @@ -251,7 +251,7 @@ skl_update_plane(struct drm_plane *drm_plane,
> Â
> Â surf_addr = intel_plane_obj_offset(intel_plane, obj, 0);
> Â
> - if (intel_rotation_90_or_270(rotation)) {
> + if (drm_rotation_90_or_270(rotation)) {
> Â int cpp = drm_format_plane_cpp(fb->pixel_format, 0);
> Â
> Â /* stride: Surface height in tiles */
> diff --git a/drivers/gpu/drm/omapdrm/omap_plane.c
> b/drivers/gpu/drm/omapdrm/omap_plane.c
> index 5252ab720e70..7f0d567b8d67 100644
> --- a/drivers/gpu/drm/omapdrm/omap_plane.c
> +++ b/drivers/gpu/drm/omapdrm/omap_plane.c
> @@ -108,16 +108,12 @@ static void omap_plane_atomic_update(struct drm_plane
> *plane,
> Â win.src_x = state->src_x >> 16;
> Â win.src_y = state->src_y >> 16;
> Â
> - switch (state->rotation & DRM_ROTATE_MASK) {
> - case BIT(DRM_ROTATE_90):
> - case BIT(DRM_ROTATE_270):
> + if (drm_rotation_90_or_270(state->rotation)) {
> Â win.src_w = state->src_h >> 16;
> Â win.src_h = state->src_w >> 16;
> - break;
> - default:
> + } else {
> Â win.src_w = state->src_w >> 16;
> Â win.src_h = state->src_h >> 16;
> - break;
> Â }
> Â
> Â /* update scanout: */
> diff --git a/include/drm/drm_crtc.h b/include/drm/drm_crtc.h
> index 3edeaf88ebc0..b7ac7dcf52db 100644
> --- a/include/drm/drm_crtc.h
> +++ b/include/drm/drm_crtc.h
> @@ -92,6 +92,11 @@ static inline uint64_t I642U64(int64_t val)
> Â #define DRM_REFLECT_X 4
> Â #define DRM_REFLECT_Y 5
> Â
> +static inline bool drm_rotation_90_or_270(unsigned int rotation)
> +{
> + return rotation & (BIT(DRM_ROTATE_90) | BIT(DRM_ROTATE_270));
> +}
> +
> Â enum drm_connector_force {
> Â DRM_FORCE_UNSPECIFIED,
> Â DRM_FORCE_OFF,
--
Joonas Lahtinen
Open Source Technology Center
Intel Corporation