From: Daniel Vetter Subject: Re: [PATCH v4 4/4] drm/i915: Add support for variable cursor size on 845/865 Date: Wed, 13 Aug 2014 13:34:44 +0200 Message-ID: <20140813113444.GT10500@phenom.ffwll.local> References: <20140813071833.GE22250@nuc-i3427.alporthouse.com> <1407920225-10999-1-git-send-email-ville.syrjala@linux.intel.com> Mime-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Return-path: Received: from mail-wg0-f42.google.com (mail-wg0-f42.google.com [74.125.82.42]) by gabe.freedesktop.org (Postfix) with ESMTP id B6AC489E63 for ; Wed, 13 Aug 2014 04:34:32 -0700 (PDT) Received: by mail-wg0-f42.google.com with SMTP id l18so11042873wgh.1 for ; Wed, 13 Aug 2014 04:34:31 -0700 (PDT) Content-Disposition: inline In-Reply-To: <1407920225-10999-1-git-send-email-ville.syrjala@linux.intel.com> List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" To: ville.syrjala@linux.intel.com Cc: intel-gfx@lists.freedesktop.org List-Id: intel-gfx@lists.freedesktop.org On Wed, Aug 13, 2014 at 11:57:05AM +0300, ville.syrjala@linux.intel.com wro= te: > From: Ville Syrj=E4l=E4 > = > 845/865 support different cursor sizes as well, albeit a bit differently > than later platforms. Add the necessary code to make them work. > = > Untested due to lack of hardware. > = > v2: Warn but accept invalid stride (Chris) > Rewrite the cursor size checks for other platforms (Chris) > v3: More polish and magic to the cursor size checks (Chris) > v4: Moar polish and a comment (Chris) > = > Reviewed-by: Chris Wilson > Signed-off-by: Ville Syrj=E4l=E4 All merged to dinq, thanks. -Daniel > --- > drivers/gpu/drm/i915/i915_reg.h | 3 +- > drivers/gpu/drm/i915/intel_display.c | 111 +++++++++++++++++++++++++++--= ------ > drivers/gpu/drm/i915/intel_drv.h | 1 + > 3 files changed, 91 insertions(+), 24 deletions(-) > = > diff --git a/drivers/gpu/drm/i915/i915_reg.h b/drivers/gpu/drm/i915/i915_= reg.h > index f79c20d..203062e 100644 > --- a/drivers/gpu/drm/i915/i915_reg.h > +++ b/drivers/gpu/drm/i915/i915_reg.h > @@ -4128,7 +4128,8 @@ enum punit_power_well { > /* Old style CUR*CNTR flags (desktop 8xx) */ > #define CURSOR_ENABLE 0x80000000 > #define CURSOR_GAMMA_ENABLE 0x40000000 > -#define CURSOR_STRIDE_MASK 0x30000000 > +#define CURSOR_STRIDE_SHIFT 28 > +#define CURSOR_STRIDE(x) ((ffs(x)-9) << CURSOR_STRIDE_SHIFT) /* 256,51= 2,1k,2k */ > #define CURSOR_PIPE_CSC_ENABLE (1<<24) > #define CURSOR_FORMAT_SHIFT 24 > #define CURSOR_FORMAT_MASK (0x07 << CURSOR_FORMAT_SHIFT) > diff --git a/drivers/gpu/drm/i915/intel_display.c b/drivers/gpu/drm/i915/= intel_display.c > index a1cf052..0cefd15 100644 > --- a/drivers/gpu/drm/i915/intel_display.c > +++ b/drivers/gpu/drm/i915/intel_display.c > @@ -8005,30 +8005,55 @@ static void i845_update_cursor(struct drm_crtc *c= rtc, u32 base) > struct drm_device *dev =3D crtc->dev; > struct drm_i915_private *dev_priv =3D dev->dev_private; > struct intel_crtc *intel_crtc =3D to_intel_crtc(crtc); > - uint32_t cntl; > + uint32_t cntl =3D 0, size =3D 0; > = > - if (base !=3D intel_crtc->cursor_base) { > - /* On these chipsets we can only modify the base whilst > - * the cursor is disabled. > - */ > - if (intel_crtc->cursor_cntl) { > - I915_WRITE(_CURACNTR, 0); > - POSTING_READ(_CURACNTR); > - intel_crtc->cursor_cntl =3D 0; > + if (base) { > + unsigned int width =3D intel_crtc->cursor_width; > + unsigned int height =3D intel_crtc->cursor_height; > + unsigned int stride =3D roundup_pow_of_two(width) * 4; > + > + switch (stride) { > + default: > + WARN_ONCE(1, "Invalid cursor width/stride, width=3D%u, stride=3D%u\n", > + width, stride); > + stride =3D 256; > + /* fallthrough */ > + case 256: > + case 512: > + case 1024: > + case 2048: > + break; > } > = > + cntl |=3D CURSOR_ENABLE | > + CURSOR_GAMMA_ENABLE | > + CURSOR_FORMAT_ARGB | > + CURSOR_STRIDE(stride); > + > + size =3D (height << 12) | width; > + } > + > + if (intel_crtc->cursor_cntl !=3D 0 && > + (intel_crtc->cursor_base !=3D base || > + intel_crtc->cursor_size !=3D size || > + intel_crtc->cursor_cntl !=3D cntl)) { > + /* On these chipsets we can only modify the base/size/stride > + * whilst the cursor is disabled. > + */ > + I915_WRITE(_CURACNTR, 0); > + POSTING_READ(_CURACNTR); > + intel_crtc->cursor_cntl =3D 0; > + } > + > + if (intel_crtc->cursor_base !=3D base) > I915_WRITE(_CURABASE, base); > - POSTING_READ(_CURABASE); > + > + if (intel_crtc->cursor_size !=3D size) { > + I915_WRITE(CURSIZE, size); > + intel_crtc->cursor_size =3D size; > } > = > - /* XXX width must be 64, stride 256 =3D> 0x00 << 28 */ > - cntl =3D 0; > - if (base) > - cntl =3D (CURSOR_ENABLE | > - CURSOR_GAMMA_ENABLE | > - CURSOR_FORMAT_ARGB); > if (intel_crtc->cursor_cntl !=3D cntl) { > - I915_WRITE(CURSIZE, (64 << 12) | 64); > I915_WRITE(_CURACNTR, cntl); > POSTING_READ(_CURACNTR); > intel_crtc->cursor_cntl =3D cntl; > @@ -8127,6 +8152,43 @@ static void intel_crtc_update_cursor(struct drm_cr= tc *crtc, > intel_crtc->cursor_base =3D base; > } > = > +static bool cursor_size_ok(struct drm_device *dev, > + uint32_t width, uint32_t height) > +{ > + if (width =3D=3D 0 || height =3D=3D 0) > + return false; > + > + /* > + * 845g/865g are special in that they are only limited by > + * the width of their cursors, the height is arbitrary up to > + * the precision of the register. Everything else requires > + * square cursors, limited to a few power-of-two sizes. > + */ > + if (IS_845G(dev) || IS_I865G(dev)) { > + if ((width & 63) !=3D 0) > + return false; > + > + if (width > (IS_845G(dev) ? 64 : 512)) > + return false; > + > + if (height > 1023) > + return false; > + } else { > + switch (width | height) { > + case 256: > + case 128: > + if (IS_GEN2(dev)) > + return false; > + case 64: > + break; > + default: > + return false; > + } > + } > + > + return true; > +} > + > /* > * intel_crtc_cursor_set_obj - Set cursor to specified GEM object > * > @@ -8141,7 +8203,7 @@ static int intel_crtc_cursor_set_obj(struct drm_crt= c *crtc, > struct drm_device *dev =3D crtc->dev; > struct intel_crtc *intel_crtc =3D to_intel_crtc(crtc); > enum pipe pipe =3D intel_crtc->pipe; > - unsigned old_width; > + unsigned old_width, stride; > uint32_t addr; > int ret; > = > @@ -8155,14 +8217,13 @@ static int intel_crtc_cursor_set_obj(struct drm_c= rtc *crtc, > } > = > /* Check for which cursor types we support */ > - if (!((width =3D=3D 64 && height =3D=3D 64) || > - (width =3D=3D 128 && height =3D=3D 128 && !IS_GEN2(dev)) || > - (width =3D=3D 256 && height =3D=3D 256 && !IS_GEN2(dev)))) { > + if (!cursor_size_ok(dev, width, height)) { > DRM_DEBUG("Cursor dimension not supported\n"); > return -EINVAL; > } > = > - if (obj->base.size < width * height * 4) { > + stride =3D roundup_pow_of_two(width) * 4; > + if (obj->base.size < stride * height) { > DRM_DEBUG_KMS("buffer is too small\n"); > ret =3D -ENOMEM; > goto fail; > @@ -11755,6 +11816,7 @@ static void intel_crtc_init(struct drm_device *de= v, int pipe) > = > intel_crtc->cursor_base =3D ~0; > intel_crtc->cursor_cntl =3D ~0; > + intel_crtc->cursor_size =3D ~0; > = > BUG_ON(pipe >=3D ARRAY_SIZE(dev_priv->plane_to_crtc_mapping) || > dev_priv->plane_to_crtc_mapping[intel_crtc->plane] !=3D NULL); > @@ -12543,7 +12605,10 @@ void intel_modeset_init(struct drm_device *dev) > dev->mode_config.max_height =3D 8192; > } > = > - if (IS_GEN2(dev)) { > + if (IS_845G(dev) || IS_I865G(dev)) { > + dev->mode_config.cursor_width =3D IS_845G(dev) ? 64 : 512; > + dev->mode_config.cursor_height =3D 1023; > + } else if (IS_GEN2(dev)) { > dev->mode_config.cursor_width =3D GEN2_CURSOR_WIDTH; > dev->mode_config.cursor_height =3D GEN2_CURSOR_HEIGHT; > } else { > diff --git a/drivers/gpu/drm/i915/intel_drv.h b/drivers/gpu/drm/i915/inte= l_drv.h > index 1b3d1d7..3cde050 100644 > --- a/drivers/gpu/drm/i915/intel_drv.h > +++ b/drivers/gpu/drm/i915/intel_drv.h > @@ -405,6 +405,7 @@ struct intel_crtc { > uint32_t cursor_addr; > int16_t cursor_width, cursor_height; > uint32_t cursor_cntl; > + uint32_t cursor_size; > uint32_t cursor_base; > = > struct intel_plane_config plane_config; > -- = > 1.8.5.5 > = > _______________________________________________ > Intel-gfx mailing list > Intel-gfx@lists.freedesktop.org > http://lists.freedesktop.org/mailman/listinfo/intel-gfx -- = Daniel Vetter Software Engineer, Intel Corporation +41 (0) 79 365 57 48 - http://blog.ffwll.ch