mbox series

[0/4] drm/atmel-hlcdc: fix plane clipping/rotation issues

Message ID 20190110151020.30468-1-peda@axentia.se (mailing list archive)
Headers show
Series drm/atmel-hlcdc: fix plane clipping/rotation issues | expand

Message

Peter Rosin Jan. 10, 2019, 3:10 p.m. UTC
Hi!

I found an unfortunate issue while recoding plane handling to use
drm_atomic_helper_check_plane_state(). The driver rotates clockwise,
which is not correct. I simply fixed it (patch 1/4), but maybe that
will cause regressions for unsuspecting users who simply assumed
that the clockwise rotation was correct? I don't know what to do
about that? Adding an option to get the old broken behavior seems
useless, wouldn't it be just as easy to just fix whatever app to
rotate the other way instead of adding an option somewhere?

I have only tested this series on sama5d3, but I did check the docs
for various other chips (sama5d2, sama5d4, sam9n12, sam9g15, sam9g35
and sam9x35) supported by the driver (relevant to patch 4/4).

Cheers,
Peter

Peter Rosin (4):
  drm/atmel-hlcdc: rotate planes counterclockwise
  drm/atmel-hlcdc: do not swap w/h of the crtc when a plane is rotated
  drm/atmel-hlcdc: fix clipping of planes
  drm/atmel-hlcdc: do not immediately disable planes, wait for next
    frame

 drivers/gpu/drm/atmel-hlcdc/atmel_hlcdc_plane.c | 179 +++++++++---------------
 1 file changed, 67 insertions(+), 112 deletions(-)

Comments

Peter Rosin Jan. 10, 2019, 6:51 p.m. UTC | #1
On 2019-01-10 18:29, Boris Brezillon wrote:
> On Thu, 10 Jan 2019 15:10:48 +0000
> Peter Rosin <peda@axentia.se> wrote:
> 
>> The A2Q and UPDATE bits have no effect in the channel disable registers.
>> However, since they are present, assume that the intention is to disable
>> planes, not immediately as indicated by the RST bit, but on the next
>> frame shift since that is what A2Q and UPDATE means in the channel enable
>> registers.
>>
>> Disabling the plane on the next frame shift is done with the EN bit,
>> so use that.
> 
> It's been a long time, but I think I had a good reason for forcing a
> reset. IIRC, when you don't do that and the CRTC is disabled before the
> plane, the EN bit stays around, and next time you queue a plane update,
> you'll start with an invalid buf pointer.

It might be possible to clear the EN bit in ...CHDR before enabling the
plane in ...CHER. Or is that too late? But this patch is not overly
important, I just wanted to avoid the resulting "black hole" when the
plane DMA is disabled mid-frame. But disabling planes is probably not
something that happens frequently and will perhaps not be noticed at
all...

Cheers,
Peter

>>
>> Signed-off-by: Peter Rosin <peda@axentia.se>
>> ---
>>  drivers/gpu/drm/atmel-hlcdc/atmel_hlcdc_plane.c | 4 +---
>>  1 file changed, 1 insertion(+), 3 deletions(-)
>>
>> diff --git a/drivers/gpu/drm/atmel-hlcdc/atmel_hlcdc_plane.c b/drivers/gpu/drm/atmel-hlcdc/atmel_hlcdc_plane.c
>> index 05519e8c6586..f2f570642f84 100644
>> --- a/drivers/gpu/drm/atmel-hlcdc/atmel_hlcdc_plane.c
>> +++ b/drivers/gpu/drm/atmel-hlcdc/atmel_hlcdc_plane.c
>> @@ -728,9 +728,7 @@ static void atmel_hlcdc_plane_atomic_disable(struct drm_plane *p,
>>  
>>  	/* Disable the layer */
>>  	atmel_hlcdc_layer_write_reg(&plane->layer, ATMEL_HLCDC_LAYER_CHDR,
>> -				    ATMEL_HLCDC_LAYER_RST |
>> -				    ATMEL_HLCDC_LAYER_A2Q |
>> -				    ATMEL_HLCDC_LAYER_UPDATE);
>> +				    ATMEL_HLCDC_LAYER_EN);
>>  
>>  	/* Clear all pending interrupts */
>>  	atmel_hlcdc_layer_read_reg(&plane->layer, ATMEL_HLCDC_LAYER_ISR);
>
Peter Rosin Jan. 10, 2019, 9:24 p.m. UTC | #2
On 2019-01-10 18:45, Boris Brezillon wrote:
> On Thu, 10 Jan 2019 15:10:28 +0000
> Peter Rosin <peda@axentia.se> wrote:
> 
>> Hi!
>>
>> I found an unfortunate issue while recoding plane handling to use
>> drm_atomic_helper_check_plane_state(). The driver rotates clockwise,
>> which is not correct. I simply fixed it (patch 1/4), but maybe that
>> will cause regressions for unsuspecting users who simply assumed
>> that the clockwise rotation was correct? I don't know what to do
>> about that? Adding an option to get the old broken behavior seems
>> useless, wouldn't it be just as easy to just fix whatever app to
>> rotate the other way instead of adding an option somewhere?
> 
> Hm, rotation support has been added before the standard rotation
> property was created, and at that time I assumed rotation was clockwise
> (which apparently was an unwise choice). Anyway, I don't have a
> solution for this problem, so I'll let Nicolas decide if it's
> acceptable to change the rotation behavior.

Speaking of unwise, fbcon rotation is clockwise and drm rotation
is counterclockwise. 'nuff said.

Cheers,
Peter
Peter Rosin Jan. 11, 2019, 9:16 a.m. UTC | #3
On 2019-01-10 21:16, Sam Ravnborg wrote:
> Hi Peter.
> 
> (Hijacking this thread as I lost the orginal mails)

Assuming you wanted to reply to this patch?
https://patchwork.kernel.org/patch/10753571/

>>> I found an unfortunate issue while recoding plane handling to use
>>> drm_atomic_helper_check_plane_state(). The driver rotates clockwise,
>>> which is not correct. I simply fixed it (patch 1/4), but maybe that
>>> will cause regressions for unsuspecting users who simply assumed
>>> that the clockwise rotation was correct? I don't know what to do
>>> about that? Adding an option to get the old broken behavior seems
>>> useless, wouldn't it be just as easy to just fix whatever app to
>>> rotate the other way instead of adding an option somewhere?
>>
>> Hm, rotation support has been added before the standard rotation
>> property was created, and at that time I assumed rotation was clockwise
>> (which apparently was an unwise choice). Anyway, I don't have a
>> solution for this problem, so I'll let Nicolas decide if it's
>> acceptable to change the rotation behavior.
>>
>>> I have only tested this series on sama5d3, but I did check the docs
>>> for various other chips (sama5d2, sama5d4, sam9n12, sam9g15, sam9g35
>>> and sam9x35) supported by the driver (relevant to patch 4/4).
> 
> I wonder if, when this code path is anyway touched, could benefit
> from drm_rect_rotate().
> 
> It is obviously not a simple replacement, but could it be used then
> I hope the resulting code is simpler.

What are you referring to that goes beyond what is done in patch 3/4
in this series? After setting up the strides, the only use of src_[xywh]
are to calculate the scaling factors, and for that the position is
irrelevant. I.e. src_x and src_y are not used. Sure, in some theoretical
sense it might be good if src_[xy] are also transformed into the rotated
coordinate system along with src_[wh], but it seems a bit backwards to
switch over to struct drm_rect when the interesting properties are the
width and height, not the coordinates of the corners. No strong feelings
on the issue though...

Cheers,
Peter
Nicolas Ferre Jan. 11, 2019, 2:18 p.m. UTC | #4
On 10/01/2019 at 18:45, Boris Brezillon wrote:
> On Thu, 10 Jan 2019 15:10:28 +0000
> Peter Rosin <peda@axentia.se> wrote:
> 
>> Hi!
>>
>> I found an unfortunate issue while recoding plane handling to use
>> drm_atomic_helper_check_plane_state(). The driver rotates clockwise,
>> which is not correct. I simply fixed it (patch 1/4), but maybe that
>> will cause regressions for unsuspecting users who simply assumed
>> that the clockwise rotation was correct? I don't know what to do
>> about that? Adding an option to get the old broken behavior seems
>> useless, wouldn't it be just as easy to just fix whatever app to
>> rotate the other way instead of adding an option somewhere?
> 
> Hm, rotation support has been added before the standard rotation
> property was created, and at that time I assumed rotation was clockwise
> (which apparently was an unwise choice). Anyway, I don't have a
> solution for this problem, so I'll let Nicolas decide if it's
> acceptable to change the rotation behavior.

Yes, being consistent with standard DRM sub-system is far more important 
in my opinion.

Best regards,
   Nicolas

>> I have only tested this series on sama5d3, but I did check the docs
>> for various other chips (sama5d2, sama5d4, sam9n12, sam9g15, sam9g35
>> and sam9x35) supported by the driver (relevant to patch 4/4).
> 
> Thanks for addressing those problems.
> 
>>
>> Cheers,
>> Peter
>>
>> Peter Rosin (4):
>>    drm/atmel-hlcdc: rotate planes counterclockwise
>>    drm/atmel-hlcdc: do not swap w/h of the crtc when a plane is rotated
>>    drm/atmel-hlcdc: fix clipping of planes
>>    drm/atmel-hlcdc: do not immediately disable planes, wait for next
>>      frame
>>
>>   drivers/gpu/drm/atmel-hlcdc/atmel_hlcdc_plane.c | 179 +++++++++---------------
>>   1 file changed, 67 insertions(+), 112 deletions(-)
>>
> 
>
Peter Rosin Jan. 11, 2019, 2:29 p.m. UTC | #5
On 2019-01-10 20:25, Boris Brezillon wrote:
> On Thu, 10 Jan 2019 18:51:21 +0000
> Peter Rosin <peda@axentia.se> wrote:
> 
>> On 2019-01-10 18:29, Boris Brezillon wrote:
>>> On Thu, 10 Jan 2019 15:10:48 +0000
>>> Peter Rosin <peda@axentia.se> wrote:
>>>   
>>>> The A2Q and UPDATE bits have no effect in the channel disable registers.
>>>> However, since they are present, assume that the intention is to disable
>>>> planes, not immediately as indicated by the RST bit, but on the next
>>>> frame shift since that is what A2Q and UPDATE means in the channel enable
>>>> registers.
>>>>
>>>> Disabling the plane on the next frame shift is done with the EN bit,
>>>> so use that.  
>>>
>>> It's been a long time, but I think I had a good reason for forcing a
>>> reset. IIRC, when you don't do that and the CRTC is disabled before the
>>> plane, the EN bit stays around, and next time you queue a plane update,
>>> you'll start with an invalid buf pointer.  
>>
>> It might be possible to clear the EN bit in ...CHDR before enabling the
>> plane in ...CHER. Or is that too late?
> 
> I think I tried that, but I'm not sure (BTW, this change was done in
> bd4248bb5e8b ("drm: atmel-hlcdc: reset layer A2Q and UPDATE bits when

That patch is a big fat NOP if you read the documentation. Those bits
are marked with a '-' for all LCDC channel disable registers, for all
supported chips IIUC. Are the effects of those bits mentioned in any
errata?

It would be good with a comment that the present undocumented disable
method is intentional. That would have kept me from assuming the whole
thing was just copy-paste junk from ..._enable that happened to work.

>> disabling it")). Anyway, I'm not even sure this is still needed now
>> that atomic updates have a wait_for_flip_done/vblank() in the commit
>> path.

The documentation for the RST bit states "Resets the layer immediately.
The frame is aborted." which sounds a bit scary and heavy-handed. But
again, I don't know what that actually means and what the effects are
but that was the reason for me wanting to avoid the RST bit.

Cheers,
Peter

>> But this patch is not overly
>> important, I just wanted to avoid the resulting "black hole" when the
>> plane DMA is disabled mid-frame. But disabling planes is probably not
>> something that happens frequently and will perhaps not be noticed at
>> all...
> 
> Okay. Other patches look good to me, I'm just waiting for Nicolas
> feedback before applying them.
>
Boris Brezillon Jan. 16, 2019, 2:45 p.m. UTC | #6
On Fri, 11 Jan 2019 14:29:28 +0000
Peter Rosin <peda@axentia.se> wrote:

> On 2019-01-10 20:25, Boris Brezillon wrote:
> > On Thu, 10 Jan 2019 18:51:21 +0000
> > Peter Rosin <peda@axentia.se> wrote:
> >   
> >> On 2019-01-10 18:29, Boris Brezillon wrote:  
> >>> On Thu, 10 Jan 2019 15:10:48 +0000
> >>> Peter Rosin <peda@axentia.se> wrote:
> >>>     
> >>>> The A2Q and UPDATE bits have no effect in the channel disable registers.
> >>>> However, since they are present, assume that the intention is to disable
> >>>> planes, not immediately as indicated by the RST bit, but on the next
> >>>> frame shift since that is what A2Q and UPDATE means in the channel enable
> >>>> registers.
> >>>>
> >>>> Disabling the plane on the next frame shift is done with the EN bit,
> >>>> so use that.    
> >>>
> >>> It's been a long time, but I think I had a good reason for forcing a
> >>> reset. IIRC, when you don't do that and the CRTC is disabled before the
> >>> plane, the EN bit stays around, and next time you queue a plane update,
> >>> you'll start with an invalid buf pointer.    
> >>
> >> It might be possible to clear the EN bit in ...CHDR before enabling the
> >> plane in ...CHER. Or is that too late?  
> > 
> > I think I tried that, but I'm not sure (BTW, this change was done in
> > bd4248bb5e8b ("drm: atmel-hlcdc: reset layer A2Q and UPDATE bits when  
> 
> That patch is a big fat NOP if you read the documentation. Those bits
> are marked with a '-' for all LCDC channel disable registers, for all
> supported chips IIUC. Are the effects of those bits mentioned in any
> errata?

IIRC, it was not documented in the datasheet, but this came out during
a discussion with the IP designer.

> 
> It would be good with a comment that the present undocumented disable
> method is intentional.

Yes, I should have added a comment about that, my bad.

> That would have kept me from assuming the whole
> thing was just copy-paste junk from ..._enable that happened to work.
> 
> >> disabling it")). Anyway, I'm not even sure this is still needed now
> >> that atomic updates have a wait_for_flip_done/vblank() in the commit
> >> path.  
> 
> The documentation for the RST bit states "Resets the layer immediately.
> The frame is aborted." which sounds a bit scary and heavy-handed. But
> again, I don't know what that actually means and what the effects are
> but that was the reason for me wanting to avoid the RST bit.

As I said, I'm not even sure the problem I was trying to fix still
exists.
Boris Brezillon Jan. 27, 2019, 8:27 a.m. UTC | #7
On Thu, 10 Jan 2019 15:10:28 +0000
Peter Rosin <peda@axentia.se> wrote:

> Hi!
> 
> I found an unfortunate issue while recoding plane handling to use
> drm_atomic_helper_check_plane_state(). The driver rotates clockwise,
> which is not correct. I simply fixed it (patch 1/4), but maybe that
> will cause regressions for unsuspecting users who simply assumed
> that the clockwise rotation was correct? I don't know what to do
> about that? Adding an option to get the old broken behavior seems
> useless, wouldn't it be just as easy to just fix whatever app to
> rotate the other way instead of adding an option somewhere?
> 
> I have only tested this series on sama5d3, but I did check the docs
> for various other chips (sama5d2, sama5d4, sam9n12, sam9g15, sam9g35
> and sam9x35) supported by the driver (relevant to patch 4/4).
> 
> Cheers,
> Peter
> 
> Peter Rosin (4):
>   drm/atmel-hlcdc: rotate planes counterclockwise
>   drm/atmel-hlcdc: do not swap w/h of the crtc when a plane is rotated
>   drm/atmel-hlcdc: fix clipping of planes

Queued patches 1-3 to drm-misc-next.

>   drm/atmel-hlcdc: do not immediately disable planes, wait for next
>     frame

Still waiting for Nicolas feedback on this one.


Thanks,

Boris
Peter Rosin Jan. 31, 2019, 1:13 p.m. UTC | #8
On 2019-01-27 09:27, Boris Brezillon wrote:
> On Thu, 10 Jan 2019 15:10:28 +0000
> Peter Rosin <peda@axentia.se> wrote:
> 
>> Hi!
>>
>> I found an unfortunate issue while recoding plane handling to use
>> drm_atomic_helper_check_plane_state(). The driver rotates clockwise,
>> which is not correct. I simply fixed it (patch 1/4), but maybe that
>> will cause regressions for unsuspecting users who simply assumed
>> that the clockwise rotation was correct? I don't know what to do
>> about that? Adding an option to get the old broken behavior seems
>> useless, wouldn't it be just as easy to just fix whatever app to
>> rotate the other way instead of adding an option somewhere?
>>
>> I have only tested this series on sama5d3, but I did check the docs
>> for various other chips (sama5d2, sama5d4, sam9n12, sam9g15, sam9g35
>> and sam9x35) supported by the driver (relevant to patch 4/4).
>>
>> Cheers,
>> Peter
>>
>> Peter Rosin (4):
>>   drm/atmel-hlcdc: rotate planes counterclockwise
>>   drm/atmel-hlcdc: do not swap w/h of the crtc when a plane is rotated
>>   drm/atmel-hlcdc: fix clipping of planes
> 
> Queued patches 1-3 to drm-misc-next.

Great, thanks.

>>   drm/atmel-hlcdc: do not immediately disable planes, wait for next
>>     frame
> 
> Still waiting for Nicolas feedback on this one.

[Adding back Nicolas, he seems to have gone missing from the list
recipients.]

I have done some testing of that patch and for me it's a definite
improvement. The test I did was removing a white plane from a white
background. Without the patch, the driver will output black where
the plane was for the current frame (since the driver does that
disc-area thing for the largest hidden part of the background).
With the patch, I get no visual glitches when removing a plane.

I use a plane to scroll a text, and if you know what to look for,
the black rectangle that flickers by as the plane with the scrolling
text is removed is little bit disturbing. Not a significant problem,
and maybe only geeks notice it, but still...

Just wanted to say that the resulting "black hole" mentioned in the
other thread really does exist and that the patch may make sense
beyond the fact that it removes usage of undocumented features.

I have not seen any bad side effects fro the patch, but admittedly
my testing was very limited and I did not try to remove the plane
while doing other stuff with the driver. So, there might still be
reasons for removing planes immediately...

Cheers,
Peter
Boris Brezillon Jan. 31, 2019, 1:21 p.m. UTC | #9
On Thu, 31 Jan 2019 13:13:22 +0000
Peter Rosin <peda@axentia.se> wrote:

> On 2019-01-27 09:27, Boris Brezillon wrote:
> > On Thu, 10 Jan 2019 15:10:28 +0000
> > Peter Rosin <peda@axentia.se> wrote:
> >   
> >> Hi!
> >>
> >> I found an unfortunate issue while recoding plane handling to use
> >> drm_atomic_helper_check_plane_state(). The driver rotates clockwise,
> >> which is not correct. I simply fixed it (patch 1/4), but maybe that
> >> will cause regressions for unsuspecting users who simply assumed
> >> that the clockwise rotation was correct? I don't know what to do
> >> about that? Adding an option to get the old broken behavior seems
> >> useless, wouldn't it be just as easy to just fix whatever app to
> >> rotate the other way instead of adding an option somewhere?
> >>
> >> I have only tested this series on sama5d3, but I did check the docs
> >> for various other chips (sama5d2, sama5d4, sam9n12, sam9g15, sam9g35
> >> and sam9x35) supported by the driver (relevant to patch 4/4).
> >>
> >> Cheers,
> >> Peter
> >>
> >> Peter Rosin (4):
> >>   drm/atmel-hlcdc: rotate planes counterclockwise
> >>   drm/atmel-hlcdc: do not swap w/h of the crtc when a plane is rotated
> >>   drm/atmel-hlcdc: fix clipping of planes  
> > 
> > Queued patches 1-3 to drm-misc-next.  
> 
> Great, thanks.
> 
> >>   drm/atmel-hlcdc: do not immediately disable planes, wait for next
> >>     frame  
> > 
> > Still waiting for Nicolas feedback on this one.  
> 
> [Adding back Nicolas, he seems to have gone missing from the list
> recipients.]
> 
> I have done some testing of that patch and for me it's a definite
> improvement. The test I did was removing a white plane from a white
> background. Without the patch, the driver will output black where
> the plane was for the current frame (since the driver does that
> disc-area thing for the largest hidden part of the background).
> With the patch, I get no visual glitches when removing a plane.
> 
> I use a plane to scroll a text, and if you know what to look for,
> the black rectangle that flickers by as the plane with the scrolling
> text is removed is little bit disturbing. Not a significant problem,
> and maybe only geeks notice it, but still...
> 
> Just wanted to say that the resulting "black hole" mentioned in the
> other thread really does exist and that the patch may make sense
> beyond the fact that it removes usage of undocumented features.
> 
> I have not seen any bad side effects fro the patch, but admittedly
> my testing was very limited and I did not try to remove the plane
> while doing other stuff with the driver. So, there might still be
> reasons for removing planes immediately...

Since everything is now synchronized on vsync events thanks to the
atomic modeset infra (including plane/crtc disable requests), I think
the problem I was trying to fix at the time no longer exists (might
re-appear if we start supporting async plane disable requests which is
anyway not supported by the core). So I think I'll just apply your
patch.

Thanks,

Boris