drm: Add drm_rotation_90_or_270()
authorVille Syrjälä <ville.syrjala@linux.intel.com>
Mon, 26 Sep 2016 16:30:46 +0000 (19:30 +0300)
committerDaniel Vetter <daniel.vetter@ffwll.ch>
Fri, 21 Oct 2016 16:21:33 +0000 (18:21 +0200)
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.

v2: Drop the BIT()
    Convert all new intel_rotation_90_or_270() calls
    Deal with superfluous code shuffling

Signed-off-by: Ville Syrjälä <ville.syrjala@linux.intel.com>
Reviewed-by: Chris Wilson <chris@chris-wilson.co.uk> (v1)
Reviewed-by: Joonas Lahtinen <joonas.lahtinen@linux.intel.com>
Signed-off-by: Daniel Vetter <daniel.vetter@ffwll.ch>
Link: http://patchwork.freedesktop.org/patch/msgid/1474907460-10717-2-git-send-email-ville.syrjala@linux.intel.com
drivers/gpu/drm/atmel-hlcdc/atmel_hlcdc_plane.c
drivers/gpu/drm/drm_atomic_helper.c
drivers/gpu/drm/drm_crtc.c
drivers/gpu/drm/i915/intel_atomic_plane.c
drivers/gpu/drm/i915/intel_display.c
drivers/gpu/drm/i915/intel_drv.h
drivers/gpu/drm/i915/intel_fbc.c
drivers/gpu/drm/i915/intel_pm.c
drivers/gpu/drm/omapdrm/omap_plane.c
include/drm/drm_blend.h

