drm/i915: Add support to change pixel format, tiling mode, tiling offset.
Subsystems (3)
PATCH 1/1 drm/i915: Add support to change pixel format, tiling mode, tiling offset.
Change: Add support to change the pixel format, base surface address, tiling mode, tiling offset on the flow during the primary plane flip.
Issue: This support is needed by hardware composer to meet the performance optimization requirement for 3D benchmark. This patch enables change in pixel format and tiling params without adding and removing the framebuffer. Adding and removing the framebuffer impacts performance.
Change Details-
drm: Defined function pointer set_pixelformat in drm_crtc_funcs. drm_crtc.c is modified to execute the function to update pixel format.
drm/i915: intel_crtc_set_pixel_format() implemented in i915 driver code (intel_display.c) and set to drm_crtc_funcs->set_pixelformat.haswell_set_pixelformat() implemented to update pixel format. This is specific to Haswell haswell_update_plane() implemented to update changes in tiling offset, surface base address and stride-fb->pitches[0]. Sends MI command to update the params in primary plane control registers.
--- drivers/gpu/drm/drm_crtc.c | 15 +++- drivers/gpu/drm/i915/intel_display.c | 156 ++++++++++++++++++++++++++++++++++ include/drm/drm_crtc.h | 8 ++ 3 files changed, 176 insertions(+), 3 deletions(-)
drivers/gpu/drm/drm_crtc.c +12 -3
@@ -3518,9 +3518,18 @@ int drm_mode_page_flip_ioctl(struct drm_device *dev, }if (crtc->fb->pixel_format != fb->pixel_format) { -DRM_DEBUG_KMS ("Page flip is not allowed to change frame buffer format.\n" ); - ret = -EINVAL ; - goto out; +if (crtc->funcs->set_pixelformat ==NULL ) { +DRM_DEBUG_KMS ("Pixel format change not allowed" ); + ret = -EINVAL ; + goto out; + } +/* supports dynamic change in pixel format */ + ret = crtc->funcs->set_pixelformat (crtc, fb->pixel_format); +if (ret) { +DRM_DEBUG_KMS ("Pixel format change failed %d" , + fb->pixel_format); + goto out; + } }if (page_flip->flags &DRM_MODE_PAGE_FLIP_EVENT ) {
drivers/gpu/drm/i915/intel_display.c +156 -0
192 lines not on this page · raw message
include/drm/drm_crtc.h +8 -0
@@ -323,6 +323,7 @@ struct drm_plane;* @set_property: called when a property is changed * @set_config: apply a new CRTC configuration * @page_flip: initiate a page flip +* @set_pixelformat: apply new pixel format to primary plane control register * * The drm_crtc_funcs structure is the central CRTC management structure * in the DRM. Each CRTC controls one or more connectors (note that the name
@@ -369,6 +370,13 @@ struct drm_crtc_funcs {int (*set_property)(struct drm_crtc *crtc,struct drm_property *property,uint64_t val); +/* +* Update the primary plane pixel format register during page flip. +* To support dynamic change in pixel format define the callback +* function for set_pixelformat. +*/ +int (*set_pixelformat)(struct drm_crtc *crtc, +uint32_t pixel_format); };/**
Signature · 1 line
1.7.9.5
Quoted 7 lines · Sandeep Ramankutty
Change: Add support to change the pixel format, base surface address, tiling mode, tiling offset on the flow during the primary plane flip.
Issue: This support is needed by hardware composer to meet the performance optimization requirement for 3D benchmark. This patch enables change in pixel format and tiling params without adding and removing the framebuffer. Adding and removing the framebuffer impacts performance.
We can't do it quite like this unfortunately. Watermarksm may need to be updated carefully if the bpp changes. Also updating multiple plane registers isn't always atomic, so we anyway need the vblank evade tricks to make it look pretty. I suppose it might be possible to make all that work via the ring, but my plan is to go for MMIO, and later investigate if we can optimize it by using the ring.
As far as the lowlevel details go, you supposedly need a SRM after each LRI aimed at the display registers. Otherwise I guess you could even blast all the registers with a single LRI.
Quoted 280 lines
Change Details-
drm: Defined function pointerset_pixelformatindrm_crtc_funcs.drm_crtc.cis modified to execute the function to update pixel format.
drm/i915:intel_crtc_set_pixel_format()implemented in i915 driver code (intel_display.c) and set todrm_crtc_funcs->set_pixelformat.haswell_set_pixelformat()implemented to update pixel format. This is specific to Haswellhaswell_update_plane()implemented to update changes in tiling offset, surface base address and stride-fb->pitches[0]. Sends MI command to update the params in primary plane control registers.Change-Id I4b0af83f641b2b79ee4f5c3401790d7d90ccd9efSigned-off-by Pallavi G <[email protected]>Signed-off-by Sandeep Ramakutty <[email protected]>--- drivers/gpu/drm/drm_crtc.c | 15 +++- drivers/gpu/drm/i915/intel_display.c | 156 ++++++++++++++++++++++++++++++++++ include/drm/drm_crtc.h | 8 ++ 3 files changed, 176 insertions(+), 3 deletions(-)drivers/gpu/drm/drm_crtc.c +12
-3@@ -3518,9 +3518,18 @@ int drm_mode_page_flip_ioctl(struct drm_device *dev, }if (crtc->fb->pixel_format != fb->pixel_format) { -DRM_DEBUG_KMS ("Page flip is not allowed to change frame buffer format.\n" ); - ret = -EINVAL ; - goto out; +if (crtc->funcs->set_pixelformat ==NULL ) { +DRM_DEBUG_KMS ("Pixel format change not allowed" ); + ret = -EINVAL ; + goto out; + } +/* supports dynamic change in pixel format */ + ret = crtc->funcs->set_pixelformat (crtc, fb->pixel_format); +if (ret) { +DRM_DEBUG_KMS ("Pixel format change failed %d" , + fb->pixel_format); + goto out; + } }if (page_flip->flags &DRM_MODE_PAGE_FLIP_EVENT ) {drivers/gpu/drm/i915/intel_display.c +156
-0@@ -45,6 +45,7 @@ bool intel_pipe_has_type(struct drm_crtc *crtc, int type);static void intel_increase_pllclock (struct drm_crtc *crtc);static void intel_crtc_update_cursor (struct drm_crtc *crtc,bool on); +typedef struct {int min, max; }intel_range_t ;@@ -1959,6 +1960,128 @@ static int i9xx_update_plane(struct drm_crtc *crtc, struct drm_framebuffer *fb,return 0 ; } +/* Set Pixel format for Haswell using MI commands */ +static int haswell_set_pixelformat (struct drm_crtc *crtc,u32 pixel_format) +{ +u32 dspcntr, reg; +struct drm_device *dev = crtc->dev; +struct drm_i915_private *dev_priv = dev->dev_private; +struct intel_crtc *intel_crtc =to_intel_crtc (crtc); +struct intel_ring_buffer *ring = &dev_priv->ring[BCS ]; +int ret =0 ; + + reg =DSPCNTR (intel_crtc->pipe); + dspcntr =I915_READ (reg); +DRM_DEBUG_DRIVER ("pixel format = %d\n" , pixel_format); +/* Mask out pixel format bits in case we change it */ + dspcntr &= ~DISPPLANE_PIXFORMAT_MASK ; +switch (pixel_format) { +case DRM_FORMAT_C8 : + dspcntr |=DISPPLANE_8BPP ; +break ; +case DRM_FORMAT_XRGB1555 : +case DRM_FORMAT_ARGB1555 : + dspcntr |=DISPPLANE_BGRX555 ; +break ; +case DRM_FORMAT_RGB565 : + dspcntr |=DISPPLANE_BGRX565 ; +break ; +case DRM_FORMAT_XRGB8888 : +case DRM_FORMAT_ARGB8888 : + dspcntr |=DISPPLANE_BGRX888 ; +break ; +case DRM_FORMAT_XBGR8888 : +case DRM_FORMAT_ABGR8888 : + dspcntr |=DISPPLANE_RGBX888 ; +break ; +case DRM_FORMAT_XRGB2101010 : +case DRM_FORMAT_ARGB2101010 : + dspcntr |=DISPPLANE_BGRX101010 ; +break ; +case DRM_FORMAT_XBGR2101010 : +case DRM_FORMAT_ABGR2101010 : + dspcntr |=DISPPLANE_RGBX101010 ; +break ; +default : +DRM_ERROR ("Unsupported pixel format 0x%08x\n" , pixel_format); +return -EINVAL ; + } + +/* Write pixel format update command to ring */ + ret =intel_ring_begin (ring,4 ); +if (ret) { +DRM_ERROR ("MI Command emit failed.\n" ); +return ret; + } +intel_ring_emit (ring,MI_NOOP ); +intel_ring_emit (ring,MI_LOAD_REGISTER_IMM (1 )); +intel_ring_emit (ring, reg); +intel_ring_emit (ring, dspcntr); +intel_ring_advance (ring); +return 0 ; +} + +/* Update the primary plane registers. Uses MI commands */ +static int haswell_update_plane (struct drm_crtc *crtc, +struct drm_framebuffer *fb,int x,int y) +{ +int ret; +struct drm_device *dev = crtc->dev; +struct drm_i915_private *dev_priv = dev->dev_private; +struct intel_crtc *intel_crtc =to_intel_crtc (crtc); +struct intel_ring_buffer *ring = &dev_priv->ring[BCS ]; +struct drm_i915_gem_object *obj; +int plane = intel_crtc->plane; + +switch (plane) { +case 0 : +case 1 : +case 2 : +break ; +default : +DRM_ERROR ("Can't update plane %c\n" ,plane_name (plane)); +return -EINVAL ; + } + obj =to_intel_framebuffer (fb)->obj; + +/* Set pixel format */ +haswell_set_pixelformat (crtc, fb->pixel_format); + +/* Set tiling offsets. Tiling mode is not set here as * +* it is set from intel_gen7_queue_flip. Send MI Command * +* to change - * +* 1. Tiling offset * +* 2. stride - fb->pitches[0] * +* 2. surface base address * +* Linear offset and tile offset is same for Haswell */ + intel_crtc->dspaddr_offset = +intel_gen4_compute_page_offset (&x, &y, obj->tiling_mode, + fb->bits_per_pixel /8 , + fb->pitches[0 ]); + +DRM_DEBUG_KMS ("Writing base %08X %08lX %d %d %d\n" , + obj->gtt_offset, intel_crtc->dspaddr_offset, + x, y, fb->pitches[0 ]); + +/* Emit MI commands here */ + ret =intel_ring_begin (ring,10 ); +if (ret) +return ret; +intel_ring_emit (ring,MI_NOOP ); +intel_ring_emit (ring,MI_LOAD_REGISTER_IMM (1 )); +intel_ring_emit (ring,DSPOFFSET (plane)); +intel_ring_emit (ring, (y <<16 ) | x); +intel_ring_emit (ring,MI_LOAD_REGISTER_IMM (1 )); +intel_ring_emit (ring,DSPSTRIDE (plane)); +intel_ring_emit (ring, fb->pitches[0 ]); +intel_ring_emit (ring,MI_LOAD_REGISTER_IMM (1 )); +intel_ring_emit (ring,DSPSURF (plane)); +intel_ring_emit (ring, obj->gtt_offset + intel_crtc->dspaddr_offset); +intel_ring_advance (ring); + +return 0 ; +} +static int ironlake_update_plane (struct drm_crtc *crtc,struct drm_framebuffer *fb,int x,int y) {@@ -7494,9 +7617,26 @@ static int intel_crtc_page_flip(struct drm_crtc *crtc,struct drm_framebuffer *old_fb = crtc->fb;struct drm_i915_gem_object *obj =to_intel_framebuffer (fb)->obj;struct intel_crtc *intel_crtc =to_intel_crtc (crtc); +struct intel_framebuffer *intel_fb;struct intel_unpin_work *work;unsigned long flags;int ret; +/* +* TILEOFF registers can't be changed via MI display flips. +* Changes in pitches[0] and offsets[0] updates the primary plane +* control registers. +*/ + intel_fb =to_intel_framebuffer (crtc->fb); +if ((IS_HASWELL (dev)) && + ((obj->tiling_mode != intel_fb->obj->tiling_mode) || + (fb->offsets[0 ] != crtc->fb->offsets[0 ]) || + (fb->pitches[0 ] != crtc->fb->pitches[0 ]))) { +DRM_DEBUG_DRIVER (" crtc fb: pitch = %d offset = %d\n" , + crtc->fb->pitches[0 ], crtc->fb->offsets[0 ]); +DRM_DEBUG_DRIVER (" input fb: pitch = %d offset = %d\n" , + fb->pitches[0 ], fb->offsets[0 ]); +haswell_update_plane (crtc, fb,0 ,0 ); + } work =kzalloc (sizeof *work,GFP_KERNEL );if (work ==NULL )@@ -8766,6 +8906,20 @@ out_config:return ret; } +/* Callback function - Called if change in pixel format is detected. +* Sends MI command to update change in pixel format. +*/ +static int intel_crtc_set_pixel_format (struct drm_crtc *crtc,u32 pixel_format) +{ +struct drm_device *dev = crtc->dev; +if (IS_HASWELL (dev)) { +return haswell_set_pixelformat (crtc, pixel_format); + }else { +DRM_ERROR ("Pixel format change not allowed.\n" ); +return -EINVAL ; + } +} +static const struct drm_crtc_funcs intel_crtc_funcs = { .cursor_set = intel_crtc_cursor_set, .cursor_move = intel_crtc_cursor_move,@@ -8773,6 +8927,7 @@ static const struct drm_crtc_funcs intel_crtc_funcs = { .set_config = intel_crtc_set_config, .destroy = intel_crtc_destroy, .page_flip = intel_crtc_page_flip, + .set_pixelformat = intel_crtc_set_pixel_format, };static void intel_cpu_pll_init (struct drm_device *dev)@@ -10180,3 +10335,4 @@ intel_display_print_error_state(struct drm_i915_error_state_buf *m, } }#endif +include/drm/drm_crtc.h +8
-0@@ -323,6 +323,7 @@ struct drm_plane;* @set_property: called when a property is changed * @set_config: apply a new CRTC configuration * @page_flip: initiate a page flip +* @set_pixelformat: apply new pixel format to primary plane control register * * The drm_crtc_funcs structure is the central CRTC management structure * in the DRM. Each CRTC controls one or more connectors (note that the name @@ -369,6 +370,13 @@ struct drm_crtc_funcs {int (*set_property)(struct drm_crtc *crtc,struct drm_property *property,uint64_t val); +/* +* Update the primary plane pixel format register during page flip. +* To support dynamic change in pixel format define the callback +* function for set_pixelformat. +*/ +int (*set_pixelformat)(struct drm_crtc *crtc, +uint32_t pixel_format); };/** Signature · 6 lines
1.7.9.5 _______________________________________________ Intel-gfx mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/intel-gfx
Signature · 2 lines
Ville Syrjälä Intel OTC
Hi Ville ,
Thanks for the feedback.
We verified without updating watermarks and found that the video playback, 3DMark and GLBenchmark plays fine. There was no underrun error too. Cases tried out-
Pixel format changed to 32BPP when water mark calculated based on 16BPP
Pixel format changed to 16BPP when water mark calculated based on 32BPP.
In both cases, we verified with video playback, 3DMark and GLBenchmark and did not see any underrun error. Is there any specific situations in which not setting WM can throw up an issue?
With MMIO there may be a possibility of flickering. The pixel format may be updated well before a page flip. With MMIO, the format will be written to register before a page flip and this can cause unwanted effects. Hence we used MI commands as this will get updated much nearer to a page flip.
What is SRM?
Regards,
Sandeep
-----Original Message-----
From: Ville Syrjälä [mailto:[email protected]]
Sent: Friday, September 13, 2013 7:56 PM
To: Ramakutty, SandeepX
Cc: [email protected]
Subject: Re: [Intel-gfx] [PATCH] drm/i915: Add support to change pixel format, tiling mode, tiling offset.
Quoted 7 lines · Sandeep Ramankutty
Change: Add support to change the pixel format, base surface address, tiling mode, tiling offset on the flow during the primary plane flip.
Issue: This support is needed by hardware composer to meet the
performance optimization requirement for 3D benchmark. This patch
enables change in pixel format and tiling params without adding and removing the framebuffer. Adding and removing the framebuffer impacts performance.
We can't do it quite like this unfortunately. Watermarksm may need to be updated carefully if the bpp changes. Also updating multiple plane registers isn't always atomic, so we anyway need the vblank evade tricks to make it look pretty. I suppose it might be possible to make all that work via the ring, but my plan is to go for MMIO, and later investigate if we can optimize it by using the ring.
As far as the lowlevel details go, you supposedly need a SRM after each LRI aimed at the display registers. Otherwise I guess you could even blast all the registers with a single LRI.
Quoted 276 lines
Change Details-
drm: Defined function pointerset_pixelformatindrm_crtc_funcs.drm_crtc.cis modified to execute the function to update pixel format. drm/i915:intel_crtc_set_pixel_format()implemented in i915 driver code (intel_display.c) and set todrm_crtc_funcs->set_pixelformat.haswell_set_pixelformat()implemented to update pixel format. This is specific to Haswellhaswell_update_plane()implemented to update changes in tiling offset, surface base address and stride-fb->pitches[0]. Sends MI command to update the params in primary plane control registers.Change-Id I4b0af83f641b2b79ee4f5c3401790d7d90ccd9efSigned-off-by Pallavi G <[email protected]>Signed-off-by Sandeep Ramakutty <[email protected]>--- drivers/gpu/drm/drm_crtc.c | 15 +++- drivers/gpu/drm/i915/intel_display.c | 156 ++++++++++++++++++++++++++++++++++ include/drm/drm_crtc.h | 8 ++ 3 files changed, 176 insertions(+), 3 deletions(-)drivers/gpu/drm/drm_crtc.c +12
-3@@ -3518,9 +3518,18 @@ int drm_mode_page_flip_ioctl(struct drm_device *dev, }if (crtc->fb->pixel_format != fb->pixel_format) { -DRM_DEBUG_KMS ("Page flip is not allowed to change frame buffer format.\n" ); - ret = -EINVAL ; - goto out; +if (crtc->funcs->set_pixelformat ==NULL ) { +DRM_DEBUG_KMS ("Pixel format change not allowed" ); + ret = -EINVAL ; + goto out; + } +/* supports dynamic change in pixel format */ + ret = crtc->funcs->set_pixelformat (crtc, fb->pixel_format); +if (ret) { +DRM_DEBUG_KMS ("Pixel format change failed %d" , + fb->pixel_format); + goto out; + } } if (page_flip->flags & DRM_MODE_PAGE_FLIP_EVENT) { diff --git
a/drivers/gpu/drm/i915/intel_display.cb/drivers/gpu/drm/i915/intel_display.c
index 955df91..7bfe088 100644drivers/gpu/drm/i915/intel_display.c +152
-0@@ -45,6 +45,7 @@ bool intel_pipe_has_type(struct drm_crtc *crtc, int type); static void intel_increase_pllclock(struct drm_crtc *crtc);static void intel_crtc_update_cursor (struct drm_crtc *crtc,bool on); +typedef struct {int min, max; }intel_range_t ;@@ -1959,6 +1960,128 @@ static int i9xx_update_plane(struct drm_crtc *crtc, struct drm_framebuffer *fb,return 0 ; } +/* Set Pixel format for Haswell using MI commands */ static int +haswell_set_pixelformat (struct drm_crtc *crtc,u32 pixel_format) { +u32 dspcntr, reg; +struct drm_device *dev = crtc->dev; +struct drm_i915_private *dev_priv = dev->dev_private; +struct intel_crtc *intel_crtc =to_intel_crtc (crtc); +struct intel_ring_buffer *ring = &dev_priv->ring[BCS ]; +int ret =0 ; + + reg =DSPCNTR (intel_crtc->pipe); + dspcntr =I915_READ (reg); +DRM_DEBUG_DRIVER ("pixel format = %d\n" , pixel_format); +/* Mask out pixel format bits in case we change it */ + dspcntr &= ~DISPPLANE_PIXFORMAT_MASK ; +switch (pixel_format) { +case DRM_FORMAT_C8 : + dspcntr |=DISPPLANE_8BPP ; +break ; +case DRM_FORMAT_XRGB1555 : +case DRM_FORMAT_ARGB1555 : + dspcntr |=DISPPLANE_BGRX555 ; +break ; +case DRM_FORMAT_RGB565 : + dspcntr |=DISPPLANE_BGRX565 ; +break ; +case DRM_FORMAT_XRGB8888 : +case DRM_FORMAT_ARGB8888 : + dspcntr |=DISPPLANE_BGRX888 ; +break ; +case DRM_FORMAT_XBGR8888 : +case DRM_FORMAT_ABGR8888 : + dspcntr |=DISPPLANE_RGBX888 ; +break ; +case DRM_FORMAT_XRGB2101010 : +case DRM_FORMAT_ARGB2101010 : + dspcntr |=DISPPLANE_BGRX101010 ; +break ; +case DRM_FORMAT_XBGR2101010 : +case DRM_FORMAT_ABGR2101010 : + dspcntr |=DISPPLANE_RGBX101010 ; +break ; +default : +DRM_ERROR ("Unsupported pixel format 0x%08x\n" , pixel_format); +return -EINVAL ; + } + +/* Write pixel format update command to ring */ + ret =intel_ring_begin (ring,4 ); +if (ret) { +DRM_ERROR ("MI Command emit failed.\n" ); +return ret; + } +intel_ring_emit (ring,MI_NOOP ); +intel_ring_emit (ring,MI_LOAD_REGISTER_IMM (1 )); +intel_ring_emit (ring, reg); +intel_ring_emit (ring, dspcntr); +intel_ring_advance (ring); +return 0 ; +} + +/* Update the primary plane registers. Uses MI commands */ static int +haswell_update_plane (struct drm_crtc *crtc, +struct drm_framebuffer *fb,int x,int y) { +int ret; +struct drm_device *dev = crtc->dev; +struct drm_i915_private *dev_priv = dev->dev_private; +struct intel_crtc *intel_crtc =to_intel_crtc (crtc); +struct intel_ring_buffer *ring = &dev_priv->ring[BCS ]; +struct drm_i915_gem_object *obj; +int plane = intel_crtc->plane; + +switch (plane) { +case 0 : +case 1 : +case 2 : +break ; +default : +DRM_ERROR ("Can't update plane %c\n" ,plane_name (plane)); +return -EINVAL ; + } + obj =to_intel_framebuffer (fb)->obj; + +/* Set pixel format */ +haswell_set_pixelformat (crtc, fb->pixel_format); + +/* Set tiling offsets. Tiling mode is not set here as * +* it is set from intel_gen7_queue_flip. Send MI Command * +* to change - * +* 1. Tiling offset * +* 2. stride - fb->pitches[0] * +* 2. surface base address * +* Linear offset and tile offset is same for Haswell */ + intel_crtc->dspaddr_offset = +intel_gen4_compute_page_offset (&x, &y, obj->tiling_mode, + fb->bits_per_pixel /8 , + fb->pitches[0 ]); + +DRM_DEBUG_KMS ("Writing base %08X %08lX %d %d %d\n" , + obj->gtt_offset, intel_crtc->dspaddr_offset, + x, y, fb->pitches[0 ]); + +/* Emit MI commands here */ + ret =intel_ring_begin (ring,10 ); +if (ret) +return ret; +intel_ring_emit (ring,MI_NOOP ); +intel_ring_emit (ring,MI_LOAD_REGISTER_IMM (1 )); +intel_ring_emit (ring,DSPOFFSET (plane)); +intel_ring_emit (ring, (y <<16 ) | x); +intel_ring_emit (ring,MI_LOAD_REGISTER_IMM (1 )); +intel_ring_emit (ring,DSPSTRIDE (plane)); +intel_ring_emit (ring, fb->pitches[0 ]); +intel_ring_emit (ring,MI_LOAD_REGISTER_IMM (1 )); +intel_ring_emit (ring,DSPSURF (plane)); +intel_ring_emit (ring, obj->gtt_offset + intel_crtc->dspaddr_offset); +intel_ring_advance (ring); + +return 0 ; +} +static int ironlake_update_plane (struct drm_crtc *crtc, struct drm_framebuffer *fb, int x, int y) { @@ -7494,9 +7617,26 @@ static int intel_crtc_page_flip(struct drm_crtc *crtc, struct drm_framebuffer *old_fb = crtc->fb;struct drm_i915_gem_object *obj =to_intel_framebuffer (fb)->obj;struct intel_crtc *intel_crtc =to_intel_crtc (crtc); +struct intel_framebuffer *intel_fb;struct intel_unpin_work *work;unsigned long flags;int ret; +/* +* TILEOFF registers can't be changed via MI display flips. +* Changes in pitches[0] and offsets[0] updates the primary plane +* control registers. +*/ + intel_fb =to_intel_framebuffer (crtc->fb); +if ((IS_HASWELL (dev)) && + ((obj->tiling_mode != intel_fb->obj->tiling_mode) || + (fb->offsets[0 ] != crtc->fb->offsets[0 ]) || + (fb->pitches[0 ] != crtc->fb->pitches[0 ]))) { +DRM_DEBUG_DRIVER (" crtc fb: pitch = %d offset = %d\n" , + crtc->fb->pitches[0 ], crtc->fb->offsets[0 ]); +DRM_DEBUG_DRIVER (" input fb: pitch = %d offset = %d\n" , + fb->pitches[0 ], fb->offsets[0 ]); +haswell_update_plane (crtc, fb,0 ,0 ); + } work =kzalloc (sizeof *work,GFP_KERNEL );if (work ==NULL )@@ -8766,6 +8906,20 @@ out_config:return ret; } +/* Callback function - Called if change in pixel format is detected. +* Sends MI command to update change in pixel format. +*/ +static int intel_crtc_set_pixel_format (struct drm_crtc *crtc,u32 +pixel_format) { +struct drm_device *dev = crtc->dev; +if (IS_HASWELL (dev)) { +return haswell_set_pixelformat (crtc, pixel_format); + }else { +DRM_ERROR ("Pixel format change not allowed.\n" ); +return -EINVAL ; + } +} +static const struct drm_crtc_funcs intel_crtc_funcs = { .cursor_set = intel_crtc_cursor_set, .cursor_move = intel_crtc_cursor_move, @@ -8773,6 +8927,7 @@ staticconst struct
drm_crtc_funcsintel_crtc_funcs= {drivers/gpu/drm/i915/intel_display.c +3
-0.set_config = intel_crtc_set_config, .destroy = intel_crtc_destroy, .page_flip = intel_crtc_page_flip, + .set_pixelformat = intel_crtc_set_pixel_format, }; static void intel_cpu_pll_init(struct drm_device *dev) @@ -10180,3 +10335,4 @@ intel_display_print_error_state(struct drm_i915_error_state_buf *m, } }#endif +include/drm/drm_crtc.h index renamed from include/drm/drm_crtc.h +0
-0e215bcc..9a0ea92 100644
include/drm/drm_crtc.h +2
-0@@ -323,6 +323,7 @@ struct drm_plane;* @set_property: called when a property is changed * @set_config: apply a new CRTC configuration * @page_flip: initiate a page flip +* @set_pixelformat: apply new pixel format to primary plane control +register * * The drm_crtc_funcs structure is the central CRTC management structure * in the DRM. Each CRTC controls one or more connectors (note that the name @@ -369,6 +370,13 @@ struct
drm_crtc_funcs{include/drm/drm_crtc.h +7
-1int (*set_property)(struct drm_crtc *crtc,struct drm_property *property,uint64_t val); +/* +* Update the primary plane pixel format register during page flip. +* To support dynamic change in pixel format define the callback +* function for set_pixelformat. +*/ +int (*set_pixelformat)(struct drm_crtc *crtc, +uint32_t pixel_format); };/** -- 1.7.9.5
Quoted 4 lines
_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx
--
Ville Syrjälä
Intel OTC
Quoted 9 lines · SandeepX
Hi Ville ,
Thanks for the feedback.
We verified without updating watermarks and found that the video playback, 3DMark and GLBenchmark plays fine. There was no underrun error too. Cases tried out-
Pixel format changed to 32BPP when water mark calculated based on 16BPP
Pixel format changed to 16BPP when water mark calculated based on 32BPP.
Quoted 5 lines
In both cases, we verified with video playback, 3DMark and GLBenchmark and did not see any underrun error. Is there any specific situations in which not setting WM can throw up an issue?
With MMIO there may be a possibility of flickering. The pixel format may be updated well before a page flip. With MMIO, the format will be written to register before a page flip and this can cause unwanted effects. Hence we used MI commands as this will get updated much nearer to a page flip.
What is SRM?
"store register mem". It reads the register and stores the result to memory.
BSpec tells us that there can only be one outstanding LRI targeted at the display registers at any given. So you need to do LRI+SRM for every display register you want to write w/ LRI.
Quoted 308 lines
Regards,
Sandeep-----Original Message-----
From: Ville Syrjälä [mailto:[email protected]]
Sent: Friday, September 13, 2013 7:56 PM
To: Ramakutty, SandeepX
Cc: [email protected]
Subject: Re: [Intel-gfx] [PATCH] drm/i915: Add support to change pixel format, tiling mode, tiling offset.Quoted 7 lines · Sandeep Ramankutty
Change: Add support to change the pixel format, base surface address, tiling mode, tiling offset on the flow during the primary plane flip.
Issue: This support is needed by hardware composer to meet the
performance optimization requirement for 3D benchmark. This patch
enables change in pixel format and tiling params without adding and removing the framebuffer. Adding and removing the framebuffer impacts performance.We can't do it quite like this unfortunately. Watermarksm may need to be updated carefully if the bpp changes. Also updating multiple plane registers isn't always atomic, so we anyway need the vblank evade tricks to make it look pretty. I suppose it might be possible to make all that work via the ring, but my plan is to go for MMIO, and later investigate if we can optimize it by using the ring.
As far as the lowlevel details go, you supposedly need a SRM after each LRI aimed at the display registers. Otherwise I guess you could even blast all the registers with a single LRI.
Quoted 276 lines
Change Details-
drm: Defined function pointerset_pixelformatindrm_crtc_funcs.drm_crtc.cis modified to execute the function to update pixel format. drm/i915:intel_crtc_set_pixel_format()implemented in i915 driver code (intel_display.c) and set todrm_crtc_funcs->set_pixelformat.haswell_set_pixelformat()implemented to update pixel format. This is specific to Haswellhaswell_update_plane()implemented to update changes in tiling offset, surface base address and stride-fb->pitches[0]. Sends MI command to update the params in primary plane control registers.Change-Id I4b0af83f641b2b79ee4f5c3401790d7d90ccd9efSigned-off-by Pallavi G <[email protected]>Signed-off-by Sandeep Ramakutty <[email protected]>--- drivers/gpu/drm/drm_crtc.c | 15 +++- drivers/gpu/drm/i915/intel_display.c | 156 ++++++++++++++++++++++++++++++++++ include/drm/drm_crtc.h | 8 ++ 3 files changed, 176 insertions(+), 3 deletions(-)drivers/gpu/drm/drm_crtc.c +12
-3@@ -3518,9 +3518,18 @@ int drm_mode_page_flip_ioctl(struct drm_device *dev, }if (crtc->fb->pixel_format != fb->pixel_format) { -DRM_DEBUG_KMS ("Page flip is not allowed to change frame buffer format.\n" ); - ret = -EINVAL ; - goto out; +if (crtc->funcs->set_pixelformat ==NULL ) { +DRM_DEBUG_KMS ("Pixel format change not allowed" ); + ret = -EINVAL ; + goto out; + } +/* supports dynamic change in pixel format */ + ret = crtc->funcs->set_pixelformat (crtc, fb->pixel_format); +if (ret) { +DRM_DEBUG_KMS ("Pixel format change failed %d" , + fb->pixel_format); + goto out; + } } if (page_flip->flags & DRM_MODE_PAGE_FLIP_EVENT) { diff --git
a/drivers/gpu/drm/i915/intel_display.cb/drivers/gpu/drm/i915/intel_display.c
index 955df91..7bfe088 100644drivers/gpu/drm/i915/intel_display.c +152
-0@@ -45,6 +45,7 @@ bool intel_pipe_has_type(struct drm_crtc *crtc, int type); static void intel_increase_pllclock(struct drm_crtc *crtc);static void intel_crtc_update_cursor (struct drm_crtc *crtc,bool on); +typedef struct {int min, max; }intel_range_t ;@@ -1959,6 +1960,128 @@ static int i9xx_update_plane(struct drm_crtc *crtc, struct drm_framebuffer *fb,return 0 ; } +/* Set Pixel format for Haswell using MI commands */ static int +haswell_set_pixelformat (struct drm_crtc *crtc,u32 pixel_format) { +u32 dspcntr, reg; +struct drm_device *dev = crtc->dev; +struct drm_i915_private *dev_priv = dev->dev_private; +struct intel_crtc *intel_crtc =to_intel_crtc (crtc); +struct intel_ring_buffer *ring = &dev_priv->ring[BCS ]; +int ret =0 ; + + reg =DSPCNTR (intel_crtc->pipe); + dspcntr =I915_READ (reg); +DRM_DEBUG_DRIVER ("pixel format = %d\n" , pixel_format); +/* Mask out pixel format bits in case we change it */ + dspcntr &= ~DISPPLANE_PIXFORMAT_MASK ; +switch (pixel_format) { +case DRM_FORMAT_C8 : + dspcntr |=DISPPLANE_8BPP ; +break ; +case DRM_FORMAT_XRGB1555 : +case DRM_FORMAT_ARGB1555 : + dspcntr |=DISPPLANE_BGRX555 ; +break ; +case DRM_FORMAT_RGB565 : + dspcntr |=DISPPLANE_BGRX565 ; +break ; +case DRM_FORMAT_XRGB8888 : +case DRM_FORMAT_ARGB8888 : + dspcntr |=DISPPLANE_BGRX888 ; +break ; +case DRM_FORMAT_XBGR8888 : +case DRM_FORMAT_ABGR8888 : + dspcntr |=DISPPLANE_RGBX888 ; +break ; +case DRM_FORMAT_XRGB2101010 : +case DRM_FORMAT_ARGB2101010 : + dspcntr |=DISPPLANE_BGRX101010 ; +break ; +case DRM_FORMAT_XBGR2101010 : +case DRM_FORMAT_ABGR2101010 : + dspcntr |=DISPPLANE_RGBX101010 ; +break ; +default : +DRM_ERROR ("Unsupported pixel format 0x%08x\n" , pixel_format); +return -EINVAL ; + } + +/* Write pixel format update command to ring */ + ret =intel_ring_begin (ring,4 ); +if (ret) { +DRM_ERROR ("MI Command emit failed.\n" ); +return ret; + } +intel_ring_emit (ring,MI_NOOP ); +intel_ring_emit (ring,MI_LOAD_REGISTER_IMM (1 )); +intel_ring_emit (ring, reg); +intel_ring_emit (ring, dspcntr); +intel_ring_advance (ring); +return 0 ; +} + +/* Update the primary plane registers. Uses MI commands */ static int +haswell_update_plane (struct drm_crtc *crtc, +struct drm_framebuffer *fb,int x,int y) { +int ret; +struct drm_device *dev = crtc->dev; +struct drm_i915_private *dev_priv = dev->dev_private; +struct intel_crtc *intel_crtc =to_intel_crtc (crtc); +struct intel_ring_buffer *ring = &dev_priv->ring[BCS ]; +struct drm_i915_gem_object *obj; +int plane = intel_crtc->plane; + +switch (plane) { +case 0 : +case 1 : +case 2 : +break ; +default : +DRM_ERROR ("Can't update plane %c\n" ,plane_name (plane)); +return -EINVAL ; + } + obj =to_intel_framebuffer (fb)->obj; + +/* Set pixel format */ +haswell_set_pixelformat (crtc, fb->pixel_format); + +/* Set tiling offsets. Tiling mode is not set here as * +* it is set from intel_gen7_queue_flip. Send MI Command * +* to change - * +* 1. Tiling offset * +* 2. stride - fb->pitches[0] * +* 2. surface base address * +* Linear offset and tile offset is same for Haswell */ + intel_crtc->dspaddr_offset = +intel_gen4_compute_page_offset (&x, &y, obj->tiling_mode, + fb->bits_per_pixel /8 , + fb->pitches[0 ]); + +DRM_DEBUG_KMS ("Writing base %08X %08lX %d %d %d\n" , + obj->gtt_offset, intel_crtc->dspaddr_offset, + x, y, fb->pitches[0 ]); + +/* Emit MI commands here */ + ret =intel_ring_begin (ring,10 ); +if (ret) +return ret; +intel_ring_emit (ring,MI_NOOP ); +intel_ring_emit (ring,MI_LOAD_REGISTER_IMM (1 )); +intel_ring_emit (ring,DSPOFFSET (plane)); +intel_ring_emit (ring, (y <<16 ) | x); +intel_ring_emit (ring,MI_LOAD_REGISTER_IMM (1 )); +intel_ring_emit (ring,DSPSTRIDE (plane)); +intel_ring_emit (ring, fb->pitches[0 ]); +intel_ring_emit (ring,MI_LOAD_REGISTER_IMM (1 )); +intel_ring_emit (ring,DSPSURF (plane)); +intel_ring_emit (ring, obj->gtt_offset + intel_crtc->dspaddr_offset); +intel_ring_advance (ring); + +return 0 ; +} +static int ironlake_update_plane (struct drm_crtc *crtc, struct drm_framebuffer *fb, int x, int y) { @@ -7494,9 +7617,26 @@ static int intel_crtc_page_flip(struct drm_crtc *crtc, struct drm_framebuffer *old_fb = crtc->fb;struct drm_i915_gem_object *obj =to_intel_framebuffer (fb)->obj;struct intel_crtc *intel_crtc =to_intel_crtc (crtc); +struct intel_framebuffer *intel_fb;struct intel_unpin_work *work;unsigned long flags;int ret; +/* +* TILEOFF registers can't be changed via MI display flips. +* Changes in pitches[0] and offsets[0] updates the primary plane +* control registers. +*/ + intel_fb =to_intel_framebuffer (crtc->fb); +if ((IS_HASWELL (dev)) && + ((obj->tiling_mode != intel_fb->obj->tiling_mode) || + (fb->offsets[0 ] != crtc->fb->offsets[0 ]) || + (fb->pitches[0 ] != crtc->fb->pitches[0 ]))) { +DRM_DEBUG_DRIVER (" crtc fb: pitch = %d offset = %d\n" , + crtc->fb->pitches[0 ], crtc->fb->offsets[0 ]); +DRM_DEBUG_DRIVER (" input fb: pitch = %d offset = %d\n" , + fb->pitches[0 ], fb->offsets[0 ]); +haswell_update_plane (crtc, fb,0 ,0 ); + } work =kzalloc (sizeof *work,GFP_KERNEL );if (work ==NULL )@@ -8766,6 +8906,20 @@ out_config:return ret; } +/* Callback function - Called if change in pixel format is detected. +* Sends MI command to update change in pixel format. +*/ +static int intel_crtc_set_pixel_format (struct drm_crtc *crtc,u32 +pixel_format) { +struct drm_device *dev = crtc->dev; +if (IS_HASWELL (dev)) { +return haswell_set_pixelformat (crtc, pixel_format); + }else { +DRM_ERROR ("Pixel format change not allowed.\n" ); +return -EINVAL ; + } +} +static const struct drm_crtc_funcs intel_crtc_funcs = { .cursor_set = intel_crtc_cursor_set, .cursor_move = intel_crtc_cursor_move, @@ -8773,6 +8927,7 @@ staticconst struct
drm_crtc_funcsintel_crtc_funcs= {drivers/gpu/drm/i915/intel_display.c +3
-0.set_config = intel_crtc_set_config, .destroy = intel_crtc_destroy, .page_flip = intel_crtc_page_flip, + .set_pixelformat = intel_crtc_set_pixel_format, }; static void intel_cpu_pll_init(struct drm_device *dev) @@ -10180,3 +10335,4 @@ intel_display_print_error_state(struct drm_i915_error_state_buf *m, } }#endif +include/drm/drm_crtc.h index renamed from include/drm/drm_crtc.h +0
-0e215bcc..9a0ea92 100644
include/drm/drm_crtc.h +2
-0@@ -323,6 +323,7 @@ struct drm_plane;* @set_property: called when a property is changed * @set_config: apply a new CRTC configuration * @page_flip: initiate a page flip +* @set_pixelformat: apply new pixel format to primary plane control +register * * The drm_crtc_funcs structure is the central CRTC management structure * in the DRM. Each CRTC controls one or more connectors (note that the name @@ -369,6 +370,13 @@ struct
drm_crtc_funcs{include/drm/drm_crtc.h +7
-1int (*set_property)(struct drm_crtc *crtc,struct drm_property *property,uint64_t val); +/* +* Update the primary plane pixel format register during page flip. +* To support dynamic change in pixel format define the callback +* function for set_pixelformat. +*/ +int (*set_pixelformat)(struct drm_crtc *crtc, +uint32_t pixel_format); };/** -- 1.7.9.5
Quoted 4 lines
_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx--
Ville Syrjälä
Intel OTC
Signature · 2 lines
Ville Syrjälä Intel OTC
Hi Ville,
Thanks for the information. Here MI_LOAD_REGISTER_IMM is used and not MI_LOAD_REGISTER_MEM. Is SRM needed after MI_LOAD_REGISTER_IMM? BSpec for MI_LOAD_REGISTER_IMM does not mention any thing about using SRM, but it is there for MI_LOAD_REGISTER_MEM.
Regards,
Sandeep
-----Original Message-----
From: Ville Syrjälä [mailto:[email protected]]
Sent: Thursday, October 31, 2013 5:54 PM
To: Ramakutty, SandeepX
Cc: [email protected]
Subject: Re: [Intel-gfx] [PATCH] drm/i915: Add support to change pixel format, tiling mode, tiling offset.
Quoted 9 lines · SandeepX
Hi Ville ,
Thanks for the feedback.
We verified without updating watermarks and found that the video playback, 3DMark and GLBenchmark plays fine. There was no underrun error too. Cases tried out-
Pixel format changed to 32BPP when water mark calculated based on
16BPP Pixel format changed to 16BPP when water mark calculated based on 32BPP.
Quoted 5 lines
In both cases, we verified with video playback, 3DMark and GLBenchmark and did not see any underrun error. Is there any specific situations in which not setting WM can throw up an issue?
With MMIO there may be a possibility of flickering. The pixel format may be updated well before a page flip. With MMIO, the format will be written to register before a page flip and this can cause unwanted effects. Hence we used MI commands as this will get updated much nearer to a page flip.
What is SRM?
"store register mem". It reads the register and stores the result to memory.
BSpec tells us that there can only be one outstanding LRI targeted at the display registers at any given. So you need to do LRI+SRM for every display register you want to write w/ LRI.
Quoted 302 lines
Regards,
Sandeep-----Original Message-----
From: Ville Syrjälä [mailto:[email protected]]
Sent: Friday, September 13, 2013 7:56 PM
To: Ramakutty, SandeepX
Cc: [email protected]
Subject: Re: [Intel-gfx] [PATCH] drm/i915: Add support to change pixel format, tiling mode, tiling offset.Quoted 7 lines · Sandeep Ramankutty
Change: Add support to change the pixel format, base surface address, tiling mode, tiling offset on the flow during the primary plane flip.
Issue: This support is needed by hardware composer to meet the
performance optimization requirement for 3D benchmark. This patch
enables change in pixel format and tiling params without adding and removing the framebuffer. Adding and removing the framebuffer impacts performance.We can't do it quite like this unfortunately. Watermarksm may need to be updated carefully if the bpp changes. Also updating multiple plane registers isn't always atomic, so we anyway need the vblank evade tricks to make it look pretty. I suppose it might be possible to make all that work via the ring, but my plan is to go for MMIO, and later investigate if we can optimize it by using the ring.
As far as the lowlevel details go, you supposedly need a SRM after each LRI aimed at the display registers. Otherwise I guess you could even blast all the registers with a single LRI.
Quoted 278 lines
Change Details-
drm: Defined function pointerset_pixelformatindrm_crtc_funcs.drm_crtc.cis modified to execute the function to update pixel format. drm/i915:intel_crtc_set_pixel_format()implemented in i915 driver code (intel_display.c) and set todrm_crtc_funcs->set_pixelformat.haswell_set_pixelformat()implemented to update pixel format. This is specific to Haswellhaswell_update_plane()implemented to update changes in tiling offset, surface base address and stride-fb->pitches[0]. Sends MI command to update the params in primary plane control registers.Change-Id I4b0af83f641b2b79ee4f5c3401790d7d90ccd9efSigned-off-by Pallavi G <[email protected]>Signed-off-by Sandeep Ramakutty <[email protected]>--- drivers/gpu/drm/drm_crtc.c | 15 +++- drivers/gpu/drm/i915/intel_display.c | 156 ++++++++++++++++++++++++++++++++++ include/drm/drm_crtc.h | 8 ++ 3 files changed, 176 insertions(+), 3 deletions(-)drivers/gpu/drm/drm_crtc.c +12
-3@@ -3518,9 +3518,18 @@ int drm_mode_page_flip_ioctl(struct drm_device *dev, }if (crtc->fb->pixel_format != fb->pixel_format) { -DRM_DEBUG_KMS ("Page flip is not allowed to change frame buffer format.\n" ); - ret = -EINVAL ; - goto out; +if (crtc->funcs->set_pixelformat ==NULL ) { +DRM_DEBUG_KMS ("Pixel format change not allowed" ); + ret = -EINVAL ; + goto out; + } +/* supports dynamic change in pixel format */ + ret = crtc->funcs->set_pixelformat (crtc, fb->pixel_format); +if (ret) { +DRM_DEBUG_KMS ("Pixel format change failed %d" , + fb->pixel_format); + goto out; + } } if (page_flip->flags & DRM_MODE_PAGE_FLIP_EVENT) { diff --git
a/drivers/gpu/drm/i915/intel_display.cb/drivers/gpu/drm/i915/intel_display.c
index 955df91..7bfe088 100644drivers/gpu/drm/i915/intel_display.c +0
-0@@ -45,6 +45,7 @@ bool intel_pipe_has_type(struct drm_crtc *crtc,int type); static void
intel_increase_pllclock(struct drm_crtc *crtc); static voidintel_crtc_update_cursor(struct drm_crtc *crtc, bool on);drivers/gpu/drm/i915/intel_display.c +153
-0+typedef struct {int min, max; }intel_range_t ;@@ -1959,6 +1960,128 @@ static int i9xx_update_plane(struct drm_crtc *crtc, struct drm_framebuffer *fb,return 0 ; } +/* Set Pixel format for Haswell using MI commands */ static int +haswell_set_pixelformat (struct drm_crtc *crtc,u32 pixel_format) { +u32 dspcntr, reg; +struct drm_device *dev = crtc->dev; +struct drm_i915_private *dev_priv = dev->dev_private; +struct intel_crtc *intel_crtc =to_intel_crtc (crtc); +struct intel_ring_buffer *ring = &dev_priv->ring[BCS ]; +int ret =0 ; + + reg =DSPCNTR (intel_crtc->pipe); + dspcntr =I915_READ (reg); +DRM_DEBUG_DRIVER ("pixel format = %d\n" , pixel_format); +/* Mask out pixel format bits in case we change it */ + dspcntr &= ~DISPPLANE_PIXFORMAT_MASK ; +switch (pixel_format) { +case DRM_FORMAT_C8 : + dspcntr |=DISPPLANE_8BPP ; +break ; +case DRM_FORMAT_XRGB1555 : +case DRM_FORMAT_ARGB1555 : + dspcntr |=DISPPLANE_BGRX555 ; +break ; +case DRM_FORMAT_RGB565 : + dspcntr |=DISPPLANE_BGRX565 ; +break ; +case DRM_FORMAT_XRGB8888 : +case DRM_FORMAT_ARGB8888 : + dspcntr |=DISPPLANE_BGRX888 ; +break ; +case DRM_FORMAT_XBGR8888 : +case DRM_FORMAT_ABGR8888 : + dspcntr |=DISPPLANE_RGBX888 ; +break ; +case DRM_FORMAT_XRGB2101010 : +case DRM_FORMAT_ARGB2101010 : + dspcntr |=DISPPLANE_BGRX101010 ; +break ; +case DRM_FORMAT_XBGR2101010 : +case DRM_FORMAT_ABGR2101010 : + dspcntr |=DISPPLANE_RGBX101010 ; +break ; +default : +DRM_ERROR ("Unsupported pixel format 0x%08x\n" , pixel_format); +return -EINVAL ; + } + +/* Write pixel format update command to ring */ + ret =intel_ring_begin (ring,4 ); +if (ret) { +DRM_ERROR ("MI Command emit failed.\n" ); +return ret; + } +intel_ring_emit (ring,MI_NOOP ); +intel_ring_emit (ring,MI_LOAD_REGISTER_IMM (1 )); +intel_ring_emit (ring, reg); +intel_ring_emit (ring, dspcntr); +intel_ring_advance (ring); +return 0 ; +} + +/* Update the primary plane registers. Uses MI commands */ static +int haswell_update_plane (struct drm_crtc *crtc, +struct drm_framebuffer *fb,int x,int y) { +int ret; +struct drm_device *dev = crtc->dev; +struct drm_i915_private *dev_priv = dev->dev_private; +struct intel_crtc *intel_crtc =to_intel_crtc (crtc); +struct intel_ring_buffer *ring = &dev_priv->ring[BCS ]; +struct drm_i915_gem_object *obj; +int plane = intel_crtc->plane; + +switch (plane) { +case 0 : +case 1 : +case 2 : +break ; +default : +DRM_ERROR ("Can't update plane %c\n" ,plane_name (plane)); +return -EINVAL ; + } + obj =to_intel_framebuffer (fb)->obj; + +/* Set pixel format */ +haswell_set_pixelformat (crtc, fb->pixel_format); + +/* Set tiling offsets. Tiling mode is not set here as * +* it is set from intel_gen7_queue_flip. Send MI Command * +* to change - * +* 1. Tiling offset * +* 2. stride - fb->pitches[0] * +* 2. surface base address * +* Linear offset and tile offset is same for Haswell */ + intel_crtc->dspaddr_offset = +intel_gen4_compute_page_offset (&x, &y, obj->tiling_mode, + fb->bits_per_pixel /8 , + fb->pitches[0 ]); + +DRM_DEBUG_KMS ("Writing base %08X %08lX %d %d %d\n" , + obj->gtt_offset, intel_crtc->dspaddr_offset, + x, y, fb->pitches[0 ]); + +/* Emit MI commands here */ + ret =intel_ring_begin (ring,10 ); +if (ret) +return ret; +intel_ring_emit (ring,MI_NOOP ); +intel_ring_emit (ring,MI_LOAD_REGISTER_IMM (1 )); +intel_ring_emit (ring,DSPOFFSET (plane)); +intel_ring_emit (ring, (y <<16 ) | x); +intel_ring_emit (ring,MI_LOAD_REGISTER_IMM (1 )); +intel_ring_emit (ring,DSPSTRIDE (plane)); +intel_ring_emit (ring, fb->pitches[0 ]); +intel_ring_emit (ring,MI_LOAD_REGISTER_IMM (1 )); +intel_ring_emit (ring,DSPSURF (plane)); +intel_ring_emit (ring, obj->gtt_offset + intel_crtc->dspaddr_offset); +intel_ring_advance (ring); + +return 0 ; +} +static int ironlake_update_plane (struct drm_crtc *crtc, struct drm_framebuffer *fb, int x, int y) { @@ -7494,9 +7617,26 @@ static int intel_crtc_page_flip(struct drm_crtc *crtc, struct drm_framebuffer *old_fb = crtc->fb;struct drm_i915_gem_object *obj =to_intel_framebuffer (fb)->obj;struct intel_crtc *intel_crtc =to_intel_crtc (crtc); +struct intel_framebuffer *intel_fb;struct intel_unpin_work *work;unsigned long flags;int ret; +/* +* TILEOFF registers can't be changed via MI display flips. +* Changes in pitches[0] and offsets[0] updates the primary plane +* control registers. +*/ + intel_fb =to_intel_framebuffer (crtc->fb); +if ((IS_HASWELL (dev)) && + ((obj->tiling_mode != intel_fb->obj->tiling_mode) || + (fb->offsets[0 ] != crtc->fb->offsets[0 ]) || + (fb->pitches[0 ] != crtc->fb->pitches[0 ]))) { +DRM_DEBUG_DRIVER (" crtc fb: pitch = %d offset = %d\n" , + crtc->fb->pitches[0 ], crtc->fb->offsets[0 ]); +DRM_DEBUG_DRIVER (" input fb: pitch = %d offset = %d\n" , + fb->pitches[0 ], fb->offsets[0 ]); +haswell_update_plane (crtc, fb,0 ,0 ); + } work =kzalloc (sizeof *work,GFP_KERNEL );if (work ==NULL )@@ -8766,6 +8906,20 @@ out_config:return ret; } +/* Callback function - Called if change in pixel format is detected. +* Sends MI command to update change in pixel format. +*/ +static int intel_crtc_set_pixel_format (struct drm_crtc *crtc,u32 +pixel_format) { +struct drm_device *dev = crtc->dev; +if (IS_HASWELL (dev)) { +return haswell_set_pixelformat (crtc, pixel_format); + }else { +DRM_ERROR ("Pixel format change not allowed.\n" ); +return -EINVAL ; + } +} +static const struct drm_crtc_funcs intel_crtc_funcs = { .cursor_set = intel_crtc_cursor_set, .cursor_move = intel_crtc_cursor_move, @@ -8773,6 +8927,7 @@static const struct
drm_crtc_funcsintel_crtc_funcs= {drivers/gpu/drm/i915/intel_display.c +4
-0.set_config = intel_crtc_set_config, .destroy = intel_crtc_destroy, .page_flip = intel_crtc_page_flip, + .set_pixelformat = intel_crtc_set_pixel_format, }; static void intel_cpu_pll_init(struct drm_device *dev) @@ -10180,3 +10335,4 @@ intel_display_print_error_state(struct +drm_i915_error_state_buf *m, } }#endif +include/drm/drm_crtc.h index renamed from include/drm/drm_crtc.h +0
-0e215bcc..9a0ea92 100644
include/drm/drm_crtc.h +2
-0@@ -323,6 +323,7 @@ struct drm_plane;* @set_property: called when a property is changed * @set_config: apply a new CRTC configuration * @page_flip: initiate a page flip +* @set_pixelformat: apply new pixel format to primary plane +control register * * The drm_crtc_funcs structure is the central CRTC management structure * in the DRM. Each CRTC controls one or more connectors (note that the name @@ -369,6 +370,13 @@ struct
drm_crtc_funcs{include/drm/drm_crtc.h +7
-1int (*set_property)(struct drm_crtc *crtc,struct drm_property *property,uint64_t val); +/* +* Update the primary plane pixel format register during page flip. +* To support dynamic change in pixel format define the callback +* function for set_pixelformat. +*/ +int (*set_pixelformat)(struct drm_crtc *crtc, +uint32_t pixel_format); };/** -- 1.7.9.5
Quoted 8 lines
Quoted 4 lines
_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx--
Ville Syrjälä
Intel OTC
--
Ville Syrjälä
Intel OTC
Quoted 3 lines · SandeepX
Hi Ville,
Thanks for the information. Here
MI_LOAD_REGISTER_IMMis used and notMI_LOAD_REGISTER_MEM. Is SRM needed afterMI_LOAD_REGISTER_IMM? BSpec forMI_LOAD_REGISTER_IMMdoes not mention any thing about using SRM, but it is there forMI_LOAD_REGISTER_MEM.
Just checked BSpec and it's still there:
"Limited LRI cycles to the Display Engine 0x40000-0xBFFFF) are allowed,
but must be spaced to allow only one pending at a time. This can be done by issuing an SRM to the same address immediately after each LRI."
Quoted 345 lines
Regards,
Sandeep-----Original Message-----
From: Ville Syrjälä [mailto:[email protected]]
Sent: Thursday, October 31, 2013 5:54 PM
To: Ramakutty, SandeepX
Cc: [email protected]
Subject: Re: [Intel-gfx] [PATCH] drm/i915: Add support to change pixel format, tiling mode, tiling offset.Quoted 9 lines · SandeepX
Hi Ville ,
Thanks for the feedback.
We verified without updating watermarks and found that the video playback, 3DMark and GLBenchmark plays fine. There was no underrun error too. Cases tried out-
Pixel format changed to 32BPP when water mark calculated based on
16BPP Pixel format changed to 16BPP when water mark calculated based on 32BPP.Quoted 5 lines
In both cases, we verified with video playback, 3DMark and GLBenchmark and did not see any underrun error. Is there any specific situations in which not setting WM can throw up an issue?
With MMIO there may be a possibility of flickering. The pixel format may be updated well before a page flip. With MMIO, the format will be written to register before a page flip and this can cause unwanted effects. Hence we used MI commands as this will get updated much nearer to a page flip.
What is SRM?
"store register mem". It reads the register and stores the result to memory.
BSpec tells us that there can only be one outstanding LRI targeted at the display registers at any given. So you need to do LRI+SRM for every display register you want to write w/ LRI.
Quoted 302 lines
Regards,
Sandeep-----Original Message-----
From: Ville Syrjälä [mailto:[email protected]]
Sent: Friday, September 13, 2013 7:56 PM
To: Ramakutty, SandeepX
Cc: [email protected]
Subject: Re: [Intel-gfx] [PATCH] drm/i915: Add support to change pixel format, tiling mode, tiling offset.Quoted 7 lines · Sandeep Ramankutty
Change: Add support to change the pixel format, base surface address, tiling mode, tiling offset on the flow during the primary plane flip.
Issue: This support is needed by hardware composer to meet the
performance optimization requirement for 3D benchmark. This patch
enables change in pixel format and tiling params without adding and removing the framebuffer. Adding and removing the framebuffer impacts performance.We can't do it quite like this unfortunately. Watermarksm may need to be updated carefully if the bpp changes. Also updating multiple plane registers isn't always atomic, so we anyway need the vblank evade tricks to make it look pretty. I suppose it might be possible to make all that work via the ring, but my plan is to go for MMIO, and later investigate if we can optimize it by using the ring.
As far as the lowlevel details go, you supposedly need a SRM after each LRI aimed at the display registers. Otherwise I guess you could even blast all the registers with a single LRI.
Quoted 278 lines
Change Details-
drm: Defined function pointerset_pixelformatindrm_crtc_funcs.drm_crtc.cis modified to execute the function to update pixel format. drm/i915:intel_crtc_set_pixel_format()implemented in i915 driver code (intel_display.c) and set todrm_crtc_funcs->set_pixelformat.haswell_set_pixelformat()implemented to update pixel format. This is specific to Haswellhaswell_update_plane()implemented to update changes in tiling offset, surface base address and stride-fb->pitches[0]. Sends MI command to update the params in primary plane control registers.Change-Id I4b0af83f641b2b79ee4f5c3401790d7d90ccd9efSigned-off-by Pallavi G <[email protected]>Signed-off-by Sandeep Ramakutty <[email protected]>--- drivers/gpu/drm/drm_crtc.c | 15 +++- drivers/gpu/drm/i915/intel_display.c | 156 ++++++++++++++++++++++++++++++++++ include/drm/drm_crtc.h | 8 ++ 3 files changed, 176 insertions(+), 3 deletions(-)drivers/gpu/drm/drm_crtc.c +12
-3@@ -3518,9 +3518,18 @@ int drm_mode_page_flip_ioctl(struct drm_device *dev, }if (crtc->fb->pixel_format != fb->pixel_format) { -DRM_DEBUG_KMS ("Page flip is not allowed to change frame buffer format.\n" ); - ret = -EINVAL ; - goto out; +if (crtc->funcs->set_pixelformat ==NULL ) { +DRM_DEBUG_KMS ("Pixel format change not allowed" ); + ret = -EINVAL ; + goto out; + } +/* supports dynamic change in pixel format */ + ret = crtc->funcs->set_pixelformat (crtc, fb->pixel_format); +if (ret) { +DRM_DEBUG_KMS ("Pixel format change failed %d" , + fb->pixel_format); + goto out; + } } if (page_flip->flags & DRM_MODE_PAGE_FLIP_EVENT) { diff --git
a/drivers/gpu/drm/i915/intel_display.cb/drivers/gpu/drm/i915/intel_display.c
index 955df91..7bfe088 100644drivers/gpu/drm/i915/intel_display.c +0
-0@@ -45,6 +45,7 @@ bool intel_pipe_has_type(struct drm_crtc *crtc,int type); static void
intel_increase_pllclock(struct drm_crtc *crtc); static voidintel_crtc_update_cursor(struct drm_crtc *crtc, bool on);drivers/gpu/drm/i915/intel_display.c +153
-0+typedef struct {int min, max; }intel_range_t ;@@ -1959,6 +1960,128 @@ static int i9xx_update_plane(struct drm_crtc *crtc, struct drm_framebuffer *fb,return 0 ; } +/* Set Pixel format for Haswell using MI commands */ static int +haswell_set_pixelformat (struct drm_crtc *crtc,u32 pixel_format) { +u32 dspcntr, reg; +struct drm_device *dev = crtc->dev; +struct drm_i915_private *dev_priv = dev->dev_private; +struct intel_crtc *intel_crtc =to_intel_crtc (crtc); +struct intel_ring_buffer *ring = &dev_priv->ring[BCS ]; +int ret =0 ; + + reg =DSPCNTR (intel_crtc->pipe); + dspcntr =I915_READ (reg); +DRM_DEBUG_DRIVER ("pixel format = %d\n" , pixel_format); +/* Mask out pixel format bits in case we change it */ + dspcntr &= ~DISPPLANE_PIXFORMAT_MASK ; +switch (pixel_format) { +case DRM_FORMAT_C8 : + dspcntr |=DISPPLANE_8BPP ; +break ; +case DRM_FORMAT_XRGB1555 : +case DRM_FORMAT_ARGB1555 : + dspcntr |=DISPPLANE_BGRX555 ; +break ; +case DRM_FORMAT_RGB565 : + dspcntr |=DISPPLANE_BGRX565 ; +break ; +case DRM_FORMAT_XRGB8888 : +case DRM_FORMAT_ARGB8888 : + dspcntr |=DISPPLANE_BGRX888 ; +break ; +case DRM_FORMAT_XBGR8888 : +case DRM_FORMAT_ABGR8888 : + dspcntr |=DISPPLANE_RGBX888 ; +break ; +case DRM_FORMAT_XRGB2101010 : +case DRM_FORMAT_ARGB2101010 : + dspcntr |=DISPPLANE_BGRX101010 ; +break ; +case DRM_FORMAT_XBGR2101010 : +case DRM_FORMAT_ABGR2101010 : + dspcntr |=DISPPLANE_RGBX101010 ; +break ; +default : +DRM_ERROR ("Unsupported pixel format 0x%08x\n" , pixel_format); +return -EINVAL ; + } + +/* Write pixel format update command to ring */ + ret =intel_ring_begin (ring,4 ); +if (ret) { +DRM_ERROR ("MI Command emit failed.\n" ); +return ret; + } +intel_ring_emit (ring,MI_NOOP ); +intel_ring_emit (ring,MI_LOAD_REGISTER_IMM (1 )); +intel_ring_emit (ring, reg); +intel_ring_emit (ring, dspcntr); +intel_ring_advance (ring); +return 0 ; +} + +/* Update the primary plane registers. Uses MI commands */ static +int haswell_update_plane (struct drm_crtc *crtc, +struct drm_framebuffer *fb,int x,int y) { +int ret; +struct drm_device *dev = crtc->dev; +struct drm_i915_private *dev_priv = dev->dev_private; +struct intel_crtc *intel_crtc =to_intel_crtc (crtc); +struct intel_ring_buffer *ring = &dev_priv->ring[BCS ]; +struct drm_i915_gem_object *obj; +int plane = intel_crtc->plane; + +switch (plane) { +case 0 : +case 1 : +case 2 : +break ; +default : +DRM_ERROR ("Can't update plane %c\n" ,plane_name (plane)); +return -EINVAL ; + } + obj =to_intel_framebuffer (fb)->obj; + +/* Set pixel format */ +haswell_set_pixelformat (crtc, fb->pixel_format); + +/* Set tiling offsets. Tiling mode is not set here as * +* it is set from intel_gen7_queue_flip. Send MI Command * +* to change - * +* 1. Tiling offset * +* 2. stride - fb->pitches[0] * +* 2. surface base address * +* Linear offset and tile offset is same for Haswell */ + intel_crtc->dspaddr_offset = +intel_gen4_compute_page_offset (&x, &y, obj->tiling_mode, + fb->bits_per_pixel /8 , + fb->pitches[0 ]); + +DRM_DEBUG_KMS ("Writing base %08X %08lX %d %d %d\n" , + obj->gtt_offset, intel_crtc->dspaddr_offset, + x, y, fb->pitches[0 ]); + +/* Emit MI commands here */ + ret =intel_ring_begin (ring,10 ); +if (ret) +return ret; +intel_ring_emit (ring,MI_NOOP ); +intel_ring_emit (ring,MI_LOAD_REGISTER_IMM (1 )); +intel_ring_emit (ring,DSPOFFSET (plane)); +intel_ring_emit (ring, (y <<16 ) | x); +intel_ring_emit (ring,MI_LOAD_REGISTER_IMM (1 )); +intel_ring_emit (ring,DSPSTRIDE (plane)); +intel_ring_emit (ring, fb->pitches[0 ]); +intel_ring_emit (ring,MI_LOAD_REGISTER_IMM (1 )); +intel_ring_emit (ring,DSPSURF (plane)); +intel_ring_emit (ring, obj->gtt_offset + intel_crtc->dspaddr_offset); +intel_ring_advance (ring); + +return 0 ; +} +static int ironlake_update_plane (struct drm_crtc *crtc, struct drm_framebuffer *fb, int x, int y) { @@ -7494,9 +7617,26 @@ static int intel_crtc_page_flip(struct drm_crtc *crtc, struct drm_framebuffer *old_fb = crtc->fb;struct drm_i915_gem_object *obj =to_intel_framebuffer (fb)->obj;struct intel_crtc *intel_crtc =to_intel_crtc (crtc); +struct intel_framebuffer *intel_fb;struct intel_unpin_work *work;unsigned long flags;int ret; +/* +* TILEOFF registers can't be changed via MI display flips. +* Changes in pitches[0] and offsets[0] updates the primary plane +* control registers. +*/ + intel_fb =to_intel_framebuffer (crtc->fb); +if ((IS_HASWELL (dev)) && + ((obj->tiling_mode != intel_fb->obj->tiling_mode) || + (fb->offsets[0 ] != crtc->fb->offsets[0 ]) || + (fb->pitches[0 ] != crtc->fb->pitches[0 ]))) { +DRM_DEBUG_DRIVER (" crtc fb: pitch = %d offset = %d\n" , + crtc->fb->pitches[0 ], crtc->fb->offsets[0 ]); +DRM_DEBUG_DRIVER (" input fb: pitch = %d offset = %d\n" , + fb->pitches[0 ], fb->offsets[0 ]); +haswell_update_plane (crtc, fb,0 ,0 ); + } work =kzalloc (sizeof *work,GFP_KERNEL );if (work ==NULL )@@ -8766,6 +8906,20 @@ out_config:return ret; } +/* Callback function - Called if change in pixel format is detected. +* Sends MI command to update change in pixel format. +*/ +static int intel_crtc_set_pixel_format (struct drm_crtc *crtc,u32 +pixel_format) { +struct drm_device *dev = crtc->dev; +if (IS_HASWELL (dev)) { +return haswell_set_pixelformat (crtc, pixel_format); + }else { +DRM_ERROR ("Pixel format change not allowed.\n" ); +return -EINVAL ; + } +} +static const struct drm_crtc_funcs intel_crtc_funcs = { .cursor_set = intel_crtc_cursor_set, .cursor_move = intel_crtc_cursor_move, @@ -8773,6 +8927,7 @@static const struct
drm_crtc_funcsintel_crtc_funcs= {drivers/gpu/drm/i915/intel_display.c +4
-0.set_config = intel_crtc_set_config, .destroy = intel_crtc_destroy, .page_flip = intel_crtc_page_flip, + .set_pixelformat = intel_crtc_set_pixel_format, }; static void intel_cpu_pll_init(struct drm_device *dev) @@ -10180,3 +10335,4 @@ intel_display_print_error_state(struct +drm_i915_error_state_buf *m, } }#endif +include/drm/drm_crtc.h index renamed from include/drm/drm_crtc.h +0
-0e215bcc..9a0ea92 100644
include/drm/drm_crtc.h +2
-0@@ -323,6 +323,7 @@ struct drm_plane;* @set_property: called when a property is changed * @set_config: apply a new CRTC configuration * @page_flip: initiate a page flip +* @set_pixelformat: apply new pixel format to primary plane +control register * * The drm_crtc_funcs structure is the central CRTC management structure * in the DRM. Each CRTC controls one or more connectors (note that the name @@ -369,6 +370,13 @@ struct
drm_crtc_funcs{include/drm/drm_crtc.h +7
-1int (*set_property)(struct drm_crtc *crtc,struct drm_property *property,uint64_t val); +/* +* Update the primary plane pixel format register during page flip. +* To support dynamic change in pixel format define the callback +* function for set_pixelformat. +*/ +int (*set_pixelformat)(struct drm_crtc *crtc, +uint32_t pixel_format); };/** -- 1.7.9.5
Quoted 8 lines
Quoted 4 lines
_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx--
Ville Syrjälä
Intel OTC--
Ville Syrjälä
Intel OTC
Signature · 2 lines
Ville Syrjälä Intel OTC
Quoted 2 lines · Sandeep Ramankutty
Change: Add support to change the pixel format, base surface address, tiling mode, tiling offset on the flow during the primary plane flip.
Tell us why first. Why this patch is necesary is the fundamental reason that we need to record in the changelog. Discuss the background and the motivation that leads us to require a kernel patch.
Quoted 4 lines
Issue: This support is needed by hardware composer to meet the performance optimization requirement for 3D benchmark. This patch enables change in pixel format and tiling params without adding and removing the framebuffer. Adding and removing the framebuffer impacts performance.
So you say. Examples are vital, especially if you make a claim as towards performance. And then to back those up with tests to make sure nothing is broken. The other question is how do we end up regularly flipping between pixel formats that it shows up in a performance benchmark.
Quoted 9 lines
Change Details-
drm: Defined function pointerset_pixelformatindrm_crtc_funcs.drm_crtc.cis modified to execute the function to update pixel format.
drm/i915:intel_crtc_set_pixel_format()implemented in i915 driver code (intel_display.c) and set todrm_crtc_funcs->set_pixelformat.haswell_set_pixelformat()implemented to update pixel format. This is specific to Haswellhaswell_update_plane()implemented to update changes in tiling offset, surface base address and stride-fb->pitches[0]. Sends MI command to update the params in primary plane control registers.
You don't need to repeat the patch, just tell us what complications you encountered and how you resolved them, or what issues remain.
Quoted 18 lines
Change-Id I4b0af83f641b2b79ee4f5c3401790d7d90ccd9efSigned-off-by Pallavi G <[email protected]>Signed-off-by Sandeep Ramakutty <[email protected]>--- drivers/gpu/drm/drm_crtc.c | 15 +++- drivers/gpu/drm/i915/intel_display.c | 156 ++++++++++++++++++++++++++++++++++ include/drm/drm_crtc.h | 8 ++ 3 files changed, 176 insertions(+), 3 deletions(-)drivers/gpu/drm/drm_crtc.c +0
-0@@ -3518,9 +3518,18 @@ int drm_mode_page_flip_ioctl(struct drm_device *dev, }if (crtc->fb->pixel_format != fb->pixel_format) {
drivers/gpu/drm/drm_crtc.c int drm_mode_page_flip_ioctl(struct drm_device *dev, · line 3527
Quoted 10 lines
drivers/gpu/drm/drm_crtc.c +7
-3-DRM_DEBUG_KMS ("Page flip is not allowed to change frame buffer format.\n" ); - ret = -EINVAL ; - goto out; +if (crtc->funcs->set_pixelformat ==NULL ) { +DRM_DEBUG_KMS ("Pixel format change not allowed" ); + ret = -EINVAL ; + goto out; + } +/* supports dynamic change in pixel format */ + ret = crtc->funcs->set_pixelformat (crtc, fb->pixel_format);
Bleh.
Just install a default set_pixelformat that returns -EINVAL and lose the i++; /* increment i after reading */
Also the current use of crtc->funcs->set_pixelformat suggests confusion is paramount.
drivers/gpu/drm/drm_crtc.c int drm_mode_page_flip_ioctl(struct drm_device *dev, · line 3532
Quoted 5 lines
drivers/gpu/drm/drm_crtc.c +5
-0+if (ret) { +DRM_DEBUG_KMS ("Pixel format change failed %d" , + fb->pixel_format); + goto out; + }
What happens if the flip fails afterwards? Where's the unwind? Where's the protection that prevents the format change whilst the current scanout is still visible? Perhaps this being the ring emission is being attempted far too early.
Quoted 18 lines
drivers/gpu/drm/drm_crtc.c +0
-0}if (page_flip->flags &DRM_MODE_PAGE_FLIP_EVENT ) {drivers/gpu/drm/i915/intel_display.c +1
-0@@ -45,6 +45,7 @@ bool intel_pipe_has_type(struct drm_crtc *crtc, int type);static void intel_increase_pllclock (struct drm_crtc *crtc);static void intel_crtc_update_cursor (struct drm_crtc *crtc,bool on); +typedef struct {int min, max; }intel_range_t ;@@ -1959,6 +1960,128 @@ static int i9xx_update_plane(struct drm_crtc *crtc, struct drm_framebuffer *fb,return 0 ; }
drivers/gpu/drm/i915/intel_display.c static int i9xx_update_plane(struct drm_crtc *crtc, struct drm_framebuffer *fb, · line 1971
Quoted 10 lines
drivers/gpu/drm/i915/intel_display.c +9
-0+/* Set Pixel format for Haswell using MI commands */ +static int haswell_set_pixelformat (struct drm_crtc *crtc,u32 pixel_format) +{ +u32 dspcntr, reg; +struct drm_device *dev = crtc->dev; +struct drm_i915_private *dev_priv = dev->dev_private; +struct intel_crtc *intel_crtc =to_intel_crtc (crtc); +struct intel_ring_buffer *ring = &dev_priv->ring[BCS ]; +int ret =0 ;
Interesting choice of ring.
Quoted 74 lines
drivers/gpu/drm/i915/intel_display.c +74
-0+ reg =DSPCNTR (intel_crtc->pipe); + dspcntr =I915_READ (reg); +DRM_DEBUG_DRIVER ("pixel format = %d\n" , pixel_format); +/* Mask out pixel format bits in case we change it */ + dspcntr &= ~DISPPLANE_PIXFORMAT_MASK ; +switch (pixel_format) { +case DRM_FORMAT_C8 : + dspcntr |=DISPPLANE_8BPP ; +break ; +case DRM_FORMAT_XRGB1555 : +case DRM_FORMAT_ARGB1555 : + dspcntr |=DISPPLANE_BGRX555 ; +break ; +case DRM_FORMAT_RGB565 : + dspcntr |=DISPPLANE_BGRX565 ; +break ; +case DRM_FORMAT_XRGB8888 : +case DRM_FORMAT_ARGB8888 : + dspcntr |=DISPPLANE_BGRX888 ; +break ; +case DRM_FORMAT_XBGR8888 : +case DRM_FORMAT_ABGR8888 : + dspcntr |=DISPPLANE_RGBX888 ; +break ; +case DRM_FORMAT_XRGB2101010 : +case DRM_FORMAT_ARGB2101010 : + dspcntr |=DISPPLANE_BGRX101010 ; +break ; +case DRM_FORMAT_XBGR2101010 : +case DRM_FORMAT_ABGR2101010 : + dspcntr |=DISPPLANE_RGBX101010 ; +break ; +default : +DRM_ERROR ("Unsupported pixel format 0x%08x\n" , pixel_format); +return -EINVAL ; + } + +/* Write pixel format update command to ring */ + ret =intel_ring_begin (ring,4 ); +if (ret) { +DRM_ERROR ("MI Command emit failed.\n" ); +return ret; + } +intel_ring_emit (ring,MI_NOOP ); +intel_ring_emit (ring,MI_LOAD_REGISTER_IMM (1 )); +intel_ring_emit (ring, reg); +intel_ring_emit (ring, dspcntr); +intel_ring_advance (ring); +return 0 ; +} + +/* Update the primary plane registers. Uses MI commands */ +static int haswell_update_plane (struct drm_crtc *crtc, +struct drm_framebuffer *fb,int x,int y) +{ +int ret; +struct drm_device *dev = crtc->dev; +struct drm_i915_private *dev_priv = dev->dev_private; +struct intel_crtc *intel_crtc =to_intel_crtc (crtc); +struct intel_ring_buffer *ring = &dev_priv->ring[BCS ]; +struct drm_i915_gem_object *obj; +int plane = intel_crtc->plane; + +switch (plane) { +case 0 : +case 1 : +case 2 : +break ; +default : +DRM_ERROR ("Can't update plane %c\n" ,plane_name (plane)); +return -EINVAL ; + } + obj =to_intel_framebuffer (fb)->obj; +
drivers/gpu/drm/i915/intel_display.c static int i9xx_update_plane(struct drm_crtc *crtc, struct drm_framebuffer *fb, · line 2056
Quoted 10 lines
drivers/gpu/drm/i915/intel_display.c +10
-0+/* Set pixel format */ +haswell_set_pixelformat (crtc, fb->pixel_format); + +/* Set tiling offsets. Tiling mode is not set here as * +* it is set from intel_gen7_queue_flip. Send MI Command * +* to change - * +* 1. Tiling offset * +* 2. stride - fb->pitches[0] * +* 2. surface base address * +* Linear offset and tile offset is same for Haswell */
The first rule of adding code is to be consistent with the surrounding code.
Quoted 44 lines
drivers/gpu/drm/i915/intel_display.c +34
-0+ intel_crtc->dspaddr_offset = +intel_gen4_compute_page_offset (&x, &y, obj->tiling_mode, + fb->bits_per_pixel /8 , + fb->pitches[0 ]); + +DRM_DEBUG_KMS ("Writing base %08X %08lX %d %d %d\n" , + obj->gtt_offset, intel_crtc->dspaddr_offset, + x, y, fb->pitches[0 ]); + +/* Emit MI commands here */ + ret =intel_ring_begin (ring,10 ); +if (ret) +return ret; +intel_ring_emit (ring,MI_NOOP ); +intel_ring_emit (ring,MI_LOAD_REGISTER_IMM (1 )); +intel_ring_emit (ring,DSPOFFSET (plane)); +intel_ring_emit (ring, (y <<16 ) | x); +intel_ring_emit (ring,MI_LOAD_REGISTER_IMM (1 )); +intel_ring_emit (ring,DSPSTRIDE (plane)); +intel_ring_emit (ring, fb->pitches[0 ]); +intel_ring_emit (ring,MI_LOAD_REGISTER_IMM (1 )); +intel_ring_emit (ring,DSPSURF (plane)); +intel_ring_emit (ring, obj->gtt_offset + intel_crtc->dspaddr_offset); +intel_ring_advance (ring); + +return 0 ; +} +static int ironlake_update_plane (struct drm_crtc *crtc,struct drm_framebuffer *fb,int x,int y) {@@ -7494,9 +7617,26 @@ static int intel_crtc_page_flip(struct drm_crtc *crtc,struct drm_framebuffer *old_fb = crtc->fb;struct drm_i915_gem_object *obj =to_intel_framebuffer (fb)->obj;struct intel_crtc *intel_crtc =to_intel_crtc (crtc); +struct intel_framebuffer *intel_fb;struct intel_unpin_work *work;unsigned long flags;int ret; +/* +* TILEOFF registers can't be changed via MI display flips. +* Changes in pitches[0] and offsets[0] updates the primary plane +* control registers. +*/
drivers/gpu/drm/i915/intel_display.c static int intel_crtc_page_flip(struct drm_crtc *crtc, · line 7638
Quoted 10 lines
drivers/gpu/drm/i915/intel_display.c +10
-0+ intel_fb =to_intel_framebuffer (crtc->fb); +if ((IS_HASWELL (dev)) && + ((obj->tiling_mode != intel_fb->obj->tiling_mode) || + (fb->offsets[0 ] != crtc->fb->offsets[0 ]) || + (fb->pitches[0 ] != crtc->fb->pitches[0 ]))) { +DRM_DEBUG_DRIVER (" crtc fb: pitch = %d offset = %d\n" , + crtc->fb->pitches[0 ], crtc->fb->offsets[0 ]); +DRM_DEBUG_DRIVER (" input fb: pitch = %d offset = %d\n" , + fb->pitches[0 ], fb->offsets[0 ]); +haswell_update_plane (crtc, fb,0 ,0 );
We do expect code to at least bear some resemblence to the CODING_STYLE.
Also this techinique does not look to be haswell specific, and with some rearrangement could be written much more neatly.
-Chris
Signature · 1 line
Chris Wilson, Intel Open Source Technology Centre
Hi Chris,
This patch is necessary for applying pixel format changes without creating new frame buffer. The pixel format will be changed at page flip.
Background - The present kernel code does not support applying pixel format to the current frame buffer. Hence hardware composer needs to create a new frame buffer each time it needs to change the frame buffer. If the application/game tries to change the pixel format very frequently, this affects performance. Motivation - This change enables the hardware composer to apply the new pixel format without creating a new framebuffer. This improves the performance at a time when the application frequently changes the pixel format.
Let me know if any queries.
Regards,
Sandeep
-----Original Message-----
From: Chris Wilson [mailto:[email protected]]
Sent: Friday, September 13, 2013 8:08 PM
To: Ramakutty, SandeepX
Cc: [email protected]
Subject: Re: [Intel-gfx] [PATCH] drm/i915: Add support to change pixel format, tiling mode, tiling offset.
Quoted 2 lines · Sandeep Ramankutty
Change: Add support to change the pixel format, base surface address, tiling mode, tiling offset on the flow during the primary plane flip.
Tell us why first. Why this patch is necesary is the fundamental reason that we need to record in the changelog. Discuss the background and the motivation that leads us to require a kernel patch.
Quoted 4 lines
Issue: This support is needed by hardware composer to meet the
performance optimization requirement for 3D benchmark. This patch
enables change in pixel format and tiling params without adding and removing the framebuffer. Adding and removing the framebuffer impacts performance.
So you say. Examples are vital, especially if you make a claim as towards performance. And then to back those up with tests to make sure nothing is broken. The other question is how do we end up regularly flipping between pixel formats that it shows up in a performance benchmark.
Quoted 10 lines
Change Details-
drm: Defined function pointerset_pixelformatindrm_crtc_funcs.drm_crtc.cis modified to execute the function to update pixel format. drm/i915:intel_crtc_set_pixel_format()implemented in i915 driver code (intel_display.c) and set todrm_crtc_funcs->set_pixelformat.haswell_set_pixelformat()implemented to update pixel format. This is specific to Haswellhaswell_update_plane()implemented to update changes in tiling offset, surface base address and stride-fb->pitches[0]. Sends MI command to update the params in primary plane control registers.
You don't need to repeat the patch, just tell us what complications you encountered and how you resolved them, or what issues remain.
Quoted 18 lines
Change-Id I4b0af83f641b2b79ee4f5c3401790d7d90ccd9efSigned-off-by Pallavi G <[email protected]>Signed-off-by Sandeep Ramakutty <[email protected]>--- drivers/gpu/drm/drm_crtc.c | 15 +++- drivers/gpu/drm/i915/intel_display.c | 156 ++++++++++++++++++++++++++++++++++ include/drm/drm_crtc.h | 8 ++ 3 files changed, 176 insertions(+), 3 deletions(-)drivers/gpu/drm/drm_crtc.c +0
-0@@ -3518,9 +3518,18 @@ int drm_mode_page_flip_ioctl(struct drm_device *dev, }if (crtc->fb->pixel_format != fb->pixel_format) {
drivers/gpu/drm/drm_crtc.c int drm_mode_page_flip_ioctl(struct drm_device *dev, · line 3527
Quoted 10 lines
drivers/gpu/drm/drm_crtc.c +7
-3-DRM_DEBUG_KMS ("Page flip is not allowed to change frame buffer format.\n" ); - ret = -EINVAL ; - goto out; +if (crtc->funcs->set_pixelformat ==NULL ) { +DRM_DEBUG_KMS ("Pixel format change not allowed" ); + ret = -EINVAL ; + goto out; + } +/* supports dynamic change in pixel format */ + ret = crtc->funcs->set_pixelformat (crtc, fb->pixel_format);
Bleh.
Just install a default set_pixelformat that returns -EINVAL and lose the i++; /* increment i after reading */
Also the current use of crtc->funcs->set_pixelformat suggests confusion is paramount.
drivers/gpu/drm/drm_crtc.c int drm_mode_page_flip_ioctl(struct drm_device *dev, · line 3532
Quoted 5 lines
drivers/gpu/drm/drm_crtc.c +5
-0+if (ret) { +DRM_DEBUG_KMS ("Pixel format change failed %d" , + fb->pixel_format); + goto out; + }
What happens if the flip fails afterwards? Where's the unwind? Where's the protection that prevents the format change whilst the current scanout is still visible? Perhaps this being the ring emission is being attempted far too early.
Quoted 18 lines
drivers/gpu/drm/drm_crtc.c +0
-0} if (page_flip->flags & DRM_MODE_PAGE_FLIP_EVENT) { diff --git
a/drivers/gpu/drm/i915/intel_display.cb/drivers/gpu/drm/i915/intel_display.c
index 955df91..7bfe088 100644drivers/gpu/drm/i915/intel_display.c +1
-0@@ -45,6 +45,7 @@ bool intel_pipe_has_type(struct drm_crtc *crtc, int type); static void intel_increase_pllclock(struct drm_crtc *crtc);static void intel_crtc_update_cursor (struct drm_crtc *crtc,bool on); +typedef struct {int min, max; }intel_range_t ;@@ -1959,6 +1960,128 @@ static int i9xx_update_plane(struct drm_crtc *crtc, struct drm_framebuffer *fb,return 0 ;
drivers/gpu/drm/i915/intel_display.c static int i9xx_update_plane(struct drm_crtc *crtc, struct drm_framebuffer *fb, · line 1970
Quoted 10 lines
drivers/gpu/drm/i915/intel_display.c +8
-0} +/* Set Pixel format for Haswell using MI commands */ static int +haswell_set_pixelformat (struct drm_crtc *crtc,u32 pixel_format) { +u32 dspcntr, reg; +struct drm_device *dev = crtc->dev; +struct drm_i915_private *dev_priv = dev->dev_private; +struct intel_crtc *intel_crtc =to_intel_crtc (crtc); +struct intel_ring_buffer *ring = &dev_priv->ring[BCS ]; +int ret =0 ;
Interesting choice of ring.
Quoted 73 lines
drivers/gpu/drm/i915/intel_display.c +73
-0+ reg =DSPCNTR (intel_crtc->pipe); + dspcntr =I915_READ (reg); +DRM_DEBUG_DRIVER ("pixel format = %d\n" , pixel_format); +/* Mask out pixel format bits in case we change it */ + dspcntr &= ~DISPPLANE_PIXFORMAT_MASK ; +switch (pixel_format) { +case DRM_FORMAT_C8 : + dspcntr |=DISPPLANE_8BPP ; +break ; +case DRM_FORMAT_XRGB1555 : +case DRM_FORMAT_ARGB1555 : + dspcntr |=DISPPLANE_BGRX555 ; +break ; +case DRM_FORMAT_RGB565 : + dspcntr |=DISPPLANE_BGRX565 ; +break ; +case DRM_FORMAT_XRGB8888 : +case DRM_FORMAT_ARGB8888 : + dspcntr |=DISPPLANE_BGRX888 ; +break ; +case DRM_FORMAT_XBGR8888 : +case DRM_FORMAT_ABGR8888 : + dspcntr |=DISPPLANE_RGBX888 ; +break ; +case DRM_FORMAT_XRGB2101010 : +case DRM_FORMAT_ARGB2101010 : + dspcntr |=DISPPLANE_BGRX101010 ; +break ; +case DRM_FORMAT_XBGR2101010 : +case DRM_FORMAT_ABGR2101010 : + dspcntr |=DISPPLANE_RGBX101010 ; +break ; +default : +DRM_ERROR ("Unsupported pixel format 0x%08x\n" , pixel_format); +return -EINVAL ; + } + +/* Write pixel format update command to ring */ + ret =intel_ring_begin (ring,4 ); +if (ret) { +DRM_ERROR ("MI Command emit failed.\n" ); +return ret; + } +intel_ring_emit (ring,MI_NOOP ); +intel_ring_emit (ring,MI_LOAD_REGISTER_IMM (1 )); +intel_ring_emit (ring, reg); +intel_ring_emit (ring, dspcntr); +intel_ring_advance (ring); +return 0 ; +} + +/* Update the primary plane registers. Uses MI commands */ static int +haswell_update_plane (struct drm_crtc *crtc, +struct drm_framebuffer *fb,int x,int y) { +int ret; +struct drm_device *dev = crtc->dev; +struct drm_i915_private *dev_priv = dev->dev_private; +struct intel_crtc *intel_crtc =to_intel_crtc (crtc); +struct intel_ring_buffer *ring = &dev_priv->ring[BCS ]; +struct drm_i915_gem_object *obj; +int plane = intel_crtc->plane; + +switch (plane) { +case 0 : +case 1 : +case 2 : +break ; +default : +DRM_ERROR ("Can't update plane %c\n" ,plane_name (plane)); +return -EINVAL ; + } + obj =to_intel_framebuffer (fb)->obj; +
drivers/gpu/drm/i915/intel_display.c static int i9xx_update_plane(struct drm_crtc *crtc, struct drm_framebuffer *fb, · line 2056
Quoted 10 lines
drivers/gpu/drm/i915/intel_display.c +10
-0+/* Set pixel format */ +haswell_set_pixelformat (crtc, fb->pixel_format); + +/* Set tiling offsets. Tiling mode is not set here as * +* it is set from intel_gen7_queue_flip. Send MI Command * +* to change - * +* 1. Tiling offset * +* 2. stride - fb->pitches[0] * +* 2. surface base address * +* Linear offset and tile offset is same for Haswell */
The first rule of adding code is to be consistent with the surrounding code.
Quoted 43 lines
drivers/gpu/drm/i915/intel_display.c +34
-0+ intel_crtc->dspaddr_offset = +intel_gen4_compute_page_offset (&x, &y, obj->tiling_mode, + fb->bits_per_pixel /8 , + fb->pitches[0 ]); + +DRM_DEBUG_KMS ("Writing base %08X %08lX %d %d %d\n" , + obj->gtt_offset, intel_crtc->dspaddr_offset, + x, y, fb->pitches[0 ]); + +/* Emit MI commands here */ + ret =intel_ring_begin (ring,10 ); +if (ret) +return ret; +intel_ring_emit (ring,MI_NOOP ); +intel_ring_emit (ring,MI_LOAD_REGISTER_IMM (1 )); +intel_ring_emit (ring,DSPOFFSET (plane)); +intel_ring_emit (ring, (y <<16 ) | x); +intel_ring_emit (ring,MI_LOAD_REGISTER_IMM (1 )); +intel_ring_emit (ring,DSPSTRIDE (plane)); +intel_ring_emit (ring, fb->pitches[0 ]); +intel_ring_emit (ring,MI_LOAD_REGISTER_IMM (1 )); +intel_ring_emit (ring,DSPSURF (plane)); +intel_ring_emit (ring, obj->gtt_offset + intel_crtc->dspaddr_offset); +intel_ring_advance (ring); + +return 0 ; +} +static int ironlake_update_plane (struct drm_crtc *crtc, struct drm_framebuffer *fb, int x, int y) { @@ -7494,9 +7617,26 @@ static int intel_crtc_page_flip(struct drm_crtc *crtc, struct drm_framebuffer *old_fb = crtc->fb;struct drm_i915_gem_object *obj =to_intel_framebuffer (fb)->obj;struct intel_crtc *intel_crtc =to_intel_crtc (crtc); +struct intel_framebuffer *intel_fb;struct intel_unpin_work *work;unsigned long flags;int ret; +/* +* TILEOFF registers can't be changed via MI display flips. +* Changes in pitches[0] and offsets[0] updates the primary plane +* control registers. +*/
drivers/gpu/drm/i915/intel_display.c static int i9xx_update_plane(struct drm_crtc *crtc, struct drm_framebuffer *fb,
Quoted 10 lines
drivers/gpu/drm/i915/intel_display.c +10
-0+ intel_fb =to_intel_framebuffer (crtc->fb); +if ((IS_HASWELL (dev)) && + ((obj->tiling_mode != intel_fb->obj->tiling_mode) || + (fb->offsets[0 ] != crtc->fb->offsets[0 ]) || + (fb->pitches[0 ] != crtc->fb->pitches[0 ]))) { +DRM_DEBUG_DRIVER (" crtc fb: pitch = %d offset = %d\n" , + crtc->fb->pitches[0 ], crtc->fb->offsets[0 ]); +DRM_DEBUG_DRIVER (" input fb: pitch = %d offset = %d\n" , + fb->pitches[0 ], fb->offsets[0 ]); +haswell_update_plane (crtc, fb,0 ,0 );
We do expect code to at least bear some resemblence to the CODING_STYLE.
Also this techinique does not look to be haswell specific, and with some rearrangement could be written much more neatly. -Chris
--
Chris Wilson, Intel Open Source Technology Centre
Quoted 3 lines · SandeepX
Hi Chris,
This patch is necessary for applying pixel format changes without creating new frame buffer.
No, it doesn't. As pixelformat is only specified with AddFB2, it appears there is something else required to allow changing format on an existing fb on the fly.
Quoted 3 lines
The pixel format will be changed at page flip.
Background - The present kernel code does not support applying pixel format to the current frame buffer. Hence hardware composer needs to create a new frame buffer each time it needs to change the frame buffer. If the application/game tries to change the pixel format very frequently, this affects performance. Motivation - This change enables the hardware composer to apply the new pixel format without creating a new framebuffer. This improves the performance at a time when the application frequently changes the pixel format.
That's obvious from the patch. I was hoping for more details on the use case to demonstrate the necessity of this approach, I still do not see a scenario that would require frequent changes in scanout pixelformat.
Quantify, quantify, quantify. Then we know whether the approach meets your goal, and more importantly detect any future regressions. -Chris
Signature · 1 line
Chris Wilson, Intel Open Source Technology Centre