drm/i915: Big watermark changes
Subsystems (2)
cover drm/i915: Big watermark changes
This is a rather messy diff resulting from my attempt at making our watermark handling more robust, and especially more suitable for the atomic age.
I'll have to work on splitting the diff into some more sensible pieces, but I would appreciate some early comments on the general approach. But for that, it's possibly better to look at the resulting code [1] rather than the crappy diff.
[1] git://gitorious.org/vsyrjala/linux.git watermark2
RFC PATCH 1/1 drm/i915: Rewrite ILK+ watermark handling
From: Ville Syrjälä <[email protected]>
Rewrite the ILK+ watermark code to allow:
- updating the watermarks safely (to avoid underruns)
- pre-computing watermarks (will help with atomic modest and pageflip)
- enabling LP1+ watermarks for HSW multi-pipe scenarios
The watermark registers are not double buffered, so we have to be careful when/how we update them. It might be possible to increase the watermark level before a plane update occurs, but decreasing the watermark must happen after the plane update has finished. Also the FIFO split can change depending on whether a sprite is enabled or not.
The HSW multi-pipe low power watermark feature adds another level of complexity since the LP watermarks must be the max of all pipes at any given time.
All of this makes the whole idea of updating watermarks before the plane update too difficult. Instead just always update watermarks from the vblank interrupt.
We track the pending and active watermark levels for each pipe separately, and when the active levels for any pipe are updated from the vblank interrupt, we update the merged LP watermarks as well. We also need to track the active state of sprites and pipes alongside the watermarks to make sure we check the merged watermarks against the correct limits. The assumption is that if even one pipe is using a sprite we must check the merged values against the 1:1 (or 1:5) split FIFO sizes.
TODO:
- pre-gen5/vlv obviously
- are the IVB sprite scaling workarounds good enough or do we need extra vbl waits there?
- lots of testing to make sure it works
- really pre-compute the watermarks and fail the modeset if LP0 watermarks exceeds the limits
- make sure that the WM computations are correct
- try to verify the WM register max values w/ real hardware
- try to split the monster patch into reasonable pieces
- something else I forgot?
--- drivers/gpu/drm/i915/i915_drv.h | 4 +- drivers/gpu/drm/i915/i915_irq.c | 12 +- drivers/gpu/drm/i915/i915_reg.h | 13 + drivers/gpu/drm/i915/intel_display.c | 111 ++- drivers/gpu/drm/i915/intel_drv.h | 51 +- drivers/gpu/drm/i915/intel_pm.c | 1406 ++++++++++++++++++++-------------- drivers/gpu/drm/i915/intel_sprite.c | 38 +- 7 files changed, 1022 insertions(+), 613 deletions(-)
drivers/gpu/drm/i915/i915_drv.h +3 -1
@@ -297,6 +297,7 @@ struct drm_i915_display_funcs {int (*get_fifo_size)(struct drm_device *dev,int plane);void (*update_wm)(struct drm_device *dev);void (*update_sprite_wm)(struct drm_device *dev,int pipe, +int plane,bool enabled,bool scaled,uint32_t sprite_width,int pixel_size);void (*update_linetime_wm)(struct drm_device *dev,int pipe,struct drm_display_mode *mode);
@@ -955,7 +956,6 @@ typedef struct drm_i915_private {/* overlay */ struct intel_overlay *overlay; -unsigned int sprite_scaling_enabled;/* backlight */ struct {
@@ -1072,6 +1072,8 @@ typedef struct drm_i915_private {u32 fdi_rx_config; +spinlock_t wm_lock; +struct i915_suspend_saved_registers regfile;/* Old dri1 support infrastructure, beware the dragons ya fools entering
drivers/gpu/drm/i915/i915_irq.c +9 -3
@@ -1201,8 +1201,10 @@ static irqreturn_t ivybridge_irq_handler(int irq, void *arg)intel_opregion_asle_intr (dev);for (i =0 ; i <3 ; i++) { -if (de_iir & (DE_PIPEA_VBLANK_IVB << (5 * i))) +if (de_iir & (DE_PIPEA_VBLANK_IVB << (5 * i))) {drm_handle_vblank (dev, i); +ilk_pipe_update_wm (dev, i); + }if (de_iir & (DE_PLANEA_FLIP_DONE_IVB << (5 * i))) {intel_prepare_page_flip (dev, i);intel_finish_page_flip_plane (dev, i);
@@ -1297,11 +1299,15 @@ static irqreturn_t ironlake_irq_handler(int irq, void *arg)if (de_iir &DE_GSE )intel_opregion_asle_intr (dev); -if (de_iir &DE_PIPEA_VBLANK ) +if (de_iir &DE_PIPEA_VBLANK ) {drm_handle_vblank (dev,0 ); +ilk_pipe_update_wm (dev,0 ); + } -if (de_iir &DE_PIPEB_VBLANK ) +if (de_iir &DE_PIPEB_VBLANK ) {drm_handle_vblank (dev,1 ); +ilk_pipe_update_wm (dev,1 ); + }if (de_iir &DE_POISON )DRM_ERROR ("Poison interrupt\n" );
drivers/gpu/drm/i915/i915_reg.h +13 -0
@@ -3100,6 +3100,14 @@#define SNB_READ_WM2_LATENCY () SNB_LATENCY(SSKPD_WM2_SHIFT)#define SNB_READ_WM3_LATENCY () SNB_LATENCY(SSKPD_WM3_SHIFT) +#define HSW_LATENCY (offset, shift, mask) (I915_READ(MCHBAR_MIRROR_BASE_SNB + SSKPD + (offset)) >> (shift) & (mask)) +#define HSW_READ_WM0_OLD_LATENCY () HSW_LATENCY(0, 0, 0xf) +#define HSW_READ_WM1_LATENCY () HSW_LATENCY(0, 4, 0xff) +#define HSW_READ_WM2_LATENCY () HSW_LATENCY(0, 12, 0xff) +#define HSW_READ_WM3_LATENCY () HSW_LATENCY(0, 20, 0x1ff) +#define HSW_READ_WM4_LATENCY () HSW_LATENCY(4, 0, 0x1ff) +#define HSW_READ_WM0_NEW_LATENCY () HSW_LATENCY(4, 24, 0xff) +/* * The two pipe frame counter registers are not synchronized, so * reading a stable value is somewhat tricky. The following code
@@ -3696,6 +3704,8 @@#define DISP_ARB_CTL 0x45000#define DISP_TILE_SURFACE_SWIZZLING (1<<13)#define DISP_FBC_WM_DIS (1<<15) +#define DISP_ARB_CTL2 0x45004 +#define DISP_DATA_BUFFER_PARTITIONING (1<<6)#define GEN7_MSG_CTL 0x45010#define WAIT_FOR_PCH_RESET_ACK (1<<1)#define WAIT_FOR_PCH_FLR_ACK (1<<0)
@@ -4900,6 +4910,9 @@#define LCPLL_CD2X_CLOCK_DISABLE (1<<23)#define LCPLL_CD_SOURCE_FCLK (1<<21) +#define WM_MISC 0x45260 +#define WM_DATA_BUFFER_PARTITIONING (1<<0) +/* Pipe WM_LINETIME - watermark line time */ #define PIPE_WM_LINETIME_A 0x45270#define PIPE_WM_LINETIME_B 0x45274
drivers/gpu/drm/i915/intel_display.c +98 -13
262 lines not on this page · raw message
drivers/gpu/drm/i915/intel_drv.h +46 -5
79 lines not on this page · raw message
drivers/gpu/drm/i915/intel_pm.c +842 -564
1,561 lines not on this page · raw message
drivers/gpu/drm/i915/intel_sprite.c +11 -27
@@ -114,8 +114,6 @@ vlv_update_plane(struct drm_plane *dplane, struct drm_framebuffer *fb, crtc_w--; crtc_h--; -intel_update_sprite_watermarks (dev, pipe, crtc_w, pixel_size); -I915_WRITE (SPSTRIDE (pipe, plane), fb->pitches[0 ]);I915_WRITE (SPPOS (pipe, plane), (crtc_y <<16 ) | crtc_x);
@@ -219,7 +217,6 @@ ivb_update_plane(struct drm_plane *plane, struct drm_framebuffer *fb,u32 sprctl, sprscale =0 ;unsigned long sprsurf_offset, linear_offset;int pixel_size =drm_format_plane_cpp (fb->pixel_format,0 ); -bool scaling_was_enabled = dev_priv->sprite_scaling_enabled; sprctl =I915_READ (SPRCTL (pipe));
@@ -268,23 +265,13 @@ ivb_update_plane(struct drm_plane *plane, struct drm_framebuffer *fb, crtc_w--; crtc_h--; -intel_update_sprite_watermarks (dev, pipe, crtc_w, pixel_size); -/* * IVB workaround: must disable low power watermarks for at least * one frame before enabling scaling. LP watermarks can be re-enabled * when scaling is disabled. */ -if (crtc_w != src_w || crtc_h != src_h) { - dev_priv->sprite_scaling_enabled |=1 << pipe; - -if (!scaling_was_enabled) { -intel_update_watermarks (dev); -intel_wait_for_vblank (dev, pipe); - } +if (crtc_w != src_w || crtc_h != src_h) sprscale =SPRITE_SCALE_ENABLE | (src_w <<16 ) | src_h; - }else - dev_priv->sprite_scaling_enabled &= ~(1 << pipe);I915_WRITE (SPRSTRIDE (pipe), fb->pitches[0 ]);I915_WRITE (SPRPOS (pipe), (crtc_y <<16 ) | crtc_x);
@@ -310,10 +297,6 @@ ivb_update_plane(struct drm_plane *plane, struct drm_framebuffer *fb,I915_WRITE (SPRCTL (pipe), sprctl);I915_MODIFY_DISPBASE (SPRSURF (pipe), obj->gtt_offset + sprsurf_offset);POSTING_READ (SPRSURF (pipe)); - -/* potentially re-enable LP watermarks */ -if (scaling_was_enabled && !dev_priv->sprite_scaling_enabled) -intel_update_watermarks (dev); } static void
@@ -323,7 +306,6 @@ ivb_disable_plane(struct drm_plane *plane)struct drm_i915_private *dev_priv = dev->dev_private;struct intel_plane *intel_plane =to_intel_plane (plane);int pipe = intel_plane->pipe; -bool scaling_was_enabled = dev_priv->sprite_scaling_enabled;I915_WRITE (SPRCTL (pipe),I915_READ (SPRCTL (pipe)) & ~SPRITE_ENABLE );/* Can't leave the scaler enabled... */
@@ -332,12 +314,6 @@ ivb_disable_plane(struct drm_plane *plane)/* Activate double buffered register update */ I915_MODIFY_DISPBASE (SPRSURF (pipe),0 );POSTING_READ (SPRSURF (pipe)); - - dev_priv->sprite_scaling_enabled &= ~(1 << pipe); - -/* potentially re-enable LP watermarks */ -if (scaling_was_enabled && !dev_priv->sprite_scaling_enabled) -intel_update_watermarks (dev); } static int
@@ -453,8 +429,6 @@ ilk_update_plane(struct drm_plane *plane, struct drm_framebuffer *fb, crtc_w--; crtc_h--; -intel_update_sprite_watermarks (dev, pipe, crtc_w, pixel_size); - dvsscale =0 ;if (IS_GEN5 (dev) || crtc_w != src_w || crtc_h != src_h) dvsscale =DVS_SCALE_ENABLE | (src_w <<16 ) | src_h;
@@ -808,6 +782,11 @@ intel_update_plane(struct drm_plane *plane, struct drm_crtc *crtc, intel_plane->obj = obj; +intel_update_sprite_watermarks (dev, pipe, intel_plane->plane, + visible, + src_w != crtc_w || src_h != crtc_h, + src_w, pixel_size); +/* * Be sure to re-enable the primary before the sprite is no longer * covering it fully.
@@ -853,6 +832,11 @@ intel_disable_plane(struct drm_plane *plane)struct intel_plane *intel_plane =to_intel_plane (plane);int ret =0 ; +intel_update_sprite_watermarks (dev, + intel_plane->pipe, + intel_plane->plane, + false, false,0 ,0 ); +if (plane->crtc)intel_enable_primary (plane->crtc); intel_plane->disable_plane (plane);
Signature · 6 lines
1.8.1.5 _______________________________________________ Intel-gfx mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/intel-gfx
Re: [RFC][PATCH 1/1] drm/i915: Rewrite ILK+ watermark handling
2013/5/6 <[email protected]>:
Quoted 29 lines
From: Ville Syrjälä <[email protected]>
Rewrite the ILK+ watermark code to allow:
- updating the watermarks safely (to avoid underruns)
- pre-computing watermarks (will help with atomic modest and pageflip)
- enabling LP1+ watermarks for HSW multi-pipe scenariosThe watermark registers are not double buffered, so we have to be careful when/how we update them. It might be possible to increase the watermark level before a plane update occurs, but decreasing the watermark must happen after the plane update has finished. Also the FIFO split can change depending on whether a sprite is enabled or not.
The HSW multi-pipe low power watermark feature adds another level of complexity since the LP watermarks must be the max of all pipes at any given time.
All of this makes the whole idea of updating watermarks before the plane update too difficult. Instead just always update watermarks from the vblank interrupt.
We track the pending and active watermark levels for each pipe separately, and when the active levels for any pipe are updated from the vblank interrupt, we update the merged LP watermarks as well. We also need to track the active state of sprites and pipes alongside the watermarks to make sure we check the merged watermarks against the correct limits. The assumption is that if even one pipe is using a sprite we must check the merged values against the 1:1 (or 1:5) split FIFO sizes.
Quoted 5 lines
TODO:
- pre-gen5/vlv obviously
- are the IVB sprite scaling workarounds good enough or do we need extra vbl waits there?
- lots of testing to make sure it works
I wanted to see if the values computed were correct, so I compiled your gitorious tree. On Haswell, it gives a "divide error" when I try to modprobe i915.ko.
Signature · 1 line
Paulo Zanoni
Re: [RFC][PATCH 1/1] drm/i915: Rewrite ILK+ watermark handling
In reply to [email protected]Quoted 6 lines · On Mon, 6 May 2013 16:45:52 +0300 [email protected] wrote:
From: Ville Syrjälä <[email protected]>
Rewrite the ILK+ watermark code to allow:
- updating the watermarks safely (to avoid underruns)
- pre-computing watermarks (will help with atomic modest and pageflip)
- enabling LP1+ watermarks for HSW multi-pipe scenarios
This looks like the right way to go long term. But Paulo's patches for HSW are fairly small and make things better immediately, so we should probably get them in first.
This one needs to be split up somehow so we can review it better like you mention in the TODO.
Another thing that I used when doing the WM code way back when was to port it to userspace and run through various configs to make sure the values were all sane. Might be nice if we could do that easily somehow, maybe with an #ifdef or putting all the wm stuff into a separate file.
Signature · 5 lines
Jesse Barnes, Intel Open Source Technology Center _______________________________________________ Intel-gfx mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/intel-gfx
Re: [RFC][PATCH 1/1] drm/i915: Rewrite ILK+ watermark handling
Quoted 5 lines · Jesse Barnes
Quoted 2 lines · On Mon, 6 May 2013 16:45:52 +0300 [email protected] wrote:
From: Ville Syrjälä <[email protected]>
Quoted 8 lines
Quoted 4 lines
Rewrite the ILK+ watermark code to allow:
- updating the watermarks safely (to avoid underruns)
- pre-computing watermarks (will help with atomic modest and pageflip)
- enabling LP1+ watermarks for HSW multi-pipe scenariosThis looks like the right way to go long term. But Paulo's patches for HSW are fairly small and make things better immediately, so we should probably get them in first.
Agreed. I'll try to review them properly soon, so far I just glanced at them.
Quoted 8 lines
This one needs to be split up somehow so we can review it better like you mention in the TODO.
Another thing that I used when doing the WM code way back when was to port it to userspace and run through various configs to make sure the values were all sane. Might be nice if we could do that easily somehow, maybe with an #ifdef or putting all the wm stuff into a separate file.
Actually I had this stuff running in user space first :)
It's not that hard to implement the required stubs to get some drm file to compile in userland. I did it already for drm_edid.c (stuff that I've neglected to publish anywhere). I've not tried it for i915 code, and I suppose it may be a bit more work. Splitting the watermark stuff into a separate file could help a bit though.
Signature · 2 lines
Ville Syrjälä Intel OTC