index 9d4c030672f0ff8ae8a830e63afe26a7948707c0..b380179d4013c3f596ef80fce54682375d11535c 100644 (file)
@@ -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 & (DRM_ROTATE_90 | 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 & (DRM_ROTATE_90 | 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;
index 07b432f43b98002fab481d55178138a02dbea4dd..f9362760bfb2df74a42f46fe2e538f0841513404 100644 (file)
@@ -2399,7 +2399,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 & (DRM_ROTATE_90 | 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 {
index 60403bf7a4ffa9132c88f2a101fac3c02b40b377..13441e21117c10ab82323becd209ec23e24fd242 100644 (file)
@@ -727,8 +727,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 & (DRM_ROTATE_90 |
-                                             DRM_ROTATE_270))
+           drm_rotation_90_or_270(crtc->primary->state->rotation))
                swap(hdisplay, vdisplay);
 
        return drm_framebuffer_check_src_coords(x << 16, y << 16,
index b82de3072d4f802653127e46a2e141871d2d0e94..c762ae549a1cccc1a783afb75080b814fe9708ac 100644 (file)
@@ -142,8 +142,9 @@ 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)) {
                char *format_name;
+
                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");
index e11896cd2015eaa3cde6fb8c8af3dab7cb7ba26e..af18e2cce34bc53bcdbfc5cbf90aeec443faca3e 100644 (file)
@@ -2139,7 +2139,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 {
@@ -2260,7 +2260,7 @@ void intel_unpin_fb_obj(struct drm_framebuffer *fb, unsigned int rotation)
 static int intel_fb_pitch(const struct drm_framebuffer *fb, int plane,
                          unsigned int rotation)
 {
-       if (intel_rotation_90_or_270(rotation))
+       if (drm_rotation_90_or_270(rotation))
                return to_intel_framebuffer(fb)->rotated[plane].pitch;
        else
                return fb->pitches[plane];
@@ -2296,7 +2296,7 @@ void intel_add_fb_offsets(int *x, int *y,
        const struct intel_framebuffer *intel_fb = to_intel_framebuffer(state->base.fb);
        unsigned int rotation = state->base.rotation;
 
-       if (intel_rotation_90_or_270(rotation)) {
+       if (drm_rotation_90_or_270(rotation)) {
                *x += intel_fb->rotated[plane].x;
                *y += intel_fb->rotated[plane].y;
        } else {
@@ -2360,7 +2360,7 @@ static u32 intel_adjust_tile_offset(int *x, int *y,
                intel_tile_dims(dev_priv, &tile_width, &tile_height,
                                fb->modifier[plane], 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 {
@@ -2416,7 +2416,7 @@ static u32 _intel_compute_tile_offset(const struct drm_i915_private *dev_priv,
                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 {
@@ -2976,7 +2976,7 @@ int skl_check_plane_surface(struct intel_plane_state *plane_state)
        int ret;
 
        /* Rotate src coordinates to match rotated GTT view */
-       if (intel_rotation_90_or_270(rotation))
+       if (drm_rotation_90_or_270(rotation))
                drm_rect_rotate(&plane_state->base.src,
                                fb->width, fb->height, DRM_ROTATE_270);
 
@@ -3276,7 +3276,7 @@ u32 skl_plane_stride(const struct drm_framebuffer *fb, int plane,
         * 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)) {
                int cpp = drm_format_plane_cpp(fb->pixel_format, plane);
 
                stride /= intel_tile_height(dev_priv, fb->modifier[0], cpp);
@@ -4666,7 +4666,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);
 
index 8fd16adf069b2f894d0eb1d65d662e39754fbaf4..c6ae525fe1f5b60f88958481fc4acb024c69140f 100644 (file)
@@ -1284,12 +1284,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 & (DRM_ROTATE_90 | DRM_ROTATE_270);
-}
-
 void intel_create_rotation_property(struct drm_device *dev,
                                        struct intel_plane *plane);
 
index faa67624e1ed734b80b0c0b9734b63c173d9389c..afc040be1172245499fdd51484cdca9c8997c451 100644 (file)
@@ -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 {
index 2df06b703e3df9363772c7fc037457a89ec693a9..1472400ddce362e9a182661a8b6e1aabd67b4aea 100644 (file)
@@ -3151,7 +3151,7 @@ skl_plane_downscale_amount(const struct intel_plane_state *pstate)
        src_h = drm_rect_height(&pstate->base.src);
        dst_w = drm_rect_width(&pstate->base.dst);
        dst_h = drm_rect_height(&pstate->base.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);
@@ -3182,7 +3182,7 @@ skl_plane_relative_data_rate(const struct intel_crtc_state *cstate,
        width = drm_rect_width(&intel_pstate->base.src) >> 16;
        height = drm_rect_height(&intel_pstate->base.src) >> 16;
 
-       if (intel_rotation_90_or_270(pstate->rotation))
+       if (drm_rotation_90_or_270(pstate->rotation))
                swap(width, height);
 
        /* for planar format */
@@ -3282,7 +3282,7 @@ skl_ddb_min_alloc(const struct drm_plane_state *pstate,
        src_w = drm_rect_width(&intel_pstate->base.src) >> 16;
        src_h = drm_rect_height(&intel_pstate->base.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 */
@@ -3296,7 +3296,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;
@@ -3554,7 +3554,7 @@ static int skl_compute_plane_wm(const struct drm_i915_private *dev_priv,
        width = drm_rect_width(&intel_pstate->base.src) >> 16;
        height = drm_rect_height(&intel_pstate->base.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);
@@ -3575,7 +3575,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);
index 66ac8c40db2614966af3992b561feb43dec5ab10..1549e83930561805adbbaa94a19f684ae602e53b 100644 (file)
@@ -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 DRM_ROTATE_90:
-       case 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: */
index 36baa175de9949c739a9a21e56308eb8fff07cc9..bb493410396cd77883227a58ddc70da21e3e4a4e 100644 (file)
@@ -47,6 +47,11 @@ struct drm_atomic_state;
 #define DRM_REFLECT_Y  BIT(5)
 #define DRM_REFLECT_MASK (DRM_REFLECT_X | DRM_REFLECT_Y)
 
+static inline bool drm_rotation_90_or_270(unsigned int rotation)
+{
+       return rotation & (DRM_ROTATE_90 | DRM_ROTATE_270);
+}
+
 struct drm_property *drm_mode_create_rotation_property(struct drm_device *dev,
                                                       unsigned int supported_rotations);
 unsigned int drm_rotation_simplify(unsigned int rotation